Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: xfa/fwl/core/cfwl_scrollbar.cpp

Issue 2525083002: Rename IFWL classes which do not have CFWL equivalents (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fwl/core/cfwl_scrollbar.h ('k') | xfa/fwl/core/cfwl_spinbutton.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fwl/core/ifwl_scrollbar.h" 7 #include "xfa/fwl/core/cfwl_scrollbar.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 12
13 #include "third_party/base/ptr_util.h" 13 #include "third_party/base/ptr_util.h"
14 #include "xfa/fwl/core/cfwl_msgmouse.h" 14 #include "xfa/fwl/core/cfwl_msgmouse.h"
15 #include "xfa/fwl/core/cfwl_msgmousewheel.h" 15 #include "xfa/fwl/core/cfwl_msgmousewheel.h"
16 #include "xfa/fwl/core/cfwl_notedriver.h" 16 #include "xfa/fwl/core/cfwl_notedriver.h"
17 #include "xfa/fwl/core/cfwl_themebackground.h" 17 #include "xfa/fwl/core/cfwl_themebackground.h"
18 #include "xfa/fwl/core/cfwl_themepart.h" 18 #include "xfa/fwl/core/cfwl_themepart.h"
19 #include "xfa/fwl/core/cfwl_timerinfo.h" 19 #include "xfa/fwl/core/cfwl_timerinfo.h"
20 #include "xfa/fwl/core/ifwl_themeprovider.h" 20 #include "xfa/fwl/core/ifwl_themeprovider.h"
21 21
22 #define FWL_SCROLLBAR_Elapse 500 22 #define FWL_SCROLLBAR_Elapse 500
23 #define FWL_SCROLLBAR_MinThumb 5 23 #define FWL_SCROLLBAR_MinThumb 5
24 24
25 IFWL_ScrollBar::IFWL_ScrollBar( 25 CFWL_ScrollBar::CFWL_ScrollBar(
26 const CFWL_App* app, 26 const CFWL_App* app,
27 std::unique_ptr<CFWL_WidgetProperties> properties, 27 std::unique_ptr<CFWL_WidgetProperties> properties,
28 IFWL_Widget* pOuter) 28 IFWL_Widget* pOuter)
29 : IFWL_Widget(app, std::move(properties), pOuter), 29 : IFWL_Widget(app, std::move(properties), pOuter),
30 m_pTimerInfo(nullptr), 30 m_pTimerInfo(nullptr),
31 m_fRangeMin(0), 31 m_fRangeMin(0),
32 m_fRangeMax(-1), 32 m_fRangeMax(-1),
33 m_fPageSize(0), 33 m_fPageSize(0),
34 m_fStepSize(0), 34 m_fStepSize(0),
35 m_fPos(0), 35 m_fPos(0),
(...skipping 13 matching lines...) Expand all
49 m_fMinThumb(FWL_SCROLLBAR_MinThumb), 49 m_fMinThumb(FWL_SCROLLBAR_MinThumb),
50 m_Timer(this) { 50 m_Timer(this) {
51 m_rtClient.Reset(); 51 m_rtClient.Reset();
52 m_rtThumb.Reset(); 52 m_rtThumb.Reset();
53 m_rtMinBtn.Reset(); 53 m_rtMinBtn.Reset();
54 m_rtMaxBtn.Reset(); 54 m_rtMaxBtn.Reset();
55 m_rtMinTrack.Reset(); 55 m_rtMinTrack.Reset();
56 m_rtMaxTrack.Reset(); 56 m_rtMaxTrack.Reset();
57 } 57 }
58 58
59 IFWL_ScrollBar::~IFWL_ScrollBar() {} 59 CFWL_ScrollBar::~CFWL_ScrollBar() {}
60 60
61 FWL_Type IFWL_ScrollBar::GetClassID() const { 61 FWL_Type CFWL_ScrollBar::GetClassID() const {
62 return FWL_Type::ScrollBar; 62 return FWL_Type::ScrollBar;
63 } 63 }
64 64
65 void IFWL_ScrollBar::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { 65 void CFWL_ScrollBar::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) {
66 if (!bAutoSize) { 66 if (!bAutoSize) {
67 rect = m_pProperties->m_rtWidget; 67 rect = m_pProperties->m_rtWidget;
68 return; 68 return;
69 } 69 }
70 70
71 rect.Set(0, 0, 0, 0); 71 rect.Set(0, 0, 0, 0);
72 FX_FLOAT* pfMinWidth = static_cast<FX_FLOAT*>( 72 FX_FLOAT* pfMinWidth = static_cast<FX_FLOAT*>(
73 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); 73 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
74 if (!pfMinWidth) 74 if (!pfMinWidth)
75 return; 75 return;
76 if (IsVertical()) 76 if (IsVertical())
77 rect.Set(0, 0, (*pfMinWidth), (*pfMinWidth) * 3); 77 rect.Set(0, 0, (*pfMinWidth), (*pfMinWidth) * 3);
78 else 78 else
79 rect.Set(0, 0, (*pfMinWidth) * 3, (*pfMinWidth)); 79 rect.Set(0, 0, (*pfMinWidth) * 3, (*pfMinWidth));
80 IFWL_Widget::GetWidgetRect(rect, true); 80 IFWL_Widget::GetWidgetRect(rect, true);
81 } 81 }
82 82
83 void IFWL_ScrollBar::Update() { 83 void CFWL_ScrollBar::Update() {
84 if (IsLocked()) 84 if (IsLocked())
85 return; 85 return;
86 if (!m_pProperties->m_pThemeProvider) 86 if (!m_pProperties->m_pThemeProvider)
87 m_pProperties->m_pThemeProvider = GetAvailableTheme(); 87 m_pProperties->m_pThemeProvider = GetAvailableTheme();
88 88
89 Layout(); 89 Layout();
90 } 90 }
91 91
92 void IFWL_ScrollBar::DrawWidget(CFX_Graphics* pGraphics, 92 void CFWL_ScrollBar::DrawWidget(CFX_Graphics* pGraphics,
93 const CFX_Matrix* pMatrix) { 93 const CFX_Matrix* pMatrix) {
94 if (!pGraphics) 94 if (!pGraphics)
95 return; 95 return;
96 if (!m_pProperties->m_pThemeProvider) 96 if (!m_pProperties->m_pThemeProvider)
97 return; 97 return;
98 98
99 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; 99 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
100 if (HasBorder()) 100 if (HasBorder())
101 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); 101 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix);
102 if (HasEdge()) 102 if (HasEdge())
103 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); 103 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix);
104 DrawTrack(pGraphics, pTheme, true, pMatrix); 104 DrawTrack(pGraphics, pTheme, true, pMatrix);
105 DrawTrack(pGraphics, pTheme, false, pMatrix); 105 DrawTrack(pGraphics, pTheme, false, pMatrix);
106 DrawArrowBtn(pGraphics, pTheme, true, pMatrix); 106 DrawArrowBtn(pGraphics, pTheme, true, pMatrix);
107 DrawArrowBtn(pGraphics, pTheme, false, pMatrix); 107 DrawArrowBtn(pGraphics, pTheme, false, pMatrix);
108 DrawThumb(pGraphics, pTheme, pMatrix); 108 DrawThumb(pGraphics, pTheme, pMatrix);
109 } 109 }
110 110
111 void IFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { 111 void CFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) {
112 m_fTrackPos = fTrackPos; 112 m_fTrackPos = fTrackPos;
113 CalcThumbButtonRect(m_rtThumb); 113 CalcThumbButtonRect(m_rtThumb);
114 CalcMinTrackRect(m_rtMinTrack); 114 CalcMinTrackRect(m_rtMinTrack);
115 CalcMaxTrackRect(m_rtMaxTrack); 115 CalcMaxTrackRect(m_rtMaxTrack);
116 } 116 }
117 117
118 bool IFWL_ScrollBar::DoScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos) { 118 bool CFWL_ScrollBar::DoScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos) {
119 if (dwCode == FWL_SCBCODE::None) 119 if (dwCode == FWL_SCBCODE::None)
120 return false; 120 return false;
121 return OnScroll(dwCode, fPos); 121 return OnScroll(dwCode, fPos);
122 } 122 }
123 123
124 void IFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, 124 void CFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics,
125 IFWL_ThemeProvider* pTheme, 125 IFWL_ThemeProvider* pTheme,
126 bool bLower, 126 bool bLower,
127 const CFX_Matrix* pMatrix) { 127 const CFX_Matrix* pMatrix) {
128 CFWL_ThemeBackground param; 128 CFWL_ThemeBackground param;
129 param.m_pWidget = this; 129 param.m_pWidget = this;
130 param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack; 130 param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack;
131 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) 131 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
132 ? CFWL_PartState_Disabled 132 ? CFWL_PartState_Disabled
133 : (bLower ? m_iMinTrackState : m_iMaxTrackState); 133 : (bLower ? m_iMinTrackState : m_iMaxTrackState);
134 param.m_pGraphics = pGraphics; 134 param.m_pGraphics = pGraphics;
135 param.m_matrix.Concat(*pMatrix); 135 param.m_matrix.Concat(*pMatrix);
136 param.m_rtPart = bLower ? m_rtMinTrack : m_rtMaxTrack; 136 param.m_rtPart = bLower ? m_rtMinTrack : m_rtMaxTrack;
137 pTheme->DrawBackground(&param); 137 pTheme->DrawBackground(&param);
138 } 138 }
139 139
140 void IFWL_ScrollBar::DrawArrowBtn(CFX_Graphics* pGraphics, 140 void CFWL_ScrollBar::DrawArrowBtn(CFX_Graphics* pGraphics,
141 IFWL_ThemeProvider* pTheme, 141 IFWL_ThemeProvider* pTheme,
142 bool bMinBtn, 142 bool bMinBtn,
143 const CFX_Matrix* pMatrix) { 143 const CFX_Matrix* pMatrix) {
144 CFWL_ThemeBackground param; 144 CFWL_ThemeBackground param;
145 param.m_pWidget = this; 145 param.m_pWidget = this;
146 param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow; 146 param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow;
147 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) 147 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
148 ? CFWL_PartState_Disabled 148 ? CFWL_PartState_Disabled
149 : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState); 149 : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState);
150 param.m_pGraphics = pGraphics; 150 param.m_pGraphics = pGraphics;
151 param.m_matrix.Concat(*pMatrix); 151 param.m_matrix.Concat(*pMatrix);
152 param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn; 152 param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn;
153 if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0) 153 if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0)
154 pTheme->DrawBackground(&param); 154 pTheme->DrawBackground(&param);
155 } 155 }
156 156
157 void IFWL_ScrollBar::DrawThumb(CFX_Graphics* pGraphics, 157 void CFWL_ScrollBar::DrawThumb(CFX_Graphics* pGraphics,
158 IFWL_ThemeProvider* pTheme, 158 IFWL_ThemeProvider* pTheme,
159 const CFX_Matrix* pMatrix) { 159 const CFX_Matrix* pMatrix) {
160 CFWL_ThemeBackground param; 160 CFWL_ThemeBackground param;
161 param.m_pWidget = this; 161 param.m_pWidget = this;
162 param.m_iPart = CFWL_Part::Thumb; 162 param.m_iPart = CFWL_Part::Thumb;
163 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) 163 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
164 ? CFWL_PartState_Disabled 164 ? CFWL_PartState_Disabled
165 : m_iThumbButtonState; 165 : m_iThumbButtonState;
166 param.m_pGraphics = pGraphics; 166 param.m_pGraphics = pGraphics;
167 param.m_matrix.Concat(*pMatrix); 167 param.m_matrix.Concat(*pMatrix);
168 param.m_rtPart = m_rtThumb; 168 param.m_rtPart = m_rtThumb;
169 pTheme->DrawBackground(&param); 169 pTheme->DrawBackground(&param);
170 } 170 }
171 171
172 void IFWL_ScrollBar::Layout() { 172 void CFWL_ScrollBar::Layout() {
173 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; 173 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
174 CFWL_ThemePart part; 174 CFWL_ThemePart part;
175 part.m_pWidget = this; 175 part.m_pWidget = this;
176 m_fMinThumb = *static_cast<FX_FLOAT*>( 176 m_fMinThumb = *static_cast<FX_FLOAT*>(
177 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Size)); 177 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Size));
178 GetClientRect(m_rtClient); 178 GetClientRect(m_rtClient);
179 CalcButtonLen(); 179 CalcButtonLen();
180 CalcMinButtonRect(m_rtMinBtn); 180 CalcMinButtonRect(m_rtMinBtn);
181 CalcMaxButtonRect(m_rtMaxBtn); 181 CalcMaxButtonRect(m_rtMaxBtn);
182 CalcThumbButtonRect(m_rtThumb); 182 CalcThumbButtonRect(m_rtThumb);
183 CalcMinTrackRect(m_rtMinTrack); 183 CalcMinTrackRect(m_rtMinTrack);
184 CalcMaxTrackRect(m_rtMaxTrack); 184 CalcMaxTrackRect(m_rtMaxTrack);
185 } 185 }
186 186
187 void IFWL_ScrollBar::CalcButtonLen() { 187 void CFWL_ScrollBar::CalcButtonLen() {
188 m_fButtonLen = IsVertical() ? m_rtClient.width : m_rtClient.height; 188 m_fButtonLen = IsVertical() ? m_rtClient.width : m_rtClient.height;
189 FX_FLOAT fLength = IsVertical() ? m_rtClient.height : m_rtClient.width; 189 FX_FLOAT fLength = IsVertical() ? m_rtClient.height : m_rtClient.width;
190 if (fLength < m_fButtonLen * 2) { 190 if (fLength < m_fButtonLen * 2) {
191 m_fButtonLen = fLength / 2; 191 m_fButtonLen = fLength / 2;
192 m_bMinSize = true; 192 m_bMinSize = true;
193 } else { 193 } else {
194 m_bMinSize = false; 194 m_bMinSize = false;
195 } 195 }
196 } 196 }
197 197
198 void IFWL_ScrollBar::CalcMinButtonRect(CFX_RectF& rect) { 198 void CFWL_ScrollBar::CalcMinButtonRect(CFX_RectF& rect) {
199 rect.left = m_rtClient.left; 199 rect.left = m_rtClient.left;
200 rect.top = m_rtClient.top; 200 rect.top = m_rtClient.top;
201 rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; 201 rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen;
202 rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; 202 rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height;
203 } 203 }
204 204
205 void IFWL_ScrollBar::CalcMaxButtonRect(CFX_RectF& rect) { 205 void CFWL_ScrollBar::CalcMaxButtonRect(CFX_RectF& rect) {
206 rect.left = 206 rect.left =
207 IsVertical() ? m_rtClient.left : m_rtClient.right() - m_fButtonLen; 207 IsVertical() ? m_rtClient.left : m_rtClient.right() - m_fButtonLen;
208 rect.top = IsVertical() ? m_rtClient.bottom() - m_fButtonLen : m_rtClient.top; 208 rect.top = IsVertical() ? m_rtClient.bottom() - m_fButtonLen : m_rtClient.top;
209 rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; 209 rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen;
210 rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; 210 rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height;
211 } 211 }
212 212
213 void IFWL_ScrollBar::CalcThumbButtonRect(CFX_RectF& rect) { 213 void CFWL_ScrollBar::CalcThumbButtonRect(CFX_RectF& rect) {
214 if (!IsEnabled()) { 214 if (!IsEnabled()) {
215 m_rtThumb.Reset(); 215 m_rtThumb.Reset();
216 return; 216 return;
217 } 217 }
218 if (m_bMinSize) { 218 if (m_bMinSize) {
219 m_rtThumb.Empty(); 219 m_rtThumb.Empty();
220 return; 220 return;
221 } 221 }
222 222
223 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; 223 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin;
(...skipping 28 matching lines...) Expand all
252 rect.left += iPos; 252 rect.left += iPos;
253 253
254 rect.top = rtClient.top; 254 rect.top = rtClient.top;
255 if (IsVertical()) 255 if (IsVertical())
256 rect.top += iPos; 256 rect.top += iPos;
257 257
258 rect.width = IsVertical() ? rtClient.width : fThumbSize; 258 rect.width = IsVertical() ? rtClient.width : fThumbSize;
259 rect.height = IsVertical() ? fThumbSize : rtClient.height; 259 rect.height = IsVertical() ? fThumbSize : rtClient.height;
260 } 260 }
261 261
262 void IFWL_ScrollBar::CalcMinTrackRect(CFX_RectF& rect) { 262 void CFWL_ScrollBar::CalcMinTrackRect(CFX_RectF& rect) {
263 if (m_bMinSize) { 263 if (m_bMinSize) {
264 rect.Empty(); 264 rect.Empty();
265 return; 265 return;
266 } 266 }
267 267
268 FX_FLOAT fBottom = m_rtThumb.bottom(); 268 FX_FLOAT fBottom = m_rtThumb.bottom();
269 FX_FLOAT fRight = m_rtThumb.right(); 269 FX_FLOAT fRight = m_rtThumb.right();
270 FX_FLOAT ix = (m_rtThumb.left + fRight) / 2; 270 FX_FLOAT ix = (m_rtThumb.left + fRight) / 2;
271 FX_FLOAT iy = (m_rtThumb.top + fBottom) / 2; 271 FX_FLOAT iy = (m_rtThumb.top + fBottom) / 2;
272 rect.left = m_rtClient.left; 272 rect.left = m_rtClient.left;
273 rect.top = m_rtClient.top; 273 rect.top = m_rtClient.top;
274 bool bVertical = IsVertical(); 274 bool bVertical = IsVertical();
275 rect.width = bVertical ? m_rtClient.width : ix; 275 rect.width = bVertical ? m_rtClient.width : ix;
276 rect.height = bVertical ? iy : m_rtClient.height; 276 rect.height = bVertical ? iy : m_rtClient.height;
277 } 277 }
278 278
279 void IFWL_ScrollBar::CalcMaxTrackRect(CFX_RectF& rect) { 279 void CFWL_ScrollBar::CalcMaxTrackRect(CFX_RectF& rect) {
280 if (m_bMinSize) { 280 if (m_bMinSize) {
281 rect.Empty(); 281 rect.Empty();
282 return; 282 return;
283 } 283 }
284 284
285 FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2; 285 FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2;
286 FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2; 286 FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2;
287 bool bVertical = IsVertical(); 287 bool bVertical = IsVertical();
288 rect.left = bVertical ? m_rtClient.left : ix; 288 rect.left = bVertical ? m_rtClient.left : ix;
289 rect.top = bVertical ? iy : m_rtClient.top; 289 rect.top = bVertical ? iy : m_rtClient.top;
290 rect.width = bVertical ? m_rtClient.width : m_rtClient.right() - ix; 290 rect.width = bVertical ? m_rtClient.width : m_rtClient.right() - ix;
291 rect.height = bVertical ? m_rtClient.bottom() - iy : m_rtClient.height; 291 rect.height = bVertical ? m_rtClient.bottom() - iy : m_rtClient.height;
292 } 292 }
293 293
294 FX_FLOAT IFWL_ScrollBar::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) { 294 FX_FLOAT CFWL_ScrollBar::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) {
295 FX_FLOAT fDiffX = fx - m_cpTrackPointX; 295 FX_FLOAT fDiffX = fx - m_cpTrackPointX;
296 FX_FLOAT fDiffY = fy - m_cpTrackPointY; 296 FX_FLOAT fDiffY = fy - m_cpTrackPointY;
297 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; 297 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin;
298 FX_FLOAT fPos; 298 FX_FLOAT fPos;
299 299
300 if (IsVertical()) { 300 if (IsVertical()) {
301 fPos = fRange * fDiffY / 301 fPos = fRange * fDiffY /
302 (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); 302 (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height);
303 } else { 303 } else {
304 fPos = fRange * fDiffX / 304 fPos = fRange * fDiffX /
305 (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); 305 (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width);
306 } 306 }
307 307
308 fPos += m_fLastTrackPos; 308 fPos += m_fLastTrackPos;
309 return std::min(std::max(fPos, m_fRangeMin), m_fRangeMax); 309 return std::min(std::max(fPos, m_fRangeMin), m_fRangeMax);
310 } 310 }
311 311
312 void IFWL_ScrollBar::GetTrackRect(CFX_RectF& rect, bool bLower) { 312 void CFWL_ScrollBar::GetTrackRect(CFX_RectF& rect, bool bLower) {
313 bool bDisabled = !!(m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled); 313 bool bDisabled = !!(m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled);
314 if (bDisabled) { 314 if (bDisabled) {
315 rect = bLower ? m_rtMinTrack : m_rtMaxTrack; 315 rect = bLower ? m_rtMinTrack : m_rtMaxTrack;
316 return; 316 return;
317 } 317 }
318 318
319 FX_FLOAT fW = m_rtThumb.width / 2; 319 FX_FLOAT fW = m_rtThumb.width / 2;
320 FX_FLOAT fH = m_rtThumb.height / 2; 320 FX_FLOAT fH = m_rtThumb.height / 2;
321 bool bVert = IsVertical(); 321 bool bVert = IsVertical();
322 if (bLower) { 322 if (bLower) {
(...skipping 19 matching lines...) Expand all
342 fMaxTrackHeight); 342 fMaxTrackHeight);
343 return; 343 return;
344 } 344 }
345 345
346 FX_FLOAT fMaxTrackWidth = m_rtMaxTrack.width - fW - m_rtMaxBtn.width + 2; 346 FX_FLOAT fMaxTrackWidth = m_rtMaxTrack.width - fW - m_rtMaxBtn.width + 2;
347 fMaxTrackWidth = (fMaxTrackWidth >= 0.0f) ? fMaxTrackWidth : 0.0f; 347 fMaxTrackWidth = (fMaxTrackWidth >= 0.0f) ? fMaxTrackWidth : 0.0f;
348 rect.Set(m_rtMaxTrack.left + fW, m_rtMaxTrack.top, fMaxTrackWidth, 348 rect.Set(m_rtMaxTrack.left + fW, m_rtMaxTrack.top, fMaxTrackWidth,
349 m_rtMaxTrack.height); 349 m_rtMaxTrack.height);
350 } 350 }
351 351
352 bool IFWL_ScrollBar::SendEvent() { 352 bool CFWL_ScrollBar::SendEvent() {
353 if (m_iMinButtonState == CFWL_PartState_Pressed) { 353 if (m_iMinButtonState == CFWL_PartState_Pressed) {
354 DoScroll(FWL_SCBCODE::StepBackward, m_fTrackPos); 354 DoScroll(FWL_SCBCODE::StepBackward, m_fTrackPos);
355 return false; 355 return false;
356 } 356 }
357 if (m_iMaxButtonState == CFWL_PartState_Pressed) { 357 if (m_iMaxButtonState == CFWL_PartState_Pressed) {
358 DoScroll(FWL_SCBCODE::StepForward, m_fTrackPos); 358 DoScroll(FWL_SCBCODE::StepForward, m_fTrackPos);
359 return false; 359 return false;
360 } 360 }
361 if (m_iMinTrackState == CFWL_PartState_Pressed) { 361 if (m_iMinTrackState == CFWL_PartState_Pressed) {
362 DoScroll(FWL_SCBCODE::PageBackward, m_fTrackPos); 362 DoScroll(FWL_SCBCODE::PageBackward, m_fTrackPos);
363 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); 363 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY);
364 } 364 }
365 if (m_iMaxTrackState == CFWL_PartState_Pressed) { 365 if (m_iMaxTrackState == CFWL_PartState_Pressed) {
366 DoScroll(FWL_SCBCODE::PageForward, m_fTrackPos); 366 DoScroll(FWL_SCBCODE::PageForward, m_fTrackPos);
367 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); 367 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY);
368 } 368 }
369 if (m_iMouseWheel) { 369 if (m_iMouseWheel) {
370 FWL_SCBCODE dwCode = m_iMouseWheel < 0 ? FWL_SCBCODE::StepForward 370 FWL_SCBCODE dwCode = m_iMouseWheel < 0 ? FWL_SCBCODE::StepForward
371 : FWL_SCBCODE::StepBackward; 371 : FWL_SCBCODE::StepBackward;
372 DoScroll(dwCode, m_fTrackPos); 372 DoScroll(dwCode, m_fTrackPos);
373 } 373 }
374 return true; 374 return true;
375 } 375 }
376 376
377 bool IFWL_ScrollBar::OnScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos) { 377 bool CFWL_ScrollBar::OnScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos) {
378 bool bRet = true; 378 bool bRet = true;
379 CFWL_EvtScroll ev; 379 CFWL_EvtScroll ev;
380 ev.m_iScrollCode = dwCode; 380 ev.m_iScrollCode = dwCode;
381 ev.m_pSrcTarget = this; 381 ev.m_pSrcTarget = this;
382 ev.m_fPos = fPos; 382 ev.m_fPos = fPos;
383 ev.m_pRet = &bRet; 383 ev.m_pRet = &bRet;
384 DispatchEvent(&ev); 384 DispatchEvent(&ev);
385 return bRet; 385 return bRet;
386 } 386 }
387 387
388 void IFWL_ScrollBar::OnProcessMessage(CFWL_Message* pMessage) { 388 void CFWL_ScrollBar::OnProcessMessage(CFWL_Message* pMessage) {
389 if (!pMessage) 389 if (!pMessage)
390 return; 390 return;
391 391
392 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); 392 CFWL_MessageType dwMsgCode = pMessage->GetClassID();
393 if (dwMsgCode == CFWL_MessageType::Mouse) { 393 if (dwMsgCode == CFWL_MessageType::Mouse) {
394 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); 394 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage);
395 switch (pMsg->m_dwCmd) { 395 switch (pMsg->m_dwCmd) {
396 case FWL_MouseCommand::LeftButtonDown: 396 case FWL_MouseCommand::LeftButtonDown:
397 OnLButtonDown(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); 397 OnLButtonDown(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy);
398 break; 398 break;
399 case FWL_MouseCommand::LeftButtonUp: 399 case FWL_MouseCommand::LeftButtonUp:
400 OnLButtonUp(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); 400 OnLButtonUp(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy);
401 break; 401 break;
402 case FWL_MouseCommand::Move: 402 case FWL_MouseCommand::Move:
403 OnMouseMove(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); 403 OnMouseMove(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy);
404 break; 404 break;
405 case FWL_MouseCommand::Leave: 405 case FWL_MouseCommand::Leave:
406 OnMouseLeave(); 406 OnMouseLeave();
407 break; 407 break;
408 default: 408 default:
409 break; 409 break;
410 } 410 }
411 } else if (dwMsgCode == CFWL_MessageType::MouseWheel) { 411 } else if (dwMsgCode == CFWL_MessageType::MouseWheel) {
412 CFWL_MsgMouseWheel* pMsg = static_cast<CFWL_MsgMouseWheel*>(pMessage); 412 CFWL_MsgMouseWheel* pMsg = static_cast<CFWL_MsgMouseWheel*>(pMessage);
413 OnMouseWheel(pMsg->m_fx, pMsg->m_fy, pMsg->m_dwFlags, pMsg->m_fDeltaX, 413 OnMouseWheel(pMsg->m_fx, pMsg->m_fy, pMsg->m_dwFlags, pMsg->m_fDeltaX,
414 pMsg->m_fDeltaY); 414 pMsg->m_fDeltaY);
415 } 415 }
416 } 416 }
417 417
418 void IFWL_ScrollBar::OnDrawWidget(CFX_Graphics* pGraphics, 418 void CFWL_ScrollBar::OnDrawWidget(CFX_Graphics* pGraphics,
419 const CFX_Matrix* pMatrix) { 419 const CFX_Matrix* pMatrix) {
420 DrawWidget(pGraphics, pMatrix); 420 DrawWidget(pGraphics, pMatrix);
421 } 421 }
422 422
423 void IFWL_ScrollBar::OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { 423 void CFWL_ScrollBar::OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) {
424 if (!IsEnabled()) 424 if (!IsEnabled())
425 return; 425 return;
426 426
427 m_bMouseDown = true; 427 m_bMouseDown = true;
428 SetGrab(true); 428 SetGrab(true);
429 m_cpTrackPointX = fx; 429 m_cpTrackPointX = fx;
430 m_cpTrackPointY = fy; 430 m_cpTrackPointY = fy;
431 m_fLastTrackPos = m_fTrackPos; 431 m_fLastTrackPos = m_fTrackPos;
432 if (m_rtMinBtn.Contains(fx, fy)) 432 if (m_rtMinBtn.Contains(fx, fy))
433 DoMouseDown(0, m_rtMinBtn, m_iMinButtonState, fx, fy); 433 DoMouseDown(0, m_rtMinBtn, m_iMinButtonState, fx, fy);
434 else if (m_rtThumb.Contains(fx, fy)) 434 else if (m_rtThumb.Contains(fx, fy))
435 DoMouseDown(1, m_rtThumb, m_iThumbButtonState, fx, fy); 435 DoMouseDown(1, m_rtThumb, m_iThumbButtonState, fx, fy);
436 else if (m_rtMaxBtn.Contains(fx, fy)) 436 else if (m_rtMaxBtn.Contains(fx, fy))
437 DoMouseDown(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); 437 DoMouseDown(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy);
438 else if (m_rtMinTrack.Contains(fx, fy)) 438 else if (m_rtMinTrack.Contains(fx, fy))
439 DoMouseDown(3, m_rtMinTrack, m_iMinTrackState, fx, fy); 439 DoMouseDown(3, m_rtMinTrack, m_iMinTrackState, fx, fy);
440 else 440 else
441 DoMouseDown(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); 441 DoMouseDown(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy);
442 442
443 if (!SendEvent()) 443 if (!SendEvent())
444 m_pTimerInfo = m_Timer.StartTimer(FWL_SCROLLBAR_Elapse, true); 444 m_pTimerInfo = m_Timer.StartTimer(FWL_SCROLLBAR_Elapse, true);
445 } 445 }
446 446
447 void IFWL_ScrollBar::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { 447 void CFWL_ScrollBar::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) {
448 m_pTimerInfo->StopTimer(); 448 m_pTimerInfo->StopTimer();
449 m_bMouseDown = false; 449 m_bMouseDown = false;
450 DoMouseUp(0, m_rtMinBtn, m_iMinButtonState, fx, fy); 450 DoMouseUp(0, m_rtMinBtn, m_iMinButtonState, fx, fy);
451 DoMouseUp(1, m_rtThumb, m_iThumbButtonState, fx, fy); 451 DoMouseUp(1, m_rtThumb, m_iThumbButtonState, fx, fy);
452 DoMouseUp(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); 452 DoMouseUp(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy);
453 DoMouseUp(3, m_rtMinTrack, m_iMinTrackState, fx, fy); 453 DoMouseUp(3, m_rtMinTrack, m_iMinTrackState, fx, fy);
454 DoMouseUp(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); 454 DoMouseUp(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy);
455 SetGrab(false); 455 SetGrab(false);
456 } 456 }
457 457
458 void IFWL_ScrollBar::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { 458 void CFWL_ScrollBar::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) {
459 DoMouseMove(0, m_rtMinBtn, m_iMinButtonState, fx, fy); 459 DoMouseMove(0, m_rtMinBtn, m_iMinButtonState, fx, fy);
460 DoMouseMove(1, m_rtThumb, m_iThumbButtonState, fx, fy); 460 DoMouseMove(1, m_rtThumb, m_iThumbButtonState, fx, fy);
461 DoMouseMove(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); 461 DoMouseMove(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy);
462 DoMouseMove(3, m_rtMinTrack, m_iMinTrackState, fx, fy); 462 DoMouseMove(3, m_rtMinTrack, m_iMinTrackState, fx, fy);
463 DoMouseMove(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); 463 DoMouseMove(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy);
464 } 464 }
465 465
466 void IFWL_ScrollBar::OnMouseLeave() { 466 void CFWL_ScrollBar::OnMouseLeave() {
467 DoMouseLeave(0, m_rtMinBtn, m_iMinButtonState); 467 DoMouseLeave(0, m_rtMinBtn, m_iMinButtonState);
468 DoMouseLeave(1, m_rtThumb, m_iThumbButtonState); 468 DoMouseLeave(1, m_rtThumb, m_iThumbButtonState);
469 DoMouseLeave(2, m_rtMaxBtn, m_iMaxButtonState); 469 DoMouseLeave(2, m_rtMaxBtn, m_iMaxButtonState);
470 DoMouseLeave(3, m_rtMinTrack, m_iMinTrackState); 470 DoMouseLeave(3, m_rtMinTrack, m_iMinTrackState);
471 DoMouseLeave(4, m_rtMaxTrack, m_iMaxTrackState); 471 DoMouseLeave(4, m_rtMaxTrack, m_iMaxTrackState);
472 } 472 }
473 473
474 void IFWL_ScrollBar::OnMouseWheel(FX_FLOAT fx, 474 void CFWL_ScrollBar::OnMouseWheel(FX_FLOAT fx,
475 FX_FLOAT fy, 475 FX_FLOAT fy,
476 uint32_t dwFlags, 476 uint32_t dwFlags,
477 FX_FLOAT fDeltaX, 477 FX_FLOAT fDeltaX,
478 FX_FLOAT fDeltaY) { 478 FX_FLOAT fDeltaY) {
479 m_iMouseWheel = (int32_t)fDeltaX; 479 m_iMouseWheel = (int32_t)fDeltaX;
480 SendEvent(); 480 SendEvent();
481 m_iMouseWheel = 0; 481 m_iMouseWheel = 0;
482 } 482 }
483 483
484 void IFWL_ScrollBar::DoMouseDown(int32_t iItem, 484 void CFWL_ScrollBar::DoMouseDown(int32_t iItem,
485 const CFX_RectF& rtItem, 485 const CFX_RectF& rtItem,
486 int32_t& iState, 486 int32_t& iState,
487 FX_FLOAT fx, 487 FX_FLOAT fx,
488 FX_FLOAT fy) { 488 FX_FLOAT fy) {
489 if (!rtItem.Contains(fx, fy)) 489 if (!rtItem.Contains(fx, fy))
490 return; 490 return;
491 if (iState == CFWL_PartState_Pressed) 491 if (iState == CFWL_PartState_Pressed)
492 return; 492 return;
493 493
494 iState = CFWL_PartState_Pressed; 494 iState = CFWL_PartState_Pressed;
495 Repaint(&rtItem); 495 Repaint(&rtItem);
496 } 496 }
497 497
498 void IFWL_ScrollBar::DoMouseUp(int32_t iItem, 498 void CFWL_ScrollBar::DoMouseUp(int32_t iItem,
499 const CFX_RectF& rtItem, 499 const CFX_RectF& rtItem,
500 int32_t& iState, 500 int32_t& iState,
501 FX_FLOAT fx, 501 FX_FLOAT fx,
502 FX_FLOAT fy) { 502 FX_FLOAT fy) {
503 int32_t iNewState = 503 int32_t iNewState =
504 rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; 504 rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal;
505 if (iState == iNewState) 505 if (iState == iNewState)
506 return; 506 return;
507 507
508 iState = iNewState; 508 iState = iNewState;
509 Repaint(&rtItem); 509 Repaint(&rtItem);
510 OnScroll(FWL_SCBCODE::EndScroll, m_fTrackPos); 510 OnScroll(FWL_SCBCODE::EndScroll, m_fTrackPos);
511 } 511 }
512 512
513 void IFWL_ScrollBar::DoMouseMove(int32_t iItem, 513 void CFWL_ScrollBar::DoMouseMove(int32_t iItem,
514 const CFX_RectF& rtItem, 514 const CFX_RectF& rtItem,
515 int32_t& iState, 515 int32_t& iState,
516 FX_FLOAT fx, 516 FX_FLOAT fx,
517 FX_FLOAT fy) { 517 FX_FLOAT fy) {
518 if (!m_bMouseDown) { 518 if (!m_bMouseDown) {
519 int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered 519 int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered
520 : CFWL_PartState_Normal; 520 : CFWL_PartState_Normal;
521 if (iState == iNewState) 521 if (iState == iNewState)
522 return; 522 return;
523 523
524 iState = iNewState; 524 iState = iNewState;
525 Repaint(&rtItem); 525 Repaint(&rtItem);
526 } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) { 526 } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) {
527 FX_FLOAT fPos = GetTrackPointPos(fx, fy); 527 FX_FLOAT fPos = GetTrackPointPos(fx, fy);
528 m_fTrackPos = fPos; 528 m_fTrackPos = fPos;
529 OnScroll(FWL_SCBCODE::TrackPos, fPos); 529 OnScroll(FWL_SCBCODE::TrackPos, fPos);
530 } 530 }
531 } 531 }
532 532
533 void IFWL_ScrollBar::DoMouseLeave(int32_t iItem, 533 void CFWL_ScrollBar::DoMouseLeave(int32_t iItem,
534 const CFX_RectF& rtItem, 534 const CFX_RectF& rtItem,
535 int32_t& iState) { 535 int32_t& iState) {
536 if (iState == CFWL_PartState_Normal) 536 if (iState == CFWL_PartState_Normal)
537 return; 537 return;
538 538
539 iState = CFWL_PartState_Normal; 539 iState = CFWL_PartState_Normal;
540 Repaint(&rtItem); 540 Repaint(&rtItem);
541 } 541 }
542 542
543 void IFWL_ScrollBar::DoMouseHover(int32_t iItem, 543 void CFWL_ScrollBar::DoMouseHover(int32_t iItem,
544 const CFX_RectF& rtItem, 544 const CFX_RectF& rtItem,
545 int32_t& iState) { 545 int32_t& iState) {
546 if (iState == CFWL_PartState_Hovered) 546 if (iState == CFWL_PartState_Hovered)
547 return; 547 return;
548 548
549 iState = CFWL_PartState_Hovered; 549 iState = CFWL_PartState_Hovered;
550 Repaint(&rtItem); 550 Repaint(&rtItem);
551 } 551 }
552 552
553 IFWL_ScrollBar::Timer::Timer(IFWL_ScrollBar* pToolTip) : CFWL_Timer(pToolTip) {} 553 CFWL_ScrollBar::Timer::Timer(CFWL_ScrollBar* pToolTip) : CFWL_Timer(pToolTip) {}
554 554
555 void IFWL_ScrollBar::Timer::Run(CFWL_TimerInfo* pTimerInfo) { 555 void CFWL_ScrollBar::Timer::Run(CFWL_TimerInfo* pTimerInfo) {
556 IFWL_ScrollBar* pButton = static_cast<IFWL_ScrollBar*>(m_pWidget); 556 CFWL_ScrollBar* pButton = static_cast<CFWL_ScrollBar*>(m_pWidget);
557 557
558 if (pButton->m_pTimerInfo) 558 if (pButton->m_pTimerInfo)
559 pButton->m_pTimerInfo->StopTimer(); 559 pButton->m_pTimerInfo->StopTimer();
560 560
561 if (!pButton->SendEvent()) 561 if (!pButton->SendEvent())
562 pButton->m_pTimerInfo = StartTimer(0, true); 562 pButton->m_pTimerInfo = StartTimer(0, true);
563 } 563 }
OLDNEW
« no previous file with comments | « xfa/fwl/core/cfwl_scrollbar.h ('k') | xfa/fwl/core/cfwl_spinbutton.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698