1 /**************************************************************************
2 ** (c) Copyright 1998, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 ** FILE NAME : xwindow.cpp
7 ** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
8 ** VERSION NUMBER : $Revision: 1.2 $
10 ** DESCRIPTION : Implementation of the window class
15 ***************************************************************************
16 ** ADMINISTRATIVE INFORMATION *
17 ********************************
18 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 ** CREATION DATE : Feb 06, 1998
20 ** LAST UPDATE : Feb 09, 1998
22 **************************************************************************/
24 /*****************************
26 Revision 1.2 2002-09-26 14:50:54 arjen
27 Proper casting of event data in EV_ClientMessage()
29 Revision 1.1 2002/07/25 08:01:27 arjen
30 First checkin, AXE release 0.2
32 *****************************/
34 static const char *RCSID = "$Id: xwindow.cpp,v 1.2 2002-09-26 14:50:54 arjen Exp $";
36 #include "xappl.h" /* Includes xwindow.h */
41 /*=========================================================================
54 **=========================================================================
57 window::window(int x, int y, unsigned int _w, unsigned int _h, int bw)
65 win_id = XCreateSimpleWindow(stddpy.Dpy(), stddpy.Root(),
67 stddpy.Black(), stddpy.White());
71 XApp->add_window(win_id, this);
75 /*=========================================================================
88 **=========================================================================
91 window::window(window &parentw, int x, int y,
92 unsigned int _w, unsigned int _h, int bw)
99 parentw.add_child(this);
101 win_id = XCreateSimpleWindow(stddpy.Dpy(), parentw.win_id,
103 stddpy.Black(), stddpy.White());
107 XApp->add_window(win_id, this);
111 /*=========================================================================
124 **=========================================================================
131 parent->remove_child(this);
134 XDestroyWindow(stddpy.Dpy(), win_id);
136 XApp->remove_window(win_id);
141 /*=========================================================================
142 ** NAME : add_child - Add subwindow in the list
154 **=========================================================================
157 void window::add_child(window *ch)
168 /*=========================================================================
169 ** NAME : remove_child - Remove subwindow from the list
181 **=========================================================================
184 void window::remove_child(window *ch)
186 win_list *l = 0, *prev = 0;
189 while (l && l->child != ch)
195 // If l would be NULL, the child window would not be in
196 // it's parent's list of children. This can not happen !
200 prev->next = l->next;
210 /*=========================================================================
212 ** SYNOPSIS : int window::EV_Expose(XExposeEvent ev)
214 ** RETURN VALUE : 0 if the application should quit
216 ** DESCRIPTION : Event handling functions.
217 ** Most of the event handling functions are empty.
218 ** Derived classes of window should override these functions
219 ** to implement speecific behavior.
226 **=========================================================================
229 int window::EV_Expose(XExposeEvent ev)
234 int window::EV_NoExpose(XNoExposeEvent ev)
239 int window::EV_KeyPress(XKeyEvent ev)
244 int window::EV_KeyRelease(XKeyEvent ev)
249 int window::EV_ButtonPress(XButtonEvent ev)
254 int window::EV_ButtonRelease(XButtonEvent ev)
259 int window::EV_MotionNotify(XMotionEvent ev)
264 int window::EV_EnterNotify(XCrossingEvent ev)
269 int window::EV_LeaveNotify(XCrossingEvent ev)
274 int window::EV_FocusIn(XFocusChangeEvent ev)
279 int window::EV_FocusOut(XFocusChangeEvent ev)
285 /*=========================================================================
286 ** NAME : EV_ConfigureNotify - Handle Configure event
291 ** DESCRIPTION : Handles the event where the window is moved relative
292 ** to its parent, resized or restacked.
293 ** The default handler calls ParentResized for all of its
294 ** children. The subwindows usually react by fitting their
295 ** size to the size of the parent.
301 ** LAST MODIFIED : Feb 10, 1998
302 **=========================================================================
305 int window::EV_ConfigureNotify(XConfigureEvent ev)
312 for (l = children; l; l = l->next)
314 l->child->ParentResized(ev.width, ev.height);
319 int window::EV_ClientMessage(XClientMessageEvent ev)
324 int window::ParentResized(int w, int h)
331 /* Event names. Used in "type" field in XEvent structures. Not to be
332 confused with event masks above. They start from 2 because 0 and 1
333 are reserved in the protocol for errors and replies. */
335 static char * event_names[] =
374 int window::EV_Default(XEvent ev)
379 void window::ChildMessage(win_message &msg)
383 void window::ParentMessage(int id)
391 parent->ChildMessage(msg);
394 void window::Resize(unsigned width, unsigned height)
399 XResizeWindow(stddpy.Dpy(), win_id, w, h);
402 void window::Resize(size sz)
407 XResizeWindow(stddpy.Dpy(), win_id, w, h);
410 void window::Move(int x, int y)
412 XMoveWindow(stddpy, win_id, x, y);
415 /*=========================================================================
417 ** SYNOPSIS : void window::Background(unsigned long pixel)
421 ** DESCRIPTION : Set the pixel value of the window's background color
428 **=========================================================================
431 void window::Background(unsigned long pixel)
433 XSetWindowAttributes attrib;
435 attrib.background_pixel = pixel;
436 XChangeWindowAttributes(stddpy.Dpy(), win_id, CWBackPixel, &attrib);
439 void window::WindowGravity(int gravity)
441 XSetWindowAttributes attrib;
443 attrib.win_gravity = gravity;
444 XChangeWindowAttributes(stddpy.Dpy(), win_id, CWWinGravity, &attrib);
447 void window::Clear(void)
449 XClearWindow(stddpy.Dpy(), win_id);
452 /*=========================================================================
453 ** NAME : SelectInput - Turn events on or off.
454 ** SYNOPSIS : long window::SelectInput(long events, int on)
455 ** PARAMETERS : events : Bitwise OR of event masks
456 ** on : 0 - Events off; 1 - Events on
457 ** RETURN VALUE : The new event selection mask
466 **=========================================================================
469 long window::SelectInput(long events, int on)
473 selection_mask |= events;
477 selection_mask &= ~events;
480 XSelectInput(stddpy.Dpy(), win_id, selection_mask);
482 return selection_mask;
485 int window::GrabPointer(Cursor curs)
489 status = XGrabPointer(stddpy, win_id, True,
490 ButtonPressMask|ButtonReleaseMask|EnterWindowMask|LeaveWindowMask,
491 GrabModeAsync, GrabModeAsync, None, curs, CurrentTime);
497 int window::UngrabPointer(void)
501 status = XUngrabPointer(stddpy, CurrentTime);
507 int managed_window::EV_FocusIn(XFocusChangeEvent ev)
514 int managed_window::EV_ClientMessage(XClientMessageEvent ev)
516 if (ev.message_type == XInternAtom(stddpy, "WM_PROTOCOLS", True))
518 if ((Atom)ev.data.l[0] == XInternAtom(stddpy, "WM_DELETE_WINDOW", True))
520 return XApp->SendCommand(WM_Delete_Command);