onButton = TRUE;
return this;
}
-
+
int w = m_width;
if (m_image != -1) w += 20;
m_imageListNormal =
m_imageListState = (wxImageList *) NULL;
-
+
m_dragCount = 0;
}
bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
- long style,
- const wxValidator &validator,
- const wxString& name )
+ long style,
+ const wxValidator &validator,
+ const wxString& name )
{
Init();
wxScrolledWindow::Create( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name );
-
+
SetValidator( validator );
SetBackgroundColour( *wxWHITE );
wxArrayTreeItems& children = item.m_pItem->GetChildren();
if ( (size_t)cookie < children.Count() )
{
- return item.m_pItem->GetChildren().Item(cookie++);
+ return children.Item(cookie++);
}
else
{
}
}
+wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), wxTreeItemId(), "invalid tree item" );
+
+ wxArrayTreeItems& children = item.m_pItem->GetChildren();
+ return children.IsEmpty() ? wxTreeItemId() : children.Last();
+}
+
wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const
{
wxCHECK_MSG( item.IsOk(), wxTreeItemId(), "invalid tree item" );
{
wxGenericTreeItem *item = itemId.m_pItem;
- if ( !item->HasPlus() )
+ if ( !item->HasPlus() )
return;
-
+
if ( item->IsExpanded() )
return;
int start_y = 0;
ViewStart( &start_x, &start_y );
start_y *= 10;
-
+
int client_h = 0;
int client_w = 0;
GetClientSize( &client_w, &client_h );
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-client_h/2)/10 );
+ SetScrollbars( 10, 10, x/10, y/10, x_pos, (item_y-client_h/2)/10 );
return;
}
wxCHECK_RET( itemId.IsOk(), "invalid tree item" );
wxGenericTreeItem *item = itemId.m_pItem;
-
+
wxCHECK_RET( !s_treeBeingSorted,
"wxTreeCtrl::SortChildren is not reentrant" );
s_treeBeingSorted = this;
children.Sort(tree_ctrl_compare_func);
s_treeBeingSorted = NULL;
-
+
m_dirty = TRUE;
}
//else: don't make the tree dirty as nothing changed
/* render bold items in bold */
wxFont fontOld;
wxFont fontNew;
-
+
if (item->IsBold())
{
fontOld = dc.GetFont();
{
m_imageListNormal->GetSize( item->GetSelectedImage(), image_w, image_h );
image_w += 4;
- }
+ }
else if (item->GetImage() != -1)
{
m_imageListNormal->GetSize( item->GetImage(), image_w, image_h );
dc.DrawLine( horizX+13, y, horizX+18, y );
if (!item->IsExpanded())
- {
+ {
dc.DrawLine( horizX+15, y-2, horizX+15, y+3 );
- }
+ }
}
if (item->HasHilight())
void wxTreeCtrl::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
{
m_hasFocus = TRUE;
-
+
if (m_current) RefreshLine( m_current );
}
void wxTreeCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
{
m_hasFocus = FALSE;
-
+
if (m_current) RefreshLine( m_current );
}
void wxTreeCtrl::OnChar( wxKeyEvent &event )
{
- wxTreeEvent te( wxEVT_COMMAND_TREE_KEY_DOWN, GetId() );
- te.m_code = event.KeyCode();
- te.SetEventObject( this );
- GetEventHandler()->ProcessEvent( te );
+ wxTreeEvent te( wxEVT_COMMAND_TREE_KEY_DOWN, GetId() );
+ te.m_code = event.KeyCode();
+ te.SetEventObject( this );
+ GetEventHandler()->ProcessEvent( te );
- if (m_current == 0)
- {
- event.Skip();
- return;
- }
+ if (m_current == 0)
+ {
+ event.Skip();
+ return;
+ }
- switch (event.KeyCode())
- {
- case '+':
- case WXK_ADD:
- if (m_current->HasPlus() && !IsExpanded(m_current))
- {
- Expand(m_current);
- }
- break;
+ switch (event.KeyCode())
+ {
+ case '+':
+ case WXK_ADD:
+ if (m_current->HasPlus() && !IsExpanded(m_current))
+ {
+ Expand(m_current);
+ }
+ break;
- case '-':
- case WXK_SUBTRACT:
- if (IsExpanded(m_current))
- {
- Collapse(m_current);
- }
- break;
+ case '-':
+ case WXK_SUBTRACT:
+ if (IsExpanded(m_current))
+ {
+ Collapse(m_current);
+ }
+ break;
- case '*':
- case WXK_MULTIPLY:
- Toggle(m_current);
- break;
+ case '*':
+ case WXK_MULTIPLY:
+ Toggle(m_current);
+ break;
- case ' ':
- case WXK_RETURN:
- {
- wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
- event.m_item = m_current;
- event.m_code = 0;
- event.SetEventObject( this );
- GetEventHandler()->ProcessEvent( event );
- }
- break;
+ case ' ':
+ case WXK_RETURN:
+ {
+ wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
+ event.m_item = m_current;
+ event.m_code = 0;
+ event.SetEventObject( this );
+ GetEventHandler()->ProcessEvent( event );
+ }
+ break;
- case WXK_UP:
- {
- wxTreeItemId prev = GetPrevSibling( m_current );
- if (!prev)
- {
- prev = GetParent( m_current );
- long cockie = 0;
- wxTreeItemId current = m_current;
- if (current == GetFirstChild( prev, cockie ))
- {
- // otherwise we return to where we came from
- SelectItem( prev );
- EnsureVisible( prev );
- break;
- }
- }
- if (prev)
- {
- while (IsExpanded(prev))
- {
- int c = (int)GetChildrenCount( prev, FALSE );
- long cockie = 0;
- prev = GetFirstChild( prev, cockie );
- for (int i = 0; i < c-1; i++)
- prev = GetNextSibling( prev );
- }
- SelectItem( prev );
- EnsureVisible( prev );
- }
- }
- break;
- case WXK_LEFT:
- {
- wxTreeItemId prev = GetPrevSibling( m_current );
- if (prev != 0)
- {
- SelectItem( prev );
- EnsureVisible( prev );
- }
- else
- {
- prev = GetParent( m_current );
- if (prev)
- {
- EnsureVisible( prev );
- SelectItem( prev );
- }
- }
- }
- break;
+ // up goes to the previous sibling or to the last of its children if
+ // it's expanded
+ case WXK_UP:
+ {
+ wxTreeItemId prev = GetPrevSibling( m_current );
+ if (!prev)
+ {
+ prev = GetParent( m_current );
+ long cockie = 0;
+ wxTreeItemId current = m_current;
+ if (current == GetFirstChild( prev, cockie ))
+ {
+ // otherwise we return to where we came from
+ SelectItem( prev );
+ EnsureVisible( prev );
+ break;
+ }
+ }
+ if (prev)
+ {
+ while (IsExpanded(prev))
+ {
+ int c = (int)GetChildrenCount( prev, FALSE );
+ long cockie = 0;
+ prev = GetFirstChild( prev, cockie );
+ for (int i = 0; i < c-1; i++)
+ prev = GetNextSibling( prev );
+ }
+ SelectItem( prev );
+ EnsureVisible( prev );
+ }
+ }
+ break;
- case WXK_RIGHT:
- // this works the same as the down arrow except that we also expand the
- // item if it wasn't expanded yet
- Expand(m_current);
- // fall through
+ // left arrow goes to the parent
+ case WXK_LEFT:
+ {
+ wxTreeItemId prev = GetParent( m_current );
+ if (prev)
+ {
+ EnsureVisible( prev );
+ SelectItem( prev );
+ }
+ }
+ break;
- 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)
+ case WXK_RIGHT:
+ // this works the same as the down arrow except that we also expand the
+ // item if it wasn't expanded yet
+ Expand(m_current);
+ // fall through
+
+ case WXK_DOWN:
{
- current = GetParent( current );
- if (current) next = GetNextSibling( current );
+ 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 );
+ }
+ }
}
- }
- if (next != 0)
- {
- SelectItem( next );
- EnsureVisible( next );
- }
- }
- }
- break;
+ break;
- default:
- event.Skip();
- }
+ // <End> selects the last visible tree item
+ case WXK_END:
+ {
+ wxTreeItemId last = GetRootItem();
+
+ while ( last.IsOk() && IsExpanded(last) )
+ {
+ wxTreeItemId lastChild = GetLastChild(last);
+
+ // it may happen if the item was expanded but then all of
+ // its children have been deleted - so IsExpanded() returned
+ // TRUE, but GetLastChild() returned invalid item
+ if ( !lastChild )
+ break;
+
+ last = lastChild;
+ }
+
+ if ( last.IsOk() )
+ {
+ EnsureVisible( last );
+ SelectItem( last );
+ }
+ }
+ break;
+
+ // <Home> selects the root item
+ case WXK_HOME:
+ {
+ wxTreeItemId prev = GetRootItem();
+ if (prev)
+ {
+ EnsureVisible( prev );
+ SelectItem( prev );
+ }
+ }
+ break;
+
+ default:
+ event.Skip();
+ }
}
wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& WXUNUSED(flags))
if ( !(event.LeftDown() || event.LeftDClick() || event.Dragging()) ) return;
if ( !m_anchor ) return;
-
+
wxClientDC dc(this);
PrepareDC(dc);
long x = dc.DeviceToLogicalX( (long)event.GetX() );
bool onButton = FALSE;
wxGenericTreeItem *item = m_anchor->HitTest( wxPoint(x,y), onButton );
-
+
if (item == NULL) return; /* we hit the blank area */
if (event.Dragging())
if (m_dragCount == 2) /* small drag latency (3?) */
{
m_dragCount = 0;
-
+
wxTreeEvent nevent(wxEVT_COMMAND_TREE_BEGIN_DRAG, GetId());
nevent.m_item = m_current;
nevent.SetEventObject(this);
}
return;
}
-
+
if (!IsSelected(item)) SelectItem(item); /* we dont support multiple selections, BTW */
if (event.LeftDClick())
if ( !item->IsExpanded() )
{
- /* we dont need to calculate collapsed branches */
+ /* we dont need to calculate collapsed branches */
return;
}
rect.y = dc.LogicalToDeviceY( item->GetY() - 2 );
rect.width = 1000;
rect.height = dc.GetCharHeight() + 6;
-
+
Refresh( TRUE, &rect );
}
// Created: 07/05/98
// RCS-ID: $Id$
// Copyright: (c) Denis Pershin
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
y = 0;
m_needParent = TRUE;
-
+
printf("precreate\n");
PreCreation( parent, id, pos, size, style, name );
printf("Robert's new insertion code :-)\n");
m_parent->AddChild( this );
(m_parent->m_insertCallback)( m_parent, this );
-
+
printf("postcreate\n");
PostCreation();
gtk_widget_realize(GTK_WIDGET(m_tree));
Show(TRUE);
-
+
return TRUE;
}
return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent)->children, cookie)->data);
}
+wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const
+{
+ GtkTreeItem *p = (GtkTreeItem *)item;
+ GtkWidget *parent = GTK_WIDGET(p)->parent;
+
+ wxCHECK_MSG( GTK_IS_TREE(parent), NULL, "invalid tree item" );
+
+ return GTK_TREE_ITEM(g_list_last(GTK_TREE(parent)->children)->data);
+}
+
wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const {
GtkTreeItem *p = (GtkTreeItem *)item;
GtkWidget *parent = GTK_WIDGET(p)->parent;
wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
const wxString& text, int image, int selectedImage,
- wxTreeItemData *data) {
+ wxTreeItemData *data) {
return p_InsertItem(parent, text, image, selectedImage, data);
}
wxTreeItemId wxTreeCtrl::p_InsertItem(GtkTreeItem *p,
const wxString& text, int image, int selectedImage,
- wxTreeItemData *data) {
+ wxTreeItemData *data) {
GtkTreeItem *item;
printf("begin insert\n");
if (next != NULL)
return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
-
+
return (-1);
}
if (next != NULL)
return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
-
+
return (-1);
}
if (next != NULL)
return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
-
+
return (-1);
}
// Created: 07/05/98
// RCS-ID: $Id$
// Copyright: (c) Denis Pershin
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
y = 0;
m_needParent = TRUE;
-
+
printf("precreate\n");
PreCreation( parent, id, pos, size, style, name );
printf("Robert's new insertion code :-)\n");
m_parent->AddChild( this );
(m_parent->m_insertCallback)( m_parent, this );
-
+
printf("postcreate\n");
PostCreation();
gtk_widget_realize(GTK_WIDGET(m_tree));
Show(TRUE);
-
+
return TRUE;
}
return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent)->children, cookie)->data);
}
+wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const
+{
+ GtkTreeItem *p = (GtkTreeItem *)item;
+ GtkWidget *parent = GTK_WIDGET(p)->parent;
+
+ wxCHECK_MSG( GTK_IS_TREE(parent), NULL, "invalid tree item" );
+
+ return GTK_TREE_ITEM(g_list_last(GTK_TREE(parent)->children)->data);
+}
+
wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const {
GtkTreeItem *p = (GtkTreeItem *)item;
GtkWidget *parent = GTK_WIDGET(p)->parent;
wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
const wxString& text, int image, int selectedImage,
- wxTreeItemData *data) {
+ wxTreeItemData *data) {
return p_InsertItem(parent, text, image, selectedImage, data);
}
wxTreeItemId wxTreeCtrl::p_InsertItem(GtkTreeItem *p,
const wxString& text, int image, int selectedImage,
- wxTreeItemData *data) {
+ wxTreeItemData *data) {
GtkTreeItem *item;
printf("begin insert\n");
if (next != NULL)
return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
-
+
return (-1);
}
if (next != NULL)
return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
-
+
return (-1);
}
if (next != NULL)
return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
-
+
return (-1);
}