1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Main screen type thing
4 /////////////////////////////////////////////////////////////////////////////
6 // ============================================================================
8 // ============================================================================
10 #include "includes.hpp"
13 #include "bitmaps/globe.xpm"
14 #include "bitmaps/mail.xpm"
15 #include "bitmaps/who.xpm"
16 #include "bitmaps/chat.xpm"
21 wxMDIParentFrame *BigMDI;
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 // Define a new application type, each program should derive a class from wxApp
31 class Daphne : public wxApp
34 // override base class virtuals
35 // ----------------------------
37 // this one is called on application startup and is a good place for the app
38 // initialization (doing it here and not in the ctor allows to have an error
39 // return: if OnInit() returns false, the application terminates)
40 virtual bool OnInit();
43 // Define a new frame type: this is going to be our main frame
44 class MyFrame : public wxMDIParentFrame
48 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
50 // event handlers (these functions should _not_ be virtual)
51 void OnQuit(wxCommandEvent& event);
52 void OnAbout(wxCommandEvent& event);
53 void OnDoCmd(wxCommandEvent& event);
54 void GotoNewRoom(wxTreeEvent& event);
56 void OnConnect(wxCommandEvent& event);
57 void OnGotoMail(wxCommandEvent& event);
58 void OnTestWin(wxCommandEvent& event);
59 void OnEditMenu(wxCommandEvent& cmd);
60 void OnUsersMenu(wxCommandEvent& cmd);
61 void OnRoomsMenu(wxCommandEvent& cmd);
62 void MyFrame::OnSize(wxSizeEvent& event);
64 void InitToolBar(wxToolBar* toolBar);
68 // any class wishing to process wxWindows events must use this macro
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 // IDs for the controls and the menu commands
94 // ----------------------------------------------------------------------------
95 // event tables and other macros for wxWindows
96 // ----------------------------------------------------------------------------
98 // the event tables connect the wxWindows events with the functions (event
99 // handlers) which process them. It can be also done at run-time, but for the
100 // simple menu events like this the static method is much simpler.
101 BEGIN_EVENT_TABLE( MyFrame, wxMDIParentFrame)
102 EVT_MENU( IG_Quit, MyFrame::OnQuit)
103 EVT_MENU( IG_About, MyFrame::OnAbout)
104 EVT_MENU( MENU_CONNECT, MyFrame::OnConnect)
105 EVT_MENU( EMENU_PREFS, MyFrame::OnEditMenu)
106 EVT_MENU( GOTO_MAIL, MyFrame::OnGotoMail)
107 EVT_MENU( MENU_TESTWIN, MyFrame::OnTestWin)
108 EVT_MENU( UMENU_WHO, MyFrame::OnUsersMenu)
109 EVT_MENU( UMENU_SEND_EXPRESS, MyFrame::OnUsersMenu)
110 EVT_MENU( RMENU_GOTO, MyFrame::OnRoomsMenu)
111 EVT_BUTTON( BUTTON_DO_CMD, MyFrame::OnDoCmd)
112 EVT_SIZE( MyFrame::OnSize)
115 // Create a new application object: this macro will allow wxWindows to create
116 // the application object during program execution (it's better than using a
117 // static object for many reasons) and also declares the accessor function
118 // wxGetApp() which will return the reference of the right type (i.e. Daphne
120 IMPLEMENT_APP(Daphne)
122 // ============================================================================
124 // ============================================================================
126 wxRadioBox *DevSelect;
130 // ----------------------------------------------------------------------------
131 // the application class
132 // ----------------------------------------------------------------------------
134 // `Main program' equivalent: the program execution "starts" here
135 bool Daphne::OnInit()
140 // Read the configuration file
141 ini = new wxConfig("daphne");
142 ini->SetRecordDefaults(TRUE);
143 ini->Read("/Window Sizes/Main", &sizestr, "600 450");
144 sscanf((const char *)sizestr, "%d %d", &w, &h);
146 // Connect to the server
147 citadel = new CitClient();
149 // Create the main application window
150 MyFrame *frame = new MyFrame("Daphne",
151 wxPoint(10, 10), wxSize(w, h));
154 // Show it and tell the application that it's our main window
155 // @@@ what does it do exactly, in fact? is it necessary here?
158 // success: wxApp::OnRun() will be called which will enter the main
159 // message loop and the application will run. If we returned FALSE
160 // here, the application would exit immediately.
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
169 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
171 (wxMDIParentFrame *)NULL,
173 title, pos, size, wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL
180 // Set up the left-side thingie
182 RoomList = new RoomTree(this, citadel);
184 // Set up the toolbar
186 CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL);
187 InitToolBar(GetToolBar());
190 // Set up the pulldown menus
192 wxMenu *menuFile = new wxMenu;
193 menuFile->Append(MENU_CONNECT, "&Connect");
194 menuFile->Append(MENU_TESTWIN, "Add &Test window");
195 menuFile->AppendSeparator();
196 menuFile->Append(IG_Quit, "E&xit");
198 wxMenu *menuEdit = new wxMenu;
199 menuEdit->Append(EMENU_PREFS, "&Preferences...");
201 wxMenu *menuUsers = new wxMenu;
202 menuUsers->Append(UMENU_WHO, "&Who is online?");
203 menuUsers->Append(UMENU_SEND_EXPRESS, "&Page another user");
205 wxMenu *menuRooms = new wxMenu;
206 menuRooms->Append(RMENU_GOTO, "&Goto next room with unread messages");
208 wxMenu *menuHelp = new wxMenu;
209 menuHelp->Append(IG_About, "&About...");
211 // now append the freshly created menu to the menu bar...
212 wxMenuBar *menuBar = new wxMenuBar;
213 menuBar->Append(menuFile, "&File");
214 menuBar->Append(menuEdit, "&Edit");
215 menuBar->Append(menuUsers, "&Users");
216 menuBar->Append(menuRooms, "&Rooms");
217 menuBar->Append(menuHelp, "&Help");
219 // ... and attach this menu bar to the frame
222 // Create the status bar
224 SetStatusText("Not connected", 0);
229 ini->Read("/Citadel Server/ConnectOnStartup", &buf, "no");
230 if (!buf.CmpNoCase("yes")) {
231 wxCommandEvent cjunk;
238 // The toolbar for this application.
239 void MyFrame::InitToolBar(wxToolBar* toolBar) {
241 wxBitmap* bitmaps[4];
243 // wxGTK seems to do the right thing by itself, while wxMSW wants to be
244 // told how big the toolbar icons are going to be, otherwise it defaults to
245 // 16x16. Strangely, wxToolBar::SetToolBitmapSize() doesn't seem to be
246 // available at all in wxGTK, hence the ifdef...
248 toolBar->SetToolBitmapSize(wxSize(32, 32));
251 // Set up the toolbar icons (BMP is available on both GTK and MSW)
253 bitmaps[0] = new wxBitmap("bitmaps/globe.bmp", wxBITMAP_TYPE_BMP);
254 bitmaps[1] = new wxBitmap("bitmaps/mail.bmp", wxBITMAP_TYPE_BMP);
255 bitmaps[2] = new wxBitmap("bitmaps/who.bmp", wxBITMAP_TYPE_BMP);
256 bitmaps[3] = new wxBitmap("bitmaps/chat.bmp", wxBITMAP_TYPE_BMP);
258 bitmaps[0] = new wxBitmap(globe_xpm);
259 bitmaps[1] = new wxBitmap(mail_xpm);
260 bitmaps[2] = new wxBitmap(who_xpm);
261 bitmaps[3] = new wxBitmap(chat_xpm);
264 toolBar->AddTool(MENU_CONNECT,
272 toolBar->AddSeparator();
274 toolBar->AddTool(GOTO_MAIL,
280 "Open your e-mail inbox");
282 toolBar->AddSeparator();
284 toolBar->AddTool(UMENU_WHO,
292 toolBar->AddTool(DO_NOTHING,
302 for (i = 0; i < 4; i++)
311 // We really could handle all menu items in one function, but that would
312 // get kind of confusing, so we break it down by top-level menus.
314 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
316 // Kill the client connection
319 // TRUE is to force the frame to close
327 void MyFrame::OnEditMenu(wxCommandEvent& cmd) {
330 if (id == EMENU_PREFS) {
331 new Preferences(citadel, this);
338 void MyFrame::OnUsersMenu(wxCommandEvent& cmd) {
342 if (id == UMENU_WHO) {
343 //if (TheWholist == NULL)
344 TheWholist = new who(citadel, this);
346 //TheWholist->Activate();
348 else if (id == UMENU_SEND_EXPRESS)
349 new SendExpress(citadel, this, "");
353 // Rooms menu handler
354 void MyFrame::OnRoomsMenu(wxCommandEvent& cmd) {
358 if (id == RMENU_GOTO) {
359 new RoomView(citadel, this, RoomList->GetNextRoom());
364 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
368 "This is the development version of a project code-named 'Daphne',\n"
369 "a GUI client for the Citadel/UX groupware system. It is being\n"
370 "developed using the wxWindows toolkit, and therefore should be\n"
371 "easy to port to Linux, Windows, and eventually Macintosh."
373 wxMessageBox(msg, "Daphne", wxOK | wxICON_INFORMATION, this);
376 void MyFrame::OnDoCmd(wxCommandEvent& whichbutton) {
380 void MyFrame::OnConnect(wxCommandEvent& unused) {
382 wxString DefaultHost, DefaultPort;
384 ini->Read("/Citadel Server/Host", &DefaultHost, DEFAULT_HOST);
385 ini->Read("/Citadel Server/Port", &DefaultPort, DEFAULT_PORT);
387 if (citadel->IsConnected()) {
388 wxMessageBox("You are currently connected to "
390 + ". If you wish to connect to a different Citadel "
391 + "server, you must log out first.",
392 "Already connected");
394 retval = citadel->attach(DefaultHost, DefaultPort);
396 SetStatusText("Connected to " + citadel->HumanNode, 0);
397 new UserLogin(citadel, this);
399 wxMessageBox("Could not connect to server.", "Error");
404 void MyFrame::OnGotoMail(wxCommandEvent& unused) {
405 new RoomView(citadel, this, "_MAIL_");
408 void MyFrame::OnTestWin(wxCommandEvent& unused) {
409 new TestWindow(citadel, this);
412 void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event) )
417 // Handle the MDI and roomlist crap
418 GetClientSize(&w, &h);
419 RoomList->SetSize(0, 0, 200, h);
420 GetClientWindow()->SetSize(200, 0, w - 200, h);
422 // Remember the size of the window from session to session
424 sw.Printf("%d %d", w, h);
425 ini->Write("/Window Sizes/Main", sw);