2 * Copyright (c) 2023 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
34 * HelenOS file manager.
40 #include <ui/menubar.h>
41 #include <ui/menudd.h>
42 #include <ui/menuentry.h>
46 /** Create navigator menu.
48 * @param window Navigator window
49 * @param rmenu Place to store pointer to new menu
50 * @return EOK on success or an error code
52 errno_t
nav_menu_create(ui_window_t
*window
, nav_menu_t
**rmenu
)
56 ui_menu_entry_t
*mopen
;
57 ui_menu_entry_t
*mfsep
;
58 ui_menu_entry_t
*mexit
;
63 menu
= calloc(1, sizeof(nav_menu_t
));
67 menu
->window
= window
;
68 menu
->ui
= ui_window_get_ui(window
);
70 rc
= ui_menu_bar_create(menu
->ui
, menu
->window
,
75 rc
= ui_menu_dd_create(menu
->menubar
, "~F~ile", NULL
, &mfile
);
79 rc
= ui_menu_entry_create(mfile
, "~O~pen", "Enter", &mopen
);
83 ui_menu_entry_set_cb(mopen
, nav_menu_file_open
, (void *) menu
);
85 rc
= ui_menu_entry_sep_create(mfile
, &mfsep
);
89 rc
= ui_menu_entry_create(mfile
, "E~x~it", "Ctrl-Q", &mexit
);
93 ui_menu_entry_set_cb(mexit
, nav_menu_file_exit
, (void *) menu
);
95 ui_window_get_app_rect(menu
->window
, &arect
);
98 rect
.p1
.x
= arect
.p1
.x
;
99 rect
.p1
.y
= arect
.p0
.y
+ 1;
100 ui_menu_bar_set_rect(menu
->menubar
, &rect
);
105 nav_menu_destroy(menu
);
109 /** Set navigator menu callbacks.
112 * @param cb Callbacks
113 * @param arg Argument to callback functions
115 void nav_menu_set_cb(nav_menu_t
*menu
, nav_menu_cb_t
*cb
, void *arg
)
121 /** Destroy navigator menu.
125 void nav_menu_destroy(nav_menu_t
*menu
)
127 if (menu
->menubar
!= NULL
)
128 ui_menu_bar_destroy(menu
->menubar
);
133 /** Return base UI control for the menu bar.
135 * @param menu Navigator menu
138 ui_control_t
*nav_menu_ctl(nav_menu_t
*menu
)
140 return ui_menu_bar_ctl(menu
->menubar
);
143 /** File / Open menu entry selected.
145 * @param mentry Menu entry
146 * @param arg Argument (navigator_t *)
148 void nav_menu_file_open(ui_menu_entry_t
*mentry
, void *arg
)
150 nav_menu_t
*menu
= (nav_menu_t
*)arg
;
152 if (menu
->cb
!= NULL
&& menu
->cb
->file_open
!= NULL
)
153 menu
->cb
->file_open(menu
->cb_arg
);
156 /** File / Exit menu entry selected.
158 * @param mentry Menu entry
159 * @param arg Argument (navigator_t *)
161 void nav_menu_file_exit(ui_menu_entry_t
*mentry
, void *arg
)
163 nav_menu_t
*menu
= (nav_menu_t
*)arg
;
165 if (menu
->cb
!= NULL
&& menu
->cb
->file_exit
!= NULL
)
166 menu
->cb
->file_exit(menu
->cb_arg
);