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 |
|
|
/** Scroll Wheel Management (Generic Scroll Wheel) */ |
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_utility.h" |
32 |
|
|
#include "gx_scroll_wheel.h" |
33 |
|
|
|
34 |
|
|
/**************************************************************************/ |
35 |
|
|
/* */ |
36 |
|
|
/* FUNCTION RELEASE */ |
37 |
|
|
/* */ |
38 |
|
|
/* _gx_generic_scroll_wheel_children_position PORTABLE C */ |
39 |
|
|
/* 6.1.7 */ |
40 |
|
|
/* AUTHOR */ |
41 |
|
|
/* */ |
42 |
|
|
/* Ting Zhu, Microsoft Corporation */ |
43 |
|
|
/* */ |
44 |
|
|
/* DESCRIPTION */ |
45 |
|
|
/* */ |
46 |
|
|
/* This function positions the children for the generic scroll wheel. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* wheel Scroll wheel control block */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* status Completion status */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* _gx_utility_rectangle_shift Shift rectangle */ |
59 |
|
|
/* _gx_window_client_height_get Retrieve the client height */ |
60 |
|
|
/* of the widget */ |
61 |
|
|
/* _gx_widget_first_visible_client_child_get */ |
62 |
|
|
/* Get the first visible client */ |
63 |
|
|
/* _gx_widget_next_visible_client_child_get */ |
64 |
|
|
/* Get the next visible client */ |
65 |
|
|
/* _gx_widget_resize resizes the widget */ |
66 |
|
|
/* _gx_generic_scroll_wheel_scroll Scroll the generic scroll wheel*/ |
67 |
|
|
/* */ |
68 |
|
|
/* CALLED BY */ |
69 |
|
|
/* */ |
70 |
|
|
/* GUIX Internal Code */ |
71 |
|
|
/* */ |
72 |
|
|
/**************************************************************************/ |
73 |
|
54 |
UINT _gx_generic_scroll_wheel_children_position(GX_GENERIC_SCROLL_WHEEL *wheel) |
74 |
|
|
{ |
75 |
|
|
GX_RECTANGLE childsize; |
76 |
|
|
GX_WIDGET *child; |
77 |
|
|
GX_VALUE height; |
78 |
|
|
GX_VALUE row_height; |
79 |
|
|
GX_VALUE selected_top; |
80 |
|
|
GX_RECTANGLE *client; |
81 |
|
|
INT top_rows; |
82 |
|
|
INT row; |
83 |
|
|
INT selected_row; |
84 |
|
|
|
85 |
|
|
/* Pick up first visible child. */ |
86 |
|
54 |
child = _gx_widget_first_visible_client_child_get((GX_WIDGET*)wheel); |
87 |
|
|
|
88 |
✓✓ |
54 |
if (!child) |
89 |
|
|
{ |
90 |
|
10 |
return GX_SUCCESS; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
/* Get row height. */ |
94 |
|
44 |
row_height = wheel -> gx_scroll_wheel_row_height; |
95 |
|
|
|
96 |
✓✓ |
44 |
if (!row_height) |
97 |
|
|
{ |
98 |
|
1 |
return GX_SUCCESS; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
/* Get client rectangle. */ |
102 |
|
43 |
client = &wheel -> gx_window_client; |
103 |
|
|
|
104 |
|
|
/* Calculate rectangle top of the selected row. */ |
105 |
|
43 |
selected_top = (GX_VALUE)((client -> gx_rectangle_top + client -> gx_rectangle_bottom) >> 1); |
106 |
|
43 |
selected_top = (GX_VALUE)(selected_top - (row_height >> 1)); |
107 |
|
43 |
selected_top = (GX_VALUE)(selected_top + wheel -> gx_scroll_wheel_selected_yshift); |
108 |
|
|
|
109 |
|
|
/* Calculate first child size. */ |
110 |
|
43 |
childsize = *client; |
111 |
|
|
|
112 |
|
43 |
top_rows = (selected_top -client -> gx_rectangle_top + row_height) / row_height; |
113 |
|
|
|
114 |
✓✓✓✓
|
43 |
if ((wheel -> gx_scroll_wheel_total_rows) && top_rows >= wheel -> gx_scroll_wheel_total_rows) |
115 |
|
|
{ |
116 |
|
6 |
top_rows = wheel -> gx_scroll_wheel_total_rows - 1; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
43 |
childsize.gx_rectangle_top = (GX_VALUE)(selected_top - (top_rows * row_height)); |
120 |
|
43 |
childsize.gx_rectangle_bottom = (GX_VALUE)(childsize.gx_rectangle_top + row_height - 1); |
121 |
|
|
|
122 |
|
|
/* Initiate child count as 0. */ |
123 |
|
43 |
wheel -> gx_generic_scroll_wheel_child_count = 0; |
124 |
|
|
|
125 |
|
|
/* Save selected row. */ |
126 |
|
43 |
selected_row = wheel -> gx_scroll_wheel_selected_row; |
127 |
|
|
|
128 |
|
43 |
row = wheel -> gx_generic_scroll_wheel_top_index; |
129 |
|
43 |
wheel -> gx_scroll_wheel_selected_row = row + top_rows; |
130 |
|
|
|
131 |
|
|
/* Resize child widgets. */ |
132 |
✓✓ |
295 |
while (child) |
133 |
|
|
{ |
134 |
|
|
|
135 |
|
|
/* Increment child count. */ |
136 |
|
252 |
wheel -> gx_generic_scroll_wheel_child_count++; |
137 |
|
|
|
138 |
✓✓ |
252 |
if (childsize.gx_rectangle_top == selected_top) |
139 |
|
|
{ |
140 |
|
43 |
child -> gx_widget_style |= GX_STYLE_DRAW_SELECTED; |
141 |
|
|
} |
142 |
|
|
else |
143 |
|
|
{ |
144 |
|
209 |
child -> gx_widget_style &= (~GX_STYLE_DRAW_SELECTED); |
145 |
|
|
} |
146 |
|
|
|
147 |
|
252 |
child -> gx_widget_status &= ~GX_STATUS_ACCEPTS_FOCUS; |
148 |
|
|
|
149 |
|
|
/* Resize widget. */ |
150 |
|
252 |
_gx_widget_resize(child, &childsize); |
151 |
|
|
|
152 |
|
252 |
_gx_utility_rectangle_shift(&childsize, 0, row_height); |
153 |
|
|
|
154 |
|
252 |
child = _gx_widget_next_visible_client_child_get(child); |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
/* Get client height. */ |
158 |
|
43 |
_gx_window_client_height_get((GX_WINDOW*)wheel, &height); |
159 |
|
|
|
160 |
|
|
/* Calculate number of visible rows. */ |
161 |
|
43 |
wheel -> gx_generic_scroll_wheel_visible_rows = (GX_VALUE)((height + row_height - 1) / row_height); |
162 |
|
|
|
163 |
✓✓ |
43 |
if (selected_row != wheel -> gx_scroll_wheel_selected_row) |
164 |
|
|
{ |
165 |
|
|
|
166 |
|
|
/* If current selected row is not match the configured row, |
167 |
|
|
scroll the widget to the configured row selected. */ |
168 |
|
37 |
row = wheel -> gx_scroll_wheel_selected_row - selected_row; |
169 |
|
|
|
170 |
|
37 |
_gx_generic_scroll_wheel_scroll(wheel, (GX_VALUE)(row_height * row)); |
171 |
|
|
} |
172 |
|
|
|
173 |
|
43 |
return GX_SUCCESS; |
174 |
|
|
} |
175 |
|
|
|