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