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