GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_widget_delete.c Lines: 26 26 100.0 %
Date: 2026-03-06 19:21:09 Branches: 8 8 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
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_widget_delete_helper                            PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function safely destroys a widget.                             */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    widget                                Widget control block          */
49
/*                                                                        */
50
/*  OUTPUT                                                                */
51
/*                                                                        */
52
/*    status                                Completion status             */
53
/*                                                                        */
54
/*  CALLS                                                                 */
55
/*                                                                        */
56
/*    _gx_widget_unlink                     Unlink a widget               */
57
/*    _gx_system_private_string_delete      Delete string copy            */
58
/*    _gx_system_dirty_list_remove          Trims the dirty list          */
59
/*    _gx_system_timer_stop                 Stop timers owned by widget   */
60
/*    _gx_widget_free                       Free memory owned by widget   */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    Application Code                                                    */
65
/*    GUIX Internal Code                                                  */
66
/*                                                                        */
67
/**************************************************************************/
68
331
static VOID _gx_widget_delete_helper(GX_WIDGET *widget)
69
{
70
GX_EVENT delete_event;
71
72
331
    delete_event.gx_event_type = GX_EVENT_DELETE;
73
331
    delete_event.gx_event_target = widget;
74
331
    widget -> gx_widget_event_process_function(widget, &delete_event);
75
76
331
    _gx_widget_unlink(widget);
77
78
    /* now delete top-level widget */
79
331
    widget -> gx_widget_type = 0;
80
81
    /* this widget cannot have dirty list entries */
82
331
    _gx_system_dirty_list_remove(widget);
83
84
    /* this widget cannot have timers */
85
331
    _gx_system_timer_stop(widget, 0);
86
87
    /* this widget cannot have events */
88
331
    _gx_system_event_remove(widget);
89
90
    /* test for deleting focus widget */
91
331
    if (_gx_system_focus_owner == widget)
92
    {
93
1
        _gx_system_focus_owner = GX_NULL;
94
    }
95
96
331
    if (widget -> gx_widget_status & GX_STATUS_DYNAMICALLY_ALLOCATED)
97
    {
98
38
        _gx_widget_free(widget);
99
    }
100
    else
101
    {
102
293
        widget -> gx_widget_id = 0;
103
293
        widget -> gx_widget_status = 0;
104
    }
105
331
}
106
107
108
/**************************************************************************/
109
/*                                                                        */
110
/*  FUNCTION                                               RELEASE        */
111
/*                                                                        */
112
/*    _gx_widget_delete                                   PORTABLE C      */
113
/*                                                           6.1          */
114
/*  AUTHOR                                                                */
115
/*                                                                        */
116
/*    Kenneth Maxwell, Microsoft Corporation                              */
117
/*                                                                        */
118
/*  DESCRIPTION                                                           */
119
/*                                                                        */
120
/*    This function delete a widget tree.                                 */
121
/*                                                                        */
122
/*  INPUT                                                                 */
123
/*                                                                        */
124
/*    widget                                Widget control block          */
125
/*                                                                        */
126
/*  OUTPUT                                                                */
127
/*                                                                        */
128
/*    status                                Completion status             */
129
/*                                                                        */
130
/*  CALLS                                                                 */
131
/*                                                                        */
132
/*    GX_ENTER_CRITICAL                     Lock access to GUIX           */
133
/*    _gx_widget_delete_helper              Safely delete widget instance */
134
/*    _gx_widget_free                       Free memory owned by widget   */
135
/*    GX_EXIT_CRITICAL                      Release the protection        */
136
/*                                                                        */
137
/*  CALLED BY                                                             */
138
/*                                                                        */
139
/*    Application Code                                                    */
140
/*    GUIX Internal Code                                                  */
141
/*                                                                        */
142
/**************************************************************************/
143
98
UINT  _gx_widget_delete(GX_WIDGET *widget)
144
{
145
GX_WIDGET *child;
146
147
    /* lock access to GUIX */
148
98
    GX_ENTER_CRITICAL
149
150
    /* first delete widget children */
151
331
    while (widget -> gx_widget_first_child)
152
    {
153
233
        child = widget -> gx_widget_first_child;
154
316
        while (child -> gx_widget_first_child)
155
        {
156
83
            child = child -> gx_widget_first_child;
157
        }
158
159
233
        _gx_widget_delete_helper(child);
160
    }
161
98
    _gx_widget_delete_helper(widget);
162
163
    /* Release the protection.  */
164
98
    GX_EXIT_CRITICAL
165
166
    /* Return successful status.  */
167
98
    return(GX_SUCCESS);
168
}
169