Marco DeFreitas
2014-02-11 19:55:19 UTC
I have a need to append to a wxTreeCtrl and have the tree scroll down all
the way to the bottom to show the newly appended item. Under wxGTK-2.8.12
the EnsureVisible function allowed the specified item to be totally
visible. Under wxGTK-3.0.0, it appears to only be partially visible. Note
that under wxMSW-3.0.0, the EnsureVisible function seems to fully show the
specified item, so it seems to be a GTK issue?
I don't know if this is related, but the treectrl sample program seemed to
have a problem as well. If I create many items and then select "Make the
last item visible" from the "Tree" pulldown menu, nothing happens.
This is a sample program that shows my issue. It creates a tree, and then
from the menu you can append. Note that the newly appended item is only
partially shown. Is there a way to scroll all the way to the bottom? (The
ScrollTo function did not seem to do the job either).
#include "wx/wx.h"
#include "wx/treectrl.h"
#define MY_ADD_ID wxID_HIGHEST + 1
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame();
void OnAdd(wxCommandEvent& event);
void OnClose(wxCloseEvent& event);
private:
wxTreeCtrl *m_tree;
wxTreeItemId m_folder;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(MY_ADD_ID, MyFrame::OnAdd)
EVT_CLOSE( MyFrame::OnClose)
END_EVENT_TABLE()
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame();
frame->Show(true);
return true;
}
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)
MyFrame::MyFrame()
:
wxFrame(NULL, wxID_ANY, "test")
{
wxMenuBar *mb = new wxMenuBar;
wxMenu *fmenu = new wxMenu;
fmenu->Append(MY_ADD_ID, "Append an item");
mb->Append(fmenu, "File");
SetMenuBar(mb);
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
m_tree = new wxTreeCtrl(this, wxID_ANY, wxDefaultPosition,
wxSize(300, 300), wxTR_HAS_BUTTONS|wxTR_HIDE_ROOT|wxTR_LINES_AT_ROOT|
wxTR_MULTIPLE|wxBORDER_SUNKEN);
sizer->Add(m_tree, 1, wxALIGN_CENTER_HORIZONTAL|wxTOP|wxLEFT|wxRIGHT|
wxEXPAND, 5);
wxTreeItemId root = m_tree->AddRoot("Root");
wxTreeItemId last_id;
m_folder = m_tree->AppendItem(root, "Folder");
for (int i = 0; i < 50; i++) {
wxString data;
data << "data" << i;
last_id = m_tree->AppendItem(m_folder, data);
}
m_tree->EnsureVisible(last_id);
SetSizerAndFit(sizer);
}
void MyFrame::OnAdd(wxCommandEvent& event)
{
wxTreeItemId id = m_tree->AppendItem(m_folder, "NewItem");
m_tree->EnsureVisible(id);
}
void MyFrame::OnClose(wxCloseEvent& event)
{
Destroy();
}
---
Thanks,
Marco
the way to the bottom to show the newly appended item. Under wxGTK-2.8.12
the EnsureVisible function allowed the specified item to be totally
visible. Under wxGTK-3.0.0, it appears to only be partially visible. Note
that under wxMSW-3.0.0, the EnsureVisible function seems to fully show the
specified item, so it seems to be a GTK issue?
I don't know if this is related, but the treectrl sample program seemed to
have a problem as well. If I create many items and then select "Make the
last item visible" from the "Tree" pulldown menu, nothing happens.
This is a sample program that shows my issue. It creates a tree, and then
from the menu you can append. Note that the newly appended item is only
partially shown. Is there a way to scroll all the way to the bottom? (The
ScrollTo function did not seem to do the job either).
#include "wx/wx.h"
#include "wx/treectrl.h"
#define MY_ADD_ID wxID_HIGHEST + 1
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame();
void OnAdd(wxCommandEvent& event);
void OnClose(wxCloseEvent& event);
private:
wxTreeCtrl *m_tree;
wxTreeItemId m_folder;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(MY_ADD_ID, MyFrame::OnAdd)
EVT_CLOSE( MyFrame::OnClose)
END_EVENT_TABLE()
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame();
frame->Show(true);
return true;
}
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)
MyFrame::MyFrame()
:
wxFrame(NULL, wxID_ANY, "test")
{
wxMenuBar *mb = new wxMenuBar;
wxMenu *fmenu = new wxMenu;
fmenu->Append(MY_ADD_ID, "Append an item");
mb->Append(fmenu, "File");
SetMenuBar(mb);
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
m_tree = new wxTreeCtrl(this, wxID_ANY, wxDefaultPosition,
wxSize(300, 300), wxTR_HAS_BUTTONS|wxTR_HIDE_ROOT|wxTR_LINES_AT_ROOT|
wxTR_MULTIPLE|wxBORDER_SUNKEN);
sizer->Add(m_tree, 1, wxALIGN_CENTER_HORIZONTAL|wxTOP|wxLEFT|wxRIGHT|
wxEXPAND, 5);
wxTreeItemId root = m_tree->AddRoot("Root");
wxTreeItemId last_id;
m_folder = m_tree->AppendItem(root, "Folder");
for (int i = 0; i < 50; i++) {
wxString data;
data << "data" << i;
last_id = m_tree->AppendItem(m_folder, data);
}
m_tree->EnsureVisible(last_id);
SetSizerAndFit(sizer);
}
void MyFrame::OnAdd(wxCommandEvent& event)
{
wxTreeItemId id = m_tree->AppendItem(m_folder, "NewItem");
m_tree->EnsureVisible(id);
}
void MyFrame::OnClose(wxCloseEvent& event)
{
Destroy();
}
---
Thanks,
Marco
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users