+
+ wxDELETE(m_currentSegment);
+ }
+
+ // is this the start of a new segment?
+ if ( m_lastMousePos != wxDefaultPosition && event.Dragging() )
+ {
+ if ( !m_currentSegment )
+ m_currentSegment = new DoodleSegment;
+
+ m_currentSegment->AddLine(m_lastMousePos, pt);
+
+ dc.DrawLine(m_lastMousePos, pt);
+ }
+
+ m_lastMousePos = pt;
+}
+
+// ----------------------------------------------------------------------------
+// ImageCanvas implementation
+// ----------------------------------------------------------------------------
+
+// Define a constructor for my canvas
+ImageCanvas::ImageCanvas(wxView* view)
+ : wxScrolledWindow(view->GetFrame())
+{
+ m_view = view;
+ SetScrollRate( 10, 10 );
+}
+
+// Define the repainting behaviour
+void ImageCanvas::OnDraw(wxDC& dc)
+{
+ if ( m_view )
+ m_view->OnDraw(& dc);
+}
+
+// ----------------------------------------------------------------------------
+// ImageView implementation
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(ImageView, wxView)
+
+ImageDocument* ImageView::GetDocument()
+{
+ return wxStaticCast(wxView::GetDocument(), ImageDocument);
+}
+
+bool ImageView::OnCreate(wxDocument* doc, long flags)
+{
+ if ( !wxView::OnCreate(doc, flags) )
+ return false;
+
+ wxFrame* frame = wxGetApp().CreateChildFrame(this, false);
+ wxASSERT(frame == GetFrame());
+ m_canvas = new ImageCanvas(this);
+ frame->Show();
+
+ return true;
+}
+
+void ImageView::OnUpdate(wxView* sender, wxObject* hint)
+{
+ wxView::OnUpdate(sender, hint);
+ wxImage image = GetDocument()->GetImage();
+ if ( image.IsOk() )
+ {
+ m_canvas->SetVirtualSize(image.GetWidth(), image.GetHeight());
+ }
+}
+
+void ImageView::OnDraw(wxDC* dc)
+{
+ wxImage image = GetDocument()->GetImage();
+ if ( image.IsOk() )
+ {
+ dc->DrawBitmap(wxBitmap(image), 0, 0, true /* use mask */);
+ }
+}
+
+bool ImageView::OnClose(bool deleteWindow)
+{
+ if ( !wxView::OnClose(deleteWindow) )
+ return false;
+
+ Activate(false);
+
+ if ( wxGetApp().GetMode() == MyApp::Mode_Single )
+ {
+ GetDocument()->DeleteContents();
+ }
+ else // not single window mode
+ {
+ if ( deleteWindow )