source: branches/Xvcl/Xvcl.Forms.pas

Last change on this file was 24, checked in by chronos, 12 years ago
  • Fixed: Make only one form focused at once.
  • Modified: Enhanced TList generic class to support more methods.
File size: 2.9 KB
Line 
1unit Xvcl.Forms;
2
3interface
4
5uses
6 Xvcl.Classes, Xvcl.Controls, Xvcl.Graphics, Xvcl.Generics;
7
8type
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
35implementation
36
37uses
38 Xvcl.Kernel;
39
40{ TApplication }
41
42procedure TApplication.Run;
43begin
44
45end;
46
47procedure TApplication.Terminate;
48begin
49
50end;
51
52{ TForm }
53
54function TForm.GetVideoDevice: TVideoDevice;
55begin
56 if Assigned(Screen) then Result := TScreen(Screen).VideoDevice
57 else Result := nil;
58end;
59
60function TForm.HandleMessage(Message: TMessage): Boolean;
61var
62 TitleBarBounds: TRectangle;
63begin
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;
88end;
89
90procedure TForm.Paint;
91begin
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;
107end;
108
109procedure TForm.SetFocused(const Value: Boolean);
110begin
111 if FFocused <> Value then begin
112 FFocused := Value;
113 if Value then TScreen(Screen).FocusForm(Self);
114 end;
115end;
116
117end.
Note: See TracBrowser for help on using the repository browser.