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 |
|
|
/** Menu Management (Menu) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "gx_api.h" |
28 |
|
|
#include "gx_menu.h" |
29 |
|
|
#include "gx_widget.h" |
30 |
|
|
#include "gx_system.h" |
31 |
|
|
|
32 |
|
|
/**************************************************************************/ |
33 |
|
|
/* */ |
34 |
|
|
/* FUNCTION RELEASE */ |
35 |
|
|
/* */ |
36 |
|
|
/* _gx_menu_one_level_position PORTABLE C */ |
37 |
|
|
/* 6.1 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function positions first level items for a menu widget. */ |
45 |
|
|
/* */ |
46 |
|
|
/* INPUT */ |
47 |
|
|
/* */ |
48 |
|
|
/* menu Pointer to menu control block */ |
49 |
|
|
/* indentation Menu indentations */ |
50 |
|
|
/* */ |
51 |
|
|
/* OUTPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* status Completion status */ |
54 |
|
|
/* */ |
55 |
|
|
/* CALLS */ |
56 |
|
|
/* */ |
57 |
|
|
/* _gx_widget_resize Resize a widget */ |
58 |
|
|
/* _gx_widget_detach Detach a widget from its */ |
59 |
|
|
/* parent */ |
60 |
|
|
/* */ |
61 |
|
|
/* CALLED BY */ |
62 |
|
|
/* */ |
63 |
|
|
/* GUIX Internal Code */ |
64 |
|
|
/* */ |
65 |
|
|
/**************************************************************************/ |
66 |
|
981 |
UINT _gx_menu_one_level_position(GX_MENU *menu, GX_VALUE indentation) |
67 |
|
|
{ |
68 |
|
981 |
GX_RECTANGLE *menu_size = &menu -> gx_widget_size; |
69 |
|
981 |
GX_WIDGET *list = (GX_WIDGET *)&menu -> gx_menu_list; |
70 |
|
|
GX_WIDGET *item; |
71 |
|
|
GX_RECTANGLE size; |
72 |
|
|
GX_VALUE height; |
73 |
|
|
GX_VALUE width; |
74 |
|
981 |
INT max_width = 0; |
75 |
|
|
GX_MENU_LIST *item_list; |
76 |
|
|
|
77 |
|
981 |
size.gx_rectangle_left = (GX_VALUE)(menu_size -> gx_rectangle_left + indentation); |
78 |
|
981 |
size.gx_rectangle_right = (GX_VALUE)(menu_size -> gx_rectangle_right); |
79 |
|
981 |
size.gx_rectangle_top = (GX_VALUE)(menu_size -> gx_rectangle_bottom + 1); |
80 |
|
981 |
size.gx_rectangle_bottom = (GX_VALUE)(size.gx_rectangle_top - 1); |
81 |
|
|
|
82 |
|
|
/* Reposition menu list. */ |
83 |
|
981 |
_gx_widget_resize(list, &size); |
84 |
|
|
|
85 |
✓✓ |
981 |
if (menu -> gx_widget_style & GX_STYLE_MENU_EXPANDED) |
86 |
|
|
{ |
87 |
✓✓ |
59 |
if (!list -> gx_widget_parent) |
88 |
|
|
{ |
89 |
|
22 |
_gx_widget_link(menu -> gx_widget_parent, (GX_WIDGET *)list); |
90 |
|
|
} |
91 |
|
|
} |
92 |
|
|
else |
93 |
|
|
{ |
94 |
✓✓ |
922 |
if (list -> gx_widget_parent) |
95 |
|
|
{ |
96 |
|
8 |
_gx_widget_detach((GX_WIDGET *)list); |
97 |
|
|
} |
98 |
|
|
} |
99 |
|
|
|
100 |
|
981 |
item = list -> gx_widget_first_child; |
101 |
|
981 |
size.gx_rectangle_bottom = menu_size -> gx_rectangle_bottom; |
102 |
|
|
|
103 |
|
|
/* Reposition items of menu list. */ |
104 |
✓✓ |
2357 |
while (item) |
105 |
|
|
{ |
106 |
✓✓ |
1376 |
if (item -> gx_widget_type == GX_TYPE_MENU_LIST) |
107 |
|
|
{ |
108 |
|
21 |
item = item -> gx_widget_next; |
109 |
|
21 |
continue; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
1355 |
height = (GX_VALUE)(item -> gx_widget_size.gx_rectangle_bottom - item -> gx_widget_size.gx_rectangle_top + 1); |
113 |
|
1355 |
width = (GX_VALUE)(item -> gx_widget_size.gx_rectangle_right - item -> gx_widget_size.gx_rectangle_left + 1); |
114 |
|
|
|
115 |
✓✓ |
1355 |
if (width > max_width) |
116 |
|
|
{ |
117 |
|
1038 |
max_width = width; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
1355 |
size.gx_rectangle_top = (GX_VALUE)(size.gx_rectangle_bottom + 1); |
121 |
|
1355 |
size.gx_rectangle_bottom = (GX_VALUE)(size.gx_rectangle_top + height - 1); |
122 |
|
1355 |
size.gx_rectangle_right = (GX_VALUE)(size.gx_rectangle_left + width - 1); |
123 |
|
|
|
124 |
|
1355 |
_gx_widget_resize(item, &size); |
125 |
|
|
|
126 |
✓✓ |
1355 |
switch (item -> gx_widget_type) |
127 |
|
|
{ |
128 |
|
296 |
case GX_TYPE_MENU: |
129 |
|
296 |
item_list = &((GX_MENU *)item) -> gx_menu_list; |
130 |
✓✓ |
296 |
if (item_list -> gx_widget_parent) |
131 |
|
|
{ |
132 |
|
21 |
_gx_widget_shift((GX_WIDGET *)item_list, |
133 |
|
21 |
(GX_VALUE)(size.gx_rectangle_left + indentation - item_list -> gx_widget_size.gx_rectangle_left), |
134 |
|
21 |
(GX_VALUE)(size.gx_rectangle_bottom + 1 - item_list -> gx_widget_size.gx_rectangle_top), GX_FALSE); |
135 |
|
|
|
136 |
|
21 |
height = (GX_VALUE)(item_list -> gx_widget_size.gx_rectangle_bottom - size.gx_rectangle_top + 1); |
137 |
|
21 |
width = (GX_VALUE)(item_list -> gx_widget_size.gx_rectangle_right - size.gx_rectangle_left + 1); |
138 |
|
|
|
139 |
✓✓ |
21 |
if (width > max_width) |
140 |
|
|
{ |
141 |
|
20 |
max_width = width; |
142 |
|
|
} |
143 |
|
|
} |
144 |
|
296 |
break; |
145 |
|
|
|
146 |
|
1059 |
default: |
147 |
|
1059 |
break; |
148 |
|
|
} |
149 |
|
|
|
150 |
|
1355 |
size.gx_rectangle_bottom = (GX_VALUE)(size.gx_rectangle_top + height - 1); |
151 |
|
|
|
152 |
|
1355 |
item = item -> gx_widget_next; |
153 |
|
|
} |
154 |
|
|
|
155 |
✓✓ |
981 |
if (menu -> gx_widget_style & GX_STYLE_MENU_EXPANDED) |
156 |
|
|
{ |
157 |
|
59 |
size.gx_rectangle_top = (GX_VALUE)(menu_size -> gx_rectangle_bottom + 1); |
158 |
|
59 |
size.gx_rectangle_right = (GX_VALUE)(size.gx_rectangle_left + max_width - 1); |
159 |
|
59 |
_gx_widget_resize(list, &size); |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
/* Return completion status code. */ |
163 |
|
981 |
return(GX_SUCCESS); |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
/**************************************************************************/ |
167 |
|
|
/* */ |
168 |
|
|
/* FUNCTION RELEASE */ |
169 |
|
|
/* */ |
170 |
|
|
/* _gx_menu_position PORTABLE C */ |
171 |
|
|
/* 6.1 */ |
172 |
|
|
/* AUTHOR */ |
173 |
|
|
/* */ |
174 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
175 |
|
|
/* */ |
176 |
|
|
/* DESCRIPTION */ |
177 |
|
|
/* */ |
178 |
|
|
/* This function positions a menu and its menu list. */ |
179 |
|
|
/* */ |
180 |
|
|
/* INPUT */ |
181 |
|
|
/* */ |
182 |
|
|
/* menu Pointer to menu control block */ |
183 |
|
|
/* */ |
184 |
|
|
/* OUTPUT */ |
185 |
|
|
/* */ |
186 |
|
|
/* status Completion status */ |
187 |
|
|
/* */ |
188 |
|
|
/* CALLS */ |
189 |
|
|
/* */ |
190 |
|
|
/* _gx_menu_one_level_position Position a menu widget */ |
191 |
|
|
/* */ |
192 |
|
|
/* CALLED BY */ |
193 |
|
|
/* */ |
194 |
|
|
/* GUIX Internal Code */ |
195 |
|
|
/* */ |
196 |
|
|
/**************************************************************************/ |
197 |
|
271 |
UINT _gx_menu_position(GX_MENU *menu, GX_VALUE indentation) |
198 |
|
|
{ |
199 |
|
271 |
UINT status = GX_SUCCESS; |
200 |
|
271 |
GX_WIDGET *parent = (GX_WIDGET *)menu; |
201 |
|
|
GX_WIDGET *child; |
202 |
|
|
GX_MENU_LIST *child_list; |
203 |
|
|
|
204 |
|
271 |
child = menu -> gx_menu_list.gx_widget_first_child; |
205 |
|
|
|
206 |
|
|
/* Reposition items of menu list. */ |
207 |
✓✓ |
746 |
while (child) |
208 |
|
|
{ |
209 |
✓✓ |
735 |
if (child -> gx_widget_type == GX_TYPE_MENU) |
210 |
|
|
{ |
211 |
|
198 |
child_list = &((GX_MENU *)child) -> gx_menu_list; |
212 |
|
|
|
213 |
✓✓ |
198 |
if (child_list -> gx_widget_first_child) |
214 |
|
|
{ |
215 |
|
196 |
child = child_list -> gx_widget_first_child; |
216 |
|
196 |
continue; |
217 |
|
|
} |
218 |
✓✓ |
2 |
else if (child_list -> gx_widget_parent) |
219 |
|
|
{ |
220 |
|
1 |
_gx_widget_detach((GX_WIDGET *)child_list); |
221 |
|
|
} |
222 |
|
|
} |
223 |
|
|
|
224 |
✓✓✓✓
|
995 |
while ((child -> gx_widget_next == GX_NULL) && (child != parent)) |
225 |
|
|
{ |
226 |
|
|
/* Child parent is menu list. */ |
227 |
|
456 |
child_list = (GX_MENU_LIST *)child -> gx_widget_parent; |
228 |
|
456 |
child = child_list -> gx_menu_list_owner; |
229 |
|
|
|
230 |
|
456 |
_gx_menu_one_level_position((GX_MENU *)child, indentation); |
231 |
|
|
} |
232 |
|
|
|
233 |
✓✓ |
539 |
if (child == parent) |
234 |
|
|
{ |
235 |
|
260 |
break; |
236 |
|
|
} |
237 |
|
|
|
238 |
|
279 |
child = child -> gx_widget_next; |
239 |
|
|
} |
240 |
|
|
|
241 |
|
|
/* Return completion status code. */ |
242 |
|
271 |
return(status); |
243 |
|
|
} |
244 |
|
|
|