"Fossies" - the Fresh Open Source Software Archive 
Member "xosview-1.23/xwin.h" (11 Jul 2020, 6407 Bytes) of package /linux/misc/xosview-1.23.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "xwin.h" see the
Fossies "Dox" file reference documentation.
1 #ifndef _XWIN_H_
2 #define _XWIN_H_
3
4 #include "Xrm.h"
5 #include <string.h>
6 #include <X11/Xlib.h>
7 #include <X11/Xutil.h>
8 #include <iostream>
9
10 class XWin;
11
12 typedef void (XWin::*EventCallBack)( XEvent &event );
13
14
15 class XWin {
16 public:
17 XWin ();
18 XWin( int argc, char *argv[], int x, int y, int width, int height );
19 //XWin( int& argc, char *argv[], char *geometry );
20 virtual ~XWin( void );
21 void XWinInit ( int argc, char* argv[], char* geometry, Xrm* xrmp );
22
23 int width( void ) { return width_; }
24 void width( int val ) { width_ = val; }
25 int height( void ) { return height_; }
26 void height( int val ) { height_ = val; }
27 Display *display( void ) { return display_; }
28 Window window( void ) { return window_; }
29 int done( void ) { return done_; }
30 void done( int val ) { done_ = val; }
31 void title( const char *str ) { XStoreName( display_, window_, str ); }
32 void iconname( const char *str ) { XSetIconName( display_, window_, str ); }
33
34 void clear( void ) { XClearWindow( display_, window_ ); }
35 void clear( int x, int y, int width, int height )
36 { XClearArea( display_, window_, x, y, width, height, False ); }
37 unsigned long allocColor( const char *name );
38 void setForeground( unsigned long pixelvalue )
39 { XSetForeground( display_, gc_, pixelvalue ); }
40 void setBackground( unsigned long pixelvalue )
41 { XSetBackground( display_, gc_, pixelvalue ); }
42 void setStipple( Pixmap stipple)
43 { if (!doStippling_) return;
44 XSetStipple(display_, gc_, stipple);
45 XGCValues xgcv;
46 xgcv.fill_style = FillOpaqueStippled;
47 XChangeGC (display_, gc_, GCFillStyle, &xgcv); }
48 void setStippleN (int n) {setStipple(stipples_[n]); }
49 Pixmap createPixmap(const char* data, unsigned int w, unsigned int h) {
50 return XCreatePixmapFromBitmapData(display_, window_,
51 const_cast<char *>(data), w, h, 0, 1, 1); }
52
53 unsigned long foreground( void ) { return fgcolor_; }
54 unsigned long background( void ) { return bgcolor_; }
55 void resize( int width, int height )
56 { XResizeWindow( display_, window_, width, height ); }
57 void lineWidth( int width )
58 {
59 XGCValues xgcv;
60 xgcv.line_width = width;
61 XChangeGC( display_, gc_, GCLineWidth, &xgcv );
62 }
63 void drawLine( int x1, int y1, int x2, int y2 )
64 { XDrawLine( display_, window_, gc_, x1, y1, x2, y2 ); }
65 void drawRectangle( int x, int y, int width, int height )
66 { XDrawRectangle( display_, window_, gc_, x, y, width, height ); }
67 void drawFilledRectangle( int x, int y, int width, int height )
68 { XFillRectangle( display_, window_, gc_, x, y, width + 1, height + 1 ); }
69 void drawString( int x, int y, const char *str )
70 { XDrawString( display_, window_, gc_, x, y, str, strlen( str ) ); }
71 void copyArea( int src_x, int src_y, int width, int height, int dest_x, int dest_y )
72 { XCopyArea( display_, window_, window_, gc_, src_x, src_y, width, height, dest_x, dest_y ); }
73 int textWidth( const char *str, int n )
74 { return XTextWidth( font_, str, n ); }
75 int textWidth( const char *str )
76 { return textWidth( str, strlen( str ) ); }
77 int textAscent( void ) { return font_->ascent; }
78 int textDescent( void ) { return font_->descent; }
79 int textHeight( void ) { return textAscent() + textDescent(); }
80
81
82 virtual void checkevent( void );
83 void map( void ) { XMapWindow( display_, window_ ); }
84 void unmap( void ) { XUnmapWindow( display_, window_ ); }
85 void flush( void ) { XFlush( display_ ); }
86
87 const char *getResource( const char *name );
88 const char *getResourceOrUseDefault( const char *name, const char* defaultVal );
89 int isResourceTrue( const char* name ) {
90 return (!strncasecmp(getResource(name),"True", 5)); }
91 void dumpResources(std::ostream &os );
92
93 protected:
94 class Event {
95 public:
96 Event( XWin *parent, int event, EventCallBack callBack );
97 virtual ~Event( void ){}
98
99 friend class XWin;
100
101 void callBack( XEvent &event )
102 { if ( event.type == event_ ) (parent_->*callBack_)( event ); }
103
104 protected:
105 XWin *parent_;
106 EventCallBack callBack_;
107 int event_;
108 long mask_;
109 private:
110 Event *next_;
111 };
112
113 int borderwidth_; // width of border
114 int x_, y_; // position of the window
115 int width_, height_; // width and height of the window
116 Display *display_; // Connection to X display
117 Window window_; // Application's main window
118 GC gc_; // The graphics context for the window
119 XFontStruct *font_; // Info on the default font
120 char *name_; // Application's name
121 XTextProperty title_; // Window name for title bar
122 XTextProperty iconname_; // Icon name for icon label
123 unsigned long fgcolor_; // Foreground color of the window
124 unsigned long bgcolor_; // Background color of the window
125 XWindowAttributes attr_; // Attributes of the window
126 XWMHints *wmhints_; // Hints for the window manager
127 XSizeHints *sizehints_; // Size hints for window manager
128 XClassHint *classhints_; // Class hint for window manager
129 Event *events_; // List of Events for this window
130 int done_; // If true the application is finished.
131 Atom wm_, wmdelete_; // Used to handle delete Events
132 Colormap colormap_; // The colormap
133 char display_name_[256]; // Display name string.
134 char* geometry_; // geometry string.
135 Xrm* xrmptr_; // Pointer to the XOSView xrm. FIXME???
136 int doStippling_; // Either 0 or 1.
137 Pixmap stipples_[4]; // Array of Stipple masks.
138
139 void init( int argc, char *argv[] );
140 void getGeometry( void );
141 int getPixmap(Pixmap *);
142 void setDisplayName (const char* new_display_name) { strncpy
143 (display_name_, new_display_name, 256); }
144 const char* displayName () { return display_name_; }
145
146 void addEvent( Event *event );
147 void setColors( void );
148 void openDisplay( void );
149 void setHints( int argc, char *argv[] );
150 void setFont( void );
151 void selectEvents( long mask );
152 void ignoreEvents( long mask );
153 void configureEvent( XEvent &event );
154 void mappingNotify( XEvent &event )
155 { XRefreshKeyboardMapping( &event.xmapping ); }
156 void deleteEvent( XEvent &event );
157 //void usage( void );
158 Colormap colormap( void ) { return colormap_; }
159 int screen( void ) { return DefaultScreen( display_ ); }
160 private:
161 };
162
163 #endif