Fix handling of controls in vertical toolbars in wxMSW.

Not adding the controls to vertical toolbar is not enough, we also need to
hide them to prevent them from being shown as independent floating windows.
And we also need to add separators instead of the controls themselves to keep
the indices the same as in the horizontal case.

Closes #11821.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@76098 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-03-08 14:33:29 +00:00
parent 4bddf85f6c
commit f4bdf2b324
2 changed files with 45 additions and 12 deletions

View File

@@ -638,6 +638,7 @@ wxMSW:
- Fix crash when adding/removing the same path to/from wxFileSystemWatcher. - Fix crash when adding/removing the same path to/from wxFileSystemWatcher.
- Draw "classic" disabled owner drawn buttons better (Artur Wieczorek). - Draw "classic" disabled owner drawn buttons better (Artur Wieczorek).
- Fix width of the vertical toolbars (Artur Wieczorek). - Fix width of the vertical toolbars (Artur Wieczorek).
- Fix handling of controls in the vertical toolbars (Artur Wieczorek).
- Fix loading of top to bottom BMP files in wxBitmap (Artur Wieczorek). - Fix loading of top to bottom BMP files in wxBitmap (Artur Wieczorek).
wxOSX: wxOSX:

View File

@@ -244,11 +244,12 @@ private:
// helper functions // helper functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// return the rectangle of the item at the given index // Return the rectangle of the item at the given index and, if specified, with
// the given id.
// //
// returns an empty (0, 0, 0, 0) rectangle if fails so the caller may compare // Returns an empty (0, 0, 0, 0) rectangle if fails so the caller may compare
// r.right or r.bottom with 0 to check for this // r.right or r.bottom with 0 to check for this.
static RECT wxGetTBItemRect(HWND hwnd, int index) static RECT wxGetTBItemRect(HWND hwnd, int index, int id = wxID_NONE)
{ {
RECT r; RECT r;
@@ -256,12 +257,34 @@ static RECT wxGetTBItemRect(HWND hwnd, int index)
// only appeared in v4.70 of comctl32.dll // only appeared in v4.70 of comctl32.dll
if ( !::SendMessage(hwnd, TB_GETITEMRECT, index, (LPARAM)&r) ) if ( !::SendMessage(hwnd, TB_GETITEMRECT, index, (LPARAM)&r) )
{ {
wxLogLastError(wxT("TB_GETITEMRECT")); // This call can return false status even when there is no real error,
// e.g. for a hidden button, so check for this to avoid spurious logs.
const DWORD err = ::GetLastError();
if ( err != ERROR_SUCCESS )
{
bool reportError = true;
r.top = if ( id != wxID_NONE )
r.left = {
r.right = const LRESULT state = ::SendMessage(hwnd, TB_GETSTATE, id, 0);
r.bottom = 0; if ( state != -1 && (state & TBSTATE_HIDDEN) )
{
// There is no real error to report after all.
reportError = false;
}
else // It is not hidden.
{
// So it must have been a real error, report it with the
// original error code and not the one from TB_GETSTATE.
::SetLastError(err);
}
}
if ( reportError )
wxLogLastError(wxT("TB_GETITEMRECT"));
}
::SetRectEmpty(&r);
} }
return r; return r;
@@ -988,7 +1011,14 @@ bool wxToolBar::Realize()
} }
button.idCommand = tool->GetId(); button.idCommand = tool->GetId();
button.fsState = TBSTATE_ENABLED;
// We don't embed controls in the vertical toolbar but for
// every control there must exist a corresponding button to
// keep indexes the same as in the horizontal case.
if ( IsVertical() && tool->IsControl() )
button.fsState = TBSTATE_HIDDEN;
else
button.fsState = TBSTATE_ENABLED;
button.fsStyle = TBSTYLE_SEP; button.fsStyle = TBSTYLE_SEP;
break; break;
@@ -1102,7 +1132,7 @@ bool wxToolBar::Realize()
{ {
wxToolBarTool * const tool = (wxToolBarTool*)node->GetData(); wxToolBarTool * const tool = (wxToolBarTool*)node->GetData();
const RECT r = wxGetTBItemRect(GetHwnd(), toolIndex); const RECT r = wxGetTBItemRect(GetHwnd(), toolIndex, tool->GetId());
if ( !tool->IsControl() ) if ( !tool->IsControl() )
{ {
@@ -1114,15 +1144,17 @@ bool wxToolBar::Realize()
continue; continue;
} }
wxControl * const control = tool->GetControl();
if ( IsVertical() ) if ( IsVertical() )
{ {
// don't embed controls in the vertical toolbar, this doesn't look // don't embed controls in the vertical toolbar, this doesn't look
// good and wxGTK doesn't do it neither (and the code below can't // good and wxGTK doesn't do it neither (and the code below can't
// deal with this case) // deal with this case)
control->Hide();
continue; continue;
} }
wxControl * const control = tool->GetControl(); control->Show();
wxStaticText * const staticText = tool->GetStaticText(); wxStaticText * const staticText = tool->GetStaticText();
wxSize size = control->GetSize(); wxSize size = control->GetSize();