MutDocument.cpp
gehe zur Dokumentation dieser Datei
00001 
00043 // availlable groups: GUI, route, kernel, muwx, debug
00044 
00045 // ---------------------------------------------------------------------------
00046 // headers
00047 // ---------------------------------------------------------------------------
00048 
00049 // For compilers that support precompilation, includes "wx/wx.h".
00050 #include "Defs.h"
00051 #include <wx/wxprec.h>
00052 
00053 #ifdef __BORLANDC__
00054 #pragma hdrstop
00055 #endif
00056 
00057 #include "MutDocument.h"
00058 #include "MutView.h"
00059 #include "MutApp.h"
00060 #include <wx/debug.h>
00061 
00062 #include <cstdio>
00063 #include <iostream>
00064 
00065 using mutaborGUI::MutDocument;
00066 IMPLEMENT_DYNAMIC_CLASS(MutDocument, wxDocument)
00067 
00068 BEGIN_EVENT_TABLE(MutDocument, wxDocument)
00069 //      EVT_MENU(ID_NewViewFrame, MutDocument::CmdNewView)
00070 //      EVT_UPDATE_UI(ID_NewViewFrame, MutDocument::OnNewViewUpdateUI)
00071 //      EVT_MENU(ID_UpdateAllViews, MutDocument::CmdUpdateAllViews)
00072 END_EVENT_TABLE()
00073 
00074 namespace mutaborGUI {
00075 
00076         MutDocument::MutDocument():wxDocument()
00077         {
00078 
00079 
00080         }
00081 
00082         MutDocument::~MutDocument()
00083         {
00084 
00085         }
00086 
00087 
00088         bool MutDocument::DoSaveDocument(const wxString& filename)
00089         {
00090                 MutView *view = (MutView *)GetFirstView();
00091 
00092                 if (!view->GetTextsw()->SaveFile(filename))
00093                         return false;
00094 
00095                 return true;
00096         }
00097 
00098         bool MutDocument::DoOpenDocument(const wxString& filename)
00099         {
00100                 MutView *view = (MutView *)GetFirstView();
00101                 if (!view->GetTextsw()->LoadFile(filename))
00102                         return false;
00103                 DEBUGLOG(docview,_T("New title: ")+GetDocumentManager()->MakeFrameTitle(this));
00104                 MutFrame * frame = view->GetMutFrame();
00105                 if (frame)
00106                         frame->SetTitle(GetDocumentManager()->MakeFrameTitle(this));
00107                 return true;
00108         }
00109 
00110         bool MutDocument::OnNewDocument() 
00111         {
00112                 if (!wxDocument::OnNewDocument()) 
00113                         return false;
00114                 DEBUGLOG(docview,_T("New title: ")+GetDocumentManager()->MakeFrameTitle(this));
00115                 
00116                 
00117                 MutView *view = (MutView *)GetFirstView();
00118                 if (view) {
00119                         MutFrame * frame = view -> GetMutFrame();
00120                         if (frame)
00121                                 frame -> SetTitle(GetDocumentManager()->MakeFrameTitle(this));
00122                 } 
00123                 return true;
00124         }
00125 
00126 #if wxUSE_STD_IOSTREAM
00127 
00128         wxSTD ostream& MutDocument::SaveObject(wxSTD ostream& stream)
00129         {
00130                 printf("cmydoc::saveobject\n");
00131                 stream << 5;
00132                 stream << 'j';
00133                 return stream;
00134         }
00135 
00136         wxSTD istream& MutDocument::LoadObject(wxSTD istream& stream)
00137         {
00138                 DEBUGLOG(docview,_T(""));
00139                 bool bOK(false);
00140                 int nA(0);
00141                 char ch(0);
00142 
00143                 stream >> nA;
00144                 stream >> ch;
00145 
00146                 if(stream.good())
00147                 {
00148                         DEBUGLOG(docview,_T("num is %d and char is %c"), nA, ch);
00149                         bOK = true;
00150                 }
00151 
00152                 if(bOK == false)
00153                 {
00154                         DEBUGLOG(docview,_T("load error"));
00155                         // tell the framework to abort the load procedure
00156                         stream.clear(std::ios_base::badbit);
00157                 }
00158                 return stream;
00159         }
00160 
00161 #else
00162 
00163         wxOutputStream& MutDocument::SaveObject(wxOutputStream& stream)
00164         {
00165                 printf("mydoc::saveobject()\n");
00166                 return stream;
00167         }
00168 
00169         wxInputStream& MutDocument::LoadObject(wxInputStream& stream)
00170         {
00171                 printf("mydoc::loadobject()\n");
00172                 return stream;
00173         }
00174 
00175 #endif
00176 
00177         bool MutDocument::OnCreate(const wxString& path, long flags)
00178         {
00179 
00180                 // you should call the one in the superclass
00181                 return wxDocument::OnCreate(path, flags);
00182         }
00183 
00184         bool MutDocument::IsModified(void) const
00185         {
00186                 MutView *view = (MutView *)GetFirstView();
00187                 if (view && view -> GetTextsw())
00188                 {
00189                         return (wxDocument::IsModified() || view->GetTextsw()->IsModified());
00190                 }
00191                 else
00192                         return wxDocument::IsModified();
00193         }
00194 
00195         void MutDocument::Modify(bool mod)
00196         {
00197                 MutView *view = (MutView *)GetFirstView();
00198 
00199                 wxDocument::Modify(mod);
00200 
00201                 if (!mod && view && view->GetTextsw())
00202                         view->GetTextsw()->SetSavePoint();
00203         }
00204 
00205         void MutDocument::CmdNewView(wxCommandEvent& event)
00206         {
00207                 printf("MutDocument::CmdNewView\n");
00208                 //wxMessageBox(wxT("doc newview 1"), _T("dialog"), wxOK | wxICON_INFORMATION, NULL);
00209 
00210                 //  we manually create a view, and register it with the document.
00211                 // the view needs to create a window for itself, which 
00212                 //  it can do in OnCreate
00213                 MutView* pview = new MutView();
00214                 bool bKeep = pview->OnCreate(NULL, 0);
00215                 if(bKeep)
00216                 {
00217                         AddView(pview);
00218                         // we could set the title of the view's frame
00219                         // AddView() does not set the document in the view, so we do that now
00220                         pview->SetDocument(this);
00221                 }
00222                 else
00223                 {
00224                         // kill the view and its window. Hopefully nothing else.
00225                         pview->Close(TRUE);
00226                         // I don't think the Close function works
00227                         wxFAIL;
00228                 }       
00229 
00230                 // wxMessageBox(wxT("doc newview 2"), _T("dialog"), wxOK | wxICON_INFORMATION, NULL);
00231 
00232 
00233         }
00234 
00235         void MutDocument::CmdUpdateAllViews(wxCommandEvent& event)
00236         {
00237                 UpdateAllViews();
00238         }
00239 
00240         void MutDocument::OnNewViewUpdateUI(wxUpdateUIEvent& event)
00241         {
00242                 event.Enable(true);
00243                 // printf("MutDocument::OnNewViewUpdateUI\n");
00244         }
00245 
00246         
00247 }
00248 
00249 

Erzeugt am Sun Aug 21 2011 10:51:54 für Mutabor von doxygen 1.7.4