]> git.decadent.org.uk Git - ion3.git/blob - ioncore/presize.c
Imported Upstream version 20090110
[ion3.git] / ioncore / presize.c
1 /*
2  * ion/ioncore/presize.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2009. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include "presize.h"
10 #include "resize.h"
11 #include "window.h"
12 #include "pointer.h"
13 #include "grab.h"
14
15
16 /*{{{ Resize */
17
18
19 static int p_dx1mul=0, p_dx2mul=0, p_dy1mul=0, p_dy2mul=0;
20
21
22 #define MINCORNER 16
23
24
25 void window_p_resize_prepare(WWindow *wwin, XButtonEvent *ev)
26 {
27     int ww=REGION_GEOM(wwin).w/2;
28     int hh=REGION_GEOM(wwin).h/2;
29     int xdiv, ydiv;
30     int tmpx, tmpy, atmpx, atmpy;
31
32     p_dx1mul=0;
33     p_dx2mul=0;
34     p_dy1mul=0;
35     p_dy2mul=0;
36     
37     tmpx=ev->x-ww;
38     tmpy=hh-ev->y;
39     xdiv=ww/2;
40     ydiv=hh/2;
41     atmpx=abs(tmpx);
42     atmpy=abs(tmpy);
43     
44     if(xdiv<MINCORNER && xdiv>1){
45         xdiv=ww-MINCORNER;
46         if(xdiv<1)
47             xdiv=1;
48     }
49     
50     if(ydiv<MINCORNER && ydiv>1){
51         ydiv=hh-MINCORNER;
52         if(ydiv<1)
53             ydiv=1;
54     }
55     
56     if(xdiv==0){
57         p_dx2mul=1;
58     }else if(hh*atmpx/xdiv>=tmpy && -hh*atmpx/xdiv<=tmpy){
59         p_dx1mul=(tmpx<0);
60         p_dx2mul=(tmpx>=0);
61     }
62     
63     if(ydiv==0){
64         p_dy2mul=1;
65     }else if(ww*atmpy/ydiv>=tmpx && -ww*atmpy/ydiv<=tmpx){
66         p_dy1mul=(tmpy>0);
67         p_dy2mul=(tmpy<=0);
68     }
69 }
70
71
72 static void p_moveres_end(WWindow *wwin, XButtonEvent *ev)
73 {
74     WMoveresMode *mode=moveres_mode((WRegion*)wwin);
75     if(mode!=NULL)
76         moveresmode_do_end(mode, TRUE);
77 }
78
79
80 static void p_moveres_cancel(WWindow *wwin)
81 {
82     WMoveresMode *mode=moveres_mode((WRegion*)wwin);
83     if(mode!=NULL)
84         moveresmode_do_end(mode, FALSE);
85 }
86
87
88 static void confine_to_parent(WWindow *wwin)
89 {
90     WRegion *par=REGION_PARENT_REG(wwin);
91     if(par!=NULL)
92         ioncore_grab_confine_to(region_xwindow(par));
93 }
94
95
96 static void p_resize_motion(WWindow *wwin, XMotionEvent *ev, int dx, int dy)
97 {
98     WMoveresMode *mode=moveres_mode((WRegion*)wwin);
99     if(mode!=NULL){
100         moveresmode_delta_resize(mode, p_dx1mul*dx, p_dx2mul*dx,
101                                  p_dy1mul*dy, p_dy2mul*dy, NULL);
102     }
103 }
104
105
106 static void p_resize_begin(WWindow *wwin, XMotionEvent *ev, int dx, int dy)
107 {
108     region_begin_resize((WRegion*)wwin, NULL, TRUE);
109     p_resize_motion(wwin, ev, dx, dy);
110 }
111
112
113 /*EXTL_DOC
114  * Start resizing \var{wwin} with the mouse or other pointing device.
115  * This function should only be used by binding it to \emph{mpress} or
116  * \emph{mdrag} action.
117  */
118 EXTL_EXPORT_MEMBER
119 void window_p_resize(WWindow *wwin)
120 {
121     if(!ioncore_set_drag_handlers((WRegion*)wwin,
122                                   (WMotionHandler*)p_resize_begin,
123                                   (WMotionHandler*)p_resize_motion,
124                                   (WButtonHandler*)p_moveres_end,
125                                   NULL, 
126                                   (GrabKilledHandler*)p_moveres_cancel))
127         return;
128     
129     confine_to_parent(wwin);
130 }
131
132
133 /*}}}*/
134
135
136 /*{{{ Move */
137
138
139 static void p_move_motion(WWindow *wwin, XMotionEvent *ev, int dx, int dy)
140 {
141     WMoveresMode *mode=moveres_mode((WRegion*)wwin);
142     if(mode!=NULL)
143         moveresmode_delta_move(mode, dx, dy, NULL);
144 }
145
146
147 static void p_move_begin(WWindow *wwin, XMotionEvent *ev, int dx, int dy)
148 {
149     region_begin_move((WRegion*)wwin, NULL, TRUE);
150     p_move_motion(wwin, ev, dx, dy);
151 }
152
153
154 /*EXTL_DOC
155  * Start moving \var{wwin} with the mouse or other pointing device.
156  * This function should only be used by binding it to \emph{mpress} or
157  * \emph{mdrag} action.
158  */
159 EXTL_EXPORT_MEMBER
160 void window_p_move(WWindow *wwin)
161 {
162     if(!ioncore_set_drag_handlers((WRegion*)wwin,
163                                   (WMotionHandler*)p_move_begin,
164                                   (WMotionHandler*)p_move_motion,
165                                   (WButtonHandler*)p_moveres_end,
166                                   NULL, 
167                                   (GrabKilledHandler*)p_moveres_cancel))
168         return;
169     
170     confine_to_parent(wwin);
171 }
172
173
174 /*}}}*/