1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
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_execute PORTABLE C */ |
39 |
|
|
/* 6.1 */ |
40 |
|
|
/* AUTHOR */ |
41 |
|
|
/* */ |
42 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
43 |
|
|
/* */ |
44 |
|
|
/* DESCRIPTION */ |
45 |
|
|
/* */ |
46 |
|
|
/* This function modally executes a window. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* window Window's widget control block */ |
51 |
|
|
/* return_ptr return value */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* status Completion status */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLS */ |
58 |
|
|
/* */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLED BY */ |
61 |
|
|
/* */ |
62 |
|
|
/* Application Code */ |
63 |
|
|
/* GUIX Internal Code */ |
64 |
|
|
/* */ |
65 |
|
|
/**************************************************************************/ |
66 |
|
9 |
UINT _gx_window_execute(GX_WINDOW *window, ULONG *return_ptr) |
67 |
|
|
{ |
68 |
|
9 |
UINT status = GX_SUCCESS; |
69 |
|
9 |
UINT return_code = 0; |
70 |
|
|
|
71 |
|
|
#ifdef GX_THREADX_BINDING |
72 |
|
|
ULONG event_memory[GX_EVENT_ULONGS]; |
73 |
|
|
#else |
74 |
|
|
GX_EVENT event_memory; |
75 |
|
|
#endif |
76 |
|
|
|
77 |
|
|
GX_EVENT *event_ptr; |
78 |
|
|
GX_WIDGET *widget; |
79 |
|
|
|
80 |
✓✓ |
9 |
if (window -> gx_widget_status & GX_STATUS_MODAL) |
81 |
|
|
{ |
82 |
|
1 |
return GX_NO_CHANGE; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
8 |
_gx_widget_status_add((GX_WIDGET *)window, GX_STATUS_MODAL); |
86 |
|
|
|
87 |
|
|
/* Loop to process GUIX events. */ |
88 |
✓✓ |
37 |
while (!return_code) |
89 |
|
|
{ |
90 |
|
|
#ifdef GX_THREADX_BINDING |
91 |
|
|
/* Pickup event from event queue. */ |
92 |
|
31 |
status = tx_queue_receive(&_gx_system_event_queue, &event_memory[0], TX_NO_WAIT); |
93 |
|
|
|
94 |
|
|
/* Was there an event? */ |
95 |
✓✓ |
31 |
if (status == TX_QUEUE_EMPTY) |
96 |
|
|
{ |
97 |
|
|
/* No event to process, so re-draw dirty widgets */ |
98 |
|
30 |
_gx_system_canvas_refresh(); |
99 |
|
|
|
100 |
|
|
/* Now block this thread until an event is received. */ |
101 |
|
30 |
status = tx_queue_receive(&_gx_system_event_queue, &event_memory[0], TX_WAIT_FOREVER); |
102 |
✓✓ |
30 |
if (status == TX_SUCCESS) |
103 |
|
|
{ |
104 |
|
28 |
status = GX_SUCCESS; |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
#else |
108 |
|
|
/* here for generic RTOS binding */ |
109 |
|
|
status = GX_EVENT_POP(&event_memory, GX_FALSE); |
110 |
|
|
if (status == GX_FAILURE) |
111 |
|
|
{ |
112 |
|
|
_gx_system_canvas_refresh(); |
113 |
|
|
status = GX_EVENT_POP(&event_memory, GX_TRUE); |
114 |
|
|
} |
115 |
|
|
#endif |
116 |
|
|
|
117 |
|
|
/* Check for a successful status. */ |
118 |
✓✓ |
31 |
if (status == GX_SUCCESS) |
119 |
|
|
{ |
120 |
|
|
/* Setup a pointer to the event. */ |
121 |
|
29 |
event_ptr = (GX_EVENT *)(&event_memory); |
122 |
|
|
|
123 |
✓✓✓✓ ✓✓✓✓
|
29 |
switch (event_ptr -> gx_event_type) |
124 |
|
|
{ |
125 |
|
|
/* Determine if a redraw event is present. */ |
126 |
|
13 |
case GX_EVENT_REDRAW: |
127 |
|
|
/* Yes, a redraw event is present, detect and process the dirty area(s). */ |
128 |
|
13 |
widget = (GX_WIDGET *)_gx_system_root_window_created_list; |
129 |
✓✓ |
39 |
while (widget) |
130 |
|
|
{ |
131 |
|
26 |
_gx_system_dirty_mark(widget); |
132 |
|
26 |
widget = widget -> gx_widget_next; |
133 |
|
|
} |
134 |
|
13 |
break; |
135 |
|
|
|
136 |
|
2 |
case GX_EVENT_TIMER: |
137 |
✓✓ |
2 |
if (event_ptr -> gx_event_target == GX_NULL) |
138 |
|
|
{ |
139 |
|
|
/* the event is from gx_system_timer_expiration */ |
140 |
|
1 |
_gx_system_timer_update(event_ptr -> gx_event_payload.gx_event_ulongdata); |
141 |
|
|
} |
142 |
|
|
else |
143 |
|
|
{ |
144 |
|
1 |
return_code = _gx_system_event_dispatch(event_ptr); |
145 |
|
|
} |
146 |
|
2 |
break; |
147 |
|
|
|
148 |
|
6 |
case GX_EVENT_PEN_DOWN: |
149 |
|
|
case GX_EVENT_PEN_UP: |
150 |
|
|
case GX_EVENT_PEN_DRAG: |
151 |
✓✓✓✓
|
10 |
if (_gx_system_capture_count > 0 || |
152 |
|
4 |
_gx_utility_rectangle_point_detect(&window -> gx_widget_size, event_ptr -> gx_event_payload.gx_event_pointdata)) |
153 |
|
|
{ |
154 |
|
3 |
return_code = _gx_system_event_dispatch(event_ptr); |
155 |
|
|
} |
156 |
|
6 |
break; |
157 |
|
|
|
158 |
|
1 |
case GX_EVENT_TERMINATE: |
159 |
|
1 |
_gx_system_event_send(event_ptr); |
160 |
|
1 |
return_code = GX_EVENT_TERMINATE; |
161 |
|
1 |
break; |
162 |
|
|
|
163 |
|
1 |
case GX_EVENT_HIDE: |
164 |
|
1 |
_gx_system_event_dispatch(event_ptr); |
165 |
|
1 |
return_code = GX_EVENT_HIDE; |
166 |
|
1 |
break; |
167 |
|
|
|
168 |
|
1 |
case GX_EVENT_CLOSE: |
169 |
|
1 |
_gx_system_event_dispatch(event_ptr); |
170 |
|
1 |
return_code = GX_EVENT_CLOSE; |
171 |
|
1 |
break; |
172 |
|
|
|
173 |
|
1 |
case 0: |
174 |
|
|
/* event has been purged */ |
175 |
|
1 |
break; |
176 |
|
|
|
177 |
|
4 |
default: |
178 |
|
|
/* Dispatch the event to GUIX proper window/widget. */ |
179 |
|
4 |
return_code = _gx_system_event_dispatch(event_ptr); |
180 |
|
4 |
break; |
181 |
|
|
} |
182 |
|
|
} |
183 |
|
|
else |
184 |
|
|
{ |
185 |
|
|
/* Error receiving event - call system error handler. */ |
186 |
|
2 |
_gx_system_error_process(GX_SYSTEM_EVENT_RECEIVE_ERROR); |
187 |
|
|
|
188 |
|
|
/* Return to exit the system thread. */ |
189 |
|
|
|
190 |
|
2 |
_gx_widget_status_remove((GX_WIDGET *)window, GX_STATUS_MODAL); |
191 |
|
|
|
192 |
✓✓ |
2 |
if (return_ptr) |
193 |
|
|
{ |
194 |
|
1 |
*return_ptr = 0; |
195 |
|
|
} |
196 |
|
2 |
return GX_SYSTEM_EVENT_RECEIVE_ERROR; |
197 |
|
|
} |
198 |
|
|
} |
199 |
|
|
|
200 |
|
6 |
_gx_widget_status_remove((GX_WIDGET *)window, GX_STATUS_MODAL); |
201 |
|
|
|
202 |
✓✓ |
6 |
if (return_ptr) |
203 |
|
|
{ |
204 |
|
3 |
*return_ptr = return_code; |
205 |
|
|
} |
206 |
|
|
|
207 |
|
6 |
_gx_widget_detach((GX_WIDGET *)window); |
208 |
|
6 |
return GX_SUCCESS; |
209 |
|
|
} |
210 |
|
|
|