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 |
|
|
/** Vertical 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_vertical_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 |
|
|
/* vertical_list Vertical list widget control */ |
50 |
|
|
/* 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_vertical_list_page_index_set */ |
63 |
|
|
/* _gx_widget_event_generate */ |
64 |
|
|
/* _gx_system_dirty_mark */ |
65 |
|
|
/* */ |
66 |
|
|
/* CALLED BY */ |
67 |
|
|
/* */ |
68 |
|
|
/* Application Code */ |
69 |
|
|
/* _gx_drop_list_event_process Process drop list event */ |
70 |
|
|
/* */ |
71 |
|
|
/**************************************************************************/ |
72 |
|
69 |
UINT _gx_vertical_list_selected_set(GX_VERTICAL_LIST *vertical_list, INT index) |
73 |
|
|
{ |
74 |
|
|
GX_WIDGET *child; |
75 |
|
69 |
GX_WIDGET *found = GX_NULL; |
76 |
|
69 |
INT page_index = vertical_list -> gx_vertical_list_top_index; |
77 |
|
|
INT top_index; |
78 |
|
|
INT bottom_index; |
79 |
|
|
|
80 |
✓✓ |
69 |
if (vertical_list -> gx_vertical_list_selected == index) |
81 |
|
|
{ |
82 |
✓✗ |
11 |
if ((vertical_list -> gx_widget_style & GX_STYLE_REPEAT_SELECT) == 0) |
83 |
|
|
{ |
84 |
|
11 |
return GX_SUCCESS; |
85 |
|
|
} |
86 |
|
|
} |
87 |
|
|
|
88 |
✓✓ |
58 |
if (index < 0) |
89 |
|
|
{ |
90 |
|
7 |
_gx_vertical_list_selected_widget_get(vertical_list, &child); |
91 |
|
|
|
92 |
✓✗ |
7 |
if (child) |
93 |
|
|
{ |
94 |
|
7 |
child -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED; |
95 |
|
7 |
_gx_system_dirty_mark(child); |
96 |
|
|
} |
97 |
|
7 |
vertical_list -> gx_vertical_list_selected = index; |
98 |
|
7 |
return GX_SUCCESS; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
51 |
child = _gx_widget_first_client_child_get((GX_WIDGET *)vertical_list); |
102 |
|
|
|
103 |
✓✓✓✓
|
159 |
while (child && (child -> gx_widget_size.gx_rectangle_bottom <= vertical_list -> gx_widget_size.gx_rectangle_top)) |
104 |
|
|
{ |
105 |
|
108 |
page_index++; |
106 |
|
108 |
child = _gx_widget_next_client_child_get(child); |
107 |
|
|
} |
108 |
|
|
|
109 |
|
51 |
top_index = vertical_list -> gx_vertical_list_top_index; |
110 |
|
51 |
bottom_index = top_index + vertical_list -> gx_vertical_list_child_count - 1; |
111 |
|
|
|
112 |
|
|
/* Reset page index when needed and calculate the child count from the top index to new index. */ |
113 |
✓✓ |
51 |
if (bottom_index >= vertical_list -> gx_vertical_list_total_rows) |
114 |
|
|
{ |
115 |
|
12 |
bottom_index -= vertical_list -> gx_vertical_list_total_rows; |
116 |
|
|
|
117 |
✓✓ |
12 |
if (index >= top_index) |
118 |
|
|
{ |
119 |
|
3 |
page_index = index - vertical_list -> gx_vertical_list_top_index; |
120 |
|
|
} |
121 |
✓✓ |
9 |
else if (index <= bottom_index) |
122 |
|
|
{ |
123 |
|
6 |
page_index = vertical_list -> gx_vertical_list_total_rows + index - vertical_list -> gx_vertical_list_top_index; |
124 |
|
|
} |
125 |
|
|
else |
126 |
|
|
{ |
127 |
|
3 |
_gx_vertical_list_page_index_set(vertical_list, index); |
128 |
|
3 |
page_index = index - vertical_list -> gx_vertical_list_top_index; |
129 |
|
|
} |
130 |
|
|
} |
131 |
|
|
else |
132 |
|
|
{ |
133 |
✓✓ |
39 |
if (index < top_index) |
134 |
|
|
{ |
135 |
|
6 |
_gx_vertical_list_page_index_set(vertical_list, index); |
136 |
|
|
} |
137 |
✓✓ |
33 |
else if (index > bottom_index) |
138 |
|
|
{ |
139 |
|
12 |
_gx_vertical_list_page_index_set(vertical_list, index - vertical_list -> gx_vertical_list_visible_rows + 1); |
140 |
|
|
} |
141 |
|
|
|
142 |
|
39 |
page_index = index - vertical_list -> gx_vertical_list_top_index; |
143 |
|
|
} |
144 |
|
|
|
145 |
✓✓ |
51 |
if (page_index < 0) |
146 |
|
|
{ |
147 |
|
|
/* consider the situation that top index is bigger than current select index. */ |
148 |
|
2 |
page_index += vertical_list -> gx_vertical_list_total_rows; |
149 |
|
|
} |
150 |
|
|
|
151 |
|
51 |
child = _gx_widget_first_client_child_get((GX_WIDGET *)vertical_list); |
152 |
|
|
|
153 |
|
|
/* Select new index and update widget draw style. */ |
154 |
✓✓ |
785 |
while (child) |
155 |
|
|
{ |
156 |
✓✓ |
734 |
if (page_index == 0) |
157 |
|
|
{ |
158 |
|
46 |
found = child; |
159 |
|
46 |
vertical_list -> gx_vertical_list_selected = index; |
160 |
|
46 |
_gx_vertical_list_selected_visible(vertical_list, found); |
161 |
|
46 |
found -> gx_widget_style |= GX_STYLE_DRAW_SELECTED; |
162 |
|
46 |
_gx_system_dirty_mark(found); |
163 |
|
|
|
164 |
✓✓ |
46 |
if (vertical_list -> gx_widget_id) |
165 |
|
|
{ |
166 |
|
44 |
_gx_widget_event_generate((GX_WIDGET *)vertical_list, GX_EVENT_LIST_SELECT, vertical_list -> gx_vertical_list_selected); |
167 |
|
|
} |
168 |
|
|
} |
169 |
|
|
else |
170 |
|
|
{ |
171 |
✓✓ |
688 |
if (child -> gx_widget_style & GX_STYLE_DRAW_SELECTED) |
172 |
|
|
{ |
173 |
|
28 |
child -> gx_widget_style &= ~GX_STYLE_DRAW_SELECTED; |
174 |
|
28 |
_gx_system_dirty_mark(child); |
175 |
|
|
} |
176 |
|
|
} |
177 |
|
734 |
child = _gx_widget_next_client_child_get(child); |
178 |
|
734 |
page_index--; |
179 |
|
|
} |
180 |
|
|
|
181 |
✓✓ |
51 |
if (found) |
182 |
|
|
{ |
183 |
|
46 |
return GX_SUCCESS; |
184 |
|
|
} |
185 |
|
5 |
return GX_FAILURE; |
186 |
|
|
} |
187 |
|
|
|