KissCount/view/wxUI.cpp

145 lines
2.9 KiB
C++
Raw Normal View History

#include "wxUI.h"
BEGIN_EVENT_TABLE(wxUI, wxFrame)
EVT_MENU(ID_Quit, wxUI::OnQuit)
EVT_MENU(ID_About, wxUI::OnAbout)
END_EVENT_TABLE()
2010-05-16 10:35:34 +02:00
wxString months[12] = {_("january"), _("february"), _("march"), _("april"), _("may"), _("june"), _("july"), _("august"), _("september"), _("october"), _("november"), _("december")} ;
wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size)
2010-06-27 21:39:49 +02:00
: wxFrame(NULL, -1, title, pos, size), _kiss(kiss), _accountPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL),
_needReload(false)
{
_hbox = new wxBoxSizer(wxVERTICAL);
ButtonPanel* buttons = new ButtonPanel(_kiss, this);
2010-06-29 21:43:29 +02:00
// wxMenu *menuFile = new wxMenu;
2010-07-03 11:19:02 +02:00
// menuFile->Append( ID_About, wxT("&About...") );
2010-06-29 21:43:29 +02:00
// menuFile->AppendSeparator();
2010-07-03 11:19:02 +02:00
// menuFile->Append( ID_Quit, wxT("E&xit") );
2010-06-29 21:43:29 +02:00
// wxMenuBar *menuBar = new wxMenuBar;
2010-07-03 11:19:02 +02:00
// menuBar->Append( menuFile, wxT("&File") );
2010-06-29 21:43:29 +02:00
// SetMenuBar( menuBar );
2010-06-29 21:43:29 +02:00
// CreateStatusBar();
2010-07-03 11:19:02 +02:00
// SetStatusText( wxT("Welcome to wxWidgets!") );
SetSizer(_hbox);
_hbox->Add(buttons);
}
wxUI::~wxUI()
{
if (_accountPanel) delete _accountPanel;
2010-05-17 18:03:21 +02:00
if (_preferencesPanel) delete _preferencesPanel;
}
void wxUI::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
}
void wxUI::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox( _("This is a wxWidgets Hello world sample"),
_("About Hello World"),
wxOK | wxICON_INFORMATION, this );
}
2010-05-17 18:03:21 +02:00
void wxUI::ShowAccount()
{
ShowPanel(_accountPanel);
}
void wxUI::ShowPreferences()
{
ShowPanel(_preferencesPanel);
}
void wxUI::ChangeUser()
{
UsersDialog u(_kiss, this);
u.ShowModal();
}
void wxUI::LoadUser()
{
2010-05-17 18:03:21 +02:00
if (_curPanel)
{
2010-05-17 18:03:21 +02:00
_hbox->Detach(_curPanel);
_curPanel = NULL;
}
2010-05-17 18:03:21 +02:00
if (_accountPanel)
delete _accountPanel;
if (_preferencesPanel)
delete _preferencesPanel;
_preferencesPanel = new PreferencesPanel(_kiss, this);
2010-06-27 21:39:49 +02:00
_accountPanel = new AccountPanel(_kiss, this);
2010-05-17 18:03:21 +02:00
ShowPanel(_accountPanel);
}
void wxUI::ShowPanel(wxPanel* panel)
{
2010-06-27 21:39:49 +02:00
int month, year;
2010-05-17 18:03:21 +02:00
if (!panel) return;
if (_curPanel)
{
_hbox->Detach(_curPanel);
_curPanel->Hide();
}
2010-06-27 21:39:49 +02:00
if (panel == _accountPanel && _needReload)
{
month = _accountPanel->_curMonth;
year = _accountPanel->_curYear;
delete _accountPanel;
panel = _accountPanel = new AccountPanel(_kiss, this);
_accountPanel->ShowMonth(month, year);
_needReload = false;
}
2010-05-17 18:03:21 +02:00
_curPanel = panel;
_hbox->Add(panel);
_curPanel->Show();
Layout();
}
2010-06-23 19:32:42 +02:00
void wxUI::GenerateMonth(int month, int year)
{
_accountPanel->GenerateMonth(month, year);
}
2010-06-27 21:39:49 +02:00
void wxUI::KillMe()
{
if (_curPanel)
{
_hbox->Detach(_curPanel);
_curPanel = NULL;
}
if (_accountPanel)
delete _accountPanel;
if (_preferencesPanel)
delete _preferencesPanel;
_accountPanel = NULL;
_preferencesPanel = NULL;
}
void wxUI::NeedReload()
{
_needReload = true;
}