summaryrefslogtreecommitdiff
path: root/extras/contributed/nicegrid/main1.pas
blob: 27d7a3bd5c60bbc4cab4d89423976dae32fbb07a (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
361
362
363
364
365
366
367
368
unit main1;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_menu,
  fpg_nicegrid, fpg_button, fpg_checkbox, fpg_label;

type

  TfrmMain = class(TfpgForm)
  private
    FFileSubMenu: TfpgPopupMenu;
    FMenuBar : TfpgMenuBar;
    Grid1: TfpgNiceGrid;
    CheckBox1: TfpgCheckBox;
    CheckBox2: TfpgCheckBox;
    CheckBox3: TfpgCheckBox;
    CheckBox4: TfpgCheckBox;
    CheckBox5: TfpgCheckBox;
    CheckBox6: TfpgCheckBox;
    Label1: TfpgLabel;
    Button1: TfpgButton;
    Button2: TfpgButton;
    Button3: TfpgButton;
    Button4: TfpgButton;
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
    procedure CheckBox4Click(Sender: TObject);
    procedure CheckBox5Click(Sender: TObject);
    procedure CheckBox6Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Grid1DrawHeader(Sender: TObject; ACanvas: TfpgCanvas;
      Rc: TfpgRect; Str: string; var Handled: Boolean);
    procedure Grid1InsertRow(Sender: TObject; ARow: Integer);
    
    procedure miExitClicked(Sender: TObject);
  public
    procedure AfterCreate; override;
  end;

  
implementation
  

procedure TfrmMain.AfterCreate;
var x: integer;  
begin
  Name := 'frmMain';
  SetPosition(252, 121, 638, 575);
  WindowTitle := 'NiceGrid - Demo 1';
  Hint := '';
  FFileSubMenu := TfpgPopupMenu.Create(self);
  with FFileSubMenu do
  begin
    Name := 'FFileSubMenu';
    SetPosition(0, 0, 120, 32);
  end;
  FFileSubMenu.AddMenuItem('&Quit', 'Ctrl-Q', @miExitClicked);
  FMenuBar := CreateMenuBar(self);
  FMenuBar.AddMenuItem('&File', nil).SubMenu := FFileSubMenu;
  
 Grid1 := TfpgNiceGrid.Create(self);
  with Grid1 do
  begin
    Name := 'Grid1';
    SetPosition(16, 88, 597, 370);
    Anchors := [anLeft,anRight,anTop,anBottom];
    FontDesc := '#Grid';
    Hint := '';
 //   Cursor = 1
    RowCount := 20;
    AutoAddRow := True;
    DefColWidth := 100;
    Color := $ffece9d8;
    GridColor := clSilver;
    HeaderLine := 2;
    HeaderColor := clButtonFace;
    HeaderLightColor := clHilite1;
    HeaderDarkColor := clShadow1;
    HeaderFontColor := clWhite;
    HeaderFont := 'MS Sans Serif';
    FooterFontColor := clRed;
    SelectionColor := $ffD2D2FF;
    BeginUpdate;  // JP
    with Columns.Add do
    begin
      Title := 'Merged;Multilined|Merged;Multilined';
      Footer := 'Footer 0';
      Font:='Arial-8';
      FontColor:=clBlack;
      Width := 100;
      CanResize := False;
    end;
    with Columns.Add do
    begin
      Title:='First Group|One';
      Footer:='Footer 1';
      Width:=100;
      Font:='Arial-8';
      FontColor:=clRed;
      Color:=$FFFFFACD;//14024703;
      HorzAlign:=haCenter;
    end;
    with Columns.Add do
    begin
      Title:='First Group|Two';
      Footer:='Footer 2';
      Font:='Arial-8';
      FontColor:=clBlack;
      Width:=100;
    end;
    with Columns.Add do
    begin
      Title:='Second Group|One';
      Footer:='Footer 3';
      Width:=100;
      Font:='Arial-8';
      FontColor:=clBlack;
      Color:=clWhite;
      HorzAlign:=haRight;
    end;
    with Columns.Add do
    begin
      Title:='Second Group|Two';
      Footer:='Footer 4';
      Font:='Arial-8';
      FontColor:=clBlack;
      Width:=100;
      HorzAlign:=haCenter;
    end;
    GutterKind:=gkNumber;
    GutterWidth:=40;
    GutterFont:='Arial-8';
    GutterFontColor:=clBlack;
    ShowFooter:=True;
    OnDrawHeader:=@Grid1DrawHeader;
    OnInsertRow:=@Grid1InsertRow;
    TabOrder:=0;
    EndUpdate;
  end;  {Grid1}
  
  Label1:= TfpgLabel.Create(self);
  with Label1 do
  begin	  
    SetPosition(16, 42, 300, 18);
    Text:= '- Try to copy paste a cell with Ctrl+c and  Ctrl+v' 
  end;  
  CheckBox1:= TfpgCheckBox.Create(self);
  with CheckBox1 do
  begin
    Name:='CheckBox1';
    SetPosition(16,470,49,17);  
    Anchors := [anLeft, anBottom];
    Text := 'Flat';
    Checked := True;
    TabOrder := 1;
    OnChange := @CheckBox1Click;
  end;
  CheckBox2:= TfpgCheckBox.Create(self);
  with CheckBox2 do
  begin
    Name:='CheckBox2';
    SetPosition(78,470,110,17);  
    Anchors := [anLeft, anBottom];
    Text:= 'System Colors';
    Checked := True;
    TabOrder := 2;
    OnChange := @CheckBox2Click;
  end;
  CheckBox3:= TfpgCheckBox.Create(self);
  with CheckBox3 do
  begin
    Name:='CheckBox3';
    SetPosition(192,470,90,17);  
    Anchors := [anLeft, anBottom];
    Text := 'Fit to Width';
    TabOrder := 3;
    OnChange := @CheckBox3Click;
  end;
  CheckBox4:= TfpgCheckBox.Create(self);
  with CheckBox4 do
  begin
    Name:='CheckBox4';
    SetPosition(288,470,135,17);  
    Anchors := [anLeft, anBottom];
    Text := 'Auto Column Width';
    TabOrder := 4;
    OnChange := @CheckBox4Click;
  end;
  CheckBox5:= TfpgCheckBox.Create(self);
  with CheckBox5 do
  begin
    Name:='CheckBox5';
    SetPosition(424,470,90,17);  
    Anchors := [anLeft, anBottom];
    Text := 'Show Grids';
    Checked := True;
    TabOrder := 5;
    OnChange := @CheckBox5Click;
  end;
  CheckBox6:= TfpgCheckBox.Create(self);
  with CheckBox6 do
  begin
    Name:='CheckBox6';
    SetPosition(528,470,95,17);
    Anchors := [anLeft, anBottom];
    Text := 'Show Footer';
    Checked := True;
    TabOrder := 10;
    OnChange:= @CheckBox6Click;
  end;
  
  Button1:= TfpgButton.Create(self);
  with Button1 do
  begin
    Name:='Button1';
    SetPosition(272,505,129,25);
    Anchors:= [anLeft, anBottom];
    Text:= 'Hide 3rd Column';
    TabOrder:= 8;
    OnClick:= @Button1Click;
  end;
  Button2:= TfpgButton.Create(self);
  with Button2 do
  begin
    Name:='Button2';
    SetPosition(16,505,121,25);
    Anchors:= [anLeft, anBottom];
    Text:= 'Insert New Row';
    TabOrder:= 6;
    OnClick:= @Button2Click;
  end;
  Button3:= TfpgButton.Create(self);
  with Button3 do
  begin
    Name:='Button3';
    SetPosition(144,505,121,25);
    Anchors:= [anLeft, anBottom];
    Text:= 'Delete Current Row';
    TabOrder:= 7;
    OnClick:= @Button3Click;
  end;
  Button4:= TfpgButton.Create(self);
  with Button4 do
  begin
    Name:='Button4';
    SetPosition(416,505,180,25);
    Anchors:= [anLeft, anBottom];
    Text:= 'Toggle ReadOnly 3rd Column';
    TabOrder:= 9;
    OnClick:=@Button4Click;
  end;

  Grid1.BeginUpdate;
  for x := 0 to 9 do
  begin
    Grid1[0, x] := 'Sample Text';
    Grid1[1, x] := 'Centered Text';
    Grid1[2, x] := 'Left Alignment';
    Grid1[3, x] := FormatFloat('### ### ##0.##', Random(20000000));
    Grid1[4, x] := IntToStr(Random(2000));
  end;
  Grid1.EndUpdate;
end;
  
procedure TfrmMain.miExitClicked(Sender: TObject);
begin
  Close;
end;
  
procedure TfrmMain.CheckBox1Click(Sender: TObject);
begin
  Grid1.Flat := CheckBox1.Checked;
end;

procedure TfrmMain.CheckBox2Click(Sender: TObject);
begin
  if CheckBox2.Checked then
  begin
    with Grid1 do
    begin
      BeginUpdate;
      GridColor := clSilver;  
      HeaderColor := clButtonFace;
      HeaderDarkColor := clShadow1;
      HeaderLightColor := clHilite1;
      HeaderFontColor := clBlack;
      GutterFontColor:=clBlack;
      EndUpdate; 
    end;
  end
  else
  begin
    with Grid1 do
    begin
      BeginUpdate; 
      GridColor := clGray;
      HeaderColor := $FF0000DF;
      HeaderDarkColor := clBlack;
      HeaderLightColor := $FF0080FF;
      HeaderFontColor := clWhite;
      GutterFontColor:=clWhite;
      EndUpdate;
    end;
  end;
  Grid1.Invalidate; 
end;

procedure TfrmMain.CheckBox3Click(Sender: TObject);
begin
  Grid1.FitToWidth := CheckBox3.Checked;
end;

procedure TfrmMain.CheckBox4Click(Sender: TObject);
begin
  Grid1.AutoColWidth := CheckBox4.Checked;
end;

procedure TfrmMain.CheckBox5Click(Sender: TObject);
begin
  Grid1.ShowGrid := CheckBox5.Checked;
end;

procedure TfrmMain.CheckBox6Click(Sender: TObject);
begin
  Grid1.ShowFooter := CheckBox6.Checked;
end;

procedure TfrmMain.Button1Click(Sender: TObject);
begin
  Grid1.Columns[2].Visible := not Grid1.Columns[2].Visible;
end;

procedure TfrmMain.Button2Click(Sender: TObject);
begin
  Grid1.InsertRow(Grid1.Row);
end;

procedure TfrmMain.Button3Click(Sender: TObject);
begin
  Grid1.DeleteRow(Grid1.Row);
end;

procedure TfrmMain.Button4Click(Sender: TObject);
begin
  Grid1.Columns[2].ReadOnly := not Grid1.Columns[2].ReadOnly;
end;

procedure TfrmMain.Grid1DrawHeader(Sender: TObject; ACanvas: TfpgCanvas;
  Rc: TfpgRect; Str: String; var Handled: Boolean);
begin
  if (Str = 'One')
    then ACanvas.SetTextColor(clRed);
end;

procedure TfrmMain.Grid1InsertRow(Sender: TObject; ARow: Integer);
begin
  Grid1.Cells[0, ARow] := 'New Row';
end;
  
end.