summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-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
4 files changed, 34 insertions, 8 deletions
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) },