]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/statusbar.cpp
No changes, just move wxTreeCtrlBase ctor to the source file.
[wxWidgets.git] / src / msw / statusbar.cpp
index 1f3fbbb4d43b18e78f1d3e0e370bcac319dee67b..48960afe2203a4a726539e1e94b9da83e8725687 100644 (file)
@@ -89,7 +89,7 @@ WXDWORD wxStatusBar::MSWGetStyle(long style, WXDWORD *exstyle) const
     WXDWORD msStyle = wxStatusBarBase::MSWGetStyle(style, exstyle);
 
     // wxSTB_SIZEGRIP is part of our default style but it doesn't make sense to
-    // show size grip if this is the status bar of a non-resizeable TLW so turn
+    // show size grip if this is the status bar of a non-resizable TLW so turn
     // it off in such case
     wxWindow * const parent = GetParent();
     wxCHECK_MSG( parent, msStyle, wxS("Status bar must have a parent") );
@@ -103,14 +103,14 @@ WXDWORD wxStatusBar::MSWGetStyle(long style, WXDWORD *exstyle) const
     // is not given
     if ( !(style & wxSTB_SIZEGRIP) )
     {
-        *exstyle |= CCS_TOP;
+        msStyle |= CCS_TOP;
     }
     else
     {
 #ifndef __WXWINCE__
         // may be some versions of comctl32.dll do need it - anyhow, it won't
         // do any harm
-        *exstyle |= SBARS_SIZEGRIP;
+       msStyle |= SBARS_SIZEGRIP;
 #endif
     }
 
@@ -135,8 +135,6 @@ bool wxStatusBar::Create(wxWindow *parent,
     // cache the DC instance used by DoUpdateStatusText:
     m_pDC = new wxClientDC(this);
 
-    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
-
     // we must refresh the frame size when the statusbar is created, because
     // its client area might change
     //
@@ -178,10 +176,6 @@ void wxStatusBar::SetFieldsCount(int nFields, const int *widths)
     // this is a Windows limitation
     wxASSERT_MSG( (nFields > 0) && (nFields < 255), "too many fields" );
 
-    wxStatusBarBase::SetFieldsCount(nFields, widths);
-
-    MSWUpdateFieldsWidths();
-
     // keep in synch also our m_tooltips array
 
     // reset all current tooltips
@@ -191,7 +185,11 @@ void wxStatusBar::SetFieldsCount(int nFields, const int *widths)
     }
 
     // shrink/expand the array:
-    m_tooltips.resize(m_panes.GetCount(), NULL);
+    m_tooltips.resize(nFields, NULL);
+
+    wxStatusBarBase::SetFieldsCount(nFields, widths);
+
+    MSWUpdateFieldsWidths();
 }
 
 void wxStatusBar::SetStatusWidths(int n, const int widths[])
@@ -215,8 +213,11 @@ void wxStatusBar::MSWUpdateFieldsWidths()
     widthAvailable -= extraWidth*(count - 1);   // extra space between fields
     widthAvailable -= MSWGetMetrics().textMargin;   // and for the last field
 
-    if ( HasFlag(wxSTB_SIZEGRIP) )
-        widthAvailable -= MSWGetMetrics().gripWidth;
+    // Deal with the grip: we shouldn't overflow onto the space occupied by it
+    // so the effectively available space is smaller.
+    const int gripWidth = HasFlag(wxSTB_SIZEGRIP) ? MSWGetMetrics().gripWidth
+                                                  : 0;
+    widthAvailable -= gripWidth;
 
     // distribute the available space (client width) among the various fields:
 
@@ -228,21 +229,30 @@ void wxStatusBar::MSWUpdateFieldsWidths()
     int *pWidths = new int[count];
 
     int nCurPos = 0;
-    for ( int i = 0; i < count; i++ )
+    int i;
+    for ( i = 0; i < count; i++ )
     {
         nCurPos += widthsAbs[i] + extraWidth;
         pWidths[i] = nCurPos;
     }
 
+    // The total width of the panes passed to Windows must be equal to the
+    // total width available, including the grip. Otherwise we get an extra
+    // separator line just before it.
+    pWidths[count - 1] += gripWidth;
+
     if ( !StatusBar_SetParts(GetHwnd(), count, pWidths) )
     {
         wxLogLastError("StatusBar_SetParts");
     }
 
-    delete [] pWidths;
-
+    // Now that all parts have been created, set their text.
+    for ( i = 0; i < count; i++ )
+    {
+        DoUpdateStatusText(i);
+    }
 
-    // FIXME: we may want to call DoUpdateStatusText() here since we may need to (de)ellipsize status texts
+    delete [] pWidths;
 }
 
 void wxStatusBar::DoUpdateStatusText(int nField)
@@ -368,7 +378,7 @@ int wxStatusBar::MSWGetBorderWidth() const
 /* static */
 const wxStatusBar::MSWMetrics& wxStatusBar::MSWGetMetrics()
 {
-    static MSWMetrics s_metrics = { 0 };
+    static MSWMetrics s_metrics = { 0, 0 };
     if ( !s_metrics.textMargin )
     {
         // Grip size should be self explanatory (the only problem with it is
@@ -395,7 +405,18 @@ const wxStatusBar::MSWMetrics& wxStatusBar::MSWGetMetrics()
 
 void wxStatusBar::SetMinHeight(int height)
 {
-    SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0);
+    // It looks like we need to count the border twice to really make the
+    // controls taking exactly height pixels fully fit in the status bar:
+    // at least under Windows 7 the checkbox in the custom status bar of the
+    // statbar sample gets truncated otherwise.
+    height += 4*GetBorderY();
+
+    // We need to set the size and not the size to reflect the height because
+    // wxFrame uses our size and not the minimal size as it assumes that the
+    // size of a status bar never changes anyhow.
+    SetSize(-1, height);
+
+    SendMessage(GetHwnd(), SB_SETMINHEIGHT, height, 0);
 
     // we have to send a (dummy) WM_SIZE to redraw it now
     SendMessage(GetHwnd(), WM_SIZE, 0, 0);
@@ -431,14 +452,6 @@ bool wxStatusBar::GetFieldRect(int i, wxRect& rect) const
 
     wxCopyRECTToRect(r, rect);
 
-    // Windows seems to under-report the size of the last field rectangle,
-    // presumably in order to prevent the buggy applications from overflowing
-    // onto the size grip but we want to return the real size to wx users
-    if ( HasFlag(wxSTB_SIZEGRIP) && i == (int)m_panes.GetCount() - 1 )
-    {
-        rect.width += MSWGetMetrics().gripWidth - MSWGetBorderWidth();
-    }
-
     return true;
 }
 
@@ -473,11 +486,10 @@ wxSize wxStatusBar::DoGetBestSize() const
         width = 2*DEFAULT_FIELD_WIDTH;
     }
 
-    // calculate height
-    int height;
-    wxGetCharSize(GetHWND(), NULL, &height, GetFont());
-    height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(height);
-    height += borders.vert;
+    // calculate height: by default it should be just big enough to show text
+    // (see SetMinHeight() for the explanation of 4 factor)
+    int height = GetCharHeight();
+    height += 4*borders.vert;
 
     wxSize best(width, height);
     CacheBestSize(best);
@@ -504,9 +516,6 @@ void wxStatusBar::DoMoveWindow(int x, int y, int width, int height)
                        );
     }
 
-    // adjust fields widths to the new size
-    MSWUpdateFieldsWidths();
-
     // we have to trigger wxSizeEvent if there are children window in status
     // bar because GetFieldRect returned incorrect (not updated) values up to
     // here, which almost certainly resulted in incorrectly redrawn statusbar
@@ -597,15 +606,21 @@ wxStatusBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
     }
 #endif
 
-    bool needsEllipsization = HasFlag(wxSTB_ELLIPSIZE_START) ||
-                              HasFlag(wxSTB_ELLIPSIZE_MIDDLE) ||
-                              HasFlag(wxSTB_ELLIPSIZE_END);
-    if ( nMsg == WM_SIZE && needsEllipsization )
+    if ( nMsg == WM_SIZE )
     {
-        for (int i=0; i<GetFieldsCount(); i++)
-            DoUpdateStatusText(i);
-            // re-set the field text, in case we need to ellipsize
-            // (or de-ellipsize) some parts of it
+        MSWUpdateFieldsWidths();
+
+        if ( HasFlag(wxSTB_ELLIPSIZE_START) ||
+                HasFlag(wxSTB_ELLIPSIZE_MIDDLE) ||
+                    HasFlag(wxSTB_ELLIPSIZE_END) )
+        {
+            for (int i=0; i<GetFieldsCount(); i++)
+            {
+                // re-set the field text, in case we need to ellipsize
+                // (or de-ellipsize) some parts of it
+                DoUpdateStatusText(i);
+            }
+        }
     }
 
     return wxStatusBarBase::MSWWindowProc(nMsg, wParam, lParam);