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 |
|
|
/** Scrollbar Management (Scrollbar) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#include "gx_api.h" |
27 |
|
|
#include "gx_system.h" |
28 |
|
|
#include "gx_display.h" |
29 |
|
|
#include "gx_context.h" |
30 |
|
|
#include "gx_widget.h" |
31 |
|
|
#include "gx_utility.h" |
32 |
|
|
#include "gx_scrollbar.h" |
33 |
|
|
|
34 |
|
|
/**************************************************************************/ |
35 |
|
|
/* */ |
36 |
|
|
/* FUNCTION RELEASE */ |
37 |
|
|
/* */ |
38 |
|
|
/* _gx_scrollbar_value_calculate PORTABLE C */ |
39 |
|
|
/* 6.1 */ |
40 |
|
|
/* AUTHOR */ |
41 |
|
|
/* */ |
42 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
43 |
|
|
/* */ |
44 |
|
|
/* DESCRIPTION */ |
45 |
|
|
/* */ |
46 |
|
|
/* Calculate new scrollbar value give thumb button offset and size */ |
47 |
|
|
/* */ |
48 |
|
|
/* */ |
49 |
|
|
/* INPUT */ |
50 |
|
|
/* */ |
51 |
|
|
/* scroll Scrollbar control block */ |
52 |
|
|
/* offset Thumb button offset */ |
53 |
|
|
/* size Thumb button height */ |
54 |
|
|
/* (vertical) or width */ |
55 |
|
|
/* (horizontal) */ |
56 |
|
|
/* */ |
57 |
|
|
/* OUTPUT */ |
58 |
|
|
/* */ |
59 |
|
|
/* None */ |
60 |
|
|
/* */ |
61 |
|
|
/* CALLS */ |
62 |
|
|
/* */ |
63 |
|
|
/* [gx_widget_event_process_function] Parent widget event process */ |
64 |
|
|
/* function */ |
65 |
|
|
/* */ |
66 |
|
|
/* CALLED BY */ |
67 |
|
|
/* */ |
68 |
|
|
/* GUIX Internal Code */ |
69 |
|
|
/* */ |
70 |
|
|
/**************************************************************************/ |
71 |
|
1221 |
VOID _gx_scrollbar_value_calculate(GX_SCROLLBAR *scroll, INT offset, INT size) |
72 |
|
|
{ |
73 |
|
|
GX_EVENT newevent; |
74 |
|
|
INT newval; |
75 |
|
|
INT oldval; |
76 |
|
|
INT travel; |
77 |
|
|
UINT style; |
78 |
|
|
|
79 |
|
|
/* calculate range of allowed values */ |
80 |
|
1221 |
newval = (scroll -> gx_scrollbar_info.gx_scroll_maximum - |
81 |
|
1221 |
scroll -> gx_scrollbar_info.gx_scroll_minimum) - |
82 |
|
1221 |
scroll -> gx_scrollbar_info.gx_scroll_visible + 1; |
83 |
|
|
|
84 |
|
|
/* scale this by distance thumb has traveled from minimum */ |
85 |
|
1221 |
style = scroll -> gx_widget_style; |
86 |
|
|
|
87 |
✓✓ |
1221 |
if (style & GX_SCROLLBAR_VERTICAL) |
88 |
|
|
{ |
89 |
|
478 |
newval *= offset - (scroll -> gx_widget_size.gx_rectangle_top + |
90 |
|
478 |
scroll -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min); |
91 |
|
|
|
92 |
|
|
/* calculate total travel allowed */ |
93 |
|
478 |
travel = (scroll -> gx_widget_size.gx_rectangle_bottom - |
94 |
|
478 |
scroll -> gx_widget_size.gx_rectangle_top) + 1; |
95 |
|
|
} |
96 |
|
|
else |
97 |
|
|
{ |
98 |
|
743 |
newval *= offset - (scroll -> gx_widget_size.gx_rectangle_left + |
99 |
|
743 |
scroll -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min); |
100 |
|
|
|
101 |
|
|
/* calculate total travel allowed */ |
102 |
|
743 |
travel = (scroll -> gx_widget_size.gx_rectangle_right - |
103 |
|
743 |
scroll -> gx_widget_size.gx_rectangle_left) + 1; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
1221 |
travel -= scroll -> gx_scrollbar_appearance.gx_scroll_thumb_travel_max + |
107 |
|
1221 |
scroll -> gx_scrollbar_appearance.gx_scroll_thumb_travel_min; |
108 |
|
|
|
109 |
|
1221 |
travel -= size; |
110 |
|
|
|
111 |
|
|
/* scale the value using linear interpolation */ |
112 |
✓✓ |
1221 |
if (travel) |
113 |
|
|
{ |
114 |
|
1220 |
newval = (newval + (travel >> 1)) / travel; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
/* offset the value based on minimum */ |
118 |
|
1221 |
newval += scroll -> gx_scrollbar_info.gx_scroll_minimum; |
119 |
|
|
|
120 |
|
|
/* make sure we stay within desired range */ |
121 |
|
1221 |
oldval = scroll -> gx_scrollbar_info.gx_scroll_value; |
122 |
|
1221 |
scroll -> gx_scrollbar_info.gx_scroll_value = newval; |
123 |
|
1221 |
_gx_scrollbar_limit_check(scroll); |
124 |
|
|
|
125 |
|
|
/* if the value has changed, send a scroll event to my parent */ |
126 |
✓✓ |
1221 |
if (scroll -> gx_scrollbar_info.gx_scroll_value != oldval) |
127 |
|
|
{ |
128 |
|
|
/* pass the old value in data[1] */ |
129 |
|
1219 |
newevent.gx_event_payload.gx_event_intdata[1] = oldval; |
130 |
|
1219 |
newevent.gx_event_payload.gx_event_intdata[0] = scroll -> gx_scrollbar_info.gx_scroll_value; |
131 |
|
|
|
132 |
✓✓ |
1219 |
if (style & GX_SCROLLBAR_VERTICAL) |
133 |
|
|
{ |
134 |
|
476 |
newevent.gx_event_sender = GX_ID_VERTICAL_SCROLL; |
135 |
|
476 |
newevent.gx_event_type = GX_EVENT_VERTICAL_SCROLL; |
136 |
|
|
} |
137 |
|
|
else |
138 |
|
|
{ |
139 |
|
743 |
newevent.gx_event_sender = GX_ID_HORIZONTAL_SCROLL; |
140 |
|
743 |
newevent.gx_event_type = GX_EVENT_HORIZONTAL_SCROLL; |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
/* send event to my parent window */ |
144 |
|
1219 |
newevent.gx_event_target = scroll -> gx_widget_parent; |
145 |
|
1219 |
_gx_system_event_send(&newevent); |
146 |
|
|
} |
147 |
|
1221 |
} |
148 |
|
|
|