summaryrefslogtreecommitdiff
path: root/examples/gui/widgetdemo/WidgetDemo.lpr
blob: 391a412fae65ac5bfe0cc5c41f7348fec899354e (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
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
program WidgetDemo;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  ,SysUtils
  ,fpgui
  ,OpenSoftStyle
  ,gfxbase
  ;
  
type

  { TWidgetDemoForm }

  TWidgetDemoForm = class(TForm)
    topLayout: TBoxLayout;
    mainLayout: TGridLayout;
    MainMenu: TMenuBar;

    topStyleComboLayout: TBoxLayout;
    lblStyle: TLabel;
    cbStyle: TComboBox;
    
    topCheckboxLayout: TBoxLayout;
    chkStdPalette: TCheckBox;
    chkDisable: TCheckBox;

    topLeftGroupBox: TGroupBox;
    topLeftGroupBoxLayout: TBoxLayout;
    Radio1: TRadioButton;
    Radio2: TRadioButton;
    Radio3: TRadioButton;

    topRightGroupBox: TGroupBox;
    topRightGroupBoxLayout: TBoxLayout;
    Button1: TButton;
    Button2: TButton;

    StringGrid: TStringGrid;

    bottomRightGroupBox: TGroupBox;
    bottomRightGroupBoxLayout: TBoxLayout;
    Edit1: TEdit;
    Edit2: TEdit;

    bottomButtonLayout: TBoxLayout;
    btnExit: TButton;
    btnHelp: TButton;

    procedure   btnExitClick(Sender: TObject);
    procedure   Radio1Click(Sender: TObject);
    procedure   Radio2Click(Sender: TObject);
    procedure   cbStyleChanged(Sender: TObject);
    procedure   TranslateToAfrikaans;
    procedure   TranslateToEnglish;
    procedure   chkDisableClick(Sender: TObject);
  private
    procedure   CreateTopMenu;
    procedure   CreateStyleCombo;
    procedure   CreateTopCheckboxLine;
    procedure   CreateTopLeftGroupBox;
    procedure   CreateTopRightGroupBox;
    procedure   CreateBottomLeftStringGrid;
    procedure   CreateBottomRightGroupBox;
    procedure   CreateBottomButtonLayout;
  public
    constructor Create(AOwner: TComponent); override;
  end;


{ TWidgetDemoForm }

procedure TWidgetDemoForm.btnExitClick(Sender: TObject);
begin
  Close;
end;

procedure TWidgetDemoForm.Radio1Click(Sender: TObject);
begin
  TranslateToEnglish;
end;

procedure TWidgetDemoForm.Radio2Click(Sender: TObject);
begin
  TranslateToAfrikaans;
end;

procedure TWidgetDemoForm.cbStyleChanged(Sender: TObject);
begin
  if cbStyle.Text = 'OpenSoft' then
  begin
    if self.Style is TOpenSoftStyle then
      exit  //==>
    else
    begin
      Style := TOpenSoftStyle.Create(Application.Display);
      Redraw;
    end;
  end
  else
  begin
    if self.Style is TDefaultStyle then
      exit  //==>
    else
    begin
      Style := Application.DefaultStyle;
      Redraw;
    end;
  end;
end;

procedure TWidgetDemoForm.TranslateToAfrikaans;
begin
  Text                    := 'Widget Demo - Afrikaans';
  lblStyle.Text           := 'Venster Steil:';
  chkStdPalette.Text      := 'Standaard kleur tablette';
  chkDisable.Text         := 'Ge-deaktiveerde controles';
  topLeftGroupBox.Text    := 'Groep Boks Een';
  Radio1.Text             := 'Radio knoppie een';
  Radio2.Text             := 'Radio knoppie twee';
  Radio3.Text             := 'Radio knoppie drie';
  topLeftGroupBox.Text    := 'Groep Boks Twee';
  Button1.Text            := 'Normal Button';
  Button2.Text            := 'Embedded Button';
  bottomRightGroupBox.Text := 'Group Boks Drie';
  Edit1.Text              := 'Normale teks';
  Edit2.Text              := 'Wagwoord teks';
  btnExit.Text            := 'Verlaat Verlaat';
  btnHelp.Text            := 'Hulp';
  Redraw;
end;

procedure TWidgetDemoForm.TranslateToEnglish;
begin
  Text                    := 'Widget Demo - English';
  lblStyle.Text           := 'Style:';
  chkStdPalette.Text      := 'Standard color palette';
  chkDisable.Text         := 'Disable widgets';
  topLeftGroupBox.Text    := 'Group Box 1';
  Radio1.Text             := 'Radio button 1';
  Radio2.Text             := 'Radio button 2';
  Radio3.Text             := 'Radio button 3';
  topRightGroupBox.Text   := 'Group Box 2';
  Button1.Text            := 'Normal Button';
  Button2.Text            := 'Embedded Button';
  bottomRightGroupBox.Text := 'Group Box 3';
  Edit1.Text              := 'Normal Edit';
  Edit2.Text              := 'Password Edit';
  btnExit.Text            := 'Exit';
  btnHelp.Text            := 'Help';
  Redraw;
end;

procedure TWidgetDemoForm.chkDisableClick(Sender: TObject);
begin
  lblStyle.Enabled            := not chkDisable.Checked;
  cbStyle.Enabled             := not chkDisable.Checked;
  chkStdPalette.Enabled       := not chkDisable.Checked;
  topLeftGroupBox.Enabled     := not chkDisable.Checked;
  topRightGroupBox.Enabled    := not chkDisable.Checked;
  StringGrid.Enabled          := not chkDisable.Checked;
  bottomRightGroupBox.Enabled := not chkDisable.Checked;
end;

procedure TWidgetDemoForm.CreateTopMenu;
begin
  MainMenu := TMenuBar.Create(self);
  MainMenu.AddMenu('File');
  MainMenu.AddMenu('Edit');
  MainMenu.AddMenu('Options');
  MainMenu.AddMenu('Windows');
  MainMenu.AddMenu('Help');
//  MainMenu.CanExpandWidth := True;
end;

procedure TWidgetDemoForm.CreateStyleCombo;
begin
  topStyleComboLayout := TBoxLayout.Create(self);

  lblStyle := TLabel.Create('Style:', self);

  cbStyle := TComboBox.Create(self);
  cbStyle.CanExpandWidth := True;
  cbStyle.Items.Add('Windows');
  cbStyle.Items.Add('WindowsXP');
  cbStyle.Items.Add('Motif');
  cbStyle.Items.Add('ClearLooks');
  cbStyle.Items.Add('OpenSoft');
  cbStyle.OnChange := @cbStyleChanged;
  cbStyle.ItemIndex := 0;

  topStyleComboLayout.InsertChild(lblStyle);
  topStyleComboLayout.InsertChild(cbStyle);
end;

procedure TWidgetDemoForm.CreateTopCheckboxLine;
begin
  topCheckboxLayout := TBoxLayout.Create(self);

  chkStdPalette := TCheckBox.Create('Standard color palette', self);
  chkStdPalette.CanExpandWidth  := True;
  chkStdPalette.Checked         := True;

  chkDisable := TCheckBox.Create('Disable widgets', self);
  chkDisable.OnClick :=@chkDisableClick;

  topCheckboxLayout.InsertChild(chkStdPalette);
  topCheckboxLayout.InsertChild(chkDisable);
end;

procedure TWidgetDemoForm.CreateTopLeftGroupBox;
begin
  topLeftGroupBox := TGroupBox.Create('Group Box 1', self);
  topLeftGroupBox.CanExpandWidth   := True;

  topLeftGroupBoxLayout := TBoxLayout.Create(self);
  topLeftGroupBoxLayout.Orientation := Vertical;

  Radio1 := TRadioButton.Create('Radio button 1', self);
  Radio1.Checked          := True;
  Radio1.CanExpandWidth   := True;
  Radio1.OnClick          := @Radio1Click;

  Radio2 := TRadioButton.Create('Radio button 2', self);
  Radio2.CanExpandWidth   := True;
  Radio2.OnClick          := @Radio2Click;

  Radio3 := TRadioButton.Create('Radio button 3', self);
  Radio3.CanExpandWidth   := True;

  topLeftGroupBox.InsertChild(topLeftGroupBoxLayout);
  topLeftGroupBoxLayout.InsertChild(Radio1);
  topLeftGroupBoxLayout.InsertChild(Radio2);
  topLeftGroupBoxLayout.InsertChild(Radio3);
end;

procedure TWidgetDemoForm.CreateTopRightGroupBox;
begin
  topRightGroupBox := TGroupBox.Create('Group Box 2', self);
  topRightGroupBox.CanExpandWidth     := True;
  topRightGroupBox.CanExpandHeight    := True;

  topRightGroupBoxLayout := TBoxLayout.Create(self);
  topRightGroupBoxLayout.Orientation  := Vertical;
  topRightGroupBoxLayout.VertAlign    := vertCenter;
  topRightGroupBoxLayout.Spacing      := 8;

  Button1 := TButton.Create('Normal Button', self);
  Button1.CanExpandWidth := True;

  Button2 := TButton.Create('Embedded Button', self);
  Button2.CanExpandWidth := True;
  Button2.Embedded := True;

  topRightGroupBox.InsertChild(topRightGroupBoxLayout);
  topRightGroupBoxLayout.InsertChild(Button1);
  topRightGroupBoxLayout.InsertChild(Button2);
end;

procedure TWidgetDemoForm.CreateBottomLeftStringGrid;
var
  x, y: integer;
begin
  StringGrid := TStringGrid.Create(self);
  StringGrid.ColCount := 10;
  StringGrid.RowCount := 15;
  for y := 0 to StringGrid.RowCount - 1 do
    for x := 0 to StringGrid.ColCount - 1 do
      StringGrid.Cells[x, y] := Format('%d, %d', [x, y]);
end;

procedure TWidgetDemoForm.CreateBottomRightGroupBox;
begin
  bottomRightGroupBox := TGroupBox.Create('Group Box 3', self);
  bottomRightGroupBox.CanExpandHeight := True;
  bottomRightGroupBox.CanExpandWidth := True;

  bottomRightGroupBoxLayout := TBoxLayout.Create(self);
  bottomRightGroupBoxLayout.Orientation := Vertical;

  Edit1 := TEdit.Create('Normal Edit', self);
  Edit2 := TEdit.Create('Password Edit', self);
  Edit2.PasswordChar := '*';

  bottomRightGroupBox.InsertChild(bottomRightGroupBoxLayout);
  bottomRightGroupBoxLayout.InsertChild(Edit1);
  bottomRightGroupBoxLayout.InsertChild(Edit2);
end;

procedure TWidgetDemoForm.CreateBottomButtonLayout;
begin
  bottomButtonLayout := TBoxLayout.Create(self);
  bottomButtonLayout.HorzAlign := horzRight;

  btnHelp := TButton.Create('Help', self);

  btnExit := TButton.Create('Exit', self);
  btnExit.OnClick := @btnExitClick;

  bottomButtonLayout.InsertChild(btnHelp);
  bottomButtonLayout.InsertChild(btnExit);
end;

constructor TWidgetDemoForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Text          := 'Widget Demo';
  BorderWidth   := 8;
//  WindowType    := wtWindow;
  
  topLayout := TBoxLayout.Create(self);
  topLayout.Orientation     := Vertical;
  mainLayout := TGridLayout.Create(self);
  mainLayout.RowCount       := 2;
  
  CreateTopMenu;
  topLayout.InsertChild(MainMenu);

  CreateStyleCombo;
  topLayout.InsertChild(topStyleComboLayout);

  CreateTopCheckboxLine;
  topLayout.InsertChild(topCheckboxLayout);
  
  CreateTopLeftGroupBox;
  mainLayout.AddWidget(topLeftGroupBox, 0, 0, 1, 1);

  CreateTopRightGroupBox;
  mainLayout.AddWidget(topRightGroupBox, 1, 0, 1, 1);

  CreateBottomLeftStringGrid;
  mainLayout.AddWidget(StringGrid, 0, 1, 1, 1);

  CreateBottomRightGroupBox;
  mainLayout.AddWidget(bottomRightGroupBox, 1, 1, 1, 1);

  topLayout.InsertChild(mainLayout);

  CreateBottomButtonLayout;
  topLayout.InsertChild(bottomButtonLayout);

  Child := topLayout;
end;
  
  
var
  WidgetDemoForm: TWidgetDemoForm;
  
begin
  WidgetDemoForm := TWidgetDemoForm.Create(nil);
  Application.AddForm(WidgetDemoForm);
  Application.Run;
  WidgetDemoForm.Free;
end.