-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathformclocky.pas
429 lines (330 loc) · 9.04 KB
/
formclocky.pas
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
unit FormClocky;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, Menus, Process,
ClassClockyWidget
{$ifdef WINDOWS}
,Windows
{$endif}
{$ifdef LINUX}
,Gtk2, gdk2
{$endif}
;
type
{ TfrmClockyMain }
TfrmClockyMain = class(TForm)
Image1: TImage;
labClose: TLabel;
mConfig: TMenuItem;
MenuItem10: TMenuItem;
MenuItem9: TMenuItem;
mProfile: TMenuItem;
popOptions: TPopupMenu;
Timer1: TTimer;
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseEnter(Sender: TObject);
procedure FormMouseLeave(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormPaint(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure labCloseClick(Sender: TObject);
procedure labCloseMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure labCloseMouseEnter(Sender: TObject);
procedure labCloseMouseLeave(Sender: TObject);
procedure mConfigClick(Sender: TObject);
procedure MenuItem10Click(Sender: TObject);
procedure mProfile1Click(Sender: TObject);
procedure MenuItem7Click(Sender: TObject);
procedure mProfileClick(Sender: TObject);
procedure popOptionsPopup(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ private declarations }
public
OrigParentHWND: integer;
AutoLaunch: boolean;
isStarting: boolean;
isDragging: boolean;
DragStart: TPoint;
DragOffset: TPoint;
DragScreenStart: TPoint;
OrigPlace: TPoint;
clocky: TClockyWidget;
procedure ProfileMenuClicked(Sender: TObject);
procedure DoAutoLaunch;
end;
var
frmClockyMain: TfrmClockyMain;
implementation
{$R *.lfm}
function pt( x: integer; y: integer): TPoint;
begin
result.x := x;
result.y := y;
end;
{ TfrmClockyMain }
procedure TfrmClockyMain.FormCreate(Sender: TObject);
var
i, h: integer;
nProfile: integer;
mi: TMenuItem;
sParam: string;
begin
isStarting := true;
AutoLaunch := false;
width := 225;
height := 190;
isDragging := false;
{$ifdef Windows}
//hides the taskbar button
h := GetParent( Self.Handle);
ShowWindow(h, SW_HIDE);
SetWindowLong(h, GWL_EXSTYLE, getWindowLong(h, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
ShowWindow(h, SW_SHOW) ;
//
//set the parent to the desktop to pin the app
OrigParentHWND := GetParent(Self.Handle);
h := FindWindow('Progman', nil);
Windows.SetParent(Self.Handle, h);
//formStyle := fsStayOnTop;
{$endif}
{$ifdef Linux}
gtk_window_stick( PGtkWindow( self.Handle));
//gtk_window_set_opacity( PGtkWindow( self.Handle), 0.2);
gtk_window_set_type_hint( PGtkWindow( self.Handle), GDK_WINDOW_TYPE_HINT_DOCK);
gtk_window_set_keep_below( PGtkWindow( self.Handle), true);
{$endif}
//menus
for i := 1 to CLOCKY_PROFILE_COUNT do
begin
mi := TMenuItem.Create( mProfile);
mi.Tag := i;
mi.Caption := '(Unassigned)';
mi.OnClick := @ProfileMenuClicked;
mProfile.Add(mi);
end;
nProfile := 1;
if ParamCount > 0 then
begin
sParam := ParamStr(1);
if not TryStrToInt( sParam, nProfile) then
begin
if lowercase( sParam) = 'auto' then
begin
AutoLaunch := true;
end;
end;
end;
clocky := TClockyWidget.Create( ExtractFilePath( Application.ExeName));
clocky.ProfileID := nProfile;
clocky.Left := Left;
clocky.Top := Top;
Clocky.Load;
Left := Clocky.Left;
Top := Clocky.Top;
if AutoLaunch then
DoAutoLaunch;
end;
procedure TfrmClockyMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
CanClose := true;
{$ifdef Windows}
Windows.SetParent(Self.Handle, OrigParentHWND);
{$endif}
end;
procedure TfrmClockyMain.FormActivate(Sender: TObject);
begin
end;
procedure TfrmClockyMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
Clocky.Left := Left;
Clocky.Top := Top;
Clocky.Save;
end;
procedure TfrmClockyMain.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
isDragging := true;
OrigPlace := pt( Left, Top);
DragStart := pt( x, y);
DragScreenStart := Self.ClientToScreen( DragStart);
end;
procedure TfrmClockyMain.FormMouseEnter(Sender: TObject);
begin
end;
procedure TfrmClockyMain.FormMouseLeave(Sender: TObject);
begin
end;
procedure TfrmClockyMain.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
p: TPoint;
dx, dy: integer;
begin
if isDragging then
begin
p := Self.ClientToScreen( pt( x, y));
dx := p.x - DragScreenStart.x;
dy := p.y - DragScreenStart.y;
Left := OrigPlace.x + dx;
Top := OrigPlace.y + dy;
end;
Clocky.LastMove := Clocky.TickCount;
if not labClose.Visible then
labClose.Visible := true;
end;
procedure TfrmClockyMain.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
isDragging := false;
end;
procedure TfrmClockyMain.FormPaint(Sender: TObject);
begin
Clocky.Render( Canvas, Width, Height);
end;
procedure TfrmClockyMain.FormShow(Sender: TObject);
begin
end;
procedure TfrmClockyMain.Image1Click(Sender: TObject);
begin
end;
procedure TfrmClockyMain.labCloseClick(Sender: TObject);
begin
popOptions.PopUp;
end;
procedure TfrmClockyMain.labCloseMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
labClose.Font.Color := clWhite;
end;
procedure TfrmClockyMain.labCloseMouseEnter(Sender: TObject);
begin
labClose.Font.Color := clRed;
end;
procedure TfrmClockyMain.labCloseMouseLeave(Sender: TObject);
begin
labClose.Font.Color := clMaroon;
end;
procedure TfrmClockyMain.mConfigClick(Sender: TObject);
var
sFile: string;
sPath: string;
p: TProcess;
begin
sFile := GetAppConfigFile( false, true);
sPath := ExtractFilePath( sFile);
ForceDirectories( sPath);
p:=TProcess.Create(nil);
try
p.InheritHandles := false;
p.Options := [];
p.ShowWindow := swoShow;
{$ifdef Windows}
p.Executable := 'notepad.exe';
{$endif}
{$ifdef Linux}
p.Executable := 'xdg-open';
{$endif}
p.Parameters.Add( sFile);
p.Execute;
finally
p.Free;
end;
end;
procedure TfrmClockyMain.MenuItem10Click(Sender: TObject);
begin
close;
end;
procedure TfrmClockyMain.mProfile1Click(Sender: TObject);
var
mi: TMenuItem;
begin
mi := Sender as TMenuItem;
Clocky.ProfileID := StrToInt( mi.Caption);
Clocky.Load;
Clocky.UpdateWeatherConditions;
Invalidate;
end;
procedure TfrmClockyMain.ProfileMenuClicked(Sender: TObject);
var
mi: TMenuItem;
begin
mi := Sender as TMenuItem;
Clocky.ProfileID := mi.Tag;
Clocky.Load;
Clocky.UpdateWeatherConditions;
Invalidate;
end;
procedure TfrmClockyMain.MenuItem7Click(Sender: TObject);
begin
end;
procedure TfrmClockyMain.mProfileClick(Sender: TObject);
begin
end;
procedure TfrmClockyMain.popOptionsPopup(Sender: TObject);
var
i: integer;
mi: TMenuItem;
begin
for i := 1 to mProfile.Count do
begin
mi := mProfile[i-1];
mi.Caption := Clocky.GetProfileName( mi.Tag);
end;
end;
procedure TfrmClockyMain.Timer1Timer(Sender: TObject);
begin
if isStarting then
begin
isStarting := false;
end;
inc( Clocky.TickCount);
if Clocky.TickCount > (Clocky.LastMove + 1) then
begin
labClose.Visible := false;
end;
if (Clocky.TickCount mod CLOCKY_CHECK_INTERVAL) = 0 then
begin
Clocky.UpdateWeatherConditions;
end;
if Clocky.TickCount = 5 then
begin
Clocky.UpdateWeatherConditions;
end;
invalidate;
end;
procedure TfrmClockyMain.DoAutoLaunch;
var
sFile: string;
sPath: string;
p: TProcess;
i: integer;
sExe: string;
begin
sExe := Application.ExeName;
for i := 2 to CLOCKY_PROFILE_COUNT do
begin
if Clocky.isProfileAutolaunch( i) then
begin
p:=TProcess.Create(nil);
try
p.InheritHandles := false;
p.Options := [];
p.ShowWindow := swoShow;
p.Executable := sExe;
p.Parameters.Add( IntToStr( i));
p.Execute;
finally
p.Free;
end;
end;
end;
end;
end.