Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inconsitent wxTreeCtrl behavior

11 views
Skip to first unread message

Marco

unread,
Aug 27, 2010, 2:26:01 PM8/27/10
to
I am seeing something weird on Windows when I use a wxTreeCtrl with
wxTR_MULTIPLE enabled.

When I select an item, my "selection changed" event handler gets
called twice, once with event.GetItem() returning a NULL then again
with event.GetItem() returning a valid value.

On Linux, I only get one (valid) call.

I am using wx 2.8.10 on msys/mingw.

This is my test program:
(NOTE: to see the output of my "cout" on windows, I execute with the
redirection of cout to a file:
mytest > out.txt)

______________________________

#include <iostream>
using namespace std;

#include "wx/wx.h"
#include "wx/treectrl.h"

#define MY_TREE_ID wxID_HIGHEST + 1

class MyApp : public wxApp
{
public:
virtual bool OnInit();
};

class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title);

void OnQuit(wxCommandEvent& event);
void OnSelect(wxTreeEvent& event);

private:
wxTreeCtrl *m_tree;
DECLARE_EVENT_TABLE()
};

DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)


bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(wxT("Minimal App"));
frame->Show(true);
return true;
}


BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
EVT_TREE_SEL_CHANGED(MY_TREE_ID, MyFrame::OnSelect)
END_EVENT_TABLE()


MyFrame::MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY,
title)
{
wxMenu *fileMenu = new wxMenu;
fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt-X"), wxT("Quit this
program"));
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(fileMenu, wxT("&File"));
SetMenuBar(menuBar);

m_tree = new wxTreeCtrl(this, MY_TREE_ID, wxDefaultPosition,
wxSize(300, 300), wxTR_HAS_BUTTONS|wxTR_HIDE_ROOT|
wxTR_LINES_AT_ROOT|
wxTR_MULTIPLE);
wxTreeItemId root = m_tree->AddRoot("Root");
wxTreeItemId f1 = m_tree->AppendItem(root, "Folder1");
wxTreeItemId c1_1 = m_tree->AppendItem(f1, "Child1.1");
wxTreeItemId c1_2 = m_tree->AppendItem(f1, "Child1.1");
wxTreeItemId f2 = m_tree->AppendItem(root, "Folder2");
wxTreeItemId c2_1 = m_tree->AppendItem(f2, "Child2.1");
wxTreeItemId c2_2 = m_tree->AppendItem(f2, "Child2.1");
m_tree->Expand(f1);
m_tree->Expand(f2);
}

void MyFrame::OnSelect(wxTreeEvent& event)
{
wxTreeItemId id = event.GetItem();
if (id) {
cout << "GOOD" << endl;
} else {
cout << "BAD" << endl;
}
}

void MyFrame::OnQuit(wxCommandEvent& event)
{
Close();
}

0 new messages