Debian Codegraph @

xo/lwindow.h

raw
1 /* lwindow.h -*- C++ -*-
2 $Id: lwindow.h,v 1.18 1997/10/23 06:56:16 elf Exp $
3
4 written by Marc Singer
5 8 May 1997
6
7 This file is part of the project XO. See the file README for
8 more information.
9
10 Copyright (C) 1997 Marc Singer
11
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 in a file called COPYING along with this program; if not, write to
24 the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
25 02139, USA.
26
27 -----------
28 DESCRIPTION
29 -----------
30
31 */
32
33 #if !defined (__LWINDOW_H__)
34 # define __LWINDOW_H__
35
36 /* ----- Includes */
37
38 #include <memory.h>
39 #include <stdint.h>
40 #include "messages.h"
41
42 enum {
43 windowTypeNormal = 0,
44 windowTypeDesktop,
45 windowTypeDock,
46 windowTypeToolbar,
47 windowTypeMenu,
48 windowTypeUtility,
49 windowTypeSplash,
50 windowTypeDialog,
51 };
52
53 class LDisplay;
54
55 class LWindow;
56
57 typedef void (LWindow::*PFNEvent)(XEvent* pEvent);
58 typedef struct {
59 int event_type;
60 PFNEvent pfn;
61 } EventMap;
62
63
64 class LWindow {
65 protected:
66 // -- X Attributes
67 LDisplay* m_pDisplay; // X display where window is displayed
68 Window m_window; // X window handle
69 // long m_event_mask; // X event mask, cached
70 XSetWindowAttributes m_attr; // X window creation attributes
71 unsigned long m_maskAttr; // X attribute mask for creation
72 short m_x, m_y; // Origin
73 short m_width, m_height; // and extent
74 bool m_fOrigin; // true: window origin specied
75 bool m_fExtent; // true: window extent specied
76
77 // -- Properties for X Windows Window Managers
78 char* m_szXName;
79 char* m_szXClass;
80
81 // -- Relationship
82 int32_t m_id; // Generic ID
83 LWindow* m_pWindowParent; // Enclosing window, NULL for top-level
84 LWindow* m_pWindowOwner; // Notification target
85 void* m_pvOwner; // Owner's context pointer
86 LWindow* m_pWindowSibling; // Lateral link
87 LWindow* m_pWindowChild; // Leaf directed link
88
89 // -- Local Attributes
90 char* m_szName; // Window name or content
91 // void* m_pvInstance; // Instance data
92 int m_cbInstance; // Size of window class structure
93
94 // -- Event/Notification Handling
95 EventMap* m_pEventMap;
96 PFNEvent m_pfnNotify; // Object-local notification receipt function
97
98 public:
99 // -- Object creation
100 LWindow (LDisplay* pDisplay) {
101 zero (); init (pDisplay); }
102 LWindow (LWindow* pWindow) {
103 zero (); init (pWindow); }
104 virtual ~LWindow () {
105 release_this (); }
106 void init (LDisplay* pDisplay) {
107 m_pDisplay = pDisplay; }
108 void init (LWindow* pWindow); // Clone
109 void release_this (void);
110 void zero (void) {
111 memset (this, 0, sizeof (*this)); }
112
113 // -- X-Windows methods
114 bool create (LWindow* pWindowParent);
115 void map (void);
116 void unmap (void) {
117 m_window ? XUnmapWindow (m_pDisplay->display (), m_window) : 0; }
118
119 // -- Configuration methods
120 void event_map (EventMap* pEventMap) {
121 m_pEventMap = pEventMap; }
122 void extent (int width, int height) {
123 m_width = width; m_height = height; m_fExtent = true; }
124 // void* instance (void* pv) {
125 // void* pvPrev = m_pvInstance; m_pvInstance = pv; return pvPrev; }
126 void id (int id) {
127 m_id = id; }
128 void notify (PFNEvent pfn) {
129 m_pfnNotify = pfn; }
130 void owner (LWindow* pWindow, void* pv) {
131 m_pWindowOwner = pWindow;
132 m_pvOwner = pv; }
133 void owner (LWindow* pWindow, int32_t v) {
134 m_pWindowOwner = pWindow;
135 m_pvOwner = (void*) (intptr_t (v)); }
136 void geometry (const char* sz);
137 void origin (int x, int y) {
138 m_x = x; m_y = y; }
139 void position (int x, int y, int width, int height) {
140 m_x = x; m_y = y; m_width = width; m_height = height; }
141 void qualify (const char* szXName, const char* szXClass);
142 void text (const char* sz);
143 void lower (void);
144
145 // -- Access methods
146 LDisplay* display (void) {
147 return m_pDisplay; }
148 EventMap* event_map (void) {
149 return m_pEventMap; }
150 LWindow* find_child (int id) {
151 return m_pWindowChild
152 ? m_pWindowChild->find_sibling (id)
153 : (LWindow*) NULL; }
154 LWindow* find_sibling (int id);
155 int height (void) {
156 return m_height; }
157 // void* instance (void) {
158 // return m_pvInstance; }
159 int32_t id (void) {
160 return m_id; }
161 LWindow* owner (void) {
162 return m_pWindowOwner; }
163 void* owner_data (void) {
164 return m_pvOwner; }
165 const char* text (void) {
166 return m_szName; }
167 int width (void) {
168 return m_width; }
169 Window window (void) {
170 return m_window; }
171 Display* xdisplay (void) {
172 return m_pDisplay->display (); }
173 Visual* xvisual (void) {
174 return m_pDisplay->visual (); }
175
176 // -- Event control
177 void add_events (long event_mask) {
178 m_attr.event_mask |= event_mask;
179 m_window ? XSelectInput (m_pDisplay->display (),
180 m_window, m_attr.event_mask) : 0; }
181 PFNEvent find_event (int event_type, XEvent* event);
182 void ignore_events (long event_mask) {
183 m_attr.event_mask &= ~event_mask;
184 m_window ? XSelectInput (m_pDisplay->display (),
185 m_window, m_attr.event_mask) : 0; }
186 void notify (int child_event) {
187 notify (child_event, 0, NULL); }
188 void notify (int child_event, int cArgs, int* rgArgs);
189 void select_events (long event_mask) {
190 m_attr.event_mask = event_mask;
191 m_window ? XSelectInput (m_pDisplay->display (),
192 m_window, m_attr.event_mask) : 0; }
193
194 // -- Attribute methods
195 void set_background_pixel (unsigned long pixel) {
196 m_attr.background_pixel = pixel;
197 m_maskAttr |= CWBackPixel; }
198 void set_bit_gravity (int gravity) {
199 m_attr.bit_gravity = gravity;
200 m_maskAttr |= CWBitGravity; }
201 void set_override_redirect (bool f) {
202 m_attr.override_redirect = f;
203 m_maskAttr |= CWOverrideRedirect; }
204 void transient_for (LWindow* pWindow);
205 void net_window_type (int);
206
207 virtual void handle_expose (XExposeEvent* pEvent) {}
208 virtual void handle_buttonpress (XButtonEvent* pEvent) {}
209 virtual void handle_configure (XConfigureEvent* pEvent) {}
210 virtual void handle_resizerequest (XResizeRequestEvent* pEvent) {
211 m_width = pEvent->width; m_height = pEvent->height;
212 XWindowChanges changes;
213 changes.width = m_width;
214 changes.height = m_height;
215 printf ("configuring to %d %d\n", m_width, m_height);
216 // XConfigureWindow (display ()->display (),
217 // window (), CWWidth | CWHeight, &changes);
218 XResizeWindow (display ()->display (), window (), m_width, m_height);
219 }
220
221 };
222
223 /* ----- Globals */
224
225
226
227
228 #endif /* __LWINDOW_H__ */