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.
29 /** @addtogroup taskbar-cfg
32 /** @file Taskbar configuration utility (UI)
35 #include <gfx/coord.h>
39 #include <ui/resource.h>
40 #include <ui/tabset.h>
42 #include <ui/window.h>
43 #include "taskbar-cfg.h"
44 #include "startmenu.h"
46 static void wnd_close(ui_window_t
*, void *);
48 static ui_window_cb_t window_cb
= {
52 /** Window close button was clicked.
54 * @param window Window
55 * @param arg Argument (tbcfg)
57 static void wnd_close(ui_window_t
*window
, void *arg
)
59 taskbar_cfg_t
*tbcfg
= (taskbar_cfg_t
*) arg
;
64 /** Create Taskbar configuration window.
66 * @param display_spec Display specification
67 * @param rdcfg Place to store pointer to new taskbar configuration
68 * @return EOK on success or an error code
70 errno_t
taskbar_cfg_create(const char *display_spec
, taskbar_cfg_t
**rdcfg
)
73 ui_wnd_params_t params
;
74 ui_window_t
*window
= NULL
;
75 taskbar_cfg_t
*tbcfg
= NULL
;
77 ui_resource_t
*ui_res
;
80 tbcfg
= calloc(1, sizeof(taskbar_cfg_t
));
82 printf("Out of memory.\n");
86 rc
= ui_create(display_spec
, &ui
);
88 printf("Error creating UI on display %s.\n", display_spec
);
92 ui_wnd_params_init(¶ms
);
93 params
.caption
= "Taskbar Configuration";
94 if (ui_is_textmode(ui
)) {
97 params
.rect
.p1
.x
= 70;
98 params
.rect
.p1
.y
= 23;
100 params
.rect
.p0
.x
= 0;
101 params
.rect
.p0
.y
= 0;
102 params
.rect
.p1
.x
= 470;
103 params
.rect
.p1
.y
= 350;
108 rc
= ui_window_create(ui
, ¶ms
, &window
);
110 printf("Error creating window.\n");
114 ui_window_set_cb(window
, &window_cb
, (void *)tbcfg
);
115 tbcfg
->window
= window
;
117 ui_res
= ui_window_get_res(window
);
119 rc
= ui_fixed_create(&tbcfg
->fixed
);
121 printf("Error creating fixed layout.\n");
125 rc
= ui_tab_set_create(ui_res
, &tbcfg
->tabset
);
127 printf("Error creating tab set.\n");
131 ui_window_get_app_rect(window
, &rect
);
132 ui_tab_set_set_rect(tbcfg
->tabset
, &rect
);
134 rc
= ui_fixed_add(tbcfg
->fixed
, ui_tab_set_ctl(tbcfg
->tabset
));
136 printf("Error adding control to layout.\n");
140 rc
= startmenu_create(tbcfg
, &tbcfg
->startmenu
);
144 ui_window_add(window
, ui_fixed_ctl(tbcfg
->fixed
));
149 if (tbcfg
->startmenu
!= NULL
)
150 startmenu_destroy(tbcfg
->startmenu
);
151 if (tbcfg
->tabset
!= NULL
)
152 ui_tab_set_destroy(tbcfg
->tabset
);
153 if (tbcfg
->fixed
!= NULL
)
154 ui_fixed_destroy(tbcfg
->fixed
);
155 if (tbcfg
->ui
!= NULL
)
161 /** Open Taskbar configuration.
163 * @param tbcfg Taskbar configuration dialog
164 * @param cfg_repo Path to configuration repository
165 * @return EOK on success or an error code
167 errno_t
taskbar_cfg_open(taskbar_cfg_t
*tbcfg
, const char *cfg_repo
)
171 rc
= tbarcfg_open(cfg_repo
, &tbcfg
->tbarcfg
);
173 rc
= tbarcfg_create(cfg_repo
, &tbcfg
->tbarcfg
);
175 printf("Error opening Taskbar configuration.\n");
185 /** Populate task configuration from configuration repository.
187 * @param tbcfg Taskbar configuration dialog
188 * @return EOK on success or an error code
190 errno_t
taskbar_cfg_populate(taskbar_cfg_t
*tbcfg
)
194 rc
= startmenu_populate(tbcfg
->startmenu
, tbcfg
->tbarcfg
);
198 rc
= ui_window_paint(tbcfg
->window
);
200 printf("Error painting window.\n");
207 /** Destroy Taskbar configuration window.
209 * @param tbcfg Taskbar configuration window
211 void taskbar_cfg_destroy(taskbar_cfg_t
*tbcfg
)
213 if (tbcfg
->tbarcfg
!= NULL
)
214 tbarcfg_close(tbcfg
->tbarcfg
);
215 ui_window_destroy(tbcfg
->window
);
216 ui_destroy(tbcfg
->ui
);