summaryrefslogtreecommitdiff
path: root/examples/gui/calendar/calendartest.lpr
blob: 4ac8c3eba613dc1efc73fc22fac69b4e813ecee6 (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
{
   This is still under development!!!!!!!!!!!!!!!!!
}

program calendartest;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, gfxbase, fpgfx, gui_form, gui_popupcalendar, gui_edit,
  gui_button, gui_label, gfx_popupwindow, gui_combobox;

type
  TMainForm = class(TfpgForm)
  private
    procedure   btnDownClicked(Sender: TObject);
    procedure   btnDateFormatClicked(Sender: TObject);
    procedure   btnTodayClicked(Sender: TObject);
    procedure   DoDropDown;
  public
    {@VFD_HEAD_BEGIN: MainForm}
    edtName1: TfpgEdit;
    btnName1: TfpgButton;
    lblName1: TfpgLabel;
    lblName2: TfpgLabel;
    cbName1: TfpgComboBox;
    cbCalendar: TfpgCalendarCombo;
    btnDateFormat: TfpgButton;
    edtDateFormat: TfpgEdit;
    lblName3: TfpgLabel;
    lblName4: TfpgLabel;
    lblName5: TfpgLabel;
    btnToday: TfpgButton;
    lblName6: TfpgLabel;
    {@VFD_HEAD_END: MainForm}
    FDropDown: TfpgPopupCalendar;
    procedure   AfterCreate; override;
  end;
  
{@VFD_NEWFORM_DECL}

{ TMainForm }

procedure TMainForm.btnDownClicked(Sender: TObject);
begin
  DoDropDown;
end;

procedure TMainForm.btnDateFormatClicked(Sender: TObject);
begin
  cbCalendar.DateFormat := edtDateFormat.Text;
end;

procedure TMainForm.btnTodayClicked(Sender: TObject);
begin
  cbCalendar.DateValue := Now;
end;

procedure TMainForm.DoDropDown;
begin
  if (not Assigned(FDropDown)) or (not FDropDown.HasHandle) then
  begin
    FDropDown     := TfpgPopupCalendar.Create(nil, edtName1);
    FDropDown.ShowAt(self, edtName1.Left, edtName1.Top+edtName1.Height);
    FDropDown.PopupFrame:= True;
  end
  else
  begin
    FDropDown.Close;
    FreeAndNil(FDropDown);
  end;
end;

procedure TMainForm.AfterCreate;
begin
  inherited AfterCreate;
  {@VFD_BODY_BEGIN: MainForm}
  Name := 'MainForm';
  SetPosition(286, 234, 470, 253);
  WindowTitle := 'fpGUI Calendar Test';
  WindowPosition := wpUser;

  edtName1 := TfpgEdit.Create(self);
  with edtName1 do
  begin
    Name := 'edtName1';
    SetPosition(16, 48, 120, 22);
    Text := '';
    FontDesc := '#Edit1';
  end;

  btnName1 := TfpgButton.Create(self);
  with btnName1 do
  begin
    Name := 'btnName1';
    SetPosition(136, 48, 19, 22);
    Text := '';
    FontDesc := '#Label1';
    ImageName := 'sys.sb.down';
    OnClick := @btnDownClicked;
  end;

  lblName1 := TfpgLabel.Create(self);
  with lblName1 do
  begin
    Name := 'lblName1';
    SetPosition(16, 32, 80, 16);
    Text := 'Enter a date:';
    FontDesc := '#Label1';
  end;

  lblName2 := TfpgLabel.Create(self);
  with lblName2 do
  begin
    Name := 'lblName2';
    SetPosition(68, 100, 276, 16);
    Text := '*****   This still needs some testing  *****';
    FontDesc := '#Label2';
    Color := clRed;
  end;

  cbName1 := TfpgComboBox.Create(self);
  with cbName1 do
  begin
    Name := 'cbName1';
    SetPosition(132, 144, 120, 23);
    Items.Add('line1');
    Items.Add('line2');
    Items.Add('line3');
    Items.Add('line4');
    Items.Add('line5');
    Items.Add('line6');
    FontDesc := '#List';
  end;

  cbCalendar := TfpgCalendarCombo.Create(self);
  with cbCalendar do
  begin
    Name := 'cbCalendar';
    SetPosition(132, 196, 120, 23);
    FontDesc := '#List';
    DateFormat := 'yyyy-mm-dd';
  end;

  btnDateFormat := TfpgButton.Create(self);
  with btnDateFormat do
  begin
    Name := 'btnDateFormat';
    SetPosition(300, 168, 75, 23);
    Text := 'Set Format';
    FontDesc := '#Label1';
    ImageName := '';
    OnClick := @btnDateFormatClicked;
  end;

  edtDateFormat := TfpgEdit.Create(self);
  with edtDateFormat do
  begin
    Name := 'edtDateFormat';
    SetPosition(300, 196, 120, 21);
    Text := 'yy-mm-d';
    FontDesc := '#Edit1';
  end;

  lblName3 := TfpgLabel.Create(self);
  with lblName3 do
  begin
    Name := 'lblName3';
    SetPosition(160, 48, 287, 15);
    Text := '<----  This one is fake. It only used the';
    FontDesc := '#Label1';
    Color := clBlue;
  end;

  lblName4 := TfpgLabel.Create(self);
  with lblName4 do
  begin
    Name := 'lblName4';
    SetPosition(12, 148, 96, 15);
    Text := 'Normal Combo:';
    FontDesc := '#Label1';
  end;

  lblName5 := TfpgLabel.Create(self);
  with lblName5 do
  begin
    Name := 'lblName5';
    SetPosition(12, 200, 104, 15);
    Text := 'Calendar Combo:';
    FontDesc := '#Label1';
  end;

  btnToday := TfpgButton.Create(self);
  with btnToday do
  begin
    Name := 'btnToday';
    SetPosition(384, 168, 75, 23);
    Text := 'Today';
    FontDesc := '#Label1';
    ImageName := '';
    OnClick := @btnTodayClicked;
  end;

  lblName6 := TfpgLabel.Create(self);
  with lblName6 do
  begin
    Name := 'lblName6';
    SetPosition(192, 63, 246, 16);
    Text := 'calendar window part.';
    FontDesc := '#Label1';
  end;

  {@VFD_BODY_END: MainForm}
end;


{@VFD_NEWFORM_IMPL}

procedure MainProc;
var
  frm: TMainForm;
begin
  fpgApplication.Initialize;
  frm := TMainForm.Create(nil);
  try
    frm.Show;
    fpgApplication.Run;
  finally
    frm.Free;
  end;
end;

begin
  MainProc;
end.