//---------------------------------------------------------------- wxXmlNode* ToolBar::WriteNode() /** * \brief Writes a 'toolbar' xml element node. * See class description for structure of such an xml node. * \return The 'toolbar' xml element node; or NULL on error. **/ { // ToolBar Node erstellen wxXmlNode* node = PenvHelper::CreateXmlNode(_T("toolbar")); node->AddProperty(_T("id"), m_id); node->AddProperty(_T("name"), m_name); node->AddProperty(_T("visible"), PenvHelper::CreateBoolean(m_visible)); // Positions Node erstellen (node ist parent!) wxAuiManager* mgr = Environment::Get()->GetFrame()->GetManager(); wxString posinfo = mgr->SavePaneInfo(m_paneinfo); wxXmlNode* posnode = PenvHelper::CreateXmlNode(_T("position"), posinfo); PenvHelper::AddXmlChildNode(node, posnode); // ToolBar Itemes erstellen und hinzufügen for (size_t i=0; i<m_array->Count(); ++i) { ToolBarItem* item = (*m_array)[i]; wxXmlNode* toolitemnode = item->WriteNode(); PenvHelper::AddXmlChildNode(node, toolitemnode); } return (node); }
ToolBarItem *ToolBar::add_separator_item(const std::string &name) { ToolBarItem *item = mforms::manage(new ToolBarItem(SeparatorItem)); item->set_name(name); add_item(item); return item; }
bool ToolBar::get_item_checked(const std::string &name) { ToolBarItem *item = find_item(name); if (item) return item->get_checked(); return false; }
//---------------------------------------------------------------- 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); }
void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::Reference<ParameterGrp>& hGrp) const { std::vector<Base::Reference<ParameterGrp> > hGrps = hGrp->GetGroups(); CommandManager& rMgr = Application::Instance->commandManager(); std::string separator = "Separator"; for (std::vector<Base::Reference<ParameterGrp> >::iterator it = hGrps.begin(); it != hGrps.end(); ++it) { bool active = (*it)->GetBool("Active", true); if (!active) // ignore this toolbar continue; ToolBarItem* bar = new ToolBarItem(root); bar->setCommand("Custom"); // get the elements of the subgroups std::vector<std::pair<std::string,std::string> > items = hGrp->GetGroup((*it)->GetGroupName())->GetASCIIMap(); for (std::vector<std::pair<std::string,std::string> >::iterator it2 = items.begin(); it2 != items.end(); ++it2) { if (it2->first.substr(0, separator.size()) == separator) { *bar << "Separator"; } else if (it2->first == "Name") { bar->setCommand(it2->second); } else { Command* pCmd = rMgr.getCommandByName(it2->first.c_str()); if (!pCmd) { // unknown command // first try the module name as is std::string pyMod = it2->second; try { Base::Interpreter().loadModule(pyMod.c_str()); // Try again pCmd = rMgr.getCommandByName(it2->first.c_str()); } catch(const Base::Exception&) { } } // still not there? if (!pCmd) { // add the 'Gui' suffix std::string pyMod = it2->second + "Gui"; try { Base::Interpreter().loadModule(pyMod.c_str()); // Try again pCmd = rMgr.getCommandByName(it2->first.c_str()); } catch(const Base::Exception&) { } } if (pCmd) { *bar << it2->first; // command name } } } } }
void PythonBaseWorkbench::appendToolbar(const std::string& bar, const std::list<std::string>& items) const { ToolBarItem* item = _toolBar->findItem(bar); if (!item) { item = new ToolBarItem(_toolBar); item->setCommand(bar); } for (std::list<std::string>::const_iterator it = items.begin(); it != items.end(); ++it) *item << *it; }
ToolBarItem* StdWorkbench::setupToolBars() const { ToolBarItem* root = new ToolBarItem; // File ToolBarItem* file = new ToolBarItem( root ); file->setCommand("File"); *file << "Std_New" << "Std_Open" << "Std_Save" << "Std_Print" << "Separator" << "Std_Cut" << "Std_Copy" << "Std_Paste" << "Separator" << "Std_Undo" << "Std_Redo" << "Separator" << "Std_Refresh" << "Separator" << "Std_WhatsThis"; // Workbench switcher ToolBarItem* wb = new ToolBarItem( root ); wb->setCommand("Workbench"); *wb << "Std_Workbench"; // Macro ToolBarItem* macro = new ToolBarItem( root ); macro->setCommand("Macro"); *macro << "Std_DlgMacroRecord" << "Std_MacroStopRecord" << "Std_DlgMacroExecute" << "Std_DlgMacroExecuteDirect"; // View ToolBarItem* view = new ToolBarItem( root ); view->setCommand("View"); *view << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_DrawStyle" << "Separator" << "Std_ViewAxo" << "Separator" << "Std_ViewFront" << "Std_ViewTop" << "Std_ViewRight" << "Separator" << "Std_ViewRear" << "Std_ViewBottom" << "Std_ViewLeft" << "Separator" << "Std_MeasureDistance" ; return root; }
ToolBarItem* StdWorkbench::setupCommandBars() const { ToolBarItem* root = new ToolBarItem; // View ToolBarItem* view = new ToolBarItem( root ); view->setCommand("Standard views"); *view << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_ViewAxo" << "Separator" << "Std_ViewFront" << "Std_ViewRight" << "Std_ViewTop" << "Separator" << "Std_ViewRear" << "Std_ViewLeft" << "Std_ViewBottom"; // Special Ops ToolBarItem* macro = new ToolBarItem( root ); macro->setCommand("Special Ops"); *macro << "Std_DlgParameter" << "Std_DlgPreferences" << "Std_DlgMacroRecord" << "Std_MacroStopRecord" << "Std_DlgMacroExecute" << "Std_DlgCustomize"; return root; }
void Workbench::setupCustomToolbars(ToolBarItem* root, const char* toolbar) const { std::string name = this->name(); ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp") ->GetGroup("Workbench")->GetGroup(name.c_str())->GetGroup(toolbar); std::vector<Base::Reference<ParameterGrp> > hGrps = hGrp->GetGroups(); CommandManager& rMgr = Application::Instance->commandManager(); for (std::vector<Base::Reference<ParameterGrp> >::iterator it = hGrps.begin(); it != hGrps.end(); ++it) { bool active = (*it)->GetBool("Active", true); if (!active) // ignore this toolbar continue; ToolBarItem* bar = new ToolBarItem(root); bar->setCommand("Custom"); // get the elements of the subgroups std::vector<std::pair<std::string,std::string> > items = hGrp->GetGroup((*it)->GetGroupName())->GetASCIIMap(); for (std::vector<std::pair<std::string,std::string> >::iterator it2 = items.begin(); it2 != items.end(); ++it2) { if (it2->first == "Separator") { *bar << "Separator"; } else if (it2->first == "Name") { bar->setCommand(it2->second); } else { Command* pCmd = rMgr.getCommandByName(it2->first.c_str()); if (!pCmd) { // unknown command // try to find out the appropriate module name std::string pyMod = it2->second + "Gui"; try { Base::Interpreter().loadModule(pyMod.c_str()); } catch(const Base::Exception&) { } // Try again pCmd = rMgr.getCommandByName(it2->first.c_str()); } if (pCmd) { *bar << it2->first; // command name } } } } }
//---------------------------------------------------------------- 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); }
void ToolBar::set_item_checked(const std::string &name, bool flag) { ToolBarItem *item = find_item(name); if (item) item->set_checked(flag); }
MultiLineEditor::MultiLineEditor( bool call_static, bool richtextMode, QWidget *parent, QWidget *editWidget, FormWindow *fw, const QString &text ) : MultiLineEditorBase( parent, 0, WType_Dialog | WShowModal ), formwindow( fw ), doWrap( FALSE ) { callStatic = call_static; if ( callStatic ) applyButton->hide(); textEdit = new TextEdit( centralWidget(), "textedit" ); Layout4->insertWidget( 0, textEdit ); if ( richtextMode ) { QPopupMenu *stylesMenu = new QPopupMenu( this ); menuBar->insertItem( tr( "&Styles" ), stylesMenu ); basicToolBar = new QToolBar( tr( "Basics" ), this, DockTop ); ToolBarItem *it = new ToolBarItem( this, basicToolBar, tr( "Italic" ), "i", QPixmap::fromMimeSource( "designer_textitalic.png" ), CTRL+Key_I ); it->addTo( stylesMenu ); connect( it, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); ToolBarItem *b = new ToolBarItem( this, basicToolBar, tr( "Bold" ), "b", QPixmap::fromMimeSource( "designer_textbold.png" ), CTRL+Key_B ); b->addTo( stylesMenu ); connect( b, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); ToolBarItem *ul = new ToolBarItem( this, basicToolBar, tr( "Underline" ), "u", QPixmap::fromMimeSource( "designer_textunderline.png" ), CTRL+Key_U ); ul->addTo( stylesMenu ); connect( ul, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); ToolBarItem *tt = new ToolBarItem( this, basicToolBar, tr( "Typewriter" ), "tt", QPixmap::fromMimeSource( "designer_textteletext.png" ) ); tt->addTo( stylesMenu ); connect( tt, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); basicToolBar->addSeparator(); QPopupMenu *layoutMenu = new QPopupMenu( this ); menuBar->insertItem( tr( "&Layout" ), layoutMenu ); QAction *brAction = new QAction( this ); brAction->setIconSet( QPixmap::fromMimeSource( "designer_textlinebreak.png" ) ); brAction->setText( tr("Break" ) ); brAction->addTo( basicToolBar ); brAction->addTo( layoutMenu ); connect( brAction, SIGNAL( activated() ) , this, SLOT( insertBR() ) ); ToolBarItem *p = new ToolBarItem( this, basicToolBar, tr( "Paragraph" ), "p", QPixmap::fromMimeSource( "designer_textparagraph.png" ) ); p->addTo( layoutMenu ); connect( p, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); layoutMenu->insertSeparator(); basicToolBar->addSeparator(); ToolBarItem *al = new ToolBarItem( this, basicToolBar, tr( "Align left" ), "p align=\"left\"", QPixmap::fromMimeSource( "designer_textleft.png" ) ); al->addTo( layoutMenu ); connect( al, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); ToolBarItem *ac = new ToolBarItem( this, basicToolBar, tr( "Align center" ), "p align=\"center\"", QPixmap::fromMimeSource( "designer_textcenter.png" ) ); ac->addTo( layoutMenu ); connect( ac, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); ToolBarItem *ar = new ToolBarItem( this, basicToolBar, tr( "Align right" ), "p align=\"right\"", QPixmap::fromMimeSource( "designer_textright.png" ) ); ar->addTo( layoutMenu ); connect( ar, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); ToolBarItem *block = new ToolBarItem( this, basicToolBar, tr( "Blockquote" ), "blockquote", QPixmap::fromMimeSource( "designer_textjustify.png" ) ); block->addTo( layoutMenu ); connect( block, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); QPopupMenu *fontMenu = new QPopupMenu( this ); menuBar->insertItem( tr( "&Font" ), fontMenu ); fontToolBar = new QToolBar( "Fonts", this, DockTop ); QAction *fontAction = new QAction( this ); fontAction->setIconSet( QPixmap::fromMimeSource( "designer_textfont.png" ) ); fontAction->setText( tr("Font" ) ); fontAction->addTo( fontToolBar ); fontAction->addTo( fontMenu ); connect( fontAction, SIGNAL( activated() ) , this, SLOT( showFontDialog() ) ); ToolBarItem *fp1 = new ToolBarItem( this, fontToolBar, tr( "Fontsize +1" ), "font size=\"+1\"", QPixmap::fromMimeSource( "designer_textlarger.png" ) ); connect( fp1, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); ToolBarItem *fm1 = new ToolBarItem( this, fontToolBar, tr( "Fontsize -1" ), "font size=\"-1\"", QPixmap::fromMimeSource( "designer_textsmaller.png" ) ); connect( fm1, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); ToolBarItem *h1 = new ToolBarItem( this, fontToolBar, tr( "Headline 1" ), "h1", QPixmap::fromMimeSource( "designer_texth1.png" ) ); connect( h1, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); ToolBarItem *h2 = new ToolBarItem( this, fontToolBar, tr( "Headline 2" ), "h2", QPixmap::fromMimeSource( "designer_texth2.png" ) ); connect( h2, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); ToolBarItem *h3 = new ToolBarItem( this, fontToolBar, tr( "Headline 3" ), "h3", QPixmap::fromMimeSource( "designer_texth3.png" ) ); connect( h3, SIGNAL( clicked( const QString& ) ), this, SLOT( insertTags( const QString& ))); QPopupMenu *optionsMenu = new QPopupMenu( this ); menuBar->insertItem( tr( "O&ptions" ), optionsMenu ); optionsToolBar = new QToolBar( "Options", this, DockTop ); wrapAction = new QAction( this ); wrapAction->setToggleAction( TRUE ); wrapAction->setIconSet( QPixmap::fromMimeSource( "designer_wordwrap.png" ) ); wrapAction->setText( tr( "Word Wrapping" ) ); wrapAction->addTo( optionsToolBar ); wrapAction->addTo( optionsMenu ); connect( wrapAction, SIGNAL( toggled( bool ) ), this, SLOT( changeWrapMode( bool ) ) ); oldDoWrap = doWrap; wrapAction->setOn( doWrap ); connect( helpButton, SIGNAL( clicked() ), MainWindow::self, SLOT( showDialogHelp() ) ); textEdit->document()->setFormatter( new QTextFormatterBreakInWords ); textEdit->document()->setUseFormatCollection( FALSE ); textEdit->document()->setPreProcessor( new SyntaxHighlighter_HTML ); if ( !callStatic && ::qt_cast<QTextEdit*>(editWidget) ) { mlined = (QTextEdit*)editWidget; mlined->setReadOnly( TRUE ); const QMetaProperty *wordWrap = mlined->metaObject()->property( mlined->metaObject()->findProperty( "wordWrap", TRUE ), TRUE ); oldWrapMode = 0; oldWrapString = "NoWrap"; if ( wordWrap ) { oldWrapMode = mlined->property( "wordWrap" ); oldWrapString = QString( wordWrap->valueToKey( oldWrapMode.toInt() ) ); if ( oldWrapString != "NoWrap" ) doWrap = TRUE; } textEdit->setAlignment( mlined->alignment() ); textEdit->setWordWrap( mlined->wordWrap() ); textEdit->setWrapColumnOrWidth( mlined->wrapColumnOrWidth() ); textEdit->setWrapPolicy( mlined->wrapPolicy() ); textEdit->setText( mlined->text() ); if ( !mlined->text().isEmpty() ) textEdit->selectAll(); } else { textEdit->setText( text ); textEdit->selectAll(); } } else {