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 |
|
|
/** 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 |
|
|
/**************************************************************************/ |
71 |
|
|
|
72 |
|
76 |
UINT _gx_horizontal_list_selected_set(GX_HORIZONTAL_LIST *horizontal_list, INT index) |
73 |
|
|
{ |
74 |
|
|
GX_WIDGET *child; |
75 |
|
76 |
GX_WIDGET *found = GX_NULL; |
76 |
|
76 |
INT page_index = horizontal_list -> gx_horizontal_list_top_index; |
77 |
|
|
INT left_index; |
78 |
|
|
INT right_index; |
79 |
|
|
|
80 |
✓✓ |
76 |
if (horizontal_list -> gx_horizontal_list_selected == index) |
81 |
|
|
{ |
82 |
✓✗ |
11 |
if ((horizontal_list -> gx_widget_style & GX_STYLE_REPEAT_SELECT) == 0) |
83 |
|
|
{ |
84 |
|
11 |
return GX_SUCCESS; |
85 |
|
|
} |
86 |
|
|
} |
87 |
|
|
|
88 |
✓✓ |
65 |
if (index < 0) |
89 |
|
|
{ |
90 |
|
8 |
_gx_horizontal_list_selected_widget_get(horizontal_list, &child); |
91 |
|
|
|
92 |
✓✗ |
8 |
if (child) |
93 |
|
|
{ |
94 |
|
8 |
child -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED; |
95 |
|
8 |
_gx_system_dirty_mark(child); |
96 |
|
|
} |
97 |
|
8 |
horizontal_list -> gx_horizontal_list_selected = index; |
98 |
|
8 |
return GX_SUCCESS; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
/* Calculate page index. */ |
102 |
|
57 |
child = _gx_widget_first_client_child_get((GX_WIDGET *)horizontal_list); |
103 |
|
|
|
104 |
✓✓✓✓
|
103 |
while (child && (child -> gx_widget_size.gx_rectangle_right <= horizontal_list -> gx_widget_size.gx_rectangle_left)) |
105 |
|
|
{ |
106 |
|
46 |
page_index++; |
107 |
|
46 |
child = _gx_widget_next_client_child_get(child); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
57 |
left_index = horizontal_list -> gx_horizontal_list_top_index; |
111 |
|
57 |
right_index = left_index + horizontal_list -> gx_horizontal_list_child_count - 1; |
112 |
|
|
|
113 |
|
|
/* Reset page index when needed and calculate the child count from the top index to new index. */ |
114 |
✓✓ |
57 |
if (right_index >= horizontal_list -> gx_horizontal_list_total_columns) |
115 |
|
|
{ |
116 |
|
12 |
right_index -= horizontal_list -> gx_horizontal_list_total_columns; |
117 |
|
|
|
118 |
✓✓ |
12 |
if (index >= left_index) |
119 |
|
|
{ |
120 |
|
3 |
page_index = index - horizontal_list -> gx_horizontal_list_top_index; |
121 |
|
|
} |
122 |
✓✓ |
9 |
else if (index <= right_index) |
123 |
|
|
{ |
124 |
|
6 |
page_index = horizontal_list -> gx_horizontal_list_total_columns + index - horizontal_list -> gx_horizontal_list_top_index; |
125 |
|
|
} |
126 |
|
|
else |
127 |
|
|
{ |
128 |
|
3 |
_gx_horizontal_list_page_index_set(horizontal_list, index); |
129 |
|
3 |
page_index = index - horizontal_list -> gx_horizontal_list_top_index; |
130 |
|
|
} |
131 |
|
|
} |
132 |
|
|
else |
133 |
|
|
{ |
134 |
✓✓ |
45 |
if (index < left_index) |
135 |
|
|
{ |
136 |
|
6 |
_gx_horizontal_list_page_index_set(horizontal_list, index); |
137 |
|
|
} |
138 |
✓✓ |
39 |
else if (index > right_index) |
139 |
|
|
{ |
140 |
|
10 |
_gx_horizontal_list_page_index_set(horizontal_list, index - horizontal_list -> gx_horizontal_list_visible_columns + 1); |
141 |
|
|
} |
142 |
|
|
|
143 |
|
45 |
page_index = index - horizontal_list -> gx_horizontal_list_top_index; |
144 |
|
|
} |
145 |
|
|
|
146 |
✓✓ |
57 |
if (page_index < 0) |
147 |
|
|
{ |
148 |
|
|
/* consider the situation that top index is bigger than current select index. */ |
149 |
|
2 |
page_index += horizontal_list -> gx_horizontal_list_total_columns; |
150 |
|
|
} |
151 |
|
|
|
152 |
|
57 |
child = _gx_widget_first_client_child_get((GX_WIDGET *)horizontal_list); |
153 |
|
|
|
154 |
|
|
/* Select new index and update widget draw style. */ |
155 |
✓✓ |
571 |
while (child) |
156 |
|
|
{ |
157 |
✓✓ |
514 |
if (page_index == 0) |
158 |
|
|
{ |
159 |
|
52 |
found = child; |
160 |
|
|
|
161 |
|
52 |
horizontal_list -> gx_horizontal_list_selected = index; |
162 |
|
52 |
_gx_horizontal_list_selected_visible(horizontal_list, found); |
163 |
|
52 |
found -> gx_widget_style |= GX_STYLE_DRAW_SELECTED; |
164 |
|
52 |
_gx_system_dirty_mark(found); |
165 |
|
|
|
166 |
✓✓ |
52 |
if (horizontal_list -> gx_widget_id) |
167 |
|
|
{ |
168 |
|
5 |
_gx_widget_event_generate((GX_WIDGET *)horizontal_list, GX_EVENT_LIST_SELECT, horizontal_list -> gx_horizontal_list_selected); |
169 |
|
|
} |
170 |
|
|
} |
171 |
|
|
else |
172 |
|
|
{ |
173 |
✓✓ |
462 |
if (child -> gx_widget_style & GX_STYLE_DRAW_SELECTED) |
174 |
|
|
{ |
175 |
|
35 |
child -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED; |
176 |
|
35 |
_gx_system_dirty_mark(child); |
177 |
|
|
} |
178 |
|
|
} |
179 |
|
514 |
child = _gx_widget_next_client_child_get(child); |
180 |
|
514 |
page_index--; |
181 |
|
|
} |
182 |
|
|
|
183 |
✓✓ |
57 |
if (found) |
184 |
|
|
{ |
185 |
|
52 |
return GX_SUCCESS; |
186 |
|
|
} |
187 |
|
5 |
return GX_FAILURE; |
188 |
|
|
} |
189 |
|
|
|