1998-05-22 19:57:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2008-10-03 15:16:01 +00:00
|
|
|
// Name: samples/docview/view.h
|
1998-05-22 19:57:05 +00:00
|
|
|
// Purpose: View classes
|
|
|
|
// Author: Julian Smart
|
2008-10-03 15:16:01 +00:00
|
|
|
// Modified by: Vadim Zeitlin: merge with the MDI version and general cleanup
|
1998-05-22 19:57:05 +00:00
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
2008-10-03 15:16:01 +00:00
|
|
|
// Copyright: (c) 1998 Julian Smart
|
|
|
|
// (c) 2008 Vadim Zeitlin
|
2002-03-17 14:16:03 +00:00
|
|
|
// Licence: wxWindows license
|
1998-05-22 19:57:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
#ifndef _WX_SAMPLES_DOCVIEW_VIEW_H_
|
|
|
|
#define _WX_SAMPLES_DOCVIEW_VIEW_H_
|
1998-05-22 19:57:05 +00:00
|
|
|
|
|
|
|
#include "wx/docview.h"
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Drawing view classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// The window showing the drawing itself
|
2008-04-06 13:57:23 +00:00
|
|
|
class MyCanvas : public wxScrolledWindow
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
public:
|
2008-10-03 15:16:01 +00:00
|
|
|
// view may be NULL if we're not associated with one yet, but parent must
|
|
|
|
// be a valid pointer
|
|
|
|
MyCanvas(wxView *view, wxWindow *parent);
|
|
|
|
virtual ~MyCanvas();
|
2008-04-06 13:57:23 +00:00
|
|
|
|
1998-05-22 19:57:05 +00:00
|
|
|
virtual void OnDraw(wxDC& dc);
|
2008-04-06 13:57:23 +00:00
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
// in a normal multiple document application a canvas is associated with
|
|
|
|
// one view from the beginning until the end, but to support the single
|
|
|
|
// document mode in which all documents reuse the same MyApp::GetCanvas()
|
|
|
|
// we need to allow switching the canvas from one view to another one
|
|
|
|
|
|
|
|
void SetView(wxView *view)
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( !m_view, "shouldn't be already associated with a view" );
|
|
|
|
|
|
|
|
m_view = view;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetView()
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( m_view, "should be associated with a view" );
|
|
|
|
|
|
|
|
m_view = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
1998-05-22 19:57:05 +00:00
|
|
|
void OnMouseEvent(wxMouseEvent& event);
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
wxView *m_view;
|
|
|
|
|
|
|
|
// the segment being currently drawn or NULL if none
|
|
|
|
DoodleSegment *m_currentSegment;
|
2008-04-06 13:57:23 +00:00
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
// the last mouse press position
|
|
|
|
wxPoint m_lastMousePos;
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
1998-05-22 19:57:05 +00:00
|
|
|
};
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
// The view using MyCanvas to show its contents
|
2008-04-06 13:57:23 +00:00
|
|
|
class DrawingView : public wxView
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
public:
|
2008-10-03 15:16:01 +00:00
|
|
|
DrawingView() { m_canvas = NULL; m_frame = NULL; }
|
2008-04-06 13:57:23 +00:00
|
|
|
|
|
|
|
virtual bool OnCreate(wxDocument *doc, long flags);
|
|
|
|
virtual void OnDraw(wxDC *dc);
|
|
|
|
virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
|
|
|
|
virtual bool OnClose(bool deleteWindow = true);
|
|
|
|
|
|
|
|
DrawingDocument* GetDocument();
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
private:
|
2000-07-15 19:51:35 +00:00
|
|
|
void OnCut(wxCommandEvent& event);
|
2008-04-06 13:57:23 +00:00
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
wxFrame *m_frame;
|
|
|
|
MyCanvas *m_canvas;
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2008-04-06 13:57:23 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS(DrawingView)
|
1998-05-22 19:57:05 +00:00
|
|
|
};
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Text view classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// The view using a standard wxTextCtrl to show its contents
|
2008-04-06 13:57:23 +00:00
|
|
|
class TextEditView : public wxView
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
public:
|
2008-10-03 15:16:01 +00:00
|
|
|
TextEditView() : wxView() { m_frame = NULL; m_text = NULL; }
|
2008-04-06 13:57:23 +00:00
|
|
|
|
|
|
|
virtual bool OnCreate(wxDocument *doc, long flags);
|
|
|
|
virtual void OnDraw(wxDC *dc);
|
|
|
|
virtual bool OnClose(bool deleteWindow = true);
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
wxTextCtrl *GetText() const { return m_text; }
|
|
|
|
|
2008-04-06 13:57:23 +00:00
|
|
|
private:
|
2008-10-03 15:16:01 +00:00
|
|
|
void OnCopy(wxCommandEvent& WXUNUSED(event)) { m_text->Copy(); }
|
|
|
|
void OnPaste(wxCommandEvent& WXUNUSED(event)) { m_text->Paste(); }
|
|
|
|
void OnSelectAll(wxCommandEvent& WXUNUSED(event)) { m_text->SelectAll(); }
|
|
|
|
|
|
|
|
wxFrame *m_frame;
|
|
|
|
wxTextCtrl *m_text;
|
2008-04-06 17:02:25 +00:00
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
2008-04-06 13:57:23 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS(TextEditView)
|
1998-05-22 19:57:05 +00:00
|
|
|
};
|
|
|
|
|
2009-09-24 16:04:06 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxImageCanvas
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxImageCanvas : public wxScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxImageCanvas(wxView*, wxWindow* parent);
|
|
|
|
|
|
|
|
virtual void OnDraw(wxDC& dc);
|
|
|
|
|
|
|
|
// in a normal multiple document application a canvas is associated with
|
|
|
|
// one view from the beginning until the end, but to support the single
|
|
|
|
// document mode in which all documents reuse the same MyApp::GetCanvas()
|
|
|
|
// we need to allow switching the canvas from one view to another one
|
|
|
|
|
|
|
|
void SetView(wxView* view)
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( !m_view, "shouldn't be already associated with a view" );
|
|
|
|
|
|
|
|
m_view = view;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetView()
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( m_view, "should be associated with a view" );
|
|
|
|
|
|
|
|
m_view = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxView *m_view;
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxImageView
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxImageDocument;
|
|
|
|
class wxImageView : public wxView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxImageView() : wxView(), m_frame(NULL) {}
|
|
|
|
|
|
|
|
virtual bool OnCreate(wxDocument*, long flags);
|
|
|
|
virtual void OnDraw(wxDC*);
|
|
|
|
virtual bool OnClose(bool deleteWindow = true);
|
|
|
|
virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
|
|
|
|
|
|
|
|
wxImageDocument* GetDocument();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxFrame* m_frame;
|
|
|
|
wxImageCanvas* m_canvas;
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxImageView)
|
|
|
|
};
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
#endif // _WX_SAMPLES_DOCVIEW_VIEW_H_
|