Bitcoin v0.3.0 · 2010-07-06
ui.h
1// Copyright (c) 2009-2010 Satoshi Nakamoto2// Distributed under the MIT/X11 software license, see the accompanying3// file license.txt or http://www.opensource.org/licenses/mit-license.php.45DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)67#if wxUSE_GUI8static const bool fGUI=true;9#else10static const bool fGUI=false;11#endif1213inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)14{15#if wxUSE_GUI16 if (!fDaemon)17 return wxMessageBox(message, caption, style, parent, x, y);18#endif19 printf("wxMessageBox %s: %s\n", string(caption).c_str(), string(message).c_str());20 fprintf(stderr, "%s: %s\n", string(caption).c_str(), string(message).c_str());21 return wxOK;22}23#define wxMessageBox MyMessageBox2425262728void HandleCtrlA(wxKeyEvent& event);29string FormatTxStatus(const CWalletTx& wtx);30void UIThreadCall(boost::function0<void>);31int ThreadSafeMessageBox(const string& message, const string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);32bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent);33void CalledSetStatusBar(const string& strText, int nField);34void MainFrameRepaint();35void CreateMainWindow();363738394041#if !wxUSE_GUI42inline int ThreadSafeMessageBox(const string& message, const string& caption, int style, wxWindow* parent, int x, int y)43{44 return MyMessageBox(message, caption, style, parent, x, y);45}4647inline bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent)48{49 return true;50}5152inline void CalledSetStatusBar(const string& strText, int nField)53{54}5556inline void UIThreadCall(boost::function0<void> fn)57{58}5960inline void MainFrameRepaint()61{62}6364inline void CreateMainWindow()65{66}67#else // wxUSE_GUI686970717273class CMainFrame : public CMainFrameBase74{75protected:76 // Event handlers77 void OnNotebookPageChanged(wxNotebookEvent& event);78 void OnClose(wxCloseEvent& event);79 void OnIconize(wxIconizeEvent& event);80 void OnMouseEvents(wxMouseEvent& event);81 void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }82 void OnIdle(wxIdleEvent& event);83 void OnPaint(wxPaintEvent& event);84 void OnPaintListCtrl(wxPaintEvent& event);85 void OnMenuFileExit(wxCommandEvent& event);86 void OnMenuOptionsGenerate(wxCommandEvent& event);87 void OnUpdateUIOptionsGenerate(wxUpdateUIEvent& event);88 void OnMenuOptionsChangeYourAddress(wxCommandEvent& event);89 void OnMenuOptionsOptions(wxCommandEvent& event);90 void OnMenuHelpAbout(wxCommandEvent& event);91 void OnButtonSend(wxCommandEvent& event);92 void OnButtonAddressBook(wxCommandEvent& event);93 void OnSetFocusAddress(wxFocusEvent& event);94 void OnMouseEventsAddress(wxMouseEvent& event);95 void OnButtonNew(wxCommandEvent& event);96 void OnButtonCopy(wxCommandEvent& event);97 void OnListColBeginDrag(wxListEvent& event);98 void OnListItemActivated(wxListEvent& event);99 void OnListItemActivatedProductsSent(wxListEvent& event);100 void OnListItemActivatedOrdersSent(wxListEvent& event);101 void OnListItemActivatedOrdersReceived(wxListEvent& event);102 103public:104 /** Constructor */105 CMainFrame(wxWindow* parent);106 ~CMainFrame();107108 // Custom109 enum110 {111 ALL = 0,112 SENTRECEIVED = 1,113 SENT = 2,114 RECEIVED = 3,115 };116 int nPage;117 wxListCtrl* m_listCtrl;118 bool fShowGenerated;119 bool fShowSent;120 bool fShowReceived;121 bool fRefreshListCtrl;122 bool fRefreshListCtrlRunning;123 bool fOnSetFocusAddress;124 unsigned int nListViewUpdated;125 bool fRefresh;126127 void OnUIThreadCall(wxCommandEvent& event);128 int GetSortIndex(const string& strSort);129 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);130 bool DeleteLine(uint256 hashKey);131 bool InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex=-1);132 void RefreshListCtrl();133 void RefreshStatusColumn();134};135136137138139class CTxDetailsDialog : public CTxDetailsDialogBase140{141protected:142 // Event handlers143 void OnButtonOK(wxCommandEvent& event);144145public:146 /** Constructor */147 CTxDetailsDialog(wxWindow* parent, CWalletTx wtx);148149 // State150 CWalletTx wtx;151};152153154155class COptionsDialog : public COptionsDialogBase156{157protected:158 // Event handlers159 void OnListBox(wxCommandEvent& event);160 void OnKillFocusTransactionFee(wxFocusEvent& event);161 void OnCheckBoxLimitProcessors(wxCommandEvent& event);162 void OnCheckBoxUseProxy(wxCommandEvent& event);163 void OnKillFocusProxy(wxFocusEvent& event);164165 void OnButtonOK(wxCommandEvent& event);166 void OnButtonCancel(wxCommandEvent& event);167 void OnButtonApply(wxCommandEvent& event);168169public:170 /** Constructor */171 COptionsDialog(wxWindow* parent);172173 // Custom174 bool fTmpStartOnSystemStartup;175 bool fTmpMinimizeOnClose;176 void SelectPage(int nPage);177 CAddress GetProxyAddr();178};179180181182class CAboutDialog : public CAboutDialogBase183{184protected:185 // Event handlers186 void OnButtonOK(wxCommandEvent& event);187188public:189 /** Constructor */190 CAboutDialog(wxWindow* parent);191};192193194195class CSendDialog : public CSendDialogBase196{197protected:198 // Event handlers199 void OnKeyDown(wxKeyEvent& event) { HandleCtrlA(event); }200 void OnTextAddress(wxCommandEvent& event);201 void OnKillFocusAmount(wxFocusEvent& event);202 void OnButtonAddressBook(wxCommandEvent& event);203 void OnButtonPaste(wxCommandEvent& event);204 void OnButtonSend(wxCommandEvent& event);205 void OnButtonCancel(wxCommandEvent& event);206 207public:208 /** Constructor */209 CSendDialog(wxWindow* parent, const wxString& strAddress="");210211 // Custom212 bool fEnabledPrev;213 string strFromSave;214 string strMessageSave;215};216217218219class CSendingDialog : public CSendingDialogBase220{221public:222 // Event handlers223 void OnClose(wxCloseEvent& event);224 void OnButtonOK(wxCommandEvent& event);225 void OnButtonCancel(wxCommandEvent& event);226 void OnPaint(wxPaintEvent& event);227 228public:229 /** Constructor */230 CSendingDialog(wxWindow* parent, const CAddress& addrIn, int64 nPriceIn, const CWalletTx& wtxIn);231 ~CSendingDialog();232233 // State234 CAddress addr;235 int64 nPrice;236 CWalletTx wtx;237 wxDateTime start;238 char pszStatus[10000];239 bool fCanCancel;240 bool fAbort;241 bool fSuccess;242 bool fUIDone;243 bool fWorkDone;244245 void Close();246 void Repaint();247 bool Status();248 bool Status(const string& str);249 bool Error(const string& str);250 void StartTransfer();251 void OnReply2(CDataStream& vRecv);252 void OnReply3(CDataStream& vRecv);253};254255void SendingDialogStartTransfer(void* parg);256void SendingDialogOnReply2(void* parg, CDataStream& vRecv);257void SendingDialogOnReply3(void* parg, CDataStream& vRecv);258259260261class CAddressBookDialog : public CAddressBookDialogBase262{263protected:264 // Event handlers265 void OnNotebookPageChanged(wxNotebookEvent& event);266 void OnListEndLabelEdit(wxListEvent& event);267 void OnListItemSelected(wxListEvent& event);268 void OnListItemActivated(wxListEvent& event);269 void OnButtonDelete(wxCommandEvent& event);270 void OnButtonCopy(wxCommandEvent& event);271 void OnButtonEdit(wxCommandEvent& event);272 void OnButtonNew(wxCommandEvent& event);273 void OnButtonOK(wxCommandEvent& event);274 void OnButtonCancel(wxCommandEvent& event);275 void OnClose(wxCloseEvent& event);276277public:278 /** Constructor */279 CAddressBookDialog(wxWindow* parent, const wxString& strInitSelected, int nPageIn, bool fDuringSendIn);280281 // Custom282 enum283 {284 SENDING = 0,285 RECEIVING = 1,286 };287 int nPage;288 wxListCtrl* m_listCtrl;289 bool fDuringSend;290 wxString GetAddress();291 wxString GetSelectedAddress();292 wxString GetSelectedSendingAddress();293 wxString GetSelectedReceivingAddress();294 bool CheckIfMine(const string& strAddress, const string& strTitle);295};296297298299class CGetTextFromUserDialog : public CGetTextFromUserDialogBase300{301protected:302 // Event handlers303 void OnButtonOK(wxCommandEvent& event) { EndModal(true); }304 void OnButtonCancel(wxCommandEvent& event) { EndModal(false); }305 void OnClose(wxCloseEvent& event) { EndModal(false); }306307 void OnKeyDown(wxKeyEvent& event)308 {309 if (event.GetKeyCode() == '\r' || event.GetKeyCode() == WXK_NUMPAD_ENTER)310 EndModal(true);311 else312 HandleCtrlA(event);313 }314315public:316 /** Constructor */317 CGetTextFromUserDialog(wxWindow* parent,318 const string& strCaption,319 const string& strMessage1,320 const string& strValue1="",321 const string& strMessage2="",322 const string& strValue2="") : CGetTextFromUserDialogBase(parent, wxID_ANY, strCaption)323 {324 int x = GetSize().GetWidth();325 int y = GetSize().GetHeight();326 m_staticTextMessage1->SetLabel(strMessage1);327 m_textCtrl1->SetValue(strValue1);328 y += wxString(strMessage1).Freq('\n') * 14;329 if (!strMessage2.empty())330 {331 m_staticTextMessage2->Show(true);332 m_staticTextMessage2->SetLabel(strMessage2);333 m_textCtrl2->Show(true);334 m_textCtrl2->SetValue(strValue2);335 y += 46 + wxString(strMessage2).Freq('\n') * 14;336 }337 if (!fWindows)338 {339 x *= 1.14;340 y *= 1.14;341 }342 SetSize(x, y);343 }344345 // Custom346 string GetValue() { return (string)m_textCtrl1->GetValue(); }347 string GetValue1() { return (string)m_textCtrl1->GetValue(); }348 string GetValue2() { return (string)m_textCtrl2->GetValue(); }349};350351352353class CMyTaskBarIcon : public wxTaskBarIcon354{355protected:356 // Event handlers357 void OnLeftButtonDClick(wxTaskBarIconEvent& event);358 void OnMenuRestore(wxCommandEvent& event);359 void OnMenuOptions(wxCommandEvent& event);360 void OnUpdateUIGenerate(wxUpdateUIEvent& event);361 void OnMenuGenerate(wxCommandEvent& event);362 void OnMenuExit(wxCommandEvent& event);363364public:365 CMyTaskBarIcon() : wxTaskBarIcon()366 {367 Show(true);368 }369370 void Show(bool fShow=true);371 void Hide();372 void Restore();373 void UpdateTooltip();374 virtual wxMenu* CreatePopupMenu();375376DECLARE_EVENT_TABLE()377};378379#endif // wxUSE_GUI
Click a line number to link to it; use #L10-L20 for a range. "=" next to a version means the file is identical there.
