1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** GUIX Component */
17 /** */
18 /** Window Management (Window) */
19 /** */
20 /**************************************************************************/
21
22 #define GX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "gx_api.h"
28 #include "gx_system.h"
29 #include "gx_widget.h"
30 #include "gx_window.h"
31 #include "gx_utility.h"
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _gx_window_event_process PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* Kenneth Maxwell, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function processes events for the specified window. */
47 /* */
48 /* INPUT */
49 /* */
50 /* window Window's widget control block */
51 /* event_ptr Incoming event to process */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* status Completion status */
56 /* */
57 /* CALLS */
58 /* */
59 /* _gx_widget_shift Shift a widget */
60 /* _gx_window_view_update_detect Detect changes to the window */
61 /* viewport */
62 /* _gx_widget_event_process Call widget event processing */
63 /* _gx_window_cilent_scroll Scroll window client area */
64 /* _gx_widget_front_move Move window to front */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* Application Code */
69 /* GUIX Internal Code */
70 /* */
71 /* RELEASE HISTORY */
72 /* */
73 /* DATE NAME DESCRIPTION */
74 /* */
75 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
76 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
77 /* resulting in version 6.1 */
78 /* */
79 /**************************************************************************/
_gx_window_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)80 UINT _gx_window_event_process(GX_WINDOW *window, GX_EVENT *event_ptr)
81 {
82
83 UINT status;
84 GX_WIDGET *widget;
85 GX_WIDGET *parent;
86 GX_VALUE xShift;
87 GX_VALUE yShift;
88
89 status = GX_SUCCESS;
90 widget = (GX_WIDGET *)window;
91
92 /* Process relative to the type of event. */
93 switch (event_ptr -> gx_event_type)
94 {
95 case GX_EVENT_PEN_DOWN:
96 /* if this window is moveable, go into move mode */
97 if (window -> gx_widget_status & GX_STATUS_MOVABLE)
98 {
99 window -> gx_window_move_mode = GX_TRUE;
100 window -> gx_window_move_start = event_ptr -> gx_event_payload.gx_event_pointdata;
101 /* Return successful status. */
102 return(GX_SUCCESS);
103 }
104 else
105 {
106 status = _gx_widget_event_process(widget, event_ptr);
107 }
108 break;
109
110 case GX_EVENT_PEN_DRAG:
111 if (window -> gx_window_move_mode)
112 {
113 xShift = (GX_VALUE)(event_ptr -> gx_event_payload.gx_event_pointdata.gx_point_x -
114 window -> gx_window_move_start.gx_point_x);
115 yShift = (GX_VALUE)(event_ptr -> gx_event_payload.gx_event_pointdata.gx_point_y -
116 window -> gx_window_move_start.gx_point_y);
117
118 window -> gx_window_move_start = event_ptr -> gx_event_payload.gx_event_pointdata;
119
120 _gx_widget_shift(widget, xShift, yShift, GX_TRUE);
121 }
122 else
123 {
124 status = _gx_widget_event_process(widget, event_ptr);
125 }
126 return(status);
127
128 case GX_EVENT_PEN_UP:
129 if (window -> gx_window_move_mode)
130 {
131 window -> gx_window_move_mode = GX_FALSE;
132 }
133 else
134 {
135 status = _gx_widget_event_process(widget, event_ptr);
136 }
137 break;
138
139 case GX_EVENT_FOCUS_GAINED:
140 /* first do default handling */
141
142 if (widget -> gx_widget_status & GX_STATUS_ACCEPTS_FOCUS)
143 {
144 _gx_widget_event_process(widget, event_ptr);
145
146 /* If this window owns focus, try to assign focus to client child */
147 if (_gx_system_focus_owner == GX_NULL ||
148 _gx_system_focus_owner == widget)
149 {
150 _gx_widget_child_focus_assign(widget);
151 }
152
153 /* Now move window to front. */
154 if (window -> gx_widget_type != GX_TYPE_ROOT_WINDOW)
155 {
156 if (_gx_widget_front_move(widget, GX_NULL) != GX_NO_CHANGE)
157 {
158 /* if I am a top-level window and I moved in front, then
159 the viewport lists need to be updated.
160 */
161 _gx_window_view_update_detect(window);
162 }
163 }
164 }
165 break;
166
167 case GX_EVENT_HIDE:
168 /* do the default handling */
169 status = _gx_widget_event_process(widget, event_ptr);
170
171 /* if this window is child of root, viewports must be updated */
172 _gx_window_view_update_detect(window);
173 break;
174
175 case GX_EVENT_CLOSE:
176 _gx_widget_detach(widget);
177 return GX_EVENT_CLOSE;
178
179 case GX_EVENT_SHOW:
180 /* do the default handling */
181 status = _gx_widget_event_process(widget, event_ptr);
182
183 _gx_widget_nav_order_initialize(widget);
184
185 /* if this window is child of root, viewports must be updated */
186 _gx_window_view_update_detect(window);
187
188 /* if this window is in front, claim focus */
189 if (widget -> gx_widget_type != GX_TYPE_ROOT_WINDOW &&
190 !(widget -> gx_widget_status & GX_STATUS_HAS_FOCUS))
191 {
192 parent = widget;
193 while (parent && widget -> gx_widget_next == GX_NULL)
194 {
195 parent = widget -> gx_widget_parent;
196
197 if (parent)
198 {
199 if (parent -> gx_widget_type == GX_TYPE_ROOT_WINDOW)
200 {
201 _gx_system_focus_claim((GX_WIDGET *)window);
202 break;
203 }
204 widget = parent;
205 parent = widget -> gx_widget_parent;
206 }
207 }
208 }
209
210 break;
211
212 case GX_EVENT_VERTICAL_SCROLL:
213 _gx_window_scroll(window, 0, (GX_VALUE)(event_ptr -> gx_event_payload.gx_event_intdata[1] - event_ptr -> gx_event_payload.gx_event_intdata[0]));
214 break;
215
216 case GX_EVENT_HORIZONTAL_SCROLL:
217 _gx_window_scroll(window, (GX_VALUE)(event_ptr -> gx_event_payload.gx_event_intdata[1] - event_ptr -> gx_event_payload.gx_event_intdata[0]), 0);
218 break;
219
220 default:
221
222 /* Call the widget default processing. */
223 status = _gx_widget_event_process(widget, event_ptr);
224 }
225 /* Return widget event processing status. */
226 return(status);
227 }
228
229