#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)
return;
}
+ wxStatusBarBase::SetStatusText(strText, nField);
+
+ UpdateFieldText(nField);
+}
+
+void wxStatusBar::UpdateFieldText(int nField)
+{
+ if (!m_pDC)
+ return;
+
// Get field style, if any
int style;
- switch(m_panes[nField].nStyle)
+ switch(m_panes[nField].GetStyle())
{
case wxSB_RAISED:
style = SBT_POPOUT;
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
+ 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) && ((size_t)nField < m_panes.GetCount()), 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];
return true;
}
-// no idea for a default width, just choose something
-#define DEFAULT_FIELD_WIDTH 25
-
wxSize wxStatusBar::DoGetBestSize() const
{
int borders[3];
for ( size_t i = 0; i < m_panes.GetCount(); ++i )
{
int widthField =
- m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].nWidth;
+ m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].GetWidth();
if ( widthField >= 0 )
{
width += widthField;
width = 2*DEFAULT_FIELD_WIDTH;
}
-
// calculate height
int height;
wxGetCharSize(GetHWND(), NULL, &height, GetFont());
}
#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);
}