]> git.saurik.com Git - wxWidgets.git/blobdiff - user/wxLayout/wxllist.cpp
Another small modification... Sorry for CVS list overloading...
[wxWidgets.git] / user / wxLayout / wxllist.cpp
index 92e91f8e94702013391ec1bfa7f238ff490b0c48..7227929365b4fb0ce9f101423d0adf1e9853926e 100644 (file)
@@ -23,7 +23,7 @@
 #endif
 
 #include   "wxllist.h"
-#include   "iostream"
+#include   "iostream.h"
 
 #include   <wx/dc.h>
 #include   <wx/postscrp.h>
 
 #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 WXLAYOUT_DEBUG
 static const char *_t[] = { "invalid", "text", "cmd", "icon",
                             "linebreak"};
@@ -46,6 +42,14 @@ wxLayoutObjectBase::Debug(void)
    cerr << _t[GetType()] << ": size=" << GetSize(&bl).x << ","
         << GetSize(&bl).y << " bl=" << bl; 
 }
+
+#  define   VAR(x)   cerr << #x"=" << x << endl;
+#  define   DBG_POINT(p)   cerr << #p << ": " << p.x << ',' << p.y << endl
+#  define   TRACE(f)   cerr << #f":" << endl;
+#else 
+#  define   VAR(x)   
+#  define   DBG_POINT(p)   
+#  define   TRACE(f)   
 #endif
 
 //-------------------------- wxLayoutObjectText
@@ -322,11 +326,15 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords)
 
    // setting up the default:
    dc.SetTextForeground( *wxBLACK );
+   dc.SetTextBackground( *wxWHITE );
+   dc.SetBackgroundMode( wxSOLID ); // to enable setting of text background
    dc.SetFont( *wxNORMAL_FONT );
 
+
+   //FIXME: who frees the brush, how long does it need to exist?
    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();
@@ -368,6 +376,7 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords)
             dc.GetTextExtent(Str(str), &width,&height, &descent);
             VAR(height);
             VAR(width); VAR(descent);
+            if(width < 1) width = 1;
             dc.DrawLine(position.x+width,
                         position.y+(baseLineSkip-height),
                         position.x+width, position.y+baseLineSkip);
@@ -393,6 +402,8 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords)
 
       // calculate next object's position:
       position.x += size.x;
+      if(position.x > m_MaxX)
+         m_MaxX = position.x;
       
       // do we need to increase the line's height?
       if(size.y > baseLineSkip)
@@ -436,8 +447,6 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords)
             draw = false;
       }
 
-      if(position.x+size.x > m_MaxX)
-         m_MaxX = position.x+size.x;
       // is it a linebreak?
       if(type == WXLO_TYPE_LINEBREAK || i == tail())
       {
@@ -500,6 +509,9 @@ wxLayoutList::Debug(void)
 
 /******************** editing stuff ********************/
 
+// don't change this, I know how to optimise this and will do it real 
+// soon (KB)
+
 wxLayoutObjectList::iterator 
 wxLayoutList::FindObjectCursor(wxPoint const &cpos, CoordType *offset)
 {
@@ -516,11 +528,10 @@ wxLayoutList::FindObjectCursor(wxPoint const &cpos, CoordType *offset)
       width = 0;
       if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
       {
-         if(cpos.y == cursor.y)
+         if(cpos.y == cursor.y && i != begin())
          {
             --i;
-            if(offset)
-               *offset = (*i)->CountPositions();
+            if(offset) *offset = i != end() ? (*i)->CountPositions() : 0;
             return i;
          }
          cursor.x = 0; cursor.y ++;
@@ -683,7 +694,7 @@ wxLayoutList::Delete(CoordType count)
          if(offs == len)
          {
             i++;
-            if((*i)->GetType() == WXLO_TYPE_TEXT)
+            if(i != end() && (*i)->GetType() == WXLO_TYPE_TEXT)
             {
                offs = 0;  // delete from begin of next string
                tobj = (wxLayoutObjectText *)*i;
@@ -844,12 +855,16 @@ wxLayoutList::Clear(int family, int size, int style, int weight,
    m_ColourFG = wxTheColourDatabase->FindColour(fg);
    m_ColourBG = wxTheColourDatabase->FindColour(bg);
 
+   if(! m_ColourFG) m_ColourFG = wxBLACK;
+   if(! m_ColourBG) m_ColourBG = wxWHITE;
+   
    m_Position = wxPoint(0,0);
    m_CursorPosition = wxPoint(0,0);
    m_MaxLine = 0;
    m_LineHeight = (BASELINESTRETCH*m_FontPtSize)/10;
    m_MaxX = 0; m_MaxY = 0;
 
+   
    if(m_DefaultSetting)
       delete m_DefaultSetting;
    m_DefaultSetting = new