# define WXMENU_LAYOUT_DBLCLICK 1113
#endif
-#ifdef __WXDEBUG__
+// do not enable debug mode within Mahogany
+#if defined(__WXDEBUG__) && ! defined(M_BASEDIR)
# define WXLAYOUT_DEBUG
#endif
# define WXLO_TRACE(x)
#endif
-
+#define WXLO_DEBUG_URECT 0
#ifndef WXLO_DEFAULTFONTSIZE
# define WXLO_DEFAULTFONTSIZE 12
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_INVALID; }
/** Calculates the size of an object.
@param dc the wxDC to draw on
+ @param llist the wxLayoutList
*/
- virtual void Layout(wxDC &) = 0;
+ virtual void Layout(wxDC &dc, class wxLayoutList *llist) = 0;
/** Draws an object.
@param dc the wxDC to draw on
@param coords where to draw the baseline of the object.
+ @param wxllist pointer to wxLayoutList
@param begin if !=-1, from which position on to highlight it
@param end if begin !=-1, how many positions to highlight it
*/
virtual void Draw(wxDC & /* dc */,
wxPoint const & /* coords */,
+ class wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1) { }
wxLayoutObjectText(const wxString &txt);
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
- virtual void Layout(wxDC &dc);
+ virtual void Layout(wxDC &dc, class wxLayoutList *llist);
virtual void Draw(wxDC &dc, wxPoint const &coords,
+ class wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1);
/** Calculates and returns the size of the object.
~wxLayoutObjectIcon() { delete m_Icon; }
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
- virtual void Layout(wxDC &dc);
+ virtual void Layout(wxDC &dc, class wxLayoutList *llist);
virtual void Draw(wxDC &dc, wxPoint const &coords,
+ class wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1);
wxBitmap *m_Icon;
};
-/// for export to html:
+/** This structure holds all formatting information. Members which are
+ undefined (for a CmdObject this means: no change), are set to -1.
+*/
struct wxLayoutStyleInfo
{
- wxLayoutStyleInfo()
+ wxLayoutStyleInfo(int ifamily = -1,
+ int isize = -1,
+ int istyle = -1,
+ int iweight = -1,
+ int iul = -1,
+ wxColour *fg = NULL,
+ wxColour *bg = NULL);
+ wxColour & GetBGColour()
+ {
+ return m_bg;
+ }
+ wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right);
+ /// Font change parameters.
+ int size, family, style, weight, underline;
+ /// Colours
+ wxColour m_bg, m_fg;
+ bool m_fg_valid, m_bg_valid;
+};
+
+
+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()
{
- family = -1; // this marks the styleinfo as uninitialised
+ delete m_Font;
}
- int size, family, style, weight;
- bool underline;
- unsigned fg_red, fg_green, fg_blue;
- unsigned bg_red, bg_green, bg_blue;
+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;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
{
public:
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
- virtual void Layout(wxDC &dc);
+ virtual void Layout(wxDC &dc, class wxLayoutList *llist);
virtual void Draw(wxDC &dc, wxPoint const &coords,
+ class wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1);
- wxLayoutObjectCmd(int size, int family, int style, int weight,
- bool underline,
- wxColour &fg, wxColour &bg);
+ wxLayoutObjectCmd(int family = -1,
+ int size = -1,
+ int style = -1,
+ int weight = -1,
+ int underline = -1,
+ wxColour *fg = NULL,
+ wxColour *bg = NULL);
~wxLayoutObjectCmd();
/** Stores the current style in the styleinfo structure */
- void GetStyle(wxLayoutStyleInfo *si) const;
- /// return the background colour for setting colour of window
- wxColour &GetBGColour(void) { return m_ColourBG; }
+ wxLayoutStyleInfo * GetStyle(void) const;
/** Makes a copy of this object.
*/
virtual wxLayoutObject *Copy(void);
private:
- /// the font to use
- wxFont *m_font;
- /// foreground colour
- wxColour m_ColourFG;
- /// background colour
- wxColour m_ColourBG;
+ wxLayoutStyleInfo *m_StyleInfo;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
CoordType *offset,
bool *found = NULL) const ;
+ /** Finds text in this line.
+ @param needle the text to find
+ @param xpos the position where to start the search
+ @return the cursoor coord where it was found or -1
+ */
+ CoordType FindText(const wxString &needle, CoordType xpos = 0) const;
+
/** Get the first object in the list. This is used by the wxlparser
functions to export the list.
@return iterator to the first object
*/
wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos, bool
*found = NULL);
+
//@}
/**@name List traversal */
/// Recalculates the position of this line on the canvas.
wxPoint RecalculatePosition(wxLayoutList *llist);
+ /** Copies the contents of this line to another wxLayoutList
+ @param llist the wxLayoutList destination
+ @param from x cursor coordinate where to start
+ @param to x cursor coordinate where to stop, -1 for end of line
+ */
+ void Copy(wxLayoutList *llist,
+ CoordType from = 0,
+ CoordType to = -1);
+
#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:
/// Returns current cursor position.
wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; }
+ wxPoint GetCursorPos() const { return m_CursorPos; }
+
//@}
/**@name Editing functions.
//@}
+ /** Finds text in this list.
+ @param needle the text to find
+ @param cpos the position where to start the search
+ @return the cursoor coord where it was found or (-1,-1)
+ */
+ wxPoint FindText(const wxString &needle, const wxPoint &cpos = wxPoint(0,0)) const;
+
/**@name Formatting options */
//@{
/// sets font parameters
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); }
/// toggle underline flag
inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); }
/// set font colours by name
- inline void SetFontColour(char const *fg, char const *bg = NULL) { SetFont(-1,-1,-1,-1,-1,fg,bg); }
+ inline void SetFontColour(char const *fg, char const *bg = NULL)
+ { SetFont(-1,-1,-1,-1,-1,fg,bg); }
+ /// set font colours by colour
+ inline void SetFontColour(wxColour *fg, wxColour *bg = NULL)
+ { SetFont(-1,-1,-1,-1,-1,fg,bg); }
+
+
/**
Returns a pointer to the default settings.
This is only valid temporarily and should not be stored
anywhere.
@return the default settings of the list
*/
- wxLayoutObjectCmd *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);
+ // Continue selecting text
+ void ContinueSelection(void);
/// End selecting text.
void EndSelection(void);
/// Are we still selecting text?
bool IsSelecting(void);
bool IsSelected(const wxPoint &cursor);
+ /// Return the selection as a wxLayoutList:
+ wxLayoutList *GetSelection(void);
+ /// 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
+ void EndHighlighting(wxDC &dc);
+
/** Tests whether this layout line is selected and needs
highlighting.
@param line to test for
*/
int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
-
+
+ void ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc);
#ifdef WXLAYOUT_DEBUG
void Debug(void);
#endif
/// A structure for the selection.
struct Selection
{
+ Selection() { m_valid = false; m_selecting = false; }
bool m_valid;
bool m_selecting;
wxPoint m_CursorA, m_CursorB;
- Selection() { m_valid = false; m_selecting = true; }
} 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:
- wxLayoutObjectCmd *m_DefaultSetting;
+ wxLayoutStyleInfo m_DefaultSetting;
+ /// the current setting:
+ wxLayoutStyleInfo m_CurrentSetting;
//@}
};