PLplot: wxwidgets.h Source File

PLplot 5.15.0

wxwidgets.h
Go to the documentation of this file.
1 // Copyright (C) 2008 Werner Smekal
2 //
3 // This file is part of PLplot.
4 //
5 // PLplot is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Library General Public License as published
7 // by the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // PLplot is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Library General Public License for more details.
14 //
15 // You should have received a copy of the GNU Library General Public License
16 // along with PLplot; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19
20 #ifndef __WXWIDGETS_H__
21 #define __WXWIDGETS_H__
22
23 #include <vector>
24 #include <memory>
25
26 // some special wxWidgets headers
27 //We need to include these before wxwidgets_comms.h
28 // - it seems like the includion of windows.h in
29 // wxwidgets_comms.h before wx/wx.h causes some
30 // wierd interation with winsock functions for
31 // vs2017.
32 #include <wx/wx.h>
33 #include <wx/spinctrl.h>
34 #include <wx/dcgraph.h>
35
36 // plplot headers
37 #include "plplotP.h"
38 #include "wxwidgets_comms.h"
39
40 class wxPLplotFrame;
41
42 // A font class which encapsulates the PLplot font metrics and
43 // a wxFont object. Importantly however the creation of the
44 // wxFont is delayed until it is actually requested. This is
45 // useful because on Linux in wxWidgets 3.0 creation of a wxFont
46 // in a console mode application caused a crash.
47 class Font
48 {
49 public:
50 Font();
51 Font( PLUNICODE fci, PLFLT size, bool underlined, bool createFontOnConstruction = false );
52 wxFont getWxFont();
53 PLUNICODE getFci() const { return m_fci; }
54 PLFLT getSize() const { return m_size; }
55 bool getUnderlined() const { return m_underlined; }
56 private:
57 void createFont();
58 wxFont m_font;
59 PLUNICODE m_fci;
60 PLFLT m_size;
61 bool m_underlined;
62 bool m_hasFont;
63 };
64 //check equivalence of two fonts. Note that a font created
65 //with the default constructor always compares false to any
66 //other font and that whether the wxFont has been created is
67 //not included in the test.
68 bool operator ==( const Font &lhs, const Font &rhs );
69
70 class FontGrabber
71 {
72 public:
73 FontGrabber();
74 Font GetFont( PLUNICODE fci, PLFLT scaledFontSize, bool underlined );
75 bool lastWasCached( ){ return m_lastWasCached; }
76 private:
77 Font m_prevFont;
78 bool m_lastWasCached;
79 };
80
81 class PlDevice
82 {
83 public:
84 PlDevice();
85 virtual ~PlDevice() {}
86 virtual void DrawLine( short x1a, short y1a, short x2a, short y2a ) {}
87 virtual void DrawPolyline( short *xa, short *ya, PLINT npts ){}
88 virtual void ClearBackground( PLStream* pls, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 ){}
89 virtual void FillPolygon( PLStream *pls ){}
90 virtual void SetWidth( PLStream *pls ){}
91 virtual void SetColor( PLStream *pls ){}
92 virtual void SetDC( PLStream *pls, wxDC* dc ){}
93 virtual void EndPage( PLStream* pls ){}
94 virtual void BeginPage( PLStream* pls ){}
95 virtual void SetSize( PLStream* pls, int width, int height ){}
96 virtual void FixAspectRatio( bool fix ){}
97 virtual void Locate( PLStream* pls, PLGraphicsIn *graphicsIn ){}
98 virtual void Flush( PLStream* pls ){}
99 virtual void PreDestructorTidy( PLStream *pls ){}
100 virtual void SetXorMode( bool on ){}
101
102 void drawText( PLStream* pls, EscText* args );
103 private:
104 void DrawTextLine( PLUNICODE* ucs4, int ucs4Len, wxCoord xOrigin, wxCoord yOrigin, wxCoord x, wxCoord y, PLFLT *transform, PLFLT baseFontSize, bool drawText, bool &underlined, PLUNICODE &fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord &textWidth, wxCoord &textHeight, wxCoord &textDepth );
105 virtual void DrawTextSection( wxString section, wxCoord xOrigin, wxCoord yOrigin, wxCoord x, wxCoord y, PLFLT *transform, PLFLT scaledFontSize, bool drawText, bool underlined, PLUNICODE fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, PLFLT &yScale, wxCoord &sectionWidth, wxCoord &sectionHeight, wxCoord &sectionDepth ) {}
106
107 PLUNICODE m_prevSymbol;
108 PLFLT m_prevBaseFontSize;
109 PLINT m_prevLevel;
110 PLUNICODE m_prevFci;
111 wxCoord m_prevSymbolWidth;
112 wxCoord m_prevSymbolHeight;
113 wxCoord m_prevSymbolDepth;
114 };
115
116 // base device class
117 class wxPLDevice : public PlDevice
118 {
119 public:
120 wxPLDevice( PLStream *pls, char * mfo, PLINT text, PLINT hrshsym );
121 virtual ~wxPLDevice( void );
122
123 void DrawLine( short x1a, short y1a, short x2a, short y2a );
124 void DrawPolyline( short *xa, short *ya, PLINT npts );
125 void ClearBackground( PLStream* pls, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 );
126 void FillPolygon( PLStream *pls );
127 void SetWidth( PLStream *pls );
128 void SetColor( PLStream *pls );
129 void SetXorMode( bool on );
130 void SetDC( PLStream *pls, wxDC* dc );
131 void EndPage( PLStream* pls );
132 void BeginPage( PLStream* pls );
133 void SetSize( PLStream* pls, int width, int height );
134 void FixAspectRatio( bool fix );
135 void Locate( PLStream* pls, PLGraphicsIn *graphicsIn );
136 void Flush( PLStream* pls );
137 void PreDestructorTidy( PLStream *pls );
138
139 private:
140 void DrawTextSection( wxString section, wxCoord xOrigin, wxCoord yOrigin, wxCoord x, wxCoord y, PLFLT *transform, PLFLT scaledFontSize, bool drawText, bool underlined, PLUNICODE fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, PLFLT &yScale, wxCoord &sectionWidth, wxCoord &sectionHeight, wxCoord &sectionDepth );
141 void TransmitBuffer( PLStream* pls, unsigned char transmissionType );
142 void SetupMemoryMap();
143 wxRegion GetClipRegion();
144
145 //The DC we will draw on if given by the user
146 wxDC *m_dc;
147 bool m_useDcTextTransform;
148 //for the gcdc case we may need to store the graphics context for use
149 // with text transformations
150 wxGraphicsContext *m_gc;
151 wxPen m_pen;
152 wxBrush m_brush;
153
154 //A device context specifically for checking the size of text for use with
155 //the interactive viewer.
156 wxImage m_interactiveTextImage;
157 wxGCDC *m_interactiveTextGcdc;
158
159 //Size and Scale
160 //As far as plplot is concerned the size of the window is SHRT_MAX by
161 //SHRT_MAX which gives us the best resolution.
162 const PLFLT m_plplotEdgeLength;
163 PLFLT m_width; //native width
164 PLFLT m_height; //native height
165 PLFLT m_xScale; //conversion from native width to plplotEdgeLength
166 PLFLT m_yScale; //conversion from native height to plplotEdgeLength
167 PLFLT m_xAspect; //values which when multiplied by m_plplotEdgeLength give an aspect
168 PLFLT m_yAspect; //ratio equal to the native aspect ratio, the biggest of which is 1.0
169 PLFLT m_scale; //MAX(m_scalex, m_scaley)
170 bool m_fixedAspect;
171
172 // font variables
173 static const int m_max_string_length = 500;
174 //bool m_underlined;
175 FontGrabber m_fontGrabber;
176 //wxCoord m_textWidth, m_textHeight, m_textDescent, m_textLeading;
177 //PLUNICODE m_fci;
178
179 //Text positioning related variables
180 //wxCoord m_superscriptHeight; //distance between superscript top and baseline
181 //wxCoord m_subscriptDepth; //distance between subscript base and baseline
182 PLFLT m_lineSpacing;
183 //PLFLT m_yOffset;
184 //PLINT m_posX;
185 //PLINT m_posY;
186 //PLFLT m_rotation;
187
188 //variables for dealing with sending/receiving commands
189 //via a memory map
190 char m_mfo[PLPLOT_MAX_PATH];
191 #ifdef PL_WXWIDGETS_IPC3
192 // Private variable to hold all components of a MemoryMapHeader struct for a wxPLDevice instance.
193 MemoryMapHeader m_header;
194 #else
195 PLNamedMutex m_mutex;
196 #endif
197 size_t m_localBufferPosition;
198 PLMemoryMap m_outputMemoryMap;
199 };
200
201
202 struct dev_entry
203 {
204 wxString dev_name;
205 wxString dev_menu_short;
206 wxString dev_menu_long;
207 wxString dev_file_app;
208 bool pixelDevice;
209 };
210
211 //--------------------------------------------------------------------------
212 // Declarations for the device.
213 //--------------------------------------------------------------------------
214
215 void plD_init_wxwidgets( PLStream * );
216 void plD_init_wxpng( PLStream * );
217 void plD_line_wxwidgets( PLStream *, short, short, short, short );
218 void plD_polyline_wxwidgets( PLStream *, short *, short *, PLINT );
219 void plD_eop_wxwidgets( PLStream * );
220 void plD_wait_wxwidgets( PLStream * );
221 void plD_bop_wxwidgets( PLStream * );
222 void plD_tidy_wxwidgets( PLStream * );
223 void plD_state_wxwidgets( PLStream *, PLINT );
224 void plD_esc_wxwidgets( PLStream *, PLINT, void * );
225
226 void wx_set_dc( PLStream* pls, wxDC* dc );
227 void wx_set_buffer( PLStream* pls, wxImage* buffer );
228
229 //--------------------------------------------------------------------------
230 // Debug functions
231 //--------------------------------------------------------------------------
232
233 // define if you want debug output
234 // #define _DEBUG //
235 // #define _DEBUG_VERBOSE //
236 void Log_Verbose( const char *fmt, ... );
237 void Log_Debug( const char *fmt, ... );
238
239
240 //--------------------------------------------------------------------------
241 // Font style and weight lookup tables
242 //--------------------------------------------------------------------------
243 const wxFontFamily fontFamilyLookup[5] = {
244 wxFONTFAMILY_SWISS, // sans-serif
245 wxFONTFAMILY_ROMAN, // serif
246 wxFONTFAMILY_TELETYPE, // monospace
247 wxFONTFAMILY_SCRIPT, // script
248 wxFONTFAMILY_SWISS // symbol
249 };
250
251 const int fontStyleLookup[3] = {
252 wxFONTSTYLE_NORMAL, // upright
253 wxFONTSTYLE_ITALIC, // italic
254 wxFONTSTYLE_SLANT // oblique
255 };
256
257 const int fontWeightLookup[2] = {
258 wxFONTWEIGHT_NORMAL, // medium
259 wxFONTWEIGHT_BOLD // bold
260 };
261
262 #endif // __WXWIDGETS_H__
wxPLDevice::m_interactiveTextGcdc
wxGCDC * m_interactiveTextGcdc
Definition: wxwidgets.h:157
plplotP.h
dev_entry::pixelDevice
bool pixelDevice
Definition: wxwidgets.h:208
wxPLDevice::m_plplotEdgeLength
const PLFLT m_plplotEdgeLength
Definition: wxwidgets.h:162
operator==
bool operator==(const Font &lhs, const Font &rhs)
Definition: wxwidgets_dev.cpp:753
wxPLDevice::m_interactiveTextImage
wxImage m_interactiveTextImage
Definition: wxwidgets.h:156
fontWeightLookup
const int fontWeightLookup[2]
Definition: wxwidgets.h:257
plD_line_wxwidgets
void plD_line_wxwidgets(PLStream *, short, short, short, short)
Definition: wxwidgets.cpp:285
PlDevice::FillPolygon
virtual void FillPolygon(PLStream *pls)
Definition: wxwidgets.h:89
wxwidgets_comms.h
dev_entry
Definition: wxwidgets.h:202
Font::getFci
PLUNICODE getFci() const
Definition: wxwidgets.h:53
Font
Definition: wxwidgets.h:47
plD_state_wxwidgets
void plD_state_wxwidgets(PLStream *, PLINT)
Definition: wxwidgets.cpp:463
plD_polyline_wxwidgets
void plD_polyline_wxwidgets(PLStream *, short *, short *, PLINT)
Definition: wxwidgets.cpp:313
wxPLDevice::m_yAspect
PLFLT m_yAspect
Definition: wxwidgets.h:168
fontStyleLookup
const int fontStyleLookup[3]
Definition: wxwidgets.h:251
PLUNICODE
PLUINT PLUNICODE
Definition: plplot.h:201
PlDevice
Definition: wxwidgets.h:81
Font::m_fci
PLUNICODE m_fci
Definition: wxwidgets.h:59
PlDevice::m_prevFci
PLUNICODE m_prevFci
Definition: wxwidgets.h:110
PlDevice::m_prevBaseFontSize
PLFLT m_prevBaseFontSize
Definition: wxwidgets.h:108
wxPLDevice::m_fixedAspect
bool m_fixedAspect
Definition: wxwidgets.h:170
Font::getWxFont
wxFont getWxFont()
Definition: wxwidgets_dev.cpp:746
PlDevice::BeginPage
virtual void BeginPage(PLStream *pls)
Definition: wxwidgets.h:94
PlDevice::m_prevLevel
PLINT m_prevLevel
Definition: wxwidgets.h:109
wxPLDevice::m_useDcTextTransform
bool m_useDcTextTransform
Definition: wxwidgets.h:147
wxPLDevice::m_brush
wxBrush m_brush
Definition: wxwidgets.h:152
wx_set_buffer
void wx_set_buffer(PLStream *pls, wxImage *buffer)
Font::createFont
void createFont()
Definition: wxwidgets_dev.cpp:728
PlDevice::DrawPolyline
virtual void DrawPolyline(short *xa, short *ya, PLINT npts)
Definition: wxwidgets.h:87
wxPLDevice::m_lineSpacing
PLFLT m_lineSpacing
Definition: wxwidgets.h:182
plD_eop_wxwidgets
void plD_eop_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:343
PLPLOT_MAX_PATH
#define PLPLOT_MAX_PATH
Definition: plplotP.h:446
PlDevice::DrawTextSection
virtual void DrawTextSection(wxString section, wxCoord xOrigin, wxCoord yOrigin, wxCoord x, wxCoord y, PLFLT *transform, PLFLT scaledFontSize, bool drawText, bool underlined, PLUNICODE fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, PLFLT &yScale, wxCoord &sectionWidth, wxCoord &sectionHeight, wxCoord &sectionDepth)
Definition: wxwidgets.h:105
FontGrabber::m_lastWasCached
bool m_lastWasCached
Definition: wxwidgets.h:78
PlDevice::SetDC
virtual void SetDC(PLStream *pls, wxDC *dc)
Definition: wxwidgets.h:92
PLINT
int PLINT
Definition: plplot.h:181
PlDevice::PreDestructorTidy
virtual void PreDestructorTidy(PLStream *pls)
Definition: wxwidgets.h:99
FontGrabber::lastWasCached
bool lastWasCached()
Definition: wxwidgets.h:75
wxPLDevice::m_pen
wxPen m_pen
Definition: wxwidgets.h:151
wxPLDevice::m_height
PLFLT m_height
Definition: wxwidgets.h:164
FontGrabber::m_prevFont
Font m_prevFont
Definition: wxwidgets.h:77
wxPLDevice::m_localBufferPosition
size_t m_localBufferPosition
Definition: wxwidgets.h:197
wxPLDevice::m_width
PLFLT m_width
Definition: wxwidgets.h:163
EscText
Definition: plplotP.h:699
wxPLDevice::m_xScale
PLFLT m_xScale
Definition: wxwidgets.h:165
dev_entry::dev_file_app
wxString dev_file_app
Definition: wxwidgets.h:207
Font::getUnderlined
bool getUnderlined() const
Definition: wxwidgets.h:55
PlDevice::~PlDevice
virtual ~PlDevice()
Definition: wxwidgets.h:85
PlDevice::EndPage
virtual void EndPage(PLStream *pls)
Definition: wxwidgets.h:93
wxPLDevice::m_dc
wxDC * m_dc
Definition: wxwidgets.h:146
PLNamedMutex
Definition: wxwidgets_comms.h:222
PlDevice::SetColor
virtual void SetColor(PLStream *pls)
Definition: wxwidgets.h:91
plD_tidy_wxwidgets
void plD_tidy_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:429
wx_set_dc
void wx_set_dc(PLStream *pls, wxDC *dc)
fontFamilyLookup
const wxFontFamily fontFamilyLookup[5]
Definition: wxwidgets.h:243
buffer
static PLINT * buffer
Definition: plfill.c:74
Log_Verbose
void Log_Verbose(const char *fmt,...)
Definition: wxwidgets.cpp:56
Log_Debug
void Log_Debug(const char *fmt,...)
Definition: wxwidgets.cpp:77
PLMemoryMap
Definition: wxwidgets_comms.h:182
dev_entry::dev_menu_short
wxString dev_menu_short
Definition: wxwidgets.h:205
wxPLDevice::m_xAspect
PLFLT m_xAspect
Definition: wxwidgets.h:167
pls
static PLStream * pls[PL_NSTREAMS]
Definition: plcore.h:88
Font::getSize
PLFLT getSize() const
Definition: wxwidgets.h:54
Font::m_underlined
bool m_underlined
Definition: wxwidgets.h:61
wxPLDevice::m_yScale
PLFLT m_yScale
Definition: wxwidgets.h:166
PlDevice::SetWidth
virtual void SetWidth(PLStream *pls)
Definition: wxwidgets.h:90
wxPLDevice::m_scale
PLFLT m_scale
Definition: wxwidgets.h:169
MemoryMapHeader
Definition: wxwidgets_comms.h:71
dev_entry::dev_name
wxString dev_name
Definition: wxwidgets.h:204
PlDevice::Locate
virtual void Locate(PLStream *pls, PLGraphicsIn *graphicsIn)
Definition: wxwidgets.h:97
PLStream
Definition: plstrm.h:523
text
static int text
Definition: ps.c:77
wxPLDevice::m_mutex
PLNamedMutex m_mutex
Definition: wxwidgets.h:195
dev_entry::dev_menu_long
wxString dev_menu_long
Definition: wxwidgets.h:206
Font::m_font
wxFont m_font
Definition: wxwidgets.h:58
PLFLT
float PLFLT
Definition: plplot.h:163
Font::m_hasFont
bool m_hasFont
Definition: wxwidgets.h:62
Font::Font
Font()
Definition: wxwidgets_dev.cpp:710
PlDevice::SetSize
virtual void SetSize(PLStream *pls, int width, int height)
Definition: wxwidgets.h:95
PlDevice::Flush
virtual void Flush(PLStream *pls)
Definition: wxwidgets.h:98
PlDevice::FixAspectRatio
virtual void FixAspectRatio(bool fix)
Definition: wxwidgets.h:96
plD_init_wxwidgets
void plD_init_wxwidgets(PLStream *)
plD_bop_wxwidgets
void plD_bop_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:403
plD_init_wxpng
void plD_init_wxpng(PLStream *)
wxPLDevice
Definition: wxwidgets.h:117
PlDevice::SetXorMode
virtual void SetXorMode(bool on)
Definition: wxwidgets.h:100
PlDevice::m_prevSymbolHeight
wxCoord m_prevSymbolHeight
Definition: wxwidgets.h:112
hrshsym
static int hrshsym
Definition: ps.c:79
PlDevice::DrawLine
virtual void DrawLine(short x1a, short y1a, short x2a, short y2a)
Definition: wxwidgets.h:86
plD_esc_wxwidgets
void plD_esc_wxwidgets(PLStream *, PLINT, void *)
Definition: wxwidgets.cpp:504
plD_wait_wxwidgets
void plD_wait_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:373
wxPLDevice::m_outputMemoryMap
PLMemoryMap m_outputMemoryMap
Definition: wxwidgets.h:198
PlDevice::m_prevSymbol
PLUNICODE m_prevSymbol
Definition: wxwidgets.h:107
PlDevice::m_prevSymbolWidth
wxCoord m_prevSymbolWidth
Definition: wxwidgets.h:111
FontGrabber
Definition: wxwidgets.h:70
wxPLDevice::m_fontGrabber
FontGrabber m_fontGrabber
Definition: wxwidgets.h:175
PlDevice::m_prevSymbolDepth
wxCoord m_prevSymbolDepth
Definition: wxwidgets.h:113
Font::m_size
PLFLT m_size
Definition: wxwidgets.h:60
PlDevice::ClearBackground
virtual void ClearBackground(PLStream *pls, PLINT x1=-1, PLINT y1=-1, PLINT x2=-1, PLINT y2=-1)
Definition: wxwidgets.h:88
wxPLDevice::m_gc
wxGraphicsContext * m_gc
Definition: wxwidgets.h:150
PLGraphicsIn
Definition: plplot.h:433