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 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _gx_widget_unlink                                   PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function unlinks a widget.                                     */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    widget                                Widget control block          */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    GX_WIDET *                            Widget being unlinked         */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    GUIX Internal Code                                                  */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
68 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*                                                                        */
71 /**************************************************************************/
_gx_widget_unlink(GX_WIDGET * widget)72 GX_WIDGET *_gx_widget_unlink(GX_WIDGET *widget)
73 {
74 
75 GX_WIDGET *sibling;
76 GX_WIDGET *parent;
77 
78     /* Determine if the widget has a parent.  */
79     parent = widget -> gx_widget_parent;
80 
81     if (parent)
82     {
83         /* Is this widget the first child? */
84         if (parent -> gx_widget_first_child == widget)
85         {
86             /* Yes, unlink and done*/
87             parent -> gx_widget_first_child = widget -> gx_widget_next;
88             if (parent -> gx_widget_first_child)
89             {
90                 parent -> gx_widget_first_child -> gx_widget_previous = GX_NULL;
91             }
92 
93             /* if last was also pointing at this widget, then it was the only
94                child. Update last pointer: */
95             if (parent -> gx_widget_last_child == widget)
96             {
97                 parent -> gx_widget_last_child = parent -> gx_widget_first_child;
98             }
99         }
100         else
101         {
102             sibling = parent -> gx_widget_first_child;
103 
104             while (sibling -> gx_widget_next != widget)
105             {
106                 sibling = sibling -> gx_widget_next;
107             }
108             sibling -> gx_widget_next = widget -> gx_widget_next;
109 
110             if (parent -> gx_widget_last_child == widget)
111             {
112                 parent -> gx_widget_last_child = sibling;
113             }
114 
115             if (sibling -> gx_widget_next)
116             {
117                 sibling -> gx_widget_next -> gx_widget_previous = sibling;
118             }
119         }
120         if (widget -> gx_widget_status & GX_STATUS_VISIBLE)
121         {
122             _gx_widget_hide(widget);
123         }
124         widget -> gx_widget_parent = GX_NULL;
125         widget -> gx_widget_next = GX_NULL;
126         widget -> gx_widget_previous = GX_NULL;
127         widget -> gx_widget_nav_next = GX_NULL;
128         widget -> gx_widget_nav_previous = GX_NULL;
129     }
130     /* Return widget pointer  */
131     return(widget);
132 }
133 
134