]> git.saurik.com Git - wxWidgets.git/commitdiff
Keyboard navigatino in tree ctrl
authorRobert Roebling <robert@roebling.de>
Mon, 7 Dec 1998 10:38:39 +0000 (10:38 +0000)
committerRobert Roebling <robert@roebling.de>
Mon, 7 Dec 1998 10:38:39 +0000 (10:38 +0000)
  EnsureVisible()

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

docs/gtk/install.txt
docs/gtk/readme.txt
docs/gtk/todo.txt
include/wx/generic/treectrl.h
samples/treectrl/treetest.cpp
samples/treectrl/treetest.h
src/generic/treectrl.cpp

index 3bec5f9ebd2af5fb230bcaa3e39f5f2ff95844ac..728fd2f7493b4540331e0cb72994bda30c5a9aba 100644 (file)
@@ -44,9 +44,11 @@ this has no effect, but I tried...
 
 wxWindows/GTK requires the GTK+ library to be installed on your system.
 It has to be a stable version, preferebly version 1.0.6. When using
-a version previous to 1.0.6 you'll get crashes here and there. Although
-wxWindows/GTK now compiles with GTK+ 1.1.3, it does not set work
-properly. Wait for a stable version GTK 1.2. 
+a version previous to 1.0.6 you'll get crashes here and there.
+
+wxWindows/GTK does NOT work with the 1.1.X versions of the GTK+ library
+and we will wait until the 1.2 version comes out and has stabilized
+until we'll work with that library.
 
 You can get the newest version of the GTK+ from the GTK homepage
 at
index ac4bf93b6d57e890d78780e08db21acaed481e8a..36e8d2272c69b7b3d8aa7d9ede6896ba15ee3c89 100644 (file)
@@ -1,7 +1,7 @@
 
   Welcome to wxWindows/Gtk,
   
-you have downloaded version 1.97 of the GTK+ port of C++ library
+you have downloaded version 1.99 of the GTK+ port of C++ library
 wxWindows. Information on how to install can be found in the
 file INSTALL.txt, but if you cannot wait, this should work on
 all systems
@@ -19,9 +19,15 @@ YOUR PROBLEM, SUCH AS YOUR VERSION OF GTK, WXGTK, WHAT
 DISTRIBUTION YOU USE AND WHAT ERROR WAS REPORTED. I know 
 this has no effect, but I tried...
 
-wxWindows/Gtk is still in development and you can have a look
-at the TODO.txt to see what's missing before an official beta
-and - more important - before we can aim at binary compatibility.
+This is the beta release which means that we have a feature
+freeze. We'll move up to versin 2.0 rather soon and from then
+on there will be no more binary incompatible changes. We might
+add more classes, but none that would alter the behaviour of
+the existing ones. The library produced by the install process
+of the final version will be called libwx_gtk_1_0.a (static)
+and libwx_gtk_1_0.so.2.0.0 (shared) so that once a version
+of wxWindows/Gtk for GTK 1.2 comes out we'll change the name
+of the library to avoid linking problems.
 
 More information is available from my homepage at
 
@@ -32,8 +38,8 @@ bug reports or comments to either the wxGTK mailing list or to
 the wxWindows developers list. Information on how to subscribe
 is available from my homepage.
 
-wxWindows/Gtk comes with no guarantee whatsoever. It might crash
-your harddisk or destroy your monitor. It doesn't claim to be
+wxWindows/Gtk doesn't come with any guarantee whatsoever. It might 
+crash your harddisk or destroy your monitor. It doesn't claim to be
 suitable for any special purpose.
 
   Regards,
index b7899507e7ec7b6c5572a595dcc13650ae72fd98..fafe591206da7ac982cf60bf5be193a088e11c66 100644 (file)
@@ -1,15 +1,9 @@
 
 -------------------- High priority ---------------------
 
-wxTreeCtrl
-  -> Keyboard handling.
-
 wxClipboard
   -> On the way, but not functional yet.
   
-Fix printing of bitmaps
-  -> No idea.
-
 -------------------- Low priority ---------------------
     
 OwnerDraw for wxListCtrl and others
index e0f8ad328da0dea6048cc420c041c040c4caae87..6397ef5820ccb782c222f86578280eb42dd6a855 100644 (file)
@@ -56,7 +56,7 @@ public:
     wxTreeItemId(long itemId) { m_pItem = (wxGenericTreeItem *)itemId; }
     operator long() const { return (long)m_pItem; }
 
-//protected:
+//protected: // not for gcc
     // for wxTreeCtrl usage only
     wxTreeItemId(wxGenericTreeItem *pItem) { m_pItem = pItem; }
     
@@ -262,6 +262,8 @@ public:
         // is the item visible (it might be outside the view or not expanded)?
     bool IsVisible(const wxTreeItemId& item) const;
         // does the item has any children?
+    bool HasChildren(const wxTreeItemId& item) const
+      { return ItemHasChildren(item); }
     bool ItemHasChildren(const wxTreeItemId& item) const;
         // is the item expanded (only makes sense if HasChildren())?
     bool IsExpanded(const wxTreeItemId& item) const;
index f4f2443213b3895929a7df0fc8ba16112e582895..05b9adb2a308ae9be0f8e875f29e85a839695645 100644 (file)
@@ -64,7 +64,7 @@ BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl)
   EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsing)
   EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, MyTreeCtrl::OnSelChanged)
   EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, MyTreeCtrl::OnSelChanging)
-  EVT_CHAR(MyTreeCtrl::OnKeyDown)
+  EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown)
 END_EVENT_TABLE()
 
 IMPLEMENT_APP(MyApp)
@@ -317,7 +317,7 @@ void MyTreeCtrl::OnItemCollapsing(wxTreeEvent& event)
   }
 }
 
-void MyTreeCtrl::OnKeyDown(wxTreeEvent& WXUNUSED(event))
+void MyTreeCtrl::OnTreeKeyDown(wxTreeEvent&WXUNUSED(event))
 {
   // show some info about this item
   wxTreeItemId itemId = GetSelection();
@@ -328,7 +328,7 @@ void MyTreeCtrl::OnKeyDown(wxTreeEvent& WXUNUSED(event))
     item->ShowInfo(this);
   }
 
-  wxLogMessage("OnKeyDown");
+  wxLogMessage("OnTreeKeyDown");
 }
 
 static inline const char *Bool2String(bool b)
@@ -336,7 +336,7 @@ static inline const char *Bool2String(bool b)
   return b ? "" : "not ";
 }
 
-void MyTreeItemData::ShowInfo(wxTreeCtrl *tree)
+void MyTreeItemData::ShowInfo(wxTreeCtrl */*tree*/)
 {
 /*
   wxLogMessage("Item '%s': %sselected, %sexpanded, %sbold,\n"
index 440b43197db4a78136ebaad1bad2c6b4234dfc99..9adacc8acf66a928eef9f1eb49727a1f2f18d6b2 100644 (file)
@@ -54,7 +54,7 @@ public:
   void OnItemCollapsing(wxTreeEvent& event);
   void OnSelChanged(wxTreeEvent& event);
   void OnSelChanging(wxTreeEvent& event);
-  void OnKeyDown(wxTreeEvent& event);
+  void OnTreeKeyDown(wxTreeEvent& event);
 
   void GetItemsRecursively(const wxTreeItemId& idParent, long cookie);
 
@@ -88,8 +88,8 @@ public:
   void OnDeleteAll(wxCommandEvent& event);
   void OnRecreate(wxCommandEvent& event);
 
-  void OnSetBold(wxCommandEvent& event) { DoSetBold(TRUE); }
-  void OnClearBold(wxCommandEvent& event) { DoSetBold(FALSE); }
+  void OnSetBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(TRUE); }
+  void OnClearBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(FALSE); }
 
 private:
   MyTreeCtrl *m_treeCtrl;
index 43be5aaf8baed53c12cec42308cabd7f26883da0..5c0ada9b1daf55cae7b34b74fac6ef3118edcf07 100644 (file)
@@ -779,7 +779,7 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& itemId)
     event.m_item = item;
     event.m_itemOld = m_current;
     event.SetEventObject( this );
-    if ( ProcessEvent( event ) && event.WasVetoed() )
+    if ( GetEventHandler()->ProcessEvent( event ) && event.WasVetoed() )
       return;
 
     if ( m_current )
@@ -793,13 +793,46 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& itemId)
     RefreshLine( m_current );
 
     event.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED);
-    ProcessEvent( event );
+    GetEventHandler()->ProcessEvent( event );
   }
 }
 
-void wxTreeCtrl::EnsureVisible(const wxTreeItemId& WXUNUSED(item))
+void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item)
 {
-  wxFAIL_MSG("not implemented");
+  wxGenericTreeItem *gitem = item.m_pItem;
+  
+  int item_y = gitem->GetY();
+  
+  int start_x = 0;
+  int start_y = 0;
+  ViewStart( &start_x, &start_y );
+  start_y *= 10;
+  
+  if (item_y < start_y+3)
+  {
+    int x = 0;
+    int y = 0;
+    m_anchor->GetSize( x, y );
+    y += 2*m_lineHeight;
+    int x_pos = GetScrollPos( wxHORIZONTAL );
+    SetScrollbars( 10, 10, x/10, y/10, x_pos, item_y/10 );
+    return;
+  }
+  
+  int w = 0;
+  int h = 0;
+  GetClientSize( &w, &h );
+  
+  if (item_y > start_y+h-26)
+  {
+    int x = 0;
+    int y = 0;
+    m_anchor->GetSize( x, y );
+    y += 2*m_lineHeight;
+    int x_pos = GetScrollPos( wxHORIZONTAL );
+    SetScrollbars( 10, 10, x/10, y/10, x_pos, (item_y-h+30)/10 );
+     return;
+  }  
 }
 
 void wxTreeCtrl::ScrollTo(const wxTreeItemId& WXUNUSED(item))
@@ -1033,7 +1066,91 @@ void wxTreeCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
 
 void wxTreeCtrl::OnChar( wxKeyEvent &event )
 {
-  // TODO process '+', '-' (expand/collapse branch) and cursor keys
+  if (m_current == 0)
+  { 
+     event.Skip();
+     return;
+  }
+  
+  switch (event.KeyCode())
+  {
+    case '+':
+    case WXK_ADD:
+    {
+      if (HasChildren(m_current) && !IsExpanded(m_current))
+      {
+        Expand(m_current);
+      }
+      return;
+    }
+    case '-':
+    case WXK_SUBTRACT:
+    {
+      if (IsExpanded(m_current))
+      {
+        Collapse(m_current);
+      }
+      return;
+    }
+    case ' ':
+    case WXK_RETURN:
+    {
+      wxTreeEvent event( wxEVT_COMMAND_TREE_KEY_DOWN, GetId() );
+      event.m_item = m_current;
+      event.m_code = 0;
+      event.SetEventObject( this );
+      GetEventHandler()->ProcessEvent( event );
+      return;
+    }
+    case WXK_UP:
+    {
+       wxTreeItemId prev = GetPrevSibling( m_current );
+       if (prev != 0)
+       { 
+         SelectItem( prev );
+          EnsureVisible( prev );
+       }
+       else
+       {
+         prev = GetParent( m_current );
+        if (prev)
+        {
+          EnsureVisible( prev );
+          SelectItem( prev );
+        }
+       }
+      return;
+    }
+    case WXK_DOWN:
+    {
+      if (IsExpanded(m_current))
+      {
+        long cookie = 0;
+       wxTreeItemId child = GetFirstChild( m_current, cookie );
+       SelectItem( child );
+       EnsureVisible( child );
+      }
+      else
+      {
+       wxTreeItemId next = GetNextSibling( m_current );
+       if (next == 0)
+       {
+         wxTreeItemId current = m_current;
+         while (current && !next)
+         {
+           current = GetParent( current );
+           if (current) next = GetNextSibling( current );
+         }
+       }
+       if (next != 0)
+       {
+          SelectItem( next );
+          EnsureVisible( next );
+       }
+      }
+      return;
+    }
+  }
   event.Skip();
 }
 
@@ -1055,7 +1172,7 @@ void wxTreeCtrl::OnMouse( wxMouseEvent &event )
   if ( item == NULL )
     return;
 
-  SelectItem(item);
+  if (!IsSelected(item)) SelectItem(item);
 
   if ( event.LeftDClick() )
   {
@@ -1063,7 +1180,7 @@ void wxTreeCtrl::OnMouse( wxMouseEvent &event )
     event.m_item = item;
     event.m_code = 0;
     event.SetEventObject( this );
-    ProcessEvent( event );
+    GetEventHandler()->ProcessEvent( event );
   }
 
   if ( onButton )