Initial commit.

This commit is contained in:
2018-12-06 16:01:56 +01:00
parent 10867b60c2
commit 18eb3f6047
1011 changed files with 345688 additions and 10 deletions

View File

@@ -0,0 +1,24 @@
# This file is part of EPOCH.
# File: CMakeLists.txt
# Author: Florent Teichteil-Königsbuch
# Contact: florent.teichteil@onera.fr
#
# EPOCH is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# EPOCH is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EPOCH. If not, see <http://www.gnu.org/licenses/>.
MESSAGE (STATUS "Compiling wxshapeframework-1.9.2")
FILE (GLOB_RECURSE WXSHAPEFRAMEWORK_SOURCES ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src)
ADD_LIBRARY (epoch-wxshapeframework STATIC ${WXSHAPEFRAMEWORK_SOURCES})

View File

@@ -0,0 +1,85 @@
/***************************************************************
* Name: ArrowBase.h
* Purpose: Defines line arrow base class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFARROWBASE_H
#define _WXSFARROWBASE_H
#include <wx/wxsf/ShapeBase.h>
// default values
#define sfdvARROW_FILL wxBrush(*wxWHITE)
#define sfdvARROW_BORDER wxPen(*wxBLACK)
class WXDLLIMPEXP_SF wxSFLineShape;
/*! \brief Base class for a line arrows */
class WXDLLIMPEXP_SF wxSFArrowBase : public xsSerializable
{
public:
friend class wxSFLineShape;
XS_DECLARE_CLONABLE_CLASS(wxSFArrowBase);
/*! \brief Default constructor */
wxSFArrowBase(void);
/*!
* \brief Constructor.
* \param parent Pointer to a parent shape
*/
wxSFArrowBase(wxSFShapeBase* parent);
/*!
* \brief Copy constructor.
* \param obj Source base arrow shape
*/
wxSFArrowBase(const wxSFArrowBase& obj);
/*! \brief Destructor. */
~wxSFArrowBase(void);
// public member data accessors
/*!
* \brief Set a parent of the arrow shape.
* \param parent Pointer to the parent shape
*/
void SetParentShape(wxSFShapeBase* parent){m_pParentShape = parent;}
/*!
* \brief Get pointer to a parent shape.
* \return Pointer to a parent shape if exists, otherwise NULL
*/
wxSFShapeBase* GetParentShape(){return m_pParentShape;}
// public functions
// public virtual functions
/*!
* \brief Draw arrow shape at the end of a virtual line.
* \param from Start of the virtual line
* \param to End of the virtual line
* \param dc Device context for drawing
*/
virtual void Draw(const wxRealPoint& from, const wxRealPoint& to, wxDC& dc);
protected:
// protected member data
/*! \brief Pointer to a parent shape. */
wxSFShapeBase* m_pParentShape;
// protected functions
/*!
* \brief Rotate and move arrow's vertices in accordance of virtual line at which end the arrow will be placed.
* \param trg Pointer to array where translated vertices will be stored
* \param src Pointer to array of source vertices
* \param n Number of vertices
* \param from Start of the virtual line
* \param to End of the virtual line
*/
void TranslateArrow(wxPoint *trg, const wxRealPoint *src, int n, const wxRealPoint &from, const wxRealPoint& to);
};
#endif //_WXSFARROWBASE_H

View File

@@ -0,0 +1,163 @@
/***************************************************************
* Name: BitmapShape.h
* Purpose: Defines bitmap shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFBITMAPSHAPE_H
#define _WXSFBITMAPSHAPE_H
#include <wx/wxsf/RectShape.h>
// default values
#define sfdvBITMAPSHAPE_SCALEIMAGE true
#define sfdvBITMAPSHAPE_XPMDATA wxT("")
/*!
* \brief Class encapsulating the bitmap shape. The shape can display and control
* files stored in formats supported by wxBitmap class loaded from a file or created
* from XPM image. */
class WXDLLIMPEXP_SF wxSFBitmapShape : public wxSFRectShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFBitmapShape);
/*! \brief Default constructor. */
wxSFBitmapShape(void);
/*!
* \brief User contructor.
* \param pos Initial position
* \param bitmapPath BMP file name
* \param manager Pointer of parent manager
*/
wxSFBitmapShape(const wxRealPoint& pos, const wxString& bitmapPath, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Source shape
*/
wxSFBitmapShape(const wxSFBitmapShape& obj);
/*! \brief Destructor */
virtual ~wxSFBitmapShape(void);
// public member data accessors
/*!
* \brief Get full name of a source BMP file.
* \return String containig full file name
*/
wxString GetBitmapPath(){return m_sBitmapPath;}
/*!
* \brief Enable/disable scaling mode of the bitmap.
* \param canscale Set TRUE if the bitmap shape could be scaled
*/
void EnableScale(bool canscale){m_fCanScale = canscale;}
/*!
* \brief Get information about the possibility of the shape scaling.
* \return TRUE if the shape can be scaled, otherwise FALSE
*/
bool CanScale(){return m_fCanScale;}
// public functions
/*!
* \brief Load a bitmap from the file.
* \param file File name (absolute or relative)
* \param type Bitmap type (see the wxBitmap class reference)
* \return TRUE on success, otherwise FALSE
*/
bool CreateFromFile(const wxString& file, wxBitmapType type = wxBITMAP_TYPE_BMP );
/*!
* \brief Load a bitmap from the XPM structure.
* \param bits Buffer with the image bits
* \return TRUE on success, otherwise FALSE
*/
bool CreateFromXPM(const char* const* bits);
// public virtual function
/*!
* \brief Scale the bitmap shape in both directions. The function can be overrided if neccessary.
* \param x Scale ratio in the horizontal direction
* \param y Scale ratio in the vertical direction
* \param children TRUE if the shape's children shoould be scaled as well, otherwise
* the shape will be updated after scaling via Update() function.
*/
virtual void Scale(double x, double y, bool children = sfWITHCHILDREN);
/*!
* \brief Event handler called when the user started to drag the shape handle. The function can be overrided if neccessary.
* \param handle Reference to the dragged shape handle
*/
virtual void OnBeginHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the shape handle. The function can be overrided if neccessary.
* \param handle Reference to the dragged shape handle
*/
virtual void OnHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called when the user finished dragging of the shape handle. The function can be overrided if neccessary.
* \param handle Reference to the dragged shape handle
*/
virtual void OnEndHandle(wxSFShapeHandle& handle);
protected:
// protected data members
/*! \brief String containing the full bitmap file name. */
wxString m_sBitmapPath;
/*! \brief Currently processed (modified) bitmap. */
wxBitmap m_Bitmap;
/*! \brief Original archived bitmap. */
wxBitmap m_OriginalBitmap;
bool m_fCanScale;
bool m_fRescaleInProgress;
wxRealPoint m_nPrevPos;
// protected functions
/*!
* \brief Rescale the bitmap shape so it will fit the given extent. The
* shape position is not involved (the left-top bitmap corner is not moved).
* \param size New bitmap size
*/
void RescaleImage(const wxRealPoint& size);
// protected virtual functions
/*!
* \brief Draw the shape in the normal way. The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawNormal(wxDC& dc);
/*!
* \brief Draw the shape in the hower mode (the mouse cursor is above the shape). The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHover(wxDC& dc);
/*!
* \brief Draw the shape in the highlighted mode (another shape is dragged over this shape and this shape will accept the dragged one if it will be dropped on it). The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHighlighted(wxDC& dc);
/*!
* \brief Serialize shape's properties to the given XML node.
* \param node Pointer to XML node where the shape's property nodes will be append to </param>
* \sa wxSFShapeBase::Serialize
*/
virtual wxXmlNode* Serialize(wxXmlNode* node);
/*!
* \brief Deserialize shape's properties from the given XML node.
* \param node Source XML node containig the shape's property nodes
* \sa wxSFShapeBase::Deserialize
*/
virtual void Deserialize(wxXmlNode* node);
private:
// private functions
/*! \brief Initialize serializable properties. */
void MarkSerializableDataMembers();
};
#endif //_WXSFBITMAPSHAPE_H

View File

@@ -0,0 +1,136 @@
/***************************************************************
* Name: CanvasHistory.h
* Purpose: Defines manager for stored canvas states
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFCANVASHISTORY_H
#define _WXSFCANVASHISTORY_H
#include <wx/wxsf/CanvasState.h>
#define sfDEFAULT_MAX_CANVAS_STATES 25
class WXDLLIMPEXP_SF wxSFShapeCanvas;
/*! \brief
* Container class that manages stored canvas states (canvas snapshots) and implements
* basic Undo/Redo functionality.
*
* Two different working modes are available: 'histUSE_SERIALIZATION' mode uses basic
* serialization functionality encapsulated by a diagram manager for storing
* of current canvas content, but in the 'histUSE_CLONING' mode full copy of
* diagram manager content is done via its copy constructor. The first mode is
* slower than the second one, but do not require implementation of xsSerializable::Clone()
* virtual function in all classes derived from xsSerializable like the second
* posible working mode.
* \sa wxSFCanvasState, wxSFCanvasHistory::MODE, xsSerializable::Clone, wxXmlSerializer::CopyItems
*/
class WXDLLIMPEXP_SF wxSFCanvasHistory : public wxObject
{
public:
enum MODE
{
/*! \brief Use serialization for storing of a canvas content */
histUSE_SERIALIZATION,
/*! \brief Use diagram manager's copy constructor for storing of a canvas content */
histUSE_CLONING
};
/*!
* \brief Default constructor.
* \param hmode Working mode (see MODE enumeration for more details)
*/
wxSFCanvasHistory(MODE hmode = histUSE_SERIALIZATION);
/*!
* \brief User constructor.
* \param canvas Pointer to managed canvas
* \param hmode Working mode (see MODE enumeration for more details)
* \sa MODE
*/
wxSFCanvasHistory(wxSFShapeCanvas *canvas, MODE hmode = histUSE_SERIALIZATION);
/*! \brief Destructor. */
~wxSFCanvasHistory(void);
// public member data accessors
/*!
* \brief Set history working mode.
*
* For more details about available working modes see the wxSFCanvasHistory class
* description. Note that all stored canvas history will be cleared after
* usage of this function.
* \param hmode Working mode
* \sa MODE
*/
void SetMode(MODE hmode);
/*! \brief
* Set total number of stored canvas states.
* \param depth Number of stored canvas states
* \sa GetHistoryDepth
*/
void SetHistoryDepth(size_t depth){m_nHistoryDepth = depth;}
/*! \brief
* Set pointer to the parent shapes canvas. All Undo/Redo operation defined by this class
* will be performed on this shape canvas instance.
* \param canvas Pointer to parent shape canvas
*/
void SetParentCanvas(wxSFShapeCanvas* canvas){m_pParentCanvas = canvas;}
/*! \brief Get currently used working mode */
MODE GetMode(){return m_nWorkingMode;}
/*! \brief
* Get total number of canvas states which can be stored at the same time.
* \return Number of allowed concuretly stored canvas states
* \sa SetHistoryDepth
*/
size_t GetHistoryDepth(){return m_nHistoryDepth;}
// public functions
/*! \brief Save current canvas state. */
void SaveCanvasState();
/*! \brief Perform the 'Undo' operation. */
void RestoreOlderState();
/*! \brief Perform the 'Redo' operation. */
void RestoreNewerState();
/*! \brief Clear all canvas history. */
void Clear();
/*! \brief
* The function gives information whether the 'Undo' operation is available
* (exists any stored canvas state older than the current one.
* \return TRUE if the 'Undo' operation can be performed, otherwise FALSE
*/
bool CanUndo();
/*! \brief
* The function gives information whether the 'Redo' operation is available
* (exists any stored canvas state newer than the current one.
* \return TRUE if the 'Undo' operation can be performed, otherwise FALSE
*/
bool CanRedo();
protected:
// protected data members
/*! \brief Pointer to the parent canvas. */
wxSFShapeCanvas * m_pParentCanvas;
/*! \brief
* List of stored canvas state instances.
* \sa wxSFCanvasState
*/
StateList m_lstCanvasStates;
/*! \brief Auxilary pointer to current canvas state. */
wxSFCanvasState *m_pCurrentCanvasState;
/*! \brief Canvas history mode */
MODE m_nWorkingMode;
/*! \brief Total allowed amount of stored canvas states. */
size_t m_nHistoryDepth;
};
#endif //_WXSFCANVASHISTORY_H

View File

@@ -0,0 +1,62 @@
/***************************************************************
* Name: CanvasState.h
* Purpose: Defines container for stored canvas state
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFCANVASSTATE_H
#define _WXSFCANVASSTATE_H
#include <wx/wxprec.h>
#include <wx/wxsf/Defs.h>
#include <wx/wxsf/DiagramManager.h>
class wxSFShapeCanvas;
/*! \brief
* Class which stores one saved state of the shape canvas. The instaces of this
* class are managed by the wxSFCanvasHistory class which performs all related Undo/Redo
* operations.
* \sa wxSFShapeCanvas
*/
class wxSFCanvasState : public wxObject
{
friend class wxSFCanvasHistory;
public:
/*! \brief
* Constructor for 'histUSE_SERIALIZATION' mode.
* \param data Pointer to the stream buffer containig serialized content of the shape canvas
*/
wxSFCanvasState(wxStreamBuffer* data);
/*! \brief
* Constructor for 'histUSE_CLONING' mode.
* \param data Pointer to temporal data manager
*/
wxSFCanvasState(wxSFDiagramManager *data);
/*! \brief Destructor. */
~wxSFCanvasState(void);
protected:
// protected functions
/*! \brief
* Restore stored canvas state.
* \param canvas Pointer to the shape canvas which content will be replaced by the stored one
*/
void Restore(wxSFShapeCanvas* canvas);
// protected data members
/*! \brief Memory buffer used during the serialization/deserialization operations. */
wxMemoryBuffer m_dataBuffer;
/*! \brief Data manager used for storing of temporal canvas state. */
wxSFDiagramManager *m_pDataManager;
};
WX_DECLARE_LIST(wxSFCanvasState, StateList);
#endif //_WXSFCANVASSTATE_H

View File

@@ -0,0 +1,72 @@
/***************************************************************
* Name: CircleArrow.h
* Purpose: Defines circle arrow for line shapes
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2009-04-19
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFCIRCLEARROW_H
#define _WXSFCIRCLEARROW_H
#include <wx/wxsf/SolidArrow.h>
// default values
#define sfdvARROW_RADIUS 4
/*!
* \brief Class extends the wxSFSolidBase class and encapsulates
* arrow shape consisting of a filled circle located at the end of the
* parent line shape.
*/
class WXDLLIMPEXP_SF wxSFCircleArrow : public wxSFSolidArrow
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFCircleArrow);
/*! \brief Default constructor. */
wxSFCircleArrow(void);
/*!
* \brief User constructor.
* \param parent Pointer to the parent shape
*/
wxSFCircleArrow(wxSFShapeBase* parent);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFCircleArrow(const wxSFCircleArrow& obj);
/*! \brief Destructor. */
virtual ~wxSFCircleArrow(void);
// public member data accessors
/**
* \brief Set radius of circle arrow
* \param radius Radius of circle arrow
*/
void SetRadius(int radius) {m_nRadius = radius;}
/**
* \brief Get radius of circle arrow
* \return Radius if circle arrow
*/
int GetRadius() const {return m_nRadius;}
// public virtual functions
/*!
* \brief Draw arrow shape at the end of a virtual line.
* \param from Start of the virtual line
* \param to End of the virtual line
* \param dc Device context for drawing
*/
virtual void Draw(const wxRealPoint& from, const wxRealPoint& to, wxDC& dc);
protected:
// protected data members
/*! \brief Circle radius */
int m_nRadius;
};
#endif //_WXSFCIRCLEARROW_H

View File

@@ -0,0 +1,84 @@
/***************************************************************
* Name: CircleShape.h
* Purpose: Defines circle shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFCIRCLESHAPE_H
#define _WXSFCIRCLESHAPE_H
#include <wx/wxsf/FixedRectShape.h>
/*! \brief Class encapsulating the circle shape. */
class WXDLLIMPEXP_SF wxSFCircleShape : public wxSFSquareShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFCircleShape);
/*! \brief Default constructor. */
wxSFCircleShape(void);
/*! \brief
* User constructor.
* \param pos Initial shape position
* \param radius Circle radius
* \param manager Pointer to parent manager
*/
wxSFCircleShape(const wxRealPoint& pos, double radius, wxSFDiagramManager* manager);
/*! \brief
* Copy constructor.
* \param obj Reference to the source object
*/
wxSFCircleShape(const wxSFCircleShape& obj);
/*! \brief Destructor. */
virtual ~wxSFCircleShape();
// public virtual functions
/*!
* \brief Test whether the given point is inside the shape. The function
* can be overrided if neccessary.
* \param pos Examined point
* \return TRUE if the point is inside the shape area, otherwise FALSE
*/
virtual bool Contains(const wxPoint& pos);
/*!
* \brief Get intersection point of the shape border and a line leading from
* 'start' point to 'end' point. The function can be overrided if neccessary.
* \param start Starting point of the virtual intersection line
* \param end Ending point of the virtual intersection line
* \return Intersection point
*/
virtual wxRealPoint GetBorderPoint(const wxRealPoint& start, const wxRealPoint& end);
protected:
// protected virtual functions
/*!
* \brief Draw the shape in the normal way. The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawNormal(wxDC& dc);
/*!
* \brief Draw the shape in the hower mode (the mouse cursor is above the shape).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHover(wxDC& dc);
/*!
* \brief Draw the shape in the highlighted mode (another shape is dragged over this
* shape and this shape will accept the dragged one if it will be dropped on it).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHighlighted(wxDC& dc);
/*!
* \brief Draw shadow under the shape. The function can be overrided if neccessary.
* \param dc Reference to device context where the shadow will be drawn to
*/
virtual void DrawShadow(wxDC& dc);
};
#endif //_WXSFCIRCLESHAPE_H

View File

@@ -0,0 +1,45 @@
/***************************************************************
* Name: CommonFcn.h
* Purpose: Defines set of global (auxiliary) functions
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFCOMMONFCN_H
#define _WXSFCOMMONFCN_H
#include <wx/wxprec.h>
#include <wx/xml/xml.h>
#include <wx/wxsf/Defs.h>
namespace wxSFCommonFcn
{
// data conversion functions
WXDLLIMPEXP_SF wxPoint Conv2Point(const wxRealPoint& pt);
WXDLLIMPEXP_SF wxSize Conv2Size(const wxRealPoint& pt);
WXDLLIMPEXP_SF wxRealPoint Conv2RealPoint(const wxPoint& pt);
// graphics functions
WXDLLIMPEXP_SF wxColour GetHybridColour(const wxColour& orig, const wxColour& modificator);
WXDLLIMPEXP_SF bool LinesIntersection(const wxRealPoint& from1, const wxRealPoint& to1, const wxRealPoint& from2, const wxRealPoint& to2, wxRealPoint& i);
WXDLLIMPEXP_SF double Distance(const wxRealPoint& pt1, const wxRealPoint& pt2);
}
namespace wxSF
{
enum ERRCODE
{
errOK = 0,
errNOT_CREATED,
errNOT_ACCEPTED,
errINVALID_INPUT
};
WXDLLIMPEXP_SF extern const double PI;
}
#endif //_WXSFCOMMONFCN_H

View File

@@ -0,0 +1,311 @@
/***************************************************************
* Name: ControlShape.h
* Purpose: Defines GUI control shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2008-04-30
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFCONTROLSHAPE_H
#define _WXSFCONTROLSHAPE_H
#include <wx/wxsf/RectShape.h>
#define sfFIT_SHAPE_TO_CONTROL true
#define sfFIT_CONTROL_TO_SHAPE false
#define sfdvCONTROLSHAPE_CONTROLOFFSET 0
#define sfdvCONTROLSHAPE_PROCESSEVENTS wxSFControlShape::evtKEY2CANVAS | wxSFControlShape::evtMOUSE2CANVAS
#define sfdvCONTROLSHAPE_MODFILL wxBrush(*wxBLUE, wxBDIAGONAL_HATCH)
#define sfdvCONTROLSHAPE_MODBORDER wxPen(*wxBLUE, 1, wxSOLID)
class WXDLLIMPEXP_SF wxSFControlShape;
/*!
* \brief Auxiliary class used by wxSFControlShape. All events generated by a GUI control (widget)
* managed by parent control shape are redirected to this event sink which invokes a default event handler
* or send a copy of the event to shape canvas if requested.
*/
class EventSink : public wxEvtHandler
{
public:
/*! \brief Default constructor. */
EventSink();
/*!
* \brief User constructor.
* \param parent Pointer to parent control shape
*/
EventSink(wxSFControlShape *parent);
/*! \brief Destructor. */
virtual ~EventSink();
// public functions
/*!
* \brief Event handler used for delayed processing of a mouse button events.
* The handler creates new key event instance and sends it to a shape canvas for further processing.
* \param event Mouse event
*/
void _OnMouseButton(wxMouseEvent &event);
/*!
* \brief Event handler used for delayed processing of a mouse event (mouse movement).
* The handler creates new key event instance and sends it to a shape canvas for further processing.
* \param event Mouse event
*/
void _OnMouseMove(wxMouseEvent &event);
/*!
* \brief Event handler used for delayed processing of a key event.
* The handler creates new key event instance and sends it to a shape canvas for further processing.
* \param event Keyboard event
*/
void _OnKeyDown(wxKeyEvent &event);
/*! \brief Event handler used for adjusting the parent shape's size in accordance to size of managed GUI control. */
void _OnSize(wxSizeEvent &event);
protected:
// protected data members
/*! \brief Poineter to parent contol shape. */
wxSFControlShape *m_pParentShape;
// protected functions
/*!
* \brief Send copy of incomming event to a shape canvas.
* \param event Event to be send
*/
void SendEvent(wxEvent &event);
/*!
* \brief Modify given mouse event (recalculate the event's position in accordance to parent control
* shape's position.
* \param event Mouse event to be updated;
*/
void UpdateMouseEvent(wxMouseEvent &event);
};
/*!
* \brief Class encapsulates a special shape able to manage assigned GUI controls (widgets). The GUI control's
* position and size can by modified via parent control shape. User can also specify how events incoming from the
* managed GUI control are processed.
*
* Note that the managed controls use a shape canvas as their parent window so these shapes cannot be used
* without existing and properly initialized shape canvas. Moreover, managed GUI controls are not serialized in any
* way internaly so it is completely up to the user to provide this functionality if needed.
*/
class WXDLLIMPEXP_SF wxSFControlShape : public wxSFRectShape
{
public:
friend class EventSink;
XS_DECLARE_CLONABLE_CLASS(wxSFControlShape)
/*! \brief Way of processing of GUI control's events. */
enum EVTPROCESSING
{
/*! \brief Event isn't processed. */
evtNONE = 0,
/*! \brief Keyboard events are processed by the GUI control. */
evtKEY2GUI = 1,
/*! \brief Keyboard events are send to a shape canvas. */
evtKEY2CANVAS = 2,
/*! \brief Mouse events are processed by the GUI control. */
evtMOUSE2GUI = 4,
/*! \brief Mouse events are send to a shape canvas. */
evtMOUSE2CANVAS = 8
};
/*! \brief Default constructor. */
wxSFControlShape();
/*!
* \brief User constructor.
* \param ctrl Pointer to managed GUI control
* \param pos Initial position
* \param size Initial size
* \param manager Pointer to parent diagram manager
*/
wxSFControlShape(wxWindow *ctrl, const wxRealPoint& pos, const wxRealPoint& size, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Object to copy from
*/
wxSFControlShape(const wxSFControlShape& obj);
/*! \brief Default destructor. */
virtual ~wxSFControlShape();
// member data accessors
/*!
* \brief Set managed GUI control.
* \param ctrl Pointer to existing manager GUI control
* \param fit TRUE if the control shape should be resized in accordance to the given GUI control
*/
void SetControl(wxWindow * ctrl, bool fit = sfFIT_SHAPE_TO_CONTROL);
/*!
* \brief Get pointer to managed GUI control.
* \return Pointer to the GUI control
*/
wxWindow * GetControl() { return m_pControl; }
/*!
* \brief Set a way how GUI control's events are processed.
* \param mask Event processing
* \sa EVTPROCESSING
*/
void SetEventProcessing(int mask){m_nProcessEvents = mask;}
/*!
* \brief Get a way how GUI control's events are processed.
* \return Combination of EVTPROCESSING flags
* \sa EVTPROCESSING
*/
int GetEventProcessing(){return m_nProcessEvents;}
/*!
* \brief Set control shape's background style used during its modification.
* \param brush Reference to used brush
*/
void SetModFill(const wxBrush& brush){m_ModFill = brush;}
/*!
* \brief Get control shape's background style used during its modification.
* \return Used brush
*/
wxBrush GetModFill(){return m_ModFill;}
/*!
* \brief Set control shape's border styl used during its modification.
* \param pen Reference to used pen
*/
void SetModBorder(const wxPen& pen){m_ModBorder = pen;}
/*!
* \brief Get control shape's border styl used during its modification.
* \return Used pen
*/
wxPen GetModBorder(){return m_ModBorder;}
/*!
* \brief Set control shape's offset (a gap between the shape's border and managed GUI control).
* \param offset Offset size
*/
void SetControlOffset(int offset){m_nControlOffset = offset;}
/*!
* \brief Get control shape's offset (a gap between the shape's border and managed GUI control).
* \return Offset size
*/
int GetControlOffset(){return m_nControlOffset;}
// public functions
/*! \brief Update size and position of the managed control according to the parent shape. */
void UpdateControl();
/*! \brief Update size of the shape position according to the managed control. */
void UpdateShape();
// public virtual functions
/*!
* \brief Scale the shape size by in both directions. The function can be overrided if necessary
* (new implementation should call default one ore scale shape's children manualy if neccesary).
* \param x Horizontal scale factor
* \param y Vertical scale factor
* \param children TRUE if the shape's children shoould be scaled as well, otherwise the shape will be updated after scaling via Update() function.
*/
virtual void Scale(double x, double y, bool children = sfWITHCHILDREN);
/*!
* \brief Move the shape to the given absolute position. The function can be overrided if necessary.
* \param x X coordinate
* \param y Y coordinate
*/
virtual void MoveTo(double x, double y);
/*!
* \brief Move the shape by the given offset. The function can be overrided if neccessary.
* \param x X offset
* \param y Y offset
*/
virtual void MoveBy(double x, double y);
/*! \brief Upate shape (align all child shapes an resize it to fit them) */
virtual void Update();
/*! \brief Resize the shape to bound all child shapes. The function can be overrided if neccessary. */
virtual void FitToChildren();
/*!
* \brief Event handler called at the begining of the shape dragging process.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* Default implementation does nothing.
* \sa wxSFShapeCanvas
*/
virtual void OnBeginDrag(const wxPoint& pos);
/*!
* \brief Event handler called at the end of the shape dragging process.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* Default implementation does nothing.
* \param pos Current mouse position
* \sa wxSFShapeCanvas
*/
virtual void OnEndDrag(const wxPoint& pos);
/*!
* \brief Event handler called when the user started to drag the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* Default implementation does nothing.
* \param handle Reference to dragged handle
*/
virtual void OnBeginHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* Default implementation does nothing.
* \param handle Reference to dragged handle
*/
virtual void OnHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called when the user finished dragging of the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* Default implementation does nothing.
* \param handle Reference to dragged handle
*/
virtual void OnEndHandle(wxSFShapeHandle& handle);
protected:
// protected data members
/*! \brief Pointer to manager data control. */
wxWindow * m_pControl;
/*! \brief Events processing mask */
int m_nProcessEvents;
/*! \brief Brush used during the shape's modification. */
wxBrush m_ModFill;
/*! \brief Pen used during the shape's modification. */
wxPen m_ModBorder;
/*! \brief Offset between the shape and managed GUI control. */
int m_nControlOffset;
// protected functions
private:
// private data members
/*! \brief Pointer to parent window. */
wxWindow * m_pPrevParent;
/*! \brief Pointer to event sink.*/
EventSink * m_pEventSink;
/*! \brief Previous canvas style. */
long m_nPrevStyle;
/*! \brief Previously used shape's brush. */
wxBrush m_PrevFill;
/*! \brief Previously used shape's pen. */
wxPen m_PrevBorder;
// private functions
/*! \brief Initialize serializable properties. */
void MarkSerializableDataMembers();
};
#endif //_WXSFCONTROLSHAPE_H

View File

@@ -0,0 +1,82 @@
/***************************************************************
* Name: CurveShape.h
* Purpose: Defines curve shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFCURVESHAPE_H
#define _WXSFCURVESHAPE_H
#include <wx/wxsf/LineShape.h>
/*!
* \brief Interpolation line shape. The class extends wxSFLineShape class and allows
* user to create curved connection line.
*/
class WXDLLIMPEXP_SF wxSFCurveShape : public wxSFLineShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFCurveShape);
/*! \brief Default constructor. */
wxSFCurveShape();
/*!
* \brief User constructor.
* \param src ID of the source shape
* \param trg ID of the target shape
* \param path Array of line's control points
* \param manager Parent parent diagram manager
*/
wxSFCurveShape(long src, long trg, const wxXS::RealPointList& path, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFCurveShape(const wxSFCurveShape& obj);
/*! \brief Destructor. */
virtual ~wxSFCurveShape();
// public virtual function
/*!
* \brief Get line's bounding box. The function can be overrided if neccessary.
* \return Bounding rectangle
*/
virtual wxRect GetBoundingBox();
// public functions
/*!
* \brief Get a line point laying on the given line segment and shifted
* from the beggining of the segment by given offset.
* \param segment Zero-based index of the line segment
* \param offset Real value in the range from 0 to 1 which determines
* the linepoint offset inside the line segment
* \return Line point
*/
wxRealPoint GetPoint(size_t segment, double offset);
protected:
// protected virtual functions
/*!
* \brief Internal function used for drawing of completed line shape.
* \param dc Refernce of the device context where the shape will be darwn to
*/
virtual void DrawCompleteLine(wxDC& dc);
private:
// private functions
/*! \brief Auxiliary drawing function. */
void GetSegmentQuaternion(size_t segment, wxRealPoint& A, wxRealPoint& B, wxRealPoint& C, wxRealPoint& D);
/*! \brief Auxiliary drawing function. */
void Catmul_Rom_Kubika(const wxRealPoint& A, const wxRealPoint& B, const wxRealPoint& C, const wxRealPoint& D, wxDC& dc);
/*! \brief Auxiliary drawing function. */
wxRealPoint Coord_Catmul_Rom_Kubika(const wxRealPoint& p1, const wxRealPoint& p2, const wxRealPoint& p3, const wxRealPoint& p4, double t);
};
#endif //_WXSFCURVESHAPE_H

View File

@@ -0,0 +1,21 @@
#ifndef _WXSFDEFS_H
#define _WXSFDEFS_H
#ifdef USING_SOURCE_SF
#define WXDLLIMPEXP_SF
#define WXDLLIMPEXP_DATA_SF(type) type
#elif defined( LIB_USINGDLL )
#define WXDLLIMPEXP_SF
#define WXDLLIMPEXP_DATA_SF(type)
#elif defined( WXMAKINGDLL_WXSF )
#define WXDLLIMPEXP_SF WXEXPORT
#define WXDLLIMPEXP_DATA_SF(type) WXEXPORT type
#elif defined(WXUSINGDLL)
#define WXDLLIMPEXP_SF WXIMPORT
#define WXDLLIMPEXP_DATA_SF(type) WXIMPORT type
#else // not making nor using DLL
#define WXDLLIMPEXP_SF
#define WXDLLIMPEXP_DATA_SF(type) type
#endif
#endif//_WXSFDEFS_H

View File

@@ -0,0 +1,345 @@
/***************************************************************
* Name: DiagramManager.h
* Purpose: Defines shape manager class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-25
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFDIAGRAMMANAGER_H
#define _WXSFDIAGRAMMANAGER_H
#include <wx/wxsf/ShapeBase.h>
#include <wx/wxsf/CommonFcn.h>
#define serINCLUDE_PARENTS true
#define serWITHOUT_PARENTS false
#define sfINITIALIZE true
#define sfDONT_INITIALIZE false
class wxSFShapeCanvas;
class wxSFLineShape;
/*! \brief Auxiliary class encapsulation two variables suitable for shape IDs. It is
* used for storing infomation about various relevant shape IDs */
class IDPair : public wxObject
{
public:
/*! \brief Constructor */
IDPair(long oldId, long newId){m_nOldID = oldId; m_nNewID = newId;}
long m_nNewID;
long m_nOldID;
};
WX_DECLARE_LIST(IDPair, IDList);
/*! \brief Class encapsulating framework's data layer. Its functions are responsible
* for managing shape objects and their serialialization/deserialization. Presentation
* layer is provided by wxSFShapeCanvas class which tightly cooperates with the shape
* manager.
*
* An application using wxSF must have at least one shape manager object (one for
* each diagram) and every shape manager can be assigned as a source to one shape
* canvas (and vice versa).
*/
class WXDLLIMPEXP_SF wxSFDiagramManager : public wxXmlSerializer
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFDiagramManager);
/*! \brief Search mode flags for GetShapeAtPosition function */
enum SEARCHMODE
{
/*! \brief Search for selected shapes only */
searchSELECTED,
/*! \brief Search for unselected shapes only */
searchUNSELECTED,
/*! \brief Search for both selected and unselected shapes */
searchBOTH
};
/*! \brief Constructor */
wxSFDiagramManager();
/*! \brief Copy constructor */
wxSFDiagramManager(const wxSFDiagramManager &obj);
/*! \brief Destructor */
virtual ~wxSFDiagramManager();
// public functions
/*! \brief Get wxShapeFramework version number */
const wxString& GetVersion() const { return m_sSFVersion; }
/*!
* \brief Create new direct connection between two shapes.
*
* This function creates new simple connection line (without arrows) between gived
* shapes.
* \param srcId ID of a source shape
* \param trgId ID of target shape
* \param saveState Set the parameter TRUE if you wish to save canvas state after the operation
* \param err Pointer to variable where operation result will be stored. Can be NULL.
* \return Pointer to new connection object. The object is added to the shape canvas automaticaly.
* \sa StartInteractiveConnection
*/
wxSFShapeBase* CreateConnection(long srcId, long trgId, bool saveState = true, wxSF::ERRCODE *err = NULL);
/*!
* \brief Create new direct connection of given type between two shapes.
*
* This function creates new simple connection line (without arrows) between gived
* shapes.
* \param srcId ID of a source shape
* \param trgId ID of target shape
* \param lineInfo Connection type (any class inherited from wxSFLineShape)
* \param saveState Set the parameter TRUE if you wish to save canvas state after the operation
* \param err Pointer to variable where operation result will be stored. Can be NULL.
* \return Pointer to new connection object. The object is added to the shape canvas automaticaly.
* \sa StartInteractiveConnection
*/
wxSFShapeBase* CreateConnection(long srcId, long trgId, wxClassInfo *lineInfo, bool saveState = true, wxSF::ERRCODE *err = NULL);
/*!
* \brief Create new direct connection of given type between two shapes.
*
* This function creates new simple connection line (without arrows) between gived
* shapes.
* \param srcId ID of a source shape
* \param trgId ID of target shape
* \param line Pointer to line shape
* \param saveState Set the parameter TRUE if you wish to save canvas state after the operation
* \param err Pointer to variable where operation result will be stored. Can be NULL.
* \return Pointer to new connection object. The object is added to the shape canvas automaticaly.
* \sa StartInteractiveConnection
*/
wxSFShapeBase* CreateConnection(long srcId, long trgId, wxSFLineShape *line, bool saveState = true, wxSF::ERRCODE *err = NULL);
/*!
* \brief Create new shape and add it to the shape canvas.
* \param shapeInfo Shape type
* \param saveState Set the parameter TRUE if you wish to save canvas state after the operation
* \param err Pointer to variable where operation result will be stored. Can be NULL.
* \return Pointer to new shape object. The object is added to the shape canvas automaticaly.
*/
wxSFShapeBase* AddShape(wxClassInfo* shapeInfo, bool saveState = true, wxSF::ERRCODE *err = NULL);
/*!
* \brief Create new shape and add it to the shape canvas.
* \param shapeInfo Shape type
* \param pos Shape position
* \param saveState Set the parameter TRUE if you wish to save canvas state after the operation
* \param err Pointer to variable where operation result will be stored. Can be NULL.
* \return Description
* \sa Seealso
*/
wxSFShapeBase* AddShape(wxClassInfo* shapeInfo, const wxPoint& pos, bool saveState = true, wxSF::ERRCODE *err = NULL);
/*!
* \brief Add an existing shape to the canvas.
* \param shape Pointer to the shape
* \param parent Pointer to the parent shape
* \param pos Position
* \param initialize TRUE if the shape should be reinitilialized, otherwise FALSE
* \param saveState TRUE if the canvas state should be saved
* \param err Pointer to variable where operation result will be stored. Can be NULL.
* \return Pointer to the shape
*/
wxSFShapeBase* AddShape(wxSFShapeBase* shape, xsSerializable* parent, const wxPoint& pos, bool initialize, bool saveState = true, wxSF::ERRCODE *err = NULL);
/*!
* \brief Remove given shape from the shape canvas. The shape object will be deleted as well.
* \param shape Pointer to shape object should be deleted
* \param refresh Set the paramater to TRUE if you wish to repaint the canvas
*/
void RemoveShape(wxSFShapeBase* shape, bool refresh = true);
/*!
* \brief Remove shapes from the shape canvas
* \param selection List of shapes which should be removed from the canvas
*/
void RemoveShapes(const ShapeList& selection);
/*! \brief Remove all shapes from canvas */
void Clear();
/*! \brief Move all shapes so none of it will be located in negative position */
void MoveShapesFromNegatives();
/*! \brief Update all shapes in the diagram manager */
void UpdateAll();
/*!
* \brief Serialize complete shape canvas to given file
* \param file Output file
* \param withroot If TRUE then the root item's properties are serialized as well
* \return TRUE on success, otherwise FALSE
*/
virtual bool SerializeToXml(const wxString& file, bool withroot = false);
/*!
* \brief Deserialize complete shape canvas from given file
* \param file Input file
* \return TRUE on success, otherwise FALSE
*/
virtual bool DeserializeFromXml(const wxString& file);
/*!
* \brief Serialize complete shape canvas to given output stream
* \param outstream Output stream
* \param withroot If TRUE then the root item's properties are serialized as well
* \return TRUE on success, otherwise FALSE
*/
virtual bool SerializeToXml(wxOutputStream& outstream, bool withroot = false);
/*!
* \brief Deserialize complete shape canvas from given input stream
* \param instream Input stream
* \return TRUE on success, otherwise FALSE
*/
virtual bool DeserializeFromXml(wxInputStream& instream);
/*!
* \brief Deserialize shapes from XML and assign them to given parent.
*
* The parent can be NULL (in that case topmost shapes will have no parent assigned).
* \param parent Parent shapes
* \param node Source XML node
*/
virtual void DeserializeObjects(xsSerializable* parent, wxXmlNode* node);
/*!
* \brief Add given shape type to an acceptance list. The acceptance list contains class
* names of the shapes which can be inserted into this instance of shapes canvas.
* Note: Keyword 'All' behaves like any class name.
* \param type Class name of accepted shape object
* \sa IsShapeAccepted
*/
void AcceptShape(const wxString& type);
/*!
* \brief Tells whether the given shape type is accepted by this canvas instance (it means
* whether this shape can be inserted into it).
*
* The function is typically used by the framework for determination whether class type supplied
* by AddShape() function can be inserted into shape canvas.
* \param type Class name of examined shape object
* \return TRUE if the shape type is accepted, otherwise FALSE.
*/
bool IsShapeAccepted(const wxString& type);
/*!
* \brief Clear shape object acceptance list
* \sa AcceptShape
*/
inline void ClearAcceptedShapes() { m_arrAcceptedShapes.Clear(); }
/*!
* \brief Get reference to shape acceptance list
*/
inline wxArrayString& GetAcceptedShapes() { return m_arrAcceptedShapes; }
/*!
* \brief Find shape with given ID.
* \param id Shape's ID
* \return Pointer to shape if exists, otherwise NULL
*/
wxSFShapeBase* FindShape(long id);
/*!
* \brief Get list of connections assigned to given parent shape.
* \param parent Pointer to parent shape
* \param shapeInfo Line object type
* \param mode Search mode
* \param lines Reference to shape list where pointers to all found connections will be stored
* \sa wxSFShapeBase::CONNECTMODE
*/
void GetAssignedConnections(wxSFShapeBase* parent, wxClassInfo* shapeInfo, wxSFShapeBase::CONNECTMODE mode, ShapeList& lines);
/*!
* \brief Get list of shapes of given type.
* \param shapeInfo Shape object type
* \param shapes Reference to shape list where pointers to all found shapes will be stored
* \param mode Search algorithm
* \sa xsSerializable::SEARCHMODE
*/
void GetShapes(wxClassInfo* shapeInfo, ShapeList& shapes, xsSerializable::SEARCHMODE mode = xsSerializable::searchBFS);
/*!
* \brief Get shape at given logical position
* \param pos Logical position
* \param zorder Z-order of searched shape (usefull if several shapes are located at the given position)
* \param mode Search mode
* \return Pointer to shape if found, otherwise NULL
* \sa SEARCHMODE, wxSFShapeCanvas::DP2LP,, wxSFShapeCanvas::GetShapeUnderCursor
*/
wxSFShapeBase* GetShapeAtPosition(const wxPoint& pos, int zorder = 1, SEARCHMODE mode = searchBOTH);
/*!
* \brief Get list of all shapes located at given position
* \param pos Logical position
* \param shapes Reference to shape list where pointers to all found shapes will be stored
* \sa wxSFShapeCanvas::DP2LP
*/
void GetShapesAtPosition(const wxPoint& pos, ShapeList& shapes);
/*!
* \brief Get list of shapes located inside given rectangle
* \param rct Examined rectangle
* \param shapes Reference to shape list where pointers to all found shapes will be stored
*/
void GetShapesInside(const wxRect& rct, ShapeList& shapes);
/*!
* \brief Determines whether the diagram manager contains some shapes.
* \return TRUE if there are no shapes in the manager, otherwise FALSE
*/
inline bool IsEmpty() const { return ! GetRootItem()->HasChildren(); }
/*!
* \brief Function finds out whether given shape has some children.
* \param parent Pointer to potential parent shape
* \return TRUE if the parent shape has children, otherwise FALSE
*/
bool HasChildren(wxSFShapeBase* parent);
/*!
* \brief Get neighbour shapes connected to given parent shape.
* \param parent Pointer to parent shape (can be NULL for all topmost shapes)
* \param neighbours List of neighbour shapes
* \param shapeInfo Line object type
* \param condir Connection direction
* \param direct Set this flag to TRUE if only closest shapes should be found,
* otherwise also shapes connected by forked lines will be found (also
* constants sfDIRECT and sfINDIRECT can be used)
* \sa wxSFShapeBase::CONNECTMODE
*/
void GetNeighbours(wxSFShapeBase* parent, ShapeList& neighbours, wxClassInfo* shapeInfo, wxSFShapeBase::CONNECTMODE condir, bool direct = true);
// public member data accessors
/*!
* \brief Set associated shape canvas
* \param canvas Pointer to shape canvas
*/
inline void SetShapeCanvas(wxSFShapeCanvas* canvas) { m_pShapeCanvas = canvas; }
/*!
* \brief Get associated shape canvas
* \return Pointer to shape canvas
*/
inline wxSFShapeCanvas* GetShapeCanvas() { return m_pShapeCanvas; }
protected:
// protected data members
/*! \brief List of accepted shape types */
wxArrayString m_arrAcceptedShapes;
wxSFShapeCanvas* m_pShapeCanvas;
private:
/*! \brief Auxiliary list */
IDList m_lstIDPairs;
/*! \brief Auxiliary list */
ShapeList m_lstLinesForUpdate;
/*! \brief Auxiliary list */
ShapeList m_lstGridsForUpdate;
/*! \brief wxSF version number */
wxString m_sSFVersion;
/*! \brief Update connection shapes after importing/dropping of new shapes */
void UpdateConnections();
/*! \brief Update grid shapes after importing/dropping of new shapes */
void UpdateGrids();
/*!
* \brief Deserialize shapes from XML and assign them to given parent.
* \param parent Parent shapes
* \param node Source XML node
*/
void _DeserializeObjects(xsSerializable* parent, wxXmlNode* node);
};
#endif //_WXSFDIAGRAMMANAGER_H

View File

@@ -0,0 +1,51 @@
/***************************************************************
* Name: DiamondArrow.h
* Purpose: Defines diamond arrow for line shapes
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2009-04-18
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFDIAMONDARROW_H
#define _WXSFDIAMONDARROW_H
#include <wx/wxsf/SolidArrow.h>
/*!
* \brief Class extends the wxSFSolidArrow class and encapsulates
* arrow shape consisting of filled diamond located the end of the
* parent line shape.
*/
class WXDLLIMPEXP_SF wxSFDiamondArrow : public wxSFSolidArrow
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFDiamondArrow);
/*! \brief Default constructor. */
wxSFDiamondArrow(void);
/*!
* \brief User constructor.
* \param parent"> Pointer to the parent shape
*/
wxSFDiamondArrow(wxSFShapeBase* parent);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFDiamondArrow(const wxSFDiamondArrow& obj);
/*! \brief Destructor. */
virtual ~wxSFDiamondArrow(void);
// public virtual functions
/*!
* \brief Draw arrow shape at the end of a virtual line.
* \param from Start of the virtual line
* \param to End of the virtual line
* \param dc Device context for drawing
*/
virtual void Draw(const wxRealPoint& from, const wxRealPoint& to, wxDC& dc);
};
#endif //_WXSFDIAMONDARROW_H

View File

@@ -0,0 +1,51 @@
/***************************************************************
* Name: DiamondShape.h
* Purpose: Defines diamond shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFDIAMONDSHAPE_H
#define _WXSFDIAMONDSHAPE_H
#include <wx/wxsf/PolygonShape.h>
/*!
* \brief Class encapsulating the diamond shape. It extends the basic polygon shape.
* \sa wxSFPolygonShape
*/
class WXDLLIMPEXP_SF wxSFDiamondShape : public wxSFPolygonShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFDiamondShape);
/*! \brief Default constructor. */
wxSFDiamondShape();
/*!
* \brief User constructor.
* \param pos Initial position
* \param manager Pointer to parent diagram manager
*/
wxSFDiamondShape(const wxRealPoint& pos, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFDiamondShape(const wxSFDiamondShape& obj);
/*! \brief Destructor. */
virtual ~wxSFDiamondShape();
// public virtual functions
/*!
* \brief Test whether the given point is inside the shape. The function
* can be overrided if neccessary.
* \param pos Examined point
* \return TRUE if the point is inside the shape area, otherwise FALSE
*/
virtual bool Contains(const wxPoint& pos);
};
#endif //_WXSFDIAMONDSHAPE_H

View File

@@ -0,0 +1,204 @@
/***************************************************************
* Name: EditTextShape.h
* Purpose: Defines editable text shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFEDITTEXTSHAPE_H
#define _WXSFEDITTEXTSHAPE_H
#include <wx/wxsf/TextShape.h>
#define sfCANCEL_TEXT_CHANGES false
#define sfAPPLY_TEXT_CHANGES true
/*! \brief Default value of wxSFEditTextShape::m_fForceMultiline data member */
#define sfdvEDITTEXTSHAPE_FORCEMULTILINE false
/*! \brief Default value of wxSFEditTextShape::m_nEditType data member */
#define sfdvEDITTEXTSHAPE_EDITTYPE wxSFEditTextShape::editINPLACE
class WXDLLIMPEXP_SF wxSFEditTextShape;
/*!
* \brief Auxiliary class providing neccessary functionality needed for in-place
* modification of a content of the text shape. </summary>
* \sa wxSFEditTextShape
*/
class wxSFContentCtrl : public wxTextCtrl
{
public:
/*!
* \brief Constructor.
* \param parent Pointer to the parent window
* \param id ID of the text control window
* \param parentShape Pointer to the parent editable text shape
* \param content Initial content of the text control
* \param pos Initial position
* \param size Initial size
* \param style Window style
*/
wxSFContentCtrl(wxWindow* parent, wxWindowID id, wxSFEditTextShape* parentShape, const wxString& content, wxPoint pos, wxSize size, int style);
/*!
* \brief Finish the editing process/
* \param apply If TRUE then changes made in eddited text will be applied on text shape, otherwise it will be canceled
*/
void Quit( bool apply = sfAPPLY_TEXT_CHANGES );
protected:
wxWindow* m_pParent;
wxSFEditTextShape* m_pParentShape;
wxString m_sPrevContent;
/*!
* \brief Event handler called if the text control lost the focus.
* \param event Reference to the event class instance
*/
void OnKillFocus(wxFocusEvent& event);
/*!
* \brief Event handler called if the key was pressed in the text control.
* \param event Reference to the event class instance
*/
void OnKeyDown(wxKeyEvent& event);
DECLARE_EVENT_TABLE();
};
/*!
* \brief Auxiliary class providing neccessary functionality needed for dialog-based
* modification of a content of the text shape. </summary>
* \sa wxSFEditTextShape
*/
class wxSFDetachedContentCtrl : public wxDialog
{
public:
/*!
* \brief Constructor.
* \param parent Pointer to the parent window
* \param id ID of the text control window
* \param title Dialog's title
* \param pos Initial position
* \param size Initial size
* \param style Window style
*/
wxSFDetachedContentCtrl( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Edit content"),
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
/*! \brief Destructor. */
~wxSFDetachedContentCtrl();
// public member data accessors
/**
* \brief Set content of dialog's text edit control.
* \param txt Text content
*/
void SetContent(const wxString& txt){ m_pText->SetValue( txt ); }
/**
* \brief Get content of dialog's text edit control.
* \return Edited text
*/
wxString GetContent() const { return m_pText->GetValue(); }
protected:
// protected data members
wxTextCtrl* m_pText;
};
/*!
* \brief Class encapsulating the editable text shape. It extends the basic text shape.
* \sa wxSFTextShape
*/
class WXDLLIMPEXP_SF wxSFEditTextShape : public wxSFTextShape
{
public:
friend class wxSFContentCtrl;
XS_DECLARE_CLONABLE_CLASS(wxSFEditTextShape);
enum EDITTYPE
{
editINPLACE = 0,
editDIALOG,
editDISABLED
};
/*! \brief Default constructor. */
wxSFEditTextShape(void);
/*!
* \brief User constructor.
* \param pos Initial position
* \param txt Text content
* \param manager Pointer to the parent canvas
*/
wxSFEditTextShape(const wxRealPoint& pos, const wxString& txt, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFEditTextShape(const wxSFEditTextShape& obj);
/*! \brief Destructor. */
virtual ~wxSFEditTextShape(void);
// public member data accessors
/**
* \brief Set way how the text shape's content can be edited.
* \param type Edit control type
* \sa EDITTYPE
*/
void SetEditType( EDITTYPE type) { m_nEditType = type; }
/**
* \brief Get current type of text shape's edit control.
* \return Type of edit control
* \sa EDITTYPE
*/
const EDITTYPE& GetEditType() const { return m_nEditType; }
/*!
* \brief Get pointer to assigned text control allowing user to change the
* shape's content directly in the canvas.
* \return Pointer to instance of wxSFContentCtrl class
*/
wxSFContentCtrl* GetTextCtrl() {return m_pTextCtrl;}
// public functions
/*! \brief Switch the shape to a label editation mode. */
void EditLabel();
/*! \brief Force the edit text control to be multiline
* \param multiline If TRUE then the associated text control will be allways multiline
*/
void ForceMultiline(bool multiline){m_fForceMultiline = multiline;}
// public virtual functions
/*!
* \brief Event handler called when the shape was double-clicked.
* The function can be overrided if neccessary.
* \param pos Mouse position.
*/
virtual void OnLeftDoubleClick(const wxPoint& pos);
/*!
* \brief Event handler called when any key is pressed (in the shape canvas).
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* \param key The key code
* \return The function must return TRUE if the default event routine should be called
* as well, otherwise FALSE
* \sa wxSFShapeBase::OnKey
*/
virtual bool OnKey(int key);
protected:
wxSFContentCtrl* m_pTextCtrl;
long m_nCurrentState;
bool m_fForceMultiline;
EDITTYPE m_nEditType;
};
#endif //_WXSFEDITTEXTSHAPE_H

View File

@@ -0,0 +1,87 @@
/***************************************************************
* Name: EllipseShape.h
* Purpose: Defines ellipse shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFELLIPSESHAPE_H
#define _WXSFELLIPSESHAPE_H
#include <wx/wxsf/RectShape.h>
/*!
* \brief Class encapsulating the ellipse shape. It extends the basic rectangular shape.
* \sa wxSFRectShape
*/
class WXDLLIMPEXP_SF wxSFEllipseShape : public wxSFRectShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFEllipseShape);
/*! \brief Default constructor. */
wxSFEllipseShape(void);
/*!
* \brief User constructor.
* \param pos Initial position
* \param size Initial size
* \param manager Pointer to parent diagram manager
*/
wxSFEllipseShape(const wxRealPoint& pos, const wxRealPoint& size, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to the source shape
*/
wxSFEllipseShape(const wxSFEllipseShape& obj);
/*! \brief Destructor. */
virtual ~wxSFEllipseShape();
// public virtual functions
/*!
* \brief Test whether the given point is inside the shape. The function
* can be overrided if neccessary.
* \param pos Examined point
* \return TRUE if the point is inside the shape area, otherwise FALSE
*/
virtual bool Contains(const wxPoint& pos);
/*!
* \brief Get intersection point of the shape border and a line leading from
* 'start' point to 'end' point. The function can be overrided if neccessary.
* \param start Starting point of the virtual intersection line
* \param end Ending point of the virtual intersection line
* \return Intersection point
*/
virtual wxRealPoint GetBorderPoint(const wxRealPoint& start, const wxRealPoint& end);
protected:
// protected virtual functions
/*!
* \brief Draw the shape in the normal way. The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawNormal(wxDC& dc);
/*!
* \brief Draw the shape in the hower mode (the mouse cursor is above the shape).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHover(wxDC& dc);
/*!
* \brief Draw the shape in the highlighted mode (another shape is dragged over this
* shape and this shape will accept the dragged one if it will be dropped on it).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHighlighted(wxDC& dc);
/*!
* \brief Draw shadow under the shape. The function can be overrided if neccessary.
* \param dc Reference to device context where the shadow will be drawn to
*/
virtual void DrawShadow(wxDC& dc);
};
#endif //_WXSFELLIPSESHAPE_H

View File

@@ -0,0 +1,62 @@
/***************************************************************
* Name: FixedRectShape.h
* Purpose: Defines square shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFSQUARESHAPE_H
#define _WXSFSQUARESHAPE_H
#include <wx/wxsf/RectShape.h>
/*!
* \brief Class encapsulating the square shape. It extends the basic rectangular shape.
* \sa wxSFRectShape
*/
class WXDLLIMPEXP_SF wxSFSquareShape : public wxSFRectShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFSquareShape);
/*! \brief Default constructor. */
wxSFSquareShape(void);
/*!
* \brief User constructor.
* \param pos Initial position
* \param size Initial size
* \param manager Pointer to parent diagram manager
*/
wxSFSquareShape(const wxRealPoint& pos, double size, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFSquareShape(const wxSFSquareShape& obj);
/*! \brief Destructor. */
virtual ~wxSFSquareShape();
// public virtual functions
/*!
* \brief Scale the shape size by in both directions. The function can be overrided if necessary
* (new implementation should call default one ore scale shape's children manualy if neccesary).
* \param x Horizontal scale factor
* \param y Vertical scale factor
* \param children TRUE if the shape's children shoould be scaled as well, otherwise the shape will be updated after scaling via Update() function.
*/
virtual void Scale(double x, double y, bool children = sfWITHCHILDREN);
/*!
* \brief Event handler called during dragging of the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* Default implementation does nothing.
* \param handle Reference to dragged handle
*/
virtual void OnHandle(wxSFShapeHandle& handle);
};
#endif //_WXSFSQUARESHAPE_H

View File

@@ -0,0 +1,64 @@
/***************************************************************
* Name: FlexGridShape.h
* Purpose: Defines flexible grid shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2008-09-27
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFFLEXGRIDSHAPE_H
#define _WXSFFLEXGRIDSHAPE_H
#include <wx/wxsf/GridShape.h>
// default values
WX_DEFINE_ARRAY(wxSFShapeBase*, ShapePtrArray);
/*!
* \brief Class encapsulates a rectangular shape derived from wxSFGridShape class which acts as a flexible grid-based
* container able to manage other assigned child shapes (it can control their position). The managed
* shapes are aligned into defined grid with a behaviour similar to classic wxWidget's wxFlexGridSizer class.
*/
class WXDLLIMPEXP_SF wxSFFlexGridShape : public wxSFGridShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFFlexGridShape);
/*! \brief Default constructor. */
wxSFFlexGridShape();
/*!
* \brief User constructor.
* \param pos Initial position
* \param size Initial size
* \param rows Number of grid rows
* \param cols Number of grid columns
* \param cellspace Additional space between managed shapes
* \param manager Pointer to parent diagram manager
*/
wxSFFlexGridShape(const wxRealPoint& pos, const wxRealPoint& size, int rows, int cols, int cellspace, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFFlexGridShape(const wxSFFlexGridShape& obj);
/*! \brief Destructor. */
virtual ~wxSFFlexGridShape();
// public virtual functions
/*! \brief Do layout of assigned child shapes */
virtual void DoChildrenLayout();
private:
// private data members
wxXS::IntArray m_arrRowSizes;
wxXS::IntArray m_arrColSizes;
ShapePtrArray m_arrChildShapes;
};
#endif // _WXSFFLEXGRIDSHAPE_H

View File

@@ -0,0 +1,189 @@
/***************************************************************
* Name: GridShape.h
* Purpose: Defines grid shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2008-08-02
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFGRIDSHAPE_H
#define _WXSFGRIDSHAPE_H
#include <wx/wxsf/RectShape.h>
// default values
/*! \brief Default value of wxSFGridShape::m_nRows data member. */
#define sfdvGRIDSHAPE_ROWS 3
/*! \brief Default value of wxSFGridShape::m_nCols data member. */
#define sfdvGRIDSHAPE_COLS 3
/*! \brief Default value of wxSFGridShape::m_nCellSpace data member. */
#define sfdvGRIDSHAPE_CELLSPACE 5
/*!
* \brief Class encapsulates a rectangular shape derived from wxSFRectShape class which acts as a grid-based
* container able to manage other assigned child shapes (it can control their position). The managed
* shapes are aligned into defined grid with a behaviour similar to classic wxWidget's wxGridSizer class.
*/
class WXDLLIMPEXP_SF wxSFGridShape : public wxSFRectShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFGridShape);
friend class wxSFDiagramManager;
/*! \brief Default constructor. */
wxSFGridShape();
/*!
* \brief User constructor.
* \param pos Initial position
* \param size Initial size
* \param rows Number of grid rows
* \param cols Number of grid columns
* \param cellspace Additional space between managed shapes
* \param manager Pointer to parent diagram manager
*/
wxSFGridShape(const wxRealPoint& pos, const wxRealPoint& size, int rows, int cols, int cellspace, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFGridShape(const wxSFGridShape& obj);
/*! \brief Destructor. */
virtual ~wxSFGridShape();
// public member data accessors
/*!
* \brief Set grid dimensions.
* \param rows Number of rows
* \param cols Number of columns
*/
void SetDimensions(int rows, int cols);
/*!
* \brief Set space between grid cells (managed shapes).
* \param cellspace Cellspace size
*/
void SetCellSpace(int cellspace){m_nCellSpace = cellspace;}
/*!
* \brief Get grid dimensions.
* \param rows Pointer to variable where number of rows will be stored
* \param cols Pointer to variable where number of columns will be stored
*/
void GetDimensions(int *rows, int *cols);
/*!
* \brief Get space between grid cells (managed shapes).
* \return Cellspace size
*/
int GetCellSpace(){return m_nCellSpace;}
/*!
* \brief Get managed shape specified by lexicographic cell index.
* \param index Lexicographic index of requested shape
* \return Pointer to shape object of given cell index if exists, otherwise NULL
*/
wxSFShapeBase *GetManagedShape(size_t index);
/*!
* \brief Get managed shape specified by row and column indexes.
* \param row Zero-base row index
* \param col Zero-based column index
* \return Pointer to shape object stored in specified grid cell if exists, otherwise NULL
*/
wxSFShapeBase *GetManagedShape(int row, int col);
// public functions
/*!
* \brief Clear information about managed shapes and set number of rows and columns to zero.
*
* Note that this function doesn't remove managed (child) shapes from the parent grid shape
* (they are still its child shapes but aren't managed anymore).
*/
void ClearGrid();
/*!
* \brief Append given shape to the grid at the last managed position.
* \param shape Pointer to appended shape
*/
bool AppendToGrid(wxSFShapeBase *shape);
/*!
* \brief Insert given shape to the grid at the given position.
*
* Note that the grid can grow in a vertical direction only, so if the user specify desired
* horizontal position bigger than the current number of columns is then this function exits with
* an error (false) return value. If specified vertical position exceeds the number or grid rows than
* the grid is resized. If the given position (grid cell) is already occupied by some shape then the previous
* one will be moved to the grid's last lexicographic position.
* \param row Vertical position
* \param col Horizontal position
* \param shape Pointer to inserted shape
* \return True on success, otherwise False
*/
bool InsertToGrid(int row, int col, wxSFShapeBase *shape);
/*!
* \brief Insert given shape to the grid at the given position.
*
* Note that the given index is a lexicographic position of inserted shape. The given shape is inserted before
* the existing item 'index', thus InsertToGrid(0, something) will insert an item in such way that it will become
* the first grid element.
* \param index Lexicographic position of inserted shape
* \param shape Pointer to inserted shape
* \return True on successe, otherwise False
*/
bool InsertToGrid(int index, wxSFShapeBase *shape);
/**
* \brief Remove shape with given ID from the grid.
* \param id ID of shape which should be removed
*/
void RemoveFromGrid(long id);
// public virtual functions
/*! \brief Upate shape (align all child shapes an resize it to fit them) */
virtual void Update();
/*! \brief Resize the shape to bound all child shapes. The function can be overrided if neccessary. */
virtual void FitToChildren();
/*! \brief Do layout of assigned child shapes */
virtual void DoChildrenLayout();
/*!
* \brief Event handler called when any shape is dropped above this shape (and the dropped
* shape is accepted as a child of this shape). The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* \param pos Relative position of dropped shape
* \param child Pointer to dropped shape
*/
virtual void OnChildDropped(const wxRealPoint& pos, wxSFShapeBase *child);
protected:
// protected data members
/*! \brief Number of grid rows. */
int m_nRows;
/*! \brief Number of grid columns. */
int m_nCols;
/*! \brief Space additional space between managed shapes. */
int m_nCellSpace;
/*! \brief Array containing the IDs of managed shapes. */
wxXS::IntArray m_arrCells;
// protected functions
/*!
* \brief Move and resize given shape so it will fit the given bounding rectangle.
*
* The shape is aligned inside the given bounding rectangle in accordance to the shape's
* valign and halign flags.
* \param shape Pointer to modified shape
* \param rct Bounding rectangle
* \sa wxSFShapeBase::SetVAlign, wxSFShapeBase::SetHAlign
*/
void FitShapeToRect( wxSFShapeBase *shape, const wxRect& rct);
private:
// private functions
/*! \brief Initialize serializable properties. */
void MarkSerializableDataMembers();
};
#endif // _WXSFGRIDSHAPE_H

View File

@@ -0,0 +1,411 @@
/***************************************************************
* Name: LineShape.h
* Purpose: Defines line shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFLINESHAPE_H
#define _WXSFLINESHAPE_H
#include <wx/wxsf/ShapeBase.h>
#include <wx/wxsf/ArrowBase.h>
#include <limits.h>
// default values
/*! \brief Default value of undefined ID. */
#define sfdvLINESHAPE_UNKNOWNID -1
/*! \brief Default value of wxSFLineShape::m_Pen data member. */
#define sfdvLINESHAPE_PEN wxPen(*wxBLACK)
/*! \brief Default value of wxSFLineShape::m_nDockPoint data member. */
#define sfdvLINESHAPE_DOCKPOINT 0
/*! \brief Default value of wxSFLineShape::m_nDockPoint data member (start line point). */
#define sfdvLINESHAPE_DOCKPOINT_START -1
/*! \brief Default value of wxSFLineShape::m_nDockPoint data member (end line point). */
#define sfdvLINESHAPE_DOCKPOINT_END -2
/*! \brief Default value of wxSFLineShape::m_nDockPoint data member (middle dock point). */
#define sfdvLINESHAPE_DOCKPOINT_CENTER INT_MAX
/*! \brief Default value of wxSFLineShape::m_nSrcOffset and wxSFLineShape::m_nTrgOffset data members. */
#define sfdvLINESHAPE_OFFSET wxRealPoint(-1, -1)
/*! \brief Default value of wxSFLineShape::m_nSrcPoint and wxSFLineShape::m_nTrgPoint data members. */
#define sfdvLINESHAPE_DEFAULTPOINT wxRealPoint(0, 0)
/*! \brief Default value of wxSFLineShape::m_fStandAlone data member. */
#define sfdvLINESHAPE_STANDALONE false
/*!
* \brief Basic class encapsulating the multiline consisting of several line segments.
*/
class WXDLLIMPEXP_SF wxSFLineShape : public wxSFShapeBase
{
public:
friend class wxSFShapeCanvas;
XS_DECLARE_CLONABLE_CLASS(wxSFLineShape);
/*! \brief Default constructor. */
wxSFLineShape(void);
/*!
* \brief User constructor.
* \param src ID of the source shape
* \param trg ID of the target shape
* \param path List of the line control points (can be empty)
* \param manager Pointer to parent shape manager
*/
wxSFLineShape(long src, long trg, const wxXS::RealPointList& path, wxSFDiagramManager* manager);
/**
* \brief User constructor.
* \param src Starting line point
* \param trg Ending line point
* \param path List of the line control points (can be empty)
* \param manager Pointer to parent shape manager
*/
wxSFLineShape(const wxRealPoint& src, const wxRealPoint& trg, const wxXS::RealPointList& path, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFLineShape(const wxSFLineShape& obj);
/*! \brief Destructor. */
virtual ~wxSFLineShape(void);
// public member data accessors
/*!
* \brief Set line source.
* \param id ID of the source shape
*/
inline void SetSrcShapeId(long id) {m_nSrcShapeId = id;}
/*!
* \brief Get line source.
* \return ID of the source shape
*/
inline long GetSrcShapeId() {return m_nSrcShapeId;}
/*!
* \brief Set line target.
* \param id ID of the target shape
*/
inline void SetTrgShapeId(long id) {m_nTrgShapeId = id;}
/*!
* \brief Get line target.
* \return ID of the target shape
*/
inline long GetTrgShapeId() {return m_nTrgShapeId;}
/**
* \brief Set user-defined starting line point.
* \param src Starting point
*/
inline void SetSrcPoint(const wxRealPoint& src) {m_nSrcPoint = src;}
/*!
* \brief Get first line point.
* \return First line point
*/
wxRealPoint GetSrcPoint();
/**
* \brief Set user-defined ending point.
* \param trg Ending point
*/
inline void SetTrgPoint(const wxRealPoint& trg) {m_nTrgPoint = trg;}
/*!
* \brief Get last line point.
* \return Last line point
*/
wxRealPoint GetTrgPoint();
/**
* \brief Get starting and ending line points.
* \param src Reference to real point value where starting line point will be stored
* \param trg Reference to real point value where ending line point will be stored
*/
void GetDirectLine(wxRealPoint& src, wxRealPoint& trg);
/*!
* \brief Set source arrow object.
* \param arrow Pointer to the arrow object which will be assigned to the begin of the line
*/
void SetSrcArrow(wxSFArrowBase* arrow);
/*!
* \brief Set target arrow object.
* \param arrow Pointer to the arrow object which will be assigned to the end of the line
*/
void SetTrgArrow(wxSFArrowBase* arrow);
/*!
* \brief Set source arrow object created from its class info.
* \param arrowInfo Class info of the arrow class
* \return New arrow object
*/
wxSFArrowBase* SetSrcArrow(wxClassInfo* arrowInfo);
/*!
* \brief Get object of source arrow.
* \return Pointer to the arrow object if exists, otherwise NULL
*/
inline wxSFArrowBase* GetSrcArrow() {return m_pSrcArrow;}
/*!
* \brief Set target arrow object created from its class info.
* \param arrowInfo Class info of the arrow class
* \return New arrow object
*/
wxSFArrowBase* SetTrgArrow(wxClassInfo* arrowInfo);
/*!
* \brief Get object of target arrow.
* \return Pointer to the arrow object if exists, otherwise NULL
*/
inline wxSFArrowBase* GetTrgArrow() {return m_pTrgArrow;}
/*!
* \brief Set line style.
* \param pen Reference to wxPen object
*/
inline void SetLinePen(const wxPen& pen) {m_Pen = pen;}
/*!
* \brief Get line style.
* \return wxPen class
*/
inline wxPen GetLinePen() const {return m_Pen;}
/*!
* \brief Set the line dock point. It is a zerro based index of the line
* control point which will act as the shape position (value returned by GetRelativePosition() function).
* \param index Zerro based index of the line control point
* \sa sfdvLINESHAPE_DOCKPOINT_START, sfdvLINESHAPE_DOCKPOINT_END, sfdvLINESHAPE_DOCKPOINT_CENTER
*/
inline void SetDockPoint(int index) {m_nDockPoint = index;}
/*!
* \brief Get the line dock point. It is a zerro based index of the line
* control point which will act as the shape position (value returned by GetRelativePosition() function).
* \return Zerro based index of the line control point (-1 means UNDEFINED)
*/
inline int GetDockPoint() {return m_nDockPoint;}
/*!
* \brief Get a list of the line's contol points (their positions).
* \return List of control points' positions
*/
inline wxXS::RealPointList& GetControlPoints() {return m_lstPoints;}
/*!
* \brief Get a position of given line dock point.
* \param dp Dock point
* \return The dock point's position if exists, otherwise the line center
*/
wxRealPoint GetDockPointPosition(int dp);
/*!
* \brief Initialize line's starting point with existing fixed connection point.
* \param cp Pointer to connection point
*/
void SetStartingConnectionPoint(const wxSFConnectionPoint *cp);
/*!
* \brief Initialize line's ending point with existing fixed connection point.
* \param cp Pointer to connection point
*/
void SetEndingConnectionPoint(const wxSFConnectionPoint *cp);
/*!
* \brief Get starting and ending point of line segment defined by its index.
* \param index Index of desired line segment
* \param src Reference to variable where starting point will be stored
* \param trg Reference to variable where ending point will be stored
* \return TRUE if a line segment of given index exists, otherwise FALSE
*/
bool GetLineSegment(size_t index, wxRealPoint& src, wxRealPoint& trg);
/*!
* \brief Set stand-alone line mode.
* \param enab TRUE for stand-alone line, otherwise FALSE
*/
inline void SetStandAlone(bool enab) { m_fStandAlone = enab; } /*!
* \brief Get stand-alone line mode.
* \return TRUE, if the line is stand-alone, otherwise FALSE
*/
inline bool IsStandAlone() { return m_fStandAlone; }
// public virtual functions
/*!
* \brief Get line's bounding box. The function can be overrided if neccessary.
* \return Bounding rectangle
*/
virtual wxRect GetBoundingBox();
/*!
* \brief Get the shape's absolute position in the canvas.
* \return Shape's position
*/
virtual wxRealPoint GetAbsolutePosition();
/*!
* \brief Get intersection point of the shape border and a line leading from
* 'start' point to 'end' point. The function can be overrided if neccessary.
* \param start Starting point of the virtual intersection line
* \param end Ending point of the virtual intersection line
* \return Intersection point
*/
virtual wxRealPoint GetBorderPoint(const wxRealPoint& start, const wxRealPoint& end);
/*!
* \brief Test whether the given point is inside the shape. The function
* can be overrided if neccessary.
* \param pos Examined point
* \return TRUE if the point is inside the shape area, otherwise FALSE
*/
virtual bool Contains(const wxPoint& pos);
/*!
* \brief Move the shape to the given absolute position. The function
* can be overrided if neccessary.
* \param x X coordinate
* \param y Y coordinate
*/
virtual void MoveTo(double x, double y);
/*!
* \brief Move the shape by the given offset. The function
* can be overrided if neccessary.
* \param x X offset
* \param y Y offset
*/
virtual void MoveBy(double x, double y);
/*!
* \brief Function called by the framework responsible for creation of shape handles
* at the creation time. The function can be overrided if neccesary.
*/
virtual void CreateHandles();
/*!
* \brief Event handler called during dragging of the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* \param handle Reference to dragged handle
*/
virtual void OnHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called when the user finished dragging of the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* Default implementation does nothing.
* \param handle Reference to dragged handle
*/
virtual void OnEndHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called at the begining of the shape dragging process.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* \sa wxSFShapeCanvas
*/
virtual void OnBeginDrag(const wxPoint& pos);
/*!
* \brief Event handler called when the shape is double-clicked by
* the left mouse button. The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* \param pos Current mouse position
* \sa wxSFShapeCanvas
*/
virtual void OnLeftDoubleClick(const wxPoint& pos);
/*!
* \brief Scale the shape size by in both directions. The function can be overrided if necessary
* (new implementation should call default one ore scale shape's children manualy if neccesary).
* \param x Horizontal scale factor
* \param y Vertical scale factor
* \param children TRUE if the shape's children shoould be scaled as well, otherwise the shape will be updated after scaling via Update() function.
*/
virtual void Scale(double x, double y, bool children = sfWITHCHILDREN);
protected:
/*! \brief The modes in which the line shape can stay. */
enum LINEMODE
{
modeREADY,
modeUNDERCONSTRUCTION,
modeSRCCHANGE,
modeTRGCHANGE
};
// protected data members
/*! \brief List of the line's control points. */
wxXS::RealPointList m_lstPoints;
wxRealPoint m_nPrevPosition;
wxPoint m_nUnfinishedPoint;
LINEMODE m_nMode;
/*! \brief Index of the line dock point. */
int m_nDockPoint;
long m_nSrcShapeId;
long m_nTrgShapeId;
wxSFArrowBase* m_pSrcArrow;
wxSFArrowBase* m_pTrgArrow;
bool m_fStandAlone;
/*! \brief Stand alone line's starting point. */
wxRealPoint m_nSrcPoint;
/*! \brief Stand alone line's ending point. */
wxRealPoint m_nTrgPoint;
/*! \brief Modification offset for starting line point. */
wxRealPoint m_nSrcOffset;
/*! \brief Modification offset for ending line point. */
wxRealPoint m_nTrgOffset;
wxPen m_Pen;
// protected virtual functions
/*!
* \brief Draw the shape in the normal way. The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawNormal(wxDC& dc);
/*!
* \brief Draw the shape in the hower mode (the mouse cursor is above the shape).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHover(wxDC& dc);
/*!
* \brief Draw the shape in the highlighted mode (another shape is dragged over this
* shape and this shape will accept the dragged one if it will be dropped on it).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHighlighted(wxDC& dc);
/*! \brief Draw completed line. */
virtual void DrawCompleteLine(wxDC& dc);
/*!
* \brief Get index of the line segment intersecting the given point.
* \param pos Examined point
* \return Zero-based index of line segment located under the given point
*/
virtual int GetHitLinesegment(const wxPoint& pos);
// protected functions
/*!
* \brief Set line shape's working mode.
* \param mode Working mode
* \sa LINEMODE
*/
void SetLineMode(LINEMODE mode){m_nMode = mode;}
/*!
* \brief Get current working mode.
* \return Current working mode
* \sa LINEMODE
*/
LINEMODE GetLineMode(){return m_nMode;}
/*!
* \brief Set next potential control point position (usefull in modeUNDERCONSTRUCTION working mode).
* \param pos New potential control point position
* \sa LINEMODE
*/
void SetUnfinishedPoint(const wxPoint& pos){m_nUnfinishedPoint = pos;}
/*!
* \brief Get modified starting line point .
* \return Modified starting line point
*/
wxRealPoint GetModSrcPoint();
/*!
* \brief Get modified ending line point .
* \return Modified ending line point
*/
wxRealPoint GetModTrgPoint();
private:
// private functions
/*! \brief Initialize serializable properties. */
void MarkSerializableDataMembers();
};
#endif //_WXSFLINESHAPE_H

View File

@@ -0,0 +1,87 @@
/***************************************************************
* Name: MultiSelRect.h
* Purpose: Defines aux. multiselection shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFMULTIRECT_H
#define _WXSFMULTIRECT_H
#include <wx/wxsf/RectShape.h>
/*!
* \brief Auxiliary class encapsulating multiselection rectangle used
* in the shape canvas. The class shouldn't be used directly.
* \sa wxSFShapeCanvas
*/
class WXDLLIMPEXP_SF wxSFMultiSelRect : public wxSFRectShape
{
public:
/*! \brief Default constructor. */
wxSFMultiSelRect(void);
/*! \brief Destructor. */
virtual ~wxSFMultiSelRect(void);
// public virtual functions
/*!
* \brief Event handler called at the begining of the shape handle dragging process.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnBeginHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* \param handle Reference to dragged handle
*/
virtual void OnHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called at the end of the shape handle dragging process.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnEndHandle(wxSFShapeHandle& handle);
protected:
// protected virtual functions
/*!
* \brief Event handler called during dragging of the right shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnRightHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the left shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnLeftHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the top shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnTopHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the bottom shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnBottomHandle(wxSFShapeHandle& handle);
private:
// private functions
/*! \brief Auxiliary function. */
bool AnyWidthExceeded(const wxPoint& delta);
/*! \brief Auxiliary function. */
bool AnyHeightExceeded(const wxPoint& delta);
};
#endif //_WXSFMULTIRECT_H

View File

@@ -0,0 +1,68 @@
/***************************************************************
* Name: OpenArrow.h
* Purpose: Defines open arrow for line shapes
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFOPENARROW_H
#define _WXSFOPENARROW_H
#include <wx/wxsf/ArrowBase.h>
/*!
* \brief Class extends the wxSFArrowBase class and encapsulates
* arrow shape consisting of single two lines leading from the end of the
* parent line shape.
*/
class WXDLLIMPEXP_SF wxSFOpenArrow : public wxSFArrowBase
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFOpenArrow);
/*! \brief Default constructor. */
wxSFOpenArrow(void);
/*!
* \brief User constructor.
* \param parent"> Pointer to the parent shape
*/
wxSFOpenArrow(wxSFShapeBase* parent);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFOpenArrow(const wxSFOpenArrow& obj);
/*! \brief Destructor. */
virtual ~wxSFOpenArrow(void);
// public member data accessors
/**
* \brief Set a pen used for drawing of the arrow.
* \param pen Reference to the pen
*/
void SetArrowPen(const wxPen& pen) {m_Pen = pen;}
/**
* \brief Get current pen used for drawing of the arrow.
* \return Constant reference to current pen
*/
const wxPen& GetArrowPen() const {return m_Pen;}
// public virtual functions
/*!
* \brief Draw arrow shape at the end of a virtual line.
* \param from Start of the virtual line
* \param to End of the virtual line
* \param dc Device context for drawing
*/
virtual void Draw(const wxRealPoint& from, const wxRealPoint& to, wxDC& dc);
protected:
// protected data members
/*! \brief Arrow pen */
wxPen m_Pen;
};
#endif //_WXSFOPENARROW_H

View File

@@ -0,0 +1,92 @@
/***************************************************************
* Name: OrthoShape.h
* Purpose: Defines orthogonal line shape class
* Author: Michal Bližňák (michal.bliznak@gmail.com)
* Created: 2009-04-26
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFORTHOSHAPE_H
#define _WXSFORTHOSHAPE_H
#include <wx/wxsf/LineShape.h>
/*!
* \brief Orthogonal line shape. The class extends wxSFLineShape class and allows
* user to create connection line orthgonal to base axis.
*/
class WXDLLIMPEXP_SF wxSFOrthoLineShape : public wxSFLineShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFOrthoLineShape);
/*! \brief Default constructor. */
wxSFOrthoLineShape();
/*!
* \brief User constructor.
* \param src ID of the source shape
* \param trg ID of the target shape
* \param path Array of line's control points
* \param manager Parent parent diagram manager
*/
wxSFOrthoLineShape(long src, long trg, const wxXS::RealPointList& path, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFOrthoLineShape(const wxSFOrthoLineShape& obj);
/*! \brief Destructor. */
virtual ~wxSFOrthoLineShape();
protected:
// protected virtual functions
/*!
* \brief Internal function used for drawing of completed line shape.
* \param dc Refernce of the device context where the shape will be darwn to
*/
virtual void DrawCompleteLine(wxDC& dc);
/*!
* \brief Get index of the line segment intersecting the given point.
* \param pos Examined point
* \return Zero-based index of line segment located under the given point
*/
virtual int GetHitLinesegment(const wxPoint& pos);
/**
* \brief Draw one orthogonal line segment.
* \param dc Device context
* \param src Starting point of the ortho line segment.
* \param trg Ending point of the ortho line segment.
*/
virtual void DrawLineSegment(wxDC& dc, const wxRealPoint& src, const wxRealPoint& trg);
// protected functions
/**
* \brief Get first part of orthogonal line segment.
* \param src Staring point of the ortho line segment
* \param trg Ending point of the ortho line segment
* \param subsrc Starting point of the first part of ortho line segment
* \param subtrg Ending point of the first part of ortho line segment
*/
void GetFirstSubsegment( const wxRealPoint& src, const wxRealPoint& trg, wxRealPoint& subsrc, wxRealPoint& subtrg );
/**
* \brief Get middle part of orthogonal line segment.
* \param src Staring point of the ortho line segment
* \param trg Ending point of the ortho line segment
* \param subsrc Starting point of the second part of ortho line segment
* \param subtrg Ending point of the second part of ortho line segment
*/
void GetMiddleSubsegment( const wxRealPoint& src, const wxRealPoint& trg, wxRealPoint& subsrc, wxRealPoint& subtrg );
/**
* \brief Get last part of orthogonal line segment.
* \param src Staring point of the ortho line segment
* \param trg Ending point of the ortho line segment
* \param subsrc Starting point of the third part of ortho line segment
* \param subtrg Ending point of the third part of ortho line segment
*/
void GetLastSubsegment( const wxRealPoint& src, const wxRealPoint& trg, wxRealPoint& subsrc, wxRealPoint& subtrg );
};
#endif //_WXSFORTHOSHAPE_H

View File

@@ -0,0 +1,190 @@
/***************************************************************
* Name: PolygonShape.h
* Purpose: Defines polygonial shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFPOLYGONSHAPE_H
#define _WXSFPOLYGONSHAPE_H
#include <wx/wxsf/RectShape.h>
// default values
/*! \brief Default value of wxSFPolygonShape::m_fConnextToVertex data member. */
#define sfdvPOLYGONSHAPE_VERTEXCONNECTIONS true
/*!
* \brief Class extends the wxSFRectShape and encapsulates general polygon shape
* defined by a set of its vertices. The class can be used as it is or as a base class
* for shapes with more complex form and functionality.
* \sa wxSFDiamondShape
*/
class WXDLLIMPEXP_SF wxSFPolygonShape : public wxSFRectShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFPolygonShape);
/*! \brief Default constructor. */
wxSFPolygonShape(void);
/*!
* \brief User constructor.
* \param n Number of the polygon vertices
* \param pts Array of the polygon vertices
* \param pos Relative position of the polygon shape
* \param manager Pointer of parent diagram manager
*/
wxSFPolygonShape(int n, const wxRealPoint pts[], const wxRealPoint& pos, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to a source object
*/
wxSFPolygonShape(const wxSFPolygonShape& obj);
/*! \brief Destructor. */
virtual ~wxSFPolygonShape(void);
// public data accessors
/*!
* \brief Set connecting mode.
* \param enable Set this parameter to TRUE if you want to connect
* line shapes to the polygons's vertices, otherwise the lines will be connected
* to the nearest point of the shape's border.
*/
void SetConnectToVertex(bool enable){m_fConnectToVertex = enable;}
/*!
* \brief Get status of connecting mode.
* \return TRUE if the line shapes will be connected to the polygon's vertices
*/
bool IsConnectedToVertex(){return m_fConnectToVertex;}
// public functions
/*!
* \brief Set the poly vertices which define its form.
* \param n Number of the vertices
* \param pts Array of the vertices
*/
void SetVertices(size_t n, const wxRealPoint pts[]);
// public virtual functions
/*!
* \brief Resize the rectangle to bound all child shapes. The function can be overrided if neccessary. */
virtual void FitToChildren();
/*!
* \brief Get intersection point of the shape border and a line leading from
* 'start' point to 'end' point. The function can be overrided if neccessary.
* \param start Starting point of the virtual intersection line
* \param end Ending point of the virtual intersection line
* \return Intersection point
*/
virtual wxRealPoint GetBorderPoint(const wxRealPoint& start, const wxRealPoint& end);
/*!
* \brief Scale the shape size by in both directions. The function can be overrided if necessary
* (new implementation should call default one ore scale shape's children manualy if neccesary).
* \param x Horizontal scale factor
* \param y Vertical scale factor
* \param children TRUE if the shape's children shoould be scaled as well, otherwise the shape will be updated after scaling via Update() function.
*/
virtual void Scale(double x, double y, bool children = sfWITHCHILDREN);
/*!
* \brief Event handler called during dragging of the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* \param handle Reference to dragged handle
*/
virtual void OnHandle(wxSFShapeHandle &handle);
protected:
// protected data members
bool m_fConnectToVertex;
wxXS::RealPointArray m_arrVertices;
// protected functions
/*!
* \brief Move all vertices so the polygon's relative bounding box position
* will be located in the origin.
*/
void NormalizeVertices();
/*! \brief Scale polygon's vertices to fit into the rectangle bounding the polygon. */
void FitVerticesToBoundingBox();
/*! \brief Scale the bounding rectangle to fit all polygons vertices. */
void FitBoundingBoxToVertices();
/*!
* \brief Get polygon extents.
* \param minx Position of the left side of polygon's bounding box
* \param miny Position of the top side of polygon's bounding box
* \param maxx Position of the right side of polygon's bounding box
* \param maxy Position of the bottom side of polygon's bounding box
*/
void GetExtents(double *minx, double *miny, double *maxx, double *maxy);
/*!
* \brief Get absolute positions of the polygon's vertices.
* \param pts Array of translated polygon's verices
*/
void GetTranslatedVerices(wxRealPoint pts[]);
/*!
* \brief Get absolute positions of the polygon's vertices.
* \param pts Array of translated polygon's verices
*/
void GetTranslatedVerices(wxPoint pts[]);
/*!
* \brief Draw the polygon shape.
* \param dc Refernece to the device context where the shape will be drawn to
*/
void DrawPolygonShape(wxDC& dc);
// protected virtual functions
/*!
* \brief Draw the shape in the normal way. The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawNormal(wxDC& dc);
/*!
* \brief Draw the shape in the hower mode (the mouse cursor is above the shape).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHover(wxDC& dc);
/*!
* \brief Draw the shape in the highlighted mode (another shape is dragged over this
* shape and this shape will accept the dragged one if it will be dropped on it).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHighlighted(wxDC& dc);
/*!
* \brief Draw shadow under the shape. The function can be overrided if neccessary.
* \param dc Reference to device context where the shadow will be drawn to
*/
virtual void DrawShadow(wxDC& dc);
/*!
* \brief Serialize shape's properties to the given XML node. The serialization
* routine is automatically called by the framework and should take care about serialization
* of all specific (non-standard) shape's properties.
* \param node Pointer to XML node where the shape's property nodes will be appended to
* \sa xsSerializable::Serialize
*/
virtual wxXmlNode* Serialize(wxXmlNode* node);
/*!
* \brief Deserialize shape's properties from the given XML node. The
* routine is automatically called by the framework and should take care about deserialization
* of all specific (non-standard) shape's properties.
* \param node Pointer to a source XML node containig the shape's property nodes
* \sa xsSerializable::Deserialize
*/
virtual void Deserialize(wxXmlNode* node);
private:
// private functions
/*! \brief Initialize serializable properties. */
void MarkSerializableDataMembers();
};
#endif //_WXSFPOLYGONSHAPE_H

View File

@@ -0,0 +1,62 @@
/***************************************************************
* Name: Printout.h
* Purpose: Defines printout class for shape canvas
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2008-05-06
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFPRINTOUT_H
#define _WXSFPRINTOUT_H
#include <wx/print.h>
#include <wx/printdlg.h>
#include <wx/wxsf/Defs.h>
class WXDLLIMPEXP_SF wxSFShapeCanvas;
/*!
* \brief Auxiliary printout class providing all necessary functions needed for canvas printing.
* This class is used internally by the wxSFShapeCanvas class. It can be also used as a base class for other modified
* printout classes.
*/
class WXDLLIMPEXP_SF wxSFPrintout : public wxPrintout
{
public:
/*! \brief Default constructor */
wxSFPrintout(const wxString& title, wxSFShapeCanvas *canvas);
/*! \brief Default destructor */
virtual ~wxSFPrintout();
// public member data accessors
/*!
* \brief Set shape canvas which content should be printed.
* \param canvas Pointer to shape canvas
*/
void SetPrintedCanvas( wxSFShapeCanvas *canvas ){m_pCanvas = canvas;}
// public virtual functions
/*! \brief Called by printing framework. Functions TRUE if a page of given index already exists in printed document.
* This function can be overrided if necessary. */
virtual bool HasPage(int page);
/*! \brief Called by printing framework. Initialize print job. This function can be overrided if necessary. */
virtual bool OnBeginDocument(int startPage, int endPage);
/*! \brief Called by printing framework. Deinitialize the print job. This function can be overrided if necessary. */
virtual void OnEndDocument();
/*! \brief Called by printing framework. It does the print job. This function can be overrided if necessary. */
virtual bool OnPrintPage(int page);
/*! \brief Called by printing framework. Supply information about printed pages. This function can be overrided if necessary. */
virtual void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
protected:
// protected data members
/*! \brief Pointer to parent shape canvas. */
wxSFShapeCanvas *m_pCanvas;
};
#endif // _WXSFPRINTOUT_H

View File

@@ -0,0 +1,211 @@
/***************************************************************
* Name: RectShape.h
* Purpose: Defines rectangular shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFRECTSHAPE_H
#define _WXSFRECTSHAPE_H
#include <wx/wxsf/ShapeBase.h>
// default values
/*! \brief Default value of wxSFRectShape::m_nRectSize data member. */
#define sfdvRECTSHAPE_SIZE wxRealPoint(100, 50)
/*! \brief Default value of wxSFRectShape::m_Fill data member. */
#define sfdvRECTSHAPE_FILL wxBrush(*wxWHITE)
/*! \brief Default value of wxSFRectShape::m_Border data member. */
#define sfdvRECTSHAPE_BORDER wxPen(*wxBLACK)
/*!
* \brief Class encapsulates basic rectangle shape which is used as a base class
* for many other shapes that can be bounded by a simple rectangle. The class
* provides all functionality needed for manipulating the rectangle's (bounding box)
* size and position.
*/
class WXDLLIMPEXP_SF wxSFRectShape : public wxSFShapeBase
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFRectShape);
/*! \brief Default constructor. */
wxSFRectShape(void);
/*!
* \brief User constructor.
* \param pos Initial position
* \param size Initial size
* \param manager Pointer to parent diagram manager
*/
wxSFRectShape(const wxRealPoint& pos, const wxRealPoint& size, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFRectShape(const wxSFRectShape& obj);
/*! \brief Destructor. */
virtual ~wxSFRectShape(void);
// public virtual functions
/*!
* \brief Get shapes's bounding box. The function can be overrided if neccessary.
* \return Bounding rectangle
*/
virtual wxRect GetBoundingBox();
/*!
* \brief Get intersection point of the shape border and a line leading from
* 'start' point to 'end' point. The function can be overrided if neccessary.
* \param start Starting point of the virtual intersection line
* \param end Ending point of the virtual intersection line
* \return Intersection point
*/
virtual wxRealPoint GetBorderPoint(const wxRealPoint& start, const wxRealPoint& end);
/*!
* \brief Function called by the framework responsible for creation of shape handles
* at the creation time. The function can be overrided if neccesary.
*/
virtual void CreateHandles();
/*!
* \brief Event handler called during dragging of the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* \param handle Reference to dragged handle
*/
virtual void OnHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called when the user started to drag the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* \param handle Reference to dragged handle
*/
virtual void OnBeginHandle(wxSFShapeHandle& handle);
/*! \brief Resize the shape to bound all child shapes. The function can be overrided if neccessary. */
virtual void FitToChildren();
/*!
* \brief Scale the shape size by in both directions. The function can be overrided if necessary
* (new implementation should call default one ore scale shape's children manualy if neccesary).
* \param x Horizontal scale factor
* \param y Vertical scale factor
* \param children TRUE if the shape's children shoould be scaled as well, otherwise the shape will be updated after scaling via Update() function.
*/
virtual void Scale(double x, double y, bool children = sfWITHCHILDREN);
// public data accessors
/*!
* \brief Set rectangle's fill style.
* \param brush Refernce to a brush object
*/
void SetFill(const wxBrush& brush){m_Fill = brush;}
/*!
* \brief Get current fill style.
* \return Current brush
*/
wxBrush GetFill() const {return m_Fill;}
/*!
* \brief Set rectangle's border style.
* \param pen Reference to a pen object
*/
void SetBorder(const wxPen& pen){m_Border = pen;}
/*!
* \brief Get current border style.
* \return Current pen
*/
wxPen GetBorder() const {return m_Border;}
/*!
* \brief Set the rectangle size.
* \param size New size
*/
void SetRectSize(const wxRealPoint& size){m_nRectSize = size;}
/*!
* \brief Set the rectangle size.
* \param x Horizontal size
* \param y Verical size
*/
void SetRectSize(double x, double y){m_nRectSize.x = x; m_nRectSize.y = y;}
/*!
* \brief Get the rectangle size.
* \return Current size
*/
wxRealPoint GetRectSize() const {return m_nRectSize;}
protected:
// protected data members
/*! \brief Pen object used for drawing of the rectangle border. */
wxPen m_Border;
/*! \brief Brush object used for drawing of the rectangle body. */
wxBrush m_Fill;
/*! \brief The rectangle size. */
wxRealPoint m_nRectSize;
// protected virtual functions
/*!
* \brief Draw the shape in the normal way. The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawNormal(wxDC& dc);
/*!
* \brief Draw the shape in the hower mode (the mouse cursor is above the shape).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHover(wxDC& dc);
/*!
* \brief Draw the shape in the highlighted mode (another shape is dragged over this
* shape and this shape will accept the dragged one if it will be dropped on it).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHighlighted(wxDC& dc);
/*!
* \brief Draw shadow under the shape. The function can be overrided if neccessary.
* \param dc Reference to device context where the shadow will be drawn to
*/
virtual void DrawShadow(wxDC& dc);
/*!
* \brief Event handler called during dragging of the right shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnRightHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the left shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnLeftHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the top shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnTopHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the bottom shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnBottomHandle(wxSFShapeHandle& handle);
private:
// private functions
/*! \brief Initialize serializable properties. */
void MarkSerializableDataMembers();
/*! \brief Auxiliary data member. */
wxRealPoint m_nPrevSize;
/*! \brief Auxiliary data member. */
wxRealPoint m_nPrevPosition;
};
#endif //_WXSFRECTSHAPE_H

View File

@@ -0,0 +1,116 @@
/***************************************************************
* Name: RoundRectShape.h
* Purpose: Defines rounded rectangular shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFROUNDRECTSHAPE_H
#define _WXSFROUNDRECTSHAPE_H
#include <wx/wxsf/RectShape.h>
// default values
/*! \brief Default value of wxSFRoundRectShape::m_nRadius data member. */
#define sfdvROUNDRECTSHAPE_RADIUS 20
/*!
* \brief Class ecapsulating rounded rectangle. It extends the basic rectangular shape.
*/
class WXDLLIMPEXP_SF wxSFRoundRectShape : public wxSFRectShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFRoundRectShape);
/*! \brief Default constructor. */
wxSFRoundRectShape(void);
/*!
* \brief User constructor.
* \param pos Initial position
* \param size Initial size
* \param radius Corner radius
* \param manager Pointer of parent diagram manager
*/
wxSFRoundRectShape(const wxRealPoint& pos, const wxRealPoint &size, double radius, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Refernce to the source object.
*/
wxSFRoundRectShape(const wxSFRoundRectShape& obj);
/*! \brief Destructor. */
virtual ~wxSFRoundRectShape(void);
// public virtual functions
/*!
* \brief Test whether the given point is inside the shape. The function
* can be overrided if neccessary.
* \param pos Examined point
* \return TRUE if the point is inside the shape area, otherwise FALSE
*/
virtual bool Contains(const wxPoint &pos);
// public member data accessors
/*!
* \brief Set corner radius.
* \param radius New corner radius
*/
void SetRadius(double radius){m_nRadius = radius;}
/*!
* \brief Get current corner radius.
* \return Current corner radius
*/
double GetRadius(){return m_nRadius;}
protected:
// protected virtual functions
/*!
* \brief Draw the shape in the normal way. The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawNormal(wxDC& dc);
/*!
* \brief Draw the shape in the hower mode (the mouse cursor is above the shape).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHover(wxDC& dc);
/*!
* \brief Draw the shape in the highlighted mode (another shape is dragged over this
* shape and this shape will accept the dragged one if it will be dropped on it).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHighlighted(wxDC& dc);
/*!
* \brief Draw shadow under the shape. The function can be overrided if neccessary.
* \param dc Reference to device context where the shadow will be drawn to
*/
virtual void DrawShadow(wxDC& dc);
// protected functions
/*!
* \brief Auxiliary function. Checks whether the point is inside a circle with given center. The circle's radius
* is the roundrect corner radius.
* \param pos Examined point
* \param center Circle center
*/
bool IsInCircle(const wxPoint& pos, const wxPoint& center);
// protected data members
/*! \brief Corner radius. */
double m_nRadius;
private:
// private functions
/*! \brief Initialize serializable properties. */
void MarkSerializableDataMembers();
};
#endif //_WXSFROUNDRECTSHAPE_H

View File

@@ -0,0 +1,673 @@
/***************************************************************
* Name: SFEvents.h
* Purpose: Defines shape events classes
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-09-11
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFEVENTS_H
#define _WXSFEVENTS_H
#include <wx/event.h>
#include <wx/dnd.h>
#include <wx/wxsf/Defs.h>
#include <wx/wxsf/ShapeBase.h>
class WXDLLIMPEXP_SF wxSFShapeEvent;
class WXDLLIMPEXP_SF wxSFShapeTextEvent;
class WXDLLIMPEXP_SF wxSFShapeDropEvent;
class WXDLLIMPEXP_SF wxSFShapePasteEvent;
class WXDLLIMPEXP_SF wxSFShapeHandleEvent;
class WXDLLIMPEXP_SF wxSFShapeKeyEvent;
class WXDLLIMPEXP_SF wxSFShapeMouseEvent;
class WXDLLIMPEXP_SF wxSFShapeChildDropEvent;
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_LINE_DONE, 7770)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_TEXT_CHANGE, 7771)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_ON_DROP, 7772)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_ON_PASTE, 7773)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_LEFT_DOWN, 7774)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_LEFT_DCLICK, 7775)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_RIGHT_DOWN, 7776)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_RIGHT_DCLICK, 7777)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_DRAG_BEGIN, 7778)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_DRAG, 7779)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_DRAG_END, 7780)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_HANDLE_BEGIN, 7781)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_HANDLE, 7782)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_HANDLE_END, 7783)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_KEYDOWN, 7784)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_MOUSE_ENTER, 7785)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_MOUSE_OVER, 7786)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_MOUSE_LEAVE, 7787)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_SHAPE_CHILD_DROP, 7788)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SF, wxEVT_SF_LINE_BEFORE_DONE, 7789)
END_DECLARE_EVENT_TYPES()
typedef void (wxEvtHandler::*wxSFShapeEventFunction)(wxSFShapeEvent&);
typedef void (wxEvtHandler::*wxSFShapeTextEventFunction)(wxSFShapeTextEvent&);
typedef void (wxEvtHandler::*wxSFShapeDropEventFunction)(wxSFShapeDropEvent&);
typedef void (wxEvtHandler::*wxSFShapePasteEventFunction)(wxSFShapePasteEvent&);
typedef void (wxEvtHandler::*wxSFShapeHandleEventFunction)(wxSFShapeHandleEvent&);
typedef void (wxEvtHandler::*wxSFShapeKeyEventFunction)(wxSFShapeKeyEvent&);
typedef void (wxEvtHandler::*wxSFShapeMouseEventFunction)(wxSFShapeMouseEvent&);
typedef void (wxEvtHandler::*wxSFShapeChildDropEventFunction)(wxSFShapeChildDropEvent&);
#define wxSFShapeEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSFShapeEventFunction, &func)
#define wxSFShapeTextEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSFShapeTextEventFunction, &func)
#define wxSFShapeDropEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSFShapeDropEventFunction, &func)
#define wxSFShapePasteEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSFShapePasteEventFunction, &func)
#define wxSFShapeHandleEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSFShapeHandleEventFunction, &func)
#define wxSFShapeKeyEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSFShapeKeyEventFunction, &func)
#define wxSFShapeMouseEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSFShapeMouseEventFunction, &func)
#define wxSFShapeChildDropEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSFShapeChildDropEventFunction, &func)
/*! \brief Event table macro mapping event wxEVT_SF_LINE_DONE. This event occures
* when the interactive connection creation process is finished. The generated event
* object holds a pointer to the new line shape. */
#define EVT_SF_LINE_DONE(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_LINE_DONE, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_TEXT_CHANGE. This event occures
* when the editable text shape's content is changed. */
#define EVT_SF_TEXT_CHANGE(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_TEXT_CHANGE, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeTextEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_ON_DROP. This event occures
* when dragged shapes (via D&D operation) are dropped to a canvas. */
#define EVT_SF_ON_DROP(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_ON_DROP, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeDropEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_ON_PASTE. This event occures
* when shapes stored in the clipboard are pasted to a canvas. */
#define EVT_SF_ON_PASTE(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_ON_PASTE, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapePasteEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_LEFT_DOWN. This event occures
* when the shape is clicked by a left mouse button (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_LEFT_DOWN(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_LEFT_DOWN, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeMouseEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_LEFT_DCLICK. This event occures
* when the shape is double-clicked by a left mouse button (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_LEFT_DCLICK(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_LEFT_DCLICK, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeMouseEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_RIGHT_DOWN. This event occures
* when the shape is clicked by a right mouse button (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_RIGHT_DOWN(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_RIGHT_DOWN, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeMouseEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_RIGHT_DCLICK. This event occures
* when the shape is double-clicked by a right mouse button (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_RIGHT_DCLICK(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_RIGHT_DCLICK, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeMouseEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_DRAG_BEGIN. This event occures
* when the shape has started to be dragged. (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_DRAG_BEGIN(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_DRAG_BEGIN, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeMouseEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_DRAG. This event occures
* when the shape is dragging (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_DRAG(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_DRAG, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeMouseEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_DRAG_END. This event occures
* when the shape's dragging was finished (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_DRAG_END(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_DRAG_END, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeMouseEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_HANDLE_BEGIN. This event occures
* when the shape's handle has started to be dragged. (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_HANDLE_BEGIN(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_HANDLE_BEGIN, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeHandleEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_HANDLE. This event occures
* when the shape's handle is dragging (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_HANDLE(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_HANDLE, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeHandleEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_HANDLE_END. This event occures
* when the shape's dragging was finished (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_HANDLE_END(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_HANDLE_END, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeHandleEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_KEYDOWN. This event occures
* when the any key is pressed on selected shape (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_KEYDOWN(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_KEYDOWN, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeKeyEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_MOUSE_ENTER. This event occures
* when the mouse cursor enters the shape's area (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_MOUSE_ENTER(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_MOUSE_ENTER, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeMouseEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_MOUSE_OVER. This event occures
* when the mouse cursor is moving over the shape's area (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_MOUSE_OVER(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_MOUSE_OVER, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeMouseEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_MOUSE_LEAVE. This event occures
* when the mouse cursor leaves the shape's area (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_MOUSE_LEAVE(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_MOUSE_LEAVE, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeMouseEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_SHAPE_CHILD_DROP. This event occures
* when another shape is dropped onto the new parent shape (sfsEMIT_EVENTS shape style must be in use). */
#define EVT_SF_SHAPE_CHILD_DROP(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_SHAPE_CHILD_DROP, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeChildDropEventFunction, &fn ), \
(wxObject *) NULL \
),
/*! \brief Event table macro mapping event wxEVT_SF_LINE_BEFORE_DONE. This event occures
* when the interactive connection creation process is finished but this has been added in
* order to allow the developper to cancel the creation if required. The generated event
* object holds a pointer to the new line shape. */
#define EVT_SF_LINE_BEFORE_DONE(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_SF_LINE_BEFORE_DONE, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxSFShapeEventFunction, &fn ), \
(wxObject *) NULL \
),
/*!
* \brief Class encapsulates generic wxSF shape's event.
*/
class WXDLLIMPEXP_SF wxSFShapeEvent : public wxEvent
{
public:
/*! \brief Constructor */
wxSFShapeEvent(wxEventType cmdType = wxEVT_NULL, int id = 0);
/*! \brief Copy constructor */
wxSFShapeEvent(const wxSFShapeEvent& obj);
/*! \brief Destructor */
virtual ~wxSFShapeEvent();
// public member data accessors
/*!
* \brief Insert a shape object to the event object.
* \param shape Pointer to the shape object
*/
void SetShape(wxSFShapeBase* shape){m_Shape = shape;}
/*!
* \brief Get a shape object from the event object.
* \return Pointer to the shape object.
*/
wxSFShapeBase* GetShape(){return m_Shape;}
/*! \brief Clone this event object and return pointer to the new instance. */
wxEvent* Clone() const { return new wxSFShapeEvent(*this); }
/*!
* \brief Check if the event has been vetoed or not.
* \return TRUE if the event has been vetoed.
*/
bool IsVetoed() {return m_Vetoed;}
/*!
* \brief Set the veto flag to true.
*/
void Veto() {m_Vetoed = true;};
private:
// private data members
/*! \brief Pointer to stored shape object. */
wxSFShapeBase* m_Shape;
bool m_Vetoed;
};
/*!
* \brief Class encapsulates wxEVT_SF_SHAPE_KEYDOWN event.
*/
class WXDLLIMPEXP_SF wxSFShapeKeyEvent : public wxEvent
{
public:
/*! \brief Constructor */
wxSFShapeKeyEvent(wxEventType cmdType = wxEVT_NULL, int id = 0);
/*! \brief Copy constructor */
wxSFShapeKeyEvent(const wxSFShapeKeyEvent& obj);
/*! \brief Destructor */
virtual ~wxSFShapeKeyEvent();
// public member data accessors
/*!
* \brief Insert a shape object to the event object.
* \param shape Pointer to the shape object
*/
void SetShape(wxSFShapeBase* shape){m_Shape = shape;}
/*!
* \brief Get a shape object from the event object.
* \return Pointer to the shape object.
*/
wxSFShapeBase* GetShape(){return m_Shape;}
/**
* \brief Set key code.
* \param KeyCode Code of pressed key
*/
void SetKeyCode(int KeyCode) {this->m_KeyCode = KeyCode;}
/**
* \brief Get key code.
* \return Code of pressed key
*/
int GetKeyCode() const {return m_KeyCode;}
/*! \brief Clone this event object and return pointer to the new instance. */
wxEvent* Clone() const { return new wxSFShapeKeyEvent(*this); }
private:
// private data members
/*! \brief Pointer to stored shape object. */
wxSFShapeBase* m_Shape;
/*! \brief Code of pressed key. */
int m_KeyCode;
};
/*!
* \brief Class encapsulates mouse events generated by a shape.
*/
class WXDLLIMPEXP_SF wxSFShapeMouseEvent : public wxEvent
{
public:
/*! \brief Constructor */
wxSFShapeMouseEvent(wxEventType cmdType = wxEVT_NULL, int id = 0);
/*! \brief Copy constructor */
wxSFShapeMouseEvent(const wxSFShapeMouseEvent& obj);
/*! \brief Destructor */
virtual ~wxSFShapeMouseEvent();
// public member data accessors
/*!
* \brief Insert a shape object to the event object.
* \param shape Pointer to the shape object
*/
void SetShape(wxSFShapeBase* shape){m_Shape = shape;}
/*!
* \brief Get a shape object from the event object.
* \return Pointer to the shape object.
*/
wxSFShapeBase* GetShape(){return m_Shape;}
/**
* \brief Set absolute position of mouse cursor.
* \param MousePosition Mouse cursor's absolute position
*/
void SetMousePosition(const wxPoint& MousePosition) {this->m_MousePosition = MousePosition;}
/**
* \brief Get absolute position of mouse cursor
* \return Mouse cursor's absolute position
*/
const wxPoint& GetMousePosition() const {return m_MousePosition;}
/*! \brief Clone this event object and return pointer to the new instance. */
wxEvent* Clone() const { return new wxSFShapeMouseEvent(*this); }
private:
// private data members
/*! \brief Pointer to stored shape object. */
wxSFShapeBase* m_Shape;
/*! \brief Code of pressed key. */
wxPoint m_MousePosition;
};
/*!
* \brief Class encapsulates wxEVT_SF_TEXT_CHANGE event.
*/
class WXDLLIMPEXP_SF wxSFShapeTextEvent : public wxEvent
{
public:
/*! \brief Constructor */
wxSFShapeTextEvent(wxEventType cmdType = wxEVT_NULL, int id = 0);
/*! \brief Copy constructor */
wxSFShapeTextEvent(const wxSFShapeTextEvent& obj);
/*! \brief Destructor */
virtual ~wxSFShapeTextEvent();
// public member data accessors
/*!
* \brief Insert a shape object to the event object.
* \param shape Pointer to the shape object
*/
void SetShape(wxSFShapeBase* shape){m_Shape = shape;}
/*!
* \brief Get a shape object from the event object.
* \return Pointer to the shape object.
*/
wxSFShapeBase* GetShape(){return m_Shape;}
/*!
* \brief Set new text shape.
* \param txt New text content.
*/
void SetText(const wxString& txt){m_Text = txt;}
/*!
* \brief Get a shape text.
* \return Shape text content.
*/
wxString GetText(){return m_Text;}
/*! \brief Clone this event object and return pointer to the new instance. */
wxEvent* Clone() const { return new wxSFShapeTextEvent(*this); }
private:
// private data members
/*! \brief Pointer to stored shape object. */
wxSFShapeBase* m_Shape;
/*! \brief New shape text. */
wxString m_Text;
};
/*!
* \brief Class encapsulates handle-related events.
*/
class WXDLLIMPEXP_SF wxSFShapeHandleEvent : public wxEvent
{
public:
/*! \brief Constructor */
wxSFShapeHandleEvent(wxEventType cmdType = wxEVT_NULL, int id = 0);
/*! \brief Copy constructor */
wxSFShapeHandleEvent(const wxSFShapeHandleEvent& obj);
/*! \brief Destructor */
virtual ~wxSFShapeHandleEvent();
// public member data accessors
/*!
* \brief Insert a shape object to the event object.
* \param shape Pointer to the shape object
*/
void SetShape(wxSFShapeBase* shape){m_Shape = shape;}
/*!
* \brief Get a shape object from the event object.
* \return Pointer to the shape object.
*/
wxSFShapeBase* GetShape(){return m_Shape;}
/**
* \brief Set pointer to dragged shape handle.
* \param Handle Pointer to shape handle
* \sa wxSFShapeHandle
*/
void SetHandle(wxSFShapeHandle& Handle) {this->m_Handle = &Handle;}
/**
* \brief Get pointer to dragged shape handle.
* \return Pointer to shape handle
* \sa wxSFShapeHandle
*/
wxSFShapeHandle& GetHandle() const {return *m_Handle;}
/*! \brief Clone this event object and return pointer to the new instance. */
wxEvent* Clone() const { return new wxSFShapeHandleEvent(*this); }
private:
// private data members
/*! \brief Pointer to stored shape object. */
wxSFShapeBase* m_Shape;
/*! \brief Dragged handle. */
wxSFShapeHandle* m_Handle;
};
/*!
* \brief Class encapsulates wxEVT_SF_ON_DROP event.
*/
class WXDLLIMPEXP_SF wxSFShapeDropEvent : public wxEvent
{
public:
/*! \brief Constructor */
wxSFShapeDropEvent(wxEventType cmdType = wxEVT_NULL, wxCoord x = 0, wxCoord y = 0, wxSFShapeCanvas* target = NULL, wxDragResult def = wxDragNone, int id = 0);
/*! \brief Copy constructor */
wxSFShapeDropEvent(const wxSFShapeDropEvent& obj);
/*! \brief Destructor */
virtual ~wxSFShapeDropEvent();
// public member data accessors
/*!
* \brief Copy given shapes to the internal list of dropped shapes.
* \param list Reference to a list of copied shapes
*/
void SetDroppedShapes(const ShapeList& list);
/*!
* \brief Set a position where the shapes were dropped.
* \param pos Position
*/
void SetDropPosition(const wxPoint& pos){m_nDropPosition = pos;}
/*!
* \brief Set drag result.
* \param def Drag result
*/
void SetDragResult(wxDragResult def){m_nDragResult = def;}
/*!
* \brief Set drop target (shape canvas where shapes have been dropped to).
* \param target Pointer to drop target (shape canvas)
*/
void SetDropTarget(wxSFShapeCanvas *target){m_pDropTarget = target;}
/*!
* \brief Get a shape object from the event object.
* \return Pointer to the shape object.
*/
ShapeList& GetDroppedShapes(){return m_lstDroppedShapes;}
/*!
* \brief Get drop position.
* \return Position.
*/
wxPoint GetDropPosition(){return m_nDropPosition;}
/*!
* \brief Get drag result.
* \return Drag result.
*/
wxDragResult GetDragResult(){return m_nDragResult;}
/*!
* \brief Get drop target (shape canvas where shapes have been dropped to).
* \return Pointer to drop target (shape canvas)
*/
wxSFShapeCanvas* GetDropTarget(){return m_pDropTarget;}
/*! \brief Clone this event object and return pointer to the new instance. */
wxEvent* Clone() const { return new wxSFShapeDropEvent(*this); }
private:
// private data members
/*! \brief List of dropped shapes. */
ShapeList m_lstDroppedShapes;
/*! \brief Drop target. */
wxSFShapeCanvas *m_pDropTarget;
/*! \brief Drop position. */
wxPoint m_nDropPosition;
/*! \brief Drag result. */
wxDragResult m_nDragResult;
};
/*!
* \brief Class encapsulates wxEVT_SF_ON_PASTE event.
*/
class WXDLLIMPEXP_SF wxSFShapePasteEvent : public wxEvent
{
public:
/*! \brief Constructor */
wxSFShapePasteEvent(wxEventType cmdType = wxEVT_NULL, wxSFShapeCanvas *target = NULL, int id = 0);
/*! \brief Copy constructor */
wxSFShapePasteEvent(const wxSFShapePasteEvent& obj);
/*! \brief Destructor */
virtual ~wxSFShapePasteEvent();
// public member data accessors
/*!
* \brief Copy given shapes to the internal list of pasted shapes.
* \param list Reference to a list of copied shapes
*/
void SetPastedShapes(const ShapeList& list);
/*!
* \brief Set drop target (shape canvas where shapes have been pasted to).
* \param target Pointer to drop target (shape canvas)
*/
void SetDropTarget(wxSFShapeCanvas *target){m_pDropTarget = target;}
/*!
* \brief Get a shape object from the event object.
* \return Pointer to the shape object.
*/
ShapeList& GetPastedShapes(){return m_lstPastedShapes;}
/*!
* \brief Get drop target (shape canvas where shapes have been pasted to).
* \return Pointer to drop target (shape canvas)
*/
wxSFShapeCanvas* GetDropTarget(){return m_pDropTarget;}
/*! \brief Clone this event object and return pointer to the new instance. */
wxEvent* Clone() const { return new wxSFShapePasteEvent(*this); }
private:
// private data members
/*! \brief List of pasted shapes. */
ShapeList m_lstPastedShapes;
/*! \brief Drop target. */
wxSFShapeCanvas *m_pDropTarget;
};
/*!
* \brief Class encapsulates wxEVT_SF_SHAPE_CHILD_DROP event.
*/
class WXDLLIMPEXP_SF wxSFShapeChildDropEvent : public wxEvent
{
public:
/*! \brief Constructor */
wxSFShapeChildDropEvent(wxEventType cmdType = wxEVT_NULL, int id = 0);
/*! \brief Copy constructor */
wxSFShapeChildDropEvent(const wxSFShapeChildDropEvent& obj);
/*! \brief Destructor */
virtual ~wxSFShapeChildDropEvent();
// public member data accessors
/*!
* \brief Insert a shape object to the event object.
* \param shape Pointer to the shape object
*/
void SetShape(wxSFShapeBase* shape){m_Shape = shape;}
/*!
* \brief Get a shape object from the event object.
* \return Pointer to the shape object.
*/
wxSFShapeBase* GetShape(){return m_Shape;}
/**
* \brief Set a pointer to dropped child shape.
* \param ChildShape Pointer to dropped child shape
*/
void SetChildShape(wxSFShapeBase* ChildShape) {this->m_ChildShape = ChildShape;}
/**
* \brief Get a pointer to dropped child shape.
* \return Pointer to dropped child shape
*/
wxSFShapeBase* GetChildShape() {return m_ChildShape;}
/*! \brief Clone this event object and return pointer to the new instance. */
wxEvent* Clone() const { return new wxSFShapeChildDropEvent(*this); }
private:
// private data members
/*! \brief Pointer to stored shape object. */
wxSFShapeBase* m_Shape;
/*! \brief Pointer to dropped child object. */
wxSFShapeBase* m_ChildShape;
};
#endif // _WXSFEVENTS_H

View File

@@ -0,0 +1,700 @@
/***************************************************************
* Name: ScaledDC.h
* Purpose: Defines scaled DC class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2008-11-7
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFSCALEDDC_H
#define _WXSFSCALEDDC_H
#include <wx/graphics.h>
#include <wx/dc.h>
#include <math.h>
#include <wx/dcclient.h>
#include <wx/wxsf/Defs.h>
#if wxVERSION_NUMBER < 2900
/*! \brief Class acts as a wrapper for given DC class and provides modified
* drawing functions cooperating with the shape canvas able to draw scaled graphics.
* All drawing operations performed by the shapes should be done via this class otherwise
* the global scalling capabilities provided by the shape canvas wont be available.
* \sa wxSFShapeCanvas
*/
class WXDLLIMPEXP_SF wxSFScaledDC : public wxDC {
public:
wxSFScaledDC( wxWindowDC* target, double scale );
virtual ~wxSFScaledDC();
// public member data accessors
/*!
* \brief Set the global graphics scale.
* \param scale Scale
*/
void SetScale(double scale){m_nScale = scale;}
/**
* \brief Prepare wxGraphicsContext similiarly to PrepareDC() function.
*/
void PrepareGC();
/**
* \brief Enable/Disable usage of wxGraphicsContext.
* \param enab Set to TRUE if the wxGraphicsContext should be used for drawing
*/
static void EnableGC(bool enab){m_fEnableGC = enab;}
public:
virtual void CalcBoundingBox(wxCoord x, wxCoord y);
virtual bool CanDrawBitmap() const;
virtual bool CanGetTextExtent() const;
virtual void Clear();
virtual void ComputeScaleAndOrigin();
virtual void DrawObject(wxDrawObject* drawobject);
virtual void EndDoc();
virtual void EndPage();
virtual const wxBrush& GetBackground() const;
virtual int GetBackgroundMode() const;
virtual const wxBrush& GetBrush() const;
virtual wxCoord GetCharHeight() const;
virtual wxCoord GetCharWidth() const;
virtual int GetDepth() const;
virtual const wxFont& GetFont() const;
#ifdef __WXGTK__
virtual GdkWindow* GetGDKWindow() const;
#endif
virtual wxLayoutDirection GetLayoutDirection() const;
virtual int GetLogicalFunction() const;
virtual void GetLogicalScale(double *x, double *y);
virtual int GetMapMode() const;
virtual void GetMultiLineTextExtent(const wxString& string, wxCoord *width, wxCoord *height, wxCoord *heightLine = NULL, wxFont *font = NULL) const;
virtual wxSize GetPPI() const;
virtual const wxPen& GetPen() const;
virtual wxBitmap GetSelectedBitmap() const;
virtual const wxColour& GetTextBackground() const;
virtual const wxColour& GetTextForeground() const;
virtual void GetUserScale(double *x, double *y) const;
virtual bool IsOk() const;
virtual bool Ok() const;
virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
virtual void SetBackground(const wxBrush& brush);
virtual void SetBackgroundMode(int mode);
virtual void SetBrush(const wxBrush& brush);
virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
virtual void SetFont(const wxFont& font);
virtual void SetLayoutDirection(wxLayoutDirection dir);
virtual void SetLogicalFunction(int function);
virtual void SetLogicalOrigin( wxCoord x, wxCoord y );
virtual void SetLogicalScale(double x, double y);
virtual void SetMapMode( int mode );
virtual void SetPalette(const wxPalette& palette);
virtual void SetPen(const wxPen& pen);
virtual void SetTextBackground(const wxColour& colour);
virtual void SetTextForeground(const wxColour& colour);
virtual void SetUserScale( double x, double y );
virtual bool StartDoc( const wxString& message );
virtual void StartPage();
protected:
// protected data members
/*! \brief Global graphics scale. */
double m_nScale;
/*! \brief wxGraphicsContext usage flag. */
static bool m_fEnableGC;
/*! \brief Pointer to wrapped device context. */
wxWindowDC *m_pTargetDC;
#if wxUSE_GRAPHICS_CONTEXT
/*! \brief Pointer to wxGraphicsContext instance. */
wxGraphicsContext *m_pGC;
#endif
// protected function
/**
* \brief Scale given value.
* \param val Value to scale
* \return Scaled value
*/
wxCoord Scale(wxCoord val){return (wxCoord)ceil((double)val*m_nScale);}
/**
* \brief Initialize wxGraphicsContext.
*/
void InitGC();
/**
* \brief Uninitialize wxGraphicsContext.
*/
void UninitGC();
virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
virtual void DoCrossHair(wxCoord x, wxCoord y);
virtual void DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc);
virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = false);
virtual void DoDrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea);
virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
virtual void DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset);
virtual void DoDrawPoint(wxCoord x, wxCoord y);
virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle);
virtual void DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle = wxODDEVEN_RULE);
virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius);
virtual void DoDrawSpline(wxList *points);
virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE);
virtual wxBitmap DoGetAsBitmap(const wxRect *subrect) const;
virtual void DoGetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const;
virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h);
virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const;
virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const;
virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
virtual void DoGetSize(int *width, int *height) const;
virtual void DoGetSizeMM(int* width, int* height) const;
virtual void DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, wxCoord *descent = NULL, wxCoord *externalLeading = NULL, wxFont *theFont = NULL) const;
virtual void DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter);
virtual void DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection = wxEAST);
virtual void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
};
#else // ! wxVERSION_NUMBER < 2900
#include <wx/dcclient.h>
class WXDLLIMPEXP_SF wxSFScaledDC;
class wxSFDCImplWrapper : public wxDCImpl
{
public:
friend class wxSFScaledDC;
wxSFDCImplWrapper( wxDCImpl *orig, double scale ) : wxDCImpl( orig->GetOwner() )
{
m_pOrig = orig;
m_nScale = scale;
}
virtual ~wxSFDCImplWrapper()
{
}
wxDC *GetOwner() const { return m_pOrig->GetOwner(); }
wxWindow* GetWindow() const { return m_pOrig->GetWindow(); }
virtual bool IsOk() const { return m_pOrig->IsOk(); }
// query capabilities
virtual bool CanDrawBitmap() const { return m_pOrig->CanDrawBitmap(); }
virtual bool CanGetTextExtent() const { return m_pOrig->CanGetTextExtent(); }
// get Cairo context
virtual void* GetCairoContext() const
{
return m_pOrig->GetCairoContext();
}
// query dimension, colour deps, resolution
virtual void DoGetSize(int *width, int *height) const { m_pOrig->DoGetSize( width, height); }
void GetSize(int *width, int *height) const
{
DoGetSize(width, height);
return ;
}
wxSize GetSize() const
{
int w, h;
DoGetSize(&w, &h);
return wxSize(w, h);
}
virtual void DoGetSizeMM(int* width, int* height) const { m_pOrig->DoGetSizeMM( width, height); }
virtual int GetDepth() const { return m_pOrig->GetDepth(); }
virtual wxSize GetPPI() const { return m_pOrig->GetPPI(); }
// Right-To-Left (RTL) modes
virtual void SetLayoutDirection(wxLayoutDirection dir) { m_pOrig->SetLayoutDirection( dir ); }
virtual wxLayoutDirection GetLayoutDirection() const { return m_pOrig->GetLayoutDirection(); }
// page and document
virtual bool StartDoc(const wxString& message) { return m_pOrig->StartDoc( message ); }
virtual void EndDoc() { return m_pOrig->EndDoc(); }
virtual void StartPage() { m_pOrig->StartPage(); }
virtual void EndPage() { m_pOrig->EndPage(); }
// flushing the content of this dc immediately eg onto screen
virtual void Flush() { m_pOrig->Flush(); }
// bounding box
virtual void CalcBoundingBox(wxCoord x, wxCoord y) { m_pOrig->CalcBoundingBox( x, y); }
wxCoord MinX() const { return m_pOrig->MinX(); }
wxCoord MaxX() const { return m_pOrig->MaxX(); }
wxCoord MinY() const { return m_pOrig->MinY(); }
wxCoord MaxY() const { return m_pOrig->MaxY(); }
// setters and getters
virtual void SetFont(const wxFont& font) { m_pOrig->SetFont( font ); }
virtual const wxFont& GetFont() const { return m_pOrig->GetFont(); }
virtual void SetPen(const wxPen& pen) { m_pOrig->SetPen( pen ); }
virtual const wxPen& GetPen() const { return m_pOrig->GetPen(); }
virtual void SetBrush(const wxBrush& brush) { m_pOrig->SetBrush( brush ); }
virtual const wxBrush& GetBrush() const { return m_pOrig->GetBrush(); }
virtual void SetBackground(const wxBrush& brush) { m_pOrig->SetBackground( brush ); }
virtual const wxBrush& GetBackground() const { return m_pOrig->GetBackground(); }
virtual void SetBackgroundMode(int mode) { m_pOrig->SetBackgroundMode( mode ); }
virtual int GetBackgroundMode() const { return m_pOrig->GetBackgroundMode(); }
virtual void SetTextForeground(const wxColour& colour) { m_pOrig->SetTextForeground( colour ); }
virtual const wxColour& GetTextForeground() const { return m_pOrig->GetTextForeground(); }
virtual void SetTextBackground(const wxColour& colour) { m_pOrig->SetTextBackground( colour ); }
virtual const wxColour& GetTextBackground() const { return m_pOrig->GetTextBackground(); }
#if wxUSE_PALETTE
virtual void SetPalette(const wxPalette& palette) { m_pOrig->SetPalette( palette ); }
#endif // wxUSE_PALETTE
// inherit the DC attributes (font and colours) from the given window
//
// this is called automatically when a window, client or paint DC is
// created
virtual void InheritAttributes(wxWindow *win) { m_pOrig->InheritAttributes( win ); }
// logical functions
virtual void SetLogicalFunction(wxRasterOperationMode function) { m_pOrig->SetLogicalFunction( function ); }
virtual wxRasterOperationMode GetLogicalFunction() const { return m_pOrig->GetLogicalFunction(); }
// text measurement
virtual wxCoord GetCharHeight() const { return m_pOrig->GetCharHeight(); }
virtual wxCoord GetCharWidth() const { return m_pOrig->GetCharWidth(); }
virtual void DoGetTextExtent(const wxString& string,
wxCoord *x, wxCoord *y,
wxCoord *descent = NULL,
wxCoord *externalLeading = NULL,
const wxFont *theFont = NULL) const { m_pOrig->DoGetTextExtent( string, x, y, descent, externalLeading, theFont ); }
virtual void GetMultiLineTextExtent(const wxString& string,
wxCoord *width,
wxCoord *height,
wxCoord *heightLine = NULL,
const wxFont *font = NULL) const { m_pOrig->GetMultiLineTextExtent( string, width, height, heightLine, font ); }
virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const { return m_pOrig->DoGetPartialTextExtents( text, widths); }
// clearing
virtual void Clear() { m_pOrig->Clear(); }
// clipping
virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
wxCoord width, wxCoord height) { m_pOrig->DoSetClippingRegion( x, y, width, height ); }
// NB: this function works with device coordinates, not the logical ones!
virtual void DoSetDeviceClippingRegion(const wxRegion& region) { m_pOrig->DoSetDeviceClippingRegion( region ); }
virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
wxCoord *w, wxCoord *h) const { m_pOrig->DoGetClippingBox( x, y, w, h ); }
virtual void DestroyClippingRegion() { m_pOrig->DestroyClippingRegion(); }
// coordinates conversions and transforms
virtual wxCoord DeviceToLogicalX(wxCoord x) const { return m_pOrig->DeviceToLogicalX(x); }
virtual wxCoord DeviceToLogicalY(wxCoord y) const { return m_pOrig->DeviceToLogicalY(y); }
virtual wxCoord DeviceToLogicalXRel(wxCoord x) const { return m_pOrig->DeviceToLogicalXRel(x); }
virtual wxCoord DeviceToLogicalYRel(wxCoord y) const { return m_pOrig->DeviceToLogicalYRel(y); }
virtual wxCoord LogicalToDeviceX(wxCoord x) const { return m_pOrig->LogicalToDeviceX(x); }
virtual wxCoord LogicalToDeviceY(wxCoord y) const { return m_pOrig->LogicalToDeviceY(y); }
virtual wxCoord LogicalToDeviceXRel(wxCoord x) const { return m_pOrig->LogicalToDeviceXRel(x); }
virtual wxCoord LogicalToDeviceYRel(wxCoord y) const { return m_pOrig->LogicalToDeviceYRel(y); }
virtual void SetMapMode(wxMappingMode mode) { m_pOrig->SetMapMode(mode); }
virtual wxMappingMode GetMapMode() const { return m_pOrig->GetMapMode(); }
virtual void SetUserScale(double x, double y) { m_pOrig->SetUserScale( x, y ); }
virtual void GetUserScale(double *x, double *y) const { m_pOrig->GetUserScale( x, y ); }
virtual void SetLogicalScale(double x, double y) { m_pOrig->SetLogicalScale( x, y ); }
virtual void GetLogicalScale(double *x, double *y) { m_pOrig->GetLogicalScale( x, y ); }
virtual void SetLogicalOrigin(wxCoord x, wxCoord y) { m_pOrig->SetLogicalOrigin( x, y ); }
virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const { m_pOrig->DoGetLogicalOrigin( x, y); }
virtual void SetDeviceOrigin(wxCoord x, wxCoord y) { m_pOrig->SetDeviceOrigin( x, y ); }
virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const { m_pOrig->DoGetDeviceOrigin( x, y ); }
virtual void SetDeviceLocalOrigin( wxCoord x, wxCoord y ) { m_pOrig->SetDeviceLocalOrigin( x, y ); }
virtual void ComputeScaleAndOrigin() { m_pOrig->ComputeScaleAndOrigin(); }
// this needs to overidden if the axis is inverted
virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) { m_pOrig->SetAxisOrientation( xLeftRight, yBottomUp); }
// ---------------------------------------------------------
// the actual drawing API
virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
wxFloodFillStyle style = wxFLOOD_SURFACE)
{
return m_pOrig->DoFloodFill( ScaleCoord(x), ScaleCoord(y), col, style );
}
virtual void DoGradientFillLinear(const wxRect& rect,
const wxColour& initialColour,
const wxColour& destColour,
wxDirection nDirection = wxEAST)
{
m_pOrig->DoGradientFillLinear( wxRect( ScaleInt(rect.x), ScaleInt(rect.y), ScaleInt(rect.width), ScaleInt(rect.height)),
initialColour, destColour, nDirection );
}
virtual void DoGradientFillConcentric(const wxRect& rect,
const wxColour& initialColour,
const wxColour& destColour,
const wxPoint& circleCenter)
{
m_pOrig->DoGradientFillConcentric( wxRect( ScaleInt(rect.x), ScaleInt(rect.y), ScaleInt(rect.width), ScaleInt(rect.height)),
initialColour, destColour,
wxPoint( ScaleInt(circleCenter.x), ScaleInt(circleCenter.y)) );
}
virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
{
return m_pOrig->DoGetPixel( (wxCoord)ceil((double)x*m_nScale), (wxCoord)ceil((double)y*m_nScale), col );
}
virtual void DoDrawPoint(wxCoord x, wxCoord y)
{
m_pOrig->DoDrawPoint( ScaleCoord(x), ScaleCoord(y) );
}
virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{
m_pOrig->DoDrawLine( ScaleCoord(x1), ScaleCoord(y1), ScaleCoord(x2), ScaleCoord(y2) );
}
virtual void DoDrawArc(wxCoord x1, wxCoord y1,
wxCoord x2, wxCoord y2,
wxCoord xc, wxCoord yc)
{
m_pOrig->DoDrawArc( ScaleCoord(x1), ScaleCoord(y1),
ScaleCoord(x2), ScaleCoord(y2),
ScaleCoord(xc), ScaleCoord(yc) );
}
virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
wxCoord width, wxCoord height)
{
m_pOrig->DoDrawCheckMark( ScaleCoord(x), ScaleCoord(y), ScaleCoord(width), ScaleCoord(height) );
}
virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
double sa, double ea)
{
m_pOrig->DoDrawEllipticArc( ScaleCoord(x), ScaleCoord(y), ScaleCoord(w), ScaleCoord(h), sa, ea );
}
virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
m_pOrig->DoDrawRectangle( ScaleCoord(x), ScaleCoord(y), ScaleCoord(width), ScaleCoord(height) );
}
virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
wxCoord width, wxCoord height,
double radius)
{
m_pOrig->DoDrawRoundedRectangle( ScaleCoord(x), ScaleCoord(y), ScaleCoord(width), ScaleCoord(height), radius*m_nScale );
}
virtual void DoDrawEllipse(wxCoord x, wxCoord y,
wxCoord width, wxCoord height)
{
m_pOrig->DoDrawEllipse( ScaleCoord(x), ScaleCoord(y), ScaleCoord(width), ScaleCoord(height) );
}
virtual void DoCrossHair(wxCoord x, wxCoord y)
{
m_pOrig->DoCrossHair( ScaleCoord(x), ScaleCoord(y) );
}
virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
{
m_pOrig->DoDrawIcon( icon, ScaleCoord(x), ScaleCoord(y) );
}
virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
bool useMask = false)
{
m_pOrig->DoDrawBitmap( bmp, ScaleCoord(x), ScaleCoord(y), useMask );
}
virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y)
{
wxFont font = GetFont();
wxFont prevfont = font;
if(font != wxNullFont)
{
font.SetPointSize(int(font.GetPointSize()*m_nScale));
SetFont(font);
}
m_pOrig->DoDrawText( text, ScaleCoord(x), ScaleCoord(y) );
SetFont(prevfont);
}
virtual void DoDrawRotatedText(const wxString& text,
wxCoord x, wxCoord y, double angle)
{
wxFont font = GetFont();
wxFont prevfont = font;
if(font != wxNullFont)
{
font.SetPointSize(int(font.GetPointSize()*m_nScale));
SetFont(font);
}
m_pOrig->DoDrawRotatedText( text, ScaleCoord(x), ScaleCoord(y), angle );
SetFont(prevfont);
}
virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
wxCoord width, wxCoord height,
wxDC *source,
wxCoord xsrc, wxCoord ysrc,
wxRasterOperationMode rop = wxCOPY,
bool useMask = false,
wxCoord xsrcMask = wxDefaultCoord,
wxCoord ysrcMask = wxDefaultCoord)
{
return m_pOrig->DoBlit( ScaleCoord(xdest), ScaleCoord(ydest),
width, height, source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask );
}
virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest,
wxCoord dstWidth, wxCoord dstHeight,
wxDC *source,
wxCoord xsrc, wxCoord ysrc,
wxCoord srcWidth, wxCoord srcHeight,
wxRasterOperationMode rop = wxCOPY,
bool useMask = false,
wxCoord xsrcMask = wxDefaultCoord,
wxCoord ysrcMask = wxDefaultCoord)
{
return m_pOrig->DoStretchBlit( ScaleCoord(xdest), ScaleCoord(ydest), ScaleCoord(dstWidth), ScaleCoord(dstHeight),
source, xsrc, ysrc, srcWidth, srcHeight, rop, useMask, xsrcMask, ysrcMask );
}
virtual wxBitmap DoGetAsBitmap(const wxRect *subrect) const
{
return m_pOrig->DoGetAsBitmap( subrect );
}
#if wxVERSION_NUMBER < 2905
virtual void DoDrawLines(int n, wxPoint points[],
#else
virtual void DoDrawLines(int n, const wxPoint points[],
#endif
wxCoord xoffset, wxCoord yoffset )
{
wxPoint *updPoints = new wxPoint[n];
for(int i = 0; i < n; i++)
{
(updPoints + i)->x = ScaleInt((points + i)->x);
(updPoints + i)->y = ScaleInt((points + i)->y);
}
m_pOrig->DoDrawLines( n, updPoints, ScaleCoord(xoffset), ScaleCoord(yoffset) );
delete [] updPoints;
}
virtual void DrawLines(const wxPointList *list,
wxCoord xoffset, wxCoord yoffset )
{
int i = 0;
wxPoint *pts = new wxPoint[list->GetCount()];
wxPointList::compatibility_iterator node = list->GetFirst();
while( node )
{
*(pts + i) = *node->GetData();
i++;
node = node->GetNext();
}
wxSFDCImplWrapper::DoDrawLines( i, pts, xoffset, yoffset );
delete [] pts;
}
#if wxVERSION_NUMBER < 2905
virtual void DoDrawPolygon(int n, wxPoint points[],
#else
virtual void DoDrawPolygon(int n, const wxPoint points[],
#endif
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle = wxODDEVEN_RULE)
{
wxPoint *updPoints = new wxPoint[n];
for(int i = 0; i < n; i++)
{
(updPoints + i)->x = ScaleInt((points + i)->x);
(updPoints + i)->y = ScaleInt((points + i)->y);
}
m_pOrig->DoDrawPolygon(n, updPoints, ScaleCoord(xoffset), ScaleCoord(yoffset), fillStyle);
delete [] updPoints;
}
virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle)
{
int nTotalPoints = 0;
for(int i = 0; i < n; i++)nTotalPoints += count[i];
wxPoint *updPoints = new wxPoint[nTotalPoints];
for(int i = 0; i < nTotalPoints; i++)
{
(updPoints + i)->x = ScaleInt((points + i)->x);
(updPoints + i)->y = ScaleInt((points + i)->y);
}
m_pOrig->DoDrawPolyPolygon(n, count, updPoints, ScaleCoord(xoffset), ScaleCoord(yoffset), fillStyle);
delete [] updPoints;
}
void DrawPolygon(const wxPointList *list,
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle )
{
int i = 0;
wxPoint *pts = new wxPoint[list->GetCount()];
wxPointList::compatibility_iterator node = list->GetFirst();
while( node )
{
*(pts + i) = *node->GetData();
i++;
node = node->GetNext();
}
wxSFDCImplWrapper::DoDrawPolygon( i, pts, xoffset, yoffset, fillStyle );
delete [] pts;
}
#if wxUSE_SPLINES
void DrawSpline(wxCoord x1, wxCoord y1,
wxCoord x2, wxCoord y2,
wxCoord x3, wxCoord y3);
void DrawSpline(int n, wxPoint points[]);
void DrawSpline(const wxPointList *points) { DoDrawSpline(points); }
virtual void DoDrawSpline(const wxPointList *points)
{
wxPoint *pPt;
wxPointList updPoints;
wxPointList::compatibility_iterator node = points->GetFirst();
while( node )
{
pPt = node->GetData();
updPoints.Append( new wxPoint( ScaleInt(pPt->x), ScaleInt(pPt->y)) );
node = node->GetNext();
}
m_pOrig->DoDrawSpline( &updPoints );
updPoints.DeleteContents( true );
updPoints.Clear();
}
#endif
// ---------------------------------------------------------
// wxMemoryDC Impl API
virtual void DoSelect(const wxBitmap& bmp) { m_pOrig->DoSelect( bmp ); }
virtual const wxBitmap& GetSelectedBitmap() const { return m_pOrig->GetSelectedBitmap(); }
virtual wxBitmap& GetSelectedBitmap() { return m_pOrig->GetSelectedBitmap(); }
// ---------------------------------------------------------
// wxPrinterDC Impl API
virtual wxRect GetPaperRect() const { return m_pOrig->GetPaperRect(); }
virtual int GetResolution() const { return m_pOrig->GetResolution(); }
protected:
/*! \brief Pointer to original DC implementation. */
wxDCImpl *m_pOrig;
/*! \brief Global graphics scale. */
double m_nScale;
/**
* \brief Scale given value.
* \param val Value to scale
* \return Scaled value
*/
wxCoord ScaleCoord(wxCoord val){return (wxCoord)ceil((double)val*m_nScale);}
/**
* \brief Scale given value.
* \param val Value to scale
* \return Scaled value
*/
wxCoord ScaleInt(int val){return (int)ceil((double)val*m_nScale);}
};
/*! \brief Class acts as a wrapper for given DC class and provides modified
* drawing functions cooperating with the shape canvas able to draw scaled graphics.
* All drawing operations performed by the shapes should be done via this class otherwise
* the global scalling capabilities provided by the shape canvas wont be available.
* \sa wxSFShapeCanvas
*/
class WXDLLIMPEXP_SF wxSFScaledDC : public wxDC {
public:
wxSFScaledDC( wxWindowDC* target, double scale );
virtual ~wxSFScaledDC();
};
#endif // wxVERSION_NUMBER < 2900
#endif // _WXSFSCALEDDC_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,67 @@
/***************************************************************
* Name: ShapeDataObject.h
* Purpose: Defines shape data object class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFSHAPEDATAOBJECT_H
#define _WXSFSHAPEDATAOBJECT_H
#include <wx/wxsf/DiagramManager.h>
/*!
* \brief Class encapsulating data object used during clipboard operations with shapes.
*/
class wxSFShapeDataObject : public wxDataObjectSimple
{
public:
/*!
* \brief Default constructor
* \param format Data format
*/
wxSFShapeDataObject(const wxDataFormat& format);
/*!
* \brief User constructor
* \param format Data format
* \param selection List of shapes which should be stored in the data object
* \param manager Pointer to diagram manager which manages stored shapes
*/
wxSFShapeDataObject(const wxDataFormat& format, const ShapeList& selection, wxSFDiagramManager* manager);
/*! \brief Destructor */
virtual ~wxSFShapeDataObject(void);
/*! \brief Function returns sizes of the data object */
virtual size_t GetDataSize() const;
/*!
* \brief Function should export data from data object to given buffer.
* \param buf External output data buffer
* \return TRUE on success, otherwise FALSE
*/
virtual bool GetDataHere(void* buf) const;
/*!
* \brief Function should inport data from data object from given buffer.
* \param len Data lenght
* \param buf External input data buffer
* \return TRUE on success, otherwise FALSE
*/
virtual bool SetData(size_t len, const void* buf);
wxTextDataObject m_Data;
protected:
/*!
* \brief Serialize shapes to data object.
* \param selection List of shapes which should be serialized
* \param manager Parent diagram manager
* \return String containing serialized information
*/
wxString SerializeSelectedShapes(const ShapeList& selection, wxSFDiagramManager* manager);
};
#endif //_WXSFSHAPEDATAOBJECT_H

View File

@@ -0,0 +1,199 @@
/***************************************************************
* Name: ShapeHandle.h
* Purpose: Defines shape handle class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFSHAPEHANDLE_H
#define _WXSFSHAPEHANDLE_H
#include <wx/list.h>
#include <wx/wxsf/ScaledDC.h>
class WXDLLIMPEXP_SF wxSFShapeBase;
/*! \brief Class encapsulates shape's handle. The class shouldn't be used separately; see
* wxSFShapeBase class for more detailed information about functions used for managing of shape
* handles and handling their events */
class wxSFShapeHandle : public wxObject
{
public:
friend class wxSFShapeBase;
friend class wxSFShapeCanvas;
DECLARE_DYNAMIC_CLASS(wxSFShapeHandle);
/*! \brief Handle type */
enum HANDLETYPE
{
hndLEFTTOP,
hndTOP,
hndRIGHTTOP,
hndRIGHT,
hndRIGHTBOTTOM,
hndBOTTOM,
hndLEFTBOTTOM,
hndLEFT,
hndLINECTRL,
hndLINESTART,
hndLINEEND,
hndUNDEF
};
/*! \brief Default constructor */
wxSFShapeHandle(void);
/*!
* \brief User constructor
* \param parent Parent shape
* \param type Handle type
* \param id Handle ID (usefull only for line controls handles)
*/
wxSFShapeHandle(wxSFShapeBase* parent, HANDLETYPE type, long id = -1);
/*!
* \brief Copy constructor
* \param obj Source object
*/
wxSFShapeHandle(const wxSFShapeHandle& obj);
/*! \brief Destructor */
virtual ~wxSFShapeHandle(void);
// public members accessors
/*!
* \brief Get current handle position.
* \return Handle position
*/
wxPoint GetPosition() const {return m_nCurrPos;}
/*!
* \brief Get current handle delta (difference between current and previous position).
* \return Handle delta
*/
wxPoint GetDelta() const {return m_nCurrPos - m_nPrevPos;}
/*!
* \brief Get current total handle delta (difference between current and starting position
* stored at the begining of the dragging process).
* \return Total handle delta
*/
wxPoint GetTotalDelta() const {return m_nCurrPos - m_nStartPos;}
/*!
* \brief Set handle type.
* \param type Handle type
* \sa HANDLETYPE
*/
void SetType(HANDLETYPE type){m_nType = type;}
/*!
* \brief Get handle type.
* \return Handle type
* \sa HANDLETYPE
*/
HANDLETYPE GetType(){return m_nType;}
/*!
* \brief Show/hide handle
* \param show TRUE if the handle should be visible (active), otherwise FALSE
*/
void Show(bool show){m_fVisible = show;}
/*! \brief Function returns TRUE if the handle is visible, otherwise FALSE */
bool IsVisible(){return m_fVisible;}
/*!
* \brief Get parent shape.
* \return Pointer to parent shape
*/
wxSFShapeBase* GetParentShape(){return m_pParentShape;}
/*!
* \brief Set handle's ID.
* \param id Handle's ID
*/
void SetId(long id){m_nId = id;}
/*!
* \brief Get handle's ID.
* \return id Handle's ID
*/
long GetId(){return m_nId;}
// public functions
/*! \brief Refresh (repaint) the handle */
void Refresh();
/*!
* \brief Find out whether given point is inside the handle.
* \param pos Examined point
* \return TRUE if the point is inside the handle, otherwise FALSE
*/
bool Contains(const wxPoint& pos);
protected:
// protected data members
HANDLETYPE m_nType;
wxSFShapeBase *m_pParentShape;
bool m_fVisible;
bool m_fMouseOver;
// protected functions
/*!
* \brief Draw handle.
* \param dc Device context where the handle will be drawn
*/
void Draw(wxDC& dc);
/*!
* \brief Draw handle in the normal way.
* \param dc Device context where the handle will be drawn
*/
void DrawNormal(wxDC& dc);
/*!
* \brief Draw handle in the "hover" way (the mouse pointer is above the handle area).
* \param dc Device context where the handle will be drawn
*/
void DrawHover(wxDC& dc);
/*!
* \brief Set parent shape.
* \param parent Pointer to parent shape
*/
void SetParentShape(wxSFShapeBase *parent){m_pParentShape = parent;}
/*!
* \brief Get handle rectangle.
* \return Handle rectangle
*/
wxRect GetHandleRect() const;
private:
// private data memders
wxPoint m_nStartPos;
wxPoint m_nPrevPos;
wxPoint m_nCurrPos;
long m_nId;
/*!
* \brief Event handler called when the mouse pointer is moving above shape canvas.
* \param pos Current mouse position
*/
void _OnMouseMove(const wxPoint& pos);
/*!
* \brief Event handler called when the handle is started to be dragged.
* \param pos Current mouse position
*/
void _OnBeginDrag(const wxPoint& pos);
/*!
* \brief Event handler called when the handle is dragged.
* \param pos Current mouse position
*/
void _OnDragging(const wxPoint& pos);
/*!
* \brief Event handler called when the handle is released.
* \param pos Current mouse position
*/
void _OnEndDrag(const wxPoint& pos);
};
WX_DECLARE_LIST(wxSFShapeHandle, HandleList);
#endif //_WXSFSHAPEHANDLE_H

View File

@@ -0,0 +1,85 @@
/***************************************************************
* Name: SolidArrow.h
* Purpose: Defines solid arrow for line shapes
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFSOLIDARROW_H
#define _WXSFSOLIDARROW_H
#include <wx/wxsf/ArrowBase.h>
/*!
* \brief Class extends the wxSFArrowBase class and encapsulates
* arrow shape consisting of a solid triangle pointing to the end of the
* parent line shape.
*/
class WXDLLIMPEXP_SF wxSFSolidArrow : public wxSFArrowBase
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFSolidArrow);
/*! \brief Default constructor. */
wxSFSolidArrow(void);
/*!
* \brief User constructor.
* \param parent Pointer to the parent shape
*/
wxSFSolidArrow(wxSFShapeBase* parent);
/*!
* \brief Copy constructor.
* \param obj Reference to the source object
*/
wxSFSolidArrow(const wxSFSolidArrow& obj);
/*! \brief Destructor. */
virtual ~wxSFSolidArrow(void);
// public functions
// public member data accessors
/*!
* \brief Set a brush filling the arrow's body.
* \param br Reference to the brush
*/
void SetArrowFill(const wxBrush& br) {m_Fill = br;}
/**
* \brief Set a pen used for drawing of the arrow's border.
* \param pen Reference to the pen
*/
void SetArrowPen(const wxPen& pen) {m_Pen = pen;}
/*!
* \brief Get current brush used for filling of the arrow's body.
* \return Constant reference to current brush
*/
const wxBrush& GetArrowFill() const {return m_Fill;}
/**
* \brief Get current pen used for drawing of the arrow's border.
* \return Constant reference to current pen
*/
const wxPen& GetArrowPen() const {return m_Pen;}
// public virtual functions
/*!
* \brief Draw arrow shape at the end of a virtual line.
* \param from Start of the virtual line
* \param to End of the virtual line
* \param dc Device context for drawing
*/
virtual void Draw(const wxRealPoint& from, const wxRealPoint& to, wxDC& dc);
protected:
// protected data members
/*! \brief Arrows brush. */
wxBrush m_Fill;
/*! \brief Arrow pen */
wxPen m_Pen;
// protected functions
void MarkSerializableDataMembers();
};
#endif //_WXSFSOLIDARROW_H

View File

@@ -0,0 +1,196 @@
/***************************************************************
* Name: TextShape.h
* Purpose: Defines static text shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFTEXTSHAPE_H
#define _WXSFTEXTSHAPE_H
#include <wx/wxsf/RectShape.h>
// default values
/*! \brief Default value of wxSFTextShape::m_Font data member. */
#define sfdvTEXTSHAPE_FONT *wxSWISS_FONT
/*! \brief Default value of wxSFTextShape::m_TextColor data member. */
#define sfdvTEXTSHAPE_TEXTCOLOR *wxBLACK
/*! \brief Class encapsulates basic non-editable text shape which is suitable for
* displaying of various text information in the canvas.
* \sa wxSFEditTextShape
*/
class WXDLLIMPEXP_SF wxSFTextShape : public wxSFRectShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFTextShape);
/*! \brief Default constructor. */
wxSFTextShape(void);
/*!
* \brief User constructor.
* \param pos Initial position
* \param txt Text content
* \param manager Pointer to parent diagram manager
*/
wxSFTextShape(const wxRealPoint& pos, const wxString& txt, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Source objct
*/
wxSFTextShape(const wxSFTextShape& obj);
/*! \brief Destructor */
virtual ~wxSFTextShape();
// public member data accessors
/*!
* \brief Set text font.
* \param font Font
*/
void SetFont(const wxFont& font);
/*!
* \brief Get text font.
* \return Font
*/
wxFont& GetFont(){return m_Font;}
/*!
* \brief Set text.
* \param txt Text content
*/
void SetText(const wxString& txt);
/*!
* \brief Get text.
* \return Current text content
*/
wxString GetText() const {return m_sText;}
/*!
* \brief Set text color.
* \param col Text color
*/
void SetTextColour(const wxColour& col){m_TextColor = col;}
/*!
* \brief Get text color.
* \return Current text color
*/
wxColour GetTextColour() const {return m_TextColor;}
// public virtual functions
/*!
* \brief Scale the shape size by in both directions. The function can be overrided if necessary
* (new implementation should call default one ore scale shape's children manualy if neccesary).
* \param x Horizontal scale factor
* \param y Vertical scale factor
* \param children TRUE if the shape's children shoould be scaled as well, otherwise the shape will be updated after scaling via Update() function.
*/
virtual void Scale(double x, double y, bool children = sfWITHCHILDREN);
/*!
* \brief Event handler called during dragging of the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* Default implementation does nothing.
* \param handle Reference to dragged handle
*/
virtual void OnHandle(wxSFShapeHandle& handle);
/*! \brief Upate shape (align all child shapes an resize it to fit them) */
virtual void Update();
// public functions
wxSize GetTextExtent();
void UpdateRectSize();
protected:
// protected data members
wxFont m_Font;
wxColour m_TextColor;
wxString m_sText;
// protected virtual functions
/*!
* \brief Draw the shape in the normal way. The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawNormal(wxDC& dc);
/*!
* \brief Draw the shape in the hower mode (the mouse cursor is above the shape).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHover(wxDC& dc);
/*!
* \brief Draw the shape in the highlighted mode (another shape is dragged over this
* shape and this shape will accept the dragged one if it will be dropped on it).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHighlighted(wxDC& dc);
/*!
* \brief Draw shadow under the shape. The function can be overrided if neccessary.
* \param dc Reference to device context where the shadow will be drawn to
*/
virtual void DrawShadow(wxDC& dc);
/*!
* \brief Serialize shape's properties to the given XML node. The serialization
* routine is automatically called by the framework and should take care about serialization
* of all specific (non-standard) shape's properties.
* \param node Pointer to XML node where the shape's property nodes will be appended to
* \sa xsSerializable::Serialize
*/
virtual wxXmlNode* Serialize(wxXmlNode* node);
/*!
* \brief Deserialize shape's properties from the given XML node. The
* routine is automatically called by the framework and should take care about deserialization
* of all specific (non-standard) shape's properties.
* \param node Pointer to a source XML node containig the shape's property nodes
* \sa xsSerializable::Deserialize
*/
virtual void Deserialize(wxXmlNode* node);
/*!
* \brief Event handler called during dragging of the left shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnLeftHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the top shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnTopHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the right shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnRightHandle(wxSFShapeHandle& handle);
/*!
* \brief Event handler called during dragging of the bottom shape handle.
* The function can be overrided if neccessary.
* \param handle Reference to dragged shape handle
*/
virtual void OnBottomHandle(wxSFShapeHandle& handle);
// protected functions
/*!
* \brief Draw text shape.
* \param dc Device context where the text shape will be drawn to
*/
void DrawTextContent(wxDC& dc);
private:
// private functions
/*! \brief Initialize serializable properties. */
void MarkSerializableDataMembers();
wxCoord m_nLineHeight;
};
#endif //_WXSFTEXTSHAPE_H

View File

@@ -0,0 +1,120 @@
/***************************************************************
* Name: Thumbnail.h
* Purpose: Defines canvas thumbnail class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2009-06-09
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFTHUMBNAIL_H
#define _WXSFTHUMBNAIL_H
#include <wx/wxsf/ShapeCanvas.h>
/**
* \brief Class encalpsulating a shape canvas' thumbnail. This GUI control derived from wxPanel can be associated with
* one shape canvas and can be used for previewing and manipulating of it.
*/
class WXDLLIMPEXP_SF wxSFThumbnail : public wxPanel
{
public:
/** \brief Internally used IDs */
enum IDS
{
ID_UPDATETIMER = wxID_HIGHEST + 1,
IDM_SHOWELEMENTS,
IDM_SHOWCONNECTIONS
};
/** \brief Thumbnail style */
enum THUMBSTYLE
{
/** \brief Show diagram elements (excluding connections) in the thumbnail. */
tsSHOW_ELEMENTS = 1,
/** \brief Show diagram connections in the thumbnail. */
tsSHOW_CONNECTIONS = 2
};
/**
* \brief Constructor.
* \param parent Pointer to parent window
*/
wxSFThumbnail(wxWindow *parent);
/** \brief Destructor. */
virtual ~wxSFThumbnail();
// public member data accessors
/**
* \brief Set the thumbnail style.
* \param style Style value composed of predefined flags
* \sa THUMBSTYLE
*/
void SetThumbStyle(int style) { m_nThumbStyle = style; }
/**
* \brief Get current thumbnail style.
* \return Style value composed of predefined flags
* \sa THUMBSTYLE
*/
int GetThumbStyle() { return m_nThumbStyle; }
// public functions
/**
* \brief Set canvas managed by the thumbnail.
* \param canvas Pointer to shape canvas
*/
void SetCanvas(wxSFShapeCanvas *canvas);
// public virtual functions
/**
* \brief Implementation of drawing of the thumbnail's content. This virtual function can be overrided
* by the user for customization of the thumbnail appearance.
* \param dc Reference to output device context
*/
virtual void DrawContent(wxDC &dc);
protected:
// protected data members
wxSFShapeCanvas *m_pCanvas; /** \brief Pointer to managed shape canvas. */
wxTimer m_UpdateTimer; /** \brief Timer user for the thumbnail's update */
wxPoint m_nPrevMousePos; /** \brief Auxiliary varialble */
double m_nScale; /** \brief Current thumbnail's scale */
int m_nThumbStyle; /** \brief Current thumbnail's style */
// protected event handlers
/** \brief Internally used event handler. */
void _OnPaint( wxPaintEvent &event );
// protected functions
/**
* \brief Get offset (view start) of managed shape canvas defined in pixels.
* \return Canvas offset in pixels
*/
wxSize GetCanvasOffset();
private:
// private event handlers
/** \brief Internally used event handler. */
void _OnEraseBackground( wxEraseEvent& event );
/** \brief Internally used event handler. */
void _OnMouseMove( wxMouseEvent &event );
/** \brief Internally used event handler. */
void _OnLeftDown( wxMouseEvent &event );
/** \brief Internally used event handler. */
void _OnRightDown( wxMouseEvent &event );
/** \brief Internally used event handler. */
void _OnTimer( wxTimerEvent &event );
/** \brief Internally used event handler. */
void _OnShowElements( wxCommandEvent &event );
/** \brief Internally used event handler. */
void _OnShowConnections( wxCommandEvent &event );
/** \brief Internally used event handler. */
void _OnUpdateShowElements( wxUpdateUIEvent &event );
/** \brief Internally used event handler. */
void _OnUpdateShowConnections( wxUpdateUIEvent &event );
DECLARE_EVENT_TABLE();
};
#endif //_WXSFTHUMBNAIL_H

View File

@@ -0,0 +1,59 @@
/***************************************************************
* Name: wxShapeFramework.h
* Purpose: Main header file
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSF_H_
#define _WXSF_H_
// main library classes
#include <wx/wxsf/DiagramManager.h>
#include <wx/wxsf/ShapeCanvas.h>
#include <wx/wxsf/Thumbnail.h>
#include <wx/wxsf/AutoLayout.h>
// shapes' declarations
#include <wx/wxsf/RectShape.h>
#include <wx/wxsf/RoundRectShape.h>
#include <wx/wxsf/FixedRectShape.h>
#include <wx/wxsf/EllipseShape.h>
#include <wx/wxsf/CircleShape.h>
#include <wx/wxsf/DiamondShape.h>
#include <wx/wxsf/TextShape.h>
#include <wx/wxsf/EditTextShape.h>
#include <wx/wxsf/BitmapShape.h>
#include <wx/wxsf/PolygonShape.h>
#include <wx/wxsf/ControlShape.h>
#include <wx/wxsf/GridShape.h>
#include <wx/wxsf/FlexGridShape.h>
// arrows' declarations
#include <wx/wxsf/OpenArrow.h>
#include <wx/wxsf/SolidArrow.h>
#include <wx/wxsf/DiamondArrow.h>
#include <wx/wxsf/CircleArrow.h>
// connection lines' declarations
#include <wx/wxsf/LineShape.h>
#include <wx/wxsf/CurveShape.h>
#include <wx/wxsf/OrthoShape.h>
#include <wx/wxsf/RoundOrthoShape.h>
// library events
#include <wx/wxsf/SFEvents.h>
// printing support
#include <wx/wxsf/Printout.h>
// common functions
#include <wx/wxsf/CommonFcn.h>
// serialize/deserialize functionality
#include <wx/wxxmlserializer/XmlSerializer.h>
#endif //_WXSF_H_

View File

@@ -0,0 +1,21 @@
#ifndef _XSDEFS_H
#define _XSDEFS_H
#ifdef USING_SOURCE_XS
#define WXDLLIMPEXP_XS
#define WXDLLIMPEXP_DATA_XS(type) type
#elif defined( LIB_USINGDLL )
#define WXDLLIMPEXP_XS
#define WXDLLIMPEXP_DATA_XS(type)
#elif defined( WXMAKINGDLL_WXXS )
#define WXDLLIMPEXP_XS WXEXPORT
#define WXDLLIMPEXP_DATA_XS(type) WXEXPORT type
#elif defined(WXUSINGDLL)
#define WXDLLIMPEXP_XS WXIMPORT
#define WXDLLIMPEXP_DATA_XS(type) WXIMPORT type
#else // not making nor using DLL
#define WXDLLIMPEXP_XS
#define WXDLLIMPEXP_DATA_XS(type) type
#endif
#endif//_XSDEFS_H

View File

@@ -0,0 +1,321 @@
/***************************************************************
* Name: PropertyIO.cpp
* Purpose: Declares data types I/O and conversion functions
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-10-28
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _XSPROPERTYIO_H
#define _XSPROPERTYIO_H
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/hashmap.h>
#include <wx/xml/xml.h>
#include <wx/tokenzr.h>
#include <wx/list.h>
#include <wx/wxxmlserializer/Defs.h>
class WXDLLIMPEXP_XS xsProperty;
class WXDLLIMPEXP_XS xsSerializable;
class WXDLLIMPEXP_XS SerializableList;
namespace wxXS
{
WX_DECLARE_OBJARRAY_WITH_DECL(wxRealPoint, RealPointArray, class WXDLLIMPEXP_XS);
WX_DECLARE_LIST_WITH_DECL(wxRealPoint, RealPointList, class WXDLLIMPEXP_XS);
WX_DEFINE_USER_EXPORTED_ARRAY_CHAR(char, CharArray, class WXDLLIMPEXP_XS);
WX_DEFINE_USER_EXPORTED_ARRAY_INT(int, IntArray, class WXDLLIMPEXP_XS);
WX_DEFINE_USER_EXPORTED_ARRAY_LONG(long, LongArray, class WXDLLIMPEXP_XS);
WX_DEFINE_USER_EXPORTED_ARRAY_DOUBLE(double, DoubleArray, class WXDLLIMPEXP_XS);
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxString, StringMap, class WXDLLIMPEXP_XS);
}
/*!
* \brief Base class encapsulating a property I/O handler. The class is used by
* the xsSerializable class and is responsiblefor reading and writing of an XML node
* containing property information. Each supported property (data) type should have
* its own I/O handler class. Moreover, all derived classes must provide public functions
* 'static wxString classname::ToString(datatype value)' and 'static datatype classname::
* FromString( const wxString& value )' responsible for conversion between datatype and
* and its string representation (these functions are used internally by class virtual functions.
*/
class WXDLLIMPEXP_XS xsPropertyIO : public wxObject
{
public:
DECLARE_DYNAMIC_CLASS(xsProperty);
/*! \brief Constructor. */
xsPropertyIO(){;}
/*! \brief Destructor. */
virtual ~xsPropertyIO(){;}
/*!
* \brief Read content of the property XML node and store it to given property object.
* \param property Pointer to the target property object
* \param source Pointer to the source XML node
*/
virtual void Read(xsProperty *property, wxXmlNode *source){wxUnusedVar(property);wxUnusedVar(source);}
/*!
* \brief Write content of given property object to target XML node.
* \param property Pointer to the source property object
* \param target Pointer to the target XML node
*/
virtual void Write(xsProperty *property, wxXmlNode *target){wxUnusedVar(property);wxUnusedVar(target);}
/*!
* \brief Get textual representation of current property value.
* \param property Pointer to the source property object
* \return Textual representation of property's value
*/
virtual wxString GetValueStr(xsProperty *property){wxUnusedVar(property);return wxT("");}
/*!
* \brief Set value defined by its textual representation to given property.
* \param property Pointer to the target property object
* \param valstr Textual representation of given value
*/
virtual void SetValueStr(xsProperty *property, const wxString& valstr){wxUnusedVar(property); wxUnusedVar(valstr);}
/*!
* \brief Create new XML node of given name and value and assign it to the given
* parent XML node.
* \param parent Pointer to parent XML node
* \param name Name of new XML node
* \param value Content of new XML node
* \param type Type of new XML (content) node
*/
static wxXmlNode* AddPropertyNode(wxXmlNode* parent, const wxString& name, const wxString& value, wxXmlNodeType type = wxXML_TEXT_NODE );
protected:
/*!
* \brief Append info about the source property to given XML node.
* \param source Pointer to the source property
* \param target Pointer to modified XML node
*/
void AppendPropertyType(xsProperty *source, wxXmlNode *target);
};
/*!
* \brief Macro suitable for declaration of new property I/O handler
* \param datatype Property's data type
* \param name Handler class name
*/
#define XS_DECLARE_IO_HANDLER(datatype, name) \
class name : public xsPropertyIO \
{ \
public: \
DECLARE_DYNAMIC_CLASS(name); \
name(){;} \
virtual ~name(){;} \
\
virtual void Read(xsProperty *property, wxXmlNode *source); \
virtual void Write(xsProperty *property, wxXmlNode *target); \
virtual wxString GetValueStr(xsProperty *property); \
virtual void SetValueStr(xsProperty *property, const wxString& valstr); \
static wxString ToString(const datatype& value); \
static datatype FromString(const wxString& value); \
}; \
/*!
* \brief Macro suitable for declaration of exported new property I/O handler
* \param datatype Property's data type
* \param name Handler class name
* \param decoration Class decoration
*/
#define XS_DECLARE_EXPORTED_IO_HANDLER(datatype, name, decoration) \
class decoration name : public xsPropertyIO \
{ \
public: \
DECLARE_DYNAMIC_CLASS(name); \
name(){;} \
virtual ~name(){;} \
\
virtual void Read(xsProperty *property, wxXmlNode *source); \
virtual void Write(xsProperty *property, wxXmlNode *target); \
virtual wxString GetValueStr(xsProperty *property); \
virtual void SetValueStr(xsProperty *property, const wxString& valstr); \
static wxString ToString(const datatype& value); \
static datatype FromString(const wxString& value); \
}; \
/*!
* \brief Macro suitable for implementation of new property I/O handler
* \param datatype Property's data type
* \param name Handler class name
*/
#define XS_DEFINE_IO_HANDLER(datatype, name) \
IMPLEMENT_DYNAMIC_CLASS(name, xsPropertyIO); \
\
void name::Read(xsProperty *property, wxXmlNode *source) \
{ \
*((datatype*)property->m_pSourceVariable) = FromString(source->GetNodeContent()); \
} \
\
void name::Write(xsProperty *property, wxXmlNode *target) \
{ \
wxString val = ToString(*((datatype*)property->m_pSourceVariable)); \
\
if(val != property->m_sDefaultValueStr) \
{ \
wxXmlNode *newNode = AddPropertyNode(target, wxT("property"), val); \
AppendPropertyType(property, newNode); \
} \
} \
\
wxString name::GetValueStr(xsProperty *property) \
{ \
return ToString(*((datatype*)property->m_pSourceVariable)); \
} \
\
void name::SetValueStr(xsProperty *property, const wxString& valstr) \
{ \
*((datatype*)property->m_pSourceVariable) = FromString(valstr); \
} \
/*!
* \brief Property class encapsulating I/O functions used by 'wxString' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxString, xsStringPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'wxChar' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxChar, xsCharPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'long' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(long, xsLongPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'int' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(int, xsIntPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'bool' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(bool, xsBoolPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'double' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(double, xsDoublePropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'float' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(float, xsFloatPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'wxPoint' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxPoint, xsPointPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'wxSize' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxSize, xsSizePropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'wxRealPoint' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxRealPoint, xsRealPointPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'wxColour' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxColour, xsColourPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'wxPen' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxPen, xsPenPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'wxBrush' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxBrush, xsBrushPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'wxFont' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxFont, xsFontPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'wxArrayString' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxArrayString, xsArrayStringPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'CharArray' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::CharArray, xsArrayCharPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'IntArray' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::IntArray, xsArrayIntPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'LongArray' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::LongArray, xsArrayLongPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'DoubleArray' properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::DoubleArray, xsArrayDoublePropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'RealPointArray' (array of
* integer values) properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::RealPointArray, xsArrayRealPointPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'ListRealPoint' (list of
* wxRealPoint objects) properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::RealPointList, xsListRealPointPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'SerializableList' (list of
* xsSerializable objects) properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(SerializableList, xsListSerializablePropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'serializabledynamic' (xsSerializable
* dynamic class objects which are created during the deserialization process) properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(xsSerializable, xsDynObjPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'serializabledynamicnocreate' (already
* existing xsSerializable dynamic class objects) properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(xsSerializable, xsDynNCObjPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'serializablestatic' (static
* xsSerializable class objects) properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(xsSerializable, xsStaticObjPropIO, WXDLLIMPEXP_XS);
/*!
* \brief Property class encapsulating I/O functions used by 'mapstring' (string hash map) properties.
*/
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::StringMap, xsMapStringPropIO, WXDLLIMPEXP_XS);
WX_DECLARE_HASH_MAP( wxString, xsPropertyIO*, wxStringHash, wxStringEqual, PropertyIOMap );
#endif //_XSPROPERTYIO_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,80 @@
/***************************************************************
* Name: ArrowBase.cpp
* Purpose: Implements line arrow base class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/ArrowBase.h"
#include "wx/wxsf/LineShape.h"
#include "wx/wxsf/CommonFcn.h"
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFArrowBase, xsSerializable);
wxSFArrowBase::wxSFArrowBase(void)
{
m_pParentShape = NULL;
}
wxSFArrowBase::wxSFArrowBase(wxSFShapeBase* parent)
{
m_pParentShape = parent;
}
wxSFArrowBase::wxSFArrowBase(const wxSFArrowBase& obj)
: xsSerializable(obj)
{
m_pParentShape = obj.m_pParentShape;
}
wxSFArrowBase::~wxSFArrowBase(void)
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFArrowBase::Draw(const wxRealPoint& from, const wxRealPoint& to, wxDC& dc)
{
// HINT: override it for custom drawing...
wxUnusedVar( from );
wxUnusedVar( to );
wxUnusedVar( dc );
}
//----------------------------------------------------------------------------------//
// protected functions
//----------------------------------------------------------------------------------//
void wxSFArrowBase::TranslateArrow(wxPoint *trg, const wxRealPoint *src, int n, const wxRealPoint &from, const wxRealPoint& to)
{
double cosa, sina, dist;
// calculate distance between line points
dist = Distance(from, to);
// calculate sin and cos of given line segment
sina = (from.y - to.y)/dist;
cosa = (from.x - to.x)/dist;
// rotate arrow
for(int i = 0; i<n; i++)
{
trg->x = (int)((src->x*cosa-src->y*sina)+to.x);
trg->y = (int)((src->x*sina+src->y*cosa)+to.y);
trg++;
src++;
}
}

View File

@@ -0,0 +1,269 @@
/***************************************************************
* Name: BitmapShape.cpp
* Purpose: Implements bitmap shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/BitmapShape.h"
#include "wx/wxsf/ShapeCanvas.h"
#include "wx/wxsf/CommonFcn.h"
#include "res/NoSource.xpm"
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFBitmapShape, wxSFRectShape);
wxSFBitmapShape::wxSFBitmapShape(void)
: wxSFRectShape()
{
m_sBitmapPath = wxT("");
m_fRescaleInProgress = false;
m_fCanScale = sfdvBITMAPSHAPE_SCALEIMAGE;
CreateFromXPM(NoSource_xpm);
// mark serialized properties
MarkSerializableDataMembers();
}
wxSFBitmapShape::wxSFBitmapShape(const wxRealPoint& pos, const wxString& bitmapPath, wxSFDiagramManager* manager)
: wxSFRectShape(pos, wxRealPoint(1, 1), manager)
{
m_sBitmapPath = wxT("");
m_fRescaleInProgress = false;
m_fCanScale = sfdvBITMAPSHAPE_SCALEIMAGE;
CreateFromFile(bitmapPath);
// mark serialized properties
MarkSerializableDataMembers();
}
wxSFBitmapShape::wxSFBitmapShape(const wxSFBitmapShape& obj)
: wxSFRectShape(obj)
{
m_sBitmapPath = obj.m_sBitmapPath;
m_fRescaleInProgress = false;
m_fCanScale = obj.m_fCanScale;
// create real bitmap copy
m_Bitmap = obj.m_Bitmap.GetSubBitmap(wxRect(0, 0, obj.m_Bitmap.GetWidth(), obj.m_Bitmap.GetHeight()));
m_OriginalBitmap = m_Bitmap;
// mark serialized properties
MarkSerializableDataMembers();
}
wxSFBitmapShape::~wxSFBitmapShape(void)
{
}
void wxSFBitmapShape::MarkSerializableDataMembers()
{
XS_SERIALIZE(m_sBitmapPath, wxT("path"));
XS_SERIALIZE_EX(m_fCanScale, wxT("scale_image"), sfdvBITMAPSHAPE_SCALEIMAGE);
}
//----------------------------------------------------------------------------------//
// public functions
//----------------------------------------------------------------------------------//
bool wxSFBitmapShape::CreateFromFile(const wxString& file, wxBitmapType type)
{
bool fSuccess = true;
// load bitmap from the file
//if((m_sBitmapPath != file) || (!m_Bitmap.IsOk()))
{
m_sBitmapPath = file;
if(wxFileExists(m_sBitmapPath))
{
fSuccess = m_Bitmap.LoadFile(m_sBitmapPath, type);
}
else
fSuccess = false;
}
if(!fSuccess)
{
m_Bitmap = wxBitmap(NoSource_xpm);
}
m_OriginalBitmap = m_Bitmap;
m_nRectSize.x = m_Bitmap.GetWidth();
m_nRectSize.y = m_Bitmap.GetHeight();
if(m_fCanScale)
{
AddStyle(sfsSIZE_CHANGE);
}
else
RemoveStyle(sfsSIZE_CHANGE);
return fSuccess;
}
bool wxSFBitmapShape::CreateFromXPM(const char* const* bits)
{
bool fSuccess = false;
m_sBitmapPath = wxT("");
// create bitmap from XPM
m_Bitmap = wxBitmap(bits);
fSuccess = m_Bitmap.IsOk();
if(!fSuccess)
{
m_Bitmap = wxBitmap(NoSource_xpm);
}
m_OriginalBitmap = m_Bitmap;
m_nRectSize.x = m_Bitmap.GetWidth();
m_nRectSize.y = m_Bitmap.GetHeight();
if(m_fCanScale)
{
AddStyle(sfsSIZE_CHANGE);
}
else
RemoveStyle(sfsSIZE_CHANGE);
return fSuccess;
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFBitmapShape::Scale(double x, double y, bool children)
{
if(m_fCanScale)
{
m_nRectSize.x *= x;
m_nRectSize.y *= y;
if(!m_fRescaleInProgress) RescaleImage(m_nRectSize);
// call default function implementation (needed for scaling of shape's children)
wxSFShapeBase::Scale(x, y, children);
}
}
void wxSFBitmapShape::OnBeginHandle(wxSFShapeHandle& handle)
{
if(m_fCanScale)
{
m_fRescaleInProgress = true;
m_nPrevPos = GetAbsolutePosition();
}
wxSFShapeBase::OnBeginHandle(handle);
}
void wxSFBitmapShape::OnHandle(wxSFShapeHandle& handle)
{
if(m_fCanScale)
{
wxSFRectShape::OnHandle(handle);
}
else
RemoveStyle(sfsSIZE_CHANGE);
}
void wxSFBitmapShape::OnEndHandle(wxSFShapeHandle& handle)
{
if(m_fCanScale)
{
m_fRescaleInProgress = false;
RescaleImage(m_nRectSize);
}
wxSFShapeBase::OnEndHandle(handle);
}
//----------------------------------------------------------------------------------//
// protected functions
//----------------------------------------------------------------------------------//
void wxSFBitmapShape::RescaleImage(const wxRealPoint& size)
{
if( GetParentCanvas() )
{
wxImage image = m_OriginalBitmap.ConvertToImage();
if( wxSFShapeCanvas::IsGCEnabled() )
{
image.Rescale(int(size.x), int(size.y), wxIMAGE_QUALITY_NORMAL);
}
else
{
image.Rescale(int(size.x * GetParentCanvas()->GetScale()), int(size.y * GetParentCanvas()->GetScale()), wxIMAGE_QUALITY_NORMAL);
}
m_Bitmap = wxBitmap(image);
}
}
//----------------------------------------------------------------------------------//
// protected virtual functions
//----------------------------------------------------------------------------------//
void wxSFBitmapShape::DrawNormal(wxDC& dc)
{
// HINT: overload it for custom actions...
if(m_fRescaleInProgress)
{
dc.DrawBitmap(m_Bitmap, Conv2Point(m_nPrevPos));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetPen(wxPen(wxColour(100, 100, 100), 1, wxDOT));
dc.DrawRectangle(Conv2Point(GetAbsolutePosition()), Conv2Size(m_nRectSize));
dc.SetPen(wxNullPen);
dc.SetBrush(wxNullBrush);
}
else
dc.DrawBitmap(m_Bitmap, Conv2Point(GetAbsolutePosition()));
}
void wxSFBitmapShape::DrawHover(wxDC& dc)
{
// HINT: overload it for custom actions...
wxRealPoint pos = GetAbsolutePosition();
dc.DrawBitmap(m_Bitmap, Conv2Point(pos));
dc.SetPen(wxPen(m_nHoverColor, 1));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(Conv2Point(pos), Conv2Size(m_nRectSize));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFBitmapShape::DrawHighlighted(wxDC& dc)
{
// HINT: overload it for custom actions...
wxRealPoint pos = GetAbsolutePosition();
dc.DrawBitmap(m_Bitmap, Conv2Point(pos));
dc.SetPen(wxPen(m_nHoverColor, 2));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(Conv2Point(pos), Conv2Size(m_nRectSize));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}

View File

@@ -0,0 +1,59 @@
/***************************************************************
* Name: BitmapShapeXml.cpp
* Purpose: Implements bitmap shape's serialization capability
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/BitmapShape.h"
#include "wx/wxsf/CommonFcn.h"
//----------------------------------------------------------------------------------//
// Serialization
//----------------------------------------------------------------------------------//
wxXmlNode* wxSFBitmapShape::Serialize(wxXmlNode* node)
{
// HINT: overload it for custom actions...
if(node)
{
node = wxSFRectShape::Serialize(node);
}
return node;
}
void wxSFBitmapShape::Deserialize(wxXmlNode* node)
{
// HINT: overload it for custom actions...
wxSFRectShape::Deserialize(node);
wxRealPoint prevSize = m_nRectSize;
if(!m_sBitmapPath.IsEmpty())
{
CreateFromFile(m_sBitmapPath);
}
if(m_fCanScale)
{
if(m_nRectSize != prevSize)
{
m_nRectSize = prevSize;
RescaleImage(prevSize);
}
else
Scale(1, 1);
}
}

View File

@@ -0,0 +1,176 @@
/***************************************************************
* Name: CanvasHistory.cpp
* Purpose: Implements manager for stored canvas states
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include <wx/mstream.h>
#include "wx/wxsf/CanvasHistory.h"
#include "wx/wxsf/ShapeCanvas.h"
wxSFCanvasHistory::wxSFCanvasHistory(MODE hmode)
{
m_nWorkingMode = hmode;
m_pParentCanvas = NULL;
m_pCurrentCanvasState = NULL;
m_nHistoryDepth = sfDEFAULT_MAX_CANVAS_STATES;
m_lstCanvasStates.DeleteContents(true);
}
wxSFCanvasHistory::wxSFCanvasHistory(wxSFShapeCanvas *canvas, MODE hmode)
{
wxASSERT(canvas);
m_nWorkingMode = hmode;
m_pParentCanvas = canvas;
m_pCurrentCanvasState = NULL;
m_nHistoryDepth = sfDEFAULT_MAX_CANVAS_STATES;
m_lstCanvasStates.DeleteContents(true);
}
wxSFCanvasHistory::~wxSFCanvasHistory(void)
{
Clear();
}
//----------------------------------------------------------------------------------//
// Public functions
//----------------------------------------------------------------------------------//
void wxSFCanvasHistory::SetMode(MODE hmode)
{
Clear();
m_nWorkingMode = hmode;
}
void wxSFCanvasHistory::Clear()
{
m_lstCanvasStates.Clear();
m_pCurrentCanvasState = NULL;
}
void wxSFCanvasHistory::SaveCanvasState()
{
wxASSERT(m_pParentCanvas);
wxASSERT(m_pParentCanvas->GetDiagramManager());
if( m_nWorkingMode == histUSE_CLONING )
{
if(m_pParentCanvas && m_pParentCanvas->GetDiagramManager())
{
// create temporal copy of current diagram manager
wxSFDiagramManager *pDataManager = (wxSFDiagramManager*)m_pParentCanvas->GetDiagramManager()->Clone();
if( !pDataManager ) return;
// delete all states newer than the current state
if( m_pCurrentCanvasState )
{
StateList::compatibility_iterator delnode = m_lstCanvasStates.GetLast();
while(delnode->GetData() != m_pCurrentCanvasState)
{
m_lstCanvasStates.DeleteNode(delnode);
delnode = m_lstCanvasStates.GetLast();
}
}
// create and append new canvas state
m_pCurrentCanvasState = new wxSFCanvasState(pDataManager);
m_lstCanvasStates.Append(m_pCurrentCanvasState);
// check the history bounds
if(m_lstCanvasStates.GetCount() > m_nHistoryDepth)
{
m_lstCanvasStates.DeleteNode(m_lstCanvasStates.GetFirst());
}
}
}
else if( m_nWorkingMode == histUSE_SERIALIZATION )
{
wxMemoryOutputStream outstream;
if(outstream.IsOk() && m_pParentCanvas && m_pParentCanvas->GetDiagramManager())
{
// serialize canvas to memory stream
m_pParentCanvas->GetDiagramManager()->SerializeToXml(outstream);
// delete all states newer than the current state
if( m_pCurrentCanvasState )
{
StateList::compatibility_iterator delnode = m_lstCanvasStates.GetLast();
while(delnode->GetData() != m_pCurrentCanvasState)
{
m_lstCanvasStates.DeleteNode(delnode);
delnode = m_lstCanvasStates.GetLast();
}
}
// create and append new canvas state
m_pCurrentCanvasState = new wxSFCanvasState(outstream.GetOutputStreamBuffer());
m_lstCanvasStates.Append(m_pCurrentCanvasState);
// check the history bounds
if(m_lstCanvasStates.GetCount() > m_nHistoryDepth)
{
m_lstCanvasStates.DeleteNode(m_lstCanvasStates.GetFirst());
}
}
}
}
void wxSFCanvasHistory::RestoreOlderState()
{
if( !m_pCurrentCanvasState ) return;
// move to previous canvas state and restore it if exists
StateList::compatibility_iterator node = m_lstCanvasStates.Find(m_pCurrentCanvasState)->GetPrevious();
if( node ) m_pCurrentCanvasState = node->GetData();
else
m_pCurrentCanvasState = NULL;
if( m_pCurrentCanvasState )
{
m_pCurrentCanvasState->Restore(m_pParentCanvas);
}
}
void wxSFCanvasHistory::RestoreNewerState()
{
if( !m_pCurrentCanvasState ) return;
// move to next canvas state and restore it if exists
StateList::compatibility_iterator node = m_lstCanvasStates.Find(m_pCurrentCanvasState)->GetNext();
if( node ) m_pCurrentCanvasState = node->GetData();
else
m_pCurrentCanvasState = NULL;
if( m_pCurrentCanvasState )
{
m_pCurrentCanvasState->Restore(m_pParentCanvas);
}
}
bool wxSFCanvasHistory::CanUndo()
{
return ((m_pCurrentCanvasState != NULL) && (m_pCurrentCanvasState != m_lstCanvasStates.GetFirst()->GetData()));
}
bool wxSFCanvasHistory::CanRedo()
{
return ((m_pCurrentCanvasState != NULL) && (m_pCurrentCanvasState != m_lstCanvasStates.GetLast()->GetData()));
}

View File

@@ -0,0 +1,83 @@
/***************************************************************
* Name: CanvasState.cpp
* Purpose: Implements container for stored canvas state
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include <wx/mstream.h>
#include "wx/wxsf/CanvasState.h"
#include "wx/wxsf/ShapeCanvas.h"
#include <wx/listimpl.cpp>
WX_DEFINE_LIST(StateList);
wxSFCanvasState::wxSFCanvasState(wxStreamBuffer *data)
{
// copy content of stream buffer to local memory buffer
if(data)
{
data->ResetBuffer();
m_dataBuffer.AppendData(data->GetBufferStart(), data->GetDataLeft());
m_dataBuffer.AppendByte(0);
}
m_pDataManager = NULL;
}
wxSFCanvasState::wxSFCanvasState(wxSFDiagramManager *data)
{
wxASSERT(data);
m_pDataManager = data;
}
wxSFCanvasState::~wxSFCanvasState(void)
{
if( m_pDataManager)
{
delete m_pDataManager;
}
}
//----------------------------------------------------------------------------------//
// Public functions
//----------------------------------------------------------------------------------//
void wxSFCanvasState::Restore(wxSFShapeCanvas* canvas)
{
wxASSERT(canvas);
wxASSERT(canvas->GetDiagramManager());
if( m_pDataManager )
{
// copy content of stored temporal data manager into the currently used one
canvas->GetDiagramManager()->CopyItems(*m_pDataManager);
canvas->Refresh(false);
}
else
{
// create input stream from local memory buffer
wxMemoryInputStream instream(m_dataBuffer.GetData(), m_dataBuffer.GetDataLen()-1);
// deserialize canvas content
if(instream.IsOk() && canvas && canvas->GetDiagramManager())
{
// clear all previous canvas content
canvas->GetDiagramManager()->Clear();
canvas->GetDiagramManager()->DeserializeFromXml(instream);
canvas->Refresh(false);
}
}
}

View File

@@ -0,0 +1,66 @@
/***************************************************************
* Name: SolidArrow.cpp
* Purpose: Implements solid arrow for line shapes
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/CircleArrow.h"
#include "wx/wxsf/CommonFcn.h"
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFCircleArrow, wxSFSolidArrow);
wxSFCircleArrow::wxSFCircleArrow(void)
: wxSFSolidArrow()
{
m_nRadius = sfdvARROW_RADIUS;
XS_SERIALIZE_INT_EX( m_nRadius, wxT("radius"), sfdvARROW_RADIUS );
}
wxSFCircleArrow::wxSFCircleArrow(wxSFShapeBase* parent)
: wxSFSolidArrow(parent)
{
m_nRadius = sfdvARROW_RADIUS;
XS_SERIALIZE_INT_EX( m_nRadius, wxT("radius"), sfdvARROW_RADIUS );
}
wxSFCircleArrow::wxSFCircleArrow(const wxSFCircleArrow& obj)
: wxSFSolidArrow(obj)
{
m_nRadius = obj.m_nRadius;
XS_SERIALIZE_INT_EX( m_nRadius, wxT("radius"), sfdvARROW_RADIUS );
}
wxSFCircleArrow::~wxSFCircleArrow(void)
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFCircleArrow::Draw(const wxRealPoint &from, const wxRealPoint &to, wxDC& dc)
{
wxUnusedVar(from);
dc.SetPen(m_Pen);
dc.SetBrush(m_Fill);
dc.DrawCircle( Conv2Point( to ), m_nRadius );
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}

View File

@@ -0,0 +1,138 @@
/***************************************************************
* Name: CircleShape.cpp
* Purpose: Implements circle shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/CircleShape.h"
#include "wx/wxsf/CommonFcn.h"
#include "wx/wxsf/ShapeCanvas.h"
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFCircleShape, wxSFSquareShape);
wxSFCircleShape::wxSFCircleShape(void)
: wxSFSquareShape()
{
SetRectSize(50, 50);
}
wxSFCircleShape::wxSFCircleShape(const wxRealPoint& pos, double radius, wxSFDiagramManager* manager)
: wxSFSquareShape(pos, radius, manager)
{
}
wxSFCircleShape::wxSFCircleShape(const wxSFCircleShape& obj)
: wxSFSquareShape(obj)
{
}
wxSFCircleShape::~wxSFCircleShape()
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
wxRealPoint wxSFCircleShape::GetBorderPoint(const wxRealPoint& start, const wxRealPoint& end)
{
double dist = Distance(start, end);
wxRealPoint nCenter = GetAbsolutePosition() + wxRealPoint(m_nRectSize.x/2, m_nRectSize.y/2);
if(dist)
{
double srcDx = m_nRectSize.x/2*(end.x-start.x)/dist - (start.x-nCenter.x);
double srcDy = m_nRectSize.y/2*(end.y-start.y)/dist - (start.y-nCenter.y);
return wxRealPoint(start.x + srcDx, start.y + srcDy);
}
else
return nCenter;
}
bool wxSFCircleShape::Contains(const wxPoint& pos)
{
wxRealPoint center = GetAbsolutePosition() + wxRealPoint(m_nRectSize.x/2, m_nRectSize.y/2);
if(Distance(center, wxRealPoint(pos.x, pos.y)) <= m_nRectSize.x/2) return true;
else
return false;
}
//----------------------------------------------------------------------------------//
// protected virtual functions
//----------------------------------------------------------------------------------//
void wxSFCircleShape::DrawNormal(wxDC& dc)
{
// HINT: overload it for custom actions...
wxRealPoint pos = GetAbsolutePosition();
dc.SetPen(m_Border);
dc.SetBrush(m_Fill);
dc.DrawCircle(int(pos.x + m_nRectSize.x/2), int(pos.y + m_nRectSize.y/2), int(m_nRectSize.x/2));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFCircleShape::DrawHover(wxDC& dc)
{
// HINT: overload it for custom actions...
wxRealPoint pos = GetAbsolutePosition();
dc.SetPen(wxPen(m_nHoverColor, 1));
dc.SetBrush(m_Fill);
dc.DrawCircle(int(pos.x + m_nRectSize.x/2), int(pos.y + m_nRectSize.y/2), int(m_nRectSize.x/2));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFCircleShape::DrawHighlighted(wxDC& dc)
{
// HINT: overload it for custom actions...
wxRealPoint pos = GetAbsolutePosition();
dc.SetPen(wxPen(m_nHoverColor, 2));
dc.SetBrush(m_Fill);
dc.DrawCircle(int(pos.x + m_nRectSize.x/2), int(pos.y + m_nRectSize.y/2), int(m_nRectSize.x/2));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFCircleShape::DrawShadow(wxDC& dc)
{
// HINT: overload it for custom actions...
if( m_Fill.GetStyle() != wxTRANSPARENT )
{
wxRealPoint pos = GetAbsolutePosition();
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(GetParentCanvas()->GetShadowFill());
dc.DrawCircle(int(pos.x + m_nRectSize.x/2 + GetParentCanvas()->GetShadowOffset().x), int(pos.y + m_nRectSize.y/2 + GetParentCanvas()->GetShadowOffset().y), int(m_nRectSize.x/2));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
}

View File

@@ -0,0 +1,117 @@
/***************************************************************
* Name: CommonFcn.cpp
* Purpose: Implements set of global (auxiliary) functions
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include <math.h>
#include <wx/tokenzr.h>
#include "wx/wxsf/CommonFcn.h"
namespace wxSFCommonFcn
{
//----------------------------------------------------------------------------------//
// conversion functions
//----------------------------------------------------------------------------------//
wxPoint Conv2Point(const wxRealPoint& pt)
{
return wxPoint((int)pt.x, (int)pt.y);
}
wxSize Conv2Size(const wxRealPoint& pt)
{
return wxSize((int)pt.x, (int)pt.y);
}
wxRealPoint Conv2RealPoint(const wxPoint& pt)
{
return wxRealPoint((double)pt.x, (double)pt.y);
}
//----------------------------------------------------------------------------------//
// graphical functions
//----------------------------------------------------------------------------------//
wxColour GetHybridColour(const wxColour &orig, const wxColour &modificator)
{
int r, g, b;
r = orig.Red() - (255 - modificator.Red())/20;
g = orig.Green() - (255 - modificator.Green())/20;
b = orig.Blue() - (255 - modificator.Blue())/20;
if(r < 0) r = 0;
if(g < 0) g = 0;
if(b < 0) b = 0;
return wxColour(r, g, b);
}
bool LinesIntersection(const wxRealPoint& from1, const wxRealPoint& to1, const wxRealPoint& from2, const wxRealPoint& to2, wxRealPoint& i)
{
double a1, b1, c1, a2, b2, c2, ka, kb;
// bug in GCC ???
volatile double xi, yi;
// create line 1 info
a1 = to1.y - from1.y;
b1 = from1.x - to1.x;
c1 = -a1*from1.x - b1*from1.y;
// create line 2 info
a2 = to2.y - from2.y;
b2 = from2.x - to2.x;
c2 = -a2*from2.x - b2*from2.y;
// check, whether the lines are parallel...
ka = a1 / a2;
kb = b1 / b2;
if(ka == kb) return false;
// find intersection point
#ifdef __WXMSW__
xi = floor(((b1*c2 - c1*b2) / (a1*b2 - a2*b1)) + 0.5);
yi = floor((-(a1*c2 - a2*c1) / (a1*b2 - a2*b1)) + 0.5);
#else
xi = (b1*c2 - c1*b2) / (a1*b2 - a2*b1);
yi = -(a1*c2 - a2*c1) / (a1*b2 - a2*b1);
#endif
if( ((from1.x - xi)*(xi - to1.x) >= 0) &&
((from2.x - xi)*(xi - to2.x) >= 0) &&
((from1.y - yi)*(yi - to1.y) >= 0) &&
((from2.y - yi)*(yi - to2.y) >= 0) )
{
i.x = xi;
i.y = yi;
return true;
}
else
return false;
}
double Distance(const wxRealPoint& pt1, const wxRealPoint& pt2)
{
return sqrt((pt2.x - pt1.x)*(pt2.x - pt1.x) + (pt2.y - pt1.y)*(pt2.y - pt1.y));
}
}
namespace wxSF
{
const double PI = 3.14159265;
}

View File

@@ -0,0 +1,404 @@
/***************************************************************
* Name: ControlShape.cpp
* Purpose: Implements GUI control shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2008-04-30
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/ControlShape.h"
#include "wx/wxsf/DiagramManager.h"
#include "wx/wxsf/ShapeCanvas.h"
XS_IMPLEMENT_CLONABLE_CLASS(wxSFControlShape, wxSFRectShape);
wxSFControlShape::wxSFControlShape() : wxSFRectShape()
{
m_pControl = NULL;
m_nProcessEvents = sfdvCONTROLSHAPE_PROCESSEVENTS;
m_ModFill = sfdvCONTROLSHAPE_MODFILL;
m_ModBorder = sfdvCONTROLSHAPE_MODBORDER;
m_nControlOffset = sfdvCONTROLSHAPE_CONTROLOFFSET;
m_pEventSink = new EventSink(this);
m_Fill = *wxTRANSPARENT_BRUSH;
m_Border = *wxTRANSPARENT_PEN;
MarkSerializableDataMembers();
}
wxSFControlShape::wxSFControlShape(wxWindow *ctrl, const wxRealPoint& pos, const wxRealPoint& size, wxSFDiagramManager* manager)
: wxSFRectShape(pos, size, manager)
{
SetControl(ctrl);
m_nProcessEvents = sfdvCONTROLSHAPE_PROCESSEVENTS;
m_ModFill = sfdvCONTROLSHAPE_MODFILL;
m_ModBorder = sfdvCONTROLSHAPE_MODBORDER;
m_nControlOffset = sfdvCONTROLSHAPE_CONTROLOFFSET;
m_pEventSink = new EventSink(this);
m_Fill = *wxTRANSPARENT_BRUSH;
m_Border = *wxTRANSPARENT_PEN;
MarkSerializableDataMembers();
}
wxSFControlShape::wxSFControlShape(const wxSFControlShape& obj)
: wxSFRectShape(obj)
{
m_pControl = NULL;
m_nProcessEvents = obj.m_nProcessEvents;
m_ModFill = obj.m_ModFill;
m_ModBorder = obj.m_ModBorder;
m_nControlOffset = obj.m_nControlOffset;
m_pEventSink = new EventSink(this);
MarkSerializableDataMembers();
}
wxSFControlShape::~wxSFControlShape()
{
if( m_pControl ) m_pControl->Destroy();
if( m_pEventSink ) delete m_pEventSink;
}
void wxSFControlShape::MarkSerializableDataMembers()
{
XS_SERIALIZE_EX(m_nProcessEvents, wxT("process_events"), sfdvCONTROLSHAPE_PROCESSEVENTS);
XS_SERIALIZE_EX(m_nControlOffset, wxT("offset"), sfdvCONTROLSHAPE_CONTROLOFFSET);
XS_SERIALIZE_EX(m_ModFill, wxT("modification_fill"), sfdvCONTROLSHAPE_MODFILL);
XS_SERIALIZE_EX(m_ModBorder, wxT("modification_border"), sfdvCONTROLSHAPE_MODBORDER);
}
//----------------------------------------------------------------------------------//
// public functions
//----------------------------------------------------------------------------------//
void wxSFControlShape::SetControl(wxWindow *ctrl, bool fit)
{
if( m_pControl ) m_pControl->Reparent( m_pPrevParent );
m_pControl = ctrl;
if( m_pControl )
{
m_pPrevParent = ctrl->GetParent();
if( m_pParentManager )
{
wxSFShapeCanvas *pCanvas = ((wxSFDiagramManager*)m_pParentManager)->GetShapeCanvas();
// reparent GUI control if necessary
if( pCanvas && ( (wxWindow*)pCanvas != m_pPrevParent ) ) m_pControl->Reparent( (wxWindow*)pCanvas );
// redirect mouse events to the event sink for their delayed processing
m_pControl->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(EventSink::_OnMouseButton), NULL, m_pEventSink);
m_pControl->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(EventSink::_OnMouseButton), NULL, m_pEventSink);
m_pControl->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(EventSink::_OnMouseButton), NULL, m_pEventSink);
m_pControl->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(EventSink::_OnMouseButton), NULL, m_pEventSink);
m_pControl->Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(EventSink::_OnMouseButton), NULL, m_pEventSink);
m_pControl->Connect(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(EventSink::_OnMouseButton), NULL, m_pEventSink);
m_pControl->Connect(wxEVT_MOTION, wxMouseEventHandler(EventSink::_OnMouseMove), NULL, m_pEventSink);
m_pControl->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(EventSink::_OnKeyDown), NULL, m_pEventSink);
m_pControl->Connect(wxEVT_SIZE, wxSizeEventHandler(EventSink::_OnSize), NULL, m_pEventSink);
}
if( fit ) UpdateShape();
UpdateControl();
}
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFControlShape::FitToChildren()
{
wxRect ctrlRct;
wxRect bbRct = GetBoundingBox();
if( m_pControl ) ctrlRct = wxRect(m_pControl->GetPosition(), m_pControl->GetSize());
else
ctrlRct = bbRct;
wxSFRectShape::FitToChildren();
if( bbRct.Intersects(ctrlRct) && !bbRct.Contains(ctrlRct) ) UpdateShape();
}
void wxSFControlShape::Scale(double x, double y, bool children)
{
wxSFRectShape::Scale(x, y, children);
UpdateControl();
}
void wxSFControlShape::MoveTo(double x, double y)
{
wxSFRectShape::MoveTo(x, y);
UpdateControl();
}
void wxSFControlShape::MoveBy(double x, double y)
{
wxSFRectShape::MoveBy(x, y);
UpdateControl();
}
void wxSFControlShape::OnBeginDrag(const wxPoint& pos)
{
wxUnusedVar( pos );
m_PrevFill = m_Fill;
m_Fill = m_ModFill;
if( m_pParentManager )
{
wxSFShapeCanvas *pCanvas = ((wxSFDiagramManager*)m_pParentManager)->GetShapeCanvas();
if( pCanvas )
{
m_nPrevStyle = pCanvas->GetStyle();
pCanvas->RemoveStyle(wxSFShapeCanvas::sfsDND);
}
}
if( m_pControl )
{
m_pControl->Hide();
m_pControl->Disconnect(wxEVT_SIZE, wxSizeEventHandler(EventSink::_OnSize), NULL, m_pEventSink);
}
wxSFShapeBase::OnBeginDrag(pos);
}
void wxSFControlShape::OnEndDrag(const wxPoint& pos)
{
m_Fill = m_PrevFill;
if( m_pParentManager )
{
wxSFShapeCanvas *pCanvas = ((wxSFDiagramManager*)m_pParentManager)->GetShapeCanvas();
if( pCanvas ) pCanvas->SetStyle(m_nPrevStyle);
}
UpdateControl();
if( m_pControl )
{
m_pControl->Connect(wxEVT_SIZE, wxSizeEventHandler(EventSink::_OnSize), NULL, m_pEventSink);
m_pControl->Show();
m_pControl->SetFocus();
}
wxSFShapeBase::OnEndDrag(pos);
}
void wxSFControlShape::OnBeginHandle(wxSFShapeHandle& handle)
{
m_PrevBorder = m_Border;
m_Border = m_ModBorder;
m_PrevFill = m_Fill;
m_Fill = m_ModFill;
if( m_pControl )
{
m_pControl->Hide();
m_pControl->Disconnect(wxEVT_SIZE, wxSizeEventHandler(EventSink::_OnSize), NULL, m_pEventSink);
}
// call default handler
wxSFRectShape::OnBeginHandle(handle);
}
void wxSFControlShape::OnHandle(wxSFShapeHandle& handle)
{
// call default handler
wxSFRectShape::OnHandle(handle);
UpdateControl();
}
void wxSFControlShape::OnEndHandle(wxSFShapeHandle& handle)
{
m_Border = m_PrevBorder;
m_Fill = m_PrevFill;
if( m_pControl )
{
m_pControl->Show();
m_pControl->SetFocus();
m_pControl->Connect(wxEVT_SIZE, wxSizeEventHandler(EventSink::_OnSize), NULL, m_pEventSink);
}
// call default handler
wxSFRectShape::OnEndHandle(handle);
}
void wxSFControlShape::Update()
{
wxSFShapeBase::Update();
UpdateControl();
}
//----------------------------------------------------------------------------------//
// protected functions
//----------------------------------------------------------------------------------//
void wxSFControlShape::UpdateControl()
{
if( m_pControl )
{
int x = 0, y = 0;
wxRect minBB = m_pControl->GetMinSize();
wxRect rctBB = GetBoundingBox().Deflate(m_nControlOffset, m_nControlOffset);
if( rctBB.GetWidth() < minBB.GetWidth() )
{
rctBB.SetWidth(minBB.GetWidth());
m_nRectSize.x = minBB.GetWidth() + 2*m_nControlOffset;
}
if( rctBB.GetHeight() < minBB.GetHeight() )
{
rctBB.SetHeight(minBB.GetHeight());
m_nRectSize.y = minBB.GetHeight() + 2*m_nControlOffset;
}
GetParentCanvas()->CalcUnscrolledPosition(0, 0, &x, &y);
// set the control's dimensions and position according to the parent control shape
m_pControl->SetSize(rctBB.GetWidth(), rctBB.GetHeight());
m_pControl->Move(rctBB.GetLeft() - x, rctBB.GetTop() - y);
}
}
void wxSFControlShape::UpdateShape()
{
if( m_pControl )
{
wxSize nCtrlSize = m_pControl->GetSize();
m_nRectSize.x = nCtrlSize.x + 2*m_nControlOffset;
m_nRectSize.y = nCtrlSize.y + 2*m_nControlOffset;
GetShapeManager()->GetShapeCanvas()->Refresh(false);
}
}
//----------------------------------------------------------------------------------//
// private functions
//----------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------//
// EventSink class
//----------------------------------------------------------------------------------//
EventSink::EventSink()
{
m_pParentShape = NULL;
}
EventSink::EventSink(wxSFControlShape *parent)
{
wxASSERT(parent);
m_pParentShape = parent;
}
EventSink::~EventSink()
{
}
//----------------------------------------------------------------------------------//
// public functions
//----------------------------------------------------------------------------------//
void EventSink::_OnMouseButton(wxMouseEvent &event)
{
if( m_pParentShape->GetEventProcessing() & wxSFControlShape::evtMOUSE2CANVAS )
{
wxMouseEvent updatedEvent(event);
UpdateMouseEvent(updatedEvent);
SendEvent(updatedEvent);
}
// process the event also by an original handler if requested
if( m_pParentShape->GetEventProcessing() & wxSFControlShape::evtMOUSE2GUI ) event.Skip();
//m_pParentShape->GetControl()->SetFocus();
}
void EventSink::_OnMouseMove(wxMouseEvent &event)
{
if( m_pParentShape->GetEventProcessing() & wxSFControlShape::evtMOUSE2CANVAS )
{
wxMouseEvent updatedEvent(event);
UpdateMouseEvent(updatedEvent);
SendEvent(updatedEvent);
}
// process the event also by an original handler if requested
if( m_pParentShape->GetEventProcessing() & wxSFControlShape::evtMOUSE2GUI ) event.Skip();
}
void EventSink::_OnKeyDown(wxKeyEvent &event)
{
if( m_pParentShape->GetEventProcessing() & wxSFControlShape::evtKEY2CANVAS ) SendEvent(event);
// process the event also by an original handler if requested
if( m_pParentShape->GetEventProcessing() & wxSFControlShape::evtKEY2GUI ) event.Skip();
}
void EventSink::_OnSize(wxSizeEvent &event)
{
event.Skip();
m_pParentShape->UpdateShape();
}
//----------------------------------------------------------------------------------//
// protected functions
//----------------------------------------------------------------------------------//
void EventSink::SendEvent(wxEvent &event)
{
if( m_pParentShape && m_pParentShape->GetParentManager() )
{
wxSFShapeCanvas *pCanvas = ((wxSFDiagramManager*)m_pParentShape->GetParentManager())->GetShapeCanvas();
// send copy of the event to the shape canvas
if( pCanvas ) wxPostEvent( pCanvas, event );
}
}
void EventSink::UpdateMouseEvent(wxMouseEvent &event)
{
int x = 0, y = 0;
wxRealPoint nAbsPos = m_pParentShape->GetAbsolutePosition();
m_pParentShape->GetParentCanvas()->CalcUnscrolledPosition(0, 0, &x, &y);
event.m_x += ( (int)nAbsPos.x + m_pParentShape->GetControlOffset() - x );
event.m_y += ( (int)nAbsPos.y + m_pParentShape->GetControlOffset() - y );
}

View File

@@ -0,0 +1,283 @@
/***************************************************************
* Name: CurveShape.cpp
* Purpose: Implements curve shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include <math.h>
#include "wx/wxsf/CurveShape.h"
#include "wx/wxsf/ShapeCanvas.h"
#include "wx/wxsf/CommonFcn.h"
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFCurveShape, wxSFLineShape);
wxSFCurveShape::wxSFCurveShape() : wxSFLineShape()
{
}
wxSFCurveShape::wxSFCurveShape(long src, long trg, const wxXS::RealPointList& path, wxSFDiagramManager* manager)
: wxSFLineShape(src, trg, path, manager)
{
}
wxSFCurveShape::wxSFCurveShape(const wxSFCurveShape& obj)
: wxSFLineShape(obj)
{
}
wxSFCurveShape::~wxSFCurveShape()
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
wxRect wxSFCurveShape::GetBoundingBox()
{
return wxSFLineShape::GetBoundingBox().Inflate(20, 20);
}
//----------------------------------------------------------------------------------//
// public functions
//----------------------------------------------------------------------------------//
wxRealPoint wxSFCurveShape::GetPoint(size_t segment, double offset)
{
if( segment <= m_lstPoints.GetCount() )
{
wxRealPoint A, B, C, D;
GetSegmentQuaternion( segment, A, B, C, D );
return Coord_Catmul_Rom_Kubika(A, B, C, D, offset);
}
else
return wxRealPoint();
}
//----------------------------------------------------------------------------------//
// protected virtual functions
//----------------------------------------------------------------------------------//
void wxSFCurveShape::DrawCompleteLine(wxDC& dc)
{
size_t i = 0;
wxRealPoint A, B, C, D;
switch(m_nMode)
{
case modeREADY:
{
// draw line segments
if( !m_lstPoints.IsEmpty() )
{
for( i = 0; i <= m_lstPoints.GetCount(); i++ )
{
GetSegmentQuaternion( i, A, B, C, D );
Catmul_Rom_Kubika(A, B, C, D, dc);
}
}
else
{
GetDirectLine( B, C );
dc.DrawLine( Conv2Point(B), Conv2Point(C) );
}
// draw target arrow
if( m_pTrgArrow ) m_pTrgArrow->Draw( B, C, dc);
GetLineSegment( 0, B, C );
// draw source arrow
if( m_pSrcArrow ) m_pSrcArrow->Draw(C, B, dc);
}
break;
case modeUNDERCONSTRUCTION:
{
// draw basic line parts
if( !m_lstPoints.IsEmpty() )
{
for( i = 0; i < m_lstPoints.GetCount(); i++ )
{
GetSegmentQuaternion( i, A, B, C, D );
Catmul_Rom_Kubika(A, B, C, D, dc);
}
}
// draw unfinished line segment if any (for interactive line creation)
dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
if( i )
{
dc.DrawLine(Conv2Point( C ), m_nUnfinishedPoint);
}
else if( m_nSrcShapeId != -1 )
{
// draw unfinished line segment if any (for interactive line creation)
dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
wxSFShapeBase* pSrcShape = GetShapeManager()->FindShape(m_nSrcShapeId);
if( pSrcShape )
{
if( pSrcShape->GetConnectionPoints().IsEmpty() )
{
dc.DrawLine( Conv2Point(pSrcShape->GetBorderPoint(pSrcShape->GetCenter(), Conv2RealPoint(m_nUnfinishedPoint))), m_nUnfinishedPoint );
}
else
dc.DrawLine( Conv2Point( GetModSrcPoint() ), m_nUnfinishedPoint );
}
dc.SetPen(wxNullPen);
}
dc.SetPen(wxNullPen);
}
break;
case modeSRCCHANGE:
{
// draw basic line parts
for( i = 1; i <= m_lstPoints.GetCount(); i++ )
{
GetSegmentQuaternion( i, A, B, C, D );
Catmul_Rom_Kubika(A, B, C, D, dc);
}
// draw linesegment being updated
dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
if( !m_lstPoints.IsEmpty() )
{
GetSegmentQuaternion( 0, A, B, C, D );
}
else
GetDirectLine( B, C );
dc.DrawLine(m_nUnfinishedPoint, Conv2Point(C));
dc.SetPen(wxNullPen);
}
break;
case modeTRGCHANGE:
{
// draw basic line parts
if( !m_lstPoints.IsEmpty() )
{
for( i = 0; i < m_lstPoints.GetCount(); i++ )
{
GetSegmentQuaternion( i, A, B, C, D );
Catmul_Rom_Kubika(A, B, C, D, dc);
}
}
else
C = GetSrcPoint();
// draw linesegment being updated
dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
dc.DrawLine(m_nUnfinishedPoint, Conv2Point(C));
dc.SetPen(wxNullPen);
}
break;
}
}
//----------------------------------------------------------------------------------//
// private functions
//----------------------------------------------------------------------------------//
void wxSFCurveShape::GetSegmentQuaternion(size_t segment, wxRealPoint& A, wxRealPoint& B, wxRealPoint& C, wxRealPoint& D)
{
static wxRealPoint quart[4];
wxXS::RealPointList::compatibility_iterator node;
int nIndex = 2 - segment;
if( ( nIndex - 1 ) >= 0 ) quart[ nIndex - 1 ] = GetSrcPoint();
if( ( nIndex - 2 ) >= 0 ) quart[ nIndex - 2 ] = GetModSrcPoint();
if( nIndex >= 0 ) node = m_lstPoints.Item( 0 );
else
{
node = m_lstPoints.Item( abs( nIndex ) );
nIndex = 0;
}
for( ; nIndex < 4; nIndex++ )
{
if( node )
{
quart[ nIndex ] = *node->GetData();
node = node->GetNext();
}
else
{
if( nIndex == 2 ) quart[ 2 ] = GetTrgPoint();
else if( nIndex == 3 )
{
if( m_nMode == modeUNDERCONSTRUCTION ) quart[ 3 ] = Conv2RealPoint( m_nUnfinishedPoint );
else if( m_nTrgShapeId != -1 ) quart[ 3 ] = GetModTrgPoint();
}
}
}
A = quart[0];
B = quart[1];
C = quart[2];
D = quart[3];
}
void wxSFCurveShape::Catmul_Rom_Kubika(const wxRealPoint& A, const wxRealPoint& B, const wxRealPoint& C, const wxRealPoint& D, wxDC& dc)
{
// the begginig of the curve is in the B point
wxRealPoint point0=B;
wxRealPoint point1;
int nOptimSteps = double(Distance(B, C)) / 10;
if( nOptimSteps < 10 ) nOptimSteps = 10;
// draw the curve
for(double t = 0; t <= (1 + (1.0f / nOptimSteps)); t += 1.0f / (nOptimSteps-1))
{
point1 = Coord_Catmul_Rom_Kubika(A,B,C,D,t);
dc.DrawLine((int)point0.x, (int)point0.y, (int)point1.x, (int)point1.y);
point0 = point1;
}
point1 = Coord_Catmul_Rom_Kubika(A,B,C,D,1);
dc.DrawLine((int)point0.x, (int)point0.y, (int)point1.x, (int)point1.y);
}
wxRealPoint wxSFCurveShape::Coord_Catmul_Rom_Kubika(const wxRealPoint& p1, const wxRealPoint& p2, const wxRealPoint& p3, const wxRealPoint& p4, double t)
{
double pom1, pom2;
double C1,C2,C3,C4;
wxRealPoint point;
// auxiliary variables
pom1 = t - 1;
pom2 = t * t;
// used polynoms
C1 = (-pom2*t + 2*pom2 - t) / 2;
C2 = (3*pom2*t - 5*pom2 + 2) / 2;
C3 = (-3*pom2*t + 4*pom2 +t) / 2;
C4 = pom1*pom2 / 2;
// calculation of curve point for t = <0,1>
point.x = C1*p1.x + C2*p2.x + C3*p3.x + C4*p4.x;
point.y = C1*p1.y + C2*p2.y + C3*p3.y + C4*p4.y;
//point.z = C1*p1.z + C2*p2.z + C3*p3.z + C4*p4.z;
return point;
}

View File

@@ -0,0 +1,827 @@
/***************************************************************
* Name: DiagramManager.cpp
* Purpose: Implements shape manager class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-25
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include <wx/wfstream.h>
#include <wx/mstream.h>
#include <wx/listimpl.cpp>
#include "wx/wxsf/DiagramManager.h"
#include "wx/wxsf/ShapeCanvas.h"
#include "wx/wxsf/ControlShape.h"
#include "wx/wxsf/LineShape.h"
#include "wx/wxsf/GridShape.h"
using namespace wxSFCommonFcn;
// TODO: implement autolayout
// TODO: implement better line X ellipse check
WX_DEFINE_LIST(IDList);
XS_IMPLEMENT_CLONABLE_CLASS(wxSFDiagramManager, wxXmlSerializer);
wxSFDiagramManager::wxSFDiagramManager()
{
m_pShapeCanvas = NULL;
m_lstIDPairs.DeleteContents(true);
m_sSFVersion = wxT("1.12.4 beta");
SetSerializerOwner(wxT("wxShapeFramework"));
SetSerializerVersion(wxT("1.0"));
SetSerializerRootName(wxT("chart"));
}
wxSFDiagramManager::wxSFDiagramManager(const wxSFDiagramManager &obj)
: wxXmlSerializer(obj)
{
m_pShapeCanvas = NULL;
m_sSFVersion = obj.m_sSFVersion;
m_lstIDPairs.DeleteContents(true);
}
wxSFDiagramManager::~wxSFDiagramManager()
{
Clear();
}
//----------------------------------------------------------------------------------//
// Adding/removing shapes functions
//----------------------------------------------------------------------------------//
wxSFShapeBase* wxSFDiagramManager::AddShape(wxClassInfo* shapeInfo, bool saveState, wxSF::ERRCODE *err)
{
wxPoint shapePos;
if(m_pShapeCanvas)
{
wxRect crect = m_pShapeCanvas->GetClientRect();
shapePos = wxPoint((crect.GetRight() - crect.GetLeft())/2,
(crect.GetBottom() - crect.GetTop())/2);
}
wxSFShapeBase* pShape = AddShape(shapeInfo, shapePos, saveState, err);
return pShape;
}
wxSFShapeBase* wxSFDiagramManager::AddShape(wxClassInfo* shapeInfo, const wxPoint& pos, bool saveState, wxSF::ERRCODE *err)
{
wxASSERT( shapeInfo );
if( shapeInfo && IsShapeAccepted(shapeInfo->GetClassName()) )
{
// create shape object from class info
wxSFShapeBase *pShape = (wxSFShapeBase*)shapeInfo->CreateObject();
wxSFShapeBase *pParentShape = NULL;
// update given possition
wxPoint lpos = pos;
if( m_pShapeCanvas )
{
lpos = m_pShapeCanvas->FitPositionToGrid( m_pShapeCanvas->DP2LP(pos) );
}
// line shapes can be assigned to root only
if( !pShape->IsKindOf(CLASSINFO(wxSFLineShape)) ) pParentShape = GetShapeAtPosition(lpos);
if( pParentShape && pParentShape->IsChildAccepted(shapeInfo->GetClassName()) )
{
pShape = AddShape(pShape, (xsSerializable*)pParentShape, pos - Conv2Point( pParentShape->GetAbsolutePosition() ), sfINITIALIZE, saveState, err);
}
else
pShape = AddShape(pShape, GetRootItem(), pos, sfINITIALIZE, saveState, err);
if( pParentShape )pParentShape->Update();
return pShape;
}
else
{
if( err ) *err = wxSF::errNOT_ACCEPTED;
return NULL;
}
}
wxSFShapeBase* wxSFDiagramManager::AddShape(wxSFShapeBase* shape, xsSerializable* parent, const wxPoint& pos, bool initialize, bool saveState, wxSF::ERRCODE *err)
{
if(shape)
{
if( shape->IsKindOf(CLASSINFO(wxSFShapeBase)) && IsShapeAccepted(shape->GetClassInfo()->GetClassName()) )
{
if( m_pShapeCanvas )
{
wxPoint newPos = m_pShapeCanvas->FitPositionToGrid(m_pShapeCanvas->DP2LP(pos));
shape->SetRelativePosition( Conv2RealPoint(newPos) );
}
else
shape->SetRelativePosition( Conv2RealPoint(pos) );
// add parent shape to the data manager (serializer)
if(parent)
{
AddItem(parent, shape);
}
else
AddItem(GetRootItem(), shape);
// initialize added shape
if(initialize)
{
shape->CreateHandles();
if( m_pShapeCanvas )
{
shape->SetHoverColour(m_pShapeCanvas->GetHoverColour());
}
if(HasChildren(shape))
{
wxSFShapeBase* pChild;
ShapeList lstChildren;
// get shape's children (if exist)
shape->GetChildShapes(sfANY, lstChildren, sfRECURSIVE);
// initialize shape's children
ShapeList::compatibility_iterator node = lstChildren.GetFirst();
while(node)
{
pChild = (wxSFShapeBase*)node->GetData();
pChild->CreateHandles();
pChild->Update();
if( m_pShapeCanvas )
{
pChild->SetHoverColour(m_pShapeCanvas->GetHoverColour());
}
node = node->GetNext();
}
}
}
// reset scale of assigned shape canvas (if exists and it is necessary...)
if( m_pShapeCanvas && shape->IsKindOf( CLASSINFO(wxSFControlShape) ) )
{
m_pShapeCanvas->SetScale( 1 );
}
if( m_pShapeCanvas )
{
if( saveState )
{
m_pShapeCanvas->SaveCanvasState();
}
}
if( err ) *err = wxSF::errOK;
}
else
{
//wxMessageBox(wxString::Format(wxT("Unable to add '%s' class object to the canvas"), shape->GetClassInfo()->GetClassName()), wxT("ShapeFramework"), wxICON_WARNING);
delete shape;
shape = NULL;
if( err ) *err = wxSF::errNOT_ACCEPTED;
}
}
else if( err ) *err = wxSF::errINVALID_INPUT;
return shape;
}
wxSFShapeBase* wxSFDiagramManager::CreateConnection(long srcId, long trgId, bool saveState, wxSF::ERRCODE *err)
{
return CreateConnection(srcId, trgId, CLASSINFO(wxSFLineShape), saveState, err);
}
wxSFShapeBase* wxSFDiagramManager::CreateConnection(long srcId, long trgId, wxClassInfo *lineInfo, bool saveState, wxSF::ERRCODE *err)
{
wxSFShapeBase* pShape = AddShape(lineInfo, sfDONT_SAVE_STATE, err);
if(pShape)
{
wxSFLineShape *pLine = (wxSFLineShape*)pShape;
pLine->SetSrcShapeId(srcId);
pLine->SetTrgShapeId(trgId);
if( m_pShapeCanvas )
{
if(saveState)m_pShapeCanvas->SaveCanvasState();
pLine->Refresh();
}
}
return pShape;
}
wxSFShapeBase* wxSFDiagramManager::CreateConnection(long srcId, long trgId, wxSFLineShape *line, bool saveState, wxSF::ERRCODE *err)
{
wxSFShapeBase* pShape = AddShape(line, NULL, wxDefaultPosition, sfINITIALIZE, sfDONT_SAVE_STATE, err);
if(pShape)
{
wxSFLineShape *pLine = (wxSFLineShape*)pShape;
pLine->SetSrcShapeId(srcId);
pLine->SetTrgShapeId(trgId);
if( m_pShapeCanvas )
{
if(saveState)m_pShapeCanvas->SaveCanvasState();
pLine->Refresh();
}
}
return pShape;
}
void wxSFDiagramManager::RemoveShape(wxSFShapeBase* shape, bool refresh)
{
if(shape)
{
wxSFShapeBase *pParent = shape->GetParentShape();
// remove connected lines (to all children)
ShapeList lstChildren;
ShapeList lstConnections;
ShapeList lstRemovedConnections;
// get all shape's children
shape->GetChildShapes(sfANY, lstChildren, sfRECURSIVE);
lstChildren.Append(shape);
// retrieve all assigned lines
ShapeList::compatibility_iterator snode = lstChildren.GetFirst();
while(snode)
{
GetAssignedConnections(snode->GetData(), CLASSINFO(wxSFLineShape), wxSFShapeBase::lineBOTH, lstConnections);
snode = snode->GetNext();
}
// remove all assigne lines
ShapeList::compatibility_iterator node = lstConnections.GetFirst();
while(node)
{
// one connection may be used by the parent and also by his child
if(lstRemovedConnections.IndexOf(node->GetData()) == wxNOT_FOUND)
{
lstRemovedConnections.Append(node->GetData());
RemoveShape(node->GetData(), false);
}
node = node->GetNext();
}
// remove the shape also from m_lstCurrentShapes list
if( m_pShapeCanvas ) m_pShapeCanvas->RemoveFromTemporaries( shape );
// remove the shape
RemoveItem(shape);
if( pParent ) pParent->Update();
if( refresh && m_pShapeCanvas ) m_pShapeCanvas->Refresh(false);
}
}
void wxSFDiagramManager::RemoveShapes(const ShapeList& selection)
{
wxSFShapeBase* pShape;
ShapeList::compatibility_iterator node = selection.GetFirst();
while(node)
{
pShape = node->GetData();
// it is important to check whether double-linked shapes already exist before
// they are deleted
if(Contains(pShape))RemoveShape(pShape, false);
node = node->GetNext();
}
}
void wxSFDiagramManager::Clear()
{
RemoveAll();
if( m_pShapeCanvas )
{
m_pShapeCanvas->GetMultiselectionBox().Show(false);
m_pShapeCanvas->UpdateVirtualSize();
}
}
//----------------------------------------------------------------------------------//
// Serialization/deserialization functions
//----------------------------------------------------------------------------------//
bool wxSFDiagramManager::SerializeToXml(const wxString& file, bool withroot)
{
return wxXmlSerializer::SerializeToXml(file, withroot);
}
bool wxSFDiagramManager::SerializeToXml(wxOutputStream& outstream, bool withroot)
{
return wxXmlSerializer::SerializeToXml(outstream, withroot);
}
bool wxSFDiagramManager::DeserializeFromXml(const wxString& file)
{
bool fSuccess = false;
wxFileInputStream instream(file);
if(instream.IsOk())
{
if( m_pShapeCanvas) m_pShapeCanvas->ClearCanvasHistory();
fSuccess = DeserializeFromXml(instream);
if( m_pShapeCanvas) m_pShapeCanvas->SaveCanvasState();
}
else
wxMessageBox(wxT("Unable to initialize input stream."), wxT("ShapeFramework"), wxOK | wxICON_ERROR);
return fSuccess;
}
bool wxSFDiagramManager::DeserializeFromXml(wxInputStream& instream)
{
// load an XML file
try
{
wxXmlDocument xmlDoc;
xmlDoc.Load(instream);
wxXmlNode* root = xmlDoc.GetRoot();
if(root && (root->GetName() == wxT("chart")))
{
// read shape objects from XML recursively
DeserializeObjects(NULL, root);
return true;
}
else
wxMessageBox(wxT("Unknown file format."), wxT("ShapeFramework"), wxOK | wxICON_WARNING);
}
catch (...)
{
wxMessageBox(wxT("Unable to load XML file."), wxT("ShapeFramework"), wxOK | wxICON_ERROR);
}
return false;
}
void wxSFDiagramManager::DeserializeObjects(xsSerializable* parent, wxXmlNode* node)
{
_DeserializeObjects(parent, node);
// update IDs in connection lines and grids
UpdateConnections();
UpdateGrids();
m_lstIDPairs.Clear();
if( m_pShapeCanvas )
{
//m_pShapeCanvas->MoveShapesFromNegatives();
m_pShapeCanvas->UpdateVirtualSize();
}
}
void wxSFDiagramManager::_DeserializeObjects(xsSerializable* parent, wxXmlNode* node)
{
wxSFShapeBase *pShape;
wxXS::IntArray arrNewIDs;
SerializableList lstForUpdate;
wxXmlNode* shapeNode = node->GetChildren();
while(shapeNode)
{
if(shapeNode->GetName() == wxT("object"))
{
#if wxVERSION_NUMBER < 2900
pShape = AddShape((wxSFShapeBase*)wxCreateDynamicObject(shapeNode->GetPropVal(wxT("type"), wxT(""))), parent, wxPoint(0, 0), true, sfDONT_SAVE_STATE);
#else
pShape = AddShape((wxSFShapeBase*)wxCreateDynamicObject(shapeNode->GetAttribute(wxT("type"), wxT(""))), parent, wxPoint(0, 0), true, sfDONT_SAVE_STATE);
#endif
if(pShape)
{
// store new assigned ID
lstForUpdate.Append( pShape );
pShape->GetChildrenRecursively( NULL, lstForUpdate );
for( SerializableList::iterator it = lstForUpdate.begin(); it != lstForUpdate.end(); ++it )
{
arrNewIDs.Add( (*it)->GetId() );
}
// deserialize stored content
pShape->DeserializeObject(shapeNode);
// update handle in line shapes
if( pShape->IsKindOf( CLASSINFO(wxSFLineShape) ) )
{
pShape->CreateHandles();
m_lstLinesForUpdate.Append(pShape);
}
else if( pShape->IsKindOf( CLASSINFO(wxSFGridShape) ) )
{
m_lstGridsForUpdate.Append(pShape);
}
// store information about IDs' changes and re-assign shapes' IDs
int newId, i = 0;
for( SerializableList::iterator it = lstForUpdate.begin(); it != lstForUpdate.end(); ++it )
{
newId = arrNewIDs[i++];
if( newId != (*it)->GetId() )
{
m_lstIDPairs.Append( new IDPair((*it)->GetId(), newId) );
(*it)->SetId( newId );
}
}
// deserialize child objects
_DeserializeObjects(pShape, shapeNode);
arrNewIDs.Clear();
lstForUpdate.Clear();
}
else
{
// there are some unsupported shapes so the diagrams must be cleared because of possible damage
RemoveAll();
m_lstLinesForUpdate.Clear();
m_lstGridsForUpdate.Clear();
wxMessageBox( wxT("Deserialization couldn't be completed because not of all shapes are accepted."), wxT("wxShapeFramework"), wxOK | wxICON_WARNING );
return;
}
}
else if(shapeNode->GetName() == m_sRootName + wxT("_properties"))
{
m_pRoot->DeserializeObject(shapeNode->GetChildren());
}
shapeNode = shapeNode->GetNext();
}
}
//----------------------------------------------------------------------------------//
// Shape handling functions
//----------------------------------------------------------------------------------//
void wxSFDiagramManager::AcceptShape(const wxString& type)
{
if(m_arrAcceptedShapes.Index(type) == wxNOT_FOUND)
{
m_arrAcceptedShapes.Add(type);
}
}
bool wxSFDiagramManager::IsShapeAccepted(const wxString& type)
{
if( m_arrAcceptedShapes.Index(type) != wxNOT_FOUND )return true;
else if( m_arrAcceptedShapes.Index(wxT("All")) != wxNOT_FOUND )return true;
else
return false;
}
void wxSFDiagramManager::GetAssignedConnections(wxSFShapeBase* parent, wxClassInfo* shapeInfo, wxSFShapeBase::CONNECTMODE mode, ShapeList& lines)
{
wxSFLineShape* pLine;
if( parent->GetId() == -1 ) return;
SerializableList lstLines;
// lines are children of root item only so we have not to search recursively...
GetRootItem()->GetChildren( shapeInfo, lstLines );
if( !lstLines.IsEmpty() )
{
SerializableList::compatibility_iterator node = lstLines.GetFirst();
while(node)
{
pLine = (wxSFLineShape*)node->GetData();
switch(mode)
{
case wxSFShapeBase::lineSTARTING:
if( pLine->GetSrcShapeId() == parent->GetId() ) lines.Append(pLine);
break;
case wxSFShapeBase::lineENDING:
if( pLine->GetTrgShapeId() == parent->GetId() ) lines.Append(pLine);
break;
case wxSFShapeBase::lineBOTH:
if( ( pLine->GetSrcShapeId() == parent->GetId() ) ||
( pLine->GetTrgShapeId() == parent->GetId() ) ) lines.Append(pLine);
break;
}
node = node->GetNext();
}
}
}
void wxSFDiagramManager::GetShapes(wxClassInfo* shapeInfo, ShapeList& shapes, xsSerializable::SEARCHMODE mode)
{
GetItems(shapeInfo, (SerializableList&)shapes, mode);
}
wxSFShapeBase* wxSFDiagramManager::GetShapeAtPosition(const wxPoint& pos, int zorder, SEARCHMODE mode)
{
int nCounter = 0;
ShapeList m_lstSortedShapes;
wxSFShapeBase* pShape;
// sort shapes list in the way that the line shapes will be at the top of the list
ShapeList shapes;
GetShapes(CLASSINFO(wxSFShapeBase), shapes, xsSerializable::searchBFS);
ShapeList::compatibility_iterator node = shapes.GetFirst();
while(node)
{
pShape = node->GetData();
if(pShape->IsKindOf(CLASSINFO(wxSFLineShape)))
{
m_lstSortedShapes.Insert(pShape);
nCounter++;
}
else
m_lstSortedShapes.Insert(nCounter, pShape);
node = node->GetNext();
}
// find the topmost shape according to the given rules
nCounter = 1;
node = m_lstSortedShapes.GetFirst();
while(node)
{
pShape = (wxSFShapeBase*)node->GetData();
if(pShape->IsVisible() && pShape->IsActive() && pShape->Contains(pos))
{
switch(mode)
{
case searchSELECTED:
if(pShape->IsSelected())
{
if(nCounter == zorder)return pShape;
else
nCounter++;
}
break;
case searchUNSELECTED:
if(!pShape->IsSelected())
{
if(nCounter == zorder)return pShape;
else
nCounter++;
}
break;
case searchBOTH:
if(nCounter == zorder)return pShape;
else
nCounter++;
break;
}
}
node = node->GetNext();
}
return NULL;
}
void wxSFDiagramManager::GetShapesAtPosition(const wxPoint& pos, ShapeList& shapes)
{
shapes.Clear();
wxSFShapeBase *pShape;
ShapeList lstShapes;
GetShapes(CLASSINFO(wxSFShapeBase), lstShapes);
ShapeList::compatibility_iterator node = lstShapes.GetFirst();
while(node)
{
pShape = node->GetData();
if(pShape->IsVisible() && pShape->IsActive() && pShape->Contains(pos))shapes.Append(pShape);
node = node->GetNext();
}
}
void wxSFDiagramManager::GetShapesInside(const wxRect& rct, ShapeList& shapes)
{
shapes.Clear();
wxSFShapeBase* pShape;
ShapeList lstShapes;
GetShapes(CLASSINFO(wxSFShapeBase), lstShapes);
ShapeList::compatibility_iterator node = lstShapes.GetFirst();
while(node)
{
pShape = node->GetData();
if(pShape->IsVisible() && pShape->IsActive() && pShape->Intersects(rct))shapes.Append(pShape);
node = node->GetNext();
}
}
wxSFShapeBase* wxSFDiagramManager::FindShape(long id)
{
if(id == -1)return NULL;
else
return (wxSFShapeBase*)GetItem(id);
}
void wxSFDiagramManager::GetNeighbours(wxSFShapeBase* parent, ShapeList& neighbours, wxClassInfo *shapeInfo, wxSFShapeBase::CONNECTMODE condir, bool direct)
{
if(parent)
{
parent->GetNeighbours(neighbours, shapeInfo, condir, direct);
}
else
{
wxASSERT(GetRootItem());
wxSFShapeBase* pShape;
SerializableList::compatibility_iterator node = GetRootItem()->GetFirstChildNode();
while(node)
{
pShape = (wxSFShapeBase*)node->GetData();
pShape->GetNeighbours(neighbours, shapeInfo, condir, direct);
node = node->GetNext();
}
}
}
bool wxSFDiagramManager::HasChildren(wxSFShapeBase* parent)
{
if(parent->GetFirstChildNode())return true;
else
return false;
}
void wxSFDiagramManager::UpdateConnections()
{
if( !m_lstLinesForUpdate.IsEmpty() )
{
wxSFLineShape* pLine;
IDPair* pIDPair;
// now check ids
long oldSrcId, oldTrgId;
long newSrcId, newTrgId;
IDList::compatibility_iterator idnode;
ShapeList::compatibility_iterator node = m_lstLinesForUpdate.GetFirst();
while(node)
{
pLine = (wxSFLineShape*)node->GetData();
newSrcId = oldSrcId = pLine->GetSrcShapeId();
newTrgId = oldTrgId = pLine->GetTrgShapeId();
idnode = m_lstIDPairs.GetFirst();
while(idnode)
{
pIDPair = idnode->GetData();
/*if(pIDPair->m_nNewID != pIDPair->m_nOldID)
{*/
if(oldSrcId == pIDPair->m_nOldID) newSrcId = pIDPair->m_nNewID;
if(oldTrgId == pIDPair->m_nOldID) newTrgId = pIDPair->m_nNewID;
/*}*/
idnode = idnode->GetNext();
}
pLine->SetSrcShapeId(newSrcId);
pLine->SetTrgShapeId(newTrgId);
// check whether line's src and trg shapes really exists
if(!GetItem(pLine->GetSrcShapeId()) || !GetItem(pLine->GetTrgShapeId()))
{
RemoveItem(pLine);
}
node = node->GetNext();
}
m_lstLinesForUpdate.Clear();
}
}
void wxSFDiagramManager::UpdateGrids()
{
if( !m_lstGridsForUpdate.IsEmpty() )
{
// now check ids
wxSFGridShape* pGrid;
IDPair* pIDPair;
int nIndex;
IDList::compatibility_iterator idnode;
ShapeList::compatibility_iterator node = m_lstGridsForUpdate.GetFirst();
while(node)
{
pGrid = (wxSFGridShape*)node->GetData();
nIndex = wxNOT_FOUND;
idnode = m_lstIDPairs.GetFirst();
while(idnode)
{
pIDPair = idnode->GetData();
nIndex = pGrid->m_arrCells.Index( pIDPair->m_nOldID );
if( nIndex != wxNOT_FOUND ) pGrid->m_arrCells[ nIndex ] = pIDPair->m_nNewID;
idnode = idnode->GetNext();
}
// check whether grid's children really exists
for( size_t i = 0; i < pGrid->m_arrCells.GetCount(); )
{
if( !GetItem( pGrid->m_arrCells[i] ) ) pGrid->RemoveFromGrid( pGrid->m_arrCells[i] );
else
i++;
}
node = node->GetNext();
}
m_lstGridsForUpdate.Clear();
}
}
void wxSFDiagramManager::UpdateAll()
{
wxSFShapeBase *pShape;
ShapeList lstShapes;
GetShapes( CLASSINFO(wxSFShapeBase), lstShapes );
ShapeList::compatibility_iterator node = lstShapes.GetFirst();
while( node )
{
pShape = node->GetData();
// update only shapes withour children because the Update() function is called recursively on all parents
if( !HasChildren( pShape ) ) pShape->Update();
node = node->GetNext();
}
}
void wxSFDiagramManager::MoveShapesFromNegatives()
{
wxSFShapeBase *pShape;
wxRealPoint shapePos;
double minx = 0, miny = 0;
// find the maximal negative position value
ShapeList shapes;
GetShapes(CLASSINFO(wxSFShapeBase), shapes);
ShapeList::compatibility_iterator node = shapes.GetFirst();
while(node)
{
shapePos = node->GetData()->GetAbsolutePosition();
if(node == shapes.GetFirst())
{
minx = shapePos.x;
miny = shapePos.y;
}
else
{
if(shapePos.x < minx)minx = shapePos.x;
if(shapePos.y < miny)miny = shapePos.y;
}
node = node->GetNext();
}
// move all parents shape so they (and their children) will be located in the positive values only
if((minx < 0) || (miny < 0))
{
node = shapes.GetFirst();
while(node)
{
pShape = node->GetData();
if(pShape->GetParentShape() == NULL)
{
if(minx < 0)pShape->MoveBy(abs((int)minx), 0);
if(miny < 0)pShape->MoveBy(0, abs((int)miny));
}
node = node->GetNext();
}
}
}

View File

@@ -0,0 +1,58 @@
/***************************************************************
* Name: DiamondArrow.cpp
* Purpose: Implements diamond arrow for line shapes
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2009-04-18
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/DiamondArrow.h"
// arrow shape
static const wxRealPoint arrow[4]={wxRealPoint(0,0), wxRealPoint(10,4), wxRealPoint(20,0), wxRealPoint(10,-4)};
XS_IMPLEMENT_CLONABLE_CLASS(wxSFDiamondArrow, wxSFSolidArrow);
wxSFDiamondArrow::wxSFDiamondArrow(void)
: wxSFSolidArrow()
{
}
wxSFDiamondArrow::wxSFDiamondArrow(wxSFShapeBase* parent)
: wxSFSolidArrow(parent)
{
}
wxSFDiamondArrow::wxSFDiamondArrow(const wxSFDiamondArrow& obj)
: wxSFSolidArrow(obj)
{
}
wxSFDiamondArrow::~wxSFDiamondArrow(void)
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFDiamondArrow::Draw(const wxRealPoint &from, const wxRealPoint &to, wxDC& dc)
{
wxPoint rarrow[4];
TranslateArrow( rarrow, arrow, 4, from, to );
dc.SetPen(m_Pen);
dc.SetBrush(m_Fill);
dc.DrawPolygon(4, rarrow);
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}

View File

@@ -0,0 +1,78 @@
/***************************************************************
* Name: DiamondShape.cpp
* Purpose: Implements diamond shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/DiamondShape.h"
#include "wx/wxsf/CommonFcn.h"
// diamond shape
const wxRealPoint diamond[4]={wxRealPoint(0,25), wxRealPoint(50,0), wxRealPoint(100, 25), wxRealPoint(50, 50)};
XS_IMPLEMENT_CLONABLE_CLASS(wxSFDiamondShape, wxSFPolygonShape);
wxSFDiamondShape::wxSFDiamondShape()
: wxSFPolygonShape()
{
EnablePropertySerialization(wxT("vertices"), false);
SetVertices(4, diamond);
}
wxSFDiamondShape::wxSFDiamondShape(const wxRealPoint& pos, wxSFDiagramManager* manager)
: wxSFPolygonShape(4, diamond, pos, manager)
{
EnablePropertySerialization(wxT("vertices"), false);
}
wxSFDiamondShape::wxSFDiamondShape(const wxSFDiamondShape& obj)
: wxSFPolygonShape(obj)
{
}
wxSFDiamondShape::~wxSFDiamondShape()
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
bool wxSFDiamondShape::Contains(const wxPoint& pos)
{
wxRect bbRct = this->GetBoundingBox();
if(!bbRct.Contains(pos))return false;
wxRealPoint center = GetCenter();
double k = ((double)bbRct.GetHeight()/2)/((double)bbRct.GetWidth()/2);
if(pos.x <= center.x)
{
// test left-top quadrant
if((pos.y <= center.y) && (pos.y >= (center.y - (pos.x - bbRct.GetLeft())*k))) return true;
// test left-bottom quadrant
if((pos.y >= center.y) && (pos.y <= (center.y + (pos.x - bbRct.GetLeft())*k))) return true;
}
else
{
// test right-top quadrant
if((pos.y <= center.y) && (pos.y >= (bbRct.GetTop() + (pos.x - center.x)*k))) return true;
// test left-bottom quadrant
if((pos.y >= center.y) && (pos.y <= (bbRct.GetBottom() - (pos.x - center.x)*k))) return true;
}
return false;
}

View File

@@ -0,0 +1,290 @@
/***************************************************************
* Name: EditTextShape.cpp
* Purpose: Implements editable text shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include <wx/textctrl.h>
#include "wx/wxsf/EditTextShape.h"
#include "wx/wxsf/ShapeCanvas.h"
static int textCtrlId = wxNewId();
XS_IMPLEMENT_CLONABLE_CLASS(wxSFEditTextShape, wxSFTextShape);
BEGIN_EVENT_TABLE(wxSFContentCtrl, wxTextCtrl)
EVT_KILL_FOCUS(wxSFContentCtrl::OnKillFocus)
EVT_KEY_DOWN(wxSFContentCtrl::OnKeyDown)
END_EVENT_TABLE()
//----------------------------------------------------------------------------------//
// wxSFContentCtrl control class
//----------------------------------------------------------------------------------//
wxSFContentCtrl::wxSFContentCtrl(wxWindow* parent, wxWindowID id, wxSFEditTextShape* parentShape, const wxString& content, wxPoint pos, wxSize size, int style)
: wxTextCtrl(parent, id, content, pos, size, wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxNO_BORDER | style)
{
m_pParent = parent;
m_pParentShape = parentShape;
m_sPrevContent = content;
SetInsertionPointEnd();
if(m_pParentShape)
{
wxSFTextShape* pTextShape = (wxSFTextShape*)m_pParentShape;
// update the font size in accordance to the canvas scale
wxFont font = pTextShape->GetFont();
font.SetPointSize(int(font.GetPointSize() * m_pParentShape->GetParentCanvas()->GetScale()));
SetFont(font);
SetBackgroundColour(wxColour(200, 200, 200));
SetFocus();
}
}
void wxSFContentCtrl::OnKillFocus(wxFocusEvent& event)
{
wxUnusedVar( event );
//Quit();
}
void wxSFContentCtrl::OnKeyDown(wxKeyEvent& event)
{
switch(event.GetKeyCode())
{
case WXK_ESCAPE:
Quit( sfCANCEL_TEXT_CHANGES );
break;
case WXK_TAB:
Quit( sfAPPLY_TEXT_CHANGES );
break;
case WXK_RETURN:
// enter new line if SHIFT key was pressed together with the ENTER key
if( wxGetKeyState( WXK_SHIFT ) )
{
event.Skip();
}
else
Quit( sfAPPLY_TEXT_CHANGES );
break;
default:
event.Skip();
}
}
void wxSFContentCtrl::Quit(bool apply)
{
Hide();
if(m_pParentShape)
{
m_pParentShape->m_pTextCtrl = NULL;
m_pParentShape->SetStyle(m_pParentShape->m_nCurrentState);
// save canvas state if the textctrl content has changed...
if( apply && ( m_sPrevContent != GetValue() ) )
{
m_pParentShape->SetText(GetValue());
m_sPrevContent = GetValue();
// inform parent shape canvas about text change...
m_pParentShape->GetParentCanvas()->OnTextChange(m_pParentShape);
m_pParentShape->GetParentCanvas()->SaveCanvasState();
}
m_pParentShape->Update();
m_pParentShape->GetParentCanvas()->Refresh();
}
Destroy();
}
//----------------------------------------------------------------------------------//
// wxSFDetachedContentCtrl control class
//----------------------------------------------------------------------------------//
wxSFDetachedContentCtrl::wxSFDetachedContentCtrl( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxSize( -1,-1 ), wxDefaultSize );
wxBoxSizer* mainSizer;
mainSizer = new wxBoxSizer( wxVERTICAL );
m_pText = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 350,100 ), wxTE_MULTILINE );
m_pText->SetMinSize( wxSize( 350,100 ) );
mainSizer->Add( m_pText, 1, wxALL|wxEXPAND, 5 );
wxStdDialogButtonSizer* buttonSizer;
wxButton* buttonSizerOK;
wxButton* buttonSizerCancel;
buttonSizer = new wxStdDialogButtonSizer();
buttonSizerOK = new wxButton( this, wxID_OK );
buttonSizer->AddButton( buttonSizerOK );
buttonSizerCancel = new wxButton( this, wxID_CANCEL );
buttonSizer->AddButton( buttonSizerCancel );
buttonSizer->Realize();
mainSizer->Add( buttonSizer, 0, wxALIGN_RIGHT|wxBOTTOM|wxRIGHT, 5 );
this->SetSizer( mainSizer );
this->Layout();
mainSizer->Fit( this );
this->Centre( wxBOTH );
}
wxSFDetachedContentCtrl::~wxSFDetachedContentCtrl()
{
}
//----------------------------------------------------------------------------------//
// wxSFEditTextShape shape class
//----------------------------------------------------------------------------------//
wxSFEditTextShape::wxSFEditTextShape(void)
: wxSFTextShape()
{
m_pTextCtrl = NULL;
m_fForceMultiline = sfdvEDITTEXTSHAPE_FORCEMULTILINE;
m_nEditType = sfdvEDITTEXTSHAPE_EDITTYPE;
XS_SERIALIZE_EX(m_fForceMultiline, wxT("multiline"), sfdvEDITTEXTSHAPE_FORCEMULTILINE);
XS_SERIALIZE_INT_EX(m_nEditType, wxT("edittype"), sfdvEDITTEXTSHAPE_EDITTYPE);
}
wxSFEditTextShape::wxSFEditTextShape(const wxRealPoint& pos, const wxString& txt, wxSFDiagramManager* manager)
: wxSFTextShape(pos, txt, manager)
{
m_pTextCtrl = NULL;
m_fForceMultiline = sfdvEDITTEXTSHAPE_FORCEMULTILINE;
m_nEditType = sfdvEDITTEXTSHAPE_EDITTYPE;
XS_SERIALIZE_EX(m_fForceMultiline, wxT("multiline"), sfdvEDITTEXTSHAPE_FORCEMULTILINE);
XS_SERIALIZE_INT_EX(m_nEditType, wxT("edittype"), sfdvEDITTEXTSHAPE_EDITTYPE);
}
wxSFEditTextShape::wxSFEditTextShape(const wxSFEditTextShape& obj)
: wxSFTextShape(obj)
{
m_pTextCtrl = NULL;
m_fForceMultiline = obj.m_fForceMultiline;
m_nEditType = obj.m_nEditType;
XS_SERIALIZE_EX(m_fForceMultiline, wxT("multiline"), sfdvEDITTEXTSHAPE_FORCEMULTILINE);
XS_SERIALIZE_INT_EX(m_nEditType, wxT("edittype"), sfdvEDITTEXTSHAPE_EDITTYPE);
}
wxSFEditTextShape::~wxSFEditTextShape(void)
{
if(m_pTextCtrl)delete m_pTextCtrl;
}
//----------------------------------------------------------------------------------//
// public functions
//----------------------------------------------------------------------------------//
void wxSFEditTextShape::EditLabel()
{
if( GetParentCanvas() )
{
int dx, dy;
wxRealPoint shpPos = GetAbsolutePosition();
double scale = GetParentCanvas()->GetScale();
GetParentCanvas()->CalcUnscrolledPosition(0, 0, &dx, &dy);
switch( m_nEditType )
{
case editINPLACE:
{
wxRect shpBB = GetBoundingBox();
int style = 0;
if( m_fForceMultiline || m_sText.Contains(wxT("\n")) )
{
style = wxTE_MULTILINE;
// set minimal control size
}
if( (m_sText == wxEmptyString) || ((style == wxTE_MULTILINE) && (shpBB.GetWidth() < 50)) )shpBB.SetWidth(50);
m_nCurrentState = GetStyle();
RemoveStyle(sfsSIZE_CHANGE);
m_pTextCtrl = new wxSFContentCtrl(GetParentCanvas(), textCtrlId, this, m_sText, wxPoint(int((shpPos.x * scale) - dx), int((shpPos.y * scale) - dy)), wxSize(int(shpBB.GetWidth() * scale), int(shpBB.GetHeight() * scale)), style);
}
break;
case editDIALOG:
{
wxString sPrevText = GetText();
wxSFDetachedContentCtrl m_pTextDlg( GetParentCanvas() );
//m_pTextDlg.Move( wxPoint(int((shpPos.x * scale) - dx), int((shpPos.y * scale) - dy)) );
m_pTextDlg.SetContent( sPrevText );
if( m_pTextDlg.ShowModal() == wxID_OK )
{
if( m_pTextDlg.GetContent() != sPrevText )
{
SetText( m_pTextDlg.GetContent() );
GetParentCanvas()->OnTextChange( this );
GetParentCanvas()->SaveCanvasState();
Update();
GetParentCanvas()->Refresh( false );
}
}
}
break;
default:
break;
}
}
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFEditTextShape::OnLeftDoubleClick(const wxPoint& pos)
{
// HINT: override it if neccessary...
wxUnusedVar( pos );
EditLabel();
}
bool wxSFEditTextShape::OnKey(int key)
{
// HINT: override it if neccessary...
switch(key)
{
case WXK_F2:
if(IsActive() && IsVisible())
{
EditLabel();
}
break;
default:
break;
}
return wxSFShapeBase::OnKey(key);
}

View File

@@ -0,0 +1,138 @@
/***************************************************************
* Name: EllipseShape.cpp
* Purpose: Implements ellipse shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/EllipseShape.h"
#include "wx/wxsf/ShapeCanvas.h"
#include "wx/wxsf/CommonFcn.h"
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFEllipseShape, wxSFRectShape);
wxSFEllipseShape::wxSFEllipseShape(void)
:wxSFRectShape()
{
}
wxSFEllipseShape::wxSFEllipseShape(const wxRealPoint& pos, const wxRealPoint& size, wxSFDiagramManager* manager)
: wxSFRectShape(pos, size, manager)
{
}
wxSFEllipseShape::wxSFEllipseShape(const wxSFEllipseShape& obj)
: wxSFRectShape(obj)
{
}
wxSFEllipseShape::~wxSFEllipseShape()
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
wxRealPoint wxSFEllipseShape::GetBorderPoint(const wxRealPoint& start, const wxRealPoint& end)
{
double dist = Distance(start, end);
wxRealPoint nCenter = GetAbsolutePosition() + wxRealPoint(m_nRectSize.x/2, m_nRectSize.y/2);
if(dist)
{
double srcDx = m_nRectSize.x/2*(end.x-start.x)/dist - (start.x-nCenter.x);
double srcDy = m_nRectSize.y/2*(end.y-start.y)/dist - (start.y-nCenter.y);
return wxRealPoint(start.x + srcDx, start.y + srcDy);
}
else
return nCenter;
}
bool wxSFEllipseShape::Contains(const wxPoint& pos)
{
// HINT: overload it for custom actions...
double m, n, a, b;
wxRealPoint apos;
a = GetRectSize().x/2;
b = GetRectSize().y/2;
apos = GetAbsolutePosition();
m = apos.x + a;
n = apos.y + b;
if((((pos.x - m)*(pos.x - m))/(a*a) + ((pos.y - n)*(pos.y - n))/(b*b)) < 1)return true;
else
return false;
}
//----------------------------------------------------------------------------------//
// protected virtual functions
//----------------------------------------------------------------------------------//
void wxSFEllipseShape::DrawNormal(wxDC& dc)
{
// HINT: overload it for custom actions...
dc.SetPen(m_Border);
dc.SetBrush(m_Fill);
dc.DrawEllipse(Conv2Point(GetAbsolutePosition()), Conv2Size(m_nRectSize));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFEllipseShape::DrawHover(wxDC& dc)
{
// HINT: overload it for custom actions...
dc.SetPen(wxPen(m_nHoverColor, 1));
dc.SetBrush(m_Fill);
dc.DrawEllipse(Conv2Point(GetAbsolutePosition()), Conv2Size(m_nRectSize));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFEllipseShape::DrawHighlighted(wxDC& dc)
{
// HINT: overload it for custom actions...
dc.SetPen(wxPen(m_nHoverColor, 2));
dc.SetBrush(m_Fill);
dc.DrawEllipse(Conv2Point(GetAbsolutePosition()), Conv2Size(m_nRectSize));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFEllipseShape::DrawShadow(wxDC& dc)
{
// HINT: overload it for custom actions...
if( m_Fill.GetStyle() != wxTRANSPARENT )
{
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(GetParentCanvas()->GetShadowFill());
dc.DrawEllipse(Conv2Point(GetAbsolutePosition() + GetParentCanvas()->GetShadowOffset()), Conv2Size(m_nRectSize));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
}

View File

@@ -0,0 +1,160 @@
/***************************************************************
* Name: FixedRectShape.cpp
* Purpose: Implements square shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/FixedRectShape.h"
XS_IMPLEMENT_CLONABLE_CLASS(wxSFSquareShape, wxSFRectShape);
wxSFSquareShape::wxSFSquareShape(void)
: wxSFRectShape()
{
SetRectSize(100, 100);
}
wxSFSquareShape::wxSFSquareShape(const wxRealPoint& pos, double size, wxSFDiagramManager* manager)
: wxSFRectShape(pos, wxRealPoint(size, size), manager)
{
}
wxSFSquareShape::wxSFSquareShape(const wxSFSquareShape& obj)
: wxSFRectShape(obj)
{
}
wxSFSquareShape::~wxSFSquareShape()
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFSquareShape::Scale(double x, double y, bool children)
{
// HINT: overload it for custom actions...
if((x > 0) && (y > 0))
{
double s = 1;
if(x == 1) s = y;
else if (y == 1) s = x;
else if(x >= y) s = x;
else
s = y;
SetRectSize(m_nRectSize.x * s, m_nRectSize.y * s);
// call default function implementation (needed for scaling of shape's children)
wxSFShapeBase::Scale(x, y, children);
}
}
void wxSFSquareShape::OnHandle(wxSFShapeHandle& handle)
{
// HINT: overload it for custom actions...
double maxsize = 0, dx = 0, dy = 0;
wxRealPoint prevSize = m_nRectSize;
// perform standard operations
switch(handle.GetType())
{
case wxSFShapeHandle::hndLEFTTOP:
case wxSFShapeHandle::hndLEFT:
case wxSFShapeHandle::hndLEFTBOTTOM:
OnLeftHandle(handle);
break;
case wxSFShapeHandle::hndRIGHTTOP:
case wxSFShapeHandle::hndRIGHT:
case wxSFShapeHandle::hndRIGHTBOTTOM:
OnRightHandle(handle);
break;
case wxSFShapeHandle::hndTOP:
OnTopHandle(handle);
break;
case wxSFShapeHandle::hndBOTTOM:
OnBottomHandle(handle);
break;
default:
break;
}
// calculate common size and some auxilary values
if((prevSize.x < m_nRectSize.x) || (prevSize.y < m_nRectSize.y))
{
if(m_nRectSize.x >= m_nRectSize.y)maxsize = m_nRectSize.x;
else
maxsize = m_nRectSize.y;
}
else
{
if(m_nRectSize.x <= m_nRectSize.y)maxsize = m_nRectSize.x;
else
maxsize = m_nRectSize.y;
}
dx = maxsize - m_nRectSize.x;
dy = maxsize - m_nRectSize.y;
// normalize rect sizes
m_nRectSize.x = m_nRectSize.y = maxsize;
// move rect if neccessary
switch(handle.GetType())
{
case wxSFShapeHandle::hndLEFT:
MoveBy(-dx, -dy/2);
break;
case wxSFShapeHandle::hndLEFTTOP:
MoveBy(-dx, -dy);
break;
case wxSFShapeHandle::hndLEFTBOTTOM:
MoveBy(-dx, 0);
break;
case wxSFShapeHandle::hndRIGHT:
MoveBy(0, -dy/2);
break;
case wxSFShapeHandle::hndRIGHTTOP:
MoveBy(0, -dy);
break;
case wxSFShapeHandle::hndTOP:
MoveBy(-dx/2, -dy);
break;
case wxSFShapeHandle::hndBOTTOM:
MoveBy(-dx/2, 0);
break;
default:
break;
}
wxSFShapeBase::OnHandle( handle );
}

View File

@@ -0,0 +1,114 @@
/***************************************************************
* Name: FlexGridShape.cpp
* Purpose: Implements flexible grid shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2008-09-27
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/FlexGridShape.h"
XS_IMPLEMENT_CLONABLE_CLASS(wxSFFlexGridShape, wxSFGridShape);
wxSFFlexGridShape::wxSFFlexGridShape() : wxSFGridShape()
{
}
wxSFFlexGridShape::wxSFFlexGridShape(const wxRealPoint& pos, const wxRealPoint& size, int rows, int cols, int cellspace, wxSFDiagramManager* manager)
: wxSFGridShape(pos, size, rows, cols, cellspace, manager)
{
}
wxSFFlexGridShape::wxSFFlexGridShape(const wxSFFlexGridShape& obj) : wxSFGridShape(obj)
{
}
wxSFFlexGridShape::~wxSFFlexGridShape()
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFFlexGridShape::DoChildrenLayout()
{
if( !m_nCols || !m_nRows ) return;
wxSFShapeBase *pShape;
int nIndex, nRow, nCol, nTotalX, nTotalY;
size_t i;
wxRect nCurrRect;
// initialize size arrays
m_arrRowSizes.SetCount( m_nRows );
m_arrColSizes.SetCount( m_nCols );
for( i = 0; i < (size_t)m_nRows; i++ ) m_arrRowSizes[i] = 0;
for( i = 0; i < (size_t)m_nCols; i++ ) m_arrColSizes[i] = 0;
nIndex = nCol = nTotalX = nTotalY = 0;
nRow = -1;
// prepare a storage for processed shapes pointers
m_arrChildShapes.SetCount( m_arrCells.GetCount() );
// get maximum size of all managed (child) shapes per row and collumn
for( i = 0; i < m_arrCells.GetCount(); i++ )
{
pShape = (wxSFShapeBase*)GetChild(m_arrCells[i]);
if( pShape )
{
// store used shape pointer for further processing (optimization for speed)
m_arrChildShapes[i] = pShape;
if( nIndex++ % m_nCols == 0 )
{
nCol = 0; nRow++;
}
else
nCol++;
nCurrRect = pShape->GetBoundingBox();
// update maximum rows and columns sizes
if( (pShape->GetHAlign() != halignEXPAND) && (nCurrRect.GetWidth() > m_arrColSizes[nCol]) ) m_arrColSizes[nCol] = nCurrRect.GetWidth();
if( (pShape->GetVAlign() != valignEXPAND) && (nCurrRect.GetHeight() > m_arrRowSizes[nRow]) ) m_arrRowSizes[nRow] = nCurrRect.GetHeight();
}
}
// put managed shapes to appropriate positions
nIndex = nCol = 0;
nRow = -1;
for( i = 0; i < m_arrCells.GetCount(); i++ )
{
pShape = m_arrChildShapes[i];
if( pShape )
{
if( nIndex++ % m_nCols == 0 )
{
nCol = 0; nTotalX = 0; nRow++;
if( nRow > 0 ) nTotalY += m_arrRowSizes[ nRow-1 ];
}
else
{
nCol++;
if( nCol > 0 ) nTotalX += m_arrColSizes[ nCol-1 ];
}
FitShapeToRect( pShape, wxRect( nTotalX + (nCol+1)*m_nCellSpace,
nTotalY + (nRow+1)*m_nCellSpace,
m_arrColSizes[ nCol ], m_arrRowSizes[ nRow ] ) );
}
}
}

View File

@@ -0,0 +1,171 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="9" />
<object class="Project" expanded="1">
<property name="class_decoration"></property>
<property name="code_generation">C++</property>
<property name="disconnect_events">1</property>
<property name="encoding">UTF-8</property>
<property name="event_generation">connect</property>
<property name="event_handler">impl_virtual</property>
<property name="file">wxsfdetachedcontentctrl</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="internationalize">1</property>
<property name="name">wxSFDetachedContentCtrl</property>
<property name="namespace"></property>
<property name="path">.</property>
<property name="precompiled_header"></property>
<property name="relative_path">1</property>
<property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property>
<object class="Dialog" expanded="1">
<property name="bg"></property>
<property name="center">wxBOTH</property>
<property name="context_help"></property>
<property name="enabled">1</property>
<property name="extra_style"></property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size">-1,-1</property>
<property name="name">wxSFDetachedContentCtrl</property>
<property name="pos"></property>
<property name="size">-1,-1</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass"></property>
<property name="title">Edit content...</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnActivate"></event>
<event name="OnActivateApp"></event>
<event name="OnChar"></event>
<event name="OnClose"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnHibernate"></event>
<event name="OnIconize"></event>
<event name="OnIdle"></event>
<event name="OnInitDialog"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">mainSizer</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxTextCtrl" expanded="1">
<property name="bg"></property>
<property name="context_help"></property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="maxlength">0</property>
<property name="minimum_size">350,100</property>
<property name="name">m_pText</property>
<property name="permission">protected</property>
<property name="pos"></property>
<property name="size">350,100</property>
<property name="style">wxTE_MULTILINE</property>
<property name="subclass"></property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnText"></event>
<event name="OnTextEnter"></event>
<event name="OnTextMaxLen"></event>
<event name="OnTextURL"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_RIGHT|wxBOTTOM|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStdDialogButtonSizer" expanded="1">
<property name="Apply">0</property>
<property name="Cancel">1</property>
<property name="ContextHelp">0</property>
<property name="Help">0</property>
<property name="No">0</property>
<property name="OK">1</property>
<property name="Save">0</property>
<property name="Yes">0</property>
<property name="minimum_size"></property>
<property name="name">buttonSizer</property>
<property name="permission">none</property>
<event name="OnApplyButtonClick"></event>
<event name="OnCancelButtonClick"></event>
<event name="OnContextHelpButtonClick"></event>
<event name="OnHelpButtonClick"></event>
<event name="OnNoButtonClick"></event>
<event name="OnOKButtonClick"></event>
<event name="OnSaveButtonClick"></event>
<event name="OnYesButtonClick"></event>
</object>
</object>
</object>
</object>
</object>
</wxFormBuilder_Project>

View File

@@ -0,0 +1,389 @@
/***************************************************************
* Name: GridShape.cpp
* Purpose: Implements grid shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2008-08-02
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/GridShape.h"
#include "wx/wxsf/LineShape.h"
XS_IMPLEMENT_CLONABLE_CLASS(wxSFGridShape, wxSFRectShape);
wxSFGridShape::wxSFGridShape() : wxSFRectShape()
{
m_nRows = sfdvGRIDSHAPE_ROWS;
m_nCols = sfdvGRIDSHAPE_COLS;
m_nCellSpace = sfdvGRIDSHAPE_CELLSPACE;
RemoveStyle(sfsSIZE_CHANGE);
MarkSerializableDataMembers();
}
wxSFGridShape::wxSFGridShape(const wxRealPoint& pos, const wxRealPoint& size, int rows, int cols, int cellspace, wxSFDiagramManager* manager)
: wxSFRectShape(pos, size, manager)
{
m_nRows = rows;
m_nCols = cols;
m_nCellSpace = cellspace;
RemoveStyle(sfsSIZE_CHANGE);
m_arrCells.Alloc( rows * cols );
MarkSerializableDataMembers();
}
wxSFGridShape::wxSFGridShape(const wxSFGridShape& obj) : wxSFRectShape(obj)
{
m_nRows = obj.m_nRows;
m_nCols = obj.m_nCols;
m_nCellSpace = obj.m_nCellSpace;
RemoveStyle(sfsSIZE_CHANGE);
m_arrCells.Clear();
WX_APPEND_ARRAY(m_arrCells, obj.m_arrCells);
MarkSerializableDataMembers();
}
wxSFGridShape::~wxSFGridShape()
{
}
void wxSFGridShape::MarkSerializableDataMembers()
{
XS_SERIALIZE_EX(m_nRows, wxT("rows"), sfdvGRIDSHAPE_ROWS);
XS_SERIALIZE_EX(m_nCols, wxT("cols"), sfdvGRIDSHAPE_COLS);
XS_SERIALIZE_EX(m_nCellSpace, wxT("cell_space"), sfdvGRIDSHAPE_CELLSPACE);
XS_SERIALIZE(m_arrCells, wxT("cells"));
}
//----------------------------------------------------------------------------------//
// public functions
//----------------------------------------------------------------------------------//
void wxSFGridShape::SetDimensions(int rows, int cols)
{
wxASSERT(rows);
wxASSERT(cols);
if( !(rows * cols) ) return;
m_nRows = rows;
m_nCols = cols;
m_arrCells.Alloc( rows * cols );
}
void wxSFGridShape::GetDimensions(int *rows, int *cols)
{
*rows = m_nRows;
*cols = m_nCols;
}
void wxSFGridShape::ClearGrid()
{
m_nRows = 0;
m_nCols = 0;
m_arrCells.Clear();
}
bool wxSFGridShape::AppendToGrid(wxSFShapeBase *shape)
{
int row = m_arrCells.GetCount() / m_nCols;
int col = m_arrCells.GetCount() - row*m_nCols;
return InsertToGrid( row, col, shape );
}
bool wxSFGridShape::InsertToGrid(int row, int col, wxSFShapeBase *shape)
{
wxASSERT(shape);
if( shape && shape->IsKindOf(CLASSINFO(wxSFShapeBase)) && IsChildAccepted(shape->GetClassInfo()->GetClassName()) )
{
// protect duplicated occurences
if( m_arrCells.Index(shape->GetId()) != wxNOT_FOUND) return false;
// protect unbounded horizontal index (grid can grow in a vertical direction only)
if( col >= m_nCols ) return false;
// add the shape to the children list if neccessary
if( GetChildrenList().IndexOf(shape) == wxNOT_FOUND )
{
shape->Reparent(this);
}
m_arrCells.SetCount(row * m_nCols + col + 1);
m_arrCells[row * m_nCols + col] = shape->GetId();
if( m_nRows <= row ) m_nRows = row + 1;
return true;
}
return false;
}
bool wxSFGridShape::InsertToGrid(int index, wxSFShapeBase *shape)
{
wxASSERT(shape);
if( shape && shape->IsKindOf(CLASSINFO(wxSFShapeBase)) && IsChildAccepted(shape->GetClassInfo()->GetClassName()) )
{
// protect duplicated occurences
if( m_arrCells.Index(shape->GetId()) != wxNOT_FOUND) return false;
// protect unbounded index
if( index >= (m_nRows * m_nCols) ) return false;
// add the shape to the children list if neccessary
if( GetChildrenList().IndexOf(shape) == wxNOT_FOUND )
{
shape->Reparent(this);
}
m_arrCells.SetCount(index + 1);
m_arrCells.Insert(shape->GetId(), index);
return true;
}
return false;
}
wxSFShapeBase* wxSFGridShape::GetManagedShape(size_t index)
{
if( (index >= 0) && (index < GetChildrenList().GetCount()) )
{
return (wxSFShapeBase*) GetChild( m_arrCells[index] );
}
else
return NULL;
}
wxSFShapeBase* wxSFGridShape::GetManagedShape(int row, int col)
{
if( (row >= 0) && (row < m_nRows) && (col >=0) && (col < m_nCols) )
{
return GetManagedShape( row * m_nCols + col );
}
else
return NULL;
}
void wxSFGridShape::RemoveFromGrid(long id)
{
if( m_arrCells.Index( id ) != wxNOT_FOUND )
{
m_arrCells.Remove( id );
}
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFGridShape::DoChildrenLayout()
{
if( !m_nCols || !m_nRows ) return;
wxSFShapeBase *pShape;
int nIndex, nRow, nCol;
//wxRealPoint nAbsPos = GetAbsolutePosition();
wxRect currRect, maxRect = wxRect(0,0,0,0);
// get maximum size of all managed (child) shapes
SerializableList::compatibility_iterator node = GetFirstChildNode();
while(node)
{
pShape = (wxSFShapeBase*)node->GetData();
currRect = pShape->GetBoundingBox();
if( (pShape->GetHAlign() != halignEXPAND) && (currRect.GetWidth() > maxRect.GetWidth()) ) maxRect.SetWidth(currRect.GetWidth());
if( (pShape->GetVAlign() != valignEXPAND) && (currRect.GetHeight() > maxRect.GetHeight()) ) maxRect.SetHeight(currRect.GetHeight());
node = node->GetNext();
}
// put managed shapes to appropriate positions
nIndex = nCol = 0;
nRow = -1;
for(size_t i = 0; i < m_arrCells.GetCount(); i++ )
{
pShape = (wxSFShapeBase*) GetChild(m_arrCells[i]);
if( pShape )
{
if( nIndex++ % m_nCols == 0 )
{
nCol = 0; nRow++;
}
else
nCol++;
FitShapeToRect( pShape, wxRect( nCol*maxRect.GetWidth() + (nCol+1)*m_nCellSpace,
nRow*maxRect.GetHeight() + (nRow+1)*m_nCellSpace,
maxRect.GetWidth(), maxRect.GetHeight() ) );
}
}
}
void wxSFGridShape::Update()
{
wxSFShapeBase *pShape;
// check an existence of already assigned shapes
for(size_t i = 0; i < m_arrCells.GetCount(); )
{
if( !GetChild(m_arrCells[i])) m_arrCells.RemoveAt(i);
else
i++;
}
// check whether all child shapes' IDs are present in the cells array...
SerializableList::compatibility_iterator node = GetFirstChildNode();
while(node)
{
pShape = (wxSFShapeBase*)node->GetData();
if( m_arrCells.Index(pShape->GetId()) == wxNOT_FOUND ) m_arrCells.Add(pShape->GetId());
node = node->GetNext();
}
// do self-alignment
DoAlignment();
// do alignment of shape's children
this->DoChildrenLayout();
// fit the shape to its children
this->FitToChildren();
// do it recursively on all parent shapes
if( GetParentShape() )GetParentShape()->Update();
}
void wxSFGridShape::FitToChildren()
{
// HINT: overload it for custom actions...
wxSFShapeBase* pChild;
// get bounding box of the shape and children set be inside it
wxRealPoint nAbsPos = GetAbsolutePosition();
wxRect chBB = wxRect(nAbsPos.x, nAbsPos.y, 0, 0);
SerializableList::compatibility_iterator node = GetFirstChildNode();
while(node)
{
pChild = (wxSFShapeBase*)node->GetData();
if( pChild->GetStyle() & sfsALWAYS_INSIDE )
{
pChild->GetCompleteBoundingBox(chBB, bbSELF | bbCHILDREN);
}
node = node->GetNext();
}
// do not let the grid shape 'disappear' due to zero sizes...
if( (!chBB.GetWidth() || !chBB.GetHeight()) && !m_nCellSpace )
{
chBB.SetWidth( 10 );
chBB.SetHeight( 10 );
}
m_nRectSize = wxRealPoint(chBB.GetSize().x + 2*m_nCellSpace, chBB.GetSize().y + 2*m_nCellSpace);
}
void wxSFGridShape::OnChildDropped(const wxRealPoint& pos, wxSFShapeBase *child)
{
wxASSERT(child);
wxUnusedVar( pos );
if( child && !child->IsKindOf(CLASSINFO(wxSFLineShape)) ) AppendToGrid( child );
}
//----------------------------------------------------------------------------------//
// protected functions
//----------------------------------------------------------------------------------//
void wxSFGridShape::FitShapeToRect(wxSFShapeBase *shape, const wxRect& rct)
{
wxRect shapeBB = shape->GetBoundingBox();
wxRealPoint prevPos = shape->GetRelativePosition();
// do vertical alignment
switch( shape->GetVAlign() )
{
case valignTOP:
shape->SetRelativePosition( prevPos.x, rct.GetTop() + shape->GetVBorder() );
break;
case valignMIDDLE:
shape->SetRelativePosition( prevPos.x, rct.GetTop() + (rct.GetHeight()/2 - shapeBB.GetHeight()/2) );
break;
case valignBOTTOM:
shape->SetRelativePosition( prevPos.x, rct.GetBottom() - shapeBB.GetHeight() - shape->GetVBorder() );
break;
case valignEXPAND:
if( shape->ContainsStyle( sfsSIZE_CHANGE ) )
{
shape->SetRelativePosition( prevPos.x, rct.GetTop() + shape->GetVBorder() );
shape->Scale( 1.f, double(rct.GetHeight() - 2*shape->GetVBorder())/shapeBB.GetHeight() );
}
break;
default:
shape->SetRelativePosition( prevPos.x, rct.GetTop() );
break;
}
prevPos = shape->GetRelativePosition();
// do horizontal alignment
switch( shape->GetHAlign() )
{
case halignLEFT:
shape->SetRelativePosition( rct.GetLeft() + shape->GetHBorder(), prevPos.y );
break;
case halignCENTER:
shape->SetRelativePosition( rct.GetLeft() + (rct.GetWidth()/2 - shapeBB.GetWidth()/2), prevPos.y );
break;
case halignRIGHT:
shape->SetRelativePosition( rct.GetRight() - shapeBB.GetWidth() - shape->GetHBorder(), prevPos.y );
break;
case halignEXPAND:
if( shape->ContainsStyle( sfsSIZE_CHANGE ) )
{
shape->SetRelativePosition( rct.GetLeft() + shape->GetHBorder(), prevPos.y );
shape->Scale( double(rct.GetWidth() - 2*shape->GetHBorder())/shapeBB.GetWidth(), 1.f );
}
break;
default:
shape->SetRelativePosition( rct.GetLeft(), prevPos.y );
break;
}
}

View File

@@ -0,0 +1,927 @@
/***************************************************************
* Name: LineShape.cpp
* Purpose: Implements line shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/LineShape.h"
#include "wx/wxsf/ShapeCanvas.h"
#include "wx/wxsf/CommonFcn.h"
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFLineShape, wxSFShapeBase);
// arrow shape
const wxRealPoint arrow[3]={wxRealPoint(0,0), wxRealPoint(10,4), wxRealPoint(10,-4)};
wxSFLineShape::wxSFLineShape(void)
{
m_nSrcShapeId = sfdvLINESHAPE_UNKNOWNID;
m_nTrgShapeId = sfdvLINESHAPE_UNKNOWNID;
m_pSrcArrow = NULL;
m_pTrgArrow = NULL;
m_nSrcPoint = sfdvLINESHAPE_DEFAULTPOINT;
m_nTrgPoint = sfdvLINESHAPE_DEFAULTPOINT;
m_nDockPoint = sfdvLINESHAPE_DOCKPOINT;
m_Pen = sfdvLINESHAPE_PEN;
m_nSrcOffset = m_nTrgOffset = sfdvLINESHAPE_OFFSET;
m_nMode = modeREADY;
m_fStandAlone = sfdvLINESHAPE_STANDALONE;
MarkSerializableDataMembers();
m_lstPoints.DeleteContents(true);
}
wxSFLineShape::wxSFLineShape(long src, long trg, const wxXS::RealPointList& path, wxSFDiagramManager* manager)
: wxSFShapeBase(wxRealPoint(0, 0), manager)
{
m_nSrcShapeId = src;
m_nTrgShapeId = trg;
m_nDockPoint = sfdvLINESHAPE_DOCKPOINT;
m_pSrcArrow = NULL;
m_pTrgArrow = NULL;
m_nSrcPoint = sfdvLINESHAPE_DEFAULTPOINT;
m_nTrgPoint = sfdvLINESHAPE_DEFAULTPOINT;
m_Pen = sfdvLINESHAPE_PEN;
m_nSrcOffset = m_nTrgOffset = sfdvLINESHAPE_OFFSET;
m_nMode = modeREADY;
m_fStandAlone = false;
wxXS::RealPointList::compatibility_iterator node = path.GetFirst();
while(node)
{
m_lstPoints.Append(new wxRealPoint(*node->GetData()));
node = node->GetNext();
}
MarkSerializableDataMembers();
m_lstPoints.DeleteContents(true);
}
wxSFLineShape::wxSFLineShape(const wxRealPoint& src, const wxRealPoint& trg, const wxXS::RealPointList& path, wxSFDiagramManager* manager)
: wxSFShapeBase(wxRealPoint(0, 0), manager)
{
m_nSrcShapeId = sfdvLINESHAPE_UNKNOWNID;
m_nTrgShapeId = sfdvLINESHAPE_UNKNOWNID;
m_nDockPoint = sfdvLINESHAPE_DOCKPOINT;
m_pSrcArrow = NULL;
m_pTrgArrow = NULL;
m_nSrcPoint = src;
m_nTrgPoint = trg;
m_Pen = sfdvLINESHAPE_PEN;
m_nSrcOffset = m_nTrgOffset = sfdvLINESHAPE_OFFSET;
m_nMode = modeREADY;
m_fStandAlone = true;
wxXS::RealPointList::compatibility_iterator node = path.GetFirst();
while(node)
{
m_lstPoints.Append(new wxRealPoint(*node->GetData()));
node = node->GetNext();
}
MarkSerializableDataMembers();
m_lstPoints.DeleteContents(true);
}
wxSFLineShape::wxSFLineShape(const wxSFLineShape& obj)
: wxSFShapeBase(obj)
{
m_nSrcShapeId = obj.m_nSrcShapeId;
m_nTrgShapeId = obj.m_nTrgShapeId;
m_nDockPoint = obj.m_nDockPoint;
m_nSrcOffset = obj.m_nSrcOffset;
m_nTrgOffset = obj.m_nTrgOffset;
m_nSrcPoint = obj.m_nSrcPoint;
m_nTrgPoint = obj.m_nTrgPoint;
if(obj.m_pSrcArrow)
{
m_pSrcArrow = (wxSFArrowBase*)obj.m_pSrcArrow->Clone();
}
else
m_pSrcArrow = NULL;
if(obj.m_pTrgArrow)
{
m_pTrgArrow = (wxSFArrowBase*)obj.m_pTrgArrow->Clone();
}
else
m_pTrgArrow = NULL;
m_Pen = obj.m_Pen;
m_nMode = obj.m_nMode;
m_fStandAlone = obj.m_fStandAlone;
wxXS::RealPointList::compatibility_iterator node = obj.m_lstPoints.GetFirst();
while(node)
{
m_lstPoints.Append(new wxRealPoint(*node->GetData()));
node = node->GetNext();
}
MarkSerializableDataMembers();
m_lstPoints.DeleteContents(true);
}
wxSFLineShape::~wxSFLineShape(void)
{
m_lstPoints.Clear();
if(m_pSrcArrow)delete m_pSrcArrow;
if(m_pTrgArrow)delete m_pTrgArrow;
}
void wxSFLineShape::MarkSerializableDataMembers()
{
XS_SERIALIZE_EX(m_nSrcShapeId, wxT("source"), sfdvLINESHAPE_UNKNOWNID);
XS_SERIALIZE_EX(m_nTrgShapeId, wxT("target"), sfdvLINESHAPE_UNKNOWNID);
XS_SERIALIZE_EX(m_nSrcPoint, wxT("source_point"), sfdvLINESHAPE_DEFAULTPOINT);
XS_SERIALIZE_EX(m_nTrgPoint, wxT("target_point"), sfdvLINESHAPE_DEFAULTPOINT);
XS_SERIALIZE_EX(m_fStandAlone, wxT("standalone"), sfdvLINESHAPE_STANDALONE);
XS_SERIALIZE_DYNAMIC_OBJECT(m_pSrcArrow, wxT("source_arrow"));
XS_SERIALIZE_DYNAMIC_OBJECT(m_pTrgArrow, wxT("target_arrow"));
XS_SERIALIZE_EX(m_nSrcOffset, wxT("source_offset"), sfdvLINESHAPE_OFFSET);
XS_SERIALIZE_EX(m_nTrgOffset, wxT("target_offset"), sfdvLINESHAPE_OFFSET);
XS_SERIALIZE_LONG_EX(m_nDockPoint, wxT("dock_point"), sfdvLINESHAPE_DOCKPOINT);
XS_SERIALIZE_EX(m_Pen, wxT("line_style"), sfdvLINESHAPE_PEN);
XS_SERIALIZE(m_lstPoints, wxT("control_points"));
}
//----------------------------------------------------------------------------------//
// public functions
//----------------------------------------------------------------------------------//
void wxSFLineShape::SetSrcArrow(wxSFArrowBase* arrow)
{
if(m_pSrcArrow)delete m_pSrcArrow;
m_pSrcArrow = arrow;
if(m_pSrcArrow)
{
m_pSrcArrow->SetParentShape(this);
}
}
wxSFArrowBase* wxSFLineShape::SetSrcArrow(wxClassInfo* arrowInfo)
{
SetSrcArrow((wxSFArrowBase*)arrowInfo->CreateObject());
return m_pSrcArrow;
}
void wxSFLineShape::SetTrgArrow(wxSFArrowBase* arrow)
{
if(m_pTrgArrow)delete m_pTrgArrow;
m_pTrgArrow = arrow;
if(m_pTrgArrow)
{
m_pTrgArrow->SetParentShape(this);
}
}
wxSFArrowBase* wxSFLineShape::SetTrgArrow(wxClassInfo* arrowInfo)
{
SetTrgArrow((wxSFArrowBase*)arrowInfo->CreateObject());
return m_pTrgArrow;
}
wxRealPoint wxSFLineShape::GetSrcPoint()
{
if( m_fStandAlone )
{
return m_nSrcPoint;
}
else
{
wxRealPoint pt1, pt2;
wxSFShapeBase* pSrcShape = GetShapeManager()->FindShape(m_nSrcShapeId);
if( pSrcShape && !m_lstPoints.IsEmpty() )
{
if( pSrcShape->GetConnectionPoints().IsEmpty() )
{
wxXS::RealPointList::compatibility_iterator node = m_lstPoints.GetFirst();
if( node )
{
pt1 = *node->GetData();
return pSrcShape->GetBorderPoint(GetModSrcPoint(), pt1);
}
}
else
return GetModSrcPoint();
}
else
{
if( m_nMode != modeUNDERCONSTRUCTION )
GetDirectLine( pt1, pt2 );
else
pt1 = GetModSrcPoint();
return pt1;
}
return wxRealPoint();
}
}
wxRealPoint wxSFLineShape::GetTrgPoint()
{
if( m_fStandAlone )
{
return m_nTrgPoint;
}
else
{
wxRealPoint pt1, pt2;
wxSFShapeBase* pTrgShape = GetShapeManager()->FindShape(m_nTrgShapeId);
if( pTrgShape && !m_lstPoints.IsEmpty() )
{
if( pTrgShape->GetConnectionPoints().IsEmpty() )
{
wxXS::RealPointList::compatibility_iterator node = m_lstPoints.GetLast();
if( node )
{
pt2 = *node->GetData();
return pTrgShape->GetBorderPoint(GetModTrgPoint(), pt2);
}
}
else
return GetModTrgPoint();
}
else
{
if( m_nMode != modeUNDERCONSTRUCTION )
GetDirectLine( pt1, pt2 );
else
pt2 = Conv2RealPoint( m_nUnfinishedPoint );
return pt2;
}
return wxRealPoint();
}
}
void wxSFLineShape::GetDirectLine(wxRealPoint& src, wxRealPoint& trg)
{
if( m_fStandAlone )
{
src = m_nSrcPoint;
trg = m_nTrgPoint;
}
else
{
wxSFShapeBase* pSrcShape = GetShapeManager()->FindShape(m_nSrcShapeId);
wxSFShapeBase* pTrgShape = GetShapeManager()->FindShape(m_nTrgShapeId);
if( pSrcShape && pTrgShape )
{
wxRealPoint trgCenter = GetModTrgPoint();
wxRealPoint srcCenter = GetModSrcPoint();
if( (pSrcShape->GetParent() == pTrgShape) || (pTrgShape->GetParent() == pSrcShape) )
{
wxRect trgBB = pTrgShape->GetBoundingBox();
wxRect srcBB = pSrcShape->GetBoundingBox();
if( trgBB.Contains((int)srcCenter.x, (int)srcCenter.y) )
{
if( srcCenter.y > trgCenter.y )
{
src = wxRealPoint(srcCenter.x, srcBB.GetBottom());
trg = wxRealPoint(srcCenter.x, trgBB.GetBottom());
}
else
{
src = wxRealPoint(srcCenter.x, srcBB.GetTop());
trg = wxRealPoint(srcCenter.x, trgBB.GetTop());
}
return;
}
else if( srcBB.Contains((int)trgCenter.x, (int)trgCenter.y) )
{
if( trgCenter.y > srcCenter.y )
{
src = wxRealPoint(trgCenter.x, srcBB.GetBottom());
trg = wxRealPoint(trgCenter.x, trgBB.GetBottom());
}
else
{
src = wxRealPoint(trgCenter.x, srcBB.GetTop());
trg = wxRealPoint(trgCenter.x, trgBB.GetTop());
}
return;
}
}
if( pSrcShape->GetConnectionPoints().IsEmpty() ) src = pSrcShape->GetBorderPoint(srcCenter, trgCenter);
else
src = srcCenter;
if( pTrgShape->GetConnectionPoints().IsEmpty() ) trg = pTrgShape->GetBorderPoint(trgCenter, srcCenter);
else
trg = trgCenter;
}
}
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
wxRealPoint wxSFLineShape::GetAbsolutePosition()
{
return GetDockPointPosition( m_nDockPoint );
}
wxRealPoint wxSFLineShape::GetBorderPoint(const wxRealPoint& start, const wxRealPoint& end)
{
wxUnusedVar( start );
wxUnusedVar( end );
return GetAbsolutePosition();
}
wxRect wxSFLineShape::GetBoundingBox()
{
wxASSERT(m_pParentManager);
wxRect lineRct(0, 0, 0, 0);
// calculate control points area if they exist
if( !m_lstPoints.IsEmpty() )
{
wxRealPoint prevPt = GetSrcPoint();
wxXS::RealPointList::compatibility_iterator node = m_lstPoints.GetFirst();
while( node )
{
if(lineRct.IsEmpty())
{
lineRct = wxRect(Conv2Point(prevPt), Conv2Point(*node->GetData()));
}
else
lineRct.Union(wxRect(Conv2Point(prevPt), Conv2Point(*node->GetData())));
prevPt = *node->GetData();
node = node->GetNext();
}
lineRct.Union(wxRect(Conv2Point(prevPt), Conv2Point(GetTrgPoint())));
}
else
{
wxRealPoint pt;
// include starting point
pt = GetSrcPoint();
if(!lineRct.IsEmpty())
{
lineRct.Union(wxRect((int)pt.x, (int)pt.y, 1, 1));
}
else
lineRct = wxRect((int)pt.x, (int)pt.y, 1, 1);
// include ending point
pt = GetTrgPoint();
if(!lineRct.IsEmpty())
{
lineRct.Union(wxRect((int)pt.x, (int)pt.y, 1, 1));
}
else
lineRct = wxRect((int)pt.x, (int)pt.y, 1, 1);
}
// include unfinished point if the line is under construction
if((m_nMode == modeUNDERCONSTRUCTION) || (m_nMode == modeSRCCHANGE) || (m_nMode == modeTRGCHANGE))
{
if(!lineRct.IsEmpty())
{
lineRct.Union(wxRect(m_nUnfinishedPoint.x, m_nUnfinishedPoint.y, 1, 1));
}
else
lineRct = wxRect(m_nUnfinishedPoint.x, m_nUnfinishedPoint.y, 1, 1);
}
return lineRct;
}
wxRealPoint wxSFLineShape::GetDockPointPosition(int dp)
{
wxXS::RealPointList::compatibility_iterator ptnode;
int ptsCnt = (int)m_lstPoints.GetCount();
if( dp >= 0 )
{
if( ptsCnt > dp )
{
ptnode = m_lstPoints.Item(dp);
if( ptnode )return *ptnode->GetData();
}
else if( ptsCnt > 0 )
{
ptnode = m_lstPoints.Item(ptsCnt/2);
if( ptnode )return *ptnode->GetData();
}
}
else if( dp == -1 ) // start line point
{
return GetSrcPoint();
}
else if( dp == -2 ) // end line point
{
return GetTrgPoint();
}
return GetCenter();
}
bool wxSFLineShape::GetLineSegment(size_t index, wxRealPoint& src, wxRealPoint& trg)
{
if( !m_lstPoints.IsEmpty() )
{
if( index == 0 )
{
src = GetSrcPoint();
trg = *m_lstPoints.GetFirst()->GetData();
return true;
}
else if( index == m_lstPoints.GetCount() )
{
src = *m_lstPoints.GetLast()->GetData();
trg = GetTrgPoint();
return true;
}
else if( (index > 0) && (index < m_lstPoints.GetCount()) )
{
wxXS::RealPointList::compatibility_iterator node = m_lstPoints.Item(index);
src = *node->GetPrevious()->GetData();
trg = *node->GetData();
return true;
}
return false;
}
else
{
if( index == 0 )
{
GetDirectLine( src, trg );
return true;
}
else
return false;
}
}
bool wxSFLineShape::Contains(const wxPoint& pos)
{
if( (m_nMode != modeUNDERCONSTRUCTION) && (this->GetHitLinesegment(pos) >= 0) )return true;
else
return false;
}
void wxSFLineShape::Scale(double x, double y, bool children)
{
wxRealPoint *pt;
wxXS::RealPointList::compatibility_iterator node = m_lstPoints.GetFirst();
while(node)
{
pt = node->GetData();
pt->x *= x;
pt->y *= y;
node = node->GetNext();
}
// call default function implementation (needed for scaling of shape's children)
wxSFShapeBase::Scale(x, y, children);
}
void wxSFLineShape::MoveTo(double x, double y)
{
MoveBy(x - m_nPrevPosition.x, y - m_nPrevPosition.y);
m_nPrevPosition.x = x;
m_nPrevPosition.y = y;
}
void wxSFLineShape::MoveBy(double x, double y)
{
wxRealPoint *pt;
wxXS::RealPointList::compatibility_iterator node = m_lstPoints.GetFirst();
while(node)
{
pt = node->GetData();
pt->x += x;
pt->y += y;
node = node->GetNext();
}
if( m_fStandAlone )
{
m_nSrcPoint = m_nSrcPoint + wxRealPoint(x, y);
m_nTrgPoint = m_nTrgPoint + wxRealPoint(x, y);
}
if( !m_lstChildItems.IsEmpty() ) Update();
}
void wxSFLineShape::CreateHandles()
{
// first clear all previously used handles and then create new ones
m_lstHandles.Clear();
// create control points handles
for(size_t i = 0; i < m_lstPoints.GetCount(); i++) AddHandle(wxSFShapeHandle::hndLINECTRL, (int)i);
// create border handles
AddHandle(wxSFShapeHandle::hndLINESTART);
AddHandle(wxSFShapeHandle::hndLINEEND);
}
void wxSFLineShape::OnHandle(wxSFShapeHandle& handle)
{
switch(handle.GetType())
{
case wxSFShapeHandle::hndLINECTRL:
{
wxXS::RealPointList::compatibility_iterator node = m_lstPoints.Item(handle.GetId());
if(node)
{
wxRealPoint* pt = node->GetData();
pt->x = handle.GetPosition().x;
pt->y = handle.GetPosition().y;
}
}
break;
case wxSFShapeHandle::hndLINEEND:
{
m_nUnfinishedPoint = handle.GetPosition();
if( m_fStandAlone ) m_nTrgPoint = Conv2RealPoint( handle.GetPosition() );
}
break;
case wxSFShapeHandle::hndLINESTART:
{
m_nUnfinishedPoint = handle.GetPosition();
if( m_fStandAlone ) m_nSrcPoint = Conv2RealPoint( handle.GetPosition() );
}
break;
default:
break;
}
wxSFShapeBase::OnHandle( handle );
}
void wxSFLineShape::OnEndHandle(wxSFShapeHandle& handle)
{
// update percentual offset of the line's ending points
wxSFShapeBase *pParent = GetParentCanvas()->GetShapeUnderCursor();
if( pParent )
{
wxRect bbRect = pParent->GetBoundingBox();
switch( handle.GetType() )
{
case wxSFShapeHandle::hndLINESTART:
if( !m_fStandAlone && ( pParent->GetId() == m_nSrcShapeId ) )
{
m_nSrcOffset.x = double(handle.GetPosition().x - bbRect.GetLeft()) / bbRect.GetWidth();
m_nSrcOffset.y = double(handle.GetPosition().y - bbRect.GetTop()) / bbRect.GetHeight();
}
break;
case wxSFShapeHandle::hndLINEEND:
if( !m_fStandAlone && ( pParent->GetId() == m_nTrgShapeId ) )
{
m_nTrgOffset.x = double(handle.GetPosition().x - bbRect.GetLeft()) / bbRect.GetWidth();
m_nTrgOffset.y = double(handle.GetPosition().y - bbRect.GetTop()) / bbRect.GetHeight();
}
break;
default:
break;
}
}
wxSFShapeBase::OnEndHandle(handle);
}
void wxSFLineShape::OnBeginDrag(const wxPoint& pos)
{
m_nPrevPosition = GetAbsolutePosition();
wxSFShapeBase::OnBeginDrag(pos);
}
void wxSFLineShape::OnLeftDoubleClick(const wxPoint& pos)
{
// HINT: override it for custom actions
if(GetParentCanvas())
{
// remove existing handle if exist otherwise create a new one at the
// given position
wxSFShapeHandle *pHandle = GetParentCanvas()->GetTopmostHandleAtPosition(pos);
if(pHandle && (pHandle->GetParentShape() == this))
{
if(pHandle->GetType() == wxSFShapeHandle::hndLINECTRL)
m_lstPoints.DeleteNode(m_lstPoints.Item(pHandle->GetId()));
}
else
{
int nIndex = this->GetHitLinesegment(pos);
if( nIndex > -1 ) m_lstPoints.Insert(nIndex, new wxRealPoint(pos.x, pos.y));
}
CreateHandles();
ShowHandles(true);
}
}
//----------------------------------------------------------------------------------//
// protected virtual functions
//----------------------------------------------------------------------------------//
void wxSFLineShape::DrawNormal(wxDC& dc)
{
dc.SetPen(m_Pen);
DrawCompleteLine(dc);
dc.SetPen(wxNullPen);
}
void wxSFLineShape::DrawHover(wxDC& dc)
{
dc.SetPen(wxPen(m_nHoverColor, 1));
DrawCompleteLine(dc);
dc.SetPen(wxNullPen);
}
void wxSFLineShape::DrawHighlighted(wxDC& dc)
{
dc.SetPen(wxPen(m_nHoverColor, 2));
DrawCompleteLine(dc);
dc.SetPen(wxNullPen);
}
void wxSFLineShape::DrawCompleteLine(wxDC& dc)
{
if(!m_pParentManager)return;
size_t i;
wxRealPoint src, trg;
switch(m_nMode)
{
case modeREADY:
{
// draw basic line parts
for(i = 0; i <= m_lstPoints.GetCount(); i++)
{
GetLineSegment( i, src, trg );
dc.DrawLine(Conv2Point(src), Conv2Point(trg));
}
// draw target arrow
if(m_pTrgArrow)m_pTrgArrow->Draw(src, trg, dc);
// draw source arrow
if(m_pSrcArrow)
{
GetLineSegment( 0, src, trg );
m_pSrcArrow->Draw(trg, src, dc);
}
}
break;
case modeUNDERCONSTRUCTION:
{
// draw basic line parts
for(i = 0; i < m_lstPoints.GetCount(); i++)
{
GetLineSegment( i, src, trg );
dc.DrawLine(Conv2Point(src), Conv2Point(trg));
}
// draw unfinished line segment if any (for interactive line creation)
dc.SetPen( wxPen(*wxBLACK, 1, wxDOT) );
if( i )
{
dc.DrawLine( Conv2Point(trg), m_nUnfinishedPoint );
}
else
{
wxSFShapeBase* pSrcShape = GetShapeManager()->FindShape(m_nSrcShapeId);
if( pSrcShape )
{
if( pSrcShape->GetConnectionPoints().IsEmpty() )
{
dc.DrawLine( Conv2Point(pSrcShape->GetBorderPoint(pSrcShape->GetCenter(), Conv2RealPoint(m_nUnfinishedPoint))), m_nUnfinishedPoint );
}
else
dc.DrawLine( Conv2Point( GetModSrcPoint() ), m_nUnfinishedPoint );
}
}
dc.SetPen(wxNullPen);
}
break;
case modeSRCCHANGE:
{
// draw basic line parts
for(i = 1; i <= m_lstPoints.GetCount(); i++)
{
GetLineSegment( i, src, trg );
dc.DrawLine(Conv2Point(src), Conv2Point(trg));
}
// draw linesegment being updated
GetLineSegment( 0, src, trg );
if( !m_fStandAlone ) dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
dc.DrawLine(m_nUnfinishedPoint, Conv2Point(trg));
dc.SetPen(wxNullPen);
}
break;
case modeTRGCHANGE:
{
// draw basic line parts
if( !m_lstPoints.IsEmpty() )
{
for(i = 0; i < m_lstPoints.GetCount(); i++)
{
GetLineSegment( i, src, trg );
dc.DrawLine(Conv2Point(src), Conv2Point(trg));
}
}
else
trg = GetSrcPoint();
// draw linesegment being updated
if( !m_fStandAlone ) dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
dc.DrawLine( Conv2Point(trg), m_nUnfinishedPoint);
dc.SetPen(wxNullPen);
}
break;
}
}
int wxSFLineShape::GetHitLinesegment(const wxPoint& pos)
{
//if(!GetBoundingBox().Inflate(10, 10).Contains(pos))return -1;
if(!GetBoundingBox().Contains(pos))return -1;
double a, b, c, d;
wxRealPoint ptSrc, ptTrg;
wxRect lsBB;
// Get all polyline segments
for(size_t i = 0; i <= m_lstPoints.GetCount(); i++)
{
GetLineSegment( i, ptSrc, ptTrg );
// calculate line segment bounding box
lsBB = wxRect(Conv2Point(ptSrc), Conv2Point(ptTrg));
lsBB.Inflate(2);
// convert line segment to its parametric form
a = ptTrg.y - ptSrc.y;
b = ptSrc.x - ptTrg.x;
c = -a*ptSrc.x - b*ptSrc.y;
// calculate distance of the line and give point
d = (a*pos.x + b*pos.y + c)/sqrt(a*a + b*b);
if((abs((int)d) <= 5) && lsBB.Contains(pos)) return (int)i;
}
return -1;
}
//----------------------------------------------------------------------------------//
// protected functions
//----------------------------------------------------------------------------------//
wxRealPoint wxSFLineShape::GetModSrcPoint()
{
wxSFShapeBase* pSrcShape = GetShapeManager()->FindShape(m_nSrcShapeId);
if( !pSrcShape )return wxRealPoint();
wxRealPoint nModPoint;
if( m_nSrcOffset != sfdvLINESHAPE_OFFSET )
{
wxRect bbRct = pSrcShape->GetBoundingBox();
nModPoint = pSrcShape->GetAbsolutePosition();
nModPoint.x += (double)bbRct.GetWidth() * m_nSrcOffset.x;
nModPoint.y += (double)bbRct.GetHeight() * m_nSrcOffset.y;
}
else
nModPoint = pSrcShape->GetCenter();
wxSFConnectionPoint *pConnPt = pSrcShape->GetNearestConnectionPoint( nModPoint );
if( pConnPt ) nModPoint = pConnPt->GetConnectionPoint();
return nModPoint;
}
wxRealPoint wxSFLineShape::GetModTrgPoint()
{
wxSFShapeBase* pTrgShape = GetShapeManager()->FindShape(m_nTrgShapeId);
if( !pTrgShape )return wxRealPoint();
wxRealPoint nModPoint;
if( m_nTrgOffset != sfdvLINESHAPE_OFFSET )
{
wxRect bbRct = pTrgShape->GetBoundingBox();
nModPoint = pTrgShape->GetAbsolutePosition();
nModPoint.x += (double)bbRct.GetWidth() * m_nTrgOffset.x;
nModPoint.y += (double)bbRct.GetHeight() * m_nTrgOffset.y;
}
else
nModPoint = pTrgShape->GetCenter();
wxSFConnectionPoint *pConnPt = pTrgShape->GetNearestConnectionPoint( nModPoint );
if( pConnPt ) nModPoint = pConnPt->GetConnectionPoint();
return nModPoint;
}
void wxSFLineShape::SetEndingConnectionPoint(const wxSFConnectionPoint* cp)
{
if( cp && cp->GetParentShape() )
{
wxRealPoint posCp = cp->GetConnectionPoint();
wxRect rctBB = cp->GetParentShape()->GetBoundingBox();
m_nTrgOffset.x = double(posCp.x - rctBB.GetLeft()) / rctBB.GetWidth();
m_nTrgOffset.y = double(posCp.y - rctBB.GetTop()) / rctBB.GetHeight();
}
}
void wxSFLineShape::SetStartingConnectionPoint(const wxSFConnectionPoint* cp)
{
if( cp && cp->GetParentShape() )
{
wxRealPoint posCp = cp->GetConnectionPoint();
wxRect rctBB = cp->GetParentShape()->GetBoundingBox();
m_nSrcOffset.x = double(posCp.x - rctBB.GetLeft()) / rctBB.GetWidth();
m_nSrcOffset.y = double(posCp.y - rctBB.GetTop()) / rctBB.GetHeight();
}
}

View File

@@ -0,0 +1,350 @@
/***************************************************************
* Name: MultiSelRect.cpp
* Purpose: Implements aux. multiselection shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/MultiSelRect.h"
#include "wx/wxsf/ShapeCanvas.h"
#include "wx/wxsf/TextShape.h"
#include <math.h>
wxSFMultiSelRect::wxSFMultiSelRect(void)
{
SetBorder(wxPen(wxColour(100, 100, 100), 1, wxDOT));
SetFill(*wxTRANSPARENT_BRUSH);
}
wxSFMultiSelRect::~wxSFMultiSelRect(void)
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFMultiSelRect::OnBeginHandle(wxSFShapeHandle& handle)
{
// inform all selected shapes about begin of the handle dragging
if(GetParentCanvas())
{
ShapeList lstShapes;
GetParentCanvas()->GetSelectedShapes(lstShapes);
ShapeList::compatibility_iterator node = lstShapes.GetFirst();
while(node)
{
node->GetData()->OnBeginHandle(handle);
node = node->GetNext();
}
}
}
void wxSFMultiSelRect::OnEndHandle(wxSFShapeHandle& handle)
{
// inform all selected shapes about end of the handle dragging
if(GetParentCanvas())
{
ShapeList lstShapes;
GetParentCanvas()->GetSelectedShapes(lstShapes);
ShapeList::compatibility_iterator node = lstShapes.GetFirst();
while(node)
{
node->GetData()->OnEndHandle(handle);
node = node->GetNext();
}
}
}
//----------------------------------------------------------------------------------//
// protected functions
//----------------------------------------------------------------------------------//
bool wxSFMultiSelRect::AnyWidthExceeded(const wxPoint& delta)
{
if(GetParentCanvas())
{
wxSFShapeBase* pShape;
ShapeList m_lstSelection;
GetParentCanvas()->GetSelectedShapes(m_lstSelection);
// first determine whether any shape in the selection exceeds its bounds
ShapeList::compatibility_iterator node = m_lstSelection.GetFirst();
while(node)
{
pShape = node->GetData();
if(!pShape->IsKindOf(CLASSINFO(wxSFLineShape)))
if((pShape->GetBoundingBox().GetWidth() + delta.x) <= 1)return true;
node = node->GetNext();
}
return false;
}
return true;
}
bool wxSFMultiSelRect::AnyHeightExceeded(const wxPoint& delta)
{
if(GetParentCanvas())
{
wxSFShapeBase* pShape;
ShapeList m_lstSelection;
GetParentCanvas()->GetSelectedShapes(m_lstSelection);
// first determine whether any shape in the selection exceeds its bounds
ShapeList::compatibility_iterator node = m_lstSelection.GetFirst();
while(node)
{
pShape = node->GetData();
if(!pShape->IsKindOf(CLASSINFO(wxSFLineShape)))
if((pShape->GetBoundingBox().GetHeight() + delta.y) <= 1)return true;
node = node->GetNext();
}
return false;
}
return true;
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFMultiSelRect::OnRightHandle(wxSFShapeHandle& handle)
{
if(GetParentCanvas() && !AnyWidthExceeded(handle.GetDelta()))
{
wxXS::RealPointList::compatibility_iterator ptnode;
wxSFLineShape* pLine;
wxRealPoint* pt;
double dx, sx = (GetRectSize().x - 2*sfDEFAULT_ME_OFFSET + handle.GetDelta().x)/(GetRectSize().x - 2*sfDEFAULT_ME_OFFSET);
ShapeList m_lstSelection;
GetParentCanvas()->GetSelectedShapes(m_lstSelection);
ShapeList::compatibility_iterator node = m_lstSelection.GetFirst();
while(node)
{
wxSFShapeBase* pShape = node->GetData();
// scale main parent shape
if(!pShape->IsKindOf(CLASSINFO(wxSFLineShape)))
{
dx = (pShape->GetAbsolutePosition().x - (GetAbsolutePosition().x + sfDEFAULT_ME_OFFSET))/(GetRectSize().x - 2*sfDEFAULT_ME_OFFSET)*handle.GetDelta().x;
if(pShape->ContainsStyle(sfsSIZE_CHANGE))pShape->Scale(sx, 1, sfWITHCHILDREN);
if(pShape->ContainsStyle(sfsPOSITION_CHANGE))pShape->MoveBy(dx, 0);
pShape->FitToChildren();
}
else
{
if(pShape->ContainsStyle(sfsPOSITION_CHANGE))
{
pLine = (wxSFLineShape*)pShape;
ptnode = pLine->GetControlPoints().GetFirst();
while(ptnode)
{
pt = ptnode->GetData();
dx = ( pt->x - (GetAbsolutePosition().x + sfDEFAULT_ME_OFFSET))/(GetRectSize().x - 2*sfDEFAULT_ME_OFFSET)*handle.GetDelta().x;
pt->x += dx;
pt->x = floor(pt->x);
ptnode = ptnode->GetNext();
}
}
}
node = node->GetNext();
}
}
}
void wxSFMultiSelRect::OnLeftHandle(wxSFShapeHandle& handle)
{
if(GetParentCanvas() && !AnyWidthExceeded(wxPoint(-handle.GetDelta().x, 0)))
{
wxXS::RealPointList::compatibility_iterator ptnode;
wxSFLineShape* pLine;
wxRealPoint* pt;
double dx, sx = (GetRectSize().x - 2*sfDEFAULT_ME_OFFSET - handle.GetDelta().x)/(GetRectSize().x - 2*sfDEFAULT_ME_OFFSET);
ShapeList m_lstSelection;
GetParentCanvas()->GetSelectedShapes(m_lstSelection);
ShapeList::compatibility_iterator node = m_lstSelection.GetFirst();
while(node)
{
wxSFShapeBase* pShape = node->GetData();
if(!pShape->IsKindOf(CLASSINFO(wxSFLineShape)))
{
if(pShape->ContainsStyle(sfsPOSITION_CHANGE))
{
if(pShape->GetParentShape())
{
pShape->SetRelativePosition(pShape->GetRelativePosition().x*sx, pShape->GetRelativePosition().y);
}
else
{
double dx = handle.GetDelta().x - (pShape->GetAbsolutePosition().x - (GetAbsolutePosition().x + sfDEFAULT_ME_OFFSET))/(GetRectSize().x - 2*sfDEFAULT_ME_OFFSET)*handle.GetDelta().x;
pShape->MoveBy(dx, 0);
}
}
if(pShape->ContainsStyle(sfsSIZE_CHANGE))pShape->Scale(sx, 1, sfWITHCHILDREN);
pShape->FitToChildren();
}
else
{
if(pShape->ContainsStyle(sfsPOSITION_CHANGE))
{
pLine = (wxSFLineShape*)pShape;
ptnode = pLine->GetControlPoints().GetFirst();
while(ptnode)
{
pt = ptnode->GetData();
dx = handle.GetDelta().x - (pt->x - (GetAbsolutePosition().x + sfDEFAULT_ME_OFFSET))/(GetRectSize().x - 2*sfDEFAULT_ME_OFFSET)*handle.GetDelta().x;
pt->x += dx;
pt->x = floor(pt->x);
ptnode = ptnode->GetNext();
}
}
}
node = node->GetNext();
}
}
}
void wxSFMultiSelRect::OnBottomHandle(wxSFShapeHandle& handle)
{
if(GetParentCanvas() && !AnyHeightExceeded(handle.GetDelta()))
{
wxXS::RealPointList::compatibility_iterator ptnode;
wxSFLineShape* pLine;
wxRealPoint* pt;
double dy, sy = (GetRectSize().y - 2*sfDEFAULT_ME_OFFSET + handle.GetDelta().y)/(GetRectSize().y - 2*sfDEFAULT_ME_OFFSET);
ShapeList m_lstSelection;
GetParentCanvas()->GetSelectedShapes(m_lstSelection);
ShapeList::compatibility_iterator node = m_lstSelection.GetFirst();
while(node)
{
wxSFShapeBase* pShape = node->GetData();
if(!pShape->IsKindOf(CLASSINFO(wxSFLineShape)))
{
dy = (pShape->GetAbsolutePosition().y - (GetAbsolutePosition().y + sfDEFAULT_ME_OFFSET))/(GetRectSize().y - 2*sfDEFAULT_ME_OFFSET)*handle.GetDelta().y;
if(pShape->ContainsStyle(sfsSIZE_CHANGE))pShape->Scale(1, sy, sfWITHCHILDREN);
if(pShape->ContainsStyle(sfsPOSITION_CHANGE))pShape->MoveBy(0, dy);
pShape->FitToChildren();
}
else
{
if(pShape->ContainsStyle(sfsPOSITION_CHANGE))
{
pLine = (wxSFLineShape*)pShape;
ptnode = pLine->GetControlPoints().GetFirst();
while(ptnode)
{
pt = ptnode->GetData();
dy = ( pt->y - (GetAbsolutePosition().y + sfDEFAULT_ME_OFFSET))/(GetRectSize().y - 2*sfDEFAULT_ME_OFFSET)*handle.GetDelta().y;
pt->y += dy;
pt->y = floor(pt->y);
ptnode = ptnode->GetNext();
}
}
}
node = node->GetNext();
}
}
}
void wxSFMultiSelRect::OnTopHandle(wxSFShapeHandle& handle)
{
if(GetParentCanvas() && !AnyHeightExceeded(wxPoint(0, -handle.GetDelta().y)))
{
wxXS::RealPointList::compatibility_iterator ptnode;
wxSFLineShape* pLine;
wxRealPoint* pt;
double dy, sy = (GetRectSize().y - 2*sfDEFAULT_ME_OFFSET - handle.GetDelta().y)/(GetRectSize().y - 2*sfDEFAULT_ME_OFFSET);
ShapeList m_lstSelection;
GetParentCanvas()->GetSelectedShapes(m_lstSelection);
ShapeList::compatibility_iterator node = m_lstSelection.GetFirst();
while(node)
{
wxSFShapeBase* pShape = node->GetData();
if(!pShape->IsKindOf(CLASSINFO(wxSFLineShape)))
{
if(pShape->ContainsStyle(sfsPOSITION_CHANGE))
{
if(pShape->GetParentShape())
{
pShape->SetRelativePosition(pShape->GetRelativePosition().x, pShape->GetRelativePosition().y*sy);
}
else
{
double dy = handle.GetDelta().y - (pShape->GetAbsolutePosition().y - (GetAbsolutePosition().y + sfDEFAULT_ME_OFFSET))/(GetRectSize().y - 2*sfDEFAULT_ME_OFFSET)*handle.GetDelta().y;
pShape->MoveBy(0, dy);
}
}
if(pShape->ContainsStyle(sfsSIZE_CHANGE))pShape->Scale(1, sy, sfWITHCHILDREN);
pShape->FitToChildren();
}
else
{
if(pShape->ContainsStyle(sfsPOSITION_CHANGE))
{
pLine = (wxSFLineShape*)pShape;
ptnode = pLine->GetControlPoints().GetFirst();
while(ptnode)
{
pt = ptnode->GetData();
dy = handle.GetDelta().y - (pt->y - (GetAbsolutePosition().y + sfDEFAULT_ME_OFFSET))/(GetRectSize().y - 2*sfDEFAULT_ME_OFFSET)*handle.GetDelta().y;
pt->y += dy;
pt->y = floor(pt->y);
ptnode = ptnode->GetNext();
}
}
}
node = node->GetNext();
}
}
}
void wxSFMultiSelRect::OnHandle(wxSFShapeHandle& handle)
{
wxSFRectShape::OnHandle( handle );
GetParentCanvas()->InvalidateVisibleRect();
}

View File

@@ -0,0 +1,69 @@
/***************************************************************
* Name: OpenArrow.cpp
* Purpose: Implements open arrow for line shapes
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/OpenArrow.h"
#include "wx/wxsf/CommonFcn.h"
// arrow shape
static const wxRealPoint arrow[3]={wxRealPoint(0,0), wxRealPoint(10,4), wxRealPoint(10,-4)};
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFOpenArrow, wxSFArrowBase);
wxSFOpenArrow::wxSFOpenArrow(void)
: wxSFArrowBase()
{
m_Pen = sfdvARROW_BORDER;
XS_SERIALIZE_EX(m_Pen, wxT("arrow_style"), sfdvARROW_BORDER);
}
wxSFOpenArrow::wxSFOpenArrow(wxSFShapeBase* parent)
: wxSFArrowBase(parent)
{
m_Pen = sfdvARROW_BORDER;
XS_SERIALIZE_EX(m_Pen, wxT("arrow_style"), sfdvARROW_BORDER);
}
wxSFOpenArrow::wxSFOpenArrow(const wxSFOpenArrow& obj)
: wxSFArrowBase(obj)
{
m_Pen = obj.m_Pen;
XS_SERIALIZE_EX(m_Pen, wxT("arrow_style"), sfdvARROW_BORDER);
}
wxSFOpenArrow::~wxSFOpenArrow(void)
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFOpenArrow::Draw(const wxRealPoint &from, const wxRealPoint &to, wxDC& dc)
{
wxPoint rarrow[3];
TranslateArrow( rarrow, arrow, 3, from, to );
dc.SetPen( m_Pen );
dc.DrawLine(rarrow[0], rarrow[1]);
dc.DrawLine(rarrow[0], rarrow[2]);
dc.SetPen( wxNullPen );
}

View File

@@ -0,0 +1,295 @@
/***************************************************************
* Name: OrthoShape.cpp
* Purpose: Implements orthogonal line shape class
* Author: Michal Bližňák (michal.bliznak@gmail.com)
* Created: 2009-04-26
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include <math.h>
#include "wx/wxsf/OrthoShape.h"
#include "wx/wxsf/ShapeCanvas.h"
#include "wx/wxsf/CommonFcn.h"
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFOrthoLineShape, wxSFLineShape);
wxSFOrthoLineShape::wxSFOrthoLineShape() : wxSFLineShape()
{
}
wxSFOrthoLineShape::wxSFOrthoLineShape(long src, long trg, const wxXS::RealPointList& path, wxSFDiagramManager* manager)
: wxSFLineShape(src, trg, path, manager)
{
}
wxSFOrthoLineShape::wxSFOrthoLineShape(const wxSFOrthoLineShape& obj)
: wxSFLineShape(obj)
{
}
wxSFOrthoLineShape::~wxSFOrthoLineShape()
{
}
//----------------------------------------------------------------------------------//
// protected virtual functions
//----------------------------------------------------------------------------------//
void wxSFOrthoLineShape::DrawCompleteLine(wxDC& dc)
{
if(!m_pParentManager)return;
size_t i;
wxRealPoint src, trg;
switch(m_nMode)
{
case modeREADY:
{
// draw basic line parts
for(i = 0; i <= m_lstPoints.GetCount(); i++)
{
GetLineSegment( i, src, trg );
this->DrawLineSegment( dc, src, trg );
}
// draw target arrow
if(m_pTrgArrow)
{
wxRealPoint asrc, atrg;
GetLastSubsegment( src, trg, asrc, atrg );
m_pTrgArrow->Draw( asrc, atrg, dc );
}
// draw source arrow
if(m_pSrcArrow)
{
wxRealPoint asrc, atrg;
GetLineSegment( 0, src, trg );
GetFirstSubsegment( src, trg, asrc, atrg );
m_pSrcArrow->Draw( atrg, asrc, dc );
}
}
break;
case modeUNDERCONSTRUCTION:
{
// draw basic line parts
for(i = 0; i < m_lstPoints.GetCount(); i++)
{
GetLineSegment( i, src, trg );
this->DrawLineSegment( dc, src, trg );
}
// draw unfinished line segment if any (for interactive line creation)
dc.SetPen( wxPen(*wxBLACK, 1, wxDOT) );
if( i )
{
this->DrawLineSegment( dc, trg, Conv2RealPoint(m_nUnfinishedPoint) );
}
else
{
wxSFShapeBase* pSrcShape = GetShapeManager()->FindShape(m_nSrcShapeId);
if( pSrcShape )
{
if( pSrcShape->GetConnectionPoints().IsEmpty() )
{
this->DrawLineSegment( dc, pSrcShape->GetBorderPoint(pSrcShape->GetCenter(), Conv2RealPoint(m_nUnfinishedPoint)), Conv2RealPoint(m_nUnfinishedPoint) );
}
else
this->DrawLineSegment( dc, GetModSrcPoint(), Conv2RealPoint(m_nUnfinishedPoint) );
}
}
dc.SetPen(wxNullPen);
}
break;
case modeSRCCHANGE:
{
// draw basic line parts
for(i = 1; i <= m_lstPoints.GetCount(); i++)
{
GetLineSegment( i, src, trg );
this->DrawLineSegment( dc, src, trg );
}
// draw linesegment being updated
GetLineSegment( 0, src, trg );
dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
this->DrawLineSegment( dc, Conv2RealPoint(m_nUnfinishedPoint), trg );
dc.SetPen(wxNullPen);
}
break;
case modeTRGCHANGE:
{
// draw basic line parts
if( !m_lstPoints.IsEmpty() )
{
for(i = 0; i < m_lstPoints.GetCount(); i++)
{
GetLineSegment( i, src, trg );
this->DrawLineSegment( dc, src, trg );
}
}
else
trg = GetSrcPoint();
// draw linesegment being updated
dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
this->DrawLineSegment( dc, trg, Conv2RealPoint(m_nUnfinishedPoint) );
dc.SetPen(wxNullPen);
}
break;
}
}
int wxSFOrthoLineShape::GetHitLinesegment(const wxPoint& pos)
{
if( !GetBoundingBox().Inflate(5, 5).Contains(pos) )return -1;
wxRealPoint ptSrc, ptTrg, ptSSrc, ptSTrg;
wxRect rctBB;
// Get all polyline segments
for(size_t i = 0; i <= m_lstPoints.GetCount(); i++)
{
GetLineSegment( i, ptSrc, ptTrg );
// test first subsegment
GetFirstSubsegment( ptSrc, ptTrg, ptSSrc, ptSTrg );
rctBB = wxRect(Conv2Point(ptSSrc), Conv2Point(ptSTrg));
rctBB.Inflate(5);
if( rctBB.Contains(pos) ) return (int)i;
// test middle subsegment
GetMiddleSubsegment( ptSrc, ptTrg, ptSSrc, ptSTrg );
rctBB = wxRect(Conv2Point(ptSSrc), Conv2Point(ptSTrg));
rctBB.Inflate(5);
if( rctBB.Contains(pos) ) return (int)i;
// test last subsegment
GetLastSubsegment( ptSrc, ptTrg, ptSSrc, ptSTrg );
rctBB = wxRect(Conv2Point(ptSSrc), Conv2Point(ptSTrg));
rctBB.Inflate(5);
if( rctBB.Contains(pos) ) return (int)i;
}
return -1;
}
//----------------------------------------------------------------------------------//
// protected functions
//----------------------------------------------------------------------------------//
void wxSFOrthoLineShape::DrawLineSegment(wxDC& dc, const wxRealPoint& src, const wxRealPoint& trg)
{
double nDirection;
if( (trg.x == src.x) || ( trg.y == src.y ) )
{
dc.DrawLine( src.x, src.y, trg.x, trg.y );
return;
}
else
nDirection = fabs( trg.y - src.y ) / fabs( trg.x - src.x );
wxRealPoint ptCenter( (src.x + trg.x)/2, (src.y + trg.y)/2 );
if( nDirection < 1 )
{
dc.DrawLine( src.x, src.y, ptCenter.x, src.y );
dc.DrawLine( ptCenter.x, src.y, ptCenter.x, trg.y );
dc.DrawLine( ptCenter.x, trg.y, trg.x, trg.y );
}
else
{
dc.DrawLine( src.x, src.y, src.x, ptCenter.y );
dc.DrawLine( src.x, ptCenter.y, trg.x, ptCenter.y );
dc.DrawLine( trg.x, ptCenter.y, trg.x, trg.y );
}
}
void wxSFOrthoLineShape::GetFirstSubsegment(const wxRealPoint& src, const wxRealPoint& trg, wxRealPoint& subsrc, wxRealPoint& subtrg)
{
double nDirection = 0;
if( trg.x == src.x ) nDirection = 1;
else nDirection = fabs( trg.y - src.y ) / fabs( trg.x - src.x );
wxRealPoint ptCenter( (src.x + trg.x)/2, (src.y + trg.y)/2 );
if( nDirection < 1 )
{
subsrc = src;
subtrg = wxRealPoint( ptCenter.x, src.y );
}
else
{
subsrc = src;
subtrg = wxRealPoint( src.x, ptCenter.y );
}
}
void wxSFOrthoLineShape::GetLastSubsegment(const wxRealPoint& src, const wxRealPoint& trg, wxRealPoint& subsrc, wxRealPoint& subtrg)
{
double nDirection = 0;
if( trg.x == src.x ) nDirection = 1;
else nDirection = fabs( trg.y - src.y ) / fabs( trg.x - src.x );
wxRealPoint ptCenter( (src.x + trg.x)/2, (src.y + trg.y)/2 );
if( nDirection < 1 )
{
subsrc = wxRealPoint( ptCenter.x, trg.y );
subtrg = trg;
}
else
{
subsrc = wxRealPoint( trg.x, ptCenter.y );
subtrg = trg;
}
}
void wxSFOrthoLineShape::GetMiddleSubsegment(const wxRealPoint& src, const wxRealPoint& trg, wxRealPoint& subsrc, wxRealPoint& subtrg)
{
double nDirection = 0;
if( trg.x == src.x ) nDirection = 1;
else nDirection = fabs( trg.y - src.y ) / fabs( trg.x - src.x );
wxRealPoint ptCenter( (src.x + trg.x)/2, (src.y + trg.y)/2 );
if( nDirection < 1 )
{
subsrc = wxRealPoint( ptCenter.x, src.y);
subtrg = wxRealPoint( ptCenter.x, trg.y );
}
else
{
subsrc = wxRealPoint( src.x, ptCenter.y );
subtrg = wxRealPoint( trg.x, ptCenter.y );
}
}

View File

@@ -0,0 +1,322 @@
/***************************************************************
* Name: PolygonShape.cpp
* Purpose: Implements polygonial shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/PolygonShape.h"
#include "wx/wxsf/CommonFcn.h"
#include "wx/wxsf/ShapeCanvas.h"
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFPolygonShape, wxSFRectShape);
wxSFPolygonShape::wxSFPolygonShape(void)
: wxSFRectShape()
{
m_fConnectToVertex = sfdvPOLYGONSHAPE_VERTEXCONNECTIONS;
MarkSerializableDataMembers();
}
wxSFPolygonShape::wxSFPolygonShape(int n, const wxRealPoint pts[], const wxRealPoint& pos, wxSFDiagramManager* manager)
: wxSFRectShape(pos, wxRealPoint(1, 1), manager)
{
m_fConnectToVertex = sfdvPOLYGONSHAPE_VERTEXCONNECTIONS;
MarkSerializableDataMembers();
SetVertices(n, pts);
}
wxSFPolygonShape::wxSFPolygonShape(const wxSFPolygonShape& obj)
: wxSFRectShape(obj)
{
m_fConnectToVertex = obj.m_fConnectToVertex;
MarkSerializableDataMembers();
m_arrVertices.Clear();
for(size_t i = 0; i < obj.m_arrVertices.Count(); i++)m_arrVertices.Add(obj.m_arrVertices[i]);
}
wxSFPolygonShape::~wxSFPolygonShape(void)
{
}
void wxSFPolygonShape::MarkSerializableDataMembers()
{
XS_SERIALIZE_EX(m_fConnectToVertex, wxT("connect_to_vertex"), sfdvPOLYGONSHAPE_VERTEXCONNECTIONS);
XS_SERIALIZE(m_arrVertices, wxT("vertices"));
}
//----------------------------------------------------------------------------------//
// public functions
//----------------------------------------------------------------------------------//
void wxSFPolygonShape::SetVertices(size_t n, const wxRealPoint pts[])
{
m_arrVertices.Clear();
for(size_t i = 0; i < n; i++)m_arrVertices.Add(pts[i]);
NormalizeVertices();
FitBoundingBoxToVertices();
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
wxRealPoint wxSFPolygonShape::GetBorderPoint(const wxRealPoint& start, const wxRealPoint& end)
{
// HINT: override it for custom actions ...
bool fSuccess = false;
double tmpMinDist = 0, minDist = 0;
wxRealPoint tmpIntersection, intersection;
size_t ptsCnt = m_arrVertices.Count();
wxRealPoint *pts = new wxRealPoint[ptsCnt];
GetTranslatedVerices(pts);
intersection = start; //GetCenter();
if(ptsCnt == 0)return GetCenter();
if(m_fConnectToVertex)
{
minDist = Distance(pts[0], end);
intersection = pts[0];
for(size_t i = 1; i < ptsCnt; i++)
{
tmpMinDist = Distance(pts[i], end);
if(tmpMinDist < minDist)
{
minDist = tmpMinDist;
intersection = pts[i];
}
}
delete [] pts;
return intersection;
}
else
{
for(size_t i = 0; i < ptsCnt; i++)
{
if(LinesIntersection(pts[i], pts[(i+1) % ptsCnt], start, end, tmpIntersection))
{
if(!fSuccess)
{
minDist = Distance(intersection, end);
intersection = tmpIntersection;
}
else
{
tmpMinDist = Distance(intersection, end);
if(tmpMinDist < minDist)
{
minDist = tmpMinDist;
intersection = tmpIntersection;
}
}
fSuccess = true;
}
}
delete [] pts;
if(fSuccess)
{
return intersection;
}
else
{
return GetCenter();
}
}
}
void wxSFPolygonShape::FitToChildren()
{
wxSFRectShape::FitToChildren();
FitVerticesToBoundingBox();
}
void wxSFPolygonShape::Scale(double x, double y, bool children)
{
m_nRectSize.x *= x;
m_nRectSize.y *= y;
FitVerticesToBoundingBox();
// call default function implementation (needed for scaling of shape's children)
wxSFShapeBase::Scale(x, y, children);
}
void wxSFPolygonShape::OnHandle(wxSFShapeHandle& handle)
{
wxSFRectShape::OnHandle(handle);
FitVerticesToBoundingBox();
}
//----------------------------------------------------------------------------------//
// protected functions
//----------------------------------------------------------------------------------//
void wxSFPolygonShape::GetExtents(double *minx, double *miny, double *maxx, double *maxy)
{
if(m_arrVertices.Count() == 0)return;
*minx = *maxx = m_arrVertices[0].x;
*miny = *maxy = m_arrVertices[0].y;
for(size_t i = 1; i < m_arrVertices.Count(); i++)
{
if(m_arrVertices[i].x < *minx)*minx = m_arrVertices[i].x;
if(m_arrVertices[i].x > *maxx)*maxx = m_arrVertices[i].x;
if(m_arrVertices[i].y < *miny)*miny = m_arrVertices[i].y;
if(m_arrVertices[i].y > *maxy)*maxy = m_arrVertices[i].y;
}
}
void wxSFPolygonShape::GetTranslatedVerices(wxRealPoint pts[])
{
wxRealPoint absPos = GetAbsolutePosition();
for(size_t i = 0; i < m_arrVertices.Count(); i++)pts[i] = absPos + m_arrVertices[i];
}
void wxSFPolygonShape::GetTranslatedVerices(wxPoint pts[])
{
wxPoint absPos = Conv2Point(GetAbsolutePosition());
for(size_t i = 0; i < m_arrVertices.Count(); i++)pts[i] = absPos + Conv2Point(m_arrVertices[i]);
}
void wxSFPolygonShape::NormalizeVertices()
{
// move all vertices so the polygon's relative bounding box will be located in the origin
double minx = 0, miny = 0, maxx = 0, maxy = 0, dx = 0, dy = 0;
GetExtents(&minx, &miny, &maxx, &maxy);
dx = minx*(-1);
dy = miny*(-1);
for(size_t i = 0; i < m_arrVertices.Count(); i++)
{
m_arrVertices[i].x += dx;
m_arrVertices[i].y += dy;
}
}
void wxSFPolygonShape::FitVerticesToBoundingBox()
{
double minx = 0, miny = 0, maxx = 0, maxy = 0, sx = 1, sy = 1;
GetExtents(&minx, &miny, &maxx, &maxy);
sx = m_nRectSize.x/(maxx - minx);
sy = m_nRectSize.y/(maxy - miny);
for(size_t i = 0; i < m_arrVertices.Count(); i++)
{
m_arrVertices[i].x *= sx;
m_arrVertices[i].y *= sy;
}
}
void wxSFPolygonShape::FitBoundingBoxToVertices()
{
double minx = 0, miny = 0, maxx = 0, maxy = 0;
GetExtents(&minx, &miny, &maxx, &maxy);
m_nRectSize.x = maxx - minx;
m_nRectSize.y = maxy - miny;
}
void wxSFPolygonShape::DrawPolygonShape(wxDC& dc)
{
size_t vcount = m_arrVertices.Count();
wxPoint *pts = new wxPoint[vcount];
GetTranslatedVerices(pts);
dc.DrawPolygon(vcount, pts);
delete [] pts;
}
//----------------------------------------------------------------------------------//
// protected virtual functions
//----------------------------------------------------------------------------------//
void wxSFPolygonShape::DrawNormal(wxDC& dc)
{
// HINT: overload it for custom actions...
dc.SetPen(m_Border);
dc.SetBrush(m_Fill);
DrawPolygonShape(dc);
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFPolygonShape::DrawHover(wxDC& dc)
{
// HINT: overload it for custom actions...
dc.SetPen(wxPen(m_nHoverColor, 1));
dc.SetBrush(m_Fill);
DrawPolygonShape(dc);
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFPolygonShape::DrawHighlighted(wxDC& dc)
{
// HINT: overload it for custom actions...
dc.SetPen(wxPen(m_nHoverColor, 2));
dc.SetBrush(m_Fill);
DrawPolygonShape(dc);
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFPolygonShape::DrawShadow(wxDC& dc)
{
// HINT: overload it for custom actions...
if( m_Fill.GetStyle() != wxTRANSPARENT )
{
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(GetParentCanvas()->GetShadowFill());
wxRealPoint nOffset = GetParentCanvas()->GetShadowOffset();
MoveBy(nOffset);
DrawPolygonShape(dc);
MoveBy(-nOffset.x, -nOffset.y);
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
}

View File

@@ -0,0 +1,44 @@
/***************************************************************
* Name: PolygonShapeXml.cpp
* Purpose: Implements polygonial shape's serialization cap.
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/PolygonShape.h"
#include "wx/wxsf/CommonFcn.h"
//----------------------------------------------------------------------------------//
// Serialization
//----------------------------------------------------------------------------------//
wxXmlNode* wxSFPolygonShape::Serialize(wxXmlNode* node)
{
// HINT: overload it for custom actions...
if(node)
{
node = wxSFRectShape::Serialize(node);
}
return node;
}
void wxSFPolygonShape::Deserialize(wxXmlNode* node)
{
// HINT: overload it for custom actions...
wxSFRectShape::Deserialize(node);
NormalizeVertices();
FitVerticesToBoundingBox();
}

View File

@@ -0,0 +1,195 @@
/***************************************************************
* Name: Printout.cpp
* Purpose: Implements printout class for shape canvas
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2008-05-06
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/Printout.h"
#include "wx/wxsf/ScaledDC.h"
#include "wx/wxsf/ShapeCanvas.h"
wxSFPrintout::wxSFPrintout(const wxString& title, wxSFShapeCanvas *canvas)
: wxPrintout(title)
{
m_pCanvas = canvas;
}
wxSFPrintout::~wxSFPrintout()
{
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
bool wxSFPrintout::HasPage(int page)
{
return (page == 1);
}
bool wxSFPrintout::OnBeginDocument(int startPage, int endPage)
{
// HINT: perform custom actions...
return wxPrintout::OnBeginDocument(startPage, endPage);
}
void wxSFPrintout::OnEndDocument()
{
// HINT: perform custom actions ...
wxPrintout::OnEndDocument();
}
bool wxSFPrintout::OnPrintPage(int page)
{
wxUnusedVar( page );
wxASSERT_MSG(m_pCanvas, wxT("Shape canvas must be set in the wxSFPrintout class instance."));
wxDC *dc = GetDC();
if (dc && m_pCanvas)
{
// get grawing size
wxRect fitRect, totalBB = m_pCanvas->GetTotalBoundingBox();
wxCoord maxX = totalBB.GetRight();
wxCoord maxY = totalBB.GetBottom();
// set printing mode
switch( m_pCanvas->GetPrintMode() )
{
case wxSFShapeCanvas::prnFIT_TO_PAGE:
FitThisSizeToPage(wxSize(maxX, maxY));
fitRect = GetLogicalPageRect();
break;
case wxSFShapeCanvas::prnFIT_TO_PAPER:
FitThisSizeToPaper(wxSize(maxX, maxY));
fitRect = GetLogicalPaperRect();
break;
case wxSFShapeCanvas::prnFIT_TO_MARGINS:
FitThisSizeToPageMargins(wxSize(maxX, maxY), *g_pageSetupData);
fitRect = GetLogicalPageMarginsRect(*g_pageSetupData);
break;
case wxSFShapeCanvas::prnMAP_TO_PAGE:
MapScreenSizeToPage();
fitRect = GetLogicalPageRect();
break;
case wxSFShapeCanvas::prnMAP_TO_PAPER:
MapScreenSizeToPaper();
fitRect = GetLogicalPaperRect();
break;
case wxSFShapeCanvas::prnMAP_TO_MARGINS:
MapScreenSizeToPage();
fitRect = GetLogicalPageMarginsRect(*g_pageSetupData);
break;
case wxSFShapeCanvas::prnMAP_TO_DEVICE:
MapScreenSizeToDevice();
fitRect = GetLogicalPageRect();
break;
}
// This offsets the image so that it is centered within the reference
// rectangle defined above.
wxCoord xoff = ((fitRect.width - maxX - totalBB.GetLeft()) / 2) - fitRect.x;
wxCoord yoff = ((fitRect.height - maxY - totalBB.GetTop()) / 2) - fitRect.y;
switch( m_pCanvas->GetPrintHAlign() )
{
case wxSFShapeCanvas::halignLEFT:
xoff = 0;
break;
case wxSFShapeCanvas::halignRIGHT:
xoff = fitRect.width - totalBB.GetWidth();
break;
default:
break;
}
switch( m_pCanvas->GetPrintVAlign() )
{
case wxSFShapeCanvas::valignTOP:
yoff = 0;
break;
case wxSFShapeCanvas::valignBOTTOM:
yoff = fitRect.height - totalBB.GetHeight();
break;
default:
break;
}
OffsetLogicalOrigin(xoff, yoff);
// store current canvas properties
double prevScale = m_pCanvas->GetScale();
long prevStyle = m_pCanvas->GetStyle();
wxColour prevColour = m_pCanvas->GetCanvasColour();
// disable canvas background drawing if required
if( !m_pCanvas->ContainsStyle( wxSFShapeCanvas::sfsPRINT_BACKGROUND ) )
{
m_pCanvas->RemoveStyle( wxSFShapeCanvas::sfsGRADIENT_BACKGROUND );
m_pCanvas->RemoveStyle( wxSFShapeCanvas::sfsGRID_SHOW );
m_pCanvas->SetCanvasColour( *wxWHITE);
}
// draw the canvas content without any scale (dc is scaled by the printing framework)
#if wxVERSION_NUMBER < 2900
double nScale = 1;
if( wxSFShapeCanvas::IsGCEnabled() ) dc->GetUserScale( &nScale, &nScale );
m_pCanvas->SetScale(1);
#ifdef __WXMSW__
wxSFScaledDC sdc( (wxWindowDC*)dc, nScale );
sdc.PrepareGC();
m_pCanvas->DrawContent(sdc, sfNOT_FROM_PAINT);
#else
m_pCanvas->DrawContent(*dc, sfNOT_FROM_PAINT);
#endif
m_pCanvas->SetScale(prevScale);
#else
m_pCanvas->SetScale(1);
m_pCanvas->DrawContent(*dc, sfNOT_FROM_PAINT);
m_pCanvas->SetScale(prevScale);
#endif
// restore previous canvas properties if needed
if( !m_pCanvas->ContainsStyle( wxSFShapeCanvas::sfsPRINT_BACKGROUND ) )
{
m_pCanvas->SetStyle( prevStyle );
m_pCanvas->SetCanvasColour( prevColour );
}
return true;
}
else
return false;
}
void wxSFPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
{
*minPage = 1;
*maxPage = 1;
*selPageFrom = 1;
*selPageTo = 1;
}

View File

@@ -0,0 +1,365 @@
/***************************************************************
* Name: RectShape.cpp
* Purpose: Implements rectangular shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/RectShape.h"
#include "wx/wxsf/ShapeCanvas.h"
#include "wx/wxsf/CommonFcn.h"
// TODO: wxSFShapeBase: Implement LockAspectRation() function
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFRectShape, wxSFShapeBase);
wxSFRectShape::wxSFRectShape(void) : wxSFShapeBase()
{
m_nRectSize = sfdvRECTSHAPE_SIZE;
m_Border = sfdvRECTSHAPE_BORDER;
m_Fill = sfdvRECTSHAPE_FILL;
MarkSerializableDataMembers();
}
wxSFRectShape::wxSFRectShape(const wxRealPoint& pos, const wxRealPoint& size, wxSFDiagramManager* manager)
: wxSFShapeBase(pos, manager)
{
m_nRectSize = size;
m_Border = sfdvRECTSHAPE_BORDER;
m_Fill = sfdvRECTSHAPE_FILL;
MarkSerializableDataMembers();
}
wxSFRectShape::wxSFRectShape(const wxSFRectShape& obj) : wxSFShapeBase(obj)
{
m_nRectSize = obj.m_nRectSize;
m_Border = obj.m_Border;
m_Fill = obj.m_Fill;
MarkSerializableDataMembers();
}
wxSFRectShape::~wxSFRectShape(void)
{
}
void wxSFRectShape::MarkSerializableDataMembers()
{
XS_SERIALIZE_EX(m_nRectSize, wxT("size"), sfdvRECTSHAPE_SIZE);
XS_SERIALIZE_EX(m_Border, wxT("border"), sfdvRECTSHAPE_BORDER);
XS_SERIALIZE_EX(m_Fill, wxT("fill"), sfdvRECTSHAPE_FILL);
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
wxRect wxSFRectShape::GetBoundingBox()
{
wxRealPoint apos = this->GetAbsolutePosition();
return wxRect(wxPoint((int)apos.x, (int)apos.y), wxSize((int)m_nRectSize.x, (int)m_nRectSize.y ));
}
void wxSFRectShape::Scale(double x, double y, bool children)
{
// HINT: overload it for custom actions...
if((x > 0) && (y > 0))
{
SetRectSize(m_nRectSize.x * x, m_nRectSize.y * y);
// call default function implementation (needed for scaling of shape's children)
wxSFShapeBase::Scale(x, y, children);
}
}
void wxSFRectShape::FitToChildren()
{
// HINT: overload it for custom actions...
wxSFShapeBase* pChild;
// get bounding box of the shape and children set be inside it
wxRect chBB = this->GetBoundingBox();
wxRect shpBB = chBB;
SerializableList::compatibility_iterator node = GetFirstChildNode();
while(node)
{
pChild = (wxSFShapeBase*)node->GetData();
if( pChild->ContainsStyle(sfsALWAYS_INSIDE) )
{
pChild->GetCompleteBoundingBox(chBB, bbSELF | bbCHILDREN);
}
node = node->GetNext();
}
if(!chBB.IsEmpty())
{
//wxRect shpBB = this->GetBoundingBox();
if(!shpBB.Contains(chBB))
{
double dx = chBB.GetLeft() - shpBB.GetLeft();
double dy = chBB.GetTop() - shpBB.GetTop();
// resize parent shape
shpBB.Union(chBB);
MoveTo(shpBB.GetPosition().x, shpBB.GetPosition().y);
m_nRectSize = wxRealPoint(shpBB.GetSize().x, shpBB.GetSize().y);
// move its "1st level" children if neccessary
if((dx < 0) || (dy < 0))
{
node = GetFirstChildNode();
while(node)
{
pChild = (wxSFShapeBase*)node->GetData();
if(dx < 0)pChild->MoveBy(abs((int)dx), 0);
if(dy < 0)pChild->MoveBy(0, abs((int)dy));
node = node->GetNext();
}
}
}
}
}
//----------------------------------------------------------------------------------//
// protected virtual functions
//----------------------------------------------------------------------------------//
void wxSFRectShape::DrawNormal(wxDC& dc)
{
// HINT: overload it for custom actions...
dc.SetPen(m_Border);
dc.SetBrush(m_Fill);
dc.DrawRectangle(Conv2Point(GetAbsolutePosition()), Conv2Size(m_nRectSize));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFRectShape::DrawHover(wxDC& dc)
{
// HINT: overload it for custom actions...
dc.SetPen(wxPen(m_nHoverColor, 1));
dc.SetBrush(m_Fill);
dc.DrawRectangle(Conv2Point(GetAbsolutePosition()), Conv2Size(m_nRectSize));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFRectShape::DrawHighlighted(wxDC& dc)
{
// HINT: overload it for custom actions...
dc.SetPen(wxPen(m_nHoverColor, 2));
dc.SetBrush(m_Fill);
dc.DrawRectangle(Conv2Point(GetAbsolutePosition()), Conv2Size(m_nRectSize));
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFRectShape::DrawShadow(wxDC& dc)
{
// HINT: overload it for custom actions...
if( m_Fill.GetStyle() != wxTRANSPARENT )
{
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(GetParentCanvas()->GetShadowFill());
dc.DrawRectangle(Conv2Point(GetAbsolutePosition() + GetParentCanvas()->GetShadowOffset()), Conv2Size(m_nRectSize));
dc.SetBrush(m_Fill);
dc.SetPen(wxNullPen);
}
}
void wxSFRectShape::OnRightHandle(wxSFShapeHandle& handle)
{
// HINT: overload it for custom actions...
//m_nRectSize.x = handle.GetPosition().x - GetAbsolutePosition().x;
m_nRectSize.x += handle.GetDelta().x;
}
void wxSFRectShape::OnLeftHandle(wxSFShapeHandle& handle)
{
// HINT: overload it for custom actions...
wxSFShapeBase *pChild;
//double dx = (double)handle.GetPosition().x - GetAbsolutePosition().x;
double dx = (double)handle.GetDelta().x;
// update position of children
if( !ContainsStyle(sfsLOCK_CHILDREN) )
{
SerializableList::compatibility_iterator node = GetFirstChildNode();
while(node)
{
pChild = (wxSFShapeBase*)node->GetData();
if( pChild->GetHAlign() == halignNONE )
{
pChild->MoveBy(-dx, 0);
}
node = node->GetNext();
}
}
// update position and size of the shape
m_nRectSize.x -= dx;
m_nRelativePosition.x += dx;
}
void wxSFRectShape::OnTopHandle(wxSFShapeHandle& handle)
{
// HINT: overload it for custom actions...
wxSFShapeBase *pChild;
//double dy = (double)handle.GetPosition().y - GetAbsolutePosition().y;
double dy = (double)handle.GetDelta().y;
// update position of children
if( !ContainsStyle( sfsLOCK_CHILDREN ) )
{
SerializableList::compatibility_iterator node = GetFirstChildNode();
while(node)
{
pChild = (wxSFShapeBase*)node->GetData();
if( pChild->GetVAlign() == valignNONE )
{
pChild->MoveBy(0, -dy);
}
node = node->GetNext();
}
}
// update position and size of the shape
m_nRectSize.y -= dy;
m_nRelativePosition.y += dy;
}
void wxSFRectShape::OnBottomHandle(wxSFShapeHandle& handle)
{
// HINT: overload it for custom actions...
//m_nRectSize.y = handle.GetPosition().y - GetAbsolutePosition().y;
m_nRectSize.y += handle.GetDelta().y;
}
wxRealPoint wxSFRectShape::GetBorderPoint(const wxRealPoint& start, const wxRealPoint& end)
{
// HINT: override it for custom actions ...
// the function calculates intesection of line leading from the shape center to
// given point with the shape's bounding box;
wxRealPoint intersection;
wxRect bbRct = this->GetBoundingBox();
if(LinesIntersection(wxRealPoint(bbRct.GetTopLeft().x, bbRct.GetTopLeft().y),
wxRealPoint(bbRct.GetTopRight().x + 1, bbRct.GetTopRight().y), start, end, intersection)) return intersection;
if(LinesIntersection(wxRealPoint(bbRct.GetTopRight().x + 1, bbRct.GetTopRight().y),
wxRealPoint(bbRct.GetBottomRight().x + 1, bbRct.GetBottomRight().y + 1), start, end, intersection)) return intersection;
if(LinesIntersection(wxRealPoint(bbRct.GetBottomRight().x + 1, bbRct.GetBottomRight().y + 1),
wxRealPoint(bbRct.GetBottomLeft().x, bbRct.GetBottomLeft().y + 1), start, end, intersection)) return intersection;
if(LinesIntersection(wxRealPoint(bbRct.GetBottomLeft().x, bbRct.GetBottomLeft().y + 1),
wxRealPoint(bbRct.GetTopLeft().x, bbRct.GetTopLeft().y), start, end, intersection)) return intersection;
return GetCenter();
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFRectShape::CreateHandles()
{
// HINT: overload it for custom actions...
AddHandle(wxSFShapeHandle::hndLEFTTOP);
AddHandle(wxSFShapeHandle::hndTOP);
AddHandle(wxSFShapeHandle::hndRIGHTTOP);
AddHandle(wxSFShapeHandle::hndRIGHT);
AddHandle(wxSFShapeHandle::hndRIGHTBOTTOM);
AddHandle(wxSFShapeHandle::hndBOTTOM);
AddHandle(wxSFShapeHandle::hndLEFTBOTTOM);
AddHandle(wxSFShapeHandle::hndLEFT);
AddHandle(wxSFShapeHandle::hndLEFTTOP);
}
void wxSFRectShape::OnHandle(wxSFShapeHandle& handle)
{
// HINT: overload it for custom actions...
switch(handle.GetType())
{
case wxSFShapeHandle::hndLEFT:
OnLeftHandle(handle);
break;
case wxSFShapeHandle::hndLEFTTOP:
OnLeftHandle(handle);
OnTopHandle(handle);
break;
case wxSFShapeHandle::hndLEFTBOTTOM:
OnLeftHandle(handle);
OnBottomHandle(handle);
break;
case wxSFShapeHandle::hndRIGHT:
OnRightHandle(handle);
break;
case wxSFShapeHandle::hndRIGHTTOP:
OnRightHandle(handle);
OnTopHandle(handle);
break;
case wxSFShapeHandle::hndRIGHTBOTTOM:
OnRightHandle(handle);
OnBottomHandle(handle);
break;
case wxSFShapeHandle::hndTOP:
OnTopHandle(handle);
break;
case wxSFShapeHandle::hndBOTTOM:
OnBottomHandle(handle);
break;
default:
break;
}
wxSFShapeBase::OnHandle( handle );
}
void wxSFRectShape::OnBeginHandle(wxSFShapeHandle& handle)
{
m_nPrevPosition = m_nRelativePosition;
m_nPrevSize = m_nRectSize;
wxSFShapeBase::OnBeginHandle( handle );
}

View File

@@ -0,0 +1,136 @@
/***************************************************************
* Name: RoundRectShape.cpp
* Purpose: Implements rounded rectangular shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include <math.h>
#include "wx/wxsf/RoundRectShape.h"
#include "wx/wxsf/ShapeCanvas.h"
#include "wx/wxsf/CommonFcn.h"
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFRoundRectShape, wxSFRectShape);
wxSFRoundRectShape::wxSFRoundRectShape(void) : wxSFRectShape()
{
m_nRadius = sfdvROUNDRECTSHAPE_RADIUS;
MarkSerializableDataMembers();
}
wxSFRoundRectShape::wxSFRoundRectShape(const wxRealPoint& pos, const wxRealPoint &size, double radius, wxSFDiagramManager* manager)
: wxSFRectShape(pos, size, manager)
{
m_nRadius = radius;
MarkSerializableDataMembers();
}
wxSFRoundRectShape::wxSFRoundRectShape(const wxSFRoundRectShape& obj) : wxSFRectShape(obj)
{
m_nRadius = obj.m_nRadius;
MarkSerializableDataMembers();
}
wxSFRoundRectShape::~wxSFRoundRectShape(void)
{
}
void wxSFRoundRectShape::MarkSerializableDataMembers()
{
XS_SERIALIZE_EX(m_nRadius, wxT("radius"), sfdvROUNDRECTSHAPE_RADIUS);
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
bool wxSFRoundRectShape::Contains(const wxPoint &pos)
{
// get original bounding box
wxRect shpBB = GetBoundingBox();
// calculate modified boxes
wxRect hr(shpBB);
hr.Deflate(0, (int)m_nRadius);
wxRect vr(shpBB);
vr.Deflate((int)m_nRadius, 0);
// test whether given position is inside body rect or rounded corners
if(hr.Contains(pos))return true;
else if(vr.Contains(pos))return true;
else if(IsInCircle(pos, shpBB.GetTopLeft() + wxPoint((int)m_nRadius, (int)m_nRadius)))return true;
else if(IsInCircle(pos, shpBB.GetBottomLeft() + wxPoint((int)m_nRadius, (int)-m_nRadius)))return true;
else if(IsInCircle(pos, shpBB.GetTopRight() + wxPoint((int)-m_nRadius, (int)m_nRadius)))return true;
else if(IsInCircle(pos, shpBB.GetBottomRight() + wxPoint((int)-m_nRadius, (int)-m_nRadius)))return true;
return false;
}
//----------------------------------------------------------------------------------//
// protected virtual functions
//----------------------------------------------------------------------------------//
void wxSFRoundRectShape::DrawNormal(wxDC& dc)
{
dc.SetPen(m_Border);
dc.SetBrush(m_Fill);
dc.DrawRoundedRectangle(Conv2Point(GetAbsolutePosition()), Conv2Size(m_nRectSize), m_nRadius);
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFRoundRectShape::DrawHover(wxDC& dc)
{
dc.SetPen(wxPen(m_nHoverColor, 1));
dc.SetBrush(m_Fill);
dc.DrawRoundedRectangle(Conv2Point(GetAbsolutePosition()), Conv2Size(m_nRectSize), m_nRadius);
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFRoundRectShape::DrawHighlighted(wxDC& dc)
{
dc.SetPen(wxPen(m_nHoverColor, 2));
dc.SetBrush(m_Fill);
dc.DrawRoundedRectangle(Conv2Point(GetAbsolutePosition()), Conv2Size(m_nRectSize), m_nRadius);
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
void wxSFRoundRectShape::DrawShadow(wxDC& dc)
{
// HINT: overload it for custom actions...
if( m_Fill.GetStyle() != wxTRANSPARENT )
{
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(GetParentCanvas()->GetShadowFill());
dc.DrawRoundedRectangle(Conv2Point(GetAbsolutePosition() + GetParentCanvas()->GetShadowOffset()), Conv2Size(m_nRectSize), m_nRadius);
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
}
//----------------------------------------------------------------------------------//
// public functions
//----------------------------------------------------------------------------------//
bool wxSFRoundRectShape::IsInCircle(const wxPoint& pos, const wxPoint& center)
{
return (Distance(Conv2RealPoint(center), Conv2RealPoint(pos)) <= m_nRadius);
}

View File

@@ -0,0 +1,231 @@
/***************************************************************
* Name: SFEvents.cpp
* Purpose: Implements shape events classes
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-09-11
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/SFEvents.h"
DEFINE_EVENT_TYPE( wxEVT_SF_LINE_DONE );
DEFINE_EVENT_TYPE( wxEVT_SF_TEXT_CHANGE );
DEFINE_EVENT_TYPE( wxEVT_SF_ON_DROP );
DEFINE_EVENT_TYPE( wxEVT_SF_ON_PASTE );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_LEFT_DOWN );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_LEFT_DCLICK );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_RIGHT_DOWN );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_RIGHT_DCLICK);
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_DRAG_BEGIN);
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_DRAG );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_DRAG_END );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_HANDLE_BEGIN );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_HANDLE );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_HANDLE_END );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_KEYDOWN );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_MOUSE_ENTER );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_MOUSE_OVER );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_MOUSE_LEAVE );
DEFINE_EVENT_TYPE( wxEVT_SF_SHAPE_CHILD_DROP );
DEFINE_EVENT_TYPE( wxEVT_SF_LINE_BEFORE_DONE );
//----------------------------------------------------------------------------------//
// wxSFShapeEvent class
//----------------------------------------------------------------------------------//
wxSFShapeEvent::wxSFShapeEvent(wxEventType cmdType, int id)
: wxEvent(id, cmdType), m_Vetoed(false)
{
m_Shape = NULL;
}
wxSFShapeEvent::wxSFShapeEvent(const wxSFShapeEvent& obj)
: wxEvent(obj), m_Vetoed(obj.m_Vetoed)
{
m_Shape = obj.m_Shape;
}
wxSFShapeEvent::~wxSFShapeEvent()
{
}
//----------------------------------------------------------------------------------//
// wxSFShapeEvent class
//----------------------------------------------------------------------------------//
wxSFShapeTextEvent::wxSFShapeTextEvent(wxEventType cmdType, int id)
: wxEvent(id, cmdType)
{
m_Shape = NULL;
m_Text = wxT("");
}
wxSFShapeTextEvent::wxSFShapeTextEvent(const wxSFShapeTextEvent& obj)
: wxEvent(obj)
{
m_Shape = obj.m_Shape;
m_Text = obj.m_Text;
}
wxSFShapeTextEvent::~wxSFShapeTextEvent()
{
}
//----------------------------------------------------------------------------------//
// wxSFShapeDropEvent class
//----------------------------------------------------------------------------------//
wxSFShapeDropEvent::wxSFShapeDropEvent(wxEventType cmdType, wxCoord x, wxCoord y, wxSFShapeCanvas* target, wxDragResult def, int id)
: wxEvent(id, cmdType)
{
m_nDropPosition = wxPoint(x, y);
m_nDragResult = def;
m_pDropTarget = target;
}
wxSFShapeDropEvent::wxSFShapeDropEvent(const wxSFShapeDropEvent& obj)
: wxEvent(obj)
{
SetDroppedShapes(obj.m_lstDroppedShapes);
m_nDropPosition = obj.m_nDropPosition;
m_nDragResult = obj.m_nDragResult;
m_pDropTarget = obj.m_pDropTarget;
}
wxSFShapeDropEvent::~wxSFShapeDropEvent()
{
m_lstDroppedShapes.Clear();
}
void wxSFShapeDropEvent::SetDroppedShapes(const ShapeList &list)
{
ShapeList::compatibility_iterator node = list.GetFirst();
while(node)
{
m_lstDroppedShapes.Append(node->GetData());
node = node->GetNext();
}
}
//----------------------------------------------------------------------------------//
// wxSFShapeDropEvent class
//----------------------------------------------------------------------------------//
wxSFShapePasteEvent::wxSFShapePasteEvent(wxEventType cmdType, wxSFShapeCanvas *target, int id)
: wxEvent(id, cmdType)
{
m_pDropTarget = target;
}
wxSFShapePasteEvent::wxSFShapePasteEvent(const wxSFShapePasteEvent& obj)
: wxEvent(obj)
{
SetPastedShapes(obj.m_lstPastedShapes);
m_pDropTarget = obj.m_pDropTarget;
}
wxSFShapePasteEvent::~wxSFShapePasteEvent()
{
m_lstPastedShapes.Clear();
}
void wxSFShapePasteEvent::SetPastedShapes(const ShapeList &list)
{
ShapeList::compatibility_iterator node = list.GetFirst();
while(node)
{
m_lstPastedShapes.Append(node->GetData());
node = node->GetNext();
}
}
//----------------------------------------------------------------------------------//
// wxSFShapeKeyEvent class
//----------------------------------------------------------------------------------//
wxSFShapeKeyEvent::wxSFShapeKeyEvent(const wxSFShapeKeyEvent& obj) : wxEvent(obj)
{
m_Shape = obj.m_Shape;
m_KeyCode = obj.m_KeyCode;
}
wxSFShapeKeyEvent::wxSFShapeKeyEvent(wxEventType cmdType, int id) : wxEvent(id, cmdType)
{
m_Shape = NULL;
m_KeyCode = 0;
}
wxSFShapeKeyEvent::~wxSFShapeKeyEvent()
{
}
//----------------------------------------------------------------------------------//
// wxSFShapeHandleEvent class
//----------------------------------------------------------------------------------//
wxSFShapeHandleEvent::wxSFShapeHandleEvent(const wxSFShapeHandleEvent& obj) : wxEvent(obj)
{
m_Shape = obj.m_Shape;
m_Handle = obj.m_Handle;
}
wxSFShapeHandleEvent::wxSFShapeHandleEvent(wxEventType cmdType, int id) : wxEvent(id, cmdType)
{
m_Shape = NULL;
m_Handle = NULL;
}
wxSFShapeHandleEvent::~wxSFShapeHandleEvent()
{
}
//----------------------------------------------------------------------------------//
// wxSFShapeChildDropEvent class
//----------------------------------------------------------------------------------//
wxSFShapeChildDropEvent::wxSFShapeChildDropEvent(const wxSFShapeChildDropEvent& obj) : wxEvent(obj)
{
m_Shape = obj.m_Shape;
m_ChildShape = obj.m_ChildShape;
}
wxSFShapeChildDropEvent::wxSFShapeChildDropEvent(wxEventType cmdType, int id) : wxEvent(id, cmdType)
{
m_Shape = NULL;
m_ChildShape = NULL;
}
wxSFShapeChildDropEvent::~wxSFShapeChildDropEvent()
{
}
//----------------------------------------------------------------------------------//
// wxSFShapeMouseEvent class
//----------------------------------------------------------------------------------//
wxSFShapeMouseEvent::wxSFShapeMouseEvent(const wxSFShapeMouseEvent& obj) : wxEvent(obj)
{
m_Shape = obj.m_Shape;
m_MousePosition = obj.m_MousePosition;
}
wxSFShapeMouseEvent::wxSFShapeMouseEvent(wxEventType cmdType, int id) : wxEvent(id, cmdType)
{
m_Shape = NULL;
m_MousePosition = wxDefaultPosition;
}
wxSFShapeMouseEvent::~wxSFShapeMouseEvent()
{
}

View File

@@ -0,0 +1,683 @@
/***************************************************************
* Name: ScaledDC.cpp
* Purpose: Implements scaled DC class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2008-11-7
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/ScaledDC.h"
#if wxVERSION_NUMBER >= 2900
wxSFScaledDC::wxSFScaledDC( wxWindowDC *target, double scale) : wxDC( new wxSFDCImplWrapper( target->GetImpl(), scale ) )
{
}
wxSFScaledDC::~wxSFScaledDC()
{
}
#else // ! wxVERSION_NUMBER >= 2900
#include "wx/wxsf/CommonFcn.h"
bool wxSFScaledDC::m_fEnableGC = false;
//----------------------------------------------------------------------------------//
// Constructor and destructor
//----------------------------------------------------------------------------------//
wxSFScaledDC::wxSFScaledDC( wxWindowDC *target, double scale)
{
m_nScale = scale;
m_pTargetDC = target;
#if wxUSE_GRAPHICS_CONTEXT
m_pGC = wxGraphicsContext::Create( *m_pTargetDC );
//m_pGC->Scale( scale, scale );
#endif
}
wxSFScaledDC::~wxSFScaledDC()
{
#if wxUSE_GRAPHICS_CONTEXT
if( m_pGC ) delete m_pGC;
#endif
}
//----------------------------------------------------------------------------------//
// wxGraphicContext related functions
//----------------------------------------------------------------------------------//
void wxSFScaledDC::InitGC()
{
#if wxUSE_GRAPHICS_CONTEXT
m_pGC->PushState();
m_pGC->Scale( m_nScale, m_nScale );
/*m_pGC->SetPen( this->GetPen() );
m_pGC->SetBrush( this->GetBrush() );
m_pGC->SetFont( this->GetFont(), this->GetTextForeground() );*/
#endif
}
void wxSFScaledDC::UninitGC()
{
#if wxUSE_GRAPHICS_CONTEXT
/*m_pGC->SetPen( wxNullPen );
m_pGC->SetBrush( wxNullBrush );
m_pGC->SetFont( wxNullFont, *wxBLACK );*/
m_pGC->PopState();
#endif
}
void wxSFScaledDC::PrepareGC()
{
#if wxUSE_GRAPHICS_CONTEXT && !defined(__WXMAC__)
int x, y;
GetDeviceOrigin(&x, &y);
//m_pGC->Translate( x / m_nScale, y / m_nScale );
m_pGC->Translate( x, y );
#endif
}
//----------------------------------------------------------------------------------//
// Wrapped wxDC functions
//----------------------------------------------------------------------------------//
void wxSFScaledDC::CalcBoundingBox(wxCoord x, wxCoord y)
{
m_pTargetDC->CalcBoundingBox(x, y);
}
bool wxSFScaledDC::CanDrawBitmap() const
{
return m_pTargetDC->CanDrawBitmap();
}
bool wxSFScaledDC::CanGetTextExtent() const
{
return m_pTargetDC->CanGetTextExtent();
}
void wxSFScaledDC::Clear()
{
m_pTargetDC->Clear();
}
void wxSFScaledDC::ComputeScaleAndOrigin()
{
m_pTargetDC->ComputeScaleAndOrigin();
}
bool wxSFScaledDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC* source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask)
{
return m_pTargetDC->Blit( Scale(xdest), Scale(ydest), width, height, source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask);
}
void wxSFScaledDC::DoCrossHair(wxCoord x, wxCoord y)
{
m_pTargetDC->CrossHair( Scale(x), Scale(y) );
}
void wxSFScaledDC::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
InitGC();
wxGraphicsPath path = m_pGC->CreatePath();
double dist, sang, eang;
dist = wxSFCommonFcn::Distance( wxRealPoint(x2, y2), wxRealPoint(xc, yc) );
sang = acos( (x2 - xc) / dist ) + ( yc > y2 ? wxSF::PI : 0 );
dist = wxSFCommonFcn::Distance( wxRealPoint(x1, y1), wxRealPoint(xc, yc) );
eang = acos( (x1 - xc) / dist ) + ( yc > y1 ? wxSF::PI : 0 );
path.AddArc( xc, yc, dist, sang, eang, true );
m_pGC->StrokePath( path );
UninitGC();
#endif
}
else
m_pTargetDC->DrawArc(Scale(x1), Scale(y1), Scale(x2), Scale(y2), Scale(xc), Scale(yc));
}
void wxSFScaledDC::DoDrawBitmap(const wxBitmap& bmp, wxCoord x, wxCoord y, bool useMask)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
InitGC();
m_pGC->DrawBitmap( bmp, x, y, bmp.GetWidth(), bmp.GetHeight() );
UninitGC();
#endif
}
else
m_pTargetDC->DrawBitmap( bmp, Scale(x), Scale(y), useMask );
}
void wxSFScaledDC::DoDrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
m_pTargetDC->DrawCheckMark(Scale(x), Scale(y), Scale(width), Scale(height));
}
void wxSFScaledDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
InitGC();
m_pGC->DrawEllipse(x, y, width, height );
UninitGC();
#endif
}
else
m_pTargetDC->DrawEllipse( Scale(x), Scale(y), Scale(width), Scale(height) );
}
void wxSFScaledDC::DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea)
{
m_pTargetDC->DrawEllipticArc(Scale(x), Scale(y), Scale(w), Scale(h), sa, ea);
}
void wxSFScaledDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
{
m_pTargetDC->DrawIcon( icon, Scale(x), Scale(y) );
}
void wxSFScaledDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
InitGC();
m_pGC->StrokeLine(x1, y1, x2, y2);
UninitGC();
#endif
}
else
m_pTargetDC->DrawLine(Scale(x1), Scale(y1), Scale(x2), Scale(y2));
}
void wxSFScaledDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
InitGC();
wxPoint2DDouble *pts = new wxPoint2DDouble[n];
for(int i = 0; i < n; i++)
{
pts[0].m_x = points[0].x;
pts[0].m_y = points[0].y;
}
m_pGC->StrokeLines(n, pts);
delete [] pts;
UninitGC();
#endif
}
else
{
wxPoint *updPoints = new wxPoint[n];
for(int i = 0; i < n; i++)
{
updPoints[i].x = (int)((double)points[i].x*m_nScale);
updPoints[i].y = (int)((double)points[i].y*m_nScale);
}
m_pTargetDC->DrawLines(n, updPoints, Scale(xoffset), Scale(yoffset));
delete [] updPoints;
}
}
void wxSFScaledDC::DoDrawPoint(wxCoord x, wxCoord y)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
InitGC();
m_pGC->StrokeLine(x, y, x+1, y);
UninitGC();
#endif
}
else
m_pTargetDC->DrawPoint(Scale(x), Scale(y));
}
void wxSFScaledDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
int nIndex = 0;
InitGC();
wxGraphicsPath gcPath = m_pGC->CreatePath();
for(int i = 0; i < n; i++)
{
gcPath.MoveToPoint( points[nIndex].x, points[nIndex].y );
for(int j = 0; j < count[i]; j++)
{
nIndex++;
gcPath.AddLineToPoint( points[nIndex].x, points[nIndex].y );
}
gcPath.CloseSubpath();
}
m_pGC->Translate( xoffset, yoffset );
m_pGC->DrawPath( gcPath );
UninitGC();
#endif
}
else
{
int nTotalPoints = 0;
for(int i = 0; i < n; i++)nTotalPoints += count[i];
wxPoint *updPoints = new wxPoint[nTotalPoints];
for(int i = 0; i < nTotalPoints; i++)
{
updPoints[i].x = (int)((double)points[i].x*m_nScale);
updPoints[i].y = (int)((double)points[i].y*m_nScale);
}
m_pTargetDC->DrawPolyPolygon(n, count, updPoints, Scale(xoffset), Scale(yoffset), fillStyle);
delete [] updPoints;
}
}
void wxSFScaledDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
InitGC();
wxGraphicsPath gcPath = m_pGC->CreatePath();
gcPath.MoveToPoint( points[0].x, points[0].y );
for(int i = 1; i < n; i++)
{
gcPath.AddLineToPoint( points[i].x, points[i].y );
}
gcPath.CloseSubpath();
m_pGC->DrawPath( gcPath );
UninitGC();
#endif
}
else
{
wxPoint *updPoints = new wxPoint[n];
for(int i = 0; i < n; i++)
{
updPoints[i].x = (int)((double)points[i].x*m_nScale);
updPoints[i].y = (int)((double)points[i].y*m_nScale);
}
m_pTargetDC->DrawPolygon(n, updPoints, Scale(xoffset), Scale(yoffset), fillStyle);
delete [] updPoints;
}
}
void wxSFScaledDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
InitGC();
m_pGC->DrawRectangle(x, y, width, height);
UninitGC();
#endif
}
else
m_pTargetDC->DrawRectangle(Scale(x), Scale(y), Scale(width), Scale(height));
}
void wxSFScaledDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
InitGC();
m_pGC->DrawText( text, x, y, angle );
UninitGC();
#endif
}
else
{
wxFont font = GetFont();
wxFont prevfont = font;
if(font != wxNullFont)
{
font.SetPointSize(int(font.GetPointSize()*m_nScale));
SetFont(font);
}
m_pTargetDC->DrawRotatedText(text, Scale(x), Scale(y), angle);
SetFont(prevfont);
}
}
void wxSFScaledDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
InitGC();
m_pGC->DrawRoundedRectangle(x, y, width, height, radius);
UninitGC();
#endif
}
else
m_pTargetDC->DrawRoundedRectangle(Scale(x), Scale(y), Scale(width), Scale(height), radius*m_nScale);
}
void wxSFScaledDC::DoDrawSpline(wxList* points)
{
m_pTargetDC->DrawSpline( points );
}
void wxSFScaledDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
InitGC();
m_pGC->DrawText( text, x, y );
UninitGC();
#endif
}
else
{
wxFont font = GetFont();
wxFont prevfont = font;
if(font != wxNullFont)
{
int scaledSize = int(font.GetPointSize()*m_nScale);
font.SetPointSize( scaledSize ? scaledSize : 1 );
SetFont(font);
}
m_pTargetDC->DrawText(text, Scale(x), Scale(y));
SetFont(prevfont);
}
}
bool wxSFScaledDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style)
{
return m_pTargetDC->FloodFill( Scale(x), Scale(y), col, style );
}
wxBitmap wxSFScaledDC::DoGetAsBitmap(const wxRect *subrect) const
{
return m_pTargetDC->GetAsBitmap( subrect );
}
void wxSFScaledDC::DoGetClippingBox(wxCoord* x, wxCoord* y, wxCoord* w, wxCoord* h) const
{
m_pTargetDC->GetClippingBox( x, y, w, h );
}
void wxSFScaledDC::DoGetClippingRegion(wxCoord* x, wxCoord* y, wxCoord* w, wxCoord* h)
{
wxUnusedVar( x );
wxUnusedVar( y );
wxUnusedVar( w );
wxUnusedVar( h );
// not implemented...
}
void wxSFScaledDC::DoGetDeviceOrigin(wxCoord* x, wxCoord* y) const
{
m_pTargetDC->GetDeviceOrigin( x, y );
}
void wxSFScaledDC::DoGetLogicalOrigin(wxCoord* x, wxCoord* y) const
{
m_pTargetDC->GetLogicalOrigin( x, y );
}
bool wxSFScaledDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
{
return m_pTargetDC->GetPartialTextExtents( text, widths );
}
bool wxSFScaledDC::DoGetPixel(wxCoord x, wxCoord y, wxColour* col) const
{
return m_pTargetDC->GetPixel( x, y, col );
}
void wxSFScaledDC::DoGetSize(int* width, int* height) const
{
m_pTargetDC->GetSize( width, height );
}
void wxSFScaledDC::DoGetSizeMM(int* width, int* height) const
{
m_pTargetDC->GetSizeMM( width, height );
}
void wxSFScaledDC::DoGetTextExtent(const wxString& string, wxCoord* x, wxCoord* y, wxCoord* descent, wxCoord* externalLeading, wxFont* theFont) const
{
m_pTargetDC->GetTextExtent( string, x, y, descent, externalLeading, theFont );
}
void wxSFScaledDC::DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter)
{
wxRect updRct( rect.x * m_nScale, rect.y * m_nScale, rect.width * m_nScale, rect.height * m_nScale );
m_pTargetDC->GradientFillConcentric( updRct, initialColour, destColour, circleCenter);
}
void wxSFScaledDC::DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection)
{
wxRect updRct( rect.x * m_nScale, rect.y * m_nScale, rect.width * m_nScale, rect.height * m_nScale );
m_pTargetDC->GradientFillLinear( updRct, initialColour, destColour, nDirection );
}
void wxSFScaledDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
m_pTargetDC->SetClippingRegion( x, y, width, height );
}
void wxSFScaledDC::DoSetClippingRegionAsRegion(const wxRegion& region)
{
wxUnusedVar( region );
// not implemented...
}
void wxSFScaledDC::DrawObject(wxDrawObject* drawobject)
{
m_pTargetDC->DrawObject( drawobject );
}
void wxSFScaledDC::EndDoc()
{
m_pTargetDC->EndDoc();
}
void wxSFScaledDC::EndPage()
{
m_pTargetDC->EndPage();
}
const wxBrush& wxSFScaledDC::GetBackground() const
{
return m_pTargetDC->GetBackground();
}
int wxSFScaledDC::GetBackgroundMode() const
{
return m_pTargetDC->GetBackgroundMode();
}
const wxBrush& wxSFScaledDC::GetBrush() const
{
return m_pTargetDC->GetBrush();
}
wxCoord wxSFScaledDC::GetCharHeight() const
{
return m_pTargetDC->GetCharHeight();
}
wxCoord wxSFScaledDC::GetCharWidth() const
{
return m_pTargetDC->GetCharWidth();
}
int wxSFScaledDC::GetDepth() const
{
return m_pTargetDC->GetDepth();
}
const wxFont& wxSFScaledDC::GetFont() const
{
return m_pTargetDC->GetFont();
}
#ifdef __WXGTK__
GdkWindow* wxSFScaledDC::GetGDKWindow() const
{
return m_pTargetDC->GetGDKWindow();
}
#endif
wxLayoutDirection wxSFScaledDC::GetLayoutDirection() const
{
return m_pTargetDC->GetLayoutDirection();
}
int wxSFScaledDC::GetLogicalFunction() const
{
return m_pTargetDC->GetLogicalFunction();
}
void wxSFScaledDC::GetLogicalScale(double* x, double* y)
{
m_pTargetDC->GetLogicalScale( x, y );
}
int wxSFScaledDC::GetMapMode() const
{
return m_pTargetDC->GetMapMode();
}
void wxSFScaledDC::GetMultiLineTextExtent(const wxString& string, wxCoord* width, wxCoord* height, wxCoord* heightLine, wxFont* font) const
{
m_pTargetDC->GetMultiLineTextExtent( string, width, height, heightLine, font );
}
wxSize wxSFScaledDC::GetPPI() const
{
return m_pTargetDC->GetPPI();
}
const wxPen& wxSFScaledDC::GetPen() const
{
return m_pTargetDC->GetPen();
}
wxBitmap wxSFScaledDC::GetSelectedBitmap() const
{
#ifndef __WXMAC__
return m_pTargetDC->GetSelectedBitmap();
#else
return wxNullBitmap;
#endif
}
const wxColour& wxSFScaledDC::GetTextBackground() const
{
return m_pTargetDC->GetTextBackground();
}
const wxColour& wxSFScaledDC::GetTextForeground() const
{
return m_pTargetDC->GetTextForeground();
}
void wxSFScaledDC::GetUserScale(double* x, double* y) const
{
m_pTargetDC->GetUserScale( x, y );
}
bool wxSFScaledDC::IsOk() const
{
return m_pTargetDC->IsOk();
}
bool wxSFScaledDC::Ok() const
{
return m_pTargetDC->Ok();
}
void wxSFScaledDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp)
{
m_pTargetDC->SetAxisOrientation( xLeftRight, yBottomUp );
}
void wxSFScaledDC::SetBackground(const wxBrush& brush)
{
m_pTargetDC->SetBackground( brush );
}
void wxSFScaledDC::SetBackgroundMode(int mode)
{
m_pTargetDC->SetBackgroundMode( mode );
}
void wxSFScaledDC::SetBrush(const wxBrush& brush)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
m_pGC->SetBrush( brush );
#endif
}
m_pTargetDC->SetBrush( brush );
}
void wxSFScaledDC::SetDeviceOrigin(wxCoord x, wxCoord y)
{
m_pTargetDC->SetDeviceOrigin( x, y );
}
void wxSFScaledDC::SetFont(const wxFont& font)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
m_pGC->SetFont( font, this->GetTextForeground() );
#endif
}
m_pTargetDC->SetFont( font );
}
void wxSFScaledDC::SetLayoutDirection(wxLayoutDirection dir)
{
m_pTargetDC->SetLayoutDirection( dir );
}
void wxSFScaledDC::SetLogicalFunction(int function)
{
m_pTargetDC->SetLogicalFunction( function );
}
void wxSFScaledDC::SetLogicalOrigin(wxCoord x, wxCoord y)
{
m_pTargetDC->SetLogicalOrigin( x, y );
}
void wxSFScaledDC::SetLogicalScale(double x, double y)
{
m_pTargetDC->SetLogicalScale( x, y );
}
void wxSFScaledDC::SetMapMode(int mode)
{
m_pTargetDC->SetMapMode( mode );
}
void wxSFScaledDC::SetPalette(const wxPalette& palette)
{
m_pTargetDC->SetPalette( palette );
}
void wxSFScaledDC::SetPen(const wxPen& pen)
{
if( m_fEnableGC )
{
#if wxUSE_GRAPHICS_CONTEXT
m_pGC->SetPen( pen );
#endif
}
m_pTargetDC->SetPen( pen );
}
void wxSFScaledDC::SetTextBackground(const wxColour& colour)
{
m_pTargetDC->SetTextBackground( colour );
}
void wxSFScaledDC::SetTextForeground(const wxColour& colour)
{
m_pTargetDC->SetTextForeground( colour );
}
void wxSFScaledDC::SetUserScale(double x, double y)
{
m_pTargetDC->SetUserScale( x, y );
}
bool wxSFScaledDC::StartDoc( const wxString& message )
{
return m_pTargetDC->StartDoc( message );
}
void wxSFScaledDC::StartPage()
{
m_pTargetDC->StartPage();
}
#endif // wxVERSION_NUMBER >= 2900

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,50 @@
/***************************************************************
* Name: ShapeBaseXml.cpp
* Purpose: Implements basic shape's serialization capability
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/ShapeBase.h"
#include "wx/wxsf/CommonFcn.h"
//----------------------------------------------------------------------------------//
// Serialization
//----------------------------------------------------------------------------------//
wxXmlNode* wxSFShapeBase::Serialize(wxXmlNode* node)
{
// HINT: overload it for custom actions...
node = xsSerializable::Serialize(node);
return node;
}
void wxSFShapeBase::Deserialize(wxXmlNode* node)
{
// HINT: overload it for custom actions...
xsSerializable::Deserialize(node);
if( m_pUserData )
{
m_pUserData->SetParent(this);
}
// update fixed connection points
for( ConnectionPointList::iterator it = m_lstConnectionPts.begin(); it != m_lstConnectionPts.end(); ++it )
{
wxSFConnectionPoint *pCp = (wxSFConnectionPoint*) *it;
pCp->SetParentShape( this );
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,92 @@
/***************************************************************
* Name: ShapeDataObject.cpp
* Purpose: Implements shape data object class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include <wx/mstream.h>
#include "wx/wxsf/ShapeDataObject.h"
wxSFShapeDataObject::wxSFShapeDataObject(const wxDataFormat& format)
: wxDataObjectSimple(format)
{
m_Data.SetText(wxT("<?xml version=\"1.0\" encoding=\"utf-8\"?><chart />"));
}
wxSFShapeDataObject::wxSFShapeDataObject(const wxDataFormat& format, const ShapeList& selection, wxSFDiagramManager* manager)
: wxDataObjectSimple(format)
{
m_Data.SetText(SerializeSelectedShapes(selection, manager));
}
wxSFShapeDataObject::~wxSFShapeDataObject(void)
{
}
wxString wxSFShapeDataObject::SerializeSelectedShapes(const ShapeList& selection, wxSFDiagramManager* manager)
{
// create root node
wxSFShapeBase *pShape;
wxXmlNode *root = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("chart"));
// serialize copied shapes to XML node
ShapeList::compatibility_iterator node = selection.GetFirst();
while(node)
{
pShape = node->GetData();
if(pShape)
{
// serialize parent's children
manager->SerializeObjects(pShape, root, serINCLUDE_PARENTS);
}
node = node->GetNext();
}
// create XML document in the memory stream
wxMemoryOutputStream outstream;
wxXmlDocument xmlDoc;
xmlDoc.SetRoot(root);
xmlDoc.Save(outstream);
char *buffer = new char [outstream.GetSize()];
if(buffer)
{
memset(buffer, 0, outstream.GetSize());
outstream.CopyTo(buffer, outstream.GetSize()-1);
wxString output(buffer, wxConvUTF8);
delete [] buffer;
return output;
}
else
return wxT("<?xml version=\"1.0\" encoding=\"utf-8\"?><chart />");
}
size_t wxSFShapeDataObject::GetDataSize() const
{
return m_Data.GetDataSize();
}
bool wxSFShapeDataObject::GetDataHere(void* buf) const
{
return m_Data.GetDataHere(buf);
}
bool wxSFShapeDataObject::SetData(size_t len, const void* buf)
{
return m_Data.SetData(len, buf);
}

View File

@@ -0,0 +1,318 @@
/***************************************************************
* Name: ShapeHandle.cpp
* Purpose: Implements shape handle class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/ShapeCanvas.h"
#include "wx/wxsf/ShapeHandle.h"
#include "wx/wxsf/ShapeBase.h"
#include <wx/listimpl.cpp>
IMPLEMENT_DYNAMIC_CLASS(wxSFShapeHandle, wxObject);
WX_DEFINE_LIST(HandleList);
wxSFShapeHandle::wxSFShapeHandle(void)
{
// initialize data members
m_nType = hndUNDEF;
m_pParentShape = NULL;
m_nPrevPos = wxPoint(0, 0);
m_nCurrPos = wxPoint(0, 0);
m_nId = -1;
m_fVisible = false;
m_fMouseOver = false;
}
wxSFShapeHandle::wxSFShapeHandle(wxSFShapeBase* parent, HANDLETYPE type, long id)
{
// initialize data members
m_nType = type;
m_pParentShape = parent;
m_nPrevPos = wxPoint(0, 0);
m_nCurrPos = wxPoint(0, 0);
m_nId = id;
m_fVisible = false;
m_fMouseOver = false;
}
wxSFShapeHandle::wxSFShapeHandle(const wxSFShapeHandle& obj)
: wxObject(obj)
{
// initialize data members
m_nType = obj.m_nType;
m_pParentShape = obj.m_pParentShape;
m_nPrevPos = wxPoint(0, 0);
m_nCurrPos = wxPoint(0, 0);
m_nId = obj.m_nId;
m_fVisible = obj.m_fVisible;
m_fMouseOver = obj.m_fMouseOver;
}
wxSFShapeHandle::~wxSFShapeHandle(void)
{
}
//----------------------------------------------------------------------------------//
// Public functions
//----------------------------------------------------------------------------------//
bool wxSFShapeHandle::Contains(const wxPoint& pos)
{
return GetHandleRect().Contains(pos);
}
void wxSFShapeHandle::Draw(wxDC& dc)
{
if(m_fVisible && m_pParentShape)
{
if(m_fMouseOver)DrawHover(dc);
else
DrawNormal(dc);
}
}
void wxSFShapeHandle::Refresh()
{
if( m_pParentShape ) m_pParentShape->Refresh( sfDELAYED );
}
//----------------------------------------------------------------------------------//
// Protected functions
//----------------------------------------------------------------------------------//
void wxSFShapeHandle::DrawNormal(wxDC& dc)
{
#ifdef __WXGTK__
dc.SetPen(*wxTRANSPARENT_PEN);
#else
dc.SetPen(*wxBLACK_PEN);
#endif
#if wxUSE_GRAPHICS_CONTEXT
if( wxSFShapeCanvas::IsGCEnabled() )
{
dc.SetBrush( wxColour(0, 0, 0, 128) );
}
else
{
dc.SetBrush(*wxBLACK_BRUSH);
dc.SetLogicalFunction(wxINVERT);
}
#else
dc.SetBrush(*wxBLACK_BRUSH);
dc.SetLogicalFunction(wxINVERT);
#endif
dc.DrawRectangle(GetHandleRect());
dc.SetLogicalFunction(wxCOPY);
dc.SetPen(wxNullPen);
dc.SetBrush(wxNullBrush);
}
void wxSFShapeHandle::DrawHover(wxDC& dc)
{
if(m_pParentShape->ContainsStyle(wxSFShapeBase::sfsSIZE_CHANGE))
{
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(wxBrush(m_pParentShape->GetHoverColour()));
dc.DrawRectangle(GetHandleRect());
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
else
{
DrawNormal(dc);
}
}
wxRect wxSFShapeHandle::GetHandleRect() const
{
if(m_pParentShape)
{
wxRect hrct;
wxRect brct = m_pParentShape->GetBoundingBox();
switch(m_nType)
{
case hndLEFTTOP:
hrct = wxRect(brct.GetLeftTop(), wxSize(7,7));
break;
case hndTOP:
hrct = wxRect(wxPoint(brct.GetLeft() + brct.GetWidth()/2, brct.GetTop()), wxSize(7,7));
break;
case hndRIGHTTOP:
hrct = wxRect(brct.GetRightTop(), wxSize(7,7));
break;
case hndRIGHT:
hrct = wxRect(wxPoint(brct.GetRight(), brct.GetTop() + brct.GetHeight()/2), wxSize(7,7));
break;
case hndRIGHTBOTTOM:
hrct = wxRect(brct.GetRightBottom(), wxSize(7,7));
break;
case hndBOTTOM:
hrct = wxRect(wxPoint(brct.GetLeft() + brct.GetWidth()/2, brct.GetBottom()), wxSize(7,7));
break;
case hndLEFTBOTTOM:
hrct = wxRect(brct.GetLeftBottom(), wxSize(7,7));
break;
case hndLEFT:
hrct = wxRect(wxPoint(brct.GetLeft(), brct.GetTop() + brct.GetHeight()/2), wxSize(7,7));
break;
case hndLINECTRL:
{
wxRealPoint* pt = ((wxSFLineShape*)m_pParentShape)->GetControlPoints().Item(m_nId)->GetData();
hrct = wxRect(wxPoint((int)pt->x, (int)pt->y), wxSize(7,7));
}
break;
case hndLINEEND:
case hndLINESTART:
{
wxSFLineShape *pLine = (wxSFLineShape*)m_pParentShape;
wxRealPoint pt;
if( m_nType == hndLINESTART )
{
pt = pLine->GetSrcPoint();
}
else
pt = pLine->GetTrgPoint();
hrct = wxRect(wxPoint((int)pt.x, (int)pt.y), wxSize(7,7));
}
break;
default:
hrct = wxRect();
}
hrct.Offset(-3, -3);
return hrct;
}
else
return wxRect();
}
//----------------------------------------------------------------------------------//
// Private functions
//----------------------------------------------------------------------------------//
void wxSFShapeHandle::_OnBeginDrag(const wxPoint& pos)
{
m_nPrevPos = m_nStartPos = m_nCurrPos = pos;
if(m_pParentShape)m_pParentShape->OnBeginHandle(*this);
}
void wxSFShapeHandle::_OnDragging(const wxPoint& pos)
{
if(m_fVisible && m_pParentShape && m_pParentShape->ContainsStyle(wxSFShapeBase::sfsSIZE_CHANGE))
{
if(pos != m_nPrevPos)
{
wxRect prevRct = m_pParentShape->GetBoundingBox();
m_nCurrPos = pos;
switch(m_nType)
{
case hndLEFTTOP:
if((pos.x < prevRct.GetRight()) && (pos.y < prevRct.GetBottom()))
m_pParentShape->_OnHandle(*this);
break;
case hndTOP:
if(pos.y < prevRct.GetBottom())
m_pParentShape->_OnHandle(*this);
break;
case hndRIGHTTOP:
if((pos.x > prevRct.GetLeft()) && (pos.y < prevRct.GetBottom()))
m_pParentShape->_OnHandle(*this);
break;
case hndRIGHT:
if(pos.x > prevRct.GetLeft())
m_pParentShape->_OnHandle(*this);
break;
case hndRIGHTBOTTOM:
if((pos.x > prevRct.GetLeft()) && (pos.y > prevRct.GetTop()))
m_pParentShape->_OnHandle(*this);
break;
case hndBOTTOM:
if(pos.y > prevRct.GetTop())
m_pParentShape->_OnHandle(*this);
break;
case hndLEFTBOTTOM:
if((pos.x < prevRct.GetRight()) && (pos.y > prevRct.GetTop()))
m_pParentShape->_OnHandle(*this);
break;
case hndLEFT:
if(pos.x < prevRct.GetRight())
m_pParentShape->_OnHandle(*this);
break;
case hndLINESTART:
case hndLINEEND:
case hndLINECTRL:
m_pParentShape->_OnHandle(*this);
break;
default:
break;
}
}
m_nPrevPos = pos;
}
}
void wxSFShapeHandle::_OnEndDrag(const wxPoint& pos)
{
wxUnusedVar( pos );
if(m_pParentShape)m_pParentShape->OnEndHandle(*this);
}
void wxSFShapeHandle::_OnMouseMove(const wxPoint& pos)
{
if(m_fVisible)
{
if(Contains(pos))
{
if(!m_fMouseOver)
{
m_fMouseOver = true;
Refresh();
}
}
else
{
if(m_fMouseOver)
{
m_fMouseOver = false;
Refresh();
}
}
}
}

View File

@@ -0,0 +1,80 @@
/***************************************************************
* Name: SolidArrow.cpp
* Purpose: Implements solid arrow for line shapes
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/SolidArrow.h"
#include "wx/wxsf/CommonFcn.h"
// arrow shape
static const wxRealPoint arrow[3]={wxRealPoint(0,0), wxRealPoint(10,4), wxRealPoint(10,-4)};
using namespace wxSFCommonFcn;
XS_IMPLEMENT_CLONABLE_CLASS(wxSFSolidArrow, wxSFArrowBase);
wxSFSolidArrow::wxSFSolidArrow(void)
: wxSFArrowBase()
{
m_Fill = sfdvARROW_FILL;
m_Pen = sfdvARROW_BORDER;
MarkSerializableDataMembers();
}
wxSFSolidArrow::wxSFSolidArrow(wxSFShapeBase* parent)
: wxSFArrowBase(parent)
{
m_Fill = sfdvARROW_FILL;
m_Pen = sfdvARROW_BORDER;
MarkSerializableDataMembers();
}
wxSFSolidArrow::wxSFSolidArrow(const wxSFSolidArrow& obj)
: wxSFArrowBase(obj)
{
m_Fill = obj.m_Fill;
m_Pen = obj.m_Pen;
MarkSerializableDataMembers();
}
wxSFSolidArrow::~wxSFSolidArrow(void)
{
}
void wxSFSolidArrow::MarkSerializableDataMembers()
{
XS_SERIALIZE_EX(m_Fill, wxT("fill"), sfdvARROW_FILL);
XS_SERIALIZE_EX(m_Pen, wxT("border"), sfdvARROW_BORDER);
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFSolidArrow::Draw(const wxRealPoint &from, const wxRealPoint &to, wxDC& dc)
{
wxPoint rarrow[3];
TranslateArrow( rarrow, arrow, 3, from, to );
dc.SetPen(m_Pen);
dc.SetBrush(m_Fill);
dc.DrawPolygon(3, rarrow);
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}

View File

@@ -0,0 +1,390 @@
/***************************************************************
* Name: TextShape.cpp
* Purpose: Implements static text shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/TextShape.h"
#include "wx/wxsf/ShapeCanvas.h"
XS_IMPLEMENT_CLONABLE_CLASS(wxSFTextShape, wxSFRectShape);
wxSFTextShape::wxSFTextShape(void)
: wxSFRectShape()
{
m_Font = sfdvTEXTSHAPE_FONT;
m_Font.SetPointSize(12);
m_nLineHeight = 12;
m_TextColor = sfdvTEXTSHAPE_TEXTCOLOR;
m_sText = wxT("Text");
m_Fill = *wxTRANSPARENT_BRUSH;
m_Border = *wxTRANSPARENT_PEN;
m_nRectSize = wxRealPoint(0, 0);
MarkSerializableDataMembers();
UpdateRectSize();
}
wxSFTextShape::wxSFTextShape(const wxRealPoint& pos, const wxString& txt, wxSFDiagramManager* manager)
: wxSFRectShape(pos, wxRealPoint(0, 0), manager)
{
m_Font = sfdvTEXTSHAPE_FONT;
m_Font.SetPointSize(12);
m_nLineHeight = 12;
m_TextColor = sfdvTEXTSHAPE_TEXTCOLOR;
m_sText = txt;
m_Fill = *wxTRANSPARENT_BRUSH;
m_Border = *wxTRANSPARENT_PEN;
MarkSerializableDataMembers();
UpdateRectSize();
}
wxSFTextShape::wxSFTextShape(const wxSFTextShape& obj)
: wxSFRectShape(obj)
{
m_Font = obj.m_Font;
m_TextColor = obj.m_TextColor;
m_sText = obj.m_sText;
MarkSerializableDataMembers();
UpdateRectSize();
}
wxSFTextShape::~wxSFTextShape()
{
}
void wxSFTextShape::MarkSerializableDataMembers()
{
XS_SERIALIZE_EX(m_Font, wxT("font"), sfdvTEXTSHAPE_FONT);
XS_SERIALIZE_EX(m_TextColor, wxT("color"), sfdvTEXTSHAPE_TEXTCOLOR);
XS_SERIALIZE(m_sText, wxT("text"));
}
//----------------------------------------------------------------------------------//
// public virtual functions
//----------------------------------------------------------------------------------//
void wxSFTextShape::Update()
{
UpdateRectSize();
wxSFShapeBase::Update();
}
void wxSFTextShape::Scale(double x, double y, bool children)
{
// HINT: overload it for custom actions...
if((x > 0) && (y > 0))
{
double s = 1;
if(x == 1) s = y;
else if (y == 1) s = x;
else if(x >= y) s = x;
else
s = y;
double size = (double)m_Font.GetPointSize()*s;
if(size < 5)size = 5;
m_Font.SetPointSize((int)size);
UpdateRectSize();
// call default function implementation (needed for scaling of shape's children)
wxSFShapeBase::Scale(x, y, children);
}
}
void wxSFTextShape::OnHandle(wxSFShapeHandle& handle)
{
// HINT: overload it for custom actions...
wxRealPoint prevSize = GetRectSize();
// perform standard operations
switch(handle.GetType())
{
case wxSFShapeHandle::hndLEFT:
OnLeftHandle(handle);
break;
case wxSFShapeHandle::hndRIGHT:
OnRightHandle(handle);
break;
case wxSFShapeHandle::hndTOP:
OnTopHandle(handle);
break;
case wxSFShapeHandle::hndBOTTOM:
OnBottomHandle(handle);
break;
default:
break;
}
wxRealPoint newSize = m_nRectSize;
double sx = newSize.x / prevSize.x;
double sy = newSize.y / prevSize.y;
Scale(sx, sy);
switch(handle.GetType())
{
case wxSFShapeHandle::hndLEFT:
{
double dx = m_nRectSize.x - prevSize.x;
MoveBy(-dx, 0);
SerializableList::compatibility_iterator node = GetFirstChildNode();
while(node)
{
((wxSFShapeBase*)node->GetData())->MoveBy(-dx, 0);
node = node->GetNext();
}
}
break;
case wxSFShapeHandle::hndTOP:
{
double dy = m_nRectSize.y - prevSize.y;
MoveBy(0, -dy);
SerializableList::compatibility_iterator node = GetFirstChildNode();
while(node)
{
((wxSFShapeBase*)node->GetData())->MoveBy(0, -dy);
node = node->GetNext();
}
}
break;
default:
break;
}
wxSFShapeBase::OnHandle( handle );
}
//----------------------------------------------------------------------------------//
// public functions
//----------------------------------------------------------------------------------//
wxSize wxSFTextShape::GetTextExtent()
{
wxCoord w = -1, h = -1;
if(m_pParentManager && GetParentCanvas())
{
wxClientDC dc((wxWindow*)GetParentCanvas());
// calculate text extent
if( wxSFShapeCanvas::IsGCEnabled() )
{
#if wxUSE_GRAPHICS_CONTEXT
double wd = -1, hd = -1, d = 0, e = 0;
wxGraphicsContext *pGC = wxGraphicsContext::Create( dc );
pGC->SetFont( m_Font, *wxBLACK );
// we must use string tokenizer to inspect all lines of possible multiline text
h = 0;
wxString sLine;
wxStringTokenizer tokens( m_sText, wxT("\n\r"), wxTOKEN_RET_EMPTY );
while( tokens.HasMoreTokens() )
{
sLine = tokens.GetNextToken();
pGC->GetTextExtent( sLine, &wd, &hd, &d, &e );
h += (hd + e);
if( (wd + d) > w ) w = (wd + d);
}
m_nLineHeight = (hd + e);
pGC->SetFont( wxNullFont, *wxBLACK );
#endif
}
else
{
dc.SetFont(m_Font);
dc.GetMultiLineTextExtent(m_sText, &w, &h, &m_nLineHeight);
dc.SetFont(wxNullFont);
}
}
else
{
w = (int)m_nRectSize.x;
h = (int)m_nRectSize.y;
wxStringTokenizer tokens(m_sText, wxT("\n\r"), wxTOKEN_RET_EMPTY);
m_nLineHeight = int(m_nRectSize.y/tokens.CountTokens());
}
/*if( wxSFShapeCanvas::IsGCEnabled() )
{
return wxSize((wxCoord)(wd + d), (wxCoord)(hd + e));
}
else*/
return wxSize(w, h);
}
void wxSFTextShape::UpdateRectSize()
{
wxSize tsize = GetTextExtent();
if(tsize.IsFullySpecified())
{
if(tsize.x <= 0) tsize.x = 1;
if(tsize.y <= 0) tsize.y = 1;
m_nRectSize.x = (double)tsize.x;
m_nRectSize.y = (double)tsize.y;
}
}
void wxSFTextShape::SetText(const wxString& txt)
{
m_sText = txt;
UpdateRectSize();
}
void wxSFTextShape::SetFont(const wxFont& font)
{
m_Font = font;
UpdateRectSize();
}
//----------------------------------------------------------------------------------//
// protected virtual functions
//----------------------------------------------------------------------------------//
void wxSFTextShape::DrawNormal(wxDC& dc)
{
wxSFRectShape::DrawNormal(dc);
DrawTextContent(dc);
}
void wxSFTextShape::DrawHover(wxDC& dc)
{
wxSFRectShape::DrawHover(dc);
DrawTextContent(dc);
}
void wxSFTextShape::DrawHighlighted(wxDC& dc)
{
wxSFRectShape::DrawHighlighted(dc);
DrawTextContent(dc);
}
void wxSFTextShape::DrawShadow(wxDC& dc)
{
// HINT: overload it for custom actions...
wxColour nCurrColor = m_TextColor;
m_TextColor = GetParentCanvas()->GetShadowFill().GetColour();
wxRealPoint nOffset = GetParentCanvas()->GetShadowOffset();
MoveBy(nOffset);
DrawTextContent(dc);
MoveBy(-nOffset.x, -nOffset.y);
m_TextColor = nCurrColor;
}
void wxSFTextShape::OnLeftHandle(wxSFShapeHandle& handle)
{
// HINT: overload it for custom actions...
m_nRectSize.x -= ((double)handle.GetPosition().x - GetAbsolutePosition().x);
//m_nRectSize.x -= (double)handle.GetDelta().x;
}
void wxSFTextShape::OnTopHandle(wxSFShapeHandle& handle)
{
// HINT: overload it for custom actions...
m_nRectSize.y -= ((double)handle.GetPosition().y - GetAbsolutePosition().y);
//m_nRectSize.y -= (double)handle.GetDelta().y;
}
void wxSFTextShape::OnBottomHandle(wxSFShapeHandle& handle)
{
// HINT: overload it for custom actions...
m_nRectSize.y = handle.GetPosition().y - GetAbsolutePosition().y;
}
void wxSFTextShape::OnRightHandle(wxSFShapeHandle& handle)
{
// HINT: overload it for custom actions...
m_nRectSize.x =handle.GetPosition().x - GetAbsolutePosition().x;
}
//----------------------------------------------------------------------------------//
// protected functions
//----------------------------------------------------------------------------------//
void wxSFTextShape::DrawTextContent(wxDC& dc)
{
wxString line;
int i = 0;
dc.SetBrush(m_Fill);
dc.SetBackgroundMode(wxTRANSPARENT);
/*#ifdef __WXMSW__
if(m_Fill.GetStyle() == wxTRANSPARENT)
{
dc.SetBackgroundMode(wxTRANSPARENT);
}
else
{
dc.SetBackgroundMode(wxSOLID);
dc.SetTextBackground(m_Fill.GetColour());
}
#endif*/
dc.SetTextForeground(m_TextColor);
dc.SetFont(m_Font);
wxRealPoint pos = GetAbsolutePosition();
// draw all text lines
wxStringTokenizer tokens(m_sText, wxT("\n\r"), wxTOKEN_RET_EMPTY);
while(tokens.HasMoreTokens())
{
line = tokens.GetNextToken();
dc.DrawText(line, (int)pos.x, (int)pos.y + i*m_nLineHeight);
i++;
}
dc.SetFont(wxNullFont);
dc.SetBrush(wxNullBrush);
}

View File

@@ -0,0 +1,45 @@
/***************************************************************
* Name: TextShapeXml.cpp
* Purpose: Implements text shape's serialization capability
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include "wx/wxsf/TextShape.h"
#include "wx/wxsf/CommonFcn.h"
//----------------------------------------------------------------------------------//
// Serialization
//----------------------------------------------------------------------------------//
wxXmlNode * wxSFTextShape::Serialize(wxXmlNode* node)
{
// HINT: overload it for custom actions...
if(node)
{
node = wxSFShapeBase::Serialize(node);
}
return node;
}
void wxSFTextShape::Deserialize(wxXmlNode* node)
{
// HINT: overload it for custom actions...
wxSFShapeBase::Deserialize(node);
UpdateRectSize();
}

View File

@@ -0,0 +1,256 @@
/***************************************************************
* Name: Thumbnail.h
* Purpose: Implements canvas thumbnail class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2009-06-09
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#include "wx_pch.h"
#ifdef _DEBUG_MSVC
#define new DEBUG_NEW
#endif
#include <wx/dcbuffer.h>
#include "wx/wxsf/Thumbnail.h"
#include "wx/wxsf/BitmapShape.h"
BEGIN_EVENT_TABLE(wxSFThumbnail, wxPanel)
EVT_PAINT( wxSFThumbnail::_OnPaint )
EVT_ERASE_BACKGROUND( wxSFThumbnail::_OnEraseBackground )
EVT_MOTION( wxSFThumbnail::_OnMouseMove )
EVT_LEFT_DOWN( wxSFThumbnail::_OnLeftDown )
EVT_RIGHT_DOWN( wxSFThumbnail::_OnRightDown )
EVT_TIMER( wxSFThumbnail::ID_UPDATETIMER, wxSFThumbnail::_OnTimer )
EVT_UPDATE_UI( wxSFThumbnail::IDM_SHOWELEMENTS, wxSFThumbnail::_OnUpdateShowElements )
EVT_UPDATE_UI( wxSFThumbnail::IDM_SHOWCONNECTIONS, wxSFThumbnail::_OnUpdateShowConnections )
EVT_MENU( wxSFThumbnail::IDM_SHOWELEMENTS, wxSFThumbnail::_OnShowElements )
EVT_MENU( wxSFThumbnail::IDM_SHOWCONNECTIONS, wxSFThumbnail::_OnShowConnections )
END_EVENT_TABLE()
//----------------------------------------------------------------------------------//
// constructor and destructor
//----------------------------------------------------------------------------------//
wxSFThumbnail::wxSFThumbnail(wxWindow *parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(200, 150), wxTAB_TRAVERSAL | wxFULL_REPAINT_ON_RESIZE )
{
SetExtraStyle( wxWS_EX_BLOCK_EVENTS );
SetSizeHints( wxSize(10, 10), wxDefaultSize );
m_pCanvas = NULL;
m_nScale = 1;
m_nThumbStyle = tsSHOW_ELEMENTS | tsSHOW_CONNECTIONS;
m_UpdateTimer.SetOwner(this, ID_UPDATETIMER);
}
wxSFThumbnail::~wxSFThumbnail()
{
m_pCanvas = NULL;
m_UpdateTimer.Stop();
}
//----------------------------------------------------------------------------------//
// public functions
//----------------------------------------------------------------------------------//
void wxSFThumbnail::SetCanvas(wxSFShapeCanvas* canvas)
{
m_pCanvas = canvas;
if( m_pCanvas ) m_UpdateTimer.Start(100);
else
{
m_UpdateTimer.Stop();
Refresh(false);
}
}
void wxSFThumbnail::DrawContent(wxDC& dc)
{
// HINT: overload it for custom actions...
wxSFShapeBase *pShape;
SerializableList::compatibility_iterator node = m_pCanvas->GetDiagramManager()->GetRootItem()->GetFirstChildNode();
while( node )
{
pShape = wxDynamicCast( node->GetData(), wxSFShapeBase );
if( pShape )
{
if( (m_nThumbStyle & tsSHOW_CONNECTIONS) && pShape->IsKindOf(CLASSINFO(wxSFLineShape)) ) pShape->Draw( dc, sfWITHOUTCHILDREN );
else if( m_nThumbStyle & tsSHOW_ELEMENTS )
{
if( pShape->IsKindOf(CLASSINFO(wxSFBitmapShape)) )
{
dc.SetPen( wxPen( *wxBLACK, 1, wxDOT) );
dc.SetBrush( *wxWHITE_BRUSH );
dc.DrawRectangle( pShape->GetBoundingBox() );
dc.SetBrush( wxNullBrush );
dc.SetPen( wxNullPen );
}
else if( !pShape->IsKindOf(CLASSINFO(wxSFLineShape)) ) pShape->Draw( dc, sfWITHOUTCHILDREN );
}
}
node = node->GetNext();
}
}
//----------------------------------------------------------------------------------//
// protected event handlers
//----------------------------------------------------------------------------------//
void wxSFThumbnail::_OnEraseBackground(wxEraseEvent& event)
{
wxUnusedVar( event );
// do nothing to eliminate flickering on Windows
}
void wxSFThumbnail::_OnLeftDown(wxMouseEvent& event)
{
m_nPrevMousePos = event.GetPosition();
}
void wxSFThumbnail::_OnRightDown(wxMouseEvent& event)
{
wxMenu menuPopup;
menuPopup.AppendCheckItem( IDM_SHOWELEMENTS, wxT("Show elements") );
menuPopup.AppendCheckItem( IDM_SHOWCONNECTIONS, wxT("Show connections") );
PopupMenu( &menuPopup, event.GetPosition() );
}
void wxSFThumbnail::_OnMouseMove(wxMouseEvent& event)
{
if( m_pCanvas && IsShown() && event.Dragging() )
{
int ux, uy;
m_pCanvas->GetScrollPixelsPerUnit( &ux, &uy );
wxPoint szDelta = event.GetPosition() - m_nPrevMousePos;
wxSize szCanvasOffset = GetCanvasOffset();
m_pCanvas->Scroll( (double(szDelta.x)/m_nScale + szCanvasOffset.x)/ux, (double(szDelta.y)/m_nScale + szCanvasOffset.y)/uy );
m_nPrevMousePos = event.GetPosition();
Refresh(false);
}
}
void wxSFThumbnail::_OnPaint(wxPaintEvent& event)
{
wxUnusedVar( event );
#if wxVERSION_NUMBER < 2900 && wxUSE_GRAPHICS_CONTEXT
bool fGCEnabled = wxSFShapeCanvas::IsGCEnabled();
wxSFScaledDC::EnableGC( false );
#endif
wxBufferedPaintDC dc(this);
// clear background
dc.SetBackground( wxBrush(wxColour(150, 150, 150)) );
dc.Clear();
if( m_pCanvas )
{
wxSize szCanvas = m_pCanvas->GetClientSize();
wxSize szVirtCanvas = m_pCanvas->GetVirtualSize();
wxSize szCanvasOffset = GetCanvasOffset();
wxSize szThumb = GetClientSize();
// scale and copy bitmap to DC
double cx = szVirtCanvas.x, cy = szVirtCanvas.y, tx = szThumb.x, ty = szThumb.y;
if( (tx/ty) > (cx/cy) ) m_nScale = ty/cy;
else
m_nScale = tx/cx;
// draw virtual canvas area
dc.SetPen(*wxWHITE_PEN);
dc.SetBrush( wxBrush(wxColour(240, 240, 240)) );
dc.DrawRectangle(0, 0, double(szVirtCanvas.x)*m_nScale, double(szVirtCanvas.y)*m_nScale);
// draw top level shapes
wxSFScaledDC sdc( (wxWindowDC*)&dc, m_nScale * m_pCanvas->GetScale() );
this->DrawContent( sdc );
// draw canvas client area
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(double(szCanvasOffset.x)*m_nScale, double(szCanvasOffset.y)*m_nScale, double(szCanvas.x)*m_nScale, double(szCanvas.y)*m_nScale);
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
}
dc.SetBackground( wxNullBrush );
#if wxVERSION_NUMBER < 2900 && wxUSE_GRAPHICS_CONTEXT
wxSFScaledDC::EnableGC( fGCEnabled );
#endif
}
void wxSFThumbnail::_OnTimer(wxTimerEvent& event)
{
wxUnusedVar( event );
if( m_pCanvas && IsShown() ) Refresh(false);
}
void wxSFThumbnail::_OnShowConnections(wxCommandEvent& event)
{
wxUnusedVar( event );
if( m_nThumbStyle & tsSHOW_CONNECTIONS ) m_nThumbStyle &= ~tsSHOW_CONNECTIONS;
else
m_nThumbStyle |= tsSHOW_CONNECTIONS;
}
void wxSFThumbnail::_OnShowElements(wxCommandEvent& event)
{
wxUnusedVar( event );
if( m_nThumbStyle & tsSHOW_ELEMENTS ) m_nThumbStyle &= ~tsSHOW_ELEMENTS;
else
m_nThumbStyle |= tsSHOW_ELEMENTS;
}
void wxSFThumbnail::_OnUpdateShowConnections(wxUpdateUIEvent& event)
{
event.Check( m_nThumbStyle & tsSHOW_CONNECTIONS );
}
void wxSFThumbnail::_OnUpdateShowElements(wxUpdateUIEvent& event)
{
event.Check( m_nThumbStyle & tsSHOW_ELEMENTS );
}
//----------------------------------------------------------------------------------//
// protected functions
//----------------------------------------------------------------------------------//
wxSize wxSFThumbnail::GetCanvasOffset()
{
if( m_pCanvas )
{
int ux, uy, offsetx, offsety;
m_pCanvas->GetScrollPixelsPerUnit( &ux, &uy );
m_pCanvas->GetViewStart( &offsetx, &offsety );
return wxSize( offsetx*ux, offsety*uy );
}
return wxSize();
}

View File

@@ -0,0 +1,60 @@
--*****************************************************************************
--* Author: Michal Bližňák
--* Date: 18/11/2007
--* Version: 1.00
--*
--* NOTES:
--* - use the '/' slash for all paths.
--*****************************************************************************
dofile('../build/premake/scripts/init.lua')
--******* Initial Setup ************
--* Most of the setting are set here.
--**********************************
-- Set the name of your package.
package.name = "wxSF"
-- Set this if you want a different name for your target than the package's name.
targetName = "wxsf"
-- Set the kind of package you want to create.
-- Options: exe | winexe | lib | dll
if( options["shared"] ) then
package.kind = "dll"
else
package.kind = "lib"
end
-- Setup the package compiler settings.
if( options["shared"] ) then
package.defines = { "WXMAKINGDLL_WXSF", "WXMAKINGDLL_WXXS" }
end
if ( target == "vs2005" ) then
-- Windows and Visual C++ 2005
table.insert(package.defines,"_CRT_SECURE_NO_DEPRECATE" )
end
if( target == "vs2003" or target == "vs2005" ) then
table.insert( package.defines, "_DISWARNINGS_MSVC" )
table.insert(package.config["Debug"].defines, "_DEBUG_MSVC")
end
if( ( target == "vs2003" or target == "vs2005" ) and options["no-builtin-wchar"] ) then
table.insert(package.buildoptions, "/Zc:wchar_t-")
end
-- Set the files to include.
package.files = { matchrecursive( "*.cpp", "*.h", "*.rc", "../include/*.h" ) }
if ( not windows ) then
table.insert( package.excludes, matchrecursive( "*.rc" ) )
end
-- Set the include paths.
package.includepaths = { "../include", "../src" }
-- Set precompiled headers support
package.pchheader = "wx_pch.h"
package.pchsource = "wx_pch.cpp"
dofile('../build/premake/scripts/wxpresets.lua')

View File

@@ -0,0 +1,69 @@
/* XPM */
static const char * NoSource_xpm[] = {
"100 50 16 1",
" c #000000",
". c #800000",
"+ c #008000",
"@ c #808000",
"# c #000080",
"$ c #800080",
"% c #008080",
"& c #808080",
"* c #C0C0C0",
"= c #FF0000",
"- c #00FF00",
"; c #FFFF00",
"> c #0000FF",
", c #FF00FF",
"' c #00FFFF",
") c #FFFFFF",
"====================================================================================================",
"=)==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)=",
"=)))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))=",
"=)))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))=",
"=)))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))=",
"=)))))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))))=",
"=)))))))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))))))=",
"=)))))))))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))))))))=",
"=)))))))))))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))))))))))=",
"=)))))))))))))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))))))))))))=",
"=)))))))))))))))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))))))))))))))=",
"=)))))))))))))))))))====)===)))))))))===))))))))))))))))))))))))))))))))))))==)))))))))))))))))))))=",
"=)))))))))))))))))))===)====)))))))))===))))))))))))))))))))))))))))))))))==)))))))))))))))))))))))=",
"=)))))))))))))))))))===))===)===)==))===))======)==))))===)))===)===)======)==)))))))))))))))))))))=",
"=)))))))))))))))))))===))===========)===)===)=======))=====))===)===)==========))))))))))))))))))))=",
"=)))))))))))))))))))===))===)===)===)======))===)===)===)===))=========)===)===))))))))))))))))))))=",
"=)))))))))))))))))))===))===)=======)======))===)===)===)===))=========)===)===))))))))))))))))))))=",
"=)))))))))))))))))))===))===)===)===)=======)===)===)===)===))====)====)===)===))))))))))))))))))))=",
"=))))))))))))))))))))======))===)=======)===)===)===))=====)))===)))==))===)===))))))))))))))))))))=",
"=)))))))))))))))))))))====)))===)===)===))======)===)))===))==)==)))==))===)===))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))))))))))))==))))))))))))))))==)))))))))))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))))))))))))))==))))))))))))==)))))))))))))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))))))))))))))))==))))))))==)))))))))))))))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))))))))))))))))))==))))==)))))))))))))))))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))))))))))))))))))))====)))))))))))))))))))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))))))))))))))))))))====)))))))))))))))))))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))))))))))))))))))==))))==)))))))))))))))))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))))))))))))))))==))))))))==)))))))))))))))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))))))))))))))==))))))))))))==)))))))))))))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))===)))))))==))))))))))))))))==)))))))))))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))))))))))==))))))))))))))))))))==)))))))))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))===)======)===)))=====)))==)===)======)))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))===)===========)=======)=======))=====)))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))=======)===)===)==))===)===)===)===)===))))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))))===)===)===)===)))=====)===)===)========)))))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))))=====)===)===)===)===)===)===)===)===)))))==)))))))))))))))))))))))))))=",
"=)))))))))))))))))))))))))==))===)===)===)===)===)===)=======))======)))==)))))))))))))))))))))))))=",
"=)))))))))))))))))))))))==))))===)===)===)===))======))==)===)))====))))))==)))))))))))))))))))))))=",
"=)))))))))))))))))))))==))))))))))))))))))))))))))))))))))===)))))))))))))))==)))))))))))))))))))))=",
"=)))))))))))))))))))==))))))))))))))))))))))))))))))))======))))))))))))))))))==)))))))))))))))))))=",
"=)))))))))))))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))))))))))))=",
"=)))))))))))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))))))))))=",
"=)))))))))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))))))))=",
"=)))))))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))))))=",
"=)))))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))))=",
"=)))))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))))=",
"=)))))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))))=",
"=)))==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)))=",
"=)==))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))==)=",
"===================================================================================================="};

View File

@@ -0,0 +1,17 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wxSF.rc
// Purpose: a standard Win32 .rc file for the wxWidgets
// Author: Ryan Pusztai
// Modified by: Ryan Mulder
// Created: 11.21.05
// Copyright: (c) 2005 RJP Computing <support@rjpcomputing.com>
/////////////////////////////////////////////////////////////////////////////
// set this to 1 if you don't want to use manifest resource (manifest resource
// is needed to enable visual styles on Windows XP - see docs/msw/winxp.txt
// for more information)
#define wxUSE_NO_MANIFEST 0
// this is not always needed but doesn't hurt (except making the executable
// very slightly larger): this file contains the standard icons, cursors, ...
#include "wx/msw/wx.rc"

View File

@@ -0,0 +1 @@
#include "wx_pch.h"

View File

@@ -0,0 +1,44 @@
/***************************************************************
* Name: wx_pch.h
* Purpose: Header to create Pre-Compiled Header (PCH)
* Author: Michal Bližňák ()
* Created: 2007-03-04
* Copyright: Michal Bližňák ()
* License:
**************************************************************/
#ifndef WX_PCH_H_INCLUDED
#define WX_PCH_H_INCLUDED
#ifdef _DISWARNINGS_MSVC
//#pragma warning( disable : 4100 )
#pragma warning( disable : 4251 )
#pragma warning( disable : 4275 )
#endif
// debug memory allocation enhancement (see next tip)
#ifdef _DEBUG_MSVC
#ifdef _DEBUG
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
#else
#define DEBUG_NEW new
#endif
#endif
// basic wxWidgets headers
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#ifdef WX_PRECOMP
// put here all your rarely-changing header files
#endif // WX_PRECOMP
#endif // WX_PCH_H_INCLUDED

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff