make bitcoin include files more modular
[novacoin.git] / src / ui.cpp
index 2277da6..6e28435 100644 (file)
@@ -7,6 +7,8 @@
 #include <crtdbg.h>
 #endif
 
+using namespace std;
+using namespace boost;
 
 
 DEFINE_EVENT_TYPE(wxEVT_UITHREADCALL)
@@ -196,7 +198,7 @@ int ThreadSafeMessageBox(const string& message, const string& caption, int style
 
 bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent)
 {
-    if (nFeeRequired < CENT || nFeeRequired <= nTransactionFee || fDaemon)
+    if (nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
         return true;
     string strMessage = strprintf(
         _("This transaction is over the size limit.  You can still send it for a fee of %s, "
@@ -294,7 +296,7 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent)
     dResize -= 0.01;
 #endif
     wxListCtrl* pplistCtrl[] = {m_listCtrlAll, m_listCtrlSentReceived, m_listCtrlSent, m_listCtrlReceived};
-    foreach(wxListCtrl* p, pplistCtrl)
+    BOOST_FOREACH(wxListCtrl* p, pplistCtrl)
     {
         p->InsertColumn(0, "",               wxLIST_FORMAT_LEFT,  dResize * 0);
         p->InsertColumn(1, "",               wxLIST_FORMAT_LEFT,  dResize * 0);
@@ -528,7 +530,7 @@ string SingleLine(const string& strIn)
 {
     string strOut;
     bool fOneSpace = false;
-    foreach(unsigned char c, strIn)
+    BOOST_FOREACH(unsigned char c, strIn)
     {
         if (isspace(c))
         {
@@ -609,7 +611,7 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
             if (nCredit == 0)
             {
                 int64 nUnmatured = 0;
-                foreach(const CTxOut& txout, wtx.vout)
+                BOOST_FOREACH(const CTxOut& txout, wtx.vout)
                     nUnmatured += txout.GetCredit();
                 if (wtx.IsInMainChain())
                 {
@@ -644,7 +646,7 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
             // Received by Bitcoin Address
             if (!fShowReceived)
                 return false;
-            foreach(const CTxOut& txout, wtx.vout)
+            BOOST_FOREACH(const CTxOut& txout, wtx.vout)
             {
                 if (txout.IsMine())
                 {
@@ -687,11 +689,11 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
     else
     {
         bool fAllFromMe = true;
-        foreach(const CTxIn& txin, wtx.vin)
+        BOOST_FOREACH(const CTxIn& txin, wtx.vin)
             fAllFromMe = fAllFromMe && txin.IsMine();
 
         bool fAllToMe = true;
-        foreach(const CTxOut& txout, wtx.vout)
+        BOOST_FOREACH(const CTxOut& txout, wtx.vout)
             fAllToMe = fAllToMe && txout.IsMine();
 
         if (fAllFromMe && fAllToMe)
@@ -776,9 +778,9 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
             // Mixed debit transaction, can't break down payees
             //
             bool fAllMine = true;
-            foreach(const CTxOut& txout, wtx.vout)
+            BOOST_FOREACH(const CTxOut& txout, wtx.vout)
                 fAllMine = fAllMine && txout.IsMine();
-            foreach(const CTxIn& txin, wtx.vin)
+            BOOST_FOREACH(const CTxIn& txin, wtx.vin)
                 fAllMine = fAllMine && txin.IsMine();
 
             InsertLine(fNew, nIndex, hash, strSort, colour,
@@ -1006,7 +1008,7 @@ void CMainFrame::OnPaintListCtrl(wxPaintEvent& event)
                 string strTop;
                 if (m_listCtrl->GetItemCount())
                     strTop = (string)m_listCtrl->GetItemText(0);
-                foreach(uint256 hash, vWalletUpdated)
+                BOOST_FOREACH(uint256 hash, vWalletUpdated)
                 {
                     map<uint256, CWalletTx>::iterator mi = mapWallet.find(hash);
                     if (mi != mapWallet.end())
@@ -1094,12 +1096,6 @@ void CMainFrame::OnMenuFileExit(wxCommandEvent& event)
     Close(true);
 }
 
-void CMainFrame::OnMenuOptionsGenerate(wxCommandEvent& event)
-{
-    // Options->Generate Coins
-    GenerateBitcoins(event.IsChecked());
-}
-
 void CMainFrame::OnUpdateUIOptionsGenerate(wxUpdateUIEvent& event)
 {
     event.Check(fGenerateBitcoins);
@@ -1271,7 +1267,7 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
             if (nNet > 0)
             {
                 // Credit
-                foreach(const CTxOut& txout, wtx.vout)
+                BOOST_FOREACH(const CTxOut& txout, wtx.vout)
                 {
                     if (txout.IsMine())
                     {
@@ -1322,7 +1318,7 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
             // Coinbase
             //
             int64 nUnmatured = 0;
-            foreach(const CTxOut& txout, wtx.vout)
+            BOOST_FOREACH(const CTxOut& txout, wtx.vout)
                 nUnmatured += txout.GetCredit();
             strHTML += _("<b>Credit:</b> ");
             if (wtx.IsInMainChain())
@@ -1341,11 +1337,11 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
         else
         {
             bool fAllFromMe = true;
-            foreach(const CTxIn& txin, wtx.vin)
+            BOOST_FOREACH(const CTxIn& txin, wtx.vin)
                 fAllFromMe = fAllFromMe && txin.IsMine();
 
             bool fAllToMe = true;
-            foreach(const CTxOut& txout, wtx.vout)
+            BOOST_FOREACH(const CTxOut& txout, wtx.vout)
                 fAllToMe = fAllToMe && txout.IsMine();
 
             if (fAllFromMe)
@@ -1353,7 +1349,7 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
                 //
                 // Debit
                 //
-                foreach(const CTxOut& txout, wtx.vout)
+                BOOST_FOREACH(const CTxOut& txout, wtx.vout)
                 {
                     if (txout.IsMine())
                         continue;
@@ -1394,10 +1390,10 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
                 //
                 // Mixed debit transaction
                 //
-                foreach(const CTxIn& txin, wtx.vin)
+                BOOST_FOREACH(const CTxIn& txin, wtx.vin)
                     if (txin.IsMine())
                         strHTML += _("<b>Debit:</b> ") + FormatMoney(-txin.GetDebit()) + "<br>";
-                foreach(const CTxOut& txout, wtx.vout)
+                BOOST_FOREACH(const CTxOut& txout, wtx.vout)
                     if (txout.IsMine())
                         strHTML += _("<b>Credit:</b> ") + FormatMoney(txout.GetCredit()) + "<br>";
             }
@@ -1424,10 +1420,10 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
         if (fDebug)
         {
             strHTML += "<hr><br>debug print<br><br>";
-            foreach(const CTxIn& txin, wtx.vin)
+            BOOST_FOREACH(const CTxIn& txin, wtx.vin)
                 if (txin.IsMine())
                     strHTML += "<b>Debit:</b> " + FormatMoney(-txin.GetDebit()) + "<br>";
-            foreach(const CTxOut& txout, wtx.vout)
+            BOOST_FOREACH(const CTxOut& txout, wtx.vout)
                 if (txout.IsMine())
                     strHTML += "<b>Credit:</b> " + FormatMoney(txout.GetCredit()) + "<br>";
 
@@ -1437,7 +1433,7 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
             strHTML += "<br><b>Inputs:</b><br>";
             CRITICAL_BLOCK(cs_mapWallet)
             {
-                foreach(const CTxIn& txin, wtx.vin)
+                BOOST_FOREACH(const CTxIn& txin, wtx.vin)
                 {
                     COutPoint prevout = txin.prevout;
                     map<uint256, CWalletTx>::iterator mi = mapWallet.find(prevout.hash);
@@ -1655,13 +1651,6 @@ COptionsDialog::COptionsDialog(wxWindow* parent) : COptionsDialogBase(parent)
 
     // Init values
     m_textCtrlTransactionFee->SetValue(FormatMoney(nTransactionFee));
-    m_checkBoxLimitProcessors->SetValue(fLimitProcessors);
-    m_spinCtrlLimitProcessors->Enable(fLimitProcessors);
-    m_spinCtrlLimitProcessors->SetValue(nLimitProcessors);
-    int nProcessors = wxThread::GetCPUCount();
-    if (nProcessors < 1)
-        nProcessors = 999;
-    m_spinCtrlLimitProcessors->SetRange(1, nProcessors);
     m_checkBoxStartOnSystemStartup->SetValue(fTmpStartOnSystemStartup = GetStartOnSystemStartup());
     m_checkBoxMinimizeToTray->SetValue(fMinimizeToTray);
     m_checkBoxMinimizeOnClose->SetValue(fMinimizeOnClose);
@@ -1702,11 +1691,6 @@ void COptionsDialog::OnKillFocusTransactionFee(wxFocusEvent& event)
     m_textCtrlTransactionFee->SetValue(FormatMoney(nTmp));
 }
 
-void COptionsDialog::OnCheckBoxLimitProcessors(wxCommandEvent& event)
-{
-    m_spinCtrlLimitProcessors->Enable(event.IsChecked());
-}
-
 void COptionsDialog::OnCheckBoxUseProxy(wxCommandEvent& event)
 {
     m_textCtrlProxyIP->Enable(event.IsChecked());
@@ -1755,20 +1739,6 @@ void COptionsDialog::OnButtonApply(wxCommandEvent& event)
     if (ParseMoney(m_textCtrlTransactionFee->GetValue(), nTransactionFee) && nTransactionFee != nPrevTransactionFee)
         walletdb.WriteSetting("nTransactionFee", nTransactionFee);
 
-    int nPrevMaxProc = (fLimitProcessors ? nLimitProcessors : INT_MAX);
-    if (fLimitProcessors != m_checkBoxLimitProcessors->GetValue())
-    {
-        fLimitProcessors = m_checkBoxLimitProcessors->GetValue();
-        walletdb.WriteSetting("fLimitProcessors", fLimitProcessors);
-    }
-    if (nLimitProcessors != m_spinCtrlLimitProcessors->GetValue())
-    {
-        nLimitProcessors = m_spinCtrlLimitProcessors->GetValue();
-        walletdb.WriteSetting("nLimitProcessors", nLimitProcessors);
-    }
-    if (fGenerateBitcoins && (fLimitProcessors ? nLimitProcessors : INT_MAX) > nPrevMaxProc)
-        GenerateBitcoins(fGenerateBitcoins);
-
     if (fTmpStartOnSystemStartup != m_checkBoxStartOnSystemStartup->GetValue())
     {
         fTmpStartOnSystemStartup = m_checkBoxStartOnSystemStartup->GetValue();
@@ -1859,6 +1829,7 @@ CSendDialog::CSendDialog(wxWindow* parent, const wxString& strAddress) : CSendDi
     m_bitmapCheckMark->Show(false);
     fEnabledPrev = true;
     m_textCtrlAddress->SetFocus();
+    
     //// todo: should add a display of your balance for convenience
 #ifndef __WXMSW__
     wxFont fontTmp = m_staticTextInstructions->GetFont();
@@ -1867,7 +1838,7 @@ CSendDialog::CSendDialog(wxWindow* parent, const wxString& strAddress) : CSendDi
     m_staticTextInstructions->SetFont(fontTmp);
     SetSize(725, 180);
 #endif
-
+    
     // Set Icon
     wxIcon iconSend;
     iconSend.CopyFromBitmap(wxBitmap(send16noshadow_xpm));
@@ -1960,6 +1931,7 @@ void CSendDialog::OnButtonSend(wxCommandEvent& event)
                 {
                     wxMessageBox(strError + "  ", _("Sending..."));
                     EndModal(false);
+                    return;
                 }
            }
         }
@@ -2371,7 +2343,7 @@ CAddressBookDialog::CAddressBookDialog(wxWindow* parent, const wxString& strInit
     CRITICAL_BLOCK(cs_mapAddressBook)
     {
         string strDefaultReceiving = (string)pframeMain->m_textCtrlAddress->GetValue();
-        foreach(const PAIRTYPE(string, string)& item, mapAddressBook)
+        BOOST_FOREACH(const PAIRTYPE(string, string)& item, mapAddressBook)
         {
             string strAddress = item.first;
             string strName = item.second;
@@ -2605,6 +2577,7 @@ void CAddressBookDialog::OnClose(wxCloseEvent& event)
 enum
 {
     ID_TASKBAR_RESTORE = 10001,
+    ID_TASKBAR_SEND,
     ID_TASKBAR_OPTIONS,
     ID_TASKBAR_GENERATE,
     ID_TASKBAR_EXIT,
@@ -2613,8 +2586,8 @@ enum
 BEGIN_EVENT_TABLE(CMyTaskBarIcon, wxTaskBarIcon)
     EVT_TASKBAR_LEFT_DCLICK(CMyTaskBarIcon::OnLeftButtonDClick)
     EVT_MENU(ID_TASKBAR_RESTORE, CMyTaskBarIcon::OnMenuRestore)
+    EVT_MENU(ID_TASKBAR_SEND, CMyTaskBarIcon::OnMenuSend)
     EVT_MENU(ID_TASKBAR_OPTIONS, CMyTaskBarIcon::OnMenuOptions)
-    EVT_MENU(ID_TASKBAR_GENERATE, CMyTaskBarIcon::OnMenuGenerate)
     EVT_UPDATE_UI(ID_TASKBAR_GENERATE, CMyTaskBarIcon::OnUpdateUIGenerate)
     EVT_MENU(ID_TASKBAR_EXIT, CMyTaskBarIcon::OnMenuExit)
 END_EVENT_TABLE()
@@ -2665,6 +2638,13 @@ void CMyTaskBarIcon::OnMenuRestore(wxCommandEvent& event)
     Restore();
 }
 
+void CMyTaskBarIcon::OnMenuSend(wxCommandEvent& event)
+{
+    // Taskbar: Send
+    CSendDialog dialog(pframeMain);
+    dialog.ShowModal();
+}
+
 void CMyTaskBarIcon::OnMenuOptions(wxCommandEvent& event)
 {
     // Since it's modal, get the main window to do it
@@ -2681,11 +2661,6 @@ void CMyTaskBarIcon::Restore()
     pframeMain->Raise();
 }
 
-void CMyTaskBarIcon::OnMenuGenerate(wxCommandEvent& event)
-{
-    GenerateBitcoins(event.IsChecked());
-}
-
 void CMyTaskBarIcon::OnUpdateUIGenerate(wxUpdateUIEvent& event)
 {
     event.Check(fGenerateBitcoins);
@@ -2706,8 +2681,8 @@ wxMenu* CMyTaskBarIcon::CreatePopupMenu()
 {
     wxMenu* pmenu = new wxMenu;
     pmenu->Append(ID_TASKBAR_RESTORE, _("&Open Bitcoin"));
+    pmenu->Append(ID_TASKBAR_SEND, _("&Send Bitcoins"));
     pmenu->Append(ID_TASKBAR_OPTIONS, _("O&ptions..."));
-    pmenu->AppendCheckItem(ID_TASKBAR_GENERATE, _("&Generate Coins"))->Check(fGenerateBitcoins);
 #ifndef __WXMAC_OSX__ // Mac has built-in quit menu
     pmenu->AppendSeparator();
     pmenu->Append(ID_TASKBAR_EXIT, _("E&xit"));
@@ -2839,9 +2814,6 @@ bool CMyApp::OnInit()
     extern int g_isPainting;
     g_isPainting = 10000;
 #endif
-#ifdef GUI
-    wxImage::AddHandler(new wxPNGHandler);
-#endif
 #if defined(__WXMSW__ ) || defined(__WXMAC_OSX__)
     SetAppName("Bitcoin");
 #else