]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/docview/view.cpp
To make it clear in the sample that a custom animation is used, use wxSHOW_EFFECT_BLE...
[wxWidgets.git] / samples / docview / view.cpp
index d27e3f6a20f7a0a67a3ecc768f7398508c733f02..ff24096c08ee2ef8b9f1b867c8a5dff9e29d2654 100644 (file)
@@ -104,8 +104,9 @@ DrawingDocument* DrawingView::GetDocument()
     return wxStaticCast(wxView::GetDocument(), DrawingDocument);
 }
 
-void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
+void DrawingView::OnUpdate(wxView* sender, wxObject* hint)
 {
+    wxView::OnUpdate(sender, hint);
     if ( m_canvas )
         m_canvas->Refresh();
 }
@@ -282,3 +283,82 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
     m_lastMousePos = pt;
 }
 
+// ----------------------------------------------------------------------------
+// ImageCanvas implementation
+// ----------------------------------------------------------------------------
+
+// Define a constructor for my canvas
+ImageCanvas::ImageCanvas(wxView* view, wxWindow* parent)
+    : wxScrolledWindow(parent, wxID_ANY, wxPoint(0, 0), parent->GetClientSize())
+{
+    SetScrollRate( 10, 10 );
+
+    m_view = view;
+}
+
+// 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 WXUNUSED(flags))
+{
+    m_frame = wxGetApp().CreateChildFrame(doc, this, false);
+    m_frame->SetTitle("Image View");
+    m_canvas = new ImageCanvas(this, m_frame);
+    m_frame->Show(true);
+    Activate(true);
+    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);
+    }
+}
+
+bool ImageView::OnClose(bool deleteWindow)
+{
+    if ( !GetDocument()->Close() )
+        return false;
+
+    Activate(false);
+
+    if ( wxGetApp().GetMode() == MyApp::Mode_Single )
+    {
+        GetDocument()->DeleteContents();
+    }
+    else // not single window mode
+    {
+        if ( deleteWindow )
+            wxDELETE(m_frame);
+    }
+    return true;
+}
+