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