| 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 | *
|
|---|
| 49 | * @param navigator Navigator
|
|---|
| 50 | * @param rmenu Place to store pointer to new menu
|
|---|
| 51 | * @return EOK on success or an error code
|
|---|
| 52 | */
|
|---|
| 53 | errno_t nav_menu_create(navigator_t *navigator, nav_menu_t **rmenu)
|
|---|
| 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 |
|
|---|
| 66 | rc = ui_menu_bar_create(navigator->ui, navigator->window,
|
|---|
| 67 | &menu->menubar);
|
|---|
| 68 | if (rc != EOK)
|
|---|
| 69 | goto error;
|
|---|
| 70 |
|
|---|
| 71 | rc = ui_menu_create(menu->menubar, "File", &mfile);
|
|---|
| 72 | if (rc != EOK)
|
|---|
| 73 | goto error;
|
|---|
| 74 |
|
|---|
| 75 | rc = ui_menu_entry_create(mfile, "Exit", "Ctrl-Q", &mexit);
|
|---|
| 76 | if (rc != EOK)
|
|---|
| 77 | goto error;
|
|---|
| 78 |
|
|---|
| 79 | ui_menu_entry_set_cb(mexit, nav_file_exit, (void *) navigator);
|
|---|
| 80 |
|
|---|
| 81 | ui_window_get_app_rect(navigator->window, &arect);
|
|---|
| 82 |
|
|---|
| 83 | rect.p0 = arect.p0;
|
|---|
| 84 | rect.p1.x = arect.p1.x;
|
|---|
| 85 | rect.p1.y = arect.p0.y + 1;
|
|---|
| 86 | ui_menu_bar_set_rect(menu->menubar, &rect);
|
|---|
| 87 |
|
|---|
| 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 | *rmenu = menu;
|
|---|
| 94 | return EOK;
|
|---|
| 95 | error:
|
|---|
| 96 | nav_menu_destroy(menu);
|
|---|
| 97 | return rc;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | /** Destroy navigator menu.
|
|---|
| 101 | *
|
|---|
| 102 | * @param menu Menu
|
|---|
| 103 | */
|
|---|
| 104 | void nav_menu_destroy(nav_menu_t *menu)
|
|---|
| 105 | {
|
|---|
| 106 | if (menu->menubar != NULL) {
|
|---|
| 107 | ui_fixed_remove(menu->navigator->fixed,
|
|---|
| 108 | ui_menu_bar_ctl(menu->menubar));
|
|---|
| 109 | ui_menu_bar_destroy(menu->menubar);
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | free(menu);
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | /** File / Exit menu entry selected.
|
|---|
| 116 | *
|
|---|
| 117 | * @param mentry Menu entry
|
|---|
| 118 | * @param arg Argument (navigator_t *)
|
|---|
| 119 | */
|
|---|
| 120 | static void nav_file_exit(ui_menu_entry_t *mentry, void *arg)
|
|---|
| 121 | {
|
|---|
| 122 | navigator_t *navigator = (navigator_t *) arg;
|
|---|
| 123 |
|
|---|
| 124 | ui_quit(navigator->ui);
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | /** @}
|
|---|
| 128 | */
|
|---|