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 OnMenuOptionsOptions(wxCommandEvent& event);
63 void OnMenuHelpAbout(wxCommandEvent& event);
64 void OnButtonSend(wxCommandEvent& event);
65 void OnButtonAddressBook(wxCommandEvent& event);
66 void OnSetFocusAddress(wxFocusEvent& event);
67 void OnMouseEventsAddress(wxMouseEvent& event);
68 void OnButtonNew(wxCommandEvent& event);
69 void OnButtonCopy(wxCommandEvent& event);
70 void OnListColBeginDrag(wxListEvent& event);
71 void OnListItemActivated(wxListEvent& event);
72 void OnListItemActivatedProductsSent(wxListEvent& event);
73 void OnListItemActivatedOrdersSent(wxListEvent& event);
74 void OnListItemActivatedOrdersReceived(wxListEvent& event);
78 CMainFrame(wxWindow* parent);
90 wxListCtrl* m_listCtrl;
94 bool fRefreshListCtrl;
95 bool fRefreshListCtrlRunning;
96 bool fOnSetFocusAddress;
97 unsigned int nListViewUpdated;
100 void OnUIThreadCall(wxCommandEvent& event);
101 int GetSortIndex(const std::string& strSort);
102 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);
103 bool DeleteLine(uint256 hashKey);
104 bool InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex=-1);
105 void RefreshListCtrl();
106 void RefreshStatusColumn();
112 class CTxDetailsDialog : public CTxDetailsDialogBase
116 void OnButtonOK(wxCommandEvent& event);
120 CTxDetailsDialog(wxWindow* parent, CWalletTx wtx);
128 class COptionsDialog : public COptionsDialogBase
132 void OnListBox(wxCommandEvent& event);
133 void OnKillFocusTransactionFee(wxFocusEvent& event);
134 void OnCheckBoxUseProxy(wxCommandEvent& event);
135 void OnKillFocusProxy(wxFocusEvent& event);
137 void OnButtonOK(wxCommandEvent& event);
138 void OnButtonCancel(wxCommandEvent& event);
139 void OnButtonApply(wxCommandEvent& event);
143 COptionsDialog(wxWindow* parent);
146 bool fTmpStartOnSystemStartup;
147 bool fTmpMinimizeOnClose;
148 void SelectPage(int nPage);
149 CAddress GetProxyAddr();
154 class CAboutDialog : public CAboutDialogBase
158 void OnButtonOK(wxCommandEvent& event);
162 CAboutDialog(wxWindow* parent);
167 class CSendDialog : public CSendDialogBase
171 void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
172 void OnKillFocusAmount(wxFocusEvent& event);
173 void OnButtonAddressBook(wxCommandEvent& event);
174 void OnButtonPaste(wxCommandEvent& event);
175 void OnButtonSend(wxCommandEvent& event);
176 void OnButtonCancel(wxCommandEvent& event);
180 CSendDialog(wxWindow* parent, const wxString& strAddress="");
184 std::string strFromSave;
185 std::string strMessageSave;
190 class CSendingDialog : public CSendingDialogBase
194 void OnClose(wxCloseEvent& event);
195 void OnButtonOK(wxCommandEvent& event);
196 void OnButtonCancel(wxCommandEvent& event);
197 void OnPaint(wxPaintEvent& event);
201 CSendingDialog(wxWindow* parent, const CAddress& addrIn, int64 nPriceIn, const CWalletTx& wtxIn);
209 char pszStatus[10000];
219 bool Status(const std::string& str);
220 bool Error(const std::string& str);
221 void StartTransfer();
222 void OnReply2(CDataStream& vRecv);
223 void OnReply3(CDataStream& vRecv);
226 void SendingDialogStartTransfer(void* parg);
227 void SendingDialogOnReply2(void* parg, CDataStream& vRecv);
228 void SendingDialogOnReply3(void* parg, CDataStream& vRecv);
232 class CAddressBookDialog : public CAddressBookDialogBase
236 void OnNotebookPageChanged(wxNotebookEvent& event);
237 void OnListEndLabelEdit(wxListEvent& event);
238 void OnListItemSelected(wxListEvent& event);
239 void OnListItemActivated(wxListEvent& event);
240 void OnButtonDelete(wxCommandEvent& event);
241 void OnButtonCopy(wxCommandEvent& event);
242 void OnButtonEdit(wxCommandEvent& event);
243 void OnButtonNew(wxCommandEvent& event);
244 void OnButtonOK(wxCommandEvent& event);
245 void OnButtonCancel(wxCommandEvent& event);
246 void OnClose(wxCloseEvent& event);
250 CAddressBookDialog(wxWindow* parent, const wxString& strInitSelected, int nPageIn, bool fDuringSendIn);
259 wxListCtrl* m_listCtrl;
261 wxString GetAddress();
262 wxString GetSelectedAddress();
263 wxString GetSelectedSendingAddress();
264 wxString GetSelectedReceivingAddress();
265 bool CheckIfMine(const std::string& strAddress, const std::string& strTitle);
270 class CGetTextFromUserDialog : public CGetTextFromUserDialogBase
274 void OnButtonOK(wxCommandEvent& event) { EndModal(true); }
275 void OnButtonCancel(wxCommandEvent& event) { EndModal(false); }
276 void OnClose(wxCloseEvent& event) { EndModal(false); }
278 void OnKeyDown(wxKeyEvent& event)
280 if (event.GetKeyCode() == '\r' || event.GetKeyCode() == WXK_NUMPAD_ENTER)
288 CGetTextFromUserDialog(wxWindow* parent,
289 const std::string& strCaption,
290 const std::string& strMessage1,
291 const std::string& strValue1="",
292 const std::string& strMessage2="",
293 const std::string& strValue2="") : CGetTextFromUserDialogBase(parent, wxID_ANY, strCaption)
295 int x = GetSize().GetWidth();
296 int y = GetSize().GetHeight();
297 m_staticTextMessage1->SetLabel(strMessage1);
298 m_textCtrl1->SetValue(strValue1);
299 y += wxString(strMessage1).Freq('\n') * 14;
300 if (!strMessage2.empty())
302 m_staticTextMessage2->Show(true);
303 m_staticTextMessage2->SetLabel(strMessage2);
304 m_textCtrl2->Show(true);
305 m_textCtrl2->SetValue(strValue2);
306 y += 46 + wxString(strMessage2).Freq('\n') * 14;
316 std::string GetValue() { return (std::string)m_textCtrl1->GetValue(); }
317 std::string GetValue1() { return (std::string)m_textCtrl1->GetValue(); }
318 std::string GetValue2() { return (std::string)m_textCtrl2->GetValue(); }
323 class CMyTaskBarIcon : public wxTaskBarIcon
327 void OnLeftButtonDClick(wxTaskBarIconEvent& event);
328 void OnMenuRestore(wxCommandEvent& event);
329 void OnMenuSend(wxCommandEvent& event);
330 void OnMenuOptions(wxCommandEvent& event);
331 void OnUpdateUIGenerate(wxUpdateUIEvent& event);
332 void OnMenuGenerate(wxCommandEvent& event);
333 void OnMenuExit(wxCommandEvent& event);
336 CMyTaskBarIcon() : wxTaskBarIcon()
341 void Show(bool fShow=true);
344 void UpdateTooltip();
345 virtual wxMenu* CreatePopupMenu();
347 DECLARE_EVENT_TABLE()