1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
{
fpGUI - Free Pascal GUI Library
fpGUI master file
Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
for details about redistributing fpGUI.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Description:
It is fully object-oriented; its main goal is to provide its services
independent of any operating system or graphics environment. All painting
is done using fpGFX, while fpGUI provides a comfortable widget set and
other high-level classes.
}
unit fpGUI;
{.$DEFINE LAYOUTTRACES}
{.$DEFINE TRACEEVENTS}
{$IFDEF Debug}
{$ASSERTIONS On}
{$ENDIF}
{$IFDEF FPC}
{$mode objfpc}{$h+}
{$ENDIF}
interface
uses
{$IFDEF mswindows}
Windows, GFX_GDI, // This must be removed!!!
{$ENDIF}
SysUtils
,Classes
,GFXBase
,fpGFX
// ,Types
;
type
TColor = type LongWord;
const
InfiniteSize = 16383;
// Insert loads of named colors
{$I fpguicolors.inc}
resourcestring
mbText_Yes = 'Yes';
mbText_No = 'No';
mbText_Ok = 'Ok';
mbText_Cancel = 'Cancel';
mbText_Apply = 'Apply';
mbText_Abort = 'Abort';
mbText_Retry = 'Retry';
mbText_Ignore = 'Ignore';
mbText_All = 'All';
mbText_NoToAll = 'No to all';
mbText_YesToAll = 'Yes to all';
mbText_Help = 'Help';
type
TWidget = class;
TEventObj = class;
TCustomForm = class;
TWidgetState = set of (
wsEnabled,
wsIsVisible,
wsSizeIsForced,
wsHasFocus,
wsMouseInside,
wsClicked
);
TOrientation = (Horizontal, Vertical);
// The following flags are used for styles
TButtonFlags = set of (btnIsEmbedded, btnIsDefault, btnIsPressed,
btnIsSelected, btnHasFocus);
TCheckboxFlags = set of (cbIsPressed, cbHasFocus, cbIsEnabled, cbIsChecked);
// Other stuff
TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbApply, mbAbort, mbRetry,
mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp);
TMsgDlgButtons = set of TMsgDlgBtn;
// Panel & Frame types
TBevelStyle = (bsPlain, bsLowered, bsRaised);
TBevelShape = (bsNoFrame, bsBox, bsFrame, bsBottomLine, bsLeftLine,
bsRightLine, bsTopLine);
{ This lets us use a single include file for both the Interface and
Implementation sections. }
{$define read_interface}
{$undef read_implementation}
{$I fpguistyle.inc}
{$I fpguiwidget.inc}
{$I fpguicontainer.inc}
{$I fpguibin.inc}
{$I fpguilayouts.inc}
{$I fpguiform.inc}
{$I fpguipopupwindow.inc}
{$I fpguilabel.inc}
{$I fpguiedit.inc}
{$I fpguibuttons.inc}
{$I fpguiscrollbar.inc}
{$I fpguiscrollbox.inc}
{$I fpguicheckbox.inc}
{$I fpguiradiobutton.inc}
{$I fpguiseparator.inc}
{$I fpguigroupbox.inc}
{$I fpguilistbox.inc}
{$I fpguicombobox.inc}
{$I fpguigrid.inc}
{$I fpguidialogs.inc}
{$I fpguipanel.inc}
{$I fpguimenus.inc}
{$I fpguiprogressbar.inc}
function Min(a, b: Integer): Integer; inline;
function Max(a, b: Integer): Integer; inline;
function ClipMinMax(val, min, max: Integer): Integer; inline;
{ This will change at a later date! }
procedure LoadForm(AForm: TComponent);
implementation
uses
Math
,stylemanager
,MotifStyle // so they register with style manager
,OpenSoftStyle // so they register with style manager
,WindowsStyle // so they register with style manager
;
resourcestring
sListIndexError = 'List index exceeds bounds (%d)';
{$IFDEF TraceEvents}
var
EventNestingLevel: Integer;
{$ENDIF}
function Min(a, b: Integer): Integer;
begin
if a < b then
Result := a
else
Result := b;
end;
function Max(a, b: Integer): Integer;
begin
if a > b then
Result := a
else
Result := b;
end;
function ClipMinMax(val, min, max: Integer): Integer;
begin
if val < min then
Result := min
else if val > max then
begin
Result := max;
if Result < min then
Result := min;
end else
Result := val;
end;
procedure LoadForm(AForm: TComponent);
type
PForm = ^TCustomForm;
var
lForm: PForm;
Filename: string;
TextStream, BinStream: TStream;
begin
Filename := LowerCase(Copy(AForm.ClassName, 2, 255)) + '.frm';
TextStream := TFileStream.Create(Filename, fmOpenRead);
BinStream := TMemoryStream.Create;
ObjectTextToBinary(TextStream, BinStream);
TextStream.Free;
lForm := @AForm;
BinStream.Position := 0;
BinStream.ReadComponent(lForm^);
BinStream.Free;
end;
{$IFDEF LAYOUTTRACES}
procedure LAYOUTTRACE(const Position: String; const args: array of const);
{$IFDEF TraceEvents}
var
i: Integer;
{$ENDIF}
begin
{$IFDEF TraceEvents}
for i := 1 to EventNestingLevel do
Write(' ');
{$ENDIF}
WriteLn(Format(Position, args));
end;
{$ELSE}
procedure LAYOUTTRACE(const Position: String; const args: array of const);
begin
end;
{$ENDIF}
function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
begin
if Assigned(@Rect) then
begin
with Rect do
begin
dec(Left, dx);
dec(Top, dy);
inc(Right, dx);
inc(Bottom, dy);
end;
Result := True;
end
else
Result := False;
end;
function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
begin
if assigned(@Rect) then
begin
with Rect do
begin
inc(Left,dx);
inc(Top,dy);
inc(Right,dx);
inc(Bottom,dy);
end;
OffsetRect := True;
end
else
OffsetRect := False;
end;
function CenterPoint(const Rect: TRect): TPoint;
begin
with Rect do
begin
Result.X := (Left+Right) div 2;
Result.Y := (Top+Bottom) div 2;
end;
end;
{ This lets us use a single include file for both the Interface and
Implementation sections. }
{$undef read_interface}
{$define read_implementation}
{$I fpguistyle.inc}
{$I fpguiwidget.inc}
{$I fpguicontainer.inc}
{$I fpguibin.inc}
{$I fpguilayouts.inc}
{$I fpguiform.inc}
{$I fpguipopupwindow.inc}
{$I fpguilabel.inc}
{$I fpguiedit.inc}
{$I fpguibuttons.inc}
{$I fpguiscrollbar.inc}
{$I fpguiscrollbox.inc}
{$I fpguicheckbox.inc}
{$I fpguiradiobutton.inc}
{$I fpguiseparator.inc}
{$I fpguigroupbox.inc}
{$I fpguilistbox.inc}
{$I fpguicombobox.inc}
{$I fpguigrid.inc}
{$I fpguidialogs.inc}
{$I fpguipanel.inc}
{$I fpguimenus.inc}
{$I fpguiprogressbar.inc}
const
Orientations: array[TOrientation] of TIdentMapEntry = (
(Value: Ord(Horizontal); Name: 'Horizontal'),
(Value: Ord(Vertical); Name: 'Vertical')
);
function IdentToOrientation(const Ident: String; var Orientation: LongInt): Boolean;
begin
Result := IdentToInt(Ident, Orientation, Orientations);
end;
function OrientationToIdent(Orientation: LongInt; var Ident: String): Boolean;
begin
Result := IntToIdent(Orientation, Ident, Orientations);
end;
initialization
RegisterIntegerConsts(TypeInfo(TOrientation),
@IdentToOrientation, @OrientationToIdent);
end.
|