source: mainline/uspace/app/nav/menu.c@ 5bbb4453

serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5bbb4453 was 6aa85c1, checked in by jxsvoboda <5887334+jxsvoboda@…>, 4 years ago

Add panel class and add unit tests for all classes

  • Property mode set to 100644
File size: 3.4 KB
Line 
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
45static void nav_file_exit(ui_menu_entry_t *, void *);
46
47/** Create navigator menu.
48 *
49 * @param window Navigator window
50 * @param rmenu Place to store pointer to new menu
51 * @return EOK on success or an error code
52 */
53errno_t nav_menu_create(ui_window_t *window, 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 menu->window = window;
67 menu->ui = ui_window_get_ui(window);
68
69 rc = ui_menu_bar_create(menu->ui, menu->window,
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
82 ui_menu_entry_set_cb(mexit, nav_file_exit, (void *) menu);
83
84 ui_window_get_app_rect(menu->window, &arect);
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;
93error:
94 nav_menu_destroy(menu);
95 return rc;
96}
97
98/** Destroy navigator menu.
99 *
100 * @param menu Menu
101 */
102void nav_menu_destroy(nav_menu_t *menu)
103{
104 if (menu->menubar != NULL)
105 ui_menu_bar_destroy(menu->menubar);
106
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 */
115ui_control_t *nav_menu_ctl(nav_menu_t *menu)
116{
117 return ui_menu_bar_ctl(menu->menubar);
118}
119
120/** File / Exit menu entry selected.
121 *
122 * @param mentry Menu entry
123 * @param arg Argument (navigator_t *)
124 */
125static 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 */
Note: See TracBrowser for help on using the repository browser.