source: mainline/uspace/lib/gui/widget.h@ 0c322fa

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0c322fa was 55edba0, checked in by Vojtech Horky <vojtechhorky@…>, 12 years ago

C style: do not redefine typedefs

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