1 | unit Xvcl.Forms;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Xvcl.Classes, Xvcl.Controls, Xvcl.Graphics, Xvcl.Generics;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TForm = class(TWinControl)
|
---|
10 | private
|
---|
11 | FFocused: Boolean;
|
---|
12 | procedure SetFocused(const Value: Boolean);
|
---|
13 | protected
|
---|
14 | function GetVideoDevice: TVideoDevice; override;
|
---|
15 | public
|
---|
16 | const
|
---|
17 | TitleBarHeight = 24;
|
---|
18 | var
|
---|
19 | Screen: TObject; // TScreen;
|
---|
20 | Caption: string;
|
---|
21 | function HandleMessage(Message: TMessage): Boolean; override;
|
---|
22 | procedure Paint; override;
|
---|
23 | property Focused: Boolean read FFocused write SetFocused;
|
---|
24 | end;
|
---|
25 |
|
---|
26 | TApplication = class(TComponent)
|
---|
27 | Screen: TObject; // TScreen;
|
---|
28 | Forms: TList<TForm>;
|
---|
29 | MainForm: TForm;
|
---|
30 | procedure Run; virtual;
|
---|
31 | procedure Terminate; virtual;
|
---|
32 | end;
|
---|
33 |
|
---|
34 |
|
---|
35 | implementation
|
---|
36 |
|
---|
37 | uses
|
---|
38 | Xvcl.Kernel;
|
---|
39 |
|
---|
40 | { TApplication }
|
---|
41 |
|
---|
42 | procedure TApplication.Run;
|
---|
43 | begin
|
---|
44 |
|
---|
45 | end;
|
---|
46 |
|
---|
47 | procedure TApplication.Terminate;
|
---|
48 | begin
|
---|
49 |
|
---|
50 | end;
|
---|
51 |
|
---|
52 | { TForm }
|
---|
53 |
|
---|
54 | function TForm.GetVideoDevice: TVideoDevice;
|
---|
55 | begin
|
---|
56 | if Assigned(Screen) then Result := TScreen(Screen).VideoDevice
|
---|
57 | else Result := nil;
|
---|
58 | end;
|
---|
59 |
|
---|
60 | function TForm.HandleMessage(Message: TMessage): Boolean;
|
---|
61 | var
|
---|
62 | TitleBarBounds: TRectangle;
|
---|
63 | begin
|
---|
64 | Result := False;
|
---|
65 | if Message is TMessageMouseDown then
|
---|
66 | with TMessageMouseDown(Message) do begin
|
---|
67 | TitleBarBounds := TRectangle.Create(0, 0, Bounds.Width, TitleBarHeight);
|
---|
68 | Focused := True;
|
---|
69 | if TitleBarBounds.Contains(ScreenToClient(Position)) then begin
|
---|
70 | Move.StartControlPos := Bounds.TopLeft;
|
---|
71 | Move.StartMousePos := Position;
|
---|
72 | Move.Active := True;
|
---|
73 | Result := True;
|
---|
74 | end;
|
---|
75 | end else
|
---|
76 | if Message is TMessageMouseUp then
|
---|
77 | with TMessageMouseUp(Message) do begin
|
---|
78 | Move.Active := False;
|
---|
79 | end else
|
---|
80 | if Message is TMessageMouseMove then
|
---|
81 | with TMessageMouseUp(Message) do begin
|
---|
82 | if Move.Active then begin
|
---|
83 | Bounds.TopLeft := Move.StartControlPos + (Position - Move.StartMousePos);
|
---|
84 | TScreen(Screen).Paint;
|
---|
85 | end;
|
---|
86 | end;
|
---|
87 | if not Result then inherited;
|
---|
88 | end;
|
---|
89 |
|
---|
90 | procedure TForm.Paint;
|
---|
91 | begin
|
---|
92 | inherited;
|
---|
93 | with Canvas do begin
|
---|
94 | if Focused then Brush.Color := clLightBlue else
|
---|
95 | Brush.Color := clSilver;
|
---|
96 | FillRect(TRectangle.Create(0, 0, Bounds.Width - 1, TitleBarHeight));
|
---|
97 | MoveTo(TPoint.Create(0, 0));
|
---|
98 | LineTo(TPoint.Create(Bounds.Width - 1, 0));
|
---|
99 | LineTo(TPoint.Create(Bounds.Width - 1, Bounds.Height - 1));
|
---|
100 | LineTo(TPoint.Create(0, Bounds.Height - 1));
|
---|
101 | LineTo(TPoint.Create(0, 0));
|
---|
102 | MoveTo(TPoint.Create(0, TitleBarHeight));
|
---|
103 | LineTo(TPoint.Create(Bounds.Width - 1, TitleBarHeight));
|
---|
104 | TextOut(TPoint.Create((Bounds.Width - GetTextSize(Caption).X) div 2,
|
---|
105 | (TitleBarHeight - GetTextSize(Caption).Y) div 2), Caption);
|
---|
106 | end;
|
---|
107 | end;
|
---|
108 |
|
---|
109 | procedure TForm.SetFocused(const Value: Boolean);
|
---|
110 | begin
|
---|
111 | if FFocused <> Value then begin
|
---|
112 | FFocused := Value;
|
---|
113 | if Value then TScreen(Screen).FocusForm(Self);
|
---|
114 | end;
|
---|
115 | end;
|
---|
116 |
|
---|
117 | end.
|
---|