Ignore SIGHUP's
[forms.git] / src / F_Scrollbar.C
blobd3a7449e82975faa947cac4ff24272ea45b97505
2  /*
3   *   Copyright (C) 2007, Harbour, All rights reserved.
4   */
6 #include <F_Scrollbar.H>
7 #include <F_Window.H>
9 using namespace F;
11 void F_Scrollbar::draw()
13  if (!bounds_)
14    return;
15  bgch(f_text_display->recode('�'));
16  F_Widget::draw();
17  F_Point p(0, 0);
18  F_Text_Symbol smb;
19  smb.color(parent()->fg(), parent()->bg());
20  // draw arrows
21  if (type_ == F_VERTICAL) {
22    smb.ch_ = 0x18;
23    draw_buf.set(p, smb);
24    p.move(0, h() - 1);
25    smb.ch_ = 0x19;
26    draw_buf.set(p, smb);
27  } else {
28    smb.ch_ = 0x1B;
29    draw_buf.set(p, smb);
30    p.move(w() - 1, 0);
31    smb.ch_ = 0x1A;
32    draw_buf.set(p, smb);
33  }
34  // draw bar
35  smb.ch_ = f_text_display->recode('�');
36  unsigned int position;
37  if (type_ == F_VERTICAL)
38    position = (int)((((float)value_)/((float)bounds_)) * ((h() - 1) - size_));
39  else
40    position = (int)((((float)value_)/((float)bounds_)) * ((w() - 1) - size_));
41  if (!position)
42    position = 1;
43  if (type_ == F_VERTICAL) {
44    if (int(position + size_) > (h() - 1))
45      position = (h() - 1) - size_;
46  } else {
47    if (int(position + size_) > (w() - 1))
48      position = (w() - 1) - size_;
49  }
50  if (!position)
51    position = 1;
52  for (unsigned int i = 0; i < size_; i++) {
53    if (type_ == F_VERTICAL)
54      p.move(0, position + i);
55    else
56      p.move(position + i, 0);
57    draw_buf.set(p, smb);
58  }
61 static coord_t cur_mouse_x, cur_mouse_y;
63 bool F_Scrollbar::handle(F_Event_t &ev)
65  switch(ev.type) {
66    case F_ENTER:
67    case F_FOCUS:
68 //     debug("F_ENTER: sbrid - %d", id());
69      draw();
70      return true;
71    case F_LEAVE:
72    case F_UNFOCUS:
73 //     debug("F_LEAVE: sbrid - %d", id());
74      draw();
75      return true;
76    case F_KEY_PRESS:
77      switch (ev.kbd.key) {
78        case F_Page_Down:
79          if (type_ == F_VERTICAL)
80            value(value() + (h() - 1));
81          else
82            value(value() + (w() - 1));
83          break;
84        case F_Page_Up:
85          if (type_ == F_VERTICAL)
86            value(value() - (h() - 1));
87          else
88            value(value() - (w() - 1));
89          break;
90        case F_Up:
91          if (type_ == F_VERTICAL)
92            value(value() - 1);
93          break;
94        case F_Down:
95          if (type_ == F_VERTICAL)
96            value(value() + 1);
97          break;
98        case F_Left:
99          if (type_ == F_HORIZONTAL)
100            value(value() - 1);
101          break;
102        case F_Right:
103          if (type_ == F_HORIZONTAL)
104            value(value() + 1);
105          break;
106        case F_Home:
107          if (ev.kbd.modifiers & F_CTRL) {
108            value(0);
109            break;
110       }
111        case F_End:
112          if (ev.kbd.modifiers & F_CTRL) {
113            value(bounds_);
114            break;
115       }
116        default:
117          return false;
118      }
119        draw();
120        do_callback();
121        return true;
122    case F_KEY_RELEASE:
123      break;
124    case F_POINTER_DRAG:
125 //     debug("F_POINTER_DRAG: sbrid - %d", id());
126      if (type_ == F_HORIZONTAL) { // sense x movement
127        int x = ev.mouse.x - cur_mouse_x;
128        if (x > 0)
129          value(value() + 1);
130        else if (x < 0)
131          value(value() - 1);
132        else
133          break;
134      } else {
135        int y = ev.mouse.y - cur_mouse_y;
136        if (y > 0)
137          value(value() + 1);
138        else if (y < 0)
139          value(value() - 1);
140        else
141          break;
142      }
143      draw();
144      do_callback();
145    case F_POINTER_PRESS:
146      // check if bar or space pressed
147      // ....
148      cur_mouse_x = ev.mouse.x;
149      cur_mouse_y = ev.mouse.y;
150      return true;
151    default:
152 //     debug("sbrid - %d, evtype - %d", id(), ev.type);
153      break;
155  return false;