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 license.txt or http://www.opensource.org/licenses/mit-license.php.
8 #include <boost/function.hpp>
11 DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)
15 extern wxLocale g_locale;
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);
31 inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)
35 return wxMessageBox(message, caption, style, parent, x, y);
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());
41 #define wxMessageBox MyMessageBox
48 class CMainFrame : public CMainFrameBase
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);
81 CMainFrame(wxWindow* parent);
93 wxListCtrl* m_listCtrl;
97 bool fRefreshListCtrl;
98 bool fRefreshListCtrlRunning;
99 bool fOnSetFocusAddress;
100 unsigned int nListViewUpdated;
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();
115 class CTxDetailsDialog : public CTxDetailsDialogBase
119 void OnButtonOK(wxCommandEvent& event);
123 CTxDetailsDialog(wxWindow* parent, CWalletTx wtx);
131 class COptionsDialog : public COptionsDialogBase
135 void OnListBox(wxCommandEvent& event);
136 void OnKillFocusTransactionFee(wxFocusEvent& event);
137 void OnCheckBoxUseProxy(wxCommandEvent& event);
138 void OnKillFocusProxy(wxFocusEvent& event);
140 void OnButtonOK(wxCommandEvent& event);
141 void OnButtonCancel(wxCommandEvent& event);
142 void OnButtonApply(wxCommandEvent& event);
146 COptionsDialog(wxWindow* parent);
149 bool fTmpStartOnSystemStartup;
150 bool fTmpMinimizeOnClose;
151 void SelectPage(int nPage);
152 CAddress GetProxyAddr();
157 class CAboutDialog : public CAboutDialogBase
161 void OnButtonOK(wxCommandEvent& event);
165 CAboutDialog(wxWindow* parent);
170 class CSendDialog : public CSendDialogBase
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);
183 CSendDialog(wxWindow* parent, const wxString& strAddress="");
187 std::string strFromSave;
188 std::string strMessageSave;
193 class CSendingDialog : public CSendingDialogBase
197 void OnClose(wxCloseEvent& event);
198 void OnButtonOK(wxCommandEvent& event);
199 void OnButtonCancel(wxCommandEvent& event);
200 void OnPaint(wxPaintEvent& event);
204 CSendingDialog(wxWindow* parent, const CAddress& addrIn, int64 nPriceIn, const CWalletTx& wtxIn);
212 char pszStatus[10000];
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);
229 void SendingDialogStartTransfer(void* parg);
230 void SendingDialogOnReply2(void* parg, CDataStream& vRecv);
231 void SendingDialogOnReply3(void* parg, CDataStream& vRecv);
235 class CAddressBookDialog : public CAddressBookDialogBase
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);
253 CAddressBookDialog(wxWindow* parent, const wxString& strInitSelected, int nPageIn, bool fDuringSendIn);
262 wxListCtrl* m_listCtrl;
264 wxString GetAddress();
265 wxString GetSelectedAddress();
266 wxString GetSelectedSendingAddress();
267 wxString GetSelectedReceivingAddress();
268 bool CheckIfMine(const std::string& strAddress, const std::string& strTitle);
273 class CGetTextFromUserDialog : public CGetTextFromUserDialogBase
277 void OnButtonOK(wxCommandEvent& event) { EndModal(true); }
278 void OnButtonCancel(wxCommandEvent& event) { EndModal(false); }
279 void OnClose(wxCloseEvent& event) { EndModal(false); }
281 void OnKeyDown(wxKeyEvent& event)
283 if (event.GetKeyCode() == '\r' || event.GetKeyCode() == WXK_NUMPAD_ENTER)
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)
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())
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;
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(); }
326 class CMyTaskBarIcon : public wxTaskBarIcon
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);
339 CMyTaskBarIcon() : wxTaskBarIcon()
344 void Show(bool fShow=true);
347 void UpdateTooltip();
348 virtual wxMenu* CreatePopupMenu();
350 DECLARE_EVENT_TABLE()