|
From: Emilien K. <cur...@us...> - 2005-09-14 14:19:22
|
Update of /cvsroot/wxdevcenter/wxDevCenter/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30551/src Modified Files: MDIFrame.cpp MainFrame.cpp Frame.cpp Application.cpp Command.cpp Added Files: Layout.cpp Log Message: Add Command support (menu/toolbar unification). Add begining of layout support. Index: MainFrame.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/MainFrame.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** MainFrame.cpp 26 Aug 2005 08:35:58 -0000 1.19 --- MainFrame.cpp 14 Sep 2005 14:19:11 -0000 1.20 *************** *** 31,34 **** --- 31,37 ---- #include <wxDevCenter/DocView.h> #include <wxDevCenter/WorkBar.h> + #include <wxDevCenter/Command.h> + #include <wxDevCenter/Layout.h> + #include <wx/artprov.h> *************** *** 287,291 **** { wxMenuBar *pMenuBar = new wxMenuBar(); ! wxMenu *pMenu; // Menu Fichier --- 290,294 ---- { wxMenuBar *pMenuBar = new wxMenuBar(); ! /* wxMenu *pMenu; // Menu Fichier *************** *** 333,341 **** // Fixe la barre de menus ! SetMenuBar(pMenuBar); ! m_iMenuSeparator = 1; // Reconstruit le sous menu des workbars ! RebuildWorkBarMenu(); } --- 336,346 ---- // Fixe la barre de menus ! */ SetMenuBar(pMenuBar); ! CommandManager::GetCommandManager().PopulateMenuBar(GetMenuBar(), GetLayout()); ! ! /* m_iMenuSeparator = 1; // Reconstruit le sous menu des workbars ! RebuildWorkBarMenu();*/ } *************** *** 363,367 **** void MainFrame::OnCurrentViewChanging(ViewEvent &event) { ! RemoveViewMenu(event.GetOldView()); SetIcon(m_Icon); SetTitle(WXDC_NAME); --- 368,373 ---- void MainFrame::OnCurrentViewChanging(ViewEvent &event) { ! // RemoveViewMenu(event.GetOldView()); ! CommandManager::GetCommandManager().PopulateMenuBar(GetMenuBar(), GetLayout()); SetIcon(m_Icon); SetTitle(WXDC_NAME); *************** *** 376,380 **** if(pNewView!=NULL) { ! InsertViewMenu(pNewView); wxString strIconName = pNewView->GetViewTemplate()->strIcons; wxIconBundle IB; --- 382,388 ---- if(pNewView!=NULL) { ! // InsertViewMenu(pNewView); ! CommandManager::GetCommandManager().PopulateMenuBar(GetMenuBar(), GetLayout()); ! wxString strIconName = pNewView->GetViewTemplate()->strIcons; wxIconBundle IB; *************** *** 453,459 **** void MainFrame::RebuildWorkBarMenu() { ! wxMenu *pMenu = m_pMenuItemWorkBar->GetSubMenu(); ! m_pLayoutManager->SetWindowMenu(pMenu); } --- 461,467 ---- void MainFrame::RebuildWorkBarMenu() { ! // wxMenu *pMenu = m_pMenuItemWorkBar->GetSubMenu(); ! // m_pLayoutManager->SetWindowMenu(pMenu); } Index: Frame.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/Frame.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Frame.cpp 14 May 2005 12:15:56 -0000 1.9 --- Frame.cpp 14 Sep 2005 14:19:11 -0000 1.10 *************** *** 148,151 **** --- 148,157 ---- } + // Retourne le layout attaché à la fenetre. + wxDevCenter::Layout TopFrame::GetLayout() + { + wxDevCenter::Layout lay(this); + return lay; + } ////////////////////////////////////////////////////////////////////// Index: Application.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/Application.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Application.cpp 26 Aug 2005 08:35:58 -0000 1.32 --- Application.cpp 14 Sep 2005 14:19:11 -0000 1.33 *************** *** 35,38 **** --- 35,39 ---- #include <wxDevCenter/Project.h> #include <wxDevCenter/ArtProvider.h> + #include <wxDevCenter/Command.h> #include <wx/dynlib.h> *************** *** 98,101 **** --- 99,105 ---- m_FileSystemManager.Register(m_pStandardFileSystem, true); + // Initialise les menus par défaut. + InitCommandGroups(); + // Crée la fenetre principale m_pMainFrame = new MainFrame(); *************** *** 482,483 **** --- 486,536 ---- (*GetPagesSetupDialogData()) = Dialog.GetPageSetupData(); } + + // Initie les groupes de commandes de l'application. + void Application::InitCommandGroups() + { + CommandGroup *pCmdGroup; + + // Groupe "Fichier" + pCmdGroup = new CommandGroup(WXDC_MENU_FILES); + pCmdGroup->AppendCommand(IDM_FILE_NEW, WXDC_MENU_FILE_NEW); + pCmdGroup->AppendCommand(IDM_FILE_OPEN, WXDC_MENU_FILE_OPEN); + pCmdGroup->AppendCommand(IDM_FILE_CLOSE, WXDC_MENU_FILE_CLOSE); + pCmdGroup->AppendCommand(IDM_FILE_CLOSEALL, WXDC_MENU_FILE_CLOSEALL); + pCmdGroup->AppendCommand(IDM_FILE_SAVE, WXDC_MENU_FILE_SAVE); + pCmdGroup->AppendCommand(IDM_FILE_SAVEAS, WXDC_MENU_FILE_SAVEAS); + pCmdGroup->AppendSeparator(); + pCmdGroup->AppendCommand(IDM_PROJECT_NEW, WXDC_MENU_PROJECT_NEW); + pCmdGroup->AppendCommand(IDM_PROJECT_OPEN, WXDC_MENU_PROJECT_OPEN); + pCmdGroup->AppendCommand(IDM_PROJECT_CLOSE, WXDC_MENU_PROJECT_CLOSE); + pCmdGroup->AppendSeparator(); + pCmdGroup->AppendCommand(IDM_FILE_PRINT, WXDC_MENU_FILE_PRINT); + pCmdGroup->AppendCommand(IDM_FILE_PRINTSETUP, WXDC_MENU_FILE_PRINTSETUP); + pCmdGroup->AppendCommand(IDM_FILE_PRINTPREVIEW, WXDC_MENU_FILE_PRINTPREVIEW); + pCmdGroup->AppendSeparator(); + pCmdGroup->AppendCommand(wxID_EXIT, WXDC_MENU_APP_EXIT); + CommandManager::GetCommandManager().AddCommandManager(pCmdGroup, NULL, CmdGrpType_Application); + + // Menu Fenetres + pCmdGroup = new CommandGroup(WXDC_MENU_WINDOW); + pCmdGroup->AppendCommand(IDM_WINDOW_CLONE, WXDC_MENU_WINDOW_CLONE); + pCmdGroup->AppendCommand(IDM_WINDOW_NEW, WXDC_MENU_WINDOW_NEW); + pCmdGroup->AppendCommand(IDM_WINDOW_CLOSE, WXDC_MENU_WINDOW_CLOSE); + pCmdGroup->AppendCommand(IDM_WINDOW_CLOSEALL, WXDC_MENU_WINDOW_CLOSEALL); + pCmdGroup->AppendSeparator(); + // pCmdGroup->AppendCommand(IDM_WINDOW_WORKBAR, WXDC_MENU_WINDOW_WORKBAR, new wxMenu); + pCmdGroup->AppendSeparator(); + pCmdGroup->AppendCommand(IDM_WINDOW_NEXT, WXDC_MENU_WINDOW_NEXT); + pCmdGroup->AppendCommand(IDM_WINDOW_PREV, WXDC_MENU_WINDOW_PREV); + pCmdGroup->AppendSeparator(); + // pCmdGroup->AppendCommand(pMenu, WXDC_MENU_WINDOW); + CommandManager::GetCommandManager().AddCommandManager(pCmdGroup, NULL, CmdGrpType_Frame); + + // Menu Aide + pCmdGroup = new CommandGroup(WXDC_MENU_HELP); + pCmdGroup->AppendCommand(IDM_HELP_CONTENT, WXDC_MENU_HELP_CONTENT); + pCmdGroup->AppendCommand(IDM_HELP_INDEX, WXDC_MENU_HELP_INDEX); + pCmdGroup->AppendSeparator(); + pCmdGroup->AppendCommand(IDM_HELP_ABOUT, WXDC_MENU_HELP_ABOUT); + CommandManager::GetCommandManager().AddCommandManager(pCmdGroup, NULL, CmdGrpType_Help); + } Index: MDIFrame.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/MDIFrame.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MDIFrame.cpp 2 Aug 2005 12:50:54 -0000 1.7 --- MDIFrame.cpp 14 Sep 2005 14:19:11 -0000 1.8 *************** *** 224,225 **** --- 224,233 ---- } + View* MDIFrame::GetCurrentView()const + { + if(GetSelection()!=wxNOT_FOUND) + return wxDynamicCast(GetCurrentPage(), View); + else + return NULL; + } + --- NEW FILE: Layout.cpp --- (This appears to be a binary file; contents omitted.) Index: Command.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/Command.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Command.cpp 28 Aug 2005 15:57:10 -0000 1.1 --- Command.cpp 14 Sep 2005 14:19:11 -0000 1.2 *************** *** 25,28 **** --- 25,29 ---- #include <wxDevCenter/Command.h> #include <wxDevCenter/Application.h> + #include <wxDevCenter/Layout.h> #include <wx/artprov.h> *************** *** 47,53 **** m_strHelp(wxT("")), m_strIconName(wxT("")), ! m_kind(wxITEM_NORMAL), ! m_isChecked(false), ! m_isEnabled(false) { --- 48,52 ---- m_strHelp(wxT("")), m_strIconName(wxT("")), ! m_kind(wxITEM_NORMAL) { *************** *** 63,74 **** m_strHelp(cmd.m_strHelp), m_strIconName(cmd.m_strIconName), ! m_kind(cmd.m_kind), ! m_isChecked(cmd.m_isChecked), ! m_isEnabled(cmd.m_isEnabled) { } // Constructor. ! Command::Command(int iID, CommandGroup* pGroup, CommandGroup* pSubGroup, wxString strLabel, wxString strHelp, wxString strIconName, wxItemKind kind, bool isChecked, bool isEnabled): wxObject(), m_iID(iID), --- 62,71 ---- m_strHelp(cmd.m_strHelp), m_strIconName(cmd.m_strIconName), ! m_kind(cmd.m_kind) { } // Constructor. ! Command::Command(int iID, CommandGroup* pGroup, CommandGroup* pSubGroup, wxString strLabel, wxString strHelp, wxString strIconName, wxItemKind kind): wxObject(), m_iID(iID), *************** *** 78,84 **** m_strHelp(strHelp), m_strIconName(strIconName), ! m_kind(kind), ! m_isChecked(isChecked), ! m_isEnabled(isEnabled) { } --- 75,92 ---- m_strHelp(strHelp), m_strIconName(strIconName), ! m_kind(kind) ! { ! } ! ! // Direct init constructor. ! Command::Command(int iID, wxString strLabel, wxString strHelp, wxString strIconName, wxItemKind kind): ! wxObject(), ! m_iID(iID), ! m_pGroup(NULL), ! m_pSubGroup(NULL), ! m_strLabel(strLabel), ! m_strHelp(strHelp), ! m_strIconName(strIconName), ! m_kind(kind) { } *************** *** 86,92 **** // Create a menu item corrsponding to the command. ! wxMenuItem* Command::CreateMenuItem()const { ! wxMenuItem* pMI = new wxMenuItem(NULL, GetID(), GetLabel(), GetHelp(), GetKind()); if(GetSubGroup()!=NULL) { --- 94,100 ---- // Create a menu item corrsponding to the command. ! wxMenuItem* Command::CreateMenuItem(wxMenu* pMenu)const { ! wxMenuItem* pMI = new wxMenuItem(pMenu, GetID(), GetLabel(), GetHelp(), GetKind()); if(GetSubGroup()!=NULL) { *************** *** 97,102 **** if(!GetIconName().IsEmpty()) pMI->SetBitmap(wxArtProvider::GetBitmap(GetIconName())); - pMI->Enable(IsEnabled()); - pMI->Check(IsChecked()); return pMI; } --- 105,108 ---- *************** *** 106,114 **** *****/ ! CommandGroup::CommandGroup(wxString strLabel, wxString strIconName): ObjectManager<Command>(), m_strLabel(strLabel), m_strIconName(strIconName) { } --- 112,126 ---- *****/ ! CommandGroup::CommandGroup(wxString strLabel, wxString strIconName, Command* pCommands, long nbCommands): ObjectManager<Command>(), m_strLabel(strLabel), m_strIconName(strIconName) { + while(nbCommands>0) + { + Command* pCmd = &(pCommands[nbCommands--]); + pCmd->SetGroup(this); + Register(pCmd); + } } *************** *** 116,120 **** Command* CommandGroup::AppendCommand(int ID, wxString strLabel, wxString strHelp, wxString strIconName) { ! Command* pCmd = new Command(ID, this, NULL, strLabel, strHelp, strIconName, wxITEM_NORMAL, false, true); Register(pCmd); return pCmd; --- 128,132 ---- Command* CommandGroup::AppendCommand(int ID, wxString strLabel, wxString strHelp, wxString strIconName) { ! Command* pCmd = new Command(ID, this, NULL, strLabel, strHelp, strIconName, wxITEM_NORMAL); Register(pCmd); return pCmd; *************** *** 122,128 **** // Append a checkable command. ! Command* CommandGroup::AppendChechCommand(int ID, wxString strLabel, wxString strHelp, wxString strIconName, bool isChecked) { ! Command* pCmd = new Command(ID, this, NULL, strLabel, strHelp, strIconName, wxITEM_CHECK, isChecked, true); Register(pCmd); return pCmd; --- 134,140 ---- // Append a checkable command. ! Command* CommandGroup::AppendChechCommand(int ID, wxString strLabel, wxString strHelp, wxString strIconName) { ! Command* pCmd = new Command(ID, this, NULL, strLabel, strHelp, strIconName, wxITEM_CHECK); Register(pCmd); return pCmd; *************** *** 132,136 **** Command* CommandGroup::AppendSeparator() { ! Command* pCmd = new Command(wxID_SEPARATOR, this, NULL, wxT(""), wxT(""), wxT(""), wxITEM_SEPARATOR, false, true); Register(pCmd); return pCmd; --- 144,148 ---- Command* CommandGroup::AppendSeparator() { ! Command* pCmd = new Command(wxID_SEPARATOR, this, NULL, wxT(""), wxT(""), wxT(""), wxITEM_SEPARATOR); Register(pCmd); return pCmd; *************** *** 140,149 **** Command* CommandGroup::AppendSubGroup(int ID, CommandGroup* pSubGroup) { ! Command* pCmd = new Command(ID, this, pSubGroup, pSubGroup->m_strLabel, wxT(""), pSubGroup->m_strIconName, wxITEM_NORMAL, false, true); Register(pCmd); return pCmd; } ! // Create a menu corrsponding to the command. wxMenu* CommandGroup::CreateMenu()const { --- 152,161 ---- Command* CommandGroup::AppendSubGroup(int ID, CommandGroup* pSubGroup) { ! Command* pCmd = new Command(ID, this, pSubGroup, pSubGroup->m_strLabel, wxT(""), pSubGroup->m_strIconName, wxITEM_NORMAL); Register(pCmd); return pCmd; } ! // Create a menu corresponding to the command. wxMenu* CommandGroup::CreateMenu()const { *************** *** 152,167 **** for(long l=0; l<(long)GetCount(); l++) { ! pMenu->Append(Item(l).CreateMenuItem()); } return pMenu; } /***** * CommandManager *****/ CommandManager::CommandManager(): ! ObjectManager<CommandGroup>() { } --- 164,191 ---- for(long l=0; l<(long)GetCount(); l++) { ! pMenu->Append(Item(l).CreateMenuItem(pMenu)); } return pMenu; } + /***** + * SelfRegisteredCommandGroup + *****/ + + // Standard constructor. + SelfRegisteredCommandGroup::SelfRegisteredCommandGroup(wxClassInfo* pRefClassInfo, CommandGroupType Type, wxString strLabel, wxString strIconName, Command* pCommands, long nbCommands): + CommandGroup(strLabel, strIconName, pCommands, nbCommands) + { + CommandManager::GetCommandManager().AddCommandManager(this, pRefClassInfo, Type); + } /***** * CommandManager *****/ + + CommandManager CommandManager::s_CommandManager; CommandManager::CommandManager(): ! wxObject() { } *************** *** 173,177 **** pGroup->SetRefInfo(pRefClassInfo); pGroup->SetType(Type); ! Register(pGroup); return true; } --- 197,256 ---- pGroup->SetRefInfo(pRefClassInfo); pGroup->SetType(Type); ! m_CommandGroups[Type].Register(pGroup); return true; } + + // Peuple une barre de menu. + bool CommandManager::PopulateMenuBar(wxMenuBar* pMenuBar, const Layout& layout) + { + if(pMenuBar==NULL) + return false; + // Vide la barre de menu. + while(pMenuBar->GetMenuCount()>0) + delete pMenuBar->Remove(pMenuBar->GetMenuCount()-1); + + // Pour chaque type de groupe. + for(long lGroupType=0; lGroupType<CommandGroupNumber; lGroupType++) + { + switch(lGroupType) + { + case CmdGrpType_Document: + // Pour chaque groupe, ajouter si le type de document correspond. + for(long lGroup=0; lGroup<(long)m_CommandGroups[lGroupType].GetCount(); lGroup++) + { + CommandGroup &CmdGrp = m_CommandGroups[lGroupType].Item(lGroup); + if(CmdGrp.GetRefInfo()->GetClassName()==layout.GetDocClass()) + pMenuBar->Append(CmdGrp.CreateMenu(), CmdGrp.GetLabel()); + } + break; + case CmdGrpType_View: + // Pour chaque groupe, ajouter si le type de vue correspond. + for(long lGroup=0; lGroup<(long)m_CommandGroups[lGroupType].GetCount(); lGroup++) + { + CommandGroup &CmdGrp = m_CommandGroups[lGroupType].Item(lGroup); + if(CmdGrp.GetRefInfo()->GetClassName()==layout.GetViewClass()) + pMenuBar->Append(CmdGrp.CreateMenu(), CmdGrp.GetLabel()); + } + break; + case CmdGrpType_WorkBar: + case CmdGrpType_Project: + case CmdGrpType_Workspace: + /** @todo Ajouter le code d'ajout des menus des workbars.*/ + /** @todo Ajouter le code d'ajout des menus du projet.*/ + /** @todo Ajouter le code d'ajout des menus de l'espace de travail.*/ + break; + default: + // Pour chaque groupe, tout ajouter + for(long lGroup=0; lGroup<(long)m_CommandGroups[lGroupType].GetCount(); lGroup++) + { + CommandGroup &CmdGrp = m_CommandGroups[lGroupType].Item(lGroup); + pMenuBar->Append(CmdGrp.CreateMenu(), CmdGrp.GetLabel()); + } + break; + } + } + + + return true; + } + |