#include "kbList.h"
-#include <wx/wx.h>
-
-#ifndef WXDEBUG
-# define WXDEBUG
+#include "wx/wx.h"
+#include "wx/print.h"
+#include "wx/printdlg.h"
+#include "wx/generic/printps.h"
+#include "wx/generic/prntdlgg.h"
+
+// skip the following defines if embedded in M application
+#ifdef M_BASEDIR
+# ifdef DEBUG
+//# define WXLAYOUT_DEBUG
+# endif
+#else
+ // for testing only:
+# define WXLAYOUT_DEBUG
+ // The wxLayout classes can be compiled with std::string instead of wxString
+ //# define USE_STD_STRING
#endif
+#ifdef USE_STD_STRING
+# include <string>
+ typedef std::string String;
+# define Str(str)(str.c_str())
+#else
+ typedef wxString String;
+# define Str(str) str
+#endif
-enum wxLayoutObjectType { WXLO_TYPE_INVALID, WXLO_TYPE_TEXT, WXLO_TYPE_CMD, WXLO_TYPE_ICON, WXLO_TYPE_LINEBREAK };
+/// Types of currently supported layout objects.
+enum wxLayoutObjectType
+{ WXLO_TYPE_INVALID = 0, WXLO_TYPE_TEXT, WXLO_TYPE_CMD, WXLO_TYPE_ICON, WXLO_TYPE_LINEBREAK };
+/// Type used for coordinates in drawing.
typedef long CoordType;
class wxLayoutList;
class wxLayoutObjectBase;
-KBLIST_DEFINE(wxLayoutObjectList, wxLayoutObjectBase);
-KBLIST_DEFINE(wxLayoutOLinesList, wxLayoutObjectList::iterator);
-
+class wxDC;
+class wxColour;
+class wxFont;
+/** The base class defining the interface to each object which can be
+ part of the layout. Each object needs to draw itself and calculate
+ its size.
+*/
class wxLayoutObjectBase
{
public:
+ /// return the type of this object
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_INVALID; } ;
/** Draws an object.
@param dc the wxDC to draw on
virtual void Draw(wxDC &dc, wxPoint position, CoordType baseLine,
bool draw = true) {};
+ /** Calculates and returns the size of the object. May need to be
+ called twice to work.
+ @param baseLine pointer where to store the baseline position of
+ this object (i.e. the height from the top of the box to the
+ baseline)
+ @return the size of the object's box in pixels
+ */
virtual wxPoint GetSize(CoordType *baseLine) const { return
wxPoint(0,0); };
/// returns the number of cursor positions occupied by this object
virtual CoordType CountPositions(void) const { return 1; }
+ /// constructor
wxLayoutObjectBase() { m_UserData = NULL; }
- virtual ~wxLayoutObjectBase() {}
-#ifdef WXDEBUG
+ /// note: any user data will be freed at the time the object is deleted
+ virtual ~wxLayoutObjectBase() { if(m_UserData) delete m_UserData; }
+#ifdef WXLAYOUT_DEBUG
virtual void Debug(void);
#endif
+ /** Tells the object about some user data. This data is associated
+ with the object and will be deleted at destruction time.
+ */
void SetUserData(void *data) { m_UserData = data; }
+ /** Return the user data. */
void * GetUserData(void) const { return m_UserData; }
private:
/// optional data for application's use
void * m_UserData;
};
+/// Define a list type of wxLayoutObjectBase pointers.
+KBLIST_DEFINE(wxLayoutObjectList, wxLayoutObjectBase);
+
+
/// object for text block
class wxLayoutObjectText : public wxLayoutObjectBase
{
align text objects.
*/
virtual wxPoint GetSize(CoordType *baseLine) const;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
virtual void Debug(void);
#endif
- wxLayoutObjectText(const wxString &txt);
+ wxLayoutObjectText(const String &txt);
virtual CoordType CountPositions(void) const { return strlen(m_Text.c_str()); }
// for editing:
- wxString & GetText(void) { return m_Text; }
- void SetText(wxString const &text) { m_Text = text; }
+ String & GetText(void) { return m_Text; }
+ void SetText(String const &text) { m_Text = text; }
private:
- wxString m_Text;
+ String m_Text;
/// size of the box containing text
long m_Width, m_Height;
/// the position of the baseline counted from the top of the box
bool draw = true);
virtual wxPoint GetSize(CoordType *baseLine) const;
wxLayoutObjectIcon(wxIcon *icon);
+
private:
- wxIcon * m_Icon;
+ wxIcon *m_Icon;
};
/// for export to html:
bool underline,
wxColour const *fg, wxColour const *bg);
~wxLayoutObjectCmd();
- // caller must free pointer:
+ /// caller must free pointer:
wxLayoutStyleInfo *GetStyle(void) const ;
+ /// return the background colour for setting colour of window
+ wxColour const *GetBGColour(void) const { return m_ColourBG; }
private:
/// the font to use
wxFont *m_font;
};
+class wxLayoutPrintout;
+
/**
This class provides a high level abstraction to the wxFText
classes.
/// adds an object:
void AddObject(wxLayoutObjectBase *obj);
- void AddText(wxString const &txt);
+ void AddText(String const &txt);
void LineBreak(void);
void SetFont(int family, int size, int style,
wxColour const *bg);
void SetFont(int family=-1, int size = -1, int style=-1,
int weight=-1, int underline = -1,
- char const *fg = NULL,
- char const *bg = NULL);
+ char const *fg = (const char *) NULL,
+ char const *bg = (const char *) NULL);
+ inline void SetFontFamily(int family) { SetFont(family); }
+ inline void SetFontSize(int size) { SetFont(-1,size); }
+ inline void SetFontStyle(int style) { SetFont(-1,-1,style); }
+ inline void SetFontWeight(int weight) { SetFont(-1,-1,-1,weight); }
+ inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); }
+ inline void SetFontColour(char const *fg, char const *bg = (const char *) NULL) { SetFont(-1,-1,-1,-1,-1,fg,bg); }
+
+
/** Draw the list on a given DC.
@param findObject if true, return the object occupying the
position specified by coords
@param coords position where to find the object
+ @pageNo if > 0, print only that page of a document (for
+ printing)
+ @reallyDraw set this to false if you don't want to draw but just calculate the coordinates
@return if findObject == true, the object or NULL
*/
wxLayoutObjectBase *Draw(wxDC &dc, bool findObject = false,
- wxPoint const &coords = wxPoint(0,0));
+ wxPoint const &coords = wxPoint(0,0),
+ int pageNo = -1, bool reallyDraw = true);
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
void Debug(void);
+ void ShowCurrentObject();
#endif
void GetSize(CoordType *max_x, CoordType *max_y,
CoordType *lineHeight);
+
/**@name Functionality for editing */
//@{
/// set list editable or read only
- void SetEditable(bool editable = true) { m_Editable = true; }
- /// move cursor
- void MoveCursor(int dx = 0, int dy = 0);
+ void SetEditable(bool editable = true) { m_Editable = editable; }
+ /// return true if list is editable
+ bool IsEditable(void) const { return m_Editable; }
+ /// move cursor, returns true if it could move to the desired position
+ bool MoveCursor(int dx = 0, int dy = 0);
void SetCursor(wxPoint const &p) { m_CursorPosition = p; }
+ wxPoint GetCursor(void) const { return m_CursorPosition; }
/// delete one or more cursor positions
void Delete(CoordType count = 1);
- void Insert(wxString const &text);
+ void Insert(String const &text);
void Insert(wxLayoutObjectBase *obj);
- void Clear(void);
+ void Clear(int family = wxROMAN, int size=12, int style=wxNORMAL, int weight=wxNORMAL,
+ int underline=0, char const *fg="black", char const *bg="white");
+
+ /// return a pointer to the default settings:
+ wxLayoutObjectCmd const *GetDefaults(void) const { return m_DefaultSetting ; }
- //@}
+ wxLayoutObjectList::iterator FindCurrentObject(CoordType *offset = (CoordType *) NULL);
+ // get the length of the line with the object pointed to by i, offs
+ // only used to decide whether we are before or after linebreak
+ CoordType GetLineLength(wxLayoutObjectList::iterator i,
+ CoordType offs = 0);
+ wxLayoutPrintout *MakePrintout(wxString const &name);
+
+//@}
protected:
/// font parameters:
int m_FontFamily, m_FontStyle, m_FontWeight;
/// colours:
wxColour const * m_ColourFG;
wxColour const * m_ColourBG;
+ /// the default setting:
+ wxLayoutObjectCmd *m_DefaultSetting;
/// needs recalculation?
bool m_dirty;
bool m_Editable;
/// find the object to the cursor position and returns the offset
/// in there
- wxLayoutObjectList::iterator FindObjectCursor(wxPoint const &cpos, CoordType *offset = NULL);
- wxLayoutObjectList::iterator FindCurrentObject(CoordType *offset = NULL);
- // get the length of the line with the object pointed to by i
- CoordType GetLineLength(wxLayoutObjectList::iterator i);
+ wxLayoutObjectList::iterator FindObjectCursor(wxPoint *cpos, CoordType *offset = (CoordType *) NULL);
};
+class wxLayoutPrintout: public wxPrintout
+{
+ public:
+ wxLayoutPrintout(wxLayoutList &llist, wxString const & title = "My printout"):wxPrintout(title)
+ { m_llist = &llist; m_maxPage = 0; }
+ bool OnPrintPage(int page);
+ bool HasPage(int page);
+ bool OnBeginDocument(int startPage, int endPage);
+ void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int
+ *selPageTo);
+private:
+ wxLayoutList *m_llist;
+ int m_maxPage;
+};
+
#endif // WXLLIST_H