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 | |
| parent | 58bedf9610ac7a388d5951b2d57612a0d4e03ef7 (diff) | |
| download | NiGui-ab626e6f6a46f5cd03a4409fa4f1f91bb34edc49.tar.gz NiGui-ab626e6f6a46f5cd03a4409fa4f1f91bb34edc49.zip | |
Add checkbox to windows
Diffstat (limited to 'src')
| -rwxr-xr-x | src/nigui.nim | 69 | ||||
| -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 |
4 files changed, 107 insertions, 3 deletions
diff --git a/src/nigui.nim b/src/nigui.nim index e8b4e8f..b633094 100755 --- a/src/nigui.nim +++ b/src/nigui.nim @@ -353,6 +353,10 @@ type fText: string fEnabled: bool + Checkbox* = ref object of ControlImpl + fText: string + fEnabled: bool + Label* = ref object of ControlImpl fText: string @@ -879,6 +883,24 @@ method `enabled=`*(button: Button, enabled: bool) # ---------------------------------------------------------------------------------------- +# Checkbox +# ---------------------------------------------------------------------------------------- + +proc newCheckbox*(text = ""): Checkbox + +proc init*(checkbox: Checkbox) +proc init*(checkbox: NativeCheckbox) + +method text*(checkbox: Checkbox): string +method `text=`*(checkbox: Checkbox, text: string) + +method enabled*(checkbox: Checkbox): bool +method `enabled=`*(checkbox: Checkbox, enabled: bool) + +method getState*(checkbox: Checkbox): int + + +# ---------------------------------------------------------------------------------------- # Label # ---------------------------------------------------------------------------------------- @@ -2360,6 +2382,51 @@ method `onDraw=`(container: NativeButton, callback: DrawProc) = raiseError("Nati # ---------------------------------------------------------------------------------------- +# Checkbox +# ---------------------------------------------------------------------------------------- + +proc newCheckbox(text = ""): Checkbox = + result = new NativeCheckbox + result.NativeCheckbox.init() + result.text = text + +proc init(checkbox: Checkbox) = + checkbox.ControlImpl.init() + checkbox.fText = "" + checkbox.fOnClick = nil + checkbox.fWidthMode = WidthMode_Auto + checkbox.fHeightMode = HeightMode_Auto + checkbox.enabled = true + +method text(checkbox: Checkbox): string = checkbox.fText + +method `text=`(checkbox: Checkbox, text: string) = + checkbox.fText = text + checkbox.tag = text + checkbox.triggerRelayoutIfModeIsAuto() + checkbox.forceRedraw() + +method naturalWidth(checkbox: Checkbox): int = checkbox.getTextWidth(checkbox.text) + 20.scaleToDpi + +method naturalHeight(checkbox: Checkbox): int = checkbox.getTextLineHeight() * checkbox.text.countLines + 12.scaleToDpi + +method enabled(checkbox: Checkbox): bool = checkbox.fEnabled + +method `enabled=`(checkbox: Checkbox, enabled: bool) = discard + +method getState(checkbox: Checkbox): int = discard + +method handleKeyDownEvent*(checkbox: Checkbox, event: KeyboardEvent) = + if event.key == Key_Return or event.key == Key_Space: + var clickEvent = new ClickEvent + clickEvent.control = checkbox + checkbox.handleClickEvent(clickEvent) + + +method `onDraw=`(container: NativeCheckbox, callback: DrawProc) = raiseError("NativeCheckbox does not allow onDraw.") + + +# ---------------------------------------------------------------------------------------- # Label # ---------------------------------------------------------------------------------------- @@ -2490,4 +2557,4 @@ method `wrap=`(textArea: TextArea, wrap: bool) = # ---------------------------------------------------------------------------------------- when useWindows(): include "nigui/private/windows/platform_impl" -when useGtk(): include "nigui/private/gtk3/platform_impl" +when useGtk(): include "nigui/private/gtk3/platform_impl"
\ No newline at end of file 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 |
