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

Go to the SVN repository for this file.

1 /* $Id: window_manager_service_impl.cpp 33169 2015-06-05 18:46:12Z katargir $
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: Andrey Yazhuk
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
33 
37 
38 
40 
41 
43 : m_WindowManager(NULL),
44  m_Frame(NULL),
45  m_MenuService(NULL)
46 {
47 }
48 
49 
51 {
52  if (m_WindowManager)
54 }
55 
56 
57 void CWindowManagerService::SetFrame(wxFrame* frame)
58 {
59  m_Frame = frame;
60 }
61 
62 
64 {
66 
67  // create and setip n instance of CWindowManager
69 
72 
73  string path = CGuiRegistryUtil::MakeKey(m_RegPath, "Window Manager");
75 
77 
78  CWorkbenchFrame* wf = dynamic_cast<CWorkbenchFrame*>(m_Frame);
79  if (wf!=NULL) {
80  wf->SetDockManager( m_WindowManager->GetDockManager());
81  }
82 }
83 
84 
86 {
87  if(m_WindowManager) {
89 
91 
92  //TODO need to FORCE
94 
95  m_WindowManager->Hide();
96  m_WindowManager->Destroy();
98  }
99 }
100 
101 
103 {
105  m_WindowManager->SetAdvisor(advisor);
106 }
107 
108 
110 {
112  m_WindowManager->AddClient(client, bFloat);
113 }
114 
116 {
119 }
120 
122 {
125 }
126 
127 
129 {
131  m_WindowManager->CloseClients(clients);
132 }
133 
134 
136 {
139 }
140 
141 
143 {
145  m_WindowManager->GetAllClients(clients);
146 }
147 
148 
150 {
153 }
154 
155 
157 {
160 }
161 
162 
164 {
167 }
168 
170 {
173 }
174 
176 {
179 }
180 
182 {
185 }
186 
188 {
191 }
192 
194 {
196  return (m_WindowManager->IsDragging());
197 }
198 
200 {
203 }
204 
205 void CWindowManagerService::ApplyLayout(const objects::CUser_object& layout)
206 {
207  return m_WindowManager->ApplyLayout(layout);
208 }
209 
210 
211 objects::CUser_object* CWindowManagerService::SaveLayout()
212 {
214  return m_WindowManager->SaveLayout();
215 }
216 
217 
218 void CWindowManagerService::LoadLayout(const objects::CUser_object& layout,
219  IWMClientFactory& factory)
220 {
222  m_WindowManager->LoadLayout(layout, factory);
223 }
224 
225 
227 {
228  //TODO delete all existing toolbars
231 
232  for( size_t i = 0; i < m_ToolBarFactories.size(); i++ ) {
234  delete factory;
235  }
236  m_ToolBarFactories.clear();
237 }
238 
239 
241 {
242  _ASSERT(m_WindowManager && factory);
243 
244  if(factory == NULL) {
245  ERR_POST("CToolBarService::AddToolBarFactory() - NULL factory");
246  } else {
247  TToolBarFactories::const_iterator it =
248  std::find(m_ToolBarFactories.begin(), m_ToolBarFactories.end(),
249  factory);
250 
251  if(it == m_ToolBarFactories.end()) {
252  m_ToolBarFactories.push_back(factory); // add the factory
253  } else {
254  LOG_POST(Error << "CToolBarService::AddToolBarFactory() - "
255  "factory already registered");
256  }
257  }
258 }
259 
260 
262 {
263  _ASSERT(factory);
264 
265  TToolBarFactories::iterator it =
266  std::find(m_ToolBarFactories.begin(), m_ToolBarFactories.end(), factory);
267 
268  if(it == m_ToolBarFactories.end()) {
269  ERR_POST("CWorkbench::RemoveToolBarFactory() - "
270  "factory is not registered");
271  } else {
272  delete factory;
273  m_ToolBarFactories.erase(it);
274  }
275 }
276 
277 
279 {
281  if(m_MenuService) {
282  m_MenuService->ResetMenuBar(); //TODO optimize
283  }
284 }
285 
286 
288 {
289  static const char* kFunc = "CWindowManagerService::AddToolBarContext()";
290  _ASSERT(context);
291 
293  if(it != m_ToolBarContexts.end()) {
294  LOG_POST(Error << kFunc << " context already registered");
295  } else {
297 
298  vector<string> new_names;
299  context->GetCompatibleToolBars(new_names);
300 
301  // show new toolbars if needed
302  for( size_t i = 0; i < new_names.size(); i++ ) {
303  const string& name = new_names[i];
305  if(n_it == m_TBNameToCount.end()) {
306  // add the new toolbar
307  m_TBNameToCount[name] = 1;
308  x_ShowToolBar(name, true);
309  } else {
310  n_it->second++;
311  }
312  }
313  }
314 }
315 
316 
318 {
319  static const char* kFunc = "CWindowManagerService::RemoveToolBarContext()";
320  _ASSERT(context);
321 
323  if(it == m_ToolBarContexts.end()) {
324  _ASSERT(false);
325  LOG_POST(Error << kFunc << " context is not registered");
326  } else {
327  vector<string> names;
328  context->GetCompatibleToolBars(names);
329 
330  /// remove names from the map
331  for( size_t i = 0; i < names.size(); i++ ) {
332  const string& name = names[i];
334 
335  if( n_it != m_TBNameToCount.end() ){
336  if(n_it->second == 1) {
337  // the last reference to this toolbar
338  x_ShowToolBar(name, false);
339  m_TBNameToCount.erase(n_it);
340  } else {
341  n_it->second--;
342  }
343  }
344  }
345 
347  }
348 }
349 
350 
351 void CWindowManagerService::x_ShowToolBar(const string& name, bool show)
352 {
353 #ifdef _DEBUG
354  LOG_POST(Info << "CWindowManagerService::x_ShowToolBar() " << name << " " << show);
355 #endif
356 
357  bool is_shown = m_WindowManager->HasToolBar(name);
358 
359  if(is_shown != show) {
360  // action needed
361  if(show) {
362  // create and add a new toolbar
364  IToolBarContributor& factory = **it;
365 
366  vector<string> names;
367  factory.GetToolBarNames(names);
368  vector<string>::iterator it_n =
369  std::find(names.begin(), names.end(), name);
370  if(it_n != names.end()) {
371  wxFrame* frame = m_WindowManager->GetFrameWindow();
372  _ASSERT(frame);
373 
374  wxAuiToolBar* toolbar = factory.CreateToolBar(name, frame);
375  m_WindowManager->AddToolBar(toolbar);
376  return;
377  }
378  }
379  LOG_POST(Error << "Window Manager Service - cannot create toolbar \""
380  << name << " - factory is not found");
381  } else {
383  }
384  }
385 }
386 
387 
389 {
390  m_MenuService = service;
391 }
392 
393 
395 {
397 
398  if(m_WindowManager) {
399  const wxMenu* menu = m_WindowManager->GetMenu();
400  if(menu) {
401  return CloneMenu(*menu);
402  }
403  }
404  return NULL;
405 }
406 
408 {
409  m_RegPath = path;
410 }
411 
412 
414 {
415 }
416 
417 
419 {
420 }
421 
422 
423 bool CWindowManagerService::OnCommandEvent(wxCommandEvent& event)
424 {
425  if(m_WindowManager) {
426  return m_WindowManager->ProcessEvent(event);
427  }
428  return false;
429 }
430 
431 
static string MakeKey(const string &section, const string &key, const string &delim=CGuiRegistry::kDecimalDot)
create a key from a section and a subkey
Definition: registry.cpp:504
CWindowManager - component controlling windowing of client windows.
bool HasToolBar(const string &name)
bool CloseClient(IWMClient &client)
virtual const wxMenu * GetMenu()
static void RegisterImageAliases(wxFileArtProvider &provider)
registers graphical resources used by Window Manager
void DeleteToolBar(const string &name)
virtual void SetAdvisor(IWindowManagerAdvisor *advisor)
virtual void SetMenuListener(IWindowManagerMenuListener *listener)
void RegisterActiveClient(IWMClient &client)
virtual void SetRegistryPath(const string &reg_path)
void UnRegisterActiveClient(IWMClient &client)
void ActivateClient(IWMClient &client)
void GetAllClients(TClients &clients)
CDockManager * GetDockManager()
void LoadLayout(const objects::CUser_object &layout, IWMClientFactory &factory)
void CloseClients(const TClients &clients)
void RaiseFloatingWindowsInZOrder()
void AddToolBar(wxAuiToolBar *toolbar)
wxFrame * MoveToFloatingFrame(IWMClient &client)
IWMClient * GetActiveClient()
virtual bool ProcessEvent(wxEvent &event)
void ActivateClients(TClients &clients)
objects::CUser_object * SaveLayout()
virtual bool Create(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
void ApplyLayout(const objects::CUser_object &layout)
wxFrame * GetFrameWindow()
virtual bool AddClient(IWMClient &client, bool bFloat)
adds the client to the Main Tabbed Pane
void RefreshClient(IWMClient &client)
static bool IsDragging()
CWorkbenchFrame Main Application Frame for Workbench-based applications.
IMenuService - Menu Service.
IToolBarContext - represent a UI object that requires toolbars.
IToolBarContributor - a factory that produces toolbars.
Definition: ui_command.hpp:395
virtual void GetToolBarNames(vector< string > &names)=0
returns the names of toolbars produced
virtual wxAuiToolBar * CreateToolBar(const string &name, wxWindow *parent)=0
creates a toolbar with the given name (must be deleted by the caller)
IWMClientFactory - IWMClient factory.
Definition: wm_client.hpp:133
IWClient - abstract Window Manager client.
Definition: wm_client.hpp:50
IWindowManagerAdvisor.
void erase(iterator pos)
Definition: map.hpp:167
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
void clear()
Definition: set.hpp:153
parent_type::iterator iterator
Definition: set.hpp:80
const_iterator find(const key_type &key) const
Definition: set.hpp:137
void erase(iterator pos)
Definition: set.hpp:151
const_iterator end() const
Definition: set.hpp:136
parent_type::const_iterator const_iterator
Definition: set.hpp:79
static const struct name_t names[]
double wf(double lambda, double D_LR, double D_LU, double D_LD, double D_RU, double D_RD, double D_DU)
Definition: gme.cpp:78
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
virtual void RegisterActiveClient(IWMClient &client)
vector< IToolBarContributor * > TToolBarFactories
virtual void AddToolBarFactory(IToolBarContributor *factory)
the service assumes ownership of the given factory (will delete it)
virtual IWMClient * GetActiveClient()
returns Active client (i.e. client that has focus)
virtual void CloseClients(const TClients &clients)
virtual void DeleteToolBarFactory(IToolBarContributor *factory)
forces deleting of the factory
virtual void ActivateClients(TClients &clients)
makes clients visible, make the first client in the given container focused
virtual void AddClient(IWMClient &client, bool bFloat)
places the given IWMClient in the Main Tabbed Pane in Window Manager
virtual void LoadLayout(const objects::CUser_object &layout, IWMClientFactory &factory)
creates a new window layout based on description in the given CUser_object creates clients using IWMC...
virtual void RaiseFloatingWindowsInZOrder()
Raise all floating windows to preserve/refresh z-order.
virtual objects::CUser_object * SaveLayout()
saves current window layout to CUser_object
virtual void x_ShowToolBar(const string &name, bool show)
virtual void SetRegistryPath(const string &path)
virtual void RefreshClient(IWMClient &client)
refresh client UI (title)
TTBNameToCount m_TBNameToCount
holds a map of toolbar names declared by registered contexts toolbar name -> context count
vector< IWMClient * > TClients
bool OnCommandEvent(wxCommandEvent &event)
TToolBarContexts m_ToolBarContexts
holds registered toolbar contexts
virtual void CloseClient(IWMClient &client)
remove client(s) from Window Manager these functions do not disconnect clients from other services
virtual void ResetMenuBar()=0
virtual void AddToolBarContext(IToolBarContext *context)
register toolbar context the service does NOT assume ownership of the context
virtual wxFrame * MoveToFloatingFrame(IWMClient &client)
virtual void SetAdvisor(IWindowManagerAdvisor *advisor)
the service does not assume ownership of the given object
virtual void SetMenuService(IMenuService *service)
virtual void GetAllClients(TClients &clients)
returns a list of all registered IWMClients
virtual void SetFrame(wxFrame *frame)
virtual bool IsDragging() const
Returns true if a drag operation is currently in progress.
virtual void ApplyLayout(const objects::CUser_object &layout)
virtual const wxMenu * GetMenu()
returns a menu (must be deleted by the caller) menu injections should follow a separator named "Contr...
virtual void ActivateClient(IWMClient &client)
makes client visible and focused
virtual void UnRegisterActiveClient(IWMClient &client)
virtual void RemoveToolBarContext(IToolBarContext *context)
unregister toolbar context
#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
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
static static static wxID_ANY
static CNamedPipeClient * client
#define _ASSERT
static CS_CONTEXT * context
Definition: will_convert.c:21
wxFileArtProvider * GetDefaultFileArtProvider()
Definition: wx_utils.cpp:334
wxMenu * CloneMenu(const wxMenu &menu)
create a copy of the given menu
Definition: wx_utils.cpp:559
Modified on Tue Apr 30 06:43:00 2024 by modify_doxy.py rev. 669887