]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/treectlg.cpp
Initial check in of wxApplet code to CVS
[wxWidgets.git] / src / generic / treectlg.cpp
index 0a49c02a4c030149b3b560bad707e121ecf4ccaf..4669cdca4485d4b1f92b9efe162130d4837f42c3 100644 (file)
@@ -298,23 +298,23 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
     {
         (*m_accept) = TRUE;
         (*m_res) = GetValue();
     {
         (*m_accept) = TRUE;
         (*m_res) = GetValue();
-        
+
         if (!wxPendingDelete.Member(this))
             wxPendingDelete.Append(this);
 
         if ((*m_accept) && ((*m_res) != m_startValue))
             m_owner->OnRenameAccept();
         if (!wxPendingDelete.Member(this))
             wxPendingDelete.Append(this);
 
         if ((*m_accept) && ((*m_res) != m_startValue))
             m_owner->OnRenameAccept();
-            
+
         return;
     }
     if (event.m_keyCode == WXK_ESCAPE)
     {
         (*m_accept) = FALSE;
         (*m_res) = "";
         return;
     }
     if (event.m_keyCode == WXK_ESCAPE)
     {
         (*m_accept) = FALSE;
         (*m_res) = "";
-        
+
         if (!wxPendingDelete.Member(this))
             wxPendingDelete.Append(this);
         if (!wxPendingDelete.Member(this))
             wxPendingDelete.Append(this);
-            
+
         return;
     }
     event.Skip();
         return;
     }
     event.Skip();
@@ -331,7 +331,7 @@ void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event )
     if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x;
     if (mySize.x > sx) sx = mySize.x;
     SetSize(sx, -1);
     if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x;
     if (mySize.x > sx) sx = mySize.x;
     SetSize(sx, -1);
-    
+
     event.Skip();
 }
 
     event.Skip();
 }
 
@@ -632,7 +632,7 @@ void wxGenericTreeCtrl::Init()
 
     m_imageListNormal =
     m_imageListState = (wxImageList *) NULL;
 
     m_imageListNormal =
     m_imageListState = (wxImageList *) NULL;
-    m_ownsImageListNormal = 
+    m_ownsImageListNormal =
     m_ownsImageListState = FALSE;
 
     m_dragCount = 0;
     m_ownsImageListState = FALSE;
 
     m_dragCount = 0;
@@ -818,6 +818,21 @@ void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font
     RefreshLine(pItem);
 }
 
     RefreshLine(pItem);
 }
 
+bool wxGenericTreeCtrl::SetFont( const wxFont &font )
+{
+    wxScrolledWindow::SetFont(font);
+
+    m_normalFont = font ;
+    m_boldFont = wxFont( m_normalFont.GetPointSize(),
+                            m_normalFont.GetFamily(),
+                            m_normalFont.GetStyle(),
+                            wxBOLD,
+                            m_normalFont.GetUnderlined());
+
+    return TRUE;
+}
+
+
 // -----------------------------------------------------------------------------
 // item status inquiries
 // -----------------------------------------------------------------------------
 // -----------------------------------------------------------------------------
 // item status inquiries
 // -----------------------------------------------------------------------------
@@ -1557,7 +1572,7 @@ void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId &item)
     // We have to call this here because the label in
     // question might just have been added and no screen
     // update taken place.
     // We have to call this here because the label in
     // question might just have been added and no screen
     // update taken place.
-    if (m_dirty) wxYield();
+    if (m_dirty) wxYieldIfNeeded();
 
     wxGenericTreeItem *gitem = (wxGenericTreeItem*) item.m_pItem;
 
 
     wxGenericTreeItem *gitem = (wxGenericTreeItem*) item.m_pItem;
 
@@ -1770,7 +1785,15 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
         dc.SetBrush(wxBrush(colBg, wxSOLID));
     }
 
         dc.SetBrush(wxBrush(colBg, wxSOLID));
     }
 
-    dc.DrawRectangle( item->GetX()-2, item->GetY(), item->GetWidth()+2, total_h );
+    if (item->IsSelected() && image != NO_IMAGE)
+    {
+        // If it's selected, and there's an image, then we should
+        // take care to leave the area under the image painted in the
+        // background colour.
+        dc.DrawRectangle( item->GetX() + image_w - 2, item->GetY(), item->GetWidth() - image_w + 2, total_h );
+    }
+    else
+        dc.DrawRectangle( item->GetX()-2, item->GetY(), item->GetWidth()+2, total_h );
 
     if ( image != NO_IMAGE )
     {
 
     if ( image != NO_IMAGE )
     {
@@ -2203,7 +2226,9 @@ wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags)
     // We have to call this here because the label in
     // question might just have been added and no screen
     // update taken place.
     // We have to call this here because the label in
     // question might just have been added and no screen
     // update taken place.
-    if (m_dirty) wxYield();
+    // JACS: removed this because the yield can cause the window to be
+    // deleted from under us if a close window event is pending
+    // if (m_dirty) wxYieldIfNeeded();
 
     wxClientDC dc(this);
     PrepareDC(dc);
 
     wxClientDC dc(this);
     PrepareDC(dc);
@@ -2218,13 +2243,16 @@ wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags)
     if (point.y<0) flags|=wxTREE_HITTEST_ABOVE;
     if (point.y>h) flags|=wxTREE_HITTEST_BELOW;
 
     if (point.y<0) flags|=wxTREE_HITTEST_ABOVE;
     if (point.y>h) flags|=wxTREE_HITTEST_BELOW;
 
-    return m_anchor->HitTest( wxPoint(x, y), this, flags);
+    if (m_anchor)
+        return m_anchor->HitTest( wxPoint(x, y), this, flags);
+    else
+        return wxTreeItemId();
 }
 
 // get the bounding rectangle of the item (or of its label only)
 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId& item,
                          wxRect& rect,
 }
 
 // get the bounding rectangle of the item (or of its label only)
 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId& item,
                          wxRect& rect,
-                         bool textOnly) const
+                         bool WXUNUSED(textOnly)) const
 {
     wxCHECK_MSG( item.IsOk(), FALSE, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
 
 {
     wxCHECK_MSG( item.IsOk(), FALSE, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
 
@@ -2260,7 +2288,7 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
     // We have to call this here because the label in
     // question might just have been added and no screen
     // update taken place.
     // We have to call this here because the label in
     // question might just have been added and no screen
     // update taken place.
-    if (m_dirty) wxYield();
+    if (m_dirty) wxYieldIfNeeded();
 
     wxString s = m_currentEdit->GetText();
     int x = m_currentEdit->GetX();
 
     wxString s = m_currentEdit->GetText();
     int x = m_currentEdit->GetX();
@@ -2292,8 +2320,13 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
     x = dc.LogicalToDeviceX( x );
     y = dc.LogicalToDeviceY( y );
 
     x = dc.LogicalToDeviceX( x );
     y = dc.LogicalToDeviceY( y );
 
-    wxTreeTextCtrl *text = new wxTreeTextCtrl(
-      this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) );
+    wxTreeTextCtrl *text = new wxTreeTextCtrl(this, -1,
+                                              &m_renameAccept,
+                                              &m_renameRes,
+                                              this,
+                                              s,
+                                              wxPoint(x-4,y-4),
+                                              wxSize(w+11,h+8));
     text->SetFocus();
 }
 
     text->SetFocus();
 }
 
@@ -2403,7 +2436,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
             // highlight the current drop target if any
             DrawDropEffect(m_dropTarget);
 
             // highlight the current drop target if any
             DrawDropEffect(m_dropTarget);
 
-            wxYield();
+            wxYieldIfNeeded();
         }
     }
     else if ( (event.LeftUp() || event.RightUp()) && m_isDragging )
         }
     }
     else if ( (event.LeftUp() || event.RightUp()) && m_isDragging )
@@ -2434,7 +2467,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
 
         SetCursor(m_oldCursor);
 
 
         SetCursor(m_oldCursor);
 
-        wxYield();
+        wxYieldIfNeeded();
     }
     else
     {
     }
     else
     {
@@ -2449,7 +2482,9 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
             wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, GetId());
             nevent.m_item = (long) item;
             nevent.m_code = 0;
             wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, GetId());
             nevent.m_item = (long) item;
             nevent.m_code = 0;
-            nevent.m_pointDrag = wxPoint(x, y);
+            CalcScrolledPosition(x, y,
+                                 &nevent.m_pointDrag.x,
+                                 &nevent.m_pointDrag.y);
             nevent.SetEventObject(this);
             GetEventHandler()->ProcessEvent(nevent);
         }
             nevent.SetEventObject(this);
             GetEventHandler()->ProcessEvent(nevent);
         }
@@ -2470,13 +2505,26 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
                 m_lastOnSame = FALSE;
             }
         }
                 m_lastOnSame = FALSE;
             }
         }
-        else
+        else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
         {
             if ( event.LeftDown() )
             {
                 m_lastOnSame = item == m_current;
             }
 
         {
             if ( event.LeftDown() )
             {
                 m_lastOnSame = item == m_current;
             }
 
+            if ( flags & wxTREE_HITTEST_ONITEMBUTTON )
+            {
+                // only toggle the item for a single click, double click on
+                // the button doesn't do anything (it toggles the item twice)
+                if ( event.LeftDown() )
+                {
+                    Toggle( item );
+                }
+
+                // don't select the item if the button was clicked
+                return;
+            }
+
             // how should the selection work for this event?
             bool is_multiple, extended_select, unselect_others;
             EventFlagsToSelType(GetWindowStyleFlag(),
             // how should the selection work for this event?
             bool is_multiple, extended_select, unselect_others;
             EventFlagsToSelType(GetWindowStyleFlag(),
@@ -2484,13 +2532,6 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
                                 event.ControlDown(),
                                 is_multiple, extended_select, unselect_others);
 
                                 event.ControlDown(),
                                 is_multiple, extended_select, unselect_others);
 
-            if ( (flags & wxTREE_HITTEST_ONITEMBUTTON) && event.LeftDown() )
-            {
-                Toggle( item );
-                if ( is_multiple )
-                    return;
-            }
-
             SelectItem(item, unselect_others, extended_select);
 
             if ( event.LeftDClick() )
             SelectItem(item, unselect_others, extended_select);
 
             if ( event.LeftDClick() )
@@ -2502,7 +2543,9 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
                 wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
                 nevent.m_item = (long) item;
                 nevent.m_code = 0;
                 wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
                 nevent.m_item = (long) item;
                 nevent.m_code = 0;
-                nevent.m_pointDrag = wxPoint(x, y);
+                CalcScrolledPosition(x, y,
+                                     &nevent.m_pointDrag.x,
+                                     &nevent.m_pointDrag.y);
                 nevent.SetEventObject( this );
                 GetEventHandler()->ProcessEvent( nevent );
             }
                 nevent.SetEventObject( this );
                 GetEventHandler()->ProcessEvent( nevent );
             }