X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2d1df0fc585f03cca4b194d1f9159b49a5711da6..b3ecee8d120ac8af59cbf82b00d4c7da9f648f53:/samples/docview/view.cpp diff --git a/samples/docview/view.cpp b/samples/docview/view.cpp index d27e3f6a20..6129bac8a3 100644 --- a/samples/docview/view.cpp +++ b/samples/docview/view.cpp @@ -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; +} +