int fields = GetLong(wxT("fields"), 1);
wxString widths = GetParamValue(wxT("widths"));
+ wxString styles = GetParamValue(wxT("styles"));
if (fields > 1 && !widths.IsEmpty())
{
else
statbar->SetFieldsCount(fields);
+ if (!styles.IsEmpty())
+ {
+ int *style = new int[fields];
+ for (int i = 0; i < fields; ++i)
+ {
+ style[i] = wxSB_NORMAL;
+
+ wxString first = styles.BeforeFirst(wxT(','));
+ if (first == wxT("wxSB_NORMAL"))
+ style[i] = wxSB_NORMAL;
+ else if (first == wxT("wxSB_FLAT"))
+ style[i] = wxSB_FLAT;
+ else if (first == wxT("wxSB_RAISED"))
+ style[i] = wxSB_RAISED;
+
+ if (!first.IsEmpty())
+ wxLogError(wxT("Error in resource, unknown statusbar field style: ") + first);
+ if(styles.Find(wxT(',')))
+ styles.Remove(0, styles.Find(wxT(',')) + 1);
+ }
+ statbar->SetStatusStyles(fields, style);
+ delete [] style;
+ }
+
if (m_parentAsWindow)
{
wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
- added wxKeyEvent::GetUnicodeKey()
- added wxKeyEvent::CmdDown() and wxMouseEvent::CmdDown()
- implemented wxListCtrl::FindItem() for non-MSW (Robin Stoll)
+- added status bar fields styles support (Tim Kosse)
Unix:
\perlnote{In wxPerl this method takes as parameters the field widths.}
+\membersection{wxStatusBar::SetStatusStyles}\label{wxstatusbarsetstatusstyles}
+
+\func{virtual void}{SetStatusStyles}{\param{int}{ n}, \param{int *}{styles}}
+
+Sets the styles of the fields in the status line which can make fields appear flat
+or raised instead of the standard sunken 3D border.
+
+\wxheading{Parameters}
+
+\docparam{n}{The number of fields in the status bar. Must be equal to the
+number passed to \helpref{SetFieldsCount}{wxstatusbarsetfieldscount} the last
+time it was called.}
+
+\docparam{styles}{Contains an array of {\it n} integers with the styles for each field. There
+are three possible styles:
+
+\twocolwidtha{5cm}
+\begin{twocollist}\itemsep=0pt
+\twocolitem{\windowstyle{wxSB\_NORMAL}}{(default) The field appears sunken with a standard 3D border.}
+\twocolitem{\windowstyle{wxSB\_FLAT}}{No border is painted around the field so that it appears flat.}
+\twocolitem{\windowstyle{wxSB\_RAISED}}{A raised 3D border is painted around the field.}
+\end{twocollist}
+
+
+
// set status line fields' widths
virtual void SetStatusWidths(int n, const int widths_field[]);
+ // set status line fields' styles
+ virtual void SetStatusStyles(int n, const int styles[]);
+
// sets the minimal vertical size of the status bar
virtual void SetMinHeight(int height);
WX_DECLARE_LIST(wxString, wxListString);
+// ----------------------------------------------------------------------------
+// wxStatusBar constants
+// ----------------------------------------------------------------------------
+
+// style flags for fields
+#define wxSB_NORMAL 0x0000
+#define wxSB_FLAT 0x0001
+#define wxSB_RAISED 0x0002
+
// ----------------------------------------------------------------------------
// wxStatusBar: a window near the bottom of the frame used for status info
// ----------------------------------------------------------------------------
// -2 grows twice as much as one with width -1 &c)
virtual void SetStatusWidths(int n, const int widths[]);
+ // field styles
+ // ------------
+
+ // Set the field style. Use either wxSB_NORMAL (default) for a standard 3D
+ // border around a field, wxSB_FLAT for no border around a field, so that it
+ // appears flat or wxSB_POPOUT to make the field appear raised.
+ // Setting field styles only works on wxMSW
+ virtual void SetStatusStyles(int n, const int styles[]);
+
// geometry
// --------
// reset the widths
void ReinitWidths() { FreeWidths(); InitWidths(); }
+ // same, for field styles
+ void InitStyles();
+ void FreeStyles();
+ void ReinitStyles() { FreeStyles(); InitStyles(); }
+
// same, for text stacks
void InitStacks();
void FreeStacks();
// width otherwise
int *m_statusWidths;
+ // the styles of the fields
+ int *m_statusStyles;
+
// stacks of previous values for PushStatusText/PopStatusText
// this is created on demand, use GetStatusStack/GetOrCreateStatusStack
wxListString **m_statusTextStacks;
virtual void DrawStatusField(wxDC& dc,
const wxRect& rect,
const wxString& label,
- int flags = 0) = 0;
+ int flags = 0, int style = 0) = 0;
// draw complete frame/dialog titlebar
virtual void DrawFrameTitleBar(wxDC& dc,
virtual void DrawStatusField(wxDC& dc,
const wxRect& rect,
const wxString& label,
- int flags = 0)
- { m_renderer->DrawStatusField(dc, rect, label, flags); }
+ int flags = 0, inst style = 0)
+ { m_renderer->DrawStatusField(dc, rect, label, flags, style); }
virtual void DrawFrameTitleBar(wxDC& dc,
const wxRect& rect,
void OnSetStatusFields(wxCommandEvent& event);
void OnRecreateStatusBar(wxCommandEvent& event);
+ void OnSetStyleNormal(wxCommandEvent& event);
+ void OnSetStyleFlat(wxCommandEvent& event);
+ void OnSetStyleRaised(wxCommandEvent& event);
private:
enum StatBarKind
} m_statbarKind;
void OnUpdateSetStatusFields(wxUpdateUIEvent& event);
void OnUpdateStatusBarToggle(wxUpdateUIEvent& event);
+ void OnUpdateSetStyleNormal(wxUpdateUIEvent& event);
+ void OnUpdateSetStyleFlat(wxUpdateUIEvent& event);
+ void OnUpdateSetStyleRaised(wxUpdateUIEvent& event);
void OnStatusBarToggle(wxCommandEvent& event);
void DoCreateStatusBar(StatBarKind kind);
+ void ApplyStyle();
wxStatusBar *m_statbarDefault;
MyStatusBar *m_statbarCustom;
+ int m_statbarStyle;
+
// any class wishing to process wxWidgets events must use this macro
DECLARE_EVENT_TABLE()
};
StatusBar_Recreate,
StatusBar_About,
StatusBar_Toggle,
- StatusBar_Checkbox = 1000
+ StatusBar_Checkbox = 1000,
+ StatusBar_SetStyle,
+ StatusBar_SetStyleNormal,
+ StatusBar_SetStyleFlat,
+ StatusBar_SetStyleRaised
};
static const int BITMAP_SIZE_X = 32;
EVT_MENU(StatusBar_Recreate, MyFrame::OnRecreateStatusBar)
EVT_MENU(StatusBar_About, MyFrame::OnAbout)
EVT_MENU(StatusBar_Toggle, MyFrame::OnStatusBarToggle)
+ EVT_MENU(StatusBar_SetStyleNormal, MyFrame::OnSetStyleNormal)
+ EVT_MENU(StatusBar_SetStyleFlat, MyFrame::OnSetStyleFlat)
+ EVT_MENU(StatusBar_SetStyleRaised, MyFrame::OnSetStyleRaised)
EVT_UPDATE_UI(StatusBar_Toggle, MyFrame::OnUpdateStatusBarToggle)
EVT_UPDATE_UI(StatusBar_SetFields, MyFrame::OnUpdateSetStatusFields)
+ EVT_UPDATE_UI(StatusBar_SetStyleNormal, MyFrame::OnUpdateSetStyleNormal)
+ EVT_UPDATE_UI(StatusBar_SetStyleFlat, MyFrame::OnUpdateSetStyleFlat)
+ EVT_UPDATE_UI(StatusBar_SetStyleRaised, MyFrame::OnUpdateSetStyleRaised)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(MyStatusBar, wxStatusBar)
m_statbarDefault = NULL;
m_statbarCustom = NULL;
+ m_statbarStyle = wxSB_NORMAL;
+
#ifdef __WXMAC__
// we need this in order to allow the about menu relocation, since ABOUT is
// not the default id of the about menu
statbarMenu->Append(StatusBar_Recreate, _T("&Recreate\tCtrl-R"),
_T("Toggle status bar format"));
+ wxMenu *statbarStyleMenu = new wxMenu;
+ statbarStyleMenu->Append(StatusBar_SetStyleNormal, _T("&Normal"), _T("Sets the style of the first field to normal (sunken) look"), true);
+ statbarStyleMenu->Append(StatusBar_SetStyleFlat, _T("&Flat"), _T("Sets the style of the first field to flat look"), true);
+ statbarStyleMenu->Append(StatusBar_SetStyleRaised, _T("&Raised"), _T("Sets the style of the first field to raised look"), true);
+ statbarMenu->Append(StatusBar_SetStyle, _T("Field style"), statbarStyleMenu);
+
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(StatusBar_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
wxFAIL_MSG(wxT("unknown stat bar kind"));
}
+ ApplyStyle();
GetStatusBar()->Show();
PositionStatusBar();
void MyFrame::OnUpdateSetStatusFields(wxUpdateUIEvent& event)
{
- // only allow the setting of the number of status fields for the default
+ // only allow the settings of the number of status fields for the default
// status bar
wxStatusBar *sb = GetStatusBar();
event.Enable(sb == m_statbarDefault);
}
-
// event handlers
void MyFrame::OnSetStatusFields(wxCommandEvent& WXUNUSED(event))
{
dlg.ShowModal();
}
+void MyFrame::OnUpdateSetStyleNormal(wxUpdateUIEvent &event)
+{
+ event.Check(m_statbarStyle == wxSB_NORMAL);
+}
+
+void MyFrame::OnUpdateSetStyleFlat(wxUpdateUIEvent &event)
+{
+ event.Check(m_statbarStyle == wxSB_FLAT);
+}
+
+void MyFrame::OnUpdateSetStyleRaised(wxUpdateUIEvent &event)
+{
+ event.Check(m_statbarStyle == wxSB_RAISED);
+}
+
+void MyFrame::OnSetStyleNormal(wxCommandEvent &event)
+{
+ m_statbarStyle = wxSB_NORMAL;
+ ApplyStyle();
+}
+
+void MyFrame::OnSetStyleFlat(wxCommandEvent &event)
+{
+ m_statbarStyle = wxSB_FLAT;
+ ApplyStyle();
+}
+
+void MyFrame::OnSetStyleRaised(wxCommandEvent &event)
+{
+ m_statbarStyle = wxSB_RAISED;
+ ApplyStyle();
+}
+
+void MyFrame::ApplyStyle()
+{
+ wxStatusBar *sb = GetStatusBar();
+ int fields = sb->GetFieldsCount();
+ int *styles = new int[fields];
+
+ for (int i = 1; i < fields; i++)
+ styles[i] = wxSB_NORMAL;
+
+ styles[0] = m_statbarStyle;
+
+ sb->SetStatusStyles(fields, styles);
+
+ delete [] styles;
+}
+
// ----------------------------------------------------------------------------
// MyAboutDialog
// ----------------------------------------------------------------------------
InitWidths();
InitStacks();
+ InitStyles();
}
wxStatusBarBase::~wxStatusBarBase()
{
FreeWidths();
FreeStacks();
+ InitStyles();
}
// ----------------------------------------------------------------------------
delete [] m_statusWidths;
}
+// ----------------------------------------------------------------------------
+// styles array handling
+// ----------------------------------------------------------------------------
+
+void wxStatusBarBase::InitStyles()
+{
+ m_statusStyles = NULL;
+}
+
+void wxStatusBarBase::FreeStyles()
+{
+ delete [] m_statusStyles;
+}
+
// ----------------------------------------------------------------------------
// field widths
// ----------------------------------------------------------------------------
m_statusTextStacks = newStacks;
}
+ // Resize styles array
+ if (m_statusStyles)
+ {
+ int *oldStyles = m_statusStyles;
+ m_statusStyles = new int[number];
+ int i, max = wxMin(number, m_nFields);
+
+ // copy old styles
+ for (i = 0; i < max; ++i)
+ m_statusStyles[i] = oldStyles[i];
+
+ // initialize new styles to wxSB_NORMAL
+ for (i = max; i < number; ++i)
+ m_statusStyles[i] = wxSB_NORMAL;
+
+ // free old styles
+ delete [] oldStyles;
+ }
+
+
m_nFields = number;
ReinitWidths();
Refresh();
}
+void wxStatusBarBase::SetStatusStyles(int WXUNUSED_UNLESS_DEBUG(n),
+ const int styles[])
+{
+ wxCHECK_RET( styles, _T("NULL pointer in SetStatusStyles") );
+
+ wxASSERT_MSG( n == m_nFields, _T("field number mismatch") );
+
+ if ( !m_statusStyles )
+ m_statusStyles = new int[m_nFields];
+
+ for ( int i = 0; i < m_nFields; i++ )
+ {
+ m_statusStyles[i] = styles[i];
+ }
+
+ // update the display after the widths changed
+ Refresh();
+}
+
wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
{
wxArrayInt widths;
for (i = m_nFields - 1; i >= number; --i)
m_statusStrings.RemoveAt(i);
- m_nFields = number;
+ wxStatusBarBase::SetFieldsCount(number, widths);
wxASSERT_MSG( m_nFields == (int)m_statusStrings.GetCount(),
_T("This really should never happen, can we do away with m_nFields here?") );
-
- SetStatusWidths(number, widths);
}
void wxStatusBarGeneric::SetStatusText(const wxString& text, int number)
wxRect rect;
GetFieldRect(i, rect);
- // Draw border
- // Have grey background, plus 3-d border -
- // One black rectangle.
- // Inside this, left and top sides - dark grey. Bottom and right -
- // white.
-
- dc.SetPen(m_hilightPen);
-
-#ifndef __WXPM__
-
- // Right and bottom white lines
- dc.DrawLine(rect.x + rect.width, rect.y,
- rect.x + rect.width, rect.y + rect.height);
- dc.DrawLine(rect.x + rect.width, rect.y + rect.height,
- rect.x, rect.y + rect.height);
-
- dc.SetPen(m_mediumShadowPen);
+ int style = wxSB_NORMAL;
+ if (m_statusStyles)
+ style = m_statusStyles[i];
- // Left and top grey lines
- dc.DrawLine(rect.x, rect.y + rect.height,
- rect.x, rect.y);
- dc.DrawLine(rect.x, rect.y,
- rect.x + rect.width, rect.y);
-#else
-
- dc.DrawLine(rect.x + rect.width, rect.height + 2,
- rect.x, rect.height + 2);
- dc.DrawLine(rect.x + rect.width, rect.y,
- rect.x + rect.width, rect.y + rect.height);
-
- dc.SetPen(m_mediumShadowPen);
- dc.DrawLine(rect.x, rect.y,
- rect.x + rect.width, rect.y);
- dc.DrawLine(rect.x, rect.y + rect.height,
- rect.x, rect.y);
+ if (style != wxSB_FLAT)
+ {
+ // Draw border
+ // For wxSB_NORMAL:
+ // Have grey background, plus 3-d border -
+ // One black rectangle.
+ // Inside this, left and top sides - dark grey. Bottom and right -
+ // white.
+ // Reverse it for wxSB_RAISED
+
+ dc.SetPen((style == wxSB_RAISED) ? m_mediumShadowPen : m_hilightPen);
+
+ #ifndef __WXPM__
+
+ // Right and bottom lines
+ dc.DrawLine(rect.x + rect.width, rect.y,
+ rect.x + rect.width, rect.y + rect.height);
+ dc.DrawLine(rect.x + rect.width, rect.y + rect.height,
+ rect.x, rect.y + rect.height);
+
+ dc.SetPen((style == wxSB_RAISED) ? m_hilightPen : m_mediumShadowPen);
+
+ // Left and top lines
+ dc.DrawLine(rect.x, rect.y + rect.height,
+ rect.x, rect.y);
+ dc.DrawLine(rect.x, rect.y,
+ rect.x + rect.width, rect.y);
+ #else
+
+ dc.DrawLine(rect.x + rect.width, rect.height + 2,
+ rect.x, rect.height + 2);
+ dc.DrawLine(rect.x + rect.width, rect.y,
+ rect.x + rect.width, rect.y + rect.height);
+
+ dc.SetPen((style == wxSB_RAISED) ? m_hilightPen : m_mediumShadowPen);
+ dc.DrawLine(rect.x, rect.y,
+ rect.x + rect.width, rect.y);
+ dc.DrawLine(rect.x, rect.y + rect.height,
+ rect.x, rect.y);
#endif
+ }
DrawFieldText(dc, i);
}
wxCHECK_RET( (nField >= 0) && (nField < m_nFields),
_T("invalid statusbar field index") );
- if ( !StatusBar_SetText(GetHwnd(), nField, strText) )
+ // Get field style, if any
+ int style;
+ if (m_statusStyles)
+ {
+ switch(m_statusStyles[nField])
+ {
+ case wxSB_RAISED:
+ style = SBT_POPOUT;
+ break;
+ case wxSB_FLAT:
+ style = SBT_NOBORDERS;
+ break;
+ case wxSB_NORMAL:
+ default:
+ style = 0;
+ break;
+ }
+ }
+ else
+ style = 0;
+
+ // Pass both field number and style. MSDN library doesn't mention
+ // that nField and style have to be 'ORed'
+ if ( !StatusBar_SetText(GetHwnd(), nField | style, strText) )
{
wxLogLastError(wxT("StatusBar_SetText"));
}
}
}
+void wxStatusBar95::SetStatusStyles(int n, const int styles[])
+{
+ wxStatusBarBase::SetStatusStyles(n, styles);
+
+ if (n != m_nFields)
+ return;
+
+ for (int i = 0; i < n; i++)
+ {
+ int style;
+ switch(styles[i])
+ {
+ case wxSB_RAISED:
+ style = SBT_POPOUT;
+ break;
+ case wxSB_FLAT:
+ style = SBT_NOBORDERS;
+ break;
+ case wxSB_NORMAL:
+ default:
+ style = 0;
+ break;
+ }
+ // The SB_SETTEXT message is both used to set the field's text as well as
+ // the fields' styles. MSDN library doesn't mention
+ // that nField and style have to be 'ORed'
+ wxString text = GetStatusText(i);
+ if (!StatusBar_SetText(GetHwnd(), style | i, text))
+ {
+ wxLogLastError(wxT("StatusBar_SetText"));
+ }
+ }
+}
+
#endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR
flags |= wxCONTROL_ISDEFAULT;
}
- m_renderer->DrawStatusField(dc, rect, m_statusText[n], flags);
+ int style;
+ if (m_statusStyles)
+ style = m_statusStyles[n];
+ else
+ style = wxSB_NORMAL;
+ m_renderer->DrawStatusField(dc, rect, m_statusText[n], flags, style);
}
rect.x += rect.width + borderBetweenFields;
#include "wx/slider.h"
#include "wx/textctrl.h"
#include "wx/toolbar.h"
+ #include "wx/statusbr.h"
#include "wx/settings.h"
#endif // WX_PRECOMP
virtual void DrawStatusField(wxDC& dc,
const wxRect& rect,
const wxString& label,
- int flags = 0);
+ int flags = 0, int style = 0);
virtual void DrawFrameTitleBar(wxDC& dc,
const wxRect& rect,
void wxGTKRenderer::DrawStatusField(wxDC& WXUNUSED(dc),
const wxRect& WXUNUSED(rect),
const wxString& WXUNUSED(label),
- int WXUNUSED(flags))
+ int WXUNUSED(flags), int WXUNUSED(style))
{
}
#include "wx/textctrl.h"
#include "wx/listbox.h"
#include "wx/toolbar.h"
+ #include "wx/statusbr.h"
#ifdef __WXMSW__
// for COLOR_* constants
virtual void DrawStatusField(wxDC& dc,
const wxRect& rect,
const wxString& label,
- int flags = 0);
+ int flags = 0, int style = 0);
// titlebars
virtual void DrawFrameTitleBar(wxDC& dc,
void wxWin32Renderer::DrawStatusField(wxDC& dc,
const wxRect& rect,
const wxString& label,
- int flags)
+ int flags, int style /*=0*/)
{
wxRect rectIn;
y2 = rect.GetBottom();
// draw the upper left part of the rect normally
- dc.SetPen(m_penDarkGrey);
- dc.DrawLine(rect.GetLeft(), rect.GetTop(), rect.GetLeft(), y2);
- dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(), x2, rect.GetTop());
+ if (style != wxSB_FLAT)
+ {
+ if (style == wxSB_RAISED)
+ dc.SetPen(m_penHighlight);
+ else
+ dc.SetPen(m_penDarkGrey);
+ dc.DrawLine(rect.GetLeft(), rect.GetTop(), rect.GetLeft(), y2);
+ dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(), x2, rect.GetTop());
+ }
// draw the grey stripes of the grip
size_t n;
}
// draw the remaining rect boundaries
- ofs -= WIDTH_STATUSBAR_GRIP_BAND;
- dc.DrawLine(x2, rect.GetTop(), x2, y2 - ofs + 1);
- dc.DrawLine(rect.GetLeft(), y2, x2 - ofs + 1, y2);
+ if (style != wxSB_FLAT)
+ {
+ if (style == wxSB_RAISED)
+ dc.SetPen(m_penDarkGrey);
+ else
+ dc.SetPen(m_penHighlight);
+ ofs -= WIDTH_STATUSBAR_GRIP_BAND;
+ dc.DrawLine(x2, rect.GetTop(), x2, y2 - ofs + 1);
+ dc.DrawLine(rect.GetLeft(), y2, x2 - ofs + 1, y2);
+ }
rectIn = rect;
rectIn.Deflate(1);
}
else // normal pane
{
- DrawBorder(dc, wxBORDER_STATIC, rect, flags, &rectIn);
+ if (style == wxSB_RAISED)
+ DrawBorder(dc, wxBORDER_RAISED, rect, flags, &rectIn);
+ else if (style != wxSB_FLAT)
+ DrawBorder(dc, wxBORDER_STATIC, rect, flags, &rectIn);
}
rectIn.Deflate(STATBAR_BORDER_X, STATBAR_BORDER_Y);
int fields = GetLong(wxT("fields"), 1);
wxString widths = GetParamValue(wxT("widths"));
+ wxString styles = GetParamValue(wxT("styles"));
if (fields > 1 && !widths.IsEmpty())
{
else
statbar->SetFieldsCount(fields);
+ if (!styles.IsEmpty())
+ {
+ int *style = new int[fields];
+ for (int i = 0; i < fields; ++i)
+ {
+ style[i] = wxSB_NORMAL;
+
+ wxString first = styles.BeforeFirst(wxT(','));
+ if (first == wxT("wxSB_NORMAL"))
+ style[i] = wxSB_NORMAL;
+ else if (first == wxT("wxSB_FLAT"))
+ style[i] = wxSB_FLAT;
+ else if (first == wxT("wxSB_RAISED"))
+ style[i] = wxSB_RAISED;
+
+ if (!first.IsEmpty())
+ wxLogError(wxT("Error in resource, unknown statusbar field style: ") + first);
+ if(styles.Find(wxT(',')))
+ styles.Remove(0, styles.Find(wxT(',')) + 1);
+ }
+ statbar->SetStatusStyles(fields, style);
+ delete [] style;
+ }
+
if (m_parentAsWindow)
{
wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);