diff options
Diffstat (limited to 'src/ui/widget.c')
-rw-r--r-- | src/ui/widget.c | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c index b3f7b27f..47522dbe 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c | |||
@@ -81,7 +81,7 @@ void deinit_Widget(iWidget *d) { | |||
81 | //#endif | 81 | //#endif |
82 | deinit_String(&d->id); | 82 | deinit_String(&d->id); |
83 | if (d->flags & keepOnTop_WidgetFlag) { | 83 | if (d->flags & keepOnTop_WidgetFlag) { |
84 | removeAll_PtrArray(onTop_RootData(), d); | 84 | removeAll_PtrArray(onTop_Root(get_Root()), d); |
85 | } | 85 | } |
86 | if (d->flags & visualOffset_WidgetFlag) { | 86 | if (d->flags & visualOffset_WidgetFlag) { |
87 | removeTicker_App(visualOffsetAnimation_Widget_, d); | 87 | removeTicker_App(visualOffsetAnimation_Widget_, d); |
@@ -95,10 +95,10 @@ static void aboutToBeDestroyed_Widget_(iWidget *d) { | |||
95 | return; | 95 | return; |
96 | } | 96 | } |
97 | if (flags_Widget(d) & keepOnTop_WidgetFlag) { | 97 | if (flags_Widget(d) & keepOnTop_WidgetFlag) { |
98 | removeOne_PtrArray(onTop_RootData(), d); | 98 | removeOne_PtrArray(onTop_Root(get_Root()), d); |
99 | } | 99 | } |
100 | if (isHover_Widget(d)) { | 100 | if (isHover_Widget(d)) { |
101 | data_Root()->hover = NULL; | 101 | get_Root()->hover = NULL; |
102 | } | 102 | } |
103 | iForEach(ObjectList, i, d->children) { | 103 | iForEach(ObjectList, i, d->children) { |
104 | aboutToBeDestroyed_Widget_(as_Widget(i.object)); | 104 | aboutToBeDestroyed_Widget_(as_Widget(i.object)); |
@@ -111,10 +111,11 @@ void destroy_Widget(iWidget *d) { | |||
111 | postRefresh_App(); | 111 | postRefresh_App(); |
112 | } | 112 | } |
113 | aboutToBeDestroyed_Widget_(d); | 113 | aboutToBeDestroyed_Widget_(d); |
114 | if (!data_Root()->pendingDestruction) { | 114 | iRoot *root = get_Root(); |
115 | data_Root()->pendingDestruction = new_PtrSet(); | 115 | if (!root->pendingDestruction) { |
116 | root->pendingDestruction = new_PtrSet(); | ||
116 | } | 117 | } |
117 | insert_PtrSet(data_Root()->pendingDestruction, d); | 118 | insert_PtrSet(root->pendingDestruction, d); |
118 | } | 119 | } |
119 | } | 120 | } |
120 | 121 | ||
@@ -138,7 +139,7 @@ void setFlags_Widget(iWidget *d, int64_t flags, iBool set) { | |||
138 | } | 139 | } |
139 | iChangeFlags(d->flags, flags, set); | 140 | iChangeFlags(d->flags, flags, set); |
140 | if (flags & keepOnTop_WidgetFlag) { | 141 | if (flags & keepOnTop_WidgetFlag) { |
141 | iPtrArray *onTop = onTop_RootData(); | 142 | iPtrArray *onTop = onTop_Root(get_Root()); |
142 | if (set) { | 143 | if (set) { |
143 | iAssert(indexOf_PtrArray(onTop, d) == iInvalidPos); | 144 | iAssert(indexOf_PtrArray(onTop, d) == iInvalidPos); |
144 | pushBack_PtrArray(onTop, d); | 145 | pushBack_PtrArray(onTop, d); |
@@ -186,7 +187,7 @@ void showCollapsed_Widget(iWidget *d, iBool show) { | |||
186 | if ((isVisible && !show) || (!isVisible && show)) { | 187 | if ((isVisible && !show) || (!isVisible && show)) { |
187 | setFlags_Widget(d, hidden_WidgetFlag, !show); | 188 | setFlags_Widget(d, hidden_WidgetFlag, !show); |
188 | /* The entire UI may be affected, if parents are resized due to the (un)collapsing. */ | 189 | /* The entire UI may be affected, if parents are resized due to the (un)collapsing. */ |
189 | arrange_Widget(get_Window()->root); | 190 | arrange_Widget(get_Window()->root.widget); |
190 | postRefresh_App(); | 191 | postRefresh_App(); |
191 | } | 192 | } |
192 | } | 193 | } |
@@ -733,7 +734,7 @@ static iBool filterEvent_Widget_(const iWidget *d, const SDL_Event *ev) { | |||
733 | } | 734 | } |
734 | 735 | ||
735 | void unhover_Widget(void) { | 736 | void unhover_Widget(void) { |
736 | data_Root()->hover = NULL; | 737 | get_Root()->hover = NULL; |
737 | } | 738 | } |
738 | 739 | ||
739 | iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) { | 740 | iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) { |
@@ -743,14 +744,14 @@ iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) { | |||
743 | /* Hover widget may change. */ | 744 | /* Hover widget may change. */ |
744 | setHover_Widget(NULL); | 745 | setHover_Widget(NULL); |
745 | } | 746 | } |
746 | if (data_Root()->focus && isKeyboardEvent_(ev)) { | 747 | if (get_Root()->focus && isKeyboardEvent_(ev)) { |
747 | /* Root dispatches keyboard events directly to the focused widget. */ | 748 | /* Root dispatches keyboard events directly to the focused widget. */ |
748 | if (dispatchEvent_Widget(data_Root()->focus, ev)) { | 749 | if (dispatchEvent_Widget(get_Root()->focus, ev)) { |
749 | return iTrue; | 750 | return iTrue; |
750 | } | 751 | } |
751 | } | 752 | } |
752 | /* Root offers events first to widgets on top. */ | 753 | /* Root offers events first to widgets on top. */ |
753 | iReverseForEach(PtrArray, i, data_Root()->onTop) { | 754 | iReverseForEach(PtrArray, i, get_Root()->onTop) { |
754 | iWidget *widget = *i.value; | 755 | iWidget *widget = *i.value; |
755 | if (isVisible_Widget(widget) && dispatchEvent_Widget(widget, ev)) { | 756 | if (isVisible_Widget(widget) && dispatchEvent_Widget(widget, ev)) { |
756 | #if 0 | 757 | #if 0 |
@@ -774,7 +775,7 @@ iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) { | |||
774 | } | 775 | } |
775 | } | 776 | } |
776 | else if (ev->type == SDL_MOUSEMOTION && | 777 | else if (ev->type == SDL_MOUSEMOTION && |
777 | (!data_Root()->hover || hasParent_Widget(d, data_Root()->hover)) && | 778 | (!get_Root()->hover || hasParent_Widget(d, get_Root()->hover)) && |
778 | flags_Widget(d) & hover_WidgetFlag && ~flags_Widget(d) & hidden_WidgetFlag && | 779 | flags_Widget(d) & hover_WidgetFlag && ~flags_Widget(d) & hidden_WidgetFlag && |
779 | ~flags_Widget(d) & disabled_WidgetFlag) { | 780 | ~flags_Widget(d) & disabled_WidgetFlag) { |
780 | if (contains_Widget(d, init_I2(ev->motion.x, ev->motion.y))) { | 781 | if (contains_Widget(d, init_I2(ev->motion.x, ev->motion.y))) { |
@@ -792,7 +793,7 @@ iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) { | |||
792 | handle the events first. */ | 793 | handle the events first. */ |
793 | iReverseForEach(ObjectList, i, d->children) { | 794 | iReverseForEach(ObjectList, i, d->children) { |
794 | iWidget *child = as_Widget(i.object); | 795 | iWidget *child = as_Widget(i.object); |
795 | if (child == data_Root()->focus && isKeyboardEvent_(ev)) { | 796 | if (child == get_Root()->focus && isKeyboardEvent_(ev)) { |
796 | continue; /* Already dispatched. */ | 797 | continue; /* Already dispatched. */ |
797 | } | 798 | } |
798 | if (isVisible_Widget(child) && child->flags & keepOnTop_WidgetFlag) { | 799 | if (isVisible_Widget(child) && child->flags & keepOnTop_WidgetFlag) { |
@@ -1081,7 +1082,7 @@ void drawChildren_Widget(const iWidget *d) { | |||
1081 | } | 1082 | } |
1082 | /* Root draws the on-top widgets on top of everything else. */ | 1083 | /* Root draws the on-top widgets on top of everything else. */ |
1083 | if (!d->parent) { | 1084 | if (!d->parent) { |
1084 | iConstForEach(PtrArray, i, onTop_RootData()) { | 1085 | iConstForEach(PtrArray, i, onTop_Root(get_Root())) { |
1085 | const iWidget *top = *i.value; | 1086 | const iWidget *top = *i.value; |
1086 | draw_Widget(top); | 1087 | draw_Widget(top); |
1087 | } | 1088 | } |
@@ -1198,7 +1199,7 @@ iAny *hitChild_Widget(const iWidget *d, iInt2 coord) { | |||
1198 | } | 1199 | } |
1199 | /* Check for on-top widgets first. */ | 1200 | /* Check for on-top widgets first. */ |
1200 | if (!d->parent) { | 1201 | if (!d->parent) { |
1201 | iReverseForEach(PtrArray, i, onTop_RootData()) { | 1202 | iReverseForEach(PtrArray, i, onTop_Root(get_Root())) { |
1202 | iWidget *child = i.ptr; | 1203 | iWidget *child = i.ptr; |
1203 | // printf("ontop: %s (%s) hidden:%d hittable:%d\n", cstr_String(id_Widget(child)), | 1204 | // printf("ontop: %s (%s) hidden:%d hittable:%d\n", cstr_String(id_Widget(child)), |
1204 | // class_Widget(child)->name, | 1205 | // class_Widget(child)->name, |
@@ -1286,12 +1287,12 @@ iBool isDisabled_Widget(const iAnyObject *d) { | |||
1286 | 1287 | ||
1287 | iBool isFocused_Widget(const iAnyObject *d) { | 1288 | iBool isFocused_Widget(const iAnyObject *d) { |
1288 | iAssert(isInstance_Object(d, &Class_Widget)); | 1289 | iAssert(isInstance_Object(d, &Class_Widget)); |
1289 | return data_Root()->focus == d; | 1290 | return get_Root()->focus == d; |
1290 | } | 1291 | } |
1291 | 1292 | ||
1292 | iBool isHover_Widget(const iAnyObject *d) { | 1293 | iBool isHover_Widget(const iAnyObject *d) { |
1293 | iAssert(isInstance_Object(d, &Class_Widget)); | 1294 | iAssert(isInstance_Object(d, &Class_Widget)); |
1294 | return data_Root()->hover == d; | 1295 | return get_Root()->hover == d; |
1295 | } | 1296 | } |
1296 | 1297 | ||
1297 | iBool isSelected_Widget(const iAnyObject *d) { | 1298 | iBool isSelected_Widget(const iAnyObject *d) { |
@@ -1337,12 +1338,12 @@ iBool isAffectedByVisualOffset_Widget(const iWidget *d) { | |||
1337 | } | 1338 | } |
1338 | 1339 | ||
1339 | void setFocus_Widget(iWidget *d) { | 1340 | void setFocus_Widget(iWidget *d) { |
1340 | if (data_Root()->focus != d) { | 1341 | if (get_Root()->focus != d) { |
1341 | if (data_Root()->focus) { | 1342 | if (get_Root()->focus) { |
1342 | iAssert(!contains_PtrSet(data_Root()->pendingDestruction, data_Root()->focus)); | 1343 | iAssert(!contains_PtrSet(get_Root()->pendingDestruction, get_Root()->focus)); |
1343 | postCommand_Widget(data_Root()->focus, "focus.lost"); | 1344 | postCommand_Widget(get_Root()->focus, "focus.lost"); |
1344 | } | 1345 | } |
1345 | data_Root()->focus = d; | 1346 | get_Root()->focus = d; |
1346 | if (d) { | 1347 | if (d) { |
1347 | iAssert(flags_Widget(d) & focusable_WidgetFlag); | 1348 | iAssert(flags_Widget(d) & focusable_WidgetFlag); |
1348 | postCommand_Widget(d, "focus.gained"); | 1349 | postCommand_Widget(d, "focus.gained"); |
@@ -1351,15 +1352,15 @@ void setFocus_Widget(iWidget *d) { | |||
1351 | } | 1352 | } |
1352 | 1353 | ||
1353 | iWidget *focus_Widget(void) { | 1354 | iWidget *focus_Widget(void) { |
1354 | return data_Root()->focus; | 1355 | return get_Root()->focus; |
1355 | } | 1356 | } |
1356 | 1357 | ||
1357 | void setHover_Widget(iWidget *d) { | 1358 | void setHover_Widget(iWidget *d) { |
1358 | data_Root()->hover = d; | 1359 | get_Root()->hover = d; |
1359 | } | 1360 | } |
1360 | 1361 | ||
1361 | iWidget *hover_Widget(void) { | 1362 | iWidget *hover_Widget(void) { |
1362 | return data_Root()->hover; | 1363 | return get_Root()->hover; |
1363 | } | 1364 | } |
1364 | 1365 | ||
1365 | static const iWidget *findFocusable_Widget_(const iWidget *d, const iWidget *startFrom, | 1366 | static const iWidget *findFocusable_Widget_(const iWidget *d, const iWidget *startFrom, |
@@ -1403,7 +1404,7 @@ static const iWidget *findFocusRoot_Widget_(const iWidget *d) { | |||
1403 | } | 1404 | } |
1404 | 1405 | ||
1405 | iAny *findFocusable_Widget(const iWidget *startFrom, enum iWidgetFocusDir focusDir) { | 1406 | iAny *findFocusable_Widget(const iWidget *startFrom, enum iWidgetFocusDir focusDir) { |
1406 | const iWidget *root = findFocusRoot_Widget_(get_Window()->root); | 1407 | const iWidget *root = findFocusRoot_Widget_(get_Window()->root.widget); |
1407 | iAssert(root != NULL); | 1408 | iAssert(root != NULL); |
1408 | iBool getNext = (startFrom ? iFalse : iTrue); | 1409 | iBool getNext = (startFrom ? iFalse : iTrue); |
1409 | const iWidget *found = findFocusable_Widget_(root, startFrom, &getNext, focusDir); | 1410 | const iWidget *found = findFocusable_Widget_(root, startFrom, &getNext, focusDir); |
@@ -1415,14 +1416,14 @@ iAny *findFocusable_Widget(const iWidget *startFrom, enum iWidgetFocusDir focusD | |||
1415 | } | 1416 | } |
1416 | 1417 | ||
1417 | void setMouseGrab_Widget(iWidget *d) { | 1418 | void setMouseGrab_Widget(iWidget *d) { |
1418 | if (data_Root()->mouseGrab != d) { | 1419 | if (get_Root()->mouseGrab != d) { |
1419 | data_Root()->mouseGrab = d; | 1420 | get_Root()->mouseGrab = d; |
1420 | SDL_CaptureMouse(d != NULL); | 1421 | SDL_CaptureMouse(d != NULL); |
1421 | } | 1422 | } |
1422 | } | 1423 | } |
1423 | 1424 | ||
1424 | iWidget *mouseGrab_Widget(void) { | 1425 | iWidget *mouseGrab_Widget(void) { |
1425 | return data_Root()->mouseGrab; | 1426 | return get_Root()->mouseGrab; |
1426 | } | 1427 | } |
1427 | 1428 | ||
1428 | void postCommand_Widget(const iAnyObject *d, const char *cmd, ...) { | 1429 | void postCommand_Widget(const iAnyObject *d, const char *cmd, ...) { |
@@ -1456,7 +1457,7 @@ void refresh_Widget(const iAnyObject *d) { | |||
1456 | } | 1457 | } |
1457 | 1458 | ||
1458 | void raise_Widget(iWidget *d) { | 1459 | void raise_Widget(iWidget *d) { |
1459 | iPtrArray *onTop = onTop_RootData(); | 1460 | iPtrArray *onTop = onTop_Root(get_Root()); |
1460 | if (d->flags & keepOnTop_WidgetFlag) { | 1461 | if (d->flags & keepOnTop_WidgetFlag) { |
1461 | iAssert(indexOf_PtrArray(onTop, d) != iInvalidPos); | 1462 | iAssert(indexOf_PtrArray(onTop, d) != iInvalidPos); |
1462 | removeOne_PtrArray(onTop, d); | 1463 | removeOne_PtrArray(onTop, d); |