m_pDC = NULL;
}
-bool wxStatusBar::Create(wxWindow *parent,
- wxWindowID id,
- long style,
- const wxString& name)
+WXDWORD wxStatusBar::MSWGetStyle(long style, WXDWORD *exstyle) const
{
- wxCHECK_MSG( parent, false, "status bar must have a parent" );
-
- SetName(name);
- SetWindowStyleFlag(style);
- SetParent(parent);
+ WXDWORD msStyle = wxStatusBarBase::MSWGetStyle(style, exstyle);
- parent->AddChild(this);
-
- m_windowId = id == wxID_ANY ? NewControlId() : id;
-
- DWORD wstyle = WS_CHILD | WS_VISIBLE;
-
- if ( style & wxCLIP_SIBLINGS )
- wstyle |= WS_CLIPSIBLINGS;
+ // 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-resizable TLW so turn
+ // it off in such case
+ wxWindow * const parent = GetParent();
+ wxCHECK_MSG( parent, msStyle, wxS("Status bar must have a parent") );
+ if ( parent->IsTopLevel() && !parent->HasFlag(wxRESIZE_BORDER) )
+ style &= ~wxSTB_SIZEGRIP;
// setting SBARS_SIZEGRIP is perfectly useless: it's always on by default
// (at least in the version of comctl32.dll I'm using), and the only way to
// is not given
if ( !(style & wxSTB_SIZEGRIP) )
{
- wstyle |= 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
- wstyle |= SBARS_SIZEGRIP;
+ msStyle |= SBARS_SIZEGRIP;
#endif
}
- m_hWnd = CreateWindow
- (
- STATUSCLASSNAME,
- wxT(""),
- wstyle,
- 0, 0, 0, 0,
- GetHwndOf(parent),
- (HMENU)wxUIntToPtr(m_windowId.GetValue()),
- wxGetInstance(),
- NULL
- );
- if ( m_hWnd == 0 )
- {
- wxLogSysError(_("Failed to create a status bar."));
+ return msStyle;
+}
+bool wxStatusBar::Create(wxWindow *parent,
+ wxWindowID id,
+ long style,
+ const wxString& name)
+{
+ if ( !CreateControl(parent, id, wxDefaultPosition, wxDefaultSize,
+ style, wxDefaultValidator, name) )
+ return false;
+
+ if ( !MSWCreateControl(STATUSCLASSNAME, wxString(),
+ wxDefaultPosition, wxDefaultSize) )
return false;
- }
SetFieldsCount(1);
- SubclassWin(m_hWnd);
// cache the DC instance used by DoUpdateStatusText:
- // 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
//
// delete existing tooltips
for (size_t i=0; i<m_tooltips.size(); i++)
{
- if (m_tooltips[i])
- {
- delete m_tooltips[i];
- m_tooltips[i] = NULL;
- }
+ wxDELETE(m_tooltips[i]);
}
wxDELETE(m_pDC);
// reset all current tooltips
for (size_t i=0; i<m_tooltips.size(); i++)
{
- if (m_tooltips[i])
- {
- delete m_tooltips[i];
- m_tooltips[i] = NULL;
- }
+ wxDELETE(m_tooltips[i]);
}
// shrink/expand the array:
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:
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");
else
{
// delete the tooltip associated with this pane; it's not needed anymore
- delete m_tooltips[nField];
- m_tooltips[nField] = NULL;
+ wxDELETE(m_tooltips[nField]);
}
}
else
/* 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
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;
}
);
}
- // 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
}
#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);