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 #define GX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_system.h"
28 #include "gx_utility.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _gx_system_all_views_free                           PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Kenneth Maxwell, Microsoft Corporation                              */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function releaes the views attached to the given root window   */
44 /*    and it's chilren back to the free list.                             */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    root                                  Root window that needs to     */
49 /*                                            have it's views released    */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    views owned by this root and children are returned to free list     */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*     _gx_system_views_free                Free views for one window     */
58 /*     _gx_system_error_process             Process error code            */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    GUIX Internal Code                                                  */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
69 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
_gx_system_all_views_free(GX_WINDOW_ROOT * root)73 VOID _gx_system_all_views_free(GX_WINDOW_ROOT *root)
74 {
75 #ifndef GX_DISABLE_ERROR_CHECKING
76 int viewcount;
77 #endif
78 
79 GX_VIEW   *test;
80 GX_WIDGET *child;
81 GX_WINDOW *win;
82 
83     /* pick up pointer to first child window */
84     child = root -> gx_widget_first_child;
85 
86     /* free each of the top-level window's views */
87     while (child)
88     {
89         if (child -> gx_widget_type >= GX_TYPE_WINDOW)
90         {
91             win = (GX_WINDOW *)child;
92             test = win -> gx_window_views;
93 
94             /* does this window have any views? */
95 
96             if (test)
97             {
98                 _gx_system_views_free(test);
99                 win -> gx_window_views = GX_NULL;
100             }
101         }
102         child = (child -> gx_widget_next);
103     }
104 
105 
106     /* lastly, free the root window's views */
107 
108     test = root -> gx_window_views;
109 
110     if (test)
111     {
112         _gx_system_views_free(test);
113         root -> gx_window_views = GX_NULL;
114     }
115 
116 #ifndef GX_DISABLE_ERROR_CHECKING
117     test = _gx_system_free_views;
118 
119     viewcount = 0;
120 
121     while (test)
122     {
123         viewcount++;
124         test = test -> gx_view_next;
125     }
126 
127     if (viewcount != GX_MAX_VIEWS)
128     {
129         _gx_system_error_process(GX_SYSTEM_OUT_OF_VIEWS);
130     }
131 #endif
132 }
133 
134