| [5d466a1] | 1 | /*
|
|---|
| [accdf882] | 2 | * Copyright (c) 2025 Jiri Svoboda
|
|---|
| [5d466a1] | 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup nav
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file Navigator.
|
|---|
| 33 | *
|
|---|
| 34 | * HelenOS file manager.
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <errno.h>
|
|---|
| 38 | #include <stdlib.h>
|
|---|
| 39 | #include <ui/menu.h>
|
|---|
| 40 | #include <ui/menubar.h>
|
|---|
| [46bd63c9] | 41 | #include <ui/menudd.h>
|
|---|
| [5d466a1] | 42 | #include <ui/menuentry.h>
|
|---|
| 43 | #include "menu.h"
|
|---|
| 44 | #include "nav.h"
|
|---|
| 45 |
|
|---|
| 46 | /** Create navigator menu.
|
|---|
| 47 | *
|
|---|
| [6aa85c1] | 48 | * @param window Navigator window
|
|---|
| [5d466a1] | 49 | * @param rmenu Place to store pointer to new menu
|
|---|
| 50 | * @return EOK on success or an error code
|
|---|
| 51 | */
|
|---|
| [6aa85c1] | 52 | errno_t nav_menu_create(ui_window_t *window, nav_menu_t **rmenu)
|
|---|
| [5d466a1] | 53 | {
|
|---|
| 54 | nav_menu_t *menu;
|
|---|
| 55 | ui_menu_t *mfile;
|
|---|
| [f9c4c433] | 56 | ui_menu_entry_t *mnew;
|
|---|
| [f59212cc] | 57 | ui_menu_entry_t *mopen;
|
|---|
| [accdf882] | 58 | ui_menu_entry_t *medit;
|
|---|
| [1ec732a] | 59 | ui_menu_entry_t *mverify;
|
|---|
| [f59212cc] | 60 | ui_menu_entry_t *mfsep;
|
|---|
| [5d466a1] | 61 | ui_menu_entry_t *mexit;
|
|---|
| 62 | gfx_rect_t arect;
|
|---|
| 63 | gfx_rect_t rect;
|
|---|
| 64 | errno_t rc;
|
|---|
| 65 |
|
|---|
| 66 | menu = calloc(1, sizeof(nav_menu_t));
|
|---|
| 67 | if (menu == NULL)
|
|---|
| 68 | return ENOMEM;
|
|---|
| 69 |
|
|---|
| [6aa85c1] | 70 | menu->window = window;
|
|---|
| 71 | menu->ui = ui_window_get_ui(window);
|
|---|
| 72 |
|
|---|
| 73 | rc = ui_menu_bar_create(menu->ui, menu->window,
|
|---|
| [5d466a1] | 74 | &menu->menubar);
|
|---|
| 75 | if (rc != EOK)
|
|---|
| 76 | goto error;
|
|---|
| 77 |
|
|---|
| [46bd63c9] | 78 | rc = ui_menu_dd_create(menu->menubar, "~F~ile", NULL, &mfile);
|
|---|
| [5d466a1] | 79 | if (rc != EOK)
|
|---|
| 80 | goto error;
|
|---|
| 81 |
|
|---|
| [f9c4c433] | 82 | rc = ui_menu_entry_create(mfile, "~N~ew File", "Ctrl-M", &mnew);
|
|---|
| 83 | if (rc != EOK)
|
|---|
| 84 | goto error;
|
|---|
| 85 |
|
|---|
| 86 | ui_menu_entry_set_cb(mnew, nav_menu_file_new_file, (void *) menu);
|
|---|
| 87 |
|
|---|
| [c38ab6c] | 88 | rc = ui_menu_entry_create(mfile, "~O~pen", "Enter", &mopen);
|
|---|
| [f59212cc] | 89 | if (rc != EOK)
|
|---|
| 90 | goto error;
|
|---|
| 91 |
|
|---|
| 92 | ui_menu_entry_set_cb(mopen, nav_menu_file_open, (void *) menu);
|
|---|
| 93 |
|
|---|
| [accdf882] | 94 | rc = ui_menu_entry_create(mfile, "~E~dit", "Ctrl-E", &medit);
|
|---|
| 95 | if (rc != EOK)
|
|---|
| 96 | goto error;
|
|---|
| 97 |
|
|---|
| 98 | ui_menu_entry_set_cb(medit, nav_menu_file_edit, (void *) menu);
|
|---|
| 99 |
|
|---|
| [1ec732a] | 100 | rc = ui_menu_entry_create(mfile, "~V~erify", "Ctrl-V", &mverify);
|
|---|
| 101 | if (rc != EOK)
|
|---|
| 102 | goto error;
|
|---|
| 103 |
|
|---|
| 104 | ui_menu_entry_set_cb(mverify, nav_menu_file_verify, (void *) menu);
|
|---|
| 105 |
|
|---|
| [f59212cc] | 106 | rc = ui_menu_entry_sep_create(mfile, &mfsep);
|
|---|
| 107 | if (rc != EOK)
|
|---|
| 108 | goto error;
|
|---|
| 109 |
|
|---|
| [c38ab6c] | 110 | rc = ui_menu_entry_create(mfile, "E~x~it", "Ctrl-Q", &mexit);
|
|---|
| [5d466a1] | 111 | if (rc != EOK)
|
|---|
| 112 | goto error;
|
|---|
| 113 |
|
|---|
| [f59212cc] | 114 | ui_menu_entry_set_cb(mexit, nav_menu_file_exit, (void *) menu);
|
|---|
| [5d466a1] | 115 |
|
|---|
| [6aa85c1] | 116 | ui_window_get_app_rect(menu->window, &arect);
|
|---|
| [5d466a1] | 117 |
|
|---|
| 118 | rect.p0 = arect.p0;
|
|---|
| 119 | rect.p1.x = arect.p1.x;
|
|---|
| 120 | rect.p1.y = arect.p0.y + 1;
|
|---|
| 121 | ui_menu_bar_set_rect(menu->menubar, &rect);
|
|---|
| 122 |
|
|---|
| 123 | *rmenu = menu;
|
|---|
| 124 | return EOK;
|
|---|
| 125 | error:
|
|---|
| 126 | nav_menu_destroy(menu);
|
|---|
| 127 | return rc;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| [f59212cc] | 130 | /** Set navigator menu callbacks.
|
|---|
| 131 | *
|
|---|
| 132 | * @param menu Menu
|
|---|
| 133 | * @param cb Callbacks
|
|---|
| 134 | * @param arg Argument to callback functions
|
|---|
| 135 | */
|
|---|
| 136 | void nav_menu_set_cb(nav_menu_t *menu, nav_menu_cb_t *cb, void *arg)
|
|---|
| 137 | {
|
|---|
| 138 | menu->cb = cb;
|
|---|
| 139 | menu->cb_arg = arg;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| [5d466a1] | 142 | /** Destroy navigator menu.
|
|---|
| 143 | *
|
|---|
| 144 | * @param menu Menu
|
|---|
| 145 | */
|
|---|
| 146 | void nav_menu_destroy(nav_menu_t *menu)
|
|---|
| 147 | {
|
|---|
| [6aa85c1] | 148 | if (menu->menubar != NULL)
|
|---|
| [5d466a1] | 149 | ui_menu_bar_destroy(menu->menubar);
|
|---|
| 150 |
|
|---|
| 151 | free(menu);
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| [6aa85c1] | 154 | /** Return base UI control for the menu bar.
|
|---|
| 155 | *
|
|---|
| 156 | * @param menu Navigator menu
|
|---|
| 157 | * @return UI control
|
|---|
| 158 | */
|
|---|
| 159 | ui_control_t *nav_menu_ctl(nav_menu_t *menu)
|
|---|
| 160 | {
|
|---|
| 161 | return ui_menu_bar_ctl(menu->menubar);
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| [f9c4c433] | 164 | /** File / New File menu entry selected.
|
|---|
| 165 | *
|
|---|
| 166 | * @param mentry Menu entry
|
|---|
| 167 | * @param arg Argument (navigator_t *)
|
|---|
| 168 | */
|
|---|
| 169 | void nav_menu_file_new_file(ui_menu_entry_t *mentry, void *arg)
|
|---|
| 170 | {
|
|---|
| 171 | nav_menu_t *menu = (nav_menu_t *)arg;
|
|---|
| 172 |
|
|---|
| 173 | if (menu->cb != NULL && menu->cb->file_new_file != NULL)
|
|---|
| 174 | menu->cb->file_new_file(menu->cb_arg);
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| [f59212cc] | 177 | /** File / Open menu entry selected.
|
|---|
| 178 | *
|
|---|
| 179 | * @param mentry Menu entry
|
|---|
| 180 | * @param arg Argument (navigator_t *)
|
|---|
| 181 | */
|
|---|
| 182 | void nav_menu_file_open(ui_menu_entry_t *mentry, void *arg)
|
|---|
| 183 | {
|
|---|
| 184 | nav_menu_t *menu = (nav_menu_t *)arg;
|
|---|
| 185 |
|
|---|
| 186 | if (menu->cb != NULL && menu->cb->file_open != NULL)
|
|---|
| 187 | menu->cb->file_open(menu->cb_arg);
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| [accdf882] | 190 | /** File / Edit menu entry selected.
|
|---|
| 191 | *
|
|---|
| 192 | * @param mentry Menu entry
|
|---|
| 193 | * @param arg Argument (navigator_t *)
|
|---|
| 194 | */
|
|---|
| 195 | void nav_menu_file_edit(ui_menu_entry_t *mentry, void *arg)
|
|---|
| 196 | {
|
|---|
| 197 | nav_menu_t *menu = (nav_menu_t *)arg;
|
|---|
| 198 |
|
|---|
| 199 | if (menu->cb != NULL && menu->cb->file_edit != NULL)
|
|---|
| 200 | menu->cb->file_edit(menu->cb_arg);
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| [1ec732a] | 203 | /** File / Verify menu entry selected.
|
|---|
| 204 | *
|
|---|
| 205 | * @param mentry Menu entry
|
|---|
| 206 | * @param arg Argument (navigator_t *)
|
|---|
| 207 | */
|
|---|
| 208 | void nav_menu_file_verify(ui_menu_entry_t *mentry, void *arg)
|
|---|
| 209 | {
|
|---|
| 210 | nav_menu_t *menu = (nav_menu_t *)arg;
|
|---|
| 211 |
|
|---|
| 212 | if (menu->cb != NULL && menu->cb->file_verify != NULL)
|
|---|
| 213 | menu->cb->file_verify(menu->cb_arg);
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| [5d466a1] | 216 | /** File / Exit menu entry selected.
|
|---|
| 217 | *
|
|---|
| 218 | * @param mentry Menu entry
|
|---|
| 219 | * @param arg Argument (navigator_t *)
|
|---|
| 220 | */
|
|---|
| [f59212cc] | 221 | void nav_menu_file_exit(ui_menu_entry_t *mentry, void *arg)
|
|---|
| [5d466a1] | 222 | {
|
|---|
| [f59212cc] | 223 | nav_menu_t *menu = (nav_menu_t *)arg;
|
|---|
| [5d466a1] | 224 |
|
|---|
| [f59212cc] | 225 | if (menu->cb != NULL && menu->cb->file_exit != NULL)
|
|---|
| 226 | menu->cb->file_exit(menu->cb_arg);
|
|---|
| [5d466a1] | 227 | }
|
|---|
| 228 |
|
|---|
| 229 | /** @}
|
|---|
| 230 | */
|
|---|