summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-21 14:37:19 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-21 14:37:19 +0300
commit14eec09b1d6f0d11292b81e23633f6c764755d0f (patch)
tree11431c97b6ded31aaff4043e3cd1b2a281a13706
parent69529fea17c904dc5205657dd04c7ec66a2a3681 (diff)
Fixed issues with popup windows
-rw-r--r--src/app.c2
-rw-r--r--src/defs.h3
-rw-r--r--src/ui/root.c3
-rw-r--r--src/ui/util.c37
-rw-r--r--src/ui/util.h1
-rw-r--r--src/ui/window.c1
6 files changed, 37 insertions, 10 deletions
diff --git a/src/app.c b/src/app.c
index d7392423..5ff93f2a 100644
--- a/src/app.c
+++ b/src/app.c
@@ -1275,7 +1275,7 @@ void processEvents_App(enum iAppEventMode eventMode) {
1275 setCurrent_Window(window); 1275 setCurrent_Window(window);
1276 window->lastHover = window->hover; 1276 window->lastHover = window->hover;
1277 wasUsed = processEvent_Window(window, &ev); 1277 wasUsed = processEvent_Window(window, &ev);
1278 if (ev.type == SDL_MOUSEMOTION) { 1278 if (ev.type == SDL_MOUSEMOTION || ev.type == SDL_MOUSEBUTTONDOWN) {
1279 break; 1279 break;
1280 } 1280 }
1281 if (wasUsed) break; 1281 if (wasUsed) break;
diff --git a/src/defs.h b/src/defs.h
index 3cb7dd2c..da424c13 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -165,7 +165,8 @@ iLocalDef int acceptKeyMod_ReturnKeyBehavior(int behavior) {
165#endif 165#endif
166 166
167#if defined (iPlatformAppleDesktop) 167#if defined (iPlatformAppleDesktop)
168# define iHaveNativeMenus 168# define iHaveNativeMenus /* main menu */
169//# define iHaveNativeContextMenus
169#endif 170#endif
170 171
171/* UI labels that depend on the platform */ 172/* UI labels that depend on the platform */
diff --git a/src/ui/root.c b/src/ui/root.c
index 2e883787..90c0c6e4 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -436,8 +436,9 @@ static void updateNavBarIdentity_(iWidget *navBar) {
436 const iString *subjectName = ident ? name_GmIdentity(ident) : NULL; 436 const iString *subjectName = ident ? name_GmIdentity(ident) : NULL;
437 const char * idLabel = subjectName 437 const char * idLabel = subjectName
438 ? format_CStr(uiTextAction_ColorEscape "%s", cstr_String(subjectName)) 438 ? format_CStr(uiTextAction_ColorEscape "%s", cstr_String(subjectName))
439 : "///${menu.identity.notactive}"; 439 : "${menu.identity.notactive}";
440 setMenuItemLabelByIndex_Widget(menu, 0, idLabel); 440 setMenuItemLabelByIndex_Widget(menu, 0, idLabel);
441 setMenuItemDisabledByIndex_Widget(menu, 0, !ident);
441 iLabelWidget *toolButton = findWidget_App("toolbar.ident"); 442 iLabelWidget *toolButton = findWidget_App("toolbar.ident");
442 iLabelWidget *toolName = findWidget_App("toolbar.name"); 443 iLabelWidget *toolName = findWidget_App("toolbar.name");
443 if (toolName) { 444 if (toolName) {
diff --git a/src/ui/util.c b/src/ui/util.c
index 6d518282..c75d7698 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -811,7 +811,7 @@ static void deleteMenuItems_(iArray *items) {
811 811
812iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { 812iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) {
813 iWidget *menu = new_Widget(); 813 iWidget *menu = new_Widget();
814#if defined (iHaveNativeMenus) 814#if defined (iHaveNativeContextMenus)
815 setFlags_Widget(menu, hidden_WidgetFlag | nativeMenu_WidgetFlag, iTrue); 815 setFlags_Widget(menu, hidden_WidgetFlag | nativeMenu_WidgetFlag, iTrue);
816 setUserData_Object(menu, deepCopyMenuItems_(menu, items, n)); 816 setUserData_Object(menu, deepCopyMenuItems_(menu, items, n));
817 addChild_Widget(parent, menu); 817 addChild_Widget(parent, menu);
@@ -949,6 +949,9 @@ void setMenuItemLabel_Widget(iWidget *menu, const char *command, const char *new
949} 949}
950 950
951void setMenuItemLabelByIndex_Widget(iWidget *menu, size_t index, const char *newLabel) { 951void setMenuItemLabelByIndex_Widget(iWidget *menu, size_t index, const char *newLabel) {
952 if (!menu) {
953 return;
954 }
952 if (flags_Widget(menu) & nativeMenu_WidgetFlag) { 955 if (flags_Widget(menu) & nativeMenu_WidgetFlag) {
953 iArray *items = userData_Object(menu); 956 iArray *items = userData_Object(menu);
954 iAssert(items); 957 iAssert(items);
@@ -976,7 +979,7 @@ iLocalDef iBool isUsingMenuPopupWindows_(void) {
976} 979}
977 980
978void releaseNativeMenu_Widget(iWidget *d) { 981void releaseNativeMenu_Widget(iWidget *d) {
979#if defined (iHaveNativeMenus) 982#if defined (iHaveNativeContextMenus)
980 iArray *items = userData_Object(d); 983 iArray *items = userData_Object(d);
981 iAssert(flags_Widget(d) & nativeMenu_WidgetFlag); 984 iAssert(flags_Widget(d) & nativeMenu_WidgetFlag);
982 iAssert(items); 985 iAssert(items);
@@ -988,7 +991,7 @@ void releaseNativeMenu_Widget(iWidget *d) {
988} 991}
989 992
990void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) { 993void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) {
991#if defined (iHaveNativeMenus) 994#if defined (iHaveNativeContextMenus)
992 const iArray *items = userData_Object(d); 995 const iArray *items = userData_Object(d);
993 iAssert(flags_Widget(d) & nativeMenu_WidgetFlag); 996 iAssert(flags_Widget(d) & nativeMenu_WidgetFlag);
994 iAssert(items); 997 iAssert(items);
@@ -1014,9 +1017,19 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) {
1014 setFlags_Widget(d, keepOnTop_WidgetFlag, iFalse); 1017 setFlags_Widget(d, keepOnTop_WidgetFlag, iFalse);
1015 setUserData_Object(d, parent_Widget(d)); 1018 setUserData_Object(d, parent_Widget(d));
1016 removeChild_Widget(parent_Widget(d), d); /* we'll borrow the widget for a while */ 1019 removeChild_Widget(parent_Widget(d), d); /* we'll borrow the widget for a while */
1017 iInt2 mousePos; 1020 const float pixelRatio = get_Window()->pixelRatio;
1018 SDL_GetGlobalMouseState(&mousePos.x, &mousePos.y); 1021 iInt2 menuPos = add_I2(get_MainWindow()->place.normalRect.pos,
1019 iWindow *win = newPopup_Window(sub_I2(mousePos, divi_I2(gap2_UI, 2)), d); 1022 divf_I2(windowCoord, pixelRatio));
1023 arrange_Widget(d);
1024 /* Check display bounds. */ {
1025 const iInt2 menuSize = divf_I2(d->rect.size, pixelRatio);
1026 SDL_Rect displayRect;
1027 SDL_GetDisplayBounds(SDL_GetWindowDisplayIndex(get_Window()->win), &displayRect);
1028 menuPos.x = iMin(menuPos.x, displayRect.x + displayRect.w - menuSize.x);
1029 menuPos.y = iMin(menuPos.y, displayRect.y + displayRect.h - menuSize.y);
1030 }
1031 // SDL_GetGlobalMouseState(&mousePos.x, &mousePos.y);
1032 iWindow *win = newPopup_Window(menuPos, d);
1020 SDL_SetWindowTitle(win->win, "Menu"); 1033 SDL_SetWindowTitle(win->win, "Menu");
1021 addPopup_App(win); /* window takes the widget */ 1034 addPopup_App(win); /* window takes the widget */
1022 SDL_ShowWindow(win->win); 1035 SDL_ShowWindow(win->win);
@@ -1134,6 +1147,18 @@ void setMenuItemDisabled_Widget(iWidget *menu, const char *command, iBool disabl
1134 } 1147 }
1135} 1148}
1136 1149
1150void setMenuItemDisabledByIndex_Widget(iWidget *menu, size_t index, iBool disable) {
1151 if (!menu) {
1152 return;
1153 }
1154 if (flags_Widget(menu) & nativeMenu_WidgetFlag) {
1155 setDisabled_NativeMenuItem(at_Array(userData_Object(menu), index), disable);
1156 }
1157 else {
1158 setFlags_Widget(child_Widget(menu, index), disabled_WidgetFlag, disable);
1159 }
1160}
1161
1137int checkContextMenu_Widget(iWidget *menu, const SDL_Event *ev) { 1162int checkContextMenu_Widget(iWidget *menu, const SDL_Event *ev) {
1138 if (menu && ev->type == SDL_MOUSEBUTTONDOWN && ev->button.button == SDL_BUTTON_RIGHT) { 1163 if (menu && ev->type == SDL_MOUSEBUTTONDOWN && ev->button.button == SDL_BUTTON_RIGHT) {
1139 if (isVisible_Widget(menu)) { 1164 if (isVisible_Widget(menu)) {
diff --git a/src/ui/util.h b/src/ui/util.h
index 574a255f..5d092700 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -241,6 +241,7 @@ iChar removeIconPrefix_String (iString *);
241iLabelWidget * findMenuItem_Widget (iWidget *menu, const char *command); 241iLabelWidget * findMenuItem_Widget (iWidget *menu, const char *command);
242iMenuItem * findNativeMenuItem_Widget (iWidget *menu, const char *commandSuffix); 242iMenuItem * findNativeMenuItem_Widget (iWidget *menu, const char *commandSuffix);
243void setMenuItemDisabled_Widget (iWidget *menu, const char *command, iBool disable); 243void setMenuItemDisabled_Widget (iWidget *menu, const char *command, iBool disable);
244void setMenuItemDisabledByIndex_Widget(iWidget *menu, size_t index, iBool disable);
244void setMenuItemLabel_Widget (iWidget *menu, const char *command, const char *newLabel); 245void setMenuItemLabel_Widget (iWidget *menu, const char *command, const char *newLabel);
245void setMenuItemLabelByIndex_Widget (iWidget *menu, size_t index, const char *newLabel); 246void setMenuItemLabelByIndex_Widget (iWidget *menu, size_t index, const char *newLabel);
246 247
diff --git a/src/ui/window.c b/src/ui/window.c
index 27ef2bc3..3f8faaea 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1582,7 +1582,6 @@ int snap_MainWindow(const iMainWindow *d) {
1582/*----------------------------------------------------------------------------------------------*/ 1582/*----------------------------------------------------------------------------------------------*/
1583 1583
1584iWindow *newPopup_Window(iInt2 screenPos, iWidget *rootWidget) { 1584iWindow *newPopup_Window(iInt2 screenPos, iWidget *rootWidget) {
1585 arrange_Widget(rootWidget);
1586 iWindow *win = 1585 iWindow *win =
1587 new_Window(popup_WindowType, 1586 new_Window(popup_WindowType,
1588 (iRect){ screenPos, divf_I2(rootWidget->rect.size, get_Window()->pixelRatio) }, 1587 (iRect){ screenPos, divf_I2(rootWidget->rect.size, get_Window()->pixelRatio) },