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.
7 #include <boost/function.hpp>
10 DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)
14 extern wxLocale g_locale;
18 void HandleCtrlA(wxKeyEvent& event);
19 void UIThreadCall(boost::function0<void>);
20 int ThreadSafeMessageBox(const std::string& message, const std::string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);
21 bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent);
22 void CalledSetStatusBar(const std::string& strText, int nField);
23 void MainFrameRepaint();
24 void CreateMainWindow();
25 void SetStartOnSystemStartup(bool fAutoStart);
30 inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)
34 return wxMessageBox(message, caption, style, parent, x, y);
36 printf("wxMessageBox %s: %s\n", std::string(caption).c_str(), std::string(message).c_str());
37 fprintf(stderr, "%s: %s\n", std::string(caption).c_str(), std::string(message).c_str());
40 #define wxMessageBox MyMessageBox
47 class CMainFrame : public CMainFrameBase
51 void OnNotebookPageChanged(wxNotebookEvent& event);
52 void OnClose(wxCloseEvent& event);
53 void OnIconize(wxIconizeEvent& event);
54 void OnMouseEvents(wxMouseEvent& event);
55 void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
56 void OnIdle(wxIdleEvent& event);
57 void OnPaint(wxPaintEvent& event);
58 void OnPaintListCtrl(wxPaintEvent& event);
59 void OnMenuFileExit(wxCommandEvent& event);
60 void OnUpdateUIOptionsGenerate(wxUpdateUIEvent& event);
61 void OnMenuOptionsChangeYourAddress(wxCommandEvent& event);
62 void OnMenuOptionsEncryptWallet(wxCommandEvent& event);
63 void OnMenuOptionsChangeWalletPassphrase(wxCommandEvent& event);
64 void OnMenuOptionsOptions(wxCommandEvent& event);
65 void OnMenuHelpAbout(wxCommandEvent& event);
66 void OnButtonSend(wxCommandEvent& event);
67 void OnButtonAddressBook(wxCommandEvent& event);
68 void OnSetFocusAddress(wxFocusEvent& event);
69 void OnMouseEventsAddress(wxMouseEvent& event);
70 void OnButtonNew(wxCommandEvent& event);
71 void OnButtonCopy(wxCommandEvent& event);
72 void OnListColBeginDrag(wxListEvent& event);
73 void OnListItemActivated(wxListEvent& event);
74 void OnListItemActivatedProductsSent(wxListEvent& event);
75 void OnListItemActivatedOrdersSent(wxListEvent& event);
76 void OnListItemActivatedOrdersReceived(wxListEvent& event);
80 CMainFrame(wxWindow* parent);
92 wxListCtrl* m_listCtrl;
96 bool fRefreshListCtrl;
97 bool fRefreshListCtrlRunning;
98 bool fOnSetFocusAddress;
99 unsigned int nListViewUpdated;
102 void OnUIThreadCall(wxCommandEvent& event);
103 int GetSortIndex(const std::string& strSort);
104 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);
105 bool DeleteLine(uint256 hashKey);
106 bool InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex=-1);
107 void RefreshListCtrl();
108 void RefreshStatusColumn();
114 class CTxDetailsDialog : public CTxDetailsDialogBase
118 void OnButtonOK(wxCommandEvent& event);
122 CTxDetailsDialog(wxWindow* parent, CWalletTx wtx);
130 class COptionsDialog : public COptionsDialogBase
134 void OnListBox(wxCommandEvent& event);
135 void OnKillFocusTransactionFee(wxFocusEvent& event);
136 void OnCheckBoxUseProxy(wxCommandEvent& event);
137 void OnKillFocusProxy(wxFocusEvent& event);
139 void OnButtonOK(wxCommandEvent& event);
140 void OnButtonCancel(wxCommandEvent& event);
141 void OnButtonApply(wxCommandEvent& event);
145 COptionsDialog(wxWindow* parent);
148 bool fTmpStartOnSystemStartup;
149 bool fTmpMinimizeOnClose;
150 void SelectPage(int nPage);
151 CAddress GetProxyAddr();
156 class CAboutDialog : public CAboutDialogBase
160 void OnButtonOK(wxCommandEvent& event);
164 CAboutDialog(wxWindow* parent);
169 class CSendDialog : public CSendDialogBase
173 void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
174 void OnKillFocusAmount(wxFocusEvent& event);
175 void OnButtonAddressBook(wxCommandEvent& event);
176 void OnButtonPaste(wxCommandEvent& event);
177 void OnButtonSend(wxCommandEvent& event);
178 void OnButtonCancel(wxCommandEvent& event);
182 CSendDialog(wxWindow* parent, const wxString& strAddress="");
186 std::string strFromSave;
187 std::string strMessageSave;
192 class CSendingDialog : public CSendingDialogBase
196 void OnClose(wxCloseEvent& event);
197 void OnButtonOK(wxCommandEvent& event);
198 void OnButtonCancel(wxCommandEvent& event);
199 void OnPaint(wxPaintEvent& event);
203 CSendingDialog(wxWindow* parent, const CAddress& addrIn, int64 nPriceIn, const CWalletTx& wtxIn);
211 char pszStatus[10000];
221 bool Status(const std::string& str);
222 bool Error(const std::string& str);
223 void StartTransfer();
224 void OnReply2(CDataStream& vRecv);
225 void OnReply3(CDataStream& vRecv);
228 void SendingDialogStartTransfer(void* parg);
229 void SendingDialogOnReply2(void* parg, CDataStream& vRecv);
230 void SendingDialogOnReply3(void* parg, CDataStream& vRecv);
234 class CAddressBookDialog : public CAddressBookDialogBase
238 void OnNotebookPageChanged(wxNotebookEvent& event);
239 void OnListEndLabelEdit(wxListEvent& event);
240 void OnListItemSelected(wxListEvent& event);
241 void OnListItemActivated(wxListEvent& event);
242 void OnButtonDelete(wxCommandEvent& event);
243 void OnButtonCopy(wxCommandEvent& event);
244 void OnButtonEdit(wxCommandEvent& event);
245 void OnButtonNew(wxCommandEvent& event);
246 void OnButtonOK(wxCommandEvent& event);
247 void OnButtonCancel(wxCommandEvent& event);
248 void OnClose(wxCloseEvent& event);
252 CAddressBookDialog(wxWindow* parent, const wxString& strInitSelected, int nPageIn, bool fDuringSendIn);
261 wxListCtrl* m_listCtrl;
263 wxString GetAddress();
264 wxString GetSelectedAddress();
265 wxString GetSelectedSendingAddress();
266 wxString GetSelectedReceivingAddress();
267 bool CheckIfMine(const std::string& strAddress, const std::string& strTitle);
272 class CGetTextFromUserDialog : public CGetTextFromUserDialogBase
276 void OnButtonOK(wxCommandEvent& event) { EndModal(true); }
277 void OnButtonCancel(wxCommandEvent& event) { EndModal(false); }
278 void OnClose(wxCloseEvent& event) { EndModal(false); }
280 void OnKeyDown(wxKeyEvent& event)
282 if (event.GetKeyCode() == '\r' || event.GetKeyCode() == WXK_NUMPAD_ENTER)
290 CGetTextFromUserDialog(wxWindow* parent,
291 const std::string& strCaption,
292 const std::string& strMessage1,
293 const std::string& strValue1="",
294 const std::string& strMessage2="",
295 const std::string& strValue2="") : CGetTextFromUserDialogBase(parent, wxID_ANY, strCaption)
297 int x = GetSize().GetWidth();
298 int y = GetSize().GetHeight();
299 m_staticTextMessage1->SetLabel(strMessage1);
300 m_textCtrl1->SetValue(strValue1);
301 y += wxString(strMessage1).Freq('\n') * 14;
302 if (!strMessage2.empty())
304 m_staticTextMessage2->Show(true);
305 m_staticTextMessage2->SetLabel(strMessage2);
306 m_textCtrl2->Show(true);
307 m_textCtrl2->SetValue(strValue2);
308 y += 46 + wxString(strMessage2).Freq('\n') * 14;
318 std::string GetValue() { return (std::string)m_textCtrl1->GetValue(); }
319 std::string GetValue1() { return (std::string)m_textCtrl1->GetValue(); }
320 std::string GetValue2() { return (std::string)m_textCtrl2->GetValue(); }
325 class CMyTaskBarIcon : public wxTaskBarIcon
329 void OnLeftButtonDClick(wxTaskBarIconEvent& event);
330 void OnMenuRestore(wxCommandEvent& event);
331 void OnMenuSend(wxCommandEvent& event);
332 void OnMenuOptions(wxCommandEvent& event);
333 void OnUpdateUIGenerate(wxUpdateUIEvent& event);
334 void OnMenuGenerate(wxCommandEvent& event);
335 void OnMenuExit(wxCommandEvent& event);
338 CMyTaskBarIcon() : wxTaskBarIcon()
343 void Show(bool fShow=true);
346 void UpdateTooltip();
347 virtual wxMenu* CreatePopupMenu();
349 DECLARE_EVENT_TABLE()