wxChartDir  2.0.1
wxchartviewer.h
1 /*
2 ** Name: wxchartviewer.h
3 ** Purpose: wxChartViewer class declaration
4 ** Author: Ulrich Telle
5 ** Created: 2018-05-09
6 ** Copyright: (C) 2018-2023, Ulrich Telle
7 ** License: LGPL - 3.0 + WITH WxWindows - exception - 3.1
8 */
9 
11 
128 #ifndef WXCHARTDIR_WXCHARTVIEWER_H
129 #define WXCHARTDIR_WXCHARTVIEWER_H
130 
131 // wxWidgets headers
132 
133 // wxChartViewer headers
134 #include "wxchartviewer_defs.h"
135 #include "wxchartviewer_version.h"
136 
137 #include <wx/bitmap.h>
138 #include <wx/event.h>
139 #include <wx/panel.h>
140 #include <wx/timer.h>
141 #include <wx/graphics.h>
142 #include <wx/overlay.h>
143 #include <wx/popupwin.h>
144 
145 #include "chartdir.h"
146 
147 #ifdef CD_NAMESPACE
148 namespace CD_NAMESPACE
149 {
150 #endif
151 
152 namespace Chart
153 {
154  // Mouse usage mode constants
155  enum
156  {
157  MouseUsageDefault = 0,
158  MouseUsageScroll = 1,
159  MouseUsageZoomIn = 3,
160  MouseUsageZoomOut = 4
161  };
162 }
163 
164 #ifdef CD_NAMESPACE
165 }
166 #endif
167 
168 // Forward declarations
169 class WXDLLIMPEXP_FWD_WXCHARTVIEWER wxEnhancedTooltip;
170 class WXDLLIMPEXP_FWD_WXCHARTVIEWER wxViewPortControl;
171 
173 
177 class WXDLLIMPEXP_WXCHARTVIEWER wxChartViewer : public wxPanel, public ViewPortManager
178 {
179 public:
181 
189  wxChartViewer(wxWindow* parent = 0, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = wxPanelNameStr);
190 
192  ~wxChartViewer();
193 
195 
217  virtual void setDPI(int dpi);
218 
220 
223  virtual int getDPI();
224 
226 
233  virtual void setChart(BaseChart* chart);
234 
236 
241  virtual BaseChart* getChart();
242 
244 
258  virtual void setImageMap(const char* imageMap);
259 
261 
264  virtual ImageMapHandler* getImageMapHandler();
265 
267 
270  virtual void setDefaultToolTip(const wxString& text);
271 
273 
287  virtual void setCDMLToolTipPrefix(const wxString& prefix);
288 
290 
293  virtual void setViewPortControl(wxViewPortControl* vpc);
294 
296 
299  virtual wxViewPortControl* getViewPortControl();
300 
302 
305  virtual void setSelectionBorderWidth(int width);
306 
308 
311  virtual int getSelectionBorderWidth();
312 
314 
317  virtual void setSelectionBorderColor(const wxColour& color);
318 
320 
323  virtual wxColour getSelectionBorderColor();
324 
326 
329  virtual void setSelectionBorderStyle(wxPenStyle style);
330 
332 
335  virtual wxPenStyle getSelectionBorderStyle();
336 
338 
381  virtual void setMouseUsage(int mouseUsage);
382 
384 
387  virtual int getMouseUsage();
388 
390 
421  virtual void setZoomDirection(int direction);
422 
424 
429  virtual int getZoomDirection();
430 
432 
437  virtual void setScrollDirection(int direction);
438 
440 
445  virtual int getScrollDirection();
446 
448 
453  virtual void setZoomInRatio(double ratio);
454 
456 
461  virtual double getZoomInRatio();
462 
464 
469  virtual void setZoomOutRatio(double ratio);
470 
472 
477  virtual double getZoomOutRatio();
478 
480 
491  virtual void setMouseWheelZoomRatio(double ratio);
492 
494 
499  virtual double getMouseWheelZoomRatio();
500 
502 
514  virtual void setMinimumDrag(int offset);
515 
517 
520  virtual int getMinimumDrag();
521 
523 
539  virtual void setUpdateInterval(int interval);
540 
542 
546  virtual int getUpdateInterval();
547 
549 
558  virtual bool needUpdateChart();
559 
561 
570  virtual bool needUpdateImageMap();
571 
573 
578  virtual bool isMouseOnPlotArea();
579 
581 
584  virtual bool isInMouseMoveEvent();
585 
587 
615  virtual bool isInViewPortChangedEvent();
616 
618 
624  virtual bool isMouseDragging();
625 
627 
649  virtual void updateViewPort(bool needUpdateChart, bool needUpdateImageMap);
650 
652  // Request wxChartViewer to redisplay the chart
660  virtual void updateDisplay();
661 
663 
669  virtual bool onMouseWheelZoom(int x, int y, int zDelta);
670 
672 
689  virtual void removeDynamicLayer(const wxString& msg);
690 
692 
697  virtual int getChartMouseX();
698 
700 
705  virtual int getChartMouseY();
706 
708 
720  virtual int getPlotAreaMouseX();
721 
723 
735  virtual int getPlotAreaMouseY();
736 
738 
744  virtual double getViewPortRight() { return getViewPortLeft() + getViewPortWidth(); }
745 
747 
753  virtual double getViewPortBottom() { return getViewPortTop() + getViewPortHeight(); }
754 
756 
765  static double ConvertDateTimeToChartTime(wxDateTime dt);
766 
768 
777  static wxDateTime ConvertChartTimeToDateTime(double ct);
778 
779  DECLARE_EVENT_TABLE()
780 
781 protected:
782  // wxChartViewer event handlers
783 
785 
788  void OnMouseMove(wxMouseEvent &evt);
789 
791 
794  void OnPaint(wxPaintEvent & evt);
795 
797 
800  void PaintNow(BaseChart* chart);
801 
803 
807  void Render(wxDC& dc, BaseChart* chart);
808 
810 
812  virtual void OnDelayedMouseMove();
813 
815 
818  virtual void OnMouseCaptureLost(wxMouseCaptureLostEvent& evt);
819 
821 
824  virtual void OnMousePressEvent(wxMouseEvent& evt);
825 
827 
830  virtual void OnMouseReleaseEvent(wxMouseEvent& evt);
831 
833 
836  virtual void OnLeaveEvent(wxMouseEvent& evt);
837 
839 
842  virtual void OnWheelEvent(wxMouseEvent& evt);
843 
845 
848  virtual void OnHoldTimerEvent (wxTimerEvent& evt);
849 
851 
854  virtual void OnDelayTimerEvent(wxTimerEvent& evt);
855 
857 
859  virtual void OnSetCursor();
860 
861 private:
863  BaseChart* m_currentChart;
864  ImageMapHandler* m_hotSpotTester;
865  BaseChart* m_imageMapChart;
866  wxString m_defaultToolTip;
867  wxColour m_selectBoxLineColor;
868  int m_selectBoxLineWidth;
869  wxPenStyle m_selectBoxLineStyle;
870 
871  int m_mouseUsage;
872  int m_zoomDirection;
873  int m_scrollDirection;
874  double m_zoomInRatio;
875  double m_zoomOutRatio;
876  double m_mouseWheelZoomRatio;
877  int m_minDragAmount;
878  int m_updateInterval;
879  bool m_needUpdateChart;
880  bool m_needUpdateImageMap;
881 
883 
884  int m_currentHotSpot;
885  bool m_isClickable;
886  bool m_isOnPlotArea;
887  bool m_isPlotAreaMouseDown;
888  bool m_isDragScrolling;
889  bool m_isMouseTracking;
890  bool m_isInMouseMove;
891 
892  // Dragging support
893 
894  int m_plotAreaMouseDownXPos;
895  int m_plotAreaMouseDownYPos;
896 
898  bool IsDrag(int direction, wxMouseEvent& event);
899 
901  void GetDragZoomRect(int px, int py, int& x, int& y, int& w, int& h);
902 
904  void OnPlotAreaMouseDrag(wxMouseEvent& point);
905 
906  // Selection rectangle
907 
908  bool m_rectVisible;
909  wxRect m_currentRect;
910  wxRect m_previousRect;
911 
913  void SetSelectionRect(int x, int y, int width, int height);
914 
916  void SetRectVisible(bool b);
917 
919  void DrawSelectionRect(wxDC& dc);
920 
921  // Chart update rate control
922 
923  bool m_holdTimerActive;
924  wxTimer m_holdTimer;
925  bool m_isInViewPortChanged;
926 
927  int m_delayUpdateChart;
928  BaseChart* m_delayedChart;
929 
931  void CommitUpdateChart();
932 
933  unsigned int m_lastMouseMove;
934  wxMouseEvent* m_delayedMouseEvent;
935  wxTimer m_delayedMouseEventTimer;
936  void CommitMouseMove(wxMouseEvent& event);
937 
938  bool m_delayImageMapUpdate;
939 
940  // Track Cursor support
941  int m_currentMouseX;
942  int m_currentMouseY;
943  int m_isInMouseMovePlotArea;
944 
945  // Dynamic Layer support
946  wxString m_autoHideMsg;
947 
949  void ApplyAutoHide(const wxString& msg);
950 
951  // Enhanced tooltip support
952  wxEnhancedTooltip* m_enhancedToolTip;
953  wxString m_cdmlToolTipPrefix;
954  void ShowToolTip(const wxString& text, const wxPoint& cursorPosition);
955  void ShowEnhancedToolTip(const wxString& text, const wxPoint& cursorPosition = wxPoint(0,0));
956  void MoveEnhancedToolTip(const wxPoint& cursorPosition, const wxRect& rFrom);
957 
958  // wxViewPortControl support
959  wxViewPortControl* m_vpControl;
960  bool m_reentrantGuard;
961 
962  wxBitmap m_chartBitmap;
963 
964  // High DPI support
965  double ToImageX(int x);
966  double ToImageY(int y);
967  int ToDisplayX(double x);
968  int ToDisplayY(double y);
969  int m_dpi;
970  double m_toImageScaleX;
971  double m_toImageScaleY;
972 };
973 
975 
980 class wxViewPortControl : public wxPanel, public ViewPortControlBase
981 {
982 public:
984 
992  wxViewPortControl(wxWindow* parent = 0, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = wxPanelNameStr);
993 
996 
998 
1003  virtual void setChart(BaseChart* chart);
1004 
1006 
1009  virtual BaseChart* getChart();
1010 
1012 
1015  virtual void setViewer(wxChartViewer* viewer);
1016 
1018 
1021  virtual wxChartViewer* getViewer();
1022 
1024 
1031  virtual void updateDisplay();
1032 
1033  DECLARE_EVENT_TABLE()
1034 
1035 protected:
1037 
1040  void OnPaint(wxPaintEvent & evt);
1041 
1043 
1046  void PaintNow(BaseChart* chart);
1047 
1049 
1053  void Render(wxDC& dc, BaseChart* chart);
1054 
1055  // wxChartViewer event handlers
1057 
1060  virtual void OnMouseMoveEvent(wxMouseEvent& evt);
1061 
1063 
1066  virtual void OnMousePressEvent(wxMouseEvent& evt);
1067 
1069 
1072  virtual void OnMouseReleaseEvent(wxMouseEvent& evt);
1073 
1075 
1078  virtual void OnMouseWheelEvent(wxMouseEvent& evt);
1079 
1081 
1084  virtual void OnMouseCaptureLost(wxMouseCaptureLostEvent& evt);
1085 
1086 private:
1088  virtual void OnViewPortChanged();
1089 
1091  bool IsDrag(wxMouseEvent& event);
1092 
1094  void PaintDisplay();
1095 
1097  void SyncState();
1098 
1100  void UpdateCursor(int position);
1101 
1103  void UpdateChartViewerIfNecessary();
1104 
1106  double ToImageX(int x);
1107 
1109  double ToImageY(int y);
1110 
1111  wxChartViewer* m_chartViewer;
1112  BaseChart* m_chart;
1113  bool m_reentrantGuard;
1114 
1115  int m_mouseDownX;
1116  int m_mouseDownY;
1117  bool m_isPlotAreaMouseDown;
1118 };
1119 
1121 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_WXCHARTVIEWER, wxEVT_CHARTVIEWER_CLICKED, wxCommandEvent);
1123 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_WXCHARTVIEWER, wxEVT_CHARTVIEWER_VIEWPORT_CHANGED, wxCommandEvent);
1125 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_WXCHARTVIEWER, wxEVT_CHARTVIEWER_MOUSEMOVE_CHART, wxCommandEvent);
1127 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_WXCHARTVIEWER, wxEVT_CHARTVIEWER_MOUSELEAVE_CHART, wxCommandEvent);
1129 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_WXCHARTVIEWER, wxEVT_CHARTVIEWER_MOUSEMOVE_PLOTAREA, wxCommandEvent);
1131 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_WXCHARTVIEWER, wxEVT_CHARTVIEWER_MOUSELEAVE_PLOTAREA, wxCommandEvent);
1133 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_WXCHARTVIEWER, wxEVT_CHARTVIEWER_MOUSEWHEEL, wxCommandEvent);
1134 
1136 #define EVT_CHARTVIEWER_CLICKED(winid, fn) \
1137  wx__DECLARE_EVT1(wxEVT_CHARTVIEWER_CLICKED, winid, wxCommandEventHandler(fn))
1139 #define EVT_CHARTVIEWER_VIEWPORT_CHANGED(winid, fn) \
1140  wx__DECLARE_EVT1(wxEVT_CHARTVIEWER_VIEWPORT_CHANGED, winid, wxCommandEventHandler(fn))
1142 #define EVT_CHARTVIEWER_MOUSEMOVE_CHART(winid, fn) \
1143  wx__DECLARE_EVT1(wxEVT_CHARTVIEWER_MOUSEMOVE_CHART, winid, wxCommandEventHandler(fn))
1145 #define EVT_CHARTVIEWER_MOUSELEAVE_CHART(winid, fn) \
1146  wx__DECLARE_EVT1(wxEVT_CHARTVIEWER_MOUSELEAVE_CHART, winid, wxCommandEventHandler(fn))
1148 #define EVT_CHARTVIEWER_MOUSEMOVE_PLOTAREA(winid, fn) \
1149  wx__DECLARE_EVT1(wxEVT_CHARTVIEWER_MOUSEMOVE_PLOTAREA, winid, wxCommandEventHandler(fn))
1151 #define EVT_CHARTVIEWER_MOUSELEAVE_PLOTAREA(winid, fn) \
1152  wx__DECLARE_EVT1(wxEVT_CHARTVIEWER_MOUSELEAVE_PLOTAREA, winid, wxCommandEventHandler(fn))
1154 #define EVT_CHARTVIEWER_MOUSEWHEEL(winid, fn) \
1155  wx__DECLARE_EVT1(wxEVT_CHARTVIEWER_MOUSEWHEEL, winid, wxCommandEventHandler(fn))
1156 
1157 #endif // WXCHARTDIR_WXCHARTVIEWER_H
Class representing a ChartDirector chart viewer control.
Definition: wxchartviewer.h:178
virtual double getViewPortBottom()
Gets the position of the bottom side of the viewport.
Definition: wxchartviewer.h:753
virtual double getViewPortRight()
Gets the position of the right side of the viewport.
Definition: wxchartviewer.h:744
Class representing a ChartDirector viewport control.
Definition: wxchartviewer.h:981