1 // XABAccountView.cpp - XABAccountView widget
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "XABAccountView.h"
21 BEGIN_EVENT_TABLE(XABAccountView, wxTreeCtrl)
22 EVT_LEFT_DCLICK(XABAccountView::OnMouseClick)
23 EVT_TREE_ITEM_EXPANDED(-1, XABAccountView::ExpColProc)
24 EVT_TREE_ITEM_COLLAPSED(-1, XABAccountView::ExpColProc)
27 void XABAccountView::Init(){
29 // Initialise the XABAccountView object.
35 bool XABAccountView::Create(wxWindow* parent){
37 // Create the XABAccountView control.
39 return wxTreeCtrl::Create(parent, 1, wxPoint(0,0), wxSize(100,100), wxTR_DEFAULT_STYLE|wxTR_HIDE_ROOT);
43 wxWindow* XABAccountView::GetControl(){
45 // Get the control pointer.
51 void XABAccountView::SetStringValue(const wxString& s){
53 // Set the string value for the XABAccountView control.
55 tid = wxTreeCtrl::GetSelection();
59 wxString XABAccountView::GetStringValue() const{
61 // Get the string value for the XABAccountView control.
64 wxString wxStrName = wxTreeCtrl::GetItemText(tid);
71 void XABAccountView::OnMouseClick(wxMouseEvent& WXUNUSED(event)){
75 // Check if item expanding or collapsed
76 // has occured before dismissing.
80 // Item expansion/collapsing didn't occur.
82 tid = wxTreeCtrl::GetSelection();
91 void XABAccountView::SetAccount(){
93 // Set the account for the XABAccountView control.
95 tid = wxTreeCtrl::GetSelection();
100 wxTreeItemId XABAccountView::FindItemByText(wxTreeItemId parent, const wxString& text)
103 // Find an item based on the supplied wxString value.
104 // Return a wxTreeItemId object if found.
106 wxTreeItemIdValue cookie;
107 wxTreeItemId child = GetFirstChild(parent, cookie);
110 if (GetItemText(child) == text)
114 if (ItemHasChildren(child))
116 wxTreeItemId found = FindItemByText(child, text);
120 child = GetNextChild(parent, cookie);
122 return wxTreeItemId();
125 void XABAccountView::ExpColProc(wxTreeEvent& event){
127 // Function when pressing the down button on the
128 // XABAccountView control.