make bitcoin include files more modular
[novacoin.git] / src / 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 #ifndef BITCOIN_UI_H
5 #define BITCOIN_UI_H
6
7 DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)
8
9
10
11 extern wxLocale g_locale;
12
13
14
15 void HandleCtrlA(wxKeyEvent& event);
16 void UIThreadCall(boost::function0<void>);
17 int ThreadSafeMessageBox(const std::string& message, const std::string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);
18 bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent);
19 void CalledSetStatusBar(const std::string& strText, int nField);
20 void MainFrameRepaint();
21 void CreateMainWindow();
22 void SetStartOnSystemStartup(bool fAutoStart);
23
24
25
26
27 inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)
28 {
29 #ifdef GUI
30     if (!fDaemon)
31         return wxMessageBox(message, caption, style, parent, x, y);
32 #endif
33     printf("wxMessageBox %s: %s\n", std::string(caption).c_str(), std::string(message).c_str());
34     fprintf(stderr, "%s: %s\n", std::string(caption).c_str(), std::string(message).c_str());
35     return wxOK;
36 }
37 #define wxMessageBox  MyMessageBox
38
39
40
41
42
43
44 class CMainFrame : public CMainFrameBase
45 {
46 protected:
47     // Event handlers
48     void OnNotebookPageChanged(wxNotebookEvent& event);
49     void OnClose(wxCloseEvent& event);
50     void OnIconize(wxIconizeEvent& event);
51     void OnMouseEvents(wxMouseEvent& event);
52     void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
53     void OnIdle(wxIdleEvent& event);
54     void OnPaint(wxPaintEvent& event);
55     void OnPaintListCtrl(wxPaintEvent& event);
56     void OnMenuFileExit(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 std::string& strSort);
99     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);
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 OnCheckBoxUseProxy(wxCommandEvent& event);
132     void OnKillFocusProxy(wxFocusEvent& event);
133
134     void OnButtonOK(wxCommandEvent& event);
135     void OnButtonCancel(wxCommandEvent& event);
136     void OnButtonApply(wxCommandEvent& event);
137
138 public:
139     /** Constructor */
140     COptionsDialog(wxWindow* parent);
141
142     // Custom
143     bool fTmpStartOnSystemStartup;
144     bool fTmpMinimizeOnClose;
145     void SelectPage(int nPage);
146     CAddress GetProxyAddr();
147 };
148
149
150
151 class CAboutDialog : public CAboutDialogBase
152 {
153 protected:
154     // Event handlers
155     void OnButtonOK(wxCommandEvent& event);
156
157 public:
158     /** Constructor */
159     CAboutDialog(wxWindow* parent);
160 };
161
162
163
164 class CSendDialog : public CSendDialogBase
165 {
166 protected:
167     // Event handlers
168     void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
169     void OnKillFocusAmount(wxFocusEvent& event);
170     void OnButtonAddressBook(wxCommandEvent& event);
171     void OnButtonPaste(wxCommandEvent& event);
172     void OnButtonSend(wxCommandEvent& event);
173     void OnButtonCancel(wxCommandEvent& event);
174         
175 public:
176     /** Constructor */
177     CSendDialog(wxWindow* parent, const wxString& strAddress="");
178
179     // Custom
180     bool fEnabledPrev;
181     std::string strFromSave;
182     std::string strMessageSave;
183 };
184
185
186
187 class CSendingDialog : public CSendingDialogBase
188 {
189 public:
190     // Event handlers
191     void OnClose(wxCloseEvent& event);
192     void OnButtonOK(wxCommandEvent& event);
193     void OnButtonCancel(wxCommandEvent& event);
194     void OnPaint(wxPaintEvent& event);
195         
196 public:
197     /** Constructor */
198     CSendingDialog(wxWindow* parent, const CAddress& addrIn, int64 nPriceIn, const CWalletTx& wtxIn);
199     ~CSendingDialog();
200
201     // State
202     CAddress addr;
203     int64 nPrice;
204     CWalletTx wtx;
205     wxDateTime start;
206     char pszStatus[10000];
207     bool fCanCancel;
208     bool fAbort;
209     bool fSuccess;
210     bool fUIDone;
211     bool fWorkDone;
212
213     void Close();
214     void Repaint();
215     bool Status();
216     bool Status(const std::string& str);
217     bool Error(const std::string& str);
218     void StartTransfer();
219     void OnReply2(CDataStream& vRecv);
220     void OnReply3(CDataStream& vRecv);
221 };
222
223 void SendingDialogStartTransfer(void* parg);
224 void SendingDialogOnReply2(void* parg, CDataStream& vRecv);
225 void SendingDialogOnReply3(void* parg, CDataStream& vRecv);
226
227
228
229 class CAddressBookDialog : public CAddressBookDialogBase
230 {
231 protected:
232     // Event handlers
233     void OnNotebookPageChanged(wxNotebookEvent& event);
234     void OnListEndLabelEdit(wxListEvent& event);
235     void OnListItemSelected(wxListEvent& event);
236     void OnListItemActivated(wxListEvent& event);
237     void OnButtonDelete(wxCommandEvent& event);
238     void OnButtonCopy(wxCommandEvent& event);
239     void OnButtonEdit(wxCommandEvent& event);
240     void OnButtonNew(wxCommandEvent& event);
241     void OnButtonOK(wxCommandEvent& event);
242     void OnButtonCancel(wxCommandEvent& event);
243     void OnClose(wxCloseEvent& event);
244
245 public:
246     /** Constructor */
247     CAddressBookDialog(wxWindow* parent, const wxString& strInitSelected, int nPageIn, bool fDuringSendIn);
248
249     // Custom
250     enum
251     {
252         SENDING = 0,
253         RECEIVING = 1,
254     };
255     int nPage;
256     wxListCtrl* m_listCtrl;
257     bool fDuringSend;
258     wxString GetAddress();
259     wxString GetSelectedAddress();
260     wxString GetSelectedSendingAddress();
261     wxString GetSelectedReceivingAddress();
262     bool CheckIfMine(const std::string& strAddress, const std::string& strTitle);
263 };
264
265
266
267 class CGetTextFromUserDialog : public CGetTextFromUserDialogBase
268 {
269 protected:
270     // Event handlers
271     void OnButtonOK(wxCommandEvent& event)     { EndModal(true); }
272     void OnButtonCancel(wxCommandEvent& event) { EndModal(false); }
273     void OnClose(wxCloseEvent& event)          { EndModal(false); }
274
275     void OnKeyDown(wxKeyEvent& event)
276     {
277         if (event.GetKeyCode() == '\r' || event.GetKeyCode() == WXK_NUMPAD_ENTER)
278             EndModal(true);
279         else
280             HandleCtrlA(event);
281     }
282
283 public:
284     /** Constructor */
285     CGetTextFromUserDialog(wxWindow* parent,
286                            const std::string& strCaption,
287                            const std::string& strMessage1,
288                            const std::string& strValue1="",
289                            const std::string& strMessage2="",
290                            const std::string& strValue2="") : CGetTextFromUserDialogBase(parent, wxID_ANY, strCaption)
291     {
292         int x = GetSize().GetWidth();
293         int y = GetSize().GetHeight();
294         m_staticTextMessage1->SetLabel(strMessage1);
295         m_textCtrl1->SetValue(strValue1);
296         y += wxString(strMessage1).Freq('\n') * 14;
297         if (!strMessage2.empty())
298         {
299             m_staticTextMessage2->Show(true);
300             m_staticTextMessage2->SetLabel(strMessage2);
301             m_textCtrl2->Show(true);
302             m_textCtrl2->SetValue(strValue2);
303             y += 46 + wxString(strMessage2).Freq('\n') * 14;
304         }
305 #ifndef __WXMSW__
306         x = x * 114 / 100;
307         y = y * 114 / 100;
308 #endif
309         SetSize(x, y);
310     }
311
312     // Custom
313     std::string GetValue()  { return (std::string)m_textCtrl1->GetValue(); }
314     std::string GetValue1() { return (std::string)m_textCtrl1->GetValue(); }
315     std::string GetValue2() { return (std::string)m_textCtrl2->GetValue(); }
316 };
317
318
319
320 class CMyTaskBarIcon : public wxTaskBarIcon
321 {
322 protected:
323     // Event handlers
324     void OnLeftButtonDClick(wxTaskBarIconEvent& event);
325     void OnMenuRestore(wxCommandEvent& event);
326     void OnMenuSend(wxCommandEvent& event);
327     void OnMenuOptions(wxCommandEvent& event);
328     void OnUpdateUIGenerate(wxUpdateUIEvent& event);
329     void OnMenuGenerate(wxCommandEvent& event);
330     void OnMenuExit(wxCommandEvent& event);
331
332 public:
333     CMyTaskBarIcon() : wxTaskBarIcon()
334     {
335         Show(true);
336     }
337
338     void Show(bool fShow=true);
339     void Hide();
340     void Restore();
341     void UpdateTooltip();
342     virtual wxMenu* CreatePopupMenu();
343
344 DECLARE_EVENT_TABLE()
345 };
346
347 #endif