made radio buttons and the toolbat text work for Win32 toolbar

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14788 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2002-03-26 00:44:57 +00:00
parent 867a54b6da
commit c631abdae9
6 changed files with 125 additions and 13 deletions

View File

@ -111,9 +111,10 @@ Unix (Base/GUI):
All (GUI):
- implemented radio menu items and radio toolbar buttons
- added possibility to show text in the toolbar buttons
- added wxArtProvider class that can be used to customize the look of standard
wxWindows dialogs
- implemented radio menu items
- significantly improved native font support
- wxImage::ComputeHistogram() now uses wxImageHistogram instead of type-unsafe
wxHashTable

View File

@ -42,9 +42,6 @@ ignore the values for explicit placement and use their own layout and the meanin
of a "separator" is a vertical line under Windows95 vs. simple space under GTK etc.
{\bf wxToolBar95:} Note that this toolbar paints tools to reflect user-selected colours.
The toolbar orientation must always be {\bf wxHORIZONTAL}.
{\bf wxToolBarGtk:} The toolbar orientation is ignored and is always {\bf wxHORIZONTAL}.
\wxheading{Window styles}
@ -60,7 +57,9 @@ toolbar).}
\twocolitem{\windowstyle{wxTB\_NOICONS}}{Doesn't show the icons in the toolbar buttons, by default they are shown}
\end{twocollist}
See also \helpref{window styles overview}{windowstyles}.
See also \helpref{window styles overview}{windowstyles}. Note that the Win32
native toolbar ignores {\tt wxTB\_NOICONS} style. Also, toggling the
{\tt wxTB\_TEXT} works only if the style was initially on.
\wxheading{Event handling}

View File

@ -60,6 +60,8 @@ public:
// implementation only from now on
// -------------------------------
virtual void SetWindowStyleFlag(long style);
virtual bool MSWCommand(WXUINT param, WXWORD id);
virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);

View File

@ -178,7 +178,7 @@ public:
void SetNormalBitmap(const wxBitmap& bmp) { m_bmpNormal = bmp; }
void SetDisabledBitmap(const wxBitmap& bmp) { m_bmpDisabled = bmp; }
void SetLabel(const wxString& label) { m_label = label; }
virtual void SetLabel(const wxString& label) { m_label = label; }
void SetClientData(wxObject *clientData)
{

View File

@ -152,7 +152,7 @@ private:
const int ID_TOOLBAR = 500;
static const long TOOLBAR_STYLE = wxNO_BORDER | wxTB_FLAT | wxTB_DOCKABLE;
static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE | wxTB_TEXT;
enum
{
@ -227,7 +227,7 @@ bool MyApp::OnInit()
// Create the main frame window
MyFrame* frame = new MyFrame((wxFrame *) NULL, -1,
"wxToolBar Sample",
wxPoint(100, 100), wxSize(450, 300));
wxPoint(100, 100), wxSize(550, 300));
frame->Show(TRUE);
@ -397,6 +397,8 @@ MyFrame::MyFrame(wxFrame* parent,
// Associate the menu bar with the frame
SetMenuBar(menuBar);
menuBar->Check(IDM_TOOLBAR_SHOW_BOTH, TRUE);
// Create the toolbar
RecreateToolbar();
}
@ -464,8 +466,8 @@ void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event))
style);
m_tbar->AddRadioTool(wxID_NEW, _T("First"), wxBITMAP(new));
m_tbar->AddRadioTool(wxID_NEW, _T("Second"), wxBITMAP(new));
m_tbar->AddRadioTool(wxID_NEW, _T("Third"), wxBITMAP(new));
m_tbar->AddRadioTool(wxID_OPEN, _T("Second"), wxBITMAP(open));
m_tbar->AddRadioTool(wxID_SAVE, _T("Third"), wxBITMAP(save));
m_tbar->AddSeparator();
m_tbar->AddTool(wxID_HELP, _T("Help"), wxBITMAP(help));

View File

@ -161,6 +161,19 @@ public:
m_nSepCount = 1;
}
virtual void SetLabel(const wxString& label)
{
if ( label == m_label )
return;
wxToolBarToolBase::SetLabel(label);
// we need to update the label shown in the toolbar because it has a
// pointer to the internal buffer of the old label
//
// TODO: use TB_SETBUTTONINFO
}
// set/get the number of separators which we use to cover the space used by
// a control in the toolbar
void SetSeparatorsCount(size_t count) { m_nSepCount = count; }
@ -543,7 +556,6 @@ bool wxToolBar::Realize()
wxLogDebug(wxT("TB_DELETEBUTTON failed"));
}
}
}
if ( addBitmap ) // no old bitmap or we can't replace it
@ -566,6 +578,7 @@ bool wxToolBar::Realize()
// this array will hold the indices of all controls in the toolbar
wxArrayInt controlIds;
bool lastWasRadio = FALSE;
int i = 0;
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
{
@ -579,6 +592,7 @@ bool wxToolBar::Realize()
wxZeroMemory(button);
bool isRadio = FALSE;
switch ( tool->GetStyle() )
{
case wxTOOL_STYLE_CONTROL:
@ -592,6 +606,12 @@ bool wxToolBar::Realize()
case wxTOOL_STYLE_BUTTON:
button.iBitmap = bitmapId;
if ( HasFlag(wxTB_TEXT) && !tool->GetLabel().empty() )
{
button.iString = (int)tool->GetLabel().c_str();
}
button.idCommand = tool->GetId();
if ( tool->IsEnabled() )
@ -599,13 +619,40 @@ bool wxToolBar::Realize()
if ( tool->IsToggled() )
button.fsState |= TBSTATE_CHECKED;
button.fsStyle = tool->CanBeToggled() ? TBSTYLE_CHECK
: TBSTYLE_BUTTON;
switch ( tool->GetKind() )
{
case wxITEM_RADIO:
button.fsStyle = TBSTYLE_CHECKGROUP;
if ( !lastWasRadio )
{
// the first item in the radio group is checked by
// default to be consistent with wxGTK and the menu
// radio items
button.fsState |= TBSTATE_CHECKED;
}
isRadio = TRUE;
break;
case wxITEM_CHECK:
button.fsStyle = TBSTYLE_CHECK;
break;
default:
wxFAIL_MSG( _T("unexpected toolbar button kind") );
// fall through
case wxITEM_NORMAL:
button.fsStyle = TBSTYLE_BUTTON;
}
bitmapId++;
break;
}
lastWasRadio = isRadio;
i++;
}
@ -981,6 +1028,67 @@ void wxToolBar::UpdateSize()
}
}
// ----------------------------------------------------------------------------
// toolbar styles
// ---------------------------------------------------------------------------
void wxToolBar::SetWindowStyleFlag(long style)
{
// there doesn't seem to be any reasonably simple way to prevent the
// toolbar from showing the icons so for now we don't honour wxTB_NOICONS
if ( (style & wxTB_TEXT) != (GetWindowStyle() & wxTB_TEXT) )
{
// update the strings of all toolbar buttons
//
// NB: we can only do it using TB_SETBUTTONINFO which is available
// in comctl32.dll >= 4.71 only
#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
if ( wxTheApp->GetComCtl32Version() >= 471 )
{
// set the (underlying) separators width to be that of the
// control
TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_TEXT;
if ( !(style & wxTB_TEXT) )
{
// don't show the text - remove the labels
tbbi.pszText = NULL;
}
for ( wxToolBarToolsList::Node *node = m_tools.GetFirst();
node;
node = node->GetNext() )
{
wxToolBarToolBase *tool = node->GetData();
if ( !tool->IsButton() )
{
continue;
}
if ( style & wxTB_TEXT )
{
// cast is harmless
tbbi.pszText = (wxChar *)tool->GetLabel().c_str();
}
if ( !SendMessage(GetHwnd(), TB_SETBUTTONINFO,
tool->GetId(), (LPARAM)&tbbi) )
{
// the id is probably invalid?
wxLogLastError(wxT("TB_SETBUTTONINFO"));
}
}
UpdateSize();
Refresh();
}
#endif // comctl32.dll 4.71
}
wxToolBarBase::SetWindowStyleFlag(style);
}
// ----------------------------------------------------------------------------
// tool state
// ----------------------------------------------------------------------------