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

Go to the SVN repository for this file.

1 /* $Id: text_item_panel.cpp 47464 2023-04-20 00:19:10Z evgeniev $
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: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <gui/utils/view_event.hpp>
36 
41 
50 
53 
55 
56 
57 #include <gui/utils/menu_item.hpp>
58 
59 #include <wx/sizer.h>
60 #include <wx/menu.h>
61 #include <wx/dcclient.h>
62 #include <wx/dcbuffer.h>
63 #include <wx/settings.h>
64 #include <wx/caret.h>
65 
66 #include <wx/sstream.h>
67 #include <wx/txtstrm.h>
68 #include <wx/clipbrd.h>
69 #include <wx/dataobj.h>
70 
72 
74 {
75  if (m_Panel) {
76  m_Panel->PopEventHandler();
77  }
78 }
79 
81 {
82  m_WSize = dc.GetTextExtent(wxT("W"));
83 }
84 
86 {
87  if (m_Panel) {
88  m_Panel->PopEventHandler();
89  }
90 
91  m_Panel = panel;
92 
93  if (m_Panel) {
94  m_Panel->PushEventHandler(this);
95  }
96 }
97 
98 void CTextPanelContext::SetFontDesc(wxWindow& wnd)
99 {
100  wxFont font = wnd.GetFont();
101  m_FontDesc = font.GetNativeFontInfoDesc();
102 }
103 
104 void CTextPanelContext::SelectItem(ITextItem* item, bool controlDown, bool WXUNUSED(shiftDown))
105 {
106  if (!item) {
108  m_Panel->Refresh();
110  return;
111  }
112 
114  if (!controlDown) {
116  }
117 
119  if (it != m_SelectedItems.end()) {
120  if (obj) {
121  set<ITextItem*> newSelection;
122  for (it = m_SelectedItems.begin(); it != m_SelectedItems.end();++it) {
123  if ((*it)->GetAssosiatedObject() != obj)
124  newSelection.insert(newSelection.end(), *it);
125  }
126  m_SelectedItems = newSelection;
127  } else {
129  }
130  }
131  else {
132  if (obj) {
133  std::pair <CTextItemPanel::TObjectToItem::iterator, CTextItemPanel::TObjectToItem::iterator> ret =
135  for (CTextItemPanel::TObjectToItem::iterator it2=ret.first; it2!=ret.second; ++it2) {
136  m_SelectedItems.insert(it2->second);
137  }
138  } else {
139  m_SelectedItems.insert(item);
140  }
141  }
142 
143  m_Panel->Refresh();
145 }
146 
147 void CTextPanelContext::EditItem(ITextItem* WXUNUSED(item), bool WXUNUSED(controlDown), bool WXUNUSED(shiftDown))
148 {
149 }
150 
152 {
153  return (m_SelectedItems.find(item) != m_SelectedItems.end());
154 }
155 
157 {
158  set<const CObject*> objSet;
160  CConstRef<CObject> object = (*it)->GetAssosiatedObject();
161  if (object && objSet.find(object.GetPointer()) == objSet.end()) {
162  objSet.insert(object.GetPointer());
163  objs.push_back(CConstRef<CObject>(object));
164  }
165  }
166 }
167 
169 {
170  set<const CObject*> objSet;
172  CConstRef<CObject> object = (*it)->GetAssosiatedObject();
173  if (object && objSet.find(object.GetPointer()) == objSet.end()) {
174  objSet.insert(object.GetPointer());
175  SConstScopedObject scopes_object;
176  scopes_object.object = object;
177  objects::CScope* scope = (*it)->GetAssosiatedScope();
178  if (scope == 0)
179  scope = m_Scope.GetPointerOrNull();
180  scopes_object.scope.Reset(scope);
181  objects.push_back(scopes_object);
182  }
183  }
184 }
185 
187 {
191 }
192 
193 void CTextPanelContext::GetActiveObjects(vector<TConstScopedObjects>& objects)
194 {
195  TConstScopedObjects objs;
196 
197  GetSelectedObjects(objs);
198  if (!objs.empty()) {
199  if (objects.size() < 1)
200  objects.resize(1);
201  objects[0].insert(objects[0].end(), objs.begin(), objs.end());
202  }
203  objs.clear();
204 
205  GetVisibleObjects(objs);
206  if (!objs.empty()) {
207  if (objects.size() < 2)
208  objects.resize(2);
209  objects[1].insert(objects[1].end(), objs.begin(), objs.end());
210  }
211  objs.clear();
212 
213  GetMainObjects(objs);
214  if (!objs.empty()) {
215  if (objects.size() < 3)
216  objects.resize(3);
217  objects[2].insert(objects[2].end(), objs.begin(), objs.end());
218  }
219  objs.clear();
220 }
221 
223 {
224  if (m_SO) {
225  SConstScopedObject scoped_object;
226  scoped_object.object = m_SO;
227  scoped_object.scope = m_Scope;
228  objects.push_back(scoped_object);
229  }
230 }
231 
233 {
234  m_Hier.clear();
235  m_MouseOverItem = 0;
236 }
237 
239 {
240  m_Hier.push_back(item);
241 }
242 
244 {
245  m_MouseOverItem = item;
246 }
247 
249 {
250  if (m_Panel)
252 }
253 
255 {
257 
258  set<const CObject*> objSet;
259  ITERATE (vector< CConstRef<CObject> >, it, objs)
260  objSet.insert(it->GetPointer());
261 
262  if (objSet.empty())
263  return;
264 
266 
267  ITERATE(set<const CObject*>, it, objSet) {
268  std::pair <CTextItemPanel::TObjectToItem::iterator, CTextItemPanel::TObjectToItem::iterator> ret =
269  objToItem.equal_range(*it);
270  for (CTextItemPanel::TObjectToItem::iterator it2=ret.first; it2!=ret.second; ++it2) {
271  m_SelectedItems.insert(it2->second);
272  }
273 
274  }
275 
276  if (m_Panel->GetTrackSelection() && m_SelectedItems.size() > 0) {
278  }
279  m_Panel->Refresh();
280 }
281 
282 BEGIN_EVENT_TABLE( CTextItemPanel, wxScrolledWindow )
283  EVT_MOUSE_EVENTS( CTextItemPanel::OnMouseEvent )
284  EVT_MOUSE_CAPTURE_LOST(CTextItemPanel::OnCaptureLost)
285  EVT_SET_FOCUS(CTextItemPanel::OnSetFocus)
286  EVT_KILL_FOCUS(CTextItemPanel::OnKillFocus)
287  EVT_TIMER(-1, CTextItemPanel::OnTimer)
288  EVT_CONTEXT_MENU( CTextItemPanel::OnContextMenu )
289  EVT_MENU( wxID_COPY, CTextItemPanel::OnCopy )
291  EVT_MENU( wxID_SELECTALL, CTextItemPanel::OnSelectAll )
293 
294 CTextItemPanel::CTextItemPanel(wxWindow* parent, wxWindowID id,
295  const wxPoint& pos, const wxSize& size, long style)
296  : m_Selecting(false), m_Timer(this), m_TooltipWindow(0), m_MousePos(-1,-1),
297  m_TrackSelection(false), m_Host()
298 {
299  Create(parent, id, pos, size, style);
300  Init();
301 }
302 
304 {
305  if (m_Context.get())
306  m_Context->SetPanel(0);
307 }
308 
310 {
311  SetBackgroundStyle(wxBG_STYLE_PAINT);
312 
313  wxClientDC dc(this);
314  InitDC(dc);
315  SetScrollRate(dc.GetCharWidth(),dc.GetCharHeight());
316 
317 #ifndef __WXOSX_COCOA__
318  wxCaret *caret = new wxCaret(this, 1, dc.GetCharHeight());
319  SetCaret(caret);
320 #endif
321 }
322 
324 {
325  return !m_TextSelection.IsEmpty();
326 }
327 
328 void CTextItemPanel::SelStart(int row, int col, bool shift)
329 {
330  CTextPosition pos(row, col);
331 
332  if (shift)
334  else
335  m_TextSelection = CTextBlock(pos, pos);
336 
337  m_Selecting = true;
338  CaptureMouse();
340 }
341 
342 void CTextItemPanel::SelMove(int row, int col)
343 {
346 }
347 
348 void CTextItemPanel::SelEnd(int row, int col)
349 {
351  m_Selecting = false;
352  if (HasCapture())
353  ReleaseMouse();
355 }
356 
358 {
359  m_TextSelection = selection;
361 }
362 
364 {
366 }
367 
369 {
370  Refresh();
371 
372  if (FindFocus() != this) return;
373 
375 }
376 
378 {
379  if (m_RootItem.get())
380  SetVirtualSize(m_RootItem->GetSize());
381  else
382  SetVirtualSize(wxSize(0,0));
383  return true;
384 }
385 
386 bool CTextItemPanel::SetFont(const wxFont& font)
387 {
388  bool retVal = wxScrolledWindow::SetFont(font);
389 
390  wxClientDC dc(this);
391  InitDC(dc);
392 
393  SetScrollRate(dc.GetCharWidth(),dc.GetCharHeight());
394 
395  wxCaret* caret = GetCaret();
396  if (caret)
397  caret->SetSize(1, dc.GetCharHeight());
398 
399  return retVal;
400 }
401 
402 namespace {
403  class CObjectToItemTraverser : public ICompositeTraverser
404  {
405  public:
406  CObjectToItemTraverser(multimap<const CObject*, ITextItem*>& map) : m_Map(map) {}
407 
408  virtual bool ProcessItem(CTextItem& textItem)
409  {
410  CConstRef<CObject> obj = textItem.GetAssosiatedObject();
411  if (obj)
412  m_Map.insert(multimap<const CObject*, ITextItem*>::value_type(obj.GetPointer(), &textItem));
413  return true;
414  }
415  virtual bool ProcessItem(CExpandItem& expandItem)
416  {
417  CConstRef<CObject> obj = expandItem.GetAssosiatedObject();
418  if (obj)
419  m_Map.insert(multimap<const CObject*, ITextItem*>::value_type(obj.GetPointer(), &expandItem));
420  return true;
421  }
422 
424  };
425 }
426 
427 void CTextItemPanel::SetMainItem(shared_ptr<ITextItem> item, shared_ptr<CTextPanelContext> context)
428 {
430 
431  m_Context = context;
432  if (m_Context.get()) {
433  m_Context->SetPanel(this);
434  }
435 
437 
438  m_RootItem = item;
439 
440  if (m_RootItem.get()) {
441  CObjectToItemTraverser traverser(m_ObjectToItem);
442  m_RootItem->Traverse(traverser);
443 
444  if (m_Context.get())
445  m_Context->RootInitialized();
446  }
447 
448  Layout();
449  Scroll(0, 0);
450  Refresh();
451 }
452 
454 {
456 
457  m_Context.reset(context);
458  if (m_Context.get()) {
459  m_Context->SetPanel(this);
460  }
461 
463 
464  m_RootItem.reset(item);
465 
466  if (m_RootItem.get()) {
467  CObjectToItemTraverser traverser(m_ObjectToItem);
468  m_RootItem->Traverse(traverser);
469 
470  if (m_Context.get())
471  m_Context->RootInitialized();
472  }
473 
474  Layout();
475  Scroll(0, 0);
476  Refresh();
477 }
478 
479 void CTextItemPanel::ReportError(const string& report)
480 {
481  CRootTextItem* root = new CRootTextItem();
482  CPlainTextItem* textItem = new CPlainTextItem();
483  textItem->SetStyle(CTextStyle(255,0,0,255,255,255,wxTRANSPARENT,false,false));
484  textItem->AddLine(report);
485  root->AddItem(textItem);
486 
488 
489  wxClientDC dc(this);
490  InitDC(dc);
491  context->CalcWSize(dc);
492  root->CalcSize(dc, context);
493  SetMainItem(root, context);
494 }
495 
497 {
498  CRootTextItem* root = new CRootTextItem();
499  CPlainTextItem* textItem = new CPlainTextItem();
500  textItem->SetStyle(CTextStyle(255,0,0,255,255,255,wxTRANSPARENT,false,false));
501  textItem->AddLine("Loading...");
502  root->AddItem(textItem);
503 
505 
506  wxClientDC dc(this);
507  InitDC(dc);
508  context->CalcWSize(dc);
509  root->CalcSize(dc, context);
510  SetMainItem(root, context);
511 }
512 
514 {
515  if (!m_RootItem.get()) return;
516 
517  wxBusyCursor wait;
518 
519  wxClientDC dc(this);
520  InitDC(dc);
521 
522  m_Context->CalcWSize(dc);
523  m_RootItem->CalcSize(dc, m_Context.get());
524 }
525 
527 {
528  dc.SetDeviceOrigin(0, 0);
529 
530  if (IsDoubleBuffered()) {
531  x_Draw(dc);
532  return;
533  }
534 
535  wxSize clientSize = GetClientRect().GetSize();
536  int w = clientSize.GetWidth(), h = clientSize.GetHeight();
537 
538  if (!m_Buffer.IsOk() || m_Buffer.GetWidth() != w || m_Buffer.GetHeight() != h) {
539  if (!m_Buffer.Create(w, h, dc)) {
540  x_Draw(dc);
541  return;
542  }
543  }
544 
545  wxMemoryDC memDC(m_Buffer);
546  x_Draw(memDC);
547 
548  memDC.SetDeviceOrigin(0, 0);
549  dc.Blit(0, 0, w, h, &memDC, 0, 0);
550 }
551 
553 {
554  InitDC(dc);
555 
556 // Fill background
557  wxRect updateRect = GetUpdateRegion().GetBox();
558  dc.DrawRectangle(updateRect);
559 
560  if (!m_RootItem.get() || !m_Context.get())
561  return;
562 
563  wxPoint origin;
564  CalcScrolledPosition(0,0,&origin.x, &origin.y);
565  m_Context->SetDeviceOrigin(origin);
566  CalcUnscrolledPosition(updateRect.x,updateRect.y,&updateRect.x, &updateRect.y);
567 
568  try {
569  m_RootItem->Draw(dc, updateRect, m_Context.get());
570  }
571  catch (const exception&) {
572  }
573 }
574 
576 {
577  wxColor bkgdColor = GetBackgroundColour();
578  if (!bkgdColor.Ok())
579  bkgdColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
580 
581  dc.SetBrush(wxBrush(bkgdColor));
582  dc.SetPen(wxPen(bkgdColor,1));
583  dc.SetTextBackground(bkgdColor);
584  dc.SetFont(GetFont());
585 }
586 
587 void CTextItemPanel::OnMouseEvent(wxMouseEvent& event)
588 {
589  if (event.LeftDown() && FindFocus() != this)
590  SetFocus();
591 
592  if (m_TooltipWindow && event.GetEventType() != wxEVT_LEAVE_WINDOW) {
593  m_TooltipWindow->Destroy();
594  m_TooltipWindow = 0;
595  }
596 
597  m_MousePos = event.GetPosition();
598 
599  if (m_RootItem.get() && m_Context.get()) {
600  wxMouseEvent ev(event);
601  CalcUnscrolledPosition(event.m_x, event.m_y, &ev.m_x, &ev.m_y);
602  m_Context->ClearMouseMove();
603  m_RootItem->MouseEvent(ev, *m_Context);
604 
605  if (event.Moving())
606  TriggerTooltip();
607  //wxRect rect = m_RootItem->GetRect();
608  //if (rect.Contains(ev.m_x, ev.m_y))
609  //m_RootItem->ProcessEvent(ev);
610  //else if (event.GetEventType() == wxEVT_MOTION)
611  //SetCursor(wxCursor(wxCURSOR_ARROW));
612  }
613 
614  if (!event.LeftDown())
615  event.Skip();
616 }
617 
618 void CTextItemPanel::OnCaptureLost(wxMouseCaptureLostEvent& event)
619 {
620  if (m_RootItem.get() && m_Context.get()) {
621  wxMouseEvent ev(wxEVT_LEFT_UP);
622  ev.SetEventObject(this);
623  CalcUnscrolledPosition(m_MousePos.x, m_MousePos.y, &ev.m_x, &ev.m_y);
624  m_Context->ClearMouseMove();
625  m_RootItem->MouseEvent(ev, *m_Context);
626  }
627 }
628 
629 void CTextItemPanel::SetCaretPos(int x, int y)
630 {
631  wxCaret* caret = GetCaret();
632  if (!caret) return;
633 
634  CalcScrolledPosition(x, y, &x, &y);
635  caret->Move(x, y);
636 }
637 
639 {
640  wxCaret* caret = GetCaret();
641  if (!caret) return;
642 
643  if (!m_RootItem.get()) return;
644 
645  CTextPosition caretPos = m_TextSelection.GetEnd();
646 
647  CTextItem* textItem = dynamic_cast<CTextItem*>(m_RootItem->GetItemByLine(caretPos.GetRow(), false));
648  if (textItem == 0)
649  return;
650 
651  wxClientDC dc(this);
652  InitDC(dc);
653 
654  caretPos.ShiftRow(-textItem->GetStartLine());
655  textItem->TextPosToCollapsed(caretPos, m_Context.get());
656  CCalcCaretPosOStream ostr(dc, m_Context->GetLeftMargin(), 0,
657  dc.GetCharHeight(), m_Context->GetIndentWidth(),
658  caretPos.GetCol(), caretPos.GetRow());
659 
660  textItem->RenderText(ostr, m_Context.get());
661  int x, y;
662  ostr.GetCaretPos(x, y);
663  wxPoint itemPos = textItem->GetPosition();
664  CalcScrolledPosition(x + itemPos.x, y + itemPos.y, &x, &y);
665  caret->Move(x, y);
666 }
667 
668 static
669 WX_DEFINE_MENU(kPopupMenu)
670  WX_MENU_SEPARATOR_L("Top Actions")
671  WX_MENU_SEPARATOR_L("Text Commands")
672  WX_MENU_ITEM(wxID_COPY)
673  WX_MENU_ITEM(wxID_SELECTALL)
674 WX_END_MENU()
675 
676 void CTextItemPanel::OnSetFocus(wxFocusEvent& WXUNUSED(event))
677 {
678  wxCaret* caret = GetCaret();
679  if (caret) caret->Show();
680  if (m_Host) m_Host->OnTextGotFocus();
681 }
682 
683 void CTextItemPanel::OnKillFocus(wxFocusEvent& WXUNUSED(event))
684 {
685  wxCaret* caret = GetCaret();
686  if (caret) caret->Hide();
687  if (m_Host) m_Host->OnTextLostFocus();
688 }
689 
690 void CTextItemPanel::OnContextMenu(wxContextMenuEvent& event)
691 {
692  wxPoint point = event.GetPosition();
693  // If from keyboard
694  if (point.x == -1 && point.y == -1) {
695  wxSize size = GetSize();
696  point.x = size.x / 2;
697  point.y = size.y / 2;
698  }
699  else {
700  point = ScreenToClient(point);
701  }
702 
704  wxMenu* menu = cmd_reg.CreateMenu(kPopupMenu);
705 
706  TConstScopedObjects sel_objects;
707  if (m_Context.get()) {
708  unique_ptr<wxMenu> contextMenu(m_Context->CreateMenu());
709  if (contextMenu.get()) {
710  Merge(*menu, *contextMenu);
711  }
712  m_Context->GetActiveObjects(sel_objects);
713  }
714 
715  vector<wxEvtHandler*> handlers;
717  *menu,
718  handlers,
720  sel_objects
721  );
722 
723  // obtain the modified menu and clean it empty sections
724  CleanupSeparators(*menu);
725 
726  for( size_t i = 0; i < handlers.size(); i++ ) {
727  PushEventHandler(handlers[i]);
728  }
729 
730  // show the menu
731  PopupMenu(menu, point);
732  delete menu;
733 
734  // disconnect and destroy the handlers
735  for( size_t i = 0; i < handlers.size(); i++ ) {
736  wxEvtHandler* h = PopEventHandler();
737  _ASSERT(h == handlers[i]);
738  delete h;
739  }
740 }
741 
742 void CTextItemPanel::OnCopy(wxCommandEvent& WXUNUSED(event))
743 {
744  if (!m_RootItem.get()) return;
745 
746  if (!IsTextSelected())
747  return;
748 
749  if (wxTheClipboard->Open()) {
750  wxStringOutputStream stream;
751  wxTextOutputStream os(stream);
752  m_RootItem->GetText(os, m_TextSelection.Normalized(), m_Context.get());
753  wxTheClipboard->SetData( new wxTextDataObject(stream.GetString()));
754  wxTheClipboard->Close();
755  }
756 }
757 
758 void CTextItemPanel::OnUpdateCopy(wxUpdateUIEvent& event)
759 {
760  event.Enable(IsTextSelected());
761 }
762 
763 void CTextItemPanel::OnSelectAll(wxCommandEvent& WXUNUSED(event))
764 {
765  if (!m_RootItem.get()) return;
766  SetSelection(CTextBlock(0, static_cast<int>(m_RootItem->GetLineCount())));
767 }
768 
770 {
771  int w, h, cw, ch;
772  GetClientSize(&cw, &ch);
773  GetVirtualSize(&w, &h);
774  if (h <= ch) return;
775 
776  int xUnit, yUnit;
777  GetScrollPixelsPerUnit(&xUnit, &yUnit);
778  Scroll(0, (h - ch)/yUnit);
779 /*
780  GetViewStart(&x, &y);
781  CalcUnscrolledPosition(x, y, &x, &y);
782 
783  CalcScrolledPosition(x, h - ch, &x, &y);
784  Scroll(x, y);
785  */
786 }
787 
788 bool CTextItemPanel::FindText(const wxString& searchStr, bool matchCase, bool forward)
789 {
790  bool found = false, searchCanceled = false;
791 
793  [this, &searchStr, matchCase, forward, &found, &searchCanceled](ICanceled& canceled) -> CTextPosition
794  {
795  string str = ToStdString(searchStr);
796  if (!matchCase)
797  str = NStr::ToUpper(str);
798 
799  CTextBlock selNorm = this->GetTextSelection().Normalized();
800  CTextPosition cursorPos = forward ? selNorm.GetEnd() : selNorm.GetStart();
801  CTextPosition foundPos;
802  for (CTextLineIterator it(this, cursorPos, forward); !canceled.IsCanceled() && it; ++it) {
803  string line = *it;
804  if (line.length() >= str.length()) {
805  size_t pos = matchCase ? line.find(str) : NStr::ToUpper(line).find(str);
806  if (pos != string::npos) {
807  foundPos = it.GetPosition();
808  foundPos.ShiftCol((int)pos);
809  found = true;
810  break;
811  }
812  }
813  }
814  searchCanceled = canceled.IsCanceled();
815  return foundPos;
816  },
817  wxT("Searching for \"") + searchStr + wxT("\"..."));
818 
819  if (searchCanceled)
820  return true;
821 
822  if (!found)
823  return false;
824 
825  CTextPosition start = pos;
826  CTextPosition end(start);
827  end.ShiftCol((int)searchStr.length());
828  MakePosVisible(start);
829  SetSelection(CTextBlock(start, end));
830  return true;
831 }
832 
833 bool CTextItemPanel::FindSequence(const wxString& text)
834 {
835  return m_Context.get() ? m_Context->FindSequence(text) : false;
836 }
837 
839 {
840  if (!m_RootItem.get()) return;
841 
842  CTextItem* posItem = dynamic_cast<CTextItem*>(m_RootItem->GetItemByLine(pos.GetRow(), true));
843  if (posItem == 0)
844  return;
845 
846  for (ITextItem* item = posItem; item;) {
847  IContainer* container = 0;
848  int index = 0;
849  item->GetContainer(container, index);
850  CExpandItem* expandItem = dynamic_cast<CExpandItem*>(container);
851  if (expandItem && !expandItem->IsExpanded())
852  expandItem->Toggle(m_Context.get(), true);
853  item = dynamic_cast<ITextItem*>(container);
854  }
855 
856  int w, h, cw, ch;
857  GetClientSize(&cw, &ch);
858  GetVirtualSize(&w, &h);
859  if (h <= ch) return;
860 
861  wxPoint itemPos = posItem->GetPosition();
862 
863  wxClientDC dc(this);
864  InitDC(dc);
865 
866  CCalcCaretPosOStream ostr(dc, m_Context->GetLeftMargin(), 0,
867  dc.GetCharHeight(), m_Context->GetIndentWidth(),
868  pos.GetCol(), pos.GetRow() - posItem->GetStartLine());
869 
870  posItem->RenderText(ostr, m_Context.get());
871  int x, y;
872  ostr.GetCaretPos(x, y);
873  int yN = y + itemPos.y;
874  CalcScrolledPosition(x + itemPos.x, y + itemPos.y, &x, &y);
875 
876  int xUnit, yUnit;
877  GetScrollPixelsPerUnit(&xUnit, &yUnit);
878 
879  //if (y + ch > h)
880  //y = h - ch;
881  if (y < 0)
882  Scroll(0, yN/yUnit);
883  else if (y + yUnit > ch)
884  Scroll(0, (yN + 2*yUnit - 1 - ch)/yUnit);
885 }
886 
888 {
889  for (ITextItem* it = item; it;) {
890  IContainer* container = 0;
891  int index = 0;
892  it->GetContainer(container, index);
893  CExpandItem* expandItem = dynamic_cast<CExpandItem*>(container);
894  if (expandItem && !expandItem->IsExpanded())
895  expandItem->Toggle(m_Context.get(), true);
896  it = dynamic_cast<ITextItem*>(container);
897  }
898 
899  int w, h, cw, ch;
900  GetClientSize(&cw, &ch);
901  GetVirtualSize(&w, &h);
902  if (h <= ch) return;
903 
904  wxPoint itemPos = item->GetPosition();
905  wxSize itemSize = item->GetSize();
906 
907  int x, y;
908  CalcScrolledPosition(0, itemPos.y, &x, &y);
909 
910  int xUnit, yUnit;
911  GetScrollPixelsPerUnit(&xUnit, &yUnit);
912 
913  //if (y + ch > h)
914  //y = h - ch;
915  if (y < 0)
916  Scroll(0, itemPos.y/yUnit);
917  else if (y + itemSize.GetY() > ch) {
918  if (itemSize.GetY() >= ch)
919  Scroll(0, itemPos.y/yUnit);
920  else
921  Scroll(0, (itemPos.y + itemSize.GetY() - ch + yUnit - 1)/yUnit);
922  }
923 }
924 
926 {
927  std::pair <TObjectToItem::iterator, TObjectToItem::iterator> ret =
928  m_ObjectToItem.equal_range(&object);
929 
930  if (ret.first != ret.second) {
931  MakeItemVisible(ret.first->second);
932  return true;
933  }
934  return false;
935 }
936 
937 
939 {
940  if (m_TooltipWindow) {
941  m_TooltipWindow->Destroy();
942  m_TooltipWindow = 0;
943  }
944 
945  m_Timer.Stop();
946  m_Timer.Start(500, wxTIMER_ONE_SHOT);
947 }
948 
949 void CTextItemPanel::OnTimer(wxTimerEvent& WXUNUSED(event))
950 {
951  if (m_Context.get() == 0)
952  return;
953 
954  if (m_Timer.IsRunning())
955  return;
956 
957  m_TooltipWindow = m_Context->CreateTooltipWindow();
958  if (m_TooltipWindow) {
959  wxSize tooltipSize = m_TooltipWindow->GetSize();
960  wxSize clientSize = GetClientSize();
961 
962  wxPoint pos = m_MousePos;
963 
964  if (pos.y + tooltipSize.GetHeight() > clientSize.GetHeight() &&
965  pos.y - tooltipSize.GetHeight() >= 0) {
966  pos.y -= tooltipSize.GetHeight();
967  }
968 
969  if (pos.x + tooltipSize.GetWidth() > clientSize.GetWidth()) {
970  pos.x = max(0, clientSize.GetWidth() - tooltipSize.GetWidth());
971  }
972 
973  m_TooltipWindow->Move(pos.x, pos.y);
974  m_TooltipWindow->Show();
975  }
976 }
977 
EVT_UPDATE_UI(eCmdAlnShowMethodsDlg, CAlnMultiWidget::OnUpdateShowMethodDlg) EVT_UPDATE_UI(eCmdMethodProperties
std::invoke_result< _Fty, ICanceled & >::type GUI_AsyncExec(_Fty &&_Fnarg, const wxString &msg=wxT("Accessing network..."))
Definition: async_call.hpp:130
void GetCaretPos(int &caretPosX, int &caretPosY) const
virtual void CalcSize(wxDC &dc, CTextPanelContext *context)
void AddItem(ITextItem *item, bool updatePositions=true)
virtual void Toggle(CTextPanelContext *context, bool update)
Definition: expand_item.cpp:84
virtual bool IsExpanded() const
Definition: expand_item.hpp:63
virtual const CConstRef< CObject > GetAssosiatedObject() const
Definition: expand_item.cpp:75
CObject –.
Definition: ncbiobj.hpp:180
void SetStyle(const CTextStyle &style)
void AddLine(const string &line)
bool IsEmpty() const
CTextPosition GetEnd() const
CTextPosition GetStart() const
CTextBlock Normalized() const
TObjectToItem & GetObjectToItem()
void OnContextMenu(wxContextMenuEvent &event)
void x_Draw(wxDC &dc)
void InitDC(wxDC &dc)
void OnCopy(wxCommandEvent &event)
ITextWidgetHost * m_Host
bool MakeObjectVisible(const CObject &object)
void SetMainItem(ITextItem *item, CTextPanelContext *context)
void MakePosVisible(const CTextPosition &pos)
void MakeItemVisible(ITextItem *item)
virtual bool Layout()
void OnSetFocus(wxFocusEvent &event)
void OnMouseEvent(wxMouseEvent &event)
void SelStart(int row, int col, bool shift)
void ObjectSelectionChanged()
void OnSelectAll(wxCommandEvent &event)
void SetCaretPos(int x, int y)
void OnUpdateCopy(wxUpdateUIEvent &event)
bool GetTrackSelection() const
void ReportError(const string &report)
bool FindText(const wxString &text, bool matchCase, bool forward)
CTextBlock GetTextSelection() const
TObjectToItem m_ObjectToItem
shared_ptr< CTextPanelContext > m_Context
bool IsTextSelected() const
shared_ptr< ITextItem > m_RootItem
void SetSelection(const CTextBlock &selection)
bool FindSequence(const wxString &text)
wxWindow * m_TooltipWindow
void SelMove(int row, int col)
void SelEnd(int row, int col)
void OnTimer(wxTimerEvent &event)
CTextBlock m_TextSelection
virtual bool SetFont(const wxFont &font)
void OnKillFocus(wxFocusEvent &event)
void OnCaptureLost(wxMouseCaptureLostEvent &event)
virtual void OnDraw(wxDC &dc)
virtual wxPoint GetPosition() const
Definition: text_item.hpp:137
virtual int GetStartLine() const
Definition: text_item.hpp:145
virtual void TextPosToCollapsed(CTextPosition &WXUNUSED(pos), CTextPanelContext *WXUNUSED(context)) const
Definition: text_item.hpp:162
void RenderText(CStyledTextOStream &ostream, CTextPanelContext *context) const
Definition: text_item.hpp:164
virtual void GetVisibleObjects(TConstScopedObjects &)
ITextItem * m_MouseOverItem
void SetSelectedObjects(const TConstObjects &objs)
virtual void GetMainObjects(TConstScopedObjects &objects)
void GetSelectedObjects(TConstObjects &objs)
virtual void EditItem(ITextItem *item, bool controlDown, bool shiftDown)
void SetFontDesc(wxWindow &wnd)
void GetActiveObjects(TConstScopedObjects &objects)
void AddHier(ITextItem *item)
CRef< objects::CScope > m_Scope
bool IsItemSelected(ITextItem *item)
void CalcWSize(wxDC &dc)
vector< ITextItem * > m_Hier
void MouseOverItem(ITextItem *item)
void SelectItem(ITextItem *item, bool controlDown, bool shiftDown)
virtual void SetPanel(CTextItemPanel *panel)
CConstRef< CSerialObject > m_SO
set< ITextItem * > m_SelectedItems
CTextItemPanel * m_Panel
int GetRow() const
int GetCol() const
void ShiftCol(int delta)
void ShiftRow(int delta)
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
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
virtual wxSize GetSize() const =0
virtual void GetContainer(IContainer *&container, int &index)=0
virtual wxPoint GetPosition() const =0
virtual const CConstRef< CObject > GetAssosiatedObject() const
Definition: text_item.hpp:109
virtual void OnTextLostFocus()=0
virtual void WidgetSelectionChanged()=0
virtual void OnTextPositionChanged(int row, int col)=0
Definition: svg.hpp:498
Definition: map.hpp:338
const_iterator_pair equal_range(const key_type &key) const
Definition: map.hpp:296
void clear()
Definition: map.hpp:309
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
void clear()
Definition: set.hpp:153
size_type size() const
Definition: set.hpp:132
bool empty() const
Definition: set.hpp:133
const_iterator find(const key_type &key) const
Definition: set.hpp:137
void erase(iterator pos)
Definition: set.hpp:151
const_iterator end() const
Definition: set.hpp:136
#define false
Definition: bool.h:36
static void Init(void)
Definition: cursor6.c:76
static const char * str(char *buf, int n)
Definition: stats.c:84
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
CRef< objects::CScope > scope
Definition: objects.hpp:53
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
CConstRef< CObject > object
Definition: objects.hpp:52
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
virtual bool IsCanceled(void) const =0
static string & ToUpper(string &str)
Convert string to upper case – string& version.
Definition: ncbistr.cpp:424
END_EVENT_TABLE()
int i
static void text(MDB_val *v)
Definition: mdb_dump.c:62
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
T max(T x_, T y_)
#define EXT_POINT__SCOPED_OBJECTS__CMD_CONTRIBUTOR
This Extension Point allows external components to add commands that can be applied to scoped CObject...
void AddCommandsForScopedObjects(wxMenu &aMenu, vector< wxEvtHandler * > &handlers, const string &anExtPointId, TConstScopedObjects &objects, CUICommandRegistry *aCmdReg=NULL)
Helper function for adding commands provided by contributors to the menu.
static const GLdouble origin[]
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
#define row(bind, expected)
Definition: string_bind.c:73
#define _ASSERT
#define WX_DEFINE_MENU(name)
New macros for defining menus for use with CUICommandRegistry.
Definition: ui_command.hpp:266
#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
void SetFocus(CRef< objects::CSeq_entry > entry)
static CS_CONTEXT * context
Definition: will_convert.c:21
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
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
void CleanupSeparators(wxMenu &menu)
Removes extra separators (in the begining or at the end of the menu, ot those that precede other sepa...
Definition: wx_utils.cpp:668
#define const
Definition: zconf.h:232
Modified on Fri Sep 20 14:57:37 2024 by modify_doxy.py rev. 669887