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;
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 
71 {
72 public:
73  FontGrabber();
74  Font GetFont( PLUNICODE fci, PLFLT scaledFontSize, bool underlined );
75  bool lastWasCached( ){ return m_lastWasCached; }
76 private:
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 
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;
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.
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.
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)
171 
172  // font variables
173  static const int m_max_string_length = 500;
174  //bool m_underlined;
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
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
196 #endif
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;
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 * );
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__
wxGCDC * m_interactiveTextGcdc
Definition: wxwidgets.h:157
bool pixelDevice
Definition: wxwidgets.h:208
const PLFLT m_plplotEdgeLength
Definition: wxwidgets.h:162
bool operator==(const Font &lhs, const Font &rhs)
wxImage m_interactiveTextImage
Definition: wxwidgets.h:156
const int fontWeightLookup[2]
Definition: wxwidgets.h:257
void plD_line_wxwidgets(PLStream *, short, short, short, short)
Definition: wxwidgets.cpp:285
virtual void FillPolygon(PLStream *pls)
Definition: wxwidgets.h:89
Definition: wxwidgets.h:202
PLUNICODE getFci() const
Definition: wxwidgets.h:53
Definition: wxwidgets.h:47
void plD_state_wxwidgets(PLStream *, PLINT)
Definition: wxwidgets.cpp:463
void plD_polyline_wxwidgets(PLStream *, short *, short *, PLINT)
Definition: wxwidgets.cpp:313
PLFLT m_yAspect
Definition: wxwidgets.h:168
const int fontStyleLookup[3]
Definition: wxwidgets.h:251
PLUINT PLUNICODE
Definition: plplot.h:201
PLUNICODE m_fci
Definition: wxwidgets.h:59
PLUNICODE m_prevFci
Definition: wxwidgets.h:110
PLFLT m_prevBaseFontSize
Definition: wxwidgets.h:108
bool m_fixedAspect
Definition: wxwidgets.h:170
wxFont getWxFont()
virtual void BeginPage(PLStream *pls)
Definition: wxwidgets.h:94
PLINT m_prevLevel
Definition: wxwidgets.h:109
bool m_useDcTextTransform
Definition: wxwidgets.h:147
wxBrush m_brush
Definition: wxwidgets.h:152
void wx_set_buffer(PLStream *pls, wxImage *buffer)
void createFont()
virtual void DrawPolyline(short *xa, short *ya, PLINT npts)
Definition: wxwidgets.h:87
PLFLT m_lineSpacing
Definition: wxwidgets.h:182
void plD_eop_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:343
#define PLPLOT_MAX_PATH
Definition: plplotP.h:446
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
bool m_lastWasCached
Definition: wxwidgets.h:78
virtual void SetDC(PLStream *pls, wxDC *dc)
Definition: wxwidgets.h:92
int PLINT
Definition: plplot.h:181
virtual void PreDestructorTidy(PLStream *pls)
Definition: wxwidgets.h:99
bool lastWasCached()
Definition: wxwidgets.h:75
wxPen m_pen
Definition: wxwidgets.h:151
PLFLT m_height
Definition: wxwidgets.h:164
Font m_prevFont
Definition: wxwidgets.h:77
size_t m_localBufferPosition
Definition: wxwidgets.h:197
PLFLT m_width
Definition: wxwidgets.h:163
PLFLT m_xScale
Definition: wxwidgets.h:165
wxString dev_file_app
Definition: wxwidgets.h:207
bool getUnderlined() const
Definition: wxwidgets.h:55
virtual ~PlDevice()
Definition: wxwidgets.h:85
virtual void EndPage(PLStream *pls)
Definition: wxwidgets.h:93
wxDC * m_dc
Definition: wxwidgets.h:146
virtual void SetColor(PLStream *pls)
Definition: wxwidgets.h:91
void plD_tidy_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:429
void wx_set_dc(PLStream *pls, wxDC *dc)
const wxFontFamily fontFamilyLookup[5]
Definition: wxwidgets.h:243
static PLINT * buffer
Definition: plfill.c:74
void Log_Verbose(const char *fmt,...)
Definition: wxwidgets.cpp:56
void Log_Debug(const char *fmt,...)
Definition: wxwidgets.cpp:77
wxString dev_menu_short
Definition: wxwidgets.h:205
PLFLT m_xAspect
Definition: wxwidgets.h:167
static PLStream * pls[PL_NSTREAMS]
Definition: plcore.h:88
PLFLT getSize() const
Definition: wxwidgets.h:54
bool m_underlined
Definition: wxwidgets.h:61
PLFLT m_yScale
Definition: wxwidgets.h:166
virtual void SetWidth(PLStream *pls)
Definition: wxwidgets.h:90
PLFLT m_scale
Definition: wxwidgets.h:169
wxString dev_name
Definition: wxwidgets.h:204
virtual void Locate(PLStream *pls, PLGraphicsIn *graphicsIn)
Definition: wxwidgets.h:97
static int text
Definition: ps.c:77
PLNamedMutex m_mutex
Definition: wxwidgets.h:195
wxString dev_menu_long
Definition: wxwidgets.h:206
wxFont m_font
Definition: wxwidgets.h:58
float PLFLT
Definition: plplot.h:163
bool m_hasFont
Definition: wxwidgets.h:62
virtual void SetSize(PLStream *pls, int width, int height)
Definition: wxwidgets.h:95
virtual void Flush(PLStream *pls)
Definition: wxwidgets.h:98
virtual void FixAspectRatio(bool fix)
Definition: wxwidgets.h:96
void plD_init_wxwidgets(PLStream *)
void plD_bop_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:403
void plD_init_wxpng(PLStream *)
virtual void SetXorMode(bool on)
Definition: wxwidgets.h:100
wxCoord m_prevSymbolHeight
Definition: wxwidgets.h:112
static int hrshsym
Definition: ps.c:79
virtual void DrawLine(short x1a, short y1a, short x2a, short y2a)
Definition: wxwidgets.h:86
void plD_esc_wxwidgets(PLStream *, PLINT, void *)
Definition: wxwidgets.cpp:504
void plD_wait_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:373
PLMemoryMap m_outputMemoryMap
Definition: wxwidgets.h:198
PLUNICODE m_prevSymbol
Definition: wxwidgets.h:107
wxCoord m_prevSymbolWidth
Definition: wxwidgets.h:111
FontGrabber m_fontGrabber
Definition: wxwidgets.h:175
wxCoord m_prevSymbolDepth
Definition: wxwidgets.h:113
PLFLT m_size
Definition: wxwidgets.h:60
virtual void ClearBackground(PLStream *pls, PLINT x1=-1, PLINT y1=-1, PLINT x2=-1, PLINT y2=-1)
Definition: wxwidgets.h:88
wxGraphicsContext * m_gc
Definition: wxwidgets.h:150