aboutsummaryrefslogtreecommitdiff
path: root/ui.cpp
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2009-11-06 18:53:26 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2009-11-06 18:53:26 +0000
commit8acda009d921a65dab87bd0a40f63981a1586561 (patch)
treea0ecc03e12f81439243bc537e565502ab5af3ba1 /ui.cpp
parent300d4608f2504e3e4a02a13b6c6000b52c436975 (diff)
UIThreadCall, ThreadSafeMessageBox
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@34 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'ui.cpp')
-rw-r--r--ui.cpp68
1 files changed, 36 insertions, 32 deletions
diff --git a/ui.cpp b/ui.cpp
index 92e1d59ce6..d330231341 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -14,13 +14,10 @@ void SetStartOnSystemStartup(bool fAutoStart);
-DEFINE_EVENT_TYPE(wxEVT_CROSSTHREADCALL)
+DEFINE_EVENT_TYPE(wxEVT_UITHREADCALL)
DEFINE_EVENT_TYPE(wxEVT_REPLY1)
DEFINE_EVENT_TYPE(wxEVT_REPLY2)
DEFINE_EVENT_TYPE(wxEVT_REPLY3)
-DEFINE_EVENT_TYPE(wxEVT_TABLEADDED)
-DEFINE_EVENT_TYPE(wxEVT_TABLEUPDATED)
-DEFINE_EVENT_TYPE(wxEVT_TABLEDELETED)
CMainFrame* pframeMain = NULL;
CMyTaskBarIcon* ptaskbaricon = NULL;
@@ -184,6 +181,24 @@ void AddToMyProducts(CProduct product)
"");
}
+void StringMessageBox(const string& message, const string& caption, int style, wxWindow* parent, int x, int y)
+{
+ wxMessageBox(message, caption, style, parent, x, y);
+}
+
+int ThreadSafeMessageBox(const string& message, const string& caption, int style, wxWindow* parent, int x, int y)
+{
+#ifdef __WXMSW__
+ wxMessageBox(message, caption, style, parent, x, y);
+#else
+ UIThreadCall(bind(StringMessageBox, message, caption, style, parent, x, y));
+#endif
+}
+
+
+
+
+
@@ -193,6 +208,7 @@ void AddToMyProducts(CProduct product)
//
// Custom events
//
+// If this code gets used again, it should be replaced with something like UIThreadCall
set<void*> setCallbackAvailable;
CCriticalSection cs_setCallbackAvailable;
@@ -279,7 +295,7 @@ CDataStream GetStreamFromEvent(const wxCommandEvent& event)
CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent)
{
- Connect(wxEVT_CROSSTHREADCALL, wxCommandEventHandler(CMainFrame::OnCrossThreadCall), NULL, this);
+ Connect(wxEVT_UITHREADCALL, wxCommandEventHandler(CMainFrame::OnUIThreadCall), NULL, this);
// Init
fRefreshListCtrl = false;
@@ -982,36 +998,27 @@ void CMainFrame::OnPaintListCtrl(wxPaintEvent& event)
}
-void CrossThreadCall(wxCommandEvent& event)
+void UIThreadCall(boost::function<void ()> fn)
{
+ // Call this with a function object created with bind.
+ // bind needs all parameters to match the function's expected types
+ // and all default parameters specified. Some examples:
+ // UIThreadCall(bind(wxBell));
+ // UIThreadCall(bind(wxMessageBox, wxT("Message"), wxT("Title"), wxOK, (wxWindow*)NULL, -1, -1));
+ // UIThreadCall(bind(&CMainFrame::OnMenuHelpAbout, pframeMain, event));
if (pframeMain)
+ {
+ wxCommandEvent event(wxEVT_UITHREADCALL);
+ event.SetClientData((void*)new boost::function<void ()>(fn));
pframeMain->GetEventHandler()->AddPendingEvent(event);
+ }
}
-void CrossThreadCall(int nID, void* pdata)
-{
- wxCommandEvent event;
- event.SetInt(nID);
- event.SetClientData(pdata);
- if (pframeMain)
- pframeMain->GetEventHandler()->AddPendingEvent(event);
-}
-
-void CMainFrame::OnCrossThreadCall(wxCommandEvent& event)
+void CMainFrame::OnUIThreadCall(wxCommandEvent& event)
{
- void* pdata = event.GetClientData();
- switch (event.GetInt())
- {
- case UICALL_ADDORDER:
- {
- break;
- }
-
- case UICALL_UPDATEORDER:
- {
- break;
- }
- }
+ boost::function<void ()>* pfn = (boost::function<void ()>*)event.GetClientData();
+ (*pfn)();
+ delete pfn;
}
void CMainFrame::OnMenuFileExit(wxCommandEvent& event)
@@ -3305,9 +3312,6 @@ wxMenu* CMyTaskBarIcon::CreatePopupMenu()
-
-
-
//////////////////////////////////////////////////////////////////////////////
//
// CMyApp