]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/docview/doc.cpp
Make it easier to define custom wxSizerXmlHandler subclasses.
[wxWidgets.git] / samples / docview / doc.cpp
index f43bbb1c13c93ebc10bc67c8923567b2ab682178..713a76d569786199611053feb0e2419740d505e7 100644 (file)
@@ -7,7 +7,7 @@
 // RCS-ID:      $Id$
 // Copyright:   (c) 1998 Julian Smart
 //              (c) 2008 Vadim Zeitlin
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ----------------------------------------------------------------------------
@@ -34,6 +34,7 @@
 #else
     #include "wx/txtstrm.h"
 #endif
+#include "wx/wfstream.h"
 
 #include "doc.h"
 #include "view.h"
@@ -176,6 +177,24 @@ DocumentIstream& DoodleSegment::LoadObject(DocumentIstream& istream)
 
 IMPLEMENT_CLASS(wxTextDocument, wxDocument)
 
+bool wxTextDocument::OnCreate(const wxString& path, long flags)
+{
+    if ( !wxDocument::OnCreate(path, flags) )
+        return false;
+
+    // subscribe to changes in the text control to update the document state
+    // when it's modified
+    GetTextCtrl()->Connect
+    (
+        wxEVT_COMMAND_TEXT_UPDATED,
+        wxCommandEventHandler(wxTextDocument::OnTextChange),
+        NULL,
+        this
+    );
+
+    return true;
+}
+
 // Since text windows have their own method for saving to/loading from files,
 // we override DoSave/OpenDocument instead of Save/LoadObject
 bool wxTextDocument::DoSaveDocument(const wxString& filename)
@@ -185,7 +204,13 @@ bool wxTextDocument::DoSaveDocument(const wxString& filename)
 
 bool wxTextDocument::DoOpenDocument(const wxString& filename)
 {
-    return GetTextCtrl()->LoadFile(filename);
+    if ( !GetTextCtrl()->LoadFile(filename) )
+        return false;
+
+    // we're not modified by the user yet
+    Modify(false);
+
+    return true;
 }
 
 bool wxTextDocument::IsModified() const
@@ -205,6 +230,13 @@ void wxTextDocument::Modify(bool modified)
     }
 }
 
+void wxTextDocument::OnTextChange(wxCommandEvent& event)
+{
+    Modify(true);
+
+    event.Skip();
+}
+
 // ----------------------------------------------------------------------------
 // TextEditDocument implementation
 // ----------------------------------------------------------------------------
@@ -216,3 +248,15 @@ wxTextCtrl* TextEditDocument::GetTextCtrl() const
     wxView* view = GetFirstView();
     return view ? wxStaticCast(view, TextEditView)->GetText() : NULL;
 }
+
+// ----------------------------------------------------------------------------
+// ImageDocument and wxImageDetailsDocument implementation
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(ImageDocument, wxDocument)
+
+bool ImageDocument::DoOpenDocument(const wxString& file)
+{
+    return m_image.LoadFile(file);
+}
+