Changeset b71c0fc in mainline
- Timestamp:
- 2020-11-07T16:07:22Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d55ab823
- Parents:
- fa01c05
- Location:
- uspace
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rfa01c05 rb71c0fc 34 34 35 35 #include <gfx/coord.h> 36 #include <io/pos_event.h>37 36 #include <stdio.h> 38 37 #include <str.h> … … 43 42 #include <ui/resource.h> 44 43 #include <ui/ui.h> 45 #include <ui/wdecor.h>46 44 #include <ui/window.h> 47 45 #include "uidemo.h" 48 46 49 47 static void wnd_close(ui_window_t *, void *); 50 static errno_t wnd_paint(ui_window_t *, void *);51 static void wnd_pos(ui_window_t *, void *, pos_event_t *pos);52 48 53 49 static ui_window_cb_t window_cb = { 54 .close = wnd_close, 55 .paint = wnd_paint, 56 .pos = wnd_pos 50 .close = wnd_close 57 51 }; 58 52 … … 73 67 74 68 ui_quit(demo->ui); 75 }76 77 /** Window paint request.78 *79 * @param window Window80 * @param arg Argument (demo)81 * @return EOK on success or an error code82 */83 static errno_t wnd_paint(ui_window_t *window, void *arg)84 {85 ui_demo_t *demo = (ui_demo_t *) arg;86 errno_t rc;87 88 /* Let window paint its background */89 rc = ui_window_def_paint(window);90 if (rc != EOK)91 return rc;92 93 return ui_fixed_paint(demo->fixed);94 }95 96 /** Window position event.97 *98 * @param window Window99 * @param arg Argument (demo)100 */101 static void wnd_pos(ui_window_t *window, void *arg, pos_event_t *event)102 {103 ui_demo_t *demo = (ui_demo_t *) arg;104 105 /* Make sure we don't process events until fully initialized */106 if (demo->fixed == NULL)107 return;108 109 ui_fixed_pos_event(demo->fixed, event);110 69 } 111 70 … … 240 199 } 241 200 201 ui_window_add(window, ui_fixed_ctl(demo.fixed)); 202 242 203 rc = ui_window_paint(window); 243 204 if (rc != EOK) { … … 248 209 ui_run(ui); 249 210 250 ui_fixed_destroy(demo.fixed);251 211 ui_window_destroy(window); 252 212 ui_destroy(ui); -
uspace/lib/ui/include/ui/fixed.h
rfa01c05 rb71c0fc 45 45 extern errno_t ui_fixed_create(ui_fixed_t **); 46 46 extern void ui_fixed_destroy(ui_fixed_t *); 47 extern ui_control_t *ui_fixed_ctl(ui_fixed_t *); 47 48 extern errno_t ui_fixed_add(ui_fixed_t *, ui_control_t *); 48 49 extern void ui_fixed_remove(ui_fixed_t *, ui_control_t *); -
uspace/lib/ui/include/ui/window.h
rfa01c05 rb71c0fc 40 40 #include <gfx/context.h> 41 41 #include <gfx/coord.h> 42 #include <io/pos_event.h> 43 #include <types/ui/control.h> 42 44 #include <types/ui/ui.h> 43 45 #include <types/ui/resource.h> … … 49 51 extern void ui_window_set_cb(ui_window_t *, ui_window_cb_t *, void *); 50 52 extern void ui_window_destroy(ui_window_t *); 53 extern void ui_window_add(ui_window_t *, ui_control_t *); 54 extern void ui_window_remove(ui_window_t *, ui_control_t *); 51 55 extern ui_resource_t *ui_window_get_res(ui_window_t *); 52 56 extern gfx_context_t *ui_window_get_gc(ui_window_t *); … … 54 58 extern errno_t ui_window_paint(ui_window_t *); 55 59 extern errno_t ui_window_def_paint(ui_window_t *); 60 extern void ui_window_def_pos(ui_window_t *, pos_event_t *); 56 61 57 62 #endif -
uspace/lib/ui/private/fixed.h
rfa01c05 rb71c0fc 48 48 */ 49 49 struct ui_fixed { 50 /** Base control object */ 51 struct ui_control *control; 50 52 /** Layout elements (ui_fixed_elem_t) */ 51 53 list_t elem; -
uspace/lib/ui/private/window.h
rfa01c05 rb71c0fc 63 63 /** Window decoration */ 64 64 struct ui_wdecor *wdecor; 65 /** Top-level control in the application area */ 66 struct ui_control *control; 65 67 }; 66 68 -
uspace/lib/ui/src/control.c
rfa01c05 rb71c0fc 81 81 * extended data). 82 82 * 83 * @param control Control 83 * @param control Control or @c NULL 84 84 */ 85 85 void ui_control_destroy(ui_control_t *control) 86 86 { 87 if (control == NULL) 88 return; 89 87 90 return control->ops->destroy(control->ext); 88 91 } -
uspace/lib/ui/src/fixed.c
rfa01c05 rb71c0fc 44 44 #include "../private/fixed.h" 45 45 46 static void ui_fixed_ctl_destroy(void *); 47 static errno_t ui_fixed_ctl_paint(void *); 48 static ui_evclaim_t ui_fixed_ctl_pos_event(void *, pos_event_t *); 49 50 /** Push button control ops */ 51 ui_control_ops_t ui_fixed_ops = { 52 .destroy = ui_fixed_ctl_destroy, 53 .paint = ui_fixed_ctl_paint, 54 .pos_event = ui_fixed_ctl_pos_event 55 }; 56 46 57 /** Create new fixed layout. 47 58 * … … 52 63 { 53 64 ui_fixed_t *fixed; 65 errno_t rc; 54 66 55 67 fixed = calloc(1, sizeof(ui_fixed_t)); 56 68 if (fixed == NULL) 57 69 return ENOMEM; 70 71 rc = ui_control_new(&ui_fixed_ops, (void *) fixed, &fixed->control); 72 if (rc != EOK) { 73 free(fixed); 74 return rc; 75 } 58 76 59 77 list_initialize(&fixed->elem); … … 83 101 } 84 102 103 ui_control_delete(fixed->control); 85 104 free(fixed); 105 } 106 107 /** Get base control from fixed layout. 108 * 109 * @param fixed Fixed layout 110 * @return Control 111 */ 112 ui_control_t *ui_fixed_ctl(ui_fixed_t *fixed) 113 { 114 return fixed->control; 86 115 } 87 116 … … 203 232 } 204 233 234 /** Destroy fixed layout control. 235 * 236 * @param arg Argument (ui_fixed_t *) 237 */ 238 void ui_fixed_ctl_destroy(void *arg) 239 { 240 ui_fixed_t *fixed = (ui_fixed_t *) arg; 241 242 ui_fixed_destroy(fixed); 243 } 244 245 /** Paint fixed layout control. 246 * 247 * @param arg Argument (ui_fixed_t *) 248 * @return EOK on success or an error code 249 */ 250 errno_t ui_fixed_ctl_paint(void *arg) 251 { 252 ui_fixed_t *fixed = (ui_fixed_t *) arg; 253 254 return ui_fixed_paint(fixed); 255 } 256 257 /** Handle fixed layout control position event. 258 * 259 * @param arg Argument (ui_fixed_t *) 260 * @param pos_event Position event 261 * @return @c ui_claimed iff the event is claimed 262 */ 263 ui_evclaim_t ui_fixed_ctl_pos_event(void *arg, pos_event_t *event) 264 { 265 ui_fixed_t *fixed = (ui_fixed_t *) arg; 266 267 return ui_fixed_pos_event(fixed, event); 268 } 269 205 270 /** @} 206 271 */ -
uspace/lib/ui/src/window.c
rfa01c05 rb71c0fc 42 42 #include <mem.h> 43 43 #include <stdlib.h> 44 #include <ui/control.h> 44 45 #include <ui/resource.h> 45 46 #include <ui/wdecor.h> 46 47 #include <ui/window.h> 48 #include "../private/control.h" 47 49 #include "../private/dummygc.h" 48 50 #include "../private/resource.h" … … 170 172 return; 171 173 174 ui_control_destroy(window->control); 172 175 ui_wdecor_destroy(window->wdecor); 173 176 ui_resource_destroy(window->res); … … 177 180 } 178 181 182 /** Add control to window. 183 * 184 * Only one control can be added to a window. If more than one control 185 * is added, the results are undefined. 186 * 187 * @param fixed Fixed layout 188 * @param control Control 189 * @return EOK on success, ENOMEM if out of memory 190 */ 191 void ui_window_add(ui_window_t *window, ui_control_t *control) 192 { 193 assert(window->control == NULL); 194 195 window->control = control; 196 control->elemp = (void *) window; 197 } 198 199 /** Remove control from window. 200 * 201 * @param window Window 202 * @param control Control 203 */ 204 void ui_window_remove(ui_window_t *window, ui_control_t *control) 205 { 206 assert(window->control == control); 207 assert((ui_window_t *) control->elemp == window); 208 209 window->control = NULL; 210 control->elemp = NULL; 211 } 212 179 213 /** Set window callbacks. 180 214 * … … 343 377 if (window->cb != NULL && window->cb->pos != NULL) 344 378 window->cb->pos(window, window->arg, pos); 379 else 380 ui_window_def_pos(window, pos); 345 381 } 346 382 … … 375 411 return rc; 376 412 413 if (window->control != NULL) 414 return ui_control_paint(window->control); 415 377 416 return EOK; 378 417 } 379 418 419 /** Default window position event routine. 420 * 421 * @param window Window 422 * @return EOK on success or an error code 423 */ 424 void ui_window_def_pos(ui_window_t *window, pos_event_t *pos) 425 { 426 if (window->control != NULL) 427 ui_control_pos_event(window->control, pos); 428 } 429 380 430 /** @} 381 431 */ -
uspace/lib/ui/test/fixed.c
rfa01c05 rb71c0fc 83 83 } 84 84 85 /** ui_fixed_ctl() returns control that has a working virtual destructor */ 86 PCUT_TEST(ctl) 87 { 88 ui_fixed_t *fixed; 89 ui_control_t *control; 90 errno_t rc; 91 92 rc = ui_fixed_create(&fixed); 93 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 94 95 control = ui_fixed_ctl(fixed); 96 PCUT_ASSERT_NOT_NULL(control); 97 98 ui_control_destroy(control); 99 } 100 85 101 /** ui_fixed_add() / ui_fixed_remove() adds/removes control */ 86 102 PCUT_TEST(add_remove) -
uspace/lib/ui/test/label.c
rfa01c05 rb71c0fc 32 32 #include <pcut/pcut.h> 33 33 #include <stdbool.h> 34 #include <ui/control.h> 34 35 #include <ui/label.h> 35 36 #include <ui/resource.h> … … 95 96 { 96 97 ui_label_destroy(NULL); 98 } 99 100 /** ui_label_ctl() returns control that has a working virtual destructor */ 101 PCUT_TEST(ctl) 102 { 103 ui_label_t *label; 104 ui_control_t *control; 105 errno_t rc; 106 107 rc = ui_label_create(NULL, "Hello", &label); 108 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 109 110 control = ui_label_ctl(label); 111 PCUT_ASSERT_NOT_NULL(control); 112 113 ui_control_destroy(control); 97 114 } 98 115 -
uspace/lib/ui/test/pbutton.c
rfa01c05 rb71c0fc 32 32 #include <pcut/pcut.h> 33 33 #include <stdbool.h> 34 #include <ui/control.h> 34 35 #include <ui/pbutton.h> 35 36 #include <ui/resource.h> … … 104 105 { 105 106 ui_pbutton_destroy(NULL); 107 } 108 109 /** ui_pbutton_ctl() returns control that has a working virtual destructor */ 110 PCUT_TEST(ctl) 111 { 112 ui_pbutton_t *pbutton; 113 ui_control_t *control; 114 errno_t rc; 115 116 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 117 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 118 119 control = ui_pbutton_ctl(pbutton); 120 PCUT_ASSERT_NOT_NULL(control); 121 122 ui_control_destroy(control); 106 123 } 107 124 -
uspace/lib/ui/test/window.c
rfa01c05 rb71c0fc 34 34 #include <pcut/pcut.h> 35 35 #include <stdbool.h> 36 #include <ui/control.h> 36 37 #include <ui/resource.h> 37 38 #include <ui/ui.h> … … 60 61 61 62 static ui_window_cb_t dummy_window_cb = { 63 }; 64 65 static errno_t test_ctl_paint(void *); 66 static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *); 67 68 static ui_control_ops_t test_ctl_ops = { 69 .paint = test_ctl_paint, 70 .pos_event = test_ctl_pos_event 62 71 }; 63 72 … … 74 83 } test_cb_resp_t; 75 84 85 typedef struct { 86 errno_t rc; 87 ui_evclaim_t claim; 88 bool paint; 89 bool pos; 90 pos_event_t pos_event; 91 } test_ctl_resp_t; 92 76 93 /** Create and destroy window */ 77 94 PCUT_TEST(create_destroy) … … 100 117 { 101 118 ui_window_destroy(NULL); 119 } 120 121 /** ui_window_add()/ui_window_remove() ... */ 122 PCUT_TEST(add_remove) 123 { 124 errno_t rc; 125 ui_t *ui = NULL; 126 ui_wnd_params_t params; 127 ui_window_t *window = NULL; 128 ui_control_t *control = NULL; 129 test_ctl_resp_t resp; 130 131 rc = ui_create_disp(NULL, &ui); 132 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 133 134 ui_wnd_params_init(¶ms); 135 params.caption = "Hello"; 136 137 rc = ui_window_create(ui, ¶ms, &window); 138 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 139 PCUT_ASSERT_NOT_NULL(window); 140 141 rc = ui_control_new(&test_ctl_ops, &resp, &control); 142 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 143 144 /* Control not called since it hasn't been added yet */ 145 resp.rc = ENOMEM; 146 resp.paint = false; 147 rc = ui_window_def_paint(window); 148 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 149 PCUT_ASSERT_FALSE(resp.paint); 150 151 ui_window_add(window, control); 152 153 /* Now paint request should be delivered to control */ 154 resp.rc = EOK; 155 resp.paint = false; 156 rc = ui_window_def_paint(window); 157 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 158 PCUT_ASSERT_TRUE(resp.paint); 159 160 ui_window_remove(window, control); 161 162 /* 163 * After having removed the control the request should no longer 164 * be delivered to it. 165 */ 166 resp.rc = ENOMEM; 167 resp.paint = false; 168 rc = ui_window_def_paint(window); 169 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 170 PCUT_ASSERT_FALSE(resp.paint); 171 172 ui_window_destroy(window); 173 ui_destroy(ui); 102 174 } 103 175 … … 166 238 ui_wnd_params_t params; 167 239 ui_window_t *window = NULL; 168 169 rc = ui_create_disp(NULL, &ui); 170 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 171 172 ui_wnd_params_init(¶ms); 173 params.caption = "Hello"; 174 175 rc = ui_window_create(ui, ¶ms, &window); 176 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 177 PCUT_ASSERT_NOT_NULL(window); 178 179 ui_window_def_paint(window); 240 ui_control_t *control = NULL; 241 test_ctl_resp_t resp; 242 243 rc = ui_create_disp(NULL, &ui); 244 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 245 246 ui_wnd_params_init(¶ms); 247 params.caption = "Hello"; 248 249 rc = ui_window_create(ui, ¶ms, &window); 250 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 251 PCUT_ASSERT_NOT_NULL(window); 252 253 rc = ui_control_new(&test_ctl_ops, &resp, &control); 254 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 255 256 ui_window_add(window, control); 257 258 resp.rc = EOK; 259 resp.paint = false; 260 rc = ui_window_def_paint(window); 261 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 262 PCUT_ASSERT_TRUE(resp.paint); 263 264 resp.rc = ENOMEM; 265 resp.paint = false; 266 rc = ui_window_def_paint(window); 267 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 268 PCUT_ASSERT_TRUE(resp.paint); 269 270 PCUT_ASSERT_TRUE(resp.paint); 271 272 /* Need to remove first because we didn't implement the destructor */ 273 ui_window_remove(window, control); 274 275 ui_window_destroy(window); 276 ui_destroy(ui); 277 } 278 279 /** ui_window_def_pos() delivers position event to control in window */ 280 PCUT_TEST(def_pos) 281 { 282 errno_t rc; 283 ui_t *ui = NULL; 284 ui_wnd_params_t params; 285 ui_window_t *window = NULL; 286 ui_control_t *control = NULL; 287 test_ctl_resp_t resp; 288 pos_event_t event; 289 290 rc = ui_create_disp(NULL, &ui); 291 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 292 293 ui_wnd_params_init(¶ms); 294 params.caption = "Hello"; 295 296 rc = ui_window_create(ui, ¶ms, &window); 297 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 298 299 rc = ui_control_new(&test_ctl_ops, &resp, &control); 300 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 301 302 ui_window_add(window, control); 303 304 event.pos_id = 1; 305 event.type = POS_PRESS; 306 event.btn_num = 2; 307 event.hpos = 3; 308 event.vpos = 4; 309 310 resp.pos = false; 311 resp.claim = ui_claimed; 312 313 ui_window_def_pos(window, &event); 314 315 PCUT_ASSERT_TRUE(resp.pos); 316 PCUT_ASSERT_INT_EQUALS(event.pos_id, resp.pos_event.pos_id); 317 PCUT_ASSERT_INT_EQUALS(event.type, resp.pos_event.type); 318 PCUT_ASSERT_INT_EQUALS(event.btn_num, resp.pos_event.btn_num); 319 PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos_event.hpos); 320 PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos_event.vpos); 321 322 /* Need to remove first because we didn't implement the destructor */ 323 ui_window_remove(window, control); 180 324 181 325 ui_window_destroy(window); … … 470 614 } 471 615 616 static errno_t test_ctl_paint(void *arg) 617 { 618 test_ctl_resp_t *resp = (test_ctl_resp_t *) arg; 619 620 resp->paint = true; 621 return resp->rc; 622 } 623 624 static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event) 625 { 626 test_ctl_resp_t *resp = (test_ctl_resp_t *) arg; 627 628 resp->pos = true; 629 resp->pos_event = *event; 630 631 return resp->claim; 632 } 633 472 634 PCUT_EXPORT(window);
Note:
See TracChangeset
for help on using the changeset viewer.