Code:
CAccountViewer::CAccountViewer(wxWindow *pParent, CAccountManager *pAM, wxString &AccountName)
: wxPanel(pParent, ID_DATAWINDOW)
{
SetOwnBackgroundColour(wxColour(100, 100, 100) );
m_Balance = 0.0;
m_AccountNames = pAM->GetAccountNames();
m_pAccount = pAM->GetAccount(AccountName);
m_pGrid = new wxGrid(this, ID_DATAWINDOW, wxDefaultPosition, wxDefaultSize, wxVSCROLL);
if (!m_pGrid->CreateGrid(0, 9) ) SHOWERROR("Could not create grid");
m_pGrid->BeginBatch();
m_pAccount->ResetTransactionCounter();
while (m_pAccount->HasMoreTransactions() )
{
AddNewRow(m_pAccount->GetNextTransaction(), false);
}
m_pGrid->EndBatch();
// set up the button panel
m_pButtonPanel = new wxPanel(this, ID_BUTTONPANEL);
m_pButtonPanel->SetBackgroundColour(wxColour(200, 200, 200) );
// set up the buttons
wxButton *pBtnCheck = new wxButton(m_pButtonPanel, IDB_CHECK, wxT("Check") );
wxButton *pBtnDebit = new wxButton(m_pButtonPanel, IDB_DEBIT, wxT("Debit") );
wxButton *pBtnDeposit = new wxButton(m_pButtonPanel, IDB_DEPOSIT, wxT("Deposit") );
wxButton *pBtnATM = new wxButton(m_pButtonPanel, IDB_ATM, wxT("ATM") );
wxButton *pBtnTransfer = new wxButton(m_pButtonPanel, IDB_TRANSFER, wxT("Transfer") );
wxBoxSizer *pButtonSizer = new wxBoxSizer(wxVERTICAL);
pButtonSizer->Add(new wxStaticText(m_pButtonPanel, wxID_ANY, wxT("Enter a new Transaction") ),
1,
wxALIGN_LEFT | wxALL, 3);
pButtonSizer->Add(pBtnCheck, 1, wxALIGN_LEFT | wxALL, 3);
pButtonSizer->Add(pBtnDebit, 1, wxALIGN_LEFT | wxALL, 3);
pButtonSizer->Add(pBtnDeposit, 1, wxALIGN_LEFT | wxALL, 3);
pButtonSizer->Add(pBtnATM, 1, wxALIGN_LEFT | wxALL, 3);
pButtonSizer->Add(pBtnTransfer, 1, wxALIGN_LEFT | wxALL, 3);
m_pButtonPanel->SetSizer(pButtonSizer);
wxBoxSizer *pVSizer = new wxBoxSizer(wxVERTICAL);
pVSizer->Add(m_pGrid, 4, wxALIGN_CENTER | wxALL | wxEXPAND, 5);
pVSizer->Add(m_pButtonPanel, 1, wxALIGN_CENTER | wxALL | wxEXPAND, 5);
SetSizer(pVSizer);
// attach handlers
// mouse right click on grid
Connect(ID_DATAWINDOW, wxEVT_GRID_CELL_RIGHT_CLICK,
wxGridEventHandler(CAccountViewer::OnTransactionRightClick) );
// popup command menu from grid
Connect(IDM_VIEW_TRANSACTION, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(CAccountViewer::OnViewTransaction) );
Connect(IDM_VIEW_IMAGES, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(CAccountViewer::OnViewImages) );
Connect(IDM_EDIT_TRANSACTION, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(CAccountViewer::OnEditTransaction) );
Connect(IDM_DELETE_TRANSACTION, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(CAccountViewer::OnDeleteTransaction) );
Connect(IDM_CHANGE_TRANSACTION_STATUS, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(CAccountViewer::OnChangeTransactionStatus) );
// buttons
pBtnCheck->Connect(IDB_CHECK, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(CAccountViewer::OnNewTransaction) );
pBtnDebit->Connect(IDB_DEBIT, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(CAccountViewer::OnNewTransaction) );
pBtnDeposit->Connect(IDB_DEPOSIT, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(CAccountViewer::OnNewTransaction) );
pBtnATM->Connect(IDB_ATM, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(CAccountViewer::OnNewTransaction) );
pBtnTransfer->Connect(IDB_TRANSFER, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(CAccountViewer::OnNewTransaction) );
}
and when one of the new transaction buttons are clicked :