-
Notifications
You must be signed in to change notification settings - Fork 51
/
platform_impl.nim
executable file
·1829 lines (1537 loc) · 70.4 KB
/
platform_impl.nim
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
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# NiGui - Win32 platform-specific code - part 3
# This file will be included in "nigui.nim".
# Idendifiers, which are only used in this file, are marked with a leading "p".
# Imports:
# math, os, strutils, times are imported by nigui.nim
import windows
import tables
import dynlib
# Link resource file to enable visual styles
# (without this, controls have Windows 95 look):
when not defined(noManifest):
when defined(i386):
{.link: "res/i386.o".}
elif defined(amd64):
{.link: "res/amd64.o".}
else:
{.fatal: "Unknown CPU architecture"}
# ----------------------------------------------------------------------------------------
# Internal Things
# ----------------------------------------------------------------------------------------
const pTopLevelWindowClass = "1"
const pContainerWindowClass = "2"
const pCustomControlWindowClass = "3"
const pWM_QUEUED = WM_USER+0
var pDefaultParentWindow: pointer
var pKeyState: KeyState
var pKeyDownKey: Key
var pQueue: int
# needed to calculate clicks:
var pLastMouseButtonDownControl: Control
var pLastMouseButtonDownControlX: int
var pLastMouseButtonDownControlY: int
var pLastMouseMoveX: int
var pLastMouseMoveY: int
var pLastMouseEnterControl: Control
var appRunning: bool
when not defined(nimv2):
template toWideCString(ws): untyped = ws
proc pRaiseLastOSError() =
let e = osLastError()
raiseError(strutils.strip(osErrorMsg(e)) & " (OS Error Code: " & $e & ")")
proc pColorToRGB32(color: Color): RGB32 =
result.red = color.red
result.green = color.green
result.blue = color.blue
proc pRgb32ToColor(color: RGB32): Color =
result.red = color.red
result.green = color.green
result.blue = color.blue
result.alpha = 255
proc pColorToARGB(color: Color): ARGB =
result.red = color.red
result.green = color.green
result.blue = color.blue
result.alpha = color.alpha
proc pUtf8ToUtf16(s: string): string =
# result is terminated with 2 null bytes
if s.len == 0:
return "\0"
var characters = MultiByteToWideChar(CP_UTF8, 0, s, s.len.int32, nil, 0) # request number of characters
if characters == 0: pRaiseLastOSError()
result = newString(characters * 2 + 1)
characters = MultiByteToWideChar(CP_UTF8, 0, s, s.len.int32, result, characters.int32) # do the conversion
result[characters * 2] = '\0'
# result[characters * 2 + 1] is set to '\0' automatically
if characters == 0: pRaiseLastOSError()
proc pUtf16ToUtf8(s: string, searchEnd = false): string =
if s.len == 0:
return ""
var characters = s.len div 2
if searchEnd:
# Search end of utf16 string:
var i = 0
while i < s.len - 1 and s[i].ord != 0:
i.inc(2)
characters = i div 2
var bytes = WideCharToMultiByte(CP_UTF8, 0, s, characters.int32, nil, 0, nil, nil) # request number of bytes
if bytes == 0: pRaiseLastOSError()
result = newString(bytes)
bytes = WideCharToMultiByte(CP_UTF8, 0, s, characters.int32, result, bytes.int32, nil, nil) # do the conversion
if bytes == 0: pRaiseLastOSError()
proc pUnicodeCharToUtf8(unicode: int): string =
var widestring = newString(2)
widestring[0] = chr(unicode mod 256)
widestring[1] = chr(unicode div 256)
result = widestring.pUtf16ToUtf8
proc pShowWindow(hWnd: pointer, nCmdShow: int32) = discard ShowWindow(hWnd, nCmdShow)
proc pSetWindowLong(hWnd: pointer, nIndex, dwNewLong: int32) =
let result = SetWindowLongA(hWnd, nIndex, dwNewLong)
if result == 0: pRaiseLastOSError()
proc pDestroyWindow(hWnd: pointer) =
let result = DestroyWindow(hWnd)
if not result: pRaiseLastOSError()
proc pSetParent(hWndChild, hWndNewParent: pointer) =
let result = SetParent(hWndChild, hWndNewParent)
if result == nil: pRaiseLastOSError()
proc pSetWindowText(hWnd: pointer, s: string) =
let result = SetWindowTextW(hWnd, s.pUtf8ToUtf16)
if not result: pRaiseLastOSError()
proc pGetWindowText(hWnd: pointer): string =
let characters = GetWindowTextLengthW(hWnd)
if characters == 0:
return
result = newString(characters * 2)
var res = GetWindowTextW(hWnd, result, characters * 2 + 1)
if res != characters: pRaiseLastOSError()
result = result.pUtf16ToUtf8
proc pSetWindowPos(wnd: pointer, x, y, cx, cy: int, uFlags: int32 = 0, hWndInsertAfter = 0) =
var result = SetWindowPos(wnd, cast[pointer](hWndInsertAfter), x.int32, y.int32, cx.int32, cy.int32, uFlags)
if not result: pRaiseLastOSError()
proc pGetClientRect(wnd: pointer): Rect =
if not GetClientRect(wnd, result): pRaiseLastOSError()
proc pGetWindowRect(wnd: pointer): Rect =
if not GetWindowRect(wnd, result): pRaiseLastOSError()
proc pCreateWindowEx(dwExStyle: int32, lpClassName: string, dwStyle: int32, x, y, nWidth, nHeight: int, hWndParent, hMenu, hInstance, lpParam: pointer): pointer =
result = CreateWindowExW(dwExStyle, lpClassName.pUtf8ToUtf16, nil, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
if result == nil: pRaiseLastOSError()
proc pGetWindowLongPtr(hWnd: pointer, nIndex: int32): pointer =
when defined(cpu64):
result = GetWindowLongPtrW(hWnd, nIndex)
else:
result = GetWindowLongW(hWnd, nIndex)
proc pSetWindowLongPtr(hWnd: pointer, nIndex: int32, dwNewLong: pointer): pointer =
when defined(cpu64):
result = SetWindowLongPtrW(hWnd, nIndex, dwNewLong)
else:
result = SetWindowLongW(hWnd, nIndex, dwNewLong)
# proc pGetStockObject(fnObject: int32): pointer =
# result = GetStockObject(fnObject)
# if result == nil: pRaiseLastOSError()
proc pCreateWindowExWithUserdata(lpClassName: string, dwStyle, dwExStyle: int32, hWndParent, userdata: pointer = nil): pointer =
result = pCreateWindowEx(dwExStyle, lpClassName, dwStyle, 0, 0, 0, 0, hWndParent, nil, nil, nil)
if userdata != nil:
discard pSetWindowLongPtr(result, GWLP_USERDATA, userdata)
# Set default font:
# discard SendMessageA(result, WM_SETFONT, pGetStockObject(DEFAULT_GUI_FONT), cast[pointer](true))
# Set window proc:
# discard pSetWindowLongPtr(result, GWLP_WNDPROC, pCommonWndProc)
proc pRegisterWindowClass(className: string, wndProc: pointer, style: int32 = 0) =
var class: WndClassEx
class.cbSize = WndClassEx.sizeof.int32
class.lpszClassName = className.pUtf8ToUtf16
class.lpfnWndProc = wndProc
class.style = style
class.hCursor = LoadCursorA(nil, cast[cstring](IDC_ARROW))
class.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)) # default background
if RegisterClassExW(class) == 0: pRaiseLastOSError()
proc pCommonWndProc(hWnd: pointer, uMsg: int32, wParam, lParam: pointer): pointer {.cdecl.} =
case uMsg
of WM_COMMAND:
if wParam.hiWord == EN_CHANGE:
let control = cast[TextBox](pGetWindowLongPtr(lParam, GWLP_USERDATA))
var evt = new TextChangeEvent
evt.control = control
control.handleTextChangeEvent(evt)
of WM_CTLCOLORSTATIC, WM_CTLCOLOREDIT:
let control = cast[ControlImpl](pGetWindowLongPtr(lParam, GWLP_USERDATA))
discard SetTextColor(wParam, control.textColor.pColorToRGB32())
discard SetBkColor(wParam, control.backgroundColor.pColorToRGB32())
if control.fBackgroundBrush == nil:
control.fBackgroundBrush = CreateSolidBrush(control.backgroundColor.pColorToRGB32)
return control.fBackgroundBrush
else:
discard
result = DefWindowProcW(hWnd, uMsg, wParam, lParam)
proc pWMParamsToKey(wParam, lParam: pointer): Key =
case cast[int32](wParam)
of VK_CONTROL, VK_SHIFT, VK_MENU:
let scancode = (cast[int32](lParam) and 0x00FF0000) shr 16
case MapVirtualKeyW(scancode, MAPVK_VSC_TO_VK_EX)
of VK_LCONTROL: result = Key_ControlL
of VK_RCONTROL: result = Key_ControlR
of VK_LSHIFT: result = Key_ShiftL
of VK_RSHIFT: result = Key_ShiftR
of VK_LMENU: result = Key_AltL
of VK_RMENU: result = Key_AltR
else: discard
of VK_PRIOR: result = Key_PageUp
of VK_NEXT: result = Key_PageDown
of VK_END: result = Key_End
of VK_HOME: result = Key_Home
of VK_LEFT: result = Key_Left
of VK_UP: result = Key_Up
of VK_RIGHT: result = Key_Right
of VK_DOWN: result = Key_Down
of VK_INSERT: result = Key_Insert
of VK_DELETE: result = Key_Delete
of VK_SNAPSHOT: result = Key_Print
of VK_OEM_PLUS: result = Key_Plus
of VK_OEM_PERIOD: result = Key_Point
of VK_OEM_COMMA: result = Key_Comma
of VK_OEM_MINUS: result = Key_Minus
of VK_RETURN:
if (cast[int32](lParam) and 0x1000000) > 0:
result = Key_NumpadEnter
else:
result = Key_Return
# the following block is probably only correct for german keyboard layout
of VK_OEM_2: result = Key_NumberSign
of VK_OEM_4: result = Key_SharpS
of VK_OEM_5: result = Key_Circumflex
of VK_OEM_102: result = Key_Less
else: result = cast[Key](cast[int32](wParam))
proc pHandleWMKEYDOWNOrWMCHAR(window: Window, control: Control, unicode: int): bool =
internalKeyDown(pKeyDownKey)
var windowEvent = new KeyboardEvent
windowEvent.window = window
windowEvent.key = pKeyDownKey
if windowEvent.key == Key_None:
echo "WM_CHAR: Unknown key value: ", unicode
return
windowEvent.unicode = unicode
windowEvent.character = unicode.pUnicodeCharToUtf8
window.handleKeyDownEvent(windowEvent)
if windowEvent.handled:
return true
if control != nil:
var controlEvent = new KeyboardEvent
controlEvent.control = control
controlEvent.key = windowEvent.key
controlEvent.unicode = windowEvent.unicode
controlEvent.character = windowEvent.character
control.handleKeyDownEvent(controlEvent)
if controlEvent.handled:
return true
# Tabstop:
if windowEvent.unicode == 9:
discard SetFocus(GetNextDlgTabItem(cast[WindowImpl](window).fHandle, cast[ControlImpl](control).fHandle, true))
proc pHandleWMKEYDOWN(window: Window, control: Control, wParam, lParam: pointer): bool =
if not GetKeyboardState(pKeyState): pRaiseLastOSError()
pKeyDownKey = pWMParamsToKey(wParam, lParam)
# Save the key for WM_CHAR, because WM_CHAR only gets the key combined with the dead key state
if pKeyDownKey != Key_Circumflex:
# When the dead key "^" on German keyboard is pressed, don't call ToUnicode(), because this would destroy the dead key state
let scancode = (cast[int32](lParam) and 0x00FF0000) shr 16
var widestring = newString(2)
let ret = ToUnicode(cast[int](wParam).int32, scancode, pKeyState, widestring, 1, 0)
if ret == 1:
return # Unicode characters are handled by WM_CHAR
result = pHandleWMKEYDOWNOrWMCHAR(window, control, 0)
proc pHandleWMCHAR(window: Window, control: Control, wParam, lParam: pointer): bool =
let unicode = cast[int](wParam)
result = pHandleWMKEYDOWNOrWMCHAR(window, control, unicode)
proc pWindowWndProc(hWnd: pointer, uMsg: int32, wParam, lParam: pointer): pointer {.cdecl.} =
case uMsg
of WM_CLOSE:
let window = cast[WindowImpl](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
window.closeClick()
return cast[pointer](true) # keeps the window open, else the window will be destroyed
of WM_SIZE:
let window = cast[WindowImpl](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
if window != nil:
var rect = pGetWindowRect(window.fHandle)
window.width = rect.right - rect.left
window.height = rect.bottom - rect.top
rect = pGetClientRect(window.fHandle)
window.fClientWidth = rect.right - rect.left
window.fClientHeight = rect.bottom - rect.top
var event = new ResizeEvent
event.window = window
window.handleResizeEvent(event)
window.triggerRelayout()
of WM_MOVE:
let window = cast[WindowImpl](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
if window != nil:
var rect = pGetWindowRect(window.fHandle)
window.fX = rect.left
window.fY = rect.top
# echo "WM_MOVE: " & $rect.left & ", " & $rect.top
of WM_SETFOCUS:
# Re-focus last focused control
let window = cast[WindowImpl](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
if window.fFocusedControl != nil:
window.fFocusedControl.focus()
of WM_KILLFOCUS:
internalAllKeysUp()
of WM_DROPFILES:
let window = cast[WindowImpl](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
var files: seq[string] = @[]
let count = DragQueryFileW(wParam, 0xFFFFFFFF.uint32, nil, 0)
for i in 0..count - 1:
let characters = DragQueryFileW(wParam, i.uint32 , nil, 0)
var filename = newString(characters * 2)
discard DragQueryFileW(wParam, i.uint32, filename, characters + 1)
files.add(filename.pUtf16ToUtf8)
DragFinish(wParam)
var event = new DropFilesEvent
event.window = window
event.files = files
window.handleDropFilesEvent(event)
of WM_KEYDOWN, WM_SYSKEYDOWN:
let window = cast[Window](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
if window != nil and pHandleWMKEYDOWN(window, nil, wParam, lParam):
return
of WM_KEYUP, WM_SYSKEYUP:
internalKeyUp(pWMParamsToKey(wParam, lParam))
of WM_CHAR:
let window = cast[Window](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
if window != nil and pHandleWMCHAR(window, nil, wParam, lParam):
return
of WM_SYSCOMMAND:
let window = cast[Window](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
if window != nil:
if cast[int](wParam) == SC_MINIMIZE:
window.fMinimized = true
elif cast[int](wParam) == SC_RESTORE:
window.fMinimized = false
of pWM_QUEUED:
let fn = cast[ptr proc()](wParam)
fn[]()
freeShared(fn)
dec pQueue
of WM_GETMINMAXINFO:
let window = cast[Window](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
if window != nil:
let minMaxInfo = cast[ptr MinMaxInfo](lParam)
minMaxInfo.ptMinTrackSize.x = window.minWidth.int32
minMaxInfo.ptMinTrackSize.y = window.minHeight.int32
else:
discard
result = pCommonWndProc(hWnd, uMsg, wParam, lParam)
proc pContainerWndProc(hWnd: pointer, uMsg: int32, wParam, lParam: pointer): pointer {.cdecl.}
proc pCustomControlWndProc(hWnd: pointer, uMsg: int32, wParam, lParam: pointer): pointer {.cdecl.}
proc pCheckGdiplusStatus(status: int32, msg = "") =
if status != 0:
if status == 7:
pRaiseLastOSError()
elif msg != "":
raiseError(msg & " (GDI+ Status: " & $status & ")")
else:
raiseError("A GDI+ error occured. (GDI+ Status: " & $status & ")")
proc pInitGdiplus() =
var input: GdiplusStartupInput
input.GdiplusVersion = 1
var gidplus: pointer
pCheckGdiplusStatus(GdiplusStartup(gidplus, input, nil))
proc pGdipCreateBitmapFromFileWrapped(filename: string, bitmap: var pointer) =
let status = GdipCreateBitmapFromFile(filename.pUtf8ToUtf16(), bitmap)
if status != 0:
if not fileExists(filename):
raiseError("Faild to load image from file '" & filename & "': File does not exist")
else:
pCheckGdiplusStatus(status, "Faild to load image from file '" & filename & "'")
proc pGetTextSize(hDC, font: pointer, text: string): Size =
let wideText = text.pUtf8ToUtf16
discard SelectObject(hdc, font)
discard GetTextExtentPoint32W(hdc, wideText, (wideText.len div 2).int32, result)
# ----------------------------------------------------------------------------------------
# App Procedures
# ----------------------------------------------------------------------------------------
proc pEnableHighDpiSupport() =
let shcoreLib = loadLib("Shcore.dll")
if shcoreLib == nil:
return
let SetProcessDpiAwareness = cast[SetProcessDpiAwarenessType](shcoreLib.symAddr("SetProcessDpiAwareness"))
if SetProcessDpiAwareness == nil:
return
discard SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
let user32Lib = loadLib("User32.dll")
if user32Lib == nil:
return
let GetDpiForWindow = cast[GetDpiForWindowType](user32Lib.symAddr("GetDpiForWindow"))
if GetDpiForWindow == nil:
return
fSystemDpi = GetDpiForWindow(pDefaultParentWindow)
fDefaultFontSize = defaultFontSizeForDefaultDpi.scaleToDpi
proc init(app: App) =
if pDefaultParentWindow != nil:
raiseError("'app.init()' must not be called a second time.")
pInitGdiplus()
pRegisterWindowClass(pTopLevelWindowClass, cast[pointer](pWindowWndProc))
pRegisterWindowClass(pCustomControlWindowClass, cast[pointer](pCustomControlWndProc), CS_HREDRAW or CS_VREDRAW)
pRegisterWindowClass(pContainerWindowClass, cast[pointer](pContainerWndProc))
pDefaultParentWindow = pCreateWindowEx(0, pTopLevelWindowClass, 0, 0, 0, 0, 0, nil, nil, nil, nil)
app.defaultTextColor = GetSysColor(COLOR_WINDOWTEXT).pRgb32ToColor()
app.defaultBackgroundColor = GetSysColor(COLOR_BTNFACE).pRgb32ToColor()
app.defaultFontFamily = "Arial"
fScrollbarSize = GetSystemMetrics(SM_CXVSCROLL)
pEnableHighDpiSupport()
appRunning = true
proc runMainLoop() =
var msg: Msg
while GetMessageW(msg.addr, nil, 0, 0) and appRunning:
discard TranslateMessage(msg.addr)
discard DispatchMessageW(msg.addr)
proc platformQuit() =
appRunning = false
proc processEvents(app: App) =
var msg: Msg
while PeekMessageW(msg.addr, nil, 0, 0, PM_REMOVE):
discard TranslateMessage(msg.addr)
discard DispatchMessageW(msg.addr)
proc queueMain(app: App, fn: proc()) =
inc pQueue
var p = createShared(proc())
p[] = fn
if (not PostMessageA(pDefaultParentWindow, pWM_QUEUED, p, nil)):
pRaiseLastOSError()
proc queued(app: App): int =
return pQueue
proc clipboardText(app: App): string =
if not OpenClipboard(nil):
return
let data = GetClipboardData(CF_TEXT)
if data == nil:
return
let text = cast[cstring](GlobalLock(data))
if text == nil:
return
result = $text
discard GlobalUnlock(data)
discard CloseClipboard()
proc `clipboardText=`(app: App, text: string) =
if not OpenClipboard(nil):
return
let size = text.len + 1
let data = GlobalAlloc(GMEM_MOVEABLE, size.int32)
if data == nil:
return
let mem = GlobalLock(data)
if mem == nil:
return
copyMem(mem, text.cstring, size)
discard GlobalUnlock(data)
discard EmptyClipboard()
discard SetClipboardData(CF_TEXT, data)
discard CloseClipboard()
# ----------------------------------------------------------------------------------------
# Dialogs
# ----------------------------------------------------------------------------------------
proc alert(window: Window, message: string, title = "Message") =
var hWnd: pointer
if window != nil:
hWnd = cast[WindowImpl](window).fHandle
MessageBoxW(hWnd, message.pUtf8ToUtf16, title.pUtf8ToUtf16, 0)
method run*(dialog: OpenFileDialog) =
const maxCharacters = 5000
dialog.files = @[]
var ofn: OpenFileName
ofn.lStructSize = OpenFileName.sizeOf.int32
ofn.lpstrTitle = dialog.title.pUtf8ToUtf16()
ofn.nMaxFile = maxCharacters
ofn.lpstrInitialDir = dialog.directory.pUtf8ToUtf16()
ofn.Flags = OFN_FILEMUSTEXIST
if dialog.multiple:
ofn.Flags = ofn.Flags or OFN_ALLOWMULTISELECT or OFN_EXPLORER
var s = newString(maxCharacters * 2)
ofn.lpstrFile = s
let ret = GetOpenFileNameW(ofn)
if ret:
var dirOrFirstFile = ""
# Split selected file names:
while s[0].ord != 0:
var i = 0
while i < s.len - 1 and s[i].ord != 0:
i.inc(2)
let filename = s.substr(0, i - 1).pUtf16ToUtf8()
if dirOrFirstFile == "":
dirOrFirstFile = filename
else:
dialog.files.add(dirOrFirstFile / filename)
s = s.substr(i + 2)
if dialog.files.len == 0:
dialog.files.add(dirOrFirstFile)
else:
let e = CommDlgExtendedError()
if e != 0:
raiseError("CommDlg Error Code: " & $e)
method run(dialog: SaveFileDialog) =
const maxCharacters = 500
dialog.file = ""
var ofn: OpenFileName
ofn.lStructSize = OpenFileName.sizeOf.int32
ofn.lpstrTitle = dialog.title.pUtf8ToUtf16()
ofn.nMaxFile = maxCharacters
ofn.lpstrInitialDir = dialog.directory.pUtf8ToUtf16()
if dialog.defaultExtension.len > 0:
ofn.lpstrDefExt = pUtf8ToUtf16(dialog.defaultExtension)
ofn.lpstrFilter = pUtf8ToUtf16(dialog.defaultExtension & "\0*." & dialog.defaultExtension & "\0All files\0*.*")
ofn.Flags = OFN_OVERWRITEPROMPT
var s = newString(maxCharacters * 2)
if dialog.defaultName.len > 0:
let temp = pUtf8ToUtf16(dialog.defaultName)
copyMem(s.cstring, temp.cstring, temp.len)
ofn.lpstrFile = s
let ret = GetSaveFileNameW(ofn)
if ret:
dialog.file = pUtf16ToUtf8(s, true)
else:
let e = CommDlgExtendedError()
if e != 0:
raiseError("CommDlg Error Code: " & $e)
method run*(dialog: SelectDirectoryDialog) =
## Notes: `dialog.startDirectory` is not supported.
const maxCharacters = 5000
dialog.selectedDirectory = ""
var bi: BrowseInfo
bi.lpszTitle = dialog.title.pUtf8ToUtf16()
bi.ulFlags = BIF_RETURNONLYFSDIRS or BIF_NEWDIALOGSTYLE
let pidl = SHBrowseForFolderW(bi)
if pidl != nil:
var s = newString(maxCharacters * 2)
SHGetPathFromIDListW(pidl, s)
dialog.selectedDirectory = pUtf16ToUtf8(s, true)
# ----------------------------------------------------------------------------------------
# Timers
# ----------------------------------------------------------------------------------------
type TimerEntry = object
timerProc: TimerProc
data: pointer
var pTimers = initTable[int64, TimerEntry]()
proc pTimerFunction(hwnd: pointer, uMsg: int32, idEvent: pointer, dwTime: int32) {.cdecl.} =
discard KillTimer(hwnd, idEvent)
let timerEntry = pTimers.getOrDefault(cast[int](idEvent))
var event = new TimerEvent
event.timer = cast[Timer](idEvent)
event.data = timerEntry.data
timerEntry.timerProc(event)
pTimers.del(cast[int](idEvent))
proc pRepeatingTimerFunction(hwnd: pointer, uMsg: int32, idEvent: pointer, dwTime: int32) {.cdecl.} =
let timerEntry = pTimers.getOrDefault(cast[int](idEvent))
var event = new TimerEvent
event.timer = cast[Timer](idEvent)
event.data = timerEntry.data
timerEntry.timerProc(event)
proc startTimer(milliSeconds: int, timerProc: TimerProc, data: pointer = nil): Timer =
result = cast[Timer](SetTimer(nil, nil, milliSeconds.int32, cast[pointer](pTimerFunction)))
var timerEntry: TimerEntry
timerEntry.timerProc = timerProc
timerEntry.data = data
pTimers[cast[int](result)] = timerEntry
proc startRepeatingTimer(milliSeconds: int, timerProc: TimerProc, data: pointer = nil): Timer =
result = cast[Timer](SetTimer(nil, nil, milliSeconds.int32, cast[pointer](pRepeatingTimerFunction)))
var timerEntry: TimerEntry
timerEntry.timerProc = timerProc
timerEntry.data = data
pTimers[cast[int](result)] = timerEntry
proc stop(timer: var Timer) =
if cast[int](timer) != inactiveTimer:
pTimers.del(cast[int](timer))
discard KillTimer(nil, cast[pointer](timer))
timer = cast[Timer](inactiveTimer)
# ----------------------------------------------------------------------------------------
# Canvas
# ----------------------------------------------------------------------------------------
proc pUpdateFont(canvas: Canvas) =
let canvasImpl = cast[CanvasImpl](canvas)
if canvasImpl.fFont == nil:
var fontFamily: pointer
pCheckGdiplusStatus(GdipCreateFontFamilyFromName(canvas.fontFamily.pUtf8ToUtf16(), nil, fontFamily))
let style: int32 =
if canvas.fontBold:
FontStyleBold
else:
FontStyleRegular
pCheckGdiplusStatus(GdipCreateFont(fontFamily, canvas.fontSize, style, UnitPixel, canvasImpl.fFont))
pCheckGdiplusStatus(GdipDeleteFontFamily(fontFamily))
proc pDeleteFont(canvas: CanvasImpl) =
if canvas.fFont != nil:
pCheckGdiplusStatus(GdipDeleteFont(canvas.fFont))
canvas.fFont = nil
proc pDeleteFontBrush(canvas: CanvasImpl) =
if canvas.fFontBrush != nil:
pCheckGdiplusStatus(GdipDeleteBrush(canvas.fFontBrush))
canvas.fFontBrush = nil
proc pDeleteAreaBrush(canvas: CanvasImpl) =
if canvas.fAreaBrush != nil:
pCheckGdiplusStatus(GdipDeleteBrush(canvas.fAreaBrush))
canvas.fAreaBrush = nil
proc pDeleteLinePen(canvas: CanvasImpl) =
if canvas.fLinePen != nil:
pCheckGdiplusStatus(GdipDeletePen(canvas.fLinePen))
canvas.fLinePen = nil
method destroy(canvas: CanvasImpl) =
procCall canvas.Canvas.destroy()
let canvasImpl = cast[CanvasImpl](canvas)
if canvasImpl.fBitmap == nil:
pDeleteFont(canvas)
pDeleteFontBrush(canvas)
pDeleteLinePen(canvas)
pDeleteAreaBrush(canvas)
if canvas.fGraphics != nil:
pCheckGdiplusStatus(GdipDeleteGraphics(canvas.fGraphics))
method drawText(canvas: Canvas, text: string, x, y = 0) =
let canvasImpl = cast[CanvasImpl](canvas)
if canvasImpl.fGraphics == nil:
raiseError("Canvas is not in drawing state.")
canvas.pUpdateFont()
if canvasImpl.fFontBrush == nil:
pCheckGdiplusStatus(GdipCreateSolidFill(canvas.textColor.pColorToARGB(), canvasImpl.fFontBrush))
var rect: RectF
rect.x = (x - 2).float
rect.y = y.float
pCheckGdiplusStatus(GdipDrawString(canvasImpl.fGraphics, text.pUtf8ToUtf16(), -1, canvasImpl.fFont, rect, nil, canvasImpl.fFontBrush))
method drawLine(canvas: Canvas, x1, y1, x2, y2: int) =
let canvasImpl = cast[CanvasImpl](canvas)
if canvasImpl.fGraphics == nil:
raiseError("Canvas is not in drawing state.")
if canvasImpl.fLinePen == nil:
pCheckGdiplusStatus(GdipCreatePen1(canvas.lineColor.pColorToARGB(), canvasImpl.lineWidth, UnitPixel, canvasImpl.fLinePen))
pCheckGdiplusStatus(GdipDrawLineI(canvasImpl.fGraphics, canvasImpl.fLinePen, x1.int32, y1.int32, x2.int32, y2.int32))
method drawRectArea(canvas: Canvas, x, y, width, height: int) =
let canvasImpl = cast[CanvasImpl](canvas)
if canvasImpl.fGraphics == nil:
raiseError("Canvas is not in drawing state.")
if canvasImpl.fAreaBrush == nil:
pCheckGdiplusStatus(GdipCreateSolidFill(canvas.areaColor.pColorToARGB(), canvasImpl.fAreaBrush))
pCheckGdiplusStatus(GdipFillRectangleI(canvasImpl.fGraphics, canvasImpl.fAreaBrush, x.int32, y.int32, width.int32, height.int32))
method drawRectOutline(canvas: Canvas, x, y, width, height: int) =
let canvasImpl = cast[CanvasImpl](canvas)
if canvasImpl.fGraphics == nil:
raiseError("Canvas is not in drawing state.")
var pen: pointer
pCheckGdiplusStatus(GdipCreatePen1(canvas.lineColor.pColorToARGB(), canvasImpl.lineWidth, UnitPixel, pen))
pCheckGdiplusStatus(GdipDrawRectangleI(canvasImpl.fGraphics, pen, x.int32, y.int32, width.int32, height.int32))
method drawEllipseArea(canvas: Canvas, x, y, width, height: int) =
let canvasImpl = cast[CanvasImpl](canvas)
if canvasImpl.fGraphics == nil:
raiseError("Canvas is not in drawing state.")
if canvasImpl.fAreaBrush == nil:
pCheckGdiplusStatus(GdipCreateSolidFill(canvas.areaColor.pColorToARGB(), canvasImpl.fAreaBrush))
pCheckGdiplusStatus(GdipFillEllipseI(canvasImpl.fGraphics, canvasImpl.fAreaBrush, x.int32, y.int32, width.int32, height.int32))
method drawEllipseOutline(canvas: Canvas, x, y, width, height: int) =
let canvasImpl = cast[CanvasImpl](canvas)
if canvasImpl.fGraphics == nil:
raiseError("Canvas is not in drawing state.")
var pen: pointer
pCheckGdiplusStatus(GdipCreatePen1(canvas.lineColor.pColorToARGB(), canvasImpl.lineWidth, UnitPixel, pen))
pCheckGdiplusStatus(GdipDrawEllipseI(canvasImpl.fGraphics, pen, x.int32, y.int32, width.int32, height.int32))
proc pRadToDegree(angleRad: float): float = angleRad / 2 / PI * 360
method drawArcOutline(canvas: Canvas, centerX, centerY: int, radius, startAngle, sweepAngle: float) =
let canvasImpl = cast[CanvasImpl](canvas)
if canvasImpl.fGraphics == nil:
raiseError("Canvas is not in drawing state.")
var pen: pointer
pCheckGdiplusStatus(GdipCreatePen1(canvas.lineColor.pColorToARGB(), canvasImpl.lineWidth, UnitPixel, pen))
let x = centerX.float - radius
let y = centerY.float - radius
let width = radius * 2
let height = radius * 2
pCheckGdiplusStatus(GdipDrawArc(canvasImpl.fGraphics, pen, x, y, width, height, startAngle.pRadToDegree(), sweepAngle.pRadToDegree()))
method drawImage(canvas: Canvas, image: Image, x, y = 0, width, height = -1) =
var drawWith = image.width
var drawHeight = image.height
if width != -1:
drawWith = width
drawHeight = int(drawHeight * drawWith / image.width)
if height != -1:
drawHeight = height
let canvasImpl = cast[CanvasImpl](canvas)
let imageCanvas = cast[CanvasImpl](image.canvas)
if canvasImpl.fGraphics == nil:
raiseError("Canvas is not in drawing state.")
pCheckGdiplusStatus(GdipDrawImageRectI(canvasImpl.fGraphics, imageCanvas.fBitmap, x.int32, y.int32, drawWith.int32, drawHeight.int32))
method setPixel(canvas: Canvas, x, y: int, color: Color) =
let canvasImpl = cast[CanvasImpl](canvas)
if canvasImpl.fBitmap == nil:
if canvasImpl.fDC == nil:
raiseError("Canvas is not in drawing state.")
discard SetPixel(canvasImpl.fDC, x.int32, y.int32, color.pColorToRGB32)
else:
let imageCanvas = cast[CanvasImpl](canvas)
pCheckGdiplusStatus(GdipBitmapSetPixel(imageCanvas.fBitmap, x.int32, y.int32, color.pColorToARGB()))
method `fontFamily=`(canvas: CanvasImpl, fontFamily: string) =
procCall canvas.Canvas.`fontFamily=`(fontFamily)
canvas.pDeleteFont()
method `fontSize=`(canvas: CanvasImpl, fontSize: float) =
procCall canvas.Canvas.`fontSize=`(fontSize)
canvas.pDeleteFont()
method `fontBold=`(canvas: CanvasImpl, fontBold: bool) =
procCall canvas.Canvas.`fontBold=`(fontBold)
canvas.pDeleteFont()
method `textColor=`(canvas: CanvasImpl, color: Color) =
procCall canvas.Canvas.`textColor=`(color)
canvas.pDeleteFontBrush()
method `lineColor=`(canvas: CanvasImpl, color: Color) =
procCall canvas.Canvas.`lineColor=`(color)
pDeleteLinePen(canvas)
method `areaColor=`(canvas: CanvasImpl, color: Color) =
procCall canvas.Canvas.`areaColor=`(color)
pDeleteAreaBrush(canvas)
proc pGetTextSize(canvas: Canvas, text: string): Size =
let canvasImpl = cast[CanvasImpl](canvas)
canvas.pUpdateFont()
var rect: RectF
var boundingBox: RectF
pCheckGdiplusStatus(GdipMeasureString(canvasImpl.fGraphics, text.pUtf8ToUtf16(), -1, canvasImpl.fFont, rect, nil, boundingBox, nil, nil))
result.cx = boundingBox.width.int32 - 4
result.cy = boundingBox.height.int32
method getTextLineWidth(canvas: CanvasImpl, text: string): int = canvas.pGetTextSize(text).cx
method getTextLineHeight(canvas: CanvasImpl): int = canvas.pGetTextSize("a").cy
method `interpolationMode=`(canvas: CanvasImpl, mode: InterpolationMode) =
procCall canvas.Canvas.`interpolationMode=`(mode)
if canvas.fGraphics == nil:
raiseError("Canvas is not in drawing state.")
let nativeMode =
case mode:
of InterpolationMode_Default: windows.InterpolationMode_Default
of InterpolationMode_NearestNeighbor: windows.InterpolationMode_NearestNeighbor
of InterpolationMode_Bilinear: windows.InterpolationMode_Bilinear
pCheckGdiplusStatus(GdipSetInterpolationMode(canvas.fGraphics, nativeMode.int32))
# ----------------------------------------------------------------------------------------
# Image
# ----------------------------------------------------------------------------------------
method resize(image: Image, width, height: int) =
let canvas = cast[CanvasImpl](image.canvas)
if canvas.fBitmap != nil:
pCheckGdiplusStatus(GdipDisposeImage(canvas.fBitmap))
pCheckGdiplusStatus(GdipDeleteGraphics(canvas.fGraphics))
canvas.fBitmap = nil
canvas.fGraphics = nil
var dc = CreateCompatibleDC(nil)
pCheckGdiplusStatus(GdipCreateFromHDC(dc, canvas.fGraphics))
pCheckGdiplusStatus(GdipCreateBitmapFromGraphics(width.int32, height.int32, canvas.fGraphics, canvas.fBitmap))
pCheckGdiplusStatus(GdipGetImageGraphicsContext(canvas.fBitmap, canvas.fGraphics)) # it's a new Graphic
image.canvas.fWidth = width
image.canvas.fHeight = height
pCheckGdiplusStatus(GdipSetTextRenderingHint(canvas.fGraphics, TextRenderingHint_AntiAlias))
method loadFromFile(image: Image, filePath: string) =
let canvas = cast[CanvasImpl](image.canvas)
if canvas.fBitmap != nil:
pCheckGdiplusStatus(GdipDisposeImage(canvas.fBitmap))
pCheckGdiplusStatus(GdipDeleteGraphics(canvas.fGraphics))
canvas.fBitmap = nil
canvas.fGraphics = nil
image.canvas.fWidth = 0
image.canvas.fHeight = 0
pGdipCreateBitmapFromFileWrapped(filePath, canvas.fBitmap)
pCheckGdiplusStatus(GdipGetImageGraphicsContext(canvas.fBitmap, canvas.fGraphics))
var width, height: int32
pCheckGdiplusStatus(GdipGetImageWidth(canvas.fBitmap, width))
pCheckGdiplusStatus(GdipGetImageHeight(canvas.fBitmap, height))
image.canvas.fWidth = width
image.canvas.fHeight = height
method saveToBitmapFile(image: Image, filePath: string) =
let canvas = cast[CanvasImpl](image.canvas)
var clsidEncoder: GUID
clsidEncoder.Data1 = 0x557cf400
clsidEncoder.Data2 = 0x11d31a04
clsidEncoder.Data3 = 0x0000739a
clsidEncoder.Data4 = 0x2ef31ef8
pCheckGdiplusStatus(GdipSaveImageToFile(canvas.fBitmap, filePath.pUtf8ToUtf16(), clsidEncoder.addr, nil))
method saveToPngFile(image: Image, filePath: string) =
let canvas = cast[CanvasImpl](image.canvas)
var clsidEncoder: GUID
clsidEncoder.Data1 = 0x557cf406
clsidEncoder.Data2 = 0x11d31a04
clsidEncoder.Data3 = 0x0000739a
clsidEncoder.Data4 = 0x2ef31ef8
pCheckGdiplusStatus(GdipSaveImageToFile(canvas.fBitmap, filePath.pUtf8ToUtf16(), clsidEncoder.addr, nil))
method saveToJpegFile(image: Image, filePath: string, quality = 80) =
let canvas = cast[CanvasImpl](image.canvas)
var clsidEncoder: GUID
clsidEncoder.Data1 = 0x557cf401
clsidEncoder.Data2 = 0x11d31a04
clsidEncoder.Data3 = 0x0000739a
clsidEncoder.Data4 = 0x2ef31ef8
# TODO: pass quality
pCheckGdiplusStatus(GdipSaveImageToFile(canvas.fBitmap, filePath.pUtf8ToUtf16(), clsidEncoder.addr, nil))
method beginPixelDataAccess(image: Image): ptr UncheckedArray[byte] =
let imageImpl = cast[ImageImpl](image)
let canvas = cast[CanvasImpl](image.canvas)
var rect: Rect
rect.left = 0
rect.top = 0
rect.right = image.width.int32
rect.bottom = image.height.int32
pCheckGdiplusStatus(GdipBitmapLockBits(canvas.fBitmap, rect, ImageLockModeWrite, PixelFormat32bppARGB, imageImpl.bitmapDataLockBits))
result = imageImpl.bitmapDataLockBits.Scan0
method endPixelDataAccess(image: Image) =
let imageImpl = cast[ImageImpl](image)
let canvas = cast[CanvasImpl](image.canvas)
pCheckGdiplusStatus(GdipBitmapUnlockBits(canvas.fBitmap, imageImpl.bitmapDataLockBits))
# ----------------------------------------------------------------------------------------
# Window
# ----------------------------------------------------------------------------------------
proc init(window: WindowImpl) =
if pDefaultParentWindow == nil:
raiseError("'app.init()' needs to be called before creating a Window.")
var dwStyle: int32 = WS_CAPTION or WS_SYSMENU or WS_THICKFRAME or WS_MINIMIZEBOX or WS_MAXIMIZEBOX
window.fHandle = pCreateWindowExWithUserdata(pTopLevelWindowClass, dwStyle, 0, nil, cast[pointer](window))
DragAcceptFiles(window.fHandle, true)
window.Window.init()
method destroy(window: WindowImpl) =
if window.fModalParent != nil:
discard EnableWindow(window.fModalParent.fHandle, true)
procCall window.Window.destroy()
pDestroyWindow(window.fHandle)
window.fHandle = nil
method `visible=`(window: WindowImpl, visible: bool) =
procCall window.Window.`visible=`(visible)
if visible:
# pShowWindow(window.fHandle, SW_SHOW)
pShowWindow(window.fHandle, SW_RESTORE)
else:
pShowWindow(window.fHandle, SW_HIDE)
method showModal(window: WindowImpl, parent: Window) =
# Overwrite base method
# Set window owner, to hide it from the taskbar
discard pSetWindowLongPtr(window.fHandle, GWL_HWNDPARENT, cast[WindowImpl](parent).fHandle)
# Hide minimize and maximize buttons:
pSetWindowLong(window.fHandle, GWL_STYLE, WS_CAPTION or WS_THICKFRAME or WS_SYSMENU)
# pSetWindowLong(window.fHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW) # does not look good
window.fModalParent = cast[WindowImpl](parent)
window.visible = true
discard EnableWindow(cast[WindowImpl](parent).fHandle, false)
method minimize(window: WindowImpl) =
procCall window.Window.minimize()
pShowWindow(window.fHandle, SW_MINIMIZE)
method `alwaysOnTop=`(window: WindowImpl, alwaysOnTop: bool) =
procCall window.Window.`alwaysOnTop=`(alwaysOnTop)
if alwaysOnTop:
pSetWindowPos(window.fHandle, -1, -1, -1, -1, SWP_NOSIZE or SWP_NOMOVE, HWND_TOPMOST)
else:
pSetWindowPos(window.fHandle, -1, -1, -1, -1, SWP_NOSIZE or SWP_NOMOVE, HWND_NOTOPMOST)
proc pUpdatePosition(window: WindowImpl) =
pSetWindowPos(window.fHandle, window.x, window.y, -1, -1, SWP_NOSIZE)
# discard MoveWindow(window.fHandle, window.x.int32, window.y.int32, window.width.int32, window.height.int32, false)
# no difference
proc pUpdateSize(window: WindowImpl) = pSetWindowPos(window.fHandle, -1, -1, window.width, window.height, SWP_NOMOVE)
method `x=`(window: WindowImpl, x: int) =
procCall window.Window.`x=`(x)
window.pUpdatePosition()
method `y=`(window: WindowImpl, y: int) =
procCall window.Window.`y=`(y)
window.pUpdatePosition()
method centerOnScreen(window: WindowImpl) =
# center on the screen which has the mouse cursor
var cursorPos: Point
discard GetCursorPos(cursorPos)
var monitorHandle = MonitorFromPoint(cursorPos, 0)
var mi: MonitorInfo
mi.cbSize = MonitorInfo.sizeOf.int32
if GetMonitorInfoA(monitorHandle, mi):
window.fX = mi.rcWork.left + (mi.rcWork.right - mi.rcWork.left - window.width) div 2
window.fY = mi.rcWork.top + (mi.rcWork.bottom - mi.rcWork.top - window.height) div 2
window.pUpdatePosition()
method `width=`*(window: WindowImpl, width: int) =
procCall window.Window.`width=`(width)
window.pUpdateSize()
method `height=`*(window: WindowImpl, height: int) =
procCall window.Window.`height=`(height)
window.pUpdateSize()
method `minWidth=`(window: WindowImpl, minWidth: int) =
procCall window.Window.`minWidth=`(minWidth)
#pUpdateMinSize(window)
method `minHeight=`(window: WindowImpl, minHeight: int) =
procCall window.Window.`minHeight=`(minHeight)
#pUpdateMinSize(window)
method `resizable=`(window: WindowImpl, resizable: bool) =
procCall window.Window.`resizable=`(resizable)
if resizable:
pSetWindowLong(window.fHandle, GWL_STYLE, WS_CAPTION or WS_SYSMENU or WS_THICKFRAME)
else:
pSetWindowLong(window.fHandle, GWL_STYLE, WS_CAPTION or WS_SYSMENU)
window.pUpdatePosition()
method `title=`(window: WindowImpl, title: string) =
procCall window.Window.`title=`(title)
pSetWindowText(window.fHandle, window.title)
method `control=`(window: WindowImpl, control: Control) =