Skip to content

Commit

Permalink
UIThreadCall, ThreadSafeMessageBox
Browse files Browse the repository at this point in the history
  • Loading branch information
non-github-bitcoin committed Nov 6, 2009
1 parent 93cfb02 commit 85c33b9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 1,284 deletions.
2 changes: 2 additions & 0 deletions headers.h
Expand Up @@ -53,6 +53,8 @@
#include <boost/tuple/tuple_comparison.hpp>
#include <boost/tuple/tuple_io.hpp>
#include <boost/array.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>

#ifdef __WXMSW__
#include <windows.h>
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Expand Up @@ -1381,7 +1381,7 @@ bool CheckDiskSpace(int64 nAdditionalBytes)
if (nFreeBytesAvailable < (int64)15000000 + nAdditionalBytes)
{
fShutdown = true;
wxMessageBox("Warning: Your disk space is low ", "Bitcoin", wxICON_EXCLAMATION);
ThreadSafeMessageBox("Warning: Your disk space is low ", "Bitcoin", wxOK | wxICON_EXCLAMATION);
_beginthread(Shutdown, 0, NULL);
return false;
}
Expand Down
68 changes: 36 additions & 32 deletions ui.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}








Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -3305,9 +3312,6 @@ wxMenu* CMyTaskBarIcon::CreatePopupMenu()






//////////////////////////////////////////////////////////////////////////////
//
// CMyApp
Expand Down
22 changes: 4 additions & 18 deletions ui.h
Expand Up @@ -5,19 +5,10 @@



DECLARE_EVENT_TYPE(wxEVT_CROSSTHREADCALL, -1)
DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)
DECLARE_EVENT_TYPE(wxEVT_REPLY1, -1)
DECLARE_EVENT_TYPE(wxEVT_REPLY2, -1)
DECLARE_EVENT_TYPE(wxEVT_REPLY3, -1)
DECLARE_EVENT_TYPE(wxEVT_TABLEADDED, -1)
DECLARE_EVENT_TYPE(wxEVT_TABLEUPDATED, -1)
DECLARE_EVENT_TYPE(wxEVT_TABLEDELETED, -1)

enum
{
UICALL_ADDORDER = 1,
UICALL_UPDATEORDER,
};



Expand All @@ -33,9 +24,10 @@ extern int fMinimizeOnClose;

extern void HandleCtrlA(wxKeyEvent& event);
extern string FormatTxStatus(const CWalletTx& wtx);
extern void CrossThreadCall(int nID, void* pdata);
extern void UIThreadCall(boost::function<void ()>);
extern void MainFrameRepaint();
extern void Shutdown(void* parg);
extern int ThreadSafeMessageBox(const string& message, const string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);



Expand Down Expand Up @@ -85,7 +77,7 @@ class CMainFrame : public CMainFrameBase
unsigned int nListViewUpdated;
bool fRefresh;

void OnCrossThreadCall(wxCommandEvent& event);
void OnUIThreadCall(wxCommandEvent& event);
int GetSortIndex(const string& strSort);
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);
bool DeleteLine(uint256 hashKey);
Expand Down Expand Up @@ -473,9 +465,3 @@ class CMyTaskBarIcon : public wxTaskBarIcon

DECLARE_EVENT_TABLE()
};






160 changes: 0 additions & 160 deletions uibase.cpp
Expand Up @@ -1702,166 +1702,6 @@ CEditReviewDialogBase::~CEditReviewDialogBase()
m_buttonCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CEditReviewDialogBase::OnButtonCancel ), NULL, this );
}

CPokerLobbyDialogBase::CPokerLobbyDialogBase( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );

wxBoxSizer* bSizer156;
bSizer156 = new wxBoxSizer( wxHORIZONTAL );

m_treeCtrl = new wxTreeCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS|wxTR_HIDE_ROOT|wxTR_LINES_AT_ROOT );
m_treeCtrl->SetMinSize( wxSize( 130,-1 ) );

bSizer156->Add( m_treeCtrl, 0, wxEXPAND|wxTOP|wxBOTTOM|wxLEFT, 5 );

wxBoxSizer* bSizer172;
bSizer172 = new wxBoxSizer( wxVERTICAL );

m_listCtrl = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_SORT_HEADER|wxLC_REPORT );
bSizer172->Add( m_listCtrl, 1, wxEXPAND|wxALL, 5 );

m_buttonNewTable = new wxButton( this, wxID_OPENNEWTABLE, wxT("&Open New Table"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer172->Add( m_buttonNewTable, 0, wxALL, 5 );

bSizer156->Add( bSizer172, 1, wxEXPAND, 5 );

this->SetSizer( bSizer156 );
this->Layout();

// Connect Events
m_treeCtrl->Connect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( CPokerLobbyDialogBase::OnTreeSelChanged ), NULL, this );
m_listCtrl->Connect( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler( CPokerLobbyDialogBase::OnListItemActivated ), NULL, this );
m_listCtrl->Connect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( CPokerLobbyDialogBase::OnListItemSelected ), NULL, this );
m_buttonNewTable->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerLobbyDialogBase::OnButtonNewTable ), NULL, this );
}

CPokerLobbyDialogBase::~CPokerLobbyDialogBase()
{
// Disconnect Events
m_treeCtrl->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( CPokerLobbyDialogBase::OnTreeSelChanged ), NULL, this );
m_listCtrl->Disconnect( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler( CPokerLobbyDialogBase::OnListItemActivated ), NULL, this );
m_listCtrl->Disconnect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( CPokerLobbyDialogBase::OnListItemSelected ), NULL, this );
m_buttonNewTable->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerLobbyDialogBase::OnButtonNewTable ), NULL, this );
}

CPokerDialogBase::CPokerDialogBase( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );

wxBoxSizer* bSizer174;
bSizer174 = new wxBoxSizer( wxVERTICAL );

m_checkSitOut = new wxCheckBox( this, wxID_ANY, wxT("Deal Me Out"), wxDefaultPosition, wxDefaultSize, 0 );

bSizer174->Add( m_checkSitOut, 0, wxALL, 5 );

m_buttonDealHand = new wxButton( this, wxID_DEALHAND, wxT("&Deal Hand"), wxDefaultPosition, wxSize( 150,25 ), 0 );
bSizer174->Add( m_buttonDealHand, 0, wxALL, 5 );

m_buttonFold = new wxButton( this, wxID_FOLD, wxT("&Fold"), wxDefaultPosition, wxSize( 80,25 ), 0 );
bSizer174->Add( m_buttonFold, 0, wxALL, 5 );

m_buttonCall = new wxButton( this, wxID_CALL, wxT("&Call"), wxDefaultPosition, wxSize( 80,25 ), 0 );
bSizer174->Add( m_buttonCall, 0, wxALL, 5 );

m_buttonRaise = new wxButton( this, wxID_RAISE, wxT("&Raise"), wxDefaultPosition, wxSize( 80,25 ), 0 );
bSizer174->Add( m_buttonRaise, 0, wxALL, 5 );

m_buttonLeaveTable = new wxButton( this, wxID_LEAVETABLE, wxT("&Leave Table"), wxDefaultPosition, wxSize( 90,25 ), 0 );
bSizer174->Add( m_buttonLeaveTable, 0, wxALL, 5 );

m_textDitchPlayer = new wxTextCtrl( this, wxID_DITCHPLAYER, wxEmptyString, wxDefaultPosition, wxSize( 45,-1 ), wxTE_PROCESS_ENTER );
bSizer174->Add( m_textDitchPlayer, 0, wxALL, 5 );

m_checkPreFold = new wxCheckBox( this, wxID_ANY, wxT("FOLD"), wxDefaultPosition, wxSize( 100,-1 ), 0 );

bSizer174->Add( m_checkPreFold, 0, wxALL, 5 );

m_checkPreCall = new wxCheckBox( this, wxID_ANY, wxT("CALL"), wxDefaultPosition, wxSize( 100,-1 ), 0 );

bSizer174->Add( m_checkPreCall, 0, wxALL, 5 );

m_checkPreCallAny = new wxCheckBox( this, wxID_ANY, wxT("CALL ANY"), wxDefaultPosition, wxSize( 100,-1 ), 0 );

bSizer174->Add( m_checkPreCallAny, 0, wxALL, 5 );

m_checkPreRaise = new wxCheckBox( this, wxID_ANY, wxT("RAISE"), wxDefaultPosition, wxSize( 100,-1 ), 0 );

bSizer174->Add( m_checkPreRaise, 0, wxALL, 5 );

m_checkPreRaiseAny = new wxCheckBox( this, wxID_ANY, wxT("RAISE ANY"), wxDefaultPosition, wxSize( 100,-1 ), 0 );

bSizer174->Add( m_checkPreRaiseAny, 0, wxALL, 5 );

this->SetSizer( bSizer174 );
this->Layout();
m_statusBar = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );

// Connect Events
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( CPokerDialogBase::OnClose ) );
this->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_MOTION, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Connect( wxEVT_PAINT, wxPaintEventHandler( CPokerDialogBase::OnPaint ) );
this->Connect( wxEVT_SIZE, wxSizeEventHandler( CPokerDialogBase::OnSize ) );
m_checkSitOut->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckSitOut ), NULL, this );
m_buttonDealHand->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnButtonDealHand ), NULL, this );
m_buttonFold->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnButtonFold ), NULL, this );
m_buttonCall->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnButtonCall ), NULL, this );
m_buttonRaise->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnButtonRaise ), NULL, this );
m_buttonLeaveTable->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnButtonLeaveTable ), NULL, this );
m_textDitchPlayer->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( CPokerDialogBase::OnDitchPlayer ), NULL, this );
m_checkPreFold->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckPreFold ), NULL, this );
m_checkPreCall->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckPreCall ), NULL, this );
m_checkPreCallAny->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckPreCallAny ), NULL, this );
m_checkPreRaise->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckPreRaise ), NULL, this );
m_checkPreRaiseAny->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckPreRaiseAny ), NULL, this );
}

CPokerDialogBase::~CPokerDialogBase()
{
// Disconnect Events
this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( CPokerDialogBase::OnClose ) );
this->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_MIDDLE_UP, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_MOTION, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( CPokerDialogBase::OnMouseEvents ) );
this->Disconnect( wxEVT_PAINT, wxPaintEventHandler( CPokerDialogBase::OnPaint ) );
this->Disconnect( wxEVT_SIZE, wxSizeEventHandler( CPokerDialogBase::OnSize ) );
m_checkSitOut->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckSitOut ), NULL, this );
m_buttonDealHand->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnButtonDealHand ), NULL, this );
m_buttonFold->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnButtonFold ), NULL, this );
m_buttonCall->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnButtonCall ), NULL, this );
m_buttonRaise->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnButtonRaise ), NULL, this );
m_buttonLeaveTable->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnButtonLeaveTable ), NULL, this );
m_textDitchPlayer->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( CPokerDialogBase::OnDitchPlayer ), NULL, this );
m_checkPreFold->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckPreFold ), NULL, this );
m_checkPreCall->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckPreCall ), NULL, this );
m_checkPreCallAny->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckPreCallAny ), NULL, this );
m_checkPreRaise->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckPreRaise ), NULL, this );
m_checkPreRaiseAny->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( CPokerDialogBase::OnCheckPreRaiseAny ), NULL, this );
}

CGetTextFromUserDialogBase::CGetTextFromUserDialogBase( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
Expand Down

0 comments on commit 85c33b9

Please sign in to comment.