Changeset 379cd75f in mainline


Ignore:
Timestamp:
2021-04-01T21:04:11Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Children:
0563982
Parents:
cd62879
Message:

Close menu when window is unfocused

This of course means we need to do all the plumbing for delivering
unfocus event to UI controls.

Location:
uspace/lib/ui
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/include/types/ui/control.h

    rcd62879 r379cd75f  
    5252        /** Position event */
    5353        ui_evclaim_t (*pos_event)(void *, pos_event_t *);
     54        /** Unfocus */
     55        void (*unfocus)(void *);
    5456} ui_control_ops_t;
    5557
  • uspace/lib/ui/include/ui/control.h

    rcd62879 r379cd75f  
    4747extern errno_t ui_control_paint(ui_control_t *);
    4848extern ui_evclaim_t ui_control_pos_event(ui_control_t *, pos_event_t *);
     49extern void ui_control_unfocus(ui_control_t *);
    4950
    5051#endif
  • uspace/lib/ui/include/ui/fixed.h

    rcd62879 r379cd75f  
    5050extern errno_t ui_fixed_paint(ui_fixed_t *);
    5151extern ui_evclaim_t ui_fixed_pos_event(ui_fixed_t *, pos_event_t *);
     52extern void ui_fixed_unfocus(ui_fixed_t *);
    5253
    5354#endif
  • uspace/lib/ui/include/ui/menubar.h

    rcd62879 r379cd75f  
    5252extern errno_t ui_menu_bar_paint(ui_menu_bar_t *);
    5353extern ui_evclaim_t ui_menu_bar_pos_event(ui_menu_bar_t *, pos_event_t *);
     54extern void ui_menu_bar_unfocus(ui_menu_bar_t *);
    5455
    5556#endif
  • uspace/lib/ui/include/ui/window.h

    rcd62879 r379cd75f  
    6161extern errno_t ui_window_def_paint(ui_window_t *);
    6262extern void ui_window_def_pos(ui_window_t *, pos_event_t *);
     63extern void ui_window_def_unfocus(ui_window_t *);
    6364
    6465#endif
  • uspace/lib/ui/src/control.c

    rcd62879 r379cd75f  
    112112}
    113113
     114/** Inform UI control that window has been unfocused.
     115 *
     116 * @param control Control
     117 */
     118void ui_control_unfocus(ui_control_t *control)
     119{
     120        if (control->ops->unfocus != NULL)
     121                control->ops->unfocus(control->ext);
     122}
     123
    114124/** @}
    115125 */
  • uspace/lib/ui/src/fixed.c

    rcd62879 r379cd75f  
    4747static errno_t ui_fixed_ctl_paint(void *);
    4848static ui_evclaim_t ui_fixed_ctl_pos_event(void *, pos_event_t *);
     49static void ui_fixed_ctl_unfocus(void *);
    4950
    5051/** Push button control ops */
     
    5253        .destroy = ui_fixed_ctl_destroy,
    5354        .paint = ui_fixed_ctl_paint,
    54         .pos_event = ui_fixed_ctl_pos_event
     55        .pos_event = ui_fixed_ctl_pos_event,
     56        .unfocus = ui_fixed_ctl_unfocus
    5557};
    5658
     
    232234}
    233235
     236/** Handle fixed layout window unfocus notification.
     237 *
     238 * @param fixed Fixed layout
     239 */
     240void ui_fixed_unfocus(ui_fixed_t *fixed)
     241{
     242        ui_fixed_elem_t *elem;
     243
     244        elem = ui_fixed_first(fixed);
     245        while (elem != NULL) {
     246                ui_control_unfocus(elem->control);
     247
     248                elem = ui_fixed_next(elem);
     249        }
     250}
     251
    234252/** Destroy fixed layout control.
    235253 *
     
    268286}
    269287
     288/** Handle fixed layout control window unfocus notification.
     289 *
     290 * @param arg Argument (ui_fixed_t *)
     291 */
     292void ui_fixed_ctl_unfocus(void *arg)
     293{
     294        ui_fixed_t *fixed = (ui_fixed_t *) arg;
     295
     296        ui_fixed_unfocus(fixed);
     297}
     298
    270299/** @}
    271300 */
  • uspace/lib/ui/src/menubar.c

    rcd62879 r379cd75f  
    6060static errno_t ui_menu_bar_ctl_paint(void *);
    6161static ui_evclaim_t ui_menu_bar_ctl_pos_event(void *, pos_event_t *);
     62static void ui_menu_bar_ctl_unfocus(void *);
    6263
    6364/** Menu bar control ops */
     
    6566        .destroy = ui_menu_bar_ctl_destroy,
    6667        .paint = ui_menu_bar_ctl_paint,
    67         .pos_event = ui_menu_bar_ctl_pos_event
     68        .pos_event = ui_menu_bar_ctl_pos_event,
     69        .unfocus = ui_menu_bar_ctl_unfocus
    6870};
    6971
     
    328330}
    329331
     332/** Handle menu bar window unfocus notification.
     333 *
     334 * @param mbar Menu bar
     335 */
     336void ui_menu_bar_unfocus(ui_menu_bar_t *mbar)
     337{
     338        ui_menu_bar_select(mbar, NULL, NULL);
     339}
     340
    330341/** Destroy menu bar control.
    331342 *
     
    364375}
    365376
     377/** Handle menu bar control window unfocus notification.
     378 *
     379 * @param arg Argument (ui_menu_bar_t *)
     380 */
     381void ui_menu_bar_ctl_unfocus(void *arg)
     382{
     383        ui_menu_bar_t *mbar = (ui_menu_bar_t *) arg;
     384
     385        ui_menu_bar_unfocus(mbar);
     386}
     387
    366388/** @}
    367389 */
  • uspace/lib/ui/src/window.c

    rcd62879 r379cd75f  
    815815        if (window->cb != NULL && window->cb->unfocus != NULL)
    816816                window->cb->unfocus(window, window->arg);
     817        else
     818                return ui_window_def_unfocus(window);
    817819}
    818820
     
    850852 *
    851853 * @param window Window
    852  * @return EOK on success or an error code
    853854 */
    854855void ui_window_def_pos(ui_window_t *window, pos_event_t *pos)
     
    856857        if (window->control != NULL)
    857858                ui_control_pos_event(window->control, pos);
     859}
     860
     861/** Default window unfocus routine.
     862 *
     863 * @param window Window
     864 * @return EOK on success or an error code
     865 */
     866void ui_window_def_unfocus(ui_window_t *window)
     867{
     868        if (window->control != NULL)
     869                ui_control_unfocus(window->control);
    858870}
    859871
  • uspace/lib/ui/test/control.c

    rcd62879 r379cd75f  
    4242static errno_t test_ctl_paint(void *);
    4343static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
     44static void test_ctl_unfocus(void *);
    4445
    4546static ui_control_ops_t test_ctl_ops = {
    4647        .destroy = test_ctl_destroy,
    4748        .paint = test_ctl_paint,
    48         .pos_event = test_ctl_pos_event
     49        .pos_event = test_ctl_pos_event,
     50        .unfocus = test_ctl_unfocus
    4951};
    5052
     
    6668        /** Position event that was sent */
    6769        pos_event_t pevent;
     70
     71        /** @c true iff unfocus was called */
     72        bool unfocus;
    6873} test_resp_t;
    6974
     
    166171}
    167172
     173/** Test sending unfocus to control */
     174PCUT_TEST(unfocus)
     175{
     176        ui_control_t *control = NULL;
     177        test_resp_t resp;
     178        errno_t rc;
     179
     180        rc = ui_control_new(&test_ctl_ops, &resp, &control);
     181        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     182        PCUT_ASSERT_NOT_NULL(control);
     183
     184        resp.unfocus = false;
     185
     186        ui_control_unfocus(control);
     187        PCUT_ASSERT_TRUE(resp.unfocus);
     188
     189        ui_control_delete(control);
     190}
     191
    168192static void test_ctl_destroy(void *arg)
    169193{
     
    191215}
    192216
     217static void test_ctl_unfocus(void *arg)
     218{
     219        test_resp_t *resp = (test_resp_t *) arg;
     220
     221        resp->unfocus = true;
     222}
     223
    193224PCUT_EXPORT(control);
  • uspace/lib/ui/test/fixed.c

    rcd62879 r379cd75f  
    4141static errno_t test_ctl_paint(void *);
    4242static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
     43static void test_ctl_unfocus(void *);
    4344
    4445static ui_control_ops_t test_ctl_ops = {
    4546        .destroy = test_ctl_destroy,
    4647        .paint = test_ctl_paint,
    47         .pos_event = test_ctl_pos_event
     48        .pos_event = test_ctl_pos_event,
     49        .unfocus = test_ctl_unfocus
    4850};
    4951
     
    6264        /** Position event that was sent */
    6365        pos_event_t pevent;
     66        /** @c true iff unfocus was called */
     67        bool unfocus;
    6468} test_resp_t;
    6569
     
    230234}
    231235
     236/** ui_fixed_unfocus() delivers unfocus notification to control */
     237PCUT_TEST(unfocus)
     238{
     239        ui_fixed_t *fixed = NULL;
     240        ui_control_t *control;
     241        test_resp_t resp;
     242        errno_t rc;
     243
     244        rc = ui_fixed_create(&fixed);
     245        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     246
     247        rc = ui_control_new(&test_ctl_ops, (void *) &resp, &control);
     248        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     249
     250        rc = ui_fixed_add(fixed, control);
     251        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     252
     253        resp.unfocus = false;
     254
     255        ui_fixed_unfocus(fixed);
     256        PCUT_ASSERT_TRUE(resp.unfocus);
     257
     258        ui_fixed_destroy(fixed);
     259}
     260
    232261static void test_ctl_destroy(void *arg)
    233262{
     
    255284}
    256285
     286static void test_ctl_unfocus(void *arg)
     287{
     288        test_resp_t *resp = (test_resp_t *) arg;
     289
     290        resp->unfocus = true;
     291}
     292
    257293PCUT_EXPORT(fixed);
  • uspace/lib/ui/test/window.c

    rcd62879 r379cd75f  
    6666static errno_t test_ctl_paint(void *);
    6767static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
     68static void test_ctl_unfocus(void *);
    6869
    6970static ui_control_ops_t test_ctl_ops = {
    7071        .paint = test_ctl_paint,
    71         .pos_event = test_ctl_pos_event
     72        .pos_event = test_ctl_pos_event,
     73        .unfocus = test_ctl_unfocus
    7274};
    7375
     
    9092        bool pos;
    9193        pos_event_t pos_event;
     94        bool unfocus;
    9295} test_ctl_resp_t;
    9396
     
    388391        PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos_event.hpos);
    389392        PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos_event.vpos);
     393
     394        /* Need to remove first because we didn't implement the destructor */
     395        ui_window_remove(window, control);
     396
     397        ui_window_destroy(window);
     398        ui_destroy(ui);
     399}
     400
     401/** ui_window_def_unfocus() delivers unfocus event to control in window */
     402PCUT_TEST(def_unfocus)
     403{
     404        errno_t rc;
     405        ui_t *ui = NULL;
     406        ui_wnd_params_t params;
     407        ui_window_t *window = NULL;
     408        ui_control_t *control = NULL;
     409        test_ctl_resp_t resp;
     410
     411        rc = ui_create_disp(NULL, &ui);
     412        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     413
     414        ui_wnd_params_init(&params);
     415        params.caption = "Hello";
     416
     417        rc = ui_window_create(ui, &params, &window);
     418        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     419
     420        rc = ui_control_new(&test_ctl_ops, &resp, &control);
     421        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     422
     423        ui_window_add(window, control);
     424
     425        resp.unfocus = false;
     426
     427        ui_window_def_unfocus(window);
     428        PCUT_ASSERT_TRUE(resp.unfocus);
    390429
    391430        /* Need to remove first because we didn't implement the destructor */
     
    701740}
    702741
     742static void test_ctl_unfocus(void *arg)
     743{
     744        test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
     745
     746        resp->unfocus = true;
     747}
     748
    703749PCUT_EXPORT(window);
Note: See TracChangeset for help on using the changeset viewer.