// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#include <stdio.h>
#include <string.h>
+#include "wx/ioswrap.h"
+
#if wxUSE_IOSTREAMH
-#include <iostream.h>
-#include <fstream.h>
+ #include <fstream.h>
#else
-#include <iostream>
-#include <fstream>
-# ifdef _MSC_VER
- using namespace std;
-# endif
+ #include <fstream>
#endif
#if !USE_SHARED_LIBRARY
bool wxDocument::SaveAs(void)
{
- wxDocTemplate *docTemplate = GetDocumentTemplate();
- if (!docTemplate)
- return FALSE;
-
- char *tmp = wxFileSelector(_("Save as"), docTemplate->GetDirectory(), GetFilename(),
- docTemplate->GetDefaultExtension(), docTemplate->GetFileFilter(),
- wxSAVE|wxOVERWRITE_PROMPT, GetDocumentWindow());
+ wxDocTemplate *docTemplate = GetDocumentTemplate();
+ if (!docTemplate)
+ return FALSE;
- if (!tmp)
- return FALSE;
- else
- {
+ wxString tmp = wxFileSelector(_("Save as"),
+ docTemplate->GetDirectory(),
+ GetFilename(),
+ docTemplate->GetDefaultExtension(),
+ docTemplate->GetFileFilter(),
+ wxSAVE | wxOVERWRITE_PROMPT,
+ GetDocumentWindow());
+
+ if (tmp.IsEmpty())
+ return FALSE;
+
wxString fileName(tmp);
wxString path("");
wxString name("");
view->OnChangeFilename();
node = node->Next();
}
- }
- return OnSaveDocument(m_documentFile);
+
+ return OnSaveDocument(m_documentFile);
}
bool wxDocument::OnSaveDocument(const wxString& file)
{
if (IsModified())
{
- char buf[400];
wxString title;
GetPrintableName(title);
else
msgTitle = wxString(_("Warning"));
- sprintf(buf, _("Do you want to save changes to document %s?"), (const char *)title);
- int res = wxMessageBox(buf, msgTitle, wxYES_NO|wxCANCEL|wxICON_QUESTION,
- GetDocumentWindow());
+ wxString prompt;
+ prompt.Printf(_("Do you want to save changes to document %s?"),
+ (const char *)title);
+ int res = wxMessageBox(prompt, msgTitle,
+ wxYES_NO|wxCANCEL|wxICON_QUESTION,
+ GetDocumentWindow());
if (res == wxNO)
{
Modify(FALSE);
* Document view
*/
-wxView::wxView(wxDocument *doc)
+wxView::wxView()
{
- SetDocument(doc);
+// SetDocument(doc);
+ m_viewDocument = (wxDocument*) NULL;
m_viewTypeName = "";
m_viewFrame = (wxFrame *) NULL;
// Make a default document name
bool wxDocManager::MakeDefaultName(wxString& name)
{
- char buf[256];
- sprintf(buf, _("unnamed%d"), m_defaultDocumentNameCounter);
- m_defaultDocumentNameCounter ++;
- name = buf;
+ name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter);
+ m_defaultDocumentNameCounter++;
+
return TRUE;
}
m_fileHistory->RemoveMenu(menu);
}
+#if wxUSE_CONFIG
void wxDocManager::FileHistoryLoad(wxConfigBase& config)
{
if (m_fileHistory)
if (m_fileHistory)
m_fileHistory->Save(config);
}
+#endif
void wxDocManager::FileHistoryAddFilesToMenu(wxMenu* menu)
{
{
// We can only have multiple filters in Windows
#ifdef __WXMSW__
- char *descrBuf = new char[1000];
- descrBuf[0] = 0;
- int i;
- for (i = 0; i < noTemplates; i++)
- {
- if (templates[i]->IsVisible())
+ wxString descrBuf;
+
+ int i;
+ for (i = 0; i < noTemplates; i++)
{
- strcat(descrBuf, templates[i]->GetDescription());
- strcat(descrBuf, " (");
- strcat(descrBuf, templates[i]->GetFileFilter());
- strcat(descrBuf, ") ");
- strcat(descrBuf, "|");
- strcat(descrBuf, templates[i]->GetFileFilter());
- strcat(descrBuf, "|");
+ if (templates[i]->IsVisible())
+ {
+ // add a '|' to separate this filter from the previous one
+ if ( !descrBuf.IsEmpty() )
+ descrBuf << '|';
+
+ descrBuf << templates[i]->GetDescription()
+ << " (" << templates[i]->GetFileFilter() << ") |"
+ << templates[i]->GetFileFilter();
+ }
}
- }
- int len = strlen(descrBuf);
- if (len > 0)
- // Omit final "|"
- descrBuf[len-1] = 0;
#else
- char* descrBuf = copystring("*.*");
+ wxString descrBuf = "*.*";
#endif
- char *pathTmp = wxFileSelector(_("Select a file"), "", "", "", descrBuf, 0, wxTheApp->GetTopWindow());
- delete[] descrBuf;
- if (pathTmp)
+ wxString pathTmp = wxFileSelector(_("Select a file"), "", "", "",
+ descrBuf, 0, wxTheApp->GetTopWindow());
+
+ if (!pathTmp.IsEmpty())
{
path = pathTmp;
char *theExt = FindExtension((char *)(const char *)path);
int n = 0;
for (i = 0; i < noTemplates; i++)
{
- if (templates[i]->IsVisible() && templates[i]->GetViewName())
+ if (templates[i]->IsVisible() && (templates[i]->GetViewName() != ""))
{
strings[n] = WXSTRINGCAST templates[i]->m_viewTypeName;
data[n] = (char *)templates[i];
// we've undone to the start of the list, but can redo the first.
wxCommand *redoCommand = (wxCommand *)m_commands.First()->Data();
wxString redoCommandName(redoCommand->GetName());
- if (!redoCommandName) redoCommandName = _("Unnamed command");
+ if (redoCommandName == "") redoCommandName = _("Unnamed command");
buf = wxString(_("&Redo ")) + redoCommandName;
m_commandEditMenu->SetLabel(wxID_REDO, buf);
m_commandEditMenu->Enable(wxID_REDO, TRUE);
for (i = 0; i < m_fileHistoryN; i++)
if (m_fileHistory[i])
{
- char buf[400];
- sprintf(buf, "&%d %s", i+1, m_fileHistory[i]);
+ wxString buf;
+ buf.Printf("&%d %s", i+1, m_fileHistory[i]);
wxNode* node = m_fileMenus.First();
while (node)
{
m_fileMenus.DeleteObject(menu);
}
+#if wxUSE_CONFIG
void wxFileHistory::Load(wxConfigBase& config)
{
m_fileHistoryN = 0;
- char buf[400];
- sprintf(buf, "file%d", m_fileHistoryN+1);
- wxString historyFile("");
+ wxString buf;
+ buf.Printf("file%d", m_fileHistoryN+1);
+ wxString historyFile;
while ((m_fileHistoryN <= m_fileMaxFiles) && config.Read(buf, &historyFile) && (historyFile != ""))
{
m_fileHistory[m_fileHistoryN] = copystring((const char*) historyFile);
m_fileHistoryN ++;
- sprintf(buf, "file%d", m_fileHistoryN+1);
+ buf.Printf("file%d", m_fileHistoryN+1);
historyFile = "";
}
AddFilesToMenu();
config.Write(buf, wxString(m_fileHistory[i]));
}
}
+#endif
void wxFileHistory::AddFilesToMenu()
{