Changeset 5e109e1 in mainline
- Timestamp:
- 2021-08-10T09:49:21Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 307d4d2, 3a4a944f
- Parents:
- edeee9f
- git-author:
- Jiri Svoboda <jiri@…> (2021-08-09 18:49:14)
- git-committer:
- Jiri Svoboda <jiri@…> (2021-08-10 09:49:21)
- Location:
- uspace
- Files:
-
- 5 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
redeee9f r5e109e1 40 40 #include <str.h> 41 41 #include <ui/entry.h> 42 #include <ui/filedialog.h> 42 43 #include <ui/fixed.h> 43 44 #include <ui/image.h> … … 85 86 }; 86 87 88 static void uidemo_file_load(ui_menu_entry_t *, void *); 87 89 static void uidemo_file_message(ui_menu_entry_t *, void *); 88 90 static void uidemo_file_exit(ui_menu_entry_t *, void *); 91 92 static void file_dialog_bok(ui_file_dialog_t *, void *, const char *); 93 static void file_dialog_bcancel(ui_file_dialog_t *, void *); 94 static void file_dialog_close(ui_file_dialog_t *, void *); 95 96 static ui_file_dialog_cb_t file_dialog_cb = { 97 .bok = file_dialog_bok, 98 .bcancel = file_dialog_bcancel, 99 .close = file_dialog_close 100 }; 89 101 90 102 static void msg_dialog_button(ui_msg_dialog_t *, void *, unsigned); … … 191 203 } 192 204 193 /** File/message menu entry selected. 194 * 195 * @param mentry Menu entry 196 * @param arg Argument (demo) 197 */ 198 static void uidemo_file_message(ui_menu_entry_t *mentry, void *arg) 199 { 200 ui_demo_t *demo = (ui_demo_t *) arg; 205 /** Display a message window. 206 * 207 * @param demo UI demo 208 * @param caption Window caption 209 * @param text Message text 210 */ 211 static void uidemo_show_message(ui_demo_t *demo, const char *caption, 212 const char *text) 213 { 201 214 ui_msg_dialog_params_t mdparams; 202 215 ui_msg_dialog_t *dialog; … … 204 217 205 218 ui_msg_dialog_params_init(&mdparams); 219 mdparams.caption = caption; 220 mdparams.text = text; 221 222 rc = ui_msg_dialog_create(demo->ui, &mdparams, &dialog); 223 if (rc != EOK) { 224 printf("Error creating message dialog.\n"); 225 return; 226 } 227 228 ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo); 229 } 230 231 232 /** File/load menu entry selected. 233 * 234 * @param mentry Menu entry 235 * @param arg Argument (demo) 236 */ 237 static void uidemo_file_load(ui_menu_entry_t *mentry, void *arg) 238 { 239 ui_demo_t *demo = (ui_demo_t *) arg; 240 ui_file_dialog_params_t fdparams; 241 ui_file_dialog_t *dialog; 242 errno_t rc; 243 244 ui_file_dialog_params_init(&fdparams); 245 fdparams.caption = "Load File"; 246 247 rc = ui_file_dialog_create(demo->ui, &fdparams, &dialog); 248 if (rc != EOK) { 249 printf("Error creating message dialog.\n"); 250 return; 251 } 252 253 ui_file_dialog_set_cb(dialog, &file_dialog_cb, demo); 254 } 255 256 /** File/message menu entry selected. 257 * 258 * @param mentry Menu entry 259 * @param arg Argument (demo) 260 */ 261 static void uidemo_file_message(ui_menu_entry_t *mentry, void *arg) 262 { 263 ui_demo_t *demo = (ui_demo_t *) arg; 264 ui_msg_dialog_params_t mdparams; 265 ui_msg_dialog_t *dialog; 266 errno_t rc; 267 268 ui_msg_dialog_params_init(&mdparams); 206 269 mdparams.caption = "Message For You"; 207 270 mdparams.text = "Hello, world!"; … … 214 277 215 278 ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo); 216 217 279 } 218 280 … … 227 289 228 290 ui_quit(demo->ui); 291 } 292 293 /** File dialog OK button press. 294 * 295 * @param dialog File dialog 296 * @param arg Argument (ui_demo_t *) 297 * @param fname File name 298 */ 299 static void file_dialog_bok(ui_file_dialog_t *dialog, void *arg, 300 const char *fname) 301 { 302 ui_demo_t *demo = (ui_demo_t *) arg; 303 char buf[128]; 304 char *p; 305 FILE *f; 306 307 ui_file_dialog_destroy(dialog); 308 309 f = fopen(fname, "rt"); 310 if (f == NULL) { 311 uidemo_show_message(demo, "Error", "Error opening file."); 312 return; 313 } 314 315 p = fgets(buf, sizeof(buf), f); 316 if (p == NULL) { 317 uidemo_show_message(demo, "Error", "Error reading file."); 318 fclose(f); 319 return; 320 } 321 322 /* Cut string off at the first non-printable character */ 323 p = buf; 324 while (*p != '\0') { 325 if (*p < ' ') { 326 *p = '\0'; 327 break; 328 } 329 ++p; 330 } 331 332 ui_entry_set_text(demo->entry, buf); 333 fclose(f); 334 } 335 336 /** File dialog cancel button press. 337 * 338 * @param dialog File dialog 339 * @param arg Argument (ui_demo_t *) 340 */ 341 static void file_dialog_bcancel(ui_file_dialog_t *dialog, void *arg) 342 { 343 ui_demo_t *demo = (ui_demo_t *) arg; 344 345 (void) demo; 346 ui_file_dialog_destroy(dialog); 347 } 348 349 /** Message dialog close request. 350 * 351 * @param dialog File dialog 352 * @param arg Argument (ui_demo_t *) 353 */ 354 static void file_dialog_close(ui_file_dialog_t *dialog, void *arg) 355 { 356 ui_demo_t *demo = (ui_demo_t *) arg; 357 358 (void) demo; 359 ui_file_dialog_destroy(dialog); 229 360 } 230 361 … … 271 402 gfx_coord2_t off; 272 403 ui_menu_entry_t *mmsg; 404 ui_menu_entry_t *mload; 273 405 ui_menu_entry_t *mfoo; 274 406 ui_menu_entry_t *mbar; … … 342 474 ui_menu_entry_set_cb(mmsg, uidemo_file_message, (void *) &demo); 343 475 476 rc = ui_menu_entry_create(demo.mfile, "Load", "", &mload); 477 if (rc != EOK) { 478 printf("Error creating menu.\n"); 479 return rc; 480 } 481 482 ui_menu_entry_set_cb(mload, uidemo_file_load, (void *) &demo); 483 344 484 rc = ui_menu_entry_create(demo.mfile, "Foo", "Ctrl-Alt-Del", &mfoo); 345 485 if (rc != EOK) { -
uspace/lib/ui/include/ui/entry.h
redeee9f r5e109e1 52 52 extern void ui_entry_set_read_only(ui_entry_t *, bool); 53 53 extern errno_t ui_entry_set_text(ui_entry_t *, const char *); 54 extern const char *ui_entry_get_text(ui_entry_t *); 54 55 extern errno_t ui_entry_paint(ui_entry_t *); 55 56 extern void ui_entry_backspace(ui_entry_t *); -
uspace/lib/ui/include/ui/msgdialog.h
redeee9f r5e109e1 31 31 */ 32 32 /** 33 * @file Message Dialog33 * @file Message dialog 34 34 */ 35 35 36 #ifndef _UI_MSG _DIALOG_H37 #define _UI_MSG _DIALOG_H36 #ifndef _UI_MSGDIALOG_H 37 #define _UI_MSGDIALOG_H 38 38 39 39 #include <errno.h> -
uspace/lib/ui/meson.build
redeee9f r5e109e1 33 33 'src/dummygc.c', 34 34 'src/entry.c', 35 'src/filedialog.c', 35 36 'src/fixed.c', 36 37 'src/image.c', … … 55 56 'test/control.c', 56 57 'test/entry.c', 58 'test/filedialog.c', 57 59 'test/fixed.c', 58 60 'test/image.c', -
uspace/lib/ui/src/entry.c
redeee9f r5e109e1 190 190 entry->pos = str_size(text); 191 191 entry->sel_start = entry->pos; 192 192 193 ui_entry_scroll_update(entry, false); 193 194 ui_entry_paint(entry); 194 195 195 196 return EOK; 197 } 198 199 /** Get entry text. 200 * 201 * @return Pointer to entry text. 202 */ 203 const char *ui_entry_get_text(ui_entry_t *entry) 204 { 205 return entry->text; 196 206 } 197 207 -
uspace/lib/ui/src/msgdialog.c
redeee9f r5e109e1 177 177 goto error; 178 178 179 dialog->bok = bok; 179 180 bok = NULL; 180 181 … … 187 188 188 189 dialog->window = window; 189 dialog->bok = bok;190 190 *rdialog = dialog; 191 191 return EOK; 192 192 error: 193 if (bok != NULL) 194 ui_pbutton_destroy(bok); 193 195 if (label != NULL) 194 196 ui_label_destroy(label); -
uspace/lib/ui/test/main.c
redeee9f r5e109e1 34 34 PCUT_IMPORT(checkbox); 35 35 PCUT_IMPORT(entry); 36 PCUT_IMPORT(file_dialog); 36 37 PCUT_IMPORT(fixed); 37 38 PCUT_IMPORT(image); … … 40 41 PCUT_IMPORT(menubar); 41 42 PCUT_IMPORT(menuentry); 43 PCUT_IMPORT(msg_dialog); 42 44 PCUT_IMPORT(paint); 43 45 PCUT_IMPORT(pbutton); -
uspace/lib/ui/test/msgdialog.c
redeee9f r5e109e1 108 108 ui_pbutton_clicked(dialog->bok); 109 109 110 /* Button callback with unfocuscallback not implemented */110 /* Button callback with callback not implemented */ 111 111 ui_msg_dialog_set_cb(dialog, &dummy_msg_dialog_cb, NULL); 112 112 ui_pbutton_clicked(dialog->bok);
Note:
See TracChangeset
for help on using the changeset viewer.