Debian Codegraph @

xo/ldisplay.h

raw ◀ ▶
1 Debian patch touch this file
1 /* ldisplay.h -*- C++ -*-
2 $Id: ldisplay.h,v 1.17 1998/10/26 18:59:11 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 NOTES
28 -----
29
30 - GC
31
32 It is *very* desirable to cache graphics contexts. It is also
33 desirable to avoid creating loads of GCs when a program starts
34 up. So, what we do is create a default GC per VISUAL.
35 Presently, we do nothing with visuals/screens, so this translates
36 to one GC per LDisplay. Eventually, we need to create one per
37 VISUAL. The idea is that most drawing can be done by fetching
38 this default GC, making the necessary changes to the graphics
39 state, and then performing drawing. But, we do something sneaky
40 here. We really create two GCs. One stores the default drawing
41 state, and the other is given to drawables to use. Before
42 handing a drawable the GC, we copy the attributes from the
43 default settings one. This way, we can simulate attribute
44 save/restore.
45
46 */
47
48 #if !defined (__LDISPLAY_H__)
49 # define __LDISPLAY_H__
50
51 /* ----- Includes */
52
53 #include "lhash.h"
54 #include "lfont.h"
55 #include <memory.h>
56
57 /* ----- Globals */
58
59
60 class LWindow;
61
62 typedef struct {
63 LWindow* pWindow; // Child window sending the notification
64 int id; // Child window ID, if there is one
65 int event; // What the child has done
66 unsigned long data[4]; // Extra data the child may want to send
67 } ChildNotifyInfo;
68
69
70 class LDisplay {
71 protected:
72 Display* m_pDisplay;
73
74 // -- Display Attributes
75 int m_cbitPadding; // Scanlines padded to this number of bits
76 int m_cbitUnit; // Bitmap row unit quant
77 int (*m_pfnAfter) (Display*); // User's after function
78
79 // -- Visual Attributes
80 Visual* m_pVisual; // We only support one visual right now
81 int m_visual_class; // Requested class
82 XVisualInfo m_visualInfo;
83 int m_shiftRed;
84 int m_shiftGreen;
85 int m_shiftBlue;
86 int m_depth; // Visual's bit depth
87 Colormap m_colormap;
88
89 // -- Drawing Contexts
90 GC m_gcAttribute; // Cached attribute GC (see NOTES)
91 GC m_gcDraw; // Cached drawing GC (see NOTES)
92
93 // -- X Resources
94 XrmDatabase m_database;
95 LFontCache m_font_cache; // Cache of font names to IDs
96
97 // -- Windows
98 LWindow* m_pWindowRoot; // Link to windows created at the root
99 LHashTable m_hashWindow; // Window->LWindow*
100 LHashTable m_hashTemplate; // "windowclass"->LWindow*
101
102 public:
103 LDisplay () {
104 zero (); }
105 ~LDisplay () {
106 release_this (); }
107 void zero (void) {
108 memset (this, 0, sizeof (*this)); }
109
110 void release_this (void);
111
112 unsigned long color_distance (XColor& color, XColor& colorMatch);
113 void dispatch_next_event (void);
•114 void dispatch_next_event_timeout (long usec);
115 void dispatch (XEvent* pEvent);
116 Colormap colormap (void) {
117 return m_colormap; }
118 int height (void) {
119 return XDisplayHeight (m_pDisplay, 0); }
120 int width (void) {
121 return XDisplayWidth (m_pDisplay, 0); }
122 int depth (void) {
123 return m_depth; }
124 Display* display (void) {
125 return m_pDisplay; }
126 bool is_pending_event (void) {
127 return m_pDisplay ? (XPending (m_pDisplay) != 0) : false; }
128 int pad (void) {
129 return m_cbitPadding; }
130 Visual* visual (void) {
131 return m_pVisual; }
132 XFontStruct* find_font (char* szFont) {
133 return m_font_cache.find (szFont); }
134 XFontStruct* find_font (Font fid) {
135 return m_font_cache.find (fid); }
136 LWindow* find_child (int id);
137 bool find_resource (const char* szName, const char* szClass, char** pszType,
138 XrmValue* pValue) {
139 char* szType = NULL;
140 pValue->addr = 0; // For the callers who don't check return
141 return m_database
142 ? ( XrmGetResource (m_database, szName, szClass,
143 pszType ? pszType : &szType, pValue) != False)
144 : False; }
145 bool find_pixel (char* szColorName, unsigned long* pPixel);
146 LWindow* find_template (const char* szTemplate);
147 LWindow* find_window (Window window);
148 void flush (void) {
149 m_pDisplay ? XFlush (m_pDisplay) : 0; }
150 GC gc (void);
151 void hash_window (LWindow* pWindow);
152 bool hash_template (const char* szTemplate, LWindow* pWindow);
153 void next_event (XEvent* pEvent) {
154 m_pDisplay ? XNextEvent (m_pDisplay, pEvent) : 0; }
•155 bool next_event_timeout (XEvent* pEvent, long usec);
156 bool open (char* szDisplay = NULL);
157 void unhash_window (LWindow* pWindow);
158
159 LWindow** root_windows (void) {
160 return &m_pWindowRoot; }
161
162 int shift_red (void) {
163 return m_shiftRed; }
164 int shift_green (void) {
165 return m_shiftGreen; }
166 int shift_blue (void) {
167 return m_shiftBlue; }
168
169 void set_after_function (int (*pfn)(Display*)) {
170 m_pfnAfter = pfn; XSetAfterFunction (m_pDisplay, pfn); }
171 void set_visual_class (int visual_class) {
172 m_visual_class = visual_class; }
173 };
174
175
176
177 #endif /* __LDISPLAY_H__ */