ide/Project: Fixed double GCC_PREFIX introduced by 'fix makefile generation to be...
[sdk] / ecere / src / gui / controls / PaneSplitter.ec
1 import "Window"
2
3 define defaultToolSize = 6;
4
5 public class PaneSplitter : Window
6 {
7    bool sliding;
8    int startPos, startX;
9    background = formColor, borderStyle = bevel;
10    anchor = { top = -2, bottom = -2 }, stayOnTop = true, inactive = true;
11    size = { w = defaultToolSize };
12    cursor = ((GuiApplication)__thisModule.application).GetCursor(sizeWE);
13
14    Window leftPane, rightPane;
15    double scaleSplit;
16    int split;
17    bool scale;
18    ScrollDirection orientation;
19    int toolSize, toolGap;
20
21    orientation = (ScrollDirection)-1;
22    toolSize = defaultToolSize;
23    toolGap = 2;
24
25    void OnResize(int width, int height)
26    {
27       if(leftPane || rightPane)
28       {
29          if(orientation == (ScrollDirection)-1) orientation = vertical;
30          if(scale)
31             property::scaleSplit = scaleSplit;
32          else
33             property::split = split;
34        }
35    }
36
37    bool OnLeftButtonDown(int x, int y, Modifiers mods)
38    {
39       sliding = true;
40       if(orientation == vertical)
41       {
42          startPos = x + absPosition.x;
43          startX = position.x;
44       }
45       else
46       {
47          startPos = y + absPosition.y;
48          startX = position.y;
49       }
50       Capture();
51
52       return true;
53    }
54
55    bool OnMouseLeave(Modifiers mods)
56    {
57       parent.cursor = null;
58       return true;
59    }
60    bool OnMouseMove(int x, int y, Modifiers mods)
61    {
62       parent.cursor = cursor;
63       if(sliding)
64       {
65          bool oldScale = scale;
66          scale = false;
67          if(orientation == vertical)
68          {
69             x += absPosition.x;
70             x -= startPos;
71             x += startX;
72             x = Max(x, leftPane ? leftPane.minClientSize.w : 20);
73             x = Min(x, parent.clientSize.w - (rightPane ? rightPane.minClientSize.w : 20) - toolGap - toolSize);
74
75             property::split = x;
76
77             scaleSplit = (double) x / (double) parent.clientSize.w;
78          }
79          else
80          {
81             y += absPosition.y;
82             y -= startPos;
83             y += startX;
84             y = Max(y, leftPane ? leftPane.minClientSize.h : 20);
85             y = Min(y, parent.clientSize.h - (rightPane ? rightPane.minClientSize.h : 20) - toolGap - toolSize);
86
87             property::split = y;
88
89             scaleSplit = (double) y / (double)parent.clientSize.h;
90          }
91          scale = oldScale;
92          NotifyResized(master, this);
93       }
94       return true;
95    }
96
97    bool OnLeftButtonUp(int x, int y, Modifiers mods)
98    {
99       if(sliding)
100       {
101          ReleaseCapture();
102          parent.cursor = null;
103          sliding = false;
104          NotifyResized(master, this);
105       }
106       return true;
107    }
108
109 public:
110    property int toolSize
111    {
112       set { toolSize = value; } get { return toolSize; }
113    }
114    property int toolGap
115    {
116       set { toolGap = value; } get { return toolGap; }
117    }
118    property Window leftPane
119    {
120       set { leftPane = value; property::split = split; } get { return leftPane; }
121    }
122    property Window rightPane
123    {
124       set { rightPane = value; property::split = split; } get { return rightPane; }
125    }
126    property Window topPane
127    {
128       set { leftPane = value; property::split = split; } get { return leftPane; }
129    }
130    property Window bottomPane
131    {
132       set { rightPane = value; property::split = split; } get { return rightPane; }
133    }
134    property double scaleSplit
135    {
136       set
137       {
138          scaleSplit = value;
139          property::split = (int)(((orientation == vertical) ? parent.clientSize.w : parent.clientSize.h) * (value) + 0.5);
140          scale = true;
141       }
142       get { return scaleSplit; }
143    }
144    property ScrollDirection orientation
145    {
146       set
147       {
148          orientation = value;
149          if(orientation == vertical)
150          {
151             size = { w = toolSize };
152             anchor = { top = -2, bottom = -2 };
153             cursor = ((GuiApplication)__thisModule.application).GetCursor(sizeWE);
154          }
155          else
156          {
157             position = { 0, 0 };
158             size = { h = toolSize };
159             anchor = { left = -2, right = -2 };
160             cursor = ((GuiApplication)__thisModule.application).GetCursor(sizeNS);
161          }
162       }
163       get { return orientation; }
164    }
165    property int split
166    {
167       set
168       {
169          split = value;
170          if(orientation == vertical)
171          {
172             int w = size.w;
173             int pw = parent.clientSize.w;
174             int x = value;
175             x = Max(x, leftPane ? leftPane.minClientSize.w : 20);
176             x = Min(x, parent.clientSize.w - (rightPane ? rightPane.minClientSize.w : 20) - toolGap - toolSize);
177
178             if(leftPane) leftPane.anchor.right = pw - x + toolGap;
179             if(rightPane) rightPane.anchor.left = x + w + toolGap;
180             anchor.left = x;
181
182             scale = false;
183          }
184          else if(orientation == horizontal)
185          {
186             int h = size.h;
187             int ph = parent.clientSize.h;
188             int y = value;
189             y = Max(y, leftPane ? leftPane.minClientSize.h : 20);
190             y = Min(y, parent.clientSize.h - (rightPane ? rightPane.minClientSize.h : 20) - toolGap - toolSize);
191
192             if(leftPane)  leftPane.anchor.bottom = ph - y + toolGap;
193             if(rightPane) rightPane.anchor.top = y + h + toolGap;
194             anchor.top = y;
195
196             scale = false;
197          }
198       }
199       get { return split; }
200    }
201
202    virtual bool Window::NotifyResized(PaneSplitter splitter);
203 }