void wxToolBarBase::ClearTools() { while ( GetToolsCount() ) { DeleteToolByPos(0); } }
wxToolBarToolBase * wxToolBarBase::InsertControl(size_t pos, wxControl *control, const wxString& label) { wxCHECK_MSG( control, NULL, _T("toolbar: can't insert NULL control") ); wxCHECK_MSG( control->GetParent() == this, NULL, _T("control must have toolbar as parent") ); wxCHECK_MSG( pos <= GetToolsCount(), NULL, _T("invalid position in wxToolBar::InsertControl()") ); wxToolBarToolBase *tool = CreateTool(control, label); if ( !InsertTool(pos, tool) ) { delete tool; return NULL; } return tool; }
wxToolBarToolBase *wxToolBarBase::InsertTool(size_t pos, int id, const wxString& label, const wxBitmap& bitmap, const wxBitmap& bmpDisabled, wxItemKind kind, const wxString& shortHelp, const wxString& longHelp, wxObject *clientData) { wxCHECK_MSG( pos <= GetToolsCount(), NULL, _T("invalid position in wxToolBar::InsertTool()") ); wxToolBarToolBase *tool = CreateTool(id, label, bitmap, bmpDisabled, kind, clientData, shortHelp, longHelp); if ( !InsertTool(pos, tool) ) { delete tool; return NULL; } return tool; }
void wxToolBar::SetRows( int nRows ) { wxCHECK_RET( nRows != 0, wxT("max number of rows must be > 0") ); m_maxCols = (GetToolsCount() + nRows - 1) / nRows; Refresh(); } // end of wxToolBar::SetRows
void wxToolBar::SetMargins( int x, int y ) { wxCHECK_RET( GetToolsCount() == 0, wxT("wxToolBar::SetMargins must be called before adding tools.") ); if (x > 1) gtk_toolbar_append_space( m_toolbar ); // oh well m_xMargin = x; m_yMargin = y; }
wxToolBarToolBase *wxToolBarBase::DoAddTool(int toolid, const wxString& label, const wxBitmap& bitmap, const wxBitmap& bmpDisabled, wxItemKind kind, const wxString& shortHelp, const wxString& longHelp, wxObject *clientData, wxCoord WXUNUSED(xPos), wxCoord WXUNUSED(yPos)) { InvalidateBestSize(); return InsertTool(GetToolsCount(), toolid, label, bitmap, bmpDisabled, kind, shortHelp, longHelp, clientData); }
wxToolBarToolBase *wxToolBarBase::InsertTool(size_t pos, int toolid, const wxString& label, const wxBitmap& bitmap, const wxBitmap& bmpDisabled, wxItemKind kind, const wxString& shortHelp, const wxString& longHelp, wxObject *clientData) { wxCHECK_MSG( pos <= GetToolsCount(), NULL, wxT("invalid position in wxToolBar::InsertTool()") ); return DoInsertNewTool(pos, CreateTool(toolid, label, bitmap, bmpDisabled, kind, clientData, shortHelp, longHelp)); }
wxToolBarToolBase * wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool) { wxCHECK_MSG( pos <= GetToolsCount(), NULL, wxT("invalid position in wxToolBar::InsertTool()") ); if ( !tool || !DoInsertTool(pos, tool) ) { return NULL; } m_tools.Insert(pos, tool); tool->Attach(this); return tool; }
void wxToolBarBase::ClearTools() { #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ while ( GetToolsCount() ) { DeleteToolByPos(0); } }
bool wxToolBarBase::DeleteToolByPos(size_t pos) { wxCHECK_MSG( pos < GetToolsCount(), false, wxT("invalid position in wxToolBar::DeleteToolByPos()") ); wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos); if ( !DoDeleteTool(pos, node->GetData()) ) { return false; } delete node->GetData(); m_tools.Erase(node); return true; }
void wxMainToolBar::InitToolBar() { // set up the toolbar controls int ipos = 0; if(m_first_dpos == 0) { ipos += InsertObject(ipos); ipos += InsertType(ipos); ipos += InsertBin(ipos); // we need to be able to set binning always m_first_dpos = ipos; } if(m_first_dpos > 0) { int ntools = GetToolsCount(); size_t max_pos = ntools-1; // Delete the camera dependent tools for(size_t ipos=max_pos; ipos>m_first_dpos; ipos--) { DeleteToolByPos(ipos); } // clear references to the deleted tools m_zoomSpin = 0; m_temp_text = 0; } wxCamera* camera = wxF()->cam(); if(camera && camera->IsArtcam()) { ipos = m_first_dpos; ipos += InsertZoom(ipos); ipos += InsertSubframe(ipos); ipos += InsertRestartExposure(ipos); ipos += InsertCooling(ipos); } //20080525:BM try to support more webcam else if(camera && camera->IsWebcam()) { ipos = m_first_dpos; ipos += InsertZoom(ipos); ipos += InsertSubframe(ipos); } Realize(); CamEnable(); }
wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos) { wxCHECK_MSG( pos <= GetToolsCount(), NULL, _T("invalid position in wxToolBar::InsertSeparator()") ); wxToolBarToolBase *tool = CreateTool(wxID_SEPARATOR, wxEmptyString, wxNullBitmap, wxNullBitmap, wxITEM_SEPARATOR, NULL, wxEmptyString, wxEmptyString); if ( !tool || !DoInsertTool(pos, tool) ) { delete tool; return NULL; } m_tools.Insert(pos, tool); return tool; }
void PWSDragBar::RefreshButtons() { const bool newButtons = PWSprefs::GetInstance()->GetPref(PWSprefs::UseNewToolbar); #define BTN newButtons? wxBitmap(DragbarElements[idx].bitmap) : wxBitmap(DragbarElements[idx].classic_bitmap) #define BTN_DISABLED newButtons? wxBitmap(DragbarElements[idx].bitmap_disabled): wxBitmap(DragbarElements[idx].classic_bitmap_disabled) if (GetToolsCount() == 0) { //being created? for (int idx = 0; size_t(idx) < NumberOf(DragbarElements); ++idx) { AddTool(idx + DRAGBAR_TOOLID_BASE, BTN, wxString(_("Drag this image onto another window to paste the '")) << DragbarElements[idx].name << _("' field."), BTN_DISABLED ); } } else { for (int idx = 0; size_t(idx) < NumberOf(DragbarElements); ++idx) { SetToolBitmaps(idx + DRAGBAR_TOOLID_BASE, BTN, BTN_DISABLED); } } #undef BTN #undef BTN_DISABLED }
bool wxToolMenuBar::Realize() { const size_t nTools = GetToolsCount(); if ( nTools == 0 ) { // nothing to do return true; } #if 0 // delete all old buttons, if any for ( size_t pos = 0; pos < m_nButtons; pos++ ) { if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) ) { wxLogDebug(wxT("TB_DELETEBUTTON failed")); } } #endif // 0 bool lastWasRadio = false; wxToolBarToolsList::compatibility_iterator node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolMenuBarTool *tool = (wxToolMenuBarTool*) node->GetData(); TBBUTTON buttons[1] ; TBBUTTON& button = buttons[0]; wxZeroMemory(button); bool isRadio = false; switch ( tool->GetStyle() ) { case wxTOOL_STYLE_CONTROL: button.idCommand = tool->GetId(); // fall through: create just a separator too // TODO: controls are not yet supported on wxToolMenuBar. case wxTOOL_STYLE_SEPARATOR: button.fsState = TBSTATE_ENABLED; button.fsStyle = TBSTYLE_SEP; break; case wxTOOL_STYLE_BUTTON: if ( HasFlag(wxTB_TEXT) ) { const wxString& label = tool->GetLabel(); if ( !label.empty() ) { button.iString = (int) wxMSW_CONV_LPCTSTR(label); } } const wxBitmap& bmp = tool->GetNormalBitmap(); wxBitmap bmpToUse = bmp; if (bmp.GetWidth() < 16 || bmp.GetHeight() < 16 || bmp.GetMask() != NULL) { wxMemoryDC memDC; wxBitmap b(16,16); memDC.SelectObject(b); wxColour col = wxColour(192,192,192); memDC.SetBackground(wxBrush(col)); memDC.Clear(); int x = (16 - bmp.GetWidth())/2; int y = (16 - bmp.GetHeight())/2; memDC.DrawBitmap(bmp, x, y, true); memDC.SelectObject(wxNullBitmap); bmpToUse = b; tool->SetNormalBitmap(b); } int n = 0; if ( bmpToUse.IsOk() ) { n = ::CommandBar_AddBitmap( (HWND) GetHWND(), NULL, (int) (HBITMAP) bmpToUse.GetHBITMAP(), 1, 16, 16 ); } button.idCommand = tool->GetId(); button.iBitmap = n; if ( tool->IsEnabled() ) button.fsState |= TBSTATE_ENABLED; if ( tool->IsToggled() ) button.fsState |= TBSTATE_CHECKED; 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; tool->Toggle(true); } isRadio = true; break; case wxITEM_CHECK: button.fsStyle = TBSTYLE_CHECK; break; default: wxFAIL_MSG( wxT("unexpected toolbar button kind") ); // fall through case wxITEM_NORMAL: button.fsStyle = TBSTYLE_BUTTON; } break; } if ( !::CommandBar_AddButtons( (HWND) GetHWND(), 1, buttons ) ) { wxFAIL_MSG( wxT("Could not add toolbar button.")); } lastWasRadio = isRadio; } return true; }
wxToolBarToolBase *wxToolBarBase::AddStretchableSpace() { return InsertStretchableSpace(GetToolsCount()); }
wxToolBarToolBase *wxToolBarBase::AddSeparator() { return InsertSeparator(GetToolsCount()); }
wxToolBarToolBase * wxToolBarBase::AddControl(wxControl *control, const wxString& label) { return InsertControl(GetToolsCount(), control, label); }
wxToolBarToolBase *wxToolBarBase::AddTool(wxToolBarToolBase *tool) { return InsertTool(GetToolsCount(), tool); }
bool wxToolBar::Realize() { if (m_tools.GetCount() == 0) return FALSE; int x = m_xMargin + kwxMacToolBarLeftMargin ; int y = m_yMargin + kwxMacToolBarTopMargin ; int tw, th; GetSize(& tw, & th); int maxWidth = 0 ; int maxHeight = 0 ; int maxToolWidth = 0; int maxToolHeight = 0; // Find the maximum tool width and height wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); while ( node ) { wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); wxSize sz = tool->GetSize() ; if ( sz.x > maxToolWidth ) maxToolWidth = sz.x ; if (sz.y> maxToolHeight) maxToolHeight = sz.y; node = node->GetNext(); } bool lastWasRadio = FALSE; node = m_tools.GetFirst(); while (node) { wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); wxSize cursize = tool->GetSize() ; bool isRadio = FALSE; if ( tool->IsButton() && tool->GetKind() == wxITEM_RADIO ) { if ( !lastWasRadio ) { if (tool->Toggle(true)) { DoToggleTool(tool, true); } } else if (tool->IsToggled()) { wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious(); while ( nodePrev ) { wxToolBarToolBase *tool = nodePrev->GetData(); if ( !tool->IsButton() || (tool->GetKind() != wxITEM_RADIO) ) break; if ( tool->Toggle(false) ) { DoToggleTool(tool, false); } nodePrev = nodePrev->GetPrevious(); } } isRadio = TRUE; } else { isRadio = FALSE; } lastWasRadio = isRadio; // for the moment we just do a single row/column alignement if ( x + cursize.x > maxWidth ) maxWidth = x + cursize.x ; if ( y + cursize.y > maxHeight ) maxHeight = y + cursize.y ; if ( GetWindowStyleFlag() & wxTB_VERTICAL ) { int x1 = x + (maxToolWidth - cursize.x)/2 ; tool->SetPosition( wxPoint( x1 , y ) ) ; } else { int y1 = y + (maxToolHeight - cursize.y)/2 ; tool->SetPosition( wxPoint( x , y1 ) ) ; } if ( GetWindowStyleFlag() & wxTB_VERTICAL ) { y += cursize.y ; y += kwxMacToolSpacing ; } else { x += cursize.x ; x += kwxMacToolSpacing ; } node = node->GetNext(); } if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) { if ( m_maxRows == 0 ) { // if not set yet, only one row SetRows(1); } m_minWidth = maxWidth; maxWidth = tw ; maxHeight += m_yMargin + kwxMacToolBarTopMargin; m_minHeight = m_maxHeight = maxHeight ; } else { if ( GetToolsCount() > 0 && m_maxRows == 0 ) { // if not set yet, have one column SetRows(GetToolsCount()); } m_minHeight = maxHeight; maxHeight = th ; maxWidth += m_xMargin + kwxMacToolBarLeftMargin; m_minWidth = m_maxWidth = maxWidth ; } SetSize( maxWidth, maxHeight ); InvalidateBestSize(); return TRUE; }
bool CToolBar::Realize() { wxASSERT(HasFlag(wxTB_NOICONS)); bool ret = wxToolBar::Realize(); if (!ret) { return false; } wxSize const size = GetToolBitmapSize(); wxASSERT(size.x > 0 && size.y > 0); auto toolImages = std::make_unique<wxImageList>(size.x, size.y, false, 0); auto disabledToolImages = std::make_unique<wxImageList>(size.x, size.y, false, 0); HWND hwnd = GetHandle(); auto hImgList = reinterpret_cast<HIMAGELIST>(toolImages->GetHIMAGELIST()); auto hDisabledImgList = reinterpret_cast<HIMAGELIST>(disabledToolImages->GetHIMAGELIST()); ::SendMessage(hwnd, TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(hImgList)); ::SendMessage(hwnd, TB_SETDISABLEDIMAGELIST, 0, reinterpret_cast<LPARAM>(hDisabledImgList)); toolImages_ = std::move(toolImages); disabledToolImages_ = std::move(disabledToolImages); for (size_t i = 0; i < GetToolsCount(); ++i) { auto tool = GetToolByPos(static_cast<int>(i)); if (!tool || tool->GetStyle() != wxTOOL_STYLE_BUTTON) { continue; } auto bmp = tool->GetBitmap(); if (!bmp.IsOk()) { continue; } int image = toolImages_->Add(bmp); auto disabled = tool->GetDisabledBitmap(); if (!disabled.IsOk()) { disabled = wxBitmap(bmp.ConvertToImage().ConvertToGreyscale()); } disabledToolImages_->Add(disabled); TBBUTTONINFO btn{}; btn.cbSize = sizeof(TBBUTTONINFO); btn.dwMask = TBIF_BYINDEX; int index = ::SendMessage(hwnd, TB_GETBUTTONINFO, i, reinterpret_cast<LPARAM>(&btn)); if (index != static_cast<int>(i)) { return false; } btn.dwMask = TBIF_BYINDEX | TBIF_IMAGE; btn.iImage = image; if (::SendMessage(hwnd, TB_SETBUTTONINFO, i, reinterpret_cast<LPARAM>(&btn)) == 0) { return false; } } ::SendMessage(hwnd, TB_SETINDENT, ConvertDialogToPixels(wxPoint(1, 0)).x, 0); return true; }