GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_widget_front_move.c Lines: 35 35 100.0 %
Date: 2026-03-06 19:21:09 Branches: 24 24 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_utility.h"
30
#include "gx_widget.h"
31
#include "gx_window.h"
32
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_widget_front_move                               PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function moves the widget to the front.                        */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    widget                                Pointer to widget to move     */
51
/*    return_moved                          Pointer to destination for    */
52
/*                                            indication widget was moved */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    status                                Completion status             */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _gx_system_dirty_partial_add          Add dirty area                */
61
/*    _gx_utility_rectangle_combine         Combine rectangles            */
62
/*    _gx_utility_rectangle_define          Define rectangle              */
63
/*    _gx_utility_rectangle_overlap_detect  Check for overlap             */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    Application Code                                                    */
68
/*    GUIX Internal Code                                                  */
69
/*                                                                        */
70
/**************************************************************************/
71
4703
UINT  _gx_widget_front_move(GX_WIDGET *widget, GX_BOOL *return_moved)
72
{
73
GX_WIDGET   *parent;
74
GX_WIDGET   *sibling;
75
GX_RECTANGLE dirty_area;
76
GX_RECTANGLE overlap;
77
78
    /* Pickup parent widget.  */
79
4703
    parent =  widget -> gx_widget_parent;
80
81
    /* Is parent valid?  */
82
4703
    if (!parent)
83
    {
84
85
        /* Return error.  */
86
1
        return(GX_PTR_ERROR);
87
    }
88
89
    /* First check to see if the widget is already in front.  */
90
4702
    if (parent -> gx_widget_last_child == widget)
91
    {
92
93
        /* Yes, widget is already in front, so nothing to do.  */
94
95
        /* Return no change.  */
96
3714
        return(GX_NO_CHANGE);
97
    }
98
99
    /* Relink widget to the end
100
        1) Determine what to dirty, all or partial
101
        2) unlink and stitch linked list
102
        3) relink to the end
103
        4) call dirty so that I will get redraw
104
     */
105
988
    _gx_utility_rectangle_define(&dirty_area, GX_VALUE_MAX, GX_VALUE_MAX, -1, -1);
106
107
    /* Pickup sibling widget.  */
108
988
    sibling =  widget -> gx_widget_next;
109
110
    /* Traverse the sibling list.  */
111
5683
    while (sibling)
112
    {
113
        /* Check for an overlap of siblings.  */
114
4695
        if (_gx_utility_rectangle_overlap_detect(&widget -> gx_widget_size, &sibling -> gx_widget_size, &overlap))
115
        {
116
            /* Yes, calculate the dirty area.  */
117
425
            if (dirty_area.gx_rectangle_left > dirty_area.gx_rectangle_right)
118
            {
119
226
                dirty_area = overlap;
120
            }
121
            else
122
            {
123
199
                _gx_utility_rectangle_combine(&dirty_area, &overlap);
124
            }
125
        }
126
127
        /* Move to next sibling.  */
128
4695
        sibling =  sibling -> gx_widget_next;
129
    }
130
131
132
988
    if (dirty_area.gx_rectangle_left <= dirty_area.gx_rectangle_right)
133
    {
134
135
        /* Add dirty area.  */
136
226
        _gx_system_dirty_partial_add(widget, &dirty_area);
137
    }
138
139
    /* Is widget the first child of it's parent?  */
140
988
    if (parent -> gx_widget_first_child == widget)
141
    {
142
        /* Yes, the first child, easy remove the first child.  */
143
433
        parent -> gx_widget_first_child =  widget -> gx_widget_next;
144
433
        widget -> gx_widget_next -> gx_widget_previous =  NULL;
145
    }
146
    else
147
    {
148
        /* No, not the first child. Remove from the middle.  */
149
555
        widget -> gx_widget_previous -> gx_widget_next =  widget -> gx_widget_next;
150
555
        widget -> gx_widget_next -> gx_widget_previous =  widget -> gx_widget_previous;
151
    }
152
153
    /* Link the widget to the end of the list.  */
154
155
988
    sibling  =  parent -> gx_widget_last_child;
156
988
    sibling -> gx_widget_next =  widget;
157
988
    widget  -> gx_widget_previous =  sibling;
158
988
    widget  -> gx_widget_next =  NULL;
159
988
    parent  -> gx_widget_last_child =  widget;
160
161
988
    if (widget -> gx_widget_type >= GX_TYPE_WINDOW)
162
    {
163
        /* if parent is root window, then viewports need to be updated */
164
869
        _gx_window_view_update_detect((GX_WINDOW *)widget);
165
166
        /* if window accepts focus and parent has focus, focus should be moved */
167
869
        if (parent -> gx_widget_status & GX_STATUS_HAS_FOCUS &&
168
868
            (widget -> gx_widget_status & GX_STATUS_ACCEPTS_FOCUS) &&
169
867
            !(widget -> gx_widget_status & GX_STATUS_HAS_FOCUS))
170
        {
171
2
            _gx_system_focus_claim(widget);
172
        }
173
    }
174
175
176
    /* Indicate the widget was moved.  */
177
178
988
    if (return_moved)
179
    {
180
7
        *return_moved =  GX_TRUE;
181
    }
182
183
    /* Return successful completion.  */
184
988
    return(GX_SUCCESS);
185
}
186