1998-05-22 19:57:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2008-10-03 15:16:01 +00:00
|
|
|
// Name: samples/docview/doc.h
|
1998-05-22 19:57:05 +00:00
|
|
|
// Purpose: Document 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
|
2008-10-03 15:16:01 +00:00
|
|
|
// Copyright: (c) 1998 Julian Smart
|
|
|
|
// (c) 2008 Vadim Zeitlin
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-22 19:57:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
#ifndef _WX_SAMPLES_DOCVIEW_DOC_H_
|
|
|
|
#define _WX_SAMPLES_DOCVIEW_DOC_H_
|
1998-05-22 19:57:05 +00:00
|
|
|
|
|
|
|
#include "wx/docview.h"
|
2001-06-27 12:31:16 +00:00
|
|
|
#include "wx/cmdproc.h"
|
2008-10-03 15:16:01 +00:00
|
|
|
#include "wx/vector.h"
|
2009-09-24 16:04:06 +00:00
|
|
|
#include "wx/image.h"
|
2008-10-03 15:16:01 +00:00
|
|
|
|
|
|
|
// This sample is written to build both with wxUSE_STD_IOSTREAM==0 and 1, which
|
|
|
|
// somewhat complicates its code but is necessary in order to support building
|
|
|
|
// it under all platforms and in all build configurations
|
|
|
|
//
|
|
|
|
// In your own code you would normally use std::stream classes only and so
|
|
|
|
// wouldn't need these typedefs
|
|
|
|
#if wxUSE_STD_IOSTREAM
|
|
|
|
typedef wxSTD istream DocumentIstream;
|
|
|
|
typedef wxSTD ostream DocumentOstream;
|
|
|
|
#else // !wxUSE_STD_IOSTREAM
|
|
|
|
typedef wxInputStream DocumentIstream;
|
|
|
|
typedef wxOutputStream DocumentOstream;
|
|
|
|
#endif // wxUSE_STD_IOSTREAM/!wxUSE_STD_IOSTREAM
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// The document class and its helpers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Represents a line from one point to the other
|
|
|
|
struct DoodleLine
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2008-10-03 15:16:01 +00:00
|
|
|
DoodleLine() { /* leave fields uninitialized */ }
|
|
|
|
|
|
|
|
DoodleLine(const wxPoint& pt1, const wxPoint& pt2)
|
|
|
|
: x1(pt1.x), y1(pt1.y), x2(pt2.x), y2(pt2.y)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
wxInt32 x1;
|
|
|
|
wxInt32 y1;
|
|
|
|
wxInt32 x2;
|
|
|
|
wxInt32 y2;
|
1998-05-22 19:57:05 +00:00
|
|
|
};
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
typedef wxVector<DoodleLine> DoodleLines;
|
|
|
|
|
1998-05-22 19:57:05 +00:00
|
|
|
// Contains a list of lines: represents a mouse-down doodle
|
2008-10-03 15:16:01 +00:00
|
|
|
class DoodleSegment
|
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
|
|
|
DocumentOstream& SaveObject(DocumentOstream& stream);
|
|
|
|
DocumentIstream& LoadObject(DocumentIstream& stream);
|
2004-10-06 20:32:05 +00:00
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
bool IsEmpty() const { return m_lines.empty(); }
|
|
|
|
void AddLine(const wxPoint& pt1, const wxPoint& pt2)
|
|
|
|
{
|
|
|
|
m_lines.push_back(DoodleLine(pt1, pt2));
|
|
|
|
}
|
|
|
|
const DoodleLines& GetLines() const { return m_lines; }
|
2004-10-06 20:32:05 +00:00
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
private:
|
|
|
|
DoodleLines m_lines;
|
1998-05-22 19:57:05 +00:00
|
|
|
};
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
typedef wxVector<DoodleSegment> DoodleSegments;
|
|
|
|
|
|
|
|
|
|
|
|
// The drawing document (model) class itself
|
2008-04-06 13:57:23 +00:00
|
|
|
class DrawingDocument : public wxDocument
|
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
|
|
|
DrawingDocument() : wxDocument() { }
|
2004-10-06 20:32:05 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
DocumentOstream& SaveObject(DocumentOstream& stream) wxOVERRIDE;
|
|
|
|
DocumentIstream& LoadObject(DocumentIstream& stream) wxOVERRIDE;
|
2004-10-06 20:32:05 +00:00
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
// add a new segment to the document
|
|
|
|
void AddDoodleSegment(const DoodleSegment& segment);
|
|
|
|
|
|
|
|
// remove the last segment, if any, and copy it in the provided pointer if
|
|
|
|
// not NULL and return true or return false and do nothing if there are no
|
|
|
|
// segments
|
|
|
|
bool PopLastSegment(DoodleSegment *segment);
|
|
|
|
|
|
|
|
// get direct access to our segments (for DrawingView)
|
|
|
|
const DoodleSegments& GetSegments() const { return m_doodleSegments; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void DoUpdate();
|
|
|
|
|
|
|
|
DoodleSegments m_doodleSegments;
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(DrawingDocument);
|
1998-05-22 19:57:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Some operations (which can be done and undone by the view) on the document:
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Base class for all operations on DrawingDocument
|
2008-04-06 13:57:23 +00:00
|
|
|
class DrawingCommand : public wxCommand
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2008-10-03 15:16:01 +00:00
|
|
|
public:
|
|
|
|
DrawingCommand(DrawingDocument *doc,
|
|
|
|
const wxString& name,
|
|
|
|
const DoodleSegment& segment = DoodleSegment())
|
|
|
|
: wxCommand(true, name),
|
|
|
|
m_doc(doc),
|
|
|
|
m_segment(segment)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
protected:
|
2008-10-03 15:16:01 +00:00
|
|
|
bool DoAdd() { m_doc->AddDoodleSegment(m_segment); return true; }
|
|
|
|
bool DoRemove() { return m_doc->PopLastSegment(&m_segment); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
DrawingDocument * const m_doc;
|
|
|
|
DoodleSegment m_segment;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The command for adding a new segment
|
|
|
|
class DrawingAddSegmentCommand : public DrawingCommand
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DrawingAddSegmentCommand(DrawingDocument *doc, const DoodleSegment& segment)
|
|
|
|
: DrawingCommand(doc, "Add new segment", segment)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool Do() wxOVERRIDE { return DoAdd(); }
|
|
|
|
virtual bool Undo() wxOVERRIDE { return DoRemove(); }
|
2008-10-03 15:16:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The command for removing the last segment
|
|
|
|
class DrawingRemoveSegmentCommand : public DrawingCommand
|
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
public:
|
2008-10-03 15:16:01 +00:00
|
|
|
DrawingRemoveSegmentCommand(DrawingDocument *doc)
|
|
|
|
: DrawingCommand(doc, "Remove last segment")
|
|
|
|
{
|
|
|
|
}
|
2004-10-06 20:32:05 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool Do() wxOVERRIDE { return DoRemove(); }
|
|
|
|
virtual bool Undo() wxOVERRIDE { return DoAdd(); }
|
1998-05-22 19:57:05 +00:00
|
|
|
};
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2009-01-09 16:01:34 +00:00
|
|
|
// wxTextDocument: wxDocument and wxTextCtrl married
|
2008-10-03 15:16:01 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-01-09 16:01:34 +00:00
|
|
|
class wxTextDocument : public wxDocument
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
public:
|
2009-01-09 16:01:34 +00:00
|
|
|
wxTextDocument() : wxDocument() { }
|
2009-05-22 22:52:31 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool OnCreate(const wxString& path, long flags) wxOVERRIDE;
|
2009-05-22 22:52:31 +00:00
|
|
|
|
2009-01-09 16:01:34 +00:00
|
|
|
virtual wxTextCtrl* GetTextCtrl() const = 0;
|
2008-04-06 13:57:23 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool IsModified() const wxOVERRIDE;
|
|
|
|
virtual void Modify(bool mod) wxOVERRIDE;
|
1998-05-22 19:57:05 +00:00
|
|
|
|
2009-01-09 16:01:34 +00:00
|
|
|
protected:
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool DoSaveDocument(const wxString& filename) wxOVERRIDE;
|
|
|
|
virtual bool DoOpenDocument(const wxString& filename) wxOVERRIDE;
|
2009-01-09 16:01:34 +00:00
|
|
|
|
2009-05-22 22:52:31 +00:00
|
|
|
void OnTextChange(wxCommandEvent& event);
|
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxTextDocument);
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_ABSTRACT_CLASS(wxTextDocument);
|
2009-01-09 16:01:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// A very simple text document class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class TextEditDocument : public wxTextDocument
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextEditDocument() : wxTextDocument() { }
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxTextCtrl* GetTextCtrl() const wxOVERRIDE;
|
2009-01-09 16:01:34 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(TextEditDocument);
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(TextEditDocument);
|
2008-10-03 15:16:01 +00:00
|
|
|
};
|
1998-05-22 19:57:05 +00:00
|
|
|
|
2009-09-24 16:04:06 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2011-06-27 00:09:37 +00:00
|
|
|
// Image and image details document classes (both are read-only for simplicity)
|
2009-09-24 16:04:06 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2011-06-27 00:09:37 +00:00
|
|
|
// This is a normal document containing an image, just like TextEditDocument
|
|
|
|
// above contains some text. It can be created from an image file on disk as
|
|
|
|
// usual.
|
2010-05-13 14:37:06 +00:00
|
|
|
class ImageDocument : public wxDocument
|
2009-09-24 16:04:06 +00:00
|
|
|
{
|
|
|
|
public:
|
2010-05-13 14:37:06 +00:00
|
|
|
ImageDocument() : wxDocument() { }
|
2009-09-24 16:04:06 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool OnOpenDocument(const wxString& file) wxOVERRIDE;
|
2011-06-27 00:09:37 +00:00
|
|
|
|
2010-05-13 14:37:06 +00:00
|
|
|
wxImage GetImage() const { return m_image; }
|
2009-09-24 16:04:06 +00:00
|
|
|
|
2010-05-13 14:37:06 +00:00
|
|
|
protected:
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool DoOpenDocument(const wxString& file) wxOVERRIDE;
|
2009-09-24 16:04:06 +00:00
|
|
|
|
2010-05-13 14:37:06 +00:00
|
|
|
private:
|
|
|
|
wxImage m_image;
|
2009-09-24 16:04:06 +00:00
|
|
|
|
2010-05-13 14:37:06 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(ImageDocument);
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(ImageDocument);
|
2009-09-24 16:04:06 +00:00
|
|
|
};
|
|
|
|
|
2011-06-27 00:09:37 +00:00
|
|
|
// This is a child document of ImageDocument: this document doesn't
|
|
|
|
// correspond to any file on disk, it's part of ImageDocument and can't be
|
|
|
|
// instantiated independently of it.
|
|
|
|
class ImageDetailsDocument : public wxDocument
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImageDetailsDocument(ImageDocument *parent);
|
|
|
|
|
|
|
|
// accessors for ImageDetailsView
|
|
|
|
wxSize GetSize() const { return m_size; }
|
|
|
|
unsigned long GetNumColours() const { return m_numColours; }
|
|
|
|
wxBitmapType GetType() const { return m_type; }
|
|
|
|
bool HasAlpha() const { return m_hasAlpha; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// some information about the image we choose to show to the user
|
|
|
|
wxSize m_size;
|
|
|
|
unsigned long m_numColours;
|
|
|
|
wxBitmapType m_type;
|
|
|
|
bool m_hasAlpha;
|
|
|
|
|
|
|
|
wxDECLARE_NO_COPY_CLASS(ImageDetailsDocument);
|
|
|
|
};
|
|
|
|
|
2008-10-03 15:16:01 +00:00
|
|
|
#endif // _WX_SAMPLES_DOCVIEW_DOC_H_
|