]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/treectrl.cpp
Doesn't reset the stream pos to 0 in CanRead().
[wxWidgets.git] / src / generic / treectrl.cpp
index 98d1ab42ea11bea5c13dbc658272d2dfd35bb5f4..0c7de225773209712422708a2743d1fb060aec96 100644 (file)
@@ -197,11 +197,7 @@ wxTreeTextCtrl::wxTreeTextCtrl( wxWindow *parent, const wxWindowID id,
     bool *accept, wxString *res, wxTreeCtrl *owner,
     const wxString &value, const wxPoint &pos, const wxSize &size,
 #if wxUSE_VALIDATORS
-#  if defined(__VISAGECPP__)
-    int style, const wxValidator* validator, const wxString &name ) :
-#  else
     int style, const wxValidator& validator, const wxString &name ) :
-#  endif
 #endif
   wxTextCtrl( parent, id, value, pos, size, style, validator, name )
 {
@@ -523,17 +519,20 @@ void wxTreeCtrl::Init()
   m_dragCount = 0;
 
   m_renameTimer = new wxTreeRenameTimer( this );
+
+  m_normalFont = wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT );
+  m_boldFont = wxFont( m_normalFont.GetPointSize(),
+                            m_normalFont.GetFamily(),
+                            m_normalFont.GetStyle(),
+                            wxBOLD,
+                            m_normalFont.GetUnderlined());
 }
 
 bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id,
                         const wxPoint& pos, const wxSize& size,
                         long style,
 #if wxUSE_VALIDATORS
-#  if defined(__VISAGECPP__)
-            const wxValidator *validator,
-#  else
             const wxValidator &validator,
-#  endif
 #endif
             const wxString& name )
 {
@@ -828,49 +827,53 @@ wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parentId,
                                       int image, int selImage,
                                       wxTreeItemData *data)
 {
-  wxGenericTreeItem *parent = parentId.m_pItem;
-  if ( !parent )
-  {
-    // should we give a warning here?
-    return AddRoot(text, image, selImage, data);
-  }
+    wxGenericTreeItem *parent = parentId.m_pItem;
+    if ( !parent )
+    {
+        // should we give a warning here?
+        return AddRoot(text, image, selImage, data);
+    }
 
-  wxClientDC dc(this);
-  wxGenericTreeItem *item = new wxGenericTreeItem(parent,
-                                                  text, dc,
-                                                  image, selImage,
-                                                  data);
+    wxClientDC dc(this);
+    wxGenericTreeItem *item =
+        new wxGenericTreeItem( parent, text, dc, image, selImage, data );
 
-  if ( data != NULL )
-  {
-    data->m_pItem = item;
-  }
+    if ( data != NULL )
+    {
+        data->m_pItem = item;
+    }
 
-  parent->Insert( item, previous );
+    parent->Insert( item, previous );
 
-  m_dirty = TRUE;
+    m_dirty = TRUE;
 
-  return item;
+    return item;
 }
 
 wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text,
                                  int image, int selImage,
                                  wxTreeItemData *data)
 {
-  wxCHECK_MSG( !m_anchor, wxTreeItemId(), wxT("tree can have only one root") );
+    wxCHECK_MSG( !m_anchor, wxTreeItemId(), wxT("tree can have only one root") );
 
-  wxClientDC dc(this);
-  m_anchor = new wxGenericTreeItem((wxGenericTreeItem *)NULL, text, dc,
+    wxClientDC dc(this);
+    m_anchor = new wxGenericTreeItem((wxGenericTreeItem *)NULL, text, dc,
                                    image, selImage, data);
-  if ( data != NULL )
-  {
-    data->m_pItem = m_anchor;
-  }
+    if ( data != NULL )
+    {
+        data->m_pItem = m_anchor;
+    }
 
-  Refresh();
-  AdjustMyScrollbars();
+    if (!HasFlag(wxTR_MULTIPLE))
+    {
+        m_current = m_key_current = m_anchor;
+       m_current->SetHilight( TRUE );
+    }
+
+    Refresh();
+    AdjustMyScrollbars();
 
-  return m_anchor;
+    return m_anchor;
 }
 
 wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
@@ -934,32 +937,32 @@ void wxTreeCtrl::DeleteChildren(const wxTreeItemId& itemId)
 
 void wxTreeCtrl::Delete(const wxTreeItemId& itemId)
 {
-  wxGenericTreeItem *item = itemId.m_pItem;
-  wxGenericTreeItem *parent = item->GetParent();
+    wxGenericTreeItem *item = itemId.m_pItem;
+    wxGenericTreeItem *parent = item->GetParent();
 
-  if ( parent )
-  {
-    parent->GetChildren().Remove(item);
-  }
+    if ( parent )
+    {
+        parent->GetChildren().Remove( item );  // remove by value
+    }
 
-  item->DeleteChildren(this);
-  SendDeleteEvent(item);
-  delete item;
+    item->DeleteChildren(this);
+    SendDeleteEvent(item);
+    delete item;
 
-  m_dirty = TRUE;
+    m_dirty = TRUE;
 }
 
 void wxTreeCtrl::DeleteAllItems()
 {
-  if ( m_anchor )
-  {
-    m_anchor->DeleteChildren(this);
-    delete m_anchor;
+    if ( m_anchor )
+    {
+        m_anchor->DeleteChildren(this);
+        delete m_anchor;
 
-    m_anchor = NULL;
+        m_anchor = NULL;
 
-    m_dirty = TRUE;
-  }
+        m_dirty = TRUE;
+    }
 }
 
 void wxTreeCtrl::Expand(const wxTreeItemId& itemId)
@@ -1406,28 +1409,8 @@ int wxTreeCtrl::GetLineHeight(wxGenericTreeItem *item) const
 
 void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
 {
-    // render bold items in bold
-    wxFont fontOld;
-    wxFont fontNew;
-
     if (item->IsBold())
-    {
-        fontOld = dc.GetFont();
-        if (fontOld.Ok())
-        {
-          // VZ: is there any better way to make a bold variant of old font?
-          fontNew = wxFont( fontOld.GetPointSize(),
-                            fontOld.GetFamily(),
-                            fontOld.GetStyle(),
-                            wxBOLD,
-                            fontOld.GetUnderlined());
-          dc.SetFont(fontNew);
-        }
-        else
-        {
-            wxFAIL_MSG(wxT("wxDC::GetFont() failed!"));
-        }
-    }
+        dc.SetFont(m_boldFont);
 
     long text_w = 0;
     long text_h = 0;
@@ -1460,11 +1443,8 @@ void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
     dc.DrawText( item->GetText(), image_w + item->GetX(), item->GetY()
                  + ((total_h > text_h) ? (total_h - text_h)/2 : 0));
 
-    // restore normal font for bold items
-    if (fontOld.Ok())
-    {
-        dc.SetFont( fontOld);
-    }
+    // restore normal font
+    dc.SetFont( m_normalFont );
 }
 
 // Now y stands for the top of the item, whereas it used to stand for middle !
@@ -1612,9 +1592,10 @@ void wxTreeCtrl::OnPaint( wxPaintEvent &WXUNUSED(event) )
     wxPaintDC dc(this);
     PrepareDC( dc );
 
-    dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ) );
-
+    dc.SetFont( m_normalFont );
     dc.SetPen( m_dottedPen );
+
+    // this is now done dynamically
     //if(GetImageList() == NULL)
     // m_lineHeight = (int)(dc.GetCharHeight() + 4);
 
@@ -2011,33 +1992,14 @@ void wxTreeCtrl::CalculateSize( wxGenericTreeItem *item, wxDC &dc )
     long text_w = 0;
     long text_h = 0;
 
-    wxFont fontOld;
-    wxFont fontNew;
     if (item->IsBold())
-    {
-        fontOld = dc.GetFont();
-        if (fontOld.Ok())
-        {
-          // VZ: is there any better way to make a bold variant of old font?
-          fontNew = wxFont( fontOld.GetPointSize(),
-                            fontOld.GetFamily(),
-                            fontOld.GetStyle(),
-                            wxBOLD,
-                            fontOld.GetUnderlined());
-          dc.SetFont(fontNew);
-        }
-        else
-        {
-            wxFAIL_MSG(wxT("wxDC::GetFont() failed!"));
-        }
-    }
+        dc.SetFont(m_boldFont);
 
     dc.GetTextExtent( item->GetText(), &text_w, &text_h );
     text_h+=2;
 
-    // restore normal font for bold items
-    if (fontOld.Ok())
-        dc.SetFont( fontOld);
+    // restore normal font
+    dc.SetFont( m_normalFont );
 
     int image_h = 0;
     int image_w = 0;
@@ -2092,7 +2054,7 @@ void wxTreeCtrl::CalculatePositions()
     wxClientDC dc(this);
     PrepareDC( dc );
 
-    dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ) );
+    dc.SetFont( m_normalFont );
 
     dc.SetPen( m_dottedPen );
     //if(GetImageList() == NULL)