// Global sizer
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
- int ctrl_style = wxLC_REPORT | /*wxLC_VRULES |*/ wxLC_EDIT_LABELS;
+ int ctrl_style = wxLC_REPORT | wxLC_VRULES;
int col_style = wxLIST_FORMAT_LEFT;
// Creating the ListCtrl for the levels > 0 (not for Root level)
mLevelList.push_back(level);
}
+#if wxUSE_MENUS
+
+ menu =new wxMenu;
+ wxMenuItem* m1=menu->Append(wxID_ANY, _T("&Sort ascending"));
+ wxMenuItem* m2=menu->Append(wxID_ANY, _T("&Sort descending"));
+ wxMenuItem* m3=menu->Append(wxID_ANY, _T("&Filter"));
+ mAscendingID=m1->GetId();
+ mDescendingID=m2->GetId();
+ mFilterID=m3->GetId();
+ Connect( mAscendingID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupSort) );
+ Connect( mDescendingID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupSort) );
+ Connect( mFilterID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupFilter) );
+
+#endif // wxUSE_MENUS
+
/// Initialize the first level splitter
mDirection=true;
mSelectionMade=false;
mProcess=true;
- CreateColorPalette();
+ //CreateColorPalette();
UpdateLevel(1);
SetSizer( sizer );
GetCtrl(l)->DeleteAllItems();
std::vector<tree::Node*>::iterator i;
+
//Adds the first item (filter)
- GetCtrl(l)->InsertItem(0, _T("Filter:"));
- for (i=sel.begin(); i!=sel.end(); ++i)
+
+ for (i=sel.begin(); i!=sel.end(); ++i)
{
GimmickDebugMessage(2,
"adding children of '"
<<(*i)->GetLabel()
- <<"'"<<level
+ <<"'"
<<std::endl);
int _id=1;
-
-
+
//Adds items (other than the first) and sets their attributes
+ GetCtrl(l)->InsertItem(0, _T("hELLO"));
GetTreeHandler()->LoadChildren(*i,1);
tree::Node::ChildrenListType::reverse_iterator j;
for (j = (*i)->GetChildrenList().rbegin();
j!= (*i)->GetChildrenList().rend();
++j)
{
- wxListItem item;
- item.SetMask(wxLIST_MASK_STATE |
+ wxListItem* item= new wxListItem;
+ item->SetMask(wxLIST_MASK_STATE |
wxLIST_MASK_TEXT |
// wxLIST_MASK_IMAGE |
wxLIST_MASK_DATA |
// wxLIST_MASK_WIDTH |
wxLIST_MASK_FORMAT
);
-
+
ItemData* data = new ItemData;
data->node = *j;
- item.SetId(_id);
+ item->SetId(_id);
data->id = _id;
- item.SetData(data);
+ item->SetData(data);
_id++;
- long id=GetCtrl(l)->InsertItem(item);
+
//Setting first column (number of children)
std::ostringstream oss;
int n= GetTreeHandler()->GetNumberOfChildren(*j);
oss << n;
std::string s(oss.str());
- item.SetText( crea::std2wx(s));
+ item->SetText( crea::std2wx(s));
- item.SetColumn(0);
- GetCtrl(l)->SetItem(item);
+ item->SetColumn(0);
+ GetCtrl(l)->InsertItem(*item);
+ //GetCtrl(l)->SetItem(item);
//Setting other attributes
for (int k=1; k<GetCtrl(l)->GetColumnCount(); k++)
{
- std::string val = (*j)->GetAttribute(mLevelList[l].key[k-1]);
+ std::string val = (*j)->GetAttribute(mLevelList[l].key[k-1]);
if (val.size()==0) val = "?";
- item.SetText( crea::std2wx(val));
- item.SetColumn(k);
- GetCtrl(l)->SetItem(item);
- }
+ item->SetText( crea::std2wx(val));
+ item->SetColumn(k);
+ GetCtrl(l)->SetItem(*item);
+ GetCtrl(l)->RefreshItem(*item);
+ }
+
}
+ GetCtrl(l)->DeleteItem(0);
}
GetCtrl(l)->Show();
-
if (level<mLevelList.size()) UpdateLevel(level+1);
GimmickMessage(1,
" Event type "<<event.GetEventType()
<<std::endl);
+ /*
if(event.m_itemIndex!=0)
- {
+ {*/
if(level<mLevelList.size()-1)
{
mSelected=GetSelected(level+2);
}
}
//SetColor(level,event.m_itemIndex);
- }
+ /*}
else
{
if(event.GetEventType()==10145)
GetCtrl(level)->EditLabel(event.m_itemIndex);
}
- }
+ }*/
}
mProcess=false;
}
- if(item!=0)
- {
+ /*if(item!=0)
+ {*/
GetCtrl(level)->SetItemState(item,wxLIST_STATE_SELECTED, wxLIST_MASK_STATE
| wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT);
- }
+ //}
}
}
//================================================================
-
//================================================================
+
void WxTreeView::OnColClick(wxListEvent& event)
- {
- //Obtain the column name and the level that needs to be organized
+ {
mColumnSelected=event.m_col;
- GimmickDebugMessage(1,
- " Column selected: " <<event.m_col
- <<std::endl);
-
+ wxPoint clientpt = event.GetPoint();
+ senderCtrl = event.GetEventObject();
+ clientpt.x+=(mColumnSelected)*(GetCtrl(0)->GetColumnWidth(mColumnSelected));
+ wxPoint screenpt = ClientToScreen(clientpt);
if(mColumnSelected!=0)
{
- wxObject* ctrl = event.GetEventObject();
+ PopupMenu(menu, clientpt);
+ }
+
+ }
+ //================================================================
+ void WxTreeView::OnPopupFilter(wxCommandEvent& event)
+ {
+ wxBusyCursor busy;
+ GimmickDebugMessage(7,
+ "WxTreeView::OnEndLabelEdit"
+ <<std::endl);
+ wxObject* ctrl = event.GetEventObject();
unsigned int level = 0;
for (level = 0; level<mLevelList.size(); ++level)
{
- if ( GetCtrl(level) == ctrl ) break;
+ if ( GetCtrl(level) == senderCtrl ) break;
}
+ std::string filter = wxGetTextFromUser(_T("Enter the filter to apply"), _T("Filter On Column"));
+
+ std::string att;
+
+ long it = -1;
+ UpdateLevel(level+1);
+ for ( ;; )
+ {
+ bool contains=false;
+ it = GetCtrl(level)->GetNextItem(it,
+ wxLIST_NEXT_ALL);
+ if ( it == -1 )
+ break;
+
+ long adr = GetCtrl(level)->GetItemData(it);
+ tree::Node* nod = ((ItemData*)adr)->node;
+ att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected-1]);
+
+ if(att.find(filter)>900)
+ {
+ GetCtrl(level)->DeleteItem(it);
+ }
+
+ }
+ GetGimmickView()->ClearSelection();
+ }
+ //================================================================
+
+ //================================================================
+ void WxTreeView::OnPopupSort(wxCommandEvent& event)
+ {
wxBusyCursor busy;
-
+ unsigned int level = 0;
+ for (level = 0; level<mLevelList.size(); ++level)
+ {
+ if ( GetCtrl(level) == senderCtrl ) break;
+ }
+ if(event.GetId()==mAscendingID)
+ {
+ mDirection=true;
+ }
+ else if(event.GetId()==mDescendingID)
+ {
+ mDirection=false;
+ }
+
+ OnSort(level);
+ }
+ //================================================================
+ void WxTreeView::OnSort(int level)
+ {
+ //Obtain the column name and the level that needs to be organized
+
+ if(mColumnSelected!=0)
+ {
int l = level - 1;
- GetCtrl(level)->DeleteItem(0);
+ //GetCtrl(level)->DeleteItem(0);
//Sets the data for the items to be sorted
std::string att;
unsigned int ty=0;
//Gets current item data
long adr = GetCtrl(level)->GetItemData(i);
+
//Extracts the node and the type of attribute
tree::Node* nod = ((ItemData*)adr)->node;
if(i==0)
GetCtrl(level)->SortItems(CompareFunctionStrings, 0);
}
- mDirection=false;
}
else
{
{
GetCtrl(level)->SortItems(CompareFunctionStrings, 1);
}
- mDirection=true;
}
//Resets original data
| wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT);
}
- GetCtrl(level)->InsertItem(0,_T("Filter:"));
+ //GetCtrl(level)->InsertItem(0,_T("Filter:"));
}
}
}
//================================================================
- BEGIN_EVENT_TABLE(WxTreeView, wxPanel)
+ BEGIN_EVENT_TABLE(WxTreeView, wxPanel)
/*
EVT_SIZE(MyFrame::OnSize)
EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused)
-
- EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick)
- */
+*/
+ EVT_LIST_COL_RIGHT_CLICK(-1, WxTreeView::OnColClick)
+
EVT_LIST_COL_CLICK(-1, WxTreeView::OnColClick)
/*
EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnColBeginDrag)