/*-*- c++ -*-********************************************************
* wxLayoutList.h - a formatted text rendering engine for wxWindows *
* *
- * (C) 1999 by Karsten Ballüder (Ballueder@usa.net) *
+ * (C) 1999-2000 by Karsten Ballüder (ballueder@gmx.net) *
* *
* $Id$
*******************************************************************/
# define WXMENU_LAYOUT_LCLICK 1111
# define WXMENU_LAYOUT_RCLICK 1112
# define WXMENU_LAYOUT_DBLCLICK 1113
+#else // for Mahogany only
+# include "MObject.h"
#endif
// use the wxWindows caret class instead of home grown cursor whenever possible
# define WXLAYOUT_USE_CARET 1
#endif // __WXMSW__
-// do not enable debug mode within Mahogany
-#if defined(__WXDEBUG__) && ! defined(M_BASEDIR)
+// do not enable debug mode within Mahogany unless in debug mode
+#if defined(__WXDEBUG__) && (( ! defined(M_BASEDIR) )|| defined(DEBUG))
# define WXLAYOUT_DEBUG
#endif
#ifdef WXLAYOUT_DEBUG
# define WXLO_TRACE(x) wxLogDebug(x)
+// activate profiling: # define WXLO_PROFILE
#else
# define WXLO_TRACE(x)
#endif
+/* Some profiling code: */
+#if defined (WXLO_PROFILE)
+#include <sys/time.h>
+#include <unistd.h>
+
+# define WXLO_TIMER_DEFINE(x) static struct timeval x
+# define WXLO_TIMER_START(x) gettimeofday(&x,NULL)
+# define WXLO_TIMER_STOP(x) { struct timeval y; \
+ gettimeofday(&y,NULL); \
+ x.tv_sec -= y.tv_sec; x.tv_usec -= y.tv_usec; }
+# define WXLO_TIMER_PRINT(x) wxLogDebug("Timer " #x " elapsed: %ld", \
+ (long)(x.tv_sec * -1000 - x.tv_usec));
+#else
+# define WXLO_TIMER_DEFINE(x)
+# define WXLO_TIMER_START(x)
+# define WXLO_TIMER_STOP(x)
+# define WXLO_TIMER_PRINT(x)
+#endif
+
+
#define WXLO_DEBUG_URECT 0
#ifndef WXLO_DEFAULTFONTSIZE
/// command object, containing font or colour changes
WXLO_TYPE_CMD,
/// icon object, any kind of image
- WXLO_TYPE_ICON
+ WXLO_TYPE_ICON,
+ /// a linebreak, does not exist as an object
+ WXLO_TYPE_LINEBREAK
};
/// Type used for coordinates in drawing. Must be signed.
its size.
*/
class wxLayoutObject
+#ifdef M_BASEDIR
+ : public MObject
+#endif
{
public:
/** This structure can be used to contain data associated with the
virtual ~wxLayoutObject() { if(m_UserData) m_UserData->DecRef(); }
#ifdef WXLAYOUT_DEBUG
- virtual void Debug(void);
+ virtual wxString DebugDump(void) const;
#endif
/** Tells the object about some user data. This data is associated
protected:
/// optional data for application's use
UserData *m_UserData;
+#if defined (M_BASEDIR) && defined (DEBUG)
+ MOBJECT_NAME(wxLayoutObject)
+#endif
};
/// Define a list type of wxLayoutObject pointers.
static wxLayoutObjectText *Read(wxString &istr);
#ifdef WXLAYOUT_DEBUG
- virtual void Debug(void);
+ virtual wxString DebugDump(void) const;
#endif
virtual CoordType GetLength(void) const { return strlen(m_Text.c_str()); }
int underline = -1,
wxColour *fg = NULL,
wxColour *bg = NULL);
+ wxLayoutObjectCmd(const wxLayoutStyleInfo &si);
~wxLayoutObjectCmd();
/** Stores the current style in the styleinfo structure */
wxLayoutStyleInfo * GetStyle(void) const;
void Append(wxLayoutObject * obj)
{
wxASSERT(obj);
-
m_ObjectList.push_back(obj);
m_Length += obj->GetLength();
}
+ /** This function prepends an object to the line. */
+ void Prepend(wxLayoutObject * obj)
+ {
+ wxASSERT(obj);
+ m_ObjectList.push_front(obj);
+ m_Length += obj->GetLength();
+ }
+
/** This function appens the next line to this, i.e. joins the two
lines into one.
*/
*/
wxLayoutLine *Break(CoordType xpos, wxLayoutList *llist);
+ /** This function wraps the line: breaks it at a suitable point
+ and merges it with the next.
+ @param wrapmargin
+ @return TRUE if broken
+ */
+ bool Wrap(CoordType wrapmargin, wxLayoutList *llist);
+
/** Deletes the next word from this position, including leading
whitespace.
This function does not delete over font changes, i.e. a word
CoordType GetHeight(void) const { return m_Height; }
/// Returns the width of this line.
CoordType GetWidth(void) const { return m_Width; }
- /** This will recalculate the position and size of this line.
- If called recursively it will abort if the position of an
- object is unchanged, assuming that none of the following
- objects need to move.
- @param recurse if greater 0 then it will be used as the
- minimum(!) recursion level, continue with all lines till the end of
- the list or until the coordinates no longer changed.
- */
- void RecalculatePositions(int recurse, wxLayoutList *llist);
/// Recalculates the position of this line on the canvas.
wxPoint RecalculatePosition(wxLayoutList *llist);
CoordType to = -1);
#ifdef WXLAYOUT_DEBUG
- void Debug(void);
+ void Debug(void) const;
#endif
wxLayoutStyleInfo const & GetStyleInfo() const { return m_StyleInfo; }
}
m_Dirty = true;
+ if(m_Next) m_Next->MarkDirty();
}
- /** Marks the following lines as dirty.
- @param recurse if -1 recurse to end of list, otherwise depth of recursion.
- */
- void MarkNextDirty(int recurse = 0);
/// Reset the dirty flag
void MarkClean() { m_Dirty = false; m_updateLeft = -1; }
@param height new height
*/
void SetHeight(CoordType height, wxLayoutList *llist)
- { m_Height = height; RecalculatePositions(true, llist); }
+ { m_Height = height; MarkDirty(); }
- /** Moves the linenumbers one on, because a line has been inserted
- or deleted.
- @param delta either +1 or -1
- */
- void MoveLines(int delta)
- {
- m_LineNumber += delta;
- if(m_Next) m_Next->MoveLines(delta);
- }
+ /** Updates the line numbers. */
+ void ReNumber(void);
//@}
private:
/// The line number.
/// Empty: clear the list but leave font settings.
void Empty(void);
+ /** Enable or disable auto-formatting. Normally, while editing this
+ should be enabled which is the default. While
+ inserting/deleting lots of text, it makes sense to temporarily
+ disable this.
+ @param enable TRUE to enable, FALSE to disable
+ */
+ void SetAutoFormatting(bool enable = TRUE)
+ { m_AutoFormat = enable; }
/**@name Cursor Management */
//@{
/** Set new cursor position.
/// Returns current cursor position.
const wxPoint &GetCursorPos(wxDC &dc) const { return m_CursorPos; }
const wxPoint &GetCursorPos() const { return m_CursorPos; }
-
+ wxLayoutLine * GetCursorLine(void) { return m_CursorLine; }
+
/// move cursor to the end of text
void MoveCursorToEnd(void)
{
@return true if line got broken
*/
bool WrapLine(CoordType column);
+
+ /** Wraps the complete buffer.
+ @param column the break position for the line, maximum length
+ @return true if line got broken
+ */
+ bool WrapAll(CoordType column);
/** This function deletes npos cursor positions.
@param npos how many positions
@return true if everything got deleted
@param offset an optional offset to shift printout
@param top optional y coordinate where to start drawing
@param bottom optional y coordinate where to stop drawing
+ @param clipStrictly if set, do not draw objects which reach
+ beyond "bottom". Set this when printing.
*/
void Draw(wxDC &dc,
const wxPoint &offset = wxPoint(0,0),
- CoordType top = -1, CoordType bottom = -1);
+ CoordType top = -1, CoordType bottom = -1,
+ bool clipStrictly = false);
/** Calculates new layout for the list, like Draw() but does not
actually draw it.
wxPoint *cpos = NULL,
wxPoint *csize = NULL);
+ /** Ensure that the whole list will be recalculate on the next call
+ to Layout() or Draw().
+ @param redrawAll TRUE or FALSE to reset it
+ */
+ void ForceTotalLayout(bool redrawAll = TRUE)
+ { m_ReLayoutAll = redrawAll; }
+
/** Returns the screen coordinates relating to a given cursor
position and the size of the cursor at that position.
@param dc for which to calculate it
wxPoint GetSize(void) const;
/** Returns the cursor position on the screen.
- @return cursor position in pixels
*/
- wxPoint GetCursorScreenPos(wxDC &dc);
+ wxPoint GetCursorScreenPos(void) const;
/** Draws the cursor.
@param active If true, draw a bold cursor to mark window as
void DecNumLines() { m_numLines--; }
/// get the line by number
- wxLayoutLine *GetLine(CoordType index) const
- {
- wxASSERT_MSG( (0 <= index) && (index < (CoordType)m_numLines),
- "invalid index" );
-
- wxLayoutLine *line;
- CoordType n = index;
- for ( line = m_FirstLine; line && n-- > 0; line = line->GetNextLine() )
- ;
-
- if ( line )
- {
- // should be the right one
- wxASSERT( line->GetLineNumber() == index );
- }
+ wxLayoutLine *GetLine(CoordType index) const;
- return line;
- }
+ /** Reads objects from a string and inserts them. Returns NULL if
+ string is empty or a linebreak was found.
+ @param istr stream to read from, will bee changed
+ */
+ void Read(wxString &istr);
private:
/// Clear the list.
/// Is the update rectangle valid?
bool m_UpdateRectValid;
+ /// Shall we auto-format?
+ bool m_AutoFormat;
+ /// Shall we re-layout everything?
+ bool m_ReLayoutAll;
/**@name Cursor Management */
//@{
/// Where the text cursor (column,line) is.
own format.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-class wxLayoutDataObject : public wxPrivateDataObject
+class wxLayoutDataObject : public wxCustomDataObject
{
public:
- wxLayoutDataObject(void)
+ wxLayoutDataObject()
{
- SetId("application/wxlayoutlist");
- //m_format.SetAtom((GdkAtom) 222222);
+ SetFormat("application/wxlayoutlist");
}
+
+ // type safe wrappers
+ void SetLayoutData(const wxString& text)
+ { SetData(text.length() + 1, text.c_str()); }
+ const char *GetLayoutData() const { return (const char *)GetData(); }
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *