plugin_arg_form.cpp
来自「ncbi源码」· C++ 代码 · 共 1,188 行 · 第 1/3 页
CPP
1,188 行
m_Choice(NULL), m_Arg(&arg){ _ASSERT(arg.GetConstraint().front()->Which() == CPluginValueConstraint::e_Set);}void CMenuFormatter::Process(void){ string val = m_Choice->text(); switch (m_Arg->GetType()) { case CPluginArg::eInteger: m_Arg->SetInteger(val); break; case CPluginArg::eDouble: m_Arg->SetDouble(val); break; case CPluginArg::eString: m_Arg->SetString(val); break; case CPluginArg::eFile: m_Arg->SetFile(val); break; default: break; }}Fl_Widget* CMenuFormatter::GetWidget(){ if ( !m_Group ) { // // create a new group for our argument // // default pieces of text const char* label_text = m_Arg->GetDesc().c_str(); const char* initial_value = m_Arg->AsString().c_str(); const char* tooltip = NULL; if (m_Arg->IsSetLong_desc()) { tooltip = m_Arg->GetLong_desc().c_str(); } // label and value sc_RowWidth int label_width = int (sc_RowWidth * sc_LabelFrac); int value_width = sc_RowWidth - label_width; int label_y = 0; int row_height = sc_RowHeight; // // create our menu // m_Choice = new Fl_Choice(label_width, 0, value_width, row_height); _ASSERT(m_Choice); int default_val = m_Choice->add(""); string val = m_Arg->AsString(); ITERATE (CPluginValueConstraint::TSet, set_iter, m_Arg->GetConstraint().front()->GetSet()) { string str = *set_iter; string::size_type pos = 0; while ( (pos = str.find_first_of("/", pos)) != string::npos) { str.insert(pos, "\\"); pos += 2; } int idx = m_Choice->add(str.c_str()); if (*set_iter == val) { default_val = idx; } } m_Choice->value(default_val); //m_Choice->box(FL_DOWN_BOX); m_Choice->color(FL_BACKGROUND2_COLOR); m_Choice->tooltip(tooltip); m_Choice->labelsize(12); m_Choice->textsize(12); // create a label to go with this as well... Fl_Box* label = new Fl_Box(0, 0, label_width, row_height); label->label(label_text); label->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT | FL_ALIGN_CLIP | FL_ALIGN_WRAP); label->labelsize(12); // create a group for this row m_Group = new Fl_Group(0, 0, sc_RowWidth, row_height); m_Group->add(label); m_Group->add_resizable(*m_Choice); m_Group->end(); } return m_Group;}//// CMultiObjFormatter formats the values stored in a multi-column// list browser as CObjects//CMultiObjFormatter::CMultiObjFormatter(CPluginArg& arg, const TConstScopedObjects& objs) : m_Group(NULL), m_Browser(NULL), m_Arg(&arg), m_Objects(objs){}CMultiObjFormatter::~CMultiObjFormatter(){} static voidscb_OnPopupBrowser(Fl_Widget* w, void* data){ CObjBrowser* browser = static_cast<CObjBrowser*>(data); if (browser) { browser->ShowBrowseDlg(); }}Fl_Widget* CMultiObjFormatter::GetWidget(){ if ( !m_Group ) { // // create a new group for our argument // // default pieces of text const char* label_text = m_Arg->GetDesc().c_str(); const char* tooltip = NULL; if (m_Arg->IsSetLong_desc()) { tooltip = m_Arg->GetLong_desc().c_str(); } // label and value sc_RowWidth const int label_y = 0; const int button_size = 19; const int label_width = int (sc_RowWidth * sc_LabelFrac); const int value_width = sc_RowWidth - label_width - button_size - 5; const int row_height = sc_RowHeight * 5; const int button_x = label_width + value_width + 5; const int button_y = label_y + row_height / 2 - button_size / 2; // // create our selector // Fl_Group* parent = new Fl_Group(0, 0, label_width + value_width, row_height); m_Browser = new CObjBrowser(parent->x(), parent->y(), parent->w(), parent->h(), m_Arg->GetObjectSubtype(), label_text); _ASSERT(m_Browser); m_Browser->Reserve(m_Arg->GetData().GetArray().size()); set<const CObject*> obj_ptrs; ITERATE (TConstScopedObjects, iter, m_Objects) { const CObject* obj = iter->object; const IDocument* doc = CDocManager::GetDocumentFromScope(*iter->scope); if (doc && obj && obj_ptrs.find(obj) == obj_ptrs.end()) { m_Browser->Add(*doc, *obj); obj_ptrs.insert(obj); } } m_Browser->tooltip(tooltip); m_Browser->box(FL_THIN_DOWN_FRAME); m_Browser->labelsize(12); parent->end(); parent->resizable(m_Browser); parent->box(FL_DOWN_BOX); parent->color(FL_BACKGROUND2_COLOR); // ...add a button to launch the select from other dialog Fl_Button* button = new Fl_Button(button_x, button_y, button_size, button_size, "..."); button->callback(scb_OnPopupBrowser, m_Browser); // create a group for this row m_Group = new Fl_Group(0, 0, sc_RowWidth, row_height); //m_Group->add(label); m_Group->add_resizable(*parent); m_Group->add(button); m_Group->end(); } return m_Group;}void CMultiObjFormatter::Process(void){ if ( !m_Browser ) { return; } CPluginArg::TValues value_list; for (size_t i = 0; i < m_Browser->GetRows(); ++i) { const SBrowserObject& obj = m_Browser->GetData(i); CRef<CPluginValue> value(new CPluginValue); value->SetObject(*obj.document, *obj.object); value_list.push_back(value); } if (value_list.size()) { m_Arg->SetObject(value_list); }}//// CSingleObjFormatter formats the values stored in an Fl_Choice // as CObjects//CSingleObjFormatter::CSingleObjFormatter(CPluginArg& arg, const TConstScopedObjects& objs) : m_Group(NULL), m_Choice(NULL), m_Arg(&arg), m_Objects(objs){}Fl_Widget* CSingleObjFormatter::GetWidget(){ if ( !m_Group ) { // // create a new group for our argument // // default pieces of text const char* label_text = m_Arg->GetDesc().c_str(); const char* tooltip = NULL; if (m_Arg->IsSetLong_desc()) { tooltip = m_Arg->GetLong_desc().c_str(); } // label and value sc_RowWidth int label_width = int (sc_RowWidth * sc_LabelFrac); int value_width = sc_RowWidth - label_width; int label_y = 0; int row_height = sc_RowHeight; // // create our menu // m_Choice = new CObjChoice(label_width, 0, value_width, row_height, m_Arg->GetObjectSubtype()); _ASSERT(m_Choice); set<const CObject*> obj_ptrs; ITERATE (TConstScopedObjects, iter, m_Objects) { const CObject* obj = iter->object; const IDocument* doc = CDocManager::GetDocumentFromScope(*iter->scope); if (doc && obj && obj_ptrs.find(obj) == obj_ptrs.end()) { m_Choice->Add(*doc, *obj); } } m_Choice->color(FL_BACKGROUND2_COLOR); m_Choice->tooltip(tooltip); m_Choice->labelsize(12); m_Choice->textsize(12); // create a label to go with this as well... Fl_Box* label = new Fl_Box(0, 0, label_width, row_height); label->label(label_text); label->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT | FL_ALIGN_CLIP | FL_ALIGN_WRAP); label->labelsize(12); // create a group for this row m_Group = new Fl_Group(0, 0, sc_RowWidth, row_height); m_Group->add(label); m_Group->add_resizable(*m_Choice); m_Group->end(); } return m_Group;}void CSingleObjFormatter::Process(void){ if ( !m_Choice ) { return; } SConstScopedObject obj = m_Choice->GetSelection(); const IDocument* doc = CDocManager::GetDocumentFromScope(*obj.scope); if (obj.object.GetPointer() && doc) { m_Arg->SetObject(*doc, *obj.object); }}//////////////////////////////////////////////////////////////////////////////// panel widget to organize flag arguments//CFlagPanel::CFlagPanel(CPluginArgSet::Tdata& args) : m_Group(NULL){ TConstScopedObjects objs; NON_CONST_ITERATE (CPluginArgSet::Tdata, iter, args) { CPluginArg& arg = **iter; CRef<CArgFormatter> fmt (CPluginArgForm::GetFormatter(arg, objs)); if (fmt) { m_Formatters.push_back(fmt); } } size_t right = m_Formatters.size() / 2; size_t left = m_Formatters.size() - right; size_t left_ht = 0; size_t right_ht = 0; size_t idx = 0; NON_CONST_ITERATE (list< CRef<CArgFormatter> >, iter, m_Formatters) { Fl_Widget* widget = (*iter)->GetWidget(); if (idx < left) { left_ht += widget->h(); } else { right_ht += widget->h(); } ++idx; } m_Group = new Fl_Group(0, 0, sc_RowWidth, max(left_ht, right_ht)); idx = 0; left_ht = 0; right_ht = 0; NON_CONST_ITERATE (list< CRef<CArgFormatter> >, iter, m_Formatters) { Fl_Widget* widget = (*iter)->GetWidget(); if (idx < left) { widget->resize(0, left_ht, sc_RowWidth / 2, widget->h()); left_ht += widget->h(); } else { widget->resize(sc_RowWidth / 2, right_ht, sc_RowWidth / 2, widget->h()); right_ht += widget->h(); } m_Group->add(widget); ++idx; } m_Group->end();}void CFlagPanel::Process(){ NON_CONST_ITERATE (list< CRef<CArgFormatter> >, iter, m_Formatters) { (*iter)->Process(); }}Fl_Widget* CFlagPanel::GetWidget(){ return m_Group;}END_NCBI_SCOPE/* * =========================================================================== * $Log: plugin_arg_form.cpp,v $ * Revision 1000.0 2004/06/01 21:17:08 gouriano * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.1 * * Revision 1.1 2004/06/01 18:04:44 dicuccio * Initial revision. Lots of changes: added gui_project ASN.1 project, added new * plugin arg form (separate widget), added plugin selector dialog * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?