From 6daa06370bdb080d3555b1e0f90292489a5e64f9 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 7 Dec 1998 10:38:39 +0000 Subject: [PATCH] Keyboard navigatino in tree ctrl EnsureVisible() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1122 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/gtk/install.txt | 8 ++- docs/gtk/readme.txt | 18 +++-- docs/gtk/todo.txt | 6 -- include/wx/generic/treectrl.h | 4 +- samples/treectrl/treetest.cpp | 8 +-- samples/treectrl/treetest.h | 6 +- src/generic/treectrl.cpp | 131 ++++++++++++++++++++++++++++++++-- 7 files changed, 151 insertions(+), 30 deletions(-) diff --git a/docs/gtk/install.txt b/docs/gtk/install.txt index 3bec5f9ebd..728fd2f749 100644 --- a/docs/gtk/install.txt +++ b/docs/gtk/install.txt @@ -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 diff --git a/docs/gtk/readme.txt b/docs/gtk/readme.txt index ac4bf93b6d..36e8d2272c 100644 --- a/docs/gtk/readme.txt +++ b/docs/gtk/readme.txt @@ -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, diff --git a/docs/gtk/todo.txt b/docs/gtk/todo.txt index b7899507e7..fafe591206 100644 --- a/docs/gtk/todo.txt +++ b/docs/gtk/todo.txt @@ -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 diff --git a/include/wx/generic/treectrl.h b/include/wx/generic/treectrl.h index e0f8ad328d..6397ef5820 100644 --- a/include/wx/generic/treectrl.h +++ b/include/wx/generic/treectrl.h @@ -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; diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index f4f2443213..05b9adb2a3 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -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" diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h index 440b43197d..9adacc8acf 100644 --- a/samples/treectrl/treetest.h +++ b/samples/treectrl/treetest.h @@ -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; diff --git a/src/generic/treectrl.cpp b/src/generic/treectrl.cpp index 43be5aaf8b..5c0ada9b1d 100644 --- a/src/generic/treectrl.cpp +++ b/src/generic/treectrl.cpp @@ -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 ) -- 2.45.2