Use override in more classes in core/
[pdfium.git] / fpdfsdk / src / pdfwindow / PWL_ScrollBar.cpp
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 "../../include/pdfwindow/PDFWindow.h"
8 #include "../../include/pdfwindow/PWL_Wnd.h"
9 #include "../../include/pdfwindow/PWL_ScrollBar.h"
10 #include "../../include/pdfwindow/PWL_Utils.h"
11
12 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
13 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
14 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
15 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
16
17 /* ------------------------------- PWL_FLOATRANGE
18  * ------------------------------- */
19
20 PWL_FLOATRANGE::PWL_FLOATRANGE() {
21   Default();
22 }
23
24 PWL_FLOATRANGE::PWL_FLOATRANGE(FX_FLOAT min, FX_FLOAT max) {
25   Set(min, max);
26 }
27
28 void PWL_FLOATRANGE::Default() {
29   fMin = 0;
30   fMax = 0;
31 }
32
33 void PWL_FLOATRANGE::Set(FX_FLOAT min, FX_FLOAT max) {
34   if (min > max) {
35     fMin = max;
36     fMax = min;
37   } else {
38     fMin = min;
39     fMax = max;
40   }
41 }
42
43 FX_BOOL PWL_FLOATRANGE::In(FX_FLOAT x) const {
44   return (IsFloatBigger(x, fMin) || IsFloatEqual(x, fMin)) &&
45          (IsFloatSmaller(x, fMax) || IsFloatEqual(x, fMax));
46 }
47
48 FX_FLOAT PWL_FLOATRANGE::GetWidth() const {
49   return fMax - fMin;
50 }
51
52 /* ------------------------------- PWL_SCROLL_PRIVATEDATA
53  * ------------------------------- */
54
55 PWL_SCROLL_PRIVATEDATA::PWL_SCROLL_PRIVATEDATA() {
56   Default();
57 }
58
59 void PWL_SCROLL_PRIVATEDATA::Default() {
60   ScrollRange.Default();
61   fScrollPos = ScrollRange.fMin;
62   fClientWidth = 0;
63   fBigStep = 10;
64   fSmallStep = 1;
65 }
66
67 void PWL_SCROLL_PRIVATEDATA::SetScrollRange(FX_FLOAT min, FX_FLOAT max) {
68   ScrollRange.Set(min, max);
69
70   if (IsFloatSmaller(fScrollPos, ScrollRange.fMin))
71     fScrollPos = ScrollRange.fMin;
72   if (IsFloatBigger(fScrollPos, ScrollRange.fMax))
73     fScrollPos = ScrollRange.fMax;
74 }
75
76 void PWL_SCROLL_PRIVATEDATA::SetClientWidth(FX_FLOAT width) {
77   fClientWidth = width;
78 }
79
80 void PWL_SCROLL_PRIVATEDATA::SetSmallStep(FX_FLOAT step) {
81   fSmallStep = step;
82 }
83
84 void PWL_SCROLL_PRIVATEDATA::SetBigStep(FX_FLOAT step) {
85   fBigStep = step;
86 }
87
88 FX_BOOL PWL_SCROLL_PRIVATEDATA::SetPos(FX_FLOAT pos) {
89   if (ScrollRange.In(pos)) {
90     fScrollPos = pos;
91     return TRUE;
92   }
93   return FALSE;
94 }
95
96 void PWL_SCROLL_PRIVATEDATA::AddSmall() {
97   if (!SetPos(fScrollPos + fSmallStep))
98     SetPos(ScrollRange.fMax);
99 }
100
101 void PWL_SCROLL_PRIVATEDATA::SubSmall() {
102   if (!SetPos(fScrollPos - fSmallStep))
103     SetPos(ScrollRange.fMin);
104 }
105
106 void PWL_SCROLL_PRIVATEDATA::AddBig() {
107   if (!SetPos(fScrollPos + fBigStep))
108     SetPos(ScrollRange.fMax);
109 }
110
111 void PWL_SCROLL_PRIVATEDATA::SubBig() {
112   if (!SetPos(fScrollPos - fBigStep))
113     SetPos(ScrollRange.fMin);
114 }
115
116 /* ------------------------------- CPWL_SBButton -------------------------------
117  */
118
119 CPWL_SBButton::CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType,
120                              PWL_SBBUTTON_TYPE eButtonType) {
121   m_eScrollBarType = eScrollBarType;
122   m_eSBButtonType = eButtonType;
123
124   m_bMouseDown = FALSE;
125 }
126
127 CPWL_SBButton::~CPWL_SBButton() {}
128
129 CFX_ByteString CPWL_SBButton::GetClassName() const {
130   return "CPWL_SBButton";
131 }
132
133 void CPWL_SBButton::OnCreate(PWL_CREATEPARAM& cp) {
134   cp.eCursorType = FXCT_ARROW;
135 }
136
137 void CPWL_SBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
138   CPWL_Wnd::GetThisAppearanceStream(sAppStream);
139
140   if (!IsVisible())
141     return;
142
143   CFX_ByteTextBuf sButton;
144
145   CPDF_Rect rectWnd = GetWindowRect();
146
147   if (rectWnd.IsEmpty())
148     return;
149
150   sAppStream << "q\n";
151
152   CPDF_Point ptCenter = GetCenterPoint();
153
154   switch (m_eScrollBarType) {
155     case SBT_HSCROLL:
156       switch (m_eSBButtonType) {
157         case PSBT_MIN: {
158           CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y);
159           CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,
160                          ptCenter.y + PWL_TRIANGLE_HALFLEN);
161           CPDF_Point pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,
162                          ptCenter.y - PWL_TRIANGLE_HALFLEN);
163
164           if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
165               rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) {
166             sButton << "0 g\n";
167             sButton << pt1.x << " " << pt1.y << " m\n";
168             sButton << pt2.x << " " << pt2.y << " l\n";
169             sButton << pt3.x << " " << pt3.y << " l\n";
170             sButton << pt1.x << " " << pt1.y << " l f\n";
171
172             sAppStream << sButton;
173           }
174         } break;
175         case PSBT_MAX: {
176           CPDF_Point pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y);
177           CPDF_Point pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,
178                          ptCenter.y + PWL_TRIANGLE_HALFLEN);
179           CPDF_Point pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,
180                          ptCenter.y - PWL_TRIANGLE_HALFLEN);
181
182           if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
183               rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) {
184             sButton << "0 g\n";
185             sButton << pt1.x << " " << pt1.y << " m\n";
186             sButton << pt2.x << " " << pt2.y << " l\n";
187             sButton << pt3.x << " " << pt3.y << " l\n";
188             sButton << pt1.x << " " << pt1.y << " l f\n";
189
190             sAppStream << sButton;
191           }
192         } break;
193         default:
194           break;
195       }
196       break;
197     case SBT_VSCROLL:
198       switch (m_eSBButtonType) {
199         case PSBT_MIN: {
200           CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN,
201                          ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f);
202           CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN,
203                          ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f);
204           CPDF_Point pt3(ptCenter.x, ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f);
205
206           if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
207               rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) {
208             sButton << "0 g\n";
209             sButton << pt1.x << " " << pt1.y << " m\n";
210             sButton << pt2.x << " " << pt2.y << " l\n";
211             sButton << pt3.x << " " << pt3.y << " l\n";
212             sButton << pt1.x << " " << pt1.y << " l f\n";
213
214             sAppStream << sButton;
215           }
216         } break;
217         case PSBT_MAX: {
218           CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN,
219                          ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f);
220           CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN,
221                          ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f);
222           CPDF_Point pt3(ptCenter.x, ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f);
223
224           if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
225               rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) {
226             sButton << "0 g\n";
227             sButton << pt1.x << " " << pt1.y << " m\n";
228             sButton << pt2.x << " " << pt2.y << " l\n";
229             sButton << pt3.x << " " << pt3.y << " l\n";
230             sButton << pt1.x << " " << pt1.y << " l f\n";
231
232             sAppStream << sButton;
233           }
234         } break;
235         default:
236           break;
237       }
238       break;
239     default:
240       break;
241   }
242
243   sAppStream << "Q\n";
244 }
245
246 void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice,
247                                        CPDF_Matrix* pUser2Device) {
248   if (!IsVisible())
249     return;
250
251   CPDF_Rect rectWnd = GetWindowRect();
252   if (rectWnd.IsEmpty())
253     return;
254
255   CPDF_Point ptCenter = GetCenterPoint();
256   int32_t nTransparancy = GetTransparency();
257
258   switch (m_eScrollBarType) {
259     case SBT_HSCROLL:
260       CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
261       switch (m_eSBButtonType) {
262         case PSBT_MIN: {
263           CPDF_Point pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y);
264           CPDF_Point pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,
265                          ptCenter.y + PWL_TRIANGLE_HALFLEN);
266           CPDF_Point pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f,
267                          ptCenter.y - PWL_TRIANGLE_HALFLEN);
268
269           if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
270               rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) {
271             CFX_PathData path;
272
273             path.SetPointCount(4);
274             path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
275             path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
276             path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
277             path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
278
279             pDevice->DrawPath(&path, pUser2Device, NULL,
280                               CPWL_Utils::PWLColorToFXColor(
281                                   PWL_DEFAULT_BLACKCOLOR, nTransparancy),
282                               0, FXFILL_ALTERNATE);
283           }
284         } break;
285         case PSBT_MAX: {
286           CPDF_Point pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y);
287           CPDF_Point pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,
288                          ptCenter.y + PWL_TRIANGLE_HALFLEN);
289           CPDF_Point pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,
290                          ptCenter.y - PWL_TRIANGLE_HALFLEN);
291
292           if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
293               rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) {
294             CFX_PathData path;
295
296             path.SetPointCount(4);
297             path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
298             path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
299             path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
300             path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
301
302             pDevice->DrawPath(&path, pUser2Device, NULL,
303                               CPWL_Utils::PWLColorToFXColor(
304                                   PWL_DEFAULT_BLACKCOLOR, nTransparancy),
305                               0, FXFILL_ALTERNATE);
306           }
307         } break;
308         default:
309           break;
310       }
311       break;
312     case SBT_VSCROLL:
313       switch (m_eSBButtonType) {
314         case PSBT_MIN: {
315           // draw border
316           CPDF_Rect rcDraw = rectWnd;
317           CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
318                                      ArgbEncode(nTransparancy, 100, 100, 100),
319                                      0.0f);
320
321           // draw inner border
322           rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f);
323           CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
324                                      ArgbEncode(nTransparancy, 255, 255, 255),
325                                      1.0f);
326
327           // draw background
328
329           rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f);
330
331           if (IsEnabled())
332             CPWL_Utils::DrawShadow(pDevice, pUser2Device, TRUE, FALSE, rcDraw,
333                                    nTransparancy, 80, 220);
334           else
335             CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw,
336                                      ArgbEncode(255, 255, 255, 255));
337
338           // draw arrow
339
340           if (rectWnd.top - rectWnd.bottom > 6.0f) {
341             FX_FLOAT fX = rectWnd.left + 1.5f;
342             FX_FLOAT fY = rectWnd.bottom;
343             CPDF_Point pts[7] = {CPDF_Point(fX + 2.5f, fY + 4.0f),
344                                  CPDF_Point(fX + 2.5f, fY + 3.0f),
345                                  CPDF_Point(fX + 4.5f, fY + 5.0f),
346                                  CPDF_Point(fX + 6.5f, fY + 3.0f),
347                                  CPDF_Point(fX + 6.5f, fY + 4.0f),
348                                  CPDF_Point(fX + 4.5f, fY + 6.0f),
349                                  CPDF_Point(fX + 2.5f, fY + 4.0f)};
350
351             if (IsEnabled())
352               CPWL_Utils::DrawFillArea(
353                   pDevice, pUser2Device, pts, 7,
354                   ArgbEncode(nTransparancy, 255, 255, 255));
355             else
356               CPWL_Utils::DrawFillArea(pDevice, pUser2Device, pts, 7,
357                                        CPWL_Utils::PWLColorToFXColor(
358                                            PWL_DEFAULT_HEAVYGRAYCOLOR, 255));
359           }
360         } break;
361         case PSBT_MAX: {
362           // draw border
363           CPDF_Rect rcDraw = rectWnd;
364           CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
365                                      ArgbEncode(nTransparancy, 100, 100, 100),
366                                      0.0f);
367
368           // draw inner border
369           rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f);
370           CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
371                                      ArgbEncode(nTransparancy, 255, 255, 255),
372                                      1.0f);
373
374           // draw background
375           rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f);
376           if (IsEnabled())
377             CPWL_Utils::DrawShadow(pDevice, pUser2Device, TRUE, FALSE, rcDraw,
378                                    nTransparancy, 80, 220);
379           else
380             CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw,
381                                      ArgbEncode(255, 255, 255, 255));
382
383           // draw arrow
384
385           if (rectWnd.top - rectWnd.bottom > 6.0f) {
386             FX_FLOAT fX = rectWnd.left + 1.5f;
387             FX_FLOAT fY = rectWnd.bottom;
388
389             CPDF_Point pts[7] = {CPDF_Point(fX + 2.5f, fY + 5.0f),
390                                  CPDF_Point(fX + 2.5f, fY + 6.0f),
391                                  CPDF_Point(fX + 4.5f, fY + 4.0f),
392                                  CPDF_Point(fX + 6.5f, fY + 6.0f),
393                                  CPDF_Point(fX + 6.5f, fY + 5.0f),
394                                  CPDF_Point(fX + 4.5f, fY + 3.0f),
395                                  CPDF_Point(fX + 2.5f, fY + 5.0f)};
396
397             if (IsEnabled())
398               CPWL_Utils::DrawFillArea(
399                   pDevice, pUser2Device, pts, 7,
400                   ArgbEncode(nTransparancy, 255, 255, 255));
401             else
402               CPWL_Utils::DrawFillArea(pDevice, pUser2Device, pts, 7,
403                                        CPWL_Utils::PWLColorToFXColor(
404                                            PWL_DEFAULT_HEAVYGRAYCOLOR, 255));
405           }
406         } break;
407         case PSBT_POS: {
408           // CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
409
410           // draw border
411           CPDF_Rect rcDraw = rectWnd;
412           CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
413                                      ArgbEncode(nTransparancy, 100, 100, 100),
414                                      0.0f);
415
416           // draw inner border
417           rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f);
418           CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
419                                      ArgbEncode(nTransparancy, 255, 255, 255),
420                                      1.0f);
421
422           if (IsEnabled()) {
423             // draw shadow effect
424
425             CPDF_Point ptTop = CPDF_Point(rectWnd.left, rectWnd.top - 1.0f);
426             CPDF_Point ptBottom =
427                 CPDF_Point(rectWnd.left, rectWnd.bottom + 1.0f);
428
429             ptTop.x += 1.5f;
430             ptBottom.x += 1.5f;
431
432             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
433                                        ArgbEncode(nTransparancy, 210, 210, 210),
434                                        1.0f);
435
436             ptTop.x += 1.0f;
437             ptBottom.x += 1.0f;
438
439             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
440                                        ArgbEncode(nTransparancy, 220, 220, 220),
441                                        1.0f);
442
443             ptTop.x += 1.0f;
444             ptBottom.x += 1.0f;
445
446             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
447                                        ArgbEncode(nTransparancy, 240, 240, 240),
448                                        1.0f);
449
450             ptTop.x += 1.0f;
451             ptBottom.x += 1.0f;
452
453             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
454                                        ArgbEncode(nTransparancy, 240, 240, 240),
455                                        1.0f);
456
457             ptTop.x += 1.0f;
458             ptBottom.x += 1.0f;
459
460             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
461                                        ArgbEncode(nTransparancy, 210, 210, 210),
462                                        1.0f);
463
464             ptTop.x += 1.0f;
465             ptBottom.x += 1.0f;
466
467             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
468                                        ArgbEncode(nTransparancy, 180, 180, 180),
469                                        1.0f);
470
471             ptTop.x += 1.0f;
472             ptBottom.x += 1.0f;
473
474             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
475                                        ArgbEncode(nTransparancy, 150, 150, 150),
476                                        1.0f);
477
478             ptTop.x += 1.0f;
479             ptBottom.x += 1.0f;
480
481             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
482                                        ArgbEncode(nTransparancy, 150, 150, 150),
483                                        1.0f);
484
485             ptTop.x += 1.0f;
486             ptBottom.x += 1.0f;
487
488             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
489                                        ArgbEncode(nTransparancy, 180, 180, 180),
490                                        1.0f);
491
492             ptTop.x += 1.0f;
493             ptBottom.x += 1.0f;
494
495             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
496                                        ArgbEncode(nTransparancy, 210, 210, 210),
497                                        1.0f);
498           } else {
499             CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw,
500                                      ArgbEncode(255, 255, 255, 255));
501           }
502
503           // draw friction
504
505           if (rectWnd.Height() > 8.0f) {
506             FX_COLORREF crStroke = ArgbEncode(nTransparancy, 120, 120, 120);
507             if (!IsEnabled())
508               crStroke = CPWL_Utils::PWLColorToFXColor(
509                   PWL_DEFAULT_HEAVYGRAYCOLOR, 255);
510
511             FX_FLOAT nFrictionWidth = 5.0f;
512             FX_FLOAT nFrictionHeight = 5.5f;
513
514             CPDF_Point ptLeft =
515                 CPDF_Point(ptCenter.x - nFrictionWidth / 2.0f,
516                            ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
517             CPDF_Point ptRight =
518                 CPDF_Point(ptCenter.x + nFrictionWidth / 2.0f,
519                            ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
520
521             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
522                                        crStroke, 1.0f);
523
524             ptLeft.y += 2.0f;
525             ptRight.y += 2.0f;
526
527             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
528                                        crStroke, 1.0f);
529
530             ptLeft.y += 2.0f;
531             ptRight.y += 2.0f;
532
533             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
534                                        crStroke, 1.0f);
535
536             /*
537             ptLeft.y += 1.5f;
538             ptRight.y += 1.5f;
539
540             CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
541                     ArgbEncode(nTransparancy,150,150,150),1.0f);
542                     */
543           }
544         } break;
545         default:
546           break;
547       }
548       break;
549     default:
550       break;
551   }
552 }
553
554 FX_BOOL CPWL_SBButton::OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag) {
555   CPWL_Wnd::OnLButtonDown(point, nFlag);
556
557   if (CPWL_Wnd* pParent = GetParentWindow())
558     pParent->OnNotify(this, PNM_LBUTTONDOWN, 0, (intptr_t)&point);
559
560   m_bMouseDown = TRUE;
561   SetCapture();
562
563   return TRUE;
564 }
565
566 FX_BOOL CPWL_SBButton::OnLButtonUp(const CPDF_Point& point, FX_DWORD nFlag) {
567   CPWL_Wnd::OnLButtonUp(point, nFlag);
568
569   if (CPWL_Wnd* pParent = GetParentWindow())
570     pParent->OnNotify(this, PNM_LBUTTONUP, 0, (intptr_t)&point);
571
572   m_bMouseDown = FALSE;
573   ReleaseCapture();
574
575   return TRUE;
576 }
577
578 FX_BOOL CPWL_SBButton::OnMouseMove(const CPDF_Point& point, FX_DWORD nFlag) {
579   CPWL_Wnd::OnMouseMove(point, nFlag);
580
581   if (CPWL_Wnd* pParent = GetParentWindow()) {
582     pParent->OnNotify(this, PNM_MOUSEMOVE, 0, (intptr_t)&point);
583
584     /*
585     if (m_bMouseDown && (m_eSBButtonType == PSBT_MIN || m_eSBButtonType ==
586     PSBT_MAX))
587     {
588             if
589     (!pParent->OnNotify(this,PNM_LBUTTONDOWN,nFlags,(intptr_t)&point))
590                     return FALSE;
591     }
592     */
593   }
594
595   return TRUE;
596 }
597
598 /* ------------------------------- CPWL_ScrollBar
599  * ---------------------------------- */
600
601 CPWL_ScrollBar::CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType)
602     : m_sbType(sbType),
603       m_pMinButton(NULL),
604       m_pMaxButton(NULL),
605       m_pPosButton(NULL),
606       m_bMouseDown(FALSE),
607       m_bMinOrMax(FALSE),
608       m_bNotifyForever(TRUE) {}
609
610 CPWL_ScrollBar::~CPWL_ScrollBar() {}
611
612 CFX_ByteString CPWL_ScrollBar::GetClassName() const {
613   return "CPWL_ScrollBar";
614 }
615
616 void CPWL_ScrollBar::OnCreate(PWL_CREATEPARAM& cp) {
617   cp.eCursorType = FXCT_ARROW;
618 }
619
620 void CPWL_ScrollBar::RePosChildWnd() {
621   CPDF_Rect rcClient = GetClientRect();
622   CPDF_Rect rcMinButton, rcMaxButton;
623   FX_FLOAT fBWidth = 0;
624
625   switch (m_sbType) {
626     case SBT_HSCROLL:
627       if (rcClient.right - rcClient.left >
628           PWL_SCROLLBAR_BUTTON_WIDTH * 2 + PWL_SCROLLBAR_POSBUTTON_MINWIDTH +
629               2) {
630         rcMinButton =
631             CPDF_Rect(rcClient.left, rcClient.bottom,
632                       rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH, rcClient.top);
633         rcMaxButton = CPDF_Rect(rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH,
634                                 rcClient.bottom, rcClient.right, rcClient.top);
635       } else {
636         fBWidth = (rcClient.right - rcClient.left -
637                    PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) /
638                   2;
639
640         if (fBWidth > 0) {
641           rcMinButton = CPDF_Rect(rcClient.left, rcClient.bottom,
642                                   rcClient.left + fBWidth, rcClient.top);
643           rcMaxButton = CPDF_Rect(rcClient.right - fBWidth, rcClient.bottom,
644                                   rcClient.right, rcClient.top);
645         } else
646           SetVisible(FALSE);
647       }
648       break;
649     case SBT_VSCROLL:
650       if (IsFloatBigger(rcClient.top - rcClient.bottom,
651                         PWL_SCROLLBAR_BUTTON_WIDTH * 2 +
652                             PWL_SCROLLBAR_POSBUTTON_MINWIDTH + 2)) {
653         rcMinButton =
654             CPDF_Rect(rcClient.left, rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH,
655                       rcClient.right, rcClient.top);
656         rcMaxButton = CPDF_Rect(rcClient.left, rcClient.bottom, rcClient.right,
657                                 rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH);
658       } else {
659         fBWidth = (rcClient.top - rcClient.bottom -
660                    PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) /
661                   2;
662
663         if (IsFloatBigger(fBWidth, 0)) {
664           rcMinButton = CPDF_Rect(rcClient.left, rcClient.top - fBWidth,
665                                   rcClient.right, rcClient.top);
666           rcMaxButton = CPDF_Rect(rcClient.left, rcClient.bottom,
667                                   rcClient.right, rcClient.bottom + fBWidth);
668         } else
669           SetVisible(FALSE);
670       }
671       break;
672   }
673
674   if (m_pMinButton)
675     m_pMinButton->Move(rcMinButton, TRUE, FALSE);
676   if (m_pMaxButton)
677     m_pMaxButton->Move(rcMaxButton, TRUE, FALSE);
678   MovePosButton(FALSE);
679 }
680
681 void CPWL_ScrollBar::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
682   CPDF_Rect rectWnd = GetWindowRect();
683
684   if (IsVisible() && !rectWnd.IsEmpty()) {
685     CFX_ByteTextBuf sButton;
686
687     sButton << "q\n";
688     sButton << "0 w\n"
689             << CPWL_Utils::GetColorAppStream(GetBackgroundColor(), TRUE);
690     sButton << rectWnd.left << " " << rectWnd.bottom << " "
691             << rectWnd.right - rectWnd.left << " "
692             << rectWnd.top - rectWnd.bottom << " re b Q\n";
693
694     sAppStream << sButton;
695   }
696 }
697
698 void CPWL_ScrollBar::DrawThisAppearance(CFX_RenderDevice* pDevice,
699                                         CPDF_Matrix* pUser2Device) {
700   CPDF_Rect rectWnd = GetWindowRect();
701
702   if (IsVisible() && !rectWnd.IsEmpty()) {
703     CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rectWnd,
704                              GetBackgroundColor(), GetTransparency());
705
706     CPWL_Utils::DrawStrokeLine(
707         pDevice, pUser2Device,
708         CPDF_Point(rectWnd.left + 2.0f, rectWnd.top - 2.0f),
709         CPDF_Point(rectWnd.left + 2.0f, rectWnd.bottom + 2.0f),
710         ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f);
711
712     CPWL_Utils::DrawStrokeLine(
713         pDevice, pUser2Device,
714         CPDF_Point(rectWnd.right - 2.0f, rectWnd.top - 2.0f),
715         CPDF_Point(rectWnd.right - 2.0f, rectWnd.bottom + 2.0f),
716         ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f);
717   }
718 }
719
720 FX_BOOL CPWL_ScrollBar::OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag) {
721   CPWL_Wnd::OnLButtonDown(point, nFlag);
722
723   if (HasFlag(PWS_AUTOTRANSPARENT)) {
724     if (GetTransparency() != 255) {
725       SetTransparency(255);
726       InvalidateRect();
727     }
728   }
729
730   CPDF_Rect rcMinArea, rcMaxArea;
731
732   if (m_pPosButton && m_pPosButton->IsVisible()) {
733     CPDF_Rect rcClient = GetClientRect();
734     CPDF_Rect rcPosButton = m_pPosButton->GetWindowRect();
735
736     switch (m_sbType) {
737       case SBT_HSCROLL:
738         rcMinArea = CPDF_Rect(rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH,
739                               rcClient.bottom, rcPosButton.left, rcClient.top);
740         rcMaxArea = CPDF_Rect(rcPosButton.right, rcClient.bottom,
741                               rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH,
742                               rcClient.top);
743
744         break;
745       case SBT_VSCROLL:
746         rcMinArea = CPDF_Rect(rcClient.left, rcPosButton.top, rcClient.right,
747                               rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH);
748         rcMaxArea = CPDF_Rect(rcClient.left,
749                               rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH,
750                               rcClient.right, rcPosButton.bottom);
751         break;
752     }
753
754     rcMinArea.Normalize();
755     rcMaxArea.Normalize();
756
757     if (rcMinArea.Contains(point.x, point.y)) {
758       m_sData.SubBig();
759       MovePosButton(TRUE);
760       NotifyScrollWindow();
761     }
762
763     if (rcMaxArea.Contains(point.x, point.y)) {
764       m_sData.AddBig();
765       MovePosButton(TRUE);
766       NotifyScrollWindow();
767     }
768   }
769
770   return TRUE;
771 }
772
773 FX_BOOL CPWL_ScrollBar::OnLButtonUp(const CPDF_Point& point, FX_DWORD nFlag) {
774   CPWL_Wnd::OnLButtonUp(point, nFlag);
775
776   if (HasFlag(PWS_AUTOTRANSPARENT)) {
777     if (GetTransparency() != PWL_SCROLLBAR_TRANSPARANCY) {
778       SetTransparency(PWL_SCROLLBAR_TRANSPARANCY);
779       InvalidateRect();
780     }
781   }
782
783   EndTimer();
784   m_bMouseDown = FALSE;
785
786   return TRUE;
787 }
788
789 void CPWL_ScrollBar::OnNotify(CPWL_Wnd* pWnd,
790                               FX_DWORD msg,
791                               intptr_t wParam,
792                               intptr_t lParam) {
793   CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
794
795   switch (msg) {
796     case PNM_LBUTTONDOWN:
797       if (pWnd == m_pMinButton) {
798         OnMinButtonLBDown(*(CPDF_Point*)lParam);
799       }
800
801       if (pWnd == m_pMaxButton) {
802         OnMaxButtonLBDown(*(CPDF_Point*)lParam);
803       }
804
805       if (pWnd == m_pPosButton) {
806         OnPosButtonLBDown(*(CPDF_Point*)lParam);
807       }
808       break;
809     case PNM_LBUTTONUP:
810       if (pWnd == m_pMinButton) {
811         OnMinButtonLBUp(*(CPDF_Point*)lParam);
812       }
813
814       if (pWnd == m_pMaxButton) {
815         OnMaxButtonLBUp(*(CPDF_Point*)lParam);
816       }
817
818       if (pWnd == m_pPosButton) {
819         OnPosButtonLBUp(*(CPDF_Point*)lParam);
820       }
821       break;
822     case PNM_MOUSEMOVE:
823       if (pWnd == m_pMinButton) {
824         OnMinButtonMouseMove(*(CPDF_Point*)lParam);
825       }
826
827       if (pWnd == m_pMaxButton) {
828         OnMaxButtonMouseMove(*(CPDF_Point*)lParam);
829       }
830
831       if (pWnd == m_pPosButton) {
832         OnPosButtonMouseMove(*(CPDF_Point*)lParam);
833       }
834       break;
835     case PNM_SETSCROLLINFO: {
836       if (PWL_SCROLL_INFO* pInfo = (PWL_SCROLL_INFO*)lParam) {
837         if (FXSYS_memcmp(&m_OriginInfo, pInfo, sizeof(PWL_SCROLL_INFO)) != 0) {
838           m_OriginInfo = *pInfo;
839           FX_FLOAT fMax =
840               pInfo->fContentMax - pInfo->fContentMin - pInfo->fPlateWidth;
841           fMax = fMax > 0.0f ? fMax : 0.0f;
842           SetScrollRange(0, fMax, pInfo->fPlateWidth);
843           SetScrollStep(pInfo->fBigStep, pInfo->fSmallStep);
844         }
845       }
846     } break;
847     case PNM_SETSCROLLPOS: {
848       FX_FLOAT fPos = *(FX_FLOAT*)lParam;
849       switch (m_sbType) {
850         case SBT_HSCROLL:
851           fPos = fPos - m_OriginInfo.fContentMin;
852           break;
853         case SBT_VSCROLL:
854           fPos = m_OriginInfo.fContentMax - fPos;
855           break;
856       }
857       SetScrollPos(fPos);
858     } break;
859   }
860 }
861
862 void CPWL_ScrollBar::CreateButtons(const PWL_CREATEPARAM& cp) {
863   PWL_CREATEPARAM scp = cp;
864   scp.pParentWnd = this;
865   scp.dwBorderWidth = 2;
866   scp.nBorderStyle = PBS_BEVELED;
867
868   scp.dwFlags =
869       PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP;
870
871   if (!m_pMinButton) {
872     m_pMinButton = new CPWL_SBButton(m_sbType, PSBT_MIN);
873     m_pMinButton->Create(scp);
874   }
875
876   if (!m_pMaxButton) {
877     m_pMaxButton = new CPWL_SBButton(m_sbType, PSBT_MAX);
878     m_pMaxButton->Create(scp);
879   }
880
881   if (!m_pPosButton) {
882     m_pPosButton = new CPWL_SBButton(m_sbType, PSBT_POS);
883     m_pPosButton->SetVisible(FALSE);
884     m_pPosButton->Create(scp);
885   }
886 }
887
888 FX_FLOAT CPWL_ScrollBar::GetScrollBarWidth() const {
889   if (!IsVisible())
890     return 0;
891
892   return PWL_SCROLLBAR_WIDTH;
893 }
894
895 void CPWL_ScrollBar::SetScrollRange(FX_FLOAT fMin,
896                                     FX_FLOAT fMax,
897                                     FX_FLOAT fClientWidth) {
898   if (m_pPosButton) {
899     m_sData.SetScrollRange(fMin, fMax);
900     m_sData.SetClientWidth(fClientWidth);
901
902     if (IsFloatSmaller(m_sData.ScrollRange.GetWidth(), 0.0f)) {
903       m_pPosButton->SetVisible(FALSE);
904     } else {
905       m_pPosButton->SetVisible(TRUE);
906       MovePosButton(TRUE);
907     }
908   }
909 }
910
911 void CPWL_ScrollBar::SetScrollPos(FX_FLOAT fPos) {
912   FX_FLOAT fOldPos = m_sData.fScrollPos;
913
914   m_sData.SetPos(fPos);
915
916   if (!IsFloatEqual(m_sData.fScrollPos, fOldPos))
917     MovePosButton(TRUE);
918 }
919
920 void CPWL_ScrollBar::SetScrollStep(FX_FLOAT fBigStep, FX_FLOAT fSmallStep) {
921   m_sData.SetBigStep(fBigStep);
922   m_sData.SetSmallStep(fSmallStep);
923 }
924
925 void CPWL_ScrollBar::MovePosButton(FX_BOOL bRefresh) {
926   ASSERT(m_pPosButton != NULL);
927   ASSERT(m_pMinButton != NULL);
928   ASSERT(m_pMaxButton != NULL);
929
930   if (m_pPosButton->IsVisible()) {
931     CPDF_Rect rcClient;
932     CPDF_Rect rcPosArea, rcPosButton;
933
934     rcClient = GetClientRect();
935     rcPosArea = GetScrollArea();
936
937     FX_FLOAT fLeft, fRight, fTop, fBottom;
938
939     switch (m_sbType) {
940       case SBT_HSCROLL:
941         fLeft = TrueToFace(m_sData.fScrollPos);
942         fRight = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth);
943
944         if (fRight - fLeft < PWL_SCROLLBAR_POSBUTTON_MINWIDTH)
945           fRight = fLeft + PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
946
947         if (fRight > rcPosArea.right) {
948           fRight = rcPosArea.right;
949           fLeft = fRight - PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
950         }
951
952         rcPosButton = CPDF_Rect(fLeft, rcPosArea.bottom, fRight, rcPosArea.top);
953
954         break;
955       case SBT_VSCROLL:
956         fBottom = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth);
957         fTop = TrueToFace(m_sData.fScrollPos);
958
959         if (IsFloatSmaller(fTop - fBottom, PWL_SCROLLBAR_POSBUTTON_MINWIDTH))
960           fBottom = fTop - PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
961
962         if (IsFloatSmaller(fBottom, rcPosArea.bottom)) {
963           fBottom = rcPosArea.bottom;
964           fTop = fBottom + PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
965         }
966
967         rcPosButton = CPDF_Rect(rcPosArea.left, fBottom, rcPosArea.right, fTop);
968
969         break;
970     }
971
972     m_pPosButton->Move(rcPosButton, TRUE, bRefresh);
973   }
974 }
975
976 void CPWL_ScrollBar::OnMinButtonLBDown(const CPDF_Point& point) {
977   m_sData.SubSmall();
978   MovePosButton(TRUE);
979   NotifyScrollWindow();
980
981   m_bMinOrMax = TRUE;
982
983   EndTimer();
984   BeginTimer(100);
985 }
986
987 void CPWL_ScrollBar::OnMinButtonLBUp(const CPDF_Point& point) {}
988
989 void CPWL_ScrollBar::OnMinButtonMouseMove(const CPDF_Point& point) {}
990
991 void CPWL_ScrollBar::OnMaxButtonLBDown(const CPDF_Point& point) {
992   m_sData.AddSmall();
993   MovePosButton(TRUE);
994   NotifyScrollWindow();
995
996   m_bMinOrMax = FALSE;
997
998   EndTimer();
999   BeginTimer(100);
1000 }
1001
1002 void CPWL_ScrollBar::OnMaxButtonLBUp(const CPDF_Point& point) {}
1003
1004 void CPWL_ScrollBar::OnMaxButtonMouseMove(const CPDF_Point& point) {}
1005
1006 void CPWL_ScrollBar::OnPosButtonLBDown(const CPDF_Point& point) {
1007   m_bMouseDown = TRUE;
1008
1009   if (m_pPosButton) {
1010     CPDF_Rect rcPosButton = m_pPosButton->GetWindowRect();
1011
1012     switch (m_sbType) {
1013       case SBT_HSCROLL:
1014         m_nOldPos = point.x;
1015         m_fOldPosButton = rcPosButton.left;
1016         break;
1017       case SBT_VSCROLL:
1018         m_nOldPos = point.y;
1019         m_fOldPosButton = rcPosButton.top;
1020         break;
1021     }
1022   }
1023 }
1024
1025 void CPWL_ScrollBar::OnPosButtonLBUp(const CPDF_Point& point) {
1026   if (m_bMouseDown) {
1027     if (!m_bNotifyForever)
1028       NotifyScrollWindow();
1029   }
1030   m_bMouseDown = FALSE;
1031 }
1032
1033 void CPWL_ScrollBar::OnPosButtonMouseMove(const CPDF_Point& point) {
1034   FX_FLOAT fOldScrollPos = m_sData.fScrollPos;
1035
1036   FX_FLOAT fNewPos = 0;
1037
1038   switch (m_sbType) {
1039     case SBT_HSCROLL:
1040       if (FXSYS_fabs(point.x - m_nOldPos) < 1)
1041         return;
1042       fNewPos = FaceToTrue(m_fOldPosButton + point.x - m_nOldPos);
1043       break;
1044     case SBT_VSCROLL:
1045       if (FXSYS_fabs(point.y - m_nOldPos) < 1)
1046         return;
1047       fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos);
1048       break;
1049   }
1050
1051   if (m_bMouseDown) {
1052     switch (m_sbType) {
1053       case SBT_HSCROLL:
1054
1055         if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) {
1056           fNewPos = m_sData.ScrollRange.fMin;
1057         }
1058
1059         if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) {
1060           fNewPos = m_sData.ScrollRange.fMax;
1061         }
1062
1063         m_sData.SetPos(fNewPos);
1064
1065         break;
1066       case SBT_VSCROLL:
1067
1068         if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) {
1069           fNewPos = m_sData.ScrollRange.fMin;
1070         }
1071
1072         if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) {
1073           fNewPos = m_sData.ScrollRange.fMax;
1074         }
1075
1076         m_sData.SetPos(fNewPos);
1077
1078         break;
1079     }
1080
1081     if (!IsFloatEqual(fOldScrollPos, m_sData.fScrollPos)) {
1082       MovePosButton(TRUE);
1083
1084       if (m_bNotifyForever)
1085         NotifyScrollWindow();
1086     }
1087   }
1088 }
1089
1090 void CPWL_ScrollBar::NotifyScrollWindow() {
1091   if (CPWL_Wnd* pParent = GetParentWindow()) {
1092     FX_FLOAT fPos;
1093     switch (m_sbType) {
1094       case SBT_HSCROLL:
1095         fPos = m_OriginInfo.fContentMin + m_sData.fScrollPos;
1096         break;
1097       case SBT_VSCROLL:
1098         fPos = m_OriginInfo.fContentMax - m_sData.fScrollPos;
1099         break;
1100     }
1101     pParent->OnNotify(this, PNM_SCROLLWINDOW, (intptr_t)m_sbType,
1102                       (intptr_t)&fPos);
1103   }
1104 }
1105
1106 CPDF_Rect CPWL_ScrollBar::GetScrollArea() const {
1107   CPDF_Rect rcClient = GetClientRect();
1108   CPDF_Rect rcArea;
1109
1110   if (!m_pMinButton || !m_pMaxButton)
1111     return rcClient;
1112
1113   CPDF_Rect rcMin = m_pMinButton->GetWindowRect();
1114   CPDF_Rect rcMax = m_pMaxButton->GetWindowRect();
1115
1116   FX_FLOAT fMinWidth = rcMin.right - rcMin.left;
1117   FX_FLOAT fMinHeight = rcMin.top - rcMin.bottom;
1118   FX_FLOAT fMaxWidth = rcMax.right - rcMax.left;
1119   FX_FLOAT fMaxHeight = rcMax.top - rcMax.bottom;
1120
1121   switch (m_sbType) {
1122     case SBT_HSCROLL:
1123       if (rcClient.right - rcClient.left > fMinWidth + fMaxWidth + 2) {
1124         rcArea = CPDF_Rect(rcClient.left + fMinWidth + 1, rcClient.bottom,
1125                            rcClient.right - fMaxWidth - 1, rcClient.top);
1126       } else {
1127         rcArea = CPDF_Rect(rcClient.left + fMinWidth + 1, rcClient.bottom,
1128                            rcClient.left + fMinWidth + 1, rcClient.top);
1129       }
1130       break;
1131     case SBT_VSCROLL:
1132       if (rcClient.top - rcClient.bottom > fMinHeight + fMaxHeight + 2) {
1133         rcArea = CPDF_Rect(rcClient.left, rcClient.bottom + fMinHeight + 1,
1134                            rcClient.right, rcClient.top - fMaxHeight - 1);
1135       } else {
1136         rcArea = CPDF_Rect(rcClient.left, rcClient.bottom + fMinHeight + 1,
1137                            rcClient.right, rcClient.bottom + fMinHeight + 1);
1138       }
1139       break;
1140   }
1141
1142   rcArea.Normalize();
1143
1144   return rcArea;
1145 }
1146
1147 FX_FLOAT CPWL_ScrollBar::TrueToFace(FX_FLOAT fTrue) {
1148   CPDF_Rect rcPosArea;
1149   rcPosArea = GetScrollArea();
1150
1151   FX_FLOAT fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth;
1152   fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
1153
1154   FX_FLOAT fFace = 0;
1155
1156   switch (m_sbType) {
1157     case SBT_HSCROLL:
1158       fFace = rcPosArea.left +
1159               fTrue * (rcPosArea.right - rcPosArea.left) / fFactWidth;
1160       break;
1161     case SBT_VSCROLL:
1162       fFace = rcPosArea.top -
1163               fTrue * (rcPosArea.top - rcPosArea.bottom) / fFactWidth;
1164       break;
1165   }
1166
1167   return fFace;
1168 }
1169
1170 FX_FLOAT CPWL_ScrollBar::FaceToTrue(FX_FLOAT fFace) {
1171   CPDF_Rect rcPosArea;
1172   rcPosArea = GetScrollArea();
1173
1174   FX_FLOAT fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth;
1175   fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
1176
1177   FX_FLOAT fTrue = 0;
1178
1179   switch (m_sbType) {
1180     case SBT_HSCROLL:
1181       fTrue = (fFace - rcPosArea.left) * fFactWidth /
1182               (rcPosArea.right - rcPosArea.left);
1183       break;
1184     case SBT_VSCROLL:
1185       fTrue = (rcPosArea.top - fFace) * fFactWidth /
1186               (rcPosArea.top - rcPosArea.bottom);
1187       break;
1188   }
1189
1190   return fTrue;
1191 }
1192
1193 void CPWL_ScrollBar::CreateChildWnd(const PWL_CREATEPARAM& cp) {
1194   CreateButtons(cp);
1195 }
1196
1197 void CPWL_ScrollBar::TimerProc() {
1198   PWL_SCROLL_PRIVATEDATA sTemp = m_sData;
1199
1200   if (m_bMinOrMax)
1201     m_sData.SubSmall();
1202   else
1203     m_sData.AddSmall();
1204
1205   if (FXSYS_memcmp(&m_sData, &sTemp, sizeof(PWL_SCROLL_PRIVATEDATA)) != 0) {
1206     MovePosButton(TRUE);
1207     NotifyScrollWindow();
1208   }
1209 }