Update of /cvsroot/anyedit/AnyEditv2 In directory sc8-pr-cvs1:/tmp/cvs-serv27703 Modified Files: AnyEdit.cpp AnyEdit.dsp AnyEdit.h AnyEdit.rc MainFrm.cpp MainFrm.h Plugin.cpp Plugin.h resource.h Added Files: AEPlugin.cpp AEPlugin.h Log Message: Added plugin support. Plugins can expose there own menus and accelerators --- NEW FILE: AEPlugin.cpp --- #include "stdafx.h" #include "AnyEdit.h" #include "AEPlugin.h" typedef int (*PLUGIN_INIT)(CPlugin *); typedef int (*PLUGIN_MENU)(CPlugin *,UINT id); void AEPlugin::InitPlugin(CPlugin * plugin) { PLUGIN_INIT pluginit; if(hinst) { pluginit = (PLUGIN_INIT) GetProcAddress(hinst,"plugin_init"); if(pluginit) pluginit(plugin); } if(nextPlugin) { nextPlugin->InitPlugin(plugin); } } void AEPlugin::ProcessEvent(CPlugin * plugin,int event_id) { } void AEPlugin::ProcessMenuClick(CPlugin * plugin,UINT uid) { PLUGIN_MENU pluginit; if(hinst) { pluginit = (PLUGIN_MENU) GetProcAddress(hinst,"OnMenuClick"); if(pluginit) pluginit(plugin,uid); } if(nextPlugin) { nextPlugin->ProcessMenuClick(plugin,uid); } } void AEPlugin::ExitPlugin(CPlugin * plugin) { if(nextPlugin) { nextPlugin->ExitPlugin(plugin); delete nextPlugin; } PLUGIN_INIT pluginit; if(hinst) { pluginit = (PLUGIN_INIT) GetProcAddress(hinst,"plugin_exit"); if(pluginit) pluginit(plugin); } } --- NEW FILE: AEPlugin.h --- #ifndef AEPLUGIN_H #define AEPLUGIN_H #include "Plugin.h" class AEPlugin { public: HINSTANCE hinst; // The loaded instance from the library AEPlugin * nextPlugin; // The next plugin in the chain of plugins CString m_pluginName; // Get this name from the plugin itself public: AEPlugin() { nextPlugin=NULL; } void InitPlugin(CPlugin * plugin); void ProcessEvent(CPlugin * plugin,int event_id); void ProcessMenuClick(CPlugin * plugin,UINT uid); void ExitPlugin(CPlugin * plugin); }; #endif Index: AnyEdit.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEdit.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** AnyEdit.cpp 17 Jul 2003 11:32:15 -0000 1.27 --- AnyEdit.cpp 23 Jul 2003 09:41:34 -0000 1.28 *************** *** 51,55 **** #endif - ///////////////////////////////////////////////////////////////////////////// // CAnyEditApp --- 51,54 ---- *************** *** 84,87 **** --- 83,87 ---- m_ClassViewParserThread=NULL; m_bLastParsedFileInCurrentProject=false; + pluginHead=NULL; } *************** *** 189,193 **** if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; ! EnableShellOpen(); m_pMainWnd = pMainFrame; --- 189,193 ---- if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; ! EnableShellOpen(); m_pMainWnd = pMainFrame; *************** *** 199,203 **** instanceChecker.TrackFirstInstanceRunning(); } ! // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; --- 199,203 ---- instanceChecker.TrackFirstInstanceRunning(); } ! LoadPlugins(); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; *************** *** 217,221 **** LoadLanguageExtensions(); - // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow); --- 217,220 ---- *************** *** 241,245 **** _CrtDumpMemoryLeaks(); ! return TRUE; } --- 240,244 ---- _CrtDumpMemoryLeaks(); ! return TRUE; } *************** *** 360,365 **** m_ContextMenuManager.AddMenu (_T("File View - File"),IDR_POPUP_FV_FILE); m_ContextMenuManager.AddMenu (_T("Clip View"),IDR_POPUP_CV); ! m_ContextMenuManager.LoadState (strMenuEntry ! ); } --- 359,363 ---- m_ContextMenuManager.AddMenu (_T("File View - File"),IDR_POPUP_FV_FILE); m_ContextMenuManager.AddMenu (_T("Clip View"),IDR_POPUP_CV); ! m_ContextMenuManager.LoadState (strMenuEntry); } *************** *** 376,381 **** += KEYBOARD_ENTRY; ! m_KeyboardManager.SaveState (strKbdEntry ! ); CString strMouseEntry --- 374,378 ---- += KEYBOARD_ENTRY; ! m_KeyboardManager.SaveState (strKbdEntry); CString strMouseEntry *************** *** 384,389 **** += MOUSE_ENTRY; ! m_MouseManager.SaveState (strMouseEntry ! ); CString strMenuEntry --- 381,385 ---- += MOUSE_ENTRY; ! m_MouseManager.SaveState (strMouseEntry); CString strMenuEntry *************** *** 392,397 **** += CONTEXT_MENU_ENTRY; ! m_ContextMenuManager.SaveState (strMenuEntry ! ); --- 388,392 ---- += CONTEXT_MENU_ENTRY; ! m_ContextMenuManager.SaveState (strMenuEntry); *************** *** 424,428 **** { // TODO: Add your specialized code here and/or call the base class ! //unreg codemax control HtmlHelp( NULL, --- 419,423 ---- { // TODO: Add your specialized code here and/or call the base class ! UnloadPlugins(); HtmlHelp( NULL, *************** *** 440,444 **** m_ClassViewParserThread=NULL; ! return CWinApp::ExitInstance(); } --- 435,439 ---- m_ClassViewParserThread=NULL; ! return CWinApp::ExitInstance(); } *************** *** 1428,1429 **** --- 1423,1465 ---- alphabetic = m_reg.GetProfileInt(_T("Preferences"),_T("EnableAlphabetic"),0); } + + void CAnyEditApp::LoadPlugins() + { + + CString app_path = theApp.GetAppPath(); + CStringArray plugins; + app_path+= _T("Plugins"); + msc.GetFilesInFolder(app_path,"*.dll",plugins); + CString plugin_path; + for(int i=0;i<plugins.GetSize();i++) + { + AEPlugin * temp_plug = new AEPlugin; + plugin_path = app_path + "\\"; + plugin_path += plugins.GetAt(i); + temp_plug->hinst = LoadLibrary(plugin_path); + temp_plug->m_pluginName = plugins.GetAt(i); + temp_plug->nextPlugin= pluginHead; + pluginHead = temp_plug; + } + + if(pluginHead) + { + pluginHead->InitPlugin(&plugin); + } + + } + + void CAnyEditApp::UnloadPlugins() + { + if(pluginHead) + { + pluginHead->ExitPlugin(&plugin); + delete pluginHead; + } + } + + void CAnyEditApp::PluginMenuClicked(UINT id) + { + pluginHead->ProcessMenuClick(&plugin,id); + } + Index: AnyEdit.dsp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEdit.dsp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** AnyEdit.dsp 18 Jul 2003 19:05:36 -0000 1.18 --- AnyEdit.dsp 23 Jul 2003 09:41:34 -0000 1.19 *************** *** 344,347 **** --- 344,351 ---- # Begin Source File + SOURCE=.\AEPlugin.cpp + # End Source File + # Begin Source File + SOURCE=.\AutoComp.cpp # End Source File *************** *** 673,676 **** --- 677,684 ---- # PROP Default_Filter ".h" + # Begin Source File + + SOURCE=.\AEPlugin.h + # End Source File # Begin Source File Index: AnyEdit.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEdit.h,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** AnyEdit.h 9 May 2003 08:53:56 -0000 1.23 --- AnyEdit.h 23 Jul 2003 09:41:34 -0000 1.24 *************** *** 32,35 **** --- 32,37 ---- #include "Misc.h" #include "TagList.h" + #include "AEPlugin.h" + #include "Plugin.h" class CAnyEditApp : public CDumpHandleApp *************** *** 97,102 **** BOOL LockTagList(); void UnlockTagList(); ! CComboBox * findbox; ! CComboBox * funcbox; BOOL CheckModification() { --- 99,105 ---- BOOL LockTagList(); void UnlockTagList(); ! void LoadPlugins(); ! void UnloadPlugins(); ! void PluginMenuClicked(UINT id); BOOL CheckModification() { *************** *** 137,140 **** --- 140,146 ---- } + public: + CComboBox * findbox; + CComboBox * funcbox; protected: *************** *** 155,158 **** --- 161,166 ---- int lastsearchflags; BOOL lastsearchdirection; + AEPlugin * pluginHead; + CPlugin plugin; protected: Index: AnyEdit.rc =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEdit.rc,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** AnyEdit.rc 18 Jul 2003 19:05:36 -0000 1.23 --- AnyEdit.rc 23 Jul 2003 09:41:34 -0000 1.24 *************** *** 153,160 **** MENUITEM "&Customize...", ID_VIEW_CUSTOMIZE END - POPUP "Plugins" - BEGIN - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN1 - END POPUP "&Help" BEGIN --- 153,156 ---- *************** *** 465,472 **** MENUITEM "&Customize...", ID_VIEW_CUSTOMIZE END - POPUP "Plugins" - BEGIN - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN1 - END POPUP "&Window" BEGIN --- 461,464 ---- *************** *** 910,917 **** MENUITEM "&Customize...", ID_VIEW_CUSTOMIZE END - POPUP "Plugins" - BEGIN - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN1 - END POPUP "&Help" BEGIN --- 902,905 ---- *************** *** 922,957 **** MENUITEM SEPARATOR MENUITEM "&About AnyEdit...", ID_APP_ABOUT - END - END - - IDR_POPUP_PLUGINS MENU DISCARDABLE - BEGIN - POPUP "<PLUGINS>" - BEGIN - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN1 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN2 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN3 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN4 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN5 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN6 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN7 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN8 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN9 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN10 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN11 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN12 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN13 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN14 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN15 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN16 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN17 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN18 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN19 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN20 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN21 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN22 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN23 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN24 - MENUITEM "<plugin1>", ID_PLUGINS_PLUGIN25 END END --- 910,913 ---- Index: MainFrm.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/MainFrm.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** MainFrm.cpp 18 Jul 2003 19:05:36 -0000 1.24 --- MainFrm.cpp 23 Jul 2003 09:41:34 -0000 1.25 *************** *** 58,62 **** #endif - typedef int (*ENTRY_FUNCTION)(CPlugin *); IMPLEMENT_MSG(UPM_FINISHED) --- 58,61 ---- *************** *** 121,127 **** ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_USER_TOOLBAR1, ID_VIEW_USER_TOOLBAR1 + iMaxUserToolbars - 1, OnUpdateToolsViewUserToolbar) ON_COMMAND_EX_RANGE(ID_USER_TOOL1, ID_USER_TOOL10, OnSelectedUserTools) - ON_COMMAND_EX_RANGE(ID_PLUGINS_PLUGIN1, ID_PLUGINS_PLUGIN25, OnSelectedPlugin) ON_UPDATE_COMMAND_UI_RANGE(ID_USER_TOOL1, ID_USER_TOOL10, OnUpdateUserTools) ON_COMMAND_EX_RANGE(ID_CUR_TOOL1, ID_CUR_TOOL5, OnCurrentUserTools) ON_REGISTERED_MESSAGE(BCGM_CUSTOMIZEHELP, OnHelpCustomizeToolbars) END_MESSAGE_MAP() --- 120,126 ---- ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_USER_TOOLBAR1, ID_VIEW_USER_TOOLBAR1 + iMaxUserToolbars - 1, OnUpdateToolsViewUserToolbar) ON_COMMAND_EX_RANGE(ID_USER_TOOL1, ID_USER_TOOL10, OnSelectedUserTools) ON_UPDATE_COMMAND_UI_RANGE(ID_USER_TOOL1, ID_USER_TOOL10, OnUpdateUserTools) ON_COMMAND_EX_RANGE(ID_CUR_TOOL1, ID_CUR_TOOL5, OnCurrentUserTools) + ON_COMMAND_EX_RANGE(50000, 55000, OnSelectedPluginMenu) ON_REGISTERED_MESSAGE(BCGM_CUSTOMIZEHELP, OnHelpCustomizeToolbars) END_MESSAGE_MAP() *************** *** 203,217 **** CBCGToolBar::AddToolBarForImageCollection (IDR_USERMENUS2); ! if (!m_wndMenuBar.Create (this)) ! { TRACE0("Failed to create menubar\n"); return -1; // fail to create } ! m_wndMenuBar.SetBarStyle(m_wndMenuBar.GetBarStyle() | CBRS_SIZE_DYNAMIC); ! m_wndMenuBar.SetHotBorder(TRUE); m_wndMenuBar.SetHotTextColor(8388608); if (!m_wndFullScreen.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || --- 202,216 ---- CBCGToolBar::AddToolBarForImageCollection (IDR_USERMENUS2); ! if (!m_wndMenuBar.Create (this)) ! { TRACE0("Failed to create menubar\n"); return -1; // fail to create } ! m_wndMenuBar.SetBarStyle(m_wndMenuBar.GetBarStyle() | CBRS_SIZE_DYNAMIC); m_wndMenuBar.SetHotBorder(TRUE); m_wndMenuBar.SetHotTextColor(8388608); + if (!m_wndFullScreen.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || *************** *** 328,336 **** //deepwashere - have commented the next line ;( //m_wndToolBar.LoadState (strControlBarRegEntry); ! m_wndMenuBar.LoadState (strControlBarRegEntry ! ); ! // TODO: add LoadState for all your predefined toolbars here ! ////m_wndToolbarBookMark.LoadState (strControlBarRegEntry); //m_wndToolbarFormat.LoadState (strControlBarRegEntry); //---------------------------- --- 327,334 ---- //deepwashere - have commented the next line ;( //m_wndToolBar.LoadState (strControlBarRegEntry); ! //m_wndMenuBar.LoadState (strControlBarRegEntry); ! // TODO: add LoadState for all your predefined toolbars here ! //m_wndToolbarBookMark.LoadState (strControlBarRegEntry); //m_wndToolbarFormat.LoadState (strControlBarRegEntry); //---------------------------- *************** *** 343,348 **** //------------------------------------- CDockState dockState; ! dockState.LoadState (strControlBarRegEntry ! ); if (IsDockStateValid (dockState)) --- 341,345 ---- //------------------------------------- CDockState dockState; ! dockState.LoadState (strControlBarRegEntry); if (IsDockStateValid (dockState)) *************** *** 415,433 **** } - if (pMenuPopup->GetMenuBar ()->CommandToIndex (ID_PLUGINS_PLUGIN1) >= 0) - { - pMenuPopup->RemoveAllItems (); - - CMenu menu; - VERIFY(menu.LoadMenu (IDR_POPUP_PLUGINS)); - - CMenu* pPopup = menu.GetSubMenu(0); - ASSERT(pPopup != NULL); - - LoadPluginMenus (*pPopup); - pMenuPopup->GetMenuBar ()->ImportFromMenu (*pPopup, TRUE); - } - - if (pMenuPopup->GetMenuBar ()->CommandToIndex (ID_FILE_RECENTWORKSPACES_WS1) >= 0) { --- 412,415 ---- *************** *** 536,563 **** } - void CMainFrame::LoadPluginMenus(CMenu &popUp) - { - CString app_path = theApp.GetAppPath(); - CStringArray plugins; - app_path+= _T("Plugins"); - msc.GetFilesInFolder(app_path,"*.dll",plugins); - - int y=plugins.GetSize(); - int pluginPos = 0; - int ccnt = ID_PLUGINS_PLUGIN1; - for(int i=0;i<y;i++) - { - popUp.ModifyMenu(ccnt,MF_STRING,ccnt,plugins.GetAt(i).Left(plugins.GetAt(i).GetLength()-4)); - ccnt++; - pluginPos++; - } - - for(int xy=pluginPos;xy<26;xy++) - { - popUp.DeleteMenu(pluginPos,MF_BYPOSITION); - } - - } - void CMainFrame::LoadToolMenus(CMenu &popUp) { --- 518,521 ---- *************** *** 1146,1171 **** } - void CMainFrame::OnSelectedPlugin(UINT id) - { - CString app_path = theApp.GetAppPath(); - CStringArray plugins; - app_path+= _T("Plugins"); - msc.GetFilesInFolder(app_path,"*.dll",plugins); - int position = ID_PLUGINS_PLUGIN1 - id; - app_path+="\\"; - app_path+= plugins.GetAt(-position); - ENTRY_FUNCTION PluginFunction = NULL; - HINSTANCE hinst = LoadLibrary(app_path); - if(hinst) - { - PluginFunction = (ENTRY_FUNCTION)GetProcAddress(hinst,"EntryFunction"); - CPlugin plugin; - if(PluginFunction) - PluginFunction(&plugin); - FreeLibrary(hinst); - } - - } - void CMainFrame::OnSelectedUserTools(UINT id) { --- 1104,1107 ---- *************** *** 1591,1594 **** --- 1527,1535 ---- { CMDIFrameWnd::OnSetFocus(pOldWnd); + } + + void CMainFrame::OnSelectedPluginMenu(UINT id) + { + theApp.PluginMenuClicked(id); } Index: MainFrm.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/MainFrm.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** MainFrm.h 18 Jul 2003 19:05:36 -0000 1.18 --- MainFrm.h 23 Jul 2003 09:41:34 -0000 1.19 *************** *** 24,28 **** #define AEM_OPENFILE ( WM_USER + 6000) ! class CMainFrame : public CMDIFrameWnd { DECLARE_DYNAMIC(CMainFrame) --- 24,28 ---- #define AEM_OPENFILE ( WM_USER + 6000) ! class CMainFrame : public CBCGMDIFrameWnd { DECLARE_DYNAMIC(CMainFrame) *************** *** 34,39 **** void SaveSettingsToRegistry(); void LoadToolMenus(CMenu &popUp); ! void LoadPluginMenus(CMenu &popUp); ! void LoadRecentMenus(CMenu &popUp); void LoadCurrentToolMenu(CMenu &popUp,LPCSTR curLang); // Attributes --- 34,38 ---- void SaveSettingsToRegistry(); void LoadToolMenus(CMenu &popUp); ! void LoadRecentMenus(CMenu &popUp); void LoadCurrentToolMenu(CMenu &popUp,LPCSTR curLang); // Attributes *************** *** 90,96 **** BOOL LockTagList(); void UnlockTagList(); - - protected: // control bar embedded members CBCGMenuBar m_wndMenuBar; CStatusBar m_wndStatusBar; CBCGToolBar m_wndToolbarFormat; --- 89,95 ---- BOOL LockTagList(); void UnlockTagList(); CBCGMenuBar m_wndMenuBar; + protected: // control bar embedded members + CStatusBar m_wndStatusBar; CBCGToolBar m_wndToolbarFormat; *************** *** 159,165 **** afx_msg void OnUpdateToolsViewUserToolbar (CCmdUI* pCmdUI); afx_msg void OnUpdateUserTools (CCmdUI* pCmdUI); ! afx_msg void OnSelectedPlugin(UINT id); ! afx_msg void OnSelectedUserTools(UINT id); afx_msg void OnCurrentUserTools(UINT id); afx_msg LRESULT OnToolbarContextMenu(WPARAM,LPARAM); afx_msg LRESULT OnHelpCustomizeToolbars(WPARAM wp, LPARAM lp); --- 158,164 ---- afx_msg void OnUpdateToolsViewUserToolbar (CCmdUI* pCmdUI); afx_msg void OnUpdateUserTools (CCmdUI* pCmdUI); ! afx_msg void OnSelectedUserTools(UINT id); afx_msg void OnCurrentUserTools(UINT id); + afx_msg void OnSelectedPluginMenu(UINT id); afx_msg LRESULT OnToolbarContextMenu(WPARAM,LPARAM); afx_msg LRESULT OnHelpCustomizeToolbars(WPARAM wp, LPARAM lp); Index: Plugin.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/Plugin.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Plugin.cpp 18 Jul 2003 19:05:36 -0000 1.1 --- Plugin.cpp 23 Jul 2003 09:41:34 -0000 1.2 *************** *** 2,5 **** --- 2,6 ---- #include "AnyEdit.h" #include "Plugin.h" + #include "MainFrm.h" void CPlugin::OpenUrl(LPCSTR url) *************** *** 11,13 **** --- 12,279 ---- { return theApp.GetAppPath(); + } + + BOOL CPlugin::MergeMenu(CMenu * pMenuDestination, const CMenu * pMenuAdd, bool bTopLevel /*=false*/) + { + // Abstract: + // Merges two menus. + // + // Parameters: + // pMenuDestination - [in, retval] destination menu handle + // pMenuAdd - [in] menu to merge + // bTopLevel - [in] indicator for special top level behavior + // + // Return value: + // <false> in case of error. + // + // Comments: + // This function calles itself recursivley. If bTopLevel is set to true, + // we append popups at top level or we insert before <Window> or <Help>. + + // get the number menu items in the menus + int iMenuAddItemCount = pMenuAdd->GetMenuItemCount(); + int iMenuDestItemCount = pMenuDestination->GetMenuItemCount(); + + // if there are no items return + if( iMenuAddItemCount == 0 ) + return true; + + // if we are not at top level and the destination menu is not empty + // -> we append a seperator + if( !bTopLevel && iMenuDestItemCount > 0 ) + pMenuDestination->AppendMenu(MF_SEPARATOR); + + // iterate through the top level of + for( int iLoop = 0; iLoop < iMenuAddItemCount; iLoop++ ) + { + // get the menu string from the add menu + CString sMenuAddString; + pMenuAdd->GetMenuString( iLoop, sMenuAddString, MF_BYPOSITION ); + + // try to get the submenu of the current menu item + CMenu* pSubMenu = pMenuAdd->GetSubMenu(iLoop); + + // check if we have a sub menu + if (!pSubMenu) + { + // normal menu item + // read the source and append at the destination + UINT nState = pMenuAdd->GetMenuState( iLoop, MF_BYPOSITION ); + UINT nItemID = pMenuAdd->GetMenuItemID( iLoop ); + + if( pMenuDestination->AppendMenu( nState, nItemID, sMenuAddString )) + { + // menu item added, don't forget to correct the item count + iMenuDestItemCount++; + } + else + { + TRACE( "MergeMenu: AppendMenu failed!\n" ); + return false; + } + } + else + { + // create or insert a new popup menu item + + // default insert pos is like ap + int iInsertPosDefault = -1; + + // if we are at top level merge into existing popups rather than + // creating new ones + if( bTopLevel ) + { + ASSERT( sMenuAddString != "&?" && sMenuAddString != "?" ); + CString sAdd( sMenuAddString ); + sAdd.Remove('&'); // for comparison of menu items supress '&' + bool bAdded = false; + + // try to find existing popup + for( int iLoop1 = 0; iLoop1 < iMenuDestItemCount; iLoop1++ ) + { + // get the menu string from the destination menu + CString sDest; + pMenuDestination->GetMenuString( iLoop1, sDest, MF_BYPOSITION ); + sDest.Remove( '&' ); // for a better compare (s.a.) + + if( sAdd == sDest ) + { + // we got a hit -> merge the two popups + // try to get the submenu of the desired destination menu item + CMenu* pSubMenuDest = pMenuDestination->GetSubMenu( iLoop1 ); + + if( pSubMenuDest ) + { + // merge the popup recursivly and continue with outer for loop + if( !MergeMenu( pSubMenuDest, pSubMenu )) + return false; + + bAdded = true; + break; + } + } + + // alternativ insert before <Window> or <Help> + if( iInsertPosDefault == -1 && ( sDest == "Window" || sDest == "?" || sDest == "Help" )) + iInsertPosDefault = iLoop1; + + } + + if( bAdded ) + { + // menu added, so go on with loop over pMenuAdd's top level + continue; + } + } + + // if the top level search did not find a position append the menu + if( iInsertPosDefault == -1 ) + iInsertPosDefault = pMenuDestination->GetMenuItemCount(); + + // create a new popup and insert before <Window> or <Help> + CMenu NewPopupMenu; + if( !NewPopupMenu.CreatePopupMenu() ) + { + TRACE( "MergeMenu: CreatePopupMenu failed!\n" ); + return false; + } + + // merge the new popup recursivly + if( !MergeMenu( &NewPopupMenu, pSubMenu )) + return false; + + // insert the new popup menu into the destination menu + HMENU hNewMenu = NewPopupMenu.GetSafeHmenu(); + + if( pMenuDestination->InsertMenu( iInsertPosDefault, + MF_BYPOSITION | MF_POPUP | MF_ENABLED, + (UINT)hNewMenu, sMenuAddString )) + { + // don't forget to correct the item count + iMenuDestItemCount++; + } + else + { + TRACE( "MergeMenu: InsertMenu failed!\n" ); + return false; + } + + // don't destroy the new menu + NewPopupMenu.Detach(); + } + } + + return true; + } + + + BOOL CPlugin::MergeAccelerator(HACCEL& hDestination, HACCEL hToMerge) + { + // this function merges the hToMerge accelerator table with that of hDestination + ASSERT(hToMerge) ; + + int original_count = 0 ; + int add_count ; + if (hDestination != NULL) + { + // we have an existing table + original_count = CopyAcceleratorTable(hDestination, NULL, 0) ; + } + add_count = CopyAcceleratorTable(hToMerge, NULL, 0) ; + if (add_count > 0) + { + ACCEL *pElements = new ACCEL[original_count + add_count] ; + // copy in the existing data if it exists + if (hDestination != NULL) + CopyAcceleratorTable(hDestination, pElements, original_count) ; + // now add in the merge accelerator + CopyAcceleratorTable(hToMerge, &pElements[original_count], add_count) ; + HACCEL hNew = CreateAcceleratorTable(pElements, original_count + add_count) ; + DestroyAcceleratorTable(hDestination) ; // because it gets replaced + hDestination = hNew ; + delete []pElements ; + return true ; + } + return false ; + } + + + BOOL CPlugin::AddAccelerator(HACCEL hToMerge,DWORD mergewith) + { + if((mergewith & ANYEDIT_MAIN)==ANYEDIT_MAIN) + { + CMultiDocTemplate dummy(1, NULL, NULL, NULL) ; + dummy.m_hAccelTable = ((CMDIFrameWnd*)theApp.m_pMainWnd)->m_hAccelTable ; + MergeAccelerator(((CMDIFrameWnd*)theApp.m_pMainWnd)->m_hAccelTable ,hToMerge) ; + dummy.m_hAccelTable = NULL ; // stop it being released + } + + POSITION pos = theApp.GetFirstDocTemplatePosition() ; + if(pos) + { + CMultiDocTemplate *pTemplate = (CMultiDocTemplate*)theApp.GetNextDocTemplate(pos); + if((mergewith & ANYEDIT_DOCUMENT)==ANYEDIT_DOCUMENT) + { + if(pTemplate) + MergeAccelerator(pTemplate->m_hAccelTable,hToMerge); + } + } + + if(pos) + { + CMultiDocTemplate *pTemplate = (CMultiDocTemplate*)theApp.GetNextDocTemplate(pos); + if((mergewith & ANYEDIT_BROWSER)==ANYEDIT_BROWSER ) + { + if(pTemplate) + MergeAccelerator(pTemplate->m_hAccelTable,hToMerge); + } + } + + return TRUE; + } + + + BOOL CPlugin::AddMenu(const CMenu * pMenuAdd, DWORD mergewith, bool bTopLevel /*= false*/) + { + + if((mergewith & ANYEDIT_MAIN)==ANYEDIT_MAIN) + { + CMultiDocTemplate dummy(1,NULL,NULL,NULL); + dummy.m_hMenuShared= ((CMainFrame *)theApp.m_pMainWnd)->m_hMenuDefault; + CMenu ddmenu; + ddmenu.Attach(dummy.m_hMenuShared); + MergeMenu(&ddmenu,pMenuAdd,bTopLevel); + ddmenu.Detach(); + dummy.m_hMenuShared = NULL; + ((CMainFrame *)theApp.m_pMainWnd)->m_wndMenuBar.CreateFromMenu(((CMainFrame *)theApp.m_pMainWnd)->m_hMenuDefault,TRUE,TRUE); + } + + + POSITION pos = theApp.GetFirstDocTemplatePosition(); + if(pos) + { + CMultiDocTemplate * temp = (CMultiDocTemplate *)theApp.GetNextDocTemplate(pos); + if((mergewith & ANYEDIT_DOCUMENT)==ANYEDIT_DOCUMENT) + { + CMenu docMenu ; + docMenu.Attach(temp->m_hMenuShared) ; + MergeMenu(&docMenu,pMenuAdd,bTopLevel); + docMenu.Detach(); + } + } + + if(pos) + { + CMultiDocTemplate * temp = (CMultiDocTemplate *)theApp.GetNextDocTemplate(pos); + if((mergewith & ANYEDIT_BROWSER)==ANYEDIT_BROWSER) + { + CMenu docMenu ; + docMenu.Attach(temp->m_hMenuShared) ; + MergeMenu(&docMenu,pMenuAdd,bTopLevel); + docMenu.Detach(); + } + } + + + return TRUE; } Index: Plugin.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/Plugin.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Plugin.h 18 Jul 2003 19:05:36 -0000 1.1 --- Plugin.h 23 Jul 2003 09:41:34 -0000 1.2 *************** *** 2,11 **** #define PLUGIN_H class CPlugin { public: virtual void OpenUrl(LPCSTR url); - virtual LPCSTR GetAppPath(); }; --- 2,29 ---- #define PLUGIN_H + // Add menu or accelerator to the following windows + #define ANYEDIT_MAIN 1 + #define ANYEDIT_DOCUMENT 2 + #define ANYEDIT_BROWSER 4 + class CPlugin { + protected: + virtual BOOL MergeMenu(CMenu * pMenuDestination, const CMenu * pMenuAdd, bool bTopLevel =TRUE); + virtual BOOL MergeAccelerator(HACCEL& hDestination, HACCEL hToMerge); + public: + // Add menu for merging with Anyedit + virtual BOOL AddMenu(const CMenu * pMenuAdd,DWORD mergewith=ANYEDIT_MAIN|ANYEDIT_DOCUMENT|ANYEDIT_BROWSER,bool bTopLevel = TRUE); + + // Add accelerator for merging with AnyEdit + virtual BOOL AddAccelerator(HACCEL hToMerge,DWORD mergewith=ANYEDIT_MAIN|ANYEDIT_DOCUMENT|ANYEDIT_BROWSER); + + // Open the following URL in a new browser window virtual void OpenUrl(LPCSTR url); + // Get the application path + virtual LPCSTR GetAppPath(); + }; Index: resource.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/resource.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** resource.h 18 Jul 2003 19:05:36 -0000 1.15 --- resource.h 23 Jul 2003 09:41:34 -0000 1.16 *************** *** 423,451 **** #define ID_CONFIGURE_CURRENTDOCUMENT_BOOKMARKMARGIN 33041 #define ID_CONFIGURE_CURRENTDOCUMENT_FOLDMARGIN 33044 - #define ID_PLUGINS_PLUGIN1 33045 - #define ID_PLUGINS_PLUGIN2 33046 - #define ID_PLUGINS_PLUGIN3 33047 - #define ID_PLUGINS_PLUGIN4 33048 - #define ID_PLUGINS_PLUGIN5 33049 - #define ID_PLUGINS_PLUGIN6 33050 - #define ID_PLUGINS_PLUGIN7 33051 - #define ID_PLUGINS_PLUGIN8 33052 - #define ID_PLUGINS_PLUGIN9 33053 - #define ID_PLUGINS_PLUGIN10 33054 - #define ID_PLUGINS_PLUGIN11 33055 - #define ID_PLUGINS_PLUGIN12 33056 - #define ID_PLUGINS_PLUGIN13 33057 - #define ID_PLUGINS_PLUGIN14 33058 - #define ID_PLUGINS_PLUGIN15 33059 - #define ID_PLUGINS_PLUGIN16 33060 - #define ID_PLUGINS_PLUGIN17 33061 - #define ID_PLUGINS_PLUGIN18 33062 - #define ID_PLUGINS_PLUGIN19 33063 - #define ID_PLUGINS_PLUGIN20 33064 - #define ID_PLUGINS_PLUGIN21 33065 - #define ID_PLUGINS_PLUGIN22 33066 - #define ID_PLUGINS_PLUGIN23 33067 - #define ID_PLUGINS_PLUGIN24 33068 - #define ID_PLUGINS_PLUGIN25 33069 #define ID_OUTPUT_CLEAR 57632 #define ID_OUTPUT_COPY 57634 --- 423,426 ---- |