Keyboard navigatino in tree ctrl

EnsureVisible()


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1122 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 1998-12-07 10:38:39 +00:00
parent 907789a0f7
commit 6daa06370b
7 changed files with 151 additions and 30 deletions

View 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

View 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,

View 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

View 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;

View 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"

View 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;

View 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 )