43 static const char *graph[] = {
51 "UX. . . . . . . . . . . . . . UX",
52 ". . . . . . . . . . . . . . . . ",
53 ". . . . . . . . . . . . . . . . ",
54 ". . . . . . . . . . . X X . . . ",
55 ". . . . . . . . . . . X X . . . ",
56 ". . . . . . . . . . . X X . . . ",
57 ". . . . . X X . . . . X X . . . ",
58 ". . . . . X X . . . . X X . . . ",
59 ". . . . . X X . X X . X X . . . ",
60 ". . . . . X X . X X . X X . . . ",
61 ". . . . . X X . X X . X X . . . ",
62 ". . . . . X X . X X . X X . . . ",
63 ". . . X X X X X X X X X X . . . ",
64 ". . . . . . . . . . . . . . . . ",
65 ". . . . . . . . . . . . . . . . ",
66 "UX. . . . . . . . . . . . . . UX"
71 { wxT(
"wxbmp" ), wxT(
"bmp (wx)..." ), wxT(
"Save this plot as bmp!" ), wxT(
"bmp files (*.bmp)|*.bmp" ),
true },
72 { wxT(
"wxpng" ), wxT(
"png (wx)..." ), wxT(
"Save this plot as png" ), wxT(
"png files (*.png)|*.png" ),
true },
73 { wxT(
"wxpcx" ), wxT(
"pcx (wx)..." ), wxT(
"Save this plot as pcx!" ), wxT(
"pcx files (*.pcx)|*.pcx" ),
true },
74 { wxT(
"wxjpeg" ), wxT(
"jpeg (wx)..." ), wxT(
"Save this plot as jpeg!" ), wxT(
"jpg files (*.jpg;*.jpeg)|*.jpg;*.jpeg" ),
true },
75 { wxT(
"wxtiff" ), wxT(
"tiff (wx)..." ), wxT(
"Save this plot as tiff!" ), wxT(
"tiff files (*.tif;*.tiff)|*.tif;*.tiff" ),
true },
76 { wxT(
"wxpnm" ), wxT(
"pnm (wx)..." ), wxT(
"Save this plot as pnm!" ), wxT(
"pnm files (*.pnm)|*.pnm" ),
true },
77 { wxT(
"pngcairo" ), wxT(
"png (cairo)..." ), wxT(
"Save this plot as png using cairo!" ), wxT(
"png files (*.png)|*.png" ),
true },
78 { wxT(
"pdfcairo" ), wxT(
"pdf (cairo)..." ), wxT(
"Save this plot as pdf using cairo!" ), wxT(
"pdf files (*.pdf)|*.pdf" ),
false },
79 { wxT(
"ps" ), wxT(
"postscript..." ), wxT(
"Save this plot as postscript!" ), wxT(
"ps files (*.ps)|*.ps" ),
false },
80 { wxT(
"psc" ), wxT(
"color postscript..." ), wxT(
"Save this plot as color postscript!" ), wxT(
"ps files (*.ps;*.psc)|*.ps;*.psc" ),
false },
81 { wxT(
"pscairo" ), wxT(
"color postscript (cairo)..." ), wxT(
"Save this plot as color postscript using cairo!" ), wxT(
"ps files (*.ps;*.psc)|*.ps;*.psc" ),
false },
82 { wxT(
"svg" ), wxT(
"svg..." ), wxT(
"Save this plot as svg!" ), wxT(
"svg files (*.svg)|*.svg" ),
false },
83 { wxT(
"svgcairo" ), wxT(
"svg (cairo)..." ), wxT(
"Save this plot as svg using cairo!" ), wxT(
"svg files (*.svg)|*.svg" ),
false },
84 { wxT(
"xfig" ), wxT(
"xfig..." ), wxT(
"Save this plot as xfig!" ), wxT(
"fig files (*.fig)|*.fig" ),
false }
92 EVT_IDLE( wxPLplotApp::OnIdle )
97 EVT_MENU( -1, wxPLplotFrame::OnMenu )
98 EVT_CLOSE( wxPLplotFrame::OnClose )
103 EVT_PAINT( wxPLplotWindow::OnPaint )
104 EVT_CHAR( wxPLplotWindow::OnChar )
105 EVT_IDLE( wxPLplotWindow::OnIdle )
106 EVT_MOUSE_EVENTS( wxPLplotWindow::OnMouse )
107 EVT_ERASE_BACKGROUND( wxPLplotWindow::OnErase )
108 EVT_SIZE( wxPLplotWindow::OnSize )
109 EVT_MAXIMIZE( wxPLplotWindow::OnMaximize )
121 bool wxPLplotApp::OnInit()
129 wxImage::AddHandler(
new wxPNGHandler );
132 wxImage::AddHandler(
new wxJPEGHandler );
135 wxImage::AddHandler(
new wxPCXHandler );
138 wxImage::AddHandler(
new wxTIFFHandler );
141 wxImage::AddHandler(
new wxPNMHandler );
157 for (
size_t i = 0; i <
FrameArray.GetCount(); i++ )
171 bool refresh =
false;
176 for (
size_t i = 0; i <
FrameArray.GetCount(); i++ )
191 : wxFrame( NULL, wxID_ANY, title, wxDefaultPosition, wxDefaultSize,
192 wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION |
193 wxCLOSE_BOX | wxRESIZE_BORDER | wxCLIP_CHILDREN )
199 m_panel =
new wxPanel(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxCLIP_CHILDREN );
200 wxBoxSizer* box =
new wxBoxSizer( wxVERTICAL );
202 box->Add( m_window, 1, wxALL | wxEXPAND, 0 );
203 m_panel->SetSizer( box );
204 m_window->SetFocus();
206 wxMenu* saveMenu =
new wxMenu;
209 saveMenu->Append(
wxPL_Save + 1, dev_entries[1].dev_menu_short, dev_entries[1].dev_menu_long );
212 saveMenu->Append(
wxPL_Save + 2, dev_entries[2].dev_menu_short, dev_entries[2].dev_menu_long );
215 saveMenu->Append(
wxPL_Save + 3, dev_entries[3].dev_menu_short, dev_entries[3].dev_menu_long );
218 saveMenu->Append(
wxPL_Save + 4, dev_entries[4].dev_menu_short, dev_entries[4].dev_menu_long );
221 saveMenu->Append(
wxPL_Save + 5, dev_entries[5].dev_menu_short, dev_entries[5].dev_menu_long );
223 for (
size_t j = 6; j <
sizeof ( dev_entries ) /
sizeof (
dev_entry ); j++ )
224 for (
int i = 0; i < m_dev->ndev; i++ )
226 if ( !strcmp( m_dev->devName[i], dev_entries[j].
dev_name.mb_str() ) )
227 saveMenu->Append(
wxPL_Save + j, dev_entries[j].dev_menu_short, dev_entries[j].dev_menu_long );
230 wxMenu* fileMenu =
new wxMenu;
231 #if ( wxMAJOR_VERSION <= 2 ) & ( wxMINOR_VERSION <= 6 )
232 fileMenu->Append( -1, wxT(
"Save plot as..." ), saveMenu, wxT(
"Save this plot as ...!" ) );
234 fileMenu->AppendSubMenu( saveMenu, wxT(
"Save plot as..." ), wxT(
"Save this plot as ...!" ) );
236 fileMenu->Append( wxID_EXIT, wxT(
"E&xit\tAlt-X" ), wxT(
"Exit wxWidgets PLplot App" ) );
238 wxMenu* orientationMenu =
new wxMenu;
239 orientationMenu->Append(
wxPL_Orientation_0, wxT(
"0 deg." ), wxT(
"Orientation 0 deg." ) );
240 orientationMenu->Append(
wxPL_Orientation_90, wxT(
"90 deg." ), wxT(
"Orientation 90 deg." ) );
241 orientationMenu->Append(
wxPL_Orientation_180, wxT(
"180 deg." ), wxT(
"Orientation 180 deg." ) );
242 orientationMenu->Append(
wxPL_Orientation_270, wxT(
"270 deg." ), wxT(
"Orientation 270 deg." ) );
244 wxMenu* plotMenu =
new wxMenu;
245 plotMenu->Append(
wxPL_Locate, wxT(
"Locate\tL" ), wxT(
"Enter locate mode" ) );
249 #if ( wxMAJOR_VERSION <= 2 ) & ( wxMINOR_VERSION <= 6 )
250 plotMenu->Append( -1, wxT(
"Set Orientation to..." ), orientationMenu, wxT(
"Set the Orientation of the plot!" ) );
252 plotMenu->AppendSubMenu( orientationMenu, wxT(
"Set Orientation to..." ), wxT(
"Set the Orientation of the plot!" ) );
256 wxMenuBar* menuBar =
new wxMenuBar();
257 menuBar->Append( fileMenu, wxT(
"&File" ) );
258 menuBar->Append( plotMenu, wxT(
"&Plot" ) );
259 SetMenuBar( menuBar );
261 SetIcon( wxIcon( graph ) );
274 switch ( event.GetId() )
278 wxPLGetApp().ExitMainLoop();
290 wxPLGetApp().SetAdvanceFlag();
302 size_t index =
event.GetId() -
wxPL_Save;
303 if ( ( event.GetId() >=
wxPL_Save ) && ( index <
sizeof ( dev_entries ) /
sizeof (
dev_entry ) ) )
307 bool proceed =
false;
312 wxGetSizeDialog sizeDialog(
this, -1, wxT(
"Size of plot" ), wxDefaultPosition, wxDefaultSize,
313 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER, width, height );
314 if ( sizeDialog.ShowModal() == wxID_OK )
316 width = sizeDialog.getWidth();
317 height = sizeDialog.getHeight();
326 wxFileDialog dialog(
this, wxT(
"Save plot as " ) + dev_entries[index].
dev_name, wxT(
"" ), wxT(
"" ),
327 dev_entries[index].
dev_file_app + wxT(
"|All Files (*.*)|*.*" ),
328 #
if ( wxMAJOR_VERSION <= 2 ) & ( wxMINOR_VERSION <= 6 )
329 wxSAVE | wxOVERWRITE_PROMPT );
331 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
333 if ( dialog.ShowModal() == wxID_OK )
335 const wxCharBuffer buf1 = dialog.GetPath().mb_str();
336 const wxCharBuffer buf2 = dev_entries[index].
dev_name.mb_str();
337 SavePlot( (
const char *) buf1, (
const char *) buf2, width, height );
353 wxPLGetApp().ExitMainLoop();
369 if ( !strcmp( devname,
"wxbmp" ) || !strcmp( devname,
"wxpng" ) || !strcmp( devname,
"wxpcx" ) ||
370 !strcmp( devname,
"wxjpeg" ) || !strcmp( devname,
"wxtiff" ) || !strcmp( devname,
"wxpnm" ) )
374 wxBitmap bitmap( width, height, -1 );
375 memDC.SelectObject( bitmap );
380 plspage( 0.0, 0.0, width, height, 0, 0 );
393 if ( !strcmp( devname,
"wxbmp" ) )
394 type = wxBITMAP_TYPE_BMP;
396 else if ( !strcmp( devname,
"wxpng" ) )
397 type = wxBITMAP_TYPE_PNG;
400 else if ( !strcmp( devname,
"wxpcx" ) )
401 type = wxBITMAP_TYPE_PCX;
404 else if ( !strcmp( devname,
"wxjpeg" ) )
405 type = wxBITMAP_TYPE_JPEG;
408 else if ( !strcmp( devname,
"wxtiff" ) )
409 type = wxBITMAP_TYPE_TIF;
412 else if ( !strcmp( devname,
"wxpnm" ) )
413 type = wxBITMAP_TYPE_PNM;
416 type = wxBITMAP_TYPE_BMP;
417 bool status = bitmap.SaveFile( wxString( filename, *wxConvCurrent ), type );
422 snprintf( buf, 512,
"File %s couldn't be saved", filename );
453 : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
454 wxNO_BORDER | wxWANTS_CHARS | wxCLIP_CHILDREN )
461 mouse_x = old_mouse_x = -1;
462 mouse_y = old_mouse_y = -1;
465 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
482 wxPaintDC dc(
this );
486 wxRegionIterator upd( GetUpdateRegion() );
491 dc.SetLogicalFunction( wxINVERT );
493 dc.SetLogicalFunction( wxCOPY );
514 dc.SetLogicalFunction( wxINVERT );
516 dc.SetLogicalFunction( wxCOPY );
536 GetClientSize( &width, &height );
545 int keycode =
event.GetKeyCode();
546 gin->
string[0] = (char) keycode;
558 wxPLGetApp().SetAdvanceFlag();
576 wxPLGetApp().SetAdvanceFlag();
589 wxPLGetApp().SetExitFlag();
594 wxPLGetApp().SetAdvanceFlag();
623 #if ( wxMAJOR_VERSION <= 2 ) & ( wxMINOR_VERSION <= 5 )
626 RefreshRect( rect,
false );
663 GetClientSize( &width, &height );
695 wxSizeEvent event( GetClientSize() );
696 AddPendingEvent( event );
709 wxPoint pos( event.GetPosition() );
713 if ( event.ButtonDown() )
718 GetClientSize( &width, &height );
722 gin->
dX = (
PLFLT) mouse_x / ( width - 1 );
725 if ( event.LeftDown() )
730 else if ( event.MiddleDown() )
735 else if ( event.RightDown() )
738 gin->
state = 1 << 10;
753 wxPLGetApp().SetAdvanceFlag();
760 wxPLGetApp().SetAdvanceFlag();
787 wxPLGetApp().SetAdvanceFlag();
809 printf(
"%f %f %c\n", gin->
wX, gin->
wY, gin->
keysym );
811 printf(
"%f %f 0x%02x\n", gin->
wX, gin->
wY, gin->
keysym );
833 wxClientDC dc(
this );
838 dc.SetLogicalFunction( wxINVERT );
841 dc.CrossHair( mouse_x,
mouse_y );
842 dc.SetLogicalFunction( wxCOPY );
852 dc.SetLogicalFunction( wxINVERT );
854 dc.SetLogicalFunction( wxCOPY );
887 const wxPoint &
position,
const wxSize& size,
long style,
int width,
int height ) :
888 wxDialog( parent, id, title, position, size, style )
890 wxBoxSizer *sizer =
new wxBoxSizer( wxVERTICAL );
892 wxStaticBoxSizer *staticSizer =
new wxStaticBoxSizer(
new wxStaticBox(
this, -1, wxT(
"Size of plot" ) ), wxVERTICAL );
894 wxFlexGridSizer *flexSizer =
new wxFlexGridSizer( 2, 0, 0 );
895 flexSizer->AddGrowableCol( 1 );
897 wxStaticText *textWidth =
new wxStaticText(
this, -1, wxT(
"Width [pixels]:" ), wxDefaultPosition, wxDefaultSize, 0 );
898 flexSizer->Add( textWidth, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
899 spinControlWidth =
new wxSpinCtrl(
this, -1, wxString::Format( wxT(
"%d" ), width ), wxDefaultPosition, wxSize( 100, -1 ), wxSP_ARROW_KEYS, 10, 4096, width );
900 flexSizer->Add( spinControlWidth, 0, wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
901 wxStaticText *textHeight =
new wxStaticText(
this, -1, wxT(
"Height [pixels]:" ), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );
902 flexSizer->Add( textHeight, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
903 spinControlHeight =
new wxSpinCtrl(
this, -1, wxString::Format( wxT(
"%d" ), height ), wxDefaultPosition, wxSize( 100, -1 ), wxSP_ARROW_KEYS, 10, 4096, height );
904 flexSizer->Add( spinControlHeight, 0, wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
906 staticSizer->Add( flexSizer, 0, wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
908 sizer->Add( staticSizer, 0, wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
910 wxBoxSizer *buttonSizer =
new wxBoxSizer( wxHORIZONTAL );
911 wxButton *buttonOK =
new wxButton(
this, wxID_OK, wxT(
"OK" ), wxDefaultPosition, wxDefaultSize, 0 );
912 buttonSizer->Add( buttonOK, 0, wxALIGN_CENTER | wxALL | wxEXPAND, 5 );
913 buttonSizer->Add( 20, 20, 1, wxALIGN_CENTER | wxALL, 5 );
914 wxButton *buttonCancel =
new wxButton(
this, wxID_CANCEL, wxT(
"Cancel" ), wxDefaultPosition, wxDefaultSize, 0 );
915 buttonSizer->Add( buttonCancel, 0, wxALIGN_CENTER | wxALL | wxEXPAND, 5 );
917 sizer->Add( buttonSizer, 0, wxGROW | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 15 );
919 this->SetSizer( sizer );
920 sizer->SetSizeHints(
this );
923 #endif // PLD_wxwidgets
void(* ButtonEH)(PLGraphicsIn *gin, void *ButtonEH_data, int *exit_eventloop)
void PLFLT PLINT PLINT position
wxPLplotWindow * m_window
void OnMaximize(wxMaximizeEvent &WXUNUSED(event))
void plGinInit(PLGraphicsIn *gin)
void OnIdle(wxIdleEvent &event)
void(* LocateEH)(PLGraphicsIn *gin, void *LocateEH_data, int *locate_mode)
void OnChar(wxKeyEvent &event)
void OnClose(wxCloseEvent &event)
void OnMouse(wxMouseEvent &event)
void OnIdle(wxIdleEvent &event)
wxPLplotWindow(wxWindow *parent, PLStream *pls)
int plTranslateCursor(PLGraphicsIn *plg)
void SetOrientation(int rot)
wxPLplotFrame(const wxString &title, PLStream *pls)
void pl_cmd(PLINT op, void *ptr)
subroutine plsetopt(opt, optarg)
void plabort(const char *errormsg)
void plRemakePlot(PLStream *pls)
void OnPaint(wxPaintEvent &event)
void(* KeyEH)(PLGraphicsIn *gin, void *KeyEH_data, int *exit_eventloop)
void OnSize(wxSizeEvent &WXUNUSED(event))
virtual void ClearBackground(PLINT bgr, PLINT bgg, PLINT bgb, PLINT x1=-1, PLINT y1=-1, PLINT x2=-1, PLINT y2=-1)=0
void OnMenu(wxCommandEvent &event)
virtual void BlitRectangle(wxDC *dc, int vX, int vY, int vW, int vH)=0
wxGetSizeDialog(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, int width=800, int height=600)
void SetRefreshFlag(bool flag=true)
wxArrayOfwxPLplotFrame FrameArray
bool SavePlot(const char *filename, const char *devname, int width, int height)
void OnErase(wxEraseEvent &WXUNUSED(event))