[f7a90df] | 1 | /*
|
---|
[2ab8ab3] | 2 | * Copyright (c) 2021 Jiri Svoboda
|
---|
[f7a90df] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libui
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file Window
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[77ffa01] | 36 | #include <congfx/console.h>
|
---|
[f7a90df] | 37 | #include <display.h>
|
---|
| 38 | #include <errno.h>
|
---|
[66a2becf] | 39 | #include <gfx/bitmap.h>
|
---|
[f7a90df] | 40 | #include <gfx/context.h>
|
---|
[1215db9] | 41 | #include <gfx/cursor.h>
|
---|
[fa01c05] | 42 | #include <gfx/render.h>
|
---|
[f03d1308] | 43 | #include <io/kbd_event.h>
|
---|
[d284ce9] | 44 | #include <io/pos_event.h>
|
---|
[f7a90df] | 45 | #include <mem.h>
|
---|
[66a2becf] | 46 | #include <memgfx/memgc.h>
|
---|
[f7a90df] | 47 | #include <stdlib.h>
|
---|
[b71c0fc] | 48 | #include <ui/control.h>
|
---|
[f7a90df] | 49 | #include <ui/resource.h>
|
---|
[9c7dc8e] | 50 | #include <ui/ui.h>
|
---|
[f7a90df] | 51 | #include <ui/wdecor.h>
|
---|
| 52 | #include <ui/window.h>
|
---|
[b71c0fc] | 53 | #include "../private/control.h"
|
---|
[f7a90df] | 54 | #include "../private/dummygc.h"
|
---|
[fa01c05] | 55 | #include "../private/resource.h"
|
---|
[f7a90df] | 56 | #include "../private/ui.h"
|
---|
[d284ce9] | 57 | #include "../private/wdecor.h"
|
---|
[f7a90df] | 58 | #include "../private/window.h"
|
---|
| 59 |
|
---|
[d284ce9] | 60 | static void dwnd_close_event(void *);
|
---|
| 61 | static void dwnd_focus_event(void *);
|
---|
| 62 | static void dwnd_kbd_event(void *, kbd_event_t *);
|
---|
| 63 | static void dwnd_pos_event(void *, pos_event_t *);
|
---|
[2d879f7] | 64 | static void dwnd_resize_event(void *, gfx_rect_t *);
|
---|
[d284ce9] | 65 | static void dwnd_unfocus_event(void *);
|
---|
| 66 |
|
---|
| 67 | static display_wnd_cb_t dwnd_cb = {
|
---|
| 68 | .close_event = dwnd_close_event,
|
---|
| 69 | .focus_event = dwnd_focus_event,
|
---|
| 70 | .kbd_event = dwnd_kbd_event,
|
---|
| 71 | .pos_event = dwnd_pos_event,
|
---|
[2d879f7] | 72 | .resize_event = dwnd_resize_event,
|
---|
[d284ce9] | 73 | .unfocus_event = dwnd_unfocus_event
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 | static void wd_close(ui_wdecor_t *, void *);
|
---|
| 77 | static void wd_move(ui_wdecor_t *, void *, gfx_coord2_t *);
|
---|
[2d879f7] | 78 | static void wd_resize(ui_wdecor_t *, void *, ui_wdecor_rsztype_t,
|
---|
| 79 | gfx_coord2_t *);
|
---|
| 80 | static void wd_set_cursor(ui_wdecor_t *, void *, ui_stock_cursor_t);
|
---|
[d284ce9] | 81 |
|
---|
| 82 | static ui_wdecor_cb_t wdecor_cb = {
|
---|
| 83 | .close = wd_close,
|
---|
[2d879f7] | 84 | .move = wd_move,
|
---|
| 85 | .resize = wd_resize,
|
---|
| 86 | .set_cursor = wd_set_cursor
|
---|
[d284ce9] | 87 | };
|
---|
| 88 |
|
---|
[2ab8ab3] | 89 | static void ui_window_invalidate(void *, gfx_rect_t *);
|
---|
| 90 | static void ui_window_update(void *);
|
---|
[1215db9] | 91 | static errno_t ui_window_cursor_get_pos(void *, gfx_coord2_t *);
|
---|
| 92 | static errno_t ui_window_cursor_set_pos(void *, gfx_coord2_t *);
|
---|
| 93 | static errno_t ui_window_cursor_set_visible(void *, bool);
|
---|
| 94 |
|
---|
| 95 | /** Window memory GC callbacks */
|
---|
| 96 | static mem_gc_cb_t ui_window_mem_gc_cb = {
|
---|
| 97 | .invalidate = ui_window_invalidate,
|
---|
| 98 | .update = ui_window_update,
|
---|
| 99 | .cursor_get_pos = ui_window_cursor_get_pos,
|
---|
| 100 | .cursor_set_pos = ui_window_cursor_set_pos,
|
---|
| 101 | .cursor_set_visible = ui_window_cursor_set_visible
|
---|
| 102 | };
|
---|
| 103 |
|
---|
[2ab8ab3] | 104 | static void ui_window_app_invalidate(void *, gfx_rect_t *);
|
---|
| 105 | static void ui_window_app_update(void *);
|
---|
[1215db9] | 106 |
|
---|
| 107 | /** Application area memory GC callbacks */
|
---|
| 108 | static mem_gc_cb_t ui_window_app_mem_gc_cb = {
|
---|
| 109 | .invalidate = ui_window_app_invalidate,
|
---|
| 110 | .update = ui_window_app_update
|
---|
| 111 | };
|
---|
| 112 |
|
---|
[214aefb] | 113 | static void ui_window_expose_cb(void *);
|
---|
[66a2becf] | 114 |
|
---|
[f7a90df] | 115 | /** Initialize window parameters structure.
|
---|
| 116 | *
|
---|
| 117 | * Window parameters structure must always be initialized using this function
|
---|
[266ec54] | 118 | * first. By default, the window will be decorated. To get a non-decorated
|
---|
| 119 | * window, one needs to clear ui_wds_decorated
|
---|
| 120 | * (e.g. params->style &= ~ui_wds_decorated).
|
---|
[f7a90df] | 121 | *
|
---|
| 122 | * @param params Window parameters structure
|
---|
| 123 | */
|
---|
[d284ce9] | 124 | void ui_wnd_params_init(ui_wnd_params_t *params)
|
---|
[f7a90df] | 125 | {
|
---|
[d284ce9] | 126 | memset(params, 0, sizeof(ui_wnd_params_t));
|
---|
[266ec54] | 127 |
|
---|
| 128 | /* Make window decorated by default. */
|
---|
| 129 | params->style = ui_wds_decorated;
|
---|
[f7a90df] | 130 | }
|
---|
| 131 |
|
---|
[90f1f19] | 132 | /** Compute where window should be placed on the screen.
|
---|
| 133 | *
|
---|
[3c3657c] | 134 | * This only applies to windows that do not use default placement or
|
---|
| 135 | * if we are running in full-screen mode.
|
---|
[90f1f19] | 136 | *
|
---|
| 137 | * @param window Window
|
---|
[3c3657c] | 138 | * @param drect Display rectangle
|
---|
[90f1f19] | 139 | * @param params Window parameters
|
---|
| 140 | * @param pos Place to store position of top-left corner
|
---|
| 141 | */
|
---|
[3c3657c] | 142 | static void ui_window_place(ui_window_t *window, gfx_rect_t *drect,
|
---|
| 143 | ui_wnd_params_t *params, gfx_coord2_t *pos)
|
---|
[c9927c66] | 144 | {
|
---|
[3c3657c] | 145 | gfx_coord2_t dims;
|
---|
| 146 |
|
---|
| 147 | assert(params->placement != ui_wnd_place_default ||
|
---|
| 148 | ui_is_fullscreen(window->ui));
|
---|
[c9927c66] | 149 |
|
---|
[90f1f19] | 150 | pos->x = 0;
|
---|
| 151 | pos->y = 0;
|
---|
| 152 |
|
---|
[c9927c66] | 153 | switch (params->placement) {
|
---|
| 154 | case ui_wnd_place_default:
|
---|
[3c3657c] | 155 | assert(ui_is_fullscreen(window->ui));
|
---|
| 156 | /* Center window */
|
---|
| 157 | gfx_rect_dims(¶ms->rect, &dims);
|
---|
| 158 | pos->x = (drect->p0.x + drect->p1.x) / 2 - dims.x / 2;
|
---|
| 159 | pos->y = (drect->p0.y + drect->p1.y) / 2 - dims.y / 2;
|
---|
| 160 | break;
|
---|
[c9927c66] | 161 | case ui_wnd_place_top_left:
|
---|
| 162 | case ui_wnd_place_full_screen:
|
---|
[3c3657c] | 163 | pos->x = drect->p0.x - params->rect.p0.x;
|
---|
| 164 | pos->y = drect->p0.y - params->rect.p0.y;
|
---|
[c9927c66] | 165 | break;
|
---|
| 166 | case ui_wnd_place_top_right:
|
---|
[3c3657c] | 167 | pos->x = drect->p1.x - params->rect.p1.x;
|
---|
| 168 | pos->y = drect->p0.y - params->rect.p0.y;
|
---|
[c9927c66] | 169 | break;
|
---|
| 170 | case ui_wnd_place_bottom_left:
|
---|
[3c3657c] | 171 | pos->x = drect->p0.x - params->rect.p0.x;
|
---|
| 172 | pos->y = drect->p1.y - params->rect.p1.y;
|
---|
[c9927c66] | 173 | break;
|
---|
| 174 | case ui_wnd_place_bottom_right:
|
---|
[3c3657c] | 175 | pos->x = drect->p1.x - params->rect.p1.x;
|
---|
| 176 | pos->y = drect->p1.y - params->rect.p1.y;
|
---|
[c9927c66] | 177 | break;
|
---|
| 178 | case ui_wnd_place_popup:
|
---|
| 179 | /* Place popup window below parent rectangle */
|
---|
[90f1f19] | 180 | pos->x = params->prect.p0.x;
|
---|
| 181 | pos->y = params->prect.p1.y;
|
---|
[c9927c66] | 182 | break;
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 |
|
---|
[f7a90df] | 186 | /** Create new window.
|
---|
| 187 | *
|
---|
| 188 | * @param ui User interface
|
---|
| 189 | * @param params Window parameters
|
---|
| 190 | * @param rwindow Place to store pointer to new window
|
---|
| 191 | * @return EOK on success or an error code
|
---|
| 192 | */
|
---|
[d284ce9] | 193 | errno_t ui_window_create(ui_t *ui, ui_wnd_params_t *params,
|
---|
[f7a90df] | 194 | ui_window_t **rwindow)
|
---|
| 195 | {
|
---|
| 196 | ui_window_t *window;
|
---|
[06d0c81] | 197 | display_info_t info;
|
---|
[266ec54] | 198 | gfx_coord2_t scr_dims;
|
---|
[f7a90df] | 199 | display_wnd_params_t dparams;
|
---|
| 200 | gfx_context_t *gc = NULL;
|
---|
| 201 | ui_resource_t *res = NULL;
|
---|
| 202 | ui_wdecor_t *wdecor = NULL;
|
---|
| 203 | dummy_gc_t *dgc = NULL;
|
---|
[2ab8ab3] | 204 | gfx_bitmap_params_t bparams;
|
---|
| 205 | gfx_bitmap_alloc_t alloc;
|
---|
| 206 | gfx_bitmap_t *bmp = NULL;
|
---|
[8ce56a6] | 207 | gfx_coord2_t off;
|
---|
[2ab8ab3] | 208 | mem_gc_t *memgc = NULL;
|
---|
[8ce56a6] | 209 | xlate_gc_t *xgc = NULL;
|
---|
[f7a90df] | 210 | errno_t rc;
|
---|
| 211 |
|
---|
| 212 | window = calloc(1, sizeof(ui_window_t));
|
---|
| 213 | if (window == NULL)
|
---|
| 214 | return ENOMEM;
|
---|
| 215 |
|
---|
[3c3657c] | 216 | window->ui = ui;
|
---|
| 217 |
|
---|
[f7a90df] | 218 | display_wnd_params_init(&dparams);
|
---|
[d284ce9] | 219 | dparams.rect = params->rect;
|
---|
[2d879f7] | 220 | /* Only allow making the window larger */
|
---|
| 221 | gfx_rect_dims(¶ms->rect, &dparams.min_size);
|
---|
[f7a90df] | 222 |
|
---|
[9e84d2c] | 223 | if ((params->flags & ui_wndf_popup) != 0)
|
---|
| 224 | dparams.flags |= wndf_popup;
|
---|
| 225 |
|
---|
[f7a90df] | 226 | if (ui->display != NULL) {
|
---|
[266ec54] | 227 | if (params->placement != ui_wnd_place_default) {
|
---|
| 228 | rc = display_get_info(ui->display, &info);
|
---|
| 229 | if (rc != EOK)
|
---|
| 230 | goto error;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | if (params->placement == ui_wnd_place_full_screen) {
|
---|
| 234 | /* Make window the size of the screen */
|
---|
| 235 | gfx_rect_dims(&info.rect, &scr_dims);
|
---|
| 236 | gfx_coord2_add(&dparams.rect.p0, &scr_dims,
|
---|
| 237 | &dparams.rect.p1);
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[90f1f19] | 240 | if (params->placement != ui_wnd_place_default) {
|
---|
| 241 | /* Set initial display window position */
|
---|
[3c3657c] | 242 | ui_window_place(window, &info.rect, params,
|
---|
| 243 | &dparams.pos);
|
---|
[90f1f19] | 244 |
|
---|
| 245 | dparams.flags |= wndf_setpos;
|
---|
| 246 | }
|
---|
| 247 |
|
---|
[d284ce9] | 248 | rc = display_window_create(ui->display, &dparams, &dwnd_cb,
|
---|
[c9927c66] | 249 | (void *) window, &window->dwindow);
|
---|
[f7a90df] | 250 | if (rc != EOK)
|
---|
| 251 | goto error;
|
---|
| 252 |
|
---|
[c9927c66] | 253 | rc = display_window_get_gc(window->dwindow, &gc);
|
---|
[f7a90df] | 254 | if (rc != EOK)
|
---|
| 255 | goto error;
|
---|
[77ffa01] | 256 | } else if (ui->console != NULL) {
|
---|
[252d03c] | 257 | gc = console_gc_get_ctx(ui->cgc);
|
---|
[f7a90df] | 258 | } else {
|
---|
| 259 | /* Needed for unit tests */
|
---|
| 260 | rc = dummygc_create(&dgc);
|
---|
| 261 | if (rc != EOK)
|
---|
| 262 | goto error;
|
---|
| 263 |
|
---|
| 264 | gc = dummygc_get_ctx(dgc);
|
---|
| 265 | }
|
---|
| 266 |
|
---|
[2ab8ab3] | 267 | #ifdef CONFIG_UI_CS_RENDER
|
---|
| 268 | /* Create window bitmap */
|
---|
| 269 | gfx_bitmap_params_init(&bparams);
|
---|
| 270 | #ifndef CONFIG_WIN_DOUBLE_BUF
|
---|
[77ffa01] | 271 | /* Console does not support direct output */
|
---|
| 272 | if (ui->display != NULL)
|
---|
| 273 | bparams.flags |= bmpf_direct_output;
|
---|
[2ab8ab3] | 274 | #endif
|
---|
| 275 |
|
---|
| 276 | /* Move rectangle so that top-left corner is 0,0 */
|
---|
| 277 | gfx_rect_rtranslate(¶ms->rect.p0, ¶ms->rect, &bparams.rect);
|
---|
| 278 |
|
---|
| 279 | rc = gfx_bitmap_create(gc, &bparams, NULL, &bmp);
|
---|
| 280 | if (rc != EOK)
|
---|
| 281 | goto error;
|
---|
| 282 |
|
---|
| 283 | /* Create memory GC */
|
---|
| 284 | rc = gfx_bitmap_get_alloc(bmp, &alloc);
|
---|
| 285 | if (rc != EOK) {
|
---|
| 286 | gfx_bitmap_destroy(window->app_bmp);
|
---|
| 287 | return rc;
|
---|
| 288 | }
|
---|
| 289 |
|
---|
[1215db9] | 290 | rc = mem_gc_create(&bparams.rect, &alloc, &ui_window_mem_gc_cb,
|
---|
| 291 | (void *) window, &memgc);
|
---|
[2ab8ab3] | 292 | if (rc != EOK) {
|
---|
| 293 | gfx_bitmap_destroy(window->app_bmp);
|
---|
| 294 | return rc;
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | window->bmp = bmp;
|
---|
| 298 | window->mgc = memgc;
|
---|
| 299 | window->gc = mem_gc_get_ctx(memgc);
|
---|
| 300 | window->realgc = gc;
|
---|
[8ce56a6] | 301 | (void) off;
|
---|
[2ab8ab3] | 302 | #else
|
---|
[8ce56a6] | 303 | /* Server-side rendering */
|
---|
| 304 |
|
---|
| 305 | /* Full-screen mode? */
|
---|
| 306 | if (ui->display == NULL) {
|
---|
| 307 | /* Create translating GC to translate window contents */
|
---|
| 308 | off.x = 0;
|
---|
| 309 | off.y = 0;
|
---|
| 310 | rc = xlate_gc_create(&off, gc, &xgc);
|
---|
| 311 | if (rc != EOK)
|
---|
| 312 | goto error;
|
---|
| 313 |
|
---|
| 314 | window->xgc = xgc;
|
---|
| 315 | window->gc = xlate_gc_get_ctx(xgc);
|
---|
| 316 | window->realgc = gc;
|
---|
| 317 | } else {
|
---|
| 318 | window->gc = gc;
|
---|
| 319 | }
|
---|
| 320 |
|
---|
[1215db9] | 321 | (void) ui_window_mem_gc_cb;
|
---|
[2ab8ab3] | 322 | (void) alloc;
|
---|
| 323 | (void) bparams;
|
---|
| 324 | #endif
|
---|
[8ce56a6] | 325 | if (ui->display == NULL) {
|
---|
[3c3657c] | 326 | ui_window_place(window, &ui->rect, params, &window->dpos);
|
---|
[8ce56a6] | 327 | FILE *f = fopen("/tmp/x", "at");
|
---|
| 328 | fprintf(f, "xlate_gc_set_off: %d,%d\n",
|
---|
| 329 | window->dpos.x, window->dpos.y);
|
---|
| 330 | fclose(f);
|
---|
| 331 |
|
---|
| 332 | if (window->xgc != NULL)
|
---|
| 333 | xlate_gc_set_off(window->xgc, &window->dpos);
|
---|
| 334 | }
|
---|
[d6c4d40] | 335 |
|
---|
[9c7dc8e] | 336 | rc = ui_resource_create(window->gc, ui_is_textmode(ui), &res);
|
---|
[f7a90df] | 337 | if (rc != EOK)
|
---|
| 338 | goto error;
|
---|
| 339 |
|
---|
[2d879f7] | 340 | rc = ui_wdecor_create(res, params->caption, params->style, &wdecor);
|
---|
[f7a90df] | 341 | if (rc != EOK)
|
---|
| 342 | goto error;
|
---|
| 343 |
|
---|
[266ec54] | 344 | ui_wdecor_set_rect(wdecor, &dparams.rect);
|
---|
[d284ce9] | 345 | ui_wdecor_set_cb(wdecor, &wdecor_cb, (void *) window);
|
---|
| 346 | ui_wdecor_paint(wdecor);
|
---|
| 347 |
|
---|
[214aefb] | 348 | ui_resource_set_expose_cb(res, ui_window_expose_cb, (void *) window);
|
---|
| 349 |
|
---|
[266ec54] | 350 | window->rect = dparams.rect;
|
---|
[f7a90df] | 351 | window->res = res;
|
---|
| 352 | window->wdecor = wdecor;
|
---|
[2d879f7] | 353 | window->cursor = ui_curs_arrow;
|
---|
[f7a90df] | 354 | *rwindow = window;
|
---|
[77ffa01] | 355 |
|
---|
[252d03c] | 356 | list_append(&window->lwindows, &ui->windows);
|
---|
[f7a90df] | 357 | return EOK;
|
---|
| 358 | error:
|
---|
| 359 | if (wdecor != NULL)
|
---|
| 360 | ui_wdecor_destroy(wdecor);
|
---|
| 361 | if (res != NULL)
|
---|
| 362 | ui_resource_destroy(res);
|
---|
[2ab8ab3] | 363 | if (memgc != NULL)
|
---|
| 364 | mem_gc_delete(memgc);
|
---|
[8ce56a6] | 365 | if (xgc != NULL)
|
---|
| 366 | xlate_gc_delete(xgc);
|
---|
[2ab8ab3] | 367 | if (bmp != NULL)
|
---|
| 368 | gfx_bitmap_destroy(bmp);
|
---|
[f7a90df] | 369 | if (dgc != NULL)
|
---|
| 370 | dummygc_destroy(dgc);
|
---|
| 371 | free(window);
|
---|
| 372 | return rc;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | /** Destroy window.
|
---|
| 376 | *
|
---|
| 377 | * @param window Window or @c NULL
|
---|
| 378 | */
|
---|
| 379 | void ui_window_destroy(ui_window_t *window)
|
---|
| 380 | {
|
---|
[252d03c] | 381 | ui_t *ui;
|
---|
| 382 |
|
---|
[f7a90df] | 383 | if (window == NULL)
|
---|
| 384 | return;
|
---|
| 385 |
|
---|
[252d03c] | 386 | ui = window->ui;
|
---|
| 387 |
|
---|
| 388 | list_remove(&window->lwindows);
|
---|
[b71c0fc] | 389 | ui_control_destroy(window->control);
|
---|
[f7a90df] | 390 | ui_wdecor_destroy(window->wdecor);
|
---|
| 391 | ui_resource_destroy(window->res);
|
---|
[2ab8ab3] | 392 | if (0 && window->app_mgc != NULL)
|
---|
| 393 | mem_gc_delete(window->app_mgc);
|
---|
| 394 | if (0 && window->app_bmp != NULL)
|
---|
| 395 | gfx_bitmap_destroy(window->app_bmp);
|
---|
| 396 | if (window->mgc != NULL) {
|
---|
| 397 | mem_gc_delete(window->mgc);
|
---|
| 398 | window->gc = NULL;
|
---|
| 399 | }
|
---|
| 400 | if (window->bmp != NULL)
|
---|
| 401 | gfx_bitmap_destroy(window->bmp);
|
---|
[77ffa01] | 402 | if (window->dwindow != NULL)
|
---|
| 403 | display_window_destroy(window->dwindow);
|
---|
[252d03c] | 404 |
|
---|
[f7a90df] | 405 | free(window);
|
---|
[252d03c] | 406 |
|
---|
| 407 | /* Need to repaint if windows are emulated */
|
---|
| 408 | if (ui_is_fullscreen(ui)) {
|
---|
| 409 | ui_paint(ui);
|
---|
| 410 | }
|
---|
[f7a90df] | 411 | }
|
---|
| 412 |
|
---|
[b71c0fc] | 413 | /** Add control to window.
|
---|
| 414 | *
|
---|
| 415 | * Only one control can be added to a window. If more than one control
|
---|
| 416 | * is added, the results are undefined.
|
---|
| 417 | *
|
---|
[3c8c580] | 418 | * @param window Window
|
---|
[b71c0fc] | 419 | * @param control Control
|
---|
| 420 | * @return EOK on success, ENOMEM if out of memory
|
---|
| 421 | */
|
---|
| 422 | void ui_window_add(ui_window_t *window, ui_control_t *control)
|
---|
| 423 | {
|
---|
| 424 | assert(window->control == NULL);
|
---|
| 425 |
|
---|
| 426 | window->control = control;
|
---|
| 427 | control->elemp = (void *) window;
|
---|
| 428 | }
|
---|
| 429 |
|
---|
| 430 | /** Remove control from window.
|
---|
| 431 | *
|
---|
| 432 | * @param window Window
|
---|
| 433 | * @param control Control
|
---|
| 434 | */
|
---|
| 435 | void ui_window_remove(ui_window_t *window, ui_control_t *control)
|
---|
| 436 | {
|
---|
| 437 | assert(window->control == control);
|
---|
| 438 | assert((ui_window_t *) control->elemp == window);
|
---|
| 439 |
|
---|
| 440 | window->control = NULL;
|
---|
| 441 | control->elemp = NULL;
|
---|
| 442 | }
|
---|
| 443 |
|
---|
[252d03c] | 444 | /** Get active window (only valid in fullscreen mode).
|
---|
| 445 | *
|
---|
| 446 | * @param ui User interface
|
---|
| 447 | * @return Active window
|
---|
| 448 | */
|
---|
| 449 | ui_window_t *ui_window_get_active(ui_t *ui)
|
---|
| 450 | {
|
---|
| 451 | link_t *link;
|
---|
| 452 |
|
---|
| 453 | link = list_last(&ui->windows);
|
---|
| 454 | if (link == NULL)
|
---|
| 455 | return NULL;
|
---|
| 456 |
|
---|
| 457 | return list_get_instance(link, ui_window_t, lwindows);
|
---|
| 458 | }
|
---|
| 459 |
|
---|
[0576df9] | 460 | /** Resize/move window.
|
---|
| 461 | *
|
---|
| 462 | * Resize window to the dimensions of @a rect. If @a rect.p0 is not 0,0,
|
---|
| 463 | * the top-left corner of the window will move on the screen accordingly.
|
---|
| 464 | *
|
---|
| 465 | * @param window Window
|
---|
| 466 | * @param rect Rectangle
|
---|
| 467 | *
|
---|
| 468 | * @return EOK on success or an error code
|
---|
| 469 | */
|
---|
| 470 | errno_t ui_window_resize(ui_window_t *window, gfx_rect_t *rect)
|
---|
| 471 | {
|
---|
| 472 | gfx_coord2_t offs;
|
---|
| 473 | gfx_rect_t nrect;
|
---|
[25f26600] | 474 | gfx_rect_t arect;
|
---|
| 475 | gfx_bitmap_t *app_bmp = NULL;
|
---|
[2ab8ab3] | 476 | gfx_bitmap_t *win_bmp = NULL;
|
---|
| 477 | gfx_bitmap_params_t app_params;
|
---|
| 478 | gfx_bitmap_params_t win_params;
|
---|
| 479 | gfx_bitmap_alloc_t app_alloc;
|
---|
| 480 | gfx_bitmap_alloc_t win_alloc;
|
---|
[0576df9] | 481 | errno_t rc;
|
---|
| 482 |
|
---|
| 483 | /*
|
---|
| 484 | * Move rect so that p0=0,0 - keep window's coordinate system origin
|
---|
| 485 | * locked to top-left corner of the window.
|
---|
| 486 | */
|
---|
| 487 | offs = rect->p0;
|
---|
| 488 | gfx_rect_rtranslate(&offs, rect, &nrect);
|
---|
| 489 |
|
---|
[2ab8ab3] | 490 | /* mgc != NULL iff client-side rendering */
|
---|
| 491 | if (window->mgc != NULL) {
|
---|
[a85d5c6] | 492 | #ifdef CONFIG_WIN_DOUBLE_BUF
|
---|
| 493 | /*
|
---|
| 494 | * Create new window bitmap in advance. If direct mapping,
|
---|
| 495 | * will need do it after resizing the window.
|
---|
| 496 | */
|
---|
[2ab8ab3] | 497 | assert(window->bmp != NULL);
|
---|
| 498 | gfx_bitmap_params_init(&win_params);
|
---|
| 499 | win_params.rect = nrect;
|
---|
| 500 |
|
---|
| 501 | rc = gfx_bitmap_create(window->realgc, &win_params, NULL,
|
---|
| 502 | &win_bmp);
|
---|
| 503 | if (rc != EOK)
|
---|
| 504 | goto error;
|
---|
| 505 |
|
---|
| 506 | rc = gfx_bitmap_get_alloc(win_bmp, &win_alloc);
|
---|
| 507 | if (rc != EOK)
|
---|
| 508 | goto error;
|
---|
[a85d5c6] | 509 | #endif
|
---|
[2ab8ab3] | 510 | }
|
---|
| 511 |
|
---|
| 512 | /* Application area GC? */
|
---|
[25f26600] | 513 | if (window->app_gc != NULL) {
|
---|
[2ab8ab3] | 514 | /* Resize application bitmap */
|
---|
[25f26600] | 515 | assert(window->app_bmp != NULL);
|
---|
| 516 |
|
---|
[2ab8ab3] | 517 | gfx_bitmap_params_init(&app_params);
|
---|
[25f26600] | 518 |
|
---|
| 519 | /*
|
---|
| 520 | * The bitmap will have the same dimensions as the
|
---|
| 521 | * application rectangle, but start at 0,0.
|
---|
| 522 | */
|
---|
| 523 | ui_wdecor_app_from_rect(window->wdecor->style, &nrect, &arect);
|
---|
[2ab8ab3] | 524 | gfx_rect_rtranslate(&arect.p0, &arect, &app_params.rect);
|
---|
[25f26600] | 525 |
|
---|
[2ab8ab3] | 526 | rc = gfx_bitmap_create(window->gc, &app_params, NULL,
|
---|
[25f26600] | 527 | &app_bmp);
|
---|
| 528 | if (rc != EOK)
|
---|
| 529 | goto error;
|
---|
| 530 |
|
---|
[2ab8ab3] | 531 | rc = gfx_bitmap_get_alloc(app_bmp, &app_alloc);
|
---|
[25f26600] | 532 | if (rc != EOK)
|
---|
| 533 | goto error;
|
---|
| 534 | }
|
---|
| 535 |
|
---|
[0576df9] | 536 | /* dwindow can be NULL in case of unit tests */
|
---|
| 537 | if (window->dwindow != NULL) {
|
---|
| 538 | rc = display_window_resize(window->dwindow, &offs, &nrect);
|
---|
| 539 | if (rc != EOK)
|
---|
[25f26600] | 540 | goto error;
|
---|
[0576df9] | 541 | }
|
---|
| 542 |
|
---|
[a85d5c6] | 543 | /* Client side rendering? */
|
---|
[2ab8ab3] | 544 | if (window->mgc != NULL) {
|
---|
[a85d5c6] | 545 | #ifndef CONFIG_WIN_DOUBLE_BUF
|
---|
| 546 | /* Window is resized, now we can map the window bitmap again */
|
---|
| 547 | gfx_bitmap_params_init(&win_params);
|
---|
| 548 | win_params.flags |= bmpf_direct_output;
|
---|
| 549 | win_params.rect = nrect;
|
---|
| 550 |
|
---|
| 551 | rc = gfx_bitmap_create(window->realgc, &win_params, NULL,
|
---|
| 552 | &win_bmp);
|
---|
| 553 | if (rc != EOK)
|
---|
| 554 | goto error;
|
---|
| 555 |
|
---|
| 556 | rc = gfx_bitmap_get_alloc(win_bmp, &win_alloc);
|
---|
| 557 | if (rc != EOK)
|
---|
| 558 | goto error;
|
---|
| 559 | #endif
|
---|
| 560 |
|
---|
[2ab8ab3] | 561 | mem_gc_retarget(window->mgc, &win_params.rect, &win_alloc);
|
---|
| 562 |
|
---|
| 563 | gfx_bitmap_destroy(window->bmp);
|
---|
| 564 | window->bmp = win_bmp;
|
---|
| 565 | }
|
---|
| 566 |
|
---|
[0576df9] | 567 | ui_wdecor_set_rect(window->wdecor, &nrect);
|
---|
| 568 | ui_wdecor_paint(window->wdecor);
|
---|
[2ab8ab3] | 569 | gfx_update(window->gc);
|
---|
[25f26600] | 570 |
|
---|
[2ab8ab3] | 571 | /* Application area GC? */
|
---|
[25f26600] | 572 | if (window->app_gc != NULL) {
|
---|
[2ab8ab3] | 573 | mem_gc_retarget(window->app_mgc, &app_params.rect, &app_alloc);
|
---|
[25f26600] | 574 |
|
---|
| 575 | gfx_bitmap_destroy(window->app_bmp);
|
---|
| 576 | window->app_bmp = app_bmp;
|
---|
| 577 | }
|
---|
| 578 |
|
---|
[0576df9] | 579 | return EOK;
|
---|
[25f26600] | 580 | error:
|
---|
| 581 | if (app_bmp != NULL)
|
---|
| 582 | gfx_bitmap_destroy(app_bmp);
|
---|
[2ab8ab3] | 583 | if (win_bmp != NULL)
|
---|
| 584 | gfx_bitmap_destroy(win_bmp);
|
---|
[25f26600] | 585 | return rc;
|
---|
[0576df9] | 586 | }
|
---|
| 587 |
|
---|
[d284ce9] | 588 | /** Set window callbacks.
|
---|
| 589 | *
|
---|
| 590 | * @param window Window
|
---|
[3c8c580] | 591 | * @param cb Window callbacks
|
---|
[d284ce9] | 592 | * @param arg Callback argument
|
---|
| 593 | */
|
---|
| 594 | void ui_window_set_cb(ui_window_t *window, ui_window_cb_t *cb, void *arg)
|
---|
| 595 | {
|
---|
| 596 | window->cb = cb;
|
---|
| 597 | window->arg = arg;
|
---|
| 598 | }
|
---|
| 599 |
|
---|
[66a2becf] | 600 | /** Get UI resource from window.
|
---|
| 601 | *
|
---|
| 602 | * @param window Window
|
---|
| 603 | * @return UI resource
|
---|
| 604 | */
|
---|
[3583ffb] | 605 | ui_resource_t *ui_window_get_res(ui_window_t *window)
|
---|
| 606 | {
|
---|
| 607 | return window->res;
|
---|
| 608 | }
|
---|
| 609 |
|
---|
[66a2becf] | 610 | /** Get window GC.
|
---|
| 611 | *
|
---|
| 612 | * @param window Window
|
---|
| 613 | * @return GC (relative to window)
|
---|
| 614 | */
|
---|
[d284ce9] | 615 | gfx_context_t *ui_window_get_gc(ui_window_t *window)
|
---|
| 616 | {
|
---|
| 617 | return window->gc;
|
---|
| 618 | }
|
---|
| 619 |
|
---|
[c9927c66] | 620 | /** Get window position.
|
---|
| 621 | *
|
---|
| 622 | * @param window Window
|
---|
| 623 | * @param pos Place to store position
|
---|
| 624 | * @return EOK on success or an error code
|
---|
| 625 | */
|
---|
| 626 | errno_t ui_window_get_pos(ui_window_t *window, gfx_coord2_t *pos)
|
---|
| 627 | {
|
---|
| 628 | errno_t rc;
|
---|
| 629 |
|
---|
| 630 | if (window->dwindow != NULL) {
|
---|
| 631 | rc = display_window_get_pos(window->dwindow, pos);
|
---|
| 632 | if (rc != EOK)
|
---|
| 633 | return rc;
|
---|
| 634 | } else {
|
---|
[3c3657c] | 635 | *pos = window->dpos;
|
---|
[c9927c66] | 636 | }
|
---|
| 637 |
|
---|
| 638 | return EOK;
|
---|
| 639 | }
|
---|
| 640 |
|
---|
[66a2becf] | 641 | /** Get window application area GC
|
---|
| 642 | *
|
---|
| 643 | * @param window Window
|
---|
| 644 | * @param rgc Place to store GC (relative to application area)
|
---|
| 645 | * @return EOK on success or an error code
|
---|
| 646 | */
|
---|
| 647 | errno_t ui_window_get_app_gc(ui_window_t *window, gfx_context_t **rgc)
|
---|
| 648 | {
|
---|
| 649 | gfx_bitmap_params_t params;
|
---|
| 650 | gfx_bitmap_alloc_t alloc;
|
---|
| 651 | gfx_rect_t rect;
|
---|
| 652 | mem_gc_t *memgc;
|
---|
| 653 | errno_t rc;
|
---|
| 654 |
|
---|
| 655 | if (window->app_gc == NULL) {
|
---|
| 656 | assert(window->app_bmp == NULL);
|
---|
| 657 |
|
---|
| 658 | gfx_bitmap_params_init(¶ms);
|
---|
| 659 |
|
---|
| 660 | /*
|
---|
| 661 | * The bitmap will have the same dimensions as the
|
---|
| 662 | * application rectangle, but start at 0,0.
|
---|
| 663 | */
|
---|
| 664 | ui_window_get_app_rect(window, &rect);
|
---|
| 665 | gfx_rect_rtranslate(&rect.p0, &rect, ¶ms.rect);
|
---|
| 666 |
|
---|
| 667 | rc = gfx_bitmap_create(window->gc, ¶ms, NULL,
|
---|
| 668 | &window->app_bmp);
|
---|
| 669 | if (rc != EOK)
|
---|
| 670 | return rc;
|
---|
| 671 |
|
---|
| 672 | rc = gfx_bitmap_get_alloc(window->app_bmp, &alloc);
|
---|
| 673 | if (rc != EOK) {
|
---|
| 674 | gfx_bitmap_destroy(window->app_bmp);
|
---|
| 675 | return rc;
|
---|
| 676 | }
|
---|
| 677 |
|
---|
[1215db9] | 678 | rc = mem_gc_create(¶ms.rect, &alloc,
|
---|
| 679 | &ui_window_app_mem_gc_cb, (void *) window, &memgc);
|
---|
[66a2becf] | 680 | if (rc != EOK) {
|
---|
| 681 | gfx_bitmap_destroy(window->app_bmp);
|
---|
| 682 | return rc;
|
---|
| 683 | }
|
---|
| 684 |
|
---|
[25f26600] | 685 | window->app_mgc = memgc;
|
---|
[66a2becf] | 686 | window->app_gc = mem_gc_get_ctx(memgc);
|
---|
| 687 | }
|
---|
| 688 |
|
---|
| 689 | *rgc = window->app_gc;
|
---|
| 690 | return EOK;
|
---|
| 691 | }
|
---|
| 692 |
|
---|
| 693 | /** Get window application rectangle
|
---|
| 694 | *
|
---|
| 695 | * @param window Window
|
---|
| 696 | * @param rect Place to store application rectangle
|
---|
| 697 | */
|
---|
[d284ce9] | 698 | void ui_window_get_app_rect(ui_window_t *window, gfx_rect_t *rect)
|
---|
| 699 | {
|
---|
| 700 | ui_wdecor_geom_t geom;
|
---|
| 701 |
|
---|
| 702 | ui_wdecor_get_geom(window->wdecor, &geom);
|
---|
| 703 | *rect = geom.app_area_rect;
|
---|
| 704 | }
|
---|
| 705 |
|
---|
[db3895d] | 706 | /** Set cursor when pointer is hovering over a control.
|
---|
| 707 | *
|
---|
| 708 | * @param window Window
|
---|
| 709 | * @param cursor Cursor
|
---|
| 710 | */
|
---|
| 711 | void ui_window_set_ctl_cursor(ui_window_t *window, ui_stock_cursor_t cursor)
|
---|
| 712 | {
|
---|
| 713 | display_stock_cursor_t dcursor;
|
---|
| 714 |
|
---|
| 715 | dcursor = wnd_dcursor_from_cursor(cursor);
|
---|
| 716 |
|
---|
| 717 | if (window->dwindow != NULL)
|
---|
| 718 | (void) display_window_set_cursor(window->dwindow, dcursor);
|
---|
| 719 | }
|
---|
| 720 |
|
---|
[66a2becf] | 721 | /** Paint window
|
---|
| 722 | *
|
---|
| 723 | * @param window Window
|
---|
| 724 | * @return EOK on success or an error code
|
---|
| 725 | */
|
---|
[fa01c05] | 726 | errno_t ui_window_paint(ui_window_t *window)
|
---|
| 727 | {
|
---|
| 728 | return ui_window_send_paint(window);
|
---|
| 729 | }
|
---|
| 730 |
|
---|
[d284ce9] | 731 | /** Handle window close event. */
|
---|
| 732 | static void dwnd_close_event(void *arg)
|
---|
| 733 | {
|
---|
| 734 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 735 |
|
---|
[fa01c05] | 736 | ui_window_send_close(window);
|
---|
[d284ce9] | 737 | }
|
---|
| 738 |
|
---|
| 739 | /** Handle window focus event. */
|
---|
| 740 | static void dwnd_focus_event(void *arg)
|
---|
| 741 | {
|
---|
| 742 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 743 |
|
---|
| 744 | if (window->wdecor != NULL) {
|
---|
| 745 | ui_wdecor_set_active(window->wdecor, true);
|
---|
| 746 | ui_wdecor_paint(window->wdecor);
|
---|
| 747 | }
|
---|
[f03d1308] | 748 |
|
---|
[fa01c05] | 749 | ui_window_send_focus(window);
|
---|
[d284ce9] | 750 | }
|
---|
| 751 |
|
---|
| 752 | /** Handle window keyboard event */
|
---|
| 753 | static void dwnd_kbd_event(void *arg, kbd_event_t *kbd_event)
|
---|
| 754 | {
|
---|
| 755 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 756 |
|
---|
| 757 | (void) window;
|
---|
[fa01c05] | 758 | ui_window_send_kbd(window, kbd_event);
|
---|
[d284ce9] | 759 | }
|
---|
| 760 |
|
---|
| 761 | /** Handle window position event */
|
---|
| 762 | static void dwnd_pos_event(void *arg, pos_event_t *event)
|
---|
| 763 | {
|
---|
| 764 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 765 |
|
---|
| 766 | /* Make sure we don't process events until fully initialized */
|
---|
| 767 | if (window->wdecor == NULL)
|
---|
| 768 | return;
|
---|
| 769 |
|
---|
| 770 | ui_wdecor_pos_event(window->wdecor, event);
|
---|
[fa01c05] | 771 | ui_window_send_pos(window, event);
|
---|
[d284ce9] | 772 | }
|
---|
| 773 |
|
---|
[2d879f7] | 774 | /** Handle window resize event */
|
---|
| 775 | static void dwnd_resize_event(void *arg, gfx_rect_t *rect)
|
---|
| 776 | {
|
---|
| 777 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 778 |
|
---|
| 779 | /* Make sure we don't process events until fully initialized */
|
---|
| 780 | if (window->wdecor == NULL)
|
---|
| 781 | return;
|
---|
| 782 |
|
---|
| 783 | if ((window->wdecor->style & ui_wds_resizable) == 0)
|
---|
| 784 | return;
|
---|
| 785 |
|
---|
| 786 | (void) ui_window_resize(window, rect);
|
---|
| 787 | (void) ui_window_paint(window);
|
---|
| 788 | }
|
---|
| 789 |
|
---|
[d284ce9] | 790 | /** Handle window unfocus event. */
|
---|
| 791 | static void dwnd_unfocus_event(void *arg)
|
---|
| 792 | {
|
---|
| 793 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 794 |
|
---|
| 795 | if (window->wdecor != NULL) {
|
---|
| 796 | ui_wdecor_set_active(window->wdecor, false);
|
---|
| 797 | ui_wdecor_paint(window->wdecor);
|
---|
| 798 | }
|
---|
[f03d1308] | 799 |
|
---|
[fa01c05] | 800 | ui_window_send_unfocus(window);
|
---|
[d284ce9] | 801 | }
|
---|
| 802 |
|
---|
| 803 | /** Window decoration requested window closure.
|
---|
| 804 | *
|
---|
| 805 | * @param wdecor Window decoration
|
---|
[2d879f7] | 806 | * @param arg Argument (window)
|
---|
[d284ce9] | 807 | */
|
---|
| 808 | static void wd_close(ui_wdecor_t *wdecor, void *arg)
|
---|
| 809 | {
|
---|
| 810 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 811 |
|
---|
[fa01c05] | 812 | ui_window_send_close(window);
|
---|
[d284ce9] | 813 | }
|
---|
| 814 |
|
---|
| 815 | /** Window decoration requested window move.
|
---|
| 816 | *
|
---|
| 817 | * @param wdecor Window decoration
|
---|
[2d879f7] | 818 | * @param arg Argument (window)
|
---|
[d284ce9] | 819 | * @param pos Position where the title bar was pressed
|
---|
| 820 | */
|
---|
| 821 | static void wd_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos)
|
---|
| 822 | {
|
---|
| 823 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 824 |
|
---|
[77ffa01] | 825 | if (window->dwindow != NULL)
|
---|
| 826 | (void) display_window_move_req(window->dwindow, pos);
|
---|
[d284ce9] | 827 | }
|
---|
| 828 |
|
---|
[2d879f7] | 829 | /** Window decoration requested window resize.
|
---|
| 830 | *
|
---|
| 831 | * @param wdecor Window decoration
|
---|
| 832 | * @param arg Argument (window)
|
---|
| 833 | * @param rsztype Resize type
|
---|
| 834 | * @param pos Position where the button was pressed
|
---|
| 835 | */
|
---|
| 836 | static void wd_resize(ui_wdecor_t *wdecor, void *arg,
|
---|
| 837 | ui_wdecor_rsztype_t rsztype, gfx_coord2_t *pos)
|
---|
| 838 | {
|
---|
| 839 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 840 |
|
---|
[77ffa01] | 841 | if (window->dwindow != NULL)
|
---|
| 842 | (void) display_window_resize_req(window->dwindow, rsztype, pos);
|
---|
[2d879f7] | 843 | }
|
---|
| 844 |
|
---|
[db3895d] | 845 | /** Get display stock cursor from UI stock cursor.
|
---|
[2d879f7] | 846 | *
|
---|
[db3895d] | 847 | * @param cursor UI stock cursor
|
---|
| 848 | * @return Display stock cursor
|
---|
[2d879f7] | 849 | */
|
---|
[db3895d] | 850 | display_stock_cursor_t wnd_dcursor_from_cursor(ui_stock_cursor_t cursor)
|
---|
[2d879f7] | 851 | {
|
---|
| 852 | display_stock_cursor_t dcursor;
|
---|
| 853 |
|
---|
| 854 | dcursor = dcurs_arrow;
|
---|
| 855 |
|
---|
| 856 | switch (cursor) {
|
---|
| 857 | case ui_curs_arrow:
|
---|
| 858 | dcursor = dcurs_arrow;
|
---|
| 859 | break;
|
---|
| 860 | case ui_curs_size_ud:
|
---|
| 861 | dcursor = dcurs_size_ud;
|
---|
| 862 | break;
|
---|
| 863 | case ui_curs_size_lr:
|
---|
| 864 | dcursor = dcurs_size_lr;
|
---|
| 865 | break;
|
---|
| 866 | case ui_curs_size_uldr:
|
---|
| 867 | dcursor = dcurs_size_uldr;
|
---|
| 868 | break;
|
---|
| 869 | case ui_curs_size_urdl:
|
---|
| 870 | dcursor = dcurs_size_urdl;
|
---|
| 871 | break;
|
---|
[db3895d] | 872 | case ui_curs_ibeam:
|
---|
| 873 | dcursor = dcurs_ibeam;
|
---|
| 874 | break;
|
---|
[2d879f7] | 875 | }
|
---|
| 876 |
|
---|
[db3895d] | 877 | return dcursor;
|
---|
| 878 | }
|
---|
| 879 |
|
---|
| 880 | /** Window decoration requested changing cursor.
|
---|
| 881 | *
|
---|
| 882 | * @param wdecor Window decoration
|
---|
| 883 | * @param arg Argument (window)
|
---|
| 884 | * @param cursor Cursor to set
|
---|
| 885 | */
|
---|
| 886 | static void wd_set_cursor(ui_wdecor_t *wdecor, void *arg,
|
---|
| 887 | ui_stock_cursor_t cursor)
|
---|
| 888 | {
|
---|
| 889 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 890 | display_stock_cursor_t dcursor;
|
---|
| 891 |
|
---|
| 892 | if (cursor == window->cursor)
|
---|
| 893 | return;
|
---|
| 894 |
|
---|
| 895 | dcursor = wnd_dcursor_from_cursor(cursor);
|
---|
| 896 |
|
---|
[77ffa01] | 897 | if (window->dwindow != NULL)
|
---|
| 898 | (void) display_window_set_cursor(window->dwindow, dcursor);
|
---|
[db3895d] | 899 |
|
---|
[2d879f7] | 900 | window->cursor = cursor;
|
---|
| 901 | }
|
---|
| 902 |
|
---|
[d284ce9] | 903 | /** Send window close event.
|
---|
| 904 | *
|
---|
| 905 | * @param window Window
|
---|
| 906 | */
|
---|
[fa01c05] | 907 | void ui_window_send_close(ui_window_t *window)
|
---|
[d284ce9] | 908 | {
|
---|
| 909 | if (window->cb != NULL && window->cb->close != NULL)
|
---|
| 910 | window->cb->close(window, window->arg);
|
---|
| 911 | }
|
---|
| 912 |
|
---|
[f03d1308] | 913 | /** Send window focus event.
|
---|
| 914 | *
|
---|
| 915 | * @param window Window
|
---|
| 916 | */
|
---|
[fa01c05] | 917 | void ui_window_send_focus(ui_window_t *window)
|
---|
[f03d1308] | 918 | {
|
---|
| 919 | if (window->cb != NULL && window->cb->focus != NULL)
|
---|
| 920 | window->cb->focus(window, window->arg);
|
---|
| 921 | }
|
---|
| 922 |
|
---|
| 923 | /** Send window keyboard event.
|
---|
| 924 | *
|
---|
| 925 | * @param window Window
|
---|
| 926 | */
|
---|
[fa01c05] | 927 | void ui_window_send_kbd(ui_window_t *window, kbd_event_t *kbd)
|
---|
[f03d1308] | 928 | {
|
---|
| 929 | if (window->cb != NULL && window->cb->kbd != NULL)
|
---|
| 930 | window->cb->kbd(window, window->arg, kbd);
|
---|
[7481ee19] | 931 | else
|
---|
| 932 | return ui_window_def_kbd(window, kbd);
|
---|
[f03d1308] | 933 | }
|
---|
| 934 |
|
---|
[fa01c05] | 935 | /** Send window paint event.
|
---|
| 936 | *
|
---|
| 937 | * @param window Window
|
---|
| 938 | */
|
---|
| 939 | errno_t ui_window_send_paint(ui_window_t *window)
|
---|
| 940 | {
|
---|
| 941 | if (window->cb != NULL && window->cb->paint != NULL)
|
---|
| 942 | return window->cb->paint(window, window->arg);
|
---|
| 943 | else
|
---|
| 944 | return ui_window_def_paint(window);
|
---|
| 945 | }
|
---|
| 946 |
|
---|
[d284ce9] | 947 | /** Send window position event.
|
---|
| 948 | *
|
---|
| 949 | * @param window Window
|
---|
| 950 | */
|
---|
[fa01c05] | 951 | void ui_window_send_pos(ui_window_t *window, pos_event_t *pos)
|
---|
[d284ce9] | 952 | {
|
---|
| 953 | if (window->cb != NULL && window->cb->pos != NULL)
|
---|
| 954 | window->cb->pos(window, window->arg, pos);
|
---|
[b71c0fc] | 955 | else
|
---|
| 956 | ui_window_def_pos(window, pos);
|
---|
[d284ce9] | 957 | }
|
---|
| 958 |
|
---|
[f03d1308] | 959 | /** Send window unfocus event.
|
---|
| 960 | *
|
---|
| 961 | * @param window Window
|
---|
| 962 | */
|
---|
[fa01c05] | 963 | void ui_window_send_unfocus(ui_window_t *window)
|
---|
[f03d1308] | 964 | {
|
---|
| 965 | if (window->cb != NULL && window->cb->unfocus != NULL)
|
---|
| 966 | window->cb->unfocus(window, window->arg);
|
---|
[62223ec] | 967 | else
|
---|
| 968 | return ui_window_def_unfocus(window);
|
---|
[f03d1308] | 969 | }
|
---|
| 970 |
|
---|
[7481ee19] | 971 | /** Default window keyboard event routine.
|
---|
| 972 | *
|
---|
| 973 | * @param window Window
|
---|
| 974 | */
|
---|
| 975 | void ui_window_def_kbd(ui_window_t *window, kbd_event_t *kbd)
|
---|
| 976 | {
|
---|
| 977 | if (window->control != NULL)
|
---|
| 978 | ui_control_kbd_event(window->control, kbd);
|
---|
| 979 | }
|
---|
| 980 |
|
---|
[fa01c05] | 981 | /** Default window paint routine.
|
---|
| 982 | *
|
---|
| 983 | * @param window Window
|
---|
| 984 | * @return EOK on success or an error code
|
---|
| 985 | */
|
---|
| 986 | errno_t ui_window_def_paint(ui_window_t *window)
|
---|
| 987 | {
|
---|
| 988 | gfx_rect_t app_rect;
|
---|
| 989 | errno_t rc;
|
---|
| 990 |
|
---|
| 991 | rc = gfx_set_color(window->gc, window->res->wnd_face_color);
|
---|
| 992 | if (rc != EOK)
|
---|
| 993 | return rc;
|
---|
| 994 |
|
---|
| 995 | ui_window_get_app_rect(window, &app_rect);
|
---|
| 996 |
|
---|
| 997 | rc = gfx_fill_rect(window->gc, &app_rect);
|
---|
| 998 | if (rc != EOK)
|
---|
| 999 | return rc;
|
---|
| 1000 |
|
---|
[b71c0fc] | 1001 | if (window->control != NULL)
|
---|
| 1002 | return ui_control_paint(window->control);
|
---|
| 1003 |
|
---|
[2ab8ab3] | 1004 | rc = gfx_update(window->res->gc);
|
---|
| 1005 | if (rc != EOK)
|
---|
| 1006 | return rc;
|
---|
| 1007 |
|
---|
[fa01c05] | 1008 | return EOK;
|
---|
| 1009 | }
|
---|
| 1010 |
|
---|
[b71c0fc] | 1011 | /** Default window position event routine.
|
---|
| 1012 | *
|
---|
| 1013 | * @param window Window
|
---|
| 1014 | */
|
---|
| 1015 | void ui_window_def_pos(ui_window_t *window, pos_event_t *pos)
|
---|
| 1016 | {
|
---|
| 1017 | if (window->control != NULL)
|
---|
| 1018 | ui_control_pos_event(window->control, pos);
|
---|
| 1019 | }
|
---|
| 1020 |
|
---|
[62223ec] | 1021 | /** Default window unfocus routine.
|
---|
| 1022 | *
|
---|
| 1023 | * @param window Window
|
---|
| 1024 | * @return EOK on success or an error code
|
---|
| 1025 | */
|
---|
| 1026 | void ui_window_def_unfocus(ui_window_t *window)
|
---|
| 1027 | {
|
---|
| 1028 | if (window->control != NULL)
|
---|
| 1029 | ui_control_unfocus(window->control);
|
---|
| 1030 | }
|
---|
| 1031 |
|
---|
[2ab8ab3] | 1032 | /** Window invalidate callback
|
---|
[66a2becf] | 1033 | *
|
---|
| 1034 | * @param arg Argument (ui_window_t *)
|
---|
| 1035 | * @param rect Rectangle to update
|
---|
| 1036 | */
|
---|
[2ab8ab3] | 1037 | static void ui_window_invalidate(void *arg, gfx_rect_t *rect)
|
---|
| 1038 | {
|
---|
| 1039 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 1040 | gfx_rect_t env;
|
---|
| 1041 |
|
---|
| 1042 | gfx_rect_envelope(&window->dirty_rect, rect, &env);
|
---|
| 1043 | window->dirty_rect = env;
|
---|
| 1044 | }
|
---|
| 1045 |
|
---|
| 1046 | /** Window update callback
|
---|
| 1047 | *
|
---|
| 1048 | * @param arg Argument (ui_window_t *)
|
---|
| 1049 | */
|
---|
| 1050 | static void ui_window_update(void *arg)
|
---|
| 1051 | {
|
---|
| 1052 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 1053 |
|
---|
[3c3657c] | 1054 | if (!gfx_rect_is_empty(&window->dirty_rect)) {
|
---|
| 1055 | (void) gfx_bitmap_render(window->bmp, &window->dirty_rect,
|
---|
| 1056 | &window->dpos);
|
---|
| 1057 | }
|
---|
[2ab8ab3] | 1058 |
|
---|
| 1059 | window->dirty_rect.p0.x = 0;
|
---|
| 1060 | window->dirty_rect.p0.y = 0;
|
---|
| 1061 | window->dirty_rect.p1.x = 0;
|
---|
| 1062 | window->dirty_rect.p1.y = 0;
|
---|
| 1063 | }
|
---|
| 1064 |
|
---|
[1215db9] | 1065 | /** Window cursor get position callback
|
---|
| 1066 | *
|
---|
| 1067 | * @param arg Argument (ui_window_t *)
|
---|
| 1068 | * @param pos Place to store position
|
---|
| 1069 | */
|
---|
| 1070 | static errno_t ui_window_cursor_get_pos(void *arg, gfx_coord2_t *pos)
|
---|
| 1071 | {
|
---|
| 1072 | ui_window_t *window = (ui_window_t *) arg;
|
---|
[3c3657c] | 1073 | gfx_coord2_t cpos;
|
---|
| 1074 | errno_t rc;
|
---|
| 1075 |
|
---|
| 1076 | rc = gfx_cursor_get_pos(window->realgc, &cpos);
|
---|
| 1077 | if (rc != EOK)
|
---|
| 1078 | return rc;
|
---|
[1215db9] | 1079 |
|
---|
[3c3657c] | 1080 | pos->x = cpos.x - window->dpos.x;
|
---|
| 1081 | pos->y = cpos.y - window->dpos.y;
|
---|
| 1082 | return EOK;
|
---|
[1215db9] | 1083 | }
|
---|
| 1084 |
|
---|
| 1085 | /** Window cursor set position callback
|
---|
| 1086 | *
|
---|
| 1087 | * @param arg Argument (ui_window_t *)
|
---|
| 1088 | * @param pos New position
|
---|
| 1089 | */
|
---|
| 1090 | static errno_t ui_window_cursor_set_pos(void *arg, gfx_coord2_t *pos)
|
---|
| 1091 | {
|
---|
| 1092 | ui_window_t *window = (ui_window_t *) arg;
|
---|
[3c3657c] | 1093 | gfx_coord2_t cpos;
|
---|
| 1094 |
|
---|
| 1095 | cpos.x = pos->x + window->dpos.x;
|
---|
| 1096 | cpos.y = pos->y + window->dpos.y;
|
---|
[1215db9] | 1097 |
|
---|
[3c3657c] | 1098 | return gfx_cursor_set_pos(window->realgc, &cpos);
|
---|
[1215db9] | 1099 | }
|
---|
| 1100 |
|
---|
| 1101 | /** Window cursor set visibility callback
|
---|
| 1102 | *
|
---|
| 1103 | * @param arg Argument (ui_window_t *)
|
---|
| 1104 | * @param visible @c true iff cursor is to be made visible
|
---|
| 1105 | */
|
---|
| 1106 | static errno_t ui_window_cursor_set_visible(void *arg, bool visible)
|
---|
| 1107 | {
|
---|
| 1108 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 1109 |
|
---|
| 1110 | return gfx_cursor_set_visible(window->realgc, visible);
|
---|
| 1111 | }
|
---|
| 1112 |
|
---|
[2ab8ab3] | 1113 | /** Application area invalidate callback
|
---|
| 1114 | *
|
---|
| 1115 | * @param arg Argument (ui_window_t *)
|
---|
| 1116 | * @param rect Rectangle to update
|
---|
| 1117 | */
|
---|
| 1118 | static void ui_window_app_invalidate(void *arg, gfx_rect_t *rect)
|
---|
[66a2becf] | 1119 | {
|
---|
| 1120 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 1121 | gfx_rect_t arect;
|
---|
| 1122 |
|
---|
| 1123 | ui_window_get_app_rect(window, &arect);
|
---|
| 1124 |
|
---|
| 1125 | /* Render bitmap rectangle inside the application area */
|
---|
| 1126 | (void) gfx_bitmap_render(window->app_bmp, rect, &arect.p0);
|
---|
[2ab8ab3] | 1127 | /*
|
---|
| 1128 | * TODO Update applications to call gfx_update(), then
|
---|
| 1129 | * we can defer update to ui_window_app_update().
|
---|
| 1130 | */
|
---|
| 1131 | (void) gfx_update(window->res->gc);
|
---|
| 1132 | }
|
---|
| 1133 |
|
---|
| 1134 | /** Application area update callback
|
---|
| 1135 | *
|
---|
| 1136 | * @param arg Argument (ui_window_t *)
|
---|
| 1137 | */
|
---|
| 1138 | static void ui_window_app_update(void *arg)
|
---|
| 1139 | {
|
---|
| 1140 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 1141 |
|
---|
| 1142 | /*
|
---|
| 1143 | * Not used since display is updated immediately
|
---|
| 1144 | * in ui_window_app_invalidate
|
---|
| 1145 | */
|
---|
| 1146 | (void) window;
|
---|
[66a2becf] | 1147 | }
|
---|
| 1148 |
|
---|
[214aefb] | 1149 | /** Window expose callback. */
|
---|
| 1150 | static void ui_window_expose_cb(void *arg)
|
---|
| 1151 | {
|
---|
| 1152 | ui_window_t *window = (ui_window_t *) arg;
|
---|
| 1153 |
|
---|
| 1154 | ui_window_paint(window);
|
---|
| 1155 | }
|
---|
| 1156 |
|
---|
[f7a90df] | 1157 | /** @}
|
---|
| 1158 | */
|
---|