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 /**   Widget Management (Widget)                                          */
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_utility.h"
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _gx_widget_delete_helper                            PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function safely destroys a widget.                             */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    widget                                Widget control block          */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    status                                Completion status             */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    _gx_widget_unlink                     Unlink a widget               */
57 /*    _gx_system_private_string_delete      Delete string copy            */
58 /*    _gx_system_dirty_list_remove          Trims the dirty list          */
59 /*    _gx_system_timer_stop                 Stop timers owned by widget   */
60 /*    _gx_widget_free                       Free memory owned by widget   */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application Code                                                    */
65 /*    GUIX Internal Code                                                  */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
72 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
73 /*                                            removed private string      */
74 /*                                            delete,                     */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_gx_widget_delete_helper(GX_WIDGET * widget)78 static VOID _gx_widget_delete_helper(GX_WIDGET *widget)
79 {
80 GX_EVENT delete_event;
81 
82     delete_event.gx_event_type = GX_EVENT_DELETE;
83     delete_event.gx_event_target = widget;
84     widget -> gx_widget_event_process_function(widget, &delete_event);
85 
86     _gx_widget_unlink(widget);
87 
88     /* now delete top-level widget */
89     widget -> gx_widget_type = 0;
90 
91     /* this widget cannot have dirty list entries */
92     _gx_system_dirty_list_remove(widget);
93 
94     /* this widget cannot have timers */
95     _gx_system_timer_stop(widget, 0);
96 
97     /* this widget cannot have events */
98     _gx_system_event_remove(widget);
99 
100     /* test for deleting focus widget */
101     if (_gx_system_focus_owner == widget)
102     {
103         _gx_system_focus_owner = GX_NULL;
104     }
105 
106     if (widget -> gx_widget_status & GX_STATUS_DYNAMICALLY_ALLOCATED)
107     {
108         _gx_widget_free(widget);
109     }
110     else
111     {
112         widget -> gx_widget_id = 0;
113         widget -> gx_widget_status = 0;
114     }
115 }
116 
117 
118 /**************************************************************************/
119 /*                                                                        */
120 /*  FUNCTION                                               RELEASE        */
121 /*                                                                        */
122 /*    _gx_widget_delete                                   PORTABLE C      */
123 /*                                                           6.1          */
124 /*  AUTHOR                                                                */
125 /*                                                                        */
126 /*    Kenneth Maxwell, Microsoft Corporation                              */
127 /*                                                                        */
128 /*  DESCRIPTION                                                           */
129 /*                                                                        */
130 /*    This function delete a widget tree.                                 */
131 /*                                                                        */
132 /*  INPUT                                                                 */
133 /*                                                                        */
134 /*    widget                                Widget control block          */
135 /*                                                                        */
136 /*  OUTPUT                                                                */
137 /*                                                                        */
138 /*    status                                Completion status             */
139 /*                                                                        */
140 /*  CALLS                                                                 */
141 /*                                                                        */
142 /*    _gx_system_lock                       Lock access to GUIX           */
143 /*    _gx_widget_delete_helper              Safely delete widget instance */
144 /*    _gx_widget_free                       Free memory owned by widget   */
145 /*                                                                        */
146 /*  CALLED BY                                                             */
147 /*                                                                        */
148 /*    Application Code                                                    */
149 /*    GUIX Internal Code                                                  */
150 /*                                                                        */
151 /*  RELEASE HISTORY                                                       */
152 /*                                                                        */
153 /*    DATE              NAME                      DESCRIPTION             */
154 /*                                                                        */
155 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
156 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
157 /*                                            resulting in version 6.1    */
158 /*                                                                        */
159 /**************************************************************************/
_gx_widget_delete(GX_WIDGET * widget)160 UINT  _gx_widget_delete(GX_WIDGET *widget)
161 {
162 GX_WIDGET *child;
163 
164     /* lock access to GUIX */
165     GX_ENTER_CRITICAL
166 
167     /* first delete widget children */
168     while (widget -> gx_widget_first_child)
169     {
170         child = widget -> gx_widget_first_child;
171         while (child -> gx_widget_first_child)
172         {
173             child = child -> gx_widget_first_child;
174         }
175 
176         _gx_widget_delete_helper(child);
177     }
178     _gx_widget_delete_helper(widget);
179 
180     /* Release the protection.  */
181     GX_EXIT_CRITICAL
182 
183     /* Return successful status.  */
184     return(GX_SUCCESS);
185 }
186 
187