#include "wxllist.h"
#include "iostream"
+#define BASELINESTRETCH 12
+
#define VAR(x) cerr << #x"=" << x << endl;
#define DBG_POINT(p) cerr << #p << ": " << p.x << ',' << p.y << endl
#define TRACE(f) cerr << #f":" << endl;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
static const char *_t[] = { "invalid", "text", "cmd", "icon",
"linebreak"};
//-------------------------- wxLayoutObjectText
-wxLayoutObjectText::wxLayoutObjectText(const wxString &txt)
+wxLayoutObjectText::wxLayoutObjectText(const String &txt)
{
m_Text = txt;
m_Width = 0;
bool draw)
{
long descent = 0l;
- dc.GetTextExtent(m_Text,&m_Width, &m_Height, &descent);
+ dc.GetTextExtent(Str(m_Text),&m_Width, &m_Height, &descent);
//FIXME: wxGTK does not set descent to a descent value yet.
if(descent == 0)
descent = (2*m_Height)/10; // crude fix
m_BaseLine = m_Height - descent;
position.y += baseLine-m_BaseLine;
if(draw)
- dc.DrawText(m_Text,position.x,position.y);
-# ifdef WXDEBUG
+ dc.DrawText(Str(m_Text),position.x,position.y);
+# ifdef WXLAYOUT_DEBUG
// dc.DrawRectangle(position.x, position.y, m_Width, m_Height);
# endif
}
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
void
wxLayoutObjectText::Debug(void)
{
wxLayoutList::wxLayoutList()
{
+ m_DefaultSetting = NULL;
Clear();
}
wxLayoutList::~wxLayoutList()
{
+ if(m_DefaultSetting)
+ delete m_DefaultSetting;
}
wxPoint position = wxPoint(0,0);
wxPoint position_HeadOfLine;
CoordType baseLine = m_FontPtSize;
- CoordType baseLineSkip = (12 * baseLine)/10;
+ CoordType baseLineSkip = (BASELINESTRETCH * baseLine)/10;
// we trace the objects' cursor positions so we can draw the cursor
wxPoint cursor = wxPoint(0,0);
CoordType objBaseLine = baseLine;
wxLayoutObjectType type;
+ // used temporarily
+ wxLayoutObjectText *tobj = NULL;
+
VAR(findObject); VAR(findCoords.x); VAR(findCoords.y);
// if the cursorobject is a cmd, we need to find the first
// printable object:
dc.SetTextForeground( *wxBLACK );
dc.SetFont( *wxNORMAL_FONT );
+ if(m_DefaultSetting)
+ m_DefaultSetting->Draw(dc,wxPoint(0,0),0,true);
+
// we calculate everything for drawing a line, then rewind to the
// begin of line and actually draw it
i = begin();
if(type == WXLO_TYPE_TEXT) // special treatment
{
long descent = 0l; long width, height;
- wxLayoutObjectText *tobj = (wxLayoutObjectText *)*i;
- wxString str = tobj->GetText();
+ tobj = (wxLayoutObjectText *)*i;
+ String str = tobj->GetText();
VAR(m_CursorPosition.x); VAR(cursor.x);
str = str.substr(0, cursorOffset);
VAR(str);
- dc.GetTextExtent(str, &width,&height, &descent);
+ dc.GetTextExtent(Str(str), &width,&height, &descent);
VAR(height);
VAR(width); VAR(descent);
dc.DrawLine(position.x+width,
position.x = 0;
position.y += baseLineSkip;
baseLine = m_FontPtSize;
- baseLineSkip = (12 * baseLine)/10;
+ objBaseLine = baseLine; // not all objects set it
+ baseLineSkip = (BASELINESTRETCH * baseLine)/10;
headOfLine = i;
headOfLine++;
position_HeadOfLine = position;
return foundObject;
}
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
void
wxLayoutList::Debug(void)
{
CoordType width;
wxLayoutObjectList::iterator i;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
cerr << "Looking for object at " << cpos.x << ',' << cpos.y <<
endl;
#endif
if(offset)
*offset = cpos.x-(cursor.x-width); // 0==cursor before
// the object
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
cerr << " found object at " << cursor.x-width << ',' <<
cursor.y << ", type:" << _t[(*i)->GetType()] <<endl;
#endif
return i;
}
}
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
cerr << " not found" << endl;
#endif
return end(); // not found
if(m_CursorPosition.x > lineLength)
m_CursorPosition.x = lineLength;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
i = FindCurrentObject(&offs);
cerr << "Cursor: "
<< m_CursorPosition.x << ','
i = FindCurrentObject(&offs);
if(i == end())
return;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
cerr << "trying to delete: " << _t[(*i)->GetType()] << endl;
#endif
if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
if((*i)->GetType() == WXLO_TYPE_TEXT && offs != 0 && offs != (*i)->CountPositions())
{
wxLayoutObjectText *tobj = (wxLayoutObjectText *) *i;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
cerr << "text: '" << tobj->GetText() << "'" << endl;
VAR(offs);
#endif
- wxString left = tobj->GetText().substr(0,offs); // get part before cursor
+ String left = tobj->GetText().substr(0,offs); // get part before cursor
VAR(left);
tobj->GetText() = tobj->GetText().substr(offs,(*i)->CountPositions()-offs); // keeps the right half
VAR(tobj->GetText());
}
void
-wxLayoutList::Insert(wxString const &text)
+wxLayoutList::Insert(String const &text)
{
+ wxLayoutObjectText *tobj = NULL;
TRACE(Insert(text));
if(! m_Editable)
if(i != end() && (*i)->GetType() == WXLO_TYPE_TEXT)
{ // insert into an existing text object:
TRACE(inserting into existing object);
- wxLayoutObjectText *tobj = (wxLayoutObjectText *)*i;
+ tobj = (wxLayoutObjectText *)*i ;
+ wxASSERT(tobj);
tobj->GetText().insert(offs,text);
}
- else
+ else // check whether the previous object is text:
{
- // check whether the previous object is text:
wxLayoutObjectList::iterator j = i;
j--;
TRACE(checking previous object);
if(0 && j != end() && (*j)->GetType() == WXLO_TYPE_TEXT)
{
- wxLayoutObjectText *tobj = (wxLayoutObjectText *)*i;
+ tobj = (wxLayoutObjectText *)*i;
+ wxASSERT(tobj);
tobj->GetText()+=text;
}
else // insert a new text object
}
void
-wxLayoutList::Clear(void)
+wxLayoutList::Clear(int family, int size, int style, int weight,
+ int underline, char const *fg, char const *bg)
{
wxLayoutObjectList::iterator i = begin();
erase(i);
// set defaults
- m_FontPtSize = 12;
+ m_FontPtSize = size;
m_FontUnderline = false;
- m_FontFamily = wxDEFAULT;
- m_FontStyle = wxNORMAL;
- m_FontWeight = wxNORMAL;
- m_ColourFG = wxTheColourDatabase->FindColour("BLACK");
- m_ColourBG = wxTheColourDatabase->FindColour("WHITE");
+ m_FontFamily = family;
+ m_FontStyle = style;
+ m_FontWeight = weight;
+ m_ColourFG = wxTheColourDatabase->FindColour(fg);
+ m_ColourBG = wxTheColourDatabase->FindColour(bg);
m_Position = wxPoint(0,0);
m_CursorPosition = wxPoint(0,0);
m_MaxLine = 0;
- m_LineHeight = (12*m_FontPtSize)/10;
+ m_LineHeight = (BASELINESTRETCH*m_FontPtSize)/10;
m_MaxX = 0; m_MaxY = 0;
+
+ if(m_DefaultSetting)
+ delete m_DefaultSetting;
+ m_DefaultSetting = new
+ wxLayoutObjectCmd(m_FontPtSize,m_FontFamily,m_FontStyle,
+ m_FontWeight,m_FontUnderline,
+ m_ColourFG, m_ColourBG);
}