+void
+wxLayoutList::SetWrapMargin(long n)
+{
+ m_WrapMargin = n;
+}
+
+void
+wxLayoutList::WrapLine(void)
+{
+ wxASSERT(m_CursorObject);
+
+ iterator i = m_CursorObject;
+
+ if(!DoWordWrap() || !i ) // empty list
+ return;
+ int cursorpos = m_CursorPos.x, cpos, offset;
+
+ if(cursorpos < m_WrapMargin)
+ return;
+
+ // else: break line
+
+ // find the right object to break:
+ // is it the current one?
+
+ i = m_CursorObject;
+ cpos = cursorpos-m_CursorOffset;
+ while(i != begin() && cpos >= m_WrapMargin)
+ {
+ i--;
+ cpos -= (**i).CountPositions();
+ }
+ // now i is the object to break and cpos its position
+
+ offset = m_WrapMargin - cpos;
+ wxASSERT(offset <= (**i).CountPositions());
+
+ // split it
+ if((**i).GetType() == WXLO_TYPE_TEXT)
+ {
+ wxLayoutObjectText &t = *(wxLayoutObjectText *)*i;
+ for(; offset > 0; offset--)
+ if(t.GetText().c_str()[offset] == ' ' || t.GetText().c_str()[offset] == '\t')
+ {
+ String left = t.GetText().substr(0,offset); // get part before cursor
+ t.GetText() = t.GetText().substr(offset+1,t.CountPositions()-offset-1); // keeps the right halve
+ insert(i,new wxLayoutObjectLineBreak);
+ insert(i,new wxLayoutObjectText(left)); // inserts before
+ break;
+ }
+ if(offset == 0)
+ {
+ // only insert a line break if there isn't already one
+ iterator j = i; j--;
+ if(j && j != begin() && (**j).GetType() != WXLO_TYPE_LINEBREAK)
+ insert(i,new wxLayoutObjectLineBreak);
+ else
+ return; // do nothing
+ }
+ }
+ else
+ insert(i,new wxLayoutObjectLineBreak);
+ m_MaxLine++;
+ m_CursorPos.y++;
+ m_CursorPos.x -= offset;
+ m_CursorOffset -= offset;
+}