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 /** Horizontal List (List) */
19 /** */
20 /**************************************************************************/
21
22 #define GX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "gx_api.h"
28 #include "gx_widget.h"
29 #include "gx_window.h"
30 #include "gx_system.h"
31 #include "gx_scrollbar.h"
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _gx_horizontal_list_selected_set PORTABLE C */
38 /* 6.1.12 */
39 /* AUTHOR */
40 /* */
41 /* Kenneth Maxwell, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This service sets the list entry at the current list index. */
46 /* */
47 /* INPUT */
48 /* */
49 /* horizontal_list Horizontal list widget */
50 /* control block */
51 /* index Index based position of new */
52 /* list entry */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* status Completion status */
57 /* */
58 /* CALLS */
59 /* */
60 /* _gx_widget_first_client_child_get */
61 /* _gx_widget_next_client_child_get */
62 /* _gx_horizontal_list_page_index_set */
63 /* _gx_widget_event_generate */
64 /* _gx_system_dirty_mark */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* _gx_horizontal_list_event_process */
69 /* */
70 /* RELEASE HISTORY */
71 /* */
72 /* DATE NAME DESCRIPTION */
73 /* */
74 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
75 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
76 /* resulting in version 6.1 */
77 /* 07-29-2022 Kenneth Maxwell Modified comment(s), */
78 /* added support for */
79 /* GX_STYLE_REPEAT_SELECT, */
80 /* resulting in version 6.1.12 */
81 /* */
82 /**************************************************************************/
83
_gx_horizontal_list_selected_set(GX_HORIZONTAL_LIST * horizontal_list,INT index)84 UINT _gx_horizontal_list_selected_set(GX_HORIZONTAL_LIST *horizontal_list, INT index)
85 {
86 GX_WIDGET *child;
87 GX_WIDGET *found = GX_NULL;
88 INT page_index = horizontal_list -> gx_horizontal_list_top_index;
89 INT left_index;
90 INT right_index;
91
92 if (horizontal_list -> gx_horizontal_list_selected == index)
93 {
94 if ((horizontal_list -> gx_widget_style & GX_STYLE_REPEAT_SELECT) == 0)
95 {
96 return GX_SUCCESS;
97 }
98 }
99
100 if (index < 0)
101 {
102 _gx_horizontal_list_selected_widget_get(horizontal_list, &child);
103
104 if (child)
105 {
106 child -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
107 _gx_system_dirty_mark(child);
108 }
109 horizontal_list -> gx_horizontal_list_selected = index;
110 return GX_SUCCESS;
111 }
112
113 /* Calculate page index. */
114 child = _gx_widget_first_client_child_get((GX_WIDGET *)horizontal_list);
115
116 while (child && (child -> gx_widget_size.gx_rectangle_right <= horizontal_list -> gx_widget_size.gx_rectangle_left))
117 {
118 page_index++;
119 child = _gx_widget_next_client_child_get(child);
120 }
121
122 left_index = horizontal_list -> gx_horizontal_list_top_index;
123 right_index = left_index + horizontal_list -> gx_horizontal_list_child_count - 1;
124
125 /* Reset page index when needed and calculate the child count from the top index to new index. */
126 if (right_index >= horizontal_list -> gx_horizontal_list_total_columns)
127 {
128 right_index -= horizontal_list -> gx_horizontal_list_total_columns;
129
130 if (index >= left_index)
131 {
132 page_index = index - horizontal_list -> gx_horizontal_list_top_index;
133 }
134 else if (index <= right_index)
135 {
136 page_index = horizontal_list -> gx_horizontal_list_total_columns + index - horizontal_list -> gx_horizontal_list_top_index;
137 }
138 else
139 {
140 _gx_horizontal_list_page_index_set(horizontal_list, index);
141 page_index = index - horizontal_list -> gx_horizontal_list_top_index;
142 }
143 }
144 else
145 {
146 if (index < left_index)
147 {
148 _gx_horizontal_list_page_index_set(horizontal_list, index);
149 }
150 else if (index > right_index)
151 {
152 _gx_horizontal_list_page_index_set(horizontal_list, index - horizontal_list -> gx_horizontal_list_visible_columns + 1);
153 }
154
155 page_index = index - horizontal_list -> gx_horizontal_list_top_index;
156 }
157
158 if (page_index < 0)
159 {
160 /* consider the situation that top index is bigger than current select index. */
161 page_index += horizontal_list -> gx_horizontal_list_total_columns;
162 }
163
164 child = _gx_widget_first_client_child_get((GX_WIDGET *)horizontal_list);
165
166 /* Select new index and update widget draw style. */
167 while (child)
168 {
169 if (page_index == 0)
170 {
171 found = child;
172
173 horizontal_list -> gx_horizontal_list_selected = index;
174 _gx_horizontal_list_selected_visible(horizontal_list, found);
175 found -> gx_widget_style |= GX_STYLE_DRAW_SELECTED;
176 _gx_system_dirty_mark(found);
177
178 if (horizontal_list -> gx_widget_id)
179 {
180 _gx_widget_event_generate((GX_WIDGET *)horizontal_list, GX_EVENT_LIST_SELECT, horizontal_list -> gx_horizontal_list_selected);
181 }
182 }
183 else
184 {
185 if (child -> gx_widget_style & GX_STYLE_DRAW_SELECTED)
186 {
187 child -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
188 _gx_system_dirty_mark(child);
189 }
190 }
191 child = _gx_widget_next_client_child_get(child);
192 page_index--;
193 }
194
195 if (found)
196 {
197 return GX_SUCCESS;
198 }
199 return GX_FAILURE;
200 }
201
202