source: mainline/uspace/lib/ui/src/control.c@ 11662bd

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 11662bd was 7481ee19, checked in by Jiri Svoboda <jiri@…>, 4 years ago

Basic editable text entry

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2021 Jiri Svoboda
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 UI control
34 */
35
36#include <errno.h>
37#include <io/kbd_event.h>
38#include <io/pos_event.h>
39#include <stdlib.h>
40#include <ui/control.h>
41#include "../private/control.h"
42
43/** Allocate new UI control.
44 *
45 * @param ops Control ops
46 * @param ext Control extended data
47 * @param rcontrol Place to store pointer to new control
48 * @return EOK on success, ENOMEM if out of memory
49 */
50errno_t ui_control_new(ui_control_ops_t *ops, void *ext,
51 ui_control_t **rcontrol)
52{
53 ui_control_t *control;
54
55 control = calloc(1, sizeof(ui_control_t));
56 if (control == NULL)
57 return ENOMEM;
58
59 control->ops = ops;
60 control->ext = ext;
61 *rcontrol = control;
62 return EOK;
63}
64
65/** Delete UI control.
66 *
67 * Deletes the base control (not the extended data).
68 *
69 * @param control UI control or @c NULL
70 */
71void ui_control_delete(ui_control_t *control)
72{
73 if (control == NULL)
74 return;
75
76 free(control);
77}
78
79/** Destroy UI control.
80 *
81 * Run the virtual control destructor (destroy complete control including
82 * extended data).
83 *
84 * @param control Control or @c NULL
85 */
86void ui_control_destroy(ui_control_t *control)
87{
88 if (control == NULL)
89 return;
90
91 return control->ops->destroy(control->ext);
92}
93
94/** Deliver keyboard event to UI control.
95 *
96 * @param control Control
97 * @param kbd_event Keyboard event
98 * @return @c ui_claimed iff the event is claimed
99 */
100ui_evclaim_t ui_control_kbd_event(ui_control_t *control, kbd_event_t *event)
101{
102 if (control->ops->kbd_event != NULL)
103 return control->ops->kbd_event(control->ext, event);
104 else
105 return ui_unclaimed;
106}
107
108/** Paint UI control.
109 *
110 * @param control Control
111 * @return EOK on success or an error code
112 */
113errno_t ui_control_paint(ui_control_t *control)
114{
115 return control->ops->paint(control->ext);
116}
117
118/** Deliver position event to UI control.
119 *
120 * @param control Control
121 * @param pos_event Position event
122 * @return @c ui_claimed iff the event is claimed
123 */
124ui_evclaim_t ui_control_pos_event(ui_control_t *control, pos_event_t *event)
125{
126 return control->ops->pos_event(control->ext, event);
127}
128
129/** Inform UI control that window has been unfocused.
130 *
131 * @param control Control
132 */
133void ui_control_unfocus(ui_control_t *control)
134{
135 if (control->ops->unfocus != NULL)
136 control->ops->unfocus(control->ext);
137}
138
139/** @}
140 */
Note: See TracBrowser for help on using the repository browser.