merged docvwmdi sample into docview one to avoid having 2 almost identical samples; and modernized and cleaned up the code in the process
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56053 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,49 +1,73 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: view.h
|
||||
// Name: samples/docview/view.h
|
||||
// Purpose: View classes
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Modified by: Vadim Zeitlin: merge with the MDI version and general cleanup
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Copyright: (c) 1998 Julian Smart
|
||||
// (c) 2008 Vadim Zeitlin
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __VIEW_H__
|
||||
#define __VIEW_H__
|
||||
#ifndef _WX_SAMPLES_DOCVIEW_VIEW_H_
|
||||
#define _WX_SAMPLES_DOCVIEW_VIEW_H_
|
||||
|
||||
#include "wx/docview.h"
|
||||
|
||||
class DrawingView;
|
||||
// ----------------------------------------------------------------------------
|
||||
// Drawing view classes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// The window showing the drawing itself
|
||||
class MyCanvas : public wxScrolledWindow
|
||||
{
|
||||
public:
|
||||
DrawingView* m_view;
|
||||
// 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();
|
||||
|
||||
MyCanvas(DrawingView*, wxFrame*, const wxPoint& pos, const wxSize& size, const long style);
|
||||
virtual void OnDraw(wxDC& dc);
|
||||
|
||||
protected:
|
||||
// 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:
|
||||
void OnMouseEvent(wxMouseEvent& event);
|
||||
|
||||
wxView *m_view;
|
||||
|
||||
// the segment being currently drawn or NULL if none
|
||||
DoodleSegment *m_currentSegment;
|
||||
|
||||
// the last mouse press position
|
||||
wxPoint m_lastMousePos;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class MyTextWindow: public wxTextCtrl
|
||||
{
|
||||
public:
|
||||
wxView* m_view;
|
||||
|
||||
MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style);
|
||||
};
|
||||
|
||||
// The view using MyCanvas to show its contents
|
||||
class DrawingView : public wxView
|
||||
{
|
||||
public:
|
||||
wxFrame* m_frame;
|
||||
MyCanvas* m_canvas;
|
||||
|
||||
DrawingView() { m_canvas = NULL; m_frame = NULL; };
|
||||
virtual ~DrawingView() {};
|
||||
DrawingView() { m_canvas = NULL; m_frame = NULL; }
|
||||
|
||||
virtual bool OnCreate(wxDocument *doc, long flags);
|
||||
virtual void OnDraw(wxDC *dc);
|
||||
@@ -52,35 +76,42 @@ public:
|
||||
|
||||
DrawingDocument* GetDocument();
|
||||
|
||||
protected:
|
||||
private:
|
||||
void OnCut(wxCommandEvent& event);
|
||||
|
||||
private:
|
||||
wxFrame *m_frame;
|
||||
MyCanvas *m_canvas;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
DECLARE_DYNAMIC_CLASS(DrawingView)
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Text view classes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// The view using a standard wxTextCtrl to show its contents
|
||||
class TextEditView : public wxView
|
||||
{
|
||||
public:
|
||||
wxFrame* m_frame;
|
||||
MyTextWindow* m_textsw;
|
||||
|
||||
TextEditView(): wxView() { m_frame = NULL; m_textsw = NULL; }
|
||||
virtual ~TextEditView() {}
|
||||
TextEditView() : wxView() { m_frame = NULL; m_text = NULL; }
|
||||
|
||||
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);
|
||||
|
||||
wxTextCtrl *GetText() const { return m_text; }
|
||||
|
||||
private:
|
||||
void OnCopy(wxCommandEvent& WXUNUSED(event)) { m_textsw->Copy(); }
|
||||
void OnPaste(wxCommandEvent& WXUNUSED(event)) { m_textsw->Paste(); }
|
||||
void OnSelectAll(wxCommandEvent& WXUNUSED(event)) { m_textsw->SelectAll(); }
|
||||
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;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
DECLARE_DYNAMIC_CLASS(TextEditView)
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // _WX_SAMPLES_DOCVIEW_VIEW_H_
|
||||
|
Reference in New Issue
Block a user