source: mainline/uspace/app/nav/nav.c@ 6aa85c1

serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6aa85c1 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: 4.2 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"
47
48static void wnd_close(ui_window_t *, void *);
49
50static ui_window_cb_t window_cb = {
51 .close = wnd_close
52};
53
54/** Window close button was clicked.
55 *
56 * @param window Window
57 * @param arg Argument (navigator)
58 */
59static void wnd_close(ui_window_t *window, void *arg)
60{
61 navigator_t *navigator = (navigator_t *) arg;
62
63 ui_quit(navigator->ui);
64}
65
[5d466a1]66/** Create navigator.
67 *
68 * @param display_spec Display specification
69 * @param rnavigator Place to store pointer to new navigator
70 * @return EOK on success or ane error code
71 */
[6aa85c1]72errno_t navigator_create(const char *display_spec,
[5d466a1]73 navigator_t **rnavigator)
[748c8bd]74{
[5d466a1]75 navigator_t *navigator;
[748c8bd]76 ui_wnd_params_t params;
77 errno_t rc;
78
[5d466a1]79 navigator = calloc(1, sizeof(navigator_t));
80 if (navigator == NULL)
81 return ENOMEM;
82
83 rc = ui_create(display_spec, &navigator->ui);
[748c8bd]84 if (rc != EOK) {
85 printf("Error creating UI on display %s.\n", display_spec);
[5d466a1]86 goto error;
[748c8bd]87 }
88
89 ui_wnd_params_init(&params);
90 params.caption = "Navigator";
[5d466a1]91 params.style &= ~ui_wds_decorated;
92 params.placement = ui_wnd_place_full_screen;
[748c8bd]93
[5d466a1]94 rc = ui_window_create(navigator->ui, &params, &navigator->window);
[748c8bd]95 if (rc != EOK) {
96 printf("Error creating window.\n");
[5d466a1]97 goto error;
[748c8bd]98 }
99
[5d466a1]100 ui_window_set_cb(navigator->window, &window_cb, (void *) navigator);
[748c8bd]101
[5d466a1]102 rc = ui_fixed_create(&navigator->fixed);
[748c8bd]103 if (rc != EOK) {
104 printf("Error creating fixed layout.\n");
[5d466a1]105 goto error;
[748c8bd]106 }
107
[5d466a1]108 ui_window_add(navigator->window, ui_fixed_ctl(navigator->fixed));
[748c8bd]109
[6aa85c1]110 rc = nav_menu_create(navigator->window, &navigator->menu);
[5d466a1]111 if (rc != EOK)
112 goto error;
[748c8bd]113
[6aa85c1]114 rc = ui_fixed_add(navigator->fixed, nav_menu_ctl(navigator->menu));
115 if (rc != EOK) {
116 printf("Error adding control to layout.\n");
117 return rc;
118 }
119
[5d466a1]120 rc = ui_window_paint(navigator->window);
[748c8bd]121 if (rc != EOK) {
[5d466a1]122 printf("Error painting window.\n");
123 goto error;
[748c8bd]124 }
125
[5d466a1]126 *rnavigator = navigator;
127 return EOK;
128error:
129 navigator_destroy(navigator);
130 return rc;
131}
[748c8bd]132
[6aa85c1]133void navigator_destroy(navigator_t *navigator)
[5d466a1]134{
[6aa85c1]135 ui_fixed_remove(navigator->fixed, nav_menu_ctl(navigator->menu));
136
[5d466a1]137 if (navigator->menu != NULL)
138 nav_menu_destroy(navigator->menu);
139 if (navigator->window != NULL)
140 ui_window_destroy(navigator->window);
141 if (navigator->ui != NULL)
142 ui_destroy(navigator->ui);
143 free(navigator);
144}
145
146/** Run navigator on the specified display. */
[6aa85c1]147errno_t navigator_run(const char *display_spec)
[5d466a1]148{
149 navigator_t *navigator;
150 errno_t rc;
[748c8bd]151
[5d466a1]152 rc = navigator_create(display_spec, &navigator);
153 if (rc != EOK)
154 return rc;
[748c8bd]155
[5d466a1]156 ui_run(navigator->ui);
[748c8bd]157
[5d466a1]158 navigator_destroy(navigator);
[748c8bd]159 return EOK;
160}
161
162/** @}
163 */
Note: See TracBrowser for help on using the repository browser.