source: mainline/uspace/app/nav/nav.c@ 61784ed

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

Create, position panels and paint boxes around them

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[748c8bd]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 <gfx/coord.h>
38#include <stdio.h>
[5d466a1]39#include <stdlib.h>
[748c8bd]40#include <str.h>
41#include <ui/fixed.h>
42#include <ui/resource.h>
43#include <ui/ui.h>
44#include <ui/window.h>
[5d466a1]45#include "menu.h"
[748c8bd]46#include "nav.h"
[b36ebb42]47#include "panel.h"
[748c8bd]48
49static void wnd_close(ui_window_t *, void *);
50
51static ui_window_cb_t window_cb = {
52 .close = wnd_close
53};
54
55/** Window close button was clicked.
56 *
57 * @param window Window
58 * @param arg Argument (navigator)
59 */
60static void wnd_close(ui_window_t *window, void *arg)
61{
62 navigator_t *navigator = (navigator_t *) arg;
63
64 ui_quit(navigator->ui);
65}
66
[5d466a1]67/** Create navigator.
68 *
69 * @param display_spec Display specification
70 * @param rnavigator Place to store pointer to new navigator
71 * @return EOK on success or ane error code
72 */
[6aa85c1]73errno_t navigator_create(const char *display_spec,
[5d466a1]74 navigator_t **rnavigator)
[748c8bd]75{
[5d466a1]76 navigator_t *navigator;
[748c8bd]77 ui_wnd_params_t params;
[b36ebb42]78 gfx_rect_t rect;
79 unsigned i;
[748c8bd]80 errno_t rc;
81
[5d466a1]82 navigator = calloc(1, sizeof(navigator_t));
83 if (navigator == NULL)
84 return ENOMEM;
85
86 rc = ui_create(display_spec, &navigator->ui);
[748c8bd]87 if (rc != EOK) {
88 printf("Error creating UI on display %s.\n", display_spec);
[5d466a1]89 goto error;
[748c8bd]90 }
91
92 ui_wnd_params_init(&params);
93 params.caption = "Navigator";
[5d466a1]94 params.style &= ~ui_wds_decorated;
95 params.placement = ui_wnd_place_full_screen;
[748c8bd]96
[5d466a1]97 rc = ui_window_create(navigator->ui, &params, &navigator->window);
[748c8bd]98 if (rc != EOK) {
99 printf("Error creating window.\n");
[5d466a1]100 goto error;
[748c8bd]101 }
102
[5d466a1]103 ui_window_set_cb(navigator->window, &window_cb, (void *) navigator);
[748c8bd]104
[5d466a1]105 rc = ui_fixed_create(&navigator->fixed);
[748c8bd]106 if (rc != EOK) {
107 printf("Error creating fixed layout.\n");
[5d466a1]108 goto error;
[748c8bd]109 }
110
[5d466a1]111 ui_window_add(navigator->window, ui_fixed_ctl(navigator->fixed));
[748c8bd]112
[6aa85c1]113 rc = nav_menu_create(navigator->window, &navigator->menu);
[5d466a1]114 if (rc != EOK)
115 goto error;
[748c8bd]116
[6aa85c1]117 rc = ui_fixed_add(navigator->fixed, nav_menu_ctl(navigator->menu));
118 if (rc != EOK) {
119 printf("Error adding control to layout.\n");
120 return rc;
121 }
122
[b36ebb42]123 for (i = 0; i < 2; i++) {
124 rc = panel_create(navigator->window, &navigator->panel[i]);
125 if (rc != EOK)
126 goto error;
127
128 rect.p0.x = 40 * i;
129 rect.p0.y = 1;
130 rect.p1.x = 40 * (i + 1);
131 rect.p1.y = 24;
132 panel_set_rect(navigator->panel[i], &rect);
133
134 rc = ui_fixed_add(navigator->fixed,
135 panel_ctl(navigator->panel[i]));
136 if (rc != EOK) {
137 printf("Error adding control to layout.\n");
138 return rc;
139 }
140 }
141
[5d466a1]142 rc = ui_window_paint(navigator->window);
[748c8bd]143 if (rc != EOK) {
[5d466a1]144 printf("Error painting window.\n");
145 goto error;
[748c8bd]146 }
147
[5d466a1]148 *rnavigator = navigator;
149 return EOK;
150error:
151 navigator_destroy(navigator);
152 return rc;
153}
[748c8bd]154
[6aa85c1]155void navigator_destroy(navigator_t *navigator)
[5d466a1]156{
[b36ebb42]157 unsigned i;
158
159 for (i = 0; i < 2; i++) {
160 ui_fixed_remove(navigator->fixed,
161 panel_ctl(navigator->panel[i]));
162 panel_destroy(navigator->panel[i]);
163 }
164
[6aa85c1]165 ui_fixed_remove(navigator->fixed, nav_menu_ctl(navigator->menu));
166
[5d466a1]167 if (navigator->menu != NULL)
168 nav_menu_destroy(navigator->menu);
169 if (navigator->window != NULL)
170 ui_window_destroy(navigator->window);
171 if (navigator->ui != NULL)
172 ui_destroy(navigator->ui);
173 free(navigator);
174}
175
176/** Run navigator on the specified display. */
[6aa85c1]177errno_t navigator_run(const char *display_spec)
[5d466a1]178{
179 navigator_t *navigator;
180 errno_t rc;
[748c8bd]181
[5d466a1]182 rc = navigator_create(display_spec, &navigator);
183 if (rc != EOK)
184 return rc;
[748c8bd]185
[5d466a1]186 ui_run(navigator->ui);
[748c8bd]187
[5d466a1]188 navigator_destroy(navigator);
[748c8bd]189 return EOK;
190}
191
192/** @}
193 */
Note: See TracBrowser for help on using the repository browser.