]> code.citadel.org Git - citadel.git/blob - daphne/enter.cpp
Initial revision
[citadel.git] / daphne / enter.cpp
1 #include "includes.hpp"
2
3 enum {
4         BUTTON_SAVE,
5         BUTTON_CANCEL,
6         BUTTON_FIND
7 };
8
9
10 BEGIN_EVENT_TABLE(EnterMessage, wxMDIChildFrame)
11         EVT_BUTTON(BUTTON_CANCEL,       EnterMessage::OnCancel)
12         EVT_BUTTON(BUTTON_SAVE,         EnterMessage::OnSave)
13         EVT_BUTTON(BUTTON_FIND,         EnterMessage::OnFind)
14 END_EVENT_TABLE()
15
16
17 // frame constructor
18 EnterMessage::EnterMessage(
19         CitClient *sock, wxMDIParentFrame *MyMDI,
20         wxString roomname, unsigned int roomflags)
21         : wxMDIChildFrame(MyMDI,        //parent
22                         -1,     //window id
23                         roomname + ": enter message",
24                         wxDefaultPosition,
25                         wxDefaultSize,
26                         wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL,
27                         roomname
28                         ) {
29
30         wxString sendcmd, recvcmd;
31
32         citsock = sock;
33         citMyMDI = MyMDI;
34         ThisRoom = roomname;
35         finduser_panel = (SelectUser *) NULL;
36
37         wxButton *cancel_button = new wxButton(
38                 this,
39                 BUTTON_CANCEL,
40                 " Cancel ",
41                 wxDefaultPosition);
42
43         wxLayoutConstraints *c1 = new wxLayoutConstraints;
44         c1->bottom.SameAs(this, wxBottom, 2);
45         c1->height.AsIs();
46         c1->width.AsIs();
47         c1->right.SameAs(this, wxRight, 2);
48         cancel_button->SetConstraints(c1);
49
50         wxButton *save_button = new wxButton(
51                 this,
52                 BUTTON_SAVE,
53                 " Save ",
54                 wxDefaultPosition);
55
56         wxLayoutConstraints *c2 = new wxLayoutConstraints;
57         c2->bottom.SameAs(cancel_button, wxBottom);
58         c2->right.LeftOf(cancel_button, 5);
59         c2->height.SameAs(cancel_button, wxHeight);
60         c2->width.AsIs();
61         save_button->SetConstraints(c2);
62
63
64
65
66         // If the user has a choice of several posting names, present them.
67
68         wxStaticText *fromlabel = new wxStaticText(this, -1, "From: ");
69
70         wxLayoutConstraints *c6 = new wxLayoutConstraints;
71         c6->top.SameAs(this, wxTop, 10);
72         c6->left.SameAs(this, wxLeft, 2);
73         c6->width.AsIs();
74         c6->height.AsIs();
75         fromlabel->SetConstraints(c6);
76
77         wxString posting_name_choices[2];
78         int num_choices;
79
80         if (roomflags & QR_ANONONLY) {
81                 posting_name_choices[0] = "****";
82                 num_choices = 1;
83         } else {
84                 posting_name_choices[0] = citsock->curr_user;
85                 num_choices = 1;
86         }
87         
88         if (roomflags & QR_ANONOPT) {
89                 posting_name_choices[num_choices++] = "Anonymous";
90         }
91
92         fromname = new wxChoice(this, -1,
93                 wxDefaultPosition, wxSize(150,25),
94                         num_choices, posting_name_choices);
95
96         wxLayoutConstraints *c7 = new wxLayoutConstraints;
97         c7->centreY.SameAs(fromlabel, wxCentreY);
98         c7->left.RightOf(fromlabel, 3);
99         c7->width.AsIs();
100         c7->height.AsIs();
101         fromname->SetConstraints(c7);
102
103
104
105         // There may also be the opportunity to present a recipient.
106         // FIX ... disable this if we're not in a mail room
107
108         wxStaticText *tolabel = new wxStaticText(this, -1, "To: ");
109
110         wxLayoutConstraints *c8 = new wxLayoutConstraints;
111         c8->centreY.SameAs(fromname, wxCentreY);
112         c8->left.RightOf(fromname, 5);
113         c8->width.AsIs();
114         c8->height.AsIs();
115         tolabel->SetConstraints(c8);
116
117         toname = new wxTextCtrl(this, -1, "",
118                 wxDefaultPosition, wxSize(150,25));
119         
120         wxLayoutConstraints *c9 = new wxLayoutConstraints;
121         c9->centreY.SameAs(tolabel, wxCentreY);
122         c9->left.RightOf(tolabel, 3);
123         c9->width.AsIs();
124         c9->height.AsIs();
125         toname->SetConstraints(c9);
126
127         wxButton *findrecp = new wxButton(
128                 this,
129                 BUTTON_FIND,
130                 " Find "
131                 );
132
133         wxLayoutConstraints *d1 = new wxLayoutConstraints;
134         d1->centreY.SameAs(toname, wxCentreY);
135         d1->left.RightOf(toname, 3);
136         d1->width.AsIs();
137         d1->height.AsIs();
138         findrecp->SetConstraints(d1);
139
140
141
142
143         // The main portion of this screen is a text entry box.
144
145         TheMessage = new wxTextCtrl(this, -1, "",
146                 wxDefaultPosition, wxDefaultSize,
147                 wxTE_MULTILINE);
148
149         wxLayoutConstraints *d9 = new wxLayoutConstraints;
150         d9->top.Below(fromname, 2);
151         d9->bottom.Above(cancel_button, -5);
152         d9->left.SameAs(this, wxLeft, 2);
153         d9->right.SameAs(this, wxRight, 2);
154         TheMessage->SetConstraints(d9);
155
156
157
158         SetAutoLayout(TRUE);
159         Show(TRUE);
160         Layout();
161 }
162
163
164
165 void EnterMessage::OnCancel(wxCommandEvent& whichbutton) {
166         delete this;
167 }
168
169
170 // The user clicked "Find" ... so we have to go looking for a recipient.
171 // Shove a FindUser panel right in front of everything else.
172 //
173 void EnterMessage::OnFind(wxCommandEvent& whichbutton) {
174         finduser_panel = new SelectUser(citsock, this,
175                                 "Please select a recipient",
176                                 "Recipients",
177                                 0,
178                                 toname);
179
180         wxLayoutConstraints *f1 = new wxLayoutConstraints;
181         f1->centreX.SameAs(this, wxCentreX);
182         f1->centreY.SameAs(this, wxCentreY);
183         f1->width.SameAs(this, wxWidth);
184         f1->height.SameAs(this, wxHeight);
185         finduser_panel->SetConstraints(f1);
186         Layout();
187 }
188
189
190 void EnterMessage::OnSave(wxCommandEvent& whichbutton) {
191         wxString sendcmd, recvcmd, xferbuf;
192
193         sendcmd = "ENT0 1|" + toname->GetValue() + "|"
194                 + ((!fromname->GetString(fromname->GetSelection()).CmpNoCase("Anonymous")) ? "1" : "0")
195                 + "|0" ;
196         xferbuf = TheMessage->GetValue();
197         if (citsock->serv_trans(sendcmd, recvcmd,
198                                 xferbuf, ThisRoom) == 4) {
199                 delete this;
200         } else {
201                 // Display the error message
202                 wxMessageDialog save_error(this,
203                         recvcmd.Mid(4),
204                         "Error",
205                         wxOK | wxCENTRE | wxICON_INFORMATION,
206                         wxDefaultPosition);
207                         save_error.ShowModal();
208
209         }
210 }