//---------------------------------------------------------------- bool ToolBar::ReadNode(wxXmlNode* node) /** * \brief Read out a 'toolbar' xml element node. * See class description for structure of such an xml node. * \param node The 'toolbar' xml element node. * \return True on success; false otherwise. **/ { // Fehler überprüfen if (unlikely(node == NULL)) { wxLogError(_T("[penv::ToolBar::ReadNode] Cannot load xml node, because parameter argument is NULL.")); return (false); } if (unlikely(node->GetType() != wxXML_ELEMENT_NODE)) { wxLogError(_T("[penv::ToolBar::ReadNode] Cannot load, xml node must be an element node.")); return (false); } if (unlikely(node->GetName() != _T("toolbar"))) { wxLogError(_T("[penv::ToolBar::ReadNode] Cannot load, xml element node must have the name \"toolbar\". This element node has the name \"%s\"."), node->GetName().c_str()); return (false); } // Einlesen der Attribute der Toolbar if (unlikely(!node->HasProp(_T("id")))) { wxLogError(_T("[penv::ToolBar::ReadNode] Cannot load, xml element node must have the attribute \"id\". This element node has the name \"%s\"."), node->GetName().c_str()); return (false); } m_id = node->GetPropVal(_T("id"), wxEmptyString); CorrectToolbarId(); m_name = node->GetPropVal(_T("name"), wxEmptyString); m_visible = PenvHelper::ParseBoolean(node->GetPropVal(_T("visible"), _T("true"))); // Einlesen der Position und der ToolBar Items Environment* env = Environment::Get(); wxXmlNode* child = node->GetChildren(); while (child != NULL) { // Nicht Elemente überspringen if (unlikely(child->GetType() != wxXML_ELEMENT_NODE)) { child = child->GetNext(); continue; } if (child->GetName() == _T("position")) { wxString strg = child->GetNodeContent(); env->GetFrame()->GetManager()->LoadPaneInfo(strg, m_paneinfo); } if (child->GetName() == _T("toolitem")) { ToolBarItem* item = new ToolBarItem(); if (!item->ReadNode(child)) { wxLogWarning(_T("[penv::ToolBar::ReadNode] Toolbar item in toolbar \"%s\" could not be readed. Skipping..."), m_name.c_str()); delete item; } else { Add(item); } } child = child->GetNext(); } return (true); }
//---------------------------------------------------------------- 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); }