source: trunk/Packages/DpiControls/Dpi.Controls.pas

Last change on this file was 642, checked in by chronos, 8 months ago
  • Fixed: Do not scroll map if mouse is outside of window region.
File size: 35.1 KB
Line 
1unit Dpi.Controls;
2
3interface
4
5uses
6 Classes, SysUtils, Controls, Graphics, LCLType, Generics.Collections,
7 Dpi.Graphics;
8
9const
10 CM_MOUSELEAVE = Controls.CM_MOUSELEAVE;
11
12type
13 TMouseButton = Controls.TMouseButton;
14 TKeyEvent = Controls.TKeyEvent;
15 TAlign = Controls.TAlign;
16 TBorderStyle = Controls.TBorderStyle;
17
18 { TControlEx }
19
20 TControlEx = class(Controls.TControl)
21 public
22 property ParentColor;
23 property OnMouseDown;
24 property OnMouseUp;
25 property OnMouseMove;
26 property OnMouseWheel;
27 property OnMouseLeave;
28 property OnMouseEnter;
29 property OnDblClick;
30 property ParentFont;
31 end;
32
33 { TGraphicControlEx }
34
35 TGraphicControlEx = class(Controls.TGraphicControl)
36 public
37 property OnPaint;
38 procedure Paint; override;
39 end;
40
41 TWinControlEx = class(Controls.TWinControl)
42 public
43 property BorderStyle;
44 property OnKeyDown;
45 end;
46
47 TWinControl = class;
48 TControlBorderSpacing = class;
49
50 { TSizeConstraints }
51
52 TSizeConstraints = class(TPersistent)
53 private
54 FMaxHeight: TConstraintSize;
55 FMaxWidth: TConstraintSize;
56 FMinHeight: TConstraintSize;
57 FMinWidth: TConstraintSize;
58 procedure SetMaxHeight(AValue: TConstraintSize);
59 procedure SetMaxWidth(AValue: TConstraintSize);
60 procedure SetMinHeight(AValue: TConstraintSize);
61 procedure SetMinWidth(AValue: TConstraintSize);
62 published
63 property MaxHeight: TConstraintSize read FMaxHeight write SetMaxHeight default 0;
64 property MaxWidth: TConstraintSize read FMaxWidth write SetMaxWidth default 0;
65 property MinHeight: TConstraintSize read FMinHeight write SetMinHeight default 0;
66 property MinWidth: TConstraintSize read FMinWidth write SetMinWidth default 0;
67 end;
68
69 { TControl }
70
71 TControl = class(TComponent)
72 private
73 FBorderSpacing: TControlBorderSpacing;
74 FConstraints: TSizeConstraints;
75 FFont: TFont;
76 FHeight: Integer;
77 FLeft: Integer;
78 FOnChangeBounds: TNotifyEvent;
79 FOnMouseUp: TMouseEvent;
80 FOnMouseDown: TMouseEvent;
81 FOnMouseMove: TMouseMoveEvent;
82 FOnMouseEnter: TNotifyEvent;
83 FOnMouseLeave: TNotifyEvent;
84 FOnMouseWheel: TMouseWheelEvent;
85 FOnResize: TNotifyEvent;
86 FTop: Integer;
87 FWidth: Integer;
88 FParent: TWinControl;
89 function GetAlign: TAlign;
90 function GetAnchors: TAnchors;
91 function GetAutoSize: Boolean;
92 function GetBoundsRect: TRect;
93 function GetClientHeight: Integer;
94 function GetClientWidth: Integer;
95 function GetColor: TColor;
96 function GetCursor: TCursor;
97 function GetEnabled: Boolean;
98 function GetHint: string;
99 function GetOnClick: TNotifyEvent;
100 function GetOnDblClick: TNotifyEvent;
101 function GetParentColor: Boolean;
102 function GetParentFont: Boolean;
103 function GetShowHint: Boolean;
104 function GetVisible: Boolean;
105 function GetWindowProc: TWndMethod;
106 function IsAnchorsStored: Boolean;
107 procedure SetAlign(AValue: TAlign);
108 procedure SetAnchors(AValue: TAnchors);
109 procedure SetAutoSize(AValue: Boolean);
110 procedure SetBorderSpacing(AValue: TControlBorderSpacing);
111 procedure SetBoundsRect(AValue: TRect);
112 procedure SetClientHeight(AValue: Integer);
113 procedure SetClientWidth(AValue: Integer);
114 procedure SetColor(AValue: TColor);
115 procedure SetCursor(AValue: TCursor);
116 procedure SetEnabled(AValue: Boolean);
117 procedure SetFont(AValue: TFont);
118 procedure SetHint(AValue: string);
119 procedure SetOnClick(AValue: TNotifyEvent);
120 procedure SetOnDblClick(AValue: TNotifyEvent);
121 procedure SetParentColor(AValue: Boolean);
122 procedure SetParentFont(AValue: Boolean);
123 procedure SetShowHint(AValue: Boolean);
124 procedure NativeFormResize(Sender: TObject);
125 procedure NativeChangeBounds(Sender: TObject);
126 procedure DoFormResize;
127 procedure DoChangeBounds;
128 procedure MouseDownHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
129 X, Y: Integer); virtual;
130 procedure MouseUpHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
131 X, Y: Integer); virtual;
132 procedure MouseMoveHandler(Sender: TObject; Shift: TShiftState; X, Y: Integer); virtual;
133 procedure MouseWheelHandler(Sender: TObject; Shift: TShiftState;
134 WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); virtual;
135 procedure MouseLeaveHandler(Sender: TObject); virtual;
136 procedure MouseEnterHandler(Sender: TObject); virtual;
137 procedure SetWindowProc(AValue: TWndMethod);
138 function ColorIsStored: Boolean; virtual;
139 protected
140 procedure DoBorderSpacingChange(Sender: TObject; InnerSpaceChanged: Boolean); virtual;
141 function GetText: TCaption; virtual;
142 procedure SetText(AValue: TCaption); virtual;
143 procedure UpdateBounds; virtual;
144 procedure FontChanged(Sender: TObject); virtual;
145 function GetCaption: string; virtual;
146 procedure SetParent(AValue: TWinControl); virtual;
147 procedure SetCaption(AValue: string); virtual;
148 procedure SetHeight(AValue: Integer); virtual;
149 procedure SetLeft(AValue: Integer); virtual;
150 procedure SetTop(AValue: Integer); virtual;
151 procedure SetVisible(AValue: Boolean); virtual;
152 procedure SetWidth(AValue: Integer); virtual;
153 function GetNativeControl: Controls.TControl; virtual;
154 procedure UpdateNativeControl; virtual;
155 procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
156 X, Y: Integer); virtual;
157 procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
158 X, Y: Integer); virtual;
159 procedure MouseMove(Shift: TShiftState; X, Y: Integer); virtual;
160 procedure MouseLeave; virtual;
161 procedure MouseEnter; virtual;
162 property Text: TCaption read GetText write SetText;
163 property ParentFont: Boolean read GetParentFont write SetParentFont default True;
164 property ParentColor: Boolean read GetParentColor write SetParentColor default True;
165 public
166 function ScreenToClient(const APoint: TPoint): TPoint; virtual;
167 function ClientToScreen(const APoint: TPoint): TPoint; virtual;
168 procedure AddHandlerOnVisibleChanged(const OnVisibleChangedEvent: TNotifyEvent;
169 AsFirst: boolean = false);
170 procedure RemoveHandlerOnVisibleChanged(const OnVisibleChangedEvent: TNotifyEvent);
171 procedure ScreenChanged; virtual;
172 procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); virtual;
173 procedure Show;
174 procedure Hide;
175 procedure Invalidate;
176 procedure Repaint;
177 procedure Update;
178 procedure Refresh;
179 function IsParentOf(AControl: TControl): Boolean; virtual;
180 function Scale96ToScreen(const ASize: Integer): Integer;
181 constructor Create(TheOwner: TComponent); override;
182 destructor Destroy; override;
183 property Parent: TWinControl read FParent write SetParent;
184 property BoundsRect: TRect read GetBoundsRect write SetBoundsRect;
185 property Visible: Boolean read GetVisible write SetVisible;
186 property Anchors: TAnchors read GetAnchors write SetAnchors stored IsAnchorsStored default [akLeft, akTop];
187 property BorderSpacing: TControlBorderSpacing read FBorderSpacing write SetBorderSpacing;
188 property WindowProc: TWndMethod read GetWindowProc write SetWindowProc;
189 published
190 property AutoSize: Boolean read GetAutoSize write SetAutoSize default False;
191 property ClientHeight: Integer read GetClientHeight write SetClientHeight;
192 property ClientWidth: Integer read GetClientWidth write SetClientWidth;
193 property Hint: string read GetHint write SetHint;
194 property Top: Integer read FTop write SetTop;
195 property Left: Integer read FLeft write SetLeft;
196 property Width: Integer read FWidth write SetWidth;
197 property Height: Integer read FHeight write SetHeight;
198 property Caption: string read GetCaption write SetCaption;
199 property Enabled: Boolean read GetEnabled write SetEnabled;
200 property ShowHint: Boolean read GetShowHint write SetShowHint;
201 property Font: TFont read FFont write SetFont;
202 property Align: TAlign read GetAlign write SetAlign;
203 property Color: TColor read GetColor write SetColor stored ColorIsStored default {$ifdef UseCLDefault}clDefault{$else}clWindow{$endif};
204 property Constraints: TSizeConstraints read FConstraints write FConstraints;
205 property Cursor: TCursor read GetCursor write SetCursor default crDefault;
206 property OnResize: TNotifyEvent read FOnResize write FOnResize;
207 property OnChangeBounds: TNotifyEvent read FOnChangeBounds write FOnChangeBounds;
208 property OnClick: TNotifyEvent read GetOnClick write SetOnClick;
209 property OnDblClick: TNotifyEvent read GetOnDblClick write SetOnDblClick;
210 property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown;
211 property OnMouseMove: TMouseMoveEvent read FOnMouseMove write FOnMouseMove;
212 property OnMouseUp: TMouseEvent read FOnMouseUp write FOnMouseUp;
213 property OnMouseWheel: TMouseWheelEvent read FOnMouseWheel write FOnMouseWheel;
214 property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
215 property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
216 end;
217
218 TDpiControls = TObjectList<TControl>;
219
220 { TWinControl }
221
222 TWinControl = class(TControl)
223 private
224 FOnKeyDown: TKeyEvent;
225 function GetBorderStyle: TBorderStyle;
226 function GetHandle: HWND;
227 function GetOnKeyDown: TKeyEvent;
228 function GetOnKeyPress: TKeyPressEvent;
229 function GetOnKeyUp: TKeyEvent;
230 function GetTabOrder: TTabOrder;
231 function GetTabStop: Boolean;
232 procedure SetBorderStyle(AValue: TBorderStyle);
233 procedure SetHandle(AValue: HWND);
234 procedure SetOnKeyDown(AValue: TKeyEvent);
235 procedure SetOnKeyPress(AValue: TKeyPressEvent);
236 procedure SetOnKeyUp(AValue: TKeyEvent);
237 procedure SetTabOrder(AValue: TTabOrder);
238 procedure SetTabStop(AValue: Boolean);
239 procedure KeyDownHandler(Sender: TObject; var Key: Word; Shift: TShiftState);
240 protected
241 procedure UpdateNativeControl; override;
242 function GetNativeControl: Controls.TControl; override;
243 function GetNativeWinControl: Controls.TWinControl; virtual;
244 property BorderStyle: TBorderStyle read GetBorderStyle write SetBorderStyle default bsNone;
245 procedure KeyDown(var Key: Word; Shift: TShiftState); virtual;
246 public
247 Controls: TDpiControls;
248 function HandleAllocated: Boolean;
249 procedure ScreenChanged; override;
250 function ControlCount: Integer;
251 procedure SetFocus; virtual;
252 constructor Create(TheOwner: TComponent); override;
253 destructor Destroy; override;
254 property Handle: HWND read GetHandle write SetHandle;
255 published
256 property TabOrder: TTabOrder read GetTabOrder write SetTabOrder default -1;
257 property TabStop: Boolean read GetTabStop write SetTabStop default False;
258 property OnKeyDown: TKeyEvent read FOnKeyDown write FOnKeyDown;
259 property OnKeyPress: TKeyPressEvent read GetOnKeyPress write SetOnKeyPress;
260 property OnKeyUp: TKeyEvent read GetOnKeyUp write SetOnKeyUp;
261 end;
262
263 { TControlBorderSpacing }
264
265 TControlBorderSpacing = class(TPersistent)
266 private
267 FAround: TSpacingSize;
268 FBottom: TSpacingSize;
269 FLeft: TSpacingSize;
270 FOnChange: TNotifyEvent;
271 FRight: TSpacingSize;
272 FTop: TSpacingSize;
273 FControl: TControl;
274 FDefault: PControlBorderSpacingDefault;
275 function IsAroundStored: Boolean;
276 function IsBottomStored: Boolean;
277 function IsLeftStored: Boolean;
278 function IsRightStored: Boolean;
279 function IsTopStored: Boolean;
280 procedure SetAround(AValue: TSpacingSize);
281 procedure SetBottom(AValue: TSpacingSize);
282 procedure SetLeft(AValue: TSpacingSize);
283 procedure SetRight(AValue: TSpacingSize);
284 procedure SetTop(AValue: TSpacingSize);
285 procedure Change(InnerSpaceChanged: Boolean); virtual;
286 public
287 constructor Create(OwnerControl: TControl; ADefault: PControlBorderSpacingDefault = nil);
288 published
289 property OnChange: TNotifyEvent read FOnChange write FOnChange;
290 property Around: TSpacingSize read FAround write SetAround stored IsAroundStored;
291 property Left: TSpacingSize read FLeft write SetLeft stored IsLeftStored;
292 property Top: TSpacingSize read FTop write SetTop stored IsTopStored;
293 property Right: TSpacingSize read FRight write SetRight stored IsRightStored;
294 property Bottom: TSpacingSize read FBottom write SetBottom stored IsBottomStored;
295 end;
296
297 { TCustomControl }
298
299 TCustomControl = class(TWinControl)
300 private
301 FCanvas: TCanvas;
302 function GetCanvas: TCanvas;
303 function GetOnPaint: TNotifyEvent;
304 function GetPixelsPerInch: Integer;
305 procedure SetOnPaint(AValue: TNotifyEvent);
306 procedure SetPixelsPerInch(AValue: Integer);
307 protected
308 function GetNativeWinControl: Controls.TWinControl; override;
309 function GetNativeCustomControl: Controls.TCustomControl; virtual;
310 public
311 constructor Create(TheOwner: TComponent); override;
312 destructor Destroy; override;
313 property Canvas: TCanvas read GetCanvas;
314 published
315 property PixelsPerInch: Integer read GetPixelsPerInch write SetPixelsPerInch stored False;
316 property OnPaint: TNotifyEvent read GetOnPaint write SetOnPaint;
317 end;
318
319 { TGraphicControl }
320
321 TGraphicControl = class(TControl)
322 private
323 FOnPaint: TNotifyEvent;
324 NativeGraphicControl: Controls.TGraphicControl;
325 FCanvas: TCanvas;
326 function GetOnPaint: TNotifyEvent;
327 procedure SetCanvas(AValue: TCanvas);
328 procedure PaintHandler(Sender: TObject);
329 procedure SetOnPaint(AValue: TNotifyEvent);
330 protected
331 procedure Paint; virtual;
332 function GetNativeControl: Controls.TControl; override;
333 function GetNativeGraphicControl: Controls.TGraphicControl; virtual;
334 procedure UpdateNativeControl; override;
335 property OnPaint: TNotifyEvent read GetOnPaint write SetOnPaint;
336 public
337 constructor Create(TheOwner: TComponent); override;
338 destructor Destroy; override;
339 published
340 property Canvas: TCanvas read FCanvas write SetCanvas;
341 end;
342
343 { TMouse }
344
345 TMouse = class
346 private
347 function GetCursorPos: TPoint;
348 procedure SetCursorPos(AValue: TPoint);
349 public
350 constructor Create;
351 destructor Destroy; override;
352 property CursorPos: TPoint read GetCursorPos write SetCursorPos;
353 end;
354
355 { TImageList }
356
357 TImageList = class(TComponent)
358 private
359 NativeImageList: Controls.TImageList;
360 function GetCount: Integer;
361 function GetHeight: Integer;
362 function GetWidth: Integer;
363 procedure SetHeight(AValue: Integer);
364 procedure SetWidth(AValue: Integer);
365 public
366 function GetNativeImageList: Controls.TImageList;
367 procedure GetBitmap(Index: Integer; Image: TBitmap);
368 procedure BeginUpdate;
369 procedure EndUpdate;
370 procedure Clear;
371 function Add(Image, Mask: TBitmap): Integer;
372 constructor Create(TheOwner: TComponent); override;
373 destructor Destroy; override;
374 property Width: Integer read GetWidth write SetWidth default 16;
375 property Height: Integer read GetHeight write SetHeight default 16;
376 property Count: Integer read GetCount;
377 end;
378
379var
380 Mouse: TMouse;
381
382
383implementation
384
385uses
386 Dpi.Common;
387
388{ TCustomControl }
389
390function TCustomControl.GetOnPaint: TNotifyEvent;
391begin
392 Result := GetNativeCustomControl.OnPaint;
393end;
394
395function TCustomControl.GetPixelsPerInch: Integer;
396begin
397 //Result := GetNativeCustomControl.Pix;
398end;
399
400function TCustomControl.GetCanvas: TCanvas;
401begin
402 Result := FCanvas;
403end;
404
405procedure TCustomControl.SetOnPaint(AValue: TNotifyEvent);
406begin
407 GetNativeCustomControl.OnPaint := AValue;
408end;
409
410procedure TCustomControl.SetPixelsPerInch(AValue: Integer);
411begin
412end;
413
414function TCustomControl.GetNativeWinControl: Controls.TWinControl;
415begin
416 Result := GetNativeCustomControl;
417end;
418
419function TCustomControl.GetNativeCustomControl: Controls.TCustomControl;
420begin
421 Result := nil;
422end;
423
424constructor TCustomControl.Create(TheOwner: TComponent);
425begin
426 inherited;
427 FCanvas := TCanvas.Create;
428 FCanvas.NativeCanvas := GetNativeCustomControl.Canvas;
429end;
430
431destructor TCustomControl.Destroy;
432begin
433 FreeAndNil(FCanvas);
434 inherited;
435end;
436
437{ TWinControl }
438
439function TWinControl.GetBorderStyle: TBorderStyle;
440begin
441 {$objectChecks-}
442 Result := TWinControlEx(GetNativeWinControl).BorderStyle;
443 {$objectChecks+}
444end;
445
446function TWinControl.GetHandle: HWND;
447begin
448 Result := GetNativeWinControl.Handle;
449end;
450
451function TWinControl.GetOnKeyDown: TKeyEvent;
452begin
453 Result := GetNativeWinControl.OnKeyDown;
454end;
455
456function TWinControl.GetOnKeyPress: TKeyPressEvent;
457begin
458 Result := GetNativeWinControl.OnKeyPress;
459end;
460
461function TWinControl.GetOnKeyUp: TKeyEvent;
462begin
463 Result := GetNativeWinControl.OnKeyUp;
464end;
465
466function TWinControl.GetTabOrder: TTabOrder;
467begin
468 Result := GetNativeWinControl.TabOrder;
469end;
470
471function TWinControl.GetTabStop: Boolean;
472begin
473 Result := GetNativeWinControl.TabStop;
474end;
475
476procedure TWinControl.SetBorderStyle(AValue: TBorderStyle);
477begin
478 {$objectChecks-}
479 TWinControlEx(GetNativeWinControl).BorderStyle := AValue;
480 {$objectChecks+}
481end;
482
483procedure TWinControl.SetHandle(AValue: HWND);
484begin
485 GetNativeWinControl.Handle := AValue;
486end;
487
488procedure TWinControl.SetOnKeyDown(AValue: TKeyEvent);
489begin
490 GetNativeWinControl.OnKeyDown := AValue;
491end;
492
493procedure TWinControl.SetOnKeyPress(AValue: TKeyPressEvent);
494begin
495 GetNativeWinControl.OnKeyPress := AValue;
496end;
497
498procedure TWinControl.SetOnKeyUp(AValue: TKeyEvent);
499begin
500 GetNativeWinControl.OnKeyUp := AValue;
501end;
502
503procedure TWinControl.SetTabOrder(AValue: TTabOrder);
504begin
505 GetNativeWinControl.TabOrder := AValue;
506end;
507
508procedure TWinControl.SetTabStop(AValue: Boolean);
509begin
510 GetNativeWinControl.TabStop := AValue;
511end;
512
513procedure TWinControl.KeyDownHandler(Sender: TObject; var Key: Word;
514 Shift: TShiftState);
515begin
516 KeyDown(Key, Shift);
517 if Assigned(FOnKeyDown) then FOnKeyDown(Self, Key, Shift);
518end;
519
520procedure TWinControl.UpdateNativeControl;
521begin
522 inherited;
523 GetNativeWinControl.OnKeyDown := KeyDownHandler;
524end;
525
526function TWinControl.GetNativeControl: Controls.TControl;
527begin
528 Result := GetNativeWinControl;
529end;
530
531function TWinControl.GetNativeWinControl: Controls.TWinControl;
532begin
533 Result := nil;
534end;
535
536procedure TWinControl.KeyDown(var Key: Word; Shift: TShiftState);
537begin
538end;
539
540function TWinControl.HandleAllocated: Boolean;
541begin
542 Result := GetNativeWinControl.HandleAllocated;
543end;
544
545procedure TWinControl.ScreenChanged;
546var
547 I: Integer;
548begin
549 inherited;
550 for I := 0 to Controls.Count - 1 do
551 Controls[I].ScreenChanged;
552end;
553
554function TWinControl.ControlCount: Integer;
555begin
556 Result := Controls.Count;
557end;
558
559procedure TWinControl.SetFocus;
560begin
561 GetNativeWinControl.SetFocus;
562end;
563
564constructor TWinControl.Create(TheOwner: TComponent);
565begin
566 Controls := TDpiControls.Create;
567 Controls.OwnsObjects := False;
568 inherited;
569end;
570
571destructor TWinControl.Destroy;
572begin
573 FreeAndNil(Controls);
574 inherited;
575end;
576
577{ TControl }
578
579procedure TControl.SetTop(AValue: Integer);
580begin
581 if FTop = AValue then Exit;
582 FTop := AValue;
583 UpdateBounds;
584end;
585
586procedure TControl.SetVisible(AValue: Boolean);
587begin
588 GetNativeControl.Visible := AValue;
589end;
590
591procedure TControl.SetWidth(AValue: Integer);
592begin
593 if FWidth = AValue then Exit;
594 FWidth := AValue;
595 UpdateBounds;
596end;
597
598function TControl.GetNativeControl: Controls.TControl;
599begin
600 Result := nil;
601end;
602
603procedure TControl.UpdateNativeControl;
604begin
605 Font.NativeFont := GetNativeControl.Font;
606 GetNativeControl.OnResize := NativeFormResize;
607 GetNativeControl.OnChangeBounds := NativeChangeBounds;
608
609 {$objectChecks-}
610 TControlEx(GetNativeControl).OnMouseDown := MouseDownHandler;
611 TControlEx(GetNativeControl).OnMouseUp := MouseUpHandler;
612 TControlEx(GetNativeControl).OnMouseMove := MouseMoveHandler;
613 TControlEx(GetNativeControl).OnMouseEnter := MouseEnterHandler;
614 TControlEx(GetNativeControl).OnMouseLeave := MouseLeaveHandler;
615 TControlEx(GetNativeControl).OnMouseWheel := MouseWheelHandler;
616 {$objectChecks+}
617end;
618
619procedure TControl.MouseDownHandler(Sender: TObject; Button: TMouseButton;
620 Shift: TShiftState; X, Y: Integer);
621begin
622 MouseDown(Button, Shift, ScaleFromNative(X), ScaleFromNative(Y));
623 if Assigned(FOnMouseDown) then FOnMouseDown(Self, Button, Shift, ScaleFromNative(X), ScaleFromNative(Y));
624end;
625
626procedure TControl.MouseUpHandler(Sender: TObject; Button: TMouseButton;
627 Shift: TShiftState; X, Y: Integer);
628begin
629 MouseUp(Button, Shift, ScaleFromNative(X), ScaleFromNative(Y));
630 if Assigned(FOnMouseUp) then FOnMouseUp(Self, Button, Shift, ScaleFromNative(X), ScaleFromNative(Y));
631end;
632
633procedure TControl.MouseMoveHandler(Sender: TObject; Shift: TShiftState; X,
634 Y: Integer);
635begin
636 MouseMove(Shift, ScaleFromNative(X), ScaleFromNative(Y));
637 if Assigned(FOnMouseMove) then FOnMouseMove(Self, Shift, ScaleFromNative(X), ScaleFromNative(Y));
638end;
639
640procedure TControl.MouseWheelHandler(Sender: TObject; Shift: TShiftState;
641 WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
642begin
643 if Assigned(FOnMouseWheel) then FOnMouseWheel(Self, Shift, WheelDelta,
644 ScalePointFromNative(MousePos), Handled);
645end;
646
647procedure TControl.MouseLeaveHandler(Sender: TObject);
648begin
649 MouseLeave;
650 if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
651end;
652
653procedure TControl.MouseEnterHandler(Sender: TObject);
654begin
655 MouseEnter;
656 if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
657end;
658
659procedure TControl.SetWindowProc(AValue: TWndMethod);
660begin
661 GetNativeControl.WindowProc := AValue;
662end;
663
664function TControl.ColorIsStored: Boolean;
665begin
666 Result := not ParentColor;
667end;
668
669procedure TControl.DoBorderSpacingChange(Sender: TObject;
670 InnerSpaceChanged: Boolean);
671begin
672 GetNativeControl.BorderSpacing.Left := ScaleToNative(FBorderSpacing.Left);
673 GetNativeControl.BorderSpacing.Right := ScaleToNative(FBorderSpacing.Right);
674 GetNativeControl.BorderSpacing.Top := ScaleToNative(FBorderSpacing.Top);
675 GetNativeControl.BorderSpacing.Bottom := ScaleToNative(FBorderSpacing.Bottom);
676 GetNativeControl.BorderSpacing.Around := ScaleToNative(FBorderSpacing.Around);
677end;
678
679procedure TControl.SetText(AValue: TCaption);
680begin
681
682end;
683
684procedure TControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
685 Y: Integer);
686begin
687end;
688
689procedure TControl.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
690 Y: Integer);
691begin
692end;
693
694procedure TControl.MouseMove(Shift: TShiftState; X, Y: Integer);
695begin
696end;
697
698procedure TControl.MouseLeave;
699begin
700end;
701
702procedure TControl.MouseEnter;
703begin
704end;
705
706function TControl.ScreenToClient(const APoint: TPoint): TPoint;
707begin
708 Result := ScalePointFromNative(GetNativeControl.ScreenToClient(ScalePointToNative(APoint)));
709end;
710
711function TControl.ClientToScreen(const APoint: TPoint): TPoint;
712begin
713 Result := ScalePointFromNative(GetNativeControl.ClientToScreen(ScalePointToNative(APoint)));
714end;
715
716procedure TControl.AddHandlerOnVisibleChanged(
717 const OnVisibleChangedEvent: TNotifyEvent; AsFirst: boolean);
718begin
719 GetNativeControl.AddHandlerOnVisibleChanged(OnVisibleChangedEvent, AsFirst);
720end;
721
722procedure TControl.RemoveHandlerOnVisibleChanged(
723 const OnVisibleChangedEvent: TNotifyEvent);
724begin
725 GetNativeControl.RemoveHandlerOnVisibleChanged(OnVisibleChangedEvent);
726end;
727
728procedure TControl.ScreenChanged;
729begin
730 UpdateBounds;
731 Font.ScreenChanged;
732end;
733
734procedure TControl.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
735begin
736 FLeft := ALeft;
737 FTop := ATop;
738 FWidth := AWidth;
739 FHeight := AHeight;
740 UpdateBounds;
741end;
742
743procedure TControl.Show;
744begin
745 Visible := True;
746end;
747
748procedure TControl.Hide;
749begin
750 Visible := False;
751end;
752
753procedure TControl.Invalidate;
754begin
755 GetNativeControl.Invalidate;
756end;
757
758procedure TControl.Repaint;
759begin
760 GetNativeControl.Repaint;
761end;
762
763procedure TControl.Update;
764begin
765 GetNativeControl.Update;
766end;
767
768procedure TControl.Refresh;
769begin
770 GetNativeControl.Refresh;
771end;
772
773function TControl.IsParentOf(AControl: TControl): Boolean;
774begin
775 Result := False;
776 while Assigned(AControl) do
777 begin
778 AControl := AControl.Parent;
779 if Self = AControl then
780 Exit(True);
781 end;
782end;
783
784function TControl.Scale96ToScreen(const ASize: Integer): Integer;
785begin
786 Result := MulDiv(ASize, ScreenInfo.Dpi, 96);
787end;
788
789constructor TControl.Create(TheOwner: TComponent);
790begin
791 inherited;
792 FFont := TFont.Create;
793 FFont.OnChange := FontChanged;
794 FConstraints := TSizeConstraints.Create;
795 if Assigned(TheOwner) and (TheOwner is TWinControl) then
796 Parent := TWinControl(TheOwner);
797 FBorderSpacing := TControlBorderSpacing.Create(Self);
798 GetNativeControl;
799 UpdateNativeControl;
800 ScreenChanged;
801end;
802
803destructor TControl.Destroy;
804begin
805 FreeAndNil(FBorderSpacing);
806 FreeAndNil(FConstraints);
807 FreeAndNil(FFont);
808 inherited;
809end;
810
811procedure TControl.SetLeft(AValue: Integer);
812begin
813 if FLeft = AValue then Exit;
814 FLeft := AValue;
815 UpdateBounds;
816end;
817
818procedure TControl.SetCaption(AValue: string);
819begin
820 GetNativeControl.Caption := AValue;
821end;
822
823procedure TControl.SetParent(AValue: TWinControl);
824begin
825 if FParent = AValue then Exit;
826 if Assigned(FParent) then begin
827 FParent.Controls.Remove(Self);
828 if Assigned(FParent) and (FParent is TWinControl) then
829 GetNativeControl.Parent := nil;
830 end;
831 FParent := AValue;
832 if Assigned(FParent) then begin
833 FParent.Controls.Add(Self);
834 if Assigned(FParent) and (FParent is TWinControl) then
835 GetNativeControl.Parent := TWinControl(FParent).GetNativeWinControl;
836 end;
837end;
838
839procedure TControl.SetFont(AValue: TFont);
840begin
841 if FFont = AValue then Exit;
842 FFont := AValue;
843end;
844
845procedure TControl.SetHint(AValue: string);
846begin
847 GetNativeControl.Hint := AValue;
848end;
849
850function TControl.GetBoundsRect: TRect;
851begin
852 Result.Left := Left;
853 Result.Top := Top;
854 Result.Right := Left + Width;
855 Result.Bottom := Top + Height;
856end;
857
858function TControl.GetAlign: TAlign;
859begin
860 Result := GetNativeControl.Align;
861end;
862
863function TControl.GetAnchors: TAnchors;
864begin
865 Result := GetNativeControl.Anchors;
866end;
867
868function TControl.GetAutoSize: Boolean;
869begin
870 Result := GetNativeControl.AutoSize;
871end;
872
873function TControl.GetClientHeight: Integer;
874begin
875 Result := ScaleFromNative(GetNativeControl.ClientHeight);
876end;
877
878function TControl.GetClientWidth: Integer;
879begin
880 Result := ScaleFromNative(GetNativeControl.ClientWidth);
881end;
882
883function TControl.GetColor: TColor;
884begin
885 Result := GetNativeControl.Color;
886end;
887
888function TControl.GetCursor: TCursor;
889begin
890 Result := GetNativeControl.Cursor;
891end;
892
893function TControl.GetEnabled: Boolean;
894begin
895 Result := GetNativeControl.Enabled;
896end;
897
898function TControl.GetHint: string;
899begin
900 Result := GetNativeControl.Hint;
901end;
902
903function TControl.GetOnClick: TNotifyEvent;
904begin
905 Result := GetNativeControl.OnClick;
906end;
907
908function TControl.GetOnDblClick: TNotifyEvent;
909begin
910 {$objectChecks-}
911 Result := TControlEx(GetNativeControl).OnDblClick;
912 {$objectChecks+}
913end;
914
915function TControl.GetParentColor: Boolean;
916begin
917 {$objectChecks-}
918 Result := TControlEx(GetNativeControl).ParentColor;
919 {$objectChecks+}
920end;
921
922function TControl.GetParentFont: Boolean;
923begin
924 {$objectChecks-}
925 Result := TControlEx(GetNativeControl).ParentFont;
926 {$objectChecks+}
927end;
928
929function TControl.GetShowHint: Boolean;
930begin
931 Result := GetNativeControl.ShowHint;
932end;
933
934function TControl.GetText: TCaption;
935begin
936 Result := '';
937end;
938
939function TControl.GetVisible: Boolean;
940begin
941 Result := GetNativeControl.Visible;
942end;
943
944function TControl.GetWindowProc: TWndMethod;
945begin
946 Result := GetNativeControl.WindowProc;
947end;
948
949function TControl.IsAnchorsStored: Boolean;
950begin
951
952end;
953
954procedure TControl.SetAlign(AValue: TAlign);
955begin
956 GetNativeControl.Align := AValue;
957end;
958
959procedure TControl.SetAnchors(AValue: TAnchors);
960begin
961 GetNativeControl.Anchors := AValue;
962end;
963
964procedure TControl.SetAutoSize(AValue: Boolean);
965begin
966 GetNativeControl.AutoSize := AValue;
967end;
968
969procedure TControl.SetBorderSpacing(AValue: TControlBorderSpacing);
970begin
971 if FBorderSpacing = AValue then Exit;
972 FBorderSpacing := AValue;
973end;
974
975procedure TControl.SetBoundsRect(AValue: TRect);
976begin
977 SetBounds(AValue.Left, AValue.Top, AValue.Right - AValue.Left, AValue.Bottom - AValue.Top);
978end;
979
980procedure TControl.SetClientHeight(AValue: Integer);
981begin
982 GetNativeControl.ClientHeight := ScaleToNative(AValue);
983end;
984
985procedure TControl.SetClientWidth(AValue: Integer);
986begin
987 GetNativeControl.ClientWidth := ScaleToNative(AValue);
988end;
989
990procedure TControl.SetColor(AValue: TColor);
991begin
992 GetNativeControl.Color := AValue;
993end;
994
995procedure TControl.SetCursor(AValue: TCursor);
996begin
997 GetNativeControl.Cursor := AValue;
998end;
999
1000procedure TControl.SetEnabled(AValue: Boolean);
1001begin
1002 GetNativeControl.Enabled := AValue;
1003end;
1004
1005procedure TControl.SetOnClick(AValue: TNotifyEvent);
1006begin
1007 GetNativeControl.OnClick := AValue;
1008end;
1009
1010procedure TControl.SetOnDblClick(AValue: TNotifyEvent);
1011begin
1012 {$objectChecks-}
1013 TControlEx(GetNativeControl).OnDblClick := AValue;
1014 {$objectChecks+}
1015end;
1016
1017procedure TControl.SetParentColor(AValue: Boolean);
1018begin
1019 {$objectChecks-}
1020 TControlEx(GetNativeControl).ParentColor := AValue;
1021 {$objectChecks+}
1022end;
1023
1024procedure TControl.SetParentFont(AValue: Boolean);
1025begin
1026 {$objectChecks-}
1027 TControlEx(GetNativeControl).ParentFont := AValue;
1028 {$objectChecks+}
1029end;
1030
1031procedure TControl.SetShowHint(AValue: Boolean);
1032begin
1033 GetNativeControl.ShowHint := AValue;
1034end;
1035
1036procedure TControl.NativeFormResize(Sender: TObject);
1037var
1038 R: TRect;
1039begin
1040 R := ScaleRectFromNative(GetNativeControl.BoundsRect);
1041 FLeft := R.Left;
1042 FTop := R.Top;
1043 FWidth := R.Width;
1044 FHeight := R.Height;
1045 DoFormResize;
1046end;
1047
1048procedure TControl.NativeChangeBounds(Sender: TObject);
1049var
1050 NewBounds: TRect;
1051begin
1052 NewBounds := ScaleRectFromNative(GetNativeControl.BoundsRect);
1053 if NewBounds <> BoundsRect then begin
1054 FLeft := NewBounds.Left;
1055 FTop := NewBounds.Top;
1056 FWidth := NewBounds.Width;
1057 FHeight := NewBounds.Height;
1058 DoChangeBounds;
1059 end;
1060end;
1061
1062procedure TControl.DoFormResize;
1063begin
1064 if Assigned(FOnResize) then begin
1065 FOnResize(Self);
1066 end;
1067end;
1068
1069procedure TControl.DoChangeBounds;
1070begin
1071 if Assigned(FOnChangeBounds) then FOnChangeBounds(Self);
1072end;
1073
1074function TControl.GetCaption: string;
1075begin
1076 Result := GetNativeControl.Caption;
1077end;
1078
1079procedure TControl.FontChanged(Sender: TObject);
1080begin
1081 GetNativeControl.Font.Size := ScaleToNative(Font.Size);
1082end;
1083
1084procedure TControl.UpdateBounds;
1085begin
1086 GetNativeControl.BoundsRect := ScaleRectToNative(BoundsRect);
1087end;
1088
1089procedure TControl.SetHeight(AValue: Integer);
1090begin
1091 if FHeight = AValue then Exit;
1092 FHeight := AValue;
1093 UpdateBounds;
1094end;
1095
1096{ TControlBorderSpacing }
1097
1098function TControlBorderSpacing.IsBottomStored: Boolean;
1099begin
1100 if FDefault = nil
1101 then Result := FBottom <> 0
1102 else Result := FBottom <> FDefault^.Bottom;
1103end;
1104
1105function TControlBorderSpacing.IsAroundStored: Boolean;
1106begin
1107 if FDefault = nil
1108 then Result := FAround <> 0
1109 else Result := FAround <> FDefault^.Around;
1110end;
1111
1112function TControlBorderSpacing.IsLeftStored: Boolean;
1113begin
1114 if FDefault = nil
1115 then Result := FLeft <> 0
1116 else Result := FLeft <> FDefault^.Left;
1117end;
1118
1119function TControlBorderSpacing.IsRightStored: Boolean;
1120begin
1121 if FDefault = nil
1122 then Result := FRight <> 0
1123 else Result := FRight <> FDefault^.Right;
1124end;
1125
1126function TControlBorderSpacing.IsTopStored: Boolean;
1127begin
1128 if FDefault = nil
1129 then Result := FTop <> 0
1130 else Result := FTop <> FDefault^.Top;
1131end;
1132
1133procedure TControlBorderSpacing.SetAround(AValue: TSpacingSize);
1134begin
1135 if FAround = AValue then Exit;
1136 FAround := AValue;
1137 Change(False);
1138end;
1139
1140procedure TControlBorderSpacing.SetBottom(AValue: TSpacingSize);
1141begin
1142 if FBottom = AValue then Exit;
1143 FBottom := AValue;
1144 Change(False);
1145end;
1146
1147procedure TControlBorderSpacing.SetLeft(AValue: TSpacingSize);
1148begin
1149 if FLeft = AValue then Exit;
1150 FLeft := AValue;
1151 Change(False);
1152end;
1153
1154procedure TControlBorderSpacing.SetRight(AValue: TSpacingSize);
1155begin
1156 if FRight = AValue then Exit;
1157 FRight := AValue;
1158 Change(False);
1159end;
1160
1161procedure TControlBorderSpacing.SetTop(AValue: TSpacingSize);
1162begin
1163 if FTop = AValue then Exit;
1164 FTop := AValue;
1165 Change(False);
1166end;
1167
1168procedure TControlBorderSpacing.Change(InnerSpaceChanged: Boolean);
1169begin
1170 if FControl <> nil then
1171 FControl.DoBorderSpacingChange(Self, InnerSpaceChanged);
1172 if Assigned(OnChange) then OnChange(Self);
1173end;
1174
1175constructor TControlBorderSpacing.Create(OwnerControl: TControl;
1176 ADefault: PControlBorderSpacingDefault);
1177begin
1178 FControl := OwnerControl;
1179 FDefault := ADefault;
1180 if ADefault <> nil then
1181 begin
1182 FLeft := ADefault^.Left;
1183 FRight := ADefault^.Right;
1184 FTop := ADefault^.Top;
1185 FBottom := ADefault^.Bottom;
1186 FAround := ADefault^.Around;
1187 end;
1188 inherited Create;
1189end;
1190
1191{ TSizeConstraints }
1192
1193procedure TSizeConstraints.SetMaxHeight(AValue: TConstraintSize);
1194begin
1195 if FMaxHeight=AValue then Exit;
1196 FMaxHeight:=AValue;
1197end;
1198
1199procedure TSizeConstraints.SetMaxWidth(AValue: TConstraintSize);
1200begin
1201 if FMaxWidth=AValue then Exit;
1202 FMaxWidth:=AValue;
1203end;
1204
1205procedure TSizeConstraints.SetMinHeight(AValue: TConstraintSize);
1206begin
1207 if FMinHeight=AValue then Exit;
1208 FMinHeight:=AValue;
1209end;
1210
1211procedure TSizeConstraints.SetMinWidth(AValue: TConstraintSize);
1212begin
1213 if FMinWidth=AValue then Exit;
1214 FMinWidth:=AValue;
1215end;
1216
1217{ TGraphicControl }
1218
1219procedure TGraphicControl.SetCanvas(AValue: TCanvas);
1220begin
1221 if FCanvas = AValue then Exit;
1222 FCanvas := AValue;
1223end;
1224
1225procedure TGraphicControl.PaintHandler(Sender: TObject);
1226begin
1227 Paint;
1228 if Assigned(FOnPaint) then
1229 FOnPaint(Sender);
1230end;
1231
1232procedure TGraphicControl.Paint;
1233begin
1234end;
1235
1236function TGraphicControl.GetNativeControl: Controls.TControl;
1237begin
1238 Result := GetNativeGraphicControl;
1239end;
1240
1241function TGraphicControl.GetNativeGraphicControl: Controls.TGraphicControl;
1242begin
1243 Result := NativeGraphicControl;
1244end;
1245
1246procedure TGraphicControl.UpdateNativeControl;
1247begin
1248 inherited;
1249 {$objectChecks-}
1250 TGraphicControlEx(GetNativeGraphicControl).OnPaint := PaintHandler;
1251 {$objectChecks+}
1252end;
1253
1254function TGraphicControl.GetOnPaint: TNotifyEvent;
1255begin
1256 Result := FOnPaint;
1257end;
1258
1259procedure TGraphicControl.SetOnPaint(AValue: TNotifyEvent);
1260begin
1261 FOnPaint := AValue;
1262end;
1263
1264constructor TGraphicControl.Create(TheOwner: TComponent);
1265begin
1266 NativeGraphicControl := Controls.TGraphicControl.Create(nil);
1267 inherited;
1268 FCanvas := TCanvas.Create;
1269 FCanvas.NativeCanvas := GetNativeGraphicControl.Canvas;
1270end;
1271
1272destructor TGraphicControl.Destroy;
1273begin
1274 FreeAndNil(FCanvas);
1275 FreeAndNil(NativeGraphicControl);
1276 inherited;
1277end;
1278
1279{ TGraphicControlEx }
1280
1281procedure TGraphicControlEx.Paint;
1282begin
1283 inherited Paint;
1284end;
1285
1286{ TMouse }
1287
1288function TMouse.GetCursorPos: TPoint;
1289begin
1290 Result := ScalePointFromNative(Controls.Mouse.CursorPos);
1291end;
1292
1293procedure TMouse.SetCursorPos(AValue: TPoint);
1294begin
1295 Controls.Mouse.CursorPos := ScalePointToNative(AValue);
1296end;
1297
1298constructor TMouse.Create;
1299begin
1300end;
1301
1302destructor TMouse.Destroy;
1303begin
1304 inherited;
1305end;
1306
1307{ TImageList }
1308
1309function TImageList.GetHeight: Integer;
1310begin
1311
1312end;
1313
1314function TImageList.GetCount: Integer;
1315begin
1316
1317end;
1318
1319function TImageList.GetWidth: Integer;
1320begin
1321
1322end;
1323
1324procedure TImageList.SetHeight(AValue: Integer);
1325begin
1326
1327end;
1328
1329procedure TImageList.SetWidth(AValue: Integer);
1330begin
1331
1332end;
1333
1334function TImageList.GetNativeImageList: Controls.TImageList;
1335begin
1336 if not Assigned(NativeImageList) then
1337 NativeImageList := Controls.TImageList.Create(nil);
1338 Result := NativeImageList;
1339end;
1340
1341procedure TImageList.GetBitmap(Index: Integer; Image: TBitmap);
1342begin
1343
1344end;
1345
1346procedure TImageList.BeginUpdate;
1347begin
1348
1349end;
1350
1351procedure TImageList.EndUpdate;
1352begin
1353
1354end;
1355
1356procedure TImageList.Clear;
1357begin
1358
1359end;
1360
1361function TImageList.Add(Image, Mask: TBitmap): Integer;
1362begin
1363
1364end;
1365
1366constructor TImageList.Create(TheOwner: TComponent);
1367begin
1368 inherited Create(TheOwner);
1369end;
1370
1371destructor TImageList.Destroy;
1372begin
1373 FreeAndNil(NativeImageList);
1374 inherited;
1375end;
1376
1377initialization
1378
1379Mouse := TMouse.Create;
1380
1381finalization;
1382
1383FreeAndNil(Mouse);
1384
1385end.
1386
Note: See TracBrowser for help on using the repository browser.