3 // =========================================================================
5 // =========================================================================
7 #include "includes.hpp"
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
13 // IDs for the controls and the menu commands
20 // ----------------------------------------------------------------------------
21 // event tables and other macros for wxWindows
22 // ----------------------------------------------------------------------------
24 // the event tables connect the wxWindows events with the functions (event
25 // handlers) which process them. It can be also done at run-time, but for the
26 // simple menu events like this the static method is much simpler.
27 BEGIN_EVENT_TABLE( Preferences, wxMDIChildFrame)
28 EVT_BUTTON( BUTTON_SAVE, Preferences::OnButtonPressed)
29 EVT_BUTTON( BUTTON_CANCEL, Preferences::OnButtonPressed)
32 // ============================================================================
34 // ============================================================================
37 // ----------------------------------------------------------------------------
38 // the application class
39 // ----------------------------------------------------------------------------
42 Preferences::Preferences( CitClient *sock,
43 wxMDIParentFrame *MyMDI)
44 : wxMDIChildFrame(MyMDI, //parent
49 wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL,
59 /* SetIcon(wxICON(mondrian)); */
61 wxButton *save_button = new wxButton(
72 wxButton *cancel_button = new wxButton(
83 wxLayoutConstraints *c1 = new wxLayoutConstraints;
84 c1->bottom.SameAs(this, wxBottom, 5);
85 c1->left.SameAs(this, wxLeft, 10);
86 c1->height.AsIs(); c1->width.AsIs();
87 save_button->SetConstraints(c1);
89 wxLayoutConstraints *c3 = new wxLayoutConstraints;
90 c3->bottom.SameAs(save_button, wxBottom);
91 c3->right.SameAs(this, wxRight, 10);
92 c3->height.AsIs(); c3->width.AsIs();
93 cancel_button->SetConstraints(c3);
95 wxStaticText *server_host_label = new wxStaticText(
96 this, -1, "Server host");
98 server_host = new wxTextCtrl(this, -1);
100 wxStaticText *server_port_label = new wxStaticText(
101 this, -1, "Server port");
103 server_port = new wxTextCtrl(this, -1);
105 wxLayoutConstraints *c4 = new wxLayoutConstraints;
106 c4->top.SameAs(this, wxTop, 10);
107 c4->left.SameAs(this, wxLeft, 10);
108 c4->height.AsIs(); c4->width.AsIs();
109 server_host_label->SetConstraints(c4);
111 wxLayoutConstraints *c5 = new wxLayoutConstraints;
112 c5->centreY.SameAs(server_host_label, wxCentreY);
113 c5->left.RightOf(server_host_label, 10);
114 c5->right.SameAs(this, wxRight, 10);
116 server_host->SetConstraints(c5);
118 wxLayoutConstraints *c6 = new wxLayoutConstraints;
119 c6->top.Below(server_host_label, 15);
120 c6->left.SameAs(this, wxLeft, 10);
121 c6->height.AsIs(); c6->width.AsIs();
122 server_port_label->SetConstraints(c6);
124 wxLayoutConstraints *c7 = new wxLayoutConstraints;
125 c7->centreY.SameAs(server_port_label, wxCentreY);
126 c7->left.SameAs(server_host, wxLeft);
127 c7->right.PercentOf(this, wxWidth, 50);
129 server_port->SetConstraints(c7);
131 server_autoconnect = new wxCheckBox(this, -1,
132 "Automatically connect at startup");
134 wxLayoutConstraints *c8 = new wxLayoutConstraints;
135 c8->centreY.SameAs(server_port, wxCentreY);
136 c8->left.RightOf(server_port, 5);
137 c8->width.AsIs(); c8->height.AsIs();
138 server_autoconnect->SetConstraints(c8);
144 ini->Read("/Citadel Server/Host", &buf, DEFAULT_HOST);
145 server_host->SetValue(buf);
147 ini->Read("/Citadel Server/Port", &buf, DEFAULT_PORT);
148 server_port->SetValue(buf);
150 ini->Read("/Citadel Server/ConnectOnStartup", &buf, "no");
151 server_autoconnect->SetValue(
152 ((!buf.CmpNoCase("yes")) ? TRUE : FALSE));
161 void Preferences::OnButtonPressed(wxCommandEvent& whichbutton) {
162 if (whichbutton.GetId() == BUTTON_CANCEL) {
164 } else if (whichbutton.GetId() == BUTTON_SAVE) {
165 ini->Write("/Citadel Server/Host", server_host->GetValue());
166 ini->Write("/Citadel Server/Port", server_port->GetValue());
167 ini->Write("/Citadel Server/ConnectOnStartup",
168 ((server_autoconnect->GetValue()==TRUE)
169 ? wxString("yes") : wxString("no")));