view.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: samples/docview/view.h
  3. // Purpose: View classes
  4. // Author: Julian Smart
  5. // Modified by: Vadim Zeitlin: merge with the MDI version and general cleanup
  6. // Created: 04/01/98
  7. // Copyright: (c) 1998 Julian Smart
  8. // (c) 2008 Vadim Zeitlin
  9. // Licence: wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11. #ifndef _WX_SAMPLES_DOCVIEW_VIEW_H_
  12. #define _WX_SAMPLES_DOCVIEW_VIEW_H_
  13. #include "wx/docview.h"
  14. // ----------------------------------------------------------------------------
  15. // Drawing view classes
  16. // ----------------------------------------------------------------------------
  17. // The window showing the drawing itself
  18. class MyCanvas : public wxScrolledWindow
  19. {
  20. public:
  21. // view may be NULL if we're not associated with one yet, but parent must
  22. // be a valid pointer
  23. MyCanvas(wxView *view, wxWindow *parent = NULL);
  24. virtual ~MyCanvas();
  25. virtual void OnDraw(wxDC& dc);
  26. // in a normal multiple document application a canvas is associated with
  27. // one view from the beginning until the end, but to support the single
  28. // document mode in which all documents reuse the same MyApp::GetCanvas()
  29. // we need to allow switching the canvas from one view to another one
  30. void SetView(wxView *view)
  31. {
  32. wxASSERT_MSG( !m_view, "shouldn't be already associated with a view" );
  33. m_view = view;
  34. }
  35. void ResetView()
  36. {
  37. wxASSERT_MSG( m_view, "should be associated with a view" );
  38. m_view = NULL;
  39. }
  40. private:
  41. void OnMouseEvent(wxMouseEvent& event);
  42. wxView *m_view;
  43. // the segment being currently drawn or NULL if none
  44. DoodleSegment *m_currentSegment;
  45. // the last mouse press position
  46. wxPoint m_lastMousePos;
  47. wxDECLARE_EVENT_TABLE();
  48. };
  49. // The view using MyCanvas to show its contents
  50. class DrawingView : public wxView
  51. {
  52. public:
  53. DrawingView() : wxView(), m_canvas(NULL) {}
  54. virtual bool OnCreate(wxDocument *doc, long flags);
  55. virtual void OnDraw(wxDC *dc);
  56. virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
  57. virtual bool OnClose(bool deleteWindow = true);
  58. DrawingDocument* GetDocument();
  59. private:
  60. void OnCut(wxCommandEvent& event);
  61. MyCanvas *m_canvas;
  62. wxDECLARE_EVENT_TABLE();
  63. wxDECLARE_DYNAMIC_CLASS(DrawingView);
  64. };
  65. // ----------------------------------------------------------------------------
  66. // Text view classes
  67. // ----------------------------------------------------------------------------
  68. // The view using a standard wxTextCtrl to show its contents
  69. class TextEditView : public wxView
  70. {
  71. public:
  72. TextEditView() : wxView(), m_text(NULL) {}
  73. virtual bool OnCreate(wxDocument *doc, long flags);
  74. virtual void OnDraw(wxDC *dc);
  75. virtual bool OnClose(bool deleteWindow = true);
  76. wxTextCtrl *GetText() const { return m_text; }
  77. private:
  78. void OnCopy(wxCommandEvent& WXUNUSED(event)) { m_text->Copy(); }
  79. void OnPaste(wxCommandEvent& WXUNUSED(event)) { m_text->Paste(); }
  80. void OnSelectAll(wxCommandEvent& WXUNUSED(event)) { m_text->SelectAll(); }
  81. wxTextCtrl *m_text;
  82. wxDECLARE_EVENT_TABLE();
  83. wxDECLARE_DYNAMIC_CLASS(TextEditView);
  84. };
  85. // ----------------------------------------------------------------------------
  86. // ImageCanvas
  87. // ----------------------------------------------------------------------------
  88. class ImageCanvas : public wxScrolledWindow
  89. {
  90. public:
  91. ImageCanvas(wxView*);
  92. virtual void OnDraw(wxDC& dc);
  93. private:
  94. wxView *m_view;
  95. };
  96. // ----------------------------------------------------------------------------
  97. // ImageView
  98. // ----------------------------------------------------------------------------
  99. class ImageView : public wxView
  100. {
  101. public:
  102. ImageView() : wxView() {}
  103. virtual bool OnCreate(wxDocument*, long flags);
  104. virtual void OnDraw(wxDC*);
  105. virtual bool OnClose(bool deleteWindow = true);
  106. virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
  107. ImageDocument* GetDocument();
  108. private:
  109. ImageCanvas* m_canvas;
  110. wxDECLARE_DYNAMIC_CLASS(ImageView);
  111. };
  112. // ----------------------------------------------------------------------------
  113. // ImageDetailsView
  114. // ----------------------------------------------------------------------------
  115. class ImageDetailsView : public wxView
  116. {
  117. public:
  118. ImageDetailsView(ImageDetailsDocument *doc);
  119. virtual void OnDraw(wxDC *dc);
  120. virtual bool OnClose(bool deleteWindow);
  121. private:
  122. wxFrame *m_frame;
  123. wxDECLARE_NO_COPY_CLASS(ImageDetailsView);
  124. };
  125. #endif // _WX_SAMPLES_DOCVIEW_VIEW_H_