summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/nigui.nim7
-rwxr-xr-xsrc/nigui/msgbox.nim12
-rwxr-xr-xsrc/nigui/private/gtk3/platform_impl.nim11
-rwxr-xr-xsrc/nigui/private/windows/platform_impl.nim15
4 files changed, 24 insertions, 21 deletions
diff --git a/src/nigui.nim b/src/nigui.nim
index 7f64f95..55bb1ae 100755
--- a/src/nigui.nim
+++ b/src/nigui.nim
@@ -2244,6 +2244,13 @@ method enabled(button: Button): bool = button.fEnabled
method `enabled=`(button: Button, enabled: bool) = discard
# has to be implemented by NativeTextBox
+method handleKeyDownEvent*(button: Button, event: KeyboardEvent) =
+ if event.key == Key_Return or event.key == Key_Space:
+ var clickEvent = new ClickEvent
+ clickEvent.control = button
+ button.handleClickEvent(clickEvent)
+
+
method `onDraw=`(container: NativeButton, callback: DrawProc) = raiseError("NativeButton does not allow onDraw.")
diff --git a/src/nigui/msgbox.nim b/src/nigui/msgbox.nim
index c955c03..eefb57a 100755
--- a/src/nigui/msgbox.nim
+++ b/src/nigui/msgbox.nim
@@ -3,10 +3,11 @@
# This module provides an extended message box.
# The message box is shown as modal window.
# The message box can have up to 3 buttons with customizable titles.
+# button1 will be focused.
# Call the proc msgBox() to open the message box.
# It will wait until the message box is closed.
# Meaning of the result value:
-# 0 - message box was closed over the window close button
+# 0 - message box was closed over the window close button or escape key
# 1..3 - button 1..3 clicked
# For an example see "example_04_msgboxes.nim".
@@ -26,6 +27,10 @@ proc msgBox*(parent: Window, message: string, title = "Message", button1 = "OK",
window.init()
window.title = title
+ window.onKeyDown = proc(event: KeyboardEvent) =
+ if event.key == Key_Escape:
+ window.dispose()
+
var container = newLayoutContainer(Layout_Vertical)
container.padding = 10
window.control = container
@@ -49,6 +54,7 @@ proc msgBox*(parent: Window, message: string, title = "Message", button1 = "OK",
b1.minWidth = buttonMinWidth
b1.onClick = buttonClick
buttonContainer.add(b1)
+ b1.focus()
if button2 != "":
b2 = newButton(button2)
@@ -76,7 +82,7 @@ proc msgBox*(parent: Window, message: string, title = "Message", button1 = "OK",
if window.clickedButton == b1:
result = 1
- elif window.clickedButton == b2:
+ elif window.clickedButton == b2 and b2 != nil:
result = 2
- elif window.clickedButton == b3:
+ elif window.clickedButton == b3 and b3 != nil:
result = 3
diff --git a/src/nigui/private/gtk3/platform_impl.nim b/src/nigui/private/gtk3/platform_impl.nim
index c66dfba..152f7b6 100755
--- a/src/nigui/private/gtk3/platform_impl.nim
+++ b/src/nigui/private/gtk3/platform_impl.nim
@@ -832,9 +832,9 @@ method `visible=`(control: ControlImpl, visible: bool) =
else:
gtk_widget_hide(control.fHandle)
-proc dummy(widget: pointer, event: var GdkEventButton, data: pointer): bool {.cdecl.} =
- echo "dummy"
- result = true # Stop propagation
+# proc dummy(widget: pointer, event: var GdkEventButton, data: pointer): bool {.cdecl.} =
+ # echo "dummy"
+ # result = true # Stop propagation
method pUpdateScrollBar(control: ControlImpl) =
if control.fScrollableWidth == -1 and control.fScrollableHeight == -1:
@@ -1093,7 +1093,6 @@ method getPadding(frame: NativeFrame): Spacing =
proc init(button: NativeButton) =
button.fHandle = gtk_button_new()
button.Button.init()
- # discard g_signal_connect_data(button.fHandle, "clicked", pWidgetClickSignal, cast[pointer](button))
method `text=`(button: NativeButton, text: string) =
procCall button.Button.`text=`(text)
@@ -1111,10 +1110,6 @@ method naturalWidth(button: NativeButton): int =
gtk_style_context_get_padding(context, GTK_STATE_FLAG_NORMAL, padding)
result = button.getTextLineWidth(button.text) + padding.left + padding.right + 5
-method pAddButtonPressEvent(control: NativeButton) =
- gtk_widget_add_events(control.fHandle, GDK_BUTTON_PRESS_MASK)
- discard g_signal_connect_data(control.fHandle, "button-press-event", pDefaultControlButtonPressSignal, cast[pointer](control))
-
method `enabled=`(button: NativeButton, enabled: bool) =
button.fEnabled = enabled
gtk_widget_set_sensitive(button.fHandle, enabled)
diff --git a/src/nigui/private/windows/platform_impl.nim b/src/nigui/private/windows/platform_impl.nim
index fbc833a..1b36d10 100755
--- a/src/nigui/private/windows/platform_impl.nim
+++ b/src/nigui/private/windows/platform_impl.nim
@@ -1280,16 +1280,11 @@ method getPadding(frame: NativeFrame): Spacing =
var pButtonOrigWndProc: pointer
proc pButtonWndProc(hWnd: pointer, uMsg: int32, wParam, lParam: pointer): pointer {.cdecl.} =
- case uMsg
- of WM_KEYDOWN:
- let button = cast[Button](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
- # if button != nil and (cast[int](wParam) == 13 or cast[int](wParam) == 32):
- if button != nil and cast[int](wParam) == 13:
- var event = new ClickEvent
- event.control = button
- button.handleClickEvent(event)
- else:
- discard
+ # case uMsg
+ # of WM_KEYDOWN:
+ # let button = cast[Button](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
+ # else:
+ # discard
let comProcRes = pCommonControlWndProc(hWnd, uMsg, wParam, lParam)
if comProcRes == PWndProcResult_False:
return cast[pointer](false)