gcc-4.3.0 fixes
[forms.git] / F / F_Scrollbar.H
blob640c3f762f4d147bdf61cb6ece9464b8660966b0
2  /*
3   *   Copyright (C) 2007, Harbour, All rights reserved.
4   */
6 #ifndef _F_SCROLLBAR_H_
7 #define _F_SCROLLBAR_H_
9 #include <F_Text_Display.H>
10 #include <F_Widget.H>
11 #include <math.h>
13 namespace F {
15 class F_Scrollbar : public F_Widget {
17   unsigned int size_; // visible scrollbar size [ 1 <-> (h() - 1) ]
18   unsigned int value_; // current virtual value
19   unsigned int bounds_; // virtual value bounds
20   char type_;
22   void draw();
23   void size(int sz) {
24     if (type_ == F_VERTICAL) {
25       if (sz > (h() - 2))
26         sz = h() - 2;
27     } else {
28       if (sz > (w() - 2))
29         sz = w() - 2;
30     }
31     if (sz < 1)
32       sz = 1;
33     size_ = sz;
34     redraw();
35   }
37  public:
38   F_Scrollbar(F_Box_Type_t btype, char type, coord_t x, coord_t y, dim_t w, dim_t h,
39     const char *label = 0) : F_Widget(x, y, w, h, label) {
40       hide();
41       type_ = type;
42       size_ = 1;
43       bounds_ = value_ = 0;
44  }
45   ~F_Scrollbar() { }
46   bool handle(F_Event_t &ev);
47   unsigned int value() { return value_; }
48   void value(int val) {
49     if (val < 0)
50       val = 0;
51     if (val > (int)bounds_)
52       value_ = bounds_;
53     else
54       value_ = val;
55   }
56   void bounds(unsigned int b) {
57     bounds_ = b;
58     if (type_ == F_VERTICAL) {
59       if (int(bounds_) < (h() - 2))
60         size((int)floorf(((float)bounds_/((float)(h() - 2))) * (float(h() - 2))));
61       else
62         size((int)floorf(((float)(h() - 2)/((float)bounds_)) * (float(h() - 2))));
63     } else {
64       if (int(bounds_) < (w() - 2))
65         size((int)floorf(((float)bounds_/((float)(w() - 2))) * (float(w() - 2))));
66       else
67         size((int)floorf(((float)(w() - 2)/((float)bounds_)) * (float(w() - 2))));
68     }
69     value(value_);
70    }
71  };
74 #endif