]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/statusbar.cpp
suppress unused parameter warning
[wxWidgets.git] / src / msw / statusbar.cpp
index a913d193089804d59a88c1a426867ec21591334c..667b9d13b645c11a335fc8383501e2673e81d4a5 100644 (file)
@@ -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,6 +124,12 @@ 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));
@@ -140,6 +151,17 @@ wxStatusBar::~wxStatusBar()
     // 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)
@@ -175,7 +197,7 @@ void wxStatusBar::SetFieldsWidth()
     int *pWidths = new int[m_panes.GetCount()];
 
     int nCurPos = 0;
-    for ( int i = 0; i < m_panes.GetCount(); i++ ) {
+    for ( size_t i = 0; i < m_panes.GetCount(); i++ ) {
         nCurPos += widthsAbs[i] + extraWidth;
         pWidths[i] = nCurPos;
     }
@@ -189,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) )
@@ -198,6 +220,16 @@ 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;
     switch(m_panes[nField].nStyle)
@@ -215,29 +247,30 @@ void wxStatusBar::SetStatusText(const wxString& strText, int nField)
         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) && (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];
@@ -264,7 +297,7 @@ void wxStatusBar::SetMinHeight(int height)
 
 bool wxStatusBar::GetFieldRect(int i, wxRect& rect) const
 {
-    wxCHECK_MSG( (i >= 0) && (i < m_panes.GetCount()), false,
+    wxCHECK_MSG( (i >= 0) && ((size_t)i < m_panes.GetCount()), false,
                  _T("invalid statusbar field index") );
 
     RECT r;
@@ -295,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];
@@ -305,7 +335,7 @@ wxSize wxStatusBar::DoGetBestSize() const
 
     // calculate width
     int width = 0;
-    for ( int i = 0; i < m_panes.GetCount(); ++i )
+    for ( size_t i = 0; i < m_panes.GetCount(); ++i )
     {
         int widthField =
             m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].nWidth;
@@ -330,7 +360,6 @@ wxSize wxStatusBar::DoGetBestSize() const
         width = 2*DEFAULT_FIELD_WIDTH;
     }
 
-
     // calculate height
     int height;
     wxGetCharSize(GetHWND(), NULL, &height, GetFont());
@@ -380,7 +409,7 @@ void wxStatusBar::SetStatusStyles(int n, const int styles[])
 {
     wxStatusBarBase::SetStatusStyles(n, styles);
 
-    if (n != m_panes.GetCount())
+    if (n != (int)m_panes.GetCount())
         return;
 
     for (int i = 0; i < n; i++)
@@ -454,6 +483,14 @@ wxStatusBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
     }
 #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);
 }