plugin_arg_form.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:30k
- /*
- * ===========================================================================
- * PRODUCTION $Log: plugin_arg_form.cpp,v $
- * PRODUCTION Revision 1000.0 2004/06/01 21:17:08 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.1
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: plugin_arg_form.cpp,v 1000.0 2004/06/01 21:17:08 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Mike DiCuccio
- *
- * File Description:
- *
- */
- #include <ncbi_pch.hpp>
- #include "plugin_arg_form.hpp"
- #include "obj_browser.hpp"
- #include "obj_menu.hpp"
- #include <FL/Fl_Group.H>
- #include <FL/Fl_Int_Input.H>
- #include <FL/Fl_File_Input.H>
- #include <FL/Fl_Secret_Input.H>
- #include <FL/Fl_Float_Input.H>
- #include <FL/Fl_Multiline_Input.H>
- #include <FL/Fl_Box.H>
- #include <FL/Fl_File_Chooser.H>
- #include <gui/plugin/PluginValue.hpp>
- #include <gui/plugin/PluginValueConstraint.hpp>
- #include <gui/dialogs/file_browser.hpp>
- #include <gui/core/doc_manager.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- //
- //
- // formatter specializations
- //
- //
- //
- // format an input box as a built-in argument type
- //
- class CSimpleFormatter : public CArgFormatter
- {
- public:
- enum EEditType {
- eMultiLine,
- eSingleLine,
- eInteger,
- eFloat,
- eFile,
- eSecret
- };
- CSimpleFormatter(objects::CPluginArg& arg);
- void Process(void);
- Fl_Widget* GetWidget();
- private:
- // the group that holds everything
- Fl_Group* m_Group;
- // our input box
- Fl_Input* m_Input;
- // the argument we represent
- CRef<objects::CPluginArg> m_Arg;
- static void cb_FileOpen(Fl_Widget* w, void* data);
- };
- //
- // format a multiline input box as a built-in argument type
- // this is valid only for arguments of type list
- //
- class CMultiLineFormatter : public CArgFormatter
- {
- public:
- CMultiLineFormatter(objects::CPluginArg& arg);
- void Process(void);
- Fl_Widget* GetWidget();
- private:
- // the group that holds everything
- Fl_Group* m_Group;
- // our input box
- Fl_Input* m_Input;
- // the argument we represent
- CRef<objects::CPluginArg> m_Arg;
- };
- //
- // format a drop-down list as a built-in argument type
- //
- class CMenuFormatter : public CArgFormatter
- {
- public:
- CMenuFormatter(objects::CPluginArg& arg);
- void Process(void);
- Fl_Widget* GetWidget();
- private:
- // the group that holds everything
- Fl_Group* m_Group;
- // our choice
- Fl_Choice* m_Choice;
- // the argument we represent
- CRef<objects::CPluginArg> m_Arg;
- };
- //
- // format a button as a built-in argument type for
- // boolean/flag arguments only.
- //
- class CButtonFormatter : public CArgFormatter
- {
- public:
- CButtonFormatter(objects::CPluginArg& arg);
- void Process(void);
- Fl_Widget* GetWidget();
- private:
- // the group that holds everything
- Fl_Button* m_Button;
- CRef<objects::CPluginArg> m_Arg;
- };
- //
- // format a drop-down list as an object
- //
- class CSingleObjFormatter : public CArgFormatter
- {
- public:
- CSingleObjFormatter(objects::CPluginArg& arg,
- const TConstScopedObjects& objs);
- void Process(void);
- Fl_Widget* GetWidget();
- private:
- Fl_Group* m_Group;
- CObjChoice* m_Choice;
- TConstScopedObjects m_Objects;
- CRef<objects::CPluginArg> m_Arg;
- };
- //
- // format a multiline browser as an array of objects
- //
- class CMultiObjFormatter : public CArgFormatter
- {
- public:
- CMultiObjFormatter(objects::CPluginArg& arg,
- const TConstScopedObjects& objs);
- ~CMultiObjFormatter();
- void Process(void);
- Fl_Widget* GetWidget();
- private:
- void x_InitArgUserDataList();
- Fl_Group* m_Group;
- CObjBrowser* m_Browser;
- TConstScopedObjects m_Objects;
- CRef<objects::CPluginArg> m_Arg;
- };
- //
- // specialized formatter for dealing with flags
- // this is made public because these are a special case
- //
- class CFlagPanel : public CArgFormatter
- {
- public:
- CFlagPanel(objects::CPluginArgSet::Tdata& args);
- void Process();
- Fl_Widget* GetWidget();
- private:
- // internal flag formatters
- list< CRef<CArgFormatter> > m_Formatters;
- // the group that holds everything
- Fl_Group* m_Group;
- };
- // silly title widget
- class CPluginArgFormTitle : public Fl_Box
- {
- public:
- CPluginArgFormTitle(int x, int y, int w, int h, const char* label_str = NULL)
- : Fl_Box(x, y, w, h)
- {
- if (label_str) {
- m_Title = label_str;
- }
- label(m_Title.c_str());
- box(FL_THIN_DOWN_BOX);
- color(fl_rgb_color(160, 160, 240));
- align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
- }
- void SetTitle(const string& title)
- {
- m_Title = title;
- }
- private:
- string m_Title;
- Fl_Box* m_LabelBox;
- Fl_Group* m_LabelSpacer;
- };
- ////////////////////////////////////////////////////////////////////////
- //
- // CPluginArgForm
- //
- CPluginArgForm::CPluginArgForm(int x, int y, int w, int h, const char* label)
- : CFlForm(x, y, w, h, label)
- {
- }
- // set the arguments for this form
- void CPluginArgForm::SetArgs(objects::CPluginArgSet& args,
- const TConstScopedObjects& selections)
- {
- // clear the pack that holds our information
- Clear();
- CPluginArgSet::Tdata required;
- CPluginArgSet::Tdata optional;
- CPluginArgSet::Tdata flags;
- // first, sort through our arguments and divide into required and optional
- // pools
- NON_CONST_ITERATE (CPluginArgSet::Tdata, iter, args.Set()) {
- CRef<CPluginArg> arg = *iter;
- if ( arg->IsSetHidden() && arg->GetHidden() ) {
- continue;
- }
- if (arg->GetType() == CPluginArg::eBoolean) {
- flags.push_back(arg);
- } else if (arg->GetOptional()) {
- optional.push_back(arg);
- } else {
- required.push_back(arg);
- }
- }
- // Create conversion cache. Might be needed for Object arguments
- CRef<CConvertCache> convert_cache(new CConvertCache);
- // required arguments first
- if ( !required.empty() ) {
- x_AddOptions(required, "Required Fields", *convert_cache, selections);
- }
- // flags next
- if ( !flags.empty() ) {
- x_AddFlags(flags, "Flags", *convert_cache);
- }
- // optional arguments next
- if ( !optional.empty()) {
- x_AddOptions(optional, "Optional Fields", *convert_cache, selections);
- }
- }
- void CPluginArgForm::x_AddFlags(CPluginArgSet::Tdata& opts,
- const char* title,
- CConvertCache& convert_cache)
- {
- if (title && *title) {
- AddTitle(title);
- }
- CRef<CArgFormatter> flag_panel(new CFlagPanel(opts));
- if (flag_panel) {
- AddFormatter(*flag_panel);
- }
- }
- void CPluginArgForm::x_AddOptions(CPluginArgSet::Tdata& opts,
- const char* title,
- CConvertCache& convert_cache,
- const TConstScopedObjects& selections)
- {
- if (title && *title) {
- AddTitle(title);
- }
- NON_CONST_ITERATE (CPluginArgSet::Tdata, iter, opts) {
- CPluginArg& arg = **iter;
- CRef<CArgFormatter> fmt
- (CPluginArgForm::GetFormatter(arg, selections));
- if (fmt) {
- AddFormatter(*fmt);
- }
- }
- }
- void CPluginArgForm::AddTitle(const string& title)
- {
- CPluginArgFormTitle* widget = new CPluginArgFormTitle(0, 0, w(), 20);
- widget->SetTitle(title);
- AddWidget(widget);
- }
- void CPluginArgForm::AddFormatter(CArgFormatter& fmt)
- {
- m_Formatters.push_back(CRef<CArgFormatter>(&fmt));
- Fl_Widget* w = fmt.GetWidget();
- if (w) {
- AddWidget(w);
- }
- }
- void CPluginArgForm::Process()
- {
- NON_CONST_ITERATE (TArgFormatters, iter, m_Formatters) {
- (*iter)->Process();
- }
- }
- // generate a new argument formatter based on a given argument.
- CArgFormatter* CPluginArgForm::GetFormatter(CPluginArg& arg,
- const TConstScopedObjects& objs)
- {
- if (arg.GetData().IsSingle()) {
- switch (arg.GetType()) {
- case CPluginArg::eString:
- case CPluginArg::eInteger:
- case CPluginArg::eDouble:
- case CPluginArg::eFile:
- if (arg.IsSetConstraint() &&
- arg.GetConstraint().front()->Which() ==
- CPluginValueConstraint::e_Set) {
- return new CMenuFormatter(arg);
- } else {
- return new CSimpleFormatter(arg);
- }
- case CPluginArg::eBoolean:
- return new CButtonFormatter(arg);
- case CPluginArg::eDocument:
- case CPluginArg::eObject:
- return new CSingleObjFormatter(arg, objs);
- default:
- LOG_POST(Error << "unhandled argument type: " << (int)arg.GetType());
- break;
- }
- } else {
- switch (arg.GetType()) {
- case CPluginArg::eString:
- case CPluginArg::eInteger:
- case CPluginArg::eDouble:
- return new CMultiLineFormatter(arg);
- case CPluginArg::eDocument:
- case CPluginArg::eObject:
- return new CMultiObjFormatter(arg, objs);
- default:
- LOG_POST(Error << "unhandled argument type: " << (int)arg.GetType());
- break;
- }
- }
- return NULL;
- }
- //
- //
- // internal implementation
- //
- //
- //
- // constants controlling layout
- //
- // default row height, in pixels
- static const int sc_RowHeight = 25;
- // default row width, in pixels
- static const int sc_RowWidth = 500;
- // default fraction of the width devoted to labels
- static const float sc_LabelFrac = 0.33f;
- //
- // argument formatter for single-line input boxes
- //
- CSimpleFormatter::CSimpleFormatter(CPluginArg& arg)
- : m_Group(NULL),
- m_Input(NULL),
- m_Arg(&arg)
- {
- }
- void CSimpleFormatter::Process(void)
- {
- if ( !m_Input || !m_Group || !m_Arg.GetPointer() ) {
- return;
- }
- string val(m_Input->value());
- 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:
- LOG_POST(Error << "CSimpleFormatter: unhandled argument type");
- break;
- }
- }
- Fl_Widget* CSimpleFormatter::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 input item
- m_Input = NULL;
- Fl_Button* button = NULL;
- switch (m_Arg->GetType()) {
- default:
- case CPluginArg::eString:
- m_Input = new Fl_Input(label_width, 0,
- value_width, row_height);
- break;
- case CPluginArg::eInteger:
- m_Input = new Fl_Int_Input(label_width, 0,
- value_width, row_height);
- break;
- case CPluginArg::eDouble:
- m_Input = new Fl_Float_Input(label_width, 0,
- value_width, row_height);
- break;
- case CPluginArg::eFile:
- label_y = 10;
- row_height += label_y;
- m_Input = new Fl_File_Input(label_width, 0,
- value_width - 30, row_height);
- // we also need a button...
- button = new Fl_Button(label_width + value_width - 22, 13, 19, 19);
- button->label("...");
- button->callback((Fl_Callback*)&CSimpleFormatter::cb_FileOpen,
- (void*)m_Input);
- break;
- }
- _ASSERT(m_Input);
- m_Input->value(initial_value);
- m_Input->color(FL_BACKGROUND2_COLOR);
- m_Input->box(FL_DOWN_BOX);
- m_Input->tooltip(tooltip);
- m_Input->labelsize(12);
- m_Input->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_Input);
- if (button) {
- m_Group->add(button);
- }
- m_Group->end();
- }
- return m_Group;
- }
- void CSimpleFormatter::cb_FileOpen(Fl_Widget* w, void* data)
- {
- Fl_Input* input = static_cast<Fl_Input*>(data);
- if (input) {
- string str = NcbiFileBrowser("Select a file", "", input->value());
- if ( !str.empty() ) {
- input->value(str.c_str());
- }
- }
- }
- //
- // argument formatter for check-box arguments
- //
- CButtonFormatter::CButtonFormatter(CPluginArg& arg)
- : m_Button(NULL),
- m_Arg(&arg)
- {
- }
- void CButtonFormatter::Process(void)
- {
- if ( !m_Button || !m_Arg.GetPointer() ) {
- return;
- }
- bool checked = m_Button->value() ? true : false;
- m_Arg->SetBoolean(checked);
- }
- Fl_Widget* CButtonFormatter::GetWidget()
- {
- if ( !m_Button ) {
- //
- // create a new group for our argument
- //
- // default pieces of text
- const char* label_text = m_Arg->GetDesc().c_str();
- bool initial_value = m_Arg->AsBoolean();
- const char* tooltip = NULL;
- if (m_Arg->IsSetLong_desc()) {
- tooltip = m_Arg->GetLong_desc().c_str();
- }
- m_Button = new Fl_Check_Button(0, 0, sc_RowWidth, sc_RowHeight,
- label_text);
- if (initial_value) {
- m_Button->value(1);
- }
- if (tooltip) {
- m_Button->tooltip(tooltip);
- }
- }
- return m_Button;
- }
- //
- // argument formatter for multiline-line input boxes
- //
- CMultiLineFormatter::CMultiLineFormatter(CPluginArg& arg)
- : m_Group(NULL),
- m_Input(NULL),
- m_Arg(&arg)
- {
- }
- void CMultiLineFormatter::Process(void)
- {
- string val(m_Input->value());
- vector<string> vals;
- string::iterator start = val.begin();
- string::iterator curr = val.begin();
- string::iterator end = val.end();
- for ( ; curr != end; ++curr) {
- if (*curr == ',' || *curr == ';') {
- // tokenize
- if ( start != curr ) {
- vals.push_back(string(start, curr));
- }
- for (++curr; curr != end; ++curr) {
- // skip whitespace
- if ( *curr != ',' &&
- *curr != ';' &&
- *curr != ' ' &&
- *curr != 't' &&
- *curr != 'n' &&
- *curr != 'r') {
- break;
- }
- }
- start = curr;
- } else if (*curr == '"') {
- // balance double quotes
- for (++curr; curr != end && *curr != '"'; ++curr) {
- }
- }
- }
- if ( start != curr ) {
- vals.push_back(string(start, curr));
- }
- CPluginArg::TValues values;
- switch (m_Arg->GetType()) {
- case CPluginArg::eInteger:
- ITERATE (vector<string>, iter, vals) {
- CRef<CPluginValue> value(new CPluginValue());
- value->SetInteger(*iter);
- values.push_back(value);
- }
- break;
- case CPluginArg::eDouble:
- ITERATE (vector<string>, iter, vals) {
- CRef<CPluginValue> value(new CPluginValue());
- value->SetDouble(*iter);
- values.push_back(value);
- }
- break;
- case CPluginArg::eString:
- ITERATE (vector<string>, iter, vals) {
- CRef<CPluginValue> value(new CPluginValue());
- value->SetString(*iter);
- values.push_back(value);
- }
- break;
- case CPluginArg::eFile:
- ITERATE (vector<string>, iter, vals) {
- CRef<CPluginValue> value(new CPluginValue());
- value->SetFile(*iter);
- values.push_back(value);
- }
- break;
- default:
- LOG_POST(Error << "CMultiLineFormatter: unhandled argument type");
- break;
- }
- m_Arg->SetList(values);
- }
- Fl_Widget* CMultiLineFormatter::GetWidget(void)
- {
- if ( !m_Group ) {
- //
- // create a new group for our argument
- //
- // default pieces of text
- const char* label_text = m_Arg->GetDesc().c_str();
- string initial_value;
- ITERATE (CPluginArg::TData::TArray, iter, m_Arg->GetData().GetArray()) {
- if ( !initial_value.empty() ) {
- initial_value += "n";
- }
- initial_value += (*iter)->AsString();
- }
- 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;// * 2;
- // create our input item
- m_Input = new Fl_Input(label_width, 0,
- value_width, row_height);
- _ASSERT(m_Input);
- m_Input->value(initial_value.c_str());
- m_Input->box(FL_DOWN_BOX);
- m_Input->color(FL_BACKGROUND2_COLOR);
- m_Input->tooltip(tooltip);
- m_Input->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_TOP);
- m_Input->labelsize(12);
- m_Input->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_Input);
- m_Group->end();
- }
- return m_Group;
- }
- //
- // CMenuFormatter handles items with 'set' constraints
- //
- CMenuFormatter::CMenuFormatter(CPluginArg& arg)
- : m_Group(NULL),
- 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 void
- scb_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
- *
- * ===========================================================================
- */