Changes in uspace/lib/ui/src/msgdialog.c [12dd36c:252d03c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/msgdialog.c
r12dd36c r252d03c 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 47 47 48 48 static void ui_msg_dialog_wnd_close(ui_window_t *, void *); 49 static void ui_msg_dialog_wnd_kbd(ui_window_t *, void *, kbd_event_t *);50 49 51 50 ui_window_cb_t ui_msg_dialog_wnd_cb = { 52 .close = ui_msg_dialog_wnd_close, 53 .kbd = ui_msg_dialog_wnd_kbd 51 .close = ui_msg_dialog_wnd_close 54 52 }; 55 53 … … 58 56 ui_pbutton_cb_t ui_msg_dialog_btn_cb = { 59 57 .clicked = ui_msg_dialog_btn_clicked 60 };61 62 static const char *ui_msg_dialog_captions[][ui_msg_dialog_maxbtn + 1] = {63 [umdc_ok] = { "OK", NULL },64 [umdc_ok_cancel] = { "OK", "Cancel", NULL }65 58 }; 66 59 … … 93 86 ui_fixed_t *fixed = NULL; 94 87 ui_label_t *label = NULL; 95 ui_pbutton_t *btn[ui_msg_dialog_maxbtn]; 96 const char **cp; 97 unsigned i, nb; 88 ui_pbutton_t *bok = NULL; 98 89 gfx_rect_t rect; 99 gfx_coord_t bw, bpad, btnsw, bp0x;100 90 ui_resource_t *ui_res; 101 102 for (i = 0; i < ui_msg_dialog_maxbtn; i++)103 btn[i] = NULL;104 91 105 92 dialog = calloc(1, sizeof(ui_msg_dialog_t)); … … 116 103 wparams.rect.p0.x = 0; 117 104 wparams.rect.p0.y = 0; 118 wparams.rect.p1.x = 60;105 wparams.rect.p1.x = 20; 119 106 wparams.rect.p1.y = 7; 120 107 } else { 121 108 wparams.rect.p0.x = 0; 122 109 wparams.rect.p0.y = 0; 123 wparams.rect.p1.x = 400;110 wparams.rect.p1.x = 200; 124 111 wparams.rect.p1.y = 110; 125 112 } … … 145 132 rect.p0.x = 3; 146 133 rect.p0.y = 2; 147 rect.p1.x = 57;134 rect.p1.x = 17; 148 135 rect.p1.y = 3; 149 136 } else { 150 137 rect.p0.x = 10; 151 138 rect.p0.y = 35; 152 rect.p1.x = 390;139 rect.p1.x = 190; 153 140 rect.p1.y = 50; 154 141 } … … 163 150 label = NULL; 164 151 165 i = 0; 166 assert(params->choice == umdc_ok || params->choice == umdc_ok_cancel); 167 cp = ui_msg_dialog_captions[params->choice]; 168 169 while (*cp != NULL) { 170 rc = ui_pbutton_create(ui_res, *cp, &btn[i]); 171 if (rc != EOK) 172 goto error; 173 174 ui_pbutton_set_cb(btn[i], &ui_msg_dialog_btn_cb, dialog); 175 ++cp; 176 ++i; 177 } 178 179 nb = i; 180 152 rc = ui_pbutton_create(ui_res, "OK", &bok); 153 if (rc != EOK) 154 goto error; 155 156 ui_pbutton_set_cb(bok, &ui_msg_dialog_btn_cb, dialog); 157 158 /* FIXME: Auto layout */ 181 159 if (ui_is_textmode(ui)) { 182 bw = 12; 183 bpad = 2; 160 rect.p0.x = 8; 161 rect.p0.y = 4; 162 rect.p1.x = 12; 163 rect.p1.y = 5; 184 164 } else { 185 bw = 90; 186 bpad = 10; 187 } 188 189 btnsw = (nb - 1) * (bw + bpad) + bw; 190 bp0x = (wparams.rect.p0.x + wparams.rect.p1.x - btnsw) / 2; 191 192 for (i = 0; i < nb; i++) { 193 /* FIXME: Auto layout */ 194 if (ui_is_textmode(ui)) { 195 rect.p0.x = bp0x + i * (bw + bpad); 196 rect.p0.y = 4; 197 rect.p1.x = bp0x + bw + i * (bw + bpad); 198 rect.p1.y = 5; 199 } else { 200 rect.p0.x = bp0x + i * (bw + bpad); 201 rect.p0.y = 60; 202 rect.p1.x = bp0x + bw + i * (bw + bpad); 203 rect.p1.y = 88; 204 } 205 206 ui_pbutton_set_rect(btn[i], &rect); 207 208 rc = ui_fixed_add(fixed, ui_pbutton_ctl(btn[i])); 209 if (rc != EOK) 210 goto error; 211 } 212 213 ui_pbutton_set_default(btn[0], true); 214 215 for (i = 0; i < ui_msg_dialog_maxbtn; i++) { 216 dialog->btn[i] = btn[i]; 217 btn[i] = NULL; 218 } 165 rect.p0.x = 55; 166 rect.p0.y = 60; 167 rect.p1.x = 145; 168 rect.p1.y = 88; 169 } 170 171 ui_pbutton_set_rect(bok, &rect); 172 173 ui_pbutton_set_default(bok, true); 174 175 rc = ui_fixed_add(fixed, ui_pbutton_ctl(bok)); 176 if (rc != EOK) 177 goto error; 178 179 bok = NULL; 219 180 220 181 ui_window_add(window, ui_fixed_ctl(fixed)); … … 226 187 227 188 dialog->window = window; 189 dialog->bok = bok; 228 190 *rdialog = dialog; 229 191 return EOK; 230 192 error: 231 for (i = 0; i < ui_msg_dialog_maxbtn; i++) {232 if (btn[i] != NULL)233 ui_pbutton_destroy(btn[i]);234 }235 193 if (label != NULL) 236 194 ui_label_destroy(label); … … 283 241 } 284 242 285 /** Message dialog window keyboard event handler.286 *287 * @param window Window288 * @param arg Argument (ui_msg_dialog_t *)289 * @param event Keyboard event290 */291 static void ui_msg_dialog_wnd_kbd(ui_window_t *window, void *arg,292 kbd_event_t *event)293 {294 ui_msg_dialog_t *dialog = (ui_msg_dialog_t *) arg;295 ui_evclaim_t claim;296 297 claim = ui_window_def_kbd(window, event);298 if (claim == ui_claimed)299 return;300 301 if (event->type == KEY_PRESS &&302 (event->mods & (KM_CTRL | KM_SHIFT | KM_ALT)) == 0) {303 if (event->key == KC_ENTER) {304 /* OK / default button */305 if (dialog->cb != NULL && dialog->cb->button != NULL) {306 dialog->cb->button(dialog, dialog->arg, 0);307 return;308 }309 } else if (event->key == KC_ESCAPE) {310 /* Cancel */311 if (dialog->cb != NULL && dialog->cb->close != NULL) {312 dialog->cb->close(dialog, dialog->arg);313 return;314 }315 }316 }317 318 }319 320 243 /** Message dialog button click handler. 321 244 * … … 326 249 { 327 250 ui_msg_dialog_t *dialog = (ui_msg_dialog_t *) arg; 328 unsigned i; 329 330 if (dialog->cb != NULL && dialog->cb->button != NULL) { 331 for (i = 0; i < ui_msg_dialog_maxbtn; i++) { 332 if (dialog->btn[i] == pbutton) 333 dialog->cb->button(dialog, dialog->arg, i); 334 } 335 } 251 252 if (dialog->cb != NULL && dialog->cb->button != NULL) 253 dialog->cb->button(dialog, dialog->arg, 0); 336 254 } 337 255
Note:
See TracChangeset
for help on using the changeset viewer.