source: mainline/uspace/app/taskbar-cfg/smeedit.c@ dcd8214

topic/msim-upgrade topic/simplify-dev-export
Last change on this file since dcd8214 was dcd8214, checked in by Jiri Svoboda <jiri@…>, 2 years ago

Add dialog window for editing start menu entry

Note it does not do anything yet.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * Copyright (c) 2023 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 taskbar-cfg
30 * @{
31 */
32/** @file Start menu entry edit dialog
33 */
34
35#include <gfx/coord.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <ui/fixed.h>
39#include <ui/resource.h>
40#include <ui/window.h>
41#include "taskbar-cfg.h"
42#include "smeedit.h"
43
44static void wnd_close(ui_window_t *, void *);
45
46static ui_window_cb_t window_cb = {
47 .close = wnd_close
48};
49
50/** Window close button was clicked.
51 *
52 * @param window Window
53 * @param arg Argument (tbcfg)
54 */
55static void wnd_close(ui_window_t *window, void *arg)
56{
57 smeedit_t *smee = (smeedit_t *)arg;
58
59 (void)window;
60 smeedit_destroy(smee);
61}
62
63/** Create start menu entry edit dialog.
64 *
65 * @param smenu Start menu
66 * @param rsmee Place to store pointer to new start menu entry edit window
67 * @return EOK on success or an error code
68 */
69errno_t smeedit_create(startmenu_t *smenu, smeedit_t **rsmee)
70{
71 ui_wnd_params_t params;
72 ui_t *ui;
73 ui_window_t *window = NULL;
74 smeedit_t *smee = NULL;
75 gfx_rect_t rect;
76 ui_resource_t *res;
77 errno_t rc;
78
79 ui = smenu->tbarcfg->ui;
80
81 smee = calloc(1, sizeof(smeedit_t));
82 if (smee == NULL) {
83 printf("Out of memory.\n");
84 return ENOMEM;
85 }
86
87 ui_wnd_params_init(&params);
88 params.caption = "Edit Start Menu Entry";
89 if (ui_is_textmode(ui)) {
90 params.rect.p0.x = 0;
91 params.rect.p0.y = 0;
92 params.rect.p1.x = 50;
93 params.rect.p1.y = 12;
94 } else {
95 params.rect.p0.x = 0;
96 params.rect.p0.y = 0;
97 params.rect.p1.x = 370;
98 params.rect.p1.y = 200;
99 }
100
101 rc = ui_window_create(ui, &params, &window);
102 if (rc != EOK) {
103 printf("Error creating window.\n");
104 goto error;
105 }
106
107 ui_window_set_cb(window, &window_cb, (void *)smee);
108 smee->window = window;
109
110 res = ui_window_get_res(window);
111
112 rc = ui_fixed_create(&smee->fixed);
113 if (rc != EOK) {
114 printf("Error creating fixed layout.\n");
115 goto error;
116 }
117
118 /* Command to run label */
119
120 rc = ui_label_create(res, "Command to run:", &smee->lcmd);
121 if (rc != EOK)
122 goto error;
123
124 /* FIXME: Auto layout */
125 if (ui_is_textmode(ui)) {
126 rect.p0.x = 3;
127 rect.p0.y = 2;
128 rect.p1.x = 48;
129 rect.p1.y = 3;
130 } else {
131 rect.p0.x = 10;
132 rect.p0.y = 35;
133 rect.p1.x = 190;
134 rect.p1.y = 50;
135 }
136
137 ui_label_set_rect(smee->lcmd, &rect);
138
139 rc = ui_fixed_add(smee->fixed, ui_label_ctl(smee->lcmd));
140 if (rc != EOK) {
141 printf("Error adding control to layout.\n");
142 goto error;
143 }
144
145 /* Command entry */
146
147 rc = ui_entry_create(window, "foo", &smee->ecmd);
148 if (rc != EOK)
149 goto error;
150
151 /* FIXME: Auto layout */
152 if (ui_is_textmode(ui)) {
153 rect.p0.x = 3;
154 rect.p0.y = 3;
155 rect.p1.x = 48;
156 rect.p1.y = 4;
157 } else {
158 rect.p0.x = 10;
159 rect.p0.y = 50;
160 rect.p1.x = 360;
161 rect.p1.y = 75;
162 }
163
164 ui_entry_set_rect(smee->ecmd, &rect);
165
166 rc = ui_fixed_add(smee->fixed, ui_entry_ctl(smee->ecmd));
167 if (rc != EOK) {
168 printf("Error adding control to layout.\n");
169 goto error;
170 }
171
172 /* Caption label */
173
174 rc = ui_label_create(res, "Caption:", &smee->lcaption);
175 if (rc != EOK)
176 goto error;
177
178 /* FIXME: Auto layout */
179 if (ui_is_textmode(ui)) {
180 rect.p0.x = 3;
181 rect.p0.y = 5;
182 rect.p1.x = 20;
183 rect.p1.y = 6;
184 } else {
185 rect.p0.x = 10;
186 rect.p0.y = 95;
187 rect.p1.x = 190;
188 rect.p1.y = 110;
189 }
190
191 ui_label_set_rect(smee->lcaption, &rect);
192
193 rc = ui_fixed_add(smee->fixed, ui_label_ctl(smee->lcaption));
194 if (rc != EOK) {
195 printf("Error adding control to layout.\n");
196 goto error;
197 }
198
199 /* Caption entry */
200
201 rc = ui_entry_create(window, "bar", &smee->ecaption);
202 if (rc != EOK)
203 goto error;
204
205 /* FIXME: Auto layout */
206 if (ui_is_textmode(ui)) {
207 rect.p0.x = 3;
208 rect.p0.y = 6;
209 rect.p1.x = 48;
210 rect.p1.y = 7;
211 } else {
212 rect.p0.x = 10;
213 rect.p0.y = 110;
214 rect.p1.x = 360;
215 rect.p1.y = 135;
216 }
217
218 ui_entry_set_rect(smee->ecaption, &rect);
219
220 rc = ui_fixed_add(smee->fixed, ui_entry_ctl(smee->ecaption));
221 if (rc != EOK) {
222 printf("Error adding control to layout.\n");
223 goto error;
224 }
225
226 /* OK button */
227
228 rc = ui_pbutton_create(res, "OK", &smee->bok);
229 if (rc != EOK)
230 goto error;
231
232 /* FIXME: Auto layout */
233 if (ui_is_textmode(ui)) {
234 rect.p0.x = 23;
235 rect.p0.y = 9;
236 rect.p1.x = 35;
237 rect.p1.y = 10;
238 } else {
239 rect.p0.x = 190;
240 rect.p0.y = 155;
241 rect.p1.x = 270;
242 rect.p1.y = 180;
243 }
244
245 ui_pbutton_set_rect(smee->bok, &rect);
246 ui_pbutton_set_default(smee->bok, true);
247
248 rc = ui_fixed_add(smee->fixed, ui_pbutton_ctl(smee->bok));
249 if (rc != EOK) {
250 printf("Error adding control to layout.\n");
251 goto error;
252 }
253
254 /* Cancel button */
255
256 rc = ui_pbutton_create(res, "Cancel", &smee->bcancel);
257 if (rc != EOK)
258 goto error;
259
260 /* FIXME: Auto layout */
261 if (ui_is_textmode(ui)) {
262 rect.p0.x = 36;
263 rect.p0.y = 9;
264 rect.p1.x = 48;
265 rect.p1.y = 10;
266 } else {
267 rect.p0.x = 280;
268 rect.p0.y = 155;
269 rect.p1.x = 360;
270 rect.p1.y = 180;
271 }
272
273 ui_pbutton_set_rect(smee->bcancel, &rect);
274
275 rc = ui_fixed_add(smee->fixed, ui_pbutton_ctl(smee->bcancel));
276 if (rc != EOK) {
277 printf("Error adding control to layout.\n");
278 goto error;
279 }
280
281 ui_window_add(window, ui_fixed_ctl(smee->fixed));
282
283 rc = ui_window_paint(window);
284 if (rc != EOK)
285 goto error;
286
287 *rsmee = smee;
288 return EOK;
289error:
290 if (smee->window != NULL)
291 ui_window_destroy(smee->window);
292 free(smee);
293 return rc;
294}
295
296/** Destroy Taskbar configuration window.
297 *
298 * @param smee Start menu entry edit dialog
299 */
300void smeedit_destroy(smeedit_t *smee)
301{
302 ui_window_destroy(smee->window);
303}
304
305/** @}
306 */
Note: See TracBrowser for help on using the repository browser.