#include "XABAccountView.h" BEGIN_EVENT_TABLE(XABAccountView, wxTreeCtrl) //EVT_LEFT_UP(XABAccountView::OnMouseClick) EVT_LEFT_DCLICK(XABAccountView::OnMouseClick) EVT_TREE_ITEM_EXPANDED(-1, XABAccountView::ExpColProc) EVT_TREE_ITEM_COLLAPSED(-1, XABAccountView::ExpColProc) END_EVENT_TABLE() void XABAccountView::Init(){ idx = -1; } bool XABAccountView::Create(wxWindow* parent){ return wxTreeCtrl::Create(parent, 1, wxPoint(0,0), wxSize(100,100), wxTR_DEFAULT_STYLE|wxTR_HIDE_ROOT); } wxWindow* XABAccountView::GetControl(){ return this; } void XABAccountView::SetStringValue(const wxString& s){ tid = wxTreeCtrl::GetSelection(); } wxString XABAccountView::GetStringValue() const{ if (tid.IsOk()){ wxString wxStrName = wxTreeCtrl::GetItemText(tid); return wxStrName; } return wxEmptyString; } void XABAccountView::OnMouseClick(wxMouseEvent& WXUNUSED(event)){ // Update control. // Check if item expanding or collapsed // has occured before dismissing. if (ixp == FALSE){ // Item expansion/collapsing didn't occur. tid = wxTreeCtrl::GetSelection(); Dismiss(); } ixp = FALSE; } void XABAccountView::SetAccount(){ tid = wxTreeCtrl::GetSelection(); Dismiss(); } // Needed by SetStringValue wxTreeItemId XABAccountView::FindItemByText(wxTreeItemId parent, const wxString& text) { wxTreeItemIdValue cookie; wxTreeItemId child = GetFirstChild(parent, cookie); while (child.IsOk()) { if (GetItemText(child) == text) { return child; } if (ItemHasChildren(child)) { wxTreeItemId found = FindItemByText(child, text); if (found.IsOk()) return found; } child = GetNextChild(parent, cookie); } return wxTreeItemId(); } void XABAccountView::ExpColProc(wxTreeEvent& event){ ixp = TRUE; }