NCBI C++ ToolKit
viewer_window_base.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: viewer_window_base.hpp 64773 2014-10-08 13:59:20Z thiessen $
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: Paul Thiessen
27 *
28 * File Description:
29 * base GUI functionality for viewers
30 *
31 * ===========================================================================
32 */
33 
34 #ifndef CN3D_VIEWER_WINDOW_BASE__HPP
35 #define CN3D_VIEWER_WINDOW_BASE__HPP
36 
37 #include <corelib/ncbistd.hpp>
38 
39 #ifdef __WXMSW__
40 #include <windows.h>
41 #include <wx/msw/winundef.h>
42 #endif
43 #include <wx/wx.h>
44 
47 
48 
49 BEGIN_SCOPE(Cn3D)
50 
51 class ViewerBase;
52 class SequenceDisplay;
53 class MoleculeIdentifier;
54 
55 // this must be included in the event table for the derived class, so that the base class's
56 // menu item callbacks are accessible
57 #define INCLUDE_VIEWER_WINDOW_BASE_EVENTS \
58  EVT_MENU_RANGE(MID_SHOW_TITLES, MID_HIDE_TITLES, ViewerWindowBase::OnTitleView) \
59  EVT_MENU_RANGE(MID_ENABLE_EDIT, MID_SYNC_STRUCS_ON, ViewerWindowBase::OnEditMenu) \
60  EVT_MENU_RANGE(MID_SELECT_RECT, MID_DRAG_HORIZ, ViewerWindowBase::OnMouseMode) \
61  EVT_MENU_RANGE(MID_LEFT, MID_SPLIT, ViewerWindowBase::OnJustification) \
62  EVT_MENU (MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) \
63  EVT_MENU (MID_FIND_PATTERN, ViewerWindowBase::OnFindPattern) \
64  EVT_MENU_RANGE(MID_CACHE_HIGHLIGHTS, MID_RESTORE_CACHED_HIGHLIGHTS, ViewerWindowBase::OnCacheHighlights)
65 
66 class ViewerWindowBase : public wxFrame
67 {
68  friend class SequenceDisplay;
69 
70 public:
71 
72  // displays a new alignment, and whether to enable the editor and column selection
73  void NewDisplay(SequenceDisplay *display, bool enableSelectByColumn);
74 
75  // if 'prompt', ask if user wants to save edits; return value indicates whether program
76  // should continue after this dialog - i.e., returns false if user hits 'cancel';
77  // program should then abort the operation that engendered this function call.
78  // 'canCancel' tells whether or not a 'cancel' button is even displayed - thus
79  // if 'canCancel' is false, the function will always return true.
80  virtual bool SaveDialog(bool prompt, bool canCancel) = 0;
81 
82  // updates alignment (e.g. if width or # rows has changed); doesn't change scroll
83  void UpdateDisplay(SequenceDisplay *display);
84 
85  // scroll to specific column
87  void ScrollToRow(int row) { viewerWidget->ScrollTo(-1, row); }
88 
89  // scroll so that this cell is visible, if it's not already
91  void MakeSequenceVisible(const MoleculeIdentifier *identifier);
92 
93  // set the font for the characters from registry values; refreshes automatically.
94  void SetupFontFromRegistry(void);
95 
96  // communicates to the derived class that the user wants to turn on/off the editor;
97  // should return true if derived class wants to allow the state change
98  virtual bool RequestEditorEnable(bool enable) { return false; }
99  virtual void EnableDerivedEditorMenuItems(bool enable) { }
100 
101  // allows the derived class to set up special mouse/cursor modes, e.g. for delete row
102  virtual void CancelDerivedSpecialModesExcept(int id) { }
103 
104  // override to set customized window title
105  virtual void SetWindowTitle(void) = 0;
106 
107  // are geometry violations on?
108  bool GeometryViolationsShown(void) const { return menuBar->IsChecked(MID_SHOW_GEOM_VLTNS); }
109  void UpdateGeometryViolations(void) const;
110 
111  // menu callbacks
112  void OnTitleView(wxCommandEvent& event);
113  void OnEditMenu(wxCommandEvent& event);
114  void OnMouseMode(wxCommandEvent& event);
115  void OnJustification(wxCommandEvent& event);
116  void OnShowGeomVltns(wxCommandEvent& event);
117  void OnFindPattern(wxCommandEvent& event);
118  void OnCacheHighlights(wxCommandEvent& event);
119 
120 protected:
121 
122  // menu identifiers
123  enum {
124  // view menu
125 #ifdef __WXMAC__
126  MID_SHOW_TITLES = 1, // avoid debug warning when have menuitem ID = 0
127 #else
129 #endif
135 
136  // edit menu
146 
147  // mouse mode
153 
154  // unaligned justification
159 
160  // so derived classes can use non-conflicting MID's
162  };
163 
164  // can't instantiate base class
165  ViewerWindowBase(ViewerBase *parentViewer,
166  const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
167  virtual ~ViewerWindowBase(void);
168 
171 
172  void EnableBaseEditorMenuItems(bool enabled);
173 
174  // so derived classes can add menu stuff
175  wxMenuBar *menuBar;
177 
179 
181 
182  void SplitBlockOff(void)
183  {
184  menuBar->Check(MID_SPLIT_BLOCK, false);
185  SetCursor(wxNullCursor);
186  }
187  void MergeBlocksOff(void)
188  {
189  menuBar->Check(MID_MERGE_BLOCKS, false);
191  SetCursor(wxNullCursor);
192  }
193  void CreateBlockOff(void)
194  {
195  menuBar->Check(MID_CREATE_BLOCK, false);
197  SetCursor(wxNullCursor);
198  }
199  void DeleteBlockOff(void)
200  {
201  menuBar->Check(MID_DELETE_BLOCK, false);
202  SetCursor(wxNullCursor);
203  }
204 
206  {
207  if (id != MID_SPLIT_BLOCK && DoSplitBlock()) SplitBlockOff();
211  }
212 
214  {
217  }
218 
220 
221 public:
222 
224  { return currentJustification; }
225 
226  void RefreshWidget(void) { viewerWidget->Refresh(false); }
227  void KillWindow(void)
228  {
229  viewer = NULL;
231  Destroy();
232  }
233 
234  bool EditorIsOn(void) const { return menuBar->IsChecked(MID_ENABLE_EDIT); }
235  void EnableUndo(bool enabled) { menuBar->Enable(MID_UNDO, enabled); }
236  void EnableRedo(bool enabled) { menuBar->Enable(MID_REDO, enabled); }
237 
238  bool DoSplitBlock(void) const { return menuBar->IsChecked(MID_SPLIT_BLOCK); }
239  bool DoMergeBlocks(void) const { return menuBar->IsChecked(MID_MERGE_BLOCKS); }
240  bool DoCreateBlock(void) const { return menuBar->IsChecked(MID_CREATE_BLOCK); }
241  bool DoDeleteBlock(void) const { return menuBar->IsChecked(MID_DELETE_BLOCK); }
242 
244 
245  void SyncStructures(void) { ProcessCommand(MID_SYNC_STRUCS); }
246  bool AlwaysSyncStructures(void) const { return menuBar->IsChecked(MID_SYNC_STRUCS_ON); }
247 };
248 
249 END_SCOPE(Cn3D)
250 
251 #endif // CN3D_VIEWER_WINDOW_BASE__HPP
void ScrollTo(int column, int row)
bool AttachAlignment(ViewableAlignment *newAlignment, int initX=0, int initY=0)
void MakeCharacterVisible(int column, int row) const
eMouseMode GetMouseMode(void) const
void Refresh(bool eraseBackground=TRUE, const wxRect *rect=NULL)
void SetMouseMode(eMouseMode mode)
bool DoCreateBlock(void) const
void NewDisplay(SequenceDisplay *display, bool enableSelectByColumn)
virtual void CancelDerivedSpecialModesExcept(int id)
bool SelectBlocksIsOn(void) const
bool DoSplitBlock(void) const
void SetupFontFromRegistry(void)
virtual bool RequestEditorEnable(bool enable)
void MakeSequenceVisible(const MoleculeIdentifier *identifier)
void OnFindPattern(wxCommandEvent &event)
SequenceViewerWidget * viewerWidget
virtual SequenceViewerWidget::eMouseMode GetMouseModeForCreateAndMerge(void)=0
BlockMultipleAlignment::eUnalignedJustification currentJustification
bool DoMergeBlocks(void) const
void ScrollToColumn(int column)
SequenceViewerWidget::eMouseMode prevMouseMode
void CancelBaseSpecialModesExcept(int id)
void UpdateGeometryViolations(void) const
void EnableRedo(bool enabled)
bool EditorIsOn(void) const
void OnJustification(wxCommandEvent &event)
void MakeCellVisible(int column, int row)
ViewerWindowBase(ViewerBase *parentViewer, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
void CancelAllSpecialModesExcept(int id)
BlockMultipleAlignment::eUnalignedJustification GetCurrentJustification(void) const
void OnEditMenu(wxCommandEvent &event)
void ScrollToRow(int row)
virtual ~ViewerWindowBase(void)
virtual void EnableDerivedEditorMenuItems(bool enable)
void OnMouseMode(wxCommandEvent &event)
bool AlwaysSyncStructures(void) const
void OnShowGeomVltns(wxCommandEvent &event)
bool DoDeleteBlock(void) const
void EnableBaseEditorMenuItems(bool enabled)
void UpdateDisplay(SequenceDisplay *display)
virtual void SetWindowTitle(void)=0
void OnTitleView(wxCommandEvent &event)
virtual bool SaveDialog(bool prompt, bool canCancel)=0
void OnCacheHighlights(wxCommandEvent &event)
void EnableUndo(bool enabled)
bool GeometryViolationsShown(void) const
Include a standard set of the NCBI C++ Toolkit most basic headers.
static const char * column
Definition: stats.c:23
#define NULL
Definition: ncbistd.hpp:225
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
const struct ncbi::grid::netcache::search::fields::SIZE size
#define row(bind, expected)
Definition: string_bind.c:73
Modified on Sun Apr 21 03:43:45 2024 by modify_doxy.py rev. 669887