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

Go to the SVN repository for this file.

1 /* $Id: window_manager.cpp 40274 2018-01-19 17:05:09Z 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  * File Description:
29  */
30 
31 #include <ncbi_pch.hpp>
32 
33 
35 
41 
46 
47 #include <gui/utils/menu_item.hpp>
48 
49 #include <algorithm>
50 
51 #include <wx/sizer.h>
52 #include <wx/menu.h>
53 #include <wx/toolbar.h>
54 
55 
57 
58 ///////////////////////////////////////////////////////////////////////////////
59 /// IWMClient::CFingerprint
61 : m_Persistent(false)
62 {
63 }
64 
65 
66 IWMClient::CFingerprint::CFingerprint(const string& id, bool persistent)
67 : m_Id(id),
68  m_Persistent(persistent)
69 {
70 }
71 
72 
74 : m_Id(orig.m_Id),
75  m_Persistent(orig.m_Persistent)
76 {
77 }
78 
79 
81 {
82  return m_Id == orig.m_Id;
83 }
84 
85 
87 {
88  return m_Id.empty();
89 }
90 
91 
93 {
94  return m_Persistent ? m_Id : kEmptyStr;
95 }
96 
97 const string IWMClient::CFingerprint::GetId() const
98 {
99  if (m_Persistent) {
100  return m_Id;
101  } else {
102  // strip out the pointer based component of ID
103  vector<string> v;
104  NStr::Split(m_Id, "@", v);
105  if (!v.empty()) {
106  string &s = v[0];
107  size_t pos1 = s.find('(');
108  if (pos1 == string::npos) {
109  return s;
110  }
111  size_t pos2 = s.find(')');
112  if (pos2 == string::npos) {
113  return s;
114  }
115 
116  string s2 = s.substr(pos1+1, (pos2 - pos1)-1);
118 
119  return s2;
120  }
121  }
122  return kEmptyStr;
123 }
124 
125 
127 {
128  m_Id = s;
129  m_Persistent = ! s.empty();
130 }
131 
132 
133 ///////////////////////////////////////////////////////////////////////////////
134 /// CWindowManagerEvent
135 
137 : CEvent(type),
138  m_Client(client),
139  m_Cmd(eCmdInvalid)
140 {
141 }
142 
144 : CEvent(ePostCommand),
145  m_Client(client),
146  m_Cmd(cmd)
147 {
148 }
149 
150 
151 CWindowManagerEvent::CWindowManagerEvent(EEventType type, const vector<IWMClient*>& clients)
152 : CEvent(type),
153  m_Client(NULL),
154  m_Clients(clients),
155  m_Cmd(eCmdInvalid)
156 {
158 }
159 
160 
162 {
163  return m_Client;
164 }
165 
166 
167 void CWindowManagerEvent::GetClients(vector<IWMClient*>& clients)
168 {
169  clients = m_Clients;
170 }
171 
172 
173 ///////////////////////////////////////////////////////////////////////////////
174 /// CWindowManager
175 
176 /// wxEvtHandler table
177 BEGIN_EVENT_TABLE(CWindowManager, wxPanel)
181  CWindowManager::OnWindowCommand)
183  CWindowManager::OnUpdateWindowCommand)
184 
185  EVT_LEFT_UP(CWindowManager::OnLeftUp)
186  EVT_MOTION(CWindowManager::OnMotion)
187  EVT_MOUSE_CAPTURE_LOST(CWindowManager::OnMouseCaptureLost)
189 
190 /// CEventHandler map
193  &CWindowManager::OnPostCommand)
194  ON_EVENT(CWindowManagerEvent, CWindowManagerEvent::eCloseClientsRequest,
195  &CWindowManager::OnCloseClientsRequestEvent)
197 
198 
200 : wxPanel(),
201  m_Advisor(NULL),
202  m_MenuListener(NULL),
203  m_FrameWindow(frame),
204  m_DockManager(NULL),
205  m_ActiveClient(NULL),
206  m_DragDockPanel(NULL),
207  m_Canceled(false)
208 {
209  SetSizer(new wxBoxSizer(wxVERTICAL));
210 
211  wxAuiDockArt* dock_art = m_AuiManager.GetArtProvider();
212  dock_art->SetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE, 0);
213 }
214 
215 
217 {
218  provider.RegisterFileAlias(wxT("wm_menu"), wxT("wm_menu.png"));
219  provider.RegisterFileAlias(wxT("wm_menu_active"), wxT("wm_menu_active.png"));
220 
221  provider.RegisterFileAlias(wxT("wm_minimize"), wxT("wm_minimize.png"));
222  provider.RegisterFileAlias(wxT("wm_minimize_active"), wxT("wm_minimize_active.png"));
223 
224  provider.RegisterFileAlias(wxT("wm_float"), wxT("wm_float.png"));
225  provider.RegisterFileAlias(wxT("wm_float_active"), wxT("wm_float_active.png"));
226 
227  provider.RegisterFileAlias(wxT("wm_close"), wxT("wm_close.png"));
228  provider.RegisterFileAlias(wxT("wm_close_active"), wxT("wm_close_active.png"));
229 }
230 
231 
232 void CWindowManager::SetRegistryPath(const string& reg_path)
233 {
234  m_RegPath = reg_path;
235 }
236 
237 
238 bool CWindowManager::Create(wxWindow *parent, wxWindowID id,
239  const wxPoint& pos, const wxSize& size)
240 {
241  bool res = wxPanel::Create(parent, id, pos, size, wxBORDER_NONE, wxT("window_manager"));
242  if(res) {
243  m_AuiManager.SetManagedWindow(m_FrameWindow);
244 
245  wxAuiPaneInfo info;
246  info.CenterPane();
247 
248  m_AuiManager.AddPane(this, info);
249 
250  m_DockManager = new CDockManager(*this, *this);
252 
253  // create the main Dock Container that will be hosted inside Window Manager
255  GetSizer()->Add(dock_cont, 1, wxEXPAND);
256 
257  // create a container for minimized Clients
259  GetSizer()->Add(cont, 0, wxEXPAND);
260 
261  m_AuiManager.Update();
262  }
263 
264  return res;
265 }
266 
267 
269 {
270  CloseAllClients();
271 
272  m_AuiManager.UnInit();
273 
274  delete m_DockManager;
276 }
277 
278 
280 {
281  m_Advisor = advisor;
282 }
283 
284 
286 {
287  m_MenuListener = listener;
288 }
289 
290 
292 {
293  return m_FrameWindow;
294 }
295 
297 {
298  return m_DockManager;
299 }
300 
301 
303 {
304  if(client.GetWindow()) {
305  if(x_RegisterClient(client)) {
306  if (!client.IsADialog()) {
309  x_ResetMenuBar();
310  } else {
311  wxWindow* wnd = client.GetWindow();
312  if (wnd) {
313  wnd->Show();
314  OnFocusChanged(wnd);
315  }
316  }
317  }
318  return true;
319  }
320  return false;
321 }
322 
323 
325 {
327 }
328 
329 
331 {
333 }
334 
335 
337 {
338  return m_DockManager->Minimize(client);
339 }
340 
341 
343 {
344  return m_DockManager->Restore(client);
345 }
346 
347 
349 {
351 }
352 
353 
355 {
357 }
358 
359 
361 {
363 }
364 
365 
366 /// max number of characters in the client labels shown in popups
367 static const int kMaxClientLabel = 30;
368 
370 {
371  string label = client.GetClientLabel();
372  if((int) label.size() > kMaxClientLabel) {
373  label.resize(kMaxClientLabel);
374  label += "...";
375  }
376  return label;
377 }
378 
379 
380 // handles commands originating from IDockPanel
382 {
383  switch(cmd) {
384  case eCmdWindowMinimize:
385  m_DockManager->Minimize(*panel.GetClient());
386  return true;
387  case eCmdCloseDockPanel:
389  /// ask advisor to take necessary action
390  if (m_Advisor) {
391  TClients clients;
392  clients.push_back(panel.GetClient());
394  }
395  return true;
396  case eCmdMoveToMainTab:
397  case eCmdWindowRestore:
398  case eCmdWindowFloat: {
399  /// these commands can affect window hierarchy and result in some windows
400  /// being destroyed because of this we need to execute them
401  /// asynchronously so that we do not destroy windows on the current call
402  /// stack
403  CRef<CEvent> evt(new CWindowManagerEvent(panel.GetClient(), cmd));
405  return true;
406  }
407  case eCmdSetClientColor:
408  return OnSetClientColor(panel);
409  default:
410  //_ASSERT(false);
411  break;
412  }
413  return false;
414 }
415 
416 
418 {
419  IWMClient* client = panel.GetClient();
420  if (client) {
421  if(client->GetColor()) {
422  // the client does support a notion of color
423  CRgbaColor color = *client->GetColor();
424  wxWindow* win = dynamic_cast<wxWindow*>(&panel);
425  if (NcbiChooseColor(win, color)) {
426  client->SetColor(color);
427  win->Refresh();
428  }
429  }
430  }
431  return true;
432 }
433 
434 
436 {
439  return true;
440 }
441 
442 
444 {
445  // disconnect from command routing
446  CEventHandler* target = dynamic_cast<CEventHandler*>(&client);
447  if(target) {
448  RemoveListener(target);
449  }
450 
451  // remove from the container
452  if (!client.IsADialog())
454 }
455 
456 
458 {
459  if(x_CloseClient(client)) {
460  x_ResetMenuBar();
461  return true;
462  }
463  return false;
464 }
465 
466 
468 {
469  for( size_t i = 0; i < clients.size(); i++ ) {
470  IWMClient& client = *clients[i];
472  }
473  x_ResetMenuBar();
474 }
475 
476 
478 {
479  while( ! m_Clients.empty()) {
480  IWMClient& client = *m_Clients.back();
482  }
483  x_ResetMenuBar();
484 }
485 
486 
487 // removes from Root Container, Unregisters and sends notification
489 {
490  TClients::iterator it =
491  std::find(m_Clients.begin(), m_Clients.end(), &client);
492  _ASSERT(it != m_Clients.end());
493 
494  if(it != m_Clients.end()) {
495  m_Clients.erase(it);
497 
499  if(m_Advisor) {
501  }
502 
504 
505  if(m_Advisor) {
507  }
508  return true;
509  } else {
510  ERR_POST("CWindowManager::x_CloseClient() - client not registred, cannot close");
511  }
512  return false;
513 }
514 
515 
516 void CWindowManager::GetAllClients(vector<IWMClient*>& clients)
517 {
518  clients = m_Clients;
519 }
520 
521 
523 {
524  bool found = (std::find(m_Clients.begin(), m_Clients.end(), &client) != m_Clients.end());
525  return found;
526 }
527 
528 
530 {
531  TClients clients;
532  clients.push_back(&client);
533  ActivateClients(clients);
534 }
535 
536 
537 // traverses all containers and adjusts tab panels so that clients become
538 // visible
540 {
541  m_DockManager->ActivateClients(clients);
542 }
543 
545 {
546  m_WindowToClient[client.GetWindow()] = &client;
547 }
548 
550 {
551  m_WindowToClient.erase(client.GetWindow());
552 
553  if (&client == m_ActiveClient) {
555 
556  if (m_Advisor)
558 
559  x_ResetMenuBar();
560  }
561 }
562 
564 {
566 }
567 
569 {
571 }
572 
573 bool CWindowManager::m_IsDragging = false;
574 
576 {
577  return m_IsDragging;
578 }
579 
580 bool CWindowManager::HasToolBar(const string& name)
581 {
582  wxString wx_name = ToWxString(name);
583  wxAuiPaneInfo& pane = m_AuiManager.GetPane(wx_name);
584  return pane.IsOk();
585 }
586 
587 
588 void CWindowManager::AddToolBar(wxAuiToolBar* toolbar)
589 {
590  _ASSERT(toolbar);
591  if(toolbar) {
592  wxAuiPaneInfo pane_info;
593 
594  wxString name = toolbar->GetName();
595  pane_info.Name(name);
596  pane_info.Caption(name);
597 
598  pane_info.ToolbarPane().Top();
599  pane_info.TopDockable(true)
600  .LeftDockable(false)
601  .RightDockable(false)
602  .BottomDockable(false);
603  pane_info.Resizable(false);
604  pane_info.DestroyOnClose(true);
605 
606  m_AuiManager.AddPane(toolbar, pane_info);
607  m_AuiManager.Update();
608  }
609 }
610 
611 
612 void CWindowManager::DeleteToolBar(const string& name)
613 {
614  wxAuiPaneInfo& pane = m_AuiManager.GetPane(ToWxString(name));
615  if(pane.IsOk()) {
616  wxWindow* toolbar = pane.window;
617  m_AuiManager.DetachPane(toolbar);
618  toolbar->Destroy();
619  }
620 }
621 
622 
624 {
625  return m_ActiveClient;
626 }
627 
628 
629 void CWindowManager::OnShowWindowsDlg(wxCommandEvent& WXUNUSED(event))
630 {
631  CWindowsDlg dlg;
632 
633  string path = CGuiRegistryUtil::MakeKey(m_RegPath, "Windows Dialog");
634  dlg.SetRegistryPath(path);
635 
636  dlg.SetWindowManager(this);
637 
638  dlg.Create(this);
639  dlg.ShowModal();
640 }
641 
642 
643 // creates entry in m_ClientToRec table if it does not exist
645 {
646  bool registered = IsRegistered(client);
647  _ASSERT( ! registered);
648 
649  if( ! registered) {
650  m_Clients.push_back(&client);
652  return true;
653  }
654  return false;
655 }
656 
657 
659 {
661  Send(&evt);
662 }
663 
664 
665 // backbone of the menu contributed to the main Menu Bar
666 
667 WX_DEFINE_MENU(sBaseMenu)
668  WX_SUBMENU("&Window")
669  WX_MENU_SEPARATOR_L("Actions")
673  WX_MENU_SEPARATOR_L("Close")
675  WX_MENU_SEPARATOR_L("Actions2")
677  WX_MENU_SEPARATOR_L("Windows")
679 WX_END_MENU()
680 
681 
682 const wxMenu* CWindowManager::GetMenu()
683 {
684  /// build on demand
685  if( ! m_Menu.get()) {
686  // create static backbone
688  m_Menu.reset(cmd_reg.CreateMenu(sBaseMenu));
689 
690  _ASSERT(m_Menu.get());
691 
692  // create dynamic part
693  x_UpdateWindowsMenu(*m_Menu);
694 
695  // get menus from only active client
696  if (m_ActiveClient) {
697  const wxMenu* client_root = m_ActiveClient->GetMenu();
698  if(client_root) {
699  // merge Client's menu into Manager's menu
700  Merge(*m_Menu, *client_root);
701  }
702  }
703 /*
704  // get menus from clients
705  ITERATE(TClients, it, m_Clients) {
706  IWMClient* client = *it;
707  const wxMenu* client_root = client->GetMenu();
708  if(client_root) {
709  // merge Client's menu into Manager's menu
710  Merge(*m_Menu, *client_root);
711  }
712  }
713  */
714  }
715  return m_Menu.get();
716 }
717 
718 const static int kMaxRecentItems = 10;
719 
720 // generate a menu item label with numeric access key "&N"
721 inline string GenerateWinItemPrefix(int index)
722 {
723  if(index < 10) {
724  return string("&" + NStr::IntToString(index) + " ");
725  } else if(index == 10) {
726  return "1&0 ";
727  }
728  return " ";
729 }
730 
731 
732 void CWindowManager::x_UpdateWindowsMenu(wxMenu& root_menu)
733 {
735 
736  static wxString sWindow(wxT("&Window"));
737 
738  wxMenuItem* win_item = ncbi::FindSubItem(root_menu, sWindow);
739  wxMenu* win_menu = win_item ? win_item->GetSubMenu() : NULL;
740 
741  if(win_menu == NULL) {
742  // not found - create new one
743  win_menu = new wxMenu(sWindow);
744  root_menu.Append(wxID_ANY, win_menu->GetTitle(), win_menu);
745  } else {
746  // remove child items corresponding to windows
747  wxMenuItemList& items = win_menu->GetMenuItems();
748  for(wxMenuItemList::compatibility_iterator it = items.GetFirst();
749  it; ) {
750  wxMenuItem* sub_item = it->GetData();
751 
752  wxMenuItemList::compatibility_iterator it_next = it->GetNext();
753 
754  if(sub_item->GetKind() == wxITEM_NORMAL) {
755  TCmdID cmd = sub_item->GetId();
756  if(cmd >= eCmdWindowXXXX && cmd <= eCmdWindowLast) {
757  win_menu->Delete(sub_item);
758  }
759  }
760  it = it_next;
761  }
762  }
763 
764  // show first kMaxRecentItems clients in "Windows" menu
765  int index = 0;
766  string s;
767  ITERATE(TClients, it, m_Clients) {
768  IWMClient* client = *it;
769 
770  TCmdID cmd = eCmdWindowXXXX + index++;
773  win_menu->Append(cmd, ToWxString(s));
774 
775  if(index >= kMaxRecentItems) { // show no more then kMaxRecentItems items
776  break;
777  }
778  }
779 }
780 
781 void CWindowManager::OnFocusChanged( wxWindow* new_focus )
782 {
783  IWMClient* new_client = 0;
784  // check if focused widget is our client or a child of our client
785  for (wxWindow* w = new_focus; w != NULL && w != this; w = w->GetParent()) {
787 
788  if (!client)
789  continue;
790 
791  // this OUR client
792  new_client = client;
793  break;
794  }
795 
796  if (new_client != m_ActiveClient) {
797  if (m_ActiveClient != 0) {
798  // redraw captions for views affected by changes in focus
799  for (wxWindow* w = m_ActiveClient->GetWindow(); w != 0; w = w->GetParent()) {
800  CDockPanel* panel = dynamic_cast<CDockPanel*>(w);
801  if (panel) {
802  w->Refresh();
803  break;
804  }
805  }
806  }
807  m_ActiveClient = new_client;
808 
809  x_ResetMenuBar();
810  }
811 
812  if (m_Advisor)
814 }
815 
816 // update m_ActiveClient to keep it in-sync with focus
818 {
819  OnFocusChanged( FindFocus() );
820 }
821 
822 void CWindowManager::OnActivateWindow( wxCommandEvent& event )
823 {
824  int cmd = event.GetId();
827 }
828 
829 
830 /// handles an internal command posted to itself
832 {
833  CWindowManagerEvent* wm_evt = dynamic_cast<CWindowManagerEvent*>(evt);
834  _ASSERT(wm_evt && wm_evt->GetClient());
835 
836  TCmdID cmd = wm_evt->GetCmd();
837  IWMClient* client = wm_evt->GetClient();
838 
839  switch(cmd) {
840  case eCmdCloseDockPanel:
841  case eCmdMoveToMainTab:
842  case eCmdWindowFloat:
843  case eCmdWindowMinimize:
844  case eCmdWindowRestore:
846  break;
847 
848  default:
849  _ASSERT(false);
850  }
851 }
852 
853 
854 // handles commands arriving from the application menu bar
855 void CWindowManager::OnWindowCommand(wxCommandEvent& event)
856 {
858  if(client) {
859  x_HandlePanelCommand(*client, event.GetId());
860  }
861 }
862 
863 
864 void CWindowManager::OnUpdateWindowCommand(wxUpdateUIEvent& event)
865 {
868 }
869 
870 
872 {
873  bool en = false;
874  if(client && !client->IsADialog()) {
875  switch(event.GetId()) {
876  case eCmdCloseDockPanel:
877  en = true;
878  break;
879 
880  case eCmdMoveToMainTab:
882  break;
883 
884  case eCmdWindowFloat:
885  en = ! m_DockManager->IsFloating(*client);
886  break;
887 
888  case eCmdWindowMinimize:
889  en = ! m_DockManager->IsMinimized(*client);
890  break;
891 
892  case eCmdWindowRestore:
894  break;
895 
896  default:
897  _ASSERT(false);
898  break;
899  }
900  }
901  event.Enable(en);
902 }
903 
904 
906 {
907  switch(cmd) {
908  case eCmdCloseDockPanel:
910  /// ask advisor to take necessary action
911  if(m_Advisor) {
912  TClients clients;
913  clients.push_back(&client);
915  }
916  break;
917 
918  case eCmdMoveToMainTab:
920  break;
921 
922  case eCmdWindowFloat:
924  break;
925 
926  case eCmdWindowMinimize:
928  break;
929 
930  case eCmdWindowRestore:
932  break;
933  default:
934  _ASSERT(false);
935  break;
936  }
937 }
938 
940 {
941  CWindowManagerEvent* wm_evt = dynamic_cast<CWindowManagerEvent*>(evt);
942  _ASSERT(wm_evt);
944 
945  if(m_Advisor) {
946  TClients clients;
947  wm_evt->GetClients(clients);
949  }
950 }
951 
952 
954 {
955  CDockPanel* panel = dynamic_cast<CDockPanel*>(widget);
956  if(panel) {
957  return panel->GetClient();
958  } else {
960  return (it == m_WindowToClient.end()) ? NULL : it->second;
961  }
962 }
963 
965 {
966  static int frameId = 1;
967 
968  if(m_Advisor) {
969  return m_Advisor->GetFloatingFrameTitle(frameId++);
970  } else {
971  return kEmptyStr;
972  }
973 }
974 
976 {
977  bool found = IsRegistered( client );
978  //_ASSERT(found); This is valid for composite view such as Multi-pane alignment view
979  if( !found ) return;
980 
981  wxWindow* window = client.GetWindow();
982  if( !window ) return;
983 
984 
985  CDockPanel* panel = dynamic_cast<CDockPanel*>( window->GetParent() );
986  if( !panel ) return;
987 
988  panel->UpdateCaption();
989 
990  wxWindow* parent = panel->GetParent();
991  CDockNotebook* notebook = dynamic_cast<CDockNotebook*>( parent );
992  if( notebook ){
993  notebook->RefreshPageByWindow( panel );
994  }
995  parent->Layout();
996  parent->Refresh();
997 }
998 
999 bool CWindowManager::Dispatch( CEvent* evt, EDispatch disp_how, int pool )
1000 {
1001  if( disp_how == eDispatch_FirstHandler ){
1002  // try to deliver event to the active client
1004  CEventHandler* client_handler = dynamic_cast<CEventHandler*>(client);
1005 
1006  if(HasListener(client_handler, pool)) {
1007  return client_handler->Send(evt, disp_how, pool);
1008  }
1009  }
1010 
1011  // default pathway
1012  return CEventHandler::Dispatch(evt, disp_how, pool);
1013 }
1014 
1015 
1016 bool CWindowManager::ProcessEvent( wxEvent& event )
1017 {
1018  // Stops the same event being processed repeatedly
1019  static wxEventType inEvent = wxEVT_NULL;
1020  if( inEvent == event.GetEventType() ){
1021  return false;
1022  }
1023  inEvent = event.GetEventType();
1024 
1025  // Redirect events to active child first.
1026  bool res = false;
1027  if( event.IsCommandEvent() ){
1028  wxEventType type = event.GetEventType();
1029 
1030  if( type == wxEVT_UPDATE_UI || type == wxEVT_COMMAND_MENU_SELECTED ){
1032  if( client ){
1033 
1034  wxEvtHandler* handler = client->GetCommandHandler();
1035  _ASSERT(handler);
1036 
1037  res = handler->ProcessEvent( event );
1038  }
1039  }
1040  }
1041  if( !res ){
1042  res = TParent::ProcessEvent( event );
1043  }
1044 
1045  inEvent = wxEVT_NULL;
1046  return res;
1047 }
1048 
1049 
1050 objects::CUser_object* CWindowManager::SaveLayout()
1051 {
1052  objects::CUser_object* layout = m_DockManager->SaveLayout();
1053  return layout;
1054 }
1055 
1056 
1057 void CWindowManager::ApplyLayout( const objects::CUser_object& layout )
1058 {
1059  m_DockManager->ApplyLayout( layout );
1060 
1061  x_ResetMenuBar();
1062 }
1063 
1064 
1065 void CWindowManager::LoadLayout( const objects::CUser_object& layout, IWMClientFactory& factory )
1066 {
1067  m_DockManager->LoadLayout( layout, factory );
1068 
1069  // We have lot of fixes with window layout since GB-575
1070  // This call causes gtk warnings on Linux, hopefully we don't need it anymore
1071  // This probably fixes window layout issues. JIRA: GB-575
1072  //Fit();
1073 
1074  x_ResetMenuBar();
1075 }
1076 
1077 
1079 {
1080  m_Menu.reset(); // delete the old one
1081 
1082  if( m_MenuListener ){
1083  m_MenuListener->UpdateMenuBar(); // request Menu Bar update
1084  }
1085 }
1086 
1087 
1088 void CWindowManager::OnDockPanelStartDrag( CDockPanel* panel, const wxPoint& pt )
1089 {
1090  m_DragDockPanel = panel;
1091 
1092  // translate mouse position into local (client) coordinate system
1093  wxPoint sc_mouse_pos = m_DragDockPanel->ClientToScreen(pt);
1094  m_ClickPoint = ScreenToClient(sc_mouse_pos);
1095  m_IsDragging = true;
1096 
1097  /// capture mouse to receive all mouse events - now we handle the mouse
1098  if (!HasCapture())
1099  CaptureMouse();
1100 
1102 }
1103 
1104 
1105 void CWindowManager::OnMotion(wxMouseEvent& evt)
1106 {
1107  wxPoint pt = evt.GetPosition();
1108  //WM_POST("CWindowManager::OnMotion() " << pt.x << " " << pt.y);
1109 
1110  if(m_IsDragging) {
1111  if ( ! evt.LeftIsDown()) {
1113  } else {
1114  x_OnDrag(pt);
1115  }
1116  }
1117 }
1118 
1119 
1120 void CWindowManager::OnLeftUp(wxMouseEvent& evt)
1121 {
1122  wxPoint pt = evt.GetPosition();
1123  //WM_POST("CWindowManager::OnLeftUp() " << pt.x << " " << pt.y);
1124 
1125  if (HasCapture()) {
1126  //WM_POST("ReleaseMouse()");
1127  ReleaseMouse();
1128  }
1129 
1130  if (m_IsDragging) {
1132  }
1133 }
1134 
1135 
1136 void CWindowManager::OnMouseCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(evt))
1137 {
1138  //WM_POST("CWindowManager::OnMouseCaptureLost()");
1139  if (m_IsDragging) {
1140  wxPoint pt = ::wxGetMousePosition();
1142  }
1143 }
1144 
1145 
1146 void CWindowManager::x_OnBeginDrag(const wxPoint& mouse_pos)
1147 {
1148  //WM_POST("CWindowManager::x_OnBeginDrag()");
1149 
1150  m_IsDragging = true;
1151  wxPoint sc_mouse_pos = ClientToScreen(mouse_pos);
1152  m_DockManager->OnBeginDrag(*m_DragDockPanel, sc_mouse_pos);
1153 }
1154 
1155 
1156 void CWindowManager::x_OnDrag(const wxPoint& mouse_pos)
1157 {
1158  //WM_POST("CWindowManager::x_OnDrag()");
1159 
1160  wxPoint sc_mouse_pos = ClientToScreen(mouse_pos);
1161  bool ok = m_DockManager->OnDrag(*m_DragDockPanel, sc_mouse_pos);
1162 
1163  if( ! ok) {
1164  // dragging has been canceled
1165  //WM_POST("CWindowManager::x_OnDrag() ok = false - canceling");
1166 
1167  m_Canceled = true;
1168  ReleaseMouse();
1169  //WM_POST("ReleaseMouse()");
1170 
1171  m_IsDragging = false;
1172 
1174  }
1175 }
1176 
1177 
1179 {
1180  //LOG_POST("CWindowManager::x_OnEndDrag()");
1181  wxPoint sc_mouse_pos = ClientToScreen(mouse_pos);
1182  m_DockManager->OnEndDrag(*m_DragDockPanel, result, sc_mouse_pos);
1183  m_IsDragging = false;
1184 
1186 }
1187 
1188 
#define false
Definition: bool.h:36
virtual void SetRegistryPath(const string &path)
Definition: dialog.cpp:59
CDockContainer is a window that hosts docked windows.
CDockManager CDockManager sends requests to Window Manager, Window Manager makes decisions about dele...
objects::CUser_object * SaveLayout()
produces Memento describing the current window layout (including all clients)
void Restore(IWMClient &client)
void MoveToMainTab(IWMClient &client)
moves the given client into the Main Tab Control ("Reset")
void OnBeginDrag(IDockableWindow &dockable, const wxPoint &sc_mouse_pos)
wxFrame * MoveToFloatingFrame(IWMClient &client)
void AddToDefaultLocation(IWMClient &client, bool bFloat)
CDockContainer * GetMainContainer()
CMinPanelContainer * GetMinPanelContainer()
bool OnDrag(IDockableWindow &dockable, const wxPoint &sc_mouse_pos)
void Remove(IWMClient &client)
void LoadLayout(const objects::CUser_object &object, IWMClientFactory &factory)
creates a new window layout based on the given Memento instantiates the clients as needed using the g...
void ActivateClients(TClients &clients)
void OnEndDrag(IDockableWindow &dockable, EDragResult result, const wxPoint &sc_mouse_pos)
bool IsInMainTab(IWMClient &client) const
void Minimize(IWMClient &client)
void SetKeyboardHook(wxFrame *frame)
void RaiseFloatingInZOrder()
bool IsMinimized(IWMClient &client) const
bool IsFloating(IWMClient &client) const
void ApplyLayout(const objects::CUser_object &object)
CDockNotebook - an extended version of wxAuiNotebook capable of working with Dock Manager and Window ...
void RefreshPageByWindow(wxWindow *page)
CDockPanel - a container with a title bar (caption) hosting a single client window (IWMClient).
Definition: dock_panel.hpp:73
void UpdateCaption()
Definition: dock_panel.cpp:369
virtual void FinishDrag()
Definition: dock_panel.cpp:568
IWMClient * GetClient()
Definition: dock_panel.hpp:93
CEventHandler.
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
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
CMinPanelContainer.
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
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
CWindowManagerEvent.
IWMClient * GetClient()
vector< IWMClient * > m_Clients
void GetClients(vector< IWMClient * > &clients)
CWindowManagerEvent(EEventType type, IWMClient *client)
CWindowManagerEvent.
TCmdID GetCmd() const
CWindowManager - component controlling windowing of client windows.
void x_RemoveClient(IWMClient &client)
bool HasToolBar(const string &name)
bool CloseClient(IWMClient &client)
vector< IWMClient * > TClients
virtual bool Dispatch(CEvent *evt, EDispatch disp_how, int pool)
Dispatches an event to the listeners (but does not handle it).
void Minimize(IWMClient &client)
TClients m_Clients
the collection of registered Client
wxAuiManager m_AuiManager
wxAuiManager is required for CNotebook
IWMClient * x_GetActiveClientByWindow(wxWindow *widget)
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 OnWindowCommand(wxCommandEvent &event)
virtual void x_OnBeginDrag(const wxPoint &mouse_pos)
bool OnCloseClientsRequest(const TClients &clients)
virtual ~CWindowManager()
void RegisterActiveClient(IWMClient &client)
bool IsRegistered(IWMClient &client) const
checks if the client in registered in the Window Manager
virtual void x_OnEndDrag(const wxPoint &mouse_pos, CDockManager::EDragResult result)
bool OnCaptionPanelCommand(CDockPanel &panel, TCmdID cmd)
TCmdToWindowMap m_CmdToWindow
bool x_RegisterClient(IWMClient &client)
virtual void SetRegistryPath(const string &reg_path)
void UnRegisterActiveClient(IWMClient &client)
void x_HandlePanelCommand(IWMClient &client, int cmd)
void ActivateClient(IWMClient &client)
void OnCloseClientsRequestEvent(CEvent *evt)
void GetAllClients(TClients &clients)
void OnUpdateWindowCommand(wxUpdateUIEvent &event)
CDockManager * GetDockManager()
void OnShowWindowsDlg(wxCommandEvent &event)
virtual void x_UpdateWindowsMenu(wxMenu &root_menu)
void LoadLayout(const objects::CUser_object &layout, IWMClientFactory &factory)
bool IsInMainTab(IWMClient &client) const
void CloseClients(const TClients &clients)
unique_ptr< wxMenu > m_Menu
bool x_CloseClient(IWMClient &client)
void RaiseFloatingWindowsInZOrder()
CDockManager * m_DockManager
the Docking Manager associated with this Window Manager
void AddToolBar(wxAuiToolBar *toolbar)
virtual void x_ResetMenuBar()
wxFrame * MoveToFloatingFrame(IWMClient &client)
IWMClient * GetActiveClient()
void OnFocusChanged(wxWindow *new_focus)
static bool m_IsDragging
bool IsFloating(IWMClient &client) const
void MoveToMainTab(IWMClient &client)
virtual bool ProcessEvent(wxEvent &event)
void ActivateClients(TClients &clients)
CDockPanel * m_DragDockPanel
void OnMouseCaptureLost(wxMouseCaptureLostEvent &event)
void OnActivateWindow(wxCommandEvent &event)
IWMClient * m_ActiveClient
belonging to focused IWMClient
void OnDockPanelStartDrag(CDockPanel *panel, const wxPoint &pt)
Called by CDockPanel to delegated DnD handling to Window Manager.
objects::CUser_object * SaveLayout()
virtual bool Create(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
wxFrame * m_FrameWindow
main frame window hosting window manager
void OnLeftUp(wxMouseEvent &evt)
void ApplyLayout(const objects::CUser_object &layout)
wxFrame * GetFrameWindow()
void OnMotion(wxMouseEvent &evt)
IWindowManagerMenuListener * m_MenuListener
virtual bool AddClient(IWMClient &client, bool bFloat)
adds the client to the Main Tabbed Pane
void x_UpdateListener(IWMClient &client)
void RefreshClient(IWMClient &client)
void OnPostCommand(CEvent *evt)
handles an internal command posted to itself
virtual void x_UpdateActiveClient()
bool OnSetClientColor(CDockPanel &panel)
TWindowToClientMap m_WindowToClient
index wxWindow -> IWMClient
virtual void x_OnDrag(const wxPoint &mouse_pos)
string GetNewFloatingFrameTitle()
void Restore(IWMClient &client)
bool IsMinimized(IWMClient &client) const
string x_GetClientLabelForMenu(IWMClient &client)
IWindowManagerAdvisor * m_Advisor
Advisor is an external object that wants to customize the behavior of Window Manager by providing a c...
void OnUpdateWindowCommand_Client(wxUpdateUIEvent &event, IWMClient *client)
static bool IsDragging()
CWindowsDlg.
Definition: windows_dlg.hpp:63
void SetWindowManager(CWindowManager *manager)
bool Create(wxWindow *parent, wxWindowID id=ID_WINDOWS_DLG, const wxString &caption=_("Windows"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
Definition: windows_dlg.cpp:88
IWMClientFactory - IWMClient factory.
Definition: wm_client.hpp:133
CFingerprint identifies an instance of IWMClient and is used for labeling layout positions.
Definition: wm_client.hpp:58
void FromPersistentString(const string &s)
CFingerprint()
IWMClient::CFingerprint.
bool operator==(const CFingerprint &orig) const
string AsPersistentString() const
returns a string for serialization (if persistent) or ""
const string GetId() const
IWClient - abstract Window Manager client.
Definition: wm_client.hpp:50
virtual wxWindow * GetWindow()=0
returns a pointer to the wxWindow representing the client
IWindowManagerAdvisor.
virtual string GetFloatingFrameTitle(int index)=0
returns the title for the floating frames created by the Window Manager
virtual void OnClientClosed(IWMClient &client)=0
called after the client has been removed
virtual void OnCloseClientsRequest(const TClients &clients)=0
indicates that user requested closing the following clients (by pressing a "close" button,...
virtual void OnActiveClientChanged(IWMClient *new_active)=0
called when Active Client is changed (i.e. focus goes into another client)
virtual void OnClientAboutToClose(IWMClient &client)=0
called before removing the client
virtual void UpdateMenuBar()=0
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
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
@ eCmdWindowFloat
Definition: dock_panel.hpp:56
@ eCmdCloseDockPanel
Definition: dock_panel.hpp:54
@ eCmdMoveToMainTab
Definition: dock_panel.hpp:55
@ eCmdWindowMinimize
Definition: dock_panel.hpp:57
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
string
Definition: cgiapp.hpp:687
#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
virtual void RemoveListener(CEventHandler *listener)
Remove a listener.
void Post(CRef< CEvent > evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Handles an event asynchronously (process and/or dispatch).
virtual bool Dispatch(CEvent *evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Dispatches an event to the listeners (but does not handle it).
#define END_EVENT_MAP()
Ends definition of Command Map.
#define BEGIN_EVENT_MAP(thisClass, baseClass)
Begins definition of Command Map for CEventHandler-derived class.
EDispatch
enum controlling dispatching strategies
virtual bool HasListener(CEventHandler *listener, int pool_name=ePool_Default) const
returns "true" if the given listener belongs to the specified pool
virtual bool Send(CEvent *evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Sends an event synchronously.
int TCmdID
@ eCmdInvalid
marks menu end in array initializers
Definition: command.hpp:64
@ eDispatch_FirstHandler
dispatch to all handlers
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3457
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3197
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5083
static const char label[]
n background color
where boath are integers</td > n< td ></td > n</tr > n< tr > n< td > tse</td > n< td > optional</td > n< td > String</td > n< td class=\"description\"> TSE option controls what blob is orig
@ eCmdWindowXXXX
a range of automatically generated commands that will be used for activating windows
@ eCmdWindowLast
@ eCmdSetClientColor
@ eCmdShowWindowsDlg
END_EVENT_TABLE()
int i
static MDB_envinfo info
Definition: mdb_load.c:37
CMinPanelContainer::OnRestoreWindow EVT_UPDATE_UI_RANGE(eCmdCloseDockPanel, eCmdWindowRestore, CMinPanelContainer::OnUpdateWindowCommand) CMinPanelContainer
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
wxEVT_COMMAND_MENU_SELECTED
static static static wxID_ANY
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
static CNamedPipeClient * client
Definition: type.c:6
#define _ASSERT
else result
Definition: token2.c:20
#define WX_DEFINE_MENU(name)
New macros for defining menus for use with CUICommandRegistry.
Definition: ui_command.hpp:266
#define WX_SUBMENU(label)
Definition: ui_command.hpp:288
#define WX_END_MENU()
Definition: ui_command.hpp:294
#define WX_MENU_SEPARATOR_L(label)
Definition: ui_command.hpp:285
#define WX_MENU_ITEM(cmd)
Definition: ui_command.hpp:270
#define WX_END_SUBMENU()
Definition: ui_command.hpp:291
eCmdWindowRestore
EVT_MENU_RANGE(eCmdCloseDockPanel, eCmdWindowRestore, CWindowManager::OnWindowCommand) EVT_UPDATE_UI_RANGE(eCmdCloseDockPanel
CWindowManager.
CWindowManager::OnUpdateWindowCommand ON_EVENT(CWindowManagerEvent, CWindowManagerEvent::ePostCommand, &CWindowManager::OnPostCommand) ON_EVENT(CWindowManagerEvent
CEventHandler map.
static const int kMaxRecentItems
string GenerateWinItemPrefix(int index)
static const int kMaxClientLabel
max number of characters in the client labels shown in popups
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
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
wxMenuItem * FindSubItem(wxMenu &menu, const wxString &text)
Find a subitem of the given menu by text.
Definition: wx_utils.cpp:426
bool NcbiChooseColor(wxWindow *parent, CRgbaColor &color)
Definition: wx_utils.cpp:1114
#define const
Definition: zconf.h:230
Modified on Sat Dec 02 09:20:51 2023 by modify_doxy.py rev. 669887