1 #include "includes.hpp"
4 #include "bitmaps/root.xpm"
5 #include "bitmaps/floor.xpm"
6 #include "bitmaps/newroom.xpm"
7 #include "bitmaps/oldroom.xpm"
8 #include "bitmaps/mailroom.xpm"
12 wxTreeItemId null_item;
23 class RoomItem : public wxTreeItemData {
25 RoomItem(wxString name, bool newmsgs, int typ);
28 wxTreeItemId nextroom;
32 RoomItem::RoomItem(wxString name, bool newmsgs, int typ)
36 HasNewMessages = newmsgs;
50 BEGIN_EVENT_TABLE(RoomTree, wxTreeCtrl)
51 EVT_TREE_ITEM_ACTIVATED(ROOMTREE_CTRL, RoomTree::OnDoubleClick)
56 RoomTree::RoomTree(wxMDIParentFrame *parent, CitClient *sock)
60 wxDefaultPosition, wxDefaultSize,
61 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER,
73 void RoomTree::InitTreeIcons(void) {
74 TreeIcons = new wxImageList(16, 16);
76 TreeIcons->Add(*new wxBitmap(root_xpm));
77 TreeIcons->Add(*new wxBitmap(floor_xpm));
78 TreeIcons->Add(*new wxBitmap(newroom_xpm));
79 TreeIcons->Add(*new wxBitmap(oldroom_xpm));
80 TreeIcons->Add(*new wxBitmap(mailroom_xpm));
82 TreeIcons->Add(*new wxBitmap("bitmaps/root.bmp", wxBITMAP_TYPE_BMP));
83 TreeIcons->Add(*new wxBitmap("bitmaps/floor.bmp", wxBITMAP_TYPE_BMP));
84 TreeIcons->Add(*new wxBitmap("bitmaps/newroom.bmp", wxBITMAP_TYPE_BMP));
85 TreeIcons->Add(*new wxBitmap("bitmaps/oldroom.bmp", wxBITMAP_TYPE_BMP));
86 TreeIcons->Add(*new wxBitmap("bitmaps/mailroom.bmp", wxBITMAP_TYPE_BMP));
88 SetImageList(TreeIcons);
92 // Load a tree with a room list
94 void RoomTree::LoadRoomList(void) {
95 wxString sendcmd, recvcmd, buf, floorname, roomname, transbuf;
98 int i, pos, floornum, where;
101 unsigned int roomflags;
105 // First, clear it out.
108 for (i=0; i<MAXFLOORS; ++i)
109 floorboards[i] = (wxTreeItemId) -1;
111 // Set the root with the name of the Citadel server.
118 // Create a fake floor for all of this user's mail rooms
119 mailfloor = AppendItem(
122 1, // FIX use an envelope icon here
124 new RoomItem(citsock->curr_user, FALSE, RI_CURRUSER)
129 // Bail out silently if we can't retrieve the floor list
130 if (citsock->serv_trans(sendcmd, recvcmd, transbuf) != 1) return;
132 // Load the floors one by one onto the tree
133 while (pos = transbuf.Find('\n', FALSE), (pos >= 0)) {
134 buf = transbuf.Left(pos);
135 transbuf = transbuf.Mid(pos+1);
136 extract(floorname, buf, 1);
137 floornum = extract_int(buf, 0);
138 floorboards[floornum] = AppendItem(
146 // Load the rooms with new messages into the tree
148 if (citsock->serv_trans(sendcmd, recvcmd, transbuf) != 1) return;
149 while (pos = transbuf.Find('\n', FALSE), (pos >= 0)) {
150 buf = transbuf.Left(pos);
151 transbuf = transbuf.Mid(pos+1);
152 extract(roomname, buf, 0);
153 roomflags = extract_int(buf, 1);
154 floornum = extract_int(buf, 2);
155 if (roomflags & QR_MAILBOX)
158 where = floorboards[floornum];
164 new RoomItem(roomname, TRUE, RI_ROOM)
166 SetItemBold(item, TRUE);
167 SetItemBold(floorboards[floornum], TRUE);
168 if (prev == null_item)
171 ((RoomItem *)GetItemData(prev))->nextroom = item;
175 // Load the rooms with no new messages into the tree
177 if (citsock->serv_trans(sendcmd, recvcmd, transbuf) != 1) return;
178 while (pos = transbuf.Find('\n', FALSE), (pos >= 0)) {
179 buf = transbuf.Left(pos);
180 transbuf = transbuf.Mid(pos+1);
181 extract(roomname, buf, 0);
182 roomflags = extract_int(buf, 1);
183 floornum = extract_int(buf, 2);
184 if (roomflags & QR_MAILBOX)
187 where = floorboards[floornum];
193 new RoomItem(roomname, FALSE, RI_ROOM)
198 /* // Create a bogus floor for zapped rooms
200 zapfloor = AppendItem(
205 new RoomItem("Zapped Rooms", FALSE, RI_ZAPPED)
209 sendcmd = "LZRM"; // List Zapped RooMs
211 if (citsock->serv_trans(sendcmd, recvcmd, transbuf) != 1) return;
212 while (pos = transbuf.Find('\n', FALSE), (pos >= 0)) {
213 buf = transbuf.Left(pos);
214 transbuf = transbuf.Mid(pos+1);
215 extract(roomname, buf, 0);
216 roomflags = extract_int(buf, 1);
217 floornum = extract_int(buf, 2);
224 new RoomItem(roomname, FALSE, RI_ROOM)
230 wxTreeItemId sp = AppendItem(
235 new RoomItem("Global settings", FALSE, RI_NOTHING)
238 AppendItem(sp, "Identity",
241 new RoomItem("Identity", FALSE, RI_SERVPROPS)
244 AppendItem(sp, "Network",
247 new RoomItem("Network", FALSE, RI_SERVPROPS)
250 AppendItem(sp, "Security",
253 new RoomItem("Security", FALSE, RI_SERVPROPS)
256 Expand(GetRootItem());
258 // Demo of traversal -- do not use
259 // while (march_next != null_item) {
260 // wxTreeItemId foo = GetNextRoomId();
261 // cout << ((RoomItem *)GetItemData(foo))->RoomName << "\n";
270 void RoomTree::OnDoubleClick(wxTreeEvent& evt) {
275 itemId = GetSelection();
277 // Don't do this unless it's a leaf node the user clicked on.
278 if (itemId == GetRootItem()) return;
279 for (i=0; i<MAXFLOORS; ++i)
280 if (itemId == floorboards[i]) return;
282 // Ok, it's a leaf node...
283 r = (RoomItem *)GetItemData(itemId);
285 switch (r->NodeType) {
288 new RoomView(citsock, citMyMDI, r->RoomName);
289 RoomList->DeleteAllItems();
290 RoomList->LoadRoomList();
294 RoomList->DeleteAllItems();
295 RoomList->LoadRoomList();
300 if (CurrServProps == NULL) {
301 CurrServProps = new ServProps(
302 citsock, citMyMDI, r->RoomName);
304 CurrServProps->ChangePanel(r->RoomName);
311 wxString RoomTree::GetNextRoom(void) {
314 wxTreeItemId RoomId = GetNextRoomId();
315 if (RoomId == null_item) {
318 rn = ((RoomItem *)GetItemData(RoomId))->RoomName;
325 wxTreeItemId RoomTree::GetNextRoomId(void) {
331 if (march_next == null_item)
334 march_next = ((RoomItem *)GetItemData(march_next))->nextroom;