Changeset 39ab17c in mainline
- Timestamp:
- 2021-10-25T00:32:45Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e0377075
- Parents:
- c632c96
- git-author:
- Jiri Svoboda <jiri@…> (2021-10-21 17:44:55)
- git-committer:
- jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
- Location:
- uspace/app/nav
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/nav.c
rc632c96 r39ab17c 63 63 }; 64 64 65 static void navigator_panel_activate_req(void *, panel_t *); 66 67 static panel_cb_t navigator_panel_cb = { 68 .activate_req = navigator_panel_activate_req 69 }; 70 65 71 /** Window close button was clicked. 66 72 * … … 183 189 panel_set_rect(navigator->panel[i], &rect); 184 190 191 panel_set_cb(navigator->panel[i], &navigator_panel_cb, 192 navigator); 193 185 194 rc = ui_fixed_add(navigator->fixed, 186 195 panel_ctl(navigator->panel[i])); … … 307 316 } 308 317 318 /** Panel callback requesting panel activation. 319 * 320 * @param arg Argument (navigator_t *) 321 * @param panel Panel 322 */ 323 void navigator_panel_activate_req(void *arg, panel_t *panel) 324 { 325 navigator_t *navigator = (navigator_t *)arg; 326 327 if (!panel_is_active(panel)) 328 navigator_switch_panel(navigator); 329 } 330 309 331 /** @} 310 332 */ -
uspace/app/nav/panel.c
rc632c96 r39ab17c 142 142 ui_control_delete(panel->control); 143 143 free(panel); 144 } 145 146 /** Set panel callbacks. 147 * 148 * @param panel Panel 149 * @param cb Callbacks 150 * @param arg Argument to callback functions 151 */ 152 void panel_set_cb(panel_t *panel, panel_cb_t *cb, void *arg) 153 { 154 panel->cb = cb; 155 panel->cb_arg = arg; 144 156 } 145 157 … … 311 323 ui_evclaim_t panel_pos_event(panel_t *panel, pos_event_t *event) 312 324 { 313 return ui_unclaimed; 325 gfx_coord2_t pos; 326 327 pos.x = event->hpos; 328 pos.y = event->vpos; 329 if (!gfx_pix_inside_rect(&pos, &panel->rect)) 330 return ui_unclaimed; 331 332 if (!panel->active) { 333 panel_activate_req(panel); 334 } 335 336 return ui_claimed; 314 337 } 315 338 … … 1114 1137 } 1115 1138 1139 /** Request panel activation. 1140 * 1141 * Call back to request panel activation. 1142 * 1143 * @param panel Panel 1144 */ 1145 void panel_activate_req(panel_t *panel) 1146 { 1147 if (panel->cb != NULL && panel->cb->activate_req != NULL) 1148 panel->cb->activate_req(panel->cb_arg, panel); 1149 } 1150 1116 1151 /** @} 1117 1152 */ -
uspace/app/nav/panel.h
rc632c96 r39ab17c 48 48 extern errno_t panel_create(ui_window_t *, bool, panel_t **); 49 49 extern void panel_destroy(panel_t *); 50 extern void panel_set_cb(panel_t *, panel_cb_t *, void *); 50 51 extern errno_t panel_entry_paint(panel_entry_t *, size_t); 51 52 extern errno_t panel_paint(panel_t *); … … 79 80 extern errno_t panel_open_dir(panel_t *, panel_entry_t *); 80 81 extern errno_t panel_open_file(panel_t *, panel_entry_t *); 82 extern void panel_activate_req(panel_t *); 83 81 84 82 85 #endif -
uspace/app/nav/test/panel.c
rc632c96 r39ab17c 40 40 PCUT_TEST_SUITE(panel); 41 41 42 /** Test response */ 43 typedef struct { 44 bool activate_req; 45 panel_t *activate_req_panel; 46 } test_resp_t; 47 48 static void test_panel_activate_req(void *, panel_t *); 49 50 static panel_cb_t test_cb = { 51 .activate_req = test_panel_activate_req 52 }; 53 42 54 /** Create and destroy panel. */ 43 55 PCUT_TEST(create_destroy) … … 48 60 rc = panel_create(NULL, true, &panel); 49 61 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 62 63 panel_destroy(panel); 64 } 65 66 /** panel_set_cb() sets callback */ 67 PCUT_TEST(set_cb) 68 { 69 panel_t *panel; 70 errno_t rc; 71 test_resp_t resp; 72 73 rc = panel_create(NULL, true, &panel); 74 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 75 76 panel_set_cb(panel, &test_cb, &resp); 77 PCUT_ASSERT_EQUALS(&test_cb, panel->cb); 78 PCUT_ASSERT_EQUALS(&resp, panel->cb_arg); 50 79 51 80 panel_destroy(panel); … … 1426 1455 } 1427 1456 1457 /** panel_activate_req() sends activation request */ 1458 PCUT_TEST(activate_req) 1459 { 1460 panel_t *panel; 1461 errno_t rc; 1462 test_resp_t resp; 1463 1464 rc = panel_create(NULL, true, &panel); 1465 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1466 1467 panel_set_cb(panel, &test_cb, &resp); 1468 1469 resp.activate_req = false; 1470 resp.activate_req_panel = NULL; 1471 1472 panel_activate_req(panel); 1473 PCUT_ASSERT_TRUE(resp.activate_req); 1474 PCUT_ASSERT_EQUALS(panel, resp.activate_req_panel); 1475 1476 panel_destroy(panel); 1477 } 1478 1479 static void test_panel_activate_req(void *arg, panel_t *panel) 1480 { 1481 test_resp_t *resp = (test_resp_t *)arg; 1482 1483 resp->activate_req = true; 1484 resp->activate_req_panel = panel; 1485 } 1486 1428 1487 PCUT_EXPORT(panel); -
uspace/app/nav/types/panel.h
rc632c96 r39ab17c 83 83 ui_window_t *window; 84 84 85 /** Callbacks */ 86 struct panel_cb *cb; 87 88 /** Callback argument */ 89 void *cb_arg; 90 85 91 /** Panel rectangle */ 86 92 gfx_rect_t rect; … … 126 132 } panel_t; 127 133 134 /** Panel callbacks */ 135 typedef struct panel_cb { 136 /** Request panel activation */ 137 void (*activate_req)(void *, panel_t *); 138 } panel_cb_t; 139 128 140 #endif 129 141
Note:
See TracChangeset
for help on using the changeset viewer.