1 /**************************************************************************
2 ** (c) Copyright 1998, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 ** FILE NAME : xwindow.h
7 ** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
8 ** VERSION NUMBER : $Revision: 1.1 $
10 ** DESCRIPTION : Definition of the window class
12 ** EXPORTED OBJECTS : class window
15 ***************************************************************************
16 ** ADMINISTRATIVE INFORMATION *
17 ********************************
18 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 ** CREATION DATE : Feb 06, 1998
20 ** LAST UPDATE : Jul 28, 2000
22 **************************************************************************/
24 /*****************************
26 Revision 1.1 2002-07-25 08:01:27 arjen
27 First checkin, AXE release 0.2
29 *****************************/
31 /* static const char *RCSID = "$Id: xwindow.h,v 1.1 2002-07-25 08:01:27 arjen Exp $"; */
43 #define GrabPointerMask (1L << 25)
46 ///////////////////////////////////////////////////////////////////////////
49 // MEMBERS : win_id : X server id of the window
50 // children : Linked list of child windows.
51 // parent : The parent window (0 if main window)
52 // selection_mask : Mask of selected events.
56 // DESCRIPTION : A window object encapsulates a window on the X workstation.
57 // A window is a rectangular area on the screen, used
58 // for graphical output. Input from mouse and keyboard
59 // is handled by event-handling functions in a window.
62 // SEE ALSO : xapplication
63 // LAST MODIFIED : Feb 13, 1998
64 ///////////////////////////////////////////////////////////////////////////
86 unsigned w, h; // Size of the window
90 void add_child(window *ch);
91 void remove_child(window *ch);
107 virtual int EV_Expose(XExposeEvent);
108 virtual int EV_NoExpose(XNoExposeEvent);
109 virtual int EV_KeyPress(XKeyEvent);
110 virtual int EV_KeyRelease(XKeyEvent);
111 virtual int EV_ButtonPress(XButtonEvent);
112 virtual int EV_ButtonRelease(XButtonEvent);
113 virtual int EV_MotionNotify(XMotionEvent);
114 virtual int EV_EnterNotify(XCrossingEvent);
115 virtual int EV_LeaveNotify(XCrossingEvent);
116 virtual int EV_FocusIn(XFocusChangeEvent);
117 virtual int EV_FocusOut(XFocusChangeEvent);
118 virtual int EV_ConfigureNotify(XConfigureEvent);
119 virtual int EV_ClientMessage(XClientMessageEvent);
121 virtual int ParentResized(int w, int h);
123 virtual void ChildMessage(win_message &msg);
125 void ParentMessage(int id);
127 int EV_Default(XEvent);
129 window(int x=0, int y=0, unsigned w=320, unsigned h=256, int bw = 4);
130 window(window &, int x=0, int y=0,
131 unsigned int w=100, unsigned int h=100, int bw = 1);
134 // Mapping and unmapping
138 XMapWindow(stddpy.Dpy(), win_id);
143 XMapSubwindows(stddpy, win_id);
144 XMapRaised(stddpy, win_id);
149 XUnmapWindow(stddpy.Dpy(), win_id);
154 void Size(unsigned &width, unsigned &height)
165 void Resize(unsigned width, unsigned height);
166 void Resize(size sz);
167 void Move(int x, int y);
169 // Border and background
171 void Border(unsigned int borderwidth)
173 XSetWindowBorderWidth(stddpy, win_id, borderwidth);
176 void Background(unsigned long pixel);
177 void WindowGravity(int gravity);
180 long SelectInput(long events, int on);
181 long SelectInput(void)
183 return selection_mask;
188 XSetInputFocus(stddpy, win_id, RevertToPointerRoot, CurrentTime);
191 int GrabPointer(Cursor curs);
192 int UngrabPointer(void);
193 void DefineCursor(Cursor curs)
195 XDefineCursor(stddpy, ID(), curs);
197 void UndefineCursor(void)
199 XUndefineCursor(stddpy, ID());
202 // Graphic drawing functions
204 void DrawString(const gc &graphic, int x, int y, String str) const
206 XDrawString(stddpy, win_id, graphic, x, y, str, ~str);
209 void DrawString(const gc &graphic, point p, String str) const
211 XDrawString(stddpy, win_id, graphic, p.x, p.y, str, ~str);
214 void DrawLine(const gc &graphic, int x1, int y1, int x2, int y2) const
216 XDrawLine(stddpy, win_id, graphic, x1, y1, x2, y2);
219 void DrawLine(const gc &graphic, point p1, point p2) const
221 XDrawLine(stddpy, win_id, graphic, p1.x, p1.y, p2.x, p2.y);
224 void DrawLine(const gc &graphic, std::vector<point> &l, int mode = CoordModeOrigin) const
226 int npoints = l.size();
227 XPoint *points = new XPoint[npoints];
229 for (int i = 0; i < npoints; i++)
231 points[i].x = l[i].x;
232 points[i].y = l[i].y;
235 XDrawLines(stddpy, win_id, graphic, points, npoints, mode);
238 void FillPolygon(const gc &graphic, std::vector<point> &l,
239 int mode = CoordModeOrigin, int shape = Complex) const
241 int npoints = l.size();
242 XPoint *points = new XPoint[npoints];
244 for (int i = 0; i < npoints; i++)
246 points[i].x = l[i].x;
247 points[i].y = l[i].y;
250 XFillPolygon(stddpy, win_id, graphic, points, npoints, shape, mode);
253 void DrawRectangle(const gc &graphic, point p, size s) const
255 XDrawRectangle(stddpy, win_id, graphic, p.x, p.y, s.w, s.h);
258 void DrawRectangle(const gc &graphic, int x, int y, unsigned w, unsigned h) const
260 XDrawRectangle(stddpy, win_id, graphic, x, y, w, h);
263 void DrawRectangle(const gc &graphic, rectangle r) const
265 DrawRectangle(graphic, r.Origin(), r.Size());
268 void DrawRectangle(const gc &graphic, point p1, point p2) const
270 DrawRectangle(graphic, rectangle(p1, p2));
273 void FillRectangle(const gc &graphic, point p, size s) const
275 XFillRectangle(stddpy, win_id, graphic, p.x, p.y, s.w, s.h);
278 void FillRectangle(const gc &graphic, int x, int y, unsigned w, unsigned h) const
280 XFillRectangle(stddpy, win_id, graphic, x, y, w, h);
283 void FillRectangle(const gc &graphic, rectangle r) const
285 FillRectangle(graphic, r.Origin(), r.Size());
288 void FillRectangle(const gc &graphic, point p1, point p2) const
290 FillRectangle(graphic, rectangle(p1, p2));
293 void DrawArc(const gc &graphic, int x, int y, unsigned w, unsigned h,
294 int angle1, int angle2) const
296 XDrawArc(stddpy, win_id, graphic, x, y, w, h, angle1, angle2);
299 void FillArc(const gc &graphic, int x, int y, unsigned w, unsigned h,
300 int angle1, int angle2) const
302 XFillArc(stddpy, win_id, graphic, x, y, w, h, angle1, angle2);
305 void DrawPixmap(const gc &graphic, int x, int y, const pixmap &pm) const
307 XCopyArea(stddpy, pm, win_id, graphic, 0, 0,
308 pm.Size().w, pm.Size().h, x, y);
312 class managed_window : public window
315 int WM_Delete_Command; // Command to send op 'close' button.
321 WM_Delete_Command = 0;
324 wm_delete = XInternAtom(stddpy, "WM_DELETE_WINDOW", true);
327 XStoreName(stddpy, ID(), "AXE Test");
329 XSetWMProtocols(stddpy, ID(),&wm_delete , 1);
331 SelectInput(StructureNotifyMask, 1);
332 SelectInput(FocusChangeMask, 1);
336 managed_window(char *name)
338 WM_Delete_Command = 0;
341 wm_delete = XInternAtom(stddpy, "WM_DELETE_WINDOW", true);
344 XStoreName(stddpy, ID(), name);
346 XSetWMProtocols(stddpy, ID(),&wm_delete , 1);
348 SelectInput(StructureNotifyMask, 1);
349 SelectInput(FocusChangeMask, 1);
353 void Title(char *name)
355 XStoreName(stddpy, ID(), name);
358 void Command_WhenClosed(int cmd)
360 WM_Delete_Command = cmd;
363 virtual int EV_FocusIn(XFocusChangeEvent);
364 virtual int EV_ClientMessage(XClientMessageEvent ev);
366 virtual int DoCommand(int code)
373 * Predefined message id's in a win_message
376 #define EDIT_ENTERED 1
377 #define EDIT_FOCUSLOST 2
378 #define SCROLL_POSITIONED 3
379 #define TABLE_ROW_SELECT 4
381 #endif /* AXE_XWINDOW_H */