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

Go to the SVN repository for this file.

1 /* $Id: text_view.cpp 39412 2017-09-21 17:44:52Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include "text_view.hpp"
35 
37 #include <gui/core/document.hpp>
38 
40 
43 
47 
51 
55 
58 
59 namespace {
60 CProjectViewTypeDescriptor s_ViewTypeDescr(
61  "Text View", // type name
62  "text_view", // icon alias
63  "Create an interactive text representation of data.",
64  "The Text View shows data in a variety of formats, including GenBank FlatFile, "
65  "NCBI ASN.1, and FastA format.",
66  "TEXT_VIEW", // help ID
67  "Generic", // category
68  false, // not a singleton
69  "SerialObject",
71 );
72 }
73 
75  : CProjectView(), m_Window(0), m_UsingStatusBar(false)
76 {
77 }
78 
80 {
83  if (sb_srv) {
84  sb_srv->RemoveSlot(1);
85  }
86  }
87 }
88 
90 {
92  return m_Window;
93 }
94 
96 {
98  return m_Window->GetWidget()->GetEventHandler();
99 }
100 
101 // override function to suppress Navigation toolbar
103 {
105 }
106 
107 const wxMenu* CTextView::GetMenu()
108 {
109  if (m_Window) {
111  if (contributor)
112  return contributor->GetMenu();
113  }
114 
115  return 0;
116 }
117 
119 {
120  CScope* scope = NULL;
121  const CObject* object = NULL;
122 
123  if(objects.size() == 1) {
124  object = objects[0].object.GetPointer();
125  scope = objects[0].scope.GetPointer();
126  }
127 
128  if (object) {
130  _ASSERT(srv);
131 
132  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
133  if (!ws) return false;
134 
135  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(*scope));
136  _ASSERT(doc);
137 
138  if (doc) {
140 
141  if (params) {
142  string viewType, initialSequence;
143  bool expandAll = false, trackSelection = false;
144 
145  const CObject_id& type = params->GetType();
146  if (type.IsStr() && type.GetStr() == "TextViewParams") {
147  ITERATE(CUser_object::TData, it, params->GetData()) {
148  const CObject_id& field_id = (*it)->GetLabel();
149  if (!field_id.IsStr())
150  continue;
151 
152  const string& label = field_id.GetStr();
153  const CUser_field::TData& data = (*it)->GetData();
154 
155  if (label == "TextViewType") {
156  if (data.IsStr())
157  viewType = data.GetStr();
158  }
159  else if (label == "ExpandAll") {
160  if (data.IsBool())
161  expandAll = data.GetBool();
162  }
163  else if (label == "TrackSelection") {
164  if (data.IsBool()) {
165  trackSelection = data.GetBool();
166  }
167  }
168  else if (label == "InitialSequence") {
169  if (data.IsStr()) {
170  initialSequence = data.GetStr();
171  }
172  }
173  }
174  }
175 
176  if (!viewType.empty())
177  m_Window->SetInitialViewType(viewType);
178 
179  if (expandAll)
180  m_Window->SetOpenExpanded(true);
181 
182  if (!initialSequence.empty())
183  m_Window->SetInitialSequence(initialSequence);
184 
185  m_Window->GetWidget()->SetTrackSelection(trackSelection);
186  }
187 
188  if (!m_Window->InitWidget(objects)) return false;
189 
190  x_AttachToProject(*doc);
192 
193  return true;
194  }
195  return false;
196  } else {
197  // cannot represent the data
199  return false;
200  }
201 }
202 
204 {
207  }
208  else if (evt.GetSubtype() == CProjectViewEvent::eData ||
210  if (m_Window) m_Window->DataChanged();
211  }
212 }
213 
214 
215 void CTextView::CreateViewWindow(wxWindow* parent)
216 {
217  _ASSERT(!m_Window);
218 
219  m_Window = new CTextPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(0, 0), wxTAB_TRAVERSAL|wxNO_BORDER);
220  m_Window->SetHost(this);
221  m_Window->GetWidget()->SetHost(this);
222 }
223 
224 
226 {
227  if (m_Window) {
228  m_Window->GetWidget()->SetHost(0);
229  m_Window->SetHost(0);
230  m_Window->Destroy();
231  m_Window = 0;
232  }
233 }
234 
235 
237 {
238  return s_ViewTypeDescr;
239 }
240 
241 
243 {
244  if (!m_Window && !x_HasProject()) return;
245 
249 }
250 
251 
253 {
254  if (!m_Window && !x_HasProject()) return;
255 
256  CScope* scope = x_GetScope();
259  ITERATE(vector< CConstRef<CObject> >, it, objects)
260  objs.push_back(SConstScopedObject(*it, scope));
261 }
262 
263 
265 {
266  if (!m_Window && !x_HasProject()) return;
267 
268  m_Window->GetMainObjects(objs);
269 }
270 
272 {
273  if (!m_Window && !x_HasProject()) return;
274 
275  vector<TConstScopedObjects> widgetObjects;
276  m_Window->GetActiveObjects(widgetObjects);
277  ITERATE(vector<TConstScopedObjects>, it, widgetObjects)
278  objects.insert(objects.end(), it->begin(), it->end());
279 }
280 
281 void CTextView::GetActiveObjects(vector<TConstScopedObjects>& objects)
282 {
283  if (!m_Window && !x_HasProject()) return;
284 
286 }
287 
288 
289 
291 {
292  if (!m_Window && !x_HasProject()) return;
293 
294  TConstObjects objs;
295  evt.GetAllObjects(objs);
296  evt.GetOther(objs);
298 }
299 
301 {
302  return m_Window ? m_Window->GetOrigObject() : 0;
303 }
304 
305 /// IFlatFileCtrl implementation
306 
307 bool CTextView::SetPosition(const string& seq, const CObject* object)
308 {
309  IFlatFileCtrl* ctrl = dynamic_cast<IFlatFileCtrl*>(m_Window);
310  return ctrl ? ctrl->SetPosition(seq, object) : false;
311 }
312 
313 bool CTextView::SetPosition(const objects::CBioseq_Handle& h, const CObject* object)
314 {
315  IFlatFileCtrl* ctrl = dynamic_cast<IFlatFileCtrl*>(m_Window);
316  return ctrl ? ctrl->SetPosition(h, object) : false;
317 }
318 
319 /// IGuiWidgetHost implementation
320 
322 {
324  prjSrv->RemoveProjectView(*this);
325 }
326 
328 {
329  if (m_SelectionService)
331 }
332 
334 {
335 }
336 
338 {
340  TConstScopedObjects scopedObjects;
341  sel_srv->GetCurrentSelection(scopedObjects);
342  ITERATE(TConstScopedObjects, it, scopedObjects)
343  objects.push_back(it->object);
344 }
345 
347 {
348 }
349 
350 void CTextView::ShowView(const string& viewName, FWindowFactory widgetFactory, TConstScopedObjects& objects, bool bFloat)
351 {
352  if (objects.empty()) return;
354  prjSrv->ShowView(viewName, widgetFactory, objects, bFloat);
355 }
356 
357 /// ITextWidgetHost implementation
358 
360 {
362  if (!m_UsingStatusBar) {
363  sb_srv->InsertSlot(1, NULL, 120);
364  m_UsingStatusBar = true;
365  }
366 }
367 
369 {
370  if (m_UsingStatusBar) {
372  sb_srv->RemoveSlot(1);
373  m_UsingStatusBar = false;
374  }
375 }
376 
378 {
379  CNcbiOstrstream ostr;
380  ostr << " Ln " << row + 1 << " Col " << col + 1;
381  string text = CNcbiOstrstreamToString(ostr);
383  sb_srv->SetStatusText(ToWxString(text), 1);
384 }
385 
386 
387 ///////////////////////////////////////////////////////////////////////////////
388 /// CTextViewFactory
390 {
391  static string sid("text_view_factory");
392  return sid;
393 }
394 
395 
397 {
398  static string slabel("Text View Factory");
399  return slabel;
400 }
401 
402 
404 {
405  string alias = GetViewTypeDescriptor().GetIconAlias();
406  provider.RegisterFileAlias(ToWxString(alias), wxT("text_view.png"));
407 }
408 
410 {
411  CTextPanel::RegisterCommands(cmd_reg, provider);
412 }
413 
415 {
416  return s_ViewTypeDescr;
417 }
418 
419 
421 {
422  return new CTextView();
423 }
424 
425 
427 {
428  return NULL;
429 }
430 
431 
433 {
434  bool found_good = false;
435  bool found_bad = false;
436 
437  for( size_t i = 0; i < objects.size(); i++) {
438  const CSerialObject* so =
439  dynamic_cast<const CSerialObject*>(objects[i].object.GetPointer());
440  if (so)
441  found_good = true;
442  else
443  found_bad = true;
444  }
445 
446  if (found_good)
447  return fCanShowSeparated | (found_bad ? fCanShowSome : fCanShowAll);
448 
449  return 0; // can show nothing
450 }
451 
452 
CGBDocument.
Definition: document.hpp:113
CUndoManager & GetUndoManager()
Definition: document.hpp:158
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CObject –.
Definition: ncbiobj.hpp:180
CProjectService - a service providing API for operations with Workspaces and Projects.
void RemoveProjectView(IProjectView &view)
removes the view from View manager Service and disconnects it from the project
virtual void x_ReportInvalidInputData(TConstScopedObjects &objects)
use this function to report incompatible data in InitView()
virtual void OnProjectChanged()
virtual void x_UpdateContentLabel()
virtual objects::CScope * x_GetScope() const
virtual void x_AttachToProject(CGBDocument &doc)
ISelectionService * m_SelectionService
virtual bool x_HasProject() const
CProjectViewEvent.
Definition: document.hpp:62
EEventSubtype GetSubtype() const
Definition: document.hpp:96
CProjectViewTypeDescriptor - holds description of a project view type.
CProjectView.
CRef –.
Definition: ncbiobj.hpp:618
CScope –.
Definition: scope.hpp:92
CSelectionEvent CSelectionEvent is used for broadcasting selection between views.
Definition: obj_event.hpp:68
void GetAllObjects(TConstObjects &objs) const
Definition: obj_event.cpp:314
void GetOther(TConstObjects &objs) const
Definition: obj_event.cpp:338
bool AddObjectSelection(const CObject &obj)
Definition: obj_event.cpp:177
Base class for all serializable objects.
Definition: serialbase.hpp:150
void SetTrackSelection(bool trackSelection)
void SetHost(ITextWidgetHost *host)
virtual void SetHost(IGuiWidgetHost *host)
IGuiWidgetHost implementation.
virtual void SetSelectedObjects(const TConstObjects &objects)
void SetInitialViewType(const string &type)
Definition: text_panel.cpp:885
virtual void DataChanging()
void GetMainObjects(TConstScopedObjects &objs)
Definition: text_panel.cpp:432
static void RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
Definition: text_panel.cpp:643
virtual void GetSelectedObjects(TConstObjects &objects) const
CTextItemPanel * GetWidget() const
Definition: text_panel.hpp:229
void SetInitialSequence(const string &sequence)
Definition: text_panel.hpp:155
virtual void GetActiveObjects(vector< TConstScopedObjects > &objects)
virtual void SetUndoManager(ICommandProccessor *cmdProccessor)
virtual bool InitWidget(TConstScopedObjects &objects)
void SetOpenExpanded(bool value)
Definition: text_panel.hpp:215
CIRef< IMenuContributor > GetMenuContributor()
Definition: text_panel.cpp:952
virtual void DataChanged()
virtual const CObject * GetOrigObject() const
CTextView.
Definition: text_view.hpp:61
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
CViewTypeDescriptor - holds description of a view type.
Definition: view.hpp:98
virtual bool SetPosition(const string &seq, const CObject *object)=0
virtual const CViewTypeDescriptor & GetViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
virtual void OnSelectionChanged(ISelectionClient *source)=0
notifies Service and its observers about changes in selection
IView - represents a standard visual part of Workbench UI.
Definition: view.hpp:73
CFingerprint identifies an instance of IWMClient and is used for labeling layout positions.
Definition: wm_client.hpp:58
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
static const struct name_t names[]
#define false
Definition: bool.h:36
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
virtual void GetCompatibleToolBars(vector< string > &names)
returns the names of toolbars compatible with this class (toolbars that are relevant and useful in th...
Definition: text_view.cpp:102
virtual const CObject * x_GetOrigObject() const
Definition: text_view.cpp:300
#define NULL
Definition: ncbistd.hpp:225
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
Definition: service.hpp:91
bool m_UsingStatusBar
Definition: text_view.hpp:138
virtual string GetExtensionIdentifier() const
CTextViewFactory.
Definition: text_view.cpp:389
virtual void GetMainObject(TConstScopedObjects &objs) const
Adds the main data objects represented by the client to "objects".
Definition: text_view.cpp:264
virtual void OnTextPositionChanged(int row, int col)
Definition: text_view.cpp:377
virtual IView * CreateInstanceByFingerprint(const TFingerprint &fingerprint) const
if fingerprint is recognized - creates and returns a new instance
Definition: text_view.cpp:426
virtual void RegisterIconAliases(wxFileArtProvider &provider)
called by the framework to give Factory a chance to register images used by view
Definition: text_view.cpp:403
virtual const wxMenu * GetMenu()
returns a menu (must be deleted by the caller) menu injections should follow a separator named "Contr...
Definition: text_view.cpp:107
virtual bool InitView(TConstScopedObjects &objects, const objects::CUser_object *params)
initialize view with data, inside this function the view must call CProjectService::AttachView to con...
Definition: text_view.cpp:118
virtual void RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
called by the framework to give Factory a chance to register commands used by view
Definition: text_view.cpp:409
virtual const CViewTypeDescriptor & GetTypeDescriptor() const
return an object providing meta information about thei view type
Definition: text_view.cpp:236
virtual void CreateViewWindow(wxWindow *parent)
create Window corresponding to the view
Definition: text_view.cpp:215
virtual bool SetPosition(const string &seq, const CObject *object)
IFlatFileCtrl implementation.
Definition: text_view.cpp:307
virtual void x_OnSetSelection(CSelectionEvent &evt)
override in derived classes in order to handle selection broadcast
Definition: text_view.cpp:290
virtual IView * CreateInstance() const
creates a view instance
Definition: text_view.cpp:420
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
Definition: text_view.cpp:396
virtual void GetSelection(CSelectionEvent &evt) const
get selection for broadcasting
Definition: text_view.cpp:242
virtual void OnWidgetCommand(const string &command)
Definition: text_view.cpp:346
virtual void GetActiveObjects(TConstScopedObjects &objects) const
Definition: text_view.cpp:271
virtual void GetAppSelection(TConstObjects &objects)
Definition: text_view.cpp:337
virtual wxEvtHandler * GetCommandHandler()
IWMClient implementation.
Definition: text_view.cpp:95
virtual void ShowView(const string &viewName, FWindowFactory widgetFactory, TConstScopedObjects &objects, bool bFloat)
Definition: text_view.cpp:350
virtual void WidgetSelectionChanged()
Definition: text_view.cpp:327
virtual void WidgetActivated()
Definition: text_view.cpp:333
virtual const CProjectViewTypeDescriptor & GetProjectViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
Definition: text_view.cpp:414
virtual void OnTextGotFocus()
ITextWidgetHost implementation.
Definition: text_view.cpp:359
virtual void CloseWidget()
IGuiWidgetHost implementation.
Definition: text_view.cpp:321
virtual void DestroyViewWindow()
destroy Window corresponding to the view
Definition: text_view.cpp:225
virtual wxWindow * GetWindow()
returns a pointer to the wxWindow representing the client
Definition: text_view.cpp:89
virtual void OnTextLostFocus()
Definition: text_view.cpp:368
virtual int TestInputObjects(TConstScopedObjects &objects)
tests input objects (probably using object conversion, or not) and returns a combination of ETestResu...
Definition: text_view.cpp:432
CTextPanel * m_Window
Definition: text_view.hpp:136
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
virtual const string & GetIconAlias() const
Definition: ui_object.cpp:130
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static const char label[]
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
const TData & GetData(void) const
Get the Data member data.
const TType & GetType(void) const
Get the Type member data.
vector< CRef< CUser_field > > TData
wxWindow *(* FWindowFactory)(wxWindow *)
Definition: gui_widget.hpp:45
int i
static void text(MDB_val *v)
Definition: mdb_dump.c:62
#define wxT(x)
Definition: muParser.cpp:41
const char * command
@ eOneObjectAccepted
static static static wxID_ANY
#define row(bind, expected)
Definition: string_bind.c:73
Definition: type.c:6
#define _ASSERT
USING_SCOPE(objects)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Tue Apr 30 06:41:30 2024 by modify_doxy.py rev. 669887