+int wxVectorCanvas::LogicalToDeviceY(double y) const
+{
+ return (int) (m_mapping_matrix.GetValue(1,1) * y + m_mapping_matrix.GetValue(2,1) + 0.5);
+}
+
+int wxVectorCanvas::LogicalToDeviceXRel(double x) const
+{
+ return (int) (x*m_mapping_matrix.GetValue(0,0) + 0.5);
+}
+
+int wxVectorCanvas::LogicalToDeviceYRel(double y) const
+{
+ return (int) (y*m_mapping_matrix.GetValue(1,1) + 0.5);
+}
+
+
+// return the inverse mapping matrix for zooming or coordinates
+wxTransformMatrix wxVectorCanvas::GetInverseMappingMatrix()
+{
+ return m_inverse_mapping;
+}
+
+wxTransformMatrix wxVectorCanvas::GetMappingMatrix()
+{
+ return m_mapping_matrix;
+}
+
+
+// ----------------------------------------------------------------------------
+// scrolling behaviour
+// ----------------------------------------------------------------------------
+
+void wxVectorCanvas::OnScroll(wxScrollWinEvent& event)
+{
+ if (event.GetEventType()==wxEVT_SCROLLWIN_THUMBRELEASE)
+ {
+ if (event.GetOrientation()==wxHORIZONTAL)
+ {
+ double x=m_virtm_minX+event.GetPosition()/1000.0*(m_virtm_maxX-m_virtm_minX);
+ x=LogicalToDeviceXRel(x-m_virt_minX);
+ ScrollWindow(-x, 0, (const wxRect *) NULL);
+ }
+ else
+ {
+ double y=m_virtm_minY+event.GetPosition()/1000.0*(m_virtm_maxY-m_virtm_minY);
+ y=LogicalToDeviceYRel(y-m_virt_minY);
+ ScrollWindow(0, -y, (const wxRect *) NULL);
+ }
+ }
+ else if (event.GetEventType()==wxEVT_SCROLLWIN_PAGEUP)
+ {
+ if (event.GetOrientation()==wxHORIZONTAL)
+ {
+ double x=GetBufferWidth();
+ ScrollWindow(x, 0, (const wxRect *) NULL);
+ }
+ else
+ {
+ double y=GetBufferHeight();
+ ScrollWindow(0, y, (const wxRect *) NULL);
+ }
+ }
+ else if (event.GetEventType()==wxEVT_SCROLLWIN_PAGEDOWN)
+ {
+ if (event.GetOrientation()==wxHORIZONTAL)
+ {
+ double x=-GetBufferWidth();
+ ScrollWindow(x, 0, (const wxRect *) NULL);
+ }
+ else
+ {
+ double y=-GetBufferHeight();
+ ScrollWindow(0, y, (const wxRect *) NULL);
+ }
+ }
+ else if (event.GetEventType()==wxEVT_SCROLLWIN_LINEUP)
+ {
+ if (event.GetOrientation()==wxHORIZONTAL)
+ {
+ int x=GetBufferWidth()/10;
+ ScrollWindow(x, 0, (const wxRect *) NULL);
+ }
+ else
+ {
+ int y=GetBufferHeight()/10;
+ ScrollWindow(0, y, (const wxRect *) NULL);
+ }
+ }
+ else if (event.GetEventType()==wxEVT_SCROLLWIN_LINEDOWN)
+ {
+ if (event.GetOrientation()==wxHORIZONTAL)
+ {
+ int x=-GetBufferWidth()/10;
+ ScrollWindow(x, 0, (const wxRect *) NULL);
+ }
+ else
+ {
+ int y=-GetBufferHeight()/10;
+ ScrollWindow(0, y, (const wxRect *) NULL);
+ }
+ }
+
+}
+
+void wxVectorCanvas::OnChar(wxKeyEvent& event)
+{
+ switch ( event.KeyCode() )
+ {
+ case WXK_PAGEUP:
+ case WXK_PRIOR:
+ {
+ double y=GetBufferHeight();
+ ScrollWindow(0, y, (const wxRect *) NULL);
+ }
+ break;
+ case WXK_PAGEDOWN:
+ case WXK_NEXT:
+ {
+ double y=-GetBufferHeight();
+ ScrollWindow(0, y, (const wxRect *) NULL);
+ }
+ break;
+ case WXK_HOME:
+ {
+ double y=m_virtm_minY;
+ y=LogicalToDeviceYRel(y-m_virt_minY);
+ ScrollWindow(0, -y, (const wxRect *) NULL);
+ }
+ break;
+ case WXK_END:
+ {
+ double y=m_virtm_minY+(m_virtm_maxY-m_virtm_minY);
+ y=LogicalToDeviceYRel(y-m_virt_minY);
+ ScrollWindow(0, -y, (const wxRect *) NULL);
+ }
+ break;
+ case WXK_UP:
+ {
+ int y;
+ if (!event.ControlDown())
+ y=GetBufferHeight()/10;
+ else
+ y=GetBufferHeight();
+ ScrollWindow(0, y, (const wxRect *) NULL);
+ }
+ break;
+
+ case WXK_DOWN:
+ {
+ int y;
+ if (!event.ControlDown())
+ y=-GetBufferHeight()/10;
+ else
+ y=-GetBufferHeight();
+ ScrollWindow(0, y, (const wxRect *) NULL);
+ }
+ break;
+
+ case WXK_LEFT:
+ {
+ int x;
+ if (!event.ControlDown())
+ x=GetBufferWidth()/10;
+ else
+ x=GetBufferWidth();
+ ScrollWindow(x, 0, (const wxRect *) NULL);
+ }
+ break;
+ case WXK_RIGHT:
+ {
+ int x;
+ if (!event.ControlDown())
+ x=-GetBufferWidth()/10;
+ else
+ x=-GetBufferWidth();
+ ScrollWindow(x, 0, (const wxRect *) NULL);
+ }
+ break;
+ default:
+ // not for us
+ event.Skip();
+ }
+}
+
+
+//----------------------------------------------------------------------------
+// wxCanvasAdmin
+//----------------------------------------------------------------------------
+
+wxCanvasAdmin::wxCanvasAdmin()
+{
+
+}
+
+wxCanvasAdmin::~wxCanvasAdmin()
+{
+}
+
+
+void wxCanvasAdmin::Append( wxCanvas* canvas )
+{
+ m_canvaslist.Append( canvas );
+}
+
+void wxCanvasAdmin::Remove( wxCanvas* canvas )
+{
+ m_canvaslist.DeleteObject( canvas );
+}
+
+void wxCanvasAdmin::Update(wxCanvasObject* obj, double x, double y, double width, double height)
+{
+ wxNode *node = m_canvaslist.First();
+ while (node)
+ {
+
+ wxCanvas *canvas = (wxCanvas*) node->Data();
+
+ if (m_active == canvas)
+ {
+ int xi = canvas->LogicalToDeviceX( x);
+ int yi = canvas->LogicalToDeviceY( y);
+ int wi = canvas->LogicalToDeviceXRel( width );
+ int hi = canvas->LogicalToDeviceYRel( height);
+ //update a little more then is strictly needed,
+ //to get rid of the 1 bit bugs
+ if (canvas->GetYaxis())
+ canvas->Update( xi-2, yi+hi-2, wi+4, -hi+4);
+ else
+ canvas->Update( xi-2, yi-2, wi+4, hi+4);
+ }
+ else
+ { wxCanvasObject* topobj=canvas->GetRoot()->Contains(obj);
+ if (topobj)
+ {
+ wxCanvas* tcanvas = m_active;
+ SetActive(canvas);
+
+ /*
+ //KKK TODO somehow the next does not work for update i do not know why
+ canvas->GetRoot()->CalcBoundingBox();
+ int xi = topobj->GetX();
+ int yi = topobj->GetY();
+ int wi = topobj->GetWidth();
+ int hi = topobj->GetHeight();
+ */
+ canvas->Update( 0,0, canvas->GetBufferWidth(),canvas->GetBufferHeight());
+ SetActive(tcanvas);
+ }
+ }
+
+ node = node->Next();
+ }
+}
+
+void wxCanvasAdmin::UpdateNow()
+{
+ wxNode *node = m_canvaslist.First();
+ while (node)
+ {
+ wxCanvas *canvas = (wxCanvas*) node->Data();
+
+ canvas->UpdateNow();
+ node = node->Next();
+ }
+}
+
+// coordinates conversions
+// -----------------------
+double wxCanvasAdmin::DeviceToLogicalX(int x) const
+{
+ return m_active->DeviceToLogicalX(x);
+}
+
+double wxCanvasAdmin::DeviceToLogicalY(int y) const
+{
+ return m_active->DeviceToLogicalY(y);
+}
+
+double wxCanvasAdmin::DeviceToLogicalXRel(int x) const
+{
+ return m_active->DeviceToLogicalXRel(x);
+}
+
+double wxCanvasAdmin::DeviceToLogicalYRel(int y) const
+{
+ return m_active->DeviceToLogicalYRel(y);
+}
+
+int wxCanvasAdmin::LogicalToDeviceX(double x) const
+{
+ return m_active->LogicalToDeviceX(x);
+}
+
+int wxCanvasAdmin::LogicalToDeviceY(double y) const
+{
+ return m_active->LogicalToDeviceY(y);
+}
+
+int wxCanvasAdmin::LogicalToDeviceXRel(double x) const
+{
+ return m_active->LogicalToDeviceXRel(x);
+}
+
+int wxCanvasAdmin::LogicalToDeviceYRel(double y) const
+{
+ return m_active->LogicalToDeviceYRel(y);
+}
+
+void wxCanvasAdmin::SetActive(wxCanvas* activate)
+{
+ wxNode *node = m_canvaslist.First();
+ while (node)
+ {
+ wxCanvas *canvas = (wxCanvas*) node->Data();
+
+ if (activate == canvas)
+ {
+ m_active=canvas;
+ break;
+ }
+ node = node->Next();
+ }
+}