Changeset c4a53280 in mainline
- Timestamp:
- 2022-12-01T14:39:56Z (2 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 795c6f7
- Parents:
- 68d68e9
- git-author:
- Jiri Svoboda <jiri@…> (2022-11-30 18:39:42)
- git-committer:
- Jiri Svoboda <jiri@…> (2022-12-01 14:39:56)
- Location:
- uspace/app/taskbar
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/test/wndlist.c
r68d68e9 rc4a53280 407 407 } 408 408 409 /** Test wndlist_last() */ 410 PCUT_TEST(last) 411 { 412 errno_t rc; 413 ui_t *ui = NULL; 414 ui_wnd_params_t params; 415 ui_window_t *window = NULL; 416 ui_fixed_t *fixed = NULL; 417 wndlist_t *wndlist; 418 wndlist_entry_t *entry; 419 420 rc = ui_create_disp(NULL, &ui); 421 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 422 423 ui_wnd_params_init(¶ms); 424 params.caption = "Hello"; 425 426 rc = ui_window_create(ui, ¶ms, &window); 427 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 428 PCUT_ASSERT_NOT_NULL(window); 429 430 rc = ui_fixed_create(&fixed); 431 ui_window_add(window, ui_fixed_ctl(fixed)); 432 433 rc = wndlist_create(window, fixed, &wndlist); 434 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 435 436 rc = wndlist_append(wndlist, 1, "Foo", true); 437 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 438 439 rc = wndlist_append(wndlist, 2, "Bar", true); 440 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 441 442 entry = wndlist_last(wndlist); 443 PCUT_ASSERT_NOT_NULL(entry); 444 PCUT_ASSERT_INT_EQUALS(2, entry->wnd_id); 445 446 wndlist_destroy(wndlist); 447 448 ui_window_destroy(window); 449 ui_destroy(ui); 450 } 451 409 452 /** Test wndlist_count() */ 410 453 PCUT_TEST(count) -
uspace/app/taskbar/types/wndlist.h
r68d68e9 rc4a53280 57 57 /** Window button */ 58 58 ui_pbutton_t *button; 59 /** Window button rectangle */ 60 gfx_rect_t rect; 59 61 } wndlist_entry_t; 60 62 … … 76 78 list_t entries; 77 79 80 /** Current button pitch */ 81 gfx_coord_t pitch; 82 78 83 /** Window management service */ 79 84 wndmgt_t *wndmgt; -
uspace/app/taskbar/wndlist.c
r68d68e9 rc4a53280 34 34 35 35 #include <gfx/coord.h> 36 #include <gfx/render.h> 36 37 #include <stdbool.h> 37 38 #include <stddef.h> … … 91 92 wndlist_t **rwndlist) 92 93 { 94 ui_resource_t *res = ui_window_get_res(window); 93 95 wndlist_t *wndlist = NULL; 94 96 errno_t rc; … … 103 105 wndlist->fixed = fixed; 104 106 list_initialize(&wndlist->entries); 107 108 if (ui_resource_is_textmode(res)) 109 wndlist->pitch = wndlist_button_pitch_max_text; 110 else 111 wndlist->pitch = wndlist_button_pitch_max; 112 105 113 *rwndlist = wndlist; 106 114 return EOK; … … 223 231 entry->visible = false; 224 232 225 /*226 * Update rectangles for all entries, including @a entry, adding227 * it to the layout, if applicable.228 */229 e = wndlist_first(wndlist);230 while (e != NULL) {231 wndlist_set_entry_rect(wndlist, e);232 e = wndlist_next(e);233 }234 235 233 /* Set button callbacks */ 236 234 ui_pbutton_set_cb(entry->button, &wndlist_button_cb, (void *)entry); 237 235 238 if (paint) 239 return wndlist_repaint(wndlist); 236 if (wndlist_update_pitch(wndlist)) { 237 /* 238 * Update rectangles for all entries, including @a entry, adding 239 * it to the layout, if applicable. 240 */ 241 e = wndlist_first(wndlist); 242 while (e != NULL) { 243 wndlist_set_entry_rect(wndlist, e); 244 e = wndlist_next(e); 245 } 246 247 if (paint) 248 return wndlist_repaint(wndlist); 249 } else { 250 wndlist_set_entry_rect(wndlist, entry); 251 if (paint) 252 return ui_pbutton_paint(entry->button); 253 } 240 254 241 255 return EOK; … … 260 274 { 261 275 wndlist_entry_t *e; 276 wndlist_entry_t *next; 277 wndlist_entry_t *last; 278 errno_t rc = EOK; 279 262 280 assert(entry->wndlist == wndlist); 281 next = wndlist_next(entry); 282 283 /* Remember last entry */ 284 last = wndlist_last(wndlist); 263 285 264 286 if (entry->visible) 265 287 ui_fixed_remove(wndlist->fixed, ui_pbutton_ctl(entry->button)); 288 list_remove(&entry->lentries); 289 290 if (wndlist_update_pitch(wndlist)) { 291 /* 292 * Update rectangles for all entries. 293 */ 294 e = wndlist_first(wndlist); 295 while (e != NULL) { 296 wndlist_set_entry_rect(wndlist, e); 297 e = wndlist_next(e); 298 } 299 300 if (paint) 301 rc = wndlist_repaint(wndlist); 302 } else { 303 /* Unpaint the last entry */ 304 if (paint) 305 rc = wndlist_unpaint_entry(last); 306 307 /* 308 * Update rectangles for entries to the right 309 */ 310 311 e = NULL; 312 while (next != NULL) { 313 e = next; 314 315 wndlist_set_entry_rect(wndlist, e); 316 if (paint) { 317 rc = ui_pbutton_paint(e->button); 318 if (rc != EOK) 319 return rc; 320 } 321 322 next = wndlist_next(e); 323 } 324 } 325 266 326 ui_pbutton_destroy(entry->button); 267 list_remove(&entry->lentries);268 327 free(entry); 269 270 /* Update positions of the all entries */ 271 e = wndlist_first(wndlist); 272 while (e != NULL) { 273 wndlist_set_entry_rect(wndlist, e); 274 e = wndlist_next(e); 275 } 276 277 if (!paint) 278 return EOK; 279 280 return wndlist_repaint(wndlist); 281 } 282 283 /** Update window list entry. 284 * 285 * @param wndlist Window list 286 * @param entry Window list entry 287 * @return @c EOK on success or an error code 288 */ 289 errno_t wndlist_update(wndlist_t *wndlist, wndlist_entry_t *entry, 290 const char *caption) 291 { 292 errno_t rc; 293 assert(entry->wndlist == wndlist); 294 295 rc = ui_pbutton_set_caption(entry->button, caption); 296 if (rc != EOK) 297 return rc; 298 299 rc = ui_pbutton_paint(entry->button); 300 if (rc != EOK) 301 return rc; 302 303 return wndlist_repaint(wndlist); 304 } 305 306 /** Compute and set window list entry rectangle. 307 * 308 * Compute rectangle for window list entry and set it. 309 * 310 * @param wndlist Window list 311 * @param entry Window list entry 312 */ 313 void wndlist_set_entry_rect(wndlist_t *wndlist, wndlist_entry_t *entry) 314 { 315 wndlist_entry_t *e; 316 gfx_rect_t rect; 328 return rc; 329 } 330 331 /** Update button pitch. 332 * 333 * Recalculatebutton pitch @c wndlist->pitch based on current number 334 * of buttons. 335 * 336 * @param wndlist Window list 337 * @return @c true iff pitch changed 338 */ 339 bool wndlist_update_pitch(wndlist_t *wndlist) 340 { 317 341 ui_resource_t *res; 342 size_t nbuttons; 318 343 gfx_coord_t pitch; 319 344 gfx_coord_t pitch_max; 320 345 gfx_coord_t pitch_min; 321 346 gfx_coord_t pad; 322 size_t idx;323 size_t nbuttons;324 325 /* Determine entry index */326 idx = 0;327 e = wndlist_first(wndlist);328 while (e != entry) {329 assert(e != NULL);330 e = wndlist_next(e);331 ++idx;332 }333 347 334 348 res = ui_window_get_res(wndlist->window); … … 346 360 /* Compute pitch that fits all buttons perfectly */ 347 361 nbuttons = wndlist_count(wndlist); 348 pitch = (wndlist->rect.p1.x - wndlist->rect.p0.x + pad) / nbuttons; 362 if (nbuttons > 0) 363 pitch = (wndlist->rect.p1.x - wndlist->rect.p0.x + pad) / nbuttons; 364 else 365 pitch = pitch_min; 366 349 367 if (pitch < pitch_min) 350 368 pitch = pitch_min; 351 369 if (pitch > pitch_max) 352 370 pitch = pitch_max; 371 372 /* Did the pitch change? */ 373 if (pitch == wndlist->pitch) 374 return false; 375 376 wndlist->pitch = pitch; 377 return true; 378 } 379 380 /** Update window list entry. 381 * 382 * @param wndlist Window list 383 * @param entry Window list entry 384 * @return @c EOK on success or an error code 385 */ 386 errno_t wndlist_update(wndlist_t *wndlist, wndlist_entry_t *entry, 387 const char *caption) 388 { 389 errno_t rc; 390 assert(entry->wndlist == wndlist); 391 392 rc = ui_pbutton_set_caption(entry->button, caption); 393 if (rc != EOK) 394 return rc; 395 396 rc = ui_pbutton_paint(entry->button); 397 if (rc != EOK) 398 return rc; 399 400 return wndlist_repaint(wndlist); 401 } 402 403 /** Compute and set window list entry rectangle. 404 * 405 * Compute rectangle for window list entry and set it. 406 * 407 * @param wndlist Window list 408 * @param entry Window list entry 409 */ 410 void wndlist_set_entry_rect(wndlist_t *wndlist, wndlist_entry_t *entry) 411 { 412 wndlist_entry_t *e; 413 gfx_rect_t rect; 414 ui_resource_t *res; 415 gfx_coord_t pitch; 416 gfx_coord_t pad; 417 size_t idx; 418 419 /* Determine entry index */ 420 idx = 0; 421 e = wndlist_first(wndlist); 422 while (e != entry) { 423 assert(e != NULL); 424 e = wndlist_next(e); 425 ++idx; 426 } 427 428 res = ui_window_get_res(wndlist->window); 429 430 if (ui_resource_is_textmode(res)) { 431 pad = wndlist_button_pad_text; 432 } else { 433 pad = wndlist_button_pad; 434 } 435 436 pitch = wndlist->pitch; 353 437 354 438 rect.p0.x = wndlist->rect.p0.x + pitch * idx; … … 375 459 376 460 ui_pbutton_set_rect(entry->button, &rect); 461 entry->rect = rect; 462 } 463 464 /** Compute and set window list entry rectangle. 465 * 466 * Compute rectangle for window list entry and set it. 467 * 468 * @param entry Window list entry 469 * @return EOK on success or an error code 470 */ 471 errno_t wndlist_unpaint_entry(wndlist_entry_t *entry) 472 { 473 errno_t rc; 474 gfx_context_t *gc; 475 ui_resource_t *res; 476 gfx_color_t *color; 477 478 gc = ui_window_get_gc(entry->wndlist->window); 479 res = ui_window_get_res(entry->wndlist->window); 480 color = ui_resource_get_wnd_face_color(res); 481 482 rc = gfx_set_color(gc, color); 483 if (rc != EOK) 484 return rc; 485 486 rc = gfx_fill_rect(gc, &entry->rect); 487 if (rc != EOK) 488 return rc; 489 490 return EOK; 377 491 } 378 492 … … 485 599 } 486 600 601 /** Get last window list entry. 602 * 603 * @param wndlist Window list 604 * @return Last entry or @c NULL if the list is empty 605 */ 606 wndlist_entry_t *wndlist_last(wndlist_t *wndlist) 607 { 608 link_t *link; 609 610 link = list_last(&wndlist->entries); 611 if (link == NULL) 612 return NULL; 613 614 return list_get_instance(link, wndlist_entry_t, lentries); 615 } 616 487 617 /** Get next window list entry. 488 618 * -
uspace/app/taskbar/wndlist.h
r68d68e9 rc4a53280 52 52 extern errno_t wndlist_append(wndlist_t *, sysarg_t, const char *, bool); 53 53 extern errno_t wndlist_remove(wndlist_t *, wndlist_entry_t *, bool); 54 extern bool wndlist_update_pitch(wndlist_t *); 54 55 extern errno_t wndlist_update(wndlist_t *, wndlist_entry_t *, const char *); 55 56 extern void wndlist_set_entry_rect(wndlist_t *, wndlist_entry_t *); 56 57 extern wndlist_entry_t *wndlist_entry_by_id(wndlist_t *, sysarg_t); 57 58 extern wndlist_entry_t *wndlist_first(wndlist_t *); 59 extern wndlist_entry_t *wndlist_last(wndlist_t *); 58 60 extern wndlist_entry_t *wndlist_next(wndlist_entry_t *); 59 61 extern size_t wndlist_count(wndlist_t *); 60 62 extern errno_t wndlist_repaint(wndlist_t *); 63 extern errno_t wndlist_unpaint_entry(wndlist_entry_t *); 61 64 62 65 #endif
Note:
See TracChangeset
for help on using the changeset viewer.