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