diff options
| author | Phillips <jphillips@lsisolutions.com> | 2019-09-09 15:40:29 -0400 |
|---|---|---|
| committer | Phillips <jphillips@lsisolutions.com> | 2019-09-09 15:40:29 -0400 |
| commit | ab626e6f6a46f5cd03a4409fa4f1f91bb34edc49 (patch) | |
| tree | d5383f04b132966bf874d02ae1b2fadc70d2ffc9 /src/nigui | |
| parent | 58bedf9610ac7a388d5951b2d57612a0d4e03ef7 (diff) | |
| download | NiGui-ab626e6f6a46f5cd03a4409fa4f1f91bb34edc49.tar.gz NiGui-ab626e6f6a46f5cd03a4409fa4f1f91bb34edc49.zip | |
Add checkbox to windows
Diffstat (limited to 'src/nigui')
| -rwxr-xr-x | src/nigui/private/windows/platform_impl.nim | 32 | ||||
| -rwxr-xr-x | src/nigui/private/windows/platform_types2.nim | 2 | ||||
| -rwxr-xr-x | src/nigui/private/windows/windows.nim | 7 |
3 files changed, 39 insertions, 2 deletions
diff --git a/src/nigui/private/windows/platform_impl.nim b/src/nigui/private/windows/platform_impl.nim index ff8b48a..d62ef22 100755 --- a/src/nigui/private/windows/platform_impl.nim +++ b/src/nigui/private/windows/platform_impl.nim @@ -1410,6 +1410,36 @@ method `enabled=`(button: NativeButton, enabled: bool) = button.fEnabled = enabled discard EnableWindow(button.fHandle, enabled) +# ---------------------------------------------------------------------------------------- +# Checkbox +# ---------------------------------------------------------------------------------------- + +var pCheckboxOrigWndProc: pointer + +proc pCheckboxWndProc(hWnd: pointer, uMsg: int32, wParam, lParam: pointer): pointer {.cdecl.} = + let comProcRes = pCommonControlWndProc(hWnd, uMsg, wParam, lParam) + if comProcRes == PWndProcResult_False: + return cast[pointer](false) + if comProcRes == PWndProcResult_True: + return cast[pointer](true) + result = CallWindowProcW(pCheckboxOrigWndProc, hWnd, uMsg, wParam, lParam) + +proc init(checkbox: NativeCheckbox) = + checkbox.fHandle = pCreateWindowExWithUserdata("BUTTON", WS_CHILD or BS_AUTOCHECKBOX, 0, pDefaultParentWindow, cast[pointer](checkbox)) + pCheckboxOrigWndProc = pSetWindowLongPtr(checkbox.fHandle, GWLP_WNDPROC, pCheckboxWndProc) + checkbox.Checkbox.init() + +method `text=`(checkbox: NativeCheckbox, text: string) = + procCall checkbox.Checkbox.`text=`(text) + pSetWindowText(checkbox.fHandle, text) + +method `enabled=`(checkbox: NativeCheckbox, enabled: bool) = + checkbox.fEnabled = enabled + discard EnableWindow(checkbox.fHandle, enabled) + +method getState(checkbox: NativeCheckbox): int = + result = loWord(SendMessageA(checkbox.fHandle, BM_GETCHECK, cast[pointer](0), cast[pointer](0))) + # ---------------------------------------------------------------------------------------- # Label @@ -1528,4 +1558,4 @@ method `wrap=`(textArea: NativeTextArea, wrap: bool) = # TODO: allow to enable/disable word draw at runtime # It seems that this is not possible. # Word wrap depends on whether dwStyle contains WS_HSCROLL at window creation. - # Changing the style later has not the wanted effect. + # Changing the style later has not the wanted effect.
\ No newline at end of file diff --git a/src/nigui/private/windows/platform_types2.nim b/src/nigui/private/windows/platform_types2.nim index 120f15f..0dfe32b 100755 --- a/src/nigui/private/windows/platform_types2.nim +++ b/src/nigui/private/windows/platform_types2.nim @@ -11,6 +11,8 @@ type NativeButton* = ref object of Button
+ NativeCheckbox* = ref object of Checkbox
+
NativeLabel* = ref object of Label
NativeTextBox* = ref object of TextBox
diff --git a/src/nigui/private/windows/windows.nim b/src/nigui/private/windows/windows.nim index ed1420e..d271cac 100755 --- a/src/nigui/private/windows/windows.nim +++ b/src/nigui/private/windows/windows.nim @@ -37,8 +37,12 @@ const BN_CLICKED* = 0 BM_SETSTYLE* = 244 BM_SETIMAGE* = 247 + BM_GETCHECK* = 0x00F0 BS_DEFPUSHBUTTON* = 0x00000001 + BS_AUTOCHECKBOX* = 0x00000003 BS_GROUPBOX* = 0x00000007 + BST_UNCHECKED* = 0x0000 + BST_CHECKED* = 0x0001 CF_TEXT* = 1 COLOR_BTNFACE* = 15 COLOR_WINDOW* = 5 @@ -166,6 +170,7 @@ const WS_THICKFRAME* = 0x00040000 WS_VSCROLL* = 0x00200000 WS_EX_CONTROLPARENT* = 0x00010000 + WS_VISIBLE* = 0x10000000 # DT_CALCRECT* = 1024 # OBJ_FONT* = 6 # SM_XVIRTUALSCREEN* = 76 @@ -543,4 +548,4 @@ proc GetSaveFileNameW*(lpofn: var OpenFileName): bool {.importc: "GetSaveFileNam # Shcore Procs # ---------------------------------------------------------------------------------------- -type SetProcessDpiAwarenessType* = proc(value: int32): int32 {.gcsafe, stdcall.} # not available on Windows 7 +type SetProcessDpiAwarenessType* = proc(value: int32): int32 {.gcsafe, stdcall.} # not available on Windows 7
\ No newline at end of file |
