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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a35b458 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 5.5 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 <adt/list.h>
40#include <io/window.h>
41
42struct window;
43typedef struct window window_t;
44
45struct widget;
46typedef struct widget widget_t;
47
48/**
49 * Base class for all widgets. This structure should be first data member of
50 * any derived widget structure.
51 */
52struct widget {
53 link_t link;
54 widget_t *parent; /**< Parent widget of this widget. NULL for root widget. */
55 list_t children; /**< Children widgets of this widget. */
56 window_t *window; /**< Window into which this widget belongs. */
57 const void *data; /**< Custom client data. */
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
130extern void widget_init(widget_t *, widget_t *, const void *);
131extern void widget_modify(widget_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t);
132extern const void *widget_get_data(widget_t *);
133extern void widget_deinit(widget_t *);
134
135#endif
136
137/** @}
138 */
139
Note: See TracBrowser for help on using the repository browser.