Changeset 6aa85c1 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:
- b36ebb42
- Parents:
- 5d466a1
- git-author:
- Jiri Svoboda <jiri@…> (2021-10-03 17:39:36)
- git-committer:
- jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
- Location:
- uspace/app/nav
- Files:
-
- 7 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/menu.c
r5d466a1 r6aa85c1 47 47 /** Create navigator menu. 48 48 * 49 * @param navigator Navigator49 * @param window Navigator window 50 50 * @param rmenu Place to store pointer to new menu 51 51 * @return EOK on success or an error code 52 52 */ 53 errno_t nav_menu_create( navigator_t *navigator, nav_menu_t **rmenu)53 errno_t nav_menu_create(ui_window_t *window, nav_menu_t **rmenu) 54 54 { 55 55 nav_menu_t *menu; … … 64 64 return ENOMEM; 65 65 66 rc = ui_menu_bar_create(navigator->ui, navigator->window, 66 menu->window = window; 67 menu->ui = ui_window_get_ui(window); 68 69 rc = ui_menu_bar_create(menu->ui, menu->window, 67 70 &menu->menubar); 68 71 if (rc != EOK) … … 77 80 goto error; 78 81 79 ui_menu_entry_set_cb(mexit, nav_file_exit, (void *) navigator);82 ui_menu_entry_set_cb(mexit, nav_file_exit, (void *) menu); 80 83 81 ui_window_get_app_rect( navigator->window, &arect);84 ui_window_get_app_rect(menu->window, &arect); 82 85 83 86 rect.p0 = arect.p0; … … 86 89 ui_menu_bar_set_rect(menu->menubar, &rect); 87 90 88 rc = ui_fixed_add(navigator->fixed, ui_menu_bar_ctl(menu->menubar));89 if (rc != EOK)90 goto error;91 92 menu->navigator = navigator;93 91 *rmenu = menu; 94 92 return EOK; … … 104 102 void nav_menu_destroy(nav_menu_t *menu) 105 103 { 106 if (menu->menubar != NULL) { 107 ui_fixed_remove(menu->navigator->fixed, 108 ui_menu_bar_ctl(menu->menubar)); 104 if (menu->menubar != NULL) 109 105 ui_menu_bar_destroy(menu->menubar); 110 }111 106 112 107 free(menu); 108 } 109 110 /** Return base UI control for the menu bar. 111 * 112 * @param menu Navigator menu 113 * @return UI control 114 */ 115 ui_control_t *nav_menu_ctl(nav_menu_t *menu) 116 { 117 return ui_menu_bar_ctl(menu->menubar); 113 118 } 114 119 -
uspace/app/nav/menu.h
r5d466a1 r6aa85c1 38 38 39 39 #include <errno.h> 40 #include <ui/control.h> 40 41 #include <ui/menu.h> 41 42 #include <ui/menubar.h> 42 43 #include <ui/menuentry.h> 44 #include <ui/ui.h> 45 #include <ui/window.h> 43 46 #include "nav.h" 44 47 45 48 /** Navigator menu */ 46 49 typedef struct nav_menu { 47 navigator_t *navigator; 50 ui_t *ui; 51 ui_window_t *window; 48 52 ui_menu_bar_t *menubar; 49 53 } nav_menu_t; 50 54 51 extern errno_t nav_menu_create( navigator_t *, nav_menu_t **);55 extern errno_t nav_menu_create(ui_window_t *, nav_menu_t **); 52 56 extern void nav_menu_destroy(nav_menu_t *); 57 extern ui_control_t *nav_menu_ctl(nav_menu_t *); 53 58 54 59 #endif -
uspace/app/nav/meson.build
r5d466a1 r6aa85c1 29 29 deps = [ 'ui' ] 30 30 src = files( 31 'main.c', 31 32 'menu.c', 32 33 'nav.c', 34 'panel.c', 33 35 ) 36 37 test_src = files( 38 'menu.c', 39 'nav.c', 40 'panel.c', 41 'test/main.c', 42 'test/menu.c', 43 'test/nav.c', 44 'test/panel.c', 45 ) -
uspace/app/nav/nav.c
r5d466a1 r6aa85c1 46 46 #include "nav.h" 47 47 48 static errno_t navigator_create(const char *, navigator_t **);49 static void navigator_destroy(navigator_t *);50 51 48 static void wnd_close(ui_window_t *, void *); 52 49 … … 73 70 * @return EOK on success or ane error code 74 71 */ 75 staticerrno_t navigator_create(const char *display_spec,72 errno_t navigator_create(const char *display_spec, 76 73 navigator_t **rnavigator) 77 74 { … … 111 108 ui_window_add(navigator->window, ui_fixed_ctl(navigator->fixed)); 112 109 113 rc = nav_menu_create(navigator , &navigator->menu);110 rc = nav_menu_create(navigator->window, &navigator->menu); 114 111 if (rc != EOK) 115 112 goto error; 113 114 rc = ui_fixed_add(navigator->fixed, nav_menu_ctl(navigator->menu)); 115 if (rc != EOK) { 116 printf("Error adding control to layout.\n"); 117 return rc; 118 } 116 119 117 120 rc = ui_window_paint(navigator->window); … … 128 131 } 129 132 130 staticvoid navigator_destroy(navigator_t *navigator)133 void navigator_destroy(navigator_t *navigator) 131 134 { 135 ui_fixed_remove(navigator->fixed, nav_menu_ctl(navigator->menu)); 136 132 137 if (navigator->menu != NULL) 133 138 nav_menu_destroy(navigator->menu); … … 140 145 141 146 /** Run navigator on the specified display. */ 142 staticerrno_t navigator_run(const char *display_spec)147 errno_t navigator_run(const char *display_spec) 143 148 { 144 149 navigator_t *navigator; … … 155 160 } 156 161 157 static void print_syntax(void)158 {159 printf("Syntax: nav [-d <display-spec>]\n");160 }161 162 int main(int argc, char *argv[])163 {164 const char *display_spec = UI_CONSOLE_DEFAULT;165 errno_t rc;166 int i;167 168 i = 1;169 while (i < argc && argv[i][0] == '-') {170 if (str_cmp(argv[i], "-d") == 0) {171 ++i;172 if (i >= argc) {173 printf("Argument missing.\n");174 print_syntax();175 return 1;176 }177 178 display_spec = argv[i++];179 } else {180 printf("Invalid option '%s'.\n", argv[i]);181 print_syntax();182 return 1;183 }184 }185 186 if (i < argc) {187 print_syntax();188 return 1;189 }190 191 rc = navigator_run(display_spec);192 if (rc != EOK)193 return 1;194 195 return 0;196 }197 198 162 /** @} 199 163 */ -
uspace/app/nav/nav.h
r5d466a1 r6aa85c1 37 37 #define NAV_H 38 38 39 #include <errno.h> 39 40 #include <display.h> 40 41 #include <ui/fixed.h> … … 54 55 } navigator_t; 55 56 57 extern errno_t navigator_create(const char *, navigator_t **); 58 extern void navigator_destroy(navigator_t *); 59 extern errno_t navigator_run(const char *); 60 61 56 62 #endif 57 63
Note:
See TracChangeset
for help on using the changeset viewer.