Changeset 9a07ee3 in mainline for uspace/lib/ui/src/msgdialog.c
- Timestamp:
- 2024-11-12T09:56:19Z (6 weeks ago)
- Branches:
- master
- Children:
- 12dd36c
- Parents:
- 0d00e53
- git-author:
- Jiri Svoboda <jiri@…> (2024-11-11 19:56:06)
- git-committer:
- Jiri Svoboda <jiri@…> (2024-11-12 09:56:19)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/msgdialog.c
r0d00e53 r9a07ee3 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 58 58 }; 59 59 60 static const char *ui_msg_dialog_captions[][ui_msg_dialog_maxbtn + 1] = { 61 [umdc_ok] = { "OK", NULL }, 62 [umdc_ok_cancel] = { "OK", "Cancel", NULL } 63 }; 64 60 65 /** Initialize message dialog parameters structure. 61 66 * … … 86 91 ui_fixed_t *fixed = NULL; 87 92 ui_label_t *label = NULL; 88 ui_pbutton_t *bok = NULL; 93 ui_pbutton_t *btn[ui_msg_dialog_maxbtn]; 94 const char **cp; 95 unsigned i, nb; 89 96 gfx_rect_t rect; 97 gfx_coord_t bw, bpad, btnsw, bp0x; 90 98 ui_resource_t *ui_res; 99 100 for (i = 0; i < ui_msg_dialog_maxbtn; i++) 101 btn[i] = NULL; 91 102 92 103 dialog = calloc(1, sizeof(ui_msg_dialog_t)); … … 103 114 wparams.rect.p0.x = 0; 104 115 wparams.rect.p0.y = 0; 105 wparams.rect.p1.x = 40;116 wparams.rect.p1.x = 60; 106 117 wparams.rect.p1.y = 7; 107 118 } else { 108 119 wparams.rect.p0.x = 0; 109 120 wparams.rect.p0.y = 0; 110 wparams.rect.p1.x = 200;121 wparams.rect.p1.x = 400; 111 122 wparams.rect.p1.y = 110; 112 123 } … … 132 143 rect.p0.x = 3; 133 144 rect.p0.y = 2; 134 rect.p1.x = 17;145 rect.p1.x = 57; 135 146 rect.p1.y = 3; 136 147 } else { 137 148 rect.p0.x = 10; 138 149 rect.p0.y = 35; 139 rect.p1.x = 190;150 rect.p1.x = 390; 140 151 rect.p1.y = 50; 141 152 } … … 150 161 label = NULL; 151 162 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 */ 163 i = 0; 164 assert(params->choice == umdc_ok || params->choice == umdc_ok_cancel); 165 cp = ui_msg_dialog_captions[params->choice]; 166 167 while (*cp != NULL) { 168 rc = ui_pbutton_create(ui_res, *cp, &btn[i]); 169 if (rc != EOK) 170 goto error; 171 172 ui_pbutton_set_cb(btn[i], &ui_msg_dialog_btn_cb, dialog); 173 ++cp; 174 ++i; 175 } 176 177 nb = i; 178 159 179 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; 180 bw = 12; 181 bpad = 2; 164 182 } 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 dialog->bok = bok; 180 bok = NULL; 183 bw = 90; 184 bpad = 10; 185 } 186 187 btnsw = (nb - 1) * (bw + bpad) + bw; 188 bp0x = (wparams.rect.p0.x + wparams.rect.p1.x - btnsw) / 2; 189 190 for (i = 0; i < nb; i++) { 191 /* FIXME: Auto layout */ 192 if (ui_is_textmode(ui)) { 193 rect.p0.x = bp0x + i * (bw + bpad); 194 rect.p0.y = 4; 195 rect.p1.x = bp0x + bw + i * (bw + bpad); 196 rect.p1.y = 5; 197 } else { 198 rect.p0.x = bp0x + i * (bw + bpad); 199 rect.p0.y = 60; 200 rect.p1.x = bp0x + bw + i * (bw + bpad); 201 rect.p1.y = 88; 202 } 203 204 ui_pbutton_set_rect(btn[i], &rect); 205 206 rc = ui_fixed_add(fixed, ui_pbutton_ctl(btn[i])); 207 if (rc != EOK) 208 goto error; 209 } 210 211 ui_pbutton_set_default(btn[0], true); 212 213 for (i = 0; i < ui_msg_dialog_maxbtn; i++) { 214 dialog->btn[i] = btn[i]; 215 btn[i] = NULL; 216 } 181 217 182 218 ui_window_add(window, ui_fixed_ctl(fixed)); … … 191 227 return EOK; 192 228 error: 193 if (bok != NULL) 194 ui_pbutton_destroy(bok); 229 for (i = 0; i < ui_msg_dialog_maxbtn; i++) { 230 if (btn[i] != NULL) 231 ui_pbutton_destroy(btn[i]); 232 } 195 233 if (label != NULL) 196 234 ui_label_destroy(label); … … 251 289 { 252 290 ui_msg_dialog_t *dialog = (ui_msg_dialog_t *) arg; 253 254 if (dialog->cb != NULL && dialog->cb->button != NULL) 255 dialog->cb->button(dialog, dialog->arg, 0); 291 unsigned i; 292 293 if (dialog->cb != NULL && dialog->cb->button != NULL) { 294 for (i = 0; i < ui_msg_dialog_maxbtn; i++) { 295 if (dialog->btn[i] == pbutton) 296 dialog->cb->button(dialog, dialog->arg, i); 297 } 298 } 256 299 } 257 300
Note:
See TracChangeset
for help on using the changeset viewer.