File: testallform.pp

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (444 lines) | stat: -rw-r--r-- 13,435 bytes parent folder | download | duplicates (3)
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
{
 ***************************************************************************
 *                                                                         *
 *   This source is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This code 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.  See the GNU     *
 *   General Public License for more details.                              *
 *                                                                         *
 *   A copy of the GNU General Public License is available on the World    *
 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 *   obtain it by writing to the Free Software Foundation,                 *
 *   Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.   *
 *                                                                         *
 ***************************************************************************
}

unit TestAllForm;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  Menus, Buttons, StdCtrls, LclProc, LCLType, ContNrs,

  Arrow, ButtonPanel;

type

  { TForm1 }

  TForm1 = class(TForm)
    BtnClear: TBitBtn;
    BottomPnl: TPanel;
    EventsLB: TListBox;
    MainMenu1: TMainMenu;
    mnuCompTZ: TMenuItem;
    mnuCompQS: TMenuItem;
    mnuCompNP: TMenuItem;
    mnuCompGM: TMenuItem;
    mnuCompDF: TMenuItem;
    mnuCompAC: TMenuItem;
    mnuComponents: TMenuItem;
    mnuAbout: TMenuItem;
    mnuFile: TMenuItem;
    mnuFileExit: TMenuItem;
    mnuDialogs: TMenuItem;
    EventsPnl: TPanel;
    TestPnl: TPanel;
    procedure BtnClearClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure mnuAboutClick(Sender: TObject);
    procedure mnuFileExitClick(Sender: TObject);
  private
    { private declarations }
    FObjList: TFPObjectList;
    procedure Clear;

    procedure CompMenuClick(Sender: TObject);
    procedure DlgMenuClick(Sender: TObject);
    procedure GenClick(Sender: TObject);
    procedure GenDblClick(Sender: TObject);
    procedure GenKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure GenKeyPress(Sender: TObject; var Key: char);
    procedure GenKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure GenMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure GenMouseEnter(Sender: TObject);
    procedure GenMouseLeave(Sender: TObject);
    procedure GenMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ShowEventFmt(const Fmt: String; const Args: array of const);

    procedure ConnectStandardEvents(AControl: TControl);
    procedure CreateMainMenu;

    // Components tests
    procedure TestArrow;
    procedure TestBitBtn;
    procedure TestButton;
    procedure TestButtonpanel;
    procedure TestCalcedit;
    procedure TestCalendar;
    procedure TestCheckbox;
    procedure TestCheckcombobox;
    procedure TestCheckgroup;
    procedure TestChecklistbox;
    procedure TestColorbox;
    procedure TestColorbutton;
    procedure TestColorlistbox;
    procedure TestCombobox;
    procedure TestComboboxex;
    procedure TestControlbar;
    procedure TestCoolbar;
    procedure TestDateedit;
    procedure TestDirectoryedit;
    procedure TestEdit;
    procedure TestEditbutton;
    procedure TestFilelistbox;
    procedure TestFilenameedit;
    procedure TestFiltercombobox;
    procedure TestFloatspinedit;
    procedure TestGroupbox;
    procedure TestHeadercontrol;
    procedure TestImage;
    procedure TestLabel;
    procedure TestLabelededit;
    procedure TestListbox;
    procedure TestListview;
    procedure TestMaskedit;
    procedure TestMemo;
    procedure TestNotebook;
    procedure TestPagecontrol;
    procedure TestPaintbox;
    procedure TestPanel;
    procedure TestProgressbar;
    procedure TestRadiobutton;
    procedure TestRadiogroup;
    procedure TestShape;
    procedure TestShelllistview;
    procedure TestShelltreeview;
    procedure TestSpeedbutton;
    procedure TestSpinedit;
    procedure TestSplitter;
    procedure TestStacTictext;
    procedure TestStatusbar;
    procedure TestStringgrid;
    procedure TestTabcontrol;
    procedure TestTimeedit;
    procedure TestTimer;
    procedure TestTogglebox;
    procedure TestToolbar;
    procedure TestTrackbar;
    procedure TestTreeview;
    procedure TestUpdown;
    procedure TestValuelisteditor;

    // Dialog tests
    procedure TestMessageDialog;
    procedure TestCalculatorDialog;
    procedure TestCalendarDialog;
    procedure TestColorDialog;
    procedure TestFindDialog;
    procedure TestFontDialog;
    procedure TestOpenDialog;
    procedure TestOpenpictureDialog;
    procedure TestReplaceDialog;
    procedure TestSaveDialog;
    procedure TestSavepictureDialog;
    procedure TestSelectdirectoryDialog;
    procedure TestQuestionDialog;

  public
    { public declarations }
  end;

var
  Form1: TForm1;


implementation

{$R *.lfm}
{$R ../images/laz_images.res}
{$R ../images/components_images.res}
{$i testallform_include.inc}

{ TForm1 }

procedure TForm1.mnuFileExitClick(Sender: TObject);
begin
  Close;
end;

procedure TForm1.Clear;
begin
  FObjList.Clear;
  EventsLB.Clear;
end;

procedure TForm1.CompMenuClick(Sender: TObject);
var
  mi: TMenuItem;
  tg: PtrInt;
  TagValid: Boolean;
begin
  debugln('TForm1.CompMenuClick A');
  mi := Sender as TMenuItem;
  tg := mi.Tag and not tagCompStart;
  TagValid := ((mi.Tag and tagCompStart) = tagCompStart) and
              (tg >= Ord(Low(taComponents))) and
              (tg <= Ord(High(taComponents)));
  if not TagValid then
  begin
    DebugLn(['TForm1.CompMenuClick: Unexpected Tag from TMenuItem: [',mi.Name,']']);
    Exit;
  end;
  case taComponents(tg) of
    tacTarrow: TestArrow;
    tacTbitbtn: TestBitBtn;
    tacTButton: TestButton;
    tacTButtonpanel: TestButtonpanel;
    tacTCalcedit: TestCalcedit;
    tacTCalendar: TestCalendar;
    tacTCheckbox: TestCheckbox;
    tacTCheckcombobox: TestCheckcombobox;
    tacTCheckgroup: TestCheckgroup;
    tacTChecklistbox: TestChecklistbox;
    tacTColorbox: TestColorbox;
    tacTColorbutton: TestColorbutton;
    tacTColorlistbox: TestColorlistbox;
    tacTCombobox: TestCombobox;
    tacTComboboxex: TestComboboxex;
    tacTControlbar: TestControlbar;
    tacTCoolbar: TestCoolbar;
    tacTDateedit: TestDateedit;
    tacTDirectoryedit: TestDirectoryedit;
    tacTEdit: TestEdit;
    tacTEditbutton: TestEditbutton;
    tacTFilelistbox: TestFilelistbox;
    tacTFilenameedit: TestFilenameedit;
    tacTFiltercombobox: TestFiltercombobox;
    tacTFloatspinedit: TestFloatspinedit;
    tacTGroupbox: TestGroupbox;
    tacTHeadercontrol: TestHeadercontrol;
    tacTImage: TestImage;
    tacTLabel: TestLabel;
    tacTLabelededit: TestLabelededit;
    tacTListbox: TestListbox;
    tacTListview: TestListview;
    tacTMaskedit: TestMaskedit;
    tacTMemo: TestMemo;
    tacTNotebook: TestNotebook;
    tacTPagecontrol: TestPagecontrol;
    tacTPaintbox: TestPaintbox;
    tacTPanel: TestPanel;
    tacTProgressbar: TestProgressbar;
    tacTRadiobutton: TestRadiobutton;
    tacTRadiogroup: TestRadiogroup;
    tacTShape: TestShape;
    tacTShelllistview: TestShelllistview;
    tacTShelltreeview: TestShelltreeview;
    tacTSpeedbutton: TestSpeedbutton;
    tacTSpinedit: TestSpinedit;
    tacTSplitter: TestSplitter;
    tacTStacTictext: TestStacTictext;
    tacTStatusbar: TestStatusbar;
    tacTStringgrid: TestStringgrid;
    tacTTabcontrol: TestTabcontrol;
    tacTTimeedit: TestTimeedit;
    tacTTimer: TestTimer;
    tacTTogglebox: TestTogglebox;
    tacTToolbar: TestToolbar;
    tacTTrackbar: TestTrackbar;
    tacTTreeview: TestTreeview;
    tacTUpdown: TestUpdown;
    tacTValuelisteditor: TestValuelisteditor;
  end;
  debugln('TForm1.CompMenuClick End');
end;

procedure TForm1.DlgMenuClick(Sender: TObject);
var
  mi: TMenuItem;
  tg: PtrInt;
  TagValid: Boolean;
begin
  debugln('TForm1.DlgMenuClick A');
  mi := Sender as TMenuItem;
  tg := mi.Tag and not tagDlgStart;
  TagValid := ((mi.Tag and tagDlgStart) = tagDlgStart) and
              (tg >= Ord(Low(taComponents))) and
              (tg <= Ord(High(taComponents)));
  if not TagValid then
  begin
    DebugLn(['TForm1.DlgMenuClick: Unexpected Tag from TMenuItem: [',mi.Name,']']);
    Exit;
  end;
  case taDialogs(tg) of
    tadTCalculatorDialog: TestCalculatorDialog;
    tadTCalendarDialog: TestCalendarDialog;
    tadTColorDialog: TestColorDialog;
    tadTFindDialog: TestFindDialog;
    tadTFontDialog: TestFontDialog;
    tadTMessageDialog: TestMessageDialog;
    tadTOpenDialog: TestOpenDialog;
    tadTOpenpictureDialog: TestOpenpictureDialog;
    tadTReplaceDialog: TestReplaceDialog;
    tadTSaveDialog: TestSaveDialog;
    tadTSavepictureDialog: TestSavepictureDialog;
    tadTSelectdirectoryDialog: TestSelectdirectoryDialog;
    tadTQuestionDialog: TestQuestionDialog;
  end;
  debugln('TForm1.DlgMenuClick End');
end;

procedure TForm1.GenClick(Sender: TObject);
begin
  ShowEventFmt('%s.OnClick',[Sender.ClassName]);
end;

procedure TForm1.GenDblClick(Sender: TObject);
begin
  ShowEventFmt('%s.OnDblClick',[Sender.ClassName]);
end;

procedure TForm1.GenKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  ShowEventFmt('%s.OnKeyDown [%s]',[Sender.ClassName,VkToString(Key)]);
end;

procedure TForm1.GenKeyPress(Sender: TObject; var Key: char);
begin
  if Key in [#33..#127] then
    ShowEventFmt('%s.OnKeyPress [%s]',[Sender.ClassName, Key])
  else
    ShowEventFmt('%s.OnKeyPress [#%d]',[Sender.ClassName, Ord(Key)])
end;

procedure TForm1.GenKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  ShowEventFmt('%s.OnKeyUp [%s]',[Sender.ClassName,VkToString(Key)]);
end;

procedure TForm1.GenMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ShowEventFmt('%s.OnMouseDown at (%d,%d)',[Sender.ClassName,X,Y]);
end;

procedure TForm1.GenMouseEnter(Sender: TObject);
begin
  ShowEventFmt('%s.OnMouseEnter',[Sender.ClassName]);
end;

procedure TForm1.GenMouseLeave(Sender: TObject);
begin
  ShowEventFmt('%s.OnMouseLeave',[Sender.ClassName]);
end;

procedure TForm1.GenMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ShowEventFmt('%s.OnMouseUp at (%d,%d)',[Sender.ClassName,X,Y]);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FObjList := TFPObjectList.Create(True);
  CreateMainMenu;
  Randomize;
end;

procedure TForm1.BtnClearClick(Sender: TObject);
begin
  Clear;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FObjList.Clear;
  FObjList.Free;
end;

procedure TForm1.mnuAboutClick(Sender: TObject);
begin
  MessageDlg(AppTitle, AboutMsg, mtInformation, [mbOK], 0);
end;

procedure TForm1.ShowEventFmt(const Fmt: String; const Args: array of const);
begin
  EventsLB.Items.Add(Fmt, Args);
  EventsLB.ItemIndex := EventsLB.Count - 1;
end;

type
  THackControl = class(TControl);

procedure TForm1.ConnectStandardEvents(AControl: TControl);
begin
  if not Assigned(AControl) then Exit;
  THackControl(AControl).OnMouseDown := @GenMouseDown;
  THackControl(AControl).OnMouseUp := @GenMouseUp;
  THackControl(AControl).OnMouseEnter := @GenMouseEnter;
  THackControl(AControl).OnMouseLeave := @GenMouseLeave;
  AControl.OnClick := @GenClick;
  THackControl(AControl).OnDblClick := @GenDblClick;
  if (AControl is TWinControl) then TWinControl(AControl).OnKeyDown := @GenKeyDown;
  if (AControl is TWinControl) then TWinControl(AControl).OnKeyUp := @GenKeyUp;
  if (AControl is TCustomEdit) then TCustomEdit(AControl).OnKeyPress := @GenKeyPress;
end;


procedure TForm1.CreateMainMenu;
var
  tac: taComponents;
  mi: TMenuItem;
  aCaption: String;
  tad: taDialogs;
begin
  for tac := Low(taComponents) to High(taComponents) do
  begin
    mi := TMenuItem.Create(Self);
    aCaption := taCompNames[tac];
    if (Upcase(aCaption[1]) = 'T') then aCaption[2] := UpCase(aCaption[2]);
    mi.Caption := aCaption;
    mi.Enabled := taCompImplemented[tac];
    mi.Name := 'mnu' + aCaption;
    mi.Tag := tagCompStart or Ord(tac);
    mi.OnClick := @CompMenuClick;
    //mnuComponents.Add(mi);
    case UpCase(aCaption[2]) of
      'A'..'C': mnuCompAC.Add(mi);
      'D'..'F': mnuCompDF.Add(mi);
      'G'..'M': mnuCompGM.Add(mi);
      'N'..'P': mnuCompNP.Add(mi);
      'Q'..'S': mnuCompQS.Add(mi);
      'T'..'Z': mnuCompTZ.Add(mi);
    end;
  end;
  for tad := Low(taDialogs) to High(taDialogs) do
  begin
    mi := TMenuItem.Create(Self);
    aCaption := taDlgNames[tad];
    //if (Upcase(aCaption[1]) = 'T') then aCaption[2] := UpCase(aCaption[2]);
    mi.Caption := aCaption;
    mi.Enabled := taDlgImplemented[tad];
    mi.Name := 'mnu' + aCaption;
    mi.Tag := tagDlgStart or Ord(tad);
    mi.OnClick := @DlgMenuClick;
    mnuDialogs.Add(mi);
  end;
end;

{$I testtools.inc}
end.