diff options
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index c468ba2b..cf75a2b0 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -426,10 +426,8 @@ iWidget *makeSheet_Widget(const char *id) { | |||
426 | setId_Widget(sheet, id); | 426 | setId_Widget(sheet, id); |
427 | setFrameColor_Widget(sheet, black_ColorId); | 427 | setFrameColor_Widget(sheet, black_ColorId); |
428 | setBackgroundColor_Widget(sheet, gray25_ColorId); | 428 | setBackgroundColor_Widget(sheet, gray25_ColorId); |
429 | setFlags_Widget(sheet, | 429 | setFlags_Widget( |
430 | keepOnTop_WidgetFlag | arrangeVertical_WidgetFlag | | 430 | sheet, keepOnTop_WidgetFlag | arrangeVertical_WidgetFlag | arrangeHeight_WidgetFlag, iTrue); |
431 | arrangeHeight_WidgetFlag, | ||
432 | iTrue); | ||
433 | const iInt2 rootSize = rootSize_Window(get_Window()); | 431 | const iInt2 rootSize = rootSize_Window(get_Window()); |
434 | setSize_Widget(sheet, init_I2(rootSize.x / 2, 0)); | 432 | setSize_Widget(sheet, init_I2(rootSize.x / 2, 0)); |
435 | setFlags_Widget(sheet, fixedHeight_WidgetFlag, iFalse); | 433 | setFlags_Widget(sheet, fixedHeight_WidgetFlag, iFalse); |
@@ -440,6 +438,7 @@ void centerSheet_Widget(iWidget *sheet) { | |||
440 | arrange_Widget(sheet); | 438 | arrange_Widget(sheet); |
441 | const iInt2 rootSize = rootSize_Window(get_Window()); | 439 | const iInt2 rootSize = rootSize_Window(get_Window()); |
442 | sheet->rect.pos.x = rootSize.x / 2 - sheet->rect.size.x / 2; | 440 | sheet->rect.pos.x = rootSize.x / 2 - sheet->rect.size.x / 2; |
441 | postRefresh_App(); | ||
443 | } | 442 | } |
444 | 443 | ||
445 | void makeFilePath_Widget(iWidget * parent, | 444 | void makeFilePath_Widget(iWidget * parent, |
@@ -479,19 +478,38 @@ static void acceptValueInput_(iWidget *dlg) { | |||
479 | cstr_String(val)); | 478 | cstr_String(val)); |
480 | } | 479 | } |
481 | 480 | ||
481 | static void updateValueInputWidth_(iWidget *dlg) { | ||
482 | const iInt2 rootSize = rootSize_Window(get_Window()); | ||
483 | iWidget * title = findChild_Widget(dlg, "valueinput.title"); | ||
484 | iWidget * prompt = findChild_Widget(dlg, "valueinput.prompt"); | ||
485 | dlg->rect.size.x = iMaxi(iMaxi(rootSize.x / 2, title->rect.size.x), prompt->rect.size.x); | ||
486 | as_Widget(findChild_Widget(dlg, "input"))->rect.size.x = dlg->rect.size.x; | ||
487 | centerSheet_Widget(dlg); | ||
488 | } | ||
489 | |||
482 | iBool valueInputHandler_(iWidget *dlg, const char *cmd) { | 490 | iBool valueInputHandler_(iWidget *dlg, const char *cmd) { |
483 | iWidget *ptr = as_Widget(pointer_Command(cmd)); | 491 | iWidget *ptr = as_Widget(pointer_Command(cmd)); |
492 | if (equal_Command(cmd, "window.resized")) { | ||
493 | if (isVisible_Widget(dlg)) { | ||
494 | updateValueInputWidth_(dlg); | ||
495 | } | ||
496 | return iFalse; | ||
497 | } | ||
484 | if (equal_Command(cmd, "input.ended")) { | 498 | if (equal_Command(cmd, "input.ended")) { |
485 | if (hasParent_Widget(ptr, dlg)) { | 499 | if (hasParent_Widget(ptr, dlg)) { |
486 | if (arg_Command(cmd)) { | 500 | if (arg_Command(cmd)) { |
487 | acceptValueInput_(dlg); | 501 | acceptValueInput_(dlg); |
488 | } | 502 | } |
503 | else { | ||
504 | postCommandf_App("valueinput.cancelled id:%s", cstr_String(id_Widget(dlg))); | ||
505 | } | ||
489 | destroy_Widget(dlg); | 506 | destroy_Widget(dlg); |
490 | return iTrue; | 507 | return iTrue; |
491 | } | 508 | } |
492 | return iFalse; | 509 | return iFalse; |
493 | } | 510 | } |
494 | else if (equal_Command(cmd, "cancel")) { | 511 | else if (equal_Command(cmd, "cancel")) { |
512 | postCommandf_App("valueinput.cancelled id:%s", cstr_String(id_Widget(dlg))); | ||
495 | destroy_Widget(dlg); | 513 | destroy_Widget(dlg); |
496 | return iTrue; | 514 | return iTrue; |
497 | } | 515 | } |
@@ -504,32 +522,48 @@ iBool valueInputHandler_(iWidget *dlg, const char *cmd) { | |||
504 | } | 522 | } |
505 | 523 | ||
506 | iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, const char *title, | 524 | iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, const char *title, |
507 | const char *prompt, const char *command) { | 525 | const char *prompt, const char *acceptLabel, const char *command) { |
508 | setFocus_Widget(NULL); | 526 | if (parent) { |
509 | processEvents_App(postedEventsOnly_AppEventMode); | 527 | setFocus_Widget(NULL); |
528 | processEvents_App(postedEventsOnly_AppEventMode); | ||
529 | } | ||
510 | iWidget *dlg = makeSheet_Widget(command); | 530 | iWidget *dlg = makeSheet_Widget(command); |
511 | setCommandHandler_Widget(dlg, valueInputHandler_); | 531 | setCommandHandler_Widget(dlg, valueInputHandler_); |
512 | addChild_Widget(parent, iClob(dlg)); | 532 | if (parent) { |
513 | addChild_Widget(dlg, iClob(new_LabelWidget(title, 0, 0, NULL))); | 533 | addChild_Widget(parent, iClob(dlg)); |
514 | addChild_Widget(dlg, iClob(new_LabelWidget(prompt, 0, 0, NULL))); | 534 | } |
535 | setId_Widget(addChild_Widget(dlg, iClob(new_LabelWidget(title, 0, 0, NULL))), "valueinput.title"); | ||
536 | setId_Widget(addChild_Widget(dlg, iClob(new_LabelWidget(prompt, 0, 0, NULL))), "valueinput.prompt"); | ||
515 | iInputWidget *input = addChild_Widget(dlg, iClob(new_InputWidget(0))); | 537 | iInputWidget *input = addChild_Widget(dlg, iClob(new_InputWidget(0))); |
516 | if (initialValue) { | 538 | if (initialValue) { |
517 | setText_InputWidget(input, initialValue); | 539 | setText_InputWidget(input, initialValue); |
518 | } | 540 | } |
519 | setId_Widget(as_Widget(input), "input"); | 541 | setId_Widget(as_Widget(input), "input"); |
520 | as_Widget(input)->rect.size.x = dlg->rect.size.x; | 542 | updateValueInputWidth_(dlg); |
521 | addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI))); | 543 | addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI))); |
522 | iWidget *div = new_Widget(); { | 544 | iWidget *div = new_Widget(); { |
523 | setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); | 545 | setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); |
524 | addChild_Widget(div, iClob(new_LabelWidget("Cancel", SDLK_ESCAPE, 0, "cancel"))); | 546 | addChild_Widget(div, iClob(new_LabelWidget("Cancel", SDLK_ESCAPE, 0, "cancel"))); |
525 | addChild_Widget(div, iClob(new_LabelWidget(cyan_ColorEscape "OK", SDLK_RETURN, 0, "valueinput.accept"))); | 547 | addChild_Widget(div, |
548 | iClob(new_LabelWidget(acceptLabel ? acceptLabel : cyan_ColorEscape "OK", | ||
549 | SDLK_RETURN, | ||
550 | 0, | ||
551 | "valueinput.accept"))); | ||
526 | } | 552 | } |
527 | addChild_Widget(dlg, iClob(div)); | 553 | addChild_Widget(dlg, iClob(div)); |
528 | centerSheet_Widget(dlg); | 554 | centerSheet_Widget(dlg); |
529 | setFocus_Widget(as_Widget(input)); | 555 | if (parent) { |
556 | setFocus_Widget(as_Widget(input)); | ||
557 | } | ||
530 | return dlg; | 558 | return dlg; |
531 | } | 559 | } |
532 | 560 | ||
561 | void updateValueInput_Widget(iWidget *d, const char *title, const char *prompt) { | ||
562 | setTextCStr_LabelWidget(findChild_Widget(d, "valueinput.title"), title); | ||
563 | setTextCStr_LabelWidget(findChild_Widget(d, "valueinput.prompt"), prompt); | ||
564 | updateValueInputWidth_(d); | ||
565 | } | ||
566 | |||
533 | static iBool messageHandler_(iWidget *msg, const char *cmd) { | 567 | static iBool messageHandler_(iWidget *msg, const char *cmd) { |
534 | /* Any command dismisses the sheet. */ | 568 | /* Any command dismisses the sheet. */ |
535 | iUnused(cmd); | 569 | iUnused(cmd); |