1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "gui/divider.hh"
|
---|
10 | #include "window/style.hh"
|
---|
11 | #include "window/win_evt.hh"
|
---|
12 |
|
---|
13 | void i4_divider_class::reparent(i4_image_class *draw_area, i4_parent_window_class *parent)
|
---|
14 | {
|
---|
15 | if (parent && (w_attached && width()!=parent->width() ||
|
---|
16 | h_attached && height()!=parent->height()))
|
---|
17 | {
|
---|
18 | int nw=w_attached ? parent->width() : width();
|
---|
19 | int nh=h_attached ? parent->height() : height();
|
---|
20 |
|
---|
21 | resize(nw,nw);
|
---|
22 | }
|
---|
23 |
|
---|
24 | i4_parent_window_class::reparent(draw_area, parent);
|
---|
25 | }
|
---|
26 |
|
---|
27 | void i4_divider_class::resize(w16 new_width, w16 new_height)
|
---|
28 | {
|
---|
29 | if (w_attached && parent)
|
---|
30 | new_width=parent->width();
|
---|
31 |
|
---|
32 | if (h_attached && parent)
|
---|
33 | new_height=parent->height();
|
---|
34 |
|
---|
35 | i4_parent_window_class::resize(new_width, new_height);
|
---|
36 |
|
---|
37 | int x1,y1,x2,y2;
|
---|
38 | get_drag_area(x1,y1,x2,y2);
|
---|
39 |
|
---|
40 | if (split_up_down)
|
---|
41 | {
|
---|
42 | if (w1.get())
|
---|
43 | {
|
---|
44 | remove_child(w1.get());
|
---|
45 | if (y1<0) y1=0;
|
---|
46 | w1->resize(new_width, y1);
|
---|
47 | add_child(0,0,w1.get());
|
---|
48 | }
|
---|
49 |
|
---|
50 | if (w2.get())
|
---|
51 | {
|
---|
52 | remove_child(w2.get());
|
---|
53 | int nh=new_height-y2;
|
---|
54 | if (nh<0) nh=0;
|
---|
55 |
|
---|
56 | w2->resize(w, nh);
|
---|
57 | add_child(0,y2+1, w2.get());
|
---|
58 | }
|
---|
59 | }
|
---|
60 | else
|
---|
61 | {
|
---|
62 | if (w1.get())
|
---|
63 | {
|
---|
64 | remove_child(w1.get());
|
---|
65 | if (x1<0) x1=0;
|
---|
66 | w1->resize(x1, new_height);
|
---|
67 | add_child(0,0,w1.get());
|
---|
68 | }
|
---|
69 |
|
---|
70 | if (w2.get())
|
---|
71 | {
|
---|
72 | remove_child(w2.get());
|
---|
73 | int nw=new_width-x2;
|
---|
74 | if (nw<0) nw=0;
|
---|
75 | w2->resize(nw, new_height);
|
---|
76 | add_child(x2+1,0, w2.get());
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | void i4_divider_class::get_drag_area(int &x1, int &y1, int &x2, int &y2)
|
---|
82 | {
|
---|
83 | w32 l,r,t,b;
|
---|
84 | style->get_out_deco_size(l,t,r,b);
|
---|
85 |
|
---|
86 | if (split_up_down)
|
---|
87 | {
|
---|
88 | int vbh=t+b;
|
---|
89 | y1=split_value-vbh/2;
|
---|
90 | y2=y1+vbh-1;
|
---|
91 | x1=0; x2=width()-1;
|
---|
92 | }
|
---|
93 | else
|
---|
94 | {
|
---|
95 | int vbw=l+r;
|
---|
96 | x1=split_value-vbw/2;
|
---|
97 | x2=x1+vbw-1;
|
---|
98 | y1=0;
|
---|
99 | y2=height()-1;
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | i4_divider_class::i4_divider_class(int w, int h,
|
---|
104 | i4_bool split_up_down,
|
---|
105 | int split_x_or_y,
|
---|
106 | i4_window_class *window1,
|
---|
107 | i4_window_class *window2,
|
---|
108 | i4_graphical_style_class *style,
|
---|
109 | int window1_min_size,
|
---|
110 | int window2_min_size)
|
---|
111 | : split_up_down(split_up_down),
|
---|
112 | split_value(split_x_or_y),
|
---|
113 | style(style),
|
---|
114 | i4_parent_window_class(w,h),
|
---|
115 | min1(window1_min_size),
|
---|
116 | min2(window2_min_size)
|
---|
117 | {
|
---|
118 | w1=window1;
|
---|
119 | w2=window2;
|
---|
120 |
|
---|
121 | if (w==-1)
|
---|
122 | {
|
---|
123 | w_attached=i4_T;
|
---|
124 | w=0;
|
---|
125 | }
|
---|
126 | else
|
---|
127 | w_attached=i4_F;
|
---|
128 |
|
---|
129 | if (h==-1)
|
---|
130 | {
|
---|
131 | h=0;
|
---|
132 | h_attached=i4_T;
|
---|
133 | }
|
---|
134 | else
|
---|
135 | h_attached=i4_F;
|
---|
136 |
|
---|
137 |
|
---|
138 | dragging=i4_F;
|
---|
139 | if (split_x_or_y==-1)
|
---|
140 | {
|
---|
141 | if (split_up_down)
|
---|
142 | split_value=h/2;
|
---|
143 | else
|
---|
144 | split_value=w/2;
|
---|
145 | }
|
---|
146 |
|
---|
147 | w1=window1;
|
---|
148 | w2=window2;
|
---|
149 |
|
---|
150 | add_child(0,0, window1);
|
---|
151 | add_child(0,0, window2);
|
---|
152 | resize(w,h);
|
---|
153 | }
|
---|
154 |
|
---|
155 |
|
---|
156 | void i4_divider_class::parent_draw(i4_draw_context_class &context)
|
---|
157 | {
|
---|
158 | int x1,y1,x2,y2;
|
---|
159 | get_drag_area(x1,y1,x2,y2);
|
---|
160 | local_image->add_dirty(x1,y1,x2,y2, context);
|
---|
161 | style->draw_out_deco(local_image, x1,y1, x2,y2, i4_F, context);
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | void i4_divider_class::receive_event(i4_event *ev)
|
---|
166 | {
|
---|
167 | switch (ev->type())
|
---|
168 | {
|
---|
169 | case i4_event::MOUSE_BUTTON_DOWN :
|
---|
170 | {
|
---|
171 | CAST_PTR(bev, i4_mouse_button_down_event_class, ev);
|
---|
172 | if (bev->left())
|
---|
173 | {
|
---|
174 | int x1,y1,x2,y2;
|
---|
175 | get_drag_area(x1,y1,x2,y2);
|
---|
176 | if (bev->x>=x1 && bev->x<=x2 &&
|
---|
177 | bev->y>=y1 && bev->y<=y2)
|
---|
178 | {
|
---|
179 | dragging=i4_T;
|
---|
180 | i4_window_request_mouse_grab_class grab(this);
|
---|
181 | i4_kernel.send_event(parent, &grab);
|
---|
182 | }
|
---|
183 | else i4_parent_window_class::receive_event(ev);
|
---|
184 | }
|
---|
185 | else i4_parent_window_class::receive_event(ev);
|
---|
186 | } break;
|
---|
187 |
|
---|
188 |
|
---|
189 | case i4_event::MOUSE_BUTTON_UP :
|
---|
190 | {
|
---|
191 | CAST_PTR(bev, i4_mouse_button_up_event_class, ev);
|
---|
192 | if (dragging && bev->left())
|
---|
193 | {
|
---|
194 | dragging=i4_F;
|
---|
195 | i4_window_request_mouse_ungrab_class ungrab(this);
|
---|
196 | i4_kernel.send_event(parent, &ungrab);
|
---|
197 | }
|
---|
198 | else i4_parent_window_class::receive_event(ev);
|
---|
199 | } break;
|
---|
200 |
|
---|
201 | case i4_event::MOUSE_MOVE :
|
---|
202 | {
|
---|
203 | CAST_PTR(mev, i4_mouse_move_event_class, ev);
|
---|
204 | if (dragging)
|
---|
205 | {
|
---|
206 | if (split_up_down)
|
---|
207 | {
|
---|
208 | if (mev->y!=split_value && mev->y>min1 && height()-mev->y>min2)
|
---|
209 | {
|
---|
210 | split_value=mev->y;
|
---|
211 | resize(width(), height());
|
---|
212 | }
|
---|
213 | }
|
---|
214 | else if (mev->y!=split_value && mev->x>min1 && width()-mev->x>min2)
|
---|
215 | {
|
---|
216 | split_value=mev->x;
|
---|
217 | resize(width(), height());
|
---|
218 | }
|
---|
219 | }
|
---|
220 | else i4_parent_window_class::receive_event(ev);
|
---|
221 | } break;
|
---|
222 |
|
---|
223 | default:
|
---|
224 | i4_parent_window_class::receive_event(ev);
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 |
|
---|
231 |
|
---|