Forgot some files

This commit is contained in:
Grégory Soutadé 2010-06-23 14:25:30 +02:00
parent ac5c26bc4f
commit ea12a1b16c
2 changed files with 213 additions and 0 deletions

178
view/GenerateDialog.cpp Normal file
View File

@ -0,0 +1,178 @@
#include "GenerateDialog.h"
enum {BUTTON_OK_ID=1, BUTTON_CANCEL_ID, YEAR_FROM_ID, MONTH_FROM_ID, YEAR_TO_ID, MONTH_TO_ID};
BEGIN_EVENT_TABLE(GenerateDialog, wxDialog)
EVT_BUTTON(BUTTON_OK_ID, GenerateDialog::OnOK)
EVT_BUTTON(BUTTON_CANCEL_ID, GenerateDialog::OnCancel)
EVT_CHOICE(YEAR_FROM_ID, GenerateDialog::OnYearFromChange)
EVT_CHOICE(YEAR_TO_ID, GenerateDialog::OnYearToChange)
END_EVENT_TABLE()
GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year) : wxDialog(&(*parent), -1, _("Generate month")), _kiss(kiss), _wxUI(parent)
{
wxGridBagSizer *gridBagSizer;
wxStaticText* label;
std::map<int, std::vector<int> >::iterator it;
int i, a, toSelect=-1;
wxDateTime curDate;
wxCommandEvent event;
std::vector<int>::iterator monthIt;
curDate.SetToCurrent();
gridBagSizer = new wxGridBagSizer(4, 5);
label = new wxStaticText(this, -1, _("From "));
gridBagSizer->Add(label, wxGBPosition(0, 0));
_yearFrom = new wxChoice(this, YEAR_FROM_ID);
gridBagSizer->Add(_yearFrom, wxGBPosition(0, 1));
_monthFrom = new wxChoice(this, MONTH_FROM_ID);
gridBagSizer->Add(_monthFrom, wxGBPosition(0, 2));
label = new wxStaticText(this, -1, _("To "));
gridBagSizer->Add(label, wxGBPosition(1, 0));
_yearTo = new wxChoice(this, YEAR_TO_ID);
gridBagSizer->Add(_yearTo, wxGBPosition(1, 1));
_monthTo = new wxChoice(this, MONTH_TO_ID);
gridBagSizer->Add(_monthTo, wxGBPosition(1, 2));
wxButton* ok = new wxButton(this, BUTTON_OK_ID, _("OK"));
wxButton* cancel = new wxButton(this, BUTTON_CANCEL_ID, _("Cancel"));
gridBagSizer->Add(ok, wxGBPosition(3, 3));
gridBagSizer->Add(cancel, wxGBPosition(3, 4));
_ops = _kiss->GetAllOperations();
_yearFrom->Append(_(""));
_monthFrom->Append(_(""));
for(i=1, it = _ops.begin(); it != _ops.end(); it++, i++)
{
_yearFrom->Append(wxString::Format(_("%d"), it->first));
if (year == it->first)
toSelect = i;
}
if (toSelect != -1)
{
_yearFrom->Select(toSelect);
OnYearFromChange(event);
toSelect=0;
if (month != -1)
{
for(i=0; i<(int)_monthFrom->GetCount(); i++)
{
if (_monthFrom->GetString(i) == months[month])
{
toSelect = i+1;
break;
}
}
}
_monthFrom->Select(toSelect);
}
OnYearFromChange(event);
for(i=2000; i<=2050; i++)
_yearTo->Append(wxString::Format(_("%d"), i));
if (year == -1)
{
_yearTo->Select(curDate.GetYear()-2000);
OnYearToChange(event);
_monthTo->Select(curDate.GetMonth()-1);
}
else
{
_yearTo->Select(year-2000);
OnYearToChange(event);
if (_ops[year].size())
month = _ops[year][0];
if (month == -1)
_monthTo->Select(0);
else
{
for(a=0, i=0, monthIt=_ops[year].begin(); monthIt!=_ops[year].end() && i<12; i++)
{
if (i != *monthIt)
{
a++;
continue;
}
if (*monthIt > month)
break;
monthIt++;
}
_monthTo->Select(a);
}
}
SetSizer(gridBagSizer);
Layout();
Center();
}
void GenerateDialog::OnYearFromChange(wxCommandEvent& event)
{
wxString years = _yearFrom->GetString(_yearFrom->GetCurrentSelection());
int year;
std::vector<int>::iterator it;
_monthFrom->Clear();
if (years == _(""))
{
_monthFrom->Append(_(""));
return;
}
year = wxAtoi(years);
for(it=_ops[year].begin(); it!=_ops[year].end(); it++)
_monthFrom->Append(months[*it]);
_monthFrom->Select(0);
Layout();
}
void GenerateDialog::OnYearToChange(wxCommandEvent& event)
{
int year, i, ok;
std::vector<int>::iterator it;
_monthTo->Clear();
year = wxAtoi(_yearTo->GetString(_yearTo->GetCurrentSelection()));
for (i=0; i<12; i++)
{
ok = 1;
for(it=_ops[year].begin(); it!=_ops[year].end(); it++)
{
if (*it == i)
{
ok=0; break;
}
}
if (ok)
_monthTo->Append(months[i]);
}
_monthTo->Select(0);
Layout();
}
void GenerateDialog::OnOK(wxCommandEvent& event)
{
Close();
}
void GenerateDialog::OnCancel(wxCommandEvent& event)
{
Close();
}

35
view/GenerateDialog.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef GENERATEDIALOG_H
#define GENERATEDIALOG_H
#include <list>
#include <wx/wx.h>
#include <wx/choice.h>
#include <wx/textctrl.h>
#include <controller/KissCount.h>
#include "wxUI.h"
#include <model/model.h>
class wxUI;
class KissCount;
class GenerateDialog : public wxDialog
{
public:
GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year);
void OnYearFromChange(wxCommandEvent& event);
void OnYearToChange(wxCommandEvent& event);
void OnOK(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
private:
KissCount* _kiss;
wxUI* _wxUI;
wxChoice* _yearFrom, *_monthFrom, *_yearTo, *_monthTo;
std::map<int, std::vector<int> > _ops;
DECLARE_EVENT_TABLE()
};
#endif