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.1 $
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.1 2002-07-25 08:01:27 arjen
27 First checkin, AXE release 0.2
29 *****************************/
31 static const char *RCSID = "$Id: xwindow.cpp,v 1.1 2002-07-25 08:01:27 arjen Exp $";
33 #include "xappl.h" /* Includes xwindow.h */
38 /*=========================================================================
51 **=========================================================================
54 window::window(int x, int y, unsigned int _w, unsigned int _h, int bw)
62 win_id = XCreateSimpleWindow(stddpy.Dpy(), stddpy.Root(),
64 stddpy.Black(), stddpy.White());
68 XApp->add_window(win_id, this);
72 /*=========================================================================
85 **=========================================================================
88 window::window(window &parentw, int x, int y,
89 unsigned int _w, unsigned int _h, int bw)
96 parentw.add_child(this);
98 win_id = XCreateSimpleWindow(stddpy.Dpy(), parentw.win_id,
100 stddpy.Black(), stddpy.White());
104 XApp->add_window(win_id, this);
108 /*=========================================================================
121 **=========================================================================
128 parent->remove_child(this);
131 XDestroyWindow(stddpy.Dpy(), win_id);
133 XApp->remove_window(win_id);
138 /*=========================================================================
139 ** NAME : add_child - Add subwindow in the list
151 **=========================================================================
154 void window::add_child(window *ch)
165 /*=========================================================================
166 ** NAME : remove_child - Remove subwindow from the list
178 **=========================================================================
181 void window::remove_child(window *ch)
183 win_list *l = 0, *prev = 0;
186 while (l && l->child != ch)
192 // If l would be NULL, the child window would not be in
193 // it's parent's list of children. This can not happen !
197 prev->next = l->next;
207 /*=========================================================================
209 ** SYNOPSIS : int window::EV_Expose(XExposeEvent ev)
211 ** RETURN VALUE : 0 if the application should quit
213 ** DESCRIPTION : Event handling functions.
214 ** Most of the event handling functions are empty.
215 ** Derived classes of window should override these functions
216 ** to implement speecific behavior.
223 **=========================================================================
226 int window::EV_Expose(XExposeEvent ev)
231 int window::EV_NoExpose(XNoExposeEvent ev)
236 int window::EV_KeyPress(XKeyEvent ev)
241 int window::EV_KeyRelease(XKeyEvent ev)
246 int window::EV_ButtonPress(XButtonEvent ev)
251 int window::EV_ButtonRelease(XButtonEvent ev)
256 int window::EV_MotionNotify(XMotionEvent ev)
261 int window::EV_EnterNotify(XCrossingEvent ev)
266 int window::EV_LeaveNotify(XCrossingEvent ev)
271 int window::EV_FocusIn(XFocusChangeEvent ev)
276 int window::EV_FocusOut(XFocusChangeEvent ev)
282 /*=========================================================================
283 ** NAME : EV_ConfigureNotify - Handle Configure event
288 ** DESCRIPTION : Handles the event where the window is moved relative
289 ** to its parent, resized or restacked.
290 ** The default handler calls ParentResized for all of its
291 ** children. The subwindows usually react by fitting their
292 ** size to the size of the parent.
298 ** LAST MODIFIED : Feb 10, 1998
299 **=========================================================================
302 int window::EV_ConfigureNotify(XConfigureEvent ev)
309 for (l = children; l; l = l->next)
311 l->child->ParentResized(ev.width, ev.height);
316 int window::EV_ClientMessage(XClientMessageEvent ev)
321 int window::ParentResized(int w, int h)
328 /* Event names. Used in "type" field in XEvent structures. Not to be
329 confused with event masks above. They start from 2 because 0 and 1
330 are reserved in the protocol for errors and replies. */
332 static char * event_names[] =
371 int window::EV_Default(XEvent ev)
376 void window::ChildMessage(win_message &msg)
380 void window::ParentMessage(int id)
388 parent->ChildMessage(msg);
391 void window::Resize(unsigned width, unsigned height)
396 XResizeWindow(stddpy.Dpy(), win_id, w, h);
399 void window::Resize(size sz)
404 XResizeWindow(stddpy.Dpy(), win_id, w, h);
407 void window::Move(int x, int y)
409 XMoveWindow(stddpy, win_id, x, y);
412 /*=========================================================================
414 ** SYNOPSIS : void window::Background(unsigned long pixel)
418 ** DESCRIPTION : Set the pixel value of the window's background color
425 **=========================================================================
428 void window::Background(unsigned long pixel)
430 XSetWindowAttributes attrib;
432 attrib.background_pixel = pixel;
433 XChangeWindowAttributes(stddpy.Dpy(), win_id, CWBackPixel, &attrib);
436 void window::WindowGravity(int gravity)
438 XSetWindowAttributes attrib;
440 attrib.win_gravity = gravity;
441 XChangeWindowAttributes(stddpy.Dpy(), win_id, CWWinGravity, &attrib);
444 void window::Clear(void)
446 XClearWindow(stddpy.Dpy(), win_id);
449 /*=========================================================================
450 ** NAME : SelectInput - Turn events on or off.
451 ** SYNOPSIS : long window::SelectInput(long events, int on)
452 ** PARAMETERS : events : Bitwise OR of event masks
453 ** on : 0 - Events off; 1 - Events on
454 ** RETURN VALUE : The new event selection mask
463 **=========================================================================
466 long window::SelectInput(long events, int on)
470 selection_mask |= events;
474 selection_mask &= ~events;
477 XSelectInput(stddpy.Dpy(), win_id, selection_mask);
479 return selection_mask;
482 int window::GrabPointer(Cursor curs)
486 status = XGrabPointer(stddpy, win_id, True,
487 ButtonPressMask|ButtonReleaseMask|EnterWindowMask|LeaveWindowMask,
488 GrabModeAsync, GrabModeAsync, None, curs, CurrentTime);
494 int window::UngrabPointer(void)
498 status = XUngrabPointer(stddpy, CurrentTime);
504 int managed_window::EV_FocusIn(XFocusChangeEvent ev)
511 int managed_window::EV_ClientMessage(XClientMessageEvent ev)
513 if (ev.message_type == XInternAtom(stddpy, "WM_PROTOCOLS", True))
515 if (ev.data.l[0] == XInternAtom(stddpy, "WM_DELETE_WINDOW", True))
517 return XApp->SendCommand(WM_Delete_Command);