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

Last change on this file was 629, checked in by chronos, 3 weeks ago
  • Fixed: Log and AI turnament windows were not shown correctly.
File size: 28.9 KB
Line 
1unit Dpi.Forms;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, LMessages, Controls, LCLType,
7 Generics.Collections, LCLProc, LResources, Graphics, Dpi.Controls,
8 Dpi.Graphics;
9
10const
11 crDefault = TCursor(0);
12
13type
14 TMessageEvent = procedure (var TheMessage : TLMessage) of object;
15 TCloseAction = Forms.TCloseAction;
16 TFormState = Forms.TFormState;
17 TFormStateType = Forms.TFormStateType;
18 TWindowState = Forms.TWindowState;
19 TScrollBarKind = Forms.TScrollBarKind;
20 TBorderIcon = Forms.TBorderIcon;
21 TShowInTaskbar = Forms.TShowInTaskbar;
22 TTaskBarBehavior = Forms.TTaskBarBehavior;
23
24 { TFormEx }
25
26 TFormEx = class(Forms.TForm)
27 private
28 FOnMessage: TMessageEvent;
29 protected
30 procedure WndProc(var TheMessage : TLMessage); override;
31 property OnMessage: TMessageEvent read FOnMessage write FOnMessage;
32 end;
33
34 { TControlScrollBar }
35
36 TControlScrollBar = class(TPersistent)
37 private
38 function GetVisible: Boolean;
39 procedure SetVisible(AValue: Boolean);
40 published
41 property Visible: Boolean read GetVisible write SetVisible;
42 end;
43
44 { TScrollingWinControl }
45
46 TScrollingWinControl = class(TCustomControl)
47 private
48 FHorzScrollBar: TControlScrollBar;
49 FVertScrollBar: TControlScrollBar;
50 protected
51 function GetNativeCustomControl: Controls.TCustomControl; override;
52 function GetNativeScrollingWinControl: Forms.TScrollingWinControl; virtual;
53 public
54 constructor Create(TheOwner: TComponent); override;
55 destructor Destroy; override;
56 published
57 property HorzScrollBar: TControlScrollBar read FHorzScrollBar write FHorzScrollBar;
58 property VertScrollBar: TControlScrollBar read FVertScrollBar write FVertScrollBar;
59 end;
60
61 { TForm }
62
63 TForm = class(TScrollingWinControl)
64 private
65 FOnActivate: TNotifyEvent;
66 FOnClose: TCloseEvent;
67 FOnCloseQuery: TCloseQueryEvent;
68 FOnDeactivate: TNotifyEvent;
69 function GetBorderIcons: TBorderIcons;
70 function GetBorderStyle: TFormBorderStyle;
71 function GetDesignTimePPI: Integer;
72 function GetFormState: TFormState;
73 function GetFormStyle: TFormStyle;
74 function GetKeyPreview: Boolean;
75 function GetLCLVersion: string;
76 function GetModalResult: TModalResult;
77 function GetOnCloseQuery: TCloseQueryEvent;
78 function GetOnCreate: TNotifyEvent;
79 function GetOnDeactivate: TNotifyEvent;
80 function GetOnDestroy: TNotifyEvent;
81 function GetOnHide: TNotifyEvent;
82 function GetOnShow: TNotifyEvent;
83 function GetPosition: TPosition;
84 function GetRestoredHeight: Integer;
85 function GetRestoredLeft: Integer;
86 function GetRestoredTop: Integer;
87 function GetRestoredWidth: Integer;
88 function GetScaled: Boolean;
89 function GetShowInTaskbar: TShowInTaskbar;
90 function GetWindowState: TWindowState;
91 procedure SetBorderIcons(AValue: TBorderIcons);
92 procedure SetBorderStyle(AValue: TFormBorderStyle);
93 procedure SetDesignTimePPI(AValue: Integer);
94 procedure SetFormStyle(AValue: TFormStyle);
95 procedure SetKeyPreview(AValue: Boolean);
96 procedure SetLCLVersion(AValue: string);
97 procedure SetModalResult(AValue: TModalResult);
98 procedure SetOnCloseQuery(AValue: TCloseQueryEvent);
99 procedure SetOnCreate(AValue: TNotifyEvent);
100 procedure SetOnDeactivate(AValue: TNotifyEvent);
101 procedure SetOnDestroy(AValue: TNotifyEvent);
102 procedure SetOnHide(AValue: TNotifyEvent);
103 procedure SetOnShow(AValue: TNotifyEvent);
104 procedure DoOnCreate;
105 procedure FormMessageHandler(var TheMessage: TLMessage);
106 procedure SetPosition(AValue: TPosition);
107 procedure SetScaled(AValue: Boolean);
108 procedure SetShowInTaskBar(AValue: TShowInTaskbar);
109 procedure SetWindowState(AValue: TWindowState);
110 procedure ActivateHandler(Sender: TObject);
111 procedure DeactivateHandler(Sender: TObject);
112 procedure DoClose(var CloseAction: TCloseAction); virtual;
113 procedure CloseHandler(Sender: TObject; var CloseAction: TCloseAction);
114 procedure CloseQueryHandler(Sender : TObject; var CanClose : boolean);
115 protected
116 procedure CreateParams(var p: TCreateParams); virtual;
117 procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
118 function GetNativeScrollingWinControl: Forms.TScrollingWinControl; override;
119 function GetNativeForm: Forms.TForm; virtual;
120 procedure UpdateNativeControl; override;
121 public
122 NativeForm: Forms.TForm;
123 procedure AfterConstruction; override;
124 property ModalResult: TModalResult read GetModalResult write SetModalResult;
125 function ShowModal: Integer; virtual;
126 procedure SetFocus; override;
127 procedure Close;
128 function CloseQuery: boolean; virtual;
129 procedure BringToFront;
130 procedure Release;
131 constructor Create(TheOwner: TComponent); override;
132 constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual;
133 destructor Destroy; override;
134 published
135 property RestoredLeft: integer read GetRestoredLeft;
136 property RestoredTop: integer read GetRestoredTop;
137 property RestoredWidth: integer read GetRestoredWidth;
138 property RestoredHeight: integer read GetRestoredHeight;
139 property DesignTimePPI: Integer read GetDesignTimePPI write SetDesignTimePPI; // Not used
140 property FormState: TFormState read GetFormState;
141 property FormStyle: TFormStyle read GetFormStyle write SetFormStyle;
142 property BorderStyle: TFormBorderStyle read GetBorderStyle write SetBorderStyle default bsSizeable;
143 property BorderIcons: TBorderIcons read GetBorderIcons write SetBorderIcons;
144 property LCLVersion: string read GetLCLVersion write SetLCLVersion;
145 property KeyPreview: Boolean read GetKeyPreview write SetKeyPreview default False;
146 property Position: TPosition read GetPosition write SetPosition default poDesigned;
147 property WindowState: TWindowState read GetWindowState write SetWindowState default wsNormal;
148 property OnShow: TNotifyEvent read GetOnShow write SetOnShow;
149 property OnHide: TNotifyEvent read GetOnHide write SetOnHide;
150 property OnCreate: TNotifyEvent read GetOnCreate write SetOnCreate;
151 property OnDestroy: TNotifyEvent read GetOnDestroy write SetOnDestroy;
152 property OnActivate: TNotifyEvent read FOnActivate write FOnActivate;
153 property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate;
154 property OnClose: TCloseEvent read FOnClose write FOnClose;
155 property OnCloseQuery: TCloseQueryEvent read FOnCloseQuery write FOnCloseQuery;
156 property ClientHeight;
157 property ClientWidth;
158 property OnMouseUp;
159 property OnMouseDown;
160 property OnMouseMove;
161 property ShowInTaskBar: TShowInTaskbar read GetShowInTaskbar write SetShowInTaskBar
162 default stDefault;
163 property Scaled: Boolean read GetScaled write SetScaled default True;
164 end;
165
166 TForms = TObjectList<TForm>;
167
168 { TApplication }
169
170 TApplication = class(TComponent)
171 private
172 FMainForm: TForm;
173 FCreatingForm: TForm;
174 function GetActive: Boolean;
175 function GetExeName: string;
176 function GetShowMainForm: Boolean;
177 function GetTaskBarBehavior: TTaskBarBehavior;
178 function GetTitle: string;
179 procedure SetMainForm(AValue: TForm);
180 function GetMainForm: TForm;
181 procedure SetShowMainForm(AValue: Boolean);
182 procedure SetTaskBarBehavior(AValue: TTaskBarBehavior);
183 procedure SetTitle(AValue: string);
184 protected
185 function GetNativeApplication: Forms.TApplication; virtual;
186 procedure DoBeforeFinalization;
187 public
188 constructor Create(AOwner: TComponent); override;
189 destructor Destroy; override;
190 procedure Run;
191 procedure Initialize;
192 procedure Terminate;
193 procedure ProcessMessages;
194 procedure UpdateMainForm(AForm: TForm);
195 procedure CreateForm(InstanceClass: TComponentClass; out Reference);
196 procedure RemoveStayOnTop(const ASystemTopAlso: Boolean = False);
197 procedure RestoreStayOnTop(const ASystemTopAlso: Boolean = False);
198 function MessageBox(Text, Caption: PChar; Flags: Longint = MB_OK): Integer;
199 property MainForm: TForm read GetMainForm write SetMainForm;
200 property ShowMainForm: Boolean read GetShowMainForm write SetShowMainForm default True;
201 property Title: string read GetTitle write SetTitle;
202 property Active: Boolean read GetActive;
203 property ExeName: string read GetExeName;
204 property TaskBarBehavior: TTaskBarBehavior read GetTaskBarBehavior write SetTaskBarBehavior;
205 end;
206
207 { TMonitor }
208
209 TMonitor = class
210 private
211 function GetLeft: Integer;
212 function GetHeight: Integer;
213 function GetTop: Integer;
214 function GetWidth: Integer;
215 function GetBoundsRect: TRect;
216 public
217 NativeMonitor: Forms.TMonitor;
218 property Left: Integer read GetLeft;
219 property Height: Integer read GetHeight;
220 property Top: Integer read GetTop;
221 property Width: Integer read GetWidth;
222 property BoundsRect: TRect read GetBoundsRect;
223 end;
224
225 { TScreen }
226
227 TScreen = class
228 private
229 FDpi: Integer;
230 FActiveForm: TForm;
231 FPrevActiveForms: TForms;
232 FPrimaryMonitor: TMonitor;
233 FForms: TForms;
234 procedure AddForm(AForm: TForm);
235 function GetDesktopHeight: Integer;
236 function GetDesktopLeft: Integer;
237 function GetDesktopTop: Integer;
238 function GetDesktopWidth: Integer;
239 function GetPrimaryMonitor: TMonitor;
240 procedure RemoveForm(AForm: TForm);
241 function GetActiveForm: TForm;
242 function GetCursor: TCursor;
243 function GetCursors(Index: Integer): HCURSOR;
244 function GetFormCount: Integer;
245 function GetForms(Index: Integer): TForm;
246 function GetHeight: Integer;
247 function GetWidth: Integer;
248 procedure SetCursor(AValue: TCursor);
249 procedure SetCursors(Index: Integer; AValue: HCURSOR);
250 procedure SetDpi(AValue: Integer);
251 procedure UpdateForms;
252 public
253 constructor Create;
254 destructor Destroy; override;
255 procedure UpdateActiveFormFromNativeScreen;
256 function DisableForms(SkipForm: TForm; DisabledList: Classes.TList = nil): Classes.TList;
257 procedure EnableForms(var AFormList: Classes.TList);
258 function GetSystemDpi: Integer;
259 property FormCount: Integer read GetFormCount;
260 property Forms[Index: Integer]: TForm read GetForms;
261 property ActiveForm: TForm read GetActiveForm;
262 property Cursor: TCursor read GetCursor write SetCursor;
263 property Cursors[Index: Integer]: HCURSOR read GetCursors write SetCursors;
264 published
265 property Dpi: Integer read FDpi write SetDpi;
266 property PixelsPerInch: Integer read FDpi;
267 property Width: Integer read GetWidth;
268 property Height: Integer read GetHeight;
269 property DesktopLeft: Integer read GetDesktopLeft;
270 property DesktopTop: Integer read GetDesktopTop;
271 property DesktopWidth: Integer read GetDesktopWidth;
272 property DesktopHeight: Integer read GetDesktopHeight;
273 property PrimaryMonitor: TMonitor read GetPrimaryMonitor;
274 end;
275
276var
277 Application: TApplication;
278 Screen: TScreen;
279
280
281implementation
282
283uses
284 Dpi.Common;
285
286var
287 LCLScreen: Forms.TScreen absolute Forms.Screen;
288
289{ TFormEx }
290
291procedure TFormEx.WndProc(var TheMessage: TLMessage);
292begin
293 inherited WndProc(TheMessage);
294 if Assigned(FOnMessage) then
295 FOnMessage(TheMessage);
296end;
297
298{ TScrollingWinControl }
299
300function TScrollingWinControl.GetNativeCustomControl: Controls.TCustomControl;
301begin
302 Result := GetNativeScrollingWinControl;
303end;
304
305function TScrollingWinControl.GetNativeScrollingWinControl: Forms.TScrollingWinControl;
306begin
307 Result := nil;
308end;
309
310constructor TScrollingWinControl.Create(TheOwner: TComponent);
311begin
312 inherited;
313 FHorzScrollBar := TControlScrollBar.Create;
314 FVertScrollBar := TControlScrollBar.Create;
315end;
316
317destructor TScrollingWinControl.Destroy;
318begin
319 FreeAndNil(FHorzScrollBar);
320 FreeAndNil(FVertScrollBar);
321 inherited;
322end;
323
324{ TApplication }
325
326procedure TApplication.SetMainForm(AValue: TForm);
327begin
328 FMainForm := AValue;
329end;
330
331function TApplication.GetTitle: string;
332begin
333 Result := GetNativeApplication.Title;
334end;
335
336function TApplication.GetShowMainForm: Boolean;
337begin
338 Result := GetNativeApplication.ShowMainForm;
339end;
340
341function TApplication.GetTaskBarBehavior: TTaskBarBehavior;
342begin
343 Result := GetNativeApplication.TaskBarBehavior;
344end;
345
346function TApplication.GetActive: Boolean;
347begin
348 Result := GetNativeApplication.Active;
349end;
350
351function TApplication.GetExeName: string;
352begin
353 Result := GetNativeApplication.ExeName;
354end;
355
356function TApplication.GetMainForm: TForm;
357begin
358 Result := FMainForm;
359end;
360
361procedure TApplication.SetShowMainForm(AValue: Boolean);
362begin
363 GetNativeApplication.ShowMainForm := AValue;
364end;
365
366procedure TApplication.SetTaskBarBehavior(AValue: TTaskBarBehavior);
367begin
368 GetNativeApplication.TaskBarBehavior := AValue;
369end;
370
371procedure TApplication.SetTitle(AValue: string);
372begin
373 GetNativeApplication.Title := AValue;
374end;
375
376function TApplication.GetNativeApplication: Forms.TApplication;
377begin
378 Result := Forms.Application;
379end;
380
381procedure DpiBeforeFinalization;
382// This is our ExitProc handler.
383begin
384 Application.DoBeforeFinalization;
385end;
386
387procedure TApplication.DoBeforeFinalization;
388var
389 I: Integer;
390begin
391 if Self = nil then Exit;
392 for I := ComponentCount - 1 downto 0 do begin
393 if I < ComponentCount then
394 Components[I].Free;
395 end;
396end;
397
398function DpiFindApplicationComponent(const ComponentName: string): TComponent;
399// Note: this function is used by TReader to auto rename forms to unique names.
400begin
401 Result := Application.FindComponent(ComponentName);
402end;
403
404constructor TApplication.Create(AOwner: TComponent);
405begin
406 RegisterFindGlobalComponentProc(@DpiFindApplicationComponent);
407 AddExitProc(@DpiBeforeFinalization);
408 inherited;
409end;
410
411destructor TApplication.Destroy;
412begin
413 UnregisterFindGlobalComponentProc(@DpiFindApplicationComponent);
414 inherited;
415end;
416
417procedure TApplication.Run;
418begin
419 if (FMainForm <> nil) and GetShowMainForm then FMainForm.Show;
420 GetNativeApplication.Run;
421end;
422
423procedure TApplication.Initialize;
424begin
425 GetNativeApplication.Initialize;
426end;
427
428procedure TApplication.Terminate;
429begin
430 GetNativeApplication.Terminate;
431end;
432
433procedure TApplication.ProcessMessages;
434begin
435 GetNativeApplication.ProcessMessages;
436end;
437
438procedure TApplication.UpdateMainForm(AForm: TForm);
439begin
440 if (FMainForm = nil)
441 and (FCreatingForm = AForm)
442 //and (not (AppDestroying in FFlags))
443 and not (AForm.FormStyle in [fsMDIChild, fsSplash])
444 then
445 FMainForm := AForm;
446 GetNativeApplication.UpdateMainForm(AForm.GetNativeForm);
447end;
448
449procedure TApplication.CreateForm(InstanceClass: TComponentClass; out
450 Reference);
451var
452 Instance: TComponent;
453 Ok: Boolean;
454 AForm: TForm;
455begin
456 // Allocate the instance, without calling the constructor
457 Instance := TComponent(InstanceClass.NewInstance);
458 // set the Reference before the constructor is called, so that
459 // events and constructors can refer to it
460 TComponent(Reference) := Instance;
461
462 Ok := False;
463 try
464 if (FCreatingForm = nil) and (Instance is TForm) then
465 FCreatingForm := TForm(Instance);
466 Instance.Create(Self);
467 Ok := True;
468 finally
469 if not Ok then begin
470 TComponent(Reference) := nil;
471 if FCreatingForm = Instance then
472 FCreatingForm := nil;
473 end;
474 end;
475
476 if (Instance is TForm) then begin
477 AForm := TForm(Instance);
478 UpdateMainForm(AForm);
479 if FMainForm = AForm then AForm.GetNativeForm.HandleNeeded;
480 if AForm.FormStyle = fsSplash then begin
481 // show the splash form and handle the paint message
482 AForm.Show;
483 AForm.Invalidate;
484 ProcessMessages;
485 end;
486 end;
487end;
488
489procedure TApplication.RemoveStayOnTop(const ASystemTopAlso: Boolean);
490begin
491 GetNativeApplication.RemoveStayOnTop(ASystemTopAlso);
492end;
493
494procedure TApplication.RestoreStayOnTop(const ASystemTopAlso: Boolean);
495begin
496 GetNativeApplication.RestoreStayOnTop(ASystemTopAlso);
497end;
498
499function TApplication.MessageBox(Text, Caption: PChar; Flags: Longint
500 ): Integer;
501begin
502 Result := Application.MessageBox(Text, Caption, Flags);
503end;
504
505{ TMonitor }
506
507function TMonitor.GetLeft: Integer;
508begin
509 Result := ScaleFromNative(NativeMonitor.Left);
510end;
511
512function TMonitor.GetHeight: Integer;
513begin
514 Result := ScaleFromNative(NativeMonitor.Height);
515end;
516
517function TMonitor.GetTop: Integer;
518begin
519 Result := ScaleFromNative(NativeMonitor.Top);
520end;
521
522function TMonitor.GetWidth: Integer;
523begin
524 Result := ScaleFromNative(NativeMonitor.Width);
525end;
526
527function TMonitor.GetBoundsRect: TRect;
528begin
529 Result := ScaleRectFromNative(NativeMonitor.BoundsRect);
530end;
531
532{ TForm }
533
534function TForm.GetBorderIcons: TBorderIcons;
535begin
536 Result := GetNativeForm.BorderIcons;
537end;
538
539function TForm.GetBorderStyle: TFormBorderStyle;
540begin
541 Result := GetNativeForm.BorderStyle;
542end;
543
544function TForm.GetDesignTimePPI: Integer;
545begin
546 Result := GetNativeForm.DesignTimePPI;
547end;
548
549function TForm.GetFormState: TFormState;
550begin
551 Result := GetNativeForm.FormState;
552end;
553
554function TForm.GetFormStyle: TFormStyle;
555begin
556 Result := GetNativeForm.FormStyle;
557end;
558
559function TForm.GetKeyPreview: Boolean;
560begin
561 Result := GetNativeForm.KeyPreview;
562end;
563
564function TForm.GetLCLVersion: string;
565begin
566 Result := GetNativeForm.LCLVersion;
567end;
568
569function TForm.GetModalResult: TModalResult;
570begin
571 Result := GetNativeForm.ModalResult;
572end;
573
574function TForm.GetOnCloseQuery: TCloseQueryEvent;
575begin
576 Result := GetNativeForm.OnCloseQuery;
577end;
578
579function TForm.GetOnCreate: TNotifyEvent;
580begin
581 Result := GetNativeForm.OnCreate;
582end;
583
584function TForm.GetOnDeactivate: TNotifyEvent;
585begin
586 Result := GetNativeForm.OnDeactivate;
587end;
588
589function TForm.GetOnDestroy: TNotifyEvent;
590begin
591 Result := GetNativeForm.OnDestroy;
592end;
593
594function TForm.GetOnHide: TNotifyEvent;
595begin
596 Result := GetNativeForm.OnHide;
597end;
598
599function TForm.GetOnShow: TNotifyEvent;
600begin
601 Result := GetNativeForm.OnShow;
602end;
603
604function TForm.GetPosition: TPosition;
605begin
606 Result := GetNativeForm.Position;
607end;
608
609function TForm.GetRestoredHeight: Integer;
610begin
611 Result := ScaleFromNative(GetNativeForm.RestoredHeight);
612end;
613
614function TForm.GetRestoredLeft: Integer;
615begin
616 Result := ScaleFromNative(GetNativeForm.RestoredLeft);
617end;
618
619function TForm.GetRestoredTop: Integer;
620begin
621 Result := ScaleFromNative(GetNativeForm.RestoredTop);
622end;
623
624function TForm.GetRestoredWidth: Integer;
625begin
626 Result := ScaleFromNative(GetNativeForm.RestoredWidth);
627end;
628
629function TForm.GetScaled: Boolean;
630begin
631 Result := GetNativeForm.Scaled;
632end;
633
634function TForm.GetShowInTaskbar: TShowInTaskbar;
635begin
636 Result := GetNativeForm.ShowInTaskBar;
637end;
638
639function TForm.GetWindowState: TWindowState;
640begin
641 Result := GetNativeForm.WindowState;
642end;
643
644procedure TForm.SetBorderIcons(AValue: TBorderIcons);
645begin
646 GetNativeForm.BorderIcons := AValue;
647end;
648
649procedure TForm.SetBorderStyle(AValue: TFormBorderStyle);
650begin
651 GetNativeForm.BorderStyle := AValue;
652end;
653
654procedure TForm.SetDesignTimePPI(AValue: Integer);
655begin
656 GetNativeForm.DesignTimePPI := AValue;
657end;
658
659procedure TForm.SetFormStyle(AValue: TFormStyle);
660begin
661 GetNativeForm.FormStyle := AValue;
662end;
663
664procedure TForm.SetKeyPreview(AValue: Boolean);
665begin
666 GetNativeForm.KeyPreview := AValue;
667end;
668
669procedure TForm.SetLCLVersion(AValue: string);
670begin
671 GetNativeForm.LCLVersion := AValue;
672end;
673
674procedure TForm.SetModalResult(AValue: TModalResult);
675begin
676 GetNativeForm.ModalResult := AValue;
677end;
678
679procedure TForm.SetOnCloseQuery(AValue: TCloseQueryEvent);
680begin
681 GetNativeForm.OnCloseQuery := AValue;
682end;
683
684procedure TForm.SetOnCreate(AValue: TNotifyEvent);
685begin
686 GetNativeForm.OnCreate := AValue;
687end;
688
689procedure TForm.SetOnDeactivate(AValue: TNotifyEvent);
690begin
691 GetNativeForm.OnDeactivate := AValue;
692end;
693
694procedure TForm.SetOnDestroy(AValue: TNotifyEvent);
695begin
696 GetNativeForm.OnDestroy := AValue;
697end;
698
699procedure TForm.SetOnHide(AValue: TNotifyEvent);
700begin
701 GetNativeForm.OnHide := AValue;
702end;
703
704procedure TForm.SetOnShow(AValue: TNotifyEvent);
705begin
706 GetNativeForm.OnShow := AValue;
707end;
708
709procedure TForm.DoOnCreate;
710begin
711 if Assigned(GetNativeForm.OnCreate) then
712 GetNativeForm.OnCreate(Self);
713end;
714
715procedure TForm.FormMessageHandler(var TheMessage: TLMessage);
716begin
717 Dispatch(TheMessage);
718end;
719
720procedure TForm.SetPosition(AValue: TPosition);
721begin
722 GetNativeForm.Position := AValue;
723end;
724
725procedure TForm.SetScaled(AValue: Boolean);
726begin
727 GetNativeForm.Scaled := AValue;
728end;
729
730procedure TForm.SetShowInTaskBar(AValue: TShowInTaskbar);
731begin
732 GetNativeForm.ShowInTaskBar := AValue;
733end;
734
735procedure TForm.SetWindowState(AValue: TWindowState);
736begin
737 GetNativeForm.WindowState := AValue;
738end;
739
740procedure TForm.ActivateHandler(Sender: TObject);
741begin
742 if Assigned(Screen.FActiveForm) then begin
743 if Screen.FPrevActiveForms.IndexOf(Screen.FActiveForm) <> - 1 then
744 Screen.FPrevActiveForms.Remove(Screen.FActiveForm);
745 Screen.FPrevActiveForms.Add(Screen.FActiveForm);
746 end;
747 Screen.FActiveForm := Self;
748 if Assigned(FOnActivate) then FOnActivate(Sender);
749end;
750
751procedure TForm.DeactivateHandler(Sender: TObject);
752begin
753 if Screen.FPrevActiveForms.Count > 0 then begin
754 Screen.FActiveForm := Screen.FPrevActiveForms.Last;
755 Screen.FPrevActiveForms.Delete(Screen.FPrevActiveForms.Count - 1);
756 end else Screen.FActiveForm := nil;
757 //Screen.UpdateActiveFormFromNativeScreen;
758 if Assigned(FOnDeactivate) then FOnDeactivate(Sender);
759end;
760
761procedure TForm.DoClose(var CloseAction: TCloseAction);
762begin
763 if Assigned(FOnClose) then FOnClose(Self, CloseAction);
764end;
765
766procedure TForm.CloseHandler(Sender: TObject; var CloseAction: TCloseAction);
767begin
768 Close;
769end;
770
771procedure TForm.CloseQueryHandler(Sender : TObject; var CanClose : boolean);
772begin
773 if Assigned(FOnCloseQuery) then FOnCloseQuery(Self, CanClose);
774end;
775
776procedure TForm.CreateParams(var p: TCreateParams);
777begin
778 // TODO: NativeForm.CreateParams(P);
779end;
780
781// This method is called by TWriter to retrieve the child components to write
782procedure TForm.GetChildren(Proc: TGetChildProc; Root: TComponent);
783var
784 I: Integer;
785 OwnedComponent: TComponent;
786begin
787 DebugLn(['TDpiForm.GetChildren ComponentCount=', ComponentCount]);
788 inherited GetChildren(Proc, Root);
789 if Root = Self then begin
790 for I := 0 to ComponentCount - 1 do begin
791 OwnedComponent := Components[I];
792 if not OwnedComponent.HasParent then Proc(OwnedComponent);
793 end;
794 end;
795end;
796
797function TForm.GetNativeScrollingWinControl: Forms.TScrollingWinControl;
798begin
799 Result := GetNativeForm;
800end;
801
802function TForm.GetNativeForm: Forms.TForm;
803begin
804 if not Assigned(NativeForm) then begin
805 NativeForm := TFormEx.CreateNew(nil);
806 (NativeForm as TFormEx).OnMessage := FormMessageHandler;
807 //NativeForm := Forms.TForm.Create(nil);
808 end;
809 Result := NativeForm;
810end;
811
812procedure TForm.UpdateNativeControl;
813begin
814 inherited;
815 GetNativeForm.OnActivate := ActivateHandler;
816 GetNativeForm.OnDeactivate := DeactivateHandler;
817 GetNativeForm.OnClose := CloseHandler;
818 GetNativeForm.OnCloseQuery := CloseQueryHandler;
819 GetNativeForm.Name := Name + 'Native';
820end;
821
822procedure TForm.AfterConstruction;
823begin
824 inherited;
825 DoOnCreate;
826end;
827
828function TForm.ShowModal: Integer;
829begin
830 Result := GetNativeForm.ShowModal;
831end;
832
833procedure TForm.SetFocus;
834begin
835 GetNativeForm.SetFocus;
836end;
837
838procedure TForm.Close;
839var
840 CloseAction: TCloseAction;
841 IsMainForm: Boolean;
842begin
843 if (fsModal in FormState) and (ModalResult = 0) then
844 ModalResult := mrCancel
845 else
846 begin
847 if CloseQuery then
848 begin
849 // IsMainForm flag set if we are closing MainForm or its parent
850 IsMainForm := (Application.MainForm = Self) or (Self.IsParentOf(Application.MainForm));
851 // Prepare default close action
852 if FormStyle = fsMDIChild then
853 begin
854 CloseAction := caNone;
855 // TODO: mdi logic
856 end
857 else
858 begin
859 if IsMainForm then
860 CloseAction := caFree
861 else
862 CloseAction := caHide;
863 end;
864 // call event handler and let user modify CloseAction
865 DoClose(CloseAction);
866 // execute action according to close action
867 case CloseAction of
868 caHide: Hide;
869 caMinimize: WindowState := wsMinimized;
870 caFree:
871 begin
872 // if form is MainForm, then terminate the application
873 // the owner of the MainForm is the application,
874 // so the Application will take care of free-ing the form
875 // and Release is not necessary
876 if IsMainForm then
877 Application.Terminate
878 else
879 Release;
880 end;
881 end;
882 end;
883 end;
884end;
885
886function TForm.CloseQuery: boolean;
887begin
888 Result := True;
889 if Assigned(FOnCloseQuery) then
890 FOnCloseQuery(Self, Result);
891end;
892
893procedure TForm.BringToFront;
894begin
895 GetNativeForm.BringToFront;
896end;
897
898procedure TForm.Release;
899begin
900 Free;
901end;
902
903// Init the component with an IDE resource
904constructor TForm.Create(TheOwner: TComponent);
905begin
906 //inherited;
907 //DebugLn(['TDpiForm.Create ', DbgSName(TheOwner)]);
908 GlobalNameSpace.BeginWrite;
909 try
910 CreateNew(TheOwner, 1); // this calls BeginFormUpdate, which is ended in AfterConstruction
911 if (ClassType <> TForm) and not (csDesigning in ComponentState) then begin
912 if not InitResourceComponent(Self, TDataModule) then begin
913 raise EResNotFound.Create('Resource missing for class ' + ClassName);
914 end;
915 end;
916 finally
917 GlobalNameSpace.EndWrite;
918 end;
919 ScreenChanged;
920 UpdateNativeControl;
921end;
922
923constructor TForm.CreateNew(AOwner: TComponent; Num: Integer);
924begin
925 inherited Create(AOwner);
926 Screen.AddForm(Self);
927end;
928
929destructor TForm.Destroy;
930begin
931 // TODO: Can't destroy directly?
932 TFormEx(NativeForm).OnMessage := nil;
933 FreeAndNil(NativeForm);
934
935 Screen.RemoveForm(Self);
936 inherited;
937end;
938
939{ TScreen }
940
941procedure TScreen.SetDpi(AValue: Integer);
942begin
943 if FDpi = AValue then Exit;
944 FDpi := AValue;
945 ScreenInfo.Dpi := Dpi;
946 UpdateForms;
947end;
948
949function TScreen.GetWidth: Integer;
950begin
951 Result := ScaleFromNative(LCLScreen.Width);
952end;
953
954procedure TScreen.SetCursor(AValue: TCursor);
955begin
956 LCLScreen.Cursor := AValue;
957end;
958
959procedure TScreen.SetCursors(Index: Integer; AValue: HCURSOR);
960begin
961 LCLScreen.Cursors[Index] := AValue;
962end;
963
964function TScreen.GetHeight: Integer;
965begin
966 Result := ScaleFromNative(LCLScreen.Height);
967end;
968
969function TScreen.GetFormCount: Integer;
970begin
971 Result := FForms.Count;
972end;
973
974function TScreen.GetForms(Index: Integer): TForm;
975begin
976 Result := FForms[Index];
977end;
978
979procedure TScreen.AddForm(AForm: TForm);
980begin
981 if AForm is TForm then begin
982 FForms.Add(AForm);
983 //Application.UpdateVisible;
984 end;
985end;
986
987function TScreen.GetDesktopHeight: Integer;
988begin
989 Result := ScaleFromNative(LCLScreen.DesktopHeight);
990end;
991
992function TScreen.GetDesktopLeft: Integer;
993begin
994 Result := ScaleFromNative(LCLScreen.DesktopLeft);
995end;
996
997function TScreen.GetDesktopTop: Integer;
998begin
999 Result := ScaleFromNative(LCLScreen.DesktopTop);
1000end;
1001
1002function TScreen.GetDesktopWidth: Integer;
1003begin
1004 Result := ScaleFromNative(LCLScreen.DesktopWidth);
1005end;
1006
1007function TScreen.GetPrimaryMonitor: TMonitor;
1008begin
1009 if not Assigned(FPrimaryMonitor) then begin
1010 FPrimaryMonitor := TMonitor.Create;
1011 FPrimaryMonitor.NativeMonitor := LCLScreen.PrimaryMonitor;
1012 end;
1013 Result := FPrimaryMonitor;
1014end;
1015
1016procedure TScreen.RemoveForm(AForm: TForm);
1017begin
1018 FForms.Remove(AForm);
1019 FPrevActiveForms.Remove(AForm);
1020 if AForm = FActiveForm then begin
1021 FActiveForm := nil;
1022 end;
1023end;
1024
1025function TScreen.GetActiveForm: TForm;
1026begin
1027 Result := FActiveForm;
1028end;
1029
1030function TScreen.GetCursor: TCursor;
1031begin
1032 Result := LCLScreen.Cursor;
1033end;
1034
1035function TScreen.GetCursors(Index: Integer): HCURSOR;
1036begin
1037 Result := LCLScreen.Cursors[Index];
1038end;
1039
1040procedure TScreen.UpdateForms;
1041var
1042 I: Integer;
1043begin
1044 for I := 0 to FForms.Count - 1 do
1045 FForms[I].ScreenChanged;
1046end;
1047
1048function TScreen.DisableForms(SkipForm: TForm; DisabledList: Classes.TList
1049 ): Classes.TList;
1050begin
1051 Result := LCLScreen.DisableForms(SkipForm.GetNativeForm, DisabledList);
1052end;
1053
1054procedure TScreen.EnableForms(var AFormList: Classes.TList);
1055begin
1056 LCLScreen.EnableForms(AFormList);
1057end;
1058
1059function TScreen.GetSystemDpi: Integer;
1060begin
1061 Result := LCLScreen.PixelsPerInch;
1062end;
1063
1064constructor TScreen.Create;
1065begin
1066 FForms := TForms.Create;
1067 FForms.OwnsObjects := False;
1068 FPrevActiveForms := TForms.Create;
1069 FPrevActiveForms.OwnsObjects := False;
1070 // Froms.Screen.PixelsPerInch is not initialized at this point
1071 Dpi := 96;
1072end;
1073
1074destructor TScreen.Destroy;
1075begin
1076 FreeAndNil(FForms);
1077 FreeAndNil(FPrevActiveForms);
1078 if Assigned(FPrimaryMonitor) then
1079 FreeAndNil(FPrimaryMonitor);
1080 inherited;
1081end;
1082
1083procedure TScreen.UpdateActiveFormFromNativeScreen;
1084var
1085 I: Integer;
1086 F: TForm;
1087begin
1088 if LCLScreen.ActiveForm = nil then FActiveForm := nil
1089 else begin
1090 for I := 0 to FormCount - 1 do begin
1091 F := Forms[I];
1092 if F.GetNativeForm = LCLScreen.ActiveForm then begin
1093 FActiveForm := F;
1094 Break;
1095 end;
1096 end;
1097 end;
1098end;
1099
1100{ TControlScrollBar }
1101
1102function TControlScrollBar.GetVisible: Boolean;
1103begin
1104
1105end;
1106
1107procedure TControlScrollBar.SetVisible(AValue: Boolean);
1108begin
1109
1110end;
1111
1112initialization
1113
1114RegisterPropertyToSkip(TForm, 'OldCreateOrder', 'Native compatibility property', '');
1115RegisterPropertyToSkip(TForm, 'TextHeight', 'Native compatibility property', '');
1116RegisterPropertyToSkip(TForm, 'Scaled', 'Native compatibility property', '');
1117RegisterPropertyToSkip(TForm, 'TransparentColorValue', 'Native compatibility property', '');
1118Screen := TScreen.Create;
1119Application := TApplication.Create(nil);
1120
1121finalization
1122
1123FreeAndNil(Application);
1124FreeAndNil(Screen);
1125
1126end.
1127
Note: See TracBrowser for help on using the repository browser.