// forward these to status bar
virtual void SetStatusText(const wxString &text, int number = 0);
virtual void SetStatusWidths(int n, const int widths_field[]);
+ void PushStatusText(const wxString &text, int number = 0);
+ void PopStatusText(int number = 0);
#endif // wxUSE_STATUSBAR
// toolbar functions
{ return FALSE; }
#endif // no wxTopLevelWindowNative
+ // show help text (typically in the statusbar); show is FALSE
+ // if you are hiding the help, TRUE otherwise
+ virtual void DoGiveHelp(const wxString& text, bool show);
+
protected:
// the frame main menu/status/tool bars
// ------------------------------------
wxStatusBar *m_frameStatusBar;
#endif // wxUSE_STATUSBAR
+ // set the status bar pane the help will be shown in
+ void SetStatusBarPane(int n) { m_statusBarPane = n; }
+ int GetStatusBarPane() const { return m_statusBarPane; }
+
+ int m_statusBarPane;
+
#if wxUSE_TOOLBAR
// override to update status bar position (or anything else) when
// something changes
#if wxUSE_STATUSBAR
+#include "wx/list.h"
+
+WX_DECLARE_LIST(wxString, wxListString);
+
// ----------------------------------------------------------------------------
// wxStatusBar: a window near the bottom of the frame used for status info
// ----------------------------------------------------------------------------
virtual void SetStatusText(const wxString& text, int number = 0) = 0;
virtual wxString GetStatusText(int number = 0) const = 0;
+ void PushStatusText(const wxString& text, int number = 0);
+ void PopStatusText(int number = 0);
+
// fields widths
// -------------
// reset the widths
void ReinitWidths() { FreeWidths(); InitWidths(); }
+ // same, for text stacks
+ void InitStacks();
+ void FreeStacks();
+ void ReinitStacks() { FreeStacks(); InitStacks(); }
+
// calculate the real field widths for the given total available size
wxArrayInt CalculateAbsWidths(wxCoord widthTotal) const;
+ // use these functions to access the stacks of field strings
+ wxListString *GetStatusStack(int i) const;
+ wxListString *GetOrCreateStatusStack(int i);
+
// the current number of fields
int m_nFields;
// the widths of the fields in pixels if !NULL, all fields have the same
// width otherwise
int *m_statusWidths;
+
+ // stacks of previous values for PushStatusText/PopStatusText
+ // this is created on demand, use GetStatusStack/GetOrCreateStatusStack
+ wxListString **m_statusTextStacks;
};
// ----------------------------------------------------------------------------
#if wxUSE_STATUSBAR
m_frameStatusBar = NULL;
#endif // wxUSE_STATUSBAR
+
+ m_statusBarPane = 0;
}
wxFrameBase::~wxFrameBase()
PositionStatusBar();
}
-bool wxFrameBase::ShowMenuHelp(wxStatusBar *statbar, int menuId)
+void wxFrameBase::PushStatusText(const wxString& text, int number)
{
-#if wxUSE_MENUS
- if ( !statbar )
- return FALSE;
+ wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") );
+
+ m_frameStatusBar->PushStatusText(text, number);
+}
+void wxFrameBase::PopStatusText(int number)
+{
+ wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") );
+
+ m_frameStatusBar->PopStatusText(number);
+}
+
+void wxFrameBase::DoGiveHelp(const wxString& text, bool show)
+{
+#if wxUSE_STATUSBAR
+ if ( m_statusBarPane < 0 ) return;
+ wxStatusBar* statbar = GetStatusBar();
+ if ( !statbar ) return;
+
+ wxString help = show ? text : wxString();
+ statbar->SetStatusText( help, m_statusBarPane );
+#endif // wxUSE_STATUSBAR
+}
+
+bool wxFrameBase::ShowMenuHelp(wxStatusBar *WXUNUSED(statbar), int menuId)
+{
+#if wxUSE_MENUS
// if no help string found, we will clear the status bar text
wxString helpString;
+ bool show = menuId != wxID_SEPARATOR && menuId != -2 /* wxID_TITLE */;
- if ( menuId != wxID_SEPARATOR && menuId != -2 /* wxID_TITLE */ )
+ if ( show )
{
wxMenuBar *menuBar = GetMenuBar();
if ( menuBar )
}
}
- // set status text even if the string is empty - this will at least
- // remove the string from the item which was previously selected
- statbar->SetStatusText(helpString);
+ DoGiveHelp(helpString, show);
return !helpString.IsEmpty();
#else // !wxUSE_MENUS
#if wxUSE_STATUSBAR
+#include "wx/listimpl.cpp"
+WX_DEFINE_LIST(wxListString);
+
// ============================================================================
// wxStatusBarBase implementation
// ============================================================================
m_nFields = 0;
InitWidths();
+ InitStacks();
}
wxStatusBarBase::~wxStatusBarBase()
{
FreeWidths();
+ FreeStacks();
}
// ----------------------------------------------------------------------------
if ( number != m_nFields )
{
+ // copy stacks if present
+ if(m_statusTextStacks)
+ {
+ wxListString **newStacks = new wxListString*[number];
+ size_t i, j, max = wxMin(number, m_nFields);
+
+ // copy old stacks
+ for(i = 0; i < max; ++i)
+ newStacks[i] = m_statusTextStacks[i];
+ // free old stacks in excess
+ for(j = i; j < (size_t)m_nFields; ++j)
+ {
+ if(m_statusTextStacks[j])
+ {
+ m_statusTextStacks[j]->Clear();
+ delete m_statusTextStacks[j];
+ }
+ }
+ // initialize new stacks to NULL
+ for(j = i; j < (size_t)number; ++j)
+ newStacks[j] = 0;
+
+ m_statusTextStacks = newStacks;
+ }
+
m_nFields = number;
ReinitWidths();
return widths;
}
+// ----------------------------------------------------------------------------
+// text stacks handling
+// ----------------------------------------------------------------------------
+
+void wxStatusBarBase::InitStacks()
+{
+ m_statusTextStacks = NULL;
+}
+
+void wxStatusBarBase::FreeStacks()
+{
+ if(!m_statusTextStacks) return;
+ size_t i;
+
+ for(i = 0; i < (size_t)m_nFields; ++i)
+ {
+ if(m_statusTextStacks[i])
+ {
+ m_statusTextStacks[i]->Clear();
+ delete m_statusTextStacks[i];
+ }
+ }
+
+ delete[] m_statusTextStacks;
+}
+
+// ----------------------------------------------------------------------------
+// text stacks
+// ----------------------------------------------------------------------------
+
+void wxStatusBarBase::PushStatusText(const wxString& text, int number)
+{
+ wxListString* st = GetOrCreateStatusStack(number);
+ st->Insert(new wxString(GetStatusText(number)));
+ SetStatusText(text, number);
+}
+
+void wxStatusBarBase::PopStatusText(int number)
+{
+ wxListString *st = GetStatusStack(number);
+ wxCHECK_RET( st, _T("Unbalanced PushStatusText/PopStatusText") );
+ wxListString::Node *top = st->GetFirst();
+
+ SetStatusText(*top->GetData(), number);
+ st->DeleteNode(top);
+ if(st->GetCount() == 0)
+ {
+ delete st;
+ m_statusTextStacks[number] = 0;
+ }
+}
+
+wxListString *wxStatusBarBase::GetStatusStack(int i) const
+{
+ if(!m_statusTextStacks)
+ return 0;
+ return m_statusTextStacks[i];
+}
+
+wxListString *wxStatusBarBase::GetOrCreateStatusStack(int i)
+{
+ if(!m_statusTextStacks)
+ {
+ m_statusTextStacks = new wxListString*[m_nFields];
+
+ size_t j;
+ for(j = 0; j < (size_t)m_nFields; ++j) m_statusTextStacks[j] = 0;
+ }
+
+ if(!m_statusTextStacks[i])
+ {
+ m_statusTextStacks[i] = new wxListString();
+ m_statusTextStacks[i]->DeleteContents(TRUE);
+ }
+
+ return m_statusTextStacks[i];
+}
+
#endif // wxUSE_STATUSBAR
event.SetEventObject(this);
event.SetInt(id);
- (void)GetEventHandler()->ProcessEvent(event);
-
wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
- if ( !frame )
- return;
-
- wxString helpstring;
-
- if ( id != -1 )
+ if( frame )
{
- wxToolBarToolBase *tool = FindById(id);
- if ( tool )
- helpstring = tool->GetLongHelp();
+ wxToolBarToolBase* tool = id == -1 ? (wxToolBarToolBase*)0 : FindById(id);
+ wxString help = tool ? tool->GetLongHelp() : wxString();
+ frame->DoGiveHelp( help, id != -1 );
}
- // set the status text anyhow, even if the string is empty: this ensures
- // that it is cleared when the mouse leaves the toolbar or enters a tool
- // without help
- if (frame->GetStatusBar())
- frame->SetStatusText(helpstring);
+ (void)GetEventHandler()->ProcessEvent(event);
}
// ----------------------------------------------------------------------------
wxStatusBarGeneric::wxStatusBarGeneric()
{
- m_statusWidths = (int *) NULL;
m_statusStrings = (wxString *) NULL;
- m_nFields = 0;
m_borderX = wxTHICK_LINE_BORDER;
m_borderY = wxTHICK_LINE_BORDER;
}
long style,
const wxString& name)
{
- m_statusWidths = (int *) NULL;
m_statusStrings = (wxString *) NULL;
- m_nFields = 0;
m_borderX = wxTHICK_LINE_BORDER;
m_borderY = wxTHICK_LINE_BORDER;
// delete the old widths in any case - this function may be used to reset
// the widths to the default (all equal)
- delete [] m_statusWidths;
+ // MBN: this is incompatible with at least wxMSW and wxMAC and not
+ // documented, but let's keep it for now
+ ReinitWidths();
if ( !widths_field )
{
// not an error, see the comment above
- m_statusWidths = (int *)NULL;
Refresh();
return;
}
- int i;
-
- // VZ: this doesn't do anything as is_variable is unused later
-#if 0
- // when one window (minimum) is variable (width <= 0)
- bool is_variable = FALSE;
- for (i = 0; i < m_nFields; i++)
- {
- if (widths_field[i] <= 0)
- is_variable = TRUE;
- }
-#endif // 0
-
- // set widths
- m_statusWidths = new int[n];
- for (i = 0; i < m_nFields; i++)
- {
- m_statusWidths[i] = widths_field[i];
- }
- Refresh();
+ wxStatusBarBase::SetStatusWidths(n, widths_field);
}
void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) )
#endif
else
{
-#if wxUSE_STATUSBAR
// don't give hints for separators (doesn't make sense) nor for the
// items opening popup menus (they don't have them anyhow) but do clear
// the status line - otherwise, we would be left with the help message
// for the previous item which doesn't apply any more
- wxStatusBar *statbar = GetStatusBar();
- if ( statbar )
- {
- statbar->SetStatusText(wxEmptyString);
- }
-#endif // wxUSE_STATUSBAR
+ DoGiveHelp(wxEmptyString, FALSE);
return FALSE;
}