#include "wx/dcclient.h"
#include "wx/intl.h"
#include "wx/log.h"
+ #include "wx/control.h"
#endif
#include "wx/msw/private.h"
#include "wx/msw/uxtheme.h"
#endif
+// no idea for a default width, just choose something
+#define DEFAULT_FIELD_WIDTH 25
+
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
SetParent(NULL);
m_hWnd = 0;
m_windowId = 0;
+ m_pDC = NULL;
}
bool wxStatusBar::Create(wxWindow *parent,
SetFieldsCount(1);
SubclassWin(m_hWnd);
+
+ // cache the DC instance used by UpdateFieldText:
+ // NOTE: create the DC before calling InheritAttributes() since
+ // it may result in a call to our SetFont()
+ m_pDC = new wxClientDC(this);
+
InheritAttributes();
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
// frame is not - otherwise statusbar leaves a hole in the place it used to
// occupy
PostSizeEventToParent();
+
+ wxDELETE(m_pDC);
+}
+
+bool wxStatusBar::SetFont(const wxFont& font)
+{
+ if (!wxWindow::SetFont(font))
+ return false;
+
+ if (m_pDC) m_pDC->SetFont(font);
+ return true;
}
void wxStatusBar::SetFieldsCount(int nFields, const int *widths)
void wxStatusBar::SetFieldsWidth()
{
- if ( !m_nFields )
+ if ( m_panes.IsEmpty() )
return;
int aBorders[3];
int extraWidth = aBorders[2]; // space between fields
wxArrayInt widthsAbs =
- CalculateAbsWidths(GetClientSize().x - extraWidth*(m_nFields - 1));
+ CalculateAbsWidths(GetClientSize().x - extraWidth*(m_panes.GetCount() - 1));
- int *pWidths = new int[m_nFields];
+ int *pWidths = new int[m_panes.GetCount()];
int nCurPos = 0;
- for ( int i = 0; i < m_nFields; i++ ) {
+ for ( size_t i = 0; i < m_panes.GetCount(); i++ ) {
nCurPos += widthsAbs[i] + extraWidth;
pWidths[i] = nCurPos;
}
- if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) {
+ if ( !StatusBar_SetParts(GetHwnd(), m_panes.GetCount(), pWidths) ) {
wxLogLastError(wxT("StatusBar_SetParts"));
}
void wxStatusBar::SetStatusText(const wxString& strText, int nField)
{
- wxCHECK_RET( (nField >= 0) && (nField < m_nFields),
+ wxCHECK_RET( (nField >= 0) && ((size_t)nField < m_panes.GetCount()),
_T("invalid statusbar field index") );
if ( strText == GetStatusText(nField) )
return;
}
+ wxStatusBarBase::SetStatusText(strText, nField);
+
+ UpdateFieldText(nField);
+}
+
+void wxStatusBar::UpdateFieldText(int nField)
+{
+ if (!m_pDC)
+ return;
+
// Get field style, if any
int style;
- if (m_statusStyles)
+ switch(m_panes[nField].nStyle)
{
- 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;
- }
+ case wxSB_RAISED:
+ style = SBT_POPOUT;
+ break;
+ case wxSB_FLAT:
+ style = SBT_NOBORDERS;
+ break;
+
+ case wxSB_NORMAL:
+ default:
+ style = 0;
+ break;
}
+
+ wxRect rc;
+ GetFieldRect(nField, rc);
+
+ int margin;
+ if (nField == GetFieldsCount()-1)
+ margin = -6; // windows reports a smaller rect for the last field; enlarge it
else
- style = 0;
+ margin = 4;
+
+ // do we need to ellipsize this string?
+ wxString ellipsizedStr =
+ wxControl::Ellipsize(GetStatusText(nField), *m_pDC,
+ GetLayoutDirection() == wxLayout_RightToLeft ? wxELLIPSIZE_START : wxELLIPSIZE_END,
+ rc.GetWidth() - margin, // leave a small margin
+ wxELLIPSIZE_EXPAND_TAB);
// 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.wx_str()) )
+ if ( !StatusBar_SetText(GetHwnd(), nField | style, ellipsizedStr.wx_str()) )
{
wxLogLastError(wxT("StatusBar_SetText"));
}
}
-wxString wxStatusBar::GetStatusText(int nField) const
-{
- wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString,
- _T("invalid statusbar field index") );
-
- wxString str;
- int len = StatusBar_GetTextLen(GetHwnd(), nField);
- if ( len > 0 )
- {
- StatusBar_GetText(GetHwnd(), nField, wxStringBuffer(str, len));
- }
-
- return str;
-}
-
int wxStatusBar::GetBorderX() const
{
int aBorders[3];
bool wxStatusBar::GetFieldRect(int i, wxRect& rect) const
{
- wxCHECK_MSG( (i >= 0) && (i < m_nFields), false,
+ wxCHECK_MSG( (i >= 0) && ((size_t)i < m_panes.GetCount()), false,
_T("invalid statusbar field index") );
RECT r;
return true;
}
-// no idea for a default width, just choose something
-#define DEFAULT_FIELD_WIDTH 25
-
wxSize wxStatusBar::DoGetBestSize() const
{
int borders[3];
// calculate width
int width = 0;
- for ( int i = 0; i < m_nFields; ++i )
+ for ( size_t i = 0; i < m_panes.GetCount(); ++i )
{
- int widthField = m_statusWidths ? m_statusWidths[i]
- : DEFAULT_FIELD_WIDTH;
+ int widthField =
+ m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].nWidth;
if ( widthField >= 0 )
{
width += widthField;
width = 2*DEFAULT_FIELD_WIDTH;
}
-
// calculate height
int height;
wxGetCharSize(GetHWND(), NULL, &height, GetFont());
{
wxStatusBarBase::SetStatusStyles(n, styles);
- if (n != m_nFields)
+ if (n != (int)m_panes.GetCount())
return;
for (int i = 0; i < n; i++)
}
#endif
+ if ( nMsg == WM_SIZE )
+ {
+ for (int i=0; i<GetFieldsCount(); i++)
+ UpdateFieldText(i);
+ // re-set the field text, in case we need to ellipsize
+ // (or de-ellipsize) some parts of it
+ }
+
return wxStatusBarBase::MSWWindowProc(nMsg, wParam, lParam);
}