Changeset f03d1308 in mainline for uspace/lib
- Timestamp:
- 2020-10-28T12:42:11Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8009dc27
- Parents:
- d284ce9
- git-author:
- Jiri Svoboda <jiri@…> (2020-10-28 12:41:11)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-10-28 12:42:11)
- Location:
- uspace/lib/ui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/types/ui/window.h
rd284ce9 rf03d1308 37 37 #define _UI_TYPES_WINDOW_H 38 38 39 #include <io/kbd_event.h> 39 40 #include <io/pos_event.h> 40 41 … … 53 54 typedef struct ui_window_cb { 54 55 void (*close)(ui_window_t *, void *); 56 void (*focus)(ui_window_t *, void *); 57 void (*kbd)(ui_window_t *, void *, kbd_event_t *); 55 58 void (*pos)(ui_window_t *, void *, pos_event_t *); 59 void (*unfocus)(ui_window_t *, void *); 56 60 } ui_window_cb_t; 57 61 -
uspace/lib/ui/private/window.h
rd284ce9 rf03d1308 40 40 #include <display.h> 41 41 #include <gfx/context.h> 42 #include <io/kbd_event.h> 42 43 #include <io/pos_event.h> 43 44 … … 64 65 65 66 extern void ui_window_close(ui_window_t *); 67 extern void ui_window_focus(ui_window_t *); 68 extern void ui_window_kbd(ui_window_t *, kbd_event_t *); 66 69 extern void ui_window_pos(ui_window_t *, pos_event_t *); 70 extern void ui_window_unfocus(ui_window_t *); 67 71 68 72 #endif -
uspace/lib/ui/src/window.c
rd284ce9 rf03d1308 37 37 #include <errno.h> 38 38 #include <gfx/context.h> 39 #include <io/kbd_event.h> 39 40 #include <io/pos_event.h> 40 41 #include <mem.h> … … 221 222 ui_wdecor_paint(window->wdecor); 222 223 } 224 225 ui_window_focus(window); 223 226 } 224 227 … … 229 232 230 233 (void) window; 231 (void) kbd_event;234 ui_window_kbd(window, kbd_event); 232 235 } 233 236 … … 254 257 ui_wdecor_paint(window->wdecor); 255 258 } 259 260 ui_window_unfocus(window); 256 261 } 257 262 … … 291 296 } 292 297 298 /** Send window focus event. 299 * 300 * @param window Window 301 */ 302 void ui_window_focus(ui_window_t *window) 303 { 304 if (window->cb != NULL && window->cb->focus != NULL) 305 window->cb->focus(window, window->arg); 306 } 307 308 /** Send window keyboard event. 309 * 310 * @param window Window 311 */ 312 void ui_window_kbd(ui_window_t *window, kbd_event_t *kbd) 313 { 314 if (window->cb != NULL && window->cb->kbd != NULL) 315 window->cb->kbd(window, window->arg, kbd); 316 } 317 293 318 /** Send window position event. 294 319 * … … 301 326 } 302 327 328 /** Send window unfocus event. 329 * 330 * @param window Window 331 */ 332 void ui_window_unfocus(ui_window_t *window) 333 { 334 if (window->cb != NULL && window->cb->unfocus != NULL) 335 window->cb->unfocus(window, window->arg); 336 } 337 303 338 /** @} 304 339 */ -
uspace/lib/ui/test/window.c
rd284ce9 rf03d1308 29 29 #include <gfx/context.h> 30 30 #include <gfx/coord.h> 31 #include <io/kbd_event.h> 31 32 #include <io/pos_event.h> 32 33 #include <mem.h> … … 43 44 44 45 static void test_window_close(ui_window_t *, void *); 46 static void test_window_focus(ui_window_t *, void *); 47 static void test_window_kbd(ui_window_t *, void *, kbd_event_t *); 45 48 static void test_window_pos(ui_window_t *, void *, pos_event_t *); 49 static void test_window_unfocus(ui_window_t *, void *); 46 50 47 51 static ui_window_cb_t test_window_cb = { 48 52 .close = test_window_close, 49 .pos = test_window_pos 53 .focus = test_window_focus, 54 .kbd = test_window_kbd, 55 .pos = test_window_pos, 56 .unfocus = test_window_unfocus 50 57 }; 51 58 … … 55 62 typedef struct { 56 63 bool close; 64 bool focus; 65 bool kbd; 66 kbd_event_t kbd_event; 57 67 bool pos; 58 68 pos_event_t pos_event; 69 bool unfocus; 59 70 } test_cb_resp_t; 60 71 … … 151 162 ui_window_close(window); 152 163 PCUT_ASSERT_TRUE(resp.close); 164 165 ui_window_destroy(window); 166 ui_destroy(ui); 167 } 168 169 /** ui_window_focus() calls focus callback set via ui_window_set_cb() */ 170 PCUT_TEST(focus) 171 { 172 errno_t rc; 173 ui_t *ui = NULL; 174 ui_wnd_params_t params; 175 ui_window_t *window = NULL; 176 test_cb_resp_t resp; 177 178 rc = ui_create_disp(NULL, &ui); 179 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 180 181 ui_wnd_params_init(¶ms); 182 params.caption = "Hello"; 183 184 rc = ui_window_create(ui, ¶ms, &window); 185 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 186 PCUT_ASSERT_NOT_NULL(window); 187 188 /* Focus callback with no callbacks set */ 189 ui_window_focus(window); 190 191 /* Focus callback with focus callback not implemented */ 192 ui_window_set_cb(window, &dummy_window_cb, NULL); 193 ui_window_focus(window); 194 195 /* Focus callback with real callback set */ 196 resp.close = false; 197 ui_window_set_cb(window, &test_window_cb, &resp); 198 ui_window_focus(window); 199 PCUT_ASSERT_TRUE(resp.focus); 200 201 ui_window_destroy(window); 202 ui_destroy(ui); 203 } 204 205 /** ui_window_kbd() calls kbd callback set via ui_window_set_cb() */ 206 PCUT_TEST(kbd) 207 { 208 errno_t rc; 209 ui_t *ui = NULL; 210 ui_wnd_params_t params; 211 ui_window_t *window = NULL; 212 kbd_event_t kbd_event; 213 test_cb_resp_t resp; 214 215 rc = ui_create_disp(NULL, &ui); 216 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 217 218 ui_wnd_params_init(¶ms); 219 params.caption = "Hello"; 220 221 rc = ui_window_create(ui, ¶ms, &window); 222 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 223 PCUT_ASSERT_NOT_NULL(window); 224 225 kbd_event.type = POS_PRESS; 226 kbd_event.key = KC_X; 227 kbd_event.mods = 0; 228 kbd_event.c = 'x'; 229 230 /* Kbd callback with no callbacks set */ 231 ui_window_kbd(window, &kbd_event); 232 233 /* Kbd callback with kbd callback not implemented */ 234 ui_window_set_cb(window, &dummy_window_cb, NULL); 235 ui_window_kbd(window, &kbd_event); 236 237 /* Kbd callback with real callback set */ 238 resp.kbd = false; 239 ui_window_set_cb(window, &test_window_cb, &resp); 240 ui_window_kbd(window, &kbd_event); 241 PCUT_ASSERT_TRUE(resp.kbd); 242 PCUT_ASSERT_EQUALS(kbd_event.type, resp.kbd_event.type); 243 PCUT_ASSERT_INT_EQUALS(kbd_event.key, resp.kbd_event.key); 244 PCUT_ASSERT_INT_EQUALS(kbd_event.mods, resp.kbd_event.mods); 245 PCUT_ASSERT_INT_EQUALS(kbd_event.c, resp.kbd_event.c); 153 246 154 247 ui_window_destroy(window); … … 204 297 } 205 298 299 /** ui_window_unfocus() calls unfocus callback set via ui_window_set_cb() */ 300 PCUT_TEST(unfocus) 301 { 302 errno_t rc; 303 ui_t *ui = NULL; 304 ui_wnd_params_t params; 305 ui_window_t *window = NULL; 306 test_cb_resp_t resp; 307 308 rc = ui_create_disp(NULL, &ui); 309 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 310 311 ui_wnd_params_init(¶ms); 312 params.caption = "Hello"; 313 314 rc = ui_window_create(ui, ¶ms, &window); 315 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 316 PCUT_ASSERT_NOT_NULL(window); 317 318 /* Unfocus callback with no callbacks set */ 319 ui_window_unfocus(window); 320 321 /* Unfocus callback with unfocus callback not implemented */ 322 ui_window_set_cb(window, &dummy_window_cb, NULL); 323 ui_window_unfocus(window); 324 325 /* Unfocus callback with real callback set */ 326 resp.close = false; 327 ui_window_set_cb(window, &test_window_cb, &resp); 328 ui_window_unfocus(window); 329 PCUT_ASSERT_TRUE(resp.unfocus); 330 331 ui_window_destroy(window); 332 ui_destroy(ui); 333 } 334 206 335 static void test_window_close(ui_window_t *window, void *arg) 207 336 { … … 209 338 210 339 resp->close = true; 340 } 341 342 static void test_window_focus(ui_window_t *window, void *arg) 343 { 344 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 345 346 resp->focus = true; 347 } 348 349 static void test_window_kbd(ui_window_t *window, void *arg, 350 kbd_event_t *event) 351 { 352 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 353 354 resp->kbd = true; 355 resp->kbd_event = *event; 211 356 } 212 357 … … 220 365 } 221 366 367 static void test_window_unfocus(ui_window_t *window, void *arg) 368 { 369 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 370 371 resp->unfocus = true; 372 } 373 222 374 PCUT_EXPORT(window);
Note:
See TracChangeset
for help on using the changeset viewer.