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