NCBI C++ ToolKit
object_contrib.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: object_contrib.cpp 18488 2008-12-11 02:10:27Z voronov $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Authors: Yury Voronov
27 *
28 * File Description:
29 *
30 */
31 
32 #include <ncbi_pch.hpp>
33 
35 
39 
40 #include <wx/menu.h>
41 #include <wx/event.h>
42 
43 
45 
47  wxMenu& aMenu,
48  vector<wxEvtHandler*>& handlers,
49  const string& anExtPointId,
51  CUICommandRegistry* aCmdReg
52 ){
53  if( objects.empty() ){
54  return;
55  }
56 
57  if( aCmdReg == NULL ){
59  }
60 
61  // get contributed menus
62  vector< CIRef<IObjectCmdContributor> > contributors;
63  GetExtensionAsInterface( anExtPointId, contributors );
64 
65  // Merge contributed menus into the main Menu
66  for( size_t i = 0; i < contributors.size(); i++ ){
67  IObjectCmdContributor& obj = *contributors[i];
68 
70  wxMenu* obj_menu = contrib.first;
71  if( obj_menu ){
72  Merge( aMenu, *obj_menu );
73  delete obj_menu;
74  }
75  wxEvtHandler* handler = contrib.second;
76  if( handler ){
77  handlers.push_back( handler );
78  }
79  }
80 }
81 
82 WX_DEFINE_MENU(kContextMenuBackbone)
83  WX_MENU_SEPARATOR_L("Top Actions")
84  WX_MENU_SEPARATOR_L("Zoom")
85  WX_MENU_SEPARATOR_L("Actions")
86  WX_MENU_SEPARATOR_L("Edit")
87  WX_MENU_SEPARATOR_L("Settings")
89 
91 {
92  return CUICommandRegistry::GetInstance().CreateMenu( kContextMenuBackbone );
93 }
94 
95 
97 
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
static CUICommandRegistry & GetInstance()
the main instance associated with the application
Definition: ui_command.cpp:176
wxMenu * CreateMenu(const SwxMenuItemRec *items)
create a menu from a static definition (see WX_*_MENU macros)
Definition: ui_command.cpp:349
IObjectCmdContributor - contributes commands applicable to scoped objects.
pair< wxMenu *, wxEvtHandler * > TContribution
virtual TContribution GetMenu(TConstScopedObjects &objects)=0
returns a menu with commands applicable to the objects and optional command handler for the commands ...
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
#define NULL
Definition: ncbistd.hpp:225
void GetExtensionAsInterface(const string &ext_point_id, vector< CIRef< I > > &interfaces)
GetExtensionAsInterface() is a helper function that extracts all extensions implementing the specifie...
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
int i
void AddCommandsForScopedObjects(wxMenu &aMenu, vector< wxEvtHandler * > &handlers, const string &anExtPointId, TConstScopedObjects &objects, CUICommandRegistry *aCmdReg)
Helper function for adding commands provided by contributors to the menu.
wxMenu * CreateContextMenuBackbone()
#define WX_DEFINE_MENU(name)
New macros for defining menus for use with CUICommandRegistry.
Definition: ui_command.hpp:266
#define WX_END_MENU()
Definition: ui_command.hpp:294
#define WX_MENU_SEPARATOR_L(label)
Definition: ui_command.hpp:285
void Merge(wxMenu &menu_1, const wxMenu &menu_2)
merges all items form menu_2 into menu_1, preserving the structure if possible
Definition: wx_utils.cpp:579
Modified on Fri Sep 20 14:57:24 2024 by modify_doxy.py rev. 669887