ion->notion
[notion/jeffpc.git] / ioncore / presize.c
blob494cc5a814e93d9978d0077f100d2869ab0e1a31
1 /*
2 * ion/ioncore/presize.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include "presize.h"
10 #include "resize.h"
11 #include "window.h"
12 #include "pointer.h"
13 #include "grab.h"
16 /*{{{ Resize */
19 static int p_dx1mul=0, p_dx2mul=0, p_dy1mul=0, p_dy2mul=0;
22 #define MINCORNER 16
25 void window_p_resize_prepare(WWindow *wwin, XButtonEvent *ev)
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;
32 p_dx1mul=0;
33 p_dx2mul=0;
34 p_dy1mul=0;
35 p_dy2mul=0;
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);
44 if(xdiv<MINCORNER && xdiv>1){
45 xdiv=ww-MINCORNER;
46 if(xdiv<1)
47 xdiv=1;
50 if(ydiv<MINCORNER && ydiv>1){
51 ydiv=hh-MINCORNER;
52 if(ydiv<1)
53 ydiv=1;
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);
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);
72 static void p_moveres_end(WWindow *wwin, XButtonEvent *ev)
74 WMoveresMode *mode=moveres_mode((WRegion*)wwin);
75 if(mode!=NULL)
76 moveresmode_do_end(mode, TRUE);
80 static void p_moveres_cancel(WWindow *wwin)
82 WMoveresMode *mode=moveres_mode((WRegion*)wwin);
83 if(mode!=NULL)
84 moveresmode_do_end(mode, FALSE);
88 static void confine_to_parent(WWindow *wwin)
90 WRegion *par=REGION_PARENT_REG(wwin);
91 if(par!=NULL)
92 ioncore_grab_confine_to(region_xwindow(par));
96 static void p_resize_motion(WWindow *wwin, XMotionEvent *ev, int dx, int dy)
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);
106 static void p_resize_begin(WWindow *wwin, XMotionEvent *ev, int dx, int dy)
108 region_begin_resize((WRegion*)wwin, NULL, TRUE);
109 p_resize_motion(wwin, ev, dx, dy);
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.
118 EXTL_EXPORT_MEMBER
119 void window_p_resize(WWindow *wwin)
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;
129 confine_to_parent(wwin);
133 /*}}}*/
136 /*{{{ Move */
139 static void p_move_motion(WWindow *wwin, XMotionEvent *ev, int dx, int dy)
141 WMoveresMode *mode=moveres_mode((WRegion*)wwin);
142 if(mode!=NULL)
143 moveresmode_delta_move(mode, dx, dy, NULL);
147 static void p_move_begin(WWindow *wwin, XMotionEvent *ev, int dx, int dy)
149 region_begin_move((WRegion*)wwin, NULL, TRUE);
150 p_move_motion(wwin, ev, dx, dy);
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.
159 EXTL_EXPORT_MEMBER
160 void window_p_move(WWindow *wwin)
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;
170 confine_to_parent(wwin);
174 /*}}}*/