]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/treectlg.cpp
Put wxContextHelp into cshelp.h/cpp, added wxContextHelpButton
[wxWidgets.git] / src / generic / treectlg.cpp
index 4f5cd2480249778dbc27f6b96bd7f51d5c4337fa..d63cdc8705a8fb9e5d90c5fa4d511eef472aa499 100644 (file)
@@ -84,7 +84,7 @@ public:
                     const wxString &value = wxEmptyString,
                     const wxPoint &pos = wxDefaultPosition,
                     const wxSize &size = wxDefaultSize,
                     const wxString &value = wxEmptyString,
                     const wxPoint &pos = wxDefaultPosition,
                     const wxSize &size = wxDefaultSize,
-                    int style = 0,
+                    int style = wxSIMPLE_BORDER,
                     const wxValidator& validator = wxDefaultValidator,
                     const wxString &name = wxTextCtrlNameStr );
 
                     const wxValidator& validator = wxDefaultValidator,
                     const wxString &name = wxTextCtrlNameStr );
 
@@ -580,6 +580,15 @@ BEGIN_EVENT_TABLE(wxGenericTreeCtrl,wxScrolledWindow)
     EVT_IDLE           (wxGenericTreeCtrl::OnIdle)
 END_EVENT_TABLE()
 
     EVT_IDLE           (wxGenericTreeCtrl::OnIdle)
 END_EVENT_TABLE()
 
+#if !defined(__WXMSW__) || defined(__WIN16__)
+/*
+ * wxTreeCtrl has to be a real class or we have problems with
+ * the run-time information.
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxGenericTreeCtrl)
+#endif
+
 // -----------------------------------------------------------------------------
 // construction/destruction
 // -----------------------------------------------------------------------------
 // -----------------------------------------------------------------------------
 // construction/destruction
 // -----------------------------------------------------------------------------
@@ -794,9 +803,34 @@ void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font
 // item status inquiries
 // -----------------------------------------------------------------------------
 
 // item status inquiries
 // -----------------------------------------------------------------------------
 
-bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId& WXUNUSED(item)) const
+bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId& item) const
 {
 {
-    wxFAIL_MSG(wxT("not implemented"));
+    wxCHECK_MSG( item.IsOk(), FALSE, wxT("invalid tree item") );
+
+       // An item is only visible if it's not a descendant of a collapsed item
+    wxGenericTreeItem *pItem = (wxGenericTreeItem*) item.m_pItem;
+       wxGenericTreeItem* parent = pItem->GetParent();
+       while (parent)
+       {
+               if (!parent->IsExpanded())
+                       return FALSE;
+               parent = parent->GetParent();
+       }
+
+    int startX, startY;
+    GetViewStart(& startX, & startY);
+
+    wxSize clientSize = GetClientSize();
+
+    wxRect rect;
+    if (!GetBoundingRect(item, rect))
+        return FALSE;
+       if (rect.GetWidth() == 0 || rect.GetHeight() == 0)
+               return FALSE;
+    if (rect.GetBottom() < 0 || rect.GetTop() > clientSize.y)
+        return FALSE;
+    if (rect.GetRight() < 0 || rect.GetLeft() > clientSize.x)
+        return FALSE;
 
     return TRUE;
 }
 
     return TRUE;
 }
@@ -912,19 +946,70 @@ wxTreeItemId wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const
                     : wxTreeItemId(siblings[(size_t)(index - 1)]);
 }
 
                     : wxTreeItemId(siblings[(size_t)(index - 1)]);
 }
 
-wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const
+// Only for internal use right now, but should probably be public
+wxTreeItemId wxGenericTreeCtrl::GetNext(const wxTreeItemId& item) const
+{
+  wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
+
+  wxGenericTreeItem *i = (wxGenericTreeItem*) item.m_pItem;
+
+  // First see if there are any children.
+  wxArrayGenericTreeItems& children = i->GetChildren();
+  if (children.GetCount() > 0)
+  {
+     return children.Item(0);
+  }
+  else
+  {
+     // Try a sibling of this or ancestor instead
+     wxTreeItemId p = item;
+     wxTreeItemId toFind;
+     do
+     {
+        toFind = GetNextSibling(p);
+        p = GetParent(p);
+     } while (p.IsOk() && !toFind.IsOk());
+     return toFind;
+  }
+}
+
+wxTreeItemId wxGenericTreeCtrl::GetPrev(const wxTreeItemId& item) const
 {
 {
+  wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
+
   wxFAIL_MSG(wxT("not implemented"));
 
   return wxTreeItemId();
 }
 
   wxFAIL_MSG(wxT("not implemented"));
 
   return wxTreeItemId();
 }
 
+wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const
+{
+  wxTreeItemId id = GetRootItem();
+  if (!id.IsOk())
+    return id;
+
+  do
+  {
+    if (IsVisible(id))
+        return id;
+    id = GetNext(id);
+  } while (id.IsOk());
+
+  return wxTreeItemId();
+}
+
 wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const
 {
   wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
 
 wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const
 {
   wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
 
-  wxFAIL_MSG(wxT("not implemented"));
+  wxTreeItemId id = item;
+  while (id.IsOk())
+  {
+         id = GetNext(id);
 
 
+         if (id.IsOk() && IsVisible(id))
+                 return id;
+  }
   return wxTreeItemId();
 }
 
   return wxTreeItemId();
 }
 
@@ -960,7 +1045,7 @@ wxTreeItemId wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId& parentId,
 
     if ( data != NULL )
     {
 
     if ( data != NULL )
     {
-        data->m_pItem = item;
+        data->m_pItem = (long) item;
     }
 
     parent->Insert( item, previous );
     }
 
     parent->Insert( item, previous );
@@ -981,7 +1066,7 @@ wxTreeItemId wxGenericTreeCtrl::AddRoot(const wxString& text,
                                    image, selImage, data);
     if ( data != NULL )
     {
                                    image, selImage, data);
     if ( data != NULL )
     {
-        data->m_pItem = m_anchor;
+        data->m_pItem = (long) m_anchor;
     }
 
     if (!HasFlag(wxTR_MULTIPLE))
     }
 
     if (!HasFlag(wxTR_MULTIPLE))
@@ -1058,7 +1143,7 @@ wxTreeItemId wxGenericTreeCtrl::AppendItem(const wxTreeItemId& parentId,
 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
 {
     wxTreeEvent event( wxEVT_COMMAND_TREE_DELETE_ITEM, GetId() );
 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
 {
     wxTreeEvent event( wxEVT_COMMAND_TREE_DELETE_ITEM, GetId() );
-    event.m_item = item;
+    event.m_item = (long) item;
     event.SetEventObject( this );
     ProcessEvent( event );
 }
     event.SetEventObject( this );
     ProcessEvent( event );
 }
@@ -1137,7 +1222,7 @@ void wxGenericTreeCtrl::Expand(const wxTreeItemId& itemId)
         return;
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_EXPANDING, GetId() );
         return;
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_EXPANDING, GetId() );
-    event.m_item = item;
+    event.m_item = (long) item;
     event.SetEventObject( this );
 
     if ( ProcessEvent( event ) && !event.IsAllowed() )
     event.SetEventObject( this );
 
     if ( ProcessEvent( event ) && !event.IsAllowed() )
@@ -1179,7 +1264,7 @@ void wxGenericTreeCtrl::Collapse(const wxTreeItemId& itemId)
         return;
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING, GetId() );
         return;
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING, GetId() );
-    event.m_item = item;
+    event.m_item = (long) item;
     event.SetEventObject( this );
     if ( ProcessEvent( event ) && !event.IsAllowed() )
     {
     event.SetEventObject( this );
     if ( ProcessEvent( event ) && !event.IsAllowed() )
     {
@@ -1355,8 +1440,8 @@ void wxGenericTreeCtrl::SelectItem(const wxTreeItemId& itemId,
     }
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGING, GetId() );
     }
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGING, GetId() );
-    event.m_item = item;
-    event.m_itemOld = m_current;
+    event.m_item = (long) item;
+    event.m_itemOld = (long) m_current;
     event.SetEventObject( this );
     // TODO : Here we don't send any selection mode yet !
 
     event.SetEventObject( this );
     // TODO : Here we don't send any selection mode yet !
 
@@ -1687,6 +1772,8 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
     int exposed_x = dc.LogicalToDeviceX( 0 );
     int exposed_y = dc.LogicalToDeviceY( item->GetY() );
 
     int exposed_x = dc.LogicalToDeviceX( 0 );
     int exposed_y = dc.LogicalToDeviceY( item->GetY() );
 
+    bool drawLines = ((GetWindowStyle() & wxTR_NO_LINES) == 0);
+
     if (IsExposed( exposed_x, exposed_y, 10000, GetLineHeight(item) ))  // 10000 = very much
     {
         int startX = horizX;
     if (IsExposed( exposed_x, exposed_y, 10000, GetLineHeight(item) ))  // 10000 = very much
     {
         int startX = horizX;
@@ -1695,11 +1782,13 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
 //        if (!item->HasChildren()) endX += (m_indent+5);
         if (!item->HasChildren()) endX += 20;
 
 //        if (!item->HasChildren()) endX += (m_indent+5);
         if (!item->HasChildren()) endX += 20;
 
-        dc.DrawLine( startX, y, endX, y );
+        if (drawLines)
+            dc.DrawLine( startX, y, endX, y );
 
         if (item->HasPlus())
         {
 
         if (item->HasPlus())
         {
-            dc.DrawLine( horizX+(m_indent+5), y, horizX+(m_indent+15), y );
+            if (drawLines)
+                dc.DrawLine( horizX+(m_indent+5), y, horizX+(m_indent+15), y );
             dc.SetPen( *wxGREY_PEN );
             dc.SetBrush( *wxWHITE_BRUSH );
             dc.DrawRectangle( horizX+(m_indent-5), y-4, 11, 9 );
             dc.SetPen( *wxGREY_PEN );
             dc.SetBrush( *wxWHITE_BRUSH );
             dc.DrawRectangle( horizX+(m_indent-5), y-4, 11, 9 );
@@ -1729,7 +1818,7 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
             if ( attr && attr->HasTextColour() )
                 colText = attr->GetTextColour();
             else
             if ( attr && attr->HasTextColour() )
                 colText = attr->GetTextColour();
             else
-                colText = *wxBLACK;
+                colText = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT );
         }
 
         // prepare to draw
         }
 
         // prepare to draw
@@ -1766,7 +1855,8 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
         if (count > 0)
         {
             semiOldY+=GetLineHeight(children[--n])/2;
         if (count > 0)
         {
             semiOldY+=GetLineHeight(children[--n])/2;
-            dc.DrawLine( horizX+m_indent, oldY+5, horizX+m_indent, semiOldY );
+            if (drawLines)
+                dc.DrawLine( horizX+m_indent, oldY+5, horizX+m_indent, semiOldY );
         }
     }
 }
         }
     }
 }
@@ -1932,7 +2022,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
         case WXK_RETURN:
             {
                 wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
         case WXK_RETURN:
             {
                 wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
-                event.m_item = m_current;
+                event.m_item = (long) m_current;
                 event.m_code = 0;
                 event.SetEventObject( this );
                 GetEventHandler()->ProcessEvent( event );
                 event.m_code = 0;
                 event.SetEventObject( this );
                 GetEventHandler()->ProcessEvent( event );
@@ -2095,6 +2185,27 @@ wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags)
     return m_anchor->HitTest( wxPoint(x, y), this, flags);
 }
 
     return m_anchor->HitTest( wxPoint(x, y), this, flags);
 }
 
+// get the bounding rectangle of the item (or of its label only)
+bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId& item,
+                         wxRect& rect,
+                         bool textOnly) const
+{
+    wxCHECK_MSG( item.IsOk(), FALSE, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
+
+    wxGenericTreeItem *i = (wxGenericTreeItem*) item.m_pItem;
+
+    int startX, startY;
+    GetViewStart(& startX, & startY);
+
+    rect.x = i->GetX() - startX*PIXELS_PER_UNIT;
+       rect.y = i->GetY() - startY*PIXELS_PER_UNIT;
+    rect.width = i->GetWidth();
+       //rect.height = i->GetHeight();
+       rect.height = GetLineHeight(i);
+
+    return TRUE;
+}
+
 /* **** */
 
 void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
 /* **** */
 
 void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
@@ -2104,7 +2215,7 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
     m_currentEdit = (wxGenericTreeItem*) item.m_pItem;
 
     wxTreeEvent te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, GetId() );
     m_currentEdit = (wxGenericTreeItem*) item.m_pItem;
 
     wxTreeEvent te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, GetId() );
-    te.m_item = m_currentEdit;
+    te.m_item = (long) m_currentEdit;
     te.SetEventObject( this );
     GetEventHandler()->ProcessEvent( te );
 
     te.SetEventObject( this );
     GetEventHandler()->ProcessEvent( te );
 
@@ -2158,7 +2269,7 @@ void wxGenericTreeCtrl::OnRenameTimer()
 void wxGenericTreeCtrl::OnRenameAccept()
 {
     wxTreeEvent le( wxEVT_COMMAND_TREE_END_LABEL_EDIT, GetId() );
 void wxGenericTreeCtrl::OnRenameAccept()
 {
     wxTreeEvent le( wxEVT_COMMAND_TREE_END_LABEL_EDIT, GetId() );
-    le.m_item = m_currentEdit;
+    le.m_item = (long) m_currentEdit;
     le.SetEventObject( this );
     le.m_label = m_renameRes;
     GetEventHandler()->ProcessEvent( le );
     le.SetEventObject( this );
     le.m_label = m_renameRes;
     GetEventHandler()->ProcessEvent( le );
@@ -2213,7 +2324,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
                               : wxEVT_COMMAND_TREE_BEGIN_DRAG;
 
         wxTreeEvent nevent( command, GetId() );
                               : wxEVT_COMMAND_TREE_BEGIN_DRAG;
 
         wxTreeEvent nevent( command, GetId() );
-        nevent.m_item = m_current;
+        nevent.m_item = (long) m_current;
         nevent.SetEventObject(this);
 
         // by default the dragging is not supported, the user code must
         nevent.SetEventObject(this);
 
         // by default the dragging is not supported, the user code must
@@ -2267,7 +2378,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
         // generate the drag end event
         wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG, GetId());
 
         // generate the drag end event
         wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG, GetId());
 
-        event.m_item = item;
+        event.m_item = (long) item;
         event.m_pointDrag = wxPoint(x, y);
         event.SetEventObject(this);
 
         event.m_pointDrag = wxPoint(x, y);
         event.SetEventObject(this);
 
@@ -2300,7 +2411,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
         if ( event.RightDown() )
         {
             wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, GetId());
         if ( event.RightDown() )
         {
             wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, GetId());
-            nevent.m_item = item;
+            nevent.m_item = (long) item;
             nevent.m_code = 0;
             nevent.SetEventObject(this);
             GetEventHandler()->ProcessEvent(nevent);
             nevent.m_code = 0;
             nevent.SetEventObject(this);
             GetEventHandler()->ProcessEvent(nevent);
@@ -2346,7 +2457,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
                 m_lastOnSame = FALSE;
 
                 wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
                 m_lastOnSame = FALSE;
 
                 wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
-                nevent.m_item = item;
+                nevent.m_item = (long) item;
                 nevent.m_code = 0;
                 nevent.SetEventObject( this );
                 GetEventHandler()->ProcessEvent( nevent );
                 nevent.m_code = 0;
                 nevent.SetEventObject( this );
                 GetEventHandler()->ProcessEvent( nevent );