-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathOSUtils.pas
More file actions
817 lines (686 loc) · 20 KB
/
OSUtils.pas
File metadata and controls
817 lines (686 loc) · 20 KB
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
(*
@Abstract(Operating systems support unit)
(C) 2006-2007 George "Mirage" Bakhtadze. <a href="http://www.casteng.com">www.casteng.com</a> <br>
The source code may be used under either MPL 1.1 or LGPL 2.1 license. See included license.txt file <br>
Unit contains basic OS-related classes
*)
{$Include GDefines.inc}
{$IFDEF USEGLUT}
{$DEFINE GLUT} // Use GLUT implementation
{$ELSE}
{$IFDEF WINDOWS}
{$DEFINE WINAPI} // Use WinAPI implementation
{$ENDIF}
{$IFDEF LINUX}
{$DEFINE X11} // Use X11 implementation
{$UNDEF GLUT}
{$ENDIF}
{$ENDIF}
unit OSUtils;
interface
uses
{$IFDEF WINAPI}
{$IFDEF FPC} FPCWindows, {$ENDIF}
ShlObj, ShellAPI,
Windows, Messages,
{$ENDIF}
{$IFDEF LINUX}
unix, x, xlib,
{$ENDIF}
{$IFDEF GLUT}
glut, freeglut,
{$ENDIF}
SysUtils, // ToDo: Move to advanced unit
Basics, BaseTypes, BaseMsg;
{$IFDEF WINAPI}
const
kernel = 'kernel32.dll';
{$ENDIF}
type
THandle = Cardinal;
// State of each key in keyboard. The key is pressed if the corresponding elements is non-zero.
TKbdState = array[0..255] of Byte;
{$IFDEF WINAPI}
TRect = Windows.TRect;
{$ELSE}
TRect = BaseTypes.TRect;
{$ENDIF}
{$IFDEF X11}
TPoint = packed record
X: Longint;
Y: Longint;
end;
{$ENDIF}
{$IFDEF GLUT}
TGLUTState = record
WindowId: Integer;
MouseCnt: Integer;
MouseX, MouseY: Integer;
KbdState: TKbdstate;
end;
{$ENDIF}
// System path
TSysFolder = (sfRecycled, sfDesktop, sfStartMenu, sfPrograms, sfStartup, sfPersonal, sfTemplates, sfRecent, sfSendTo, sfNetHood, sfAppData, sfWinRoot, sfWinSys);
// Window non-client elements
TWindowElement = (// Border across a window
weBorder,
// Window caption
weCaption,
// Minimize button
weMinimizeButton,
// Maximize button
weMaximizeButton,
// Close button
weCloseButton,
// Window menu
weMenu);
TWindowElements = set of TWindowElement;
// OS dependent
// Obtains mouse cursor position relative to screen and fills X and Y with the position
procedure ObtainCursorPos(out X, Y: Integer);
// Sets mouse cursor position relative to screen
procedure SetCursorPos(X, Y: Integer);
// Adjust mouse cursor visibility counter. The cursor will be visible if the counter >= 0. Initial value of the counter is zero.
function AdjustCursorVisibility(Show: Boolean): Integer;
procedure ClipCursor(Rect: TRect);
function GetClipCursor: TRect;
procedure GetWindowRect(Handle: THandle; out Rect: TRect);
procedure GetClientRect(Handle: THandle; out Rect: TRect);
procedure ScreenToClient(Handle: THandle; var X, Y: Integer);
procedure ClientToScreen(Handle: THandle; var X, Y: Integer);
procedure ShowWindow(Handle: THandle);
procedure HideWindow(Handle: THandle);
procedure MinimizeWindow(Handle: THandle);
procedure RestoreWindow(Handle: THandle);
function IsWindowVisible(Handle: THandle): Boolean;
procedure SetWindowCaption(Handle: THandle; const ACaption: string);
procedure ObtainKeyboardState(var State: TKbdState);
function GetAsyncKeyState(Key: Integer): Integer;
function GetOSErrorStr(ErrorID: Integer): string;
function ActivateWindow(Handle: THandle): Boolean;
function GetCurrentMs: Int64;
procedure ObtainPerformanceFrequency;
function GetPerformanceCounter: Int64;
procedure OpenWith(ParentHandle: Cardinal; const FileName: string);
procedure OpenURL(const URL: string);
{$IFDEF WINAPI}
function ThreadSafeIncrement(var Addend: Integer): Integer; stdcall; external kernel name 'InterlockedIncrement';
function ThreadSafeDecrement(var Addend: Integer): Integer; stdcall; external kernel name 'InterlockedDecrement';
{$ENDIF}
function WMToMessage(MsgID: Cardinal; wParam, lParam: Integer): TMessage; overload;
{$IFDEF WINAPI}
function WMToMessage(const Msg: Messages.TMessage): TMessage; overload;
{$ENDIF}
procedure Sleep(Milliseconds: Integer); // Not accurate (~10ms)
procedure Delay(Microseconds: Integer); // Accurate
procedure Exec(const Command: string);
function GetActiveWindow: THandle;
function GetSysFolder(SysFolder: TSysFolder): string;
function GetTextFromClipboard: string;
// OS independent
// Returns time of last file modification
function GetFileModifiedTime(const FileName: string): TDateTime;
procedure SetCursorVisibility(Counter: Integer);
procedure ShowCursor;
procedure HideCursor;
{$IFDEF LINUX}
(* Initializes X11 window system.
Handle is any valid X11 window handle used in some X11 function calls.
Should stay valid for the time when OSUtils unit is used. *)
procedure InitX11(Handle: TWindow);
// Returns pointer to X11 display
function GetXDisplay(): PXDisplay;
{$ENDIF}
var
PerformanceFrequency: Int64;
OneOverPerformanceFrequency: Single;
{$IFDEF GLUT}
GlutState: TGLUTState;
{$ENDIF}
implementation
{$IFDEF LINUX}
var
XScreen: record
Display: PXDisplay;
// Should be a valid X11 window handle on the time of any OSUtils call
Window: TWindow;
end;
procedure InitX11(Handle: TWindow);
begin
if XScreen.Display <> nil then XScreen.Display := XOpenDisplay(nil);
XScreen.Window := Handle;
end;
function GetXDisplay(): PXDisplay;
begin
Assert((Xscreen.Display <> nil), 'Call InitX11() first!');
Result := XScreen.Display;
end;
{$ENDIF}
// OS dependent
{$IFDEF WINAPI}
procedure ObtainCursorPos(out X, Y: Integer);
var
Pnt: TPoint;
begin
Windows.GetCursorPos(Pnt);
X := Pnt.X; Y := Pnt.Y;
end;
procedure SetCursorPos(X, Y: Integer);
begin
Windows.SetCursorPos(X, Y);
end;
function AdjustCursorVisibility(Show: Boolean): Integer;
begin
Result := Windows.ShowCursor(Show);
end;
procedure ClipCursor(Rect: TRect);
begin
Windows.ClipCursor(@Rect);
end;
function GetClipCursor: TRect;
begin
Windows.GetClipCursor(Result);
end;
procedure GetWindowRect(Handle: THandle; out Rect: TRect);
begin
Windows.GetWindowRect(Handle, Rect)
end;
procedure GetClientRect(Handle: THandle; out Rect: TRect);
begin
Windows.GetClientRect(Handle, Rect)
end;
procedure ScreenToClient(Handle: THandle; var X, Y: Integer);
var Pnt: TPoint;
begin
Pnt.X := X; Pnt.Y := Y;
Windows.ScreenToClient(Handle, Pnt);
X := Pnt.X; Y := Pnt.Y;
end;
procedure ClientToScreen(Handle: THandle; var X, Y: Integer);
var Pnt: TPoint;
begin
Pnt.X := X; Pnt.Y := Y;
Windows.ClientToScreen(Handle, Pnt);
X := Pnt.X; Y := Pnt.Y;
end;
procedure ShowWindow(Handle: THandle);
begin
Windows.ShowWindow(Handle, SW_SHOWNORMAL);
end;
procedure HideWindow(Handle: THandle);
begin
Windows.ShowWindow(Handle, SW_HIDE);
end;
procedure MinimizeWindow(Handle: THandle);
begin
Windows.ShowWindow(Handle, SW_MINIMIZE);
end;
procedure RestoreWindow(Handle: THandle);
begin
Windows.ShowWindow(Handle, SW_RESTORE);
end;
function IsWindowVisible(Handle: THandle): Boolean;
begin
Result := Windows.IsWindowVisible(Handle);
end;
procedure SetWindowCaption(Handle: THandle; const ACaption: string);
begin
Windows.SetWindowText(Handle, PChar(ACaption));
end;
procedure ObtainKeyboardState(var State: TKbdState);
begin
Windows.GetKeyboardState(TKeyboardState(State));
end;
function GetAsyncKeyState(Key: Integer): Integer;
begin
Result := Windows.GetAsyncKeyState(Key);
end;
function WMToMessage(MsgID: Cardinal; wParam, lParam: Integer): TMessage; overload;
begin
case MsgID of
WM_ACTIVATEAPP: begin
if wParam = 0 then Result := TWindowDeactivateMsg.Create else Result := TWindowActivateMsg.Create;
end;
// WM_EXITSIZEMOVE:
WM_SIZE: begin
if wParam = SIZE_MINIMIZED then
Result := TWindowMinimizeMsg.Create else
Result := TWindowResizeMsg.Create(0, 0, lParam and 65535, lParam shr 16);
end;
WM_MOVE: Result := TWindowMoveMsg.Create(lParam and 65535, lParam shr 16);
WM_CANCELMODE: Result := TCancelModeMsg.Create;
WM_CHAR: Result := TCharInputMsg.Create(Chr(wParam), lParam);
WM_SYSCOMMAND: Result := TWindowMenuCommand.Create(wParam);
else Result := TMessage.Create;
end;
Result.Flags := Result.Flags + [mfCore];
end;
function WMToMessage(const Msg: Messages.TMessage): TMessage; overload;
begin
Result := WMToMessage(Msg.Msg, Msg.WParam, Msg.LParam);
end;
function GetOSErrorStr(ErrorID: Integer): string;
var s: PChar;
begin
GetMem(s, 2000);
FormatMessage({FORMAT_MESSAGE_ALLOCATE_BUFFER or }FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS,
nil, ErrorID, 0, s, 2000, nil);
Result := s;
FreeMem(s);
end;
function ActivateWindow(Handle: THandle): Boolean;
var Input: TInput;
begin
Result:= True;
if Handle = GetForegroundWindow then Exit;
if IsWindow(Handle) then begin
Input.Itype:= Input_Mouse;
FillChar(Input.mi, SizeOf(Input.mi), 0);
SendInput(1, Input, SizeOf(Input));
Result := SetForegroundWindow(Handle);
// SetActiveWindow(hwnd);
if IsIconic(Handle) then OpenIcon(Handle);
Exit;
end;
Result:= False;
end;
function GetCurrentMs: Int64;
begin
Result := GetTickCount;
end;
procedure ObtainPerformanceFrequency;
begin
if QueryPerformanceFrequency(PerformanceFrequency) then begin
if PerformanceFrequency <> 0 then OneOverPerformanceFrequency := 1 / PerformanceFrequency else OneOverPerformanceFrequency := 0;
end else PerformanceFrequency := 0;
end;
function GetPerformanceCounter: Int64;
begin
QueryPerformanceCounter(Result);
end;
procedure OpenWith(ParentHandle: Cardinal; const FileName: string);
begin
ShellExecute(ParentHandle, 'open', PChar('rundll32.exe'),
PChar('shell32.dll,OpenAs_RunDLL ' + FileName), nil, SW_SHOWNORMAL);
end;
procedure OpenURL(const URL: string);
begin
ShellExecute(0, 'open', PChar(URL), nil, nil, SW_SHOWNORMAL);
Sleep(500); // To eliminate some bugs with timer
end;
procedure Sleep(Milliseconds: Integer);
begin
Windows.Sleep(Milliseconds);
end;
procedure Delay(Microseconds: Integer);
var Cnt, Dest: Int64;
begin
Cnt := GetPerformanceCounter;
Dest := Cnt + Microseconds * PerformanceFrequency div 1000000;
while GetPerformanceCounter < Dest do SpinWait(500);
end;
procedure Exec(const Command: string);
begin
ShellExecute({Starter.WindowHandle}0, 'open', PChar(Command), nil, nil, SW_SHOWNORMAL);
Sleep(500);
end;
function GetActiveWindow: THandle;
begin
Result := Windows.GetActiveWindow;
end;
function GetSysFolder(SysFolder: TSysFolder): string;
var
s: PChar;
p: PItemIDList;
Folder: Integer;
begin
Result := '';
p := nil;
case SysFolder of
sfRecycled: Folder := CSIDL_BITBUCKET;
sfDesktop: Folder := CSIDL_DESKTOPDIRECTORY;
sfStartMenu: Folder := CSIDL_STARTMENU;
sfPrograms: Folder := CSIDL_PROGRAMS;
sfStartup: Folder := CSIDL_STARTUP;
sfPersonal: Folder := CSIDL_PERSONAL;
sfRecent: Folder := CSIDL_RECENT;
sfNetHood: Folder := CSIDL_NETHOOD;
sfSendTo: Folder := CSIDL_SENDTO;
sfTemplates: Folder := CSIDL_TEMPLATES;
sfAppData: Folder := CSIDL_APPDATA;
// sfWinRoot: Folder :=
// sfWinSys: Folder :=
else begin
Assert(False);
Exit;
end;
end;
if (SHGetSpecialFolderLocation(0 ,Folder, p) <> NOERROR) or (p = nil) then Exit;
s := StrAlloc(MAX_PATH+1);
if SHGetPathFromIDList(p, s) then Result := s;
StrDispose(s);
end;
function GetTextFromClipboard: string;
var hg: THandle; P: PChar;
begin
OpenClipboard(0);
hg := GetClipboardData(CF_TEXT);
CloseClipboard;
P := GlobalLock(hg);
Result := Copy(P, 0, Length(P));
GlobalUnlock(hg);
end;
{$ENDIF}
{$IFDEF X11}
procedure ObtainCursorPos(out X, Y: Integer);
var
WRoot, WChild, Mask: LongWord;
rX, rY: LongInt;
begin
Assert((Xscreen.Display <> nil) and (XScreen.Window <> 0), 'Call InitX11() first!');
XQueryPointer(Xscreen.Display, XScreen.Window, @WRoot, @WChild, @rX, @rY, @X, @Y, @Mask);
end;
procedure SetCursorPos(X, Y: Integer);
begin
end;
function AdjustCursorVisibility(Show: Boolean): Integer;
begin
end;
procedure ClipCursor(Rect: TRect);
begin
end;
function GetClipCursor: TRect;
begin
end;
procedure GetWindowRect(Handle: THandle; out Rect: TRect);
begin
end;
procedure GetClientRect(Handle: THandle; out Rect: TRect);
begin
end;
procedure ScreenToClient(Handle: THandle; var X, Y: Integer);
begin
end;
procedure ClientToScreen(Handle: THandle; var X, Y: Integer);
begin
end;
procedure ShowWindow(Handle: THandle);
begin
end;
procedure HideWindow(Handle: THandle);
begin
end;
procedure MinimizeWindow(Handle: THandle);
begin
end;
procedure RestoreWindow(Handle: THandle);
begin
end;
function IsWindowVisible(Handle: THandle): Boolean;
begin
end;
procedure SetWindowCaption(Handle: THandle; const ACaption: string);
begin
end;
procedure ObtainKeyboardState(var State: TKbdState);
begin
end;
function GetAsyncKeyState(Key: Integer): Integer;
begin
end;
function WMToMessage(MsgID: Cardinal; wParam, lParam: Integer): TMessage; overload;
begin
end;
function GetOSErrorStr(ErrorID: Integer): string;
begin
end;
function ActivateWindow(Handle: THandle): Boolean;
begin
end;
function GetCurrentMs: Int64;
begin
end;
procedure ObtainPerformanceFrequency;
begin
end;
function GetPerformanceCounter: Int64;
begin
end;
procedure OpenWith(ParentHandle: Cardinal; const FileName: string);
begin
end;
procedure OpenURL(const URL: string);
begin
end;
procedure Sleep(Milliseconds: Integer);
begin
end;
procedure Delay(Microseconds: Integer);
begin
end;
procedure Exec(const Command: string);
begin
end;
function GetActiveWindow: THandle;
begin
end;
function GetSysFolder(SysFolder: TSysFolder): string;
begin
end;
function GetTextFromClipboard: string;
begin
end;
{$ENDIF}
{$IFDEF GLUT}
procedure ObtainCursorPos(out X, Y: Integer);
begin
X := GLUTState.MouseX;
Y := GLUTState.MouseY;
end;
procedure SetCursorPos(X, Y: Integer);
begin
ScreenToClient(glutGetWindow(), X, Y);
GlutWarpPointer(X, Y);
end;
function AdjustCursorVisibility(Show: Boolean): Integer;
begin
GlutState.MouseCnt := GlutState.MouseCnt + Ord(Show)*2-1;
Result := GlutState.MouseCnt;
if Result >= 0 then
glutSetCursor(GLUT_CURSOR_INHERIT)
else
glutSetCursor(GLUT_CURSOR_NONE);
end;
procedure ClipCursor(Rect: TRect);
begin
Writeln('ClipCursor: Not implemented via GLUT');
end;
function GetClipCursor: TRect;
begin
Writeln('GetClipCursor: Not implemented via GLUT');
end;
procedure GetWindowRect(Handle: THandle; out Rect: TRect);
var OldWindowId: Integer;
begin
OldWindowId := glutGetWindow();
glutSetWindow(Handle);
Rect.Left := glutGet(GLUT_WINDOW_X);
Rect.Top := glutGet(GLUT_WINDOW_Y);
Rect.Right := glutGet(GLUT_WINDOW_WIDTH) + Rect.Left;
Rect.Bottom := glutGet(GLUT_WINDOW_HEIGHT) + Rect.Top;
glutSetWindow(OldWindowId);
end;
procedure GetClientRect(Handle: THandle; out Rect: TRect);
var OldWindowId: Integer;
begin
OldWindowId := glutGetWindow();
glutSetWindow(Handle);
GetWindowRect(Handle, Rect);
Rect.Left := Rect.Left + glutGet(GLUT_WINDOW_BORDER_WIDTH) div 2;
Rect.Top := Rect.Top + glutGet(GLUT_WINDOW_BORDER_WIDTH) div 2;
Rect.Right := Rect.Right - glutGet(GLUT_WINDOW_BORDER_WIDTH) div 2;
Rect.Bottom := Rect.Bottom - glutGet(GLUT_WINDOW_BORDER_WIDTH) div 2;
glutSetWindow(OldWindowId);
end;
procedure ScreenToClient(Handle: THandle; var X, Y: Integer);
begin
X := X - glutGet(GLUT_WINDOW_X);
Y := Y - glutGet(GLUT_WINDOW_Y);
end;
procedure ClientToScreen(Handle: THandle; var X, Y: Integer);
begin
X := X + glutGet(GLUT_WINDOW_X);
Y := Y + glutGet(GLUT_WINDOW_Y);
end;
procedure ShowWindow(Handle: THandle);
var OldWindowId: Integer;
begin
OldWindowId := glutGetWindow();
glutSetWindow(Handle);
glutShowWindow();
glutSetWindow(OldWindowId);
end;
procedure HideWindow(Handle: THandle);
var OldWindowId: Integer;
begin
OldWindowId := glutGetWindow();
glutSetWindow(Handle);
glutHideWindow();
glutSetWindow(OldWindowId);
end;
procedure MinimizeWindow(Handle: THandle);
var OldWindowId: Integer;
begin
OldWindowId := glutGetWindow();
glutSetWindow(Handle);
glutIconifyWindow();
glutSetWindow(OldWindowId);
end;
procedure RestoreWindow(Handle: THandle);
begin
ShowWindow(Handle);
end;
function IsWindowVisible(Handle: THandle): Boolean;
begin
Writeln('IsWindowVisible: Not implemented via GLUT');
end;
procedure SetWindowCaption(Handle: THandle; const ACaption: string);
var OldWindowId: Integer; Caption: PChar;
begin
OldWindowId := glutGetWindow();
glutSetWindow(Handle);
Caption := PChar(ACaption);
glutSetWindowTitle(Caption);
glutSetIconTitle(Caption);
glutSetWindow(OldWindowId);
end;
procedure ObtainKeyboardState(var State: TKbdState);
begin
State := GLUTState.KbdState;
end;
function GetAsyncKeyState(Key: Integer): Integer;
begin
// Writeln('GetAsyncKeyState: Not implemented via GLUT');
end;
function WMToMessage(MsgID: Cardinal; wParam, lParam: Integer): TMessage; overload;
begin
Writeln('WMToMessage: Not implemented via GLUT');
end;
function GetOSErrorStr(ErrorID: Integer): string;
begin
Writeln('GetOSErrorStr: Not implemented via GLUT');
Result := 'Unknown';
end;
function ActivateWindow(Handle: THandle): Boolean;
begin
ShowWindow(Handle);
end;
function GetCurrentMs: Int64;
var tm: TimeVal;
begin
// Result := Trunc(TimeStampToMSecs(DateTimeToTimeStamp(Now))); // Range error?!
fpGetTimeOfDay(@tm, nil);
// writeln('time: ', tm.tv_sec);
Result := tm.tv_sec * Int64(1000) + tm.tv_usec div 1000;
end;
procedure ObtainPerformanceFrequency;
begin
end;
function GetPerformanceCounter: Int64;
begin
end;
procedure OpenWith(ParentHandle: Cardinal; const FileName: string);
begin
end;
procedure OpenURL(const URL: string);
begin
end;
procedure Sleep(Milliseconds: Integer);
begin
Writeln('Sleep: Not implemented via GLUT');
end;
procedure Delay(Microseconds: Integer);
begin
Writeln('Delay: Not implemented via GLUT');
end;
procedure Exec(const Command: string);
begin
end;
function GetActiveWindow: THandle;
begin
Writeln('GetActiveWindow: Not implemented via GLUT');
end;
function GetSysFolder(SysFolder: TSysFolder): string;
begin
end;
function GetTextFromClipboard: string;
begin
end;
{$ENDIF}
// OS independent
function GetFileModifiedTime(const FileName: string): TDateTime;
var sr: TSearchRec;
begin
Result := 0;
if SysUtils.FindFirst(FileName, faDirectory, sr) = 0 then begin
{$IFDEF DELPHIXE}
Result := sr.TimeStamp;
{$ELSE}
Result := SysUtils.FileDateToDateTime(sr.Time);
{$ENDIF}
// Writeln(' ===*** sr.time: ', sr.Time, ', sr.timestamp: ', Result);
end;
SysUtils.FindClose(sr);
end;
procedure SetCursorVisibility(Counter: Integer);
var i, Cur: Integer;
begin
Cur := AdjustCursorVisibility(True);
for i := 0 to Abs(Cur-Counter)-1 do AdjustCursorVisibility(Cur < Counter);
end;
procedure ShowCursor;
begin
SetCursorVisibility(0);
end;
procedure HideCursor;
begin
SetCursorVisibility(-1);
end;
initialization
{$IFDEF LINUX}
XScreen.Display := nil;
XScreen.Window := 0;
{$ENDIF}
{$IFDEF GLUT}
GLUTState.WindowId := 0;
GLUTState.MouseCnt := 0;
GLUTState.MouseX := 0;
GLUTState.MouseY := 0;
FillChar(GLUTState.KbdState, SizeOf(TGLUTState.KbdState), 0);
{$ENDIF}
ObtainPerformanceFrequency;
finalization
{$IFDEF LINUX}
if XScreen.Display <> nil then XCloseDisplay(XScreen.Display);
{$ENDIF}
end.