1 // ============================================================================
3 // ============================================================================
5 #include "includes.hpp"
7 // ----------------------------------------------------------------------------
9 // ----------------------------------------------------------------------------
13 class ReturnedUser : public wxTreeItemData {
15 ReturnedUser(wxString);
19 ReturnedUser::ReturnedUser(wxString e) {
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 // IDs for the controls and the menu commands
38 // ----------------------------------------------------------------------------
39 // event tables and other macros for wxWindows
40 // ----------------------------------------------------------------------------
42 BEGIN_EVENT_TABLE( SelectUser, wxPanel)
43 EVT_BUTTON( BUTTON_SENDCMD, SelectUser::OnButtonPressed)
44 EVT_BUTTON( BUTTON_CLOSE, SelectUser::OnButtonPressed)
47 //BEGIN_EVENT_TABLE(thisclassname, wxTreeCtrl)
48 // EVT_TREE_ITEM_ACTIVATED(THE_TREE, SelectUser::OnTreeClick)
51 // ============================================================================
53 // ============================================================================
56 // ----------------------------------------------------------------------------
57 // the application class
58 // ----------------------------------------------------------------------------
61 SelectUser::SelectUser(CitClient *sock, wxWindow *the_parent,
65 wxTextCtrl *PlaceToPutTheSelection)
66 : wxPanel(the_parent, -1) {
69 target_textctrl = PlaceToPutTheSelection;
71 TheTree = new wxTreeCtrl(
74 wxDefaultPosition, wxDefaultSize,
75 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER
78 wxStaticText *caption_ctrl = new wxStaticText(this, -1, caption);
79 wxLayoutConstraints *c0 = new wxLayoutConstraints;
80 c0->left.SameAs(this, wxLeft, 5);
81 c0->top.SameAs(this, wxTop, 5);
84 caption_ctrl->SetConstraints(c0);
86 wxButton *select_button = new wxButton(
92 wxButton *cancel_button = new wxButton(
98 wxLayoutConstraints *c5 = new wxLayoutConstraints;
99 c5->left.SameAs(this, wxLeft, 5);
100 c5->bottom.SameAs(this, wxBottom, 5);
103 select_button->SetConstraints(c5);
105 wxLayoutConstraints *c6 = new wxLayoutConstraints;
106 c6->right.SameAs(this, wxRight, 5);
107 c6->bottom.SameAs(this, wxBottom, 5);
110 cancel_button->SetConstraints(c6);
112 wxLayoutConstraints *c1 = new wxLayoutConstraints;
113 c1->top.Below(caption_ctrl, 5);
114 c1->bottom.Above(select_button, -5);
115 c1->left.SameAs(this, wxLeft, 5);
116 c1->right.SameAs(this, wxRight, 5);
117 TheTree->SetConstraints(c1);
124 // Load up the tree with some STUFF
127 -1, // FIX put an image here
128 -1, // FIX same image
129 NULL // No data here, it's only a heading
132 // Add local users to the tree (this is probably always going to be
133 // desired, so there's no need for a flag)
134 AddLocalUsers(TheTree, citsock);
139 void SelectUser::OnButtonPressed(wxCommandEvent& whichbutton) {
141 if (whichbutton.GetId()==BUTTON_CLOSE) {
144 else if (whichbutton.GetId()==BUTTON_SENDCMD) {
145 ReturnedUser *u = (ReturnedUser *)
146 TheTree->GetItemData(TheTree->GetSelection());
147 if ( (u != NULL) && (target_textctrl != NULL) ) {
148 target_textctrl->SetValue(u->emailaddr);
155 void SelectUser::AddLocalUsers(wxTreeCtrl *tree, CitClient *cit) {
159 wxStringTokenizer *ul;
160 wxString buf, username;
163 if (citsock->serv_trans(sendcmd, recvcmd, xferbuf) != 1) return;
165 wxTreeItemId localusers = tree->AppendItem(
168 -1, // FIX put an image here
170 NULL // No data here either. It's a heading.
173 ul = new wxStringTokenizer(xferbuf, "\n", FALSE);
174 while (ul->HasMoreTokens()) {
175 buf = ul->NextToken();
176 extract(username, buf, 0);
182 new ReturnedUser(username)
186 // FIX ... this has to be made case insensitive
187 tree->SortChildren(localusers);