added -testsafemode switch
[novacoin.git] / ui.h
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
4
5 DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)
6
7
8
9 extern wxLocale g_locale;
10
11
12
13 void HandleCtrlA(wxKeyEvent& event);
14 string FormatTxStatus(const CWalletTx& wtx);
15 void UIThreadCall(boost::function0<void>);
16 int ThreadSafeMessageBox(const string& message, const string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);
17 bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent);
18 void CalledSetStatusBar(const string& strText, int nField);
19 void MainFrameRepaint();
20 void CreateMainWindow();
21 void SetStartOnSystemStartup(bool fAutoStart);
22
23
24
25
26 inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)
27 {
28 #ifdef GUI
29     if (!fDaemon)
30         return wxMessageBox(message, caption, style, parent, x, y);
31 #endif
32     printf("wxMessageBox %s: %s\n", string(caption).c_str(), string(message).c_str());
33     fprintf(stderr, "%s: %s\n", string(caption).c_str(), string(message).c_str());
34     return wxOK;
35 }
36 #define wxMessageBox  MyMessageBox
37
38
39
40
41
42
43 class CMainFrame : public CMainFrameBase
44 {
45 protected:
46     // Event handlers
47     void OnNotebookPageChanged(wxNotebookEvent& event);
48     void OnClose(wxCloseEvent& event);
49     void OnIconize(wxIconizeEvent& event);
50     void OnMouseEvents(wxMouseEvent& event);
51     void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
52     void OnIdle(wxIdleEvent& event);
53     void OnPaint(wxPaintEvent& event);
54     void OnPaintListCtrl(wxPaintEvent& event);
55     void OnMenuFileExit(wxCommandEvent& event);
56     void OnMenuOptionsGenerate(wxCommandEvent& event);
57     void OnUpdateUIOptionsGenerate(wxUpdateUIEvent& event);
58     void OnMenuOptionsChangeYourAddress(wxCommandEvent& event);
59     void OnMenuOptionsOptions(wxCommandEvent& event);
60     void OnMenuHelpAbout(wxCommandEvent& event);
61     void OnButtonSend(wxCommandEvent& event);
62     void OnButtonAddressBook(wxCommandEvent& event);
63     void OnSetFocusAddress(wxFocusEvent& event);
64     void OnMouseEventsAddress(wxMouseEvent& event);
65     void OnButtonNew(wxCommandEvent& event);
66     void OnButtonCopy(wxCommandEvent& event);
67     void OnListColBeginDrag(wxListEvent& event);
68     void OnListItemActivated(wxListEvent& event);
69     void OnListItemActivatedProductsSent(wxListEvent& event);
70     void OnListItemActivatedOrdersSent(wxListEvent& event);
71     void OnListItemActivatedOrdersReceived(wxListEvent& event);
72         
73 public:
74     /** Constructor */
75     CMainFrame(wxWindow* parent);
76     ~CMainFrame();
77
78     // Custom
79     enum
80     {
81         ALL = 0,
82         SENTRECEIVED = 1,
83         SENT = 2,
84         RECEIVED = 3,
85     };
86     int nPage;
87     wxListCtrl* m_listCtrl;
88     bool fShowGenerated;
89     bool fShowSent;
90     bool fShowReceived;
91     bool fRefreshListCtrl;
92     bool fRefreshListCtrlRunning;
93     bool fOnSetFocusAddress;
94     unsigned int nListViewUpdated;
95     bool fRefresh;
96
97     void OnUIThreadCall(wxCommandEvent& event);
98     int GetSortIndex(const string& strSort);
99     void InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSort, const wxString& str1, const wxString& str2, const wxString& str3, const wxString& str4, const wxString& str5);
100     bool DeleteLine(uint256 hashKey);
101     bool InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex=-1);
102     void RefreshListCtrl();
103     void RefreshStatusColumn();
104 };
105
106
107
108
109 class CTxDetailsDialog : public CTxDetailsDialogBase
110 {
111 protected:
112     // Event handlers
113     void OnButtonOK(wxCommandEvent& event);
114
115 public:
116     /** Constructor */
117     CTxDetailsDialog(wxWindow* parent, CWalletTx wtx);
118
119     // State
120     CWalletTx wtx;
121 };
122
123
124
125 class COptionsDialog : public COptionsDialogBase
126 {
127 protected:
128     // Event handlers
129     void OnListBox(wxCommandEvent& event);
130     void OnKillFocusTransactionFee(wxFocusEvent& event);
131     void OnCheckBoxLimitProcessors(wxCommandEvent& event);
132     void OnCheckBoxUseProxy(wxCommandEvent& event);
133     void OnKillFocusProxy(wxFocusEvent& event);
134
135     void OnButtonOK(wxCommandEvent& event);
136     void OnButtonCancel(wxCommandEvent& event);
137     void OnButtonApply(wxCommandEvent& event);
138
139 public:
140     /** Constructor */
141     COptionsDialog(wxWindow* parent);
142
143     // Custom
144     bool fTmpStartOnSystemStartup;
145     bool fTmpMinimizeOnClose;
146     void SelectPage(int nPage);
147     CAddress GetProxyAddr();
148 };
149
150
151
152 class CAboutDialog : public CAboutDialogBase
153 {
154 protected:
155     // Event handlers
156     void OnButtonOK(wxCommandEvent& event);
157
158 public:
159     /** Constructor */
160     CAboutDialog(wxWindow* parent);
161 };
162
163
164
165 class CSendDialog : public CSendDialogBase
166 {
167 protected:
168     // Event handlers
169     void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
170     void OnTextAddress(wxCommandEvent& event);
171     void OnKillFocusAmount(wxFocusEvent& event);
172     void OnButtonAddressBook(wxCommandEvent& event);
173     void OnButtonPaste(wxCommandEvent& event);
174     void OnButtonSend(wxCommandEvent& event);
175     void OnButtonCancel(wxCommandEvent& event);
176         
177 public:
178     /** Constructor */
179     CSendDialog(wxWindow* parent, const wxString& strAddress="");
180
181     // Custom
182     bool fEnabledPrev;
183     string strFromSave;
184     string strMessageSave;
185 };
186
187
188
189 class CSendingDialog : public CSendingDialogBase
190 {
191 public:
192     // Event handlers
193     void OnClose(wxCloseEvent& event);
194     void OnButtonOK(wxCommandEvent& event);
195     void OnButtonCancel(wxCommandEvent& event);
196     void OnPaint(wxPaintEvent& event);
197         
198 public:
199     /** Constructor */
200     CSendingDialog(wxWindow* parent, const CAddress& addrIn, int64 nPriceIn, const CWalletTx& wtxIn);
201     ~CSendingDialog();
202
203     // State
204     CAddress addr;
205     int64 nPrice;
206     CWalletTx wtx;
207     wxDateTime start;
208     char pszStatus[10000];
209     bool fCanCancel;
210     bool fAbort;
211     bool fSuccess;
212     bool fUIDone;
213     bool fWorkDone;
214
215     void Close();
216     void Repaint();
217     bool Status();
218     bool Status(const string& str);
219     bool Error(const string& str);
220     void StartTransfer();
221     void OnReply2(CDataStream& vRecv);
222     void OnReply3(CDataStream& vRecv);
223 };
224
225 void SendingDialogStartTransfer(void* parg);
226 void SendingDialogOnReply2(void* parg, CDataStream& vRecv);
227 void SendingDialogOnReply3(void* parg, CDataStream& vRecv);
228
229
230
231 class CAddressBookDialog : public CAddressBookDialogBase
232 {
233 protected:
234     // Event handlers
235     void OnNotebookPageChanged(wxNotebookEvent& event);
236     void OnListEndLabelEdit(wxListEvent& event);
237     void OnListItemSelected(wxListEvent& event);
238     void OnListItemActivated(wxListEvent& event);
239     void OnButtonDelete(wxCommandEvent& event);
240     void OnButtonCopy(wxCommandEvent& event);
241     void OnButtonEdit(wxCommandEvent& event);
242     void OnButtonNew(wxCommandEvent& event);
243     void OnButtonOK(wxCommandEvent& event);
244     void OnButtonCancel(wxCommandEvent& event);
245     void OnClose(wxCloseEvent& event);
246
247 public:
248     /** Constructor */
249     CAddressBookDialog(wxWindow* parent, const wxString& strInitSelected, int nPageIn, bool fDuringSendIn);
250
251     // Custom
252     enum
253     {
254         SENDING = 0,
255         RECEIVING = 1,
256     };
257     int nPage;
258     wxListCtrl* m_listCtrl;
259     bool fDuringSend;
260     wxString GetAddress();
261     wxString GetSelectedAddress();
262     wxString GetSelectedSendingAddress();
263     wxString GetSelectedReceivingAddress();
264     bool CheckIfMine(const string& strAddress, const string& strTitle);
265 };
266
267
268
269 class CGetTextFromUserDialog : public CGetTextFromUserDialogBase
270 {
271 protected:
272     // Event handlers
273     void OnButtonOK(wxCommandEvent& event)     { EndModal(true); }
274     void OnButtonCancel(wxCommandEvent& event) { EndModal(false); }
275     void OnClose(wxCloseEvent& event)          { EndModal(false); }
276
277     void OnKeyDown(wxKeyEvent& event)
278     {
279         if (event.GetKeyCode() == '\r' || event.GetKeyCode() == WXK_NUMPAD_ENTER)
280             EndModal(true);
281         else
282             HandleCtrlA(event);
283     }
284
285 public:
286     /** Constructor */
287     CGetTextFromUserDialog(wxWindow* parent,
288                            const string& strCaption,
289                            const string& strMessage1,
290                            const string& strValue1="",
291                            const string& strMessage2="",
292                            const string& strValue2="") : CGetTextFromUserDialogBase(parent, wxID_ANY, strCaption)
293     {
294         int x = GetSize().GetWidth();
295         int y = GetSize().GetHeight();
296         m_staticTextMessage1->SetLabel(strMessage1);
297         m_textCtrl1->SetValue(strValue1);
298         y += wxString(strMessage1).Freq('\n') * 14;
299         if (!strMessage2.empty())
300         {
301             m_staticTextMessage2->Show(true);
302             m_staticTextMessage2->SetLabel(strMessage2);
303             m_textCtrl2->Show(true);
304             m_textCtrl2->SetValue(strValue2);
305             y += 46 + wxString(strMessage2).Freq('\n') * 14;
306         }
307 #ifndef __WXMSW__
308         x *= 1.14;
309         y *= 1.14;
310 #endif
311         SetSize(x, y);
312     }
313
314     // Custom
315     string GetValue()  { return (string)m_textCtrl1->GetValue(); }
316     string GetValue1() { return (string)m_textCtrl1->GetValue(); }
317     string GetValue2() { return (string)m_textCtrl2->GetValue(); }
318 };
319
320
321
322 class CMyTaskBarIcon : public wxTaskBarIcon
323 {
324 protected:
325     // Event handlers
326     void OnLeftButtonDClick(wxTaskBarIconEvent& event);
327     void OnMenuRestore(wxCommandEvent& event);
328     void OnMenuOptions(wxCommandEvent& event);
329     void OnUpdateUIGenerate(wxUpdateUIEvent& event);
330     void OnMenuGenerate(wxCommandEvent& event);
331     void OnMenuExit(wxCommandEvent& event);
332
333 public:
334     CMyTaskBarIcon() : wxTaskBarIcon()
335     {
336         Show(true);
337     }
338
339     void Show(bool fShow=true);
340     void Hide();
341     void Restore();
342     void UpdateTooltip();
343     virtual wxMenu* CreatePopupMenu();
344
345 DECLARE_EVENT_TABLE()
346 };