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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_GL___GLPANE_WIDGET__HPP
2 #define GUI_WIDGETS_GL___GLPANE_WIDGET__HPP
3 
4 /* $Id: gl_widget_base.hpp 42121 2018-12-21 21:49:09Z katargir $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbiobj.hpp>
36 #include <corelib/ncbifloat.h>
37 
42 
43 #include <gui/opengl/gldlist.hpp>
44 #include <gui/opengl/glpane.hpp>
45 
47 
49 #include <gui/utils/view_event.hpp>
50 
51 #include <wx/panel.h>
52 
53 #define ncbi_round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
54 
56 
57 
58 /// CGlWidgetPane represent a window component residing in CGlWidgetBase
59 /// client area.
61  public C3DCanvas,
62  public IGenericHandlerHost,
63  public ITooltipHandlerHost,
65 {
67 public:
68  CGlWidgetPane(wxWindow* parent,
69  wxWindowID id,
70  const wxPoint& pos = wxDefaultPosition,
71  const wxSize& size = wxDefaultSize,
72  long style = 0);
73  virtual ~CGlWidgetPane();
74 
75  /// returns size of the master pane in screen coordinates
76  virtual TVPPoint GetPortSize(void) = 0;
77 
78  /// @name IGenericHandlerHost interface implementation
79  /// @{
80  virtual void GHH_Redraw();
81  virtual void GHH_SetCursor(const wxCursor& cursor);
82  virtual void GHH_CaptureMouse();
83  virtual void GHH_ReleaseMouse();
84  /// @}
85 
86  /// @name ITooltipHandlerHost implementation
87  /// @{
88  virtual bool TC_NeedTooltip(const wxPoint & pt);
89  virtual string TC_GetTooltip(const wxRect & rect);
90  virtual wxWindow* TC_GetWindow();
91  /// @}
92 
93  /// @name IStickyTooltipHandlerHost implementation
94  /// @{
95  virtual wxWindow* TTHH_GetWindow() { return this; }
96  virtual bool TTHH_PopupMenuDisplayed() { return m_PopupMenuDisplayed; }
97  /// @}
98 
99 
100  /// @name wxWidgets event handlers
101  /// @{
102  void OnEnterWindow(wxMouseEvent& event);
103  void OnTimer(wxTimerEvent& event);
104  void OnMouseDown(wxMouseEvent& event);
105  void OnMouseUp(wxMouseEvent& event);
106  void OnMotion(wxMouseEvent& event);
107  void OnMouseWheel(wxMouseEvent& event);
108  void OnMouseCaptureLost(wxMouseCaptureLostEvent& event);
109  void OnLeaveWindow(wxMouseEvent& event);
110  void OnKeyEvent(wxKeyEvent& event);
111  void OnSetFocus(wxFocusEvent& event);
112  void OnKillFocus(wxFocusEvent& event);
113  void OnSize(wxSizeEvent& event);
114  void OnCmdEvent(wxCommandEvent& event);
115  void OnTipRemoved(wxCommandEvent& event);
116 
117  /// @}
118 
119  void SetPopupMenuDisplayed(bool b) { m_PopupMenuDisplayed= b; }
120  bool GetPopupMenuDisplayed() const { return m_PopupMenuDisplayed; }
121  void DlgOverlayFix();
122  void CheckOverlayTimer();
123 
124 protected:
125  virtual int x_GetAreaByWindowPos(const wxPoint& pos);
126  virtual int x_GetAreaByVPPos(TVPUnit vp_x, TVPUnit vp_y);
127 
128  // Return true if this control should grab focus when mouse enters it. Can
129  // base decsion on what control currently has focus (this base class
130  // implementation only takes focus from stickey tooltips)
131  virtual bool x_GrabFocus();
132 
133  /// @name IGlEventHandler management function
134  /// @{
135  struct SHandlerRec
136  {
138  int m_Area;
140  };
141 
142  bool x_RegisterHandler(IGlEventHandler* handler, int area, CGlPane* pane, int index=-1);
143  bool x_UnregisterHandler(IGlEventHandler* handler);
144  void x_SetCurrHandler(SHandlerRec* rec);
145 
146  bool x_Handlers_handle(wxEvent& event, int area, bool ignore_curr = true);
147  bool x_DispatchEventToHandler(wxEvent& event, SHandlerRec* rec);
148  void x_HandleAccels(wxKeyEvent& event);
149  /// @}
150 
151 protected:
152  typedef list<SHandlerRec> THandlerRecList;
153 
154  /// list of records for registered handlers
156 
157  /// pointer to record for last active handler
159 
160  /// Some handlers may need to know if popup (right click) menu is active
162 
163  /// Windows vista bug screws up opengl after dlgs/popups displayed over window.
164  /// Sometimes happens when mouse outside window so we reset after re-entering
166  /// Need associated timer since some popups take a little time to clear
168  /// For windows (e.g. tree) that do not want to layout/update for the fake size event
170 };
171 
172 
173 
174 /// this class converts model units to the integers distribited in [0, m_IntRange]
175 /// and vice versa
177 {
178 public:
179  CNormalizer(double min, double max, int int_range)
180  : m_Min(min), m_Max(max), m_IntRange(int_range) {}
181 
182  inline int RealToInt(double real)
183  {
184  double norm = (real - m_Min) / (m_Max - m_Min); // normalized in [0.0, 1.0]
185  return (int)ncbi_round(norm * m_IntRange);
186  }
187  inline int SizeToInt(double size)
188  {
189  double norm = size / (m_Max - m_Min); // normalized in [0.0, 1.0]
190  return (int)ncbi_round(norm * m_IntRange);
191  }
192  inline double IntToReal(int i)
193  {
194  double norm = double(i) / m_IntRange; // normalized in [0.0, 1.0]
195  return norm * (m_Max - m_Min) + m_Min;
196  }
197  inline double IntToSize(int i)
198  {
199  double norm = double(i) / m_IntRange; // normalized in [0.0, 1.0]
200  return (int)ncbi_round(norm * (m_Max - m_Min));
201  }
202 protected:
203  double m_Min, m_Max;
205 };
206 
207 
208 
209 ////////////////////////////////////////////////////////////////////////////////
210 /// class CGlWidgetBase
211 
213  public wxPanel,
214  public CEventHandler,
215  public IRegSettings
216 {
218 public:
219  enum {
220  ID_GLCHILDPANE = wxID_HIGHEST + 200,
223  };
224 
225  CGlWidgetBase(wxWindow* parent,
226  wxWindowID id = wxID_ANY,
227  const wxPoint& pos = wxDefaultPosition,
228  const wxSize& size = wxDefaultSize,
229  long style = wxTAB_TRAVERSAL,
230  const wxString& name = wxT("panel"));
231 
232  virtual ~CGlWidgetBase();
233 
234  /// creates controls and performs basic initialization
235  virtual void Create();
236 
237  /// @name IRegSettings interface implementation
238  /// @{
239  virtual void SetRegistryPath(const string& reg_path);
240  virtual void LoadSettings();
241  virtual void SaveSettings() const;
242  /// @}
243 
244  /// implement these 2 functions in derived classes
245  virtual CGlPane& GetPort() = 0;
246  virtual const CGlPane& GetPort() const = 0;
247 
248  /// @name wxWidgets event handlers
249  /// @{
250  void OnSize(wxSizeEvent& event);
251  void OnScroll(wxScrollEvent& event);
252 
253  void OnZoomIn(wxCommandEvent& event);
254  void OnZoomInX(wxCommandEvent& event);
255  void OnZoomInY(wxCommandEvent& event);
256  void OnZoomInMouse(wxCommandEvent& event);
257 
258  void OnZoomOut(wxCommandEvent& event);
259  void OnZoomOutX(wxCommandEvent& event);
260  void OnZoomOutY(wxCommandEvent& event);
261  void OnZoomOutMouse(wxCommandEvent& event);
262 
263  void OnZoomAll(wxCommandEvent& event);
264  void OnZoomAllX(wxCommandEvent& event);
265  void OnZoomAllY(wxCommandEvent& event);
266 
267  void OnEnableCmdUpdate(wxUpdateUIEvent& event);
268  /// @}
269 
270  virtual void ZoomRect(const TModelRect& rc);
271  virtual void ZoomPoint(const TModelPoint& point,
272  TModelUnit factor,
274  virtual void Scroll(TModelUnit d_x, TModelUnit d_y);
275 
276  virtual void NotifyVisibleRangeChanged();
277 
278  // Default events handler - reports unhandled event
279  void OnAllEvents(CViewEvent::TEventObject evt);
280 
281 protected:
282  /// Override to record when (blocking) popup menu is active
283  virtual bool DoPopupMenu(wxMenu *menu, int x, int y);
284 
285  /// creates Pane, Scrollbars and other child widgets, called from Create()
286  virtual void x_CreateControls(void);
287 
288  /// factory method creating master pane, called form x_CreateControls()
289  virtual void x_CreatePane() = 0;
290  virtual CGlWidgetPane* x_GetPane();
291 
292  virtual void x_RedrawControls(void);
293  virtual void x_Update();
294 
295  virtual void x_SaveStates(){};
296 
297  /// updates model limits of the Master CGlPane
298 
299  virtual void x_SetPortLimits(void) = 0;
300 
301  /// Zoom functions
302  virtual void x_ZoomIn(int options);
303  virtual void x_ZoomOut(int options);
304  virtual void x_ZoomAll(int options);
305  virtual void x_UpdateOnZoom();
306 
307  virtual void x_UpdateOnHScroll();
308  virtual void x_UpdateOnVScroll();
309 
310  virtual void x_UpdateScrollbars();
311  virtual void x_OnScrollX(int pos);
312  virtual void x_OnScrollY(int pos);
313 
314  ///
315  virtual void x_ShowDecoratedPopupMenu(wxMenu* menu);
316 
317 protected:
318  /// path to the widget's settings in GUI Registry
319  string m_RegPath;
320 
322 };
323 
325 
326 
327 #endif // GUI_WIDGETS_GL___GLPANE_WIDGET__HPP
CEventHandler.
CGLCanvas.
Definition: glcanvas.hpp:55
DECLARE_EVENT_TABLE()
class CGlPane
Definition: glpane.hpp:62
class CGlWidgetBase
TModelPoint m_PopupPoint
virtual void x_SaveStates()
virtual CGlPane & GetPort()=0
implement these 2 functions in derived classes
virtual const CGlPane & GetPort() const =0
string m_RegPath
path to the widget's settings in GUI Registry
virtual void x_SetPortLimits(void)=0
updates model limits of the Master CGlPane
virtual void x_CreatePane()=0
factory method creating master pane, called form x_CreateControls()
CGlWidgetPane represent a window component residing in CGlWidgetBase client area.
THandlerRecList m_lsHandlerRecs
list of records for registered handlers
virtual bool TTHH_PopupMenuDisplayed()
Return true if underlying window is currently displaying a popup menu.
bool m_PseudoSized
For windows (e.g. tree) that do not want to layout/update for the fake size event.
void SetPopupMenuDisplayed(bool b)
list< SHandlerRec > THandlerRecList
wxTimer m_GLOverlapFixTimer
Need associated timer since some popups take a little time to clear.
virtual wxWindow * TTHH_GetWindow()
Return the pointer to the underlying window.
bool m_PopupMenuDisplayed
Some handlers may need to know if popup (right click) menu is active.
bool GetPopupMenuDisplayed() const
virtual void GHH_Redraw()
redraws the Host and the handler
CStopWatch m_EnterTimer
Windows vista bug screws up opengl after dlgs/popups displayed over window.
SHandlerRec * m_pCurrHandlerRec
pointer to record for last active handler
virtual TVPPoint GetPortSize(void)=0
returns size of the master pane in screen coordinates
this class converts model units to the integers distribited in [0, m_IntRange] and vice versa
double IntToSize(int i)
CNormalizer(double min, double max, int int_range)
double IntToReal(int i)
int RealToInt(double real)
int SizeToInt(double size)
CStopWatch –.
Definition: ncbitime.hpp:1937
IGenericHandlerHost.
virtual void GHH_ReleaseMouse()=0
releases captured mouse
virtual void GHH_CaptureMouse()=0
captures mouse events in the hosting window for D&D
virtual void GHH_SetCursor(const wxCursor &cursor)=0
changes the cursor in the hosting window
IGlEventHandler.
IRegSettings An interface for objects that save / restore settings using CGuiRegistry.
IStickyTooltipHandlerHost - Class from which windows that want to support sticky tooltips ultimately ...
virtual string TC_GetTooltip(const wxRect &rect)=0
Returns tooltip string and coordinates for area tootlip associated with.
virtual bool TC_NeedTooltip(const wxPoint &pt)=0
Returns "true" if client wants to dispaly a tooltip.
virtual wxWindow * TC_GetWindow()=0
Returns pointer to the widget hosting ITooltipClient.
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
@ ID_GLCHILDPANE
#define ncbi_round(x)
GLdouble TModelUnit
Definition: gltypes.hpp:48
int TVPUnit
Definition: gltypes.hpp:47
EZoomOptions
EZoomOptions flags control behavior of Zoom operations.
Definition: glpane.hpp:99
@ fZoomXY
Definition: glpane.hpp:103
#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 NCBI_GUIWIDGETS_GL_EXPORT
Definition: gui_export.h:529
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
Floating-point support routines.
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
T max(T x_, T y_)
T min(T x_, T y_)
static static static wxID_ANY
@ ID_HSCROPLLBAR
IGlEventHandler * m_pHandler
Modified on Fri Sep 20 14:58:00 2024 by modify_doxy.py rev. 669887