added wxTB_NO_TOOLTIPS (heavily modified patch 1458009)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39379 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2006-05-28 17:17:02 +00:00
parent 0bb4ad85f3
commit 6a1b3ead3f
7 changed files with 66 additions and 30 deletions

View File

@ -140,6 +140,7 @@ All (GUI):
- wxString <-> wxColour conversions in wxColour class (Francesco Montorsi).
- Fixed bug with ignoring blank lines in multiline wxGrid cell labels
- Added wxTextAttr::Merge() (Marcin Simonides)
- Added wxTB_NO_TOOLTIPS style (Igor Korot)
wxMSW:

View File

@ -71,6 +71,7 @@ use this option under Windows XP with true colour:
\twocolitem{\windowstyle{wxTB\_HORZ\_LAYOUT}}{Shows the text and the icons alongside, not vertically stacked (Windows and GTK
2 only). This style must be used with wxTB\_TEXT.}
\twocolitem{\windowstyle{wxTB\_HORZ\_TEXT}}{Combination of wxTB\_HORZ\_LAYOUT and wxTB\_TEXT.}
\twocolitem{\windowstyle{wxTB\_NO\_TOOLTIPS}{Don't show the short help tooltips for the tools when the mouse hovers over them.}
\end{twocollist}
See also \helpref{window styles overview}{windowstyles}. Note that the Win32

View File

@ -25,7 +25,7 @@ public:
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
long style = wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr )
{
Init();

View File

@ -49,7 +49,10 @@ enum
// show the text and the icons alongside, not vertically stacked (Win32/GTK)
wxTB_HORZ_LAYOUT = 0x0800,
wxTB_HORZ_TEXT = wxTB_HORZ_LAYOUT | wxTB_TEXT
wxTB_HORZ_TEXT = wxTB_HORZ_LAYOUT | wxTB_TEXT,
// don't show the toolbar short help tooltips
wxTB_NO_TOOLTIPS = 0x1000
};
#if wxUSE_TOOLBAR

View File

@ -111,6 +111,7 @@ public:
void OnToggleToolbarSize(wxCommandEvent& event);
void OnToggleToolbarOrient(wxCommandEvent& event);
void OnToggleToolbarRows(wxCommandEvent& event);
void OnToggleTooltips(wxCommandEvent& event);
void OnToggleCustomDisabled(wxCommandEvent& event);
void OnEnablePrint(wxCommandEvent& WXUNUSED(event)) { DoEnablePrint(); }
@ -149,7 +150,8 @@ private:
bool m_smallToolbar,
m_horzToolbar,
m_horzText,
m_useCustomDisabled;
m_useCustomDisabled,
m_showTooltips;
size_t m_rows; // 1 or 2 only
// the number of print buttons we have (they're added/removed dynamically)
@ -175,6 +177,7 @@ enum
IDM_TOOLBAR_TOGGLETOOLBARSIZE = 200,
IDM_TOOLBAR_TOGGLETOOLBARORIENT,
IDM_TOOLBAR_TOGGLETOOLBARROWS,
IDM_TOOLBAR_TOGGLETOOLTIPS,
IDM_TOOLBAR_TOGGLECUSTOMDISABLED,
IDM_TOOLBAR_ENABLEPRINT,
IDM_TOOLBAR_DELETEPRINT,
@ -218,6 +221,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE, MyFrame::OnToggleToolbarSize)
EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT, MyFrame::OnToggleToolbarOrient)
EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS, MyFrame::OnToggleToolbarRows)
EVT_MENU(IDM_TOOLBAR_TOGGLETOOLTIPS, MyFrame::OnToggleTooltips)
EVT_MENU(IDM_TOOLBAR_TOGGLECUSTOMDISABLED, MyFrame::OnToggleCustomDisabled)
EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint)
@ -302,6 +306,11 @@ void MyFrame::RecreateToolbar()
style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL | wxTB_HORZ_LAYOUT);
style |= m_horzToolbar ? wxTB_HORIZONTAL : wxTB_VERTICAL;
if ( m_showTooltips )
style &= ~wxTB_NO_TOOLTIPS;
else
style |= wxTB_NO_TOOLTIPS;
if ( style & wxTB_TEXT && !(style & wxTB_NOICONS) && m_horzText )
style |= wxTB_HORZ_LAYOUT;
@ -354,10 +363,10 @@ void MyFrame::RecreateToolbar()
toolBarBitmaps[n] =
wxBitmap(toolBarBitmaps[n].ConvertToImage().Scale(w, h));
}
toolBar->SetToolBitmapSize(wxSize(w, h));
}
toolBar->SetToolBitmapSize(wxSize(w, h));
toolBar->AddTool(wxID_NEW, _T("New"), toolBarBitmaps[Tool_new], _T("New file"));
toolBar->AddTool(wxID_OPEN, _T("Open"), toolBarBitmaps[Tool_open], _T("Open file"));
@ -432,6 +441,8 @@ MyFrame::MyFrame(wxFrame* parent,
m_horzToolbar = true;
m_horzText = false;
m_useCustomDisabled = false;
m_showTooltips = true;
m_rows = 1;
m_nPrint = 1;
@ -469,6 +480,10 @@ MyFrame::MyFrame(wxFrame* parent,
_T("Toggle number of &rows\tCtrl-R"),
_T("Toggle number of toolbar rows between 1 and 2"));
tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLETOOLTIPS,
_T("Show &tooltips\tCtrl-L"),
_T("Show tooltips for the toolbar tools"));
tbarMenu->AppendCheckItem(IDM_TOOLBAR_TOGGLECUSTOMDISABLED,
_T("Use c&ustom disabled images\tCtrl-U"),
_T("Switch between using system-generated and custom disabled images"));
@ -507,6 +522,7 @@ MyFrame::MyFrame(wxFrame* parent,
SetMenuBar(menuBar);
menuBar->Check(IDM_TOOLBAR_SHOW_BOTH, true);
menuBar->Check(IDM_TOOLBAR_TOGGLETOOLTIPS, true);
// Create the toolbar
RecreateToolbar();
@ -630,6 +646,13 @@ void MyFrame::OnToggleToolbarRows(wxCommandEvent& WXUNUSED(event))
//RecreateToolbar(); -- this is unneeded
}
void MyFrame::OnToggleTooltips(wxCommandEvent& WXUNUSED(event))
{
m_showTooltips = !m_showTooltips;
RecreateToolbar();
}
void MyFrame::OnToggleCustomDisabled(wxCommandEvent& WXUNUSED(event))
{
m_useCustomDisabled = !m_useCustomDisabled;

View File

@ -317,8 +317,7 @@ bool wxToolBar::Create( wxWindow *parent,
ConnectWidget( m_widget );
gtk_widget_show(GTK_WIDGET(m_toolbar));
}
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), !(style & wxTB_NO_TOOLTIPS) );
// FIXME: there is no such function for toolbars in 2.0
#if 0
@ -346,7 +345,16 @@ void wxToolBar::GtkSetStyle()
void wxToolBar::SetWindowStyleFlag( long style )
{
wxToolBarBase::SetWindowStyleFlag(style);
if( style & wxTB_TOOLTIPS )
{
if( m_toolbar )
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
}
else
{
if( m_toolbar )
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), FALSE );
}
if ( m_toolbar )
GtkSetStyle();
}

View File

@ -376,9 +376,8 @@ WXDWORD wxToolBar::MSWGetStyle(long style, WXDWORD *exstyle) const
(style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
);
// always include this one, it never hurts and setting it later
// only if we do have tooltips wouldn't work
msStyle |= TBSTYLE_TOOLTIPS;
if ( !(style & wxTB_NO_TOOLTIPS) )
msStyle |= TBSTYLE_TOOLTIPS;
if ( style & (wxTB_FLAT | wxTB_HORZ_LAYOUT) )
{
@ -1118,33 +1117,34 @@ bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl),
WXLPARAM lParam,
WXLPARAM *WXUNUSED(result))
{
if( !HasFlag(wxTB_NO_TOOLTIPS) )
{
#if wxUSE_TOOLTIPS
// First check if this applies to us
NMHDR *hdr = (NMHDR *)lParam;
// First check if this applies to us
NMHDR *hdr = (NMHDR *)lParam;
// the tooltips control created by the toolbar is sometimes Unicode, even
// in an ANSI application - this seems to be a bug in comctl32.dll v5
UINT code = hdr->code;
if ( (code != (UINT) TTN_NEEDTEXTA) && (code != (UINT) TTN_NEEDTEXTW) )
return false;
// the tooltips control created by the toolbar is sometimes Unicode, even
// in an ANSI application - this seems to be a bug in comctl32.dll v5
UINT code = hdr->code;
if ( (code != (UINT) TTN_NEEDTEXTA) && (code != (UINT) TTN_NEEDTEXTW) )
return false;
HWND toolTipWnd = (HWND)::SendMessage((HWND)GetHWND(), TB_GETTOOLTIPS, 0, 0);
if ( toolTipWnd != hdr->hwndFrom )
return false;
HWND toolTipWnd = (HWND)::SendMessage(GetHwnd(), TB_GETTOOLTIPS, 0, 0);
if ( toolTipWnd != hdr->hwndFrom )
return false;
LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
int id = (int)ttText->hdr.idFrom;
LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
int id = (int)ttText->hdr.idFrom;
wxToolBarToolBase *tool = FindById(id);
if ( !tool )
return false;
return HandleTooltipNotify(code, lParam, tool->GetShortHelp());
wxToolBarToolBase *tool = FindById(id);
if ( tool )
return HandleTooltipNotify(code, lParam, tool->GetShortHelp());
#else
wxUnusedVar(lParam);
wxUnusedVar(lParam);
#endif
}
return false;
#endif
}
// ----------------------------------------------------------------------------