void wxStatusBarGeneric::DrawFieldText(wxDC& dc, const wxRect& rect, int i, int textHeight) { wxString text(GetStatusText(i)); if (text.empty()) return; // optimization int xpos = rect.x + wxFIELD_TEXT_MARGIN, maxWidth = rect.width - 2*wxFIELD_TEXT_MARGIN, ypos = (int) (((rect.height - textHeight) / 2) + rect.y + 0.5); if (ShowsSizeGrip()) { // don't write text over the size grip: // NOTE: overloading DoGetClientSize() and GetClientAreaOrigin() wouldn't // work because the adjustment needs to be done only when drawing // the field text and not also when drawing the background, the // size grip itself, etc if ((GetLayoutDirection() == wxLayout_RightToLeft && i == 0) || (GetLayoutDirection() != wxLayout_RightToLeft && i == (int)m_panes.GetCount()-1)) { const wxRect& gripRc = GetSizeGripRect(); // NOTE: we don't need any special treatment wrt to the layout direction // since DrawText() will automatically adjust the origin of the // text accordingly to the layout in use maxWidth -= gripRc.width; } } // eventually ellipsize the text so that it fits the field width wxEllipsizeMode ellmode = wxELLIPSIZE_NONE; if (HasFlag(wxSTB_ELLIPSIZE_START)) ellmode = wxELLIPSIZE_START; else if (HasFlag(wxSTB_ELLIPSIZE_MIDDLE)) ellmode = wxELLIPSIZE_MIDDLE; else if (HasFlag(wxSTB_ELLIPSIZE_END)) ellmode = wxELLIPSIZE_END; if (ellmode == wxELLIPSIZE_NONE) { // if we have the wxSTB_SHOW_TIPS we must set the ellipsized flag even if // we don't ellipsize the text but just truncate it if (HasFlag(wxSTB_SHOW_TIPS)) SetEllipsizedFlag(i, dc.GetTextExtent(text).GetWidth() > maxWidth); dc.SetClippingRegion(rect); } else { text = wxControl::Ellipsize(text, dc, ellmode, maxWidth, wxELLIPSIZE_FLAGS_EXPAND_TABS); // Ellipsize() will do something only if necessary // update the ellipsization status for this pane; this is used later to // decide whether a tooltip should be shown or not for this pane // (if we have wxSTB_SHOW_TIPS) SetEllipsizedFlag(i, text != GetStatusText(i)); } #if defined( __WXGTK__ ) || defined(__WXMAC__) xpos++; ypos++; #endif // draw the text dc.DrawText(text, xpos, ypos); if (ellmode == wxELLIPSIZE_NONE) dc.DestroyClippingRegion(); }
void wxStatusBar::DoUpdateStatusText(int nField) { if (!m_pDC) return; // Get field style, if any int style; switch(m_panes[nField].GetStyle()) { 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); const int maxWidth = rc.GetWidth() - MSWGetMetrics().textMargin; wxString text = GetStatusText(nField); // do we need to ellipsize this string? wxEllipsizeMode ellmode = (wxEllipsizeMode)-1; if (HasFlag(wxSTB_ELLIPSIZE_START)) ellmode = wxELLIPSIZE_START; else if (HasFlag(wxSTB_ELLIPSIZE_MIDDLE)) ellmode = wxELLIPSIZE_MIDDLE; else if (HasFlag(wxSTB_ELLIPSIZE_END)) ellmode = wxELLIPSIZE_END; if (ellmode == (wxEllipsizeMode)-1) { // if we have the wxSTB_SHOW_TIPS we must set the ellipsized flag even if // we don't ellipsize the text but just truncate it if (HasFlag(wxSTB_SHOW_TIPS)) SetEllipsizedFlag(nField, m_pDC->GetTextExtent(text).GetWidth() > maxWidth); } else { text = wxControl::Ellipsize(text, *m_pDC, ellmode, maxWidth, wxELLIPSIZE_FLAGS_EXPAND_TABS); // update the ellipsization status for this pane; this is used later to // decide whether a tooltip should be shown or not for this pane // (if we have wxSTB_SHOW_TIPS) SetEllipsizedFlag(nField, text != GetStatusText(nField)); } // Set the status text in the native control passing both field number and style. // NOTE: MSDN library doesn't mention that nField and style have to be 'ORed' if ( !StatusBar_SetText(GetHwnd(), nField | style, text.wx_str()) ) { wxLogLastError("StatusBar_SetText"); } #if wxUSE_TOOLTIPS if (HasFlag(wxSTB_SHOW_TIPS)) { wxASSERT(m_tooltips.size() == m_panes.GetCount()); if (m_tooltips[nField]) { if (GetField(nField).IsEllipsized()) { // update the rect of this tooltip: m_tooltips[nField]->SetRect(rc); // update also the text: m_tooltips[nField]->SetTip(GetStatusText(nField)); } else { // delete the tooltip associated with this pane; it's not needed anymore wxDELETE(m_tooltips[nField]); } } else { // create a new tooltip for this pane if needed if (GetField(nField).IsEllipsized()) m_tooltips[nField] = new wxToolTip(this, nField, GetStatusText(nField), rc); //else: leave m_tooltips[nField]==NULL } } #endif // wxUSE_TOOLTIPS }