view_menu.cpp

来自「ncbi源码」· C++ 代码 · 共 438 行

CPP
438
字号
/* * =========================================================================== * PRODUCTION $Log: view_menu.cpp,v $ * PRODUCTION Revision 1000.4  2004/06/01 20:44:49  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.31 * PRODUCTION * =========================================================================== *//*  $Id: view_menu.cpp,v 1000.4 2004/06/01 20:44:49 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: * *    IViewMenuData -- Class to hold callback information necessary to spawn a *                     view plugin from an FLTK callback * *    CNewViewMenuData      -- Class to hold / launch plugin to create a new *                             view around a given document *    CExistingViewMenuData -- Class to show a current view * *    CViewMenuMgr  -- Manager for dynamic FLTK view plugin menu + callback *                     data */#include <ncbi_pch.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/idocument.hpp>#include <gui/core/iview.hpp>#include <gui/core/plugin_registry.hpp>#include <gui/core/plugin_utils.hpp>#include <gui/core/selection_buffer.hpp>#include <gui/core/view_factory.hpp>#include <gui/core/view_menu.hpp>#include <gui/plugin/PluginArgSet.hpp>#include <gui/objutils/iselection.hpp>#include <gui/utils/message_box.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);//// concrete data class for new menus//class CNewViewMenuData : public IViewMenuData{public:    CNewViewMenuData(const string& plugin_name, ISelection* sel_source,                     const string& pool_name)        : IViewMenuData(),          m_Plugin(plugin_name),          m_SelSource(sel_source),          m_PoolName(pool_name)    {    }    //    // DoCallback()    // here we handle the meat of creating a new view    //    void DoCallback()    {        if ( m_Plugin.empty()  ) {            return;        }        TConstScopedObjects objs;        m_SelSource->GetSelections(objs);        CSelectionBuffer empty_buf;        NON_CONST_ITERATE (TConstScopedObjects, iter, objs) {            const IDocument* doc = CDocManager::GetDocumentFromScope(*iter->scope);            if (doc) {                empty_buf.AddSelection(doc, *iter->object);            }        }        CPluginUtils::CallPlugin(m_Plugin, eViewCommand_new_view,                                 empty_buf, NULL, m_PoolName);    }private:    string m_Plugin;    string m_PoolName;    ISelection* m_SelSource;};//// concrete data class for existing views menu//class CExistingViewMenuData : public IViewMenuData{public:    CExistingViewMenuData(IView* view)        : IViewMenuData(),          m_View(view)    {    }    //    // DoCallback()    // here we handle the meat of showing a given view    //    void DoCallback()    {        if ( !m_View ) {            return;        }        m_View->Show();    }protected:    IView* m_View;};//// default ctor for the view menu manager class//CViewMenuMgr::CViewMenuMgr(Fl_Menu_* menu, const string& base,                           ISelection* sel_source,                           const string& pool_name)    : CFltkMenuMgrBase<IViewMenuData>(menu)    , m_PoolName(pool_name)    , m_SelSource(sel_source){    SetMenuBase(base);}//// Clear()// this clears the contents of our two submenus//void CViewMenuMgr::Clear(){    // Do our base class clear    x_ClearData();    if ( !m_Menu ) {        return;    }    // we remove two sub-items - one for active views and one for new views    string base = m_Base;    if ( !base.empty() ) {        base += "/";    }    x_RemoveSubitems(base + "Current Views");    x_RemoveSubitems(base + "New View");}//// AddEmptyNewViews()// This adds an empty, non-selectable new views menu//void CViewMenuMgr::AddEmptyNewViews(const string& message){    string base = m_Base;    if ( !base.empty() ) {        base += "/";    }    x_AddNullItem(base + "&New View/" + message);}//// AddEmptyActiveViews()// This adds an empty, non-selectable new views menu//void CViewMenuMgr::AddEmptyActiveViews(const string& message){    string base = m_Base;    if ( !base.empty() ) {        base += "/";    }    x_AddNullItem(base + "&Current Views/" + message);}//// AddNewViews()// This will fill a menu with entries sufficient for creating new views for a// given document.  By default the menu itesm appear in the item// "(m_Base)/NewViews"//void CViewMenuMgr::AddNewViews(){    string menu_base = m_Base;    if ( !menu_base.empty() ) {        menu_base += "/";    }    menu_base += "New View/";    // determine what pool we live in    // if the pool name is empty, we create a new one    string pool_name(m_PoolName);    if (pool_name.empty()) {        static CAtomicCounter s_ac;        int id = s_ac.Add(1);        pool_name = "View Pool " + NStr::IntToString(id);    }    CPluginRegistry::TPlugins factories =        CPluginRegistry::GetPlugins(eViewCommand_new_view);    NON_CONST_ITERATE (CPluginRegistry::TPlugins, iter, factories) {        CPluginHandle plugin = *iter;        if ( !plugin ) {            continue;        }        string s = plugin.GetMenuItem();        if ( !menu_base.empty() ) {            s = menu_base + s;        }        x_AddItem(s, new CNewViewMenuData(plugin.GetClassName(), m_SelSource,                                          pool_name));    }}//// AddExistingViews()// This adds a submenu for the existing views for a given document//void CViewMenuMgr::AddActiveViews(IDocument* doc){    if ( !doc ) {        return;    }    string menu_base = m_Base;    if ( !menu_base.empty() ) {        menu_base += "/";    }    menu_base += "Current Views/";    if (doc->GetViews().size()) {        NON_CONST_ITERATE (IDocument::TViews, iter, doc->SetViews()) {            IView* view = *iter;            if ( !view ) {                continue;            }            string s = view->GetTitle();            if ( !menu_base.empty() ) {                s = menu_base + s;            }            x_AddItem(s, new CExistingViewMenuData(view));        }    } else {        x_AddNullItem(menu_base + "(no views open)");    }}void CViewMenuMgr::AddActiveViews(){    string menu_base = m_Base;    if ( !menu_base.empty() ) {        menu_base += "/";    }    menu_base += "Current Views/";    NON_CONST_ITERATE (CDocManager::TDocList, doc_iter,                       CDocManager::GetDocuments()) {        IDocument* doc = *doc_iter;        string doc_base = menu_base + "/" + doc->GetShortTitle() + "/";        if (doc->GetViews().size()) {            NON_CONST_ITERATE (IDocument::TViews, iter, doc->SetViews()) {                IView* view = *iter;                if ( !view ) {                    continue;                }                string s = view->GetTitle();                if ( !doc_base.empty() ) {                    s = doc_base + s;                }                x_AddItem(s, new CExistingViewMenuData(view));            }        } else {            x_AddNullItem(doc_base + "(no active views)");        }    }}END_NCBI_SCOPE/* * =========================================================================== * $Log: view_menu.cpp,v $ * Revision 1000.4  2004/06/01 20:44:49  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.31 * * Revision 1.31  2004/05/21 22:27:41  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.30  2004/05/20 12:28:20  dicuccio * Adjusted names - Active Views --> Current Views * * Revision 1.29  2004/05/03 12:51:37  dicuccio * Back out most of previous commit - inadvertent work-in-progress committed. * * Revision 1.28  2004/05/03 12:49:28  dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.27  2004/04/16 14:39:12  dicuccio * Use ISelection as selection source instead of selection buffer * * Revision 1.26  2004/04/07 12:49:09  dicuccio * Pass NULL for IReporter for views * * Revision 1.25  2003/12/31 20:27:57  dicuccio * Deleted dead code * * Revision 1.24  2003/11/06 20:05:29  dicuccio * Added handling of context parameter for view creation * * Revision 1.23  2003/09/29 15:42:05  dicuccio * Deprecated gui/scope.hpp.  Merged gui/core/types.hpp into gui/types.hpp * * Revision 1.22  2003/09/16 14:02:32  dicuccio * Renamed interface class for view menu data * * Revision 1.21  2003/09/04 14:01:51  dicuccio * Introduce IDocument and IView as abstract base classes for CDocument and CView * * Revision 1.20  2003/08/05 17:07:15  dicuccio * Changed calling semantics for the message queue - pass by reference, not * CConstRef<> * * Revision 1.19  2003/07/21 19:26:48  dicuccio * Changed data class interface from Run() to DoCallback() -- more descriptive. * Modified all menu structures to accept a selection buffer; use selection * buffers internally for all operations.  Fixed screening of plugins based on * selection contents * * Revision 1.18  2003/07/14 11:01:35  shomrat * Plugin messageing system related changes * * Revision 1.17  2003/06/25 17:02:55  dicuccio * Split CPluginHandle into a handle (pointer-to-implementation) and * implementation file.  Lots of #include file clean-ups. * * Revision 1.16  2003/05/30 14:15:41  dicuccio * Renamed MessageBox to NcbiMessageBox because brain-dead MSVC thinks this is * ::MessageBox and rewrites the symbol as MessageBoxA, which results in an * unresolved external and conflict with the Win32 API :(. * * Revision 1.15  2003/05/30 12:56:50  dicuccio * Converted code to use MessageBox() instead of fl_ask()/fl_message()/fl_alert() * * Revision 1.14  2003/05/19 13:35:59  dicuccio * Moved gui/core/plugin/ -> gui/plugin/.  Merged gui/core/algo, gui/core/doc/, * and gui/core/view/ into one library (gui/core/) * * Revision 1.13  2003/05/06 15:56:57  dicuccio * Removed unnecessary _TRACE(). * * Revision 1.12  2003/05/05 12:43:22  dicuccio * Added additional interface functions for creating view menus. * * Revision 1.11  2003/04/29 14:49:57  dicuccio * Changed API for retrieving command-specific plugins * * Revision 1.10  2003/04/24 16:35:27  dicuccio * Updated to reflect changes in IDocument API * * Revision 1.9  2003/04/16 18:23:45  dicuccio * Modified menu callbacks to use generic plugin launch facility (CallPlugin()) * * Revision 1.8  2003/03/10 23:06:13  kuznets * iterate -> ITERATE * * Revision 1.7  2003/02/26 17:53:31  dicuccio * Cleaned up the dynamic menus to make the dynamic menus resistant to menu * refreshes while the menu callback is running * * Revision 1.6  2003/02/24 13:03:17  dicuccio * Renamed classes in plugin spec: *     CArgSeg --> CPluginArgSet *     CArgument --> CPluginArg *     CPluginArgs --> CPluginCommand *     CPluginCommands --> CPluginCommandSet * * Revision 1.5  2003/02/20 19:49:57  dicuccio * Created new plugin architecture, based on ASN.1 spec.  Moved GBENCH frameowrk * over to use new plugin architecture. * * Revision 1.4  2003/01/15 21:09:08  dicuccio * Added private callback for handling dynamic view menu items * * Revision 1.3  2003/01/13 13:10:07  dicuccio * Namespace clean-up.  Retired namespace gui -> converted all to namespace * ncbi.  Moved all FLUID-generated code into namespace ncbi. * * Revision 1.2  2003/01/10 17:38:33  dicuccio * Changed TPluginList --> TPlugins.  Added accessor for all available plugins. * * Revision 1.1  2002/12/20 19:20:07  dicuccio * Initial revision. * * =========================================================================== */

⌨️ 快捷键说明

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