diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-11-21 18:28:08 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-11-21 18:28:08 +0200 |
commit | 58955605b89a47f2a438ec1eca77bef91c4af032 (patch) | |
tree | a7fc31e31c134023843ebdf0e6ef465e9b639941 /src/ui/util.c | |
parent | 9908cc3ec9c6697070f23a9da52e25e95830fb01 (diff) | |
parent | 33fe87051f3c4e293f47618adced141b1183b324 (diff) |
Merge branch 'dev' into work/v1.9
# Conflicts:
# CMakeLists.txt
# res/about/version.gmi
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 92 |
1 files changed, 52 insertions, 40 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 88348ff8..0a9dde0c 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -809,14 +809,27 @@ static void deleteMenuItems_(iArray *items) { | |||
809 | delete_Array(items); | 809 | delete_Array(items); |
810 | } | 810 | } |
811 | 811 | ||
812 | iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | 812 | void releaseNativeMenu_Widget(iWidget *d) { |
813 | iWidget *menu = new_Widget(); | ||
814 | #if defined (iHaveNativeContextMenus) | 813 | #if defined (iHaveNativeContextMenus) |
815 | setFlags_Widget(menu, hidden_WidgetFlag | nativeMenu_WidgetFlag, iTrue); | 814 | iArray *items = userData_Object(d); |
815 | if (items) { | ||
816 | iAssert(flags_Widget(d) & nativeMenu_WidgetFlag); | ||
817 | iAssert(items); | ||
818 | deleteMenuItems_(items); | ||
819 | setUserData_Object(d, NULL); | ||
820 | } | ||
821 | #else | ||
822 | iUnused(d); | ||
823 | #endif | ||
824 | } | ||
825 | |||
826 | void setNativeMenuItems_Widget(iWidget *menu, const iMenuItem *items, size_t n) { | ||
827 | #if defined (iHaveNativeContextMenus) | ||
828 | iAssert(flags_Widget(menu) & nativeMenu_WidgetFlag); | ||
829 | releaseNativeMenu_Widget(menu); | ||
816 | setUserData_Object(menu, deepCopyMenuItems_(menu, items, n)); | 830 | setUserData_Object(menu, deepCopyMenuItems_(menu, items, n)); |
817 | addChild_Widget(parent, menu); | ||
818 | iRelease(menu); /* owned by parent now */ | ||
819 | /* Keyboard shortcuts still need to triggerable via the menu, although the items don't exist. */ { | 831 | /* Keyboard shortcuts still need to triggerable via the menu, although the items don't exist. */ { |
832 | releaseChildren_Widget(menu); | ||
820 | for (size_t i = 0; i < n; i++) { | 833 | for (size_t i = 0; i < n; i++) { |
821 | const iMenuItem *item = &items[i]; | 834 | const iMenuItem *item = &items[i]; |
822 | if (item->key) { | 835 | if (item->key) { |
@@ -824,6 +837,17 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | |||
824 | } | 837 | } |
825 | } | 838 | } |
826 | } | 839 | } |
840 | #endif | ||
841 | } | ||
842 | |||
843 | iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | ||
844 | iWidget *menu = new_Widget(); | ||
845 | #if defined (iHaveNativeContextMenus) | ||
846 | setFlags_Widget(menu, hidden_WidgetFlag | nativeMenu_WidgetFlag, iTrue); | ||
847 | addChild_Widget(parent, menu); | ||
848 | iRelease(menu); /* owned by parent now */ | ||
849 | setUserData_Object(menu, NULL); | ||
850 | setNativeMenuItems_Widget(menu, items, n); | ||
827 | #else | 851 | #else |
828 | /* Non-native custom popup menu. This may still be displayed inside a separate window. */ | 852 | /* Non-native custom popup menu. This may still be displayed inside a separate window. */ |
829 | setDrawBufferEnabled_Widget(menu, iTrue); | 853 | setDrawBufferEnabled_Widget(menu, iTrue); |
@@ -990,18 +1014,6 @@ iLocalDef iBool isUsingMenuPopupWindows_(void) { | |||
990 | #endif | 1014 | #endif |
991 | } | 1015 | } |
992 | 1016 | ||
993 | void releaseNativeMenu_Widget(iWidget *d) { | ||
994 | #if defined (iHaveNativeContextMenus) | ||
995 | iArray *items = userData_Object(d); | ||
996 | iAssert(flags_Widget(d) & nativeMenu_WidgetFlag); | ||
997 | iAssert(items); | ||
998 | deleteMenuItems_(items); | ||
999 | setUserData_Object(d, NULL); | ||
1000 | #else | ||
1001 | iUnused(d); | ||
1002 | #endif | ||
1003 | } | ||
1004 | |||
1005 | void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | 1017 | void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { |
1006 | const iBool postCommands = (menuOpenFlags & postCommands_MenuOpenFlags) != 0; | 1018 | const iBool postCommands = (menuOpenFlags & postCommands_MenuOpenFlags) != 0; |
1007 | #if defined (iHaveNativeContextMenus) | 1019 | #if defined (iHaveNativeContextMenus) |
@@ -1263,8 +1275,8 @@ void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *s | |||
1263 | iMenuItem *item = findNativeMenuItem_Widget(menu, selectedCommand); | 1275 | iMenuItem *item = findNativeMenuItem_Widget(menu, selectedCommand); |
1264 | if (item) { | 1276 | if (item) { |
1265 | setSelected_NativeMenuItem(item, iTrue); | 1277 | setSelected_NativeMenuItem(item, iTrue); |
1266 | updateText_LabelWidget(dropButton, | 1278 | updateText_LabelWidget( |
1267 | removeMenuItemLabelPrefixes_String(collectNewCStr_String(item->label))); | 1279 | dropButton, removeMenuItemLabelPrefixes_String(collectNewCStr_String(item->label))); |
1268 | } | 1280 | } |
1269 | return; | 1281 | return; |
1270 | } | 1282 | } |
@@ -2199,27 +2211,27 @@ iWidget *makeDialog_Widget(const char *id, | |||
2199 | 2211 | ||
2200 | iWidget *makePreferences_Widget(void) { | 2212 | iWidget *makePreferences_Widget(void) { |
2201 | /* Common items. */ | 2213 | /* Common items. */ |
2202 | const iMenuItem langItems[] = { { "${lang.cs} - cs", 0, 0, "uilang id:cs" }, | 2214 | const iMenuItem langItems[] = { { u8"Čeština - cs", 0, 0, "uilang id:cs" }, |
2203 | { "${lang.de} - de", 0, 0, "uilang id:de" }, | 2215 | { u8"Deutsch - de", 0, 0, "uilang id:de" }, |
2204 | { "${lang.en} - en", 0, 0, "uilang id:en" }, | 2216 | { u8"English - en", 0, 0, "uilang id:en" }, |
2205 | { "${lang.es} - es", 0, 0, "uilang id:es" }, | 2217 | { u8"Español - es", 0, 0, "uilang id:es" }, |
2206 | { "${lang.es.mx} - es", 0, 0, "uilang id:es_MX" }, | 2218 | { u8"Español (México) - es", 0, 0, "uilang id:es_MX" }, |
2207 | { "${lang.eo} - eo", 0, 0, "uilang id:eo" }, | 2219 | { u8"Esperanto - eo", 0, 0, "uilang id:eo" }, |
2208 | { "${lang.fi} - fi", 0, 0, "uilang id:fi" }, | 2220 | { u8"Suomi - fi", 0, 0, "uilang id:fi" }, |
2209 | { "${lang.fr} - fr", 0, 0, "uilang id:fr" }, | 2221 | { u8"Français - fr", 0, 0, "uilang id:fr" }, |
2210 | { "${lang.gl} - gl", 0, 0, "uilang id:gl" }, | 2222 | { u8"Galego - gl", 0, 0, "uilang id:gl" }, |
2211 | { "${lang.hu} - hu", 0, 0, "uilang id:hu" }, | 2223 | { u8"Magyar - hu", 0, 0, "uilang id:hu" }, |
2212 | { "${lang.ia} - ia", 0, 0, "uilang id:ia" }, | 2224 | { u8"Interlingua - ia", 0, 0, "uilang id:ia" }, |
2213 | { "${lang.ie} - ie", 0, 0, "uilang id:ie" }, | 2225 | { u8"Interlingue - ie", 0, 0, "uilang id:ie" }, |
2214 | { "${lang.isv} - isv", 0, 0, "uilang id:isv" }, | 2226 | { u8"Interslavic - isv", 0, 0, "uilang id:isv" }, |
2215 | { "${lang.pl} - pl", 0, 0, "uilang id:pl" }, | 2227 | { u8"Polski - pl", 0, 0, "uilang id:pl" }, |
2216 | { "${lang.ru} - ru", 0, 0, "uilang id:ru" }, | 2228 | { u8"Русский - ru", 0, 0, "uilang id:ru" }, |
2217 | { "${lang.sk} - sk", 0, 0, "uilang id:sk" }, | 2229 | { u8"Slovak - sk", 0, 0, "uilang id:sk" }, |
2218 | { "${lang.sr} - sr", 0, 0, "uilang id:sr" }, | 2230 | { u8"Српски - sr", 0, 0, "uilang id:sr" }, |
2219 | { "${lang.tok} - tok", 0, 0, "uilang id:tok" }, | 2231 | { u8"Toki pona - tok", 0, 0, "uilang id:tok" }, |
2220 | { "${lang.uk} - uk", 0, 0, "uilang id:uk" }, | 2232 | { u8"Українська - uk", 0, 0, "uilang id:uk" }, |
2221 | { "${lang.zh.hans} - zh", 0, 0, "uilang id:zh_Hans" }, | 2233 | { u8"简体中文 - zh", 0, 0, "uilang id:zh_Hans" }, |
2222 | { "${lang.zh.hant} - zh", 0, 0, "uilang id:zh_Hant" }, | 2234 | { u8"繁體/正體中文 - zh", 0, 0, "uilang id:zh_Hant" }, |
2223 | { NULL } }; | 2235 | { NULL } }; |
2224 | const iMenuItem returnKeyBehaviors[] = { | 2236 | const iMenuItem returnKeyBehaviors[] = { |
2225 | { "${prefs.returnkey.linebreak} " uiTextAction_ColorEscape shift_Icon return_Icon | 2237 | { "${prefs.returnkey.linebreak} " uiTextAction_ColorEscape shift_Icon return_Icon |