implement tooltips for wxStatusBar panes whose contents were ellipsized; introduce wxST_SHOW_TIPS and wxST_DEFAULT_STYLE styles

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60265 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi 2009-04-21 11:10:44 +00:00
parent 9b49405777
commit c94bdf2a19
10 changed files with 135 additions and 36 deletions

View File

@ -1769,11 +1769,6 @@ enum wxBorder
#define wxTC_MULTILINE 0x0200 /* == wxNB_MULTILINE */ #define wxTC_MULTILINE 0x0200 /* == wxNB_MULTILINE */
#define wxTC_OWNERDRAW 0x0400 #define wxTC_OWNERDRAW 0x0400
/*
* wxStatusBar95 flags
*/
#define wxST_SIZEGRIP 0x0010
/* /*
* wxStaticBitmap flags * wxStaticBitmap flags
*/ */

View File

@ -17,6 +17,7 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include "wx/toplevel.h" // the base class #include "wx/toplevel.h" // the base class
#include "wx/statusbr.h"
// the default names for various classs // the default names for various classs
extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusLineNameStr[]; extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusLineNameStr[];
@ -103,10 +104,9 @@ public:
#if wxUSE_STATUSBAR #if wxUSE_STATUSBAR
// create the main status bar by calling OnCreateStatusBar() // create the main status bar by calling OnCreateStatusBar()
virtual wxStatusBar* CreateStatusBar(int number = 1, virtual wxStatusBar* CreateStatusBar(int number = 1,
long style = wxST_SIZEGRIP|wxFULL_REPAINT_ON_RESIZE, long style = wxST_DEFAULT_STYLE,
wxWindowID winid = 0, wxWindowID winid = 0,
const wxString& name = const wxString& name = wxStatusLineNameStr);
wxStatusLineNameStr);
// return a new status bar // return a new status bar
virtual wxStatusBar *OnCreateStatusBar(int number, virtual wxStatusBar *OnCreateStatusBar(int number,
long style, long style,

View File

@ -30,7 +30,7 @@ public:
wxStatusBarGeneric() { Init(); } wxStatusBarGeneric() { Init(); }
wxStatusBarGeneric(wxWindow *parent, wxStatusBarGeneric(wxWindow *parent,
wxWindowID winid = wxID_ANY, wxWindowID winid = wxID_ANY,
long style = wxST_SIZEGRIP, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxStatusBarNameStr) const wxString& name = wxStatusBarNameStr)
{ {
Init(); Init();
@ -41,7 +41,7 @@ public:
virtual ~wxStatusBarGeneric(); virtual ~wxStatusBarGeneric();
bool Create(wxWindow *parent, wxWindowID winid = wxID_ANY, bool Create(wxWindow *parent, wxWindowID winid = wxID_ANY,
long style = wxST_SIZEGRIP, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxStatusBarNameStr); const wxString& name = wxStatusBarNameStr);
// Create status line // Create status line
@ -64,6 +64,10 @@ public:
virtual int GetBorderY() const { return m_borderY; } virtual int GetBorderY() const { return m_borderY; }
// implementation only (not part of wxStatusBar public API):
int GetFieldFromPoint(const wxPoint& point) const;
protected: // event handlers protected: // event handlers
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
@ -104,6 +108,7 @@ protected:
int m_borderX; int m_borderX;
int m_borderY; int m_borderY;
wxPen m_mediumShadowPen; wxPen m_mediumShadowPen;
wxPen m_hilightPen; wxPen m_hilightPen;

View File

@ -23,7 +23,7 @@ public:
wxStatusBar(); wxStatusBar();
wxStatusBar(wxWindow *parent, wxStatusBar(wxWindow *parent,
wxWindowID id = wxID_ANY, wxWindowID id = wxID_ANY,
long style = wxST_SIZEGRIP, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxStatusBarNameStr) const wxString& name = wxStatusBarNameStr)
{ {
m_pDC = NULL; m_pDC = NULL;
@ -32,7 +32,7 @@ public:
bool Create(wxWindow *parent, bool Create(wxWindow *parent,
wxWindowID id = wxID_ANY, wxWindowID id = wxID_ANY,
long style = wxST_SIZEGRIP, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxStatusBarNameStr); const wxString& name = wxStatusBarNameStr);
virtual ~wxStatusBar(); virtual ~wxStatusBar();

View File

@ -19,13 +19,13 @@ class WXDLLIMPEXP_CORE wxStatusBarMac : public wxStatusBarGeneric
wxStatusBarMac(); wxStatusBarMac();
wxStatusBarMac(wxWindow *parent, wxWindowID id = wxID_ANY, wxStatusBarMac(wxWindow *parent, wxWindowID id = wxID_ANY,
long style = wxST_SIZEGRIP, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxStatusBarNameStr); const wxString& name = wxStatusBarNameStr);
virtual ~wxStatusBarMac(); virtual ~wxStatusBarMac();
bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,
long style = wxST_SIZEGRIP, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxStatusBarNameStr); const wxString& name = wxStatusBarNameStr);
virtual void DrawFieldText(wxDC& dc, const wxRect& rc, int i, int textHeight); virtual void DrawFieldText(wxDC& dc, const wxRect& rc, int i, int textHeight);

View File

@ -21,7 +21,7 @@ public:
wxStatusBarPalm(); wxStatusBarPalm();
wxStatusBarPalm(wxWindow *parent, wxStatusBarPalm(wxWindow *parent,
wxWindowID id = wxID_ANY, wxWindowID id = wxID_ANY,
long style = wxST_SIZEGRIP, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxEmptyString) const wxString& name = wxEmptyString)
{ {
(void)Create(parent, id, style, name); (void)Create(parent, id, style, name);
@ -29,7 +29,7 @@ public:
bool Create(wxWindow *parent, bool Create(wxWindow *parent,
wxWindowID id = wxID_ANY, wxWindowID id = wxID_ANY,
long style = wxST_SIZEGRIP, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxEmptyString); const wxString& name = wxEmptyString);
virtual ~wxStatusBarPalm(); virtual ~wxStatusBarPalm();

View File

@ -26,6 +26,12 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusBarNameStr[];
// wxStatusBar constants // wxStatusBar constants
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxStatusBar styles
#define wxST_SIZEGRIP 0x0010
#define wxST_SHOW_TIPS 0x0020
#define wxST_DEFAULT_STYLE (wxST_SIZEGRIP|wxST_SHOW_TIPS|wxFULL_REPAINT_ON_RESIZE)
// style flags for fields // style flags for fields
#define wxSB_NORMAL 0x0000 #define wxSB_NORMAL 0x0000
#define wxSB_FLAT 0x0001 #define wxSB_FLAT 0x0001
@ -42,7 +48,8 @@ class WXDLLIMPEXP_CORE wxStatusBarPane
public: public:
wxStatusBarPane(int style = wxSB_NORMAL, size_t width = 0) wxStatusBarPane(int style = wxSB_NORMAL, size_t width = 0)
: m_nStyle(style), m_nWidth(width) { m_arrStack.Add(wxEmptyString); } : m_nStyle(style), m_nWidth(width)
{ m_arrStack.Add(wxEmptyString); m_bEllipsized=false; }
int GetWidth() const int GetWidth() const
{ return m_nWidth; } { return m_nWidth; }
@ -52,7 +59,12 @@ public:
const wxArrayString& GetStack() const const wxArrayString& GetStack() const
{ return m_arrStack; } { return m_arrStack; }
// use wxStatusBar setter functions to modify a wxStatusBarPane // implementation-only getter:
bool IsEllipsized() const
{ return m_bEllipsized; }
// NOTE: there are no setters in wxStatusBarPane;
// use wxStatusBar functions to modify a wxStatusBarPane
protected: protected:
int m_nStyle; int m_nStyle;
@ -61,9 +73,12 @@ protected:
// this is the array of the stacked strings of this pane; note that this // this is the array of the stacked strings of this pane; note that this
// stack does include also the string currently displayed in this pane // stack does include also the string currently displayed in this pane
// as the version stored in the native status bar control is possibly // as the version stored in the native status bar control is possibly
// ellipsized; note that arrStack.Last() is the top of the stack // ellipsized; note that m_arrStack.Last() is the top of the stack
// (i.e. the string shown in the status bar) // (i.e. the string shown in the status bar)
wxArrayString m_arrStack; wxArrayString m_arrStack;
// was the m_arrStack.Last() string shown in the status bar control ellipsized?
bool m_bEllipsized;
}; };
WX_DECLARE_OBJARRAY(wxStatusBarPane, wxStatusBarPaneArray); WX_DECLARE_OBJARRAY(wxStatusBarPane, wxStatusBarPaneArray);
@ -139,6 +154,9 @@ public:
virtual int GetBorderX() const = 0; virtual int GetBorderX() const = 0;
virtual int GetBorderY() const = 0; virtual int GetBorderY() const = 0;
wxSize GetBorders() const
{ return wxSize(GetBorderX(), GetBorderY()); }
// miscellaneous // miscellaneous
// ------------- // -------------
@ -159,6 +177,11 @@ protected:
// calculate the real field widths for the given total available size // calculate the real field widths for the given total available size
wxArrayInt CalculateAbsWidths(wxCoord widthTotal) const; wxArrayInt CalculateAbsWidths(wxCoord widthTotal) const;
// an internal utility used to keep track of which panes have labels
// which were last rendered as ellipsized...
void SetEllipsizedFlag(int n, bool ellipsized)
{ m_panes[n].m_bEllipsized = ellipsized; }
// the array with the pane infos: // the array with the pane infos:
wxStatusBarPaneArray m_panes; wxStatusBarPaneArray m_panes;

View File

@ -27,7 +27,7 @@ public:
wxStatusBarUniv(wxWindow *parent, wxStatusBarUniv(wxWindow *parent,
wxWindowID id = wxID_ANY, wxWindowID id = wxID_ANY,
long style = 0, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxPanelNameStr) const wxString& name = wxPanelNameStr)
{ {
Init(); Init();
@ -37,7 +37,7 @@ public:
bool Create(wxWindow *parent, bool Create(wxWindow *parent,
wxWindowID id = wxID_ANY, wxWindowID id = wxID_ANY,
long style = 0, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxPanelNameStr); const wxString& name = wxPanelNameStr);
// set field count/widths // set field count/widths

View File

@ -53,9 +53,18 @@ public:
to give small amounts of status information. It can contain one or more fields, to give small amounts of status information. It can contain one or more fields,
one or more of which can be variable length according to the size of the window. one or more of which can be variable length according to the size of the window.
Note that in wxStatusBar context, the terms @e pane and @e field are synonyms.
@beginStyleTable @beginStyleTable
@style{wxST_SIZEGRIP} @style{wxST_SIZEGRIP}
Displays a gripper at the right-hand side of the status bar. Displays a gripper at the right-hand side of the status bar which can be used
to resize the parent window.
@style{wxST_SHOW_TIPS}
Displays tooltips for those panes whose status text has been ellipsized because
the status text doesn't fit the pane width.
Note that this style has effect only on wxGTK (with GTK+ >= 2.12) currently.
@style{wxST_DEFAULT_STYLE}
The default style: includes @c wxST_SIZEGRIP|wxST_SHOW_TIPS|wxFULL_REPAINT_ON_RESIZE.
@endStyleTable @endStyleTable
@remarks @remarks
@ -93,7 +102,7 @@ public:
@see Create() @see Create()
*/ */
wxStatusBar(wxWindow* parent, wxWindowID id = wxID_ANY, wxStatusBar(wxWindow* parent, wxWindowID id = wxID_ANY,
long style = wxST_SIZEGRIP, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxStatusBarNameStr); const wxString& name = wxStatusBarNameStr);
/** /**
@ -106,7 +115,7 @@ public:
See wxStatusBar() for details. See wxStatusBar() for details.
*/ */
bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
long style = wxST_SIZEGRIP, long style = wxST_DEFAULT_STYLE,
const wxString& name = wxStatusBarNameStr); const wxString& name = wxStatusBarNameStr);
/** /**
@ -133,6 +142,15 @@ public:
*/ */
const wxStatusBarPane& GetField(int n) const; const wxStatusBarPane& GetField(int n) const;
/**
Returns the horizontal and vertical borders used when rendering the field
text inside the field area.
Note that the rect returned by GetFieldRect() already accounts for the
presence of horizontal and vertical border returned by this function.
*/
wxSize GetBorders() const;
/** /**
Returns the string associated with a status bar field. Returns the string associated with a status bar field.

View File

@ -2,7 +2,7 @@
// Name: src/generic/statusbr.cpp // Name: src/generic/statusbr.cpp
// Purpose: wxStatusBarGeneric class implementation // Purpose: wxStatusBarGeneric class implementation
// Author: Julian Smart // Author: Julian Smart
// Modified by: // Modified by: Francesco Montorsi
// Created: 01/02/97 // Created: 01/02/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart // Copyright: (c) Julian Smart
@ -29,6 +29,7 @@
#ifdef __WXGTK20__ #ifdef __WXGTK20__
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "wx/gtk/private.h"
#endif #endif
// we only have to do it here when we use wxStatusBarGeneric in addition to the // we only have to do it here when we use wxStatusBarGeneric in addition to the
@ -48,6 +49,33 @@
// Margin between the field text and the field rect // Margin between the field text and the field rect
#define wxFIELD_TEXT_MARGIN 2 #define wxFIELD_TEXT_MARGIN 2
// ----------------------------------------------------------------------------
// GTK+ signal handler
// ----------------------------------------------------------------------------
#if defined( __WXGTK20__ ) && GTK_CHECK_VERSION(2,12,0)
extern "C" {
static
gboolean statusbar_query_tooltip(GtkWidget *widget,
gint x,
gint y,
gboolean keyboard_mode,
GtkTooltip *tooltip,
wxStatusBar* statbar)
{
int n = statbar->GetFieldFromPoint(wxPoint(x,y));
if (n == wxNOT_FOUND)
return FALSE;
// should we show the tooltip for the n-th pane of the statusbar?
if (!statbar->GetField(n).IsEllipsized())
return FALSE; // no, it's not useful
gtk_tooltip_set_text(tooltip, wxGTK_CONV_SYS(statbar->GetStatusText(n)));
return TRUE;
}
}
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxStatusBarGeneric // wxStatusBarGeneric
@ -96,6 +124,15 @@ bool wxStatusBarGeneric::Create(wxWindow *parent,
SetFieldsCount(1); SetFieldsCount(1);
#if defined( __WXGTK20__ ) && GTK_CHECK_VERSION(2,12,0)
if (HasFlag(wxST_SHOW_TIPS) && !gtk_check_version(2,12,0))
{
g_object_set(m_widget, "has-tooltip", TRUE, NULL);
g_signal_connect(m_widget, "query-tooltip",
G_CALLBACK(statusbar_query_tooltip), this);
}
#endif
return true; return true;
} }
@ -208,6 +245,10 @@ void wxStatusBarGeneric::DrawFieldText(wxDC& dc, const wxRect& rect, int i, int
wxELLIPSIZE_EXPAND_TAB); wxELLIPSIZE_EXPAND_TAB);
// Ellipsize() will do something only if necessary // Ellipsize() will do something only if necessary
// update the ellipsization status for this pane; this is used to decide
// whether a tooltip should be shown or not for this pane
SetEllipsizedFlag(i, text != GetStatusText(i));
#if defined( __WXGTK__ ) || defined(__WXMAC__) #if defined( __WXGTK__ ) || defined(__WXMAC__)
xpos++; xpos++;
ypos++; ypos++;
@ -229,11 +270,8 @@ void wxStatusBarGeneric::DrawField(wxDC& dc, int i, int textHeight)
if (style != wxSB_FLAT) if (style != wxSB_FLAT)
{ {
// Draw border // Draw border
// For wxSB_NORMAL: // For wxSB_NORMAL: paint a grey background, plus 3-d border (one black rectangle)
// Have grey background, plus 3-d border - // Inside this, left and top sides (dark grey). Bottom and right (white).
// One black rectangle.
// Inside this, left and top sides - dark grey. Bottom and right -
// white.
// Reverse it for wxSB_RAISED // Reverse it for wxSB_RAISED
dc.SetPen((style == wxSB_RAISED) ? m_mediumShadowPen : m_hilightPen); dc.SetPen((style == wxSB_RAISED) ? m_mediumShadowPen : m_hilightPen);
@ -271,7 +309,6 @@ void wxStatusBarGeneric::DrawField(wxDC& dc, int i, int textHeight)
DrawFieldText(dc, rect, i, textHeight); DrawFieldText(dc, rect, i, textHeight);
} }
// Get the position and size of the field's internal bounding rectangle
bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const
{ {
wxCHECK_MSG( (n >= 0) && ((size_t)n < m_panes.GetCount()), false, wxCHECK_MSG( (n >= 0) && ((size_t)n < m_panes.GetCount()), false,
@ -292,7 +329,29 @@ bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const
return true; return true;
} }
// Initialize colours int wxStatusBarGeneric::GetFieldFromPoint(const wxPoint& pt) const
{
if (m_widthsAbs.IsEmpty())
return wxNOT_FOUND;
// NOTE: we explicitely don't take in count the borders since they are only
// useful when rendering the status text, not for hit-test computations
if (pt.y <= 0 || pt.y >= m_lastClientHeight)
return wxNOT_FOUND;
int x = 0;
for ( size_t i = 0; i < m_panes.GetCount(); i++ )
{
if (pt.x > x && pt.x < x+m_widthsAbs[i])
return i;
x += m_widthsAbs[i];
}
return wxNOT_FOUND;
}
void wxStatusBarGeneric::InitColours() void wxStatusBarGeneric::InitColours()
{ {
#if defined(__WXPM__) #if defined(__WXPM__)
@ -366,7 +425,6 @@ void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) )
DrawField(dc, i, textHeight); DrawField(dc, i, textHeight);
} }
// Responds to colour changes, and passes event on to children.
void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent& event) void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent& event)
{ {
InitColours(); InitColours();