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_utility.h"
29 #include "gx_widget.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _gx_widget_resize PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Kenneth Maxwell, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function resizes the widget. */
45 /* */
46 /* INPUT */
47 /* */
48 /* widget Pointer to widget */
49 /* new_size New widget size */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* status Completion status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _gx_utility_rectangle_compare Compares two rectangles */
58 /* _gx_utility_rectangle_inside_detect Detect if a second rectangle */
59 /* is completely within the */
60 /* first one */
61 /* _gx_system_dirty_partial_add Add dirty area */
62 /* _gx_utility_rectangle_combine Combines two rectangles */
63 /* _gx_widget_client_get Retrieves client area */
64 /* _gx_widget_shift Changes the position of */
65 /* a widget */
66 /* _gx_widget_clipping_update Update the clipping members */
67 /* of each child widget */
68 /* _gx_widget_event_process_function Indirect call to widget */
69 /* event processing function */
70 /* */
71 /* CALLED BY */
72 /* */
73 /* Application Code */
74 /* GUIX Internal Code */
75 /* */
76 /* RELEASE HISTORY */
77 /* */
78 /* DATE NAME DESCRIPTION */
79 /* */
80 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
81 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
82 /* resulting in version 6.1 */
83 /* */
84 /**************************************************************************/
_gx_widget_resize(GX_WIDGET * widget,GX_RECTANGLE * new_size)85 UINT _gx_widget_resize(GX_WIDGET *widget, GX_RECTANGLE *new_size)
86 {
87 GX_WIDGET *child;
88 GX_WINDOW *win;
89 GX_WINDOW_ROOT *root;
90 GX_RECTANGLE area_sum;
91 GX_VALUE LeftShift;
92 GX_VALUE TopShift;
93 GX_VALUE RightShift;
94 GX_VALUE BottomShift;
95 GX_EVENT new_event;
96
97 /* first, check to see if the old and new size are the same */
98
99 if (_gx_utility_rectangle_compare(&widget -> gx_widget_size, new_size))
100 {
101 return GX_SUCCESS;
102 }
103
104 if (widget -> gx_widget_status & GX_STATUS_VISIBLE)
105 {
106 /* If my new size encompasses my old size, then I just need to
107 mark myself as dirty
108 */
109 if (_gx_utility_rectangle_inside_detect(new_size, &widget -> gx_widget_size))
110 {
111 _gx_system_dirty_partial_add(widget, new_size);
112 }
113 else
114 {
115 /* here if my new size is smaller or in a different position,
116 I need to mark my parent as dirty
117 */
118 area_sum = *new_size;
119 _gx_utility_rectangle_combine(&area_sum, &widget -> gx_widget_size);
120 _gx_system_dirty_partial_add(widget -> gx_widget_parent, &area_sum);
121 }
122 }
123
124 /* keep track of how far I am shifting */
125 LeftShift = (GX_VALUE)(new_size -> gx_rectangle_left - widget -> gx_widget_size.gx_rectangle_left);
126 TopShift = (GX_VALUE)(new_size -> gx_rectangle_top - widget -> gx_widget_size.gx_rectangle_top);
127 RightShift = (GX_VALUE)(new_size -> gx_rectangle_right - widget -> gx_widget_size.gx_rectangle_right);
128 BottomShift = (GX_VALUE)(new_size -> gx_rectangle_bottom - widget -> gx_widget_size.gx_rectangle_bottom);
129
130 /* reset my size */
131 widget -> gx_widget_size = *new_size;
132
133 /* if I am a window, update my client area */
134
135 if (widget -> gx_widget_type >= GX_TYPE_WINDOW)
136 {
137 win = (GX_WINDOW *)widget;
138 win -> gx_window_client.gx_rectangle_left = (GX_VALUE)(win -> gx_window_client.gx_rectangle_left + LeftShift);
139 win -> gx_window_client.gx_rectangle_top = (GX_VALUE)(win -> gx_window_client.gx_rectangle_top + TopShift);
140 win -> gx_window_client.gx_rectangle_right = (GX_VALUE)(win -> gx_window_client.gx_rectangle_right + RightShift);
141 win -> gx_window_client.gx_rectangle_bottom = (GX_VALUE)(win -> gx_window_client.gx_rectangle_bottom + BottomShift);
142
143 /* if parent is root window, then viewports need to be updated */
144 if (widget -> gx_widget_parent)
145 {
146 if (widget -> gx_widget_parent -> gx_widget_type == GX_TYPE_ROOT_WINDOW)
147 {
148 root = (GX_WINDOW_ROOT *)widget -> gx_widget_parent;
149 root -> gx_window_root_views_changed = GX_TRUE;
150 }
151 }
152 }
153
154 /* if my top-left shifted, I need to move my child widgets */
155
156 if (LeftShift || TopShift)
157 {
158 /* pick up pointer to first child widget */
159 child = widget -> gx_widget_first_child;
160
161 /* loop through and shift all my child widgets */
162
163 while (child)
164 {
165 _gx_widget_shift(child, LeftShift, TopShift, GX_FALSE);
166 child = child -> gx_widget_next;
167 }
168 }
169
170 if (widget -> gx_widget_type >= GX_TYPE_WINDOW)
171 {
172 /* tell all my child widgets that I have been re-sized */
173 new_event.gx_event_type = GX_EVENT_PARENT_SIZED;
174 child = widget -> gx_widget_first_child;
175
176 while (child)
177 {
178 child -> gx_widget_event_process_function(child, &new_event);
179 child = child -> gx_widget_next;
180 }
181 }
182
183 if (widget -> gx_widget_status & GX_STATUS_VISIBLE)
184 {
185
186 /* update this widget clip rectangle */
187 _gx_widget_clipping_update(widget);
188
189 if (widget -> gx_widget_status & GX_STATUS_RESIZE_NOTIFY)
190 {
191 /* Notify widget of size change. */
192 memset(&new_event, 0, sizeof(GX_EVENT));
193 new_event.gx_event_target = widget;
194 new_event.gx_event_type = GX_EVENT_RESIZED;
195 _gx_system_event_fold(&new_event);
196 }
197 }
198 return(GX_SUCCESS);
199 }
200
201