]> code.citadel.org Git - citadel.git/commitdiff
Got the room tree out to its own class.
authorArt Cancro <ajc@citadel.org>
Mon, 22 Mar 1999 04:31:11 +0000 (04:31 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 22 Mar 1999 04:31:11 +0000 (04:31 +0000)
daphne/Makefile
daphne/includes.hpp
daphne/main.cpp
daphne/userlogin.cpp
daphne/utils.cpp

index c73eaa07c0f46b6db3523dcb8c839a9ff4564b36..6ac46bff087723bbc77a50f43feb9c2c3f9b3537 100644 (file)
@@ -2,9 +2,11 @@ CFLAGS=`wx-config --cflags`
 LFLAGS=`wx-config --libs`
 
 daphne: main.o citclient.o userlogin.o testwindow.o who.o \
-       utils.o tcp_sockets.o express_message.o send_express.o
+       utils.o tcp_sockets.o express_message.o send_express.o \
+       roomtree.o
        c++ main.o citclient.o userlogin.o testwindow.o who.o \
        utils.o tcp_sockets.o express_message.o send_express.o \
+       roomtree.o \
        $(LFLAGS) -o daphne
 
 main.o: main.cpp includes.hpp
@@ -33,3 +35,6 @@ express_message.o: express_message.cpp includes.hpp
 
 send_express.o: send_express.cpp includes.hpp
        c++ -c $(CFLAGS) send_express.cpp
+
+roomtree.o: roomtree.cpp includes.hpp
+       c++ -c $(CFLAGS) roomtree.cpp
index 6d76bf701f2d8bc38ee7bae33e3903e86e5e1e98..f62990fb495d7bba16ff6399f1700dede6ef942d 100644 (file)
@@ -5,14 +5,9 @@
 #include <wx/wx.h>
 #include <wx/listctrl.h>
 #include <wx/socket.h>
-
-
-
-// Globals
-
-extern wxMDIParentFrame *BigMDI;
-extern wxTreeCtrl *RoomList;
-
+#include <wx/log.h>
+#include "wx/imaglist.h"
+#include "wx/treectrl.h"
 
 
 // TCPsocket represents a socket-level TCP connection to a server.
@@ -196,6 +191,22 @@ private:
 
 
 
+// The ever-present tree of floors and rooms
+
+class RoomTree : public wxTreeCtrl {
+public:
+       RoomTree(wxWindow *parent, CitClient *sock);
+       void LoadRoomList(void);
+private:
+       void InitTreeIcons(void);
+       CitClient *citsock;
+       wxTreeItemId floorboards[128];
+       wxImageList *TreeIcons;
+};
+
+
+
+
 
 // Stuff from utils.cpp
 
@@ -203,9 +214,16 @@ void ListToMultiline(wxString& outputbuf, wxStringList inputlist);
 void MultilineToList(wxStringList& outputlist, wxString inputbuf);
 void extract(wxString& outputbuf, wxString inputbuf, int parmnum);
 int extract_int(wxString inputbuf, int parmnum);
-void load_roomlist(wxTreeCtrl *tree, CitClient *citsock);
+void load_roomlist(RoomTree *tree, CitClient *citsock);
+
 
 
 
 
+// Globals
+
+extern wxMDIParentFrame *BigMDI;
+extern RoomTree *RoomList;
+
+
 
index 4087e1abeafacfc6fbde38667daadac4f0d905bd..f279bdee654c0c5b2ac4bea611b35fb3e0a36edd 100644 (file)
@@ -19,7 +19,7 @@
 
 // Globals
 wxMDIParentFrame *BigMDI;
-wxTreeCtrl *RoomList;
+RoomTree *RoomList;
 
 
 // ----------------------------------------------------------------------------
@@ -50,6 +50,7 @@ public:
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void OnDoCmd(wxCommandEvent& event);
+       void GotoNewRoom(wxTreeEvent& event);
 private:
        void OnConnect(wxCommandEvent& event);
        void OnTestWin(wxCommandEvent& event);
@@ -84,7 +85,8 @@ enum
        WMENU_ARRANGE,
        WMENU_NEXT,
        WMENU_PREVIOUS,
-       BUTTON_DO_CMD
+       BUTTON_DO_CMD,
+       ROOMTREE_DOUBLECLICK
 };
 
 // ----------------------------------------------------------------------------
@@ -112,8 +114,8 @@ END_EVENT_TABLE()
 // Create a new application object: this macro will allow wxWindows to create
 // the application object during program execution (it's better than using a
 // static object for many reasons) and also declares the accessor function
-// wxGetApp() which will return the reference of the right type (i.e. Daphne and
-// not wxApp)
+// wxGetApp() which will return the reference of the right type (i.e. Daphne
+// and not wxApp)
 IMPLEMENT_APP(Daphne)
 
 // ============================================================================
@@ -168,12 +170,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
 
        // Set up the left-side thingie
 
-       RoomList = new wxTreeCtrl(
-                       this, -1, 
-                       wxDefaultPosition, wxDefaultSize,
-                       wxTR_HAS_BUTTONS | wxSUNKEN_BORDER,
-                       wxDefaultValidator,
-                       "RoomList");
+       RoomList = new RoomTree(this, citadel);
 
         wxLayoutConstraints *t2 = new wxLayoutConstraints;
         t2->top.SameAs(this, wxTop, 4);
@@ -382,3 +379,4 @@ void MyFrame::OnConnect(wxCommandEvent& unused) {
 void MyFrame::OnTestWin(wxCommandEvent& unused) {
        new TestWindow(citadel, this);
 }
+
index ae2697b88f8dda941f7038c3f2e9e80a291830af..37b1d21d3a3a05db1cfec6a2e6ae7fac0056a942 100644 (file)
@@ -284,6 +284,6 @@ void UserLogin::BeginSession(wxString serv_response) {
 
        // FIX ... add code here to perform registration if necessary
 
-       load_roomlist(RoomList, citsock);
+       RoomList->LoadRoomList();
        
 }
index ab4066fcff13701486995e04fdcb2467ee9f338a..701d20041b166798454ba9c63eb22838fa6f9a73 100644 (file)
@@ -1,17 +1,7 @@
 // utility functions not belonging to any particular class
 
-#include <wx/wx.h>
 #include "includes.hpp"
 
-#include "bitmaps/root.xpm"
-#include "bitmaps/floor.xpm"
-#include "bitmaps/newroom.xpm"
-#include "bitmaps/oldroom.xpm"
-#include "bitmaps/mailroom.xpm"
-
-wxTreeItemId floorboards[128];
-wxImageList *TreeIcons = NULL;
-
 // The following two functions convert between the wxStringList class used for
 // text transfers to and from the Citadel server, and the wxString class used
 // for the contents of a wxTextCtrl.
@@ -88,85 +78,3 @@ int extract_int(wxString inputbuf, int parmnum) {
        return atoi(buf);
 }
 
-
-void InitTreeIcons(void) {
-       TreeIcons = new wxImageList(16, 16);
-       TreeIcons->Add(wxICON(root));
-       TreeIcons->Add(wxICON(floor));
-       TreeIcons->Add(wxICON(newroom));
-       TreeIcons->Add(wxICON(oldroom));
-       TreeIcons->Add(wxICON(mailroom));
-}
-
-
-// Load a tree with a room list
-//
-void load_roomlist(wxTreeCtrl *tree, CitClient *citsock) {
-       wxString sendcmd, recvcmd, buf, floorname, roomname;
-       wxStringList transbuf;
-       wxTreeItemId item;
-       int i, floornum;
-
-       if (TreeIcons == NULL) InitTreeIcons();
-
-       // First, clear it out.
-       tree->DeleteAllItems();
-       tree->SetImageList(TreeIcons);
-
-       // Set the root with the name of the Citadel server.
-       tree->AddRoot(
-               citsock->HumanNode,
-               0,
-               -1,
-               NULL);
-
-       sendcmd = "LFLR";
-       // Bail out silently if we can't retrieve the floor list
-       if (citsock->serv_trans(sendcmd, recvcmd, transbuf) != 1) return;
-
-       // Load the floors one by one onto the tree
-        for (i=0; i<transbuf.Number(); ++i) {
-                buf.Printf("%s", (wxString *)transbuf.Nth(i)->GetData());
-               extract(floorname, buf, 1);
-               floornum = extract_int(buf, 0);
-               floorboards[floornum] = tree->AppendItem(
-                       tree->GetRootItem(),
-                       floorname,
-                       1,
-                       -1,
-                       NULL);
-       }
-
-       // Load the rooms with new messages into the tree
-       sendcmd = "LKRN";
-       if (citsock->serv_trans(sendcmd, recvcmd, transbuf) != 1) return;
-        for (i=0; i<transbuf.Number(); ++i) {
-                buf.Printf("%s", (wxString *)transbuf.Nth(i)->GetData());
-               extract(roomname, buf, 0);
-               floornum = extract_int(buf, 2);
-               item = tree->AppendItem(
-                       floorboards[floornum],
-                       roomname,
-                       2,
-                       -1,
-                       NULL);
-               tree->SetItemBold(item, TRUE);
-               tree->SetItemBold(floorboards[floornum], TRUE);
-       }
-
-       // Load the rooms with new messages into the tree
-       sendcmd = "LKRO";
-       if (citsock->serv_trans(sendcmd, recvcmd, transbuf) != 1) return;
-        for (i=0; i<transbuf.Number(); ++i) {
-                buf.Printf("%s", (wxString *)transbuf.Nth(i)->GetData());
-               extract(roomname, buf, 0);
-               floornum = extract_int(buf, 2);
-               tree->AppendItem(
-                       floorboards[floornum],
-                       roomname,
-                       3,
-                       -1,
-                       NULL);
-       }
-
-}