Changes in uspace/lib/ui/src/msgdialog.c [252d03c:12dd36c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/msgdialog.c
r252d03c r12dd36c 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 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 *); 49 50 50 51 ui_window_cb_t ui_msg_dialog_wnd_cb = { 51 .close = ui_msg_dialog_wnd_close 52 .close = ui_msg_dialog_wnd_close, 53 .kbd = ui_msg_dialog_wnd_kbd 52 54 }; 53 55 … … 56 58 ui_pbutton_cb_t ui_msg_dialog_btn_cb = { 57 59 .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 } 58 65 }; 59 66 … … 86 93 ui_fixed_t *fixed = NULL; 87 94 ui_label_t *label = NULL; 88 ui_pbutton_t *bok = NULL; 95 ui_pbutton_t *btn[ui_msg_dialog_maxbtn]; 96 const char **cp; 97 unsigned i, nb; 89 98 gfx_rect_t rect; 99 gfx_coord_t bw, bpad, btnsw, bp0x; 90 100 ui_resource_t *ui_res; 101 102 for (i = 0; i < ui_msg_dialog_maxbtn; i++) 103 btn[i] = NULL; 91 104 92 105 dialog = calloc(1, sizeof(ui_msg_dialog_t)); … … 103 116 wparams.rect.p0.x = 0; 104 117 wparams.rect.p0.y = 0; 105 wparams.rect.p1.x = 20;118 wparams.rect.p1.x = 60; 106 119 wparams.rect.p1.y = 7; 107 120 } else { 108 121 wparams.rect.p0.x = 0; 109 122 wparams.rect.p0.y = 0; 110 wparams.rect.p1.x = 200;123 wparams.rect.p1.x = 400; 111 124 wparams.rect.p1.y = 110; 112 125 } … … 132 145 rect.p0.x = 3; 133 146 rect.p0.y = 2; 134 rect.p1.x = 17;147 rect.p1.x = 57; 135 148 rect.p1.y = 3; 136 149 } else { 137 150 rect.p0.x = 10; 138 151 rect.p0.y = 35; 139 rect.p1.x = 190;152 rect.p1.x = 390; 140 153 rect.p1.y = 50; 141 154 } … … 150 163 label = NULL; 151 164 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 */ 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 159 181 if (ui_is_textmode(ui)) { 160 rect.p0.x = 8; 161 rect.p0.y = 4; 162 rect.p1.x = 12; 163 rect.p1.y = 5; 182 bw = 12; 183 bpad = 2; 164 184 } else { 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; 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 } 180 219 181 220 ui_window_add(window, ui_fixed_ctl(fixed)); … … 187 226 188 227 dialog->window = window; 189 dialog->bok = bok;190 228 *rdialog = dialog; 191 229 return EOK; 192 230 error: 231 for (i = 0; i < ui_msg_dialog_maxbtn; i++) { 232 if (btn[i] != NULL) 233 ui_pbutton_destroy(btn[i]); 234 } 193 235 if (label != NULL) 194 236 ui_label_destroy(label); … … 241 283 } 242 284 285 /** Message dialog window keyboard event handler. 286 * 287 * @param window Window 288 * @param arg Argument (ui_msg_dialog_t *) 289 * @param event Keyboard event 290 */ 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 243 320 /** Message dialog button click handler. 244 321 * … … 249 326 { 250 327 ui_msg_dialog_t *dialog = (ui_msg_dialog_t *) arg; 251 252 if (dialog->cb != NULL && dialog->cb->button != NULL) 253 dialog->cb->button(dialog, dialog->arg, 0); 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 } 254 336 } 255 337
Note:
See TracChangeset
for help on using the changeset viewer.