// wxWindows macros
// ----------------------------------------------------------------------------
-#if !USE_SHARED_LIBRARY
IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler)
IMPLEMENT_ABSTRACT_CLASS(wxView, wxEvtHandler)
IMPLEMENT_ABSTRACT_CLASS(wxDocTemplate, wxObject)
IMPLEMENT_CLASS(wxCommand, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxFileHistory, wxObject)
-#endif
// ----------------------------------------------------------------------------
// function prototypes
{
if (GetFrame() && GetDocument())
{
- wxString name;
- GetDocument()->GetPrintableName(name);
+ wxString title;
+
+ GetDocument()->GetPrintableName(title);
- GetFrame()->SetTitle(name);
+ GetFrame()->SetTitle(title);
}
}
EVT_MENU(wxID_SAVEAS, wxDocManager::OnFileSaveAs)
EVT_MENU(wxID_UNDO, wxDocManager::OnUndo)
EVT_MENU(wxID_REDO, wxDocManager::OnRedo)
+
+ EVT_UPDATE_UI(wxID_OPEN, wxDocManager::OnUpdateFileOpen)
+ EVT_UPDATE_UI(wxID_CLOSE, wxDocManager::OnUpdateFileClose)
+ EVT_UPDATE_UI(wxID_REVERT, wxDocManager::OnUpdateFileRevert)
+ EVT_UPDATE_UI(wxID_NEW, wxDocManager::OnUpdateFileNew)
+ EVT_UPDATE_UI(wxID_SAVE, wxDocManager::OnUpdateFileSave)
+ EVT_UPDATE_UI(wxID_SAVEAS, wxDocManager::OnUpdateFileSaveAs)
+ EVT_UPDATE_UI(wxID_UNDO, wxDocManager::OnUpdateUndo)
+ EVT_UPDATE_UI(wxID_REDO, wxDocManager::OnUpdateRedo)
+
#if wxUSE_PRINTING_ARCHITECTURE
EVT_MENU(wxID_PRINT, wxDocManager::OnPrint)
EVT_MENU(wxID_PRINT_SETUP, wxDocManager::OnPrintSetup)
EVT_MENU(wxID_PREVIEW, wxDocManager::OnPreview)
+
+ EVT_UPDATE_UI(wxID_PRINT, wxDocManager::OnUpdatePrint)
+ EVT_UPDATE_UI(wxID_PRINT_SETUP, wxDocManager::OnUpdatePrintSetup)
+ EVT_UPDATE_UI(wxID_PREVIEW, wxDocManager::OnUpdatePreview)
#endif
END_EVENT_TABLE()
+wxDocManager* wxDocManager::sm_docManager = (wxDocManager*) NULL;
+
wxDocManager::wxDocManager(long flags, bool initialize)
{
m_defaultDocumentNameCounter = 1;
m_fileHistory = (wxFileHistory *) NULL;
if (initialize)
Initialize();
+ sm_docManager = this;
}
wxDocManager::~wxDocManager()
Clear();
if (m_fileHistory)
delete m_fileHistory;
+ sm_docManager = (wxDocManager*) NULL;
}
bool wxDocManager::Clear(bool force)
void wxDocManager::OnFileOpen(wxCommandEvent& WXUNUSED(event))
{
- CreateDocument(wxString(""), 0);
+ if ( !CreateDocument(wxString(""), 0) )
+ {
+ OnOpenFileFailure();
+ }
}
void wxDocManager::OnFileRevert(wxCommandEvent& WXUNUSED(event))
doc->GetCommandProcessor()->Redo();
}
+// Handlers for UI update commands
+
+void wxDocManager::OnUpdateFileOpen(wxUpdateUIEvent& event)
+{
+ event.Enable( TRUE );
+}
+
+void wxDocManager::OnUpdateFileClose(wxUpdateUIEvent& event)
+{
+ wxDocument *doc = GetCurrentDocument();
+ event.Enable( (doc != (wxDocument*) NULL) );
+}
+
+void wxDocManager::OnUpdateFileRevert(wxUpdateUIEvent& event)
+{
+ wxDocument *doc = GetCurrentDocument();
+ event.Enable( (doc != (wxDocument*) NULL) );
+}
+
+void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event)
+{
+ event.Enable( TRUE );
+}
+
+void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event)
+{
+ wxDocument *doc = GetCurrentDocument();
+ event.Enable( (doc != (wxDocument*) NULL) );
+}
+
+void wxDocManager::OnUpdateFileSaveAs(wxUpdateUIEvent& event)
+{
+ wxDocument *doc = GetCurrentDocument();
+ event.Enable( (doc != (wxDocument*) NULL) );
+}
+
+void wxDocManager::OnUpdateUndo(wxUpdateUIEvent& event)
+{
+ wxDocument *doc = GetCurrentDocument();
+ event.Enable( (doc && doc->GetCommandProcessor() && doc->GetCommandProcessor()->CanUndo()) );
+}
+
+void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event)
+{
+ wxDocument *doc = GetCurrentDocument();
+ event.Enable( (doc && doc->GetCommandProcessor() && doc->GetCommandProcessor()->CanRedo()) );
+}
+
+void wxDocManager::OnUpdatePrint(wxUpdateUIEvent& event)
+{
+ wxDocument *doc = GetCurrentDocument();
+ event.Enable( (doc != (wxDocument*) NULL) );
+}
+
+void wxDocManager::OnUpdatePrintSetup(wxUpdateUIEvent& event)
+{
+ event.Enable( TRUE );
+}
+
+void wxDocManager::OnUpdatePreview(wxUpdateUIEvent& event)
+{
+ wxDocument *doc = GetCurrentDocument();
+ event.Enable( (doc != (wxDocument*) NULL) );
+}
+
wxView *wxDocManager::GetCurrentView() const
{
if (m_currentView)
return TRUE;
}
+// Make a frame title (override this to do something different)
+// If docName is empty, a document is not currently active.
+wxString wxDocManager::MakeFrameTitle(wxDocument* doc)
+{
+ wxString appName = wxTheApp->GetAppName();
+ wxString title;
+ if (!doc)
+ title = appName;
+ else
+ {
+ wxString docName;
+ doc->GetPrintableName(docName);
+ title = docName + wxString(_(" - ")) + appName;
+ }
+ return title;
+}
+
+
// Not yet implemented
wxDocTemplate *wxDocManager::MatchTemplate(const wxString& WXUNUSED(path))
{
m_lastDirectory = wxPathOnly(pathTmp);
path = pathTmp;
- wxString theExt = FindExtension(path);
- if (!theExt)
- return (wxDocTemplate *) NULL;
// This is dodgy in that we're selecting the template on the
// basis of the file extension, which may not be a standard
fclose (fd1);
return TRUE;
}
+#else
+bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream)
+{
+ FILE *fd1;
+ int ch;
+
+ if ((fd1 = fopen (filename.fn_str(), "rb")) == NULL)
+ return FALSE;
+
+ while ((ch = getc (fd1)) != EOF)
+ stream.PutC((char) ch);
+
+ fclose (fd1);
+ return TRUE;
+}
+
+bool wxTransferStreamToFile(wxInputStream& stream, const wxString& filename)
+{
+ FILE *fd1;
+ char ch;
+
+ if ((fd1 = fopen (filename.fn_str(), "wb")) == NULL)
+ {
+ return FALSE;
+ }
+
+ int len = stream.StreamSize();
+ // TODO: is this the correct test for EOF?
+ while (stream.TellI() < (len - 1))
+ {
+ ch = stream.GetC();
+ putc (ch, fd1);
+ }
+ fclose (fd1);
+ return TRUE;
+}
#endif
#endif // wxUSE_DOC_VIEW_ARCHITECTURE