1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* |
4 |
|
|
* This program and the accompanying materials are made available under the |
5 |
|
|
* terms of the MIT License which is available at |
6 |
|
|
* https://opensource.org/licenses/MIT. |
7 |
|
|
* |
8 |
|
|
* SPDX-License-Identifier: MIT |
9 |
|
|
**************************************************************************/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** GUIX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** Scroll Wheel Management (Generic Scroll Wheel) */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
|
21 |
|
|
#define GX_SOURCE_CODE |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#include "gx_api.h" |
27 |
|
|
#include "gx_widget.h" |
28 |
|
|
#include "gx_window.h" |
29 |
|
|
#include "gx_system.h" |
30 |
|
|
#include "gx_utility.h" |
31 |
|
|
#include "gx_scroll_wheel.h" |
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _gx_generic_scroll_wheel_children_position PORTABLE C */ |
38 |
|
|
/* 6.1.7 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Ting Zhu, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function positions the children for the generic scroll wheel. */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* wheel Scroll wheel control block */ |
50 |
|
|
/* */ |
51 |
|
|
/* OUTPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* status Completion status */ |
54 |
|
|
/* */ |
55 |
|
|
/* CALLS */ |
56 |
|
|
/* */ |
57 |
|
|
/* _gx_utility_rectangle_shift Shift rectangle */ |
58 |
|
|
/* _gx_window_client_height_get Retrieve the client height */ |
59 |
|
|
/* of the widget */ |
60 |
|
|
/* _gx_widget_first_visible_client_child_get */ |
61 |
|
|
/* Get the first visible client */ |
62 |
|
|
/* _gx_widget_next_visible_client_child_get */ |
63 |
|
|
/* Get the next visible client */ |
64 |
|
|
/* _gx_widget_resize resizes the widget */ |
65 |
|
|
/* _gx_generic_scroll_wheel_scroll Scroll the generic scroll wheel*/ |
66 |
|
|
/* */ |
67 |
|
|
/* CALLED BY */ |
68 |
|
|
/* */ |
69 |
|
|
/* GUIX Internal Code */ |
70 |
|
|
/* */ |
71 |
|
|
/* RELEASE HISTORY */ |
72 |
|
|
/* */ |
73 |
|
|
/* DATE NAME DESCRIPTION */ |
74 |
|
|
/* */ |
75 |
|
|
/* 06-02-2021 Ting Zhu Initial Version 6.1.7 */ |
76 |
|
|
/* */ |
77 |
|
|
/**************************************************************************/ |
78 |
|
54 |
UINT _gx_generic_scroll_wheel_children_position(GX_GENERIC_SCROLL_WHEEL *wheel) |
79 |
|
|
{ |
80 |
|
|
GX_RECTANGLE childsize; |
81 |
|
|
GX_WIDGET *child; |
82 |
|
|
GX_VALUE height; |
83 |
|
|
GX_VALUE row_height; |
84 |
|
|
GX_VALUE selected_top; |
85 |
|
|
GX_RECTANGLE *client; |
86 |
|
|
INT top_rows; |
87 |
|
|
INT row; |
88 |
|
|
INT selected_row; |
89 |
|
|
|
90 |
|
|
/* Pick up first visible child. */ |
91 |
|
54 |
child = _gx_widget_first_visible_client_child_get((GX_WIDGET*)wheel); |
92 |
|
|
|
93 |
✓✓ |
54 |
if (!child) |
94 |
|
|
{ |
95 |
|
10 |
return GX_SUCCESS; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
/* Get row height. */ |
99 |
|
44 |
row_height = wheel -> gx_scroll_wheel_row_height; |
100 |
|
|
|
101 |
✓✓ |
44 |
if (!row_height) |
102 |
|
|
{ |
103 |
|
1 |
return GX_SUCCESS; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
/* Get client rectangle. */ |
107 |
|
43 |
client = &wheel -> gx_window_client; |
108 |
|
|
|
109 |
|
|
/* Calculate rectangle top of the selected row. */ |
110 |
|
43 |
selected_top = (GX_VALUE)((client -> gx_rectangle_top + client -> gx_rectangle_bottom) >> 1); |
111 |
|
43 |
selected_top = (GX_VALUE)(selected_top - (row_height >> 1)); |
112 |
|
43 |
selected_top = (GX_VALUE)(selected_top + wheel -> gx_scroll_wheel_selected_yshift); |
113 |
|
|
|
114 |
|
|
/* Calculate first child size. */ |
115 |
|
43 |
childsize = *client; |
116 |
|
|
|
117 |
|
43 |
top_rows = (selected_top -client -> gx_rectangle_top + row_height) / row_height; |
118 |
|
|
|
119 |
✓✓✓✓
|
43 |
if ((wheel -> gx_scroll_wheel_total_rows) && top_rows >= wheel -> gx_scroll_wheel_total_rows) |
120 |
|
|
{ |
121 |
|
6 |
top_rows = wheel -> gx_scroll_wheel_total_rows - 1; |
122 |
|
|
} |
123 |
|
|
|
124 |
|
43 |
childsize.gx_rectangle_top = (GX_VALUE)(selected_top - (top_rows * row_height)); |
125 |
|
43 |
childsize.gx_rectangle_bottom = (GX_VALUE)(childsize.gx_rectangle_top + row_height - 1); |
126 |
|
|
|
127 |
|
|
/* Initiate child count as 0. */ |
128 |
|
43 |
wheel -> gx_generic_scroll_wheel_child_count = 0; |
129 |
|
|
|
130 |
|
|
/* Save selected row. */ |
131 |
|
43 |
selected_row = wheel -> gx_scroll_wheel_selected_row; |
132 |
|
|
|
133 |
|
43 |
row = wheel -> gx_generic_scroll_wheel_top_index; |
134 |
|
43 |
wheel -> gx_scroll_wheel_selected_row = row + top_rows; |
135 |
|
|
|
136 |
|
|
/* Resize child widgets. */ |
137 |
✓✓ |
295 |
while (child) |
138 |
|
|
{ |
139 |
|
|
|
140 |
|
|
/* Increment child count. */ |
141 |
|
252 |
wheel -> gx_generic_scroll_wheel_child_count++; |
142 |
|
|
|
143 |
✓✓ |
252 |
if (childsize.gx_rectangle_top == selected_top) |
144 |
|
|
{ |
145 |
|
43 |
child -> gx_widget_style |= GX_STYLE_DRAW_SELECTED; |
146 |
|
|
} |
147 |
|
|
else |
148 |
|
|
{ |
149 |
|
209 |
child -> gx_widget_style &= (~GX_STYLE_DRAW_SELECTED); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
252 |
child -> gx_widget_status &= ~GX_STATUS_ACCEPTS_FOCUS; |
153 |
|
|
|
154 |
|
|
/* Resize widget. */ |
155 |
|
252 |
_gx_widget_resize(child, &childsize); |
156 |
|
|
|
157 |
|
252 |
_gx_utility_rectangle_shift(&childsize, 0, row_height); |
158 |
|
|
|
159 |
|
252 |
child = _gx_widget_next_visible_client_child_get(child); |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
/* Get client height. */ |
163 |
|
43 |
_gx_window_client_height_get((GX_WINDOW*)wheel, &height); |
164 |
|
|
|
165 |
|
|
/* Calculate number of visible rows. */ |
166 |
|
43 |
wheel -> gx_generic_scroll_wheel_visible_rows = (GX_VALUE)((height + row_height - 1) / row_height); |
167 |
|
|
|
168 |
✓✓ |
43 |
if (selected_row != wheel -> gx_scroll_wheel_selected_row) |
169 |
|
|
{ |
170 |
|
|
|
171 |
|
|
/* If current selected row is not match the configured row, |
172 |
|
|
scroll the widget to the configured row selected. */ |
173 |
|
37 |
row = wheel -> gx_scroll_wheel_selected_row - selected_row; |
174 |
|
|
|
175 |
|
37 |
_gx_generic_scroll_wheel_scroll(wheel, (GX_VALUE)(row_height * row)); |
176 |
|
|
} |
177 |
|
|
|
178 |
|
43 |
return GX_SUCCESS; |
179 |
|
|
} |
180 |
|
|
|