[6d5e378] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Petr Koupy
|
---|
| 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 gui
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef GUI_WINDOW_H_
|
---|
| 37 | #define GUI_WINDOW_H_
|
---|
| 38 |
|
---|
| 39 | #include <adt/prodcons.h>
|
---|
| 40 | #include <fibril_synch.h>
|
---|
| 41 | #include <ipc/window.h>
|
---|
| 42 | #include <io/window.h>
|
---|
[2bb6d04] | 43 | #include <draw/surface.h>
|
---|
[4645b2c] | 44 | #include <display.h>
|
---|
| 45 | #include <gfx/bitmap.h>
|
---|
| 46 | #include <gfx/context.h>
|
---|
[6d5e378] | 47 |
|
---|
| 48 | #include "widget.h"
|
---|
| 49 |
|
---|
[55edba0] | 50 | struct window {
|
---|
[6d5e378] | 51 | bool is_main; /**< True for the main window of the application. */
|
---|
| 52 | bool is_decorated; /**< True if the window decorations should be rendered. */
|
---|
[290a0f0] | 53 | bool is_focused; /**< True for the top level window of the desktop. */
|
---|
[66a408f7] | 54 | bool is_resizable; /**< True if window is resizable */
|
---|
[6d5e378] | 55 | char *caption; /**< Text title of the window header. */
|
---|
[4645b2c] | 56 | display_t *display; /**< Display service */
|
---|
| 57 | display_window_t *dwindow; /**< Display window */
|
---|
| 58 | gfx_context_t *gc; /**< GC of the window */
|
---|
[6d5e378] | 59 | prodcons_t events; /**< Queue for window event loop. */
|
---|
| 60 | widget_t root; /**< Decoration widget serving as a root of widget hiearchy. */
|
---|
| 61 | widget_t *grab; /**< Widget owning the mouse or NULL. */
|
---|
| 62 | widget_t *focus; /**< Widget owning the keyboard or NULL. */
|
---|
| 63 | fibril_mutex_t guard; /**< Mutex guarding window surface. */
|
---|
[6feccae] | 64 | surface_t *surface; /**< Window surface shared with display server. */
|
---|
[4645b2c] | 65 | gfx_bitmap_t *bitmap; /**< Window bitmap */
|
---|
[9242ad9] | 66 | display_stock_cursor_t cursor; /**< Selected cursor */
|
---|
[55edba0] | 67 | };
|
---|
[6d5e378] | 68 |
|
---|
| 69 | /**
|
---|
[6feccae] | 70 | * Allocate all resources for new window and register it in the display server.
|
---|
[6d5e378] | 71 | * If the window is declared as main, its closure causes termination of the
|
---|
[2c7fdaa] | 72 | * whole application. Note that opened window does not have any surface yet.
|
---|
| 73 | */
|
---|
[10cb47e] | 74 | extern window_t *window_open(const char *, const void *, window_flags_t,
|
---|
| 75 | const char *);
|
---|
[6d5e378] | 76 |
|
---|
| 77 | /**
|
---|
| 78 | * Post resize event into event loop. Window negotiates new surface with
|
---|
[6feccae] | 79 | * display server and asks all widgets in the tree to calculate their new
|
---|
| 80 | * properties and to paint themselves on the new surface (top-bottom order).
|
---|
| 81 | * Should be called also after opening new window to obtain surface.
|
---|
[7c3fb9b] | 82 | */
|
---|
[62fbb7e] | 83 | extern void window_resize(window_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
| 84 | window_placement_flags_t);
|
---|
[6d5e378] | 85 |
|
---|
[78188e5] | 86 | /** Change window caption. */
|
---|
[b7fd2a0] | 87 | extern errno_t window_set_caption(window_t *, const char *);
|
---|
[78188e5] | 88 |
|
---|
[6d5e378] | 89 | /**
|
---|
| 90 | * Post refresh event into event loop. Widget tree is traversed and all widgets
|
---|
| 91 | * are asked to repaint themselves in top-bottom order. Should be called by
|
---|
| 92 | * widget after such change of its internal state that does not need resizing
|
---|
[7c3fb9b] | 93 | * of neither parent nor children ().
|
---|
| 94 | */
|
---|
[6d5e378] | 95 | extern void window_refresh(window_t *);
|
---|
| 96 |
|
---|
| 97 | /**
|
---|
[6feccae] | 98 | * Post damage event into event loop. Handler informs display server to update
|
---|
| 99 | * the window surface on the screen. Should be called by widget after painting
|
---|
[7c3fb9b] | 100 | * itself or copying its buffer onto window surface.
|
---|
| 101 | */
|
---|
[6d5e378] | 102 | extern void window_damage(window_t *);
|
---|
| 103 |
|
---|
| 104 | /**
|
---|
| 105 | * Retrieve dummy root widget of the window widget tree. Intended to be called
|
---|
[7c3fb9b] | 106 | * by proper top-level widget to set his parent.
|
---|
| 107 | */
|
---|
[6d5e378] | 108 | extern widget_t *window_root(window_t *);
|
---|
| 109 |
|
---|
| 110 | /**
|
---|
| 111 | * Prepare and enqueue window fibrils for event loop and input fetching. When
|
---|
[7c3fb9b] | 112 | * async_manager() function is called, event loop is executed.
|
---|
| 113 | */
|
---|
[6d5e378] | 114 | extern void window_exec(window_t *);
|
---|
| 115 |
|
---|
| 116 | /**
|
---|
| 117 | * Claim protected window surface. Intended for widgets painting from their
|
---|
[7c3fb9b] | 118 | * internal fibrils (e.g. terminal, animation, video).
|
---|
| 119 | */
|
---|
[6d5e378] | 120 | extern surface_t *window_claim(window_t *);
|
---|
| 121 |
|
---|
| 122 | /**
|
---|
[7c3fb9b] | 123 | * Yield protected window surface after painting.
|
---|
| 124 | */
|
---|
[6d5e378] | 125 | extern void window_yield(window_t *);
|
---|
| 126 |
|
---|
| 127 | /**
|
---|
[6feccae] | 128 | * Initiate the closing cascade for the window. First, display sever deallocates
|
---|
[6d5e378] | 129 | * output resources, prepares special closing input event for the window and
|
---|
| 130 | * deallocates input resources after the event is dispatched. When window
|
---|
| 131 | * fetches closing event, it is posted into event loop and input fibril
|
---|
| 132 | * terminates. When event loop fibril handles closing event, all window
|
---|
| 133 | * resources are deallocated and fibril also terminates. Moreover, if the
|
---|
[7c3fb9b] | 134 | * window is main window of the application, whole task terminates.
|
---|
| 135 | */
|
---|
[6d5e378] | 136 | extern void window_close(window_t *);
|
---|
| 137 |
|
---|
| 138 | #endif
|
---|
| 139 |
|
---|
| 140 | /** @}
|
---|
| 141 | */
|
---|