//---------------------------------------------------------------- bool ToolBar::Update() /** * \brief Updates the toolbar and all its item. In some cases it is * necessary to update the wxAuiManager after calling this method. * \return True on success; false otherwise. **/ { Environment* env = Environment::Get(); if (unlikely(m_toolbar == NULL)) { wxToolBar* m_toolbar = new wxToolBar(env->GetFrame(), wxID_ANY, wxDefaultPosition, wxDefaultSize, penvCOMMON_TOOLBARSTYLE); m_toolbar->SetToolBitmapSize(penvCOMMON_TOOLBARICONSIZE); } else { // Because ClearTools does not remove events // from event handler, remove them manually ClearToolEvents(); // Clear all tool items m_toolbar->ClearTools(); } if (m_toolbarids != NULL) delete [] m_toolbarids; m_toolbarids = new int[m_array->Count()]; m_counttoolbarids = m_array->Count(); for (size_t i=0; i<m_array->Count(); ++i) { ToolBarItem* item = m_array->ItemPtr(i); // Überprüfen ob ID schon aufgelöst wurde if (item->GetCommand() == NULL && !item->GetId().IsEmpty()) { item->SetCommand(env->GetCommandList()->GetCommand(item->GetId())); if (item->GetCommand() == NULL) { wxLogWarning(_T("[penv::ToolBar::Update] Could not resolve command id '%s' for item. Removing item!"), item->GetId().c_str()); m_array->Del(i, true); continue; } } if (item->GetCommand() != NULL) { if (item->GetCommand()->IsEvent()) { wxLogWarning(_T("[penv::ToolBar::Update] Could not add command id '%s' to toolbar, because this command is a event. Removing item!"), item->GetId().c_str()); m_array->Del(i, true); continue; } if (!item->GetIcon().IsOk()) { wxLogWarning(_T("[penv::ToolBar::Update] Could not add command id '%s' to toolbar, because this command does not have a bitmap."), item->GetId().c_str()); continue; } } wxToolBarToolBase* tool = NULL; if (unlikely(item->IsSeparator())) { tool = m_toolbar->AddSeparator(); item->SetTool(tool); } else { tool = m_toolbar->AddTool(wxNewId(), item->GetCommand()->GetName(), item->GetCommand()->GetIcon(), wxNullBitmap, wxITEM_NORMAL, item->GetCommand()->GetName(), item->GetCommand()->GetHelp()); item->SetTool(tool); tool->Enable(item->GetCommand()->IsEnabled()); if (unlikely(!item->TryConnect())) { wxLogWarning(_T("[penv::ToolBar::Update] Could not connect tool item, with wxWidgets Event.")); m_toolbarids[i] = -1; } else { m_toolbarids[i] = tool->GetId(); } } } for (int i=m_array->Count()-1; i>=0; --i) { if (m_array->ItemPtr(i) == NULL) m_array->Remove((size_t)i, false); } m_toolbar->Realize(); // Toolbar always set caption new m_paneinfo.Caption(m_name).Name(m_id).ToolbarPane(); // Toolbar is always on top! if (m_paneinfo.dock_direction != wxAUI_DOCK_TOP) { wxLogWarning(_T("[penv::ToolBar::Update] Toolbar '%s' is not on top of the frame, changing it to display toolbar on top."), m_name.c_str()); m_paneinfo.Top(); } // Always set the correct size m_paneinfo.BestSize(m_toolbar->GetBestSize()); m_paneinfo.MinSize(-1,-1).MaxSize(-1,-1).FloatingSize(-1,-1); // Add toolbar to aui manager, if toolbar visible and there are min. 1 item if (m_visible && m_array->Count() > 0) { wxAuiManager* manager = Environment::Get()->GetFrame()->GetManager(); if (unlikely(!manager->AddPane(m_toolbar, m_paneinfo))) { wxLogError(_T("[penv::ToolBar::Update] Cannot add toolbar '%s' to aui manager."), m_name.c_str()); return (false); } m_toolbar->Show(); } else { m_toolbar->Hide(); } return (true); }