2 Copyright (C) 1996 Scott W. Sadler
10 03-Mar-96 1.0; Scott W. Sadler (ssadler@cisco.com)
17 #include <X11/cursorfont.h>
18 #include "XsResizeOutline.h"
22 Cursor XsResizeOutline::_cursors[XsResizeOutline::NumCursors];
23 int XsResizeOutline::_mutex = 0;
27 XsResizeOutline::XsResizeOutline (Widget w, int direction) : XsOutline (w)
34 _direction = direction;
36 // Translate current window location to root coordinates
40 XtTranslateCoords (XtParent (_w), (Position)_x, (Position)_y, &xpos, &ypos);
45 // Save the original window position and size
55 // Create the cursors (if necessary)
59 Display *dpy = XtDisplay (_w);
63 _cursors[TopCursor] = XCreateFontCursor (dpy, XC_top_side);
64 _cursors[BottomCursor] = XCreateFontCursor (dpy, XC_bottom_side);
65 _cursors[LeftCursor] = XCreateFontCursor (dpy, XC_left_side);
66 _cursors[RightCursor] = XCreateFontCursor (dpy, XC_right_side);
67 _cursors[TopLeftCursor] = XCreateFontCursor (dpy, XC_top_left_corner);
68 _cursors[TopRightCursor] = XCreateFontCursor (dpy, XC_top_right_corner);
69 _cursors[BottomLeftCursor] = XCreateFontCursor (dpy, XC_bottom_left_corner);
70 _cursors[BottomRightCursor] = XCreateFontCursor (dpy, XC_bottom_right_corner);
71 _cursors[Fleur] = XCreateFontCursor (dpy, XC_fleur);
78 XsResizeOutline::~XsResizeOutline ( )
85 void XsResizeOutline::setMinSize (int minWidth, int minHeight)
87 assert (minWidth > 0);
88 assert (minHeight > 0);
91 _minHeight = minHeight;
96 void XsResizeOutline::_motionHandler (XEvent *event)
102 // Get current mouse position
104 curX = event->xbutton.x_root;
105 curY = event->xbutton.y_root;
107 if (_direction & Undetermined)
111 Just let the mouse roam around until it crosses the outline.
112 When it does so, lock in the direction, change the cursor, and let
116 if (((curX <= _origRootX) || (curX >= (_origRootX + _origW)))
117 || ((curY <= _origRootY) || (curY >= (_origRootY + _origH))))
120 const int CornerOffset = 30;
122 // Crossed box. Figure out where and set direction
126 if (curY <= (_origRootY + CornerOffset))
128 else if (curY >= (_origRootY + _origH - CornerOffset))
131 if (curX <= (_origRootX + CornerOffset))
133 else if (curX >= (_origRootX + _origW - CornerOffset))
136 // Get the new cursor
138 XChangeActivePointerGrab (XtDisplay (_w), GrabEventMask,
139 _getCursor ( ), CurrentTime);
145 // Get the current values
147 x = _x; y = _y; w = _width; h = _height;
149 // Process the motion
153 if (curY < (_origRootY + _origH - 1 - _minHeight))
155 diff = _rootY - curY;
158 _height = _origRootY + _origH - curY;
162 _rootY = _origRootY + _origH - 1 - _minHeight;
163 _y = _origY + _origH - 1 - _minHeight;
164 _height = _minHeight;
167 else if (_direction & Down)
169 if (curY > (_origRootY + _minHeight))
170 _height = curY - _origRootY - 1;
172 _height = _minHeight;
175 if (_direction & Left)
177 if (curX < (_origRootX + _origW - 1 - _minWidth))
179 diff = _rootX - curX;
182 _width = _origRootX + _origW - curX;
186 _rootX = _origRootX + _origW - 1 - _minWidth;
187 _x = _origX + _origW - 1 - _minWidth;
191 else if (_direction & Right)
193 if (curX > (_origRootX + _minWidth))
194 _width = curX - _origRootX - 1;
199 // Check if the values have "really" changed
201 if ((w != _width) || (h != _height) || (x != _x) || (y != _y))
202 _drawOutline (False);
207 Cursor XsResizeOutline::_getCursor ( ) const
209 if (_direction == Up)
210 return (_cursors[TopCursor]);
211 if (_direction == Down)
212 return (_cursors[BottomCursor]);
213 if (_direction == Left)
214 return (_cursors[LeftCursor]);
215 if (_direction == Right)
216 return (_cursors[RightCursor]);
217 if (_direction == (Up | Left))
218 return (_cursors[TopLeftCursor]);
219 if (_direction == (Up | Right))
220 return (_cursors[TopRightCursor]);
221 if (_direction == (Down | Left))
222 return (_cursors[BottomLeftCursor]);
223 if (_direction == (Down | Right))
224 return (_cursors[BottomRightCursor]);
225 if (_direction == Undetermined)
226 return (_cursors[Fleur]);