Changeset f59212cc 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:
- c632c96
- Parents:
- 5bbb4453
- git-author:
- Jiri Svoboda <jiri@…> (2021-10-19 20:54:17)
- git-committer:
- jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/menu.c
r5bbb4453 rf59212cc 43 43 #include "nav.h" 44 44 45 static void nav_file_exit(ui_menu_entry_t *, void *);46 47 45 /** Create navigator menu. 48 46 * … … 55 53 nav_menu_t *menu; 56 54 ui_menu_t *mfile; 55 ui_menu_entry_t *mopen; 56 ui_menu_entry_t *mfsep; 57 57 ui_menu_entry_t *mexit; 58 58 gfx_rect_t arect; … … 76 76 goto error; 77 77 78 rc = ui_menu_entry_create(mfile, "Open", "Enter", &mopen); 79 if (rc != EOK) 80 goto error; 81 82 ui_menu_entry_set_cb(mopen, nav_menu_file_open, (void *) menu); 83 84 rc = ui_menu_entry_sep_create(mfile, &mfsep); 85 if (rc != EOK) 86 goto error; 87 78 88 rc = ui_menu_entry_create(mfile, "Exit", "Ctrl-Q", &mexit); 79 89 if (rc != EOK) 80 90 goto error; 81 91 82 ui_menu_entry_set_cb(mexit, nav_ file_exit, (void *) menu);92 ui_menu_entry_set_cb(mexit, nav_menu_file_exit, (void *) menu); 83 93 84 94 ui_window_get_app_rect(menu->window, &arect); … … 94 104 nav_menu_destroy(menu); 95 105 return rc; 106 } 107 108 /** Set navigator menu callbacks. 109 * 110 * @param menu Menu 111 * @param cb Callbacks 112 * @param arg Argument to callback functions 113 */ 114 void nav_menu_set_cb(nav_menu_t *menu, nav_menu_cb_t *cb, void *arg) 115 { 116 menu->cb = cb; 117 menu->cb_arg = arg; 96 118 } 97 119 … … 118 140 } 119 141 142 /** File / Open menu entry selected. 143 * 144 * @param mentry Menu entry 145 * @param arg Argument (navigator_t *) 146 */ 147 void nav_menu_file_open(ui_menu_entry_t *mentry, void *arg) 148 { 149 nav_menu_t *menu = (nav_menu_t *)arg; 150 151 if (menu->cb != NULL && menu->cb->file_open != NULL) 152 menu->cb->file_open(menu->cb_arg); 153 } 154 120 155 /** File / Exit menu entry selected. 121 156 * … … 123 158 * @param arg Argument (navigator_t *) 124 159 */ 125 static void nav_file_exit(ui_menu_entry_t *mentry, void *arg)160 void nav_menu_file_exit(ui_menu_entry_t *mentry, void *arg) 126 161 { 127 nav igator_t *navigator = (navigator_t *)arg;162 nav_menu_t *menu = (nav_menu_t *)arg; 128 163 129 ui_quit(navigator->ui); 164 if (menu->cb != NULL && menu->cb->file_exit != NULL) 165 menu->cb->file_exit(menu->cb_arg); 130 166 } 131 167 -
uspace/app/nav/menu.h
r5bbb4453 rf59212cc 38 38 39 39 #include <errno.h> 40 #include <ui/menuentry.h> 40 41 #include <ui/window.h> 41 42 #include "types/menu.h" 42 43 43 44 extern errno_t nav_menu_create(ui_window_t *, nav_menu_t **); 45 extern void nav_menu_set_cb(nav_menu_t *, nav_menu_cb_t *, void *); 44 46 extern void nav_menu_destroy(nav_menu_t *); 45 47 extern ui_control_t *nav_menu_ctl(nav_menu_t *); 48 extern void nav_menu_file_open(ui_menu_entry_t *, void *); 49 extern void nav_menu_file_exit(ui_menu_entry_t *, void *); 46 50 47 51 #endif -
uspace/app/nav/nav.c
r5bbb4453 rf59212cc 55 55 }; 56 56 57 static void navigator_file_open(void *); 58 static void navigator_file_exit(void *); 59 60 static nav_menu_cb_t navigator_menu_cb = { 61 .file_open = navigator_file_open, 62 .file_exit = navigator_file_exit 63 }; 64 57 65 /** Window close button was clicked. 58 66 * … … 154 162 goto error; 155 163 164 nav_menu_set_cb(navigator->menu, &navigator_menu_cb, 165 (void *)navigator); 166 156 167 rc = ui_fixed_add(navigator->fixed, nav_menu_ctl(navigator->menu)); 157 168 if (rc != EOK) { … … 278 289 } 279 290 291 /** File / Open menu entry selected */ 292 static void navigator_file_open(void *arg) 293 { 294 navigator_t *navigator = (navigator_t *)arg; 295 panel_t *panel; 296 297 panel = navigator_get_active_panel(navigator); 298 panel_open(panel, panel->cursor); 299 } 300 301 /** File / Exit menu entry selected */ 302 static void navigator_file_exit(void *arg) 303 { 304 navigator_t *navigator = (navigator_t *)arg; 305 306 ui_quit(navigator->ui); 307 } 308 280 309 /** @} 281 310 */ -
uspace/app/nav/test/menu.c
r5bbb4453 rf59212cc 29 29 #include <errno.h> 30 30 #include <pcut/pcut.h> 31 #include <stdbool.h> 31 32 #include "../menu.h" 32 33 … … 34 35 35 36 PCUT_TEST_SUITE(menu); 37 38 static void test_menu_file_open(void *); 39 static void test_menu_file_exit(void *); 40 41 static nav_menu_cb_t dummy_cb; 42 static nav_menu_cb_t test_cb = { 43 .file_open = test_menu_file_open, 44 .file_exit = test_menu_file_exit 45 }; 46 47 /** Test response */ 48 typedef struct { 49 bool file_open; 50 bool file_exit; 51 } test_resp_t; 36 52 37 53 /** Create and destroy menu. */ … … 61 77 } 62 78 79 /** nav_menu_set_cb() */ 80 PCUT_TEST(set_cb) 81 { 82 ui_t *ui; 83 ui_window_t *window; 84 ui_wnd_params_t params; 85 nav_menu_t *menu; 86 int foo; 87 errno_t rc; 88 89 rc = ui_create_disp(NULL, &ui); 90 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 91 92 ui_wnd_params_init(¶ms); 93 params.caption = "Test"; 94 95 rc = ui_window_create(ui, ¶ms, &window); 96 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 97 98 rc = nav_menu_create(window, &menu); 99 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 100 101 nav_menu_set_cb(menu, &test_cb, &foo); 102 PCUT_ASSERT_EQUALS(&test_cb, menu->cb); 103 PCUT_ASSERT_EQUALS(&foo, menu->cb_arg); 104 105 nav_menu_destroy(menu); 106 ui_window_destroy(window); 107 ui_destroy(ui); 108 } 109 110 /** File / Open callback */ 111 PCUT_TEST(file_open) 112 { 113 ui_t *ui; 114 ui_window_t *window; 115 ui_wnd_params_t params; 116 nav_menu_t *menu; 117 test_resp_t resp; 118 errno_t rc; 119 120 rc = ui_create_disp(NULL, &ui); 121 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 122 123 ui_wnd_params_init(¶ms); 124 params.caption = "Test"; 125 126 rc = ui_window_create(ui, ¶ms, &window); 127 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 128 129 rc = nav_menu_create(window, &menu); 130 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 131 132 /* Call back with no callbacks set */ 133 nav_menu_file_open(NULL, menu); 134 135 /* Call back with dummy callbacks set */ 136 nav_menu_set_cb(menu, &dummy_cb, &resp); 137 nav_menu_file_open(NULL, menu); 138 139 /* Call back with test callbacks set */ 140 resp.file_open = false; 141 nav_menu_set_cb(menu, &test_cb, &resp); 142 nav_menu_file_open(NULL, menu); 143 PCUT_ASSERT_TRUE(resp.file_open); 144 145 nav_menu_destroy(menu); 146 ui_window_destroy(window); 147 ui_destroy(ui); 148 } 149 150 /** Testing File / Open callback */ 151 static void test_menu_file_open(void *arg) 152 { 153 test_resp_t *resp = (test_resp_t *)arg; 154 155 resp->file_open = true; 156 } 157 158 /** Testing File / Exit callback */ 159 static void test_menu_file_exit(void *arg) 160 { 161 test_resp_t *resp = (test_resp_t *)arg; 162 163 resp->file_exit = true; 164 } 165 63 166 PCUT_EXPORT(menu); -
uspace/app/nav/types/menu.h
r5bbb4453 rf59212cc 41 41 #include <ui/window.h> 42 42 43 /** Navigator menu callbacks */ 44 typedef struct nav_menu_cb { 45 /** File / Open */ 46 void (*file_open)(void *); 47 /** File / Exit */ 48 void (*file_exit)(void *); 49 } nav_menu_cb_t; 50 43 51 /** Navigator menu */ 44 52 typedef struct nav_menu { 53 /** UI */ 45 54 ui_t *ui; 55 /** Containing window */ 46 56 ui_window_t *window; 57 /** Menu bar */ 47 58 ui_menu_bar_t *menubar; 59 /** Callbacks */ 60 nav_menu_cb_t *cb; 61 /** Callback argument */ 62 void *cb_arg; 48 63 } nav_menu_t; 49 64 -
uspace/lib/ui/include/ui/menuentry.h
r5bbb4453 rf59212cc 39 39 #include <errno.h> 40 40 #include <gfx/coord.h> 41 #include <io/pos_event.h> 41 42 #include <types/ui/menu.h> 42 43 #include <types/ui/menuentry.h>
Note:
See TracChangeset
for help on using the changeset viewer.