source: mainline/uspace/lib/gui/widget.h@ bdfdc51c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bdfdc51c was 10cb47e, checked in by Martin Decky <martin@…>, 9 years ago

add support for custom client data into widgets

  • Property mode set to 100644
File size: 5.6 KB
Line 
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_WIDGET_H_
37#define GUI_WIDGET_H_
38
39#include <sys/types.h>
40#include <adt/list.h>
41#include <io/window.h>
42
43struct window;
44typedef struct window window_t;
45
46struct widget;
47typedef struct widget widget_t;
48
49/**
50 * Base class for all widgets. This structure should be first data member of
51 * any derived widget structure.
52 */
53struct widget {
54 link_t link;
55 widget_t *parent; /**< Parent widget of this widget. NULL for root widget. */
56 list_t children; /**< Children widgets of this widget. */
57 window_t *window; /**< Window into which this widget belongs. */
58 const void *data; /**< Custom client data. */
59
60 sysarg_t hpos; /**< Horizontal position in window coordinates. */
61 sysarg_t vpos; /**< Vertical position in window coordinates. */
62 sysarg_t width;
63 sysarg_t height;
64
65 sysarg_t width_min;
66 sysarg_t height_min;
67 sysarg_t width_ideal; /**< Width size hint for initialization. */
68 sysarg_t height_ideal; /**< Height size hint for initialization, */
69 sysarg_t width_max;
70 sysarg_t height_max;
71
72 /**
73 * Virtual destructor. Apart from deallocating the resources specific for
74 * the particular widget, each widget shall remove itself from parents
75 * children and deallocate itself. */
76 void (*destroy)(widget_t *);
77
78 /**
79 * Reserved for bottom-top traversal when widget changes its properties and
80 * want to inform its ancestors in widget hierarchy to consider rearranging
81 * their children. As a reaction to this call, each widget shall fetch
82 * information from its children and decide whether its own properties have
83 * to be changed. If not, widget shall calculate new layout for its children
84 * and call rearrange() on each of them. Otherwise, widget shall change its
85 * own properties and call reconfigure() on its parent. */
86 void (*reconfigure)(widget_t *);
87
88 /**
89 * Reserved for top-bottom traversal when widget decides to change layout
90 * of its childer. As a reaction to this call, widget shall change its
91 * position and size according to provided arguments, paint itself,
92 * calculate new layout for its children and call rearrange() on each
93 * of them. */
94 void (*rearrange)(widget_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t);
95
96 /**
97 * As a reaction to window refresh event, widget hierarchy is traversed
98 * in top-bottom order and repaint() is called on each widget. Widget shall
99 * either paint itself or copy its private buffer onto window surface.
100 * Widget shall also post damage event into window event loop. */
101 void (*repaint)(widget_t *);
102
103 /**
104 * Keyboard events are delivered to widgets that have keyboard focus. As a
105 * reaction to the event, widget might call reconfigure() on its parent or
106 * rearrange() on its children. If the widget wants to change its visual
107 * information, refresh event should be posted to the window event loop. */
108 void (*handle_keyboard_event)(widget_t *, kbd_event_t);
109
110 /**
111 * Position events are delivered to those widgets that have mouse grab or
112 * those that intersects with cursor. As a reaction to the event, widget
113 * might call reconfigure() on its parent or rearrange() on its children.
114 * If the widget wants to change its visual information, refresh event
115 * should be posted to the window event loop. If the widget accepts
116 * keyboard events, it should take ownership of keyboard focus. Widget can
117 * also acquire or release mouse grab. */
118 void (*handle_position_event)(widget_t *, pos_event_t);
119};
120
121/*
122 * Note on derived widget constructor/destructor:
123 * In order to support inheritance, wach widget shall provide init and deinit
124 * function. These functions take already allocated widget and are responsible
125 * for (de)initializing all widget-specific resources, inserting/removing the
126 * widget into/from widget hierarchy and (de)initializing all data and functions
127 * from the top-level base class defined above. For convenience, each widget
128 * should also provide constructor to allocate and init the widget in one step.
129 */
130
131extern void widget_init(widget_t *, widget_t *, const void *);
132extern void widget_modify(widget_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t);
133extern const void *widget_get_data(widget_t *);
134extern void widget_deinit(widget_t *);
135
136#endif
137
138/** @}
139 */
140
Note: See TracBrowser for help on using the repository browser.