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

Side by Side Diff: xfa/src/fwl/basewidget/fwl_scrollbarimp.cpp

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 months 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/src/fwl/basewidget/fwl_scrollbarimp.h ('k') | xfa/src/fwl/basewidget/fwl_spinbuttonimp.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/src/fwl/basewidget/fwl_scrollbarimp.h"
8
9 #include "xfa/include/fwl/basewidget/fwl_scrollbar.h"
10 #include "xfa/include/fwl/core/fwl_theme.h"
11 #include "xfa/src/fwl/core/fwl_noteimp.h"
12 #include "xfa/src/fwl/core/fwl_targetimp.h"
13 #include "xfa/src/fwl/core/fwl_widgetimp.h"
14
15 #define FWL_SCROLLBAR_Elapse 500
16 #define FWL_SCROLLBAR_MinThumb 5
17
18 // static
19 IFWL_ScrollBar* IFWL_ScrollBar::Create(
20 const CFWL_WidgetImpProperties& properties,
21 IFWL_Widget* pOuter) {
22 IFWL_ScrollBar* pScrollBar = new IFWL_ScrollBar;
23 CFWL_ScrollBarImp* pScrollBarImpl = new CFWL_ScrollBarImp(properties, pOuter);
24 pScrollBar->SetImpl(pScrollBarImpl);
25 pScrollBarImpl->SetInterface(pScrollBar);
26 return pScrollBar;
27 }
28 IFWL_ScrollBar::IFWL_ScrollBar() {}
29 FX_BOOL IFWL_ScrollBar::IsVertical() {
30 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->IsVertical();
31 }
32 FWL_ERR IFWL_ScrollBar::GetRange(FX_FLOAT& fMin, FX_FLOAT& fMax) {
33 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->GetRange(fMin, fMax);
34 }
35 FWL_ERR IFWL_ScrollBar::SetRange(FX_FLOAT fMin, FX_FLOAT fMax) {
36 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->SetRange(fMin, fMax);
37 }
38 FX_FLOAT IFWL_ScrollBar::GetPageSize() {
39 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->GetPageSize();
40 }
41 FWL_ERR IFWL_ScrollBar::SetPageSize(FX_FLOAT fPageSize) {
42 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->SetPageSize(fPageSize);
43 }
44 FX_FLOAT IFWL_ScrollBar::GetStepSize() {
45 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->GetStepSize();
46 }
47 FWL_ERR IFWL_ScrollBar::SetStepSize(FX_FLOAT fStepSize) {
48 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->SetStepSize(fStepSize);
49 }
50 FX_FLOAT IFWL_ScrollBar::GetPos() {
51 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->GetPos();
52 }
53 FWL_ERR IFWL_ScrollBar::SetPos(FX_FLOAT fPos) {
54 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->SetPos(fPos);
55 }
56 FX_FLOAT IFWL_ScrollBar::GetTrackPos() {
57 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->GetTrackPos();
58 }
59 FWL_ERR IFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) {
60 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->SetTrackPos(fTrackPos);
61 }
62 FX_BOOL IFWL_ScrollBar::DoScroll(FX_DWORD dwCode, FX_FLOAT fPos) {
63 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->DoScroll(dwCode, fPos);
64 }
65 CFWL_ScrollBarImp::CFWL_ScrollBarImp(const CFWL_WidgetImpProperties& properties,
66 IFWL_Widget* pOuter)
67 : CFWL_WidgetImp(properties, pOuter),
68 m_hTimer(nullptr),
69 m_fRangeMin(0),
70 m_fRangeMax(-1),
71 m_fPageSize(0),
72 m_fStepSize(0),
73 m_fPos(0),
74 m_fTrackPos(0),
75 m_iMinButtonState(FWL_PARTSTATE_SCB_Normal),
76 m_iMaxButtonState(FWL_PARTSTATE_SCB_Normal),
77 m_iThumbButtonState(FWL_PARTSTATE_SCB_Normal),
78 m_iMinTrackState(FWL_PARTSTATE_SCB_Normal),
79 m_iMaxTrackState(FWL_PARTSTATE_SCB_Normal),
80 m_fLastTrackPos(0),
81 m_cpTrackPointX(0),
82 m_cpTrackPointY(0),
83 m_iMouseWheel(0),
84 m_bTrackMouseLeave(FALSE),
85 m_bMouseHover(FALSE),
86 m_bMouseDown(FALSE),
87 m_bRepaintThumb(FALSE),
88 m_fButtonLen(0),
89 m_bMinSize(FALSE),
90 m_bCustomLayout(FALSE),
91 m_fMinThumb(FWL_SCROLLBAR_MinThumb) {
92 m_rtClient.Reset();
93 m_rtThumb.Reset();
94 m_rtMinBtn.Reset();
95 m_rtMaxBtn.Reset();
96 m_rtMinTrack.Reset();
97 m_rtMaxTrack.Reset();
98 }
99 CFWL_ScrollBarImp::~CFWL_ScrollBarImp() {}
100 FWL_ERR CFWL_ScrollBarImp::GetClassName(CFX_WideString& wsClass) const {
101 wsClass = FWL_CLASS_ScrollBar;
102 return FWL_ERR_Succeeded;
103 }
104 FX_DWORD CFWL_ScrollBarImp::GetClassID() const {
105 return FWL_CLASSHASH_ScrollBar;
106 }
107 FWL_ERR CFWL_ScrollBarImp::Initialize() {
108 if (CFWL_WidgetImp::Initialize() != FWL_ERR_Succeeded)
109 return FWL_ERR_Indefinite;
110 m_pDelegate = new CFWL_ScrollBarImpDelegate(this);
111 return FWL_ERR_Succeeded;
112 }
113 FWL_ERR CFWL_ScrollBarImp::Finalize() {
114 delete m_pDelegate;
115 m_pDelegate = nullptr;
116 return CFWL_WidgetImp::Finalize();
117 }
118 FWL_ERR CFWL_ScrollBarImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) {
119 if (bAutoSize) {
120 rect.Set(0, 0, 0, 0);
121 FX_FLOAT* pfMinWidth = static_cast<FX_FLOAT*>(
122 GetThemeCapacity(FWL_WGTCAPACITY_ScrollBarWidth));
123 if (!pfMinWidth)
124 return FWL_ERR_Indefinite;
125 if (IsVertical()) {
126 rect.Set(0, 0, (*pfMinWidth), (*pfMinWidth) * 3);
127 } else {
128 rect.Set(0, 0, (*pfMinWidth) * 3, (*pfMinWidth));
129 }
130 CFWL_WidgetImp::GetWidgetRect(rect, TRUE);
131 } else {
132 rect = m_pProperties->m_rtWidget;
133 }
134 return FWL_ERR_Succeeded;
135 }
136 FWL_ERR CFWL_ScrollBarImp::Update() {
137 if (IsLocked()) {
138 return FWL_ERR_Indefinite;
139 }
140 if (!m_pProperties->m_pThemeProvider) {
141 m_pProperties->m_pThemeProvider = GetAvailableTheme();
142 }
143 Layout();
144 return FWL_ERR_Succeeded;
145 }
146 FWL_ERR CFWL_ScrollBarImp::DrawWidget(CFX_Graphics* pGraphics,
147 const CFX_Matrix* pMatrix) {
148 if (!pGraphics)
149 return FWL_ERR_Indefinite;
150 if (!m_pProperties->m_pThemeProvider)
151 return FWL_ERR_Indefinite;
152 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
153 if (HasBorder()) {
154 DrawBorder(pGraphics, FWL_PART_SCB_Border, pTheme, pMatrix);
155 }
156 if (HasEdge()) {
157 DrawEdge(pGraphics, FWL_PART_SCB_Edge, pTheme, pMatrix);
158 }
159 DrawTrack(pGraphics, pTheme, TRUE, pMatrix);
160 DrawTrack(pGraphics, pTheme, FALSE, pMatrix);
161 DrawArrowBtn(pGraphics, pTheme, TRUE, pMatrix);
162 DrawArrowBtn(pGraphics, pTheme, FALSE, pMatrix);
163 DrawThumb(pGraphics, pTheme, pMatrix);
164 return FWL_ERR_Succeeded;
165 }
166 inline FX_BOOL CFWL_ScrollBarImp::IsVertical() {
167 return m_pProperties->m_dwStyleExes & FWL_STYLEEXT_SCB_Vert;
168 }
169 FWL_ERR CFWL_ScrollBarImp::GetRange(FX_FLOAT& fMin, FX_FLOAT& fMax) {
170 fMin = m_fRangeMin;
171 fMax = m_fRangeMax;
172 return FWL_ERR_Succeeded;
173 }
174 FWL_ERR CFWL_ScrollBarImp::SetRange(FX_FLOAT fMin, FX_FLOAT fMax) {
175 m_fRangeMin = fMin;
176 m_fRangeMax = fMax;
177 return FWL_ERR_Succeeded;
178 }
179 FX_FLOAT CFWL_ScrollBarImp::GetPageSize() {
180 return m_fPageSize;
181 }
182 FWL_ERR CFWL_ScrollBarImp::SetPageSize(FX_FLOAT fPageSize) {
183 m_fPageSize = fPageSize;
184 return FWL_ERR_Succeeded;
185 }
186 FX_FLOAT CFWL_ScrollBarImp::GetStepSize() {
187 return m_fStepSize;
188 }
189 FWL_ERR CFWL_ScrollBarImp::SetStepSize(FX_FLOAT fStepSize) {
190 m_fStepSize = fStepSize;
191 return FWL_ERR_Succeeded;
192 }
193 FX_FLOAT CFWL_ScrollBarImp::GetPos() {
194 return m_fPos;
195 }
196 FWL_ERR CFWL_ScrollBarImp::SetPos(FX_FLOAT fPos) {
197 m_fPos = fPos;
198 return FWL_ERR_Succeeded;
199 }
200 FX_FLOAT CFWL_ScrollBarImp::GetTrackPos() {
201 return m_fTrackPos;
202 }
203 FWL_ERR CFWL_ScrollBarImp::SetTrackPos(FX_FLOAT fTrackPos) {
204 m_fTrackPos = fTrackPos;
205 CalcThumbButtonRect(m_rtThumb);
206 CalcMinTrackRect(m_rtMinTrack);
207 CalcMaxTrackRect(m_rtMaxTrack);
208 return FWL_ERR_Succeeded;
209 }
210 FX_BOOL CFWL_ScrollBarImp::DoScroll(FX_DWORD dwCode, FX_FLOAT fPos) {
211 switch (dwCode) {
212 case FWL_SCBCODE_Min:
213 case FWL_SCBCODE_Max:
214 case FWL_SCBCODE_PageBackward:
215 case FWL_SCBCODE_PageForward:
216 case FWL_SCBCODE_StepBackward:
217 break;
218 case FWL_SCBCODE_StepForward:
219 break;
220 case FWL_SCBCODE_Pos:
221 case FWL_SCBCODE_TrackPos:
222 case FWL_SCBCODE_EndScroll:
223 break;
224 default: { return FALSE; }
225 }
226 return OnScroll(dwCode, fPos);
227 }
228 int32_t CFWL_ScrollBarImp::Run(FWL_HTIMER hTimer) {
229 if (m_hTimer) {
230 FWL_StopTimer(m_hTimer);
231 }
232 if (!SendEvent()) {
233 m_hTimer = FWL_StartTimer(this, 0);
234 }
235 return 1;
236 }
237 FWL_ERR CFWL_ScrollBarImp::SetOuter(IFWL_Widget* pOuter) {
238 m_pOuter = pOuter;
239 return FWL_ERR_Succeeded;
240 }
241 void CFWL_ScrollBarImp::DrawTrack(CFX_Graphics* pGraphics,
242 IFWL_ThemeProvider* pTheme,
243 FX_BOOL bLower,
244 const CFX_Matrix* pMatrix) {
245 CFWL_ThemeBackground param;
246 param.m_pWidget = m_pInterface;
247 param.m_iPart = bLower ? FWL_PART_SCB_LowerTrack : FWL_PART_SCB_UpperTrack;
248 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
249 ? FWL_PARTSTATE_SCB_Disabled
250 : (bLower ? m_iMinTrackState : m_iMaxTrackState);
251 param.m_pGraphics = pGraphics;
252 param.m_matrix.Concat(*pMatrix);
253 param.m_rtPart = bLower ? m_rtMinTrack : m_rtMaxTrack;
254 pTheme->DrawBackground(&param);
255 }
256 void CFWL_ScrollBarImp::DrawArrowBtn(CFX_Graphics* pGraphics,
257 IFWL_ThemeProvider* pTheme,
258 FX_BOOL bMinBtn,
259 const CFX_Matrix* pMatrix) {
260 CFWL_ThemeBackground param;
261 param.m_pWidget = m_pInterface;
262 param.m_iPart = bMinBtn ? FWL_PART_SCB_ForeArrow : FWL_PART_SCB_BackArrow;
263 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
264 ? FWL_PARTSTATE_SCB_Disabled
265 : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState);
266 param.m_pGraphics = pGraphics;
267 param.m_matrix.Concat(*pMatrix);
268 param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn;
269 if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0) {
270 pTheme->DrawBackground(&param);
271 }
272 }
273 void CFWL_ScrollBarImp::DrawThumb(CFX_Graphics* pGraphics,
274 IFWL_ThemeProvider* pTheme,
275 const CFX_Matrix* pMatrix) {
276 if (!IsEnabled()) {
277 }
278 CFWL_ThemeBackground param;
279 param.m_pWidget = m_pInterface;
280 param.m_iPart = FWL_PART_SCB_Thumb;
281 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
282 ? FWL_PARTSTATE_SCB_Disabled
283 : m_iThumbButtonState;
284 param.m_pGraphics = pGraphics;
285 param.m_matrix.Concat(*pMatrix);
286 param.m_rtPart = m_rtThumb;
287 pTheme->DrawBackground(&param);
288 }
289 void CFWL_ScrollBarImp::Layout() {
290 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
291 CFWL_ThemePart part;
292 part.m_pWidget = m_pInterface;
293 m_fMinThumb = *static_cast<FX_FLOAT*>(
294 pTheme->GetCapacity(&part, FWL_CAPACITY_SCB_Size));
295 m_bCustomLayout = pTheme->IsCustomizedLayout(m_pInterface);
296 GetClientRect(m_rtClient);
297 CalcButtonLen();
298 CalcMinButtonRect(m_rtMinBtn);
299 CalcMaxButtonRect(m_rtMaxBtn);
300 CalcThumbButtonRect(m_rtThumb);
301 CalcMinTrackRect(m_rtMinTrack);
302 CalcMaxTrackRect(m_rtMaxTrack);
303 }
304 void CFWL_ScrollBarImp::CalcButtonLen() {
305 m_fButtonLen = IsVertical() ? m_rtClient.width : m_rtClient.height;
306 FX_FLOAT fLength = IsVertical() ? m_rtClient.height : m_rtClient.width;
307 if (fLength < m_fButtonLen * 2) {
308 m_fButtonLen = fLength / 2;
309 m_bMinSize = TRUE;
310 } else {
311 m_bMinSize = FALSE;
312 }
313 }
314 void CFWL_ScrollBarImp::CalcMinButtonRect(CFX_RectF& rect) {
315 if (m_bCustomLayout) {
316 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
317 CFWL_ThemePart pPart;
318 pPart.m_rtPart = m_rtMinBtn;
319 pPart.m_pWidget = m_pInterface;
320 pPart.m_iPart = FWL_PART_SCB_ForeArrow;
321 pPart.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
322 ? FWL_PARTSTATE_SCB_Disabled
323 : m_iMinButtonState;
324 pTheme->GetPartRect(&pPart, rect);
325 } else {
326 rect.left = m_rtClient.left;
327 rect.top = m_rtClient.top;
328 rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen;
329 rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height;
330 }
331 }
332 void CFWL_ScrollBarImp::CalcMaxButtonRect(CFX_RectF& rect) {
333 if (m_bCustomLayout) {
334 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
335 CFWL_ThemePart pPart;
336 pPart.m_rtPart = m_rtMaxBtn;
337 pPart.m_pWidget = m_pInterface;
338 pPart.m_iPart = FWL_PART_SCB_BackArrow;
339 pPart.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
340 ? FWL_PARTSTATE_SCB_Disabled
341 : m_iMaxButtonState;
342 pTheme->GetPartRect(&pPart, rect);
343 } else {
344 rect.left =
345 IsVertical() ? m_rtClient.left : m_rtClient.right() - m_fButtonLen;
346 rect.top =
347 IsVertical() ? m_rtClient.bottom() - m_fButtonLen : m_rtClient.top;
348 rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen;
349 rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height;
350 }
351 }
352 void CFWL_ScrollBarImp::CalcThumbButtonRect(CFX_RectF& rect) {
353 if (!IsEnabled()) {
354 m_rtThumb.Reset();
355 return;
356 }
357 if (m_bMinSize) {
358 m_rtThumb.Empty();
359 return;
360 }
361 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin;
362 memset(&rect, 0, sizeof(CFX_Rect));
363 if (fRange < 0) {
364 if (IsVertical()) {
365 rect.Set(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width, 0);
366 } else {
367 rect.Set(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height);
368 }
369 return;
370 }
371 CFX_RectF rtClient = m_rtClient;
372 FX_FLOAT fLength = IsVertical() ? rtClient.height : rtClient.width;
373 FX_FLOAT fSize = m_fButtonLen;
374 if (m_bCustomLayout) {
375 if (IsVertical()) {
376 fLength = fLength - m_rtMinBtn.height - m_rtMaxBtn.height;
377 if (fLength < m_rtMinBtn.height || fLength < m_rtMaxBtn.height) {
378 fLength = 0.0f;
379 }
380 } else {
381 fLength = fLength - m_rtMinBtn.width - m_rtMaxBtn.width;
382 if (fLength < m_rtMinBtn.width || fLength < m_rtMaxBtn.width) {
383 fLength = 0.0f;
384 }
385 }
386 } else {
387 fLength -= fSize * 2.0f;
388 if (fLength < fSize) {
389 fLength = 0.0f;
390 }
391 }
392 FX_FLOAT fThumbSize = fLength * fLength / (fRange + fLength);
393 if (fThumbSize < m_fMinThumb) {
394 fThumbSize = m_fMinThumb;
395 }
396 FX_FLOAT fDiff = fLength - fThumbSize;
397 if (fDiff < 0.0f) {
398 fDiff = 0.0f;
399 }
400 FX_FLOAT fTrackPos = m_fTrackPos;
401 if (fTrackPos > m_fRangeMax) {
402 fTrackPos = m_fRangeMax;
403 }
404 if (fTrackPos < m_fRangeMin) {
405 fTrackPos = m_fRangeMin;
406 }
407 if (!fRange)
408 return;
409 if (m_bCustomLayout) {
410 FX_FLOAT iPos = fDiff * (fTrackPos - m_fRangeMin) / fRange;
411 rect.left = rtClient.left;
412 if (!IsVertical()) {
413 if ((m_rtMinBtn.right() == m_rtMaxBtn.left && m_rtMinBtn.width > 0 &&
414 m_rtMaxBtn.width > 0) ||
415 (0 == m_rtMinBtn.width && 0 == m_rtMaxBtn.width)) {
416 rect.left += iPos;
417 } else {
418 rect.left += m_rtMinBtn.right() + iPos;
419 }
420 }
421 rect.top = rtClient.top;
422 if (IsVertical()) {
423 if ((m_rtMinBtn.bottom() == m_rtMaxBtn.top && m_rtMinBtn.height > 0 &&
424 m_rtMaxBtn.height > 0) ||
425 (0 == m_rtMinBtn.height && 0 == m_rtMaxBtn.height)) {
426 rect.top += iPos;
427 } else {
428 rect.top += m_rtMinBtn.bottom() + iPos;
429 }
430 }
431 rect.width = IsVertical() ? rtClient.width : fThumbSize;
432 rect.height = IsVertical() ? fThumbSize : rtClient.height;
433 } else {
434 FX_FLOAT iPos = fSize + fDiff * (fTrackPos - m_fRangeMin) / fRange;
435 rect.left = rtClient.left;
436 if (!IsVertical()) {
437 rect.left += iPos;
438 }
439 rect.top = rtClient.top;
440 if (IsVertical()) {
441 rect.top += iPos;
442 }
443 rect.width = IsVertical() ? rtClient.width : fThumbSize;
444 rect.height = IsVertical() ? fThumbSize : rtClient.height;
445 }
446 }
447 void CFWL_ScrollBarImp::CalcMinTrackRect(CFX_RectF& rect) {
448 if (m_bMinSize) {
449 rect.Empty();
450 return;
451 }
452 FX_FLOAT fBottom = m_rtThumb.bottom();
453 FX_FLOAT fRight = m_rtThumb.right();
454 FX_FLOAT ix = (m_rtThumb.left + fRight) / 2;
455 FX_FLOAT iy = (m_rtThumb.top + fBottom) / 2;
456 rect.left = m_rtClient.left;
457 rect.top = m_rtClient.top;
458 FX_BOOL bVertical = IsVertical();
459 rect.width = bVertical ? m_rtClient.width : ix;
460 rect.height = bVertical ? iy : m_rtClient.height;
461 if (m_bCustomLayout) {
462 if (bVertical) {
463 if (0 == m_rtMinBtn.height && 0 == m_rtMaxBtn.height) {
464 rect.top = m_rtClient.top;
465 } else if (m_rtMinBtn.top < m_rtThumb.top) {
466 rect.top = m_rtMinBtn.bottom();
467 rect.height -= (m_rtMinBtn.bottom() - m_rtClient.top);
468 }
469 } else {
470 if (0 == m_rtMinBtn.width && 0 == m_rtMaxBtn.width) {
471 rect.left = m_rtClient.left;
472 } else if (m_rtMinBtn.left < m_rtThumb.left) {
473 rect.left = m_rtMinBtn.right();
474 rect.width -= (m_rtMinBtn.right() - m_rtClient.left);
475 }
476 }
477 }
478 }
479 void CFWL_ScrollBarImp::CalcMaxTrackRect(CFX_RectF& rect) {
480 if (m_bMinSize) {
481 rect.Empty();
482 return;
483 }
484 FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2;
485 FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2;
486 FX_BOOL bVertical = IsVertical();
487 rect.left = bVertical ? m_rtClient.left : ix;
488 rect.top = bVertical ? iy : m_rtClient.top;
489 rect.width = bVertical ? m_rtClient.width : m_rtClient.right() - ix;
490 rect.height = bVertical ? m_rtClient.bottom() - iy : m_rtClient.height;
491 if (m_bCustomLayout) {
492 if (bVertical) {
493 if (m_rtMinBtn.top > m_rtThumb.top && m_rtMinBtn.height > 0 &&
494 m_rtMaxBtn.height > 0) {
495 rect.height -= (m_rtClient.bottom() - m_rtMinBtn.top);
496 } else if (m_rtMinBtn.height > 0 && m_rtMaxBtn.height > 0) {
497 rect.height -= (m_rtClient.bottom() - m_rtMaxBtn.top);
498 }
499 } else {
500 if (m_rtMinBtn.left > m_rtThumb.left && m_rtMinBtn.width > 0 &&
501 m_rtMaxBtn.width > 0) {
502 rect.width -= (m_rtClient.right() - m_rtMinBtn.left);
503 } else if (m_rtMinBtn.width > 0 && m_rtMaxBtn.width > 0) {
504 rect.width -= (m_rtClient.right() - m_rtMaxBtn.left);
505 }
506 }
507 }
508 }
509 FX_FLOAT CFWL_ScrollBarImp::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) {
510 FX_FLOAT fDiffX = fx - m_cpTrackPointX;
511 FX_FLOAT fDiffY = fy - m_cpTrackPointY;
512 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin;
513 FX_FLOAT fPos;
514 if (m_bCustomLayout) {
515 if (IsVertical()) {
516 if (0 == m_rtMinBtn.height && 0 == m_rtMaxBtn.height) {
517 fPos = fRange * fDiffY / (m_rtClient.height - m_rtThumb.height);
518 } else if (m_rtMinBtn.bottom() == m_rtMaxBtn.top) {
519 fPos = fRange * fDiffY /
520 (m_rtMinBtn.top - m_rtClient.top - m_rtThumb.height);
521 } else {
522 fPos = fRange * fDiffY /
523 (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height);
524 }
525 } else {
526 if (0 == m_rtMinBtn.width && 0 == m_rtMaxBtn.width) {
527 fPos = fRange * fDiffX / (m_rtClient.width - m_rtThumb.width);
528 } else if (m_rtMinBtn.right() == m_rtMaxBtn.left) {
529 fPos = fRange * fDiffX /
530 (m_rtMinBtn.left - m_rtClient.left - m_rtThumb.width);
531 } else {
532 fPos = fRange * fDiffX /
533 (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width);
534 }
535 }
536 } else {
537 if (IsVertical()) {
538 fPos = fRange * fDiffY /
539 (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height);
540 } else {
541 fPos = fRange * fDiffX /
542 (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width);
543 }
544 }
545 fPos += m_fLastTrackPos;
546 if (fPos < m_fRangeMin) {
547 fPos = m_fRangeMin;
548 }
549 if (fPos > m_fRangeMax) {
550 fPos = m_fRangeMax;
551 }
552 return fPos;
553 }
554 void CFWL_ScrollBarImp::GetTrackRect(CFX_RectF& rect, FX_BOOL bLower) {
555 FX_BOOL bDisabled = m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled;
556 if (bDisabled || m_bCustomLayout) {
557 rect = bLower ? m_rtMinTrack : m_rtMaxTrack;
558 } else {
559 FX_FLOAT fW = m_rtThumb.width / 2;
560 FX_FLOAT fH = m_rtThumb.height / 2;
561 FX_BOOL bVert = IsVertical();
562 if (bLower) {
563 if (bVert) {
564 FX_FLOAT fMinTrackHeight = m_rtMinTrack.height - fH - m_rtMinBtn.height;
565 fMinTrackHeight = (fMinTrackHeight >= 0.0f) ? fMinTrackHeight : 0.0f;
566 rect.Set(m_rtMinTrack.left, m_rtMinTrack.top + m_rtMinBtn.height,
567 m_rtMinTrack.width, fMinTrackHeight);
568 } else {
569 FX_FLOAT fMinTrackWidth =
570 m_rtMinTrack.width - fW - m_rtMinBtn.width + 2;
571 fMinTrackWidth = (fMinTrackWidth >= 0.0f) ? fMinTrackWidth : 0.0f;
572 rect.Set(m_rtMinTrack.left + m_rtMinBtn.width - 1, m_rtMinTrack.top,
573 fMinTrackWidth, m_rtMinTrack.height);
574 }
575 } else {
576 if (bVert) {
577 FX_FLOAT fMaxTrackHeight = m_rtMaxTrack.height - fH - m_rtMaxBtn.height;
578 fMaxTrackHeight = (fMaxTrackHeight >= 0.0f) ? fMaxTrackHeight : 0.0f;
579 rect.Set(m_rtMaxTrack.left, m_rtMaxTrack.top + fH, m_rtMaxTrack.width,
580 fMaxTrackHeight);
581 } else {
582 FX_FLOAT fMaxTrackWidth =
583 m_rtMaxTrack.width - fW - m_rtMaxBtn.width + 2;
584 fMaxTrackWidth = (fMaxTrackWidth >= 0.0f) ? fMaxTrackWidth : 0.0f;
585 rect.Set(m_rtMaxTrack.left + fW, m_rtMaxTrack.top, fMaxTrackWidth,
586 m_rtMaxTrack.height);
587 }
588 }
589 }
590 }
591 FX_BOOL CFWL_ScrollBarImp::SendEvent() {
592 if (m_iMinButtonState == FWL_PARTSTATE_SCB_Pressed) {
593 DoScroll(FWL_SCBCODE_StepBackward, m_fTrackPos);
594 return FALSE;
595 }
596 if (m_iMaxButtonState == FWL_PARTSTATE_SCB_Pressed) {
597 DoScroll(FWL_SCBCODE_StepForward, m_fTrackPos);
598 return FALSE;
599 }
600 if (m_iMinTrackState == FWL_PARTSTATE_SCB_Pressed) {
601 DoScroll(FWL_SCBCODE_PageBackward, m_fTrackPos);
602 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY);
603 }
604 if (m_iMaxTrackState == FWL_PARTSTATE_SCB_Pressed) {
605 DoScroll(FWL_SCBCODE_PageForward, m_fTrackPos);
606 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY);
607 }
608 if (m_iMouseWheel) {
609 FX_WORD dwCode =
610 m_iMouseWheel < 0 ? FWL_SCBCODE_StepForward : FWL_SCBCODE_StepBackward;
611 DoScroll(dwCode, m_fTrackPos);
612 }
613 return TRUE;
614 }
615 FX_BOOL CFWL_ScrollBarImp::OnScroll(FX_DWORD dwCode, FX_FLOAT fPos) {
616 FX_BOOL bRet = TRUE;
617 CFWL_EvtScroll ev;
618 ev.m_iScrollCode = dwCode;
619 ev.m_pSrcTarget = m_pInterface;
620 ev.m_fPos = fPos;
621 ev.m_pRet = &bRet;
622 DispatchEvent(&ev);
623 return bRet;
624 }
625 CFWL_ScrollBarImpDelegate::CFWL_ScrollBarImpDelegate(CFWL_ScrollBarImp* pOwner)
626 : m_pOwner(pOwner) {}
627 int32_t CFWL_ScrollBarImpDelegate::OnProcessMessage(CFWL_Message* pMessage) {
628 if (!pMessage)
629 return 0;
630 int32_t iRet = 1;
631 FX_DWORD dwMsgCode = pMessage->GetClassID();
632 if (dwMsgCode == FWL_MSGHASH_Mouse) {
633 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage);
634 FX_DWORD dwCmd = pMsg->m_dwCmd;
635 switch (dwCmd) {
636 case FWL_MSGMOUSECMD_LButtonDown: {
637 OnLButtonDown(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy);
638 break;
639 }
640 case FWL_MSGMOUSECMD_LButtonUp: {
641 OnLButtonUp(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy);
642 break;
643 }
644 case FWL_MSGMOUSECMD_MouseMove: {
645 OnMouseMove(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy);
646 break;
647 }
648 case FWL_MSGMOUSECMD_MouseLeave: {
649 OnMouseLeave();
650 break;
651 }
652 default: { iRet = 0; }
653 }
654 } else if (dwMsgCode == FWL_MSGHASH_MouseWheel) {
655 CFWL_MsgMouseWheel* pMsg = static_cast<CFWL_MsgMouseWheel*>(pMessage);
656 OnMouseWheel(pMsg->m_fx, pMsg->m_fy, pMsg->m_dwFlags, pMsg->m_fDeltaX,
657 pMsg->m_fDeltaY);
658 } else {
659 iRet = 0;
660 }
661 return iRet;
662 }
663 FWL_ERR CFWL_ScrollBarImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics,
664 const CFX_Matrix* pMatrix) {
665 return m_pOwner->DrawWidget(pGraphics, pMatrix);
666 }
667 void CFWL_ScrollBarImpDelegate::OnLButtonDown(FX_DWORD dwFlags,
668 FX_FLOAT fx,
669 FX_FLOAT fy) {
670 if (!m_pOwner->IsEnabled()) {
671 return;
672 }
673 m_pOwner->m_bMouseDown = TRUE;
674 m_pOwner->SetGrab(TRUE);
675 m_pOwner->m_cpTrackPointX = fx;
676 m_pOwner->m_cpTrackPointY = fy;
677 m_pOwner->m_fLastTrackPos = m_pOwner->m_fTrackPos;
678 if (m_pOwner->m_rtMinBtn.Contains(fx, fy)) {
679 DoMouseDown(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState, fx, fy);
680 } else {
681 if (m_pOwner->m_rtThumb.Contains(fx, fy)) {
682 DoMouseDown(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState, fx,
683 fy);
684 } else {
685 if (m_pOwner->m_rtMaxBtn.Contains(fx, fy)) {
686 DoMouseDown(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState, fx,
687 fy);
688 } else {
689 if (m_pOwner->m_rtMinTrack.Contains(fx, fy)) {
690 DoMouseDown(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState, fx,
691 fy);
692 } else {
693 DoMouseDown(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState, fx,
694 fy);
695 }
696 }
697 }
698 }
699 if (!m_pOwner->SendEvent()) {
700 m_pOwner->m_hTimer = FWL_StartTimer(m_pOwner, FWL_SCROLLBAR_Elapse);
701 }
702 }
703 void CFWL_ScrollBarImpDelegate::OnLButtonUp(FX_DWORD dwFlags,
704 FX_FLOAT fx,
705 FX_FLOAT fy) {
706 FWL_StopTimer(m_pOwner->m_hTimer);
707 m_pOwner->m_bMouseDown = FALSE;
708 DoMouseUp(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState, fx, fy);
709 DoMouseUp(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState, fx, fy);
710 DoMouseUp(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState, fx, fy);
711 DoMouseUp(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState, fx, fy);
712 DoMouseUp(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState, fx, fy);
713 m_pOwner->SetGrab(FALSE);
714 }
715 void CFWL_ScrollBarImpDelegate::OnMouseMove(FX_DWORD dwFlags,
716 FX_FLOAT fx,
717 FX_FLOAT fy) {
718 DoMouseMove(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState, fx, fy);
719 DoMouseMove(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState, fx, fy);
720 DoMouseMove(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState, fx, fy);
721 DoMouseMove(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState, fx, fy);
722 DoMouseMove(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState, fx, fy);
723 }
724 void CFWL_ScrollBarImpDelegate::OnMouseLeave() {
725 DoMouseLeave(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState);
726 DoMouseLeave(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState);
727 DoMouseLeave(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState);
728 DoMouseLeave(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState);
729 DoMouseLeave(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState);
730 }
731 void CFWL_ScrollBarImpDelegate::OnMouseWheel(FX_FLOAT fx,
732 FX_FLOAT fy,
733 FX_DWORD dwFlags,
734 FX_FLOAT fDeltaX,
735 FX_FLOAT fDeltaY) {
736 m_pOwner->m_iMouseWheel = (int32_t)fDeltaX;
737 m_pOwner->SendEvent();
738 m_pOwner->m_iMouseWheel = 0;
739 }
740 void CFWL_ScrollBarImpDelegate::DoMouseDown(int32_t iItem,
741 const CFX_RectF& rtItem,
742 int32_t& iState,
743 FX_FLOAT fx,
744 FX_FLOAT fy) {
745 if (!rtItem.Contains(fx, fy)) {
746 return;
747 }
748 if (iState == FWL_PARTSTATE_SCB_Pressed) {
749 return;
750 }
751 iState = FWL_PARTSTATE_SCB_Pressed;
752 m_pOwner->Repaint(&rtItem);
753 }
754 void CFWL_ScrollBarImpDelegate::DoMouseUp(int32_t iItem,
755 const CFX_RectF& rtItem,
756 int32_t& iState,
757 FX_FLOAT fx,
758 FX_FLOAT fy) {
759 int32_t iNewState = rtItem.Contains(fx, fy) ? FWL_PARTSTATE_SCB_Hovered
760 : FWL_PARTSTATE_SCB_Normal;
761 if (iState == iNewState) {
762 return;
763 }
764 iState = iNewState;
765 m_pOwner->Repaint(&rtItem);
766 m_pOwner->OnScroll(FWL_SCBCODE_EndScroll, m_pOwner->m_fTrackPos);
767 }
768 void CFWL_ScrollBarImpDelegate::DoMouseMove(int32_t iItem,
769 const CFX_RectF& rtItem,
770 int32_t& iState,
771 FX_FLOAT fx,
772 FX_FLOAT fy) {
773 if (!m_pOwner->m_bMouseDown) {
774 int32_t iNewState = rtItem.Contains(fx, fy) ? FWL_PARTSTATE_SCB_Hovered
775 : FWL_PARTSTATE_SCB_Normal;
776 if (iState == iNewState) {
777 return;
778 }
779 iState = iNewState;
780 m_pOwner->Repaint(&rtItem);
781 } else if ((2 == iItem) &&
782 (m_pOwner->m_iThumbButtonState == FWL_PARTSTATE_SCB_Pressed)) {
783 FX_FLOAT fPos = m_pOwner->GetTrackPointPos(fx, fy);
784 m_pOwner->m_fTrackPos = fPos;
785 m_pOwner->OnScroll(FWL_SCBCODE_TrackPos, fPos);
786 }
787 }
788 void CFWL_ScrollBarImpDelegate::DoMouseLeave(int32_t iItem,
789 const CFX_RectF& rtItem,
790 int32_t& iState) {
791 if (iState == FWL_PARTSTATE_SCB_Normal) {
792 return;
793 }
794 iState = FWL_PARTSTATE_SCB_Normal;
795 m_pOwner->Repaint(&rtItem);
796 }
797 void CFWL_ScrollBarImpDelegate::DoMouseHover(int32_t iItem,
798 const CFX_RectF& rtItem,
799 int32_t& iState) {
800 if (iState == FWL_PARTSTATE_SCB_Hovered) {
801 return;
802 }
803 iState = FWL_PARTSTATE_SCB_Hovered;
804 m_pOwner->Repaint(&rtItem);
805 }
OLDNEW
« no previous file with comments | « xfa/src/fwl/basewidget/fwl_scrollbarimp.h ('k') | xfa/src/fwl/basewidget/fwl_spinbuttonimp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698