Ticket #11821: toolbar-vert-control-vz.patch

File toolbar-vert-control-vz.patch, 3.8 KB (added by vadz, 4 years ago)

VZ version of the patch reducing code duplication

  • src/msw/toolbar.cpp

    diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp
    index 9596725..b99b7d8 100644
    a b class wxToolBarTool : public wxToolBarToolBase 
    244244// helper functions
    245245// ----------------------------------------------------------------------------
    246246
    247 // return the rectangle of the item at the given index
     247// Return the rectangle of the item at the given index and, if specified, with
     248// the given id.
    248249//
    249 // returns an empty (0, 0, 0, 0) rectangle if fails so the caller may compare
    250 // r.right or r.bottom with 0 to check for this
    251 static RECT wxGetTBItemRect(HWND hwnd, int index)
     250// Returns an empty (0, 0, 0, 0) rectangle if fails so the caller may compare
     251// r.right or r.bottom with 0 to check for this.
     252static RECT wxGetTBItemRect(HWND hwnd, int index, int id = wxID_NONE)
    252253{
    253254    RECT r;
    254255
    static RECT wxGetTBItemRect(HWND hwnd, int index) 
    256257    // only appeared in v4.70 of comctl32.dll
    257258    if ( !::SendMessage(hwnd, TB_GETITEMRECT, index, (LPARAM)&r) )
    258259    {
    259         wxLogLastError(wxT("TB_GETITEMRECT"));
     260        // This call can return false status even when there is no real error,
     261        // e.g. for a hidden button, so check for this to avoid spurious logs.
     262        const DWORD err = ::GetLastError();
     263        if ( err != ERROR_SUCCESS )
     264        {
     265            bool reportError = true;
     266
     267            if ( id != wxID_NONE )
     268            {
     269                const LRESULT state = ::SendMessage(hwnd, TB_GETSTATE, id, 0);
     270                if ( state != -1 && (state & TBSTATE_HIDDEN) )
     271                {
     272                    // There is no real error to report after all.
     273                    reportError = false;
     274                }
     275                else // It is not hidden.
     276                {
     277                    // So it must have been a real error, report it with the
     278                    // original error code and not the one from TB_GETSTATE.
     279                    ::SetLastError(err);
     280                }
     281            }
     282
     283            if ( reportError )
     284                wxLogLastError(wxT("TB_GETITEMRECT"));
     285        }
    260286
    261         r.top =
    262         r.left =
    263         r.right =
    264         r.bottom = 0;
     287        ::SetRectEmpty(&r);
    265288    }
    266289
    267290    return r;
    bool wxToolBar::Realize() 
    9981021                }
    9991022
    10001023                button.idCommand = tool->GetId();
    1001                 button.fsState = TBSTATE_ENABLED;
     1024
     1025                // We don't embed controls in the vertical toolbar but for
     1026                // every control there must exist a corresponding button to
     1027                // keep indexes the same as in the horizontal case.
     1028                if ( IsVertical() && tool->IsControl() )
     1029                    button.fsState = TBSTATE_HIDDEN;
     1030                else
     1031                    button.fsState = TBSTATE_ENABLED;
    10021032                button.fsStyle = TBSTYLE_SEP;
    10031033                break;
    10041034
    bool wxToolBar::Realize() 
    11121142    {
    11131143        wxToolBarTool * const tool = (wxToolBarTool*)node->GetData();
    11141144
    1115         const RECT r = wxGetTBItemRect(GetHwnd(), toolIndex);
     1145        const RECT r = wxGetTBItemRect(GetHwnd(), toolIndex, tool->GetId());
    11161146
    11171147        if ( !tool->IsControl() )
    11181148        {
    bool wxToolBar::Realize() 
    11241154            continue;
    11251155        }
    11261156
     1157        wxControl * const control = tool->GetControl();
    11271158        if ( IsVertical() )
    11281159        {
    11291160            // don't embed controls in the vertical toolbar, this doesn't look
    11301161            // good and wxGTK doesn't do it neither (and the code below can't
    11311162            // deal with this case)
     1163            control->Hide();
    11321164            continue;
    11331165        }
    11341166
    1135         wxControl * const control = tool->GetControl();
     1167        control->Show();
    11361168        wxStaticText * const staticText = tool->GetStaticText();
    11371169
    11381170        wxSize size = control->GetSize();