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