]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/docview/view.cpp
Also reset DatePicker property editor's global pointer (fixes #11787)
[wxWidgets.git] / samples / docview / view.cpp
index d27e3f6a20f7a0a67a3ecc768f7398508c733f02..6129bac8a36f69e119042dd474896244886a3e49 100644 (file)
@@ -7,7 +7,7 @@
 // RCS-ID:      $Id$
 // Copyright:   (c) 1998 Julian Smart
 //              (c) 2008 Vadim Zeitlin
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx/wx.h".
@@ -88,7 +88,7 @@ void DrawingView::OnDraw(wxDC *dc)
           ++i )
     {
         const DoodleLines& lines = i->GetLines();
-        for ( DoodleLines::const_iterator j = lines.begin(); 
+        for ( DoodleLines::const_iterator j = lines.begin();
               j != lines.end();
               ++j )
         {
@@ -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();
 }
@@ -113,7 +114,7 @@ void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
 // Clean up windows used for displaying the view.
 bool DrawingView::OnClose(bool deleteWindow)
 {
-    if ( !GetDocument()->Close() )
+    if ( !wxView::OnClose(deleteWindow) )
         return false;
 
     Activate(false);
@@ -180,7 +181,7 @@ void TextEditView::OnDraw(wxDC *WXUNUSED(dc))
 
 bool TextEditView::OnClose(bool deleteWindow)
 {
-    if ( !GetDocument()->Close() )
+    if ( !wxView::OnClose(deleteWindow) )
         return false;
 
     Activate(false);
@@ -264,8 +265,7 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
             doc->Modify(true);
         }
 
-        delete m_currentSegment;
-        m_currentSegment = NULL;
+        wxDELETE(m_currentSegment);
     }
 
     // is this the start of a new segment?
@@ -282,3 +282,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 ( !wxView::OnClose(deleteWindow) )
+        return false;
+
+    Activate(false);
+
+    if ( wxGetApp().GetMode() == MyApp::Mode_Single )
+    {
+        GetDocument()->DeleteContents();
+    }
+    else // not single window mode
+    {
+        if ( deleteWindow )
+            wxDELETE(m_frame);
+    }
+    return true;
+}
+