]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxllist.cpp
wxFrame::CreateToolBar() stuff
[wxWidgets.git] / user / wxLayout / wxllist.cpp
1 /*-*- c++ -*-********************************************************
2 * wxFTCanvas: a canvas for editing formatted text *
3 * *
4 * (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
5 * *
6 * $Id$ *
7 *******************************************************************/
8
9 /*
10 - each Object knows its size and how to draw itself
11 - the list is responsible for calculating positions
12 - the draw coordinates for each object are the top left corner
13 - coordinates only get calculated when things get redrawn
14 - during redraw each line gets iterated over twice, first just
15 calculating baselines and positions, second to actually draw it
16 - the cursor position is the position before an object, i.e. if the
17 buffer starts with a text-object, cursor 0,0 is just before the
18 first character
19 */
20
21 #ifdef __GNUG__
22 #pragma implementation "wxllist.h"
23 #endif
24
25 #include "wxllist.h"
26 #include "iostream.h"
27
28 #include <wx/dc.h>
29 #include <wx/postscrp.h>
30 #include <wx/print.h>
31
32 #define BASELINESTRETCH 12
33
34 #define VAR(x) cerr << #x"=" << x << endl;
35 #define DBG_POINT(p) cerr << #p << ": " << p.x << ',' << p.y << endl
36 #define TRACE(f) cerr << #f":" << endl;
37
38 #ifdef WXLAYOUT_DEBUG
39 static const char *_t[] = { "invalid", "text", "cmd", "icon",
40 "linebreak"};
41
42 void
43 wxLayoutObjectBase::Debug(void)
44 {
45 CoordType bl = 0;
46 cerr << _t[GetType()] << ": size=" << GetSize(&bl).x << ","
47 << GetSize(&bl).y << " bl=" << bl;
48 }
49 #endif
50
51 //-------------------------- wxLayoutObjectText
52
53 wxLayoutObjectText::wxLayoutObjectText(const String &txt)
54 {
55 m_Text = txt;
56 m_Width = 0;
57 m_Height = 0;
58 }
59
60
61 wxPoint
62 wxLayoutObjectText::GetSize(CoordType *baseLine) const
63 {
64 if(baseLine) *baseLine = m_BaseLine;
65 return wxPoint(m_Width, m_Height);
66 }
67
68 void
69 wxLayoutObjectText::Draw(wxDC &dc, wxPoint position, CoordType baseLine,
70 bool draw)
71 {
72 long descent = 0l;
73 dc.GetTextExtent(Str(m_Text),&m_Width, &m_Height, &descent);
74 //FIXME: wxGTK does not set descent to a descent value yet.
75 if(descent == 0)
76 descent = (2*m_Height)/10; // crude fix
77 m_BaseLine = m_Height - descent;
78 position.y += baseLine-m_BaseLine;
79 if(draw)
80 dc.DrawText(Str(m_Text),position.x,position.y);
81 # ifdef WXLAYOUT_DEBUG
82 // dc.DrawRectangle(position.x, position.y, m_Width, m_Height);
83 # endif
84 }
85
86 #ifdef WXLAYOUT_DEBUG
87 void
88 wxLayoutObjectText::Debug(void)
89 {
90 wxLayoutObjectBase::Debug();
91 cerr << " `" << m_Text << '\'';
92 }
93 #endif
94
95 //-------------------------- wxLayoutObjectIcon
96
97 wxLayoutObjectIcon::wxLayoutObjectIcon(wxIcon *icon)
98 {
99 m_Icon = icon;
100 }
101
102 void
103 wxLayoutObjectIcon::Draw(wxDC &dc, wxPoint position, CoordType baseLine,
104 bool draw)
105 {
106 position.y += baseLine - m_Icon->GetHeight();
107 if(draw)
108 dc.DrawIcon(m_Icon,position.x,position.y);
109 }
110
111 wxPoint
112 wxLayoutObjectIcon::GetSize(CoordType *baseLine) const
113 {
114 wxASSERT(baseLine);
115 *baseLine = m_Icon->GetHeight();
116 return wxPoint(m_Icon->GetWidth(), m_Icon->GetHeight());
117 }
118
119 //-------------------------- wxLayoutObjectCmd
120
121
122 wxLayoutObjectCmd::wxLayoutObjectCmd(int size, int family, int style, int
123 weight, bool underline,
124 wxColour const *fg, wxColour const *bg)
125
126 {
127 m_font = new wxFont(size,family,style,weight,underline);
128 m_ColourFG = fg;
129 m_ColourBG = bg;
130 }
131
132 wxLayoutObjectCmd::~wxLayoutObjectCmd()
133 {
134 delete m_font;
135 }
136
137 wxLayoutStyleInfo *
138 wxLayoutObjectCmd::GetStyle(void) const
139 {
140 wxLayoutStyleInfo *si = new wxLayoutStyleInfo();
141
142
143 si->size = m_font->GetPointSize();
144 si->family = m_font->GetFamily();
145 si->style = m_font->GetStyle();
146 si->underline = m_font->GetUnderlined();
147 si->weight = m_font->GetWeight();
148
149 si->fg_red = m_ColourFG->Red();
150 si->fg_green = m_ColourFG->Green();
151 si->fg_blue = m_ColourFG->Blue();
152 si->bg_red = m_ColourBG->Red();
153 si->bg_green = m_ColourBG->Green();
154 si->bg_blue = m_ColourBG->Blue();
155
156 return si;
157 }
158
159 void
160 wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint position, CoordType lineHeight,
161 bool draw)
162 {
163 wxASSERT(m_font);
164 // this get called even when draw==false, so that recalculation
165 // uses right font sizes
166 dc.SetFont(m_font);
167 if(m_ColourFG)
168 dc.SetTextForeground(*m_ColourFG);
169 if(m_ColourBG)
170 dc.SetTextBackground(*m_ColourBG);
171 }
172
173 //-------------------------- wxwxLayoutList
174
175 wxLayoutList::wxLayoutList()
176 {
177 m_DefaultSetting = NULL;
178 Clear();
179 }
180
181 wxLayoutList::~wxLayoutList()
182 {
183 if(m_DefaultSetting)
184 delete m_DefaultSetting;
185 }
186
187
188 void
189 wxLayoutList::LineBreak(void)
190 {
191 Insert(new wxLayoutObjectLineBreak);
192 m_CursorPosition.x = 0; m_CursorPosition.y++;
193 }
194
195 void
196 wxLayoutList::SetFont(int family, int size, int style, int weight,
197 int underline, wxColour const *fg,
198 wxColour const *bg)
199 {
200 if(family != -1) m_FontFamily = family;
201 if(size != -1) m_FontPtSize = size;
202 if(style != -1) m_FontStyle = style;
203 if(weight != -1) m_FontWeight = weight;
204 if(underline != -1) m_FontUnderline = underline;
205
206 if(fg != NULL) m_ColourFG = fg;
207 if(bg != NULL) m_ColourBG = bg;
208
209 Insert(
210 new wxLayoutObjectCmd(m_FontPtSize,m_FontFamily,m_FontStyle,m_FontWeight,m_FontUnderline,
211 m_ColourFG, m_ColourBG));
212 }
213
214 void
215 wxLayoutList::SetFont(int family, int size, int style, int weight,
216 int underline, char const *fg, char const *bg)
217 {
218 wxColour const
219 * cfg = NULL,
220 * cbg = NULL;
221
222 if( fg )
223 cfg = wxTheColourDatabase->FindColour(fg);
224 if( bg )
225 cbg = wxTheColourDatabase->FindColour(bg);
226
227 SetFont(family,size,style,weight,underline,cfg,cbg);
228 }
229
230
231 /// for access by wxLayoutWindow:
232 void
233 wxLayoutList::GetSize(CoordType *max_x, CoordType *max_y,
234 CoordType *lineHeight)
235 {
236 wxASSERT(max_x); wxASSERT(max_y); wxASSERT(lineHeight);
237 *max_x = m_MaxX;
238 *max_y = m_MaxY;
239 *lineHeight = m_LineHeight;
240 }
241
242 wxLayoutObjectBase *
243 wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords)
244 {
245 wxLayoutObjectList::iterator i;
246
247 // in case we need to look for an object
248 wxLayoutObjectBase *foundObject = NULL;
249
250 // first object in current line
251 wxLayoutObjectList::iterator headOfLine;
252
253 // do we need to recalculate current line?
254 bool recalculate = false;
255
256 // do we calculate or draw? Either true or false.
257 bool draw = false;
258 // drawing parameters:
259 wxPoint position = wxPoint(0,0);
260 wxPoint position_HeadOfLine;
261 CoordType baseLine = m_FontPtSize;
262 CoordType baseLineSkip = (BASELINESTRETCH * baseLine)/10;
263
264 // we trace the objects' cursor positions so we can draw the cursor
265 wxPoint cursor = wxPoint(0,0);
266 // the cursor position inside the object
267 CoordType cursorOffset = 0;
268 // object under cursor
269 wxLayoutObjectList::iterator cursorObject = FindCurrentObject(&cursorOffset);
270
271 // queried from each object:
272 wxPoint size = wxPoint(0,0);
273 CoordType objBaseLine = baseLine;
274 wxLayoutObjectType type;
275
276 // used temporarily
277 wxLayoutObjectText *tobj = NULL;
278
279
280 // this is needed for printing to a printer:
281 // only interesting for printer/PS output
282 int pageWidth, pageHeight; //GetSize() still needs int at the moment
283 struct
284 {
285 int top, bottom, left, right;
286 } margins;
287
288 if(
289 #ifdef __WXMSW__
290 dc.IsKindOf(CLASSINFO(wxPrinterDC)) ||
291 #endif
292 dc.IsKindOf(CLASSINFO(wxPostScriptDC)))
293 {
294 VAR(wxThePrintSetupData);
295
296 dc.GetSize(&pageWidth, &pageHeight);
297 dc.StartDoc(_("Printing..."));
298 dc.StartPage();
299 margins.top = (1*pageHeight)/10; // 10%
300 margins.bottom = (9*pageHeight)/10; // 90%
301 margins.left = (1*pageWidth)/10;
302 margins.right = (9*pageWidth)/10;
303 }
304 else
305 {
306 margins.top = 0; margins.left = 0;
307 margins.right = -1;
308 margins.bottom = -1;
309 }
310 position.y = margins.right;
311 position.x = margins.left;
312
313 VAR(findObject); VAR(findCoords.x); VAR(findCoords.y);
314 // if the cursorobject is a cmd, we need to find the first
315 // printable object:
316 while(cursorObject != end()
317 && (*cursorObject)->GetType() == WXLO_TYPE_CMD)
318 cursorObject++;
319
320 headOfLine = begin();
321 position_HeadOfLine = position;
322
323 // setting up the default:
324 dc.SetTextForeground( *wxBLACK );
325 dc.SetFont( *wxNORMAL_FONT );
326
327 if(m_DefaultSetting)
328 m_DefaultSetting->Draw(dc,wxPoint(0,0),0,true);
329
330 // we calculate everything for drawing a line, then rewind to the
331 // begin of line and actually draw it
332 i = begin();
333 for(;;)
334 {
335 recalculate = false;
336
337 if(i == end())
338 break;
339 type = (*i)->GetType();
340
341 // to initialise sizes of objects, we need to call Draw
342 (*i)->Draw(dc, position, baseLine, draw);
343
344 // update coordinates for next object:
345 size = (*i)->GetSize(&objBaseLine);
346 if(findObject && draw) // we need to look for an object
347 {
348 if(findCoords.y >= position.y
349 && findCoords.y <= position.y+size.y
350 && findCoords.x >= position.x
351 && findCoords.x <= position.x+size.x)
352 {
353 foundObject = *i;
354 findObject = false; // speeds things up
355 }
356 }
357 // draw the cursor
358 if(m_Editable && draw && i == cursorObject)
359 {
360 if(type == WXLO_TYPE_TEXT) // special treatment
361 {
362 long descent = 0l; long width, height;
363 tobj = (wxLayoutObjectText *)*i;
364 String str = tobj->GetText();
365 VAR(m_CursorPosition.x); VAR(cursor.x);
366 str = str.substr(0, cursorOffset);
367 VAR(str);
368 dc.GetTextExtent(Str(str), &width,&height, &descent);
369 VAR(height);
370 VAR(width); VAR(descent);
371 dc.DrawLine(position.x+width,
372 position.y+(baseLineSkip-height),
373 position.x+width, position.y+baseLineSkip);
374 }
375 else
376 {
377 if(type == WXLO_TYPE_LINEBREAK)
378 dc.DrawLine(0, position.y+baseLineSkip, 0, position.y+2*baseLineSkip);
379 else
380 {
381 if(size.x == 0)
382 {
383 if(size.y == 0)
384 dc.DrawLine(position.x, position.y, position.x, position.y+baseLineSkip);
385 else
386 dc.DrawLine(position.x, position.y, position.x, position.y+size.y);
387 }
388 else
389 dc.DrawRectangle(position.x, position.y, size.x, size.y);
390 }
391 }
392 }
393
394 // calculate next object's position:
395 position.x += size.x;
396
397 // do we need to increase the line's height?
398 if(size.y > baseLineSkip)
399 {
400 baseLineSkip = size.y;
401 recalculate = true;
402 }
403 if(objBaseLine > baseLine)
404 {
405 baseLine = objBaseLine;
406 recalculate = true;
407 }
408
409 // now check whether we have finished handling this line:
410 if(type == WXLO_TYPE_LINEBREAK || i == tail())
411 {
412 if(recalculate) // do this line again
413 {
414 position.x = position_HeadOfLine.x;
415 i = headOfLine;
416 continue;
417 }
418
419 if(! draw) // finished calculating sizes
420 {
421 // if the this line needs to go onto a new page, we need
422 // to change pages before drawing it:
423 if(margins.bottom != -1 && position.y > margins.bottom)
424 {
425 dc.EndPage();
426 position_HeadOfLine.y = margins.top;
427 dc.StartPage();
428 }
429 // do this line again, this time drawing it
430 position = position_HeadOfLine;
431 draw = true;
432 i = headOfLine;
433 continue;
434 }
435 else // we have drawn a line, so continue calculating next one
436 draw = false;
437 }
438
439 if(position.x+size.x > m_MaxX)
440 m_MaxX = position.x+size.x;
441 // is it a linebreak?
442 if(type == WXLO_TYPE_LINEBREAK || i == tail())
443 {
444 position.x = margins.left;
445 position.y += baseLineSkip;
446 baseLine = m_FontPtSize;
447 objBaseLine = baseLine; // not all objects set it
448 baseLineSkip = (BASELINESTRETCH * baseLine)/10;
449 headOfLine = i;
450 headOfLine++;
451 position_HeadOfLine = position;
452 }
453 i++;
454 }
455 dc.EndDoc();
456 m_MaxY = position.y;
457 return foundObject;
458 }
459
460 #ifdef WXLAYOUT_DEBUG
461 void
462 wxLayoutList::Debug(void)
463 {
464 CoordType offs;
465 wxLayoutObjectList::iterator i;
466
467 cerr <<
468 "------------------------debug start-------------------------" << endl;
469 for(i = begin(); i != end(); i++)
470 {
471 (*i)->Debug();
472 cerr << endl;
473 }
474 cerr <<
475 "-----------------------debug end----------------------------"
476 << endl;
477 // show current object:
478 cerr << "Cursor: "
479 << m_CursorPosition.x << ','
480 << m_CursorPosition.y;
481
482 i = FindCurrentObject(&offs);
483 cerr << " line length: " << GetLineLength(i) << " ";
484 if(i == end())
485 {
486 cerr << "<<no object found>>" << endl;
487 return; // FIXME we should set cursor position to maximum allowed
488 // value then
489 }
490 if((*i)->GetType() == WXLO_TYPE_TEXT)
491 {
492 cerr << " \"" << ((wxLayoutObjectText *)(*i))->GetText() << "\", offs: "
493 << offs << endl;
494 }
495 else
496 cerr << ' ' << _t[(*i)->GetType()] << endl;
497
498 }
499 #endif
500
501 /******************** editing stuff ********************/
502
503 wxLayoutObjectList::iterator
504 wxLayoutList::FindObjectCursor(wxPoint const &cpos, CoordType *offset)
505 {
506 wxPoint cursor = wxPoint(0,0); // runs along the objects
507 CoordType width;
508 wxLayoutObjectList::iterator i;
509
510 #ifdef WXLAYOUT_DEBUG
511 cerr << "Looking for object at " << cpos.x << ',' << cpos.y <<
512 endl;
513 #endif
514 for(i = begin(); i != end() && cursor.y <= cpos.y; i++)
515 {
516 width = 0;
517 if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
518 {
519 if(cpos.y == cursor.y)
520 {
521 --i;
522 if(offset)
523 *offset = (*i)->CountPositions();
524 return i;
525 }
526 cursor.x = 0; cursor.y ++;
527 }
528 else
529 cursor.x += (width = (*i)->CountPositions());
530 if(cursor.y == cpos.y && (cursor.x > cpos.x ||
531 ((*i)->GetType() != WXLO_TYPE_CMD && cursor.x == cpos.x))
532 ) // found it ?
533 {
534 if(offset)
535 *offset = cpos.x-(cursor.x-width); // 0==cursor before
536 // the object
537 #ifdef WXLAYOUT_DEBUG
538 cerr << " found object at " << cursor.x-width << ',' <<
539 cursor.y << ", type:" << _t[(*i)->GetType()] <<endl;
540 #endif
541 return i;
542 }
543 }
544 #ifdef WXLAYOUT_DEBUG
545 cerr << " not found" << endl;
546 #endif
547 return end(); // not found
548 }
549
550 wxLayoutObjectList::iterator
551 wxLayoutList::FindCurrentObject(CoordType *offset)
552 {
553 wxLayoutObjectList::iterator obj = end();
554
555 obj = FindObjectCursor(m_CursorPosition, offset);
556 if(obj == end()) // not ideal yet
557 {
558 obj = tail();
559 if(obj != end()) // tail really exists
560 *offset = (*obj)->CountPositions(); // at the end of it
561 }
562 return obj;
563 }
564
565 void
566 wxLayoutList::MoveCursor(int dx, int dy)
567 {
568 CoordType offs, lineLength;
569 wxLayoutObjectList::iterator i;
570
571
572 if(dy > 0 && m_CursorPosition.y < m_MaxLine)
573 m_CursorPosition.y += dy;
574 else if(dy < 0 && m_CursorPosition.y > 0)
575 m_CursorPosition.y += dy; // dy is negative
576 if(m_CursorPosition.y < 0)
577 m_CursorPosition.y = 0;
578 else if (m_CursorPosition.y > m_MaxLine)
579 m_CursorPosition.y = m_MaxLine;
580
581 while(dx > 0)
582 {
583 i = FindCurrentObject(&offs);
584 lineLength = GetLineLength(i);
585 if(m_CursorPosition.x < lineLength)
586 {
587 m_CursorPosition.x ++;
588 dx--;
589 continue;
590 }
591 else
592 {
593 if(m_CursorPosition.y < m_MaxLine)
594 {
595 m_CursorPosition.y++;
596 m_CursorPosition.x = 0;
597 dx--;
598 }
599 else
600 break; // cannot move there
601 }
602 }
603 while(dx < 0)
604 {
605 if(m_CursorPosition.x > 0)
606 {
607 m_CursorPosition.x --;
608 dx++;
609 }
610 else
611 {
612 if(m_CursorPosition.y > 0)
613 {
614 m_CursorPosition.y --;
615 m_CursorPosition.x = 0;
616 i = FindCurrentObject(&offs);
617 lineLength = GetLineLength(i);
618 m_CursorPosition.x = lineLength;
619 dx++;
620 continue;
621 }
622 else
623 break; // cannot move left any more
624 }
625 }
626 // final adjustment:
627 i = FindCurrentObject(&offs);
628 lineLength = GetLineLength(i);
629 if(m_CursorPosition.x > lineLength)
630 m_CursorPosition.x = lineLength;
631
632 #ifdef WXLAYOUT_DEBUG
633 i = FindCurrentObject(&offs);
634 cerr << "Cursor: "
635 << m_CursorPosition.x << ','
636 << m_CursorPosition.y;
637
638 if(i == end())
639 {
640 cerr << "<<no object found>>" << endl;
641 return; // FIXME we should set cursor position to maximum allowed
642 // value then
643 }
644 if((*i)->GetType() == WXLO_TYPE_TEXT)
645 {
646 cerr << " \"" << ((wxLayoutObjectText *)(*i))->GetText() << "\", offs: "
647 << offs << endl;
648 }
649 else
650 cerr << ' ' << _t[(*i)->GetType()] << endl;
651 #endif
652 }
653
654 void
655 wxLayoutList::Delete(CoordType count)
656 {
657 TRACE(Delete);
658
659 if(!m_Editable)
660 return;
661
662 VAR(count);
663
664 CoordType offs, len;
665 wxLayoutObjectList::iterator i;
666
667 do
668 {
669 i = FindCurrentObject(&offs);
670 if(i == end())
671 return;
672 #ifdef WXLAYOUT_DEBUG
673 cerr << "trying to delete: " << _t[(*i)->GetType()] << endl;
674 #endif
675 if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
676 m_MaxLine--;
677 if((*i)->GetType() == WXLO_TYPE_TEXT)
678 {
679 wxLayoutObjectText *tobj = (wxLayoutObjectText *)*i;
680 len = tobj->CountPositions();
681 // If we find the end of a text object, this means that we
682 // have to delete from the object following it.
683 if(offs == len)
684 {
685 i++;
686 if((*i)->GetType() == WXLO_TYPE_TEXT)
687 {
688 offs = 0; // delete from begin of next string
689 tobj = (wxLayoutObjectText *)*i;
690 len = tobj->CountPositions();
691 }
692 else
693 {
694 erase(i);
695 return;
696 }
697 }
698 if(len <= count) // delete this object
699 {
700 count -= len;
701 erase(i);
702 }
703 else
704 {
705 len = count;
706 VAR(offs); VAR(len);
707 tobj->GetText().erase(offs,len);
708 return; // we are done
709 }
710 }
711 else // delete the object
712 {
713 len = (*i)->CountPositions();
714 erase(i); // after this, i is the iterator for the following object
715 if(count > len)
716 count -= len;
717 else
718 count = 0;
719 }
720 }
721 while(count && i != end());
722 }
723
724 void
725 wxLayoutList::Insert(wxLayoutObjectBase *obj)
726 {
727 wxASSERT(obj);
728 CoordType offs;
729 wxLayoutObjectList::iterator i = FindCurrentObject(&offs);
730
731 TRACE(Insert(obj));
732
733 if(i == end())
734 push_back(obj);
735 else
736 {
737 // do we have to split a text object?
738 if((*i)->GetType() == WXLO_TYPE_TEXT && offs != 0 && offs != (*i)->CountPositions())
739 {
740 wxLayoutObjectText *tobj = (wxLayoutObjectText *) *i;
741 #ifdef WXLAYOUT_DEBUG
742 cerr << "text: '" << tobj->GetText() << "'" << endl;
743 VAR(offs);
744 #endif
745 String left = tobj->GetText().substr(0,offs); // get part before cursor
746 VAR(left);
747 tobj->GetText() = tobj->GetText().substr(offs,(*i)->CountPositions()-offs); // keeps the right half
748 VAR(tobj->GetText());
749 insert(i,obj);
750 insert(i,new wxLayoutObjectText(left)); // inserts before
751 }
752 else
753 {
754 wxLayoutObjectList::iterator j = i; // we want to apend after this object
755 j++;
756 if(j != end())
757 insert(j, obj);
758 else
759 push_back(obj);
760 }
761 }
762 m_CursorPosition.x += obj->CountPositions();
763 if(obj->GetType() == WXLO_TYPE_LINEBREAK)
764 m_MaxLine++;
765 }
766
767 void
768 wxLayoutList::Insert(String const &text)
769 {
770 wxLayoutObjectText *tobj = NULL;
771 TRACE(Insert(text));
772
773 if(! m_Editable)
774 return;
775
776 CoordType offs;
777 wxLayoutObjectList::iterator i = FindCurrentObject(&offs);
778
779 if(i != end() && (*i)->GetType() == WXLO_TYPE_TEXT)
780 { // insert into an existing text object:
781 TRACE(inserting into existing object);
782 tobj = (wxLayoutObjectText *)*i ;
783 wxASSERT(tobj);
784 tobj->GetText().insert(offs,text);
785 }
786 else // check whether the previous object is text:
787 {
788 wxLayoutObjectList::iterator j = i;
789 j--;
790 TRACE(checking previous object);
791 if(0 && j != end() && (*j)->GetType() == WXLO_TYPE_TEXT)
792 {
793 tobj = (wxLayoutObjectText *)*i;
794 wxASSERT(tobj);
795 tobj->GetText()+=text;
796 }
797 else // insert a new text object
798 {
799 TRACE(creating new object);
800 Insert(new wxLayoutObjectText(text)); //FIXME not too optimal, slow
801 return; // position gets incremented in Insert(obj)
802 }
803 }
804 m_CursorPosition.x += strlen(text.c_str());
805 }
806
807 CoordType
808 wxLayoutList::GetLineLength(wxLayoutObjectList::iterator i)
809 {
810 if(i == end())
811 return 0;
812
813 CoordType len = 0;
814
815 // search backwards for beginning of line:
816 while(i != begin() && (*i)->GetType() != WXLO_TYPE_LINEBREAK)
817 i--;
818 if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
819 i++;
820 // now we can start counting:
821 while(i != end() && (*i)->GetType() != WXLO_TYPE_LINEBREAK)
822 {
823 len += (*i)->CountPositions();
824 i++;
825 }
826 return len;
827 }
828
829 void
830 wxLayoutList::Clear(int family, int size, int style, int weight,
831 int underline, char const *fg, char const *bg)
832 {
833 wxLayoutObjectList::iterator i = begin();
834
835 while(i != end()) // == while valid
836 erase(i);
837
838 // set defaults
839 m_FontPtSize = size;
840 m_FontUnderline = false;
841 m_FontFamily = family;
842 m_FontStyle = style;
843 m_FontWeight = weight;
844 m_ColourFG = wxTheColourDatabase->FindColour(fg);
845 m_ColourBG = wxTheColourDatabase->FindColour(bg);
846
847 m_Position = wxPoint(0,0);
848 m_CursorPosition = wxPoint(0,0);
849 m_MaxLine = 0;
850 m_LineHeight = (BASELINESTRETCH*m_FontPtSize)/10;
851 m_MaxX = 0; m_MaxY = 0;
852
853 if(m_DefaultSetting)
854 delete m_DefaultSetting;
855 m_DefaultSetting = new
856 wxLayoutObjectCmd(m_FontPtSize,m_FontFamily,m_FontStyle,
857 m_FontWeight,m_FontUnderline,
858 m_ColourFG, m_ColourBG);
859 }