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

Go to the SVN repository for this file.

1 /* $Id: macrofloweditorapp.cpp 38070 06/07/2017 15:12:46 17:48:35Z Igor Filippov$
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: Igor Filippov
27  */
28 #include <ncbi_pch.hpp>
29 
30 // For compilers that support precompilation, includes "wx/wx.h".
31 #include "wx/wxprec.h"
32 
33 #ifdef __BORLANDC__
34 #pragma hdrstop
35 #endif
36 
37 #ifndef WX_PRECOMP
38 #include "wx/wx.h"
39 #endif
40 
41 #include <wx/graphics.h>
42 #include <wx/imaglist.h>
43 #include <wx/artprov.h>
44 #include <wx/utils.h>
45 #include <wx/app.h>
46 #include <wx/evtloop.h>
47 #include <wx/notifmsg.h>
48 #include <wx/generic/notifmsg.h>
49 #include <wx/splash.h>
50 #include <wx/graphics.h>
51 #include <wx/gdicmn.h>
55 #include <sstream>
56 #include <util/line_reader.hpp>
62 
64 
65 /*
66  * CScriptPanel type definition
67  */
68 
69 IMPLEMENT_DYNAMIC_CLASS(CScriptPanel, wxPanel)
70 
71 
72 /*
73 * CScriptPanel event table definition
74 */
75 
76 BEGIN_EVENT_TABLE(CScriptPanel, wxPanel)
77 
78  EVT_CONTEXT_MENU(CScriptPanel::OnRightClick)
79 
81 
82 
83 const string CScriptPanel::sm_Multiple = "Multiple files are present";
84 /*
85  * CScriptPanel constructors
86  */
87 
89  : m_timer(this)
90 {
91  Init();
92 }
93 
94 CScriptPanel::CScriptPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
95  : m_timer(this)
96 {
97  Init();
98  Create(parent, id, pos, size, style);
99 }
100 
101 
102 /*
103  * CScriptPanel creator
104  */
105 
106 bool CScriptPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
107 {
108 ////@begin CScriptPanel creation
109  wxPanel::Create( parent, id, pos, size, style );
110 
111  CreateControls();
112  if (GetSizer())
113  {
114  GetSizer()->SetSizeHints(this);
115  }
116  Centre();
117 ////@end CScriptPanel creation
118  return true;
119 }
120 
121 
122 /*
123  * CScriptPanel destructor
124  */
125 
127 {
128  m_ScriptWindow->RemoveEventHandler(m_handler);
129  delete m_handler;
130 }
131 
132 
133 /*
134  * Member initialisation
135  */
136 
138 {
139 ////@begin CScriptPanel member initialisation
141  m_drag = false;
142  m_once_per_drag = true;
143  m_font = wxNullFont;
144  m_modified = false;
145  m_displaced = INT_MAX;
146 
147  wxArtProvider::Push( new CwxSplittingArtProvider() );
148  wxFileArtProvider* provider = new wxFileArtProvider();
149  wxArtProvider::Push(provider);
150  provider->AddDirectory( CSysPath::ResolvePath( wxT("<res>") ));
151  provider->RegisterFileAlias(wxT("menu::dm_tiles"), wxT("tiles.png"));
152  wxBitmap bitmap(wxArtProvider::GetBitmap(wxT("menu::dm_tiles"), wxART_TOOLBAR, wxSize(16,16)));
153  wxImage image(bitmap.ConvertToImage());
154  m_copy_cursor = wxCursor(image);
155  m_scroll_pos = 0;
156 ////@end CScriptPanel member initialisation
157 }
158 
159 
160 /*
161  * Control creation for CScriptPanel
162  */
163 
165 {
166 ////@begin CScriptPanel content construction
167  CScriptPanel* itemPanel1 = this;
168 
169  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
170  itemPanel1->SetSizer(itemBoxSizer2);
171 
172  m_ScriptWindow = new wxScrolledWindow( itemPanel1, ID_CSCRIPTPANEL_SCROLLEDWND, wxDefaultPosition, wxSize(400, -1), wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL );
173  itemBoxSizer2->Add(m_ScriptWindow, 1, wxGROW|wxTOP, 10);
174  m_ScriptWindow->SetScrollbars(1, 1, 0, 0);
175 
176  wxBoxSizer* sizer1 = new wxBoxSizer(wxVERTICAL);
177  m_ScriptWindow->SetSizer(sizer1);
178 
179  m_ScriptWindow->FitInside();
180  m_handler = new CMacroLabelHandler(this);
181  m_ScriptWindow->PushEventHandler(m_handler);
182 
183  wxStaticBox* itemStaticBoxSizer6Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Parameters"));
184  wxStaticBoxSizer* itemStaticBoxSizer6 = new wxStaticBoxSizer(itemStaticBoxSizer6Static, wxHORIZONTAL);
185  itemBoxSizer2->Add(itemStaticBoxSizer6, 0, wxGROW|wxALL, 0);
186 
187  m_Parameters = new CMacroParamsPanel( itemStaticBoxSizer6->GetStaticBox(), ID_CSCRIPTPANEL_SCROLLEDWND1, wxDefaultPosition, wxSize(400, -1), wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL );
188  itemStaticBoxSizer6->Add(m_Parameters, 0, wxGROW|wxALL, 5);
189 
190 ////@end CScriptPanel content construction
191 }
192 
193 
194 /*
195  * Should we show tooltips?
196  */
197 
199 {
200  return true;
201 }
202 
203 /*
204  * Get bitmap resources
205  */
206 
207 wxBitmap CScriptPanel::GetBitmapResource( const wxString& name )
208 {
209  // Bitmap retrieval
210 ////@begin CScriptPanel bitmap retrieval
211  wxUnusedVar(name);
212  return wxNullBitmap;
213 ////@end CScriptPanel bitmap retrieval
214 }
215 
216 /*
217  * Get icon resources
218  */
219 
220 wxIcon CScriptPanel::GetIconResource( const wxString& name )
221 {
222  // Icon retrieval
223 ////@begin CScriptPanel icon retrieval
224  wxUnusedVar(name);
225  return wxNullIcon;
226 ////@end CScriptPanel icon retrieval
227 }
228 
230 {
232  m_ScriptWindow->GetSizer()->Add(label, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxRESERVE_SPACE_EVEN_IF_HIDDEN, 5);
233  label->SetIndex(m_ScriptWindow->GetSizer()->GetChildren().size());
234  return label;
235 }
236 
238 {
239  Layout();
240  Refresh();
241  m_ScriptWindow->FitInside();
242 }
243 
245 {
247  wxSizer *sizer = m_ScriptWindow->GetSizer();
248  sizer->Insert(index, label, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
249  wxSizerItemList& children = sizer->GetChildren();
250  for (size_t i = index; i < children.size(); i++)
251  {
252  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
253  if (!win)
254  continue;
255  win->SetIndex(i + 1);
256  }
257  return label;
258 }
259 
261 {
262  size_t count = 0;
263  wxSizer *sizer = m_ScriptWindow->GetSizer();
264  wxSizerItemList& children = sizer->GetChildren();
265  for (size_t i = 0; i < children.size(); i++)
266  {
267  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
268  if (!win)
269  continue;
270  count++;
271  }
272  return count;
273 }
274 
276 {
277  for (auto &label : m_selected_macros)
278  {
279  label.second->Unselect();
280  }
283 }
284 
286 {
287  if (!label)
288  return;
289  size_t index = GetIndex(label);
291  return;
292  m_Parameters->SetMacro(label->GetMacro(), label);
293  m_selected_macros[index] = label;
294  label->Select();
295 }
296 
298 {
299  if (!label)
300  return;
301  size_t index = GetIndex(label);
302  if (!m_selected_macros.empty()) {
303  size_t min_selected = m_selected_macros.begin()->first;
304  size_t max_selected = m_selected_macros.rbegin()->first;
305  wxSizer *sizer = m_ScriptWindow->GetSizer();
306  wxSizerItemList& children = sizer->GetChildren();
307  for (size_t i = min(index, min_selected); i < children.size() && i < max(index, max_selected); i++) {
308  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
309  if (!win)
310  continue;
312  continue;
313  m_selected_macros[i] = win;
314  win->Select();
315  }
316  }
317 
319  return;
320  m_Parameters->SetMacro(label->GetMacro(), label);
321  m_selected_macros[index] = label;
322  label->Select();
323 }
324 
325 void CScriptPanel::SelectItem(size_t item)
326 {
327  wxSizer *sizer = m_ScriptWindow->GetSizer();
328  wxSizerItemList& children = sizer->GetChildren();
329  for (size_t i = 0; i < children.size(); i++)
330  {
331  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
332  if (!win)
333  continue;
334  if (i == item)
335  {
336  SelectMacro(win);
337 
338  wxRect rect = win->GetRect();
339  int rect_y;
340  m_ScriptWindow->CalcUnscrolledPosition(0, rect.y, NULL, &rect_y);
341  int client_w, client_h;
342  m_ScriptWindow->GetClientSize( &client_w, &client_h );
343  int hLine;
344  m_ScriptWindow->GetScrollPixelsPerUnit(NULL, &hLine);
345  int view_y;
346  m_ScriptWindow->GetViewStart(NULL, &view_y);
347  view_y *= hLine;
348  if (rect_y < view_y)
349  m_ScriptWindow->Scroll( -1, rect_y / hLine );
350  if (rect_y + rect.height + 5 > view_y + client_h)
351  m_ScriptWindow->Scroll( -1, (rect_y + rect.height - client_h + hLine) / hLine );
352  break;
353  }
354  }
355 }
356 
358 {
359 
360  m_ScriptWindow->GetViewStart(NULL, &m_scroll_pos);
361 }
362 
364 {
365  m_ScriptWindow->Scroll(-1, m_scroll_pos);
366 }
367 
369 {
370  int x, y;
371  m_ScriptWindow->GetVirtualSize(&x, &y);
372  int unit_x, unit_y;
373  m_ScriptWindow->GetScrollPixelsPerUnit(&unit_x, &unit_y);
374  m_ScriptWindow->Scroll(0, y/unit_y);
375 }
376 
378 {
379  wxSizer *sizer = m_ScriptWindow->GetSizer();
380  wxSizerItemList& children = sizer->GetChildren();
381  for (size_t i = 0; i < children.size(); i++)
382  {
383  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
384  if (win == label)
385  return i;
386  }
387  return wxNOT_FOUND;
388 }
389 
391 {
392  if (m_selected_macros.empty())
393  return;
394  DropMacro();
395 }
396 
398 {
399  if (m_selected_macros.empty())
400  return;
401  if (!m_drag) {
402  UnselectMacro();
403  return;
404  }
405 }
406 
407 vector<pair<CRef<macro::CMacroRep>, bool>> CScriptPanel::GetScript()
408 {
409  vector<pair<CRef<macro::CMacroRep>, bool>> script;
410  wxSizer *sizer = m_ScriptWindow->GetSizer();
411  wxSizerItemList& children = sizer->GetChildren();
412  script.reserve(children.size());
413  for (size_t i = 0; i < children.size(); i++) {
414  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
415  if (!win)
416  continue;
417  script.push_back(make_pair(win->GetMacro(), !win->IsSkipped()));
418  }
419  return script;
420 }
421 
423 {
424  TVecMacroRep script;
425  wxSizer* sizer = m_ScriptWindow->GetSizer();
426  wxSizerItemList& children = sizer->GetChildren();
427  script.reserve(children.size());
428  for (size_t i = 0; i < children.size(); i++) {
429  CMacroLabel* win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
430  if (!win)
431  continue;
432  script.push_back(win->GetMacro());
433  }
434  return script;
435 }
436 
438 {
439  wxSizer* sizer = m_ScriptWindow->GetSizer();
440  wxSizerItemList& children = sizer->GetChildren();
441  if (script.size() != children.size()) {
442  return false;
443  }
444  for (size_t i = 0; i < children.size(); ++i) {
445  CMacroLabel* win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
446  if (!win) {
447  continue;
448  }
449 
450  // this parses the source of the macro
451  // the label is not regenerated
452  win->UpdateMacroRep(script[i]);
453  }
454  return true;
455 }
456 
457 void CScriptPanel::UpdateCounter(size_t i, size_t counter)
458 {
459  wxSizer *sizer = m_ScriptWindow->GetSizer();
460  wxSizerItemList& children = sizer->GetChildren();
461  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
462  if (!win)
463  return;
464  win->UpdateCounter(counter);
465 }
466 
468 {
469  macro::CMacroEngine engine;
470  auto syn_files = engine.GetSynonymFilenames(GetMacros());
471 
472  if (syn_files.empty()) {
474  }
475  else if (syn_files.size() > 1) {
477  }
478  else {
479  SetSynonymFile(syn_files[0]);
480  }
481 }
482 
484 {
485  wxSizer *sizer = m_ScriptWindow->GetSizer();
486  wxSizerItemList& children = sizer->GetChildren();
487  for (size_t i = 0; i < children.size(); i++)
488  {
489  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
490  if (!win)
491  continue;
492  win->UpdateCounter(0);
493  }
494 }
495 
497 {
498  if (m_selected_macros.empty())
499  return;
500  if (!m_drag)
501  return;
502 
503  wxPoint p = m_ScriptWindow->ScreenToClient(wxGetMousePosition());
504 
505  m_ScriptWindow->SetCursor(wxNullCursor);
506  wxSetCursor(wxNullCursor);
507 
508  if (m_ScriptWindow->HasCapture())
509  m_ScriptWindow->ReleaseMouse();
510 
511  m_displaced = INT_MAX;
512  bool lock = false;
513  m_drag = false;
514  m_once_per_drag = true;
515  if (m_timer.IsRunning())
516  m_timer.Stop();
517 
518  CMacroFlowEditor* frame = dynamic_cast<CMacroFlowEditor*>(GetParent()->GetParent()->GetParent());
519  if (frame) {
520  lock = frame->GetLockDrag();
521  }
522 
523  int client_w, client_h;
524  m_ScriptWindow->GetClientSize( &client_w, &client_h );
525  wxSizer *sizer = m_ScriptWindow->GetSizer();
526  wxSizerItemList& children = sizer->GetChildren();
527  bool rearranged = false;
528  if (p.x > 0 && p.x < client_w && p.y >= 0 && p.y <= client_h && !lock) {
529  for (auto &macro : m_selected_macros) {
530  sizer->Detach(macro.second);
531  }
532  size_t index = x_GetInsertIndex(p.y, children);
533  if (index < children.size()) {
534  for (auto &macro : m_selected_macros) {
535  sizer->Insert(index, macro.second, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxRESERVE_SPACE_EVEN_IF_HIDDEN, 5);
536  index++;
537  }
538  }
539  else {
540  for (auto &macro : m_selected_macros) {
541  sizer->Add(macro.second, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxRESERVE_SPACE_EVEN_IF_HIDDEN, 5);
542  }
543  }
544  m_modified = true;
545  rearranged = true;
546  }
547 
548 
549  for (size_t i = 0; i < children.size(); i++) {
550  wxWindow* wxwin = children[i]->GetWindow();
551  wxwin->SetPosition(wxDefaultPosition);
552  CMacroLabel *win = dynamic_cast<CMacroLabel*>(wxwin);
553  if (!win)
554  continue;
555  win->SetIndex(i + 1);
556  }
557 
558  Layout();
559  Refresh();
560  m_ScriptWindow->FitInside();
561 
562  for (auto &macro : m_selected_macros) {
563  macro.second->ShowWithEffect(wxSHOW_EFFECT_EXPAND);
564  }
565 
566  UnselectMacro();
567  if (!rearranged) {
568  frame->Shake();
569  if (lock)
570  x_ShowSplashWindow(frame);
571  }
572 }
573 
575 {
576  wxBitmap bitmap(frame->GetLockBitmap());
577  wxImage image(280, 80, true);
578  wxColour bg(GetBackgroundColour());
579  image.SetRGB(wxRect(0, 0, 280, 80), bg.Red(), bg.Green(), bg.Blue());
580  image.Paste(bitmap.ConvertToImage(), 5, 40 - bitmap.GetHeight() / 2);
581  wxBitmap composite(image);
582  wxSplashScreen *splash = new wxSplashScreen(composite, wxSPLASH_CENTRE_ON_PARENT | wxSPLASH_TIMEOUT, 2000, frame, wxID_ANY);
583  wxWindow *win = splash->GetSplashWindow();
584  wxStaticText *text = new wxStaticText( win, wxID_STATIC, wxT("Click the lock icon to enable dragging"), wxPoint(10 + bitmap.GetWidth(), 40 - bitmap.GetHeight() / 2 + 3));
585  wxGraphicsContext *gc = wxGraphicsContext::Create();
586  gc->SetFont(text->GetFont(), *wxBLACK);
587  wxDouble width;
588  wxDouble height;
589  wxDouble descent;
590  wxDouble externalLeading;
591  gc->GetTextExtent(text->GetLabel(), &width, &height, &descent, &externalLeading);
592  splash->SetSize(ceil(width) + 20 + bitmap.GetWidth(), 80);
593  delete gc;
594 }
595 
596 size_t CScriptPanel::x_GetInsertIndex(int y, wxSizerItemList& children)
597 {
598  set<CMacroLabel*> selected;
599  for (auto &macro : m_selected_macros) {
600  selected.insert(macro.second);
601  }
602 
603  size_t index = children.size();
604  int miny = INT_MAX;
605  for (size_t i = 0; i < children.size(); i++) {
606  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
607  if (!win)
608  continue;
609  if (selected.find(win) != selected.end())
610  continue;
611  wxPoint pos = win->GetPosition();
612  if (pos.y > y && pos.y < miny) {
613  index = i;
614  miny = pos.y;
615  }
616  }
617  return index;
618 }
619 
621 {
622  if (m_selected_macros.empty())
623  return;
625  wxSizer *sizer = m_ScriptWindow->GetSizer();
626  for (auto &macro : m_selected_macros)
627  {
628  sizer->Detach(macro.second);
629  macro.second->Unselect();
630  macro.second->Destroy();
631  }
633  wxSizerItemList& children = sizer->GetChildren();
634  for (size_t i = 0; i < children.size(); i++)
635  {
636  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
637  if (!win)
638  continue;
639  win->SetIndex(i + 1);
640  }
641  Layout();
642  Refresh();
643  m_ScriptWindow->FitInside();
644  m_drag = false;
645  m_once_per_drag = true;
646  if (m_timer.IsRunning())
647  m_timer.Stop();
648 }
649 
650 
652 {
653  if (m_selected_macros.empty())
654  return;
655 
656  m_CurrentMousePos = wxGetMousePosition();
657  if (m_once_per_drag) {
658  wxPoint d = m_CurrentMousePos - m_Position;
659  if (abs(d.x) < 10 && abs(d.y) < 10)
660  return;
661  }
662 
663  int client_h;
664  m_ScriptWindow->GetClientSize( NULL, &client_h );
665  int hLine;
666  m_ScriptWindow->GetScrollPixelsPerUnit(NULL, &hLine);
667 
668  wxPoint p = m_ScriptWindow->ScreenToClient(m_CurrentMousePos);
669  int view_y;
670  m_ScriptWindow->GetViewStart(NULL, &view_y);
671  view_y *= hLine;
672  bool moved = false;
673  const int d = 20;
674  if ( p.y < 5 ) {
675  view_y -= d;
676  if (view_y < 0)
677  view_y = 0;
678  m_ScriptWindow->Scroll(-1, view_y/hLine);
679  moved = true;
680  }
681  else if ( p.y > client_h - 5) {
682  view_y += d;
683  m_ScriptWindow->Scroll(-1, view_y/hLine);
684  moved = true;
685  }
686 
687  if (moved) {
688  if (!m_timer.IsRunning())
689  m_timer.Start(10);
690  }
691  else {
692  if (m_timer.IsRunning())
693  m_timer.Stop();
694  }
695 
696  m_drag = true;
698 
700 }
701 
703 {
704 
705  wxSizer *sizer = m_ScriptWindow->GetSizer();
706  wxSizerItemList& children = sizer->GetChildren();
707  size_t index = x_GetInsertIndex(m_ScriptWindow->ScreenToClient(m_CurrentMousePos).y, children);
708  vector<int> displacement(children.size(), 0);
709  if (m_once_per_drag) {
710  m_once_per_drag = false;
711  int height = 0;
712  if (!m_ScriptWindow->HasCapture())
713  m_ScriptWindow->CaptureMouse();
714 
715  m_ScriptWindow->SetCursor(m_copy_cursor);
716  wxSetCursor(m_copy_cursor);
717 
718  for (auto &macro : m_selected_macros) {
719  macro.second->HideWithEffect(wxSHOW_EFFECT_EXPAND);
720  }
721 
722  for (size_t i = 0; i < children.size(); i++) {
723  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
724  if (!win)
725  continue;
726  if (!win->IsShown()) {
727  height += win->GetSize().GetHeight() + 10;
728  continue;
729  }
730 
731  if (height > 0) {
732  displacement[i] = -height;
733  }
734  }
735  }
736 
737  for (size_t i = index; i < children.size() && i < m_displaced; i++)
738  {
739  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
740  if (!win || !win->IsShown())
741  continue;
742  displacement[i] += 50;
743  }
744  for (size_t i = m_displaced; i < children.size() && i < index; i++)
745  {
746  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
747  if (!win || !win->IsShown())
748  continue;
749  displacement[i] -= 50;
750  }
751 
752  for (size_t i = 0; i < children.size(); i++) {
753  int height = displacement[i];
754  if (height == 0)
755  continue;
756  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
757  if (!win)
758  continue;
759  if (!win->IsShown())
760  {
761  continue;
762  }
763 
764  wxPoint displace(0, height);
765  wxPoint current = win->GetPosition();
766  win->SetPosition(current + displace);
767  }
768 
769 #ifdef __WXMSW__
770  for (size_t i = min(index,m_displaced); i < children.size() && i < max(index, m_displaced); i++) {
771  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
772  if (!win || !win->IsShown())
773  continue;
774  win->Refresh();
775  win->Update();
776  }
777 #endif
778  m_displaced = index;
779 }
780 
782 {
783  if (label) {
784  label->ToggleSkip();
785  }
786 }
787 
789 {
790  for (auto &macro : m_selected_macros) {
791  ToggleSkip(macro.second);
792  }
793 }
794 
796 {
797  wxBusyCursor wait;
798  wxYield();
799  m_ScriptWindow->Freeze();
800  wxSizer *sizer = m_ScriptWindow->GetSizer();
801  wxSizerItemList& children = sizer->GetChildren();
802  for (size_t i = 0; i < children.size(); i++)
803  {
804  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
805  if (!win)
806  continue;
807  win->IncreaseFont();
808  if (i == 0)
809  m_font = win->GetFont();
810  }
811  m_ScriptWindow->FitInside();
812  m_ScriptWindow->Thaw();
813 }
814 
816 {
817  wxBusyCursor wait;
818  wxYield();
819  m_ScriptWindow->Freeze();
820  wxSizer *sizer = m_ScriptWindow->GetSizer();
821  wxSizerItemList& children = sizer->GetChildren();
822  for (size_t i = 0; i < children.size(); i++)
823  {
824  CMacroLabel *win = dynamic_cast<CMacroLabel*>(children[i]->GetWindow());
825  if (!win)
826  continue;
827  win->DecreaseFont();
828  if (i == 0)
829  m_font = win->GetFont();
830  }
831  m_ScriptWindow->FitInside();
832  m_ScriptWindow->Thaw();
833 }
834 
836 {
838 }
839 
841 {
843 }
844 
845 void CScriptPanel::OnRightClick(wxContextMenuEvent &evt)
846  {
847  if (m_drag)
848  return;
849  wxMenu itemMenu8;
850  itemMenu8.Append(ID_MACROFLOW_CUT, _("Cut\tCtrl+X"), wxEmptyString, wxITEM_NORMAL);
851  itemMenu8.Append(ID_MACROFLOW_COPY, _("Copy\tCtrl+C"), wxEmptyString, wxITEM_NORMAL);
852  itemMenu8.Append(ID_MACROFLOW_PASTE, _("Paste\tCtrl+V"), wxEmptyString, wxITEM_NORMAL);
853  itemMenu8.Append(ID_MACROFLOW_DELETE, _("Delete\tDel"), wxEmptyString, wxITEM_NORMAL);
854  itemMenu8.Append(ID_MACROFLOW_DUPLICATE, _("Duplicate\tCtrl+D"), wxEmptyString, wxITEM_NORMAL);
855  itemMenu8.Append(ID_MACROFLOW_APPEND, _("Add To Library\tAlt+A"), wxEmptyString, wxITEM_NORMAL);
856  itemMenu8.Append(ID_MACROFLOW_ADD, _("Add New Macro"), wxEmptyString, wxITEM_NORMAL);
857  itemMenu8.Append(ID_SKIP_STEP, _("Enable/Disable Step\tF3"), wxEmptyString, wxITEM_NORMAL);
858  itemMenu8.Append(ID_MANUALEDITMACRO, _("Edit Macro Script"), wxEmptyString, wxITEM_NORMAL);
859  itemMenu8.Append(ID_MACROFLOW_ZOOM_IN, _("Increase Font\tAlt+I"), wxEmptyString, wxITEM_NORMAL);
860  itemMenu8.Append(ID_MACROFLOW_ZOOM_OUT, _("Decrease Font\tAlt+D"), wxEmptyString, wxITEM_NORMAL);
861  PopupMenu(&itemMenu8);
862  }
863 
864 BEGIN_EVENT_TABLE( CMacroLabelHandler, wxEvtHandler )
865  EVT_LEFT_UP(CMacroLabelHandler::OnMouseUp)
866  EVT_LEFT_DOWN(CMacroLabelHandler::OnMouseDown)
870 
871 
872 void CMacroLabelHandler::OnMouseUp(wxMouseEvent& event)
873 {
874  if (m_win)
875  {
876  m_win->OnMouseUp();
877  }
878  else if (m_panel)
879  {
880  m_panel->OnMouseUp();
881  }
882  event.Skip();
883 }
884 
885 
886 void CMacroLabelHandler::OnMouseDown(wxMouseEvent& event)
887 {
888  if (m_win) {
889  if ( event.GetModifiers() != wxMOD_SHIFT) {
890  if ( !m_win->IsSelected()) {
891  if (event.GetModifiers() != wxMOD_CONTROL) {
892  CScriptPanel *panel = dynamic_cast<CScriptPanel*>(m_win->GetGrandParent());
893  if (panel)
894  panel->UnselectMacro();
895  }
896  m_win->OnMouseDown();
897  }
898  }
899  else {
901  }
902  }
903  else if (m_panel) {
904  m_panel->OnMouseDown();
905  }
906 
907  event.Skip();
908 }
909 
910 
911 void CMacroLabelHandler::OnMouseDrag(wxMouseEvent& event)
912 {
913  if (event.Dragging()) {
914  if (m_win)
915  m_win->OnMouseDrag();
916  else if (m_panel)
917  m_panel->DragMacro();
918  }
919  event.Skip();
920 }
921 
922 
923 void CMacroLabelHandler::OnMouseDoubleClick(wxMouseEvent& event)
924 {
925  if (m_win) { // CMacroLabel
926  CScriptPanel *panel = dynamic_cast<CScriptPanel*>(m_win->GetGrandParent());
927  if (panel) {
928  panel->SaveScrollPos();
929  CMacroFlowEditor* frame = dynamic_cast<CMacroFlowEditor*>(panel->GetParent()->GetParent()->GetParent());
930  if (frame) {
932  frame->OpenEditor(macro);
933  panel->LoadScrollPos();
934  }
935  }
936  }
937  event.Skip();
938 }
939 
941 {
942  CScriptPanel *panel = dynamic_cast<CScriptPanel*>(m_win->GetGrandParent());
943  NMacroStats::ReportUsage(wxT("ScriptPanel"), "view macro step");
945  CMacroSimple dlg(NULL, macro->GetSource());
946  if (dlg.ShowModal() != wxID_OK)
947  {
948  panel->LoadScrollPos();
949  return;
950  }
951  m_win->UpdateMacro(dlg.GetMacro());
952  panel->LoadScrollPos();
953 }
954 
956 
957 BEGIN_EVENT_TABLE( CMacroLabel, TMacroLabelParent )
959 
960 #define LABEL_WIDTH 500
961 #define MAX_TITLE_LENGTH 200
963 {
964  Init();
965 }
966 
967 CMacroLabel::CMacroLabel( wxWindow* parent, CRef<macro::CMacroRep> macro, const wxFont& font, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
968  : m_font(font)
969 {
970  if (macro) {
971  m_macro.Reset(m_MEngine.Parse(macro->GetSource()));
972  }
973 
974  Init();
975  Create( parent, id, pos, size, style );
976  x_RoundedShape();
977 }
978 
979 bool CMacroLabel::Create( wxWindow* parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
980 {
981  TMacroLabelParent::Create( parent, id, pos, size, style );
982 
983  CreateControls();
984  if (GetSizer())
985  {
986  GetSizer()->SetSizeHints(this);
987  }
988  Centre();
989  return true;
990 }
991 
993 {
994  wxGraphicsPath path = wxGraphicsRenderer::GetDefaultRenderer()->CreatePath();
995  wxSize sz = GetSize();
996  path.AddRoundedRectangle(0, 0, sz.GetWidth(), sz.GetHeight(), 15);
997  SetShape(path);
998  Refresh();
999 }
1000 /*
1001 bool CMacroLabel::Layout()
1002 {
1003  bool r = TMacroLabelParent::Layout();
1004 
1005  if (m_bitmap)
1006  {
1007  int x = (m_panel->GetSize().GetWidth() - m_static_bitmap.GetWidth()) / 2;
1008  int y = (m_panel->GetSize().GetHeight() - m_static_bitmap.GetHeight()) / 2;
1009  m_bitmap->SetPosition(wxPoint(x,y));
1010  m_bitmap->Show(m_skipped);
1011  m_bitmap->Refresh();
1012  }
1013  return r;
1014 }
1015 */
1017 {
1018  m_panel->RemoveEventHandler(m_handler1);
1019  m_index->RemoveEventHandler(m_handler2);
1020  m_text->RemoveEventHandler(m_handler3);
1021  m_bitmap->RemoveEventHandler(m_handler4);
1022  m_counter->RemoveEventHandler(m_handler5);
1023 
1024  delete m_handler1;
1025  delete m_handler2;
1026  delete m_handler3;
1027  delete m_handler4;
1028  delete m_handler5;
1029 }
1030 
1032 {
1033  m_static_bitmap = wxArtProvider::GetBitmap(wxT("menu::delete")); // wxART_CLOSE, wxART_OTHER
1034  m_skipped = false;
1035  m_bitmap = NULL;
1036  m_text = NULL;
1037  m_selected = false;
1038 }
1039 
1040 wxColour CMacroLabel::GetLabelColour(const string &str)
1041 {
1042  unsigned long hash = wxStringHash::stringHash(str.c_str());
1043  wxColour old = *wxGREEN; //notebook->GetBackgroundColour();
1044  wxImage::HSVValue hsv = wxImage::RGBtoHSV(wxImage::RGBValue(old.Red(), old.Green(), old.Blue()));
1045  hsv.hue = double(hash % 360) / 360;
1046  hsv.saturation = 0.2;
1047  wxImage::RGBValue rgb = wxImage::HSVtoRGB(hsv);
1048  wxColour upd(rgb.red, rgb.green, rgb.blue);
1049  return upd;
1050 }
1051 
1053 {
1054  CMacroLabel* itemFrame1 = this;
1055  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
1056  itemFrame1->SetSizer(itemBoxSizer2);
1057 
1058  m_panel = new wxPanel( itemFrame1, wxID_ANY, wxDefaultPosition, wxSize(LABEL_WIDTH, -1));
1059  itemBoxSizer2->Add(m_panel, 1, wxGROW|wxALL, 0);
1060 
1061  wxColour upd = GetLabelColour(m_macro->GetForEachString());
1062  m_panel->SetBackgroundColour(upd);
1063 
1064  m_handler1 = new CMacroLabelHandler(this);
1065  m_panel->PushEventHandler(m_handler1);
1066 
1067 
1068  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
1069  m_panel->SetSizer(itemBoxSizer4);
1070 
1071  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
1072  itemBoxSizer4->Add(itemBoxSizer5, 0, wxGROW, 0);
1073 
1074  m_bitmap = new wxGenericStaticBitmap(m_panel, wxID_ANY, m_static_bitmap);
1075  //m_bitmap->SetScaleMode(wxStaticBitmap::Scale_AspectFit);
1076  itemBoxSizer5->Add(m_bitmap, 0, wxALIGN_LEFT|wxRESERVE_SPACE_EVEN_IF_HIDDEN|wxALL, 0);
1077  m_handler4 = new CMacroLabelHandler(this);
1078  m_bitmap->PushEventHandler(m_handler4);
1079  m_bitmap->Hide();
1080 
1081  itemBoxSizer5->AddStretchSpacer();
1082 
1083  m_index = new wxStaticText( m_panel, wxID_STATIC, _(" "), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );
1084  itemBoxSizer5->Add(m_index, 0, wxALIGN_LEFT|wxLEFT, 5);
1085  m_handler2 = new CMacroLabelHandler(this);
1086  m_index->PushEventHandler(m_handler2);
1087 
1088  wxString title = x_ConstructTitle();
1089  m_text = new wxStaticText( m_panel, wxID_STATIC, title, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL );
1090  itemBoxSizer4->Add(m_text, 1, wxGROW|wxALL, 5);
1091  m_text->SetFont(m_font);
1092  m_handler3 = new CMacroLabelHandler(this);
1093  m_text->PushEventHandler(m_handler3);
1094 
1095  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxVERTICAL);
1096  itemBoxSizer4->Add(itemBoxSizer6, 0, wxGROW, 0);
1097 
1098  itemBoxSizer6->AddStretchSpacer();
1099 
1100  m_counter = new wxStaticText( m_panel, wxID_STATIC, _(" "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );
1101  itemBoxSizer6->Add(m_counter, 0, wxALIGN_RIGHT|wxRIGHT, 5);
1102  m_handler5 = new CMacroLabelHandler(this);
1103  m_counter->PushEventHandler(m_handler5);
1104 
1105  m_text->Wrap(x_GetTextWidth());
1106 }
1107 
1109 {
1110  wxString title = wxString(m_macro->GetTitle());
1111  if (title.Len() > MAX_TITLE_LENGTH)
1112  {
1113  title = title.Left(MAX_TITLE_LENGTH - 3) + "...";
1114  }
1115  return title;
1116 }
1117 
1119 {
1120  return LABEL_WIDTH - max(m_static_bitmap.GetWidth(), m_index->GetSize().GetWidth()) - m_counter->GetSize().GetWidth() - 10;
1121 }
1122 
1123 void CMacroLabel::SetIndex(size_t index)
1124 {
1125  wxString label;
1126  label << index;
1127  m_index_val = index;
1128  m_index->SetLabel(label);
1129 }
1130 
1131 void CMacroLabel::UpdateCounter(size_t counter)
1132 {
1133  wxString label;
1134  if (counter > 0)
1135  label << counter;
1136  m_counter->SetLabel(label);
1137 }
1138 
1140 {
1141  return true;
1142 }
1143 
1144 wxBitmap CMacroLabel::GetBitmapResource( const wxString& name )
1145 {
1146  // Bitmap retrieval
1147  wxUnusedVar(name);
1148  return wxNullBitmap;
1149 }
1150 
1151 wxIcon CMacroLabel::GetIconResource( const wxString& name )
1152 {
1153  // Icon retrieval
1154  wxUnusedVar(name);
1155  return wxNullIcon;
1156 }
1157 
1159 {
1160  m_skipped = !m_skipped;
1161 
1162  wxColour old = m_panel->GetBackgroundColour();
1163  wxImage::HSVValue hsv = wxImage::RGBtoHSV(wxImage::RGBValue(old.Red(), old.Green(), old.Blue()));
1164 
1165  if (m_skipped)
1166  hsv.saturation = 0.1;
1167  else
1168  hsv.saturation = 0.2;
1169 
1170  wxImage::RGBValue rgb = wxImage::HSVtoRGB(hsv);
1171  wxColour upd(rgb.red, rgb.green, rgb.blue);
1172  m_panel->SetBackgroundColour(upd);
1173  m_panel->Refresh();
1174  m_bitmap->Show(m_skipped);
1175 }
1176 
1178 {
1179  wxColour old = m_panel->GetBackgroundColour();
1180  wxImage::HSVValue hsv = wxImage::RGBtoHSV(wxImage::RGBValue(old.Red(), old.Green(), old.Blue()));
1181 
1182  hsv.value = 0.7;
1183 
1184  wxImage::RGBValue rgb = wxImage::HSVtoRGB(hsv);
1185  wxColour upd(rgb.red, rgb.green, rgb.blue);
1186  m_panel->SetBackgroundColour(upd);
1187  m_panel->Refresh();
1188  m_selected = true;
1189 }
1190 
1192 {
1193  wxColour old = m_panel->GetBackgroundColour();
1194  wxImage::HSVValue hsv = wxImage::RGBtoHSV(wxImage::RGBValue(old.Red(), old.Green(), old.Blue()));
1195 
1196  hsv.value = 1.0;
1197 
1198  wxImage::RGBValue rgb = wxImage::HSVtoRGB(hsv);
1199  wxColour upd(rgb.red, rgb.green, rgb.blue);
1200  m_panel->SetBackgroundColour(upd);
1201  m_panel->Refresh();
1202  m_selected = false;
1203 }
1204 
1206 {
1207  CScriptPanel *panel = dynamic_cast<CScriptPanel*>(GetGrandParent());
1208  if (!panel)
1209  return;
1210  panel->DragMacro();
1211 }
1212 
1214 {
1215  CScriptPanel *panel = dynamic_cast<CScriptPanel*>(GetGrandParent());
1216  if (!panel)
1217  return;
1218  wxPoint p = panel->GetCurrentMousePosition();
1219  wxPoint d = p - panel->GetMousePosition();
1220  wxPoint current = GetPosition();
1221  SetPosition(current + d);
1222 }
1223 
1225 {
1226  CScriptPanel *panel = dynamic_cast<CScriptPanel*>(GetGrandParent());
1227  if (!panel)
1228  return;
1229 
1230  panel->DropMacro();
1231 }
1232 
1234 {
1235  CScriptPanel *panel = dynamic_cast<CScriptPanel*>(GetGrandParent());
1236  if (!panel)
1237  return;
1238  if (!m_selected) {
1239  panel->SelectMacro(this);
1240  }
1241  else {
1242  CommitChanges();
1243  }
1244  panel->SetMousePosition(wxGetMousePosition());
1245 }
1246 
1248 {
1249  CScriptPanel *panel = dynamic_cast<CScriptPanel*>(GetGrandParent());
1250  if (!panel)
1251  return;
1252  panel->SelectMacros(this);
1253  panel->SetMousePosition(wxGetMousePosition());
1254 }
1255 
1257 {
1258  CScriptPanel *panel = dynamic_cast<CScriptPanel*>(GetGrandParent());
1259  if (!panel)
1260  return;
1261  panel->CommitChanges();
1262 }
1263 
1265 {
1266  wxSize text_sz = m_text->GetSize();
1267  wxSize panel_sz = GetSize();
1268  wxFont font = m_text->GetFont();
1269  font.MakeLarger();
1270  m_text->SetFont(font);
1271  wxString title = x_ConstructTitle();
1272  m_text->SetLabel(title);
1273  m_text->Wrap(x_GetTextWidth());
1274 
1275  wxSize new_text_sz = m_text->GetSize();
1276  int new_height = panel_sz.GetHeight() + new_text_sz.GetHeight() - text_sz.GetHeight() + m_text->GetCharHeight();
1277  SetMinSize(wxSize(panel_sz.GetWidth(), new_height));
1278  SetSize(wxSize(panel_sz.GetWidth(), new_height));
1279  x_RoundedShape();
1280 }
1281 
1283 {
1284  wxSize text_sz = m_text->GetSize();
1285  wxSize panel_sz = GetSize();
1286  wxFont font = m_text->GetFont();
1287  font.MakeSmaller();
1288  m_text->SetFont(font);
1289  wxString title = x_ConstructTitle();
1290  m_text->SetLabel(title);
1291  m_text->Wrap(x_GetTextWidth());
1292 
1293  wxSize new_text_sz = m_text->GetSize();
1294  int new_height = panel_sz.GetHeight() + new_text_sz.GetHeight() - text_sz.GetHeight() + m_text->GetCharHeight();
1295  SetMinSize(wxSize(panel_sz.GetWidth(), new_height));
1296  SetSize(wxSize(panel_sz.GetWidth(), new_height));
1297  x_RoundedShape();
1298 }
1299 
1301 {
1302  return m_text->GetFont();
1303 }
1304 
1306 {
1307  wxSize text_sz = m_text->GetSize();
1308  wxSize panel_sz = GetSize();
1309  wxString title = x_ConstructTitle();
1310  m_text->SetLabel(title);
1311  m_text->Wrap(x_GetTextWidth());
1312  wxSize new_text_sz = m_text->GetSize();
1313  int new_height = panel_sz.GetHeight() + new_text_sz.GetHeight() - text_sz.GetHeight() + m_text->GetCharHeight();
1314  SetMinSize(wxSize(panel_sz.GetWidth(), new_height));
1315  SetSize(wxSize(panel_sz.GetWidth(), new_height));
1316  x_RoundedShape();
1317  GetParent()->FitInside();
1318  CScriptPanel *panel = dynamic_cast<CScriptPanel*>(GetGrandParent());
1319  if (panel)
1320  panel->SetModified(true);
1321 }
1322 
1324 {
1325  if (macro) {
1326  m_macro.Reset(m_MEngine.Parse(macro->GetSource()));
1327  }
1328 }
1329 
1331 {
1332  if (!macro)
1333  return;
1334  m_macro.Reset(m_MEngine.Parse(macro->GetSource()));
1335  UpdateText();
1336  if (m_selected) {
1337  CScriptPanel *panel = dynamic_cast<CScriptPanel*>(GetGrandParent());
1338  if (panel)
1339  panel->UpdateParamsPanel();
1340  }
1341 }
1342 
1343 IMPLEMENT_DYNAMIC_CLASS( CMacroParamsPanel, wxPanel )
1344 
1345 BEGIN_EVENT_TABLE( CMacroParamsPanel, wxPanel )
1347 
1349 {
1350  Init();
1351 }
1352 
1353 CMacroParamsPanel::CMacroParamsPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
1354 {
1355  Init();
1356  Create(parent, id, pos, size, style);
1357 }
1358 
1359 bool CMacroParamsPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
1360 {
1361  wxPanel::Create( parent, id, pos, size, style );
1362 
1363  CreateControls();
1364  if (GetSizer())
1365  {
1366  GetSizer()->SetSizeHints(this);
1367  }
1368  Centre();
1369 
1370  return true;
1371 }
1372 
1374 {
1375 }
1376 
1378 {
1379  m_label = nullptr;
1380  m_PropGridCtrl = nullptr;
1381 }
1382 
1384 {
1385  wxBoxSizer* bs_vertical = new wxBoxSizer(wxVERTICAL);
1386  SetSizer(bs_vertical);
1387 
1388  m_PropGridCtrl = new wxPropertyGrid ( this, wxID_ANY, wxDefaultPosition, wxSize(380, -1), wxPG_SPLITTER_AUTO_CENTER | wxPG_DEFAULT_STYLE );
1389  bs_vertical->Add(m_PropGridCtrl, 1, wxEXPAND | wxALL, 5);
1390  m_PropGridCtrl->Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( CMacroParamsPanel::OnPropertyChanged ), NULL, this );
1391 }
1392 
1394 {
1395  return true;
1396 }
1397 
1398 wxBitmap CMacroParamsPanel::GetBitmapResource( const wxString& name )
1399 {
1400  wxUnusedVar(name);
1401  return wxNullBitmap;
1402 }
1403 
1404 wxIcon CMacroParamsPanel::GetIconResource( const wxString& name )
1405 {
1406  wxUnusedVar(name);
1407  return wxNullIcon;
1408 }
1409 
1411 {
1412  if (!m_label)
1413  return;
1415 }
1416 
1418 {
1419  m_PropGridCtrl->CommitChangesFromEditor();
1420 }
1421 
1423 {
1424  CommitChanges();
1425  m_macro = macro;
1426  m_label = label;
1427  m_PropGridCtrl->Clear();
1428  m_props.clear();
1429  if (!m_macro)
1430  {
1431  Refresh();
1432  return;
1433  }
1434  int blk; // var block number in macro
1435  macro::IMacroVar* var = m_macro->GetFirstVar(blk);
1436  wxPGProperty* property;
1437  while (var)
1438  {
1439  property = NULL;
1440  if (var->IsGUIResolvable())
1441  {
1442  string value = var->GetGUIResolvedValue();
1443  macro::CMacroVarAsk* pAsk = dynamic_cast<macro::CMacroVarAsk*>(var);
1444  if (pAsk)
1445  {
1446  property = new wxStringProperty ( pAsk->GetName(), wxPG_LABEL, value );
1447  }
1448  else
1449  {
1450  macro::CMacroVarChoice* pChoice = dynamic_cast<macro::CMacroVarChoice*>(var);
1451  if (pChoice)
1452  {
1453  int sel = 0;
1454  int i = 0;
1455  wxArrayString tchoices;
1456  const string* stored_value = pChoice->GetFirstChoice();
1457  while (stored_value)
1458  {
1459  tchoices.Add(wxString(*stored_value));
1460  if (*stored_value == value)
1461  sel = i;
1462  i++;
1463  stored_value = pChoice->GetNextChoice();
1464  }
1465  property = new wxEnumProperty ( wxString(pChoice->GetName()), wxPG_LABEL, tchoices, wxArrayInt(), sel );
1466  }
1467  }
1468  if (property)
1469  {
1470  m_PropGridCtrl->Append(property);
1471  m_props.push_back(make_pair(var, property));
1472  }
1473  }
1474  var = m_macro->GetNextVar(blk);
1475  }
1476  Refresh();
1477 }
1478 
1479 void CMacroParamsPanel::OnPropertyChanged( wxPropertyGridEvent& event )
1480 {
1481  if (!m_macro || !m_label)
1482  return;
1483  map<string, string> old_to_new;
1484  map<string, string> var_to_new;
1485  map<string, string> var_to_old;
1486  for (auto &p : m_props) {
1487  macro::IMacroVar* var = p.first;
1488  wxPGProperty* property = p.second;
1489  if (var && property) {
1490  string old = var->GetGUIResolvedValue();
1491  string value = property->GetValueAsString().ToStdString();
1492  var->SetGUIResolvedValue(value);
1493  old_to_new[old] = value;
1494  var_to_new[var->GetName()] = value;
1495  var_to_old[var->GetName()] = old;
1496  }
1497  }
1498  string title = m_macro->GetTitle();
1499  string old_title = title;
1500  for (auto p : old_to_new) {
1501  NStr::ReplaceInPlace(title, "'" + p.first + "'", "'" + p.second + "'");
1502  }
1503  if (title != old_title) {
1504  m_macro->SetTitle(title);
1505  }
1506 
1507  string new_source;
1508  string source = m_macro->GetSource();
1509  bool header = true;
1510  bool is_var = false;
1511  CNcbiIstrstream istr(source);
1512  CStreamLineReader line_reader(istr);
1513  do {
1514  string str = *++line_reader;
1516  if (header) {
1517  NStr::ReplaceInPlace(str, old_title, title);
1518  header = false;
1519  new_source += str + "\n";
1520  continue;
1521  }
1522 
1523  if (str.empty())
1524  continue;
1525  if (str == "VAR") {
1526  is_var = true;
1527  new_source += str + "\n";
1528  continue;
1529  }
1530  if (NStr::StartsWith(str, "FOR EACH", NStr::eNocase)) {
1531  is_var = false;
1532  new_source += str + "\n";
1533  continue;
1534  }
1535  if (!is_var) {
1536  new_source += str + "\n";
1537  continue;
1538  }
1539  list<string> row_values;
1540  NStr::Split(str, "=", row_values, NStr::fSplit_MergeDelimiters);
1541  if (row_values.size() == 2) {
1542  string var = row_values.front();
1543  string value = row_values.back();
1546  if (var.empty())
1547  continue;
1548  if (var_to_new.find(var) != var_to_new.end())
1549  NStr::ReplaceInPlace(value, "%" + var_to_old[var] + "%", "%" + var_to_new[var] + "%");
1550  str = var + " = " + value;
1551  }
1552  new_source += str + "\n";
1553  } while (!line_reader.AtEOF());
1554 
1555  if (source != new_source) {
1556  m_macro->SetSource(new_source);
1557  m_label->UpdateText();
1558  }
1559 }
1560 
1562 
1563 
wxBitmap GetLockBitmap()
void OpenEditor(CRef< macro::CMacroRep > macro_rep)
void OnMouseDoubleClick(wxMouseEvent &event)
void OnMouseDown(wxMouseEvent &event)
void OnMouseUp(wxMouseEvent &event)
CScriptPanel * m_panel
CMacroLabel * m_win
void OnMouseDrag(wxMouseEvent &event)
void OnMouseAndShiftDown()
wxStaticText * m_counter
wxGenericStaticBitmap * m_bitmap
void UpdateCounter(size_t counter)
CMacroLabel()
Constructors.
void OnMouseDrag()
void UpdateMacroRep(CRef< macro::CMacroRep > macro)
void OnMouseUp()
CMacroLabelHandler * m_handler5
void SetIndex(size_t index)
void DragMacro()
size_t m_index_val
CMacroLabelHandler * m_handler2
CMacroLabelHandler * m_handler1
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxPanel * m_panel
bool IsSkipped()
void Init()
Initialises member variables.
~CMacroLabel()
Destructor.
void x_RoundedShape()
void IncreaseFont()
CRef< macro::CMacroRep > m_macro
void UpdateText()
static wxColour GetLabelColour(const string &str)
macro::CMacroEngine m_MEngine
wxString x_ConstructTitle() const
void ToggleSkip()
bool IsSelected()
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void CommitChanges()
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxFRAME_SHAPED|wxBORDER_NONE)
void CreateControls()
Creates the controls and sizers.
wxStaticText * m_index
CRef< macro::CMacroRep > GetMacro()
wxStaticText * m_text
int x_GetTextWidth() const
static bool ShowToolTips()
Should we show tooltips?
CMacroLabelHandler * m_handler4
void UpdateMacro(CRef< macro::CMacroRep > macro)
CMacroLabelHandler * m_handler3
wxBitmap m_static_bitmap
void DecreaseFont()
void OnMouseDown()
wxFont GetFont()
CRef< macro::CMacroRep > m_macro
void CreateControls()
Creates the controls and sizers.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void Init()
Initialises member variables.
CMacroParamsPanel()
Constructors.
~CMacroParamsPanel()
Destructor.
wxPropertyGrid * m_PropGridCtrl
void OnPropertyChanged(wxPropertyGridEvent &event)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
vector< pair< macro::IMacroVar *, wxPGProperty * > > m_props
CMacroLabel * m_label
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
Creation.
void SetMacro(CRef< macro::CMacroRep > macro, CMacroLabel *label=NULL)
static bool ShowToolTips()
Should we show tooltips?
CRef< macro::CMacroRep > GetMacro()
void Init()
Initialises member variables.
void DragMacro()
void ScrollToBottom()
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
size_t x_GetInsertIndex(int y, wxSizerItemList &children)
void UnselectMacro()
wxPoint m_CurrentMousePos
void DecreaseFont()
CMacroParamsPanel * m_Parameters
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool Create(wxWindow *parent, wxWindowID id=10001, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void SetMousePosition(wxPoint p)
void OnMouseDown()
bool m_once_per_drag
void DropMacro()
void ResetCounters()
void x_ShowSplashWindow(CMacroFlowEditor *frame)
void DeleteSelected()
CScriptPanel()
Constructors.
Definition: scriptpanel.cpp:88
void CommitChanges()
void CreateControls()
Creates the controls and sizers.
void SetSynonymFile(const string &filename)
void OnMouseUp()
void UpdateParamsPanel()
wxScrolledWindow * m_ScriptWindow
TVecMacroRep GetMacros()
vector< CRef< macro::CMacroRep > > TVecMacroRep
Definition: scriptpanel.hpp:79
size_t GetIndex(CMacroLabel *label)
size_t m_displaced
void ToggleSkip()
void SetModified(bool modified)
void SelectMacro(CMacroLabel *label)
void SaveScrollPos()
void SelectItem(size_t item)
wxPoint GetMousePosition()
CMacroLabel * AddMacro(CRef< macro::CMacroRep > macro)
map< size_t, CMacroLabel * > m_selected_macros
void SelectMacros(CMacroLabel *label)
static const string sm_Multiple
Definition: scriptpanel.hpp:81
void x_ShiftBottomLabels()
void IncreaseFont()
vector< pair< CRef< macro::CMacroRep >, bool > > GetScript()
bool UpdateMacroSources(const TVecMacroRep &script)
void UpdateCounter(size_t i, size_t counter)
static bool ShowToolTips()
Should we show tooltips?
void LoadScrollPos()
wxPoint m_Position
CMacroLabelHandler * m_handler
wxCursor m_copy_cursor
wxPoint GetCurrentMousePosition()
void LookupSynonymFiles()
void OnRightClick(wxContextMenuEvent &evt)
~CScriptPanel()
Destructor.
CMacroLabel * InsertMacro(CRef< macro::CMacroRep > macro, size_t index)
size_t GetCount()
CDragTimer m_timer
Simple implementation of ILineReader for i(o)streams.
static wxString ResolvePath(const wxString &path, const wxString &rel_name)
Utility function to hide the platform specifics of locating our standard directories and files.
Definition: sys_path.cpp:106
CwxSplittingArtProvider - an adapter for old-style image aliases.
Definition: wx_utils.hpp:255
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
bool empty() const
Definition: map.hpp:149
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
int AddDirectory(wxString aDirName)
#define _(proto)
Definition: ct_nlmzip_i.h:78
IMPLEMENT_CLASS(CFloatingFrame, CFloatingFrameBaseClass) const static long kFloatFrameStyle
CFloatingFrame.
static void Init(void)
Definition: cursor6.c:76
static const char * str(char *buf, int n)
Definition: stats.c:84
#define NULL
Definition: ncbistd.hpp:225
bool AtEOF(void) const
Indicates (negatively) whether there is any more input.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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:3461
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3201
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3405
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
Definition: ncbistr.hpp:2498
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
static const char label[]
END_EVENT_TABLE()
int i
Lightweight interface for getting lines of data with minimal memory copying.
#define ID_MACROFLOW_CUT
#define ID_MACROFLOW_ZOOM_OUT
#define ID_MACROFLOW_APPEND
#define ID_MACROFLOW_ADD
#define ID_MACROFLOW_DELETE
#define ID_MACROFLOW_COPY
#define ID_SKIP_STEP
#define ID_MACROFLOW_PASTE
#define ID_MACROFLOW_ZOOM_IN
#define ID_MANUALEDITMACRO
#define ID_MACROFLOW_DUPLICATE
static void text(MDB_val *v)
Definition: mdb_dump.c:62
#define wxT(x)
Definition: muParser.cpp:41
void ReportUsage(const wxString &dialog_name, const string &action_name)
Report events in the macro_flow_editor and in the macro_editor.
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const CharType(& source)[N]
Definition: pointer.h:1149
#define abs(a)
Definition: ncbi_heapmgr.c:130
T max(T x_, T y_)
T min(T x_, T y_)
#define LABEL_WIDTH
#define MAX_TITLE_LENGTH
wxNonOwnedWindow TMacroLabelParent
#define ID_CSCRIPTPANEL_SCROLLEDWND1
Definition: scriptpanel.hpp:56
#define ID_CSCRIPTPANEL_SCROLLEDWND
Definition: scriptpanel.hpp:55
static static static wxID_ANY
Definition: _hash_fun.h:40
#define const
Definition: zconf.h:232
Modified on Mon Apr 22 04:02:02 2024 by modify_doxy.py rev. 669887