Created
November 28, 2018 20:05
-
-
Save thegabriele97/904c39f17abcaa07544081bf5fe24779 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MainFrame.h" | |
#include "AddActivity.h" | |
#include "AddActivityList.h" | |
#include <wx/aboutdlg.h> | |
#include <list> | |
#include <iterator> | |
using namespace std; | |
MainFrame::MainFrame(wxWindow* parent, Board* _board) : MainFrameBaseClass(parent){ | |
startPOS=0; | |
board=_board; | |
this->SetTitle("Diary: " + board->getName()); | |
refreshGroupListCtrl(startPOS); | |
dt = new DropTarget(list1); | |
list1->SetDropTarget(dt); | |
} | |
MainFrame::~MainFrame(){ | |
} | |
void MainFrame::OnExit(wxCommandEvent& event){ | |
wxUnusedVar(event); | |
Close(); | |
} | |
void MainFrame::OnAbout(wxCommandEvent& event){ | |
wxUnusedVar(event); | |
wxAboutDialogInfo info; | |
info.SetCopyright(_("My MainFrame")); | |
info.SetLicence(_("GPL v2 or later")); | |
info.SetDescription(_("Short description goes here")); | |
::wxAboutBox(info); | |
} | |
wxStaticText* MainFrame::getRightLabel (int POS){ | |
if(POS == 0){ | |
return text1; | |
} | |
else if (POS == 1){ | |
return text2; | |
} | |
else if (POS == 2){ | |
return text3; | |
} | |
return NULL; | |
} | |
wxListCtrl* MainFrame::getRightListCtrl (int POS){ | |
if(POS == 0){ | |
return list1; | |
} | |
else if (POS == 1){ | |
return list2; | |
} | |
else if (POS == 2){ | |
return list3; | |
} | |
return NULL; | |
} | |
void MainFrame::refreshListCtrl (int POS, ActivityList& al){ | |
int p = 0; | |
wxStaticText* label = getRightLabel(POS); | |
wxListCtrl* list = getRightListCtrl(POS); | |
label->SetLabelText(al.getName()); | |
list->DeleteAllItems(); | |
al.getActivityContainer().sort(); | |
for(Activity& a : al.getActivityContainer()){ | |
std::cout << a.getPosition(); | |
list->InsertItem(p, ""); | |
list->SetItem(p, 0, a.getTitle()); | |
list->SetItem(p, 1, (a.getDate().getYear() == 1900) ? "Nessuna scadenza" : a.getDate().getDate()); | |
list->SetItem(p, 2, a.getDescription()); | |
p++; | |
} | |
} | |
void MainFrame::refreshGroupListCtrl(int startPOS){ | |
for(int i=0; i<3 && startPOS + i < board->getActivityListContainer().size(); i++){ | |
refreshListCtrl(i, board->getActivityList(elementNameAt(startPOS + i))); | |
} | |
refreshBackForwardStatus(); | |
} | |
void MainFrame::onDrag(wxListEvent& event){ | |
} | |
void MainFrame::onKeyDown(wxListEvent& event){ | |
} | |
void MainFrame::OnButton_addboardButtonClicked(wxCommandEvent& event){ | |
AddActivityList* aal =new AddActivityList (this, board, "", false); | |
aal->Show(); | |
} | |
void MainFrame::OnButton_backButtonClicked(wxCommandEvent& event){ | |
refreshGroupListCtrl(--startPOS); | |
} | |
void MainFrame::OnButton_forwardButtonClicked(wxCommandEvent& event){ | |
refreshGroupListCtrl(++startPOS); | |
} | |
string MainFrame::elementNameAt(int index) { | |
int i = 0; | |
for (ActivityList& al : board->getActivityListContainer()) { | |
if (i++ == index) { | |
return al.getName(); | |
} | |
} | |
} | |
void MainFrame::refreshBackForwardStatus(){ | |
button_back->Enable(!(startPOS == 0)); | |
button_forward->Enable(!(startPOS + 3 >= board->getActivityListContainer().size())); | |
} | |
void MainFrame::OnButton_add1ButtonClicked(wxCommandEvent& event) { | |
AddActivity* addActivity = new AddActivity(this, &board->getActivityList(elementNameAt(startPOS + 0)), 0); | |
addActivity->Show(); | |
} | |
void MainFrame::OnButton_add2ButtonClicked(wxCommandEvent& event) { | |
AddActivity* addActivity = new AddActivity(this, &board->getActivityList(elementNameAt(startPOS + 1)), 1); | |
addActivity->Show(); | |
} | |
void MainFrame::OnButton_add3ButtonClicked(wxCommandEvent& event) { | |
AddActivity* addActivity = new AddActivity(this, &board->getActivityList(elementNameAt(startPOS + 2)), 2); | |
addActivity->Show(); | |
} | |
void MainFrame::OnList1ListItemActivated(wxListEvent& event) { | |
ActivityDetails* details = new ActivityDetails(this, &getSelectedActivity(0)); | |
details->Show(); | |
} | |
void MainFrame::OnList2ListItemActivated(wxListEvent& event) { | |
ActivityDetails* details = new ActivityDetails(this, &getSelectedActivity(1)); | |
details->Show(); | |
} | |
void MainFrame::OnList3ListItemActivated(wxListEvent& event) { | |
ActivityDetails* details = new ActivityDetails(this, &getSelectedActivity(2)); | |
details->Show(); | |
} | |
Activity& MainFrame::getSelectedActivity(int POS) { | |
wxListCtrl* list = getRightListCtrl(POS); | |
int selectedItem = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); | |
return board->getActivityList(elementNameAt(startPOS + POS)).getActivity(list->GetItemText(selectedItem, 0).ToStdString()); | |
} | |
void MainFrame::OnButton_delete1ButtonClicked(wxCommandEvent& event) { | |
board->getActivityList(elementNameAt(startPOS+0)).removeActivity(getSelectedActivity(0)); | |
refreshGroupListCtrl(startPOS); | |
button_delete1->Disable(); | |
} | |
void MainFrame::OnButton_delete2ButtonClicked(wxCommandEvent& event) { | |
board->getActivityList(elementNameAt(startPOS+1)).removeActivity(getSelectedActivity(1)); | |
refreshGroupListCtrl(startPOS); | |
button_delete2->Disable(); | |
} | |
void MainFrame::OnButton_delete3ButtonClicked(wxCommandEvent& event) { | |
board->getActivityList(elementNameAt(startPOS+2)).removeActivity(getSelectedActivity(2)); | |
refreshGroupListCtrl(startPOS); | |
button_delete3->Disable(); | |
} | |
void MainFrame::OnList1ListItemSelected(wxListEvent& event) { | |
button_delete1->Enable(); | |
} | |
void MainFrame::OnList2ListItemSelected(wxListEvent& event) { | |
button_delete2->Enable(); | |
} | |
void MainFrame::OnList3ListItemSelected(wxListEvent& event) { | |
button_delete3->Enable(); | |
} | |
void MainFrame::OnButton_rename1ButtonClicked(wxCommandEvent& event) { | |
AddActivityList* aal =new AddActivityList (this, board, elementNameAt(startPOS + 0) , true); | |
aal->Show(); | |
} | |
void MainFrame::OnButton_rename2ButtonClicked(wxCommandEvent& event) { | |
AddActivityList* aal =new AddActivityList (this, board, elementNameAt(startPOS + 1) , true); | |
aal->Show(); | |
} | |
void MainFrame::OnButton_rename3ButtonClicked(wxCommandEvent& event) { | |
AddActivityList* aal =new AddActivityList (this, board, elementNameAt(startPOS + 2) , true); | |
aal->Show(); | |
} | |
void MainFrame::OnList1ListBeginDrag(wxListEvent& event) { | |
wxString text = list1->GetItemText(event.GetIndex()); | |
dt->start = event.GetPoint(); | |
dt->index = event.GetIndex(); | |
dt->al = &board->getActivityList(elementNameAt(startPOS + 0)); | |
wxTextDataObject tdo(text); | |
wxDropSource tds(tdo, list1); | |
tds.DoDragDrop(wxDrag_CopyOnly); | |
refreshGroupListCtrl(startPOS); | |
} | |
DropTarget::DropTarget(wxListCtrl* _list) : list(_list) { | |
} | |
bool DropTarget::OnDropText(wxCoord x, wxCoord y, const wxString& data) { | |
int i, tmp, swap_index; | |
//this method will swap position between 2 sequential elements in the ActivityList | |
//the elements that will be swapped are [index-1, index] or [index, index+1] | |
//this is done using (start.y - y > 0) that knows if the mouse cursor | |
//is move up or down | |
swap_index = (start.y - y > 0) ? index - 1 : index + 1; | |
swap_index = (swap_index < 0) ? 0 : swap_index; //to beat a stupid user that try to move first element above it | |
//changing position of (index) element in the list and saving its old position in tmp | |
i = 0; | |
for (Activity& a : al->getActivityContainer()) { | |
if (i++ == index) { | |
tmp = i - 1; | |
(&al->getActivity(a.getTitle()))->setPosition(swap_index); | |
break; | |
} | |
} | |
//changing position of (index-1) or (index+1) in the list using prev value from tmp | |
i = 0; | |
for (Activity& a : al->getActivityContainer()) { | |
if (i++ == swap_index) { | |
(&al->getActivity(a.getTitle()))->setPosition(tmp); | |
break; | |
} | |
} | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MAINFRAME_H | |
#define MAINFRAME_H | |
#include "wxcrafter.h" | |
#include "Administrator.hpp" | |
#include "ActivityDetails.h" | |
#include <wx/dnd.h> | |
using namespace std; | |
class MainFrame; | |
class DropTarget : public wxTextDropTarget { | |
public: | |
DropTarget(wxListCtrl* _list); | |
virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& data); | |
wxPoint start; | |
int index; | |
ActivityList* al; | |
private: | |
wxListCtrl* list; | |
}; | |
class MainFrame : public MainFrameBaseClass { | |
public: | |
MainFrame(wxWindow* parent, Board* _board); | |
virtual ~MainFrame(); | |
void OnExit(wxCommandEvent& event); | |
void OnAbout(wxCommandEvent& event); | |
wxStaticText* getRightLabel (int POS); | |
wxListCtrl* getRightListCtrl (int POS); | |
void refreshGroupListCtrl(int startPOS); | |
void refreshListCtrl (int POS, ActivityList& al); | |
void refreshBackForwardStatus (); | |
int startPOS; | |
protected: | |
virtual void OnList1ListBeginDrag(wxListEvent& event); | |
virtual void OnButton_rename1ButtonClicked(wxCommandEvent& event); | |
virtual void OnButton_rename2ButtonClicked(wxCommandEvent& event); | |
virtual void OnButton_rename3ButtonClicked(wxCommandEvent& event); | |
virtual void OnButton_delete1ButtonClicked(wxCommandEvent& event); | |
virtual void OnButton_delete2ButtonClicked(wxCommandEvent& event); | |
virtual void OnButton_delete3ButtonClicked(wxCommandEvent& event); | |
virtual void OnList1ListItemSelected(wxListEvent& event); | |
virtual void OnList2ListItemSelected(wxListEvent& event); | |
virtual void OnList3ListItemSelected(wxListEvent& event); | |
virtual void OnList1ListItemActivated(wxListEvent& event); | |
virtual void OnList2ListItemActivated(wxListEvent& event); | |
virtual void OnList3ListItemActivated(wxListEvent& event); | |
virtual void OnButton_add1ButtonClicked(wxCommandEvent& event); | |
virtual void OnButton_add2ButtonClicked(wxCommandEvent& event); | |
virtual void OnButton_add3ButtonClicked(wxCommandEvent& event); | |
virtual void OnButton_addboardButtonClicked(wxCommandEvent& event); | |
virtual void OnButton_backButtonClicked(wxCommandEvent& event); | |
virtual void OnButton_forwardButtonClicked(wxCommandEvent& event); | |
virtual void onDrag(wxListEvent& event); | |
virtual void onKeyDown(wxListEvent& event); | |
string elementNameAt(int index); | |
private: | |
Board* board; | |
Activity& getSelectedActivity(int POS); | |
DropTarget* dt; | |
}; | |
#endif // MAINFRAME_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment