\membersection{wxFileHistory::m\_fileHistoryN}
-\member{int}{m\_fileHistoryN}
+\member{size_t}{m\_fileHistoryN}
The number of files stored in the history array.
\membersection{wxFileHistory::m\_fileMaxFiles}
-\member{int}{m\_fileMaxFiles}
+\member{size_t}{m\_fileMaxFiles}
The maximum number of files to be stored and displayed on the menu.
\membersection{wxFileHistory::wxFileHistory}
-\func{}{wxFileHistory}{\param{int}{ maxFiles = 9}}
+\func{}{wxFileHistory}{\param{size_t}{ maxFiles = 9}, \param{wxWindowID}{ idBase = wxID_FILE1}}
Constructor. Pass the maximum number of files that should be stored and displayed.
+idBase defaults to wxID_FILE1 and represents the id given to the first history menu item.
+Since menu items can't share the same ID you should change idBase (To one of your own
+defined IDs) when using more than one wxFileHistory in your application.
+
+
\membersection{wxFileHistory::\destruct{wxFileHistory}}
\func{}{\destruct{wxFileHistory}}{\void}
\membersection{wxFileHistory::GetHistoryFile}\label{wxfilehistorygethistoryfile}
-\constfunc{wxString}{GetHistoryFile}{\param{int}{ index}}
+\constfunc{wxString}{GetHistoryFile}{\param{size_t}{ index}}
Returns the file at this index (zero-based).
\membersection{wxFileHistory::GetMaxFiles}
-\constfunc{int}{GetMaxFiles}{\void}
+\constfunc{size_t}{GetMaxFiles}{\void}
Returns the maximum number of files that can be stored.
\membersection{wxFileHistory::GetNoHistoryFiles}
-\constfunc{int}{GetNoHistoryFiles}{\void}
+\constfunc{size_t}{GetNoHistoryFiles}{\void}
Returns the number of files currently stored in the file history.
// File history management
virtual void AddFileToHistory(const wxString& file);
- virtual void RemoveFileFromHistory(int i);
- virtual int GetNoHistoryFiles() const;
- virtual wxString GetHistoryFile(int i) const;
+ virtual void RemoveFileFromHistory(size_t i);
+ virtual size_t GetNoHistoryFiles() const;
+ virtual wxString GetHistoryFile(size_t i) const;
virtual void FileHistoryUseMenu(wxMenu *menu);
virtual void FileHistoryRemoveMenu(wxMenu *menu);
#if wxUSE_CONFIG
class WXDLLEXPORT wxFileHistory : public wxObject
{
public:
- wxFileHistory(int maxFiles = 9);
+ wxFileHistory(size_t maxFiles = 9, wxWindowID idBase = wxID_FILE1);
~wxFileHistory();
// Operations
virtual void AddFileToHistory(const wxString& file);
- virtual void RemoveFileFromHistory(int i);
+ virtual void RemoveFileFromHistory(size_t i);
virtual int GetMaxFiles() const { return m_fileMaxFiles; }
virtual void UseMenu(wxMenu *menu);
virtual void AddFilesToMenu(wxMenu* menu); // Single menu
// Accessors
- virtual wxString GetHistoryFile(int i) const;
+ virtual wxString GetHistoryFile(size_t i) const;
// A synonym for GetNoHistoryFiles
- virtual int GetCount() const { return m_fileHistoryN; }
- int GetNoHistoryFiles() const { return m_fileHistoryN; }
+ virtual size_t GetCount() const { return m_fileHistoryN; }
+ size_t GetNoHistoryFiles() const { return m_fileHistoryN; }
wxList& GetMenus() const { return (wxList&) m_fileMenus; }
// Last n files
wxChar** m_fileHistory;
// Number of files saved
- int m_fileHistoryN;
+ size_t m_fileHistoryN;
// Menus to maintain (may need several for an MDI app)
wxList m_fileMenus;
// Max files to maintain
- int m_fileMaxFiles;
+ size_t m_fileMaxFiles;
private:
+ // The ID of the first history menu item (Doesn't have to be wxID_FILE1)
+ wxWindowID m_idBase;
+
DECLARE_DYNAMIC_CLASS(wxFileHistory)
DECLARE_NO_COPY_CLASS(wxFileHistory)
};
m_fileHistory->AddFileToHistory(file);
}
-void wxDocManager::RemoveFileFromHistory(int i)
+void wxDocManager::RemoveFileFromHistory(size_t i)
{
if (m_fileHistory)
m_fileHistory->RemoveFileFromHistory(i);
}
-wxString wxDocManager::GetHistoryFile(int i) const
+wxString wxDocManager::GetHistoryFile(size_t i) const
{
wxString histFile;
m_fileHistory->AddFilesToMenu();
}
-int wxDocManager::GetNoHistoryFiles() const
+size_t wxDocManager::GetNoHistoryFiles() const
{
if (m_fileHistory)
return m_fileHistory->GetNoHistoryFiles();
// File history processor
// ----------------------------------------------------------------------------
-wxFileHistory::wxFileHistory(int maxFiles)
+wxFileHistory::wxFileHistory(size_t maxFiles, wxWindowID idBase)
{
m_fileMaxFiles = maxFiles;
+ m_idBase = idBase;
m_fileHistoryN = 0;
m_fileHistory = new wxChar *[m_fileMaxFiles];
}
wxFileHistory::~wxFileHistory()
{
- int i;
+ size_t i;
for (i = 0; i < m_fileHistoryN; i++)
delete[] m_fileHistory[i];
delete[] m_fileHistory;
// File history management
void wxFileHistory::AddFileToHistory(const wxString& file)
{
- int i;
+ size_t i;
// Check we don't already have this file
for (i = 0; i < m_fileHistoryN; i++)
{
menu->AppendSeparator();
}
- menu->Append(wxID_FILE1+m_fileHistoryN, _("[EMPTY]"));
+ menu->Append(m_idBase+m_fileHistoryN, _("[EMPTY]"));
node = node->GetNext();
}
m_fileHistoryN ++;
while (node)
{
wxMenu* menu = (wxMenu*) node->GetData();
- menu->SetLabel(wxID_FILE1 + i, buf);
+ menu->SetLabel(m_idBase + i, buf);
node = node->GetNext();
}
}
}
}
-void wxFileHistory::RemoveFileFromHistory(int i)
+void wxFileHistory::RemoveFileFromHistory(size_t i)
{
wxCHECK_RET( i < m_fileHistoryN,
wxT("invalid index in wxFileHistory::RemoveFileFromHistory") );
- // delete the element from the array (could use memmove() too...)
- delete [] m_fileHistory[i];
+ // delete the element from the array (could use memmove() too...)
+ delete [] m_fileHistory[i];
- int j;
- for ( j = i; j < m_fileHistoryN - 1; j++ )
- {
- m_fileHistory[j] = m_fileHistory[j + 1];
- }
+ size_t j;
+ for ( j = i; j < m_fileHistoryN - 1; j++ )
+ {
+ m_fileHistory[j] = m_fileHistory[j + 1];
+ }
wxNode* node = m_fileMenus.GetFirst();
while ( node )
{
- wxMenu* menu = (wxMenu*) node->GetData();
+ wxMenu* menu = (wxMenu*) node->GetData();
- // shuffle filenames up
- wxString buf;
- for ( j = i; j < m_fileHistoryN - 1; j++ )
- {
- buf.Printf(s_MRUEntryFormat, j + 1, m_fileHistory[j]);
- menu->SetLabel(wxID_FILE1 + j, buf);
- }
+ // shuffle filenames up
+ wxString buf;
+ for ( j = i; j < m_fileHistoryN - 1; j++ )
+ {
+ buf.Printf(s_MRUEntryFormat, j + 1, m_fileHistory[j]);
+ menu->SetLabel(m_idBase + j, buf);
+ }
- node = node->GetNext();
+ node = node->GetNext();
// delete the last menu item which is unused now
- if (menu->FindItem(wxID_FILE1 + m_fileHistoryN - 1))
- menu->Delete(wxID_FILE1 + m_fileHistoryN - 1);
+ wxWindowID lastItemId = m_idBase + m_fileHistoryN - 1;
+ if (menu->FindItem(lastItemId))
+ {
+ menu->Delete(lastItemId);
+ }
// delete the last separator too if no more files are left
if ( m_fileHistoryN == 1 )
m_fileHistoryN--;
}
-wxString wxFileHistory::GetHistoryFile(int i) const
+wxString wxFileHistory::GetHistoryFile(size_t i) const
{
wxString s;
if ( i < m_fileHistoryN )
void wxFileHistory::Save(wxConfigBase& config)
{
- int i;
+ size_t i;
for (i = 0; i < m_fileHistoryN; i++)
{
wxString buf;
menu->AppendSeparator();
}
- int i;
+ size_t i;
for (i = 0; i < m_fileHistoryN; i++)
{
if (m_fileHistory[i])
{
wxString buf;
buf.Printf(s_MRUEntryFormat, i+1, m_fileHistory[i]);
- menu->Append(wxID_FILE1+i, buf);
+ menu->Append(m_idBase+i, buf);
}
}
node = node->GetNext();
menu->AppendSeparator();
}
- int i;
+ size_t i;
for (i = 0; i < m_fileHistoryN; i++)
{
if (m_fileHistory[i])
{
wxString buf;
buf.Printf(s_MRUEntryFormat, i+1, m_fileHistory[i]);
- menu->Append(wxID_FILE1+i, buf);
+ menu->Append(m_idBase+i, buf);
}
}
}