]>
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
& stream
)
49 wxDocument::SaveObject(stream
);
51 const wxInt32 count
= m_doodleSegments
.size();
52 stream
<< count
<< '\n';
54 for ( int n
= 0; n
< count
; n
++ )
56 m_doodleSegments
[n
].SaveObject(stream
);
63 DocumentIstream
& DrawingDocument::LoadObject(DocumentIstream
& stream
)
65 wxDocument::LoadObject(stream
);
70 for ( int n
= 0; n
< count
; n
++ )
72 DoodleSegment segment
;
73 segment
.LoadObject(stream
);
74 m_doodleSegments
.push_back(segment
);
80 void DrawingDocument::DoUpdate()
86 void DrawingDocument::AddDoodleSegment(const DoodleSegment
& segment
)
88 m_doodleSegments
.push_back(segment
);
93 bool DrawingDocument::PopLastSegment(DoodleSegment
*segment
)
95 if ( m_doodleSegments
.empty() )
99 *segment
= m_doodleSegments
.back();
101 m_doodleSegments
.pop_back();
108 // ----------------------------------------------------------------------------
109 // DoodleSegment implementation
110 // ----------------------------------------------------------------------------
112 DocumentOstream
& DoodleSegment::SaveObject(DocumentOstream
& ostream
)
114 #if wxUSE_STD_IOSTREAM
115 DocumentOstream
& stream
= ostream
;
117 wxTextOutputStream
stream(ostream
);
120 const wxInt32 count
= m_lines
.size();
121 stream
<< count
<< '\n';
123 for ( int n
= 0; n
< count
; n
++ )
125 const DoodleLine
& line
= m_lines
[n
];
136 DocumentIstream
& DoodleSegment::LoadObject(DocumentIstream
& istream
)
138 #if wxUSE_STD_IOSTREAM
139 DocumentIstream
& stream
= istream
;
141 wxTextInputStream
stream(istream
);
147 for ( int n
= 0; n
< count
; n
++ )
155 m_lines
.push_back(line
);
161 // ----------------------------------------------------------------------------
162 // TextEditDocument implementation
163 // ----------------------------------------------------------------------------
165 IMPLEMENT_DYNAMIC_CLASS(TextEditDocument
, wxDocument
)
167 // Since text windows have their own method for saving to/loading from files,
168 // we override DoSave/OpenDocument instead of Save/LoadObject
169 bool TextEditDocument::DoSaveDocument(const wxString
& filename
)
171 return GetFirstView()->GetText()->SaveFile(filename
);
174 bool TextEditDocument::DoOpenDocument(const wxString
& filename
)
176 return GetFirstView()->GetText()->LoadFile(filename
);
179 bool TextEditDocument::IsModified() const
181 TextEditView
* view
= GetFirstView();
182 return wxDocument::IsModified() || (view
&& view
->GetText()->IsModified());
185 void TextEditDocument::Modify(bool modified
)
187 TextEditView
* view
= GetFirstView();
189 wxDocument::Modify(modified
);
191 if ( !modified
&& view
&& view
->GetText() )
192 view
->GetText()->DiscardEdits();
195 TextEditView
* TextEditDocument::GetFirstView() const
197 wxView
* view
= wxDocument::GetFirstView();
198 return view
? wxStaticCast(view
, TextEditView
) : NULL
;