]> code.citadel.org Git - citadel.git/blob - daphne/testwindow.cpp
* added message subject to all those tiny messages
[citadel.git] / daphne / testwindow.cpp
1 // ============================================================================
2 // declarations
3 // ============================================================================
4
5 #include "includes.hpp"
6
7 // ----------------------------------------------------------------------------
8 // private classes
9 // ----------------------------------------------------------------------------
10
11 // ----------------------------------------------------------------------------
12 // constants
13 // ----------------------------------------------------------------------------
14
15 // IDs for the controls and the menu commands
16 enum
17 {
18         BUTTON_SENDCMD,
19         BUTTON_CLOSE
20 };
21
22 // ----------------------------------------------------------------------------
23 // event tables and other macros for wxWindows
24 // ----------------------------------------------------------------------------
25
26 // the event tables connect the wxWindows events with the functions (event
27 // handlers) which process them. It can be also done at run-time, but for the
28 // simple menu events like this the static method is much simpler.
29 BEGIN_EVENT_TABLE(      TestWindow, wxMDIChildFrame)
30         EVT_BUTTON(     BUTTON_SENDCMD,         TestWindow::OnButtonPressed)
31         EVT_BUTTON(     BUTTON_CLOSE,           TestWindow::OnButtonPressed)
32 END_EVENT_TABLE()
33
34 // ============================================================================
35 // implementation
36 // ============================================================================
37
38
39 // ----------------------------------------------------------------------------
40 // the application class
41 // ----------------------------------------------------------------------------
42
43 // frame constructor
44 TestWindow::TestWindow(CitClient *sock, wxMDIParentFrame *MyMDI)
45        : wxMDIChildFrame(MyMDI, //parent
46                         -1,     //window id
47                         "Test Window",
48                         wxDefaultPosition,
49                         wxDefaultSize,
50                         wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL,
51                         "TestWindow"
52                         ) {
53
54         citsock = sock;
55
56         // set the frame icon
57         /* SetIcon(wxICON(mondrian)); */
58
59         wxStaticText *sendcmd_label = new wxStaticText(this, -1, "Server command:");
60         wxStaticText *recvcmd_label = new wxStaticText(this, -1, "Response:");
61         wxStaticText *xfercmd_label = new wxStaticText(this, -1, "Send/receive data:");
62
63         sendcmd = new wxTextCtrl(
64                 this,
65                 -1,
66                 "",
67                 wxDefaultPosition,
68                 wxDefaultSize,
69                 0, // no style
70                 wxDefaultValidator,
71                 "sendcmd"
72                 );
73
74         wxLayoutConstraints *c1 = new wxLayoutConstraints;
75         c1->top.SameAs(this, wxTop, 10);
76         c1->left.SameAs(this, wxLeft, 5);
77         c1->width.AsIs();
78         c1->height.AsIs();
79         sendcmd_label->SetConstraints(c1);
80
81         wxLayoutConstraints *c2 = new wxLayoutConstraints;
82         c2->left.RightOf(sendcmd_label, 5);
83         c2->centreY.SameAs(sendcmd_label, wxCentreY);
84         c2->height.AsIs();
85         c2->right.SameAs(this, wxRight, 5);
86         sendcmd->SetConstraints(c2);
87
88         recvcmd = new wxTextCtrl(
89                 this,
90                 -1,
91                 "",
92                 wxDefaultPosition,
93                 wxDefaultSize,
94                 wxTE_READONLY,
95                 wxDefaultValidator,
96                 "sendcmd"
97                 );
98
99         wxLayoutConstraints *c3 = new wxLayoutConstraints;
100         c3->left.SameAs(sendcmd, wxLeft);
101         c3->right.SameAs(sendcmd, wxRight);
102         c3->height.AsIs();
103         c3->top.Below(sendcmd, 5);
104         recvcmd->SetConstraints(c3);
105
106         wxLayoutConstraints *c4 = new wxLayoutConstraints;
107         c4->left.SameAs(sendcmd_label, wxLeft);
108         c4->centreY.SameAs(recvcmd, wxCentreY);
109         c4->height.AsIs();
110         c4->width.AsIs();
111         recvcmd_label->SetConstraints(c4);
112         
113         cmd_button = new wxButton(
114                 this,
115                 BUTTON_SENDCMD,
116                 "Send command",
117                 wxPoint(10,300),
118                 wxSize(100,30),
119                 0L,
120                 wxDefaultValidator,
121                 "cmd_button"
122                 );
123
124         close_button = new wxButton(
125                 this,
126                 BUTTON_CLOSE,
127                 "Close",
128                 wxPoint(150,300),
129                 wxSize(100,30),
130                 0L,
131                 wxDefaultValidator,
132                 "close_button"
133                 );
134
135         wxLayoutConstraints *c5 = new wxLayoutConstraints;
136         c5->left.SameAs(this, wxLeft, 5);
137         c5->bottom.SameAs(this, wxBottom, 5);
138         c5->width.AsIs();
139         c5->height.AsIs();
140         cmd_button->SetConstraints(c5);
141
142         wxLayoutConstraints *c6 = new wxLayoutConstraints;
143         c6->right.SameAs(this, wxRight, 5);
144         c6->bottom.SameAs(this, wxBottom, 5);
145         c6->width.AsIs();
146         c6->height.AsIs();
147         close_button->SetConstraints(c6);
148
149         wxLayoutConstraints *c7 = new wxLayoutConstraints;
150         c7->top.Below(recvcmd, 5);
151         c7->centreX.SameAs(this, wxCentreX);
152         c7->width.AsIs();
153         c7->height.AsIs();
154         xfercmd_label->SetConstraints(c7);
155
156         xfercmd = new wxTextCtrl(
157                 this,
158                 -1,
159                 "",
160                 wxDefaultPosition,
161                 wxDefaultSize,
162                 wxTE_MULTILINE,
163                 wxDefaultValidator,
164                 "xfercmd"
165                 );
166
167         wxLayoutConstraints *c8 = new wxLayoutConstraints;
168         c8->left.SameAs(this, wxLeft, 5);
169         c8->right.SameAs(this, wxRight, 5);
170         c8->top.Below(xfercmd_label, 5);
171         c8->bottom.Above(cmd_button, -5);
172         xfercmd->SetConstraints(c8);
173
174         cmd_button->SetDefault();
175         SetAutoLayout(TRUE);
176         Show(TRUE);
177         Layout();
178
179 }
180
181
182
183 void TestWindow::OnButtonPressed(wxCommandEvent& whichbutton) {
184         wxString sendbuf = "";
185         wxString recvbuf = "";
186         wxString xferbuf = "";
187
188         if (whichbutton.GetId()==BUTTON_CLOSE) {
189                 delete this;
190         }
191         else if (whichbutton.GetId()==BUTTON_SENDCMD) {
192                 sendbuf = sendcmd->GetValue();
193                 recvcmd->Clear();
194                 xferbuf = xfercmd->GetValue();
195                 citsock->serv_trans(sendbuf, recvbuf, xferbuf);
196                 recvcmd->SetValue(recvbuf);
197                 xfercmd->SetValue(xferbuf);
198         }
199 }