Discussion:
wxGTK-3.0.0: Problem with wxTreeCtrl::EnsureVisible
Marco DeFreitas
2014-02-11 19:55:19 UTC
Permalink
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
--
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
Vadim Zeitlin
2014-02-11 20:51:34 UTC
Permalink
On Tue, 11 Feb 2014 11:55:19 -0800 (PST) Marco DeFreitas wrote:

MD> I have a need to append to a wxTreeCtrl and have the tree scroll down all
MD> the way to the bottom to show the newly appended item. Under wxGTK-2.8.12
MD> the EnsureVisible function allowed the specified item to be totally
MD> visible. Under wxGTK-3.0.0, it appears to only be partially visible. Note
MD> that under wxMSW-3.0.0, the EnsureVisible function seems to fully show the
MD> specified item, so it seems to be a GTK issue?
MD>
MD> I don't know if this is related, but the treectrl sample program seemed to
MD> have a problem as well. If I create many items and then select "Make the
MD> last item visible" from the "Tree" pulldown menu, nothing happens.

What do I need to do exactly to reproduce this problem in the sample?

Thanks,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Marco DeFreitas
2014-02-11 22:22:47 UTC
Permalink
VZ> What do I need to do exactly to reproduce this problem in the sample?

Hey Vadim,

In the sample program, I tried to "Append many items" from the "Tree"
pulldown menu (to get scrollbars). Then I tried to "Make the last item
visible" from the "Tree" pulldown menu and absolutely nothing happens. That
is why I included my own sample program.

Looking at the treectrl sample source code, it looks like a check is made
in MyTreeCtrl::DoEnsureVisible to see if the last item is valid before
actually doing a wxTreeCtrl::EnsureVisible. The sample code must be doing
invalid adds since the wxTreeItemId::IsOk is returning false.

I also tried NOT using the "Append many items" from the "Tree" pulldown
menu and just adjust the height of the frame so I get scroll bars. But
again, the "Make the last item visible" from the "Tree" pulldown menu does
nothing. Evidently even the initially set up tree items have problems.

My small sample program creates a valid tree and thus shows the problem.

--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
Marco DeFreitas
2014-02-12 19:11:58 UTC
Permalink
VZ> What do I need to do exactly to reproduce this problem in the sample?

More info... In the sample program, it looks the the tree items' are ok
when first added, but somewhere along the line it becomes invalid. Perhaps
this is due to nesting in folders or expanding folders? By flattening the
tree in the sample program, I was able to get around the issue of tree
items being invalid and thus demonstrate my problem.

I made the following changes in .../samples/treectrl/treetest.cpp:

Line 60-61: Change to:
static const int NUM_CHILDREN_PER_LEVEL = 50
static const int NUM_LEVELS = 1

Line 377: Change to:
long style = wxTR_DEFAULT_STYLE | wxTR_HIDE_ROOT |

Now, if you run the sample program and select "Make the last item visible",
you will see that it is only partially visible.

So, I guess there are two problems? Why isn't EnsureVisible making the
specified item completely visible, and why is nesting in folders
invalidating items.

Regards,
Marco
Post by Marco DeFreitas
VZ> What do I need to do exactly to reproduce this problem in the sample?
Hey Vadim,
In the sample program, I tried to "Append many items" from the "Tree"
pulldown menu (to get scrollbars). Then I tried to "Make the last item
visible" from the "Tree" pulldown menu and absolutely nothing happens. That
is why I included my own sample program.
Looking at the treectrl sample source code, it looks like a check is made
in MyTreeCtrl::DoEnsureVisible to see if the last item is valid before
actually doing a wxTreeCtrl::EnsureVisible. The sample code must be doing
invalid adds since the wxTreeItemId::IsOk is returning false.
I also tried NOT using the "Append many items" from the "Tree" pulldown
menu and just adjust the height of the frame so I get scroll bars. But
again, the "Make the last item visible" from the "Tree" pulldown menu does
nothing. Evidently even the initially set up tree items have problems.
My small sample program creates a valid tree and thus shows the problem.
--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
Marco DeFreitas
2014-02-21 15:58:22 UTC
Permalink
Hey Vadim,

Were you able to duplicate this problem? At the very least, with the
treectrl sample program, you should see that:
Tree->Append many items
(expand the root folder)
Tree->Make the last item visible

does not work... that is, the last item is not shown.

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
Vadim Zeitlin
2014-02-21 16:31:45 UTC
Permalink
On Fri, 21 Feb 2014 07:58:22 -0800 (PST) Marco DeFreitas wrote:

MD> Were you able to duplicate this problem?

Sorry, I simply didn't have time to debug it yet.
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Vadim Zeitlin
2014-02-22 22:07:24 UTC
Permalink
On Fri, 21 Feb 2014 07:58:22 -0800 (PST) Marco DeFreitas wrote:

MD> Hey Vadim,
MD>
MD> Were you able to duplicate this problem? At the very least, with the
MD> treectrl sample program, you should see that:
MD> Tree->Append many items
MD> (expand the root folder)
MD> Tree->Make the last item visible
MD>
MD> does not work... that is, the last item is not shown.

This is just a bug in the sample which, for some strange reason, tried to
maintain a pointer to the last item and didn't update it correctly after
"Append many items" (so the "last" child was still "Child 5.5"). I've fixed
this in the sample now.

Is there a way to reproduce the problem with partially visible items in
it? If there is, please open a ticket for it.

Thanks,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Marco DeFreitas
2014-02-24 14:55:44 UTC
Permalink
VZ> Is there a way to reproduce the problem with partially
VZ> visible items in it? If there is, please open a ticket for it.

Yes, when "Make the last item visible" is selected, the last item does
indeed become visible, but not completely like it was in 2.8.x.

Do you see this? If so, I'll go ahead and put in a ticket for it.

Thanks a bunch!
--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
Vadim Zeitlin
2014-02-25 17:26:20 UTC
Permalink
On Mon, 24 Feb 2014 06:55:44 -0800 (PST) Marco DeFreitas wrote:

MD> VZ> Is there a way to reproduce the problem with partially
MD> VZ> visible items in it? If there is, please open a ticket for it.
MD>
MD> Yes, when "Make the last item visible" is selected, the last item does
MD> indeed become visible, but not completely like it was in 2.8.x.
MD>
MD> Do you see this? If so, I'll go ahead and put in a ticket for it.

I've just fixed this in r76009, will be part of 3.0.1.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Marco DeFreitas
2014-02-25 20:01:25 UTC
Permalink
VZ> I've just fixed this in r76009, will be part of 3.0.1.

Awesome. Thanks!
--
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
Loading...