<< GetSize(&bl).y << " bl=" << bl;
}
-# define WXL_VAR(x) cerr << #x"=" << x << endl;
+# define WXL_VAR(x) cerr << #x"=" << x << endl
# define WXL_DBG_POINT(p) cerr << #p << ": " << p.x << ',' << p.y << endl
-# define WXL_TRACE(f) cerr << #f":" << endl;
+# define WXL_TRACE(f) cerr << #f":" << endl
#else
# define WXL_VAR(x)
# define WXL_DBG_POINT(p)
CoordType baseLineSkip = (BASELINESTRETCH * baseLine)/10;
// where to draw the cursor
- wxPoint cursorPosition, cursorSize;
+ wxPoint
+ cursorPosition = wxPoint(0,0),
+ cursorSize = wxPoint(1,baseLineSkip);
- // we trace the objects' cursor positions so we can draw the cursor
- wxPoint cursor = wxPoint(0,0);
// the cursor position inside the object
CoordType cursorOffset = 0;
// object under cursor
#endif
dc.IsKindOf(CLASSINFO(wxPostScriptDC)))
{
- WXL_VAR(wxThePrintSetupData);
-
dc.GetSize(&pageWidth, &pageHeight);
dc.StartDoc(_("Printing..."));
dc.StartPage();
position.y = margins.right;
position.x = margins.left;
- WXL_VAR(findObject); WXL_VAR(findCoords.x); WXL_VAR(findCoords.y);
// if the cursorobject is a cmd, we need to find the first
// printable object:
while(cursorObject != end()
// draw the cursor
if(m_Editable && draw && i == cursorObject)
{
+ WXL_VAR((**cursorObject).GetType());
+ WXL_VAR(m_CursorPosition.x); WXL_VAR(m_CursorPosition.y);
if(type == WXLO_TYPE_TEXT) // special treatment
{
long descent = 0l; long width, height;
tobj = (wxLayoutObjectText *)*i;
String str = tobj->GetText();
- WXL_VAR(m_CursorPosition.x); WXL_VAR(cursor.x);
+ WXL_VAR(m_CursorPosition.x);
str = str.substr(0, cursorOffset);
- WXL_VAR(str);
dc.GetTextExtent(Str(str), &width,&height, &descent);
- WXL_VAR(height);
- WXL_VAR(width);
- WXL_VAR(descent);
cursorPosition = wxPoint(position.x+width,
- position.y+(baseLineSkip-height));
+ position.y+(baseLineSkip-height));
cursorSize = wxPoint(1, height);
- //dc.DrawLine(position.x+width,
- // position.y+(baseLineSkip-height),
- // position.x+width, position.y+baseLineSkip);
}
- else
+ else if(type == WXLO_TYPE_LINEBREAK)
{
- if(type == WXLO_TYPE_LINEBREAK)
- //dc.DrawLine(0, position.y+baseLineSkip, 0, position.y+2*baseLineSkip);
- {
- cursorPosition = wxPoint(0, position.y);
- cursorSize = wxPoint(1,baseLineSkip);
- }
+ WXL_VAR(cursorOffset);
+ if(cursorOffset)
+ cursorPosition = wxPoint(0, position.y+baseLineSkip);
else
- {
- cursorPosition = wxPoint(position.x, position.y);
- cursorSize = wxPoint(size.x > 0 ? size.x : 1,size.y > 0 ? size.y : baseLineSkip);
- }
+ cursorPosition = wxPoint(0, position.y);
+ cursorSize = wxPoint(1,baseLineSkip);
+
+ }
+ else
+ {
+ cursorPosition = wxPoint(position.x, position.y);
+ cursorSize = wxPoint(size.x > 0 ? size.x : 1,size.y > 0 ? size.y : baseLineSkip);
}
}
<< m_CursorPosition.y;
i = FindCurrentObject(&offs);
- cerr << " line length: " << GetLineLength(i) << " ";
+ cerr << " line length: " << GetLineLength(i,offs) << " ";
if(i == end())
{
cerr << "<<no object found>>" << endl;
{
if(cpos->x == object.x)
{
- *offset = 0;
+ if(offset) *offset = 0;
return i;
}
- *offset=1;
+ if(offset) *offset=1;
cpos->x = object.x;
return i;
}
if((**i).GetType()==WXLO_TYPE_LINEBREAK)
{
if(offset)
- *offset = (cpos->x > object.x) ? 1 : 0;
+ *offset = 1;
return i;
}
cpos->x = object.x; // would be the coordinate of next object
return obj;
}
-void
+bool
wxLayoutList::MoveCursor(int dx, int dy)
{
CoordType offs, lineLength;
wxLayoutObjectList::iterator i;
+ bool rc = true; // have we moved?
if(dy > 0 && m_CursorPosition.y < m_MaxLine)
m_CursorPosition.y += dy;
else if(dy < 0 && m_CursorPosition.y > 0)
m_CursorPosition.y += dy; // dy is negative
if(m_CursorPosition.y < 0)
+ {
m_CursorPosition.y = 0;
+ rc = false;
+ }
else if (m_CursorPosition.y > m_MaxLine)
+ {
m_CursorPosition.y = m_MaxLine;
+ rc = false;
+ }
while(dx > 0)
{
i = FindCurrentObject(&offs);
- lineLength = GetLineLength(i);
+ lineLength = GetLineLength(i,offs);
if(m_CursorPosition.x < lineLength)
{
m_CursorPosition.x ++;
dx--;
}
else
+ {
+ rc = false;
break; // cannot move there
+ }
}
}
while(dx < 0)
m_CursorPosition.y --;
m_CursorPosition.x = 0;
i = FindCurrentObject(&offs);
- lineLength = GetLineLength(i);
+ lineLength = GetLineLength(i,offs);
m_CursorPosition.x = lineLength;
dx++;
continue;
}
else
+ {
+ rc = false;
break; // cannot move left any more
+ }
}
}
// final adjustment:
i = FindCurrentObject(&offs);
- lineLength = GetLineLength(i);
+ lineLength = GetLineLength(i,offs);
if(m_CursorPosition.x > lineLength)
+ {
m_CursorPosition.x = lineLength;
-
+ rc = false;
+ }
#ifdef WXLAYOUT_DEBUG
i = FindCurrentObject(&offs);
cerr << "Cursor: "
if(i == end())
{
cerr << "<<no object found>>" << endl;
- return; // FIXME we should set cursor position to maximum allowed
+ return rc; // FIXME we should set cursor position to maximum allowed
// value then
}
if((*i)->GetType() == WXLO_TYPE_TEXT)
else
cerr << ' ' << _t[(*i)->GetType()] << endl;
#endif
+ return rc;
}
void
wxLayoutList::Insert(String const &text)
{
wxLayoutObjectText *tobj = NULL;
+ wxLayoutObjectList::iterator j;
+
WXL_TRACE(Insert(text));
if(! m_Editable)
CoordType offs;
wxLayoutObjectList::iterator i = FindCurrentObject(&offs);
- if(i != end() && (*i)->GetType() == WXLO_TYPE_TEXT)
- { // insert into an existing text object:
+ if(i == end())
+ {
+ Insert(new wxLayoutObjectText(text));
+ return;
+ }
+
+ switch((**i).GetType())
+ {
+ case WXLO_TYPE_TEXT:
+ // insert into an existing text object:
WXL_TRACE(inserting into existing object);
tobj = (wxLayoutObjectText *)*i ;
wxASSERT(tobj);
tobj->GetText().insert(offs,text);
- }
- else // check whether the previous object is text:
- {
- wxLayoutObjectList::iterator j = i;
- j--;
+ break;
+ case WXLO_TYPE_LINEBREAK:
+ j = i;
+ if(offs == 0) // try to append to previous object
+ {
+ j--;
+ if(j != end() && (**j).GetType() == WXLO_TYPE_TEXT)
+ {
+ tobj = (wxLayoutObjectText *)*j;
+ tobj->GetText()+=text;
+ }
+ else
+ insert(i,new wxLayoutObjectText(text));
+ }
+ else // cursor after linebreak
+ {
+ j++;
+ if(j != end() && (**j).GetType() == WXLO_TYPE_TEXT)
+ {
+ tobj = (wxLayoutObjectText *)*j;
+ tobj->GetText()=text+tobj->GetText();
+ }
+ else
+ {
+ if(j == end())
+ push_back(new wxLayoutObjectText(text));
+ else
+ insert(j,new wxLayoutObjectText(text));
+ }
+ }
+ break;
+ default:
+ j = i; j--;
WXL_TRACE(checking previous object);
- if(0 && j != end() && (*j)->GetType() == WXLO_TYPE_TEXT)
+ if(j != end() && (**j).GetType() == WXLO_TYPE_TEXT)
{
- tobj = (wxLayoutObjectText *)*i;
- wxASSERT(tobj);
+ tobj = (wxLayoutObjectText *)*j;
tobj->GetText()+=text;
}
else // insert a new text object
}
CoordType
-wxLayoutList::GetLineLength(wxLayoutObjectList::iterator i)
+wxLayoutList::GetLineLength(wxLayoutObjectList::iterator i, CoordType offs)
{
if(i == end())
return 0;
CoordType len = 0;
+ if(offs == 0 && (**i).GetType() == WXLO_TYPE_LINEBREAK)
+ // we are before a linebrak
+ return 0;
// search backwards for beginning of line:
while(i != begin() && (*i)->GetType() != WXLO_TYPE_LINEBREAK)
i--;