No changes, just simplify docview sample a bit.

Remove some unnecessary function arguments and m_frame member variable.

Closes #12374.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66079 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-11-10 00:36:39 +00:00
parent 0c46625036
commit 9b341e6fa1
4 changed files with 55 additions and 76 deletions

View File

@@ -228,8 +228,8 @@ bool MyApp::OnInit()
CreateMenuBarForFrame(frame, menuFile, m_menuEdit);
frame->SetIcon(wxICON(doc));
frame->Centre(wxBOTH);
frame->Show(true);
frame->Centre();
frame->Show();
SetTopWindow(frame);
return true;
@@ -285,10 +285,11 @@ void MyApp::CreateMenuBarForFrame(wxFrame *frame, wxMenu *file, wxMenu *edit)
frame->SetMenuBar(menubar);
}
wxFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas)
wxFrame *MyApp::CreateChildFrame(wxView *view, bool isCanvas)
{
// create a child frame of appropriate class for the current mode
wxFrame *subframe;
wxDocument *doc = view->GetDocument();
#if wxUSE_MDI_ARCHITECTURE
if ( GetMode() == Mode_MDI )
{
@@ -317,7 +318,7 @@ wxFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas)
wxSize(300, 300)
);
subframe->Centre(wxBOTH);
subframe->Centre();
}
wxMenu *menuFile = new wxMenu;

View File

@@ -44,7 +44,7 @@ public:
// our specific methods
Mode GetMode() const { return m_mode; }
wxFrame *CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas);
wxFrame *CreateChildFrame(wxView *view, bool isCanvas);
// these accessors should only be called in single document mode, otherwise
// the pointers are NULL and an assert is triggered

View File

@@ -41,36 +41,30 @@ END_EVENT_TABLE()
// What to do when a view is created. Creates actual
// windows for displaying the view.
bool DrawingView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
bool DrawingView::OnCreate(wxDocument *doc, long flags)
{
if ( !wxView::OnCreate(doc, flags) )
return false;
MyApp& app = wxGetApp();
if ( app.GetMode() != MyApp::Mode_Single )
{
// create a new window and canvas inside it
m_frame = app.CreateChildFrame(doc, this, true);
m_frame->SetTitle("Drawing View");
m_canvas = new MyCanvas(this, m_frame);
m_frame->Show(true);
wxFrame* frame = app.CreateChildFrame(this, true);
wxASSERT(frame == GetFrame());
m_canvas = new MyCanvas(this);
}
else // single document mode
{
// reuse the existing window and canvas
m_frame = wxStaticCast(app.GetTopWindow(), wxFrame);
m_canvas = app.GetMainWindowCanvas();
m_canvas->SetView(this);
// Associate the appropriate frame with this view.
SetFrame(m_frame);
// Make sure the document manager knows that this is the
// current view.
Activate(true);
// Initialize the edit menu Undo and Redo items
doc->GetCommandProcessor()->SetEditMenu(app.GetMainWindowEditMenu());
doc->GetCommandProcessor()->Initialize();
}
GetFrame()->Show();
return true;
}
@@ -126,17 +120,17 @@ bool DrawingView::OnClose(bool deleteWindow)
m_canvas->ResetView();
m_canvas = NULL;
if ( m_frame )
m_frame->SetTitle(wxTheApp->GetAppDisplayName());
if (GetFrame())
wxStaticCast(GetFrame(), wxFrame)->SetTitle(wxTheApp->GetAppDisplayName());
}
else // not single window mode
{
if ( deleteWindow )
wxDELETE(m_frame);
}
{
GetFrame()->Destroy();
SetFrame(NULL);
}
}
return true;
}
@@ -159,17 +153,17 @@ BEGIN_EVENT_TABLE(TextEditView, wxView)
EVT_MENU(wxID_SELECTALL, TextEditView::OnSelectAll)
END_EVENT_TABLE()
bool TextEditView::OnCreate(wxDocument *doc, long WXUNUSED(flags))
bool TextEditView::OnCreate(wxDocument *doc, long flags)
{
m_frame = wxGetApp().CreateChildFrame(doc, this, false);
m_text = new wxTextCtrl(m_frame, wxID_ANY, "",
wxPoint(0, 0), m_frame->GetClientSize(),
if ( !wxView::OnCreate(doc, flags) )
return false;
wxFrame* frame = wxGetApp().CreateChildFrame(this, false);
wxASSERT(frame == GetFrame());
m_text = new wxTextCtrl(frame, wxID_ANY, "",
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE);
m_frame->SetTitle("Text View");
m_frame->Show(true);
Activate(true);
frame->Show();
return true;
}
@@ -193,9 +187,11 @@ bool TextEditView::OnClose(bool deleteWindow)
else // not single window mode
{
if ( deleteWindow )
wxDELETE(m_frame);
{
GetFrame()->Destroy();
SetFrame(NULL);
}
}
return true;
}
@@ -209,7 +205,7 @@ END_EVENT_TABLE()
// Define a constructor for my canvas
MyCanvas::MyCanvas(wxView *view, wxWindow *parent)
: wxScrolledWindow(parent, wxID_ANY, wxPoint(0, 0), parent->GetClientSize())
: wxScrolledWindow(parent ? parent : view->GetFrame())
{
m_view = view;
m_currentSegment = NULL;
@@ -287,12 +283,11 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
// ----------------------------------------------------------------------------
// Define a constructor for my canvas
ImageCanvas::ImageCanvas(wxView* view, wxWindow* parent)
: wxScrolledWindow(parent, wxID_ANY, wxPoint(0, 0), parent->GetClientSize())
ImageCanvas::ImageCanvas(wxView* view)
: wxScrolledWindow(view->GetFrame())
{
SetScrollRate( 10, 10 );
m_view = view;
SetScrollRate( 10, 10 );
}
// Define the repainting behaviour
@@ -313,13 +308,16 @@ ImageDocument* ImageView::GetDocument()
return wxStaticCast(wxView::GetDocument(), ImageDocument);
}
bool ImageView::OnCreate(wxDocument* doc, long WXUNUSED(flags))
bool ImageView::OnCreate(wxDocument* doc, long flags)
{
m_frame = wxGetApp().CreateChildFrame(doc, this, false);
m_frame->SetTitle("Image View");
m_canvas = new ImageCanvas(this, m_frame);
m_frame->Show(true);
Activate(true);
if ( !wxView::OnCreate(doc, flags) )
return false;
wxFrame* frame = wxGetApp().CreateChildFrame(this, false);
wxASSERT(frame == GetFrame());
m_canvas = new ImageCanvas(this);
frame->Show();
return true;
}
@@ -356,7 +354,10 @@ bool ImageView::OnClose(bool deleteWindow)
else // not single window mode
{
if ( deleteWindow )
wxDELETE(m_frame);
{
GetFrame()->Destroy();
SetFrame(NULL);
}
}
return true;
}

View File

@@ -25,7 +25,7 @@ class MyCanvas : public wxScrolledWindow
public:
// view may be NULL if we're not associated with one yet, but parent must
// be a valid pointer
MyCanvas(wxView *view, wxWindow *parent);
MyCanvas(wxView *view, wxWindow *parent = NULL);
virtual ~MyCanvas();
virtual void OnDraw(wxDC& dc);
@@ -67,7 +67,7 @@ private:
class DrawingView : public wxView
{
public:
DrawingView() { m_canvas = NULL; m_frame = NULL; }
DrawingView() : wxView(), m_canvas(NULL) {}
virtual bool OnCreate(wxDocument *doc, long flags);
virtual void OnDraw(wxDC *dc);
@@ -79,7 +79,6 @@ public:
private:
void OnCut(wxCommandEvent& event);
wxFrame *m_frame;
MyCanvas *m_canvas;
DECLARE_EVENT_TABLE()
@@ -94,7 +93,7 @@ private:
class TextEditView : public wxView
{
public:
TextEditView() : wxView() { m_frame = NULL; m_text = NULL; }
TextEditView() : wxView(), m_text(NULL) {}
virtual bool OnCreate(wxDocument *doc, long flags);
virtual void OnDraw(wxDC *dc);
@@ -107,7 +106,6 @@ private:
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()
@@ -121,29 +119,9 @@ private:
class ImageCanvas : public wxScrolledWindow
{
public:
ImageCanvas(wxView*, wxWindow* parent);
ImageCanvas(wxView*);
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;
}
private:
wxView *m_view;
};
@@ -155,7 +133,7 @@ private:
class ImageView : public wxView
{
public:
ImageView() : wxView(), m_frame(NULL) {}
ImageView() : wxView() {}
virtual bool OnCreate(wxDocument*, long flags);
virtual void OnDraw(wxDC*);
@@ -165,7 +143,6 @@ public:
ImageDocument* GetDocument();
private:
wxFrame* m_frame;
ImageCanvas* m_canvas;
DECLARE_DYNAMIC_CLASS(ImageView)