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_link                                     PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function links a child widget to it's parent                   */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    parent                                The parent widget             */
50 /*    widget                                The child widget              */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    status                                Completion status             */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _gx_widget_unlink                     Unlink from previous parent   */
59 /*    _gx_widget_show                       Show the widget               */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    GUIX Internal Code                                                  */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
70 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_gx_widget_link(GX_WIDGET * parent,GX_WIDGET * widget)74 VOID _gx_widget_link(GX_WIDGET *parent, GX_WIDGET *widget)
75 {
76 GX_WIDGET *sibling;
77 
78     /* if this widget already has a different parent, then first unlink it */
79     if (widget -> gx_widget_parent)
80     {
81         if (widget -> gx_widget_parent == parent)
82         {
83             /* already linked as child of this parent, nothing to do */
84             return;
85         }
86         _gx_widget_unlink(widget);
87     }
88 
89     /* Determine if a parent widget was provided.  */
90     if (parent)
91     {
92         /* Yes, is there already a child for this parent?  */
93         if (parent -> gx_widget_first_child)
94         {
95             /* Yes, find the last child.  */
96             sibling =  parent -> gx_widget_last_child;
97 
98             /* Put this widget at the end of the list.  */
99             sibling -> gx_widget_next =     widget;
100             widget -> gx_widget_previous =  sibling;
101             widget -> gx_widget_next = NULL;
102         }
103         else
104         {
105 
106             /* First child, simply add the widget.  */
107             parent -> gx_widget_first_child =  widget;
108         }
109 
110         /* Setup the last child pointer and remember the parent widget.  */
111         parent -> gx_widget_last_child = widget;
112         widget -> gx_widget_parent = parent;
113 
114         if (parent -> gx_widget_status & GX_STATUS_VISIBLE)
115         {
116             _gx_widget_show(widget);
117         }
118     }
119 }
120 
121