From: Steve Brokenshire Date: Sun, 16 Apr 2017 16:10:17 +0000 (+0100) Subject: frmMain: Manage windows from Window menu. X-Git-Tag: release-0.03~2 X-Git-Url: http://Server1/repobrowser/?p=xestiacalendar%2F.git;a=commitdiff_plain;h=616ddd1b189837e5a7d1d6953534115be44f477b frmMain: Manage windows from Window menu. --- diff --git a/source/AppXestiaCalendar.cpp b/source/AppXestiaCalendar.cpp index a43977a..66726f5 100644 --- a/source/AppXestiaCalendar.cpp +++ b/source/AppXestiaCalendar.cpp @@ -66,6 +66,9 @@ frmMainADT::frmMainADT( wxWindow* parent, wxWindowID id, const wxString& title, menuBar->Append( mnuCreate, wxT("Create") ); + mnuWindow = new wxMenu(); + menuBar->Append( mnuWindow, wxT("Window") ); + mnuHelp = new wxMenu(); wxMenuItem* mnuHelpShow; mnuHelpShow = new wxMenuItem( mnuHelp, wxID_HELP, wxString( wxT("Show Help...") ) + wxT('\t') + wxT("F1"), wxEmptyString, wxITEM_NORMAL ); @@ -1512,22 +1515,28 @@ frmEventEditorADT::frmEventEditorADT( wxWindow* parent, wxWindowID id, const wxS this->Centre( wxBOTH ); // Connect Events + this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( frmEventEditorADT::CloseWindow ) ); this->Connect( mnuEventSave->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::SaveContact ) ); this->Connect( mnuEventSaveNew->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::SaveNewContact ) ); this->Connect( mnuEventClose->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::CloseWindow ) ); this->Connect( mnuEditCut->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::CutText ) ); this->Connect( mnuEditCopy->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::CopyText ) ); this->Connect( mnuEditPaste->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::PasteText ) ); + cmbCalendar->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( frmEventEditorADT::ProcessCalendarControl ), NULL, this ); + txtEventName->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( frmEventEditorADT::ProcessEventName ), NULL, this ); } frmEventEditorADT::~frmEventEditorADT() { // Disconnect Events + this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( frmEventEditorADT::CloseWindow ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::SaveContact ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::SaveNewContact ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::CloseWindow ) ); this->Disconnect( wxID_CUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::CutText ) ); this->Disconnect( wxID_COPY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::CopyText ) ); this->Disconnect( wxID_PASTE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmEventEditorADT::PasteText ) ); + cmbCalendar->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( frmEventEditorADT::ProcessCalendarControl ), NULL, this ); + txtEventName->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( frmEventEditorADT::ProcessEventName ), NULL, this ); } diff --git a/source/AppXestiaCalendar.h b/source/AppXestiaCalendar.h index e27361c..300a686 100644 --- a/source/AppXestiaCalendar.h +++ b/source/AppXestiaCalendar.h @@ -1,4 +1,4 @@ -// AppXesitaCalendar.cpp - Xestia Calendar application form code header +// AppXesitaCalendar.h - Xestia Calendar application form code header // // (c) 2016-2017 Xestia Software Development. // @@ -75,6 +75,7 @@ class frmMainADT : public wxFrame wxMenuBar* menuBar; wxMenu* mnuManage; wxMenu* mnuCreate; + wxMenu* mnuWindow; wxMenu* mnuHelp; wxBoxSizer* szrMain; @@ -517,12 +518,15 @@ class frmEventEditorADT : public wxFrame wxTextCtrl* m_textCtrl20; // Virtual event handlers, overide them in your derived class + virtual void CloseWindow( wxCloseEvent& event ) { event.Skip(); } virtual void SaveContact( wxCommandEvent& event ) { event.Skip(); } virtual void SaveNewContact( wxCommandEvent& event ) { event.Skip(); } virtual void CloseWindow( wxCommandEvent& event ) { event.Skip(); } virtual void CutText( wxCommandEvent& event ) { event.Skip(); } virtual void CopyText( wxCommandEvent& event ) { event.Skip(); } virtual void PasteText( wxCommandEvent& event ) { event.Skip(); } + virtual void ProcessCalendarControl( wxCommandEvent& event ) { event.Skip(); } + virtual void ProcessEventName( wxCommandEvent& event ) { event.Skip(); } public: diff --git a/source/Makefile b/source/Makefile index b9ce324..7634f03 100644 --- a/source/Makefile +++ b/source/Makefile @@ -1,7 +1,7 @@ CPP=g++ STRIP=strip -BMCO_CPPFLAGS=`xml2-config --cflags` `wx-config --cxxflags` -std=c++11 -Os -I./common -ggdb -CPPFLAGS=`xml2-config --cflags` `wx-config --cxxflags` -std=c++11 -Os -I./common -ggdb +BMCO_CPPFLAGS=`xml2-config --cflags` `wx-config --cxxflags` -std=c++11 -I./common -ggdb +CPPFLAGS=`xml2-config --cflags` `wx-config --cxxflags` -std=c++11 -I./common -ggdb BMCO_CPPLIBS=`wx-config --libs` `curl-config --libs` -lxml2 CPPLIBS=`wx-config --libs` `curl-config --libs` -lxml2 -Llibraries -lCalendarDataStorage -lsqlite3 CDSLIBS=-lsqlite3 @@ -19,7 +19,7 @@ BMCOOBJS=tools/bitmapcode.o COMMONOBJS=common/monthviewgen.o common/file.o common/text.o \ common/uuid.o common/preferences.o common/dirs.o common/defaults.o \ common/random.o common/svrblist.o -FORM_MAINOBJS=forms/main/frmMain.o +FORM_MAINOBJS=forms/main/frmMain.o forms/main/frmMain-Window.o FORM_UPDATEOBJS=forms/update/frmUpdate.o FORM_EDITACCOUNTOBJS=forms/editaccount/frmEditAccount.o FORM_NEWACCOUNTOBJS=forms/newaccount/frmNewAccount.o diff --git a/source/Makefile.in b/source/Makefile.in index ffb34a2..a326eeb 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -19,7 +19,7 @@ BMCOOBJS=tools/bitmapcode.o COMMONOBJS=common/monthviewgen.o common/file.o common/text.o \ common/uuid.o common/preferences.o common/dirs.o common/defaults.o \ common/random.o common/svrblist.o -FORM_MAINOBJS=forms/main/frmMain.o +FORM_MAINOBJS=forms/main/frmMain.o forms/main/frmMain-Window.o FORM_UPDATEOBJS=forms/update/frmUpdate.o FORM_EDITACCOUNTOBJS=forms/editaccount/frmEditAccount.o FORM_NEWACCOUNTOBJS=forms/newaccount/frmNewAccount.o diff --git a/source/common/events.h b/source/common/events.h index d95c33c..e425fa7 100644 --- a/source/common/events.h +++ b/source/common/events.h @@ -37,6 +37,14 @@ DECLARE_EVENT_TYPE(XCMAIN_DELETEEVENT, wxID_ANY) DECLARE_EVENT_TYPE(XCMAIN_ADDEVENT, wxID_ANY) DECLARE_EVENT_TYPE(XCMAIN_UPDATEEVENT, wxID_ANY) +DEFINE_EVENT_TYPE(XCMAIN_ADDWINDOWINFO) +DEFINE_EVENT_TYPE(XCMAIN_UPDATEWINDOWINFO) +DEFINE_EVENT_TYPE(XCMAIN_DELETEWINDOWINFO) + +DECLARE_EVENT_TYPE(XCMAIN_ADDWINDOWINFO, wxID_ANY) +DECLARE_EVENT_TYPE(XCMAIN_UPDATEWINDOWINFO, wxID_ANY) +DECLARE_EVENT_TYPE(XCMAIN_DELETEWINDOWINFO, wxID_ANY) + DEFINE_EVENT_TYPE(XCCALENDARDAY_UPDATEICONS) DEFINE_EVENT_TYPE(XCCALENDARDAY_DESELECTOTHERENTRIES) DEFINE_EVENT_TYPE(XCCALENDARDAY_DESELECTALLENTRIES) @@ -168,5 +176,16 @@ DECLARE_EVENT_TYPE(XCCALENDARMONTH_DISPLAYEVENTMENU, wxID_ANY) #define ID_ADDENTRY 7018 #define ID_UPDATEENTRY 7019 #define ID_UPDATECOLOUR 7020 +#define ID_ADDWINDOW 7021 +#define ID_UPDATEWINDOW 7022 +#define ID_DELETEWINDOW 7023 + +struct WindowData{ + + int DataType; + void *WindowPointer; + int WindowID; + +}; #endif \ No newline at end of file diff --git a/source/forms/eventeditor/frmEventEditor.cpp b/source/forms/eventeditor/frmEventEditor.cpp index 4c95dc3..dda8dd1 100644 --- a/source/forms/eventeditor/frmEventEditor.cpp +++ b/source/forms/eventeditor/frmEventEditor.cpp @@ -70,8 +70,15 @@ void frmEventEditor::SetupForm(CalendarDataStorage *dataStorage, XCALPreferences calendarID = eventInfo.calendarID; + // Set the calendar combination box to the name. + + string combinedName = dataStorage->GetCalendar(calendarID).accountName; + combinedName += " : "; + combinedName += dataStorage->GetCalendar(eventInfo.calendarID).calendarName; + // Load the calendar info. + cmbCalendar->SetSelection(cmbCalendar->FindString(combinedName)); cmbCalendar->Show(false); lblCalendar->Show(false); @@ -122,14 +129,20 @@ void frmEventEditor::SetupForm(CalendarDataStorage *dataStorage, XCALPreferences eventData.LoadFile(eventFilePath); // TODO: Set the duration data. + + } else { + + // Setup the date and time with some default values (today's date and time). + + SetDefaultDateTime(); - return; } - - // Setup the date and time with some default values (today's date and time). - - SetDefaultDateTime(); + // Enable window updating and update window name. + + UpdateWindowName(); + enableUpdates = true; + } void frmEventEditor::SetEditMode(bool editMode){ @@ -165,8 +178,6 @@ void frmEventEditor::SaveNewContact(wxCommandEvent &event){ szrDetails->Layout(); szrList->Layout(); - - } void frmEventEditor::SaveContact(){ @@ -348,12 +359,33 @@ void frmEventEditor::SaveContact(){ } -void frmEventEditor::CloseWindow(wxCommandEvent &event){ +void frmEventEditor::CloseWindow(wxCommandEvent &event) +{ this->Close(); } +void frmEventEditor::CloseWindow(wxCloseEvent &event) +{ + + WindowData *deleteWindowData = new WindowData; + + deleteWindowData->DataType = 1; + deleteWindowData->WindowPointer = (void*)this; + deleteWindowData->WindowID = windowID; + + // Delete the window from the window list. + + wxCommandEvent deleteEvent(XCMAIN_DELETEWINDOWINFO); + deleteEvent.SetId(ID_DELETEWINDOW); + deleteEvent.SetClientData(deleteWindowData); + wxPostEvent(this->GetParent(), deleteEvent); + + this->Destroy(); + +} + bool frmEventEditor::ProcessEvent(wxEvent& event) { @@ -469,4 +501,77 @@ void frmEventEditor::SetDefaultDateTime(){ txtEndTime->SetValue((wxString)formattedTime); +} + +void frmEventEditor::SetWindowMenuItemID(int windowID) +{ + + this->windowID = windowID; + +} + +void frmEventEditor::ProcessCalendarControl(wxCommandEvent &event) +{ + + UpdateWindowName(); + +} + +void frmEventEditor::ProcessEventName(wxCommandEvent &event) +{ + + UpdateWindowName(); + +} + +void frmEventEditor::UpdateWindowName() +{ + + // Generate the window title. + + string windowTitle; + + if (cmbCalendar->GetSelection() == -1) + { + windowTitle += "(calendar not selected)"; + } + else + { + windowTitle += cmbCalendar->GetStringSelection().ToStdString(); + } + + if (txtEventName->IsEmpty()) + { + windowTitle += " - "; + windowTitle += "(unamed event)"; + } + else + { + windowTitle += " - "; + windowTitle += txtEventName->GetValue().ToStdString(); + } + + SetTitle(windowTitle); + + // Check if post window title updating is enabled before + // going any further. + + if (enableUpdates == false) + { + return; + } + + WindowData *updateWindowData = new WindowData; + + updateWindowData->DataType = 1; + updateWindowData->WindowPointer = (void*)this; + updateWindowData->WindowID = windowID; + + // Delete the window from the window list. + + wxCommandEvent updateEvent(XCMAIN_UPDATEWINDOWINFO); + updateEvent.SetId(ID_UPDATEWINDOW); + updateEvent.SetClientData(updateWindowData); + wxPostEvent(this->GetParent(), updateEvent); + } \ No newline at end of file diff --git a/source/forms/eventeditor/frmEventEditor.h b/source/forms/eventeditor/frmEventEditor.h index a1b5f0e..dca82a0 100644 --- a/source/forms/eventeditor/frmEventEditor.h +++ b/source/forms/eventeditor/frmEventEditor.h @@ -50,26 +50,34 @@ class frmEventEditor : public frmEventEditorADT CalendarEventObject eventData; vector calendarIDList; bool editMode = false; + bool enableUpdates = false; + int accountID = 0; int eventID = 0; int calendarID = 0; + int windowID = 0; string eventFilePath; void SaveContact(); XCALPreferences *preferences; void SetDefaultDateTime(); + void UpdateWindowName(); protected: void SaveContact(wxCommandEvent &event); void SaveNewContact(wxCommandEvent &event); void CloseWindow(wxCommandEvent &event); + void CloseWindow(wxCloseEvent &event); void CutText(wxCommandEvent &event); void CopyText(wxCommandEvent &event); void PasteText(wxCommandEvent &event); bool ProcessEvent(wxEvent& event); + void ProcessCalendarControl(wxCommandEvent &event); + void ProcessEventName(wxCommandEvent &event); public: /** Constructor */ frmEventEditor( wxWindow* parent ); void SetupForm(CalendarDataStorage *dataStorage, XCALPreferences *preferences); void SetEditMode(bool editMode); void SetEventID(int eventID); + void SetWindowMenuItemID(int windowID); //// end generated class members }; diff --git a/source/forms/main/frmMain-Window.cpp b/source/forms/main/frmMain-Window.cpp new file mode 100644 index 0000000..401eead --- /dev/null +++ b/source/forms/main/frmMain-Window.cpp @@ -0,0 +1,101 @@ +// frmMain-Window.h - frmMain form window functions. +// +// (c) 2017 Xestia Software Development. +// +// This file is part of Xestia Calendar. +// +// Xestia Calendar is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by the +// Free Software Foundation, version 3 of the license. +// +// Xestia Calendar is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with Xestia Calendar. If not, see + +#include "frmMain.h" + +void frmMain::WindowAdd( wxCommandEvent &event ){ + + // Add a window to the window list. + + WindowData *receivedWindowData = (WindowData*)event.GetClientData(); + + size_t pos; + + wxMenuItem *mnuNewItem = new wxMenuItem(NULL, receivedWindowData->WindowID, wxT("Event Window #") + wxString::Format(wxT("%i"), receivedWindowData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL); + mnuNewItem->SetId(receivedWindowData->WindowID); + mnuWindow->Append(mnuNewItem); + this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowEventWindow)); + + frmEventEditor *frmEventEditorPtr = static_cast(receivedWindowData->WindowPointer); + wxString windowTitle = frmEventEditorPtr->GetTitle(); + mnuNewItem->SetItemLabel(windowTitle); + + WindowListPointersMenu.insert(std::make_pair(receivedWindowData->WindowID, mnuNewItem)); + WindowListPointers.insert(std::make_pair(receivedWindowData->WindowID, receivedWindowData->WindowPointer)); + WindowListType.insert(std::make_pair(receivedWindowData->WindowID, 0)); + + delete receivedWindowData; + receivedWindowData = NULL; + +} + +void frmMain::WindowUpdate( wxCommandEvent &event ){ + + // Add a window to the window list. + + WindowData *receivedWindowData = (WindowData*)event.GetClientData(); + + size_t pos; + + frmEventEditor *frmEventEditorPtr = static_cast(receivedWindowData->WindowPointer); + + wxString windowTitle = frmEventEditorPtr->GetTitle(); + + std::map::iterator MenuIter = WindowListPointersMenu.find(receivedWindowData->WindowID); + + MenuIter->second->SetItemLabel(windowTitle); + + delete receivedWindowData; + receivedWindowData = NULL; + +} + +void frmMain::WindowDelete( wxCommandEvent &event ){ + + // Delete the window from the window list. + + WindowData *receivedWindowData = (WindowData*)event.GetClientData(); + + size_t pos; + + std::map::iterator menuIter = WindowListPointersMenu.find(receivedWindowData->WindowID); + + mnuWindow->Destroy(menuIter->second); + + WindowListPointersMenu.erase(receivedWindowData->WindowID); + WindowListPointers.erase(receivedWindowData->WindowID); + WindowListType.erase(receivedWindowData->WindowID); + + delete receivedWindowData; + receivedWindowData = NULL; + +} + +void frmMain::ShowEventWindow( wxCommandEvent &event ){ + + // Show a contact window from the window list. + + std::map::iterator WindowIter = WindowListPointers.find(event.GetId()); + + frmEventEditor *frmEventEditorPtr = static_cast(WindowIter->second); + + frmEventEditorPtr->Show(); + frmEventEditorPtr->Raise(); + +} +} \ No newline at end of file diff --git a/source/forms/main/frmMain.cpp b/source/forms/main/frmMain.cpp index d04574f..835118b 100644 --- a/source/forms/main/frmMain.cpp +++ b/source/forms/main/frmMain.cpp @@ -1,4 +1,4 @@ -// frmMain.h - frmMain form functions header. +// frmMain.h - frmMain form functions // // (c) 2016-2017 Xestia Software Development. // @@ -85,6 +85,10 @@ frmMainADT( parent ) Connect(ID_UPDATEENTRY, XCMAIN_UPDATEEVENT, wxCommandEventHandler(frmMain::UpdateEvent)); Connect(ID_EDITEVENT, XCMAIN_EDITEVENT, wxCommandEventHandler(frmMain::EditEvent)); + Connect(ID_ADDWINDOW, XCMAIN_ADDWINDOWINFO, wxCommandEventHandler(frmMain::WindowAdd)); + Connect(ID_UPDATEWINDOW, XCMAIN_UPDATEWINDOWINFO, wxCommandEventHandler(frmMain::WindowUpdate)); + Connect(ID_DELETEWINDOW, XCMAIN_DELETEWINDOWINFO, wxCommandEventHandler(frmMain::WindowDelete)); + } void frmMain::QuitApp( wxCloseEvent& event ) @@ -469,6 +473,21 @@ void frmMain::CreateNewEvent( wxCommandEvent& event ){ frmEventEditor *frameNewEvent = new frmEventEditor ( this ); frameNewEvent->SetupForm(&calendarData, preferences); + frameNewEvent->SetWindowMenuItemID(++WindowMenuItemID); + + // Add the window to the window list. + + WindowData *newWindowData = new WindowData; + + newWindowData->DataType = 1; + newWindowData->WindowPointer = (void*)frameNewEvent; + newWindowData->WindowID = WindowMenuItemID; + + wxCommandEvent addevent(XCMAIN_ADDWINDOWINFO); + addevent.SetId(ID_ADDWINDOW); + addevent.SetClientData(newWindowData); + wxPostEvent(this, addevent); + frameNewEvent->Show(); } @@ -478,7 +497,24 @@ void frmMain::EditEvent( wxCommandEvent& event ){ frmEventEditor *frameEditEvent = new frmEventEditor ( this ); frameEditEvent->SetEventID(event.GetInt()); frameEditEvent->SetEditMode(true); + frameEditEvent->SetWindowMenuItemID(++WindowMenuItemID); frameEditEvent->SetupForm(&calendarData, preferences); + + // Add the window to the window list. + + WindowData *newWindowData = new WindowData; + + newWindowData->DataType = 1; + newWindowData->WindowPointer = (void*)frameEditEvent; + newWindowData->WindowID = WindowMenuItemID; + + wxCommandEvent addevent(XCMAIN_ADDWINDOWINFO); + addevent.SetId(ID_ADDWINDOW); + addevent.SetClientData(newWindowData); + wxPostEvent(this, addevent); + + // Setup the form and display it. + frameEditEvent->Show(); } diff --git a/source/forms/main/frmMain.h b/source/forms/main/frmMain.h index 525c4d7..23b9079 100644 --- a/source/forms/main/frmMain.h +++ b/source/forms/main/frmMain.h @@ -60,6 +60,10 @@ class frmMain : public frmMainADT CalendarDataStorage calendarData; ColourUpdateProperties updateColourData; bool reloadAccounts = false; + std::map WindowListPointersMenu; + std::map WindowListPointers; + std::map WindowListType; + int WindowMenuItemID = 0; protected: void QuitApp( wxCloseEvent& event ); @@ -82,6 +86,10 @@ class frmMain : public frmMainADT void CloseWindow( wxCommandEvent& event ); void ShowHelp( wxCommandEvent& event ); + void WindowAdd( wxCommandEvent& event ); + void WindowUpdate( wxCommandEvent& event ); + void WindowDelete( wxCommandEvent& event ); + void ShowEventWindow( wxCommandEvent &event ); public: /** Constructor */ frmMain( wxWindow* parent );