Debian Codegraph @

xo/ldisplay.h

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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 (XEvent* pEvent);
115 Colormap colormap (void) {
116 return m_colormap; }
117 int height (void) {
118 return XDisplayHeight (m_pDisplay, 0); }
119 int width (void) {
120 return XDisplayWidth (m_pDisplay, 0); }
121 int depth (void) {
122 return m_depth; }
123 Display* display (void) {
124 return m_pDisplay; }
125 bool is_pending_event (void) {
126 return m_pDisplay ? (XPending (m_pDisplay) != 0) : false; }
127 int pad (void) {
128 return m_cbitPadding; }
129 Visual* visual (void) {
130 return m_pVisual; }
131 XFontStruct* find_font (char* szFont) {
132 return m_font_cache.find (szFont); }
133 XFontStruct* find_font (Font fid) {
134 return m_font_cache.find (fid); }
135 LWindow* find_child (int id);
136 bool find_resource (const char* szName, const char* szClass, char** pszType,
137 XrmValue* pValue) {
138 char* szType = NULL;
139 pValue->addr = 0; // For the callers who don't check return
140 return m_database
141 ? ( XrmGetResource (m_database, szName, szClass,
142 pszType ? pszType : &szType, pValue) != False)
143 : False; }
144 bool find_pixel (char* szColorName, unsigned long* pPixel);
145 LWindow* find_template (const char* szTemplate);
146 LWindow* find_window (Window window);
147 void flush (void) {
148 m_pDisplay ? XFlush (m_pDisplay) : 0; }
149 GC gc (void);
150 void hash_window (LWindow* pWindow);
151 bool hash_template (const char* szTemplate, LWindow* pWindow);
152 void next_event (XEvent* pEvent) {
153 m_pDisplay ? XNextEvent (m_pDisplay, pEvent) : 0; }
154 bool open (char* szDisplay = NULL);
155 void unhash_window (LWindow* pWindow);
156
157 LWindow** root_windows (void) {
158 return &m_pWindowRoot; }
159
160 int shift_red (void) {
161 return m_shiftRed; }
162 int shift_green (void) {
163 return m_shiftGreen; }
164 int shift_blue (void) {
165 return m_shiftBlue; }
166
167 void set_after_function (int (*pfn)(Display*)) {
168 m_pfnAfter = pfn; XSetAfterFunction (m_pDisplay, pfn); }
169 void set_visual_class (int visual_class) {
170 m_visual_class = visual_class; }
171 };
172
173
174
175 #endif /* __LDISPLAY_H__ */