Changeset 20 for branches/Xvcl/Xvcl.Controls.pas
- Timestamp:
- May 6, 2013, 12:16:30 AM (12 years ago)
- Location:
- branches/Xvcl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Xvcl
- Property svn:ignore
-
old new 2 2 *.local 3 3 Win32 4 __history
-
- Property svn:ignore
-
branches/Xvcl/Xvcl.Controls.pas
r19 r20 9 9 TControl = class; 10 10 TWinControl = class; 11 12 TMessage = class 13 Number: Integer; 14 Handled: Boolean; 15 end; 16 17 TMouseButton = (mbLeft, mbRight, mbMiddle); 18 TMouseButtonSet = set of TMouseButton; 19 TMessageMouse = class(TMessage) 20 Position: TPoint; 21 Buttons: TMouseButtonSet; 22 end; 23 TMessageMouseDown = class(TMessageMouse); 24 TMessageMouseUp = class(TMessageMouse); 25 26 TKeyState = (ksShift, ksAlt, ksOS); 27 TKeyStateSet = set of TKeyState; 28 TMessageKeyboard = class(TMessage) 29 KeyCode: Integer; 30 States: TKeyStateSet; 31 end; 11 32 12 33 TControlCanvas = class(TCanvas) … … 25 46 FBounds: TRectangle; 26 47 FOnClick: TNotifyEvent; 48 FColor: TColor; 49 FOnMouseDown: TNotifyEvent; 50 FOnMouseUp: TNotifyEvent; 27 51 function GetCanvas: TCanvas; 28 52 procedure SetParent(const Value: TWinControl); virtual; 53 procedure SetColor(const Value: TColor); 29 54 protected 30 55 function GetVideoDevice: TVideoDevice; virtual; 31 56 public 32 57 Controls: TList<TControl>; 58 function HandleMessage(Message: TMessage): Boolean; virtual; 33 59 function ClientToScreen(Position: TPoint): TPoint; virtual; 60 function ScreenToClient(Position: TPoint): TPoint; virtual; 34 61 procedure Paint; virtual; 35 62 constructor Create; override; … … 40 67 property Parent: TWinControl read FParent write SetParent; 41 68 property VideoDevice: TVideoDevice read GetVideoDevice; 69 property Color: TColor read FColor write SetColor; 42 70 property OnClick: TNotifyEvent read FOnClick write FOnClick; 71 property OnMouseDown: TNotifyEvent read FOnMouseDown write FOnMouseDown; 72 property OnMouseUp: TNotifyEvent read FOnMouseUp write FOnMouseUp; 43 73 end; 44 74 45 75 TWinControl = class(TControl) 76 protected 77 public 46 78 Controls: TList<TControl>; 47 function Handle Click(Position: TPoint): Boolean;79 function HandleMessage(Message: TMessage): Boolean; override; 48 80 constructor Create; override; 49 81 destructor Destroy; override; … … 56 88 public 57 89 procedure Paint; override; 90 constructor Create; override; 58 91 property Caption: string read FCaption write SetCaption; 59 92 end; … … 75 108 function TControl.ClientToScreen(Position: TPoint): TPoint; 76 109 begin 77 Result := TPoint.Create(Bounds.Left + Position.X, Bounds.Top + Position.Y);110 Result := Position.Add(Bounds.TopLeft); 78 111 if Assigned(Parent) then Result := Parent.ClientToScreen(Result); 79 112 end; … … 107 140 end; 108 141 142 function TControl.HandleMessage(Message: TMessage): Boolean; 143 begin 144 if Message is TMessageMouseDown then begin 145 if Assigned(FOnMouseDown) then FOnMouseDown(Self); 146 Color := clGray; 147 Paint; 148 end else 149 if Message is TMessageMouseUp then begin 150 if Assigned(FOnMouseUp) then FOnMouseUp(Self); 151 Color := clSilver; 152 Paint; 153 if Assigned(FOnClick) then FOnClick(Self); 154 end; 155 end; 156 109 157 procedure TControl.Paint; 110 158 var … … 112 160 begin 113 161 for C in Controls do C.Paint; 162 end; 163 164 function TControl.ScreenToClient(Position: TPoint): TPoint; 165 begin 166 Result := Position.Substract(Bounds.TopLeft); 167 if Assigned(Parent) then Result := Parent.ClientToScreen(Result); 168 end; 169 170 procedure TControl.SetColor(const Value: TColor); 171 begin 172 if FColor <> Value then begin 173 FColor := Value; 174 Paint; 175 end; 114 176 end; 115 177 … … 125 187 { TButton } 126 188 189 constructor TButton.Create; 190 begin 191 inherited; 192 FColor := clSilver; 193 end; 194 127 195 procedure TButton.Paint; 128 196 begin 129 197 inherited; 130 198 with Canvas do begin 199 Brush.Color := Color; 200 FillRect(TRectangle.Create(0, 0, Bounds.Width, Bounds.Height)); 131 201 MoveTo(TPoint.Create(0, 0)); 132 202 LineTo(TPoint.Create(Bounds.Width - 1, 0)); … … 176 246 end; 177 247 178 function TWinControl.Handle Click(Position: TPoint): Boolean;248 function TWinControl.HandleMessage(Message: TMessage): Boolean; 179 249 var 180 250 Control: TControl; … … 182 252 Result := False; 183 253 for Control in Controls do begin 184 if Control.Bounds.Contains(Position) then begin 185 if Control is TWinControl then begin 186 if TWinControl(Control).HandleClick(Position.Substract(Bounds.LeftTop)) then begin 187 Result := True; 188 Break; 189 end; 190 end else 191 if Assigned(Control.OnClick) then begin 192 Control.OnClick(Self); 254 if Message is TMessageMouse then 255 with TMessageMouse(Message) do begin 256 if Control.Bounds.Contains(ScreenToClient(Position)) then begin 257 if TWinControl(Control).HandleMessage(Message) then begin 193 258 Result := True; 194 259 Break; … … 196 261 end; 197 262 end; 263 end; 198 264 end; 199 265
Note:
See TracChangeset
for help on using the changeset viewer.