[cb2894e] | 1 | /*
|
---|
[28ca31ed] | 2 | * Copyright (c) 2024 Jiri Svoboda
|
---|
[cb2894e] | 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 configuration tab
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <gfx/coord.h>
|
---|
| 36 | #include <loc.h>
|
---|
| 37 | #include <stdio.h>
|
---|
| 38 | #include <stdlib.h>
|
---|
| 39 | #include <str.h>
|
---|
| 40 | #include <tbarcfg/tbarcfg.h>
|
---|
| 41 | #include <ui/control.h>
|
---|
| 42 | #include <ui/label.h>
|
---|
| 43 | #include <ui/list.h>
|
---|
| 44 | #include <ui/pbutton.h>
|
---|
| 45 | #include <ui/resource.h>
|
---|
| 46 | #include <ui/tab.h>
|
---|
| 47 | #include <ui/window.h>
|
---|
[dcd8214] | 48 | #include "smeedit.h"
|
---|
[cb2894e] | 49 | #include "startmenu.h"
|
---|
| 50 | #include "taskbar-cfg.h"
|
---|
| 51 |
|
---|
| 52 | static void startmenu_entry_selected(ui_list_entry_t *, void *);
|
---|
| 53 | static void startmenu_new_entry_clicked(ui_pbutton_t *, void *);
|
---|
| 54 | static void startmenu_delete_entry_clicked(ui_pbutton_t *, void *);
|
---|
[dcd8214] | 55 | static void startmenu_edit_entry_clicked(ui_pbutton_t *, void *);
|
---|
[e63e74a] | 56 | static void startmenu_sep_entry_clicked(ui_pbutton_t *, void *);
|
---|
[28ca31ed] | 57 | static void startmenu_up_entry_clicked(ui_pbutton_t *, void *);
|
---|
| 58 | static void startmenu_down_entry_clicked(ui_pbutton_t *, void *);
|
---|
[cb2894e] | 59 |
|
---|
| 60 | /** Entry list callbacks */
|
---|
| 61 | ui_list_cb_t startmenu_entry_list_cb = {
|
---|
| 62 | .selected = startmenu_entry_selected
|
---|
| 63 | };
|
---|
| 64 |
|
---|
| 65 | /** New entry button callbacks */
|
---|
| 66 | ui_pbutton_cb_t startmenu_new_entry_button_cb = {
|
---|
| 67 | .clicked = startmenu_new_entry_clicked
|
---|
| 68 | };
|
---|
| 69 |
|
---|
[dcd8214] | 70 | /** Delete entry button callbacks */
|
---|
[cb2894e] | 71 | ui_pbutton_cb_t startmenu_delete_entry_button_cb = {
|
---|
| 72 | .clicked = startmenu_delete_entry_clicked
|
---|
| 73 | };
|
---|
| 74 |
|
---|
[dcd8214] | 75 | /** Edit entry button callbacks */
|
---|
| 76 | ui_pbutton_cb_t startmenu_edit_entry_button_cb = {
|
---|
| 77 | .clicked = startmenu_edit_entry_clicked
|
---|
| 78 | };
|
---|
| 79 |
|
---|
[e63e74a] | 80 | /** Separator entry button callbacks */
|
---|
| 81 | ui_pbutton_cb_t startmenu_sep_entry_button_cb = {
|
---|
| 82 | .clicked = startmenu_sep_entry_clicked
|
---|
| 83 | };
|
---|
| 84 |
|
---|
[28ca31ed] | 85 | /** Move entry up button callbacks */
|
---|
| 86 | ui_pbutton_cb_t startmenu_up_entry_button_cb = {
|
---|
| 87 | .clicked = startmenu_up_entry_clicked
|
---|
| 88 | };
|
---|
| 89 |
|
---|
| 90 | /** Move entry down button callbacks */
|
---|
| 91 | ui_pbutton_cb_t startmenu_down_entry_button_cb = {
|
---|
| 92 | .clicked = startmenu_down_entry_clicked
|
---|
| 93 | };
|
---|
| 94 |
|
---|
[cb2894e] | 95 | /** Create start menu configuration tab
|
---|
| 96 | *
|
---|
| 97 | * @param tbcfg Taskbar configuration dialog
|
---|
| 98 | * @param rsmenu Place to store pointer to new start menu configuration tab
|
---|
| 99 | * @return EOK on success or an error code
|
---|
| 100 | */
|
---|
| 101 | errno_t startmenu_create(taskbar_cfg_t *tbcfg, startmenu_t **rsmenu)
|
---|
| 102 | {
|
---|
| 103 | ui_resource_t *ui_res;
|
---|
| 104 | startmenu_t *smenu;
|
---|
| 105 | gfx_rect_t rect;
|
---|
| 106 | errno_t rc;
|
---|
| 107 |
|
---|
| 108 | ui_res = ui_window_get_res(tbcfg->window);
|
---|
| 109 |
|
---|
| 110 | smenu = calloc(1, sizeof(startmenu_t));
|
---|
| 111 | if (smenu == NULL) {
|
---|
| 112 | printf("Out of memory.\n");
|
---|
| 113 | return ENOMEM;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | smenu->tbarcfg = tbcfg;
|
---|
| 117 |
|
---|
| 118 | /* 'Start Menu' tab */
|
---|
| 119 |
|
---|
| 120 | rc = ui_tab_create(tbcfg->tabset, "Start Menu", &smenu->tab);
|
---|
| 121 | if (rc != EOK)
|
---|
| 122 | goto error;
|
---|
| 123 |
|
---|
| 124 | rc = ui_fixed_create(&smenu->fixed);
|
---|
| 125 | if (rc != EOK) {
|
---|
| 126 | printf("Error creating fixed layout.\n");
|
---|
| 127 | goto error;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | /* 'Start menu entries:' label */
|
---|
| 131 |
|
---|
| 132 | rc = ui_label_create(ui_res, "Start menu entries:",
|
---|
| 133 | &smenu->entries_label);
|
---|
| 134 | if (rc != EOK) {
|
---|
| 135 | printf("Error creating label.\n");
|
---|
| 136 | goto error;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | if (ui_resource_is_textmode(ui_res)) {
|
---|
| 140 | rect.p0.x = 4;
|
---|
| 141 | rect.p0.y = 4;
|
---|
| 142 | rect.p1.x = 36;
|
---|
| 143 | rect.p1.y = 5;
|
---|
| 144 | } else {
|
---|
| 145 | rect.p0.x = 20;
|
---|
| 146 | rect.p0.y = 60;
|
---|
| 147 | rect.p1.x = 360;
|
---|
| 148 | rect.p1.y = 80;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | ui_label_set_rect(smenu->entries_label, &rect);
|
---|
| 152 |
|
---|
| 153 | rc = ui_fixed_add(smenu->fixed, ui_label_ctl(smenu->entries_label));
|
---|
| 154 | if (rc != EOK) {
|
---|
| 155 | printf("Error adding control to layout.\n");
|
---|
| 156 | goto error;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | /* List of entries */
|
---|
| 160 |
|
---|
| 161 | rc = ui_list_create(tbcfg->window, false, &smenu->entries_list);
|
---|
| 162 | if (rc != EOK) {
|
---|
| 163 | printf("Error creating list.\n");
|
---|
| 164 | goto error;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | if (ui_resource_is_textmode(ui_res)) {
|
---|
| 168 | rect.p0.x = 4;
|
---|
| 169 | rect.p0.y = 5;
|
---|
| 170 | rect.p1.x = 56;
|
---|
[28ca31ed] | 171 | rect.p1.y = 20;
|
---|
[cb2894e] | 172 | } else {
|
---|
| 173 | rect.p0.x = 20;
|
---|
| 174 | rect.p0.y = 80;
|
---|
| 175 | rect.p1.x = 360;
|
---|
[28ca31ed] | 176 | rect.p1.y = 330;
|
---|
[cb2894e] | 177 | }
|
---|
| 178 |
|
---|
| 179 | ui_list_set_rect(smenu->entries_list, &rect);
|
---|
| 180 |
|
---|
| 181 | rc = ui_fixed_add(smenu->fixed, ui_list_ctl(smenu->entries_list));
|
---|
| 182 | if (rc != EOK) {
|
---|
| 183 | printf("Error adding control to layout.\n");
|
---|
| 184 | goto error;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | ui_list_set_cb(smenu->entries_list, &startmenu_entry_list_cb,
|
---|
| 188 | (void *)smenu);
|
---|
| 189 |
|
---|
[dcd8214] | 190 | /* New entry button */
|
---|
[cb2894e] | 191 |
|
---|
| 192 | rc = ui_pbutton_create(ui_res, "New...", &smenu->new_entry);
|
---|
| 193 | if (rc != EOK) {
|
---|
| 194 | printf("Error creating button.\n");
|
---|
| 195 | goto error;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | if (ui_resource_is_textmode(ui_res)) {
|
---|
| 199 | rect.p0.x = 58;
|
---|
| 200 | rect.p0.y = 5;
|
---|
| 201 | rect.p1.x = 68;
|
---|
| 202 | rect.p1.y = 6;
|
---|
| 203 | } else {
|
---|
| 204 | rect.p0.x = 370;
|
---|
| 205 | rect.p0.y = 80;
|
---|
| 206 | rect.p1.x = 450;
|
---|
| 207 | rect.p1.y = 105;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | ui_pbutton_set_rect(smenu->new_entry, &rect);
|
---|
| 211 |
|
---|
| 212 | rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->new_entry));
|
---|
| 213 | if (rc != EOK) {
|
---|
| 214 | printf("Error adding control to layout.\n");
|
---|
| 215 | goto error;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | ui_pbutton_set_cb(smenu->new_entry, &startmenu_new_entry_button_cb,
|
---|
| 219 | (void *)smenu);
|
---|
| 220 |
|
---|
[dcd8214] | 221 | /* Delete entry button */
|
---|
[cb2894e] | 222 |
|
---|
| 223 | rc = ui_pbutton_create(ui_res, "Delete", &smenu->delete_entry);
|
---|
| 224 | if (rc != EOK) {
|
---|
| 225 | printf("Error creating button.\n");
|
---|
| 226 | goto error;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | if (ui_resource_is_textmode(ui_res)) {
|
---|
| 230 | rect.p0.x = 58;
|
---|
| 231 | rect.p0.y = 7;
|
---|
| 232 | rect.p1.x = 68;
|
---|
| 233 | rect.p1.y = 8;
|
---|
| 234 | } else {
|
---|
| 235 | rect.p0.x = 370;
|
---|
| 236 | rect.p0.y = 110;
|
---|
| 237 | rect.p1.x = 450;
|
---|
| 238 | rect.p1.y = 135;
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | ui_pbutton_set_rect(smenu->delete_entry, &rect);
|
---|
| 242 |
|
---|
| 243 | rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->delete_entry));
|
---|
| 244 | if (rc != EOK) {
|
---|
| 245 | printf("Error adding control to layout.\n");
|
---|
| 246 | goto error;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | ui_pbutton_set_cb(smenu->delete_entry,
|
---|
| 250 | &startmenu_delete_entry_button_cb, (void *)smenu);
|
---|
| 251 |
|
---|
[dcd8214] | 252 | /* Edit entry button */
|
---|
| 253 |
|
---|
| 254 | rc = ui_pbutton_create(ui_res, "Edit...", &smenu->edit_entry);
|
---|
| 255 | if (rc != EOK) {
|
---|
| 256 | printf("Error creating button.\n");
|
---|
| 257 | goto error;
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | if (ui_resource_is_textmode(ui_res)) {
|
---|
| 261 | rect.p0.x = 58;
|
---|
| 262 | rect.p0.y = 9;
|
---|
| 263 | rect.p1.x = 68;
|
---|
| 264 | rect.p1.y = 10;
|
---|
| 265 | } else {
|
---|
| 266 | rect.p0.x = 370;
|
---|
| 267 | rect.p0.y = 140;
|
---|
| 268 | rect.p1.x = 450;
|
---|
| 269 | rect.p1.y = 165;
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | ui_pbutton_set_rect(smenu->edit_entry, &rect);
|
---|
| 273 |
|
---|
| 274 | rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->edit_entry));
|
---|
| 275 | if (rc != EOK) {
|
---|
| 276 | printf("Error adding control to layout.\n");
|
---|
| 277 | goto error;
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | ui_pbutton_set_cb(smenu->edit_entry,
|
---|
| 281 | &startmenu_edit_entry_button_cb, (void *)smenu);
|
---|
| 282 |
|
---|
[e63e74a] | 283 | /* Separator entry button */
|
---|
| 284 |
|
---|
| 285 | rc = ui_pbutton_create(ui_res, "Separator", &smenu->sep_entry);
|
---|
| 286 | if (rc != EOK) {
|
---|
| 287 | printf("Error creating button.\n");
|
---|
| 288 | goto error;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | if (ui_resource_is_textmode(ui_res)) {
|
---|
| 292 | rect.p0.x = 58;
|
---|
| 293 | rect.p0.y = 11;
|
---|
| 294 | rect.p1.x = 68;
|
---|
| 295 | rect.p1.y = 12;
|
---|
| 296 | } else {
|
---|
| 297 | rect.p0.x = 370;
|
---|
| 298 | rect.p0.y = 170;
|
---|
| 299 | rect.p1.x = 450;
|
---|
| 300 | rect.p1.y = 195;
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | ui_pbutton_set_rect(smenu->sep_entry, &rect);
|
---|
| 304 |
|
---|
| 305 | rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->sep_entry));
|
---|
| 306 | if (rc != EOK) {
|
---|
| 307 | printf("Error adding control to layout.\n");
|
---|
| 308 | goto error;
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | ui_pbutton_set_cb(smenu->sep_entry,
|
---|
| 312 | &startmenu_sep_entry_button_cb, (void *)smenu);
|
---|
| 313 |
|
---|
[28ca31ed] | 314 | /* Move entry up button */
|
---|
| 315 |
|
---|
| 316 | rc = ui_pbutton_create(ui_res, "Up", &smenu->up_entry);
|
---|
| 317 | if (rc != EOK) {
|
---|
| 318 | printf("Error creating button.\n");
|
---|
| 319 | goto error;
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | if (ui_resource_is_textmode(ui_res)) {
|
---|
| 323 | rect.p0.x = 58;
|
---|
[e63e74a] | 324 | rect.p0.y = 13;
|
---|
[28ca31ed] | 325 | rect.p1.x = 68;
|
---|
[e63e74a] | 326 | rect.p1.y = 14;
|
---|
[28ca31ed] | 327 | } else {
|
---|
| 328 | rect.p0.x = 370;
|
---|
[e63e74a] | 329 | rect.p0.y = 220;
|
---|
[28ca31ed] | 330 | rect.p1.x = 450;
|
---|
[e63e74a] | 331 | rect.p1.y = 245;
|
---|
[28ca31ed] | 332 | }
|
---|
| 333 |
|
---|
| 334 | ui_pbutton_set_rect(smenu->up_entry, &rect);
|
---|
| 335 |
|
---|
| 336 | rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->up_entry));
|
---|
| 337 | if (rc != EOK) {
|
---|
| 338 | printf("Error adding control to layout.\n");
|
---|
| 339 | goto error;
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | ui_pbutton_set_cb(smenu->up_entry,
|
---|
| 343 | &startmenu_up_entry_button_cb, (void *)smenu);
|
---|
| 344 |
|
---|
| 345 | /* Move entry down button */
|
---|
| 346 |
|
---|
| 347 | rc = ui_pbutton_create(ui_res, "Down", &smenu->down_entry);
|
---|
| 348 | if (rc != EOK) {
|
---|
| 349 | printf("Error creating button.\n");
|
---|
| 350 | goto error;
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | if (ui_resource_is_textmode(ui_res)) {
|
---|
| 354 | rect.p0.x = 58;
|
---|
[e63e74a] | 355 | rect.p0.y = 15;
|
---|
[28ca31ed] | 356 | rect.p1.x = 68;
|
---|
[e63e74a] | 357 | rect.p1.y = 16;
|
---|
[28ca31ed] | 358 | } else {
|
---|
| 359 | rect.p0.x = 370;
|
---|
[e63e74a] | 360 | rect.p0.y = 250;
|
---|
[28ca31ed] | 361 | rect.p1.x = 450;
|
---|
[e63e74a] | 362 | rect.p1.y = 275;
|
---|
[28ca31ed] | 363 | }
|
---|
| 364 |
|
---|
| 365 | ui_pbutton_set_rect(smenu->down_entry, &rect);
|
---|
| 366 |
|
---|
| 367 | rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->down_entry));
|
---|
| 368 | if (rc != EOK) {
|
---|
| 369 | printf("Error adding control to layout.\n");
|
---|
| 370 | goto error;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | ui_pbutton_set_cb(smenu->down_entry,
|
---|
| 374 | &startmenu_down_entry_button_cb, (void *)smenu);
|
---|
| 375 |
|
---|
[cb2894e] | 376 | ui_tab_add(smenu->tab, ui_fixed_ctl(smenu->fixed));
|
---|
| 377 |
|
---|
| 378 | *rsmenu = smenu;
|
---|
| 379 | return EOK;
|
---|
| 380 | error:
|
---|
[28ca31ed] | 381 | if (smenu->down_entry != NULL)
|
---|
| 382 | ui_pbutton_destroy(smenu->down_entry);
|
---|
| 383 | if (smenu->up_entry != NULL)
|
---|
| 384 | ui_pbutton_destroy(smenu->up_entry);
|
---|
[cb2894e] | 385 | if (smenu->delete_entry != NULL)
|
---|
| 386 | ui_pbutton_destroy(smenu->delete_entry);
|
---|
| 387 | if (smenu->new_entry != NULL)
|
---|
| 388 | ui_pbutton_destroy(smenu->new_entry);
|
---|
| 389 | if (smenu->entries_label != NULL)
|
---|
| 390 | ui_label_destroy(smenu->entries_label);
|
---|
| 391 | if (smenu->entries_list != NULL)
|
---|
| 392 | ui_list_destroy(smenu->entries_list);
|
---|
| 393 | if (smenu->fixed != NULL)
|
---|
| 394 | ui_fixed_destroy(smenu->fixed);
|
---|
| 395 | free(smenu);
|
---|
| 396 | return rc;
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | /** Populate start menu tab with start menu configuration data
|
---|
| 400 | *
|
---|
| 401 | * @param smenu Start menu configuration tab
|
---|
| 402 | * @param tbarcfg Taskbar configuration
|
---|
| 403 | * @return EOK on success or an error code
|
---|
| 404 | */
|
---|
| 405 | errno_t startmenu_populate(startmenu_t *smenu, tbarcfg_t *tbarcfg)
|
---|
| 406 | {
|
---|
| 407 | smenu_entry_t *entry;
|
---|
| 408 | startmenu_entry_t *smentry;
|
---|
| 409 | errno_t rc;
|
---|
| 410 |
|
---|
| 411 | entry = tbarcfg_smenu_first(tbarcfg);
|
---|
| 412 | while (entry != NULL) {
|
---|
[b1397ab] | 413 | rc = startmenu_insert(smenu, entry, &smentry);
|
---|
[cb2894e] | 414 | if (rc != EOK)
|
---|
| 415 | return rc;
|
---|
| 416 |
|
---|
| 417 | entry = tbarcfg_smenu_next(entry);
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 | return EOK;
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 | /** Destroy start menu configuration tab.
|
---|
| 424 | *
|
---|
| 425 | * @param smenu Start menu configuration tab
|
---|
| 426 | */
|
---|
| 427 | void startmenu_destroy(startmenu_t *smenu)
|
---|
| 428 | {
|
---|
| 429 | ui_list_entry_t *lentry;
|
---|
| 430 | startmenu_entry_t *entry;
|
---|
| 431 |
|
---|
| 432 | lentry = ui_list_first(smenu->entries_list);
|
---|
| 433 | while (lentry != NULL) {
|
---|
| 434 | entry = (startmenu_entry_t *)ui_list_entry_get_arg(lentry);
|
---|
| 435 | free(entry);
|
---|
| 436 | ui_list_entry_delete(lentry);
|
---|
| 437 | lentry = ui_list_first(smenu->entries_list);
|
---|
| 438 | }
|
---|
| 439 |
|
---|
| 440 | /* This will automatically destroy all controls in the tab */
|
---|
| 441 | ui_tab_destroy(smenu->tab);
|
---|
| 442 | free(smenu);
|
---|
| 443 | }
|
---|
| 444 |
|
---|
| 445 | /** Insert new entry into entries list.
|
---|
| 446 | *
|
---|
| 447 | * @param smenu Start menu configuration tab
|
---|
[b1397ab] | 448 | * @param entry Backing entry
|
---|
| 449 | * @param rsmentry Place to store pointer to new entry or NULL
|
---|
[cb2894e] | 450 | * @return EOK on success or an error code
|
---|
| 451 | */
|
---|
[b1397ab] | 452 | errno_t startmenu_insert(startmenu_t *smenu, smenu_entry_t *entry,
|
---|
| 453 | startmenu_entry_t **rsmentry)
|
---|
[cb2894e] | 454 | {
|
---|
[b1397ab] | 455 | startmenu_entry_t *smentry;
|
---|
[cb2894e] | 456 | ui_list_entry_attr_t attr;
|
---|
[e63e74a] | 457 | bool separator;
|
---|
[cb2894e] | 458 | errno_t rc;
|
---|
| 459 |
|
---|
[b1397ab] | 460 | smentry = calloc(1, sizeof(startmenu_entry_t));
|
---|
| 461 | if (smentry == NULL)
|
---|
[cb2894e] | 462 | return ENOMEM;
|
---|
| 463 |
|
---|
[b1397ab] | 464 | smentry->startmenu = smenu;
|
---|
| 465 | smentry->entry = entry;
|
---|
[cb2894e] | 466 |
|
---|
| 467 | ui_list_entry_attr_init(&attr);
|
---|
[e63e74a] | 468 | separator = smenu_entry_get_separator(entry);
|
---|
| 469 | if (separator)
|
---|
| 470 | attr.caption = "-- Separator --";
|
---|
| 471 | else
|
---|
| 472 | attr.caption = smenu_entry_get_caption(entry);
|
---|
| 473 |
|
---|
[b1397ab] | 474 | attr.arg = (void *)smentry;
|
---|
[e63e74a] | 475 |
|
---|
[b1397ab] | 476 | rc = ui_list_entry_append(smenu->entries_list, &attr, &smentry->lentry);
|
---|
[cb2894e] | 477 | if (rc != EOK) {
|
---|
[b1397ab] | 478 | free(smentry);
|
---|
[cb2894e] | 479 | return rc;
|
---|
| 480 | }
|
---|
| 481 |
|
---|
[b1397ab] | 482 | if (rsmentry != NULL)
|
---|
| 483 | *rsmentry = smentry;
|
---|
[cb2894e] | 484 | return EOK;
|
---|
| 485 | }
|
---|
| 486 |
|
---|
[b1397ab] | 487 | /** Get selected start menu entry.
|
---|
| 488 | *
|
---|
| 489 | * @param smenu Start menu
|
---|
[2b4e02b] | 490 | * @return Selected entry or @c NULL if no entry is selected
|
---|
[b1397ab] | 491 | */
|
---|
| 492 | startmenu_entry_t *startmenu_get_selected(startmenu_t *smenu)
|
---|
| 493 | {
|
---|
| 494 | ui_list_entry_t *entry;
|
---|
| 495 |
|
---|
| 496 | entry = ui_list_get_cursor(smenu->entries_list);
|
---|
[2b4e02b] | 497 | if (entry == NULL)
|
---|
| 498 | return NULL;
|
---|
| 499 |
|
---|
[b1397ab] | 500 | return (startmenu_entry_t *)ui_list_entry_get_arg(entry);
|
---|
| 501 | }
|
---|
| 502 |
|
---|
[f87ff8e] | 503 | /** Create new menu entry.
|
---|
| 504 | *
|
---|
| 505 | * @param smenu Start menu
|
---|
| 506 | */
|
---|
| 507 | void startmenu_new_entry(startmenu_t *smenu)
|
---|
| 508 | {
|
---|
| 509 | smeedit_t *smee;
|
---|
| 510 | errno_t rc;
|
---|
| 511 |
|
---|
| 512 | rc = smeedit_create(smenu, NULL, &smee);
|
---|
| 513 | if (rc != EOK)
|
---|
| 514 | return;
|
---|
| 515 |
|
---|
| 516 | (void)smee;
|
---|
[bff8619] | 517 | (void)tbarcfg_sync(smenu->tbarcfg->tbarcfg);
|
---|
[ee3b28a9] | 518 | (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT);
|
---|
[f87ff8e] | 519 | }
|
---|
| 520 |
|
---|
[e63e74a] | 521 | /** Create new separator menu entry.
|
---|
| 522 | *
|
---|
| 523 | * @param smenu Start menu
|
---|
| 524 | */
|
---|
| 525 | void startmenu_sep_entry(startmenu_t *smenu)
|
---|
| 526 | {
|
---|
| 527 | startmenu_entry_t *smentry = NULL;
|
---|
| 528 | smenu_entry_t *entry;
|
---|
| 529 | errno_t rc;
|
---|
| 530 |
|
---|
| 531 | rc = smenu_entry_sep_create(smenu->tbarcfg->tbarcfg, &entry);
|
---|
| 532 | if (rc != EOK)
|
---|
| 533 | return;
|
---|
| 534 |
|
---|
| 535 | (void)startmenu_insert(smenu, entry, &smentry);
|
---|
| 536 | (void)ui_control_paint(ui_list_ctl(smenu->entries_list));
|
---|
[bff8619] | 537 | (void)tbarcfg_sync(smenu->tbarcfg->tbarcfg);
|
---|
[ee3b28a9] | 538 | (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT);
|
---|
[e63e74a] | 539 | }
|
---|
| 540 |
|
---|
[dcd8214] | 541 | /** Edit selected menu entry.
|
---|
| 542 | *
|
---|
| 543 | * @param smenu Start menu
|
---|
| 544 | */
|
---|
| 545 | void startmenu_edit(startmenu_t *smenu)
|
---|
| 546 | {
|
---|
| 547 | smeedit_t *smee;
|
---|
[b1397ab] | 548 | startmenu_entry_t *smentry;
|
---|
[dcd8214] | 549 | errno_t rc;
|
---|
| 550 |
|
---|
[b1397ab] | 551 | smentry = startmenu_get_selected(smenu);
|
---|
[2b4e02b] | 552 | if (smentry == NULL)
|
---|
| 553 | return;
|
---|
[b1397ab] | 554 |
|
---|
[e63e74a] | 555 | /* Do not edit separator entries */
|
---|
| 556 | if (smenu_entry_get_separator(smentry->entry))
|
---|
| 557 | return;
|
---|
| 558 |
|
---|
[b1397ab] | 559 | rc = smeedit_create(smenu, smentry, &smee);
|
---|
[dcd8214] | 560 | if (rc != EOK)
|
---|
| 561 | return;
|
---|
| 562 |
|
---|
| 563 | (void)smee;
|
---|
| 564 | }
|
---|
| 565 |
|
---|
[5e758e4] | 566 | /** Update start menu entry caption.
|
---|
| 567 | *
|
---|
| 568 | * When editing an entry the entry's label might change. We need
|
---|
| 569 | * to update the list entry caption to reflect that.
|
---|
| 570 | *
|
---|
| 571 | * @param entry Start menu entry
|
---|
| 572 | */
|
---|
| 573 | errno_t startmenu_entry_update(startmenu_entry_t *entry)
|
---|
| 574 | {
|
---|
| 575 | return ui_list_entry_set_caption(entry->lentry,
|
---|
| 576 | smenu_entry_get_caption(entry->entry));
|
---|
| 577 | }
|
---|
| 578 |
|
---|
[550ed86] | 579 | /** Repaint start menu entry list.
|
---|
| 580 | *
|
---|
| 581 | * When editing an entry the entry's label might change. We need
|
---|
| 582 | * to update the list entry caption to reflect that.
|
---|
| 583 | *
|
---|
| 584 | * @param smenu Start menu
|
---|
| 585 | */
|
---|
| 586 | void startmenu_repaint(startmenu_t *smenu)
|
---|
| 587 | {
|
---|
| 588 | (void) ui_control_paint(ui_list_ctl(smenu->entries_list));
|
---|
| 589 | }
|
---|
| 590 |
|
---|
[cb2894e] | 591 | /** Entry in entry list is selected.
|
---|
| 592 | *
|
---|
| 593 | * @param lentry UI list entry
|
---|
| 594 | * @param arg Argument (dcfg_seats_entry_t *)
|
---|
| 595 | */
|
---|
| 596 | static void startmenu_entry_selected(ui_list_entry_t *lentry, void *arg)
|
---|
| 597 | {
|
---|
| 598 | (void)lentry;
|
---|
| 599 | (void)arg;
|
---|
| 600 | }
|
---|
| 601 |
|
---|
[dcd8214] | 602 | /** New entry button clicked.
|
---|
[cb2894e] | 603 | *
|
---|
| 604 | * @param pbutton Push button
|
---|
[dcd8214] | 605 | * @param arg Argument (startmenu_t *)
|
---|
[cb2894e] | 606 | */
|
---|
| 607 | static void startmenu_new_entry_clicked(ui_pbutton_t *pbutton, void *arg)
|
---|
| 608 | {
|
---|
[f87ff8e] | 609 | startmenu_t *smenu = (startmenu_t *)arg;
|
---|
| 610 |
|
---|
[cb2894e] | 611 | (void)pbutton;
|
---|
[f87ff8e] | 612 | startmenu_new_entry(smenu);
|
---|
[cb2894e] | 613 | }
|
---|
| 614 |
|
---|
[dcd8214] | 615 | /** Delete entry button clicked.
|
---|
[cb2894e] | 616 | *
|
---|
| 617 | * @param pbutton Push button
|
---|
[dcd8214] | 618 | * @param arg Argument (startmenu_t *)
|
---|
[cb2894e] | 619 | */
|
---|
| 620 | static void startmenu_delete_entry_clicked(ui_pbutton_t *pbutton, void *arg)
|
---|
| 621 | {
|
---|
[2b4e02b] | 622 | startmenu_t *smenu = (startmenu_t *)arg;
|
---|
| 623 | startmenu_entry_t *smentry;
|
---|
| 624 |
|
---|
[cb2894e] | 625 | (void)pbutton;
|
---|
[2b4e02b] | 626 |
|
---|
| 627 | smentry = startmenu_get_selected(smenu);
|
---|
| 628 | if (smentry == NULL)
|
---|
| 629 | return;
|
---|
| 630 |
|
---|
[bff8619] | 631 | smenu_entry_destroy(smentry->entry);
|
---|
[2b4e02b] | 632 | ui_list_entry_delete(smentry->lentry);
|
---|
| 633 | free(smentry);
|
---|
[bff8619] | 634 |
|
---|
[28ca31ed] | 635 | (void)ui_control_paint(ui_list_ctl(smenu->entries_list));
|
---|
[bff8619] | 636 | (void)tbarcfg_sync(smenu->tbarcfg->tbarcfg);
|
---|
[ee3b28a9] | 637 | (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT);
|
---|
[cb2894e] | 638 | }
|
---|
| 639 |
|
---|
[dcd8214] | 640 | /** Edit entry button clicked.
|
---|
| 641 | *
|
---|
| 642 | * @param pbutton Push button
|
---|
| 643 | * @param arg Argument (startmenu_t *)
|
---|
| 644 | */
|
---|
| 645 | static void startmenu_edit_entry_clicked(ui_pbutton_t *pbutton, void *arg)
|
---|
| 646 | {
|
---|
| 647 | startmenu_t *smenu = (startmenu_t *)arg;
|
---|
| 648 |
|
---|
| 649 | (void)pbutton;
|
---|
| 650 | startmenu_edit(smenu);
|
---|
| 651 | }
|
---|
| 652 |
|
---|
[e63e74a] | 653 | /** Separator entry button clicked.
|
---|
| 654 | *
|
---|
| 655 | * @param pbutton Push button
|
---|
| 656 | * @param arg Argument (startmenu_t *)
|
---|
| 657 | */
|
---|
| 658 | static void startmenu_sep_entry_clicked(ui_pbutton_t *pbutton, void *arg)
|
---|
| 659 | {
|
---|
| 660 | startmenu_t *smenu = (startmenu_t *)arg;
|
---|
| 661 |
|
---|
| 662 | (void)pbutton;
|
---|
| 663 | startmenu_sep_entry(smenu);
|
---|
| 664 | }
|
---|
| 665 |
|
---|
[28ca31ed] | 666 | /** Up entry button clicked.
|
---|
| 667 | *
|
---|
| 668 | * @param pbutton Push button
|
---|
| 669 | * @param arg Argument (startmenu_t *)
|
---|
| 670 | */
|
---|
| 671 | static void startmenu_up_entry_clicked(ui_pbutton_t *pbutton, void *arg)
|
---|
| 672 | {
|
---|
| 673 | startmenu_t *smenu = (startmenu_t *)arg;
|
---|
| 674 | startmenu_entry_t *smentry;
|
---|
| 675 |
|
---|
| 676 | (void)pbutton;
|
---|
| 677 |
|
---|
| 678 | smentry = startmenu_get_selected(smenu);
|
---|
| 679 | if (smentry == NULL)
|
---|
| 680 | return;
|
---|
| 681 |
|
---|
[bff8619] | 682 | smenu_entry_move_up(smentry->entry);
|
---|
[28ca31ed] | 683 | ui_list_entry_move_up(smentry->lentry);
|
---|
| 684 |
|
---|
| 685 | (void)ui_control_paint(ui_list_ctl(smenu->entries_list));
|
---|
[bff8619] | 686 | (void)tbarcfg_sync(smenu->tbarcfg->tbarcfg);
|
---|
[ee3b28a9] | 687 | (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT);
|
---|
[28ca31ed] | 688 | }
|
---|
| 689 |
|
---|
| 690 | /** Down entry button clicked.
|
---|
| 691 | *
|
---|
| 692 | * @param pbutton Push button
|
---|
| 693 | * @param arg Argument (startmenu_t *)
|
---|
| 694 | */
|
---|
| 695 | static void startmenu_down_entry_clicked(ui_pbutton_t *pbutton, void *arg)
|
---|
| 696 | {
|
---|
| 697 | startmenu_t *smenu = (startmenu_t *)arg;
|
---|
| 698 | startmenu_entry_t *smentry;
|
---|
| 699 |
|
---|
| 700 | (void)pbutton;
|
---|
| 701 |
|
---|
| 702 | smentry = startmenu_get_selected(smenu);
|
---|
| 703 | if (smentry == NULL)
|
---|
| 704 | return;
|
---|
| 705 |
|
---|
[bff8619] | 706 | smenu_entry_move_down(smentry->entry);
|
---|
[28ca31ed] | 707 | ui_list_entry_move_down(smentry->lentry);
|
---|
| 708 |
|
---|
| 709 | (void)ui_control_paint(ui_list_ctl(smenu->entries_list));
|
---|
[bff8619] | 710 | (void)tbarcfg_sync(smenu->tbarcfg->tbarcfg);
|
---|
[ee3b28a9] | 711 | (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT);
|
---|
[28ca31ed] | 712 | }
|
---|
| 713 |
|
---|
[cb2894e] | 714 | /** @}
|
---|
| 715 | */
|
---|