fw4spl
IToolBarLayoutManager.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 #include <boost/lexical_cast.hpp>
12 
13 namespace fwGui
14 {
15 namespace layoutManager
16 {
17 
18 const IToolBarLayoutManager::RegistryKeyType IToolBarLayoutManager::REGISTRY_KEY = "::fwGui::ToolBarLayoutManager";
19 
20 //-----------------------------------------------------------------------------
21 
23 {
24 }
25 
26 //-----------------------------------------------------------------------------
27 
29 {
30 }
31 
32 //-----------------------------------------------------------------------------
33 
34 void IToolBarLayoutManager::initialize( ConfigurationType configuration)
35 {
36  OSLM_ASSERT("Bad configuration name "<<configuration->getName()<< ", must be layout",
37  configuration->getName() == "layout");
38 
40  for( iter = configuration->begin(); iter != configuration->end(); ++iter )
41  {
42  if( (*iter)->getName() == "menuItem" )
43  {
44  ConfigurationType toolBarItem = *iter;
45  ActionInfo info;
46  SLM_ASSERT("Depreciated tag <state>", !toolBarItem->hasAttribute("state"));
47  SLM_ASSERT("Depreciated tag <enable>", !toolBarItem->hasAttribute("enable"));
48 
49  SLM_ASSERT("missing <name> attribute", toolBarItem->hasAttribute("name"));
50  if( toolBarItem->hasAttribute("name") )
51  {
52  info.m_name = toolBarItem->getExistingAttributeValue("name");
53  }
54 
55  if( toolBarItem->hasAttribute("icon") )
56  {
57  info.m_icon = ::fwRuntime::getBundleResourceFilePath(toolBarItem->getAttributeValue("icon"));
58  }
59 
60  if( toolBarItem->hasAttribute("icon2") )
61  {
62  SLM_ASSERT("'icon' attribute must be defined before 'icon2'", !info.m_icon.empty());
63  info.m_icon2 = ::fwRuntime::getBundleResourceFilePath(toolBarItem->getAttributeValue("icon2"));
64  }
65 
66  if( toolBarItem->hasAttribute("style") )
67  {
68  std::string style = toolBarItem->getExistingAttributeValue("style");
69  info.m_isCheckable = (style == "check");
70  info.m_isRadio = (style == "radio");
71  }
72 
73  if( toolBarItem->hasAttribute("shortcut") )
74  {
75  info.m_shortcut = toolBarItem->getExistingAttributeValue("shortcut");
76  }
77  m_actionInfo.push_back(info);
78  }
79  else if( (*iter)->getName() == "separator" )
80  {
81  ActionInfo info;
82  info.m_isSeparator = true;
83 
84  if( (*iter)->hasAttribute("size") )
85  {
86  info.m_size = ::boost::lexical_cast< int > ((*iter)->getExistingAttributeValue("size"));
87  }
88 
89  m_actionInfo.push_back( info );
90  }
91  else if( (*iter)->getName() == "spacer" )
92  {
93  ActionInfo info;
94  info.m_isSpacer = true;
95  m_actionInfo.push_back( info );
96  }
97  else if( (*iter)->getName() == "menu" )
98  {
99  ActionInfo info;
100  info.m_isMenu = true;
101  if( (*iter)->hasAttribute("name") )
102  {
103  info.m_name = (*iter)->getExistingAttributeValue("name");
104  }
105 
106  if( (*iter)->hasAttribute("icon") )
107  {
108  info.m_icon = ::fwRuntime::getBundleResourceFilePath((*iter)->getExistingAttributeValue("icon" ));
109  }
110  m_actionInfo.push_back( info );
111  }
112  else if( (*iter)->getName() == "editor" )
113  {
114  ActionInfo info;
115  info.m_isEditor = true;
116 
117  m_actionInfo.push_back( info );
118  }
119  }
120 }
121 
122 //-----------------------------------------------------------------------------
123 
125 {
126  for( ::fwGui::container::fwMenuItem::sptr menuItem : m_menuItems)
127  {
128  menuItem->destroyContainer();
129  }
130  m_menuItems.clear();
131  for( ::fwGui::container::fwMenu::sptr menu : m_menus)
132  {
133  menu->destroyContainer();
134  }
135  m_menus.clear();
136  for( ::fwGui::container::fwContainer::sptr container : m_containers)
137  {
138  container->destroyContainer();
139  }
140  m_containers.clear();
141 }
142 
143 //-----------------------------------------------------------------------------
144 
145 std::vector< ::fwGui::container::fwMenuItem::sptr > IToolBarLayoutManager::getMenuItems()
146 {
147  return this->m_menuItems;
148 }
149 
150 //-----------------------------------------------------------------------------
151 
152 std::vector< ::fwGui::container::fwMenu::sptr > IToolBarLayoutManager::getMenus()
153 {
154  return this->m_menus;
155 }
156 
157 //-----------------------------------------------------------------------------
158 
159 std::vector< ::fwGui::container::fwContainer::sptr > IToolBarLayoutManager::getContainers()
160 {
161  return this->m_containers;
162 }
163 
164 //-----------------------------------------------------------------------------
165 
166 } // namespace layoutManager
167 } // namespace fwGui
168 
std::vector< ::fwGui::container::fwMenu::sptr > m_menus
All menus managed by this layout.
virtual FWGUI_API std::vector< ::fwGui::container::fwMenu::sptr > getMenus()
Returns the vector of fwMenu managed by this layout.
virtual FWGUI_API void initialize(ConfigurationType configuration)
Initialize layout managers.
#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::fwContainer::sptr > getContainers()
Returns the vector of fwContainer managed by this layout.
std::vector< ::fwGui::container::fwMenuItem::sptr > m_menuItems
All actions managed by this layout.
FWGUI_API IToolBarLayoutManager()
Constructor. Do nothing.
#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
This file defines the interface of the base class for managing a toolbar.
std::vector< ::fwGui::container::fwContainer::sptr > m_containers
All editors managed by this layout.
std::vector< ActionInfo > m_actionInfo
Save action informations from configuration.
virtual FWGUI_API std::vector< ::fwGui::container::fwMenuItem::sptr > getMenuItems()
Returns the vector of fwMenuItem managed by this layout.
virtual FWGUI_API void destroyActions()
Helper to destroy local actions.
virtual FWGUI_API ~IToolBarLayoutManager()
Destructor. Do nothing.
Container::iterator Iterator
Defines the configuration element container type.