diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-25 14:23:46 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-25 14:23:46 +0300 |
commit | 40421af6e6571b58b97b3e3372641de3b3ba60d8 (patch) | |
tree | c319e2feccb677d17a0f1222ca760e9188c4cabd /src/ui/util.c | |
parent | e8233ba5c6f6933d6d20e114192934e1145a750e (diff) |
Fixed event processing for menus and dialogs
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 9487e004..8fc7f9e3 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -165,6 +165,7 @@ static iBool menuHandler_(iWidget *menu, const char *cmd) { | |||
165 | 165 | ||
166 | iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | 166 | iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { |
167 | iWidget *menu = new_Widget(); | 167 | iWidget *menu = new_Widget(); |
168 | setFrameColor_Widget(menu, black_ColorId); | ||
168 | setBackgroundColor_Widget(menu, gray25_ColorId); | 169 | setBackgroundColor_Widget(menu, gray25_ColorId); |
169 | setFlags_Widget(menu, | 170 | setFlags_Widget(menu, |
170 | keepOnTop_WidgetFlag | hidden_WidgetFlag | arrangeVertical_WidgetFlag | | 171 | keepOnTop_WidgetFlag | hidden_WidgetFlag | arrangeVertical_WidgetFlag | |
@@ -194,7 +195,7 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { | |||
194 | 195 | ||
195 | void openMenu_Widget(iWidget *d, iInt2 coord) { | 196 | void openMenu_Widget(iWidget *d, iInt2 coord) { |
196 | /* Menu closes when commands are emitted, so handle any pending ones beforehand. */ | 197 | /* Menu closes when commands are emitted, so handle any pending ones beforehand. */ |
197 | processEvents_App(); | 198 | processEvents_App(postedEventsOnly_AppEventMode); |
198 | setFlags_Widget(d, hidden_WidgetFlag, iFalse); | 199 | setFlags_Widget(d, hidden_WidgetFlag, iFalse); |
199 | arrange_Widget(d); | 200 | arrange_Widget(d); |
200 | d->rect.pos = coord; | 201 | d->rect.pos = coord; |
@@ -213,10 +214,27 @@ void openMenu_Widget(iWidget *d, iInt2 coord) { | |||
213 | if (left_Rect(d->rect) < 0) { | 214 | if (left_Rect(d->rect) < 0) { |
214 | d->rect.pos.x = 0; | 215 | d->rect.pos.x = 0; |
215 | } | 216 | } |
217 | refresh_App(); | ||
216 | } | 218 | } |
217 | 219 | ||
218 | void closeMenu_Widget(iWidget *d) { | 220 | void closeMenu_Widget(iWidget *d) { |
219 | setFlags_Widget(d, hidden_WidgetFlag, iTrue); | 221 | setFlags_Widget(d, hidden_WidgetFlag, iTrue); |
222 | refresh_App(); | ||
223 | } | ||
224 | |||
225 | int checkContextMenu_Widget(iWidget *menu, const SDL_Event *ev) { | ||
226 | if (ev->type == SDL_MOUSEBUTTONDOWN && ev->button.button == SDL_BUTTON_RIGHT) { | ||
227 | if (isVisible_Widget(menu)) { | ||
228 | closeMenu_Widget(menu); | ||
229 | return 0x1; | ||
230 | } | ||
231 | const iInt2 mousePos = init_I2(ev->button.x, ev->button.y); | ||
232 | if (contains_Widget(menu->parent, mousePos)) { | ||
233 | openMenu_Widget(menu, localCoord_Widget(menu->parent, mousePos)); | ||
234 | } | ||
235 | return 0x2; | ||
236 | } | ||
237 | return 0; | ||
220 | } | 238 | } |
221 | 239 | ||
222 | iLabelWidget *makeMenuButton_LabelWidget(const char *label, const iMenuItem *items, size_t n) { | 240 | iLabelWidget *makeMenuButton_LabelWidget(const char *label, const iMenuItem *items, size_t n) { |
@@ -406,6 +424,7 @@ iBool filePathHandler_(iWidget *dlg, const char *cmd) { | |||
406 | iWidget *makeSheet_Widget(const char *id) { | 424 | iWidget *makeSheet_Widget(const char *id) { |
407 | iWidget *sheet = new_Widget(); | 425 | iWidget *sheet = new_Widget(); |
408 | setId_Widget(sheet, id); | 426 | setId_Widget(sheet, id); |
427 | setFrameColor_Widget(sheet, black_ColorId); | ||
409 | setBackgroundColor_Widget(sheet, gray25_ColorId); | 428 | setBackgroundColor_Widget(sheet, gray25_ColorId); |
410 | setFlags_Widget(sheet, | 429 | setFlags_Widget(sheet, |
411 | keepOnTop_WidgetFlag | arrangeVertical_WidgetFlag | | 430 | keepOnTop_WidgetFlag | arrangeVertical_WidgetFlag | |
@@ -429,7 +448,7 @@ void makeFilePath_Widget(iWidget * parent, | |||
429 | const char * acceptLabel, | 448 | const char * acceptLabel, |
430 | const char * command) { | 449 | const char * command) { |
431 | setFocus_Widget(NULL); | 450 | setFocus_Widget(NULL); |
432 | processEvents_App(); | 451 | processEvents_App(postedEventsOnly_AppEventMode); |
433 | iWidget *dlg = makeSheet_Widget(command); | 452 | iWidget *dlg = makeSheet_Widget(command); |
434 | setCommandHandler_Widget(dlg, filePathHandler_); | 453 | setCommandHandler_Widget(dlg, filePathHandler_); |
435 | addChild_Widget(parent, iClob(dlg)); | 454 | addChild_Widget(parent, iClob(dlg)); |
@@ -487,7 +506,7 @@ iBool valueInputHandler_(iWidget *dlg, const char *cmd) { | |||
487 | iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, const char *title, | 506 | iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, const char *title, |
488 | const char *prompt, const char *command) { | 507 | const char *prompt, const char *command) { |
489 | setFocus_Widget(NULL); | 508 | setFocus_Widget(NULL); |
490 | processEvents_App(); | 509 | processEvents_App(postedEventsOnly_AppEventMode); |
491 | iWidget *dlg = makeSheet_Widget(command); | 510 | iWidget *dlg = makeSheet_Widget(command); |
492 | setCommandHandler_Widget(dlg, valueInputHandler_); | 511 | setCommandHandler_Widget(dlg, valueInputHandler_); |
493 | addChild_Widget(parent, iClob(dlg)); | 512 | addChild_Widget(parent, iClob(dlg)); |
@@ -530,7 +549,7 @@ iWidget *makeQuestion_Widget(const char *title, | |||
530 | const char *labels[], | 549 | const char *labels[], |
531 | const char *commands[], | 550 | const char *commands[], |
532 | size_t count) { | 551 | size_t count) { |
533 | processEvents_App(); | 552 | processEvents_App(postedEventsOnly_AppEventMode); |
534 | iWidget *dlg = makeSheet_Widget(""); | 553 | iWidget *dlg = makeSheet_Widget(""); |
535 | setCommandHandler_Widget(dlg, messageHandler_); | 554 | setCommandHandler_Widget(dlg, messageHandler_); |
536 | addChild_Widget(dlg, iClob(new_LabelWidget(title, 0, 0, NULL))); | 555 | addChild_Widget(dlg, iClob(new_LabelWidget(title, 0, 0, NULL))); |