GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_widget_link.c Lines: 16 16 100.0 %
Date: 2026-03-06 19:21:09 Branches: 10 10 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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
/**************************************************************************/
66
154966
VOID _gx_widget_link(GX_WIDGET *parent, GX_WIDGET *widget)
67
{
68
GX_WIDGET *sibling;
69
70
    /* if this widget already has a different parent, then first unlink it */
71
154966
    if (widget -> gx_widget_parent)
72
    {
73
1278
        if (widget -> gx_widget_parent == parent)
74
        {
75
            /* already linked as child of this parent, nothing to do */
76
1275
            return;
77
        }
78
3
        _gx_widget_unlink(widget);
79
    }
80
81
    /* Determine if a parent widget was provided.  */
82
153691
    if (parent)
83
    {
84
        /* Yes, is there already a child for this parent?  */
85
153690
        if (parent -> gx_widget_first_child)
86
        {
87
            /* Yes, find the last child.  */
88
106223
            sibling =  parent -> gx_widget_last_child;
89
90
            /* Put this widget at the end of the list.  */
91
106223
            sibling -> gx_widget_next =     widget;
92
106223
            widget -> gx_widget_previous =  sibling;
93
106223
            widget -> gx_widget_next = NULL;
94
        }
95
        else
96
        {
97
98
            /* First child, simply add the widget.  */
99
47467
            parent -> gx_widget_first_child =  widget;
100
        }
101
102
        /* Setup the last child pointer and remember the parent widget.  */
103
153690
        parent -> gx_widget_last_child = widget;
104
153690
        widget -> gx_widget_parent = parent;
105
106
153690
        if (parent -> gx_widget_status & GX_STATUS_VISIBLE)
107
        {
108
1942
            _gx_widget_show(widget);
109
        }
110
    }
111
}
112