added status bar fields styles support (patch 988292)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28480 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2004-07-25 16:13:52 +00:00
parent 22dec51f90
commit c2919ab326
14 changed files with 373 additions and 50 deletions

View File

@@ -53,12 +53,14 @@ wxStatusBarBase::wxStatusBarBase()
InitWidths();
InitStacks();
InitStyles();
}
wxStatusBarBase::~wxStatusBarBase()
{
FreeWidths();
FreeStacks();
InitStyles();
}
// ----------------------------------------------------------------------------
@@ -75,6 +77,20 @@ void wxStatusBarBase::FreeWidths()
delete [] m_statusWidths;
}
// ----------------------------------------------------------------------------
// styles array handling
// ----------------------------------------------------------------------------
void wxStatusBarBase::InitStyles()
{
m_statusStyles = NULL;
}
void wxStatusBarBase::FreeStyles()
{
delete [] m_statusStyles;
}
// ----------------------------------------------------------------------------
// field widths
// ----------------------------------------------------------------------------
@@ -112,6 +128,26 @@ void wxStatusBarBase::SetFieldsCount(int number, const int *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();
@@ -151,6 +187,25 @@ void wxStatusBarBase::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n),
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;

View File

@@ -140,12 +140,10 @@ void wxStatusBarGeneric::SetFieldsCount(int number, const int *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)
@@ -269,43 +267,52 @@ void wxStatusBarGeneric::DrawField(wxDC& dc, int i)
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.
int style = wxSB_NORMAL;
if (m_statusStyles)
style = m_statusStyles[i];
dc.SetPen(m_hilightPen);
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
#ifndef __WXPM__
dc.SetPen((style == wxSB_RAISED) ? m_mediumShadowPen : m_hilightPen);
// 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);
#ifndef __WXPM__
dc.SetPen(m_mediumShadowPen);
// 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);
// 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.SetPen((style == wxSB_RAISED) ? m_hilightPen : m_mediumShadowPen);
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);
// 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.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);
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);
}

View File

@@ -177,7 +177,30 @@ void wxStatusBar95::SetStatusText(const wxString& strText, int nField)
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"));
}
@@ -267,5 +290,39 @@ void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height)
}
}
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

View File

@@ -140,7 +140,12 @@ void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
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;

View File

@@ -42,6 +42,7 @@
#include "wx/slider.h"
#include "wx/textctrl.h"
#include "wx/toolbar.h"
#include "wx/statusbr.h"
#include "wx/settings.h"
#endif // WX_PRECOMP
@@ -228,7 +229,7 @@ public:
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,
@@ -2236,7 +2237,7 @@ wxGTKRenderer::GetStatusBarBorders(wxCoord * WXUNUSED(borderBetweenFields)) cons
void wxGTKRenderer::DrawStatusField(wxDC& WXUNUSED(dc),
const wxRect& WXUNUSED(rect),
const wxString& WXUNUSED(label),
int WXUNUSED(flags))
int WXUNUSED(flags), int WXUNUSED(style))
{
}

View File

@@ -40,6 +40,7 @@
#include "wx/textctrl.h"
#include "wx/listbox.h"
#include "wx/toolbar.h"
#include "wx/statusbr.h"
#ifdef __WXMSW__
// for COLOR_* constants
@@ -299,7 +300,7 @@ public:
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,
@@ -3224,7 +3225,7 @@ wxSize wxWin32Renderer::GetStatusBarBorders(wxCoord *borderBetweenFields) const
void wxWin32Renderer::DrawStatusField(wxDC& dc,
const wxRect& rect,
const wxString& label,
int flags)
int flags, int style /*=0*/)
{
wxRect rectIn;
@@ -3240,9 +3241,15 @@ void wxWin32Renderer::DrawStatusField(wxDC& dc,
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;
@@ -3262,9 +3269,16 @@ void wxWin32Renderer::DrawStatusField(wxDC& dc,
}
// 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);
@@ -3273,7 +3287,10 @@ void wxWin32Renderer::DrawStatusField(wxDC& dc,
}
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);

View File

@@ -47,6 +47,7 @@ wxObject *wxStatusBarXmlHandler::DoCreateResource()
int fields = GetLong(wxT("fields"), 1);
wxString widths = GetParamValue(wxT("widths"));
wxString styles = GetParamValue(wxT("styles"));
if (fields > 1 && !widths.IsEmpty())
{
@@ -64,6 +65,30 @@ wxObject *wxStatusBarXmlHandler::DoCreateResource()
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);