]>
git.saurik.com Git - wxWidgets.git/blob - samples/docview/doc.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/docview/doc.cpp
3 // Purpose: Implements document functionality
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin: merge with the MDI version and general cleanup
8 // Copyright: (c) 1998 Julian Smart
9 // (c) 2008 Vadim Zeitlin
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
24 #if !wxUSE_DOC_VIEW_ARCHITECTURE
25 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
32 #if wxUSE_STD_IOSTREAM
33 #include "wx/ioswrap.h"
35 #include "wx/txtstrm.h"
41 // ----------------------------------------------------------------------------
42 // DrawingDocument implementation
43 // ----------------------------------------------------------------------------
45 IMPLEMENT_DYNAMIC_CLASS(DrawingDocument
, wxDocument
)
47 DocumentOstream
& DrawingDocument::SaveObject(DocumentOstream
& ostream
)
49 #if wxUSE_STD_IOSTREAM
50 DocumentOstream
& stream
= ostream
;
52 wxTextOutputStream
stream(ostream
);
55 wxDocument::SaveObject(ostream
);
57 const wxInt32 count
= m_doodleSegments
.size();
58 stream
<< count
<< '\n';
60 for ( int n
= 0; n
< count
; n
++ )
62 m_doodleSegments
[n
].SaveObject(ostream
);
69 DocumentIstream
& DrawingDocument::LoadObject(DocumentIstream
& istream
)
71 #if wxUSE_STD_IOSTREAM
72 DocumentIstream
& stream
= istream
;
74 wxTextInputStream
stream(istream
);
77 wxDocument::LoadObject(istream
);
82 for ( int n
= 0; n
< count
; n
++ )
84 DoodleSegment segment
;
85 segment
.LoadObject(istream
);
86 m_doodleSegments
.push_back(segment
);
92 void DrawingDocument::DoUpdate()
98 void DrawingDocument::AddDoodleSegment(const DoodleSegment
& segment
)
100 m_doodleSegments
.push_back(segment
);
105 bool DrawingDocument::PopLastSegment(DoodleSegment
*segment
)
107 if ( m_doodleSegments
.empty() )
111 *segment
= m_doodleSegments
.back();
113 m_doodleSegments
.pop_back();
120 // ----------------------------------------------------------------------------
121 // DoodleSegment implementation
122 // ----------------------------------------------------------------------------
124 DocumentOstream
& DoodleSegment::SaveObject(DocumentOstream
& ostream
)
126 #if wxUSE_STD_IOSTREAM
127 DocumentOstream
& stream
= ostream
;
129 wxTextOutputStream
stream(ostream
);
132 const wxInt32 count
= m_lines
.size();
133 stream
<< count
<< '\n';
135 for ( int n
= 0; n
< count
; n
++ )
137 const DoodleLine
& line
= m_lines
[n
];
148 DocumentIstream
& DoodleSegment::LoadObject(DocumentIstream
& istream
)
150 #if wxUSE_STD_IOSTREAM
151 DocumentIstream
& stream
= istream
;
153 wxTextInputStream
stream(istream
);
159 for ( int n
= 0; n
< count
; n
++ )
167 m_lines
.push_back(line
);
173 // ----------------------------------------------------------------------------
174 // wxTextDocument: wxDocument and wxTextCtrl married
175 // ----------------------------------------------------------------------------
177 IMPLEMENT_CLASS(wxTextDocument
, wxDocument
)
179 // Since text windows have their own method for saving to/loading from files,
180 // we override DoSave/OpenDocument instead of Save/LoadObject
181 bool wxTextDocument::DoSaveDocument(const wxString
& filename
)
183 return GetTextCtrl()->SaveFile(filename
);
186 bool wxTextDocument::DoOpenDocument(const wxString
& filename
)
188 return GetTextCtrl()->LoadFile(filename
);
191 bool wxTextDocument::IsModified() const
193 wxTextCtrl
* wnd
= GetTextCtrl();
194 return wxDocument::IsModified() || (wnd
&& wnd
->IsModified());
197 void wxTextDocument::Modify(bool modified
)
199 wxDocument::Modify(modified
);
201 wxTextCtrl
* wnd
= GetTextCtrl();
202 if (wnd
&& !modified
)
208 // ----------------------------------------------------------------------------
209 // TextEditDocument implementation
210 // ----------------------------------------------------------------------------
212 IMPLEMENT_DYNAMIC_CLASS(TextEditDocument
, wxDocument
)
214 wxTextCtrl
* TextEditDocument::GetTextCtrl() const
216 wxView
* view
= GetFirstView();
217 return view
? wxStaticCast(view
, TextEditView
)->GetText() : NULL
;