#include "wx/printdlg.h"
#include "wx/generic/printps.h"
#include "wx/generic/prntdlgg.h"
+#include "wx/dataobj.h"
// skip the following defines if embedded in M application
#ifndef M_BASEDIR
# define WXLO_DEFAULTFONTSIZE 12
#endif
+#ifdef __WXMSW__
+# define WXLO_BITMAP_FORMAT wxBITMAP_TYPE_BMP
+#else
+# define WXLO_BITMAP_FORMAT wxBITMAP_TYPE_PNG
+#endif
+
/// Types of currently supported layout objects.
enum wxLayoutObjectType
struct UserData
{
UserData() { m_refcount = 1; }
- void IncRef(void) { m_refcount++; }
- void DecRef(void) { m_refcount--; if(m_refcount == 0) delete this;}
+ inline void IncRef(void) { m_refcount++; }
+ inline void DecRef(void) { m_refcount--; if(m_refcount == 0) delete this;}
+ inline void SetLabel(const wxString &l) { m_label = l; }
+ inline const wxString & GetLabel(void) const { return m_label; }
private:
int m_refcount;
+ wxString m_label;
protected:
virtual ~UserData() { wxASSERT(m_refcount == 0); }
/// prevents gcc from generating stupid warnings
/** Tells the object about some user data. This data is associated
with the object and will be deleted at destruction time.
+ It is reference counted.
*/
void SetUserData(UserData *data)
{
if(m_UserData)
m_UserData->DecRef();
m_UserData = data;
- m_UserData->IncRef();
+ if(m_UserData)
+ m_UserData->IncRef();
}
- /** Return the user data. */
- void * GetUserData(void) const { if(m_UserData) m_UserData->IncRef(); return m_UserData; }
+ /** Return the user data.
+ Increments the object's reference count. When no longer needed,
+ caller must call DecRef() on the pointer returned.
+ */
+ UserData * GetUserData(void) const { if(m_UserData) m_UserData->IncRef(); return m_UserData; }
/** Makes a copy of this object.
*/
virtual wxLayoutObject *Copy(void) = 0;
+
+ /** Clipboard support function. Read and write objects to
+ strings. */
+ //@{
+ /// Writes the object to the string.
+ virtual void Write(wxString &ostr) = 0;
+ /** Reads an object.
+ @param str stream to read from, will bee changed
+ @return true on success
+ */
+ static wxLayoutObject *Read(wxString &istr);
+ //@}
protected:
/// optional data for application's use
UserData *m_UserData;
class wxLayoutObjectText : public wxLayoutObject
{
public:
- wxLayoutObjectText(const wxString &txt);
-
+ wxLayoutObjectText(const wxString &txt = "");
+
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
virtual void Layout(wxDC &dc, class wxLayoutList *llist);
virtual void Draw(wxDC &dc, wxPoint const &coords,
*/
virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const;
+ virtual void Write(wxString &ostr);
+ static wxLayoutObjectText *Read(wxString &istr);
#ifdef WXLAYOUT_DEBUG
virtual void Debug(void);
class wxLayoutObjectIcon : public wxLayoutObject
{
public:
- wxLayoutObjectIcon(wxBitmap *icon);
+ wxLayoutObjectIcon(wxBitmap *icon = NULL);
wxLayoutObjectIcon(wxBitmap const &icon);
- ~wxLayoutObjectIcon() { delete m_Icon; }
+ ~wxLayoutObjectIcon() { if(m_Icon) delete m_Icon; }
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
virtual void Layout(wxDC &dc, class wxLayoutList *llist);
/** Makes a copy of this object.
*/
virtual wxLayoutObject *Copy(void);
+ virtual void Write(wxString &ostr);
+ static wxLayoutObjectIcon *Read(wxString &istr);
private:
wxBitmap *m_Icon;
};
int iul = -1,
wxColour *fg = NULL,
wxColour *bg = NULL);
- wxColour * GetBGColour() const
+ wxColour & GetBGColour()
{
- return fg_valid ? new
- wxColour(bg_red,bg_green,bg_blue)
- : wxWHITE;
+ return m_bg;
}
- wxFont *GetFont(wxLayoutStyleInfo *);
+ wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right);
/// Font change parameters.
int size, family, style, weight, underline;
- /// Is foreground colour valid to bet set?
- bool fg_valid;
- /// Is background colour valid to bet set?
- bool bg_valid;
- /// Foreground colour RGB values.
- unsigned fg_red, fg_green, fg_blue;
- /// Background colour RGB values.
- unsigned bg_red, bg_green, bg_blue;
+ /// Colours
+ wxColour m_bg, m_fg;
+ int m_fg_valid, m_bg_valid; // bool, but must be int!
+};
+
+
+class wxFontCacheEntry
+{
+public:
+ wxFontCacheEntry(int family, int size, int style, int weight,
+ bool underline)
+ {
+ m_Family = family; m_Size = size; m_Style = style;
+ m_Weight = weight; m_Underline = underline;
+ m_Font = new wxFont(m_Size, m_Family,
+ m_Style, m_Weight, m_Underline);
+ }
+ bool Matches(int family, int size, int style, int weight,
+ bool underline) const
+ {
+ return size == m_Size && family == m_Family
+ && style == m_Style && weight == m_Weight
+ && underline == m_Underline;
+ }
+ wxFont & GetFont(void) { return *m_Font; }
+ ~wxFontCacheEntry()
+ {
+ delete m_Font;
+ }
+private:
+ wxFont *m_Font;
+ int m_Family, m_Size, m_Style, m_Weight;
+ bool m_Underline;
+};
+
+KBLIST_DEFINE(wxFCEList, wxFontCacheEntry);
+
+class wxFontCache
+{
+public:
+ wxFont & GetFont(int family, int size, int style, int weight,
+ bool underline);
+ wxFont & GetFont(wxLayoutStyleInfo const &si)
+ {
+ return GetFont(si.family, si.size, si.style, si.weight, si.underline);
+ }
+private:
+ wxFCEList m_FontList;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
class wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1);
- wxLayoutObjectCmd(int size = -1,
- int family = -1,
+ wxLayoutObjectCmd(int family = -1,
+ int size = -1,
int style = -1,
int weight = -1,
int underline = -1,
/** Makes a copy of this object.
*/
virtual wxLayoutObject *Copy(void);
+ virtual void Write(wxString &ostr);
+ static wxLayoutObjectCmd *Read(wxString &istr);
private:
- /// the font to use
- wxFont *m_font;
wxLayoutStyleInfo *m_StyleInfo;
};
#ifdef WXLAYOUT_DEBUG
void Debug(void);
#endif
-
+ wxLayoutStyleInfo &GetStyleInfo() { return m_StyleInfo; }
+
+ /// Returns dirty state
+ bool IsDirty(void) const { return m_Dirty; }
+ /// Marks line as diry.
+ void MarkDirty(void) { m_Dirty = true; }
private:
/// Destructor is private. Use DeleteLine() to remove it.
~wxLayoutLine();
wxLayoutLine *m_Previous;
/// Pointer to next line if it exists.
wxLayoutLine *m_Next;
+ /// A StyleInfo structure, holding the current settings.
+ wxLayoutStyleInfo m_StyleInfo;
/// Just to suppress gcc compiler warnings.
friend class dummy;
private:
{ MoveCursorHorizontally(-m_CursorPos.x); }
/// Returns current cursor position.
- wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; }
- wxPoint GetCursorPos() const { return m_CursorPos; }
+ const wxPoint &GetCursorPos(wxDC &dc) const { return m_CursorPos; }
+ const wxPoint &GetCursorPos() const { return m_CursorPos; }
//@}
bool Insert(wxString const &text);
/// Insert some other object at current cursor position.
bool Insert(wxLayoutObject *obj);
+ /// Inserts objects at current cursor positions
+ bool Insert(wxLayoutList *llist);
+
/// Inserts a linebreak at current cursor position.
bool LineBreak(void);
/** Wraps the current line. Searches to the left of the cursor to
char const *bg = NULL);
/// changes to the next larger font size
inline void SetFontLarger(void)
- { SetFont(-1,(12*m_FontPtSize)/10); }
+ { SetFont(-1,(12*m_CurrentSetting.size)/10); }
/// changes to the next smaller font size
inline void SetFontSmaller(void)
- { SetFont(-1,(10*m_FontPtSize)/12); }
+ { SetFont(-1,(10*m_CurrentSetting.size)/12); }
/// set font family
inline void SetFontFamily(int family) { SetFont(family); }
anywhere.
@return the default settings of the list
*/
- wxLayoutStyleInfo *GetDefaults(void) { return m_DefaultSetting ; }
+ wxLayoutStyleInfo *GetDefaults(void) { return &m_DefaultSetting ; }
+ wxLayoutStyleInfo *GetStyleInfo(void) { return &m_CurrentSetting ; }
//@}
/**@name Drawing */
actually draw it.
@param dc the wxDC to draw on
@param bottom optional y coordinate where to stop calculating
+ @param forceAll force re-layout of all lines
*/
- void Layout(wxDC &dc, CoordType bottom = -1);
+ void Layout(wxDC &dc, CoordType bottom = -1, bool forceAll = false);
/** Calculates new sizes for everything in the list, like Layout()
but this is needed after the list got changed.
//@}
/// Begin selecting text.
- void StartSelection(void);
+ void StartSelection(wxPoint cpos = wxPoint(-1,-1));
// Continue selecting text
- void ContinueSelection(void);
+ void ContinueSelection(wxPoint cpos = wxPoint(-1,-1));
/// End selecting text.
- void EndSelection(void);
+ void EndSelection(wxPoint cpos = wxPoint(-1,-1));
/// Are we still selecting text?
bool IsSelecting(void);
bool IsSelected(const wxPoint &cursor);
- /// Return the selection as a wxLayoutList:
- wxLayoutList *GetSelection(void);
+ /** Return the selection as a wxLayoutList.
+ @param invalidate if true, the selection will be invalidated after this and can no longer be used.
+ @return Another layout list object holding the selection, must be freed by caller
+ */
+ wxLayoutList *GetSelection(class wxLayoutDataObject *wxldo = NULL, bool invalidate = TRUE);
/// Delete selected bit
void DeleteSelection(void);
wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0),
const wxPoint &to = wxPoint(-1,-1));
-
+
/// starts highlighting of text for selections
void StartHighlighting(wxDC &dc);
/// ends highlighting of text for selections
*/
int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
-
void ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc);
#ifdef WXLAYOUT_DEBUG
void Debug(void);
} m_Selection;
/** @name Font parameters. */
//@{
- int m_FontFamily, m_FontStyle, m_FontWeight;
- int m_FontPtSize;
- bool m_FontUnderline;
- /// colours:
- wxColour m_ColourFG;
- wxColour m_ColourBG;
+ /// this object manages the fonts for us
+ wxFontCache m_FontCache;
/// the default setting:
- wxLayoutStyleInfo *m_DefaultSetting;
+ wxLayoutStyleInfo m_DefaultSetting;
/// the current setting:
wxLayoutStyleInfo m_CurrentSetting;
//@}
};
-
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+ The wxLayoutDataObject for exporting data to the clipboard in our
+ own format.
+
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+class wxLayoutDataObject : public wxPrivateDataObject
+{
+public:
+ wxLayoutDataObject(void)
+ {
+ SetId("application/wxlayoutlist");
+ //m_format.SetAtom((GdkAtom) 222222);
+ }
+};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *