[5d466a1] | 1 | /*
|
---|
| 2 | * Copyright (c) 2021 Jiri Svoboda
|
---|
| 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>
|
---|
| 41 | #include <ui/menuentry.h>
|
---|
| 42 | #include "menu.h"
|
---|
| 43 | #include "nav.h"
|
---|
| 44 |
|
---|
| 45 | static void nav_file_exit(ui_menu_entry_t *, void *);
|
---|
| 46 |
|
---|
| 47 | /** Create navigator menu.
|
---|
| 48 | *
|
---|
[6aa85c1] | 49 | * @param window Navigator window
|
---|
[5d466a1] | 50 | * @param rmenu Place to store pointer to new menu
|
---|
| 51 | * @return EOK on success or an error code
|
---|
| 52 | */
|
---|
[6aa85c1] | 53 | errno_t nav_menu_create(ui_window_t *window, nav_menu_t **rmenu)
|
---|
[5d466a1] | 54 | {
|
---|
| 55 | nav_menu_t *menu;
|
---|
| 56 | ui_menu_t *mfile;
|
---|
| 57 | ui_menu_entry_t *mexit;
|
---|
| 58 | gfx_rect_t arect;
|
---|
| 59 | gfx_rect_t rect;
|
---|
| 60 | errno_t rc;
|
---|
| 61 |
|
---|
| 62 | menu = calloc(1, sizeof(nav_menu_t));
|
---|
| 63 | if (menu == NULL)
|
---|
| 64 | return ENOMEM;
|
---|
| 65 |
|
---|
[6aa85c1] | 66 | menu->window = window;
|
---|
| 67 | menu->ui = ui_window_get_ui(window);
|
---|
| 68 |
|
---|
| 69 | rc = ui_menu_bar_create(menu->ui, menu->window,
|
---|
[5d466a1] | 70 | &menu->menubar);
|
---|
| 71 | if (rc != EOK)
|
---|
| 72 | goto error;
|
---|
| 73 |
|
---|
| 74 | rc = ui_menu_create(menu->menubar, "File", &mfile);
|
---|
| 75 | if (rc != EOK)
|
---|
| 76 | goto error;
|
---|
| 77 |
|
---|
| 78 | rc = ui_menu_entry_create(mfile, "Exit", "Ctrl-Q", &mexit);
|
---|
| 79 | if (rc != EOK)
|
---|
| 80 | goto error;
|
---|
| 81 |
|
---|
[6aa85c1] | 82 | ui_menu_entry_set_cb(mexit, nav_file_exit, (void *) menu);
|
---|
[5d466a1] | 83 |
|
---|
[6aa85c1] | 84 | ui_window_get_app_rect(menu->window, &arect);
|
---|
[5d466a1] | 85 |
|
---|
| 86 | rect.p0 = arect.p0;
|
---|
| 87 | rect.p1.x = arect.p1.x;
|
---|
| 88 | rect.p1.y = arect.p0.y + 1;
|
---|
| 89 | ui_menu_bar_set_rect(menu->menubar, &rect);
|
---|
| 90 |
|
---|
| 91 | *rmenu = menu;
|
---|
| 92 | return EOK;
|
---|
| 93 | error:
|
---|
| 94 | nav_menu_destroy(menu);
|
---|
| 95 | return rc;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | /** Destroy navigator menu.
|
---|
| 99 | *
|
---|
| 100 | * @param menu Menu
|
---|
| 101 | */
|
---|
| 102 | void nav_menu_destroy(nav_menu_t *menu)
|
---|
| 103 | {
|
---|
[6aa85c1] | 104 | if (menu->menubar != NULL)
|
---|
[5d466a1] | 105 | ui_menu_bar_destroy(menu->menubar);
|
---|
| 106 |
|
---|
| 107 | free(menu);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[6aa85c1] | 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);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[5d466a1] | 120 | /** File / Exit menu entry selected.
|
---|
| 121 | *
|
---|
| 122 | * @param mentry Menu entry
|
---|
| 123 | * @param arg Argument (navigator_t *)
|
---|
| 124 | */
|
---|
| 125 | static void nav_file_exit(ui_menu_entry_t *mentry, void *arg)
|
---|
| 126 | {
|
---|
| 127 | navigator_t *navigator = (navigator_t *) arg;
|
---|
| 128 |
|
---|
| 129 | ui_quit(navigator->ui);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | /** @}
|
---|
| 133 | */
|
---|