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 /**   System Management (System)                                          */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    gx_system.h                                         PORTABLE C      */
29 /*                                                           6.1.11       */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    Kenneth Maxwell, Microsoft Corporation                              */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file defines the GUIX system management component,             */
37 /*    including all data types and external references.  It is assumed    */
38 /*    that gx_api.h and gx_port.h have already been included.             */
39 /*                                                                        */
40 /*  RELEASE HISTORY                                                       */
41 /*                                                                        */
42 /*    DATE              NAME                      DESCRIPTION             */
43 /*                                                                        */
44 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
45 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
46 /*                                            removed private string      */
47 /*                                            delete declaration,         */
48 /*                                            resulting in version 6.1    */
49 /*  12-31-2020     Kenneth Maxwell          Modified comment(s),          */
50 /*                                            added GX_DISABLE_THREADX_   */
51 /*                                            TIMER_SOURCE configuration, */
52 /*                                            resulting in version 6.1.3  */
53 /*  04-25-2022     Ting Zhu                 Modified comment(s),          */
54 /*                                            added new parameter to      */
55 /*                                            _gx_system_pen_flick_test,  */
56 /*                                            resulting in version 6.1.11 */
57 /*                                                                        */
58 /**************************************************************************/
59 
60 #ifndef GX_SYSTEM_H
61 #define GX_SYSTEM_H
62 
63 
64 /* Define system management function prototypes.  */
65 
66 UINT _gx_system_active_language_set(GX_UBYTE language);
67 VOID _gx_system_all_canvas_dirty(VOID);
68 VOID _gx_system_all_views_free(GX_WINDOW_ROOT *root);
69 
70 #if (GX_ANIMATION_POOL_SIZE > 0)
71 UINT _gx_system_animation_get(GX_ANIMATION **animation);
72 UINT _gx_system_animation_free(GX_ANIMATION *animation);
73 #endif
74 
75 #if defined(GX_DYNAMIC_BIDI_TEXT_SUPPORT)
76 UINT _gx_system_bidi_text_enable(VOID);
77 UINT _gx_system_bidi_text_disable(VOID);
78 #endif
79 
80 #if defined(GX_THAI_GLYPH_SHAPING_SUPPORT)
81 UINT _gx_system_text_render_style_set(GX_UBYTE style);
82 #endif
83 
84 UINT     _gx_system_canvas_refresh(VOID);
85 
86 UINT     _gx_system_clipboard_put(VOID *data, UINT data_size);
87 UINT     _gx_system_clipboard_get(VOID **data, UINT *data_size);
88 
89 UINT     _gx_system_dirty_mark(GX_WIDGET *widget);
90 UINT     _gx_system_dirty_list_trim(GX_RECTANGLE *dirty_area, GX_WINDOW_ROOT *root);
91 VOID     _gx_system_dirty_list_remove(GX_WIDGET *remove);
92 UINT     _gx_system_dirty_partial_add(GX_WIDGET *widget, GX_RECTANGLE *dirty_area);
93 VOID     _gx_system_dirty_entry_shift(GX_WIDGET *widget, INT xShift, INT yShift);
94 UINT     _gx_system_draw_context_get(GX_DRAW_CONTEXT **current_context);
95 
96 VOID     _gx_system_error_process(UINT error_code);
97 UINT     _gx_system_event_dispatch(GX_EVENT *new_event);
98 UINT     _gx_system_event_fold(GX_EVENT *in_event);
99 VOID     _gx_system_event_remove(GX_WIDGET *widget);
100 UINT     _gx_system_event_send(GX_EVENT *in_event);
101 UINT     _gx_system_focus_claim(GX_WIDGET *widget);
102 GX_VIEW *_gx_system_free_view_get(VOID);
103 
104 UINT     _gx_system_initialize(VOID);
105 
106 UINT     _gx_system_input_capture(GX_WIDGET *owner);
107 UINT     _gx_system_input_release(GX_WIDGET *owner);
108 
109 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
110 UINT _gx_system_language_table_get(GX_CHAR ****language_table, GX_UBYTE *language_count, UINT *string_count);
111 UINT _gx_system_language_table_set(GX_CHAR ***language_table, GX_UBYTE number_of_langauges, UINT number_of_strings);
112 #endif
113 
114 VOID _gx_system_lock(VOID);
115 UINT _gx_system_memory_allocator_set(VOID *(*allocate)(ULONG size), VOID (*release)(VOID *));
116 
117 VOID _gx_system_unlock(VOID);
118 VOID _gx_system_input_lock(VOID);
119 VOID _gx_system_input_unlock(VOID);
120 
121 VOID _gx_system_pen_speed_init(GX_POINT *current);
122 VOID _gx_system_pen_speed_update(GX_POINT *current);
123 VOID _gx_system_pen_flick_test(GX_WIDGET *target);
124 UINT _gx_system_pen_configure(GX_PEN_CONFIGURATION *pen_configuration);
125 
126 UINT _gx_system_private_string_copy(GX_STRING *ptr_address, GX_CONST GX_STRING *text);
127 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
128 UINT _gx_system_private_string_list_copy(GX_CONST GX_CHAR ***ptr_address, GX_CONST GX_CHAR **string_list, INT string_count);
129 VOID _gx_system_private_string_list_get(GX_CONST GX_CHAR **input, GX_CONST GX_CHAR ***output, ULONG style);
130 #endif
131 UINT _gx_system_private_string_list_copy_ext(GX_STRING **ptr_address, USHORT *buffer_size, GX_CONST GX_STRING *string_list, INT string_count);
132 VOID _gx_system_private_string_get(GX_CONST GX_STRING *input, GX_STRING *output, ULONG style);
133 
134 VOID _gx_system_root_view_add(GX_WINDOW_ROOT *root, GX_RECTANGLE *inrect);
135 UINT _gx_system_screen_stack_create(GX_WIDGET **memory, INT size);
136 UINT _gx_system_screen_stack_pop(VOID);
137 UINT _gx_system_screen_stack_push(GX_WIDGET *screen);
138 UINT _gx_system_screen_stack_get(GX_WIDGET **popped_parent, GX_WIDGET **popped_screen);
139 UINT _gx_system_screen_stack_reset(VOID);
140 UINT _gx_system_scroll_appearance_get(ULONG type,  GX_SCROLLBAR_APPEARANCE *save);
141 UINT _gx_system_scroll_appearance_set(ULONG style, GX_SCROLLBAR_APPEARANCE *appearance);
142 UINT _gx_system_start(VOID);
143 
144 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
145 UINT _gx_system_string_get(GX_RESOURCE_ID string_id, GX_CONST GX_CHAR **return_string);
146 UINT _gx_system_string_table_get(GX_UBYTE langauge, GX_CHAR ***put_table, UINT *put_size);
147 UINT _gx_system_string_width_get(GX_CONST GX_FONT *font, GX_CONST GX_CHAR *string, INT string_length, GX_VALUE *return_width);
148 #endif
149 
150 UINT            _gx_system_string_width_get_ext(GX_CONST GX_FONT *font, GX_CONST GX_STRING *string, GX_VALUE *return_width);
151 
152 VOID            _gx_system_thread_entry(ULONG id);
153 VOID            _gx_system_timer_expiration(ULONG val);
154 UINT            _gx_system_timer_start(GX_WIDGET *owner, UINT timer_id, UINT initial_ticks, UINT reschedule_ticks);
155 UINT            _gx_system_timer_stop(GX_WIDGET *owner, UINT timer_id);
156 VOID            _gx_system_timer_update(ULONG ticks);
157 GX_WINDOW_ROOT *_gx_system_top_root_find(GX_EVENT *in_event);
158 GX_WIDGET      *_gx_system_top_widget_find(GX_WIDGET *root, GX_POINT test_point, ULONG status);
159 
160 #ifdef GX_ENABLE_DEPRECATED_STRING_API
161 UINT    _gx_system_version_string_get(GX_CHAR **return_string);
162 #endif
163 UINT    _gx_system_version_string_get_ext(GX_STRING *return_string);
164 
165 VOID    _gx_system_view_add(GX_WINDOW *win, GX_RECTANGLE *view);
166 GX_BOOL _gx_system_view_fold(GX_WINDOW *win, GX_RECTANGLE *view);
167 VOID    _gx_system_views_free(GX_VIEW *head);
168 VOID    _gx_system_view_split(GX_WINDOW *over, GX_WINDOW_ROOT *root, GX_RECTANGLE *original);
169 VOID    _gx_system_views_update(GX_WINDOW_ROOT *root);
170 UINT    _gx_system_widget_find(USHORT widget_id, INT search_level, GX_WIDGET **return_search_result);
171 
172 
173 /* Define error checking shells for API services.  These are only referenced by the
174    application.  */
175 
176 UINT _gxe_system_active_language_set(GX_UBYTE language);
177 
178 #if (GX_ANIMATION_POOL_SIZE > 0)
179 UINT _gxe_system_animation_get(GX_ANIMATION **animation);
180 UINT _gxe_system_animation_free(GX_ANIMATION *animation);
181 #endif
182 
183 UINT _gxe_system_canvas_refresh(VOID);
184 UINT _gxe_system_dirty_mark(GX_WIDGET *widget);
185 UINT _gxe_system_dirty_partial_add(GX_WIDGET *widget, GX_RECTANGLE *dirty_area);
186 UINT _gxe_system_draw_context_get(GX_DRAW_CONTEXT **current_context);
187 UINT _gxe_system_event_fold(GX_EVENT *event_ptr);
188 UINT _gxe_system_event_send(GX_EVENT *event_ptr);
189 UINT _gxe_system_focus_claim(GX_WIDGET *widget);
190 UINT _gxe_system_initialize(VOID);
191 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
192 UINT _gxe_system_language_table_get(GX_CHAR ****language_table, GX_UBYTE *language_count, UINT *string_count);
193 UINT _gxe_system_language_table_set(GX_CHAR ***string_table, GX_UBYTE language_count, UINT number_of_strings);
194 #endif
195 UINT _gxe_system_memory_allocator_set(VOID *(*allocate)(ULONG size), VOID (*release)(VOID *));
196 UINT _gxe_system_pen_configure(GX_PEN_CONFIGURATION *pen_configuration);
197 UINT _gxe_system_screen_stack_create(GX_WIDGET **memory, INT size, UINT control_block_size);
198 UINT _gxe_system_screen_stack_get(GX_WIDGET **popped_parent, GX_WIDGET **popped_screen);
199 UINT _gxe_system_screen_stack_pop(VOID);
200 UINT _gxe_system_screen_stack_push(GX_WIDGET *screen);
201 UINT _gxe_system_scroll_appearance_get(ULONG style, GX_SCROLLBAR_APPEARANCE *return_appearance);
202 UINT _gxe_system_scroll_appearance_set(ULONG style, GX_SCROLLBAR_APPEARANCE *appearance);
203 UINT _gxe_system_start(VOID);
204 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
205 UINT _gxe_system_string_get(GX_RESOURCE_ID string_id, GX_CONST GX_CHAR **return_string);
206 UINT _gxe_system_string_table_get(GX_UBYTE language, GX_CHAR ***get_table, UINT *get_size);
207 UINT _gxe_system_string_width_get(GX_CONST GX_FONT *font, GX_CONST GX_CHAR *string, INT string_length, GX_VALUE *return_width);
208 #endif
209 UINT _gxe_system_string_width_get_ext(GX_CONST GX_FONT *font, GX_CONST GX_STRING *string, GX_VALUE *return_width);
210 UINT _gxe_system_timer_start(GX_WIDGET *owner, UINT timer_id, UINT initial_ticks, UINT reschedule_ticks);
211 UINT _gxe_system_timer_stop(GX_WIDGET *owner, UINT timer_id);
212 
213 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
214 UINT _gxe_system_version_string_get(GX_CHAR **return_string);
215 #endif
216 UINT _gxe_system_version_string_get_ext(GX_STRING *return_string);
217 UINT _gxe_system_widget_find(USHORT widget_id, INT search_level, GX_WIDGET **return_search_result);
218 
219 /* System management component data declarations follow.  */
220 
221 /* Determine if the initialization function of this component is including
222    this file.  If so, make the data definitions really happen.  Otherwise,
223    make them extern so other functions in the component can access them.  */
224 
225 #ifdef GX_SYSTEM_INIT
226 #define SYSTEM_DECLARE
227 #else
228 #define SYSTEM_DECLARE           extern
229 #endif
230 
231 #define GX_VERSION_STRING_LENGTH 16
232 
233 /* Define string for holding system version information */
234 SYSTEM_DECLARE  GX_CHAR _gx_system_version_string[GX_VERSION_STRING_LENGTH];
235 
236 /* internal structure for implementing gx_system_timer API. */
237 typedef struct GX_TIMER_STRUCT
238 {
239     UINT                    gx_timer_initial_ticks;
240     UINT                    gx_timer_reschedule_ticks;
241     UINT                    gx_timer_id;
242     GX_WIDGET              *gx_timer_owner;
243     struct GX_TIMER_STRUCT *gx_timer_next;
244 } GX_TIMER;
245 
246 /* Define touch configuration information. */
247 SYSTEM_DECLARE GX_PEN_CONFIGURATION _gx_system_pen_configuration;
248 
249 /* Define the created display list head pointer.  */
250 
251 SYSTEM_DECLARE  GX_DISPLAY *_gx_system_display_created_list;
252 
253 /* Define the number of created displays.  */
254 
255 SYSTEM_DECLARE  ULONG _gx_system_display_created_count;
256 
257 /* Define the created canvas list head pointer.  */
258 
259 SYSTEM_DECLARE  GX_CANVAS *_gx_system_canvas_created_list;
260 
261 /* Define the number of created canvases.  */
262 
263 SYSTEM_DECLARE  ULONG _gx_system_canvas_created_count;
264 
265 /* Define the root window list head pointer.  */
266 
267 SYSTEM_DECLARE  GX_WINDOW_ROOT *_gx_system_root_window_created_list;
268 
269 /* define memory for holding nested drawing context */
270 SYSTEM_DECLARE  GX_DRAW_CONTEXT _gx_system_draw_context_stack[GX_MAX_CONTEXT_NESTING];
271 
272 /* define pointer to the current active drawing context */
273 SYSTEM_DECLARE  GX_DRAW_CONTEXT *_gx_system_current_draw_context;
274 
275 /* define pointer to the end of the draw context stack */
276 SYSTEM_DECLARE GX_DRAW_CONTEXT *_gx_system_draw_context_stack_end;
277 
278 /* define storage for GX_TIMERs */
279 
280 SYSTEM_DECLARE GX_TIMER _gx_system_timer_memory[GX_MAX_ACTIVE_TIMERS];
281 
282 /* linked list of running timers */
283 SYSTEM_DECLARE GX_TIMER *_gx_system_active_timer_list;
284 
285 /* linked list of free timers */
286 SYSTEM_DECLARE GX_TIMER *_gx_system_free_timer_list;
287 
288 /* define scratchpad area for storing line end points
289    used by wide line, circle, and arc functions */
290 
291 /* Scratch area. */
292 SYSTEM_DECLARE INT _gx_system_scratchpad[GX_MAX_DISPLAY_HEIGHT * 2];
293 
294 /* Define memory for holding GX_ANIMATION structure pool */
295 #if (GX_ANIMATION_POOL_SIZE > 0)
296 SYSTEM_DECLARE GX_ANIMATION  _gx_system_animation_pool[GX_ANIMATION_POOL_SIZE];
297 SYSTEM_DECLARE GX_ANIMATION *_gx_system_animation_free_list;
298 #endif
299 
300 /* linked list of active animations */
301 SYSTEM_DECLARE GX_ANIMATION *_gx_system_animation_list;
302 
303 /* linked list of created gradients */
304 SYSTEM_DECLARE GX_GRADIENT *_gx_system_gradient_list;
305 
306 /* application defined memory allocation function */
307 SYSTEM_DECLARE VOID * (*_gx_system_memory_allocator)(ULONG);
308 
309 /* application defined memory free function */
310 SYSTEM_DECLARE VOID (*_gx_system_memory_free)(VOID *);
311 
312 /* storage for the system views */
313 
314 SYSTEM_DECLARE GX_VIEW _gx_system_view_memory[GX_MAX_VIEWS];
315 
316 /* linked list of free GX_VIEWS */
317 SYSTEM_DECLARE GX_VIEW *_gx_system_free_views;
318 
319 /* Define pointer to widget that owns input focus */
320 SYSTEM_DECLARE  GX_WIDGET *_gx_system_focus_owner;
321 
322 /* storage for default vertical scrollbar appearance */
323 SYSTEM_DECLARE ULONG                   _gx_system_vertical_scrollbar_style;
324 SYSTEM_DECLARE GX_SCROLLBAR_APPEARANCE _gx_system_vertical_scrollbar_appearance;
325 
326 /* storage for default horizontal scrollbar appearance */
327 SYSTEM_DECLARE ULONG                   _gx_system_horizontal_scrollbar_style;
328 SYSTEM_DECLARE GX_SCROLLBAR_APPEARANCE _gx_system_horizontal_scrollbar_appearance;
329 
330 /* stack of input owners */
331 
332 SYSTEM_DECLARE  GX_WIDGET *_gx_system_input_capture_stack[GX_MAX_INPUT_CAPTURE_NESTING];
333 SYSTEM_DECLARE  GX_WIDGET *_gx_system_input_owner;
334 SYSTEM_DECLARE  INT        _gx_system_capture_count;
335 
336 /* stack of rich text context. */
337 SYSTEM_DECLARE  GX_RICH_TEXT_CONTEXT_STACK  _gx_system_rich_text_context_stack;
338 
339 /* temporary stack used to save rich text context stack. */
340 SYSTEM_DECLARE  GX_RICH_TEXT_CONTEXT_STACK  _gx_system_rich_text_context_stack_save;
341 
342 #ifdef GX_THREADX_BINDING
343 
344 /* guix system thread control block */
345 SYSTEM_DECLARE  TX_THREAD _gx_system_thread;
346 
347 /* guix system thread stack */
348 SYSTEM_DECLARE GX_UBYTE _gx_system_thread_stack[GX_THREAD_STACK_SIZE];
349 
350 /* Keep track of which thread has GUIX locked */
351 
352 SYSTEM_DECLARE  TX_THREAD *_gx_system_lock_thread;
353 
354 /* Keep track of which thread has block input */
355 
356 SYSTEM_DECLARE  TX_THREAD *_gx_system_input_lock_thread;
357 
358 /* Define the system event queue.  */
359 
360 SYSTEM_DECLARE  TX_QUEUE _gx_system_event_queue;
361 
362 /* Define the system protection mutex.  */
363 
364 SYSTEM_DECLARE  TX_MUTEX _gx_system_protect;
365 
366 /* Define the system input lock mutex. */
367 
368 SYSTEM_DECLARE TX_MUTEX _gx_system_input_protect;
369 /* Define the system timer.  */
370 
371 #ifndef GX_DISABLE_THREADX_TIMER_SOURCE
372 SYSTEM_DECLARE  TX_TIMER _gx_system_timer;
373 #endif
374 
375 /* Define the memory area for the system event queue.  */
376 
377 SYSTEM_DECLARE  GX_UBYTE _gx_system_event_queue_memory[GX_MAX_QUEUE_EVENTS * GX_EVENT_SIZE];
378 
379 #define         GX_CURRENT_THREAD _tx_thread_identify()
380 
381 #else
382 
383 SYSTEM_DECLARE  VOID *_gx_system_lock_thread;
384 
385 #endif  /* GX_THREADX_BINDING */
386 
387 
388 /* Define the system mutex lock count.  */
389 
390 SYSTEM_DECLARE  UINT _gx_system_lock_nesting;
391 
392 /* Define the system input lock count. */
393 
394 SYSTEM_DECLARE UINT _gx_system_input_lock_nesting;
395 
396 /* Define variables for tracking pen speed */
397 SYSTEM_DECLARE ULONG    _gx_system_last_clock;
398 SYSTEM_DECLARE LONG     _gx_system_clock_delta;
399 SYSTEM_DECLARE GX_POINT _gx_system_last_pen_point;
400 SYSTEM_DECLARE INT      _gx_system_pen_speed_x;
401 SYSTEM_DECLARE INT      _gx_system_pen_speed_y;
402 
403 #if defined(GX_DYNAMIC_BIDI_TEXT_SUPPORT)
404 /* Define text style. */
405 SYSTEM_DECLARE GX_BOOL _gx_system_bidi_text_enabled;
406 #endif
407 
408 #if defined(GX_THAI_GLYPH_SHAPING_SUPPORT)
409 SYSTEM_DECLARE GX_UBYTE _gx_system_text_render_style;
410 #endif
411 
412 /* Define the theme table */
413 SYSTEM_DECLARE GX_CONST GX_THEME **_gx_system_theme_table;
414 
415 /* Define the theme table size.  */
416 SYSTEM_DECLARE  GX_RESOURCE_ID _gx_system_theme_table_size;
417 
418 /* Define the active theme.  */
419 SYSTEM_DECLARE GX_RESOURCE_ID _gx_system_active_theme;
420 
421 /* Define the storage for the last system error code.  */
422 
423 SYSTEM_DECLARE  UINT _gx_system_last_error;
424 
425 /* Define the number of system errors.  */
426 
427 SYSTEM_DECLARE  ULONG                  _gx_system_error_count;
428 
429 SYSTEM_DECLARE VOID                   *_gx_system_clipboard;
430 SYSTEM_DECLARE UINT                    _gx_system_clipboard_size;
431 
432 SYSTEM_DECLARE GX_SCREEN_STACK_CONTROL _gx_system_screen_stack;
433 
434 #endif
435 
436