X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8556b795c369382a1f5f2ed9405138a450ecc4a6..8fb816ff93dc7c26365337d2746316929bed5380:/contrib/src/plot/plot.cpp diff --git a/contrib/src/plot/plot.cpp b/contrib/src/plot/plot.cpp index af509c3440..aa9a42e517 100644 --- a/contrib/src/plot/plot.cpp +++ b/contrib/src/plot/plot.cpp @@ -29,10 +29,12 @@ #include "wx/log.h" #include "wx/intl.h" #include "wx/dcclient.h" +#include "wx/stattext.h" #endif #include "wx/plot/plot.h" #include "wx/bmpbuttn.h" +#include "wx/module.h" #include @@ -49,6 +51,32 @@ #include "wx/plot/plot_dwn.xpm" #endif +//---------------------------------------------------------------------------- +// event types +//---------------------------------------------------------------------------- + +DEFINE_EVENT_TYPE(wxEVT_PLOT_SEL_CHANGING); +DEFINE_EVENT_TYPE(wxEVT_PLOT_SEL_CHANGED); +DEFINE_EVENT_TYPE(wxEVT_PLOT_CLICKED); +DEFINE_EVENT_TYPE(wxEVT_PLOT_DOUBLECLICKED); +DEFINE_EVENT_TYPE(wxEVT_PLOT_ZOOM_IN); +DEFINE_EVENT_TYPE(wxEVT_PLOT_ZOOM_OUT); +DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CREATING); +DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CREATED); +DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CHANGING); +DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CHANGED); +DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CREATING); +DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CREATED); +DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CHANGING); +DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CHANGED); +DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_X_LABEL_EDIT); +DEFINE_EVENT_TYPE(wxEVT_PLOT_END_X_LABEL_EDIT); +DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_Y_LABEL_EDIT); +DEFINE_EVENT_TYPE(wxEVT_PLOT_END_Y_LABEL_EDIT); +DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_TITLE_EDIT); +DEFINE_EVENT_TYPE(wxEVT_PLOT_END_TITLE_EDIT); +DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_CREATE); + //---------------------------------------------------------------------------- // accessor functions for the bitmaps (may return NULL, check for it!) //---------------------------------------------------------------------------- @@ -60,32 +88,6 @@ static wxBitmap *GetZoomOutBitmap(); static wxBitmap *GetUpBitmap(); static wxBitmap *GetDownBitmap(); -//---------------------------------------------------------------------------- -// event types -//---------------------------------------------------------------------------- - -int wxEVT_PLOT_SEL_CHANGING; -int wxEVT_PLOT_SEL_CHANGED; -int wxEVT_PLOT_CLICKED; -int wxEVT_PLOT_DOUBLECLICKED; -int wxEVT_PLOT_ZOOM_IN; -int wxEVT_PLOT_ZOOM_OUT; -int wxEVT_PLOT_VALUE_SEL_CREATING; -int wxEVT_PLOT_VALUE_SEL_CREATED; -int wxEVT_PLOT_VALUE_SEL_CHANGING; -int wxEVT_PLOT_VALUE_SEL_CHANGED; -int wxEVT_PLOT_AREA_SEL_CREATING; -int wxEVT_PLOT_AREA_SEL_CREATED; -int wxEVT_PLOT_AREA_SEL_CHANGING; -int wxEVT_PLOT_AREA_SEL_CHANGED; -int wxEVT_PLOT_BEGIN_X_LABEL_EDIT; -int wxEVT_PLOT_END_X_LABEL_EDIT; -int wxEVT_PLOT_BEGIN_Y_LABEL_EDIT; -int wxEVT_PLOT_END_Y_LABEL_EDIT; -int wxEVT_PLOT_BEGIN_TITLE_EDIT; -int wxEVT_PLOT_END_TITLE_EDIT; -int wxEVT_PLOT_AREA_CREATE; - //----------------------------------------------------------------------------- // consts //----------------------------------------------------------------------------- @@ -98,12 +100,12 @@ int wxEVT_PLOT_AREA_CREATE; wxPlotEvent::wxPlotEvent( wxEventType commandType, int id ) : wxNotifyEvent( commandType, id ) -{ +{ m_curve = (wxPlotCurve*) NULL; m_zoom = 1.0; m_position = 0; } - + //----------------------------------------------------------------------------- // wxPlotCurve //----------------------------------------------------------------------------- @@ -111,6 +113,7 @@ wxPlotEvent::wxPlotEvent( wxEventType commandType, int id ) IMPLEMENT_ABSTRACT_CLASS(wxPlotCurve, wxObject) wxPlotCurve::wxPlotCurve( int offsetY, double startY, double endY ) +: m_penNormal(*wxGREY_PEN), m_penSelected(*wxBLACK_PEN) { m_offsetY = offsetY; m_startY = startY; @@ -135,14 +138,14 @@ wxPlotOnOffCurve::wxPlotOnOffCurve( int offsetY ) void wxPlotOnOffCurve::Add( wxInt32 on, wxInt32 off, void *clientData ) { - wxASSERT_MSG( on > 0, wxT("plot index < 0") ); + wxASSERT_MSG( on > 0, _T("plot index < 0") ); wxASSERT( on <= off ); if (m_minX == -1) m_minX = on; if (off > m_maxX) m_maxX = off; - + wxPlotOnOff *v = new wxPlotOnOff; v->m_on = on; v->m_off = off; @@ -197,17 +200,17 @@ void wxPlotOnOffCurve::DrawOffLine( wxDC &dc, wxCoord y, wxCoord start, wxCoord IMPLEMENT_DYNAMIC_CLASS(wxPlotArea, wxWindow) BEGIN_EVENT_TABLE(wxPlotArea, wxWindow) - EVT_PAINT( wxPlotArea::OnPaint) - EVT_LEFT_DOWN( wxPlotArea::OnMouse) - EVT_LEFT_DCLICK( wxPlotArea::OnMouse) + EVT_PAINT( wxPlotArea::OnPaint) + EVT_LEFT_DOWN( wxPlotArea::OnMouse) + EVT_LEFT_DCLICK( wxPlotArea::OnMouse) END_EVENT_TABLE() wxPlotArea::wxPlotArea( wxPlotWindow *parent ) - : wxWindow( parent, -1, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER, "plotarea" ) + : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER, _T("plotarea") ) { m_owner = parent; - - m_zooming = FALSE; + + m_zooming = false; SetBackgroundColour( *wxWHITE ); } @@ -222,25 +225,25 @@ void wxPlotArea::OnMouse( wxMouseEvent &event ) m_owner->GetViewStart( &view_x, &view_y ); view_x *= wxPLOT_SCROLL_STEP; view_y *= wxPLOT_SCROLL_STEP; - + wxCoord x = event.GetX(); wxCoord y = event.GetY(); x += view_x; y += view_y; - - wxNode *node = m_owner->m_curves.First(); + + wxList::compatibility_iterator node = m_owner->m_curves.GetFirst(); while (node) { - wxPlotCurve *curve = (wxPlotCurve*)node->Data(); - + wxPlotCurve *curve = (wxPlotCurve*)node->GetData(); + double double_client_height = (double)client_height; double range = curve->GetEndY() - curve->GetStartY(); double end = curve->GetEndY(); wxCoord offset_y = curve->GetOffsetY(); - + double dy = (end - curve->GetY( (wxInt32)(x/m_owner->GetZoom()) )) / range; wxCoord curve_y = (wxCoord)(dy * double_client_height) - offset_y - 1; - + if ((y-curve_y < 4) && (y-curve_y > -4)) { wxPlotEvent event1( event.ButtonDClick() ? wxEVT_PLOT_DOUBLECLICKED : wxEVT_PLOT_CLICKED, m_owner->GetId() ); @@ -249,8 +252,8 @@ void wxPlotArea::OnMouse( wxMouseEvent &event ) event1.SetCurve( curve ); event1.SetPosition( (int)floor(x/m_owner->GetZoom()) ); m_owner->GetEventHandler()->ProcessEvent( event1 ); - - if (curve != m_owner->GetCurrent()) + + if (curve != m_owner->GetCurrentCurve()) { wxPlotEvent event2( wxEVT_PLOT_SEL_CHANGING, m_owner->GetId() ); event2.SetEventObject( m_owner ); @@ -258,13 +261,13 @@ void wxPlotArea::OnMouse( wxMouseEvent &event ) event2.SetCurve( curve ); if (!m_owner->GetEventHandler()->ProcessEvent( event2 ) || event2.IsAllowed()) { - m_owner->SetCurrent( curve ); + m_owner->SetCurrentCurve( curve ); } } return; } - - node = node->Next(); + + node = node->GetNext(); } } @@ -282,17 +285,17 @@ void wxPlotArea::DrawCurve( wxDC *dc, wxPlotCurve *curve, int from, int to ) int view_y; m_owner->GetViewStart( &view_x, &view_y ); view_x *= wxPLOT_SCROLL_STEP; - + if (from == -1) from = view_x; int client_width; int client_height; GetClientSize( &client_width, &client_height); - + if (to == -1) to = view_x + client_width; - + double zoom = m_owner->GetZoom(); int start_x = wxMax( from, (int)floor(curve->GetStartX()*zoom) ); @@ -300,23 +303,23 @@ void wxPlotArea::DrawCurve( wxDC *dc, wxPlotCurve *curve, int from, int to ) start_x = wxMax( view_x, start_x ); end_x = wxMin( view_x + client_width, end_x ); - + end_x++; double double_client_height = (double)client_height; double range = curve->GetEndY() - curve->GetStartY(); double end = curve->GetEndY(); wxCoord offset_y = curve->GetOffsetY(); - - wxCoord y=0,last_y=0; + + wxCoord last_y=0; for (int x = start_x; x < end_x; x++) { double dy = (end - curve->GetY( (wxInt32)(x/zoom) )) / range; - y = (wxCoord)(dy * double_client_height) - offset_y - 1; - + wxCoord y = (wxCoord)(dy * double_client_height) - offset_y - 1; + if (x != start_x) dc->DrawLine( x-1, last_y, x, y ); - + last_y = y; } } @@ -327,17 +330,17 @@ void wxPlotArea::DrawOnOffCurve( wxDC *dc, wxPlotOnOffCurve *curve, int from, in int view_y; m_owner->GetViewStart( &view_x, &view_y ); view_x *= wxPLOT_SCROLL_STEP; - + if (from == -1) from = view_x; int client_width; int client_height; GetClientSize( &client_width, &client_height); - + if (to == -1) to = view_x + client_width; - + double zoom = m_owner->GetZoom(); int start_x = wxMax( from, (int)floor(curve->GetStartX()*zoom) ); @@ -345,19 +348,19 @@ void wxPlotArea::DrawOnOffCurve( wxDC *dc, wxPlotOnOffCurve *curve, int from, in start_x = wxMax( view_x, start_x ); end_x = wxMin( view_x + client_width, end_x ); - + end_x++; wxCoord offset_y = curve->GetOffsetY(); wxCoord last_off = -5; - + if (curve->GetCount() == 0) return; - + for (size_t index = 0; index < curve->GetCount(); index++) { wxPlotOnOff *p = curve->GetAt( index ); - + wxCoord on = (wxCoord)(p->m_on*zoom); wxCoord off = (wxCoord)(p->m_off*zoom); @@ -366,7 +369,7 @@ void wxPlotArea::DrawOnOffCurve( wxDC *dc, wxPlotOnOffCurve *curve, int from, in curve->DrawOffLine( *dc, client_height-offset_y, last_off, on ); break; } - + if (off >= start_x) { curve->DrawOffLine( *dc, client_height-offset_y, last_off, on ); @@ -374,7 +377,7 @@ void wxPlotArea::DrawOnOffCurve( wxDC *dc, wxPlotOnOffCurve *curve, int from, in } last_off = off; } - + wxPlotOnOff *p = curve->GetAt( curve->GetCount()-1 ); wxCoord off = (wxCoord)(p->m_off*zoom); if (off < end_x) @@ -393,16 +396,12 @@ void wxPlotArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) m_owner->PrepareDC( dc ); wxRegionIterator upd( GetUpdateRegion() ); - + while (upd) { - int update_x = upd.GetX(); - int update_y = upd.GetY(); + int update_x = upd.GetX() + view_x; int update_width = upd.GetWidth(); - - update_x += view_x; - update_y += view_y; - + /* if (m_owner->m_current) { @@ -411,34 +410,34 @@ void wxPlotArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.DrawLine( update_x-1, base_line-1, update_x+update_width+2, base_line-1 ); } */ - - wxNode *node = m_owner->m_curves.First(); + + wxList::compatibility_iterator node = m_owner->m_curves.GetFirst(); while (node) { - wxPlotCurve *curve = (wxPlotCurve*) node->Data(); - - if (curve == m_owner->GetCurrent()) - dc.SetPen( *wxBLACK_PEN ); + wxPlotCurve *curve = (wxPlotCurve*) node->GetData(); + + if (curve == m_owner->GetCurrentCurve()) + dc.SetPen( curve->GetPenSelected() ); else - dc.SetPen( *wxGREY_PEN ); - + dc.SetPen( curve->GetPenNormal() ); + DrawCurve( &dc, curve, update_x-1, update_x+update_width+2 ); - node = node->Next(); + node = node->GetNext(); } - + dc.SetPen( *wxRED_PEN ); - - node = m_owner->m_onOffCurves.First(); + + node = m_owner->m_onOffCurves.GetFirst(); while (node) { - wxPlotOnOffCurve *curve = (wxPlotOnOffCurve*) node->Data(); - + wxPlotOnOffCurve *curve = (wxPlotOnOffCurve*) node->GetData(); + DrawOnOffCurve( &dc, curve, update_x-1, update_x+update_width+2 ); - - node = node->Next(); + + node = node->GetNext(); } - + upd ++; } } @@ -461,10 +460,10 @@ BEGIN_EVENT_TABLE(wxPlotXAxisArea, wxWindow) END_EVENT_TABLE() wxPlotXAxisArea::wxPlotXAxisArea( wxPlotWindow *parent ) - : wxWindow( parent, -1, wxDefaultPosition, wxSize(-1,40), 0, "plotxaxisarea" ) + : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxSize(wxDefaultCoord,40), 0, _T("plotxaxisarea") ) { m_owner = parent; - + SetBackgroundColour( *wxWHITE ); SetFont( *wxSMALL_FONT ); } @@ -479,13 +478,13 @@ void wxPlotXAxisArea::OnMouse( wxMouseEvent &event ) m_owner->GetViewStart( &view_x, &view_y ); view_x *= wxPLOT_SCROLL_STEP; view_y *= wxPLOT_SCROLL_STEP; - - wxCoord x = event.GetX(); - wxCoord y = event.GetY(); - x += view_x; - y += view_y; - - /* do something here */ + + wxCoord x = event.GetX() + view_x; + wxCoord y = event.GetY() + view_y; + + /* TO DO: do something here */ + wxUnusedVar(x); + wxUnusedVar(y); } void wxPlotXAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) @@ -497,34 +496,34 @@ void wxPlotXAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) view_y *= wxPLOT_SCROLL_STEP; wxPaintDC dc( this ); - + int client_width; int client_height; GetClientSize( &client_width, &client_height); - + double zoom = m_owner->GetZoom(); - + double ups = m_owner->GetUnitsPerValue() / zoom; - + double start = view_x * ups; double end = (view_x + client_width) * ups; double range = end - start; - + int int_log_range = (int)floor( log10( range ) ); double step = 1.0; if (int_log_range > 0) { for (int i = 0; i < int_log_range; i++) - step *= 10; + step *= 10; } if (int_log_range < 0) { for (int i = 0; i < -int_log_range; i++) - step /= 10; + step /= 10; } double lower = ceil(start / step) * step; double upper = floor(end / step) * step; - + // if too few values, shrink size if ((range/step) < 4) { @@ -532,7 +531,7 @@ void wxPlotXAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) if (lower-step > start) lower -= step; if (upper+step < end) upper += step; } - + // if still too few, again if ((range/step) < 4) { @@ -540,13 +539,13 @@ void wxPlotXAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) if (lower-step > start) lower -= step; if (upper+step < end) upper += step; } - + dc.SetBrush( *wxWHITE_BRUSH ); dc.SetPen( *wxTRANSPARENT_PEN ); dc.DrawRectangle( 4, 5, client_width-14, 10 ); dc.DrawRectangle( 0, 20, client_width, 20 ); dc.SetPen( *wxBLACK_PEN ); - + double current = lower; while (current < upper+(step/2)) { @@ -557,20 +556,20 @@ void wxPlotXAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) wxString label; if (range < 50) { - label.Printf( wxT("%f"), current ); - while (label.Last() == wxT('0')) + label.Printf( _T("%f"), current ); + while (label.Last() == _T('0')) label.RemoveLast(); - if ((label.Last() == wxT('.')) || (label.Last() == wxT(','))) - label.Append( wxT('0') ); + if ((label.Last() == _T('.')) || (label.Last() == _T(','))) + label.Append( _T('0') ); } else - label.Printf( wxT("%d"), (int)floor(current) ); + label.Printf( _T("%d"), (int)floor(current) ); dc.DrawText( label, x-4, 20 ); } current += step; } - + dc.DrawLine( 0, 15, client_width-8, 15 ); dc.DrawLine( client_width-4, 15, client_width-10, 10 ); dc.DrawLine( client_width-4, 15, client_width-10, 20 ); @@ -588,10 +587,10 @@ BEGIN_EVENT_TABLE(wxPlotYAxisArea, wxWindow) END_EVENT_TABLE() wxPlotYAxisArea::wxPlotYAxisArea( wxPlotWindow *parent ) - : wxWindow( parent, -1, wxDefaultPosition, wxSize(60,-1), 0, "plotyaxisarea" ) + : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxSize(60,wxDefaultCoord), 0, _T("plotyaxisarea") ) { m_owner = parent; - + SetBackgroundColour( *wxWHITE ); SetFont( *wxSMALL_FONT ); } @@ -604,36 +603,36 @@ void wxPlotYAxisArea::OnMouse( wxMouseEvent &WXUNUSED(event) ) void wxPlotYAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) { wxPaintDC dc( this ); - - wxPlotCurve *curve = m_owner->GetCurrent(); - + + wxPlotCurve *curve = m_owner->GetCurrentCurve(); + if (!curve) return; - + int client_width; int client_height; GetClientSize( &client_width, &client_height); - + double range = curve->GetEndY() - curve->GetStartY(); double offset = ((double) curve->GetOffsetY() / (double)client_height ) * range; double start = curve->GetStartY() - offset; double end = curve->GetEndY() - offset; - + int int_log_range = (int)floor( log10( range ) ); double step = 1.0; if (int_log_range > 0) { for (int i = 0; i < int_log_range; i++) - step *= 10; + step *= 10; } if (int_log_range < 0) { for (int i = 0; i < -int_log_range; i++) - step /= 10; + step /= 10; } double lower = ceil(start / step) * step; double upper = floor(end / step) * step; - + // if too few values, shrink size if ((range/step) < 4) { @@ -641,7 +640,7 @@ void wxPlotYAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) if (lower-step > start) lower -= step; if (upper+step < end) upper += step; } - + // if still too few, again if ((range/step) < 4) { @@ -651,7 +650,7 @@ void wxPlotYAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) } dc.SetPen( *wxBLACK_PEN ); - + double current = lower; while (current < upper+(step/2)) { @@ -663,20 +662,20 @@ void wxPlotYAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) wxString label; if (range < 50) { - label.Printf( wxT("%f"), current ); - while (label.Last() == wxT('0')) + label.Printf( _T("%f"), current ); + while (label.Last() == _T('0')) label.RemoveLast(); - if ((label.Last() == wxT('.')) || (label.Last() == wxT(','))) - label.Append( wxT('0') ); + if ((label.Last() == _T('.')) || (label.Last() == _T(','))) + label.Append( _T('0') ); } else - label.Printf( wxT("%d"), (int)floor(current) ); + label.Printf( _T("%d"), (int)floor(current) ); dc.DrawText( label, 5, y-7 ); } current += step; } - + dc.DrawLine( client_width-15, 6, client_width-15, client_height ); dc.DrawLine( client_width-15, 2, client_width-20, 8 ); dc.DrawLine( client_width-15, 2, client_width-10, 8 ); @@ -699,30 +698,31 @@ void wxPlotYAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) IMPLEMENT_DYNAMIC_CLASS(wxPlotWindow, wxScrolledWindow) BEGIN_EVENT_TABLE(wxPlotWindow, wxScrolledWindow) - EVT_BUTTON( ID_MOVE_UP, wxPlotWindow::OnMoveUp) - EVT_BUTTON( ID_MOVE_DOWN, wxPlotWindow::OnMoveDown) - - EVT_BUTTON( ID_ENLARGE, wxPlotWindow::OnEnlarge) - EVT_BUTTON( ID_SHRINK, wxPlotWindow::OnShrink) - - EVT_BUTTON( ID_ZOOM_IN, wxPlotWindow::OnZoomIn) - EVT_BUTTON( ID_ZOOM_OUT, wxPlotWindow::OnZoomOut) - - EVT_SCROLLWIN( wxPlotWindow::OnScroll2) + EVT_BUTTON( ID_MOVE_UP, wxPlotWindow::OnMoveUp) + EVT_BUTTON( ID_MOVE_DOWN, wxPlotWindow::OnMoveDown) + + EVT_BUTTON( ID_ENLARGE, wxPlotWindow::OnEnlarge) + EVT_BUTTON( ID_SHRINK, wxPlotWindow::OnShrink) + + EVT_BUTTON( ID_ZOOM_IN, wxPlotWindow::OnZoomIn) + EVT_BUTTON( ID_ZOOM_OUT, wxPlotWindow::OnZoomOut) + + EVT_SCROLLWIN( wxPlotWindow::OnScroll2) END_EVENT_TABLE() wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag ) - : wxScrolledWindow( parent, id, pos, size, flag, "plotcanvas" ) + : wxScrolledWindow( parent, id, pos, size, flag, _T("plotcanvas") ), + m_titleStaticText( NULL ) { m_xUnitsPerValue = 1.0; m_xZoom = 1.0; - - m_enlargeAroundWindowCentre = FALSE; - m_scrollOnThumbRelease = FALSE; + + m_enlargeAroundWindowCentre = false; + m_scrollOnThumbRelease = false; m_area = new wxPlotArea( this ); wxBoxSizer *mainsizer = new wxBoxSizer( wxHORIZONTAL ); - + if ((GetWindowStyleFlag() & wxPLOT_BUTTON_ALL) != 0) { wxBoxSizer *buttonlist = new wxBoxSizer( wxVERTICAL ); @@ -745,15 +745,20 @@ wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, } mainsizer->Add( buttonlist, 0, wxEXPAND|wxALL, 4 ); } - + wxBoxSizer *plotsizer = new wxBoxSizer( wxHORIZONTAL ); - + + //Add sizer to hold the title and plot. + //Title to be added later. + m_plotAndTitleSizer = new wxBoxSizer( wxVERTICAL ); + m_plotAndTitleSizer->Add( plotsizer, 1, wxEXPAND | wxTOP, 10 ); + if ((GetWindowStyleFlag() & wxPLOT_Y_AXIS) != 0) { m_yaxis = new wxPlotYAxisArea( this ); - + wxBoxSizer *vert1 = new wxBoxSizer( wxVERTICAL ); - plotsizer->Add( vert1, 0, wxEXPAND ); + plotsizer->Add( vert1, 1, wxEXPAND|wxTOP,10 ); vert1->Add( m_yaxis, 1 ); if ((GetWindowStyleFlag() & wxPLOT_X_AXIS) != 0) vert1->Add( 60, 40 ); @@ -762,14 +767,14 @@ wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, { m_yaxis = (wxPlotYAxisArea*) NULL; } - + if ((GetWindowStyleFlag() & wxPLOT_X_AXIS) != 0) { m_xaxis = new wxPlotXAxisArea( this ); - + wxBoxSizer *vert2 = new wxBoxSizer( wxVERTICAL ); - plotsizer->Add( vert2, 1, wxEXPAND ); - vert2->Add( m_area, 1, wxEXPAND ); + plotsizer->Add( vert2, 5, wxEXPAND); + vert2->Add( m_area, 1, wxEXPAND|wxTOP,10 ); vert2->Add( m_xaxis, 0, wxEXPAND ); } else @@ -778,15 +783,17 @@ wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, m_xaxis = (wxPlotXAxisArea*) NULL; } - mainsizer->Add( plotsizer, 1, wxEXPAND ); - - SetAutoLayout( TRUE ); + mainsizer->Add( m_plotAndTitleSizer, 1, wxEXPAND ); + + SetAutoLayout( true ); SetSizer( mainsizer ); + mainsizer->Fit(this); + mainsizer->SetSizeHints(this); SetTargetWindow( m_area ); SetBackgroundColour( *wxWHITE ); - + m_current = (wxPlotCurve*) NULL; } @@ -798,7 +805,7 @@ void wxPlotWindow::Add( wxPlotCurve *curve ) { m_curves.Append( curve ); if (!m_current) m_current = curve; - + ResetScrollbar(); } @@ -809,20 +816,20 @@ size_t wxPlotWindow::GetCount() wxPlotCurve *wxPlotWindow::GetAt( size_t n ) { - wxNode *node = m_curves.Nth( n ); + wxList::compatibility_iterator node = m_curves.Item( n ); if (!node) return (wxPlotCurve*) NULL; - - return (wxPlotCurve*) node->Data(); + + return (wxPlotCurve*) node->GetData(); } -void wxPlotWindow::SetCurrent( wxPlotCurve* current ) +void wxPlotWindow::SetCurrentCurve( wxPlotCurve* current ) { m_current = current; - m_area->Refresh( FALSE ); - + m_area->Refresh( false ); + RedrawYAxis(); - + wxPlotEvent event( wxEVT_PLOT_SEL_CHANGED, GetId() ); event.SetEventObject( this ); event.SetZoom( GetZoom() ); @@ -832,16 +839,18 @@ void wxPlotWindow::SetCurrent( wxPlotCurve* current ) void wxPlotWindow::Delete( wxPlotCurve* curve ) { - wxNode *node = m_curves.Find( curve ); + wxList::compatibility_iterator node = m_curves.Find( curve ); if (!node) return; - + m_curves.DeleteObject( curve ); - + m_area->DeleteCurve( curve ); - m_area->Refresh( FALSE ); + m_area->Refresh( false ); + + if (curve == m_current) m_current = (wxPlotCurve *) NULL; } -wxPlotCurve *wxPlotWindow::GetCurrent() +wxPlotCurve *wxPlotWindow::GetCurrentCurve() { return m_current; } @@ -853,9 +862,9 @@ void wxPlotWindow::Add( wxPlotOnOffCurve *curve ) void wxPlotWindow::Delete( wxPlotOnOffCurve* curve ) { - wxNode *node = m_onOffCurves.Find( curve ); + wxList::compatibility_iterator node = m_onOffCurves.Find( curve ); if (!node) return; - + m_onOffCurves.DeleteObject( curve ); } @@ -866,57 +875,57 @@ size_t wxPlotWindow::GetOnOffCurveCount() wxPlotOnOffCurve *wxPlotWindow::GetOnOffCurveAt( size_t n ) { - wxNode *node = m_onOffCurves.Nth( n ); + wxList::compatibility_iterator node = m_onOffCurves.Item( n ); if (!node) return (wxPlotOnOffCurve*) NULL; - - return (wxPlotOnOffCurve*) node->Data(); + + return (wxPlotOnOffCurve*) node->GetData(); } void wxPlotWindow::Move( wxPlotCurve* curve, int pixels_up ) { m_area->DeleteCurve( curve ); - + curve->SetOffsetY( curve->GetOffsetY() + pixels_up ); - - m_area->Refresh( FALSE ); - + + m_area->Refresh( false ); + RedrawYAxis(); } void wxPlotWindow::OnMoveUp( wxCommandEvent& WXUNUSED(event) ) { if (!m_current) return; - + Move( m_current, 25 ); } void wxPlotWindow::OnMoveDown( wxCommandEvent& WXUNUSED(event) ) { if (!m_current) return; - + Move( m_current, -25 ); } void wxPlotWindow::Enlarge( wxPlotCurve *curve, double factor ) { m_area->DeleteCurve( curve ); - + int client_width; int client_height; m_area->GetClientSize( &client_width, &client_height); double offset = (double)curve->GetOffsetY() / (double)client_height; - + double range = curve->GetEndY() - curve->GetStartY(); offset *= range; - + double new_range = range / factor; double new_offset = offset / factor; - + if (m_enlargeAroundWindowCentre) { double middle = curve->GetStartY() - offset + range/2; - + curve->SetStartY( middle - new_range / 2 + new_offset ); curve->SetEndY( middle + new_range / 2 + new_offset ); } @@ -925,15 +934,15 @@ void wxPlotWindow::Enlarge( wxPlotCurve *curve, double factor ) curve->SetStartY( (curve->GetStartY() - offset)/factor + new_offset ); curve->SetEndY( (curve->GetEndY() - offset)/factor + new_offset ); } - - m_area->Refresh( FALSE ); + + m_area->Refresh( false ); RedrawYAxis(); } void wxPlotWindow::SetUnitsPerValue( double upv ) { m_xUnitsPerValue = upv; - + RedrawXAxis(); } @@ -941,64 +950,101 @@ void wxPlotWindow::SetZoom( double zoom ) { double old_zoom = m_xZoom; m_xZoom = zoom; - + int view_x = 0; int view_y = 0; GetViewStart( &view_x, &view_y ); - + wxInt32 max = 0; - wxNode *node = m_curves.First(); + wxList::compatibility_iterator node = m_curves.GetFirst(); while (node) { - wxPlotCurve *curve = (wxPlotCurve*) node->Data(); + wxPlotCurve *curve = (wxPlotCurve*) node->GetData(); if (curve->GetEndX() > max) max = curve->GetEndX(); - node = node->Next(); + node = node->GetNext(); } - SetScrollbars( wxPLOT_SCROLL_STEP, wxPLOT_SCROLL_STEP, - (int)((max*m_xZoom)/wxPLOT_SCROLL_STEP)+1, 0, - (int)(view_x*zoom/old_zoom), 0, - TRUE ); + SetScrollbars( wxPLOT_SCROLL_STEP, wxPLOT_SCROLL_STEP, + (int)((max*m_xZoom)/wxPLOT_SCROLL_STEP)+1, 0, + (int)(view_x*zoom/old_zoom), 0, + true ); RedrawXAxis(); - m_area->Refresh( TRUE ); + m_area->Refresh( true ); } void wxPlotWindow::ResetScrollbar() { wxInt32 max = 0; - wxNode *node = m_curves.First(); + wxList::compatibility_iterator node = m_curves.GetFirst(); while (node) { - wxPlotCurve *curve = (wxPlotCurve*) node->Data(); + wxPlotCurve *curve = (wxPlotCurve*) node->GetData(); if (curve->GetEndX() > max) max = curve->GetEndX(); - node = node->Next(); + node = node->GetNext(); } - - SetScrollbars( wxPLOT_SCROLL_STEP, wxPLOT_SCROLL_STEP, + + SetScrollbars( wxPLOT_SCROLL_STEP, wxPLOT_SCROLL_STEP, (int)(((max*m_xZoom)/wxPLOT_SCROLL_STEP)+1), 0 ); } +void wxPlotWindow::AddChartTitle(const wxString& title, wxFont font, + wxColour colour) +{ + m_title = title; + m_titleFont = font; + m_titleColour = colour; + DrawChartTitle(); +} + +void wxPlotWindow::DrawChartTitle() +{ + if(m_title.size() != 0) + { + //If it is already added, remove child and delete + if(m_titleStaticText) + { + RemoveChild( m_titleStaticText ); + m_titleStaticText->Destroy(); + } + + //Create the text control and set the font, colour + m_titleStaticText = new wxStaticText( this, -1, m_title ); + m_titleStaticText->SetFont( m_titleFont ); + m_titleStaticText->SetForegroundColour( m_titleColour ); + + //Create a sizer for the title. Prepend it to the Plot + Title sizer. + wxBoxSizer* titleSizer = new wxBoxSizer( wxHORIZONTAL ); + titleSizer->Add( m_titleStaticText, 0, wxALIGN_CENTER | wxALL, 10 ); + m_plotAndTitleSizer->Prepend( titleSizer, 0, wxALIGN_CENTER_HORIZONTAL ); + + //Finally, force layout + m_plotAndTitleSizer->Layout(); + } +} + void wxPlotWindow::RedrawXAxis() { if (m_xaxis) - m_xaxis->Refresh( FALSE ); + m_xaxis->Refresh( true ); } void wxPlotWindow::RedrawYAxis() { if (m_yaxis) - m_yaxis->Refresh( TRUE ); + m_yaxis->Refresh( true ); } void wxPlotWindow::RedrawEverything() { if (m_xaxis) - m_xaxis->Refresh( TRUE ); + m_xaxis->Refresh( true ); if (m_yaxis) - m_yaxis->Refresh( TRUE ); - m_area->Refresh( TRUE ); + m_yaxis->Refresh( true ); + m_area->Refresh( true ); + + DrawChartTitle(); } void wxPlotWindow::OnZoomIn( wxCommandEvent& WXUNUSED(event) ) @@ -1014,14 +1060,14 @@ void wxPlotWindow::OnZoomOut( wxCommandEvent& WXUNUSED(event) ) void wxPlotWindow::OnEnlarge( wxCommandEvent& WXUNUSED(event) ) { if (!m_current) return; - + Enlarge( m_current, 1.5 ); } void wxPlotWindow::OnShrink( wxCommandEvent& WXUNUSED(event) ) { if (!m_current) return; - + Enlarge( m_current, 0.6666666 ); } @@ -1042,14 +1088,14 @@ void wxPlotWindow::OnScroll2( wxScrollWinEvent& event ) static wxBitmap *GetEnlargeBitmap() { static wxBitmap* s_bitmap = (wxBitmap *) NULL; - static bool s_loaded = FALSE; + static bool s_loaded = false; if ( !s_loaded ) { - s_loaded = TRUE; // set it to TRUE anyhow, we won't try again + s_loaded = true; // set it to true anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_enl_bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap(_T("plot_enl_bmp"), wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_enl_xpm ); #endif @@ -1061,14 +1107,14 @@ static wxBitmap *GetEnlargeBitmap() static wxBitmap *GetShrinkBitmap() { static wxBitmap* s_bitmap = (wxBitmap *) NULL; - static bool s_loaded = FALSE; + static bool s_loaded = false; if ( !s_loaded ) { - s_loaded = TRUE; // set it to TRUE anyhow, we won't try again + s_loaded = true; // set it to true anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_shr_bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap(_T("plot_shr_bmp"), wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_shr_xpm ); #endif @@ -1080,14 +1126,14 @@ static wxBitmap *GetShrinkBitmap() static wxBitmap *GetZoomInBitmap() { static wxBitmap* s_bitmap = (wxBitmap *) NULL; - static bool s_loaded = FALSE; + static bool s_loaded = false; if ( !s_loaded ) { - s_loaded = TRUE; // set it to TRUE anyhow, we won't try again + s_loaded = true; // set it to true anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_zin_bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap(_T("plot_zin_bmp"), wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_zin_xpm ); #endif @@ -1099,14 +1145,14 @@ static wxBitmap *GetZoomInBitmap() static wxBitmap *GetZoomOutBitmap() { static wxBitmap* s_bitmap = (wxBitmap *) NULL; - static bool s_loaded = FALSE; + static bool s_loaded = false; if ( !s_loaded ) { - s_loaded = TRUE; // set it to TRUE anyhow, we won't try again + s_loaded = true; // set it to true anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_zot_bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap(_T("plot_zot_bmp"), wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_zot_xpm ); #endif @@ -1118,14 +1164,14 @@ static wxBitmap *GetZoomOutBitmap() static wxBitmap *GetUpBitmap() { static wxBitmap* s_bitmap = (wxBitmap *) NULL; - static bool s_loaded = FALSE; + static bool s_loaded = false; if ( !s_loaded ) { - s_loaded = TRUE; // set it to TRUE anyhow, we won't try again + s_loaded = true; // set it to true anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_up_bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap(_T("plot_up_bmp"), wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_up_xpm ); #endif @@ -1137,14 +1183,14 @@ static wxBitmap *GetUpBitmap() static wxBitmap *GetDownBitmap() { static wxBitmap* s_bitmap = (wxBitmap *) NULL; - static bool s_loaded = FALSE; + static bool s_loaded = false; if ( !s_loaded ) { - s_loaded = TRUE; // set it to TRUE anyhow, we won't try again + s_loaded = true; // set it to true anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_dwn_bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap(_T("plot_dwn_bmp"), wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_dwn_xpm ); #endif @@ -1153,52 +1199,3 @@ static wxBitmap *GetDownBitmap() return s_bitmap; } - -//---------------------------------------------------------------------------- -// wxPlotModule -//---------------------------------------------------------------------------- - -class wxPlotModule : public wxModule -{ -public: - bool OnInit(); - void OnExit(); - -private: - DECLARE_CLASS(wxPlotModule) -}; - -IMPLEMENT_DYNAMIC_CLASS(wxPlotModule, wxModule) - -bool wxPlotModule::OnInit() -{ - wxEVT_PLOT_SEL_CHANGING = wxNewId(); - wxEVT_PLOT_SEL_CHANGED = wxNewId(); - wxEVT_PLOT_CLICKED = wxNewId(); - wxEVT_PLOT_DOUBLECLICKED = wxNewId(); - wxEVT_PLOT_ZOOM_IN = wxNewId(); - wxEVT_PLOT_ZOOM_OUT = wxNewId(); - wxEVT_PLOT_VALUE_SEL_CREATING = wxNewId(); - wxEVT_PLOT_VALUE_SEL_CREATED = wxNewId(); - wxEVT_PLOT_VALUE_SEL_CHANGING = wxNewId(); - wxEVT_PLOT_VALUE_SEL_CHANGED = wxNewId(); - wxEVT_PLOT_AREA_SEL_CREATING = wxNewId(); - wxEVT_PLOT_AREA_SEL_CREATED = wxNewId(); - wxEVT_PLOT_AREA_SEL_CHANGING = wxNewId(); - wxEVT_PLOT_AREA_SEL_CHANGED = wxNewId(); - wxEVT_PLOT_BEGIN_X_LABEL_EDIT = wxNewId(); - wxEVT_PLOT_END_X_LABEL_EDIT = wxNewId(); - wxEVT_PLOT_BEGIN_Y_LABEL_EDIT = wxNewId(); - wxEVT_PLOT_END_Y_LABEL_EDIT = wxNewId(); - wxEVT_PLOT_BEGIN_TITLE_EDIT = wxNewId(); - wxEVT_PLOT_END_TITLE_EDIT = wxNewId(); - wxEVT_PLOT_AREA_CREATE = wxNewId(); - - return TRUE; -} - -void wxPlotModule::OnExit() -{ -} - -