X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/936f635341e9b92b37db93cc7781d564babbe25f..2d14a14c573db4b8f8959b1460a269cf23defbcf:/src/msw/statusbar.cpp diff --git a/src/msw/statusbar.cpp b/src/msw/statusbar.cpp index aef8e5c567..667b9d13b6 100644 --- a/src/msw/statusbar.cpp +++ b/src/msw/statusbar.cpp @@ -27,6 +27,7 @@ #include "wx/dcclient.h" #include "wx/intl.h" #include "wx/log.h" + #include "wx/control.h" #endif #include "wx/msw/private.h" @@ -36,6 +37,9 @@ #include "wx/msw/uxtheme.h" #endif +// no idea for a default width, just choose something +#define DEFAULT_FIELD_WIDTH 25 + // ---------------------------------------------------------------------------- // macros // ---------------------------------------------------------------------------- @@ -59,6 +63,7 @@ wxStatusBar::wxStatusBar() SetParent(NULL); m_hWnd = 0; m_windowId = 0; + m_pDC = NULL; } bool wxStatusBar::Create(wxWindow *parent, @@ -119,17 +124,23 @@ 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)); // we must refresh the frame size when the statusbar is created, because // its client area might change - wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); - if ( frame ) - { - frame->SendSizeEvent(); - } + // + // notice that we must post the event, not send it, as the frame doesn't + // know that we're its status bar yet so laying it out right now wouldn't + // work correctly, we need to wait until we return to the main loop + PostSizeEventToParent(); return true; } @@ -139,11 +150,18 @@ wxStatusBar::~wxStatusBar() // we must refresh the frame size when the statusbar is deleted but the // frame is not - otherwise statusbar leaves a hole in the place it used to // occupy - wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); - if ( frame && !frame->IsBeingDeleted() ) - { - frame->SendSizeEvent(); - } + 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) @@ -165,7 +183,7 @@ void wxStatusBar::SetStatusWidths(int n, const int widths[]) void wxStatusBar::SetFieldsWidth() { - if ( !m_nFields ) + if ( m_panes.IsEmpty() ) return; int aBorders[3]; @@ -174,17 +192,17 @@ void wxStatusBar::SetFieldsWidth() 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")); } @@ -193,7 +211,7 @@ void wxStatusBar::SetFieldsWidth() 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) ) @@ -202,50 +220,57 @@ void wxStatusBar::SetStatusText(const wxString& strText, int 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]; @@ -272,7 +297,7 @@ void wxStatusBar::SetMinHeight(int height) 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; @@ -303,9 +328,6 @@ bool wxStatusBar::GetFieldRect(int i, wxRect& rect) const return true; } -// no idea for a default width, just choose something -#define DEFAULT_FIELD_WIDTH 25 - wxSize wxStatusBar::DoGetBestSize() const { int borders[3]; @@ -313,10 +335,10 @@ wxSize wxStatusBar::DoGetBestSize() const // 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; @@ -338,7 +360,6 @@ wxSize wxStatusBar::DoGetBestSize() const width = 2*DEFAULT_FIELD_WIDTH; } - // calculate height int height; wxGetCharSize(GetHWND(), NULL, &height, GetFont()); @@ -388,7 +409,7 @@ void wxStatusBar::SetStatusStyles(int n, const int styles[]) { wxStatusBarBase::SetStatusStyles(n, styles); - if (n != m_nFields) + if (n != (int)m_panes.GetCount()) return; for (int i = 0; i < n; i++) @@ -462,6 +483,14 @@ wxStatusBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) } #endif + if ( nMsg == WM_SIZE ) + { + for (int i=0; i