Merge remote branch 'refs/remotes/svn/trunk' into svn
[bitcoinplatinum.git] / ui.h
blob9769fd700defc73fbdf8efa98b1633ec7205bc31
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.
5 DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)
9 extern wxLocale g_locale;
13 void HandleCtrlA(wxKeyEvent& event);
14 string FormatTxStatus(const CWalletTx& wtx);
15 void UIThreadCall(boost::function0<void>);
16 int ThreadSafeMessageBox(const string& message, const string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);
17 bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent);
18 void CalledSetStatusBar(const string& strText, int nField);
19 void MainFrameRepaint();
20 void CreateMainWindow();
21 void SetStartOnSystemStartup(bool fAutoStart);
26 inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)
28 #ifdef GUI
29 if (!fDaemon)
30 return wxMessageBox(message, caption, style, parent, x, y);
31 #endif
32 printf("wxMessageBox %s: %s\n", string(caption).c_str(), string(message).c_str());
33 fprintf(stderr, "%s: %s\n", string(caption).c_str(), string(message).c_str());
34 return wxOK;
36 #define wxMessageBox MyMessageBox
43 class CMainFrame : public CMainFrameBase
45 protected:
46 // Event handlers
47 void OnNotebookPageChanged(wxNotebookEvent& event);
48 void OnClose(wxCloseEvent& event);
49 void OnIconize(wxIconizeEvent& event);
50 void OnMouseEvents(wxMouseEvent& event);
51 void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
52 void OnIdle(wxIdleEvent& event);
53 void OnPaint(wxPaintEvent& event);
54 void OnPaintListCtrl(wxPaintEvent& event);
55 void OnMenuFileExit(wxCommandEvent& event);
56 void OnMenuOptionsGenerate(wxCommandEvent& event);
57 void OnUpdateUIOptionsGenerate(wxUpdateUIEvent& event);
58 void OnMenuOptionsChangeYourAddress(wxCommandEvent& event);
59 void OnMenuOptionsOptions(wxCommandEvent& event);
60 void OnMenuHelpAbout(wxCommandEvent& event);
61 void OnButtonSend(wxCommandEvent& event);
62 void OnButtonAddressBook(wxCommandEvent& event);
63 void OnSetFocusAddress(wxFocusEvent& event);
64 void OnMouseEventsAddress(wxMouseEvent& event);
65 void OnButtonNew(wxCommandEvent& event);
66 void OnButtonCopy(wxCommandEvent& event);
67 void OnListColBeginDrag(wxListEvent& event);
68 void OnListItemActivated(wxListEvent& event);
69 void OnListItemActivatedProductsSent(wxListEvent& event);
70 void OnListItemActivatedOrdersSent(wxListEvent& event);
71 void OnListItemActivatedOrdersReceived(wxListEvent& event);
73 public:
74 /** Constructor */
75 CMainFrame(wxWindow* parent);
76 ~CMainFrame();
78 // Custom
79 enum
81 ALL = 0,
82 SENTRECEIVED = 1,
83 SENT = 2,
84 RECEIVED = 3,
86 int nPage;
87 wxListCtrl* m_listCtrl;
88 bool fShowGenerated;
89 bool fShowSent;
90 bool fShowReceived;
91 bool fRefreshListCtrl;
92 bool fRefreshListCtrlRunning;
93 bool fOnSetFocusAddress;
94 unsigned int nListViewUpdated;
95 bool fRefresh;
97 void OnUIThreadCall(wxCommandEvent& event);
98 int GetSortIndex(const string& strSort);
99 void InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSort, const wxString& str1, const wxString& str2, const wxString& str3, const wxString& str4, const wxString& str5);
100 bool DeleteLine(uint256 hashKey);
101 bool InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex=-1);
102 void RefreshListCtrl();
103 void RefreshStatusColumn();
109 class CTxDetailsDialog : public CTxDetailsDialogBase
111 protected:
112 // Event handlers
113 void OnButtonOK(wxCommandEvent& event);
115 public:
116 /** Constructor */
117 CTxDetailsDialog(wxWindow* parent, CWalletTx wtx);
119 // State
120 CWalletTx wtx;
125 class COptionsDialog : public COptionsDialogBase
127 protected:
128 // Event handlers
129 void OnListBox(wxCommandEvent& event);
130 void OnKillFocusTransactionFee(wxFocusEvent& event);
131 void OnCheckBoxLimitProcessors(wxCommandEvent& event);
132 void OnCheckBoxUseProxy(wxCommandEvent& event);
133 void OnKillFocusProxy(wxFocusEvent& event);
135 void OnButtonOK(wxCommandEvent& event);
136 void OnButtonCancel(wxCommandEvent& event);
137 void OnButtonApply(wxCommandEvent& event);
139 public:
140 /** Constructor */
141 COptionsDialog(wxWindow* parent);
143 // Custom
144 bool fTmpStartOnSystemStartup;
145 bool fTmpMinimizeOnClose;
146 void SelectPage(int nPage);
147 CAddress GetProxyAddr();
152 class CAboutDialog : public CAboutDialogBase
154 protected:
155 // Event handlers
156 void OnButtonOK(wxCommandEvent& event);
158 public:
159 /** Constructor */
160 CAboutDialog(wxWindow* parent);
165 class CSendDialog : public CSendDialogBase
167 protected:
168 // Event handlers
169 void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }
170 void OnTextAddress(wxCommandEvent& event);
171 void OnKillFocusAmount(wxFocusEvent& event);
172 void OnButtonAddressBook(wxCommandEvent& event);
173 void OnButtonPaste(wxCommandEvent& event);
174 void OnButtonSend(wxCommandEvent& event);
175 void OnButtonCancel(wxCommandEvent& event);
177 public:
178 /** Constructor */
179 CSendDialog(wxWindow* parent, const wxString& strAddress="");
181 // Custom
182 bool fEnabledPrev;
183 string strFromSave;
184 string strMessageSave;
189 class CSendingDialog : public CSendingDialogBase
191 public:
192 // Event handlers
193 void OnClose(wxCloseEvent& event);
194 void OnButtonOK(wxCommandEvent& event);
195 void OnButtonCancel(wxCommandEvent& event);
196 void OnPaint(wxPaintEvent& event);
198 public:
199 /** Constructor */
200 CSendingDialog(wxWindow* parent, const CAddress& addrIn, int64 nPriceIn, const CWalletTx& wtxIn);
201 ~CSendingDialog();
203 // State
204 CAddress addr;
205 int64 nPrice;
206 CWalletTx wtx;
207 wxDateTime start;
208 char pszStatus[10000];
209 bool fCanCancel;
210 bool fAbort;
211 bool fSuccess;
212 bool fUIDone;
213 bool fWorkDone;
215 void Close();
216 void Repaint();
217 bool Status();
218 bool Status(const string& str);
219 bool Error(const string& str);
220 void StartTransfer();
221 void OnReply2(CDataStream& vRecv);
222 void OnReply3(CDataStream& vRecv);
225 void SendingDialogStartTransfer(void* parg);
226 void SendingDialogOnReply2(void* parg, CDataStream& vRecv);
227 void SendingDialogOnReply3(void* parg, CDataStream& vRecv);
231 class CAddressBookDialog : public CAddressBookDialogBase
233 protected:
234 // Event handlers
235 void OnNotebookPageChanged(wxNotebookEvent& event);
236 void OnListEndLabelEdit(wxListEvent& event);
237 void OnListItemSelected(wxListEvent& event);
238 void OnListItemActivated(wxListEvent& event);
239 void OnButtonDelete(wxCommandEvent& event);
240 void OnButtonCopy(wxCommandEvent& event);
241 void OnButtonEdit(wxCommandEvent& event);
242 void OnButtonNew(wxCommandEvent& event);
243 void OnButtonOK(wxCommandEvent& event);
244 void OnButtonCancel(wxCommandEvent& event);
245 void OnClose(wxCloseEvent& event);
247 public:
248 /** Constructor */
249 CAddressBookDialog(wxWindow* parent, const wxString& strInitSelected, int nPageIn, bool fDuringSendIn);
251 // Custom
252 enum
254 SENDING = 0,
255 RECEIVING = 1,
257 int nPage;
258 wxListCtrl* m_listCtrl;
259 bool fDuringSend;
260 wxString GetAddress();
261 wxString GetSelectedAddress();
262 wxString GetSelectedSendingAddress();
263 wxString GetSelectedReceivingAddress();
264 bool CheckIfMine(const string& strAddress, const string& strTitle);
269 class CGetTextFromUserDialog : public CGetTextFromUserDialogBase
271 protected:
272 // Event handlers
273 void OnButtonOK(wxCommandEvent& event) { EndModal(true); }
274 void OnButtonCancel(wxCommandEvent& event) { EndModal(false); }
275 void OnClose(wxCloseEvent& event) { EndModal(false); }
277 void OnKeyDown(wxKeyEvent& event)
279 if (event.GetKeyCode() == '\r' || event.GetKeyCode() == WXK_NUMPAD_ENTER)
280 EndModal(true);
281 else
282 HandleCtrlA(event);
285 public:
286 /** Constructor */
287 CGetTextFromUserDialog(wxWindow* parent,
288 const string& strCaption,
289 const string& strMessage1,
290 const string& strValue1="",
291 const string& strMessage2="",
292 const string& strValue2="") : CGetTextFromUserDialogBase(parent, wxID_ANY, strCaption)
294 int x = GetSize().GetWidth();
295 int y = GetSize().GetHeight();
296 m_staticTextMessage1->SetLabel(strMessage1);
297 m_textCtrl1->SetValue(strValue1);
298 y += wxString(strMessage1).Freq('\n') * 14;
299 if (!strMessage2.empty())
301 m_staticTextMessage2->Show(true);
302 m_staticTextMessage2->SetLabel(strMessage2);
303 m_textCtrl2->Show(true);
304 m_textCtrl2->SetValue(strValue2);
305 y += 46 + wxString(strMessage2).Freq('\n') * 14;
307 #ifndef __WXMSW__
308 x = x * 114 / 100;
309 y = y * 114 / 100;
310 #endif
311 SetSize(x, y);
314 // Custom
315 string GetValue() { return (string)m_textCtrl1->GetValue(); }
316 string GetValue1() { return (string)m_textCtrl1->GetValue(); }
317 string GetValue2() { return (string)m_textCtrl2->GetValue(); }
322 class CMyTaskBarIcon : public wxTaskBarIcon
324 protected:
325 // Event handlers
326 void OnLeftButtonDClick(wxTaskBarIconEvent& event);
327 void OnMenuRestore(wxCommandEvent& event);
328 void OnMenuOptions(wxCommandEvent& event);
329 void OnUpdateUIGenerate(wxUpdateUIEvent& event);
330 void OnMenuGenerate(wxCommandEvent& event);
331 void OnMenuExit(wxCommandEvent& event);
333 public:
334 CMyTaskBarIcon() : wxTaskBarIcon()
336 Show(true);
339 void Show(bool fShow=true);
340 void Hide();
341 void Restore();
342 void UpdateTooltip();
343 virtual wxMenu* CreatePopupMenu();
345 DECLARE_EVENT_TABLE()