diff options
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 80 |
1 files changed, 70 insertions, 10 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 0af33138..ff6f8822 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -52,6 +52,57 @@ const char *command_UserEvent(const SDL_Event *d) { | |||
52 | return ""; | 52 | return ""; |
53 | } | 53 | } |
54 | 54 | ||
55 | void toString_Sym(int key, int kmods, iString *str) { | ||
56 | #if defined (iPlatformApple) | ||
57 | if (kmods & KMOD_CTRL) { | ||
58 | appendChar_String(str, 0x2303); | ||
59 | } | ||
60 | if (kmods & KMOD_ALT) { | ||
61 | appendChar_String(str, 0x2325); | ||
62 | } | ||
63 | if (kmods & KMOD_SHIFT) { | ||
64 | appendChar_String(str, 0x21e7); | ||
65 | } | ||
66 | if (kmods & KMOD_GUI) { | ||
67 | appendChar_String(str, 0x2318); | ||
68 | } | ||
69 | #else | ||
70 | if (kmods & KMOD_CTRL) { | ||
71 | appendCStr_String(str, "Ctrl+"); | ||
72 | } | ||
73 | if (kmods & KMOD_ALT) { | ||
74 | appendCStr_String(str, "Alt+"); | ||
75 | } | ||
76 | if (kmods & KMOD_SHIFT) { | ||
77 | appendCStr_String(str, "Shift+"); | ||
78 | } | ||
79 | if (kmods & KMOD_GUI) { | ||
80 | appendCStr_String(str, "Meta+"); | ||
81 | } | ||
82 | #endif | ||
83 | if (key == 0x20) { | ||
84 | appendCStr_String(str, "Space"); | ||
85 | } | ||
86 | else if (key == SDLK_LEFT) { | ||
87 | appendChar_String(str, 0x2190); | ||
88 | } | ||
89 | else if (key == SDLK_RIGHT) { | ||
90 | appendChar_String(str, 0x2192); | ||
91 | } | ||
92 | else if (key < 128 && (isalnum(key) || ispunct(key))) { | ||
93 | appendChar_String(str, upper_Char(key)); | ||
94 | } | ||
95 | else if (key == SDLK_BACKSPACE) { | ||
96 | appendChar_String(str, 0x232b); /* Erase to the Left */ | ||
97 | } | ||
98 | else if (key == SDLK_DELETE) { | ||
99 | appendChar_String(str, 0x2326); /* Erase to the Right */ | ||
100 | } | ||
101 | else { | ||
102 | appendCStr_String(str, SDL_GetKeyName(key)); | ||
103 | } | ||
104 | } | ||
105 | |||
55 | int keyMods_Sym(int kmods) { | 106 | int keyMods_Sym(int kmods) { |
56 | kmods &= (KMOD_SHIFT | KMOD_ALT | KMOD_CTRL | KMOD_GUI); | 107 | kmods &= (KMOD_SHIFT | KMOD_ALT | KMOD_CTRL | KMOD_GUI); |
57 | /* Don't treat left/right modifiers differently. */ | 108 | /* Don't treat left/right modifiers differently. */ |
@@ -192,6 +243,12 @@ iWidget *addAction_Widget(iWidget *parent, int key, int kmods, const char *comma | |||
192 | 243 | ||
193 | /*-----------------------------------------------------------------------------------------------*/ | 244 | /*-----------------------------------------------------------------------------------------------*/ |
194 | 245 | ||
246 | static iBool isCommandIgnoredByMenus_(const char *cmd) { | ||
247 | return equal_Command(cmd, "media.updated") || equal_Command(cmd, "document.request.updated") || | ||
248 | equal_Command(cmd, "window.resized") || | ||
249 | (equal_Command(cmd, "mouse.clicked") && !arg_Command(cmd)); /* button released */ | ||
250 | } | ||
251 | |||
195 | static iBool menuHandler_(iWidget *menu, const char *cmd) { | 252 | static iBool menuHandler_(iWidget *menu, const char *cmd) { |
196 | if (isVisible_Widget(menu)) { | 253 | if (isVisible_Widget(menu)) { |
197 | if (equalWidget_Command(cmd, menu, "menu.opened")) { | 254 | if (equalWidget_Command(cmd, menu, "menu.opened")) { |
@@ -201,13 +258,13 @@ static iBool menuHandler_(iWidget *menu, const char *cmd) { | |||
201 | /* Don't reopen self; instead, root will close the menu. */ | 258 | /* Don't reopen self; instead, root will close the menu. */ |
202 | return iFalse; | 259 | return iFalse; |
203 | } | 260 | } |
204 | if (equal_Command(cmd, "mouse.clicked") && arg_Command(cmd)) { | 261 | if ((equal_Command(cmd, "mouse.clicked") || equal_Command(cmd, "mouse.missed")) && |
262 | arg_Command(cmd)) { | ||
205 | /* Dismiss open menus when clicking outside them. */ | 263 | /* Dismiss open menus when clicking outside them. */ |
206 | closeMenu_Widget(menu); | 264 | closeMenu_Widget(menu); |
207 | return iTrue; | 265 | return iTrue; |
208 | } | 266 | } |
209 | if (!equal_Command(cmd, "window.resized") && | 267 | if (!isCommandIgnoredByMenus_(cmd)) { |
210 | !(equal_Command(cmd, "mouse.clicked") && !arg_Command(cmd)) /* ignore button release */) { | ||
211 | closeMenu_Widget(menu); | 268 | closeMenu_Widget(menu); |
212 | } | 269 | } |
213 | } | 270 | } |
@@ -252,6 +309,7 @@ void openMenu_Widget(iWidget *d, iInt2 coord) { | |||
252 | postCommand_App("cancel"); /* dismiss any other menus */ | 309 | postCommand_App("cancel"); /* dismiss any other menus */ |
253 | processEvents_App(postedEventsOnly_AppEventMode); | 310 | processEvents_App(postedEventsOnly_AppEventMode); |
254 | setFlags_Widget(d, hidden_WidgetFlag, iFalse); | 311 | setFlags_Widget(d, hidden_WidgetFlag, iFalse); |
312 | setFlags_Widget(d, commandOnMouseMiss_WidgetFlag, iTrue); | ||
255 | setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse); | 313 | setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse); |
256 | arrange_Widget(d); | 314 | arrange_Widget(d); |
257 | d->rect.pos = coord; | 315 | d->rect.pos = coord; |
@@ -681,10 +739,9 @@ void updateValueInput_Widget(iWidget *d, const char *title, const char *prompt) | |||
681 | 739 | ||
682 | static iBool messageHandler_(iWidget *msg, const char *cmd) { | 740 | static iBool messageHandler_(iWidget *msg, const char *cmd) { |
683 | /* Almost any command dismisses the sheet. */ | 741 | /* Almost any command dismisses the sheet. */ |
684 | // if (equal_Command(cmd, "menu.closed")) { | 742 | if (!(equal_Command(cmd, "media.updated") || equal_Command(cmd, "document.request.updated"))) { |
685 | // return iFalse; | 743 | destroy_Widget(msg); |
686 | // } | 744 | } |
687 | destroy_Widget(msg); | ||
688 | return iFalse; | 745 | return iFalse; |
689 | } | 746 | } |
690 | 747 | ||
@@ -755,14 +812,16 @@ iWidget *makePreferences_Widget(void) { | |||
755 | addChild_Widget(dlg, iClob(page)); | 812 | addChild_Widget(dlg, iClob(page)); |
756 | setFlags_Widget(page, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); | 813 | setFlags_Widget(page, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); |
757 | iWidget *headings = addChildFlags_Widget( | 814 | iWidget *headings = addChildFlags_Widget( |
758 | page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); | 815 | page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); |
759 | iWidget *values = addChildFlags_Widget( | 816 | iWidget *values = addChildFlags_Widget( |
760 | page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); | 817 | page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); |
818 | addChild_Widget(headings, iClob(makeHeading_Widget("Downloads folder:"))); | ||
819 | setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.downloads"); | ||
761 | #if defined (iPlatformApple) || defined (iPlatformMSys) | 820 | #if defined (iPlatformApple) || defined (iPlatformMSys) |
762 | addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:"))); | 821 | addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:"))); |
763 | addChild_Widget(values, iClob(makeToggle_Widget("prefs.ostheme"))); | 822 | addChild_Widget(values, iClob(makeToggle_Widget("prefs.ostheme"))); |
764 | #endif | 823 | #endif |
765 | addChild_Widget(headings, iClob(makeHeading_Widget("Theme:"))); | 824 | addChild_Widget(headings, iClob(makeHeading_Widget("Theme:"))); |
766 | iWidget *themes = new_Widget(); | 825 | iWidget *themes = new_Widget(); |
767 | /* Themes. */ { | 826 | /* Themes. */ { |
768 | setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Pure Black", 0, 0, "theme.set arg:0"))), "prefs.theme.0"); | 827 | setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Pure Black", 0, 0, "theme.set arg:0"))), "prefs.theme.0"); |
@@ -782,8 +841,9 @@ iWidget *makePreferences_Widget(void) { | |||
782 | addChild_Widget(headings, iClob(makeHeading_Widget("HTTP proxy:"))); | 841 | addChild_Widget(headings, iClob(makeHeading_Widget("HTTP proxy:"))); |
783 | setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.proxy.http"); | 842 | setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.proxy.http"); |
784 | arrange_Widget(dlg); | 843 | arrange_Widget(dlg); |
785 | /* Text input widths. */ { | 844 | /* Set text input widths. */ { |
786 | const int inputWidth = width_Rect(page->rect) - width_Rect(headings->rect); | 845 | const int inputWidth = width_Rect(page->rect) - width_Rect(headings->rect); |
846 | as_Widget(findChild_Widget(values, "prefs.downloads"))->rect.size.x = inputWidth; | ||
787 | as_Widget(findChild_Widget(values, "prefs.proxy.http"))->rect.size.x = inputWidth; | 847 | as_Widget(findChild_Widget(values, "prefs.proxy.http"))->rect.size.x = inputWidth; |
788 | as_Widget(findChild_Widget(values, "prefs.proxy.gopher"))->rect.size.x = inputWidth; | 848 | as_Widget(findChild_Widget(values, "prefs.proxy.gopher"))->rect.size.x = inputWidth; |
789 | } | 849 | } |