- wxControl *control = tool->GetControl();
-
- wxSize size = control->GetSize();
-
- // the position of the leftmost controls corner
- int left = -1;
-
- // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
-#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
- // available in headers, now check whether it is available now
- // (during run-time)
- if ( wxTheApp->GetComCtl32Version() >= 471 )
- {
- // set the (underlying) separators width to be that of the
- // control
- TBBUTTONINFO tbbi;
- tbbi.cbSize = sizeof(tbbi);
- tbbi.dwMask = TBIF_SIZE;
- tbbi.cx = size.x;
- if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO,
- tool->GetId(), (LPARAM)&tbbi) )
- {
- // the id is probably invalid?
- wxLogLastError(wxT("TB_SETBUTTONINFO"));
- }
- }
- else
-#endif // comctl32.dll 4.71
- // TB_SETBUTTONINFO unavailable
- {
- // try adding several separators to fit the controls width
- int widthSep = r.right - r.left;
- left = r.left;
-
- TBBUTTON tbb;
- wxZeroMemory(tbb);
- tbb.idCommand = 0;
- tbb.fsState = TBSTATE_ENABLED;
- tbb.fsStyle = TBSTYLE_SEP;
-
- size_t nSeparators = size.x / widthSep;
- for ( size_t nSep = 0; nSep < nSeparators; nSep++ )
- {
- if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON,
- index, (LPARAM)&tbb) )
- {
- wxLogLastError(wxT("TB_INSERTBUTTON"));
- }
-
- index++;
- }
-
- // remember the number of separators we used - we'd have to
- // delete all of them later
- ((wxToolBarTool *)tool)->SetSeparatorsCount(nSeparators);
-
- // adjust the controls width to exactly cover the separators
- control->SetSize((nSeparators + 1)*widthSep, wxDefaultCoord);
- }
-
- // position the control itself correctly vertically
- int height = r.bottom - r.top;
- int diff = height - size.y;
- if ( diff < 0 )
- {
- // the control is too high, resize to fit
- control->SetSize(wxDefaultCoord, height - 2);
-
- diff = 2;
- }
-
- int top;
- if ( isVertical )
- {
- left = 0;
- top = y;
-
- y += height + 2*GetMargins().y;
- }
- else // horizontal toolbar
- {
- if ( left == -1 )
- left = r.left;
-
- top = r.top;
- }
-
- control->Move(left, top + (diff + 1) / 2);
- }
-
- // the max index is the "real" number of buttons - i.e. counting even the
- // separators which we added just for aligning the controls
- m_nButtons = index;
-
- if ( !isVertical )
- {
- if ( m_maxRows == 0 )
- {
- // if not set yet, only one row
- SetRows(1);
- }
- }
- else if ( m_nButtons > 0 ) // vertical non empty toolbar
- {
- if ( m_maxRows == 0 )
- {
- // if not set yet, have one column
- SetRows(m_nButtons);
- }