fw4spl
IMenuLayoutManager.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
8 
9 #include <fwRuntime/operations.hpp>
10 
11 namespace fwGui
12 {
13 namespace layoutManager
14 {
15 
16 const IMenuLayoutManager::RegistryKeyType IMenuLayoutManager::REGISTRY_KEY = "::fwGui::MenuLayoutManager";
17 
18 //-----------------------------------------------------------------------------
19 
21 {
22 }
23 
24 //-----------------------------------------------------------------------------
25 
27 {
28 }
29 
30 //-----------------------------------------------------------------------------
31 
32 void IMenuLayoutManager::initialize( ConfigurationType configuration)
33 {
34  OSLM_ASSERT("Bad configuration name "<<configuration->getName()<< ", must be layout",
35  configuration->getName() == "layout");
36 
38  for( iter = configuration->begin(); iter != configuration->end(); ++iter )
39  {
40  if( (*iter)->getName() == "menuItem" )
41  {
42  ConfigurationType menuItem = *iter;
43  ActionInfo info;
44 
45  SLM_ASSERT("Depreciated tag <state>", !menuItem->hasAttribute("state"));
46  SLM_ASSERT("Depreciated tag <enable>", !menuItem->hasAttribute("enable"));
47 
48  SLM_ASSERT("missing <name> attribute", menuItem->hasAttribute("name"));
49  if( menuItem->hasAttribute("name") )
50  {
51  info.m_name = menuItem->getExistingAttributeValue("name");
52  }
53 
54  if( menuItem->hasAttribute("shortcut") )
55  {
56  info.m_shortcut = menuItem->getExistingAttributeValue("shortcut");
57  }
58 
59  if( menuItem->hasAttribute("icon") )
60  {
61  info.m_icon = ::fwRuntime::getBundleResourceFilePath(menuItem->getAttributeValue("icon"));
62  }
63 
64  if( menuItem->hasAttribute("style") )
65  {
66  std::string style = menuItem->getExistingAttributeValue("style");
67  info.m_isCheckable = (style == "check");
68  info.m_isRadio = (style == "radio");
69  }
70 
71  if( menuItem->hasAttribute("specialAction") )
72  {
73  std::string specialActionName = menuItem->getExistingAttributeValue("specialAction");
74  if (specialActionName == "DEFAULT")
75  {
76  info.m_type = DEFAULT;
77  }
78  else if (specialActionName == "QUIT")
79  {
80  info.m_type = QUIT;
81  }
82  else if (specialActionName == "ABOUT")
83  {
84  info.m_type = ABOUT;
85  }
86  else if (specialActionName == "HELP")
87  {
88  info.m_type = HELP;
89  }
90  else if (specialActionName == "NEW")
91  {
92  info.m_type = NEW;
93  }
94  else
95  {
96  OSLM_FATAL("specialAction " << specialActionName << " is unknown." );
97  }
98  }
99 
100  m_actionInfo.push_back(info);
101  }
102  if( (*iter)->getName() == "separator" )
103  {
104  ActionInfo info;
105  info.m_isSeparator = true;
106  info.m_type = SEPARATOR;
107  m_actionInfo.push_back( info );
108  }
109 
110  if( (*iter)->getName() == "menu" )
111  {
112  ActionInfo info;
113  info.m_isMenu = true;
114  if( (*iter)->hasAttribute("name") )
115  {
116  info.m_name = (*iter)->getExistingAttributeValue("name");
117  }
118  m_actionInfo.push_back( info );
119  }
120  }
121 }
122 
123 //-----------------------------------------------------------------------------
124 
126 {
127  for( ::fwGui::container::fwMenuItem::sptr menuItem : m_menuItems)
128  {
129  menuItem->destroyContainer();
130  }
131  m_menuItems.clear();
132  for( ::fwGui::container::fwMenu::sptr menu : m_menus)
133  {
134  menu->destroyContainer();
135  }
136  m_menus.clear();
137 }
138 
139 //-----------------------------------------------------------------------------
140 
141 std::vector< ::fwGui::container::fwMenuItem::sptr > IMenuLayoutManager::getMenuItems()
142 {
143  return this->m_menuItems;
144 }
145 
146 //-----------------------------------------------------------------------------
147 
148 std::vector< ::fwGui::container::fwMenu::sptr > IMenuLayoutManager::getMenus()
149 {
150  return this->m_menus;
151 }
152 
153 //-----------------------------------------------------------------------------
154 
155 } // namespace layoutManager
156 } // namespace fwGui
157 
This file defines the interface of the base class for managing a menu.
#define OSLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:310
The namespace fwGui contains the base interface for IHM services.
Definition: SJobBar.hpp:23
virtual FWGUI_API std::vector< ::fwGui::container::fwMenu::sptr > getMenus()
Returns the vector of fwMenu managed by this layout.
FWGUI_API IMenuLayoutManager()
Constructor. Do nothing.
virtual FWGUI_API std::vector< ::fwGui::container::fwMenuItem::sptr > getMenuItems()
Returns the vector of fwMenuItem managed by this layout.
std::vector< ::fwGui::container::fwMenu::sptr > m_menus
All menus managed by this layout.
virtual FWGUI_API void initialize(ConfigurationType configuration)
Initialize layout managers.
std::vector< ActionInfo > m_actionInfo
Save action informations from configuration.
virtual FWGUI_API void destroyActions()
Helper to destroy local actions.
std::vector< ::fwGui::container::fwMenuItem::sptr > m_menuItems
All actions managed by this layout.
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
#define OSLM_FATAL(message)
Definition: spyLog.hpp:285
Container::iterator Iterator
Defines the configuration element container type.
virtual FWGUI_API ~IMenuLayoutManager()
Destructor. Do nothing.