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

Go to the SVN repository for this file.

1 /* $Id: windows_dlg.cpp 27376 2013-02-04 19:22:26Z 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: Andrey Yazhuk
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 ////@begin includes
33 ////@end includes
34 
39 
40 
41 #include <wx/button.h>
42 
43 
45 
46 IMPLEMENT_DYNAMIC_CLASS( CWindowsDlg, CDialog )
47 
48 BEGIN_EVENT_TABLE( CWindowsDlg, CDialog )
49 
50 ////@begin CWindowsDlg event table entries
51  EVT_LIST_ITEM_SELECTED( ID_TABLE, CWindowsDlg::OnTableSelected )
52  EVT_LIST_ITEM_DESELECTED( ID_TABLE, CWindowsDlg::OnTableDeselected )
53 
54  EVT_BUTTON( ID_ACTIVATE, CWindowsDlg::OnActivateClick )
55 
56  EVT_BUTTON( ID_FLOAT, CWindowsDlg::OnFloatClick )
57 
58  EVT_BUTTON( ID_RECOVER, CWindowsDlg::OnRecoverClick )
59 
60  EVT_BUTTON( ID_MINIMIZE, CWindowsDlg::OnMinimizeClick )
61 
62  EVT_BUTTON( ID_RESTORE, CWindowsDlg::OnRestoreClick )
63 
64  EVT_BUTTON( wxID_CLOSE, CWindowsDlg::OnCloseClick )
65 
66 ////@end CWindowsDlg event table entries
67 
69 
70 
72 {
73  Init();
74 }
75 
76 
77 CWindowsDlg::CWindowsDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
78 {
79  Init();
80  Create(parent, id, caption, pos, size, style);
81 }
82 
83 
84 /*!
85  * CWindowsDlg creator
86  */
87 
88 bool CWindowsDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
89 {
90 ////@begin CWindowsDlg creation
91  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
92  CDialog::Create( parent, id, caption, pos, size, style );
93 
95  if (GetSizer())
96  {
97  GetSizer()->SetSizeHints(this);
98  }
99  Centre();
100 ////@end CWindowsDlg creation
101  return true;
102 }
103 
104 
106 {
107 ////@begin CWindowsDlg destruction
108 ////@end CWindowsDlg destruction
109 
110  m_Table->RemoveModel();
111 }
112 
113 
115 {
116 ////@begin CWindowsDlg member initialisation
117  m_Table = NULL;
118  m_FloatBtn = NULL;
119  m_RecoverBtn = NULL;
121  m_RestoreBtn = NULL;
122  m_CloseBtn = NULL;
123 ////@end CWindowsDlg member initialisation
124 
126 }
127 
128 
130 {
131 ////@begin CWindowsDlg content construction
132  CWindowsDlg* itemCDialog1 = this;
133 
134  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
135  itemCDialog1->SetSizer(itemBoxSizer2);
136 
137  m_Table = new CwxTableListCtrl( itemCDialog1, ID_TABLE, wxDefaultPosition, itemCDialog1->ConvertDialogToPixels(wxSize(180, 100)), wxLC_REPORT|wxLC_VIRTUAL );
138  itemBoxSizer2->Add(m_Table, 1, wxGROW|wxALL, 5);
139 
140  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
141  itemBoxSizer2->Add(itemBoxSizer4, 0, wxGROW|wxALL, 5);
142 
143  wxButton* itemButton5 = new wxButton( itemCDialog1, ID_ACTIVATE, _("&Activate"), wxDefaultPosition, wxDefaultSize, 0 );
144  itemButton5->SetHelpText(_("Make window visible and focused"));
146  itemButton5->SetToolTip(_("Make window visible and focused"));
147  itemBoxSizer4->Add(itemButton5, 0, wxGROW|wxALL, 5);
148 
149  m_FloatBtn = new wxButton( itemCDialog1, ID_FLOAT, _("&Float"), wxDefaultPosition, wxDefaultSize, 0 );
150  m_FloatBtn->SetHelpText(_("Move to a floating window"));
152  m_FloatBtn->SetToolTip(_("Move to a floating window"));
153  itemBoxSizer4->Add(m_FloatBtn, 0, wxGROW|wxALL, 5);
154 
155  m_RecoverBtn = new wxButton( itemCDialog1, ID_RECOVER, _("&Reset"), wxDefaultPosition, wxDefaultSize, 0 );
156  m_RecoverBtn->SetHelpText(_("Move window into the central tabbed pane"));
158  m_RecoverBtn->SetToolTip(_("Move window into the central tabbed pane"));
159  itemBoxSizer4->Add(m_RecoverBtn, 0, wxGROW|wxALL, 5);
160 
161  m_MinimizeBtn = new wxButton( itemCDialog1, ID_MINIMIZE, _("&Minimize"), wxDefaultPosition, wxDefaultSize, 0 );
162  m_MinimizeBtn->SetHelpText(_("Move window into the central tabbed pane"));
164  m_MinimizeBtn->SetToolTip(_("Move window into the central tabbed pane"));
165  itemBoxSizer4->Add(m_MinimizeBtn, 0, wxGROW|wxALL, 5);
166 
167  m_RestoreBtn = new wxButton( itemCDialog1, ID_RESTORE, _("&Restore"), wxDefaultPosition, wxDefaultSize, 0 );
168  m_RestoreBtn->SetHelpText(_("Move window into the central tabbed pane"));
170  m_RestoreBtn->SetToolTip(_("Move window into the central tabbed pane"));
171  itemBoxSizer4->Add(m_RestoreBtn, 0, wxGROW|wxALL, 5);
172 
173  m_CloseBtn = new wxButton( itemCDialog1, wxID_CLOSE, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
174  itemBoxSizer4->Add(m_CloseBtn, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
175 
176  itemBoxSizer4->Add(7, 32, 1, wxGROW|wxALL, 5);
177 
178  wxButton* itemButton12 = new wxButton( itemCDialog1, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
179  itemBoxSizer4->Add(itemButton12, 0, wxGROW|wxALL, 5);
180 
181 ////@end CWindowsDlg content construction
182 
183  {{
184  vector<IWMClient*> clients;
185  m_WindowManager->GetAllClients( clients );
186  x_UpdateTable(clients);
187  }}
188 
189  m_Table->SetModel( &m_Model );
190  wxRect rc = m_Table->GetRect();
191  m_Table->SetColumnWidth(0, rc.width - 4);
192 
193  /// select active window
195  vector<IWMClient*> clients(1, client);
196  x_SelectClients(clients);
197 
198  x_UpdateButtons();
199 
200  m_Table->SetFocus();
201 }
202 
203 
205 {
206  return true;
207 }
208 
209 
210 wxBitmap CWindowsDlg::GetBitmapResource( const wxString& name )
211 {
212  // Bitmap retrieval
213 ////@begin CWindowsDlg bitmap retrieval
214  wxUnusedVar(name);
215  return wxNullBitmap;
216 ////@end CWindowsDlg bitmap retrieval
217 }
218 
219 
220 wxIcon CWindowsDlg::GetIconResource( const wxString& name )
221 {
222  // Icon retrieval
223 ////@begin CWindowsDlg icon retrieval
224  wxUnusedVar(name);
225  return wxNullIcon;
226 ////@end CWindowsDlg icon retrieval
227 }
228 
229 
231 {
232  m_WindowManager = manager;
233 }
234 
235 
236 void CWindowsDlg::x_UpdateTable(const vector<IWMClient*>& clients)
237 {
238  vector<wxString> names;
239  names.push_back( wxT("Window Title") );
240 
242 
243  size_t n_rows = clients.size();
244  m_Model.Init( names, (int)n_rows );
245 
246  for( size_t i = 0; i < n_rows; i++ ) {
247  IWMClient* cl = clients[i];
248 
249  m_Model.SetIcon( (int)i, wxString::FromUTF8( cl->GetIconAlias().c_str() ) );
250  wxString value = wxString::FromUTF8( cl->GetClientLabel().c_str() );
251  m_Model.SetStringValueAt( (int)i, 0, value );
252  m_Model.SetAttachment( (int)i, cl );
253  }
254 }
255 
256 
257 void CWindowsDlg::OnActivateClick( wxCommandEvent& event )
258 {
259  vector<IWMClient*> clients;
260  x_GetSelectedClients(clients);
262 
263  Raise();
264 }
265 
266 
267 void CWindowsDlg::OnFloatClick( wxCommandEvent& event )
268 {
269  vector<IWMClient*> clients;
270  x_GetSelectedClients(clients);
271 
272  for( size_t i = 0; i < clients.size(); i++ ) {
273  IWMClient* client = clients[i];
274  if( ! m_WindowManager->IsFloating(*client)) {
276  }
277  }
278 
279  x_UpdateButtons();
280  Raise();
281 }
282 
283 
284 void CWindowsDlg::OnRecoverClick( wxCommandEvent& event )
285 {
286  vector<IWMClient*> clients;
287  x_GetSelectedClients(clients);
288 
289  for( size_t i = 0; i < clients.size(); i++ ) {
290  IWMClient* client = clients[i];
293  }
294  }
295 
296  x_UpdateButtons();
297 }
298 
299 
300 void CWindowsDlg::OnMinimizeClick( wxCommandEvent& event )
301 {
302  vector<IWMClient*> clients;
303  x_GetSelectedClients(clients);
304 
305  for( size_t i = 0; i < clients.size(); i++ ) {
306  IWMClient* client = clients[i];
309  }
310  }
311 
312  x_UpdateButtons();
313 }
314 
315 
316 void CWindowsDlg::OnRestoreClick( wxCommandEvent& event )
317 {
318  vector<IWMClient*> clients;
319  x_GetSelectedClients( clients );
320 
321  for( size_t i = 0; i < clients.size(); i++ ){
322  IWMClient* client = clients[i];
325  }
326  }
327 
328  x_UpdateButtons();
329 }
330 
331 
332 void CWindowsDlg::OnCloseClick( wxCommandEvent& event )
333 {
334  vector<IWMClient*> selected;
335  x_GetSelectedClients(selected);
336 
337  vector<IWMClient*> clients;
338  m_WindowManager->GetAllClients( clients );
339 
340  for( size_t i = 0; i < selected.size(); i++ ) {
341  vector<IWMClient*>::iterator it = find(clients.begin(), clients.end(), selected[i]);
342  if (it != clients.end()) {
343  clients.erase(it);
344  }
345  }
346  x_UpdateTable(clients);
348 
350 
351  // update the list of windows
352  /*
353  during setting selections idle processing is activated
354  so TableDeselectedEvent is processed
355 
356  m_Table->ClearSelection();
357  */
358 
359  x_UpdateButtons();
360 }
361 
362 
363 void CWindowsDlg::x_GetSelectedClients(vector<IWMClient*>& clients)
364 {
365  vector<int> rows;
367 
368  for( size_t i = 0; i < rows.size(); i++ ) {
369  int row = rows[i];
370  void* att = m_Model.GetAttachment( row );
371  IWMClient* cl = reinterpret_cast<IWMClient*>(att);
372  clients.push_back(cl);
373  }
374 }
375 
376 
377 void CWindowsDlg::x_SelectClients(vector<IWMClient*>& clients)
378 {
379  vector<int> rows;
380 
381  int count = m_Table->GetNumRowsVisible();
382 
383  for( int i = 0; i < count; i++ ) {
384  void* att = m_Model.GetAttachment(i);
385  IWMClient* cl = reinterpret_cast<IWMClient*>(att);
386 
387  vector<IWMClient*>::const_iterator it =
388  std::find(clients.begin(), clients.end(), cl);
389  if(it != clients.end()) {
390  rows.push_back(i);
391  }
392  }
393 
395 }
396 
397 
399 {
400  bool en_minimize = false;
401  bool en_restore = false;
402  bool en_recover = false;
403  bool en_float = false;
404 
405  vector<IWMClient*> clients;
406  x_GetSelectedClients(clients);
407 
408  for( size_t i = 0; i < clients.size(); i++ ) {
409  IWMClient* client = clients[i];
411  en_restore = true;
412  } else {
413  en_minimize = true;
414  }
416  en_recover = true;
417  }
418  if( ! m_WindowManager->IsFloating(*client)) {
419  en_float = true;
420  }
421  }
422 
423  m_RecoverBtn->Enable(en_recover);
424  m_FloatBtn->Enable(en_float);
425  m_RestoreBtn->Enable(en_restore);
426  m_MinimizeBtn->Enable(en_minimize);
427 }
428 
429 
430 void CWindowsDlg::OnTableSelected( wxListEvent& event )
431 {
432  x_UpdateButtons();
433 }
434 
435 
436 void CWindowsDlg::OnTableDeselected( wxListEvent& event )
437 {
438  x_UpdateButtons();
439 }
440 
441 
443 
444 
445 
CDialog.
Definition: dialog.hpp:47
virtual void * GetAttachment(int row)
virtual void Init(int n_cols, int n_rows)
virtual void FireDataChanged()
virtual void SetAttachment(int row, void *attachment)
virtual void SetIcon(int row, const wxString &icon_alias)
virtual void SetStringValueAt(int row, int col, const wxString &value)
CWindowManager - component controlling windowing of client windows.
void Minimize(IWMClient &client)
bool OnCloseClientsRequest(const TClients &clients)
void GetAllClients(TClients &clients)
bool IsInMainTab(IWMClient &client) const
wxFrame * MoveToFloatingFrame(IWMClient &client)
IWMClient * GetActiveClient()
bool IsFloating(IWMClient &client) const
void MoveToMainTab(IWMClient &client)
void ActivateClients(TClients &clients)
void Restore(IWMClient &client)
bool IsMinimized(IWMClient &client) const
CWindowsDlg.
Definition: windows_dlg.hpp:63
wxButton * m_FloatBtn
CwxTableListCtrl * m_Table
wxButton * m_RecoverBtn
~CWindowsDlg()
Destructor.
void OnActivateClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ACTIVATE
void OnTableSelected(wxListEvent &event)
wxEVT_COMMAND_LIST_ITEM_SELECTED event handler for ID_TABLE
void OnRecoverClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RECOVER
CWindowsDlg()
Constructors.
Definition: windows_dlg.cpp:71
void SetWindowManager(CWindowManager *manager)
CTextTableModel m_Model
void x_UpdateButtons()
wxButton * m_MinimizeBtn
void x_UpdateTable(const vector< IWMClient * > &clients)
wxButton * m_CloseBtn
wxButton * m_RestoreBtn
void OnRestoreClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RESTORE
CWindowManager * m_WindowManager
static bool ShowToolTips()
Should we show tooltips?
void x_SelectClients(vector< IWMClient * > &clients)
void OnFloatClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FLOAT
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void OnCloseClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CLOSE
void x_GetSelectedClients(vector< IWMClient * > &clients)
void CreateControls()
Creates the controls and sizers.
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
void Init()
Initialises member variables.
void OnMinimizeClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_MINIMIZE
void OnTableDeselected(wxListEvent &event)
wxEVT_COMMAND_LIST_ITEM_DESELECTED event handler for ID_TABLE
CwxTableListCtrl - generic wxListCtrl-based Table Control.
wxArrayInt GetDataRowsSelected() const
void SetModel(IwxTableModel *data_model, bool own=false)
void SetDataRowsSelected(const vector< int > &rows)
int GetNumRowsVisible() const
IWClient - abstract Window Manager client.
Definition: wm_client.hpp:50
virtual string GetClientLabel(IWMClient::ELabel ltype=IWMClient::eDefault) const =0
returns the client label (name) to be displayed in UI
virtual string GetIconAlias() const =0
returns an icon alias that can be used to retrieve the client's icon
char value[7]
Definition: config.c:431
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define ID_TABLE
static const struct name_t names[]
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
END_EVENT_TABLE()
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
static CNamedPipeClient * client
#define _ASSERT
Modified on Sun Mar 03 03:11:59 2024 by modify_doxy.py rev. 669887