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