You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui.h 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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.
  5. #ifndef BITCOIN_UI_H
  6. #define BITCOIN_UI_H
  7. #include <boost/function.hpp>
  8. #include "wallet.h"
  9. DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)
  10. extern wxLocale g_locale;
  11. void HandleCtrlA(wxKeyEvent& event);
  12. void UIThreadCall(boost::function0<void>);
  13. int ThreadSafeMessageBox(const std::string& message, const std::string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);
  14. bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent);
  15. void CalledSetStatusBar(const std::string& strText, int nField);
  16. void MainFrameRepaint();
  17. void CreateMainWindow();
  18. void SetStartOnSystemStartup(bool fAutoStart);
  19. inline void InitMessage(const std::string &message)
  20. {
  21. }
  22. inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)
  23. {
  24. #ifdef GUI
  25. if (!fDaemon)
  26. return wxMessageBox(message, caption, style, parent, x, y);
  27. #endif
  28. printf("wxMessageBox %s: %s\n", std::string(caption).c_str(), std::string(message).c_str());
  29. fprintf(stderr, "%s: %s\n", std::string(caption).c_str(), std::string(message).c_str());
  30. return wxOK;
  31. }
  32. #define wxMessageBox MyMessageBox
  33. class CMainFrame : public CMainFrameBase
  34. {
  35. protected:
  36. // Event handlers
  37. void OnNotebookPageChanged(wxNotebookEvent& event);
  38. void OnClose(wxCloseEvent& event);
  39. void OnIconize(wxIconizeEvent& event);
  40. void OnMouseEvents(wxMouseEvent& event);
  41. void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
  42. void OnIdle(wxIdleEvent& event);
  43. void OnPaint(wxPaintEvent& event);
  44. void OnPaintListCtrl(wxPaintEvent& event);
  45. void OnMenuFileExit(wxCommandEvent& event);
  46. void OnUpdateUIOptionsGenerate(wxUpdateUIEvent& event);
  47. void OnMenuOptionsChangeYourAddress(wxCommandEvent& event);
  48. void OnMenuOptionsEncryptWallet(wxCommandEvent& event);
  49. void OnMenuOptionsChangeWalletPassphrase(wxCommandEvent& event);
  50. void OnMenuOptionsOptions(wxCommandEvent& event);
  51. void OnMenuHelpAbout(wxCommandEvent& event);
  52. void OnButtonSend(wxCommandEvent& event);
  53. void OnButtonAddressBook(wxCommandEvent& event);
  54. void OnSetFocusAddress(wxFocusEvent& event);
  55. void OnMouseEventsAddress(wxMouseEvent& event);
  56. void OnButtonNew(wxCommandEvent& event);
  57. void OnButtonCopy(wxCommandEvent& event);
  58. void OnListColBeginDrag(wxListEvent& event);
  59. void OnListItemActivated(wxListEvent& event);
  60. void OnListItemActivatedProductsSent(wxListEvent& event);
  61. void OnListItemActivatedOrdersSent(wxListEvent& event);
  62. void OnListItemActivatedOrdersReceived(wxListEvent& event);
  63. public:
  64. /** Constructor */
  65. CMainFrame(wxWindow* parent);
  66. ~CMainFrame();
  67. // Custom
  68. enum
  69. {
  70. ALL = 0,
  71. SENTRECEIVED = 1,
  72. SENT = 2,
  73. RECEIVED = 3,
  74. };
  75. int nPage;
  76. wxListCtrl* m_listCtrl;
  77. bool fShowGenerated;
  78. bool fShowSent;
  79. bool fShowReceived;
  80. bool fRefreshListCtrl;
  81. bool fRefreshListCtrlRunning;
  82. bool fOnSetFocusAddress;
  83. unsigned int nListViewUpdated;
  84. bool fRefresh;
  85. void OnUIThreadCall(wxCommandEvent& event);
  86. int GetSortIndex(const std::string& strSort);
  87. 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);
  88. bool DeleteLine(uint256 hashKey);
  89. bool InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex=-1);
  90. void RefreshListCtrl();
  91. void RefreshStatusColumn();
  92. };
  93. class CTxDetailsDialog : public CTxDetailsDialogBase
  94. {
  95. protected:
  96. // Event handlers
  97. void OnButtonOK(wxCommandEvent& event);
  98. public:
  99. /** Constructor */
  100. CTxDetailsDialog(wxWindow* parent, CWalletTx wtx);
  101. // State
  102. CWalletTx wtx;
  103. };
  104. class COptionsDialog : public COptionsDialogBase
  105. {
  106. protected:
  107. // Event handlers
  108. void OnListBox(wxCommandEvent& event);
  109. void OnKillFocusTransactionFee(wxFocusEvent& event);
  110. void OnCheckBoxUseProxy(wxCommandEvent& event);
  111. void OnKillFocusProxy(wxFocusEvent& event);
  112. void OnButtonOK(wxCommandEvent& event);
  113. void OnButtonCancel(wxCommandEvent& event);
  114. void OnButtonApply(wxCommandEvent& event);
  115. public:
  116. /** Constructor */
  117. COptionsDialog(wxWindow* parent);
  118. // Custom
  119. bool fTmpStartOnSystemStartup;
  120. bool fTmpMinimizeOnClose;
  121. void SelectPage(int nPage);
  122. CAddress GetProxyAddr();
  123. };
  124. class CAboutDialog : public CAboutDialogBase
  125. {
  126. protected:
  127. // Event handlers
  128. void OnButtonOK(wxCommandEvent& event);
  129. public:
  130. /** Constructor */
  131. CAboutDialog(wxWindow* parent);
  132. };
  133. class CSendDialog : public CSendDialogBase
  134. {
  135. protected:
  136. // Event handlers
  137. void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
  138. void OnKillFocusAmount(wxFocusEvent& event);
  139. void OnButtonAddressBook(wxCommandEvent& event);
  140. void OnButtonPaste(wxCommandEvent& event);
  141. void OnButtonSend(wxCommandEvent& event);
  142. void OnButtonCancel(wxCommandEvent& event);
  143. public:
  144. /** Constructor */
  145. CSendDialog(wxWindow* parent, const wxString& strAddress="");
  146. // Custom
  147. bool fEnabledPrev;
  148. std::string strFromSave;
  149. std::string strMessageSave;
  150. };
  151. class CSendingDialog : public CSendingDialogBase
  152. {
  153. public:
  154. // Event handlers
  155. void OnClose(wxCloseEvent& event);
  156. void OnButtonOK(wxCommandEvent& event);
  157. void OnButtonCancel(wxCommandEvent& event);
  158. void OnPaint(wxPaintEvent& event);
  159. public:
  160. /** Constructor */
  161. CSendingDialog(wxWindow* parent, const CAddress& addrIn, int64 nPriceIn, const CWalletTx& wtxIn);
  162. ~CSendingDialog();
  163. // State
  164. CAddress addr;
  165. int64 nPrice;
  166. CWalletTx wtx;
  167. wxDateTime start;
  168. char pszStatus[10000];
  169. bool fCanCancel;
  170. bool fAbort;
  171. bool fSuccess;
  172. bool fUIDone;
  173. bool fWorkDone;
  174. void Close();
  175. void Repaint();
  176. bool Status();
  177. bool Status(const std::string& str);
  178. bool Error(const std::string& str);
  179. void StartTransfer();
  180. void OnReply2(CDataStream& vRecv);
  181. void OnReply3(CDataStream& vRecv);
  182. };
  183. void SendingDialogStartTransfer(void* parg);
  184. void SendingDialogOnReply2(void* parg, CDataStream& vRecv);
  185. void SendingDialogOnReply3(void* parg, CDataStream& vRecv);
  186. class CAddressBookDialog : public CAddressBookDialogBase
  187. {
  188. protected:
  189. // Event handlers
  190. void OnNotebookPageChanged(wxNotebookEvent& event);
  191. void OnListEndLabelEdit(wxListEvent& event);
  192. void OnListItemSelected(wxListEvent& event);
  193. void OnListItemActivated(wxListEvent& event);
  194. void OnButtonDelete(wxCommandEvent& event);
  195. void OnButtonCopy(wxCommandEvent& event);
  196. void OnButtonEdit(wxCommandEvent& event);
  197. void OnButtonNew(wxCommandEvent& event);
  198. void OnButtonOK(wxCommandEvent& event);
  199. void OnButtonCancel(wxCommandEvent& event);
  200. void OnClose(wxCloseEvent& event);
  201. public:
  202. /** Constructor */
  203. CAddressBookDialog(wxWindow* parent, const wxString& strInitSelected, int nPageIn, bool fDuringSendIn);
  204. // Custom
  205. enum
  206. {
  207. SENDING = 0,
  208. RECEIVING = 1,
  209. };
  210. int nPage;
  211. wxListCtrl* m_listCtrl;
  212. bool fDuringSend;
  213. wxString GetAddress();
  214. wxString GetSelectedAddress();
  215. wxString GetSelectedSendingAddress();
  216. wxString GetSelectedReceivingAddress();
  217. bool CheckIfMine(const std::string& strAddress, const std::string& strTitle);
  218. };
  219. class CGetTextFromUserDialog : public CGetTextFromUserDialogBase
  220. {
  221. protected:
  222. // Event handlers
  223. void OnButtonOK(wxCommandEvent& event) { EndModal(true); }
  224. void OnButtonCancel(wxCommandEvent& event) { EndModal(false); }
  225. void OnClose(wxCloseEvent& event) { EndModal(false); }
  226. void OnKeyDown(wxKeyEvent& event)
  227. {
  228. if (event.GetKeyCode() == '\r' || event.GetKeyCode() == WXK_NUMPAD_ENTER)
  229. EndModal(true);
  230. else
  231. HandleCtrlA(event);
  232. }
  233. public:
  234. /** Constructor */
  235. CGetTextFromUserDialog(wxWindow* parent,
  236. const std::string& strCaption,
  237. const std::string& strMessage1,
  238. const std::string& strValue1="",
  239. const std::string& strMessage2="",
  240. const std::string& strValue2="") : CGetTextFromUserDialogBase(parent, wxID_ANY, strCaption)
  241. {
  242. int x = GetSize().GetWidth();
  243. int y = GetSize().GetHeight();
  244. m_staticTextMessage1->SetLabel(strMessage1);
  245. m_textCtrl1->SetValue(strValue1);
  246. y += wxString(strMessage1).Freq('\n') * 14;
  247. if (!strMessage2.empty())
  248. {
  249. m_staticTextMessage2->Show(true);
  250. m_staticTextMessage2->SetLabel(strMessage2);
  251. m_textCtrl2->Show(true);
  252. m_textCtrl2->SetValue(strValue2);
  253. y += 46 + wxString(strMessage2).Freq('\n') * 14;
  254. }
  255. #ifndef __WXMSW__
  256. x = x * 114 / 100;
  257. y = y * 114 / 100;
  258. #endif
  259. SetSize(x, y);
  260. }
  261. // Custom
  262. std::string GetValue() { return (std::string)m_textCtrl1->GetValue(); }
  263. std::string GetValue1() { return (std::string)m_textCtrl1->GetValue(); }
  264. std::string GetValue2() { return (std::string)m_textCtrl2->GetValue(); }
  265. };
  266. class CMyTaskBarIcon : public wxTaskBarIcon
  267. {
  268. protected:
  269. // Event handlers
  270. void OnLeftButtonDClick(wxTaskBarIconEvent& event);
  271. void OnMenuRestore(wxCommandEvent& event);
  272. void OnMenuSend(wxCommandEvent& event);
  273. void OnMenuOptions(wxCommandEvent& event);
  274. void OnUpdateUIGenerate(wxUpdateUIEvent& event);
  275. void OnMenuGenerate(wxCommandEvent& event);
  276. void OnMenuExit(wxCommandEvent& event);
  277. public:
  278. CMyTaskBarIcon() : wxTaskBarIcon()
  279. {
  280. Show(true);
  281. }
  282. void Show(bool fShow=true);
  283. void Hide();
  284. void Restore();
  285. void UpdateTooltip();
  286. virtual wxMenu* CreatePopupMenu();
  287. DECLARE_EVENT_TABLE()
  288. };
  289. #endif