summaryrefslogtreecommitdiff
path: root/gui/fpgui.pas
blob: 592397faab09018e00e46232520d81791a76eb8d (plain)
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
{
    fpGUI  -  Free Pascal Graphical User Interface
    Copyright (C) 2000 - 2001 by
      Areca Systems GmbH / Sebastian Guenther
    Copyright (C) 2006 by Graeme Geldenhuys 
      member of the fpGUI development team.

    fpGUI master file

    See the file COPYING.fpGUI, included in this distribution,
    for details about the copyright.

    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}
{$mode objfpc}{$h+}

interface

uses
{$IFDEF mswindows}
  Windows, GFX_GDI,       // This must be removed!!!
{$ENDIF}
  SysUtils
  ,Classes
//  ,DOM
  ,GFXBase
//  ,GFXInterface
  ,fpgfx
//  ,Types    { used for OffsetRect() }
//  ,Contnrs
  ;

type
  TColor = type LongWord;

const

  InfiniteSize = 16383;

{$I colors.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 style.inc}
{$I widget.inc}
{$I container.inc}
{$I bin.inc}
{$I layouts.inc}
{$I form.inc}
{$I popupwindow.inc}
{$I label.inc}
{$I edit.inc}
{$I buttons.inc}
{$I scrollbar.inc}
{$I scrollbox.inc}
{$I checkbox.inc}
{$I radiobutton.inc}
{$I separator.inc}
{$I groupbox.inc}
{$I listbox.inc}
{$I combobox.inc}
{$I grid.inc}
{$I dialogs.inc}
{.$I application.inc}
{$I panel.inc}
{$I menus.inc}
{$I progressbar.inc}


//var
//  Application: TApplication;


function Min(a, b: Integer): Integer; inline;
function Max(a, b: Integer): Integer; inline;
function ClipMinMax(val, min, max: Integer): Integer; inline;


implementation
uses
//  XMLRead {!!!:, XMLStreaming}
  Math
  ,StyleManager
  ;


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;


{$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}


{ This lets us use a single include file for both the Interface and
  Implementation sections. }
{$undef read_interface}
{$define read_implementation}


{$I style.inc}
{$I widget.inc}
{$I container.inc}
{$I bin.inc}
{$I layouts.inc}
{$I form.inc}
{$I popupwindow.inc}
{$I label.inc}
{$I edit.inc}
{$I buttons.inc}
{$I scrollbar.inc}
{$I scrollbox.inc}
{$I checkbox.inc}
{$I radiobutton.inc}
{$I separator.inc}
{$I groupbox.inc}
{$I listbox.inc}
{$I combobox.inc}
{$I grid.inc}
{$I dialogs.inc}
{.$I application.inc}
{$I panel.inc}
{$I menus.inc}
{$I progressbar.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);

//  Application := TApplication.Create;


finalization
//  Application.Free;
  
end.