1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
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 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _gx_widget_shift_helper                             PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    Internal helper function to shift one widget and optionally marks   */
46 /*    it as dirty.                                                        */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    widget                                Pointer to widget             */
51 /*    x_shift                               Number of pixels to shift on  */
52 /*                                            the x-axis                  */
53 /*    y_shift                               Number of pixels to shift on  */
54 /*                                            the y-axis                  */
55 /*    mark_dirty                            GX_TRUE to indicate dirty,    */
56 /*                                            otherwise GX_FALSE          */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    status                                Completion status             */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    _gx_utility_rectangle_shift           Adjust a rectangle            */
65 /*    _gx_utility_rectangle_combine         Combine rectangles            */
66 /*    _gx_system_dirty_partial_add          Add area to the dirty list    */
67 /*    _gx_widget_shift                      Shift a widget                */
68 /*                                                                        */
69 /*  CALLED BY                                                             */
70 /*                                                                        */
71 /*    _gx_widget_shift                                                    */
72 /*                                                                        */
73 /*  RELEASE HISTORY                                                       */
74 /*                                                                        */
75 /*    DATE              NAME                      DESCRIPTION             */
76 /*                                                                        */
77 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
78 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
79 /*                                            resulting in version 6.1    */
80 /*                                                                        */
81 /**************************************************************************/
_gx_widget_shift_helper(GX_WIDGET * widget,GX_VALUE x_shift,GX_VALUE y_shift,GX_BOOL mark_dirty)82 static VOID _gx_widget_shift_helper(GX_WIDGET *widget, GX_VALUE x_shift, GX_VALUE y_shift, GX_BOOL mark_dirty)
83 {
84 GX_WINDOW   *win;
85 GX_RECTANGLE area_sum;
86 GX_RECTANGLE newsize;
87 GX_EVENT     new_event;
88 
89     newsize = widget -> gx_widget_size;
90     _gx_utility_rectangle_shift(&newsize, x_shift, y_shift);
91 
92     if (mark_dirty && (widget -> gx_widget_status & GX_STATUS_VISIBLE))
93     {
94         /* here if my new size is smaller or in a different position,
95            I need to mark my parent as dirty
96          */
97         area_sum = newsize;
98         _gx_utility_rectangle_combine(&area_sum, &widget -> gx_widget_size);
99         _gx_system_dirty_partial_add(widget -> gx_widget_parent, &area_sum);
100     }
101 
102     widget -> gx_widget_size = newsize;
103 
104     if (widget -> gx_widget_type >= GX_TYPE_WINDOW)
105     {
106         win = (GX_WINDOW *)widget;
107         _gx_utility_rectangle_shift(&win -> gx_window_client, x_shift, y_shift);
108 
109         if (win -> gx_widget_status & GX_STATUS_VISIBLE)
110         {
111             /* check to see if viewports need to be updated */
112             _gx_window_view_update_detect(win);
113         }
114     }
115 
116     if ((widget -> gx_widget_status & GX_STATUS_VISIBLE) &&
117         (widget -> gx_widget_status & GX_STATUS_RESIZE_NOTIFY))
118     {
119         /* Notify widget of size change. */
120         memset(&new_event, 0, sizeof(GX_EVENT));
121         new_event.gx_event_target = widget;
122         new_event.gx_event_type = GX_EVENT_RESIZED;
123         _gx_system_event_fold(&new_event);
124     }
125 }
126 
127 /**************************************************************************/
128 /*                                                                        */
129 /*  FUNCTION                                               RELEASE        */
130 /*                                                                        */
131 /*    _gx_widget_shift                                    PORTABLE C      */
132 /*                                                           6.1          */
133 /*  AUTHOR                                                                */
134 /*                                                                        */
135 /*    Kenneth Maxwell, Microsoft Corporation                              */
136 /*                                                                        */
137 /*  DESCRIPTION                                                           */
138 /*                                                                        */
139 /*    This service shifts the widget and optionally marks it as dirty.    */
140 /*                                                                        */
141 /*  INPUT                                                                 */
142 /*                                                                        */
143 /*    widget                                Pointer to widget             */
144 /*    x_shift                               Number of pixels to shift on  */
145 /*                                            the x-axis                  */
146 /*    y_shift                               Number of pixels to shift on  */
147 /*                                            the y-axis                  */
148 /*    mark_dirty                            GX_TRUE to indicate dirty,    */
149 /*                                            otherwise GX_FALSE          */
150 /*                                                                        */
151 /*  OUTPUT                                                                */
152 /*                                                                        */
153 /*    status                                Completion status             */
154 /*                                                                        */
155 /*  CALLS                                                                 */
156 /*                                                                        */
157 /*    _gx_widget_shift_helper               Shift a widget                */
158 /*    _gx_widget_clipping_update            Update widget clipping area   */
159 /*                                                                        */
160 /*  CALLED BY                                                             */
161 /*                                                                        */
162 /*    Application Code                                                    */
163 /*    GUIX Internal Code                                                  */
164 /*                                                                        */
165 /*  RELEASE HISTORY                                                       */
166 /*                                                                        */
167 /*    DATE              NAME                      DESCRIPTION             */
168 /*                                                                        */
169 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
170 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
171 /*                                            resulting in version 6.1    */
172 /*                                                                        */
173 /**************************************************************************/
_gx_widget_shift(GX_WIDGET * widget,GX_VALUE x_shift,GX_VALUE y_shift,GX_BOOL mark_dirty)174 UINT  _gx_widget_shift(GX_WIDGET *widget, GX_VALUE x_shift, GX_VALUE y_shift, GX_BOOL mark_dirty)
175 {
176 GX_WIDGET *child;
177 
178     if (x_shift == 0 && y_shift == 0)
179     {
180         return GX_SUCCESS;
181     }
182 
183     _gx_widget_shift_helper(widget, x_shift, y_shift, mark_dirty);
184 
185     /* pick up pointer to first child widget */
186     child = widget -> gx_widget_first_child;
187 
188     /* loop through and shift all my child widgets */
189 
190     while (child)
191     {
192         _gx_widget_shift_helper(child, x_shift, y_shift, GX_FALSE);
193 
194         if (child -> gx_widget_first_child)
195         {
196             child = child -> gx_widget_first_child;
197             continue;
198         }
199 
200         while ((child -> gx_widget_next == GX_NULL) && (child != widget))
201         {
202             child = child -> gx_widget_parent;
203         }
204 
205         if (child == widget)
206         {
207             break;
208         }
209 
210         child = child -> gx_widget_next;
211     }
212 
213     if (mark_dirty && (widget -> gx_widget_status & GX_STATUS_VISIBLE))
214     {
215         _gx_widget_clipping_update(widget);
216     }
217 
218     return(GX_SUCCESS);
219 }
220 
221