]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/treebase.cpp
Restore ability to parse hours only with wxDateTime::ParseTime().
[wxWidgets.git] / src / common / treebase.cpp
index e573f9cec926a0e2699193529d86aa4e86ae9f96..82c7da2704eca91ff545ab85437360a514a63457 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        treebase.cpp
+// Name:        src/common/treebase.cpp
 // Purpose:     Base wxTreeCtrl classes
 // Author:      Julian Smart
 // Created:     01/02/97
@@ -35,27 +35,27 @@ extern WXDLLEXPORT_DATA(const char) wxTreeCtrlNameStr[] = "treeCtrl";
 // events
 // ----------------------------------------------------------------------------
 
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_BEGIN_DRAG, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_BEGIN_RDRAG, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_END_LABEL_EDIT, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_DELETE_ITEM, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_GET_INFO, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_SET_INFO, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_ITEM_EXPANDED, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_ITEM_EXPANDING, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_ITEM_COLLAPSED, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_ITEM_COLLAPSING, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_SEL_CHANGING, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_KEY_DOWN, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_END_DRAG, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, wxTreeEvent );
-wxDEFINE_EVENT( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_BEGIN_DRAG, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_BEGIN_RDRAG, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_BEGIN_LABEL_EDIT, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_END_LABEL_EDIT, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_DELETE_ITEM, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_GET_INFO, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_SET_INFO, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_ITEM_EXPANDED, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_ITEM_EXPANDING, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_ITEM_COLLAPSED, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_ITEM_COLLAPSING, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_SEL_CHANGED, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_SEL_CHANGING, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_KEY_DOWN, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_ITEM_ACTIVATED, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_ITEM_RIGHT_CLICK, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_ITEM_MIDDLE_CLICK, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_END_DRAG, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_STATE_IMAGE_CLICK, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_ITEM_GETTOOLTIP, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_TREE_ITEM_MENU, wxTreeEvent );
 
 // ----------------------------------------------------------------------------
 // XTI
@@ -111,9 +111,9 @@ wxEND_FLAGS( wxTreeCtrlStyle )
 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxTreeCtrl, wxControl, "wx/treectrl.h")
 
 wxBEGIN_PROPERTIES_TABLE(wxTreeCtrl)
-wxEVENT_PROPERTY( TextUpdated, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEvent )
-wxEVENT_RANGE_PROPERTY( TreeEvent, wxEVT_COMMAND_TREE_BEGIN_DRAG, \
-                       wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, wxTreeEvent )
+wxEVENT_PROPERTY( TextUpdated, wxEVT_TEXT, wxCommandEvent )
+wxEVENT_RANGE_PROPERTY( TreeEvent, wxEVT_TREE_BEGIN_DRAG, \
+                       wxEVT_TREE_STATE_IMAGE_CLICK, wxTreeEvent )
 
 wxPROPERTY_FLAGS( WindowStyle, wxTreeCtrlStyle, long, SetWindowStyleFlag, \
                  GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
@@ -167,6 +167,22 @@ wxTreeEvent::wxTreeEvent(const wxTreeEvent & event)
 // wxTreeCtrlBase
 // ----------------------------------------------------------------------------
 
+wxTreeCtrlBase::wxTreeCtrlBase()
+{
+    m_imageListNormal =
+    m_imageListState = NULL;
+    m_ownsImageListNormal =
+    m_ownsImageListState = false;
+
+    // arbitrary default
+    m_spacing = 18;
+
+    // quick DoGetBestSize calculation
+    m_quickBestSize = true;
+
+    Connect(wxEVT_CHAR_HOOK, wxKeyEventHandler(wxTreeCtrlBase::OnCharHook));
+}
+
 wxTreeCtrlBase::~wxTreeCtrlBase()
 {
     if (m_ownsImageListNormal)
@@ -323,8 +339,10 @@ void wxTreeCtrlBase::CollapseAllChildren(const wxTreeItemId& item)
         CollapseAllChildren(idCurr);
     }
 
-    // then collapse this element too
-    Collapse(item);
+    // then collapse this element too unless it's the hidden root which can't
+    // be collapsed
+    if ( item != GetRootItem() || !HasFlag(wxTR_HIDE_ROOT) )
+        Collapse(item);
     Thaw();
 }
 
@@ -333,4 +351,26 @@ bool wxTreeCtrlBase::IsEmpty() const
     return !GetRootItem().IsOk();
 }
 
+void wxTreeCtrlBase::OnCharHook(wxKeyEvent& event)
+{
+    if ( GetEditControl() )
+    {
+        bool discardChanges = false;
+        switch ( event.GetKeyCode() )
+        {
+            case WXK_ESCAPE:
+                discardChanges = true;
+                // fall through
+
+            case WXK_RETURN:
+                EndEditLabel(GetFocusedItem(), discardChanges);
+
+                // Do not call Skip() below.
+                return;
+        }
+    }
+
+    event.Skip();
+}
+
 #endif // wxUSE_TREECTRL