Fixed major issues
[ede] / explorer / src / SplitWindow.ec
1 import "ecere"
2
3 class SplitWindow : Window
4 {
5    bool sliding;
6    int startPos, startX;
7    background = activeBorder, borderStyle = bevel;
8    anchor = { top = -2, bottom = -2 }, stayOnTop = true, inactive = true;
9    size = { w = 6 };
10    cursor = ((GuiApplication)__thisModule).GetCursor(sizeWE);
11
12    Window leftPane, rightPane;
13    double scaleSplit;
14    int split;
15    bool scale;
16
17    property double scaleSplit
18    {
19       set
20       {
21          scaleSplit = value;
22          property::split = (int)(parent.clientSize.w * (value) + 0.5);
23          scale = true;
24       }
25    }
26    property int split
27    {
28       set
29       {
30          int w = size.w;
31          int pw = parent.clientSize.w;
32          int x = value;
33
34          split = value;
35          
36          if(leftPane && !rightPane)
37             leftPane.anchor.right = 0;
38          else if(rightPane && !leftPane)
39             rightPane.anchor.left = 0;
40          else
41          {
42             if(leftPane)
43                leftPane.anchor.right = pw - x;
44             if(rightPane)
45                rightPane.anchor.left = x + w / 2;
46          }
47          anchor.left = x;
48
49          scale = false;
50       }      
51    }
52
53    void OnResize(int width, int height)
54    {
55       //if(visible)
56       {
57          if(scale)
58             property::scaleSplit = scaleSplit;
59          else
60             property::split = split;
61       }
62    }
63          
64    bool OnLeftButtonDown(int x, int y, Modifiers mods)
65    {
66       sliding = true;
67       startPos = x + absPosition.x;
68       startX = position.x;
69
70       Capture();
71       
72       return true;
73    }
74
75    bool OnMouseLeave(Modifiers mods)
76    {
77       parent.cursor = null;
78       return true;
79    }
80    bool OnMouseMove(int x, int y, Modifiers mods)
81    {
82       parent.cursor = cursor;
83       if(sliding)
84       {
85          bool oldScale = scale;
86          x += absPosition.x;
87          x -= startPos;
88          x += startX;
89          x = Max(x, 20);
90          x = Min(x, parent.clientSize.w - 20);
91
92          property::split = x;
93          scale = oldScale;
94       }
95       return true;
96    }
97
98    bool OnLeftButtonUp(int x, int y, Modifiers mods)
99    {
100       if(sliding)
101       {
102          ReleaseCapture();
103          parent.cursor = null;
104          sliding = false;
105       }
106       return true;
107    }
108 }
109