Skip to content

Commit

Permalink
FEAT: [GTK] support tri-state CHECK face
Browse files Browse the repository at this point in the history
  • Loading branch information
9214 authored and qtxie committed May 5, 2020
1 parent 5f42b0b commit 8807332
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
8 changes: 5 additions & 3 deletions modules/view/backends/gtk3/events.reds
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ Red/System [
gui-evt: declare red-event! ;-- low-level event value slot
gui-evt/header: TYPE_EVENT

modal-loop-type: 0 ;-- remanence of last EVT_MOVE or EVT_SIZE
check-handler: 0 ;-- for blocking signal propagation during check's state update

modal-loop-type: 0 ;-- remanence of last EVT_MOVE or EVT_SIZE
zoom-distance: 0
special-key: -1 ;-- <> -1 if a non-displayable key is pressed
special-key: -1 ;-- <> -1 if a non-displayable key is pressed

flags-blk: declare red-block! ;-- static block value for event/flags
flags-blk/header: TYPE_BLOCK
Expand Down Expand Up @@ -1024,7 +1026,7 @@ connect-widget-events: func [

case [
sym = check [
gobj_signal_connect(widget "toggled" :button-toggled widget)
check-handler: gobj_signal_connect(widget "toggled" :button-toggled widget) ;-- used to block signal
]
sym = radio [
0
Expand Down
45 changes: 33 additions & 12 deletions modules/view/backends/gtk3/handlers.reds
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,43 @@ vbar-value-changed: func [

button-toggled: func [
[cdecl]
evbox [handle!]
button [handle!]
evbox [handle!]
button [handle!]
/local
bool [red-logic!]
type [integer!]
undetermined? [logic!]
values [red-value!]
bool [red-logic!]
type [red-word!]
flags [integer!]
sym [integer!]
tri? [logic!]
toggled? [logic!]
mixed? [logic!]
][
bool: (as red-logic! get-face-values button) + FACE_OBJ_DATA
undetermined?: gtk_toggle_button_get_inconsistent button

either undetermined? [
type: TYPE_OF(bool)
bool/header: TYPE_NONE ;-- NONE indicates undeterminate
values: get-face-values button
bool: as red-logic! values + FACE_OBJ_DATA
type: as red-word! values + FACE_OBJ_TYPE
flags: get-flags as red-block! values + FACE_OBJ_FLAGS

sym: symbol/resolve type/symbol
tri?: flags and FACET_FLAGS_TRISTATE <> 0
toggled?: gtk_toggle_button_get_active button

either all [sym = check tri?][
mixed?: gtk_toggle_button_get_inconsistent button
if toggled? [
gtk_toggle_button_set_inconsistent button not mixed? ;-- flip on each toggle
unless mixed? [ ;-- N Y
g_signal_handler_block button check-handler ;-- [ ] <-> [v] <-> [-]
gtk_toggle_button_set_active button no ;-- |--- emulate ---^
g_signal_handler_unblock button check-handler
bool/header: TYPE_NONE
]
]
][
bool/value: gtk_toggle_button_get_active button
bool/header: TYPE_LOGIC
bool/value: toggled?
]

make-event button 0 EVT_CHANGE
]

Expand Down

0 comments on commit 8807332

Please sign in to comment.