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);
27 inline void InitMessage(const std::string &message)
33 inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)
37 return wxMessageBox(message, caption, style, parent, x, y);
39 printf("wxMessageBox %s: %s\n", std::string(caption).c_str(), std::string(message).c_str());
40 fprintf(stderr, "%s: %s\n", std::string(caption).c_str(), std::string(message).c_str());
43 #define wxMessageBox MyMessageBox
50 class CMainFrame : public CMainFrameBase
54 void OnNotebookPageChanged(wxNotebookEvent& event);
55 void OnClose(wxCloseEvent& event);
56 void OnIconize(wxIconizeEvent& event);
57 void OnMouseEvents(wxMouseEvent& event);
58 void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
59 void OnIdle(wxIdleEvent& event);
60 void OnPaint(wxPaintEvent& event);
61 void OnPaintListCtrl(wxPaintEvent& event);
62 void OnMenuFileExit(wxCommandEvent& event);
63 void OnUpdateUIOptionsGenerate(wxUpdateUIEvent& event);
64 void OnMenuOptionsChangeYourAddress(wxCommandEvent& event);
65 void OnMenuOptionsEncryptWallet(wxCommandEvent& event);
66 void OnMenuOptionsChangeWalletPassphrase(wxCommandEvent& event);
67 void OnMenuOptionsOptions(wxCommandEvent& event);
68 void OnMenuHelpAbout(wxCommandEvent& event);
69 void OnButtonSend(wxCommandEvent& event);
70 void OnButtonAddressBook(wxCommandEvent& event);
71 void OnSetFocusAddress(wxFocusEvent& event);
72 void OnMouseEventsAddress(wxMouseEvent& event);
73 void OnButtonNew(wxCommandEvent& event);
74 void OnButtonCopy(wxCommandEvent& event);
75 void OnListColBeginDrag(wxListEvent& event);
76 void OnListItemActivated(wxListEvent& event);
77 void OnListItemActivatedProductsSent(wxListEvent& event);
78 void OnListItemActivatedOrdersSent(wxListEvent& event);
79 void OnListItemActivatedOrdersReceived(wxListEvent& event);
83 CMainFrame(wxWindow* parent);
95 wxListCtrl* m_listCtrl;
99 bool fRefreshListCtrl;
100 bool fRefreshListCtrlRunning;
101 bool fOnSetFocusAddress;
102 unsigned int nListViewUpdated;
105 void OnUIThreadCall(wxCommandEvent& event);
106 int GetSortIndex(const std::string& strSort);
107 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);
108 bool DeleteLine(uint256 hashKey);
109 bool InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex=-1);
110 void RefreshListCtrl();
111 void RefreshStatusColumn();
117 class CTxDetailsDialog : public CTxDetailsDialogBase
121 void OnButtonOK(wxCommandEvent& event);
125 CTxDetailsDialog(wxWindow* parent, CWalletTx wtx);
133 class COptionsDialog : public COptionsDialogBase
137 void OnListBox(wxCommandEvent& event);
138 void OnKillFocusTransactionFee(wxFocusEvent& event);
139 void OnCheckBoxUseProxy(wxCommandEvent& event);
140 void OnKillFocusProxy(wxFocusEvent& event);
142 void OnButtonOK(wxCommandEvent& event);
143 void OnButtonCancel(wxCommandEvent& event);
144 void OnButtonApply(wxCommandEvent& event);
148 COptionsDialog(wxWindow* parent);
151 bool fTmpStartOnSystemStartup;
152 bool fTmpMinimizeOnClose;
153 void SelectPage(int nPage);
154 CAddress GetProxyAddr();
159 class CAboutDialog : public CAboutDialogBase
163 void OnButtonOK(wxCommandEvent& event);
167 CAboutDialog(wxWindow* parent);
172 class CSendDialog : public CSendDialogBase
176 void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
177 void OnKillFocusAmount(wxFocusEvent& event);
178 void OnButtonAddressBook(wxCommandEvent& event);
179 void OnButtonPaste(wxCommandEvent& event);
180 void OnButtonSend(wxCommandEvent& event);
181 void OnButtonCancel(wxCommandEvent& event);
185 CSendDialog(wxWindow* parent, const wxString& strAddress="");
189 std::string strFromSave;
190 std::string strMessageSave;
195 class CSendingDialog : public CSendingDialogBase
199 void OnClose(wxCloseEvent& event);
200 void OnButtonOK(wxCommandEvent& event);
201 void OnButtonCancel(wxCommandEvent& event);
202 void OnPaint(wxPaintEvent& event);
206 CSendingDialog(wxWindow* parent, const CAddress& addrIn, int64 nPriceIn, const CWalletTx& wtxIn);
214 char pszStatus[10000];
224 bool Status(const std::string& str);
225 bool Error(const std::string& str);
226 void StartTransfer();
227 void OnReply2(CDataStream& vRecv);
228 void OnReply3(CDataStream& vRecv);
231 void SendingDialogStartTransfer(void* parg);
232 void SendingDialogOnReply2(void* parg, CDataStream& vRecv);
233 void SendingDialogOnReply3(void* parg, CDataStream& vRecv);
237 class CAddressBookDialog : public CAddressBookDialogBase
241 void OnNotebookPageChanged(wxNotebookEvent& event);
242 void OnListEndLabelEdit(wxListEvent& event);
243 void OnListItemSelected(wxListEvent& event);
244 void OnListItemActivated(wxListEvent& event);
245 void OnButtonDelete(wxCommandEvent& event);
246 void OnButtonCopy(wxCommandEvent& event);
247 void OnButtonEdit(wxCommandEvent& event);
248 void OnButtonNew(wxCommandEvent& event);
249 void OnButtonOK(wxCommandEvent& event);
250 void OnButtonCancel(wxCommandEvent& event);
251 void OnClose(wxCloseEvent& event);
255 CAddressBookDialog(wxWindow* parent, const wxString& strInitSelected, int nPageIn, bool fDuringSendIn);
264 wxListCtrl* m_listCtrl;
266 wxString GetAddress();
267 wxString GetSelectedAddress();
268 wxString GetSelectedSendingAddress();
269 wxString GetSelectedReceivingAddress();
270 bool CheckIfMine(const std::string& strAddress, const std::string& strTitle);
275 class CGetTextFromUserDialog : public CGetTextFromUserDialogBase
279 void OnButtonOK(wxCommandEvent& event) { EndModal(true); }
280 void OnButtonCancel(wxCommandEvent& event) { EndModal(false); }
281 void OnClose(wxCloseEvent& event) { EndModal(false); }
283 void OnKeyDown(wxKeyEvent& event)
285 if (event.GetKeyCode() == '\r' || event.GetKeyCode() == WXK_NUMPAD_ENTER)
293 CGetTextFromUserDialog(wxWindow* parent,
294 const std::string& strCaption,
295 const std::string& strMessage1,
296 const std::string& strValue1="",
297 const std::string& strMessage2="",
298 const std::string& strValue2="") : CGetTextFromUserDialogBase(parent, wxID_ANY, strCaption)
300 int x = GetSize().GetWidth();
301 int y = GetSize().GetHeight();
302 m_staticTextMessage1->SetLabel(strMessage1);
303 m_textCtrl1->SetValue(strValue1);
304 y += wxString(strMessage1).Freq('\n') * 14;
305 if (!strMessage2.empty())
307 m_staticTextMessage2->Show(true);
308 m_staticTextMessage2->SetLabel(strMessage2);
309 m_textCtrl2->Show(true);
310 m_textCtrl2->SetValue(strValue2);
311 y += 46 + wxString(strMessage2).Freq('\n') * 14;
321 std::string GetValue() { return (std::string)m_textCtrl1->GetValue(); }
322 std::string GetValue1() { return (std::string)m_textCtrl1->GetValue(); }
323 std::string GetValue2() { return (std::string)m_textCtrl2->GetValue(); }
328 class CMyTaskBarIcon : public wxTaskBarIcon
332 void OnLeftButtonDClick(wxTaskBarIconEvent& event);
333 void OnMenuRestore(wxCommandEvent& event);
334 void OnMenuSend(wxCommandEvent& event);
335 void OnMenuOptions(wxCommandEvent& event);
336 void OnUpdateUIGenerate(wxUpdateUIEvent& event);
337 void OnMenuGenerate(wxCommandEvent& event);
338 void OnMenuExit(wxCommandEvent& event);
341 CMyTaskBarIcon() : wxTaskBarIcon()
346 void Show(bool fShow=true);
349 void UpdateTooltip();
350 virtual wxMenu* CreatePopupMenu();
352 DECLARE_EVENT_TABLE()