GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_widget_link.c Lines: 16 16 100.0 %
Date: 2024-12-05 08:52:37 Branches: 10 10 100.0 %

Line Branch Exec Source
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
/**   Widget Management (Widget)                                          */
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_widget.h"
29
#include "gx_utility.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_widget_link                                     PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function links a child widget to it's parent                   */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    parent                                The parent widget             */
49
/*    widget                                The child widget              */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    status                                Completion status             */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    _gx_widget_unlink                     Unlink from previous parent   */
58
/*    _gx_widget_show                       Show the widget               */
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
/**************************************************************************/
73
154968
VOID _gx_widget_link(GX_WIDGET *parent, GX_WIDGET *widget)
74
{
75
GX_WIDGET *sibling;
76
77
    /* if this widget already has a different parent, then first unlink it */
78
154968
    if (widget -> gx_widget_parent)
79
    {
80
1278
        if (widget -> gx_widget_parent == parent)
81
        {
82
            /* already linked as child of this parent, nothing to do */
83
1275
            return;
84
        }
85
3
        _gx_widget_unlink(widget);
86
    }
87
88
    /* Determine if a parent widget was provided.  */
89
153693
    if (parent)
90
    {
91
        /* Yes, is there already a child for this parent?  */
92
153692
        if (parent -> gx_widget_first_child)
93
        {
94
            /* Yes, find the last child.  */
95
106225
            sibling =  parent -> gx_widget_last_child;
96
97
            /* Put this widget at the end of the list.  */
98
106225
            sibling -> gx_widget_next =     widget;
99
106225
            widget -> gx_widget_previous =  sibling;
100
106225
            widget -> gx_widget_next = NULL;
101
        }
102
        else
103
        {
104
105
            /* First child, simply add the widget.  */
106
47467
            parent -> gx_widget_first_child =  widget;
107
        }
108
109
        /* Setup the last child pointer and remember the parent widget.  */
110
153692
        parent -> gx_widget_last_child = widget;
111
153692
        widget -> gx_widget_parent = parent;
112
113
153692
        if (parent -> gx_widget_status & GX_STATUS_VISIBLE)
114
        {
115
1944
            _gx_widget_show(widget);
116
        }
117
    }
118
}
119