+ i++;
+ node = node->Next();
+ }
+
+ if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS,
+ (WPARAM)i, (LPARAM)buttons) )
+ {
+ wxLogLastError("TB_ADDBUTTONS");
+ }
+
+ delete [] buttons;
+
+ // adjust the controls size to fit nicely in the toolbar
+ size_t nControls = controlIds.GetCount();
+ for ( size_t nCtrl = 0; nCtrl < nControls; nCtrl++ )
+ {
+ wxToolBarTool *tool = (wxToolBarTool *)
+ m_tools.Nth(controlIds[nCtrl])->Data();
+ 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->m_index, (LPARAM)&tbbi) )
+ {
+ // the index is probably invalid
+ wxLogLastError("TB_SETBUTTONINFO");
+ }
+
+ }
+ else
+ #endif // comctl32.dll 4.71
+ // TB_SETBUTTONINFO unavailable
+ {
+ int index = GetIndexFromId(tool->m_index);
+ wxASSERT_MSG( index != wxNOT_FOUND,
+ _T("control wasn't added to the tbar?") );
+
+ // try adding several separators to fit the controls width
+ RECT r;
+ if ( !SendMessage(GetHwnd(), TB_GETRECT,
+ tool->m_index, (LPARAM)(LPRECT)&r) )
+ {
+ wxLogLastError("TB_GETITEMRECT");
+ }
+
+ 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++ )
+ {
+ m_ids.Insert(0, (size_t)index);
+
+ if ( !SendMessage(GetHwnd(), TB_INSERTBUTTON,
+ index, (LPARAM)&tbb) )
+ {
+ wxLogLastError("TB_INSERTBUTTON");
+ }
+ }
+
+ // adjust the controls width to exactly cover the separators
+ control->SetSize((nSeparators + 1)*widthSep, -1);
+ }
+
+ // and position the control itself correctly vertically
+ RECT r;
+ if ( !SendMessage(GetHwnd(), TB_GETRECT,
+ tool->m_index, (LPARAM)(LPRECT)&r) )
+ {
+ wxLogLastError("TB_GETRECT");
+ }
+
+ int height = r.bottom - r.top;
+ int diff = height - size.y;
+ if ( diff < 0 )
+ {
+ // the control is too high, resize to fit
+ control->SetSize(-1, height - 2);
+
+ diff = 2;
+ }
+
+ control->Move(left == -1 ? r.left : left, r.top + diff / 2);
+ }
+
+ (void)::SendMessage(GetHwnd(), TB_AUTOSIZE, (WPARAM)0, (LPARAM) 0);
+
+ SetRows(m_maxRows);
+
+ return TRUE;