]> git.saurik.com Git - wxWidgets.git/commitdiff
1. added wxTreeCtrl::SetItemBold and IsBold, updated the sample to show them
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 30 Nov 1998 00:08:57 +0000 (00:08 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 30 Nov 1998 00:08:57 +0000 (00:08 +0000)
2. wxTreeItemId HitTest(const wxPoint& point) added - to be implemented
   on other platforms

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1086 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/treectrl.h
samples/treectrl/treetest.cpp
samples/treectrl/treetest.h
src/msw/treectrl.cpp

index 03795479dda2e2b8c4247d21968bad56d8d44b9c..27ab5a75629cf6e6edad0afd6b6799552817b6ee 100644 (file)
@@ -110,9 +110,7 @@ public:
     wxTreeItemId(WXHTREEITEM itemId) { m_itemId = (long)itemId; }
     operator WXHTREEITEM() const { return (WXHTREEITEM)m_itemId; }
 
-    void operator =(WXHTREEITEM item) { m_itemId = (long) item; }
-
-//    wxTreeItemId(long itemId) { m_itemId = itemId; }
+    void operator=(WXHTREEITEM item) { m_itemId = (long) item; }
 
 protected:
     long m_itemId;
@@ -238,6 +236,9 @@ public:
         // usage and loading time.
     void SetItemHasChildren(const wxTreeItemId& item, bool has = TRUE);
 
+        // the item will be shown in bold
+    void SetItemBold(const wxTreeItemId& item, bool bold = TRUE);
+
     // item status inquiries
     // ---------------------
 
@@ -249,6 +250,8 @@ public:
     bool IsExpanded(const wxTreeItemId& item) const;
         // is this item currently selected (the same as has focus)?
     bool IsSelected(const wxTreeItemId& item) const;
+        // is item text in bold font?
+    bool IsBold(const wxTreeItemId& item) const;
 
     // number of children
     // ------------------
@@ -371,19 +374,23 @@ public:
     // helpers
     // -------
 
-    // @@@ do we really need to expose these functions to the application?
+        // determine to which item (if any) belongs the given point (the
+        // coordinates specified are relative to the client area of tree ctrl)
+        // and fill the flags parameter with a bitmask of wxTREE_HITTEST_xxx
+        // constants.
+        //
+        // The first function is more portable (because easier to implement
+        // on other platforms), but the second one returns some extra info.
+    wxTreeItemId HitTest(const wxPoint& point)
+        { int dummy; return HitTest(point, dummy); }
+    wxTreeItemId HitTest(const wxPoint& point, int& flags);
 
         // get the bounding rectangle of the item (or of its label only)
+        // @@@ do we really need to expose this functions to the application?
     void GetBoundingRect(const wxTreeItemId& item,
                          wxRectangle& rect,
                          bool textOnly = FALSE) const;
 
-        // determine to which item (if any) belongs the given point (the
-        // coordinates specified are relative to the client area of tree ctrl)
-        // and fill the flags parameter with a bitmask of wxTREE_HITTEST_xxx
-        // constants
-    wxTreeItemId HitTest(const wxPoint& point, int& flags);
-
     // deprecated
     // ----------
 
index 5085521447ce1a8c12bedcfb837ba8511a35fc38..d5d4ce6e54f936372c08f5e913efd6d951695588 100644 (file)
@@ -43,6 +43,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
   EVT_MENU(TreeTest_Quit, MyFrame::OnQuit)
   EVT_MENU(TreeTest_About, MyFrame::OnAbout)
   EVT_MENU(TreeTest_Dump, MyFrame::OnDump)
+  EVT_MENU(TreeTest_Bold, MyFrame::OnSetBold)
+  EVT_MENU(TreeTest_UnBold, MyFrame::OnClearBold)
   EVT_MENU(TreeTest_Delete, MyFrame::OnDelete)
   EVT_MENU(TreeTest_DeleteAll, MyFrame::OnDeleteAll)
   EVT_MENU(TreeTest_Recreate, MyFrame::OnRecreate)
@@ -101,6 +103,9 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
   file_menu->Append(TreeTest_DeleteAll, "Delete &all items");
   file_menu->Append(TreeTest_Recreate, "&Recreate the tree");
   file_menu->AppendSeparator();
+  file_menu->Append(TreeTest_Bold, "Make item &bold");
+  file_menu->Append(TreeTest_UnBold, "Make item &not bold");
+  file_menu->AppendSeparator();
   file_menu->Append(TreeTest_About, "&About...");
   file_menu->AppendSeparator();
   file_menu->Append(TreeTest_Quit, "E&xit");
@@ -167,6 +172,11 @@ void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event))
   m_treeCtrl->GetItemsRecursively(root, -1);
 }
 
+void MyFrame::DoSetBold(bool bold)
+{
+  m_treeCtrl->SetItemBold(m_treeCtrl->GetSelection(), bold);
+}
+
 void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
 {
   wxTreeItemId item = m_treeCtrl->GetSelection();
@@ -227,7 +237,7 @@ void MyTreeCtrl::AddItemsRecursively(const wxTreeItemId& idParent,
       int image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder;
       wxTreeItemId id = AppendItem(idParent, str, image, image,
                                    new MyTreeItemData(str));
-      AddItemsRecursively(id, numChildren, depth - 1,n+1);
+      AddItemsRecursively(id, numChildren, depth - 1, n + 1);
     }
   }
   //else: done!
@@ -240,7 +250,7 @@ void MyTreeCtrl::AddTestItemsToTree(size_t numChildren,
                         TreeCtrlIcon_Folder, TreeCtrlIcon_Folder,
                         new MyTreeItemData("Root item"));
 
-  AddItemsRecursively(rootId, numChildren, depth,0);
+  AddItemsRecursively(rootId, numChildren, depth, 0);
 }
 
 void MyTreeCtrl::GetItemsRecursively(const wxTreeItemId& idParent, long cookie)
@@ -322,11 +332,12 @@ static inline const char *Bool2String(bool b)
 
 void MyTreeItemData::ShowInfo(wxTreeCtrl *tree)
 {
-  wxLogMessage("Item '%s': %sselected, %sexpanded, "
+  wxLogMessage("Item '%s': %sselected, %sexpanded, %sbold,\n"
                "%u children (%u immediately under this item).",
                m_desc.c_str(),
                Bool2String(tree->IsSelected(GetId())),
                Bool2String(tree->IsExpanded(GetId())),
+               Bool2String(tree->IsBold(GetId())),
                tree->GetChildrenCount(GetId()),
                tree->GetChildrenCount(GetId(), FALSE));
 }
index 7d125f59822a0bfb9a74db779dab8f42fd776e82..440b43197db4a78136ebaad1bad2c6b4234dfc99 100644 (file)
@@ -32,8 +32,8 @@ class MyTreeCtrl : public wxTreeCtrl
 public:
   enum
   {
-    TreeCtrlIcon_Folder,
-    TreeCtrlIcon_File
+    TreeCtrlIcon_File,
+    TreeCtrlIcon_Folder
   };
 
   MyTreeCtrl(wxWindow *parent, const wxWindowID id,
@@ -88,9 +88,14 @@ public:
   void OnDeleteAll(wxCommandEvent& event);
   void OnRecreate(wxCommandEvent& event);
 
+  void OnSetBold(wxCommandEvent& event) { DoSetBold(TRUE); }
+  void OnClearBold(wxCommandEvent& event) { DoSetBold(FALSE); }
+
 private:
   MyTreeCtrl *m_treeCtrl;
 
+  void DoSetBold(bool bold = TRUE);
+
   DECLARE_EVENT_TABLE()
 };
 
@@ -100,6 +105,8 @@ enum
   TreeTest_Quit,
   TreeTest_About,
   TreeTest_Dump,
+  TreeTest_Bold,
+  TreeTest_UnBold,
   TreeTest_Delete,
   TreeTest_DeleteAll,
   TreeTest_Recreate,
index 496e1f38631cb8d4f5eaefef1f549c20b6d92130..cbecafa355f5261000db5a02b3ae827c16466f1f 100644 (file)
@@ -54,7 +54,7 @@
 #undef GetNextSibling
 #endif
 
-#include "wx/treectrl.h"
+#include "wx/msw/treectrl.h"
 
 // Bug in headers, sometimes
 #ifndef TVIS_FOCUSED
@@ -336,16 +336,22 @@ void wxTreeCtrl::SetItemHasChildren(const wxTreeItemId& item, bool has)
     DoSetItem(&tvItem);
 }
 
+void wxTreeCtrl::SetItemBold(const wxTreeItemId& item, bool bold)
+{
+    wxTreeViewItem tvItem(item, TVIF_STATE, TVIS_BOLD);
+    tvItem.state = bold ? TVIS_BOLD : 0;
+    DoSetItem(&tvItem);
+}
+
 // ----------------------------------------------------------------------------
 // Item status
 // ----------------------------------------------------------------------------
 
 bool wxTreeCtrl::IsVisible(const wxTreeItemId& item) const
 {
+    // Bug in Gnu-Win32 headers, so don't use the macro TreeView_GetItemRect
     RECT rect;
-//    return (TreeView_GetItemRect(wxhWnd, (HTREEITEM) (WXHTREEITEM)item, &rect, FALSE) != 0);
-    // Bug in Gnu-Win32 headers, so don't use the macro.
-    return (SendMessage((wxhWnd), TVM_GETITEMRECT, (WPARAM) FALSE, (LPARAM) & rect) != 0);
+    return SendMessage(wxhWnd, TVM_GETITEMRECT, FALSE, (LPARAM)&rect) != 0;
 
 }
 
@@ -376,6 +382,14 @@ bool wxTreeCtrl::IsSelected(const wxTreeItemId& item) const
     return (tvItem.state & TVIS_SELECTED) != 0;
 }
 
+bool wxTreeCtrl::IsBold(const wxTreeItemId& item) const
+{
+    wxTreeViewItem tvItem(item, TVIF_STATE, TVIS_BOLD);
+    DoGetItem(&tvItem);
+
+    return (tvItem.state & TVIS_BOLD) != 0;
+}
+
 // ----------------------------------------------------------------------------
 // navigation
 // ----------------------------------------------------------------------------
@@ -552,10 +566,6 @@ wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
 
 void wxTreeCtrl::Delete(const wxTreeItemId& item)
 {
-    wxTreeItemData *data = GetItemData(item);
-       if(data!=NULL)
-               delete data;    // may be NULL, ok
-
     if ( !TreeView_DeleteItem(wxhWnd, (HTREEITEM)(WXHTREEITEM)item) )
     {
         wxLogLastError("TreeView_DeleteItem");