GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_widget_resize.c Lines: 43 43 100.0 %
Date: 2026-03-06 19:21:09 Branches: 26 26 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
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_widget_resize                                   PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function  resizes the widget.                                  */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    widget                                Pointer to widget             */
50
/*    new_size                              New widget size               */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    status                                Completion status             */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _gx_utility_rectangle_compare          Compares two rectangles      */
59
/*    _gx_utility_rectangle_inside_detect    Detect if a second rectangle */
60
/*                                             is completely within the   */
61
/*                                             first one                  */
62
/*    _gx_system_dirty_partial_add           Add dirty area               */
63
/*    _gx_utility_rectangle_combine          Combines two rectangles      */
64
/*    _gx_widget_client_get                  Retrieves client area        */
65
/*    _gx_widget_shift                       Changes the position of      */
66
/*                                             a widget                   */
67
/*    _gx_widget_clipping_update             Update the clipping members  */
68
/*                                             of each child widget       */
69
/*    _gx_widget_event_process_function      Indirect call to widget      */
70
/*                                             event processing function  */
71
/*                                                                        */
72
/*  CALLED BY                                                             */
73
/*                                                                        */
74
/*    Application Code                                                    */
75
/*    GUIX Internal Code                                                  */
76
/*                                                                        */
77
/**************************************************************************/
78
47829
UINT  _gx_widget_resize(GX_WIDGET *widget, GX_RECTANGLE *new_size)
79
{
80
GX_WIDGET      *child;
81
GX_WINDOW      *win;
82
GX_WINDOW_ROOT *root;
83
GX_RECTANGLE    area_sum;
84
GX_VALUE        LeftShift;
85
GX_VALUE        TopShift;
86
GX_VALUE        RightShift;
87
GX_VALUE        BottomShift;
88
GX_EVENT        new_event;
89
90
    /* first, check to see if the old and new size are the same */
91
92
47829
    if (_gx_utility_rectangle_compare(&widget -> gx_widget_size, new_size))
93
    {
94
25888
        return GX_SUCCESS;
95
    }
96
97
21941
    if (widget -> gx_widget_status & GX_STATUS_VISIBLE)
98
    {
99
        /* If my new size encompasses my old size, then I just need to
100
           mark myself as dirty
101
         */
102
10539
        if (_gx_utility_rectangle_inside_detect(new_size, &widget -> gx_widget_size))
103
        {
104
1592
            _gx_system_dirty_partial_add(widget, new_size);
105
        }
106
        else
107
        {
108
            /* here if my new size is smaller or in a different position,
109
               I need to mark my parent as dirty
110
             */
111
8947
            area_sum = *new_size;
112
8947
            _gx_utility_rectangle_combine(&area_sum, &widget -> gx_widget_size);
113
8947
            _gx_system_dirty_partial_add(widget -> gx_widget_parent, &area_sum);
114
        }
115
    }
116
117
    /* keep track of how far I am shifting */
118
21941
    LeftShift = (GX_VALUE)(new_size -> gx_rectangle_left - widget -> gx_widget_size.gx_rectangle_left);
119
21941
    TopShift = (GX_VALUE)(new_size -> gx_rectangle_top - widget -> gx_widget_size.gx_rectangle_top);
120
21941
    RightShift = (GX_VALUE)(new_size -> gx_rectangle_right - widget -> gx_widget_size.gx_rectangle_right);
121
21941
    BottomShift = (GX_VALUE)(new_size -> gx_rectangle_bottom - widget -> gx_widget_size.gx_rectangle_bottom);
122
123
    /* reset my size */
124
21941
    widget -> gx_widget_size = *new_size;
125
126
    /* if I am a window, update my client area */
127
128
21941
    if (widget -> gx_widget_type >= GX_TYPE_WINDOW)
129
    {
130
432
        win = (GX_WINDOW *)widget;
131
432
        win -> gx_window_client.gx_rectangle_left   = (GX_VALUE)(win -> gx_window_client.gx_rectangle_left + LeftShift);
132
432
        win -> gx_window_client.gx_rectangle_top    = (GX_VALUE)(win -> gx_window_client.gx_rectangle_top + TopShift);
133
432
        win -> gx_window_client.gx_rectangle_right  = (GX_VALUE)(win -> gx_window_client.gx_rectangle_right + RightShift);
134
432
        win -> gx_window_client.gx_rectangle_bottom = (GX_VALUE)(win -> gx_window_client.gx_rectangle_bottom + BottomShift);
135
136
        /* if parent is root window, then viewports need to be updated */
137
432
        if (widget -> gx_widget_parent)
138
        {
139
289
            if (widget -> gx_widget_parent -> gx_widget_type == GX_TYPE_ROOT_WINDOW)
140
            {
141
18
                root = (GX_WINDOW_ROOT *)widget -> gx_widget_parent;
142
18
                root -> gx_window_root_views_changed = GX_TRUE;
143
            }
144
        }
145
    }
146
147
    /* if my top-left shifted, I need to move my child widgets */
148
149

21941
    if (LeftShift || TopShift)
150
    {
151
        /* pick up pointer to first child widget */
152
12811
        child = widget -> gx_widget_first_child;
153
154
        /* loop through and shift all my child widgets */
155
156
16711
        while (child)
157
        {
158
3900
            _gx_widget_shift(child, LeftShift, TopShift, GX_FALSE);
159
3900
            child = child -> gx_widget_next;
160
        }
161
    }
162
163
21941
    if (widget -> gx_widget_type >= GX_TYPE_WINDOW)
164
    {
165
        /* tell all my child widgets that I have been re-sized */
166
432
        new_event.gx_event_type = GX_EVENT_PARENT_SIZED;
167
432
        child = widget -> gx_widget_first_child;
168
169
1494
        while (child)
170
        {
171
1062
            child -> gx_widget_event_process_function(child, &new_event);
172
1062
            child = child -> gx_widget_next;
173
        }
174
    }
175
176
21941
    if (widget -> gx_widget_status & GX_STATUS_VISIBLE)
177
    {
178
179
        /* update this widget clip rectangle */
180
10539
        _gx_widget_clipping_update(widget);
181
182
10539
        if (widget -> gx_widget_status & GX_STATUS_RESIZE_NOTIFY)
183
        {
184
            /* Notify widget of size change.  */
185
624
            memset(&new_event, 0, sizeof(GX_EVENT));
186
624
            new_event.gx_event_target = widget;
187
624
            new_event.gx_event_type = GX_EVENT_RESIZED;
188
624
            _gx_system_event_fold(&new_event);
189
        }
190
    }
191
21941
    return(GX_SUCCESS);
192
}
193