plugin_arg_form.cpp

来自「ncbi源码」· C++ 代码 · 共 1,188 行 · 第 1/3 页

CPP
1,188
字号
/* * =========================================================================== * 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_SCOPEUSING_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 widgetclass 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 formvoid 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:

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?