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