oilmenus.cpp

Go to the documentation of this file.
00001 // $Id: oilmenus.cpp 1667 2006-08-04 11:40:10Z luke $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 /********************************************************************************************
00100 
00101     oilmenus.cpp - Responsibilities include menu initialisation and deinitialisation as well 
00102     as updating menu states and performing menu commands.
00103 
00104 ********************************************************************************************/
00105 
00106 
00107          
00108 #include "camtypes.h"
00109 #include "oilmenus.h"
00110 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 #include "menupref.h"
00112 //#include "opdesc.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00114 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 //#include "mario.h" 
00116 #include "contmenu.h"
00117 #include "menuops.h"
00118 
00119 #include "plugmngr.h"   // PlugInManager
00120 //#include "app.h"      // GetApplication() - in camtypes.h [AUTOMATICALLY REMOVED]
00121 #include "camframe.h"   // GetMainFrame()
00122 #include "camelot.h"    // wxGetApp
00123 
00124 DECLARE_SOURCE("$Revision: 1667 $");  
00125 
00126 // This wasn't here before 7/3/97
00127 // We want better memory tracking
00128 #define new CAM_DEBUG_NEW
00129 
00130 MenuItem* CamelotDefMenu;               //Platform-Independent Menus
00131 MenuItem* CamelotMDIMenu;
00132 MenuItem* CamelotContextMenu;
00133 
00134 wxCamMenuBar*   WinDefMenu;                     //Windows Menus
00135 wxCamMenuBar*   WinMDIMenu;
00136 wxMenu*         WinContextMenu;
00137 
00138 /********************************************************************************************
00139 
00140 >   MenuItem *SetupDefaultMenu()
00141 
00142     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00143     Created:    30/6/93
00144     Inputs:     None.
00145     Outputs:    None.
00146     Returns:    MenuItem - A platform independent mainframe menu.
00147     Purpose:    Creates the default mainframe menu for an MDI type interface.
00148     Errors:     None
00149     SeeAlso:    OilMenus
00150     SeeAlso:    MenuItem        
00151     SeeAlso:    SetupSharedMenu()
00152     SeeAlso:    GetMenuPreferences()
00153 
00154 ********************************************************************************************/
00155 
00156 MenuItem *SetupDefaultMenu()
00157 {
00158     MenuItem* pMenu = GetMenuPreferences(_R(IDM_DEFAULT_MENU));
00159     return pMenu;
00160 }                               
00161 
00162 /********************************************************************************************
00163 
00164 >   MenuItem *SetupSharedMenu()
00165 
00166     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00167     Created:    30/6/93
00168     Inputs:     None.
00169     Outputs:    None.
00170     Returns:    MenuItem - A platform independent MDI menu.
00171     Purpose:    Creates a MDI type shared menu.
00172     Errors:     None
00173     SeeAlso:    OilMenus
00174     SeeAlso:    MenuItem
00175     SeeAlso:    SetupDefaultMenu()
00176     SeeAlso:    GetMenuPreferences()
00177 
00178 ********************************************************************************************/
00179 
00180 MenuItem *SetupSharedMenu()
00181 {
00182     MenuItem* pMenu = GetMenuPreferences(_R(IDM_SHARED_MENU));
00183     return pMenu;
00184 }
00185 
00186 /********************************************************************************************
00187 
00188 >   wxMenuBar *ConvertToWinMenu(MenuItem *GroupSubMenu)
00189 
00190     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00191     Created:    30/6/93
00192     Inputs:     MenuItem - A platform-independent menu.
00193     Outputs:    None.
00194     Returns:    wxMenu - Windows MFC-type menu object.
00195     Purpose:    Converts from a platform-independent menu system into a Windows specific one.
00196     Errors:     None
00197     SeeAlso:    OilMenus
00198     SeeAlso:    MenuItem
00199     SeeAlso:    CreatePopup()
00200 
00201 ********************************************************************************************/
00202 /* 
00203 Technical Notes:
00204 
00205 ConvertToWinMenu iterates through the MenuItem tree structure creating new wxMenu objects for
00206 each node. The recursive function CreatePopup() is called for each group MenuItem (popup) 
00207 found in the tree. The function assumes that all menuItems on the MenuBar are group MenuItems
00208 (popups)
00209 
00210 ********************************************************************************************/
00211 
00212 wxCamMenuBar *ConvertToWinMenu(MenuItem *GroupSubMenu)
00213 {                  
00214     wxCamMenuBar*   WinMenu = new wxCamMenuBar;         // Top Level Menu - Menu Bar
00215     MenuItem*       SubMenu;                            // Sub Menu Iterator
00216                                 
00217     SubMenu = GroupSubMenu->GetFirstMenuItem();                           
00218     
00219     while (SubMenu != NULL)                         // Assumes that all MenuItems on the 
00220     {                                               // MenuBar are Group MenuItems
00221         wxMenu*     pSubMenu = CreatePopup( SubMenu );
00222         if (pSubMenu)
00223         {
00224             wxString sName((TCHAR*)SubMenu->GetMenuText());
00225             if (!WinMenu->Append( pSubMenu, sName ))
00226             {
00227                 TRACEUSER("luke", _T("Append failed\n"));
00228             }
00229         }
00230         SubMenu = GroupSubMenu->GetNextMenuItem(SubMenu);
00231     } 
00232 
00233     return WinMenu;
00234 }
00235 
00236 /********************************************************************************************
00237 
00238 >   wxMenu *CreatePopup(MenuItem *CamSubMenu)
00239 
00240     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00241     Created:    30/6/93
00242     Inputs:     MenuItem - A platform-independent menu (popup).
00243     Outputs:    None.
00244     Returns:    wxMenu - Windows MFC-type menu object.
00245     Purpose:    Converts from a platform-independent menu into a Windows specific one.
00246     Errors:     None
00247     Scope:      Private - can only be called from within the OilMenus module
00248     SeeAlso:    OilMenus
00249     SeeAlso:    MenuItem
00250 
00251 ********************************************************************************************/
00252 /* 
00253 Technical Notes:
00254 
00255 CreatePopup() is a recursive function. It calls itself whenever it comes across a sub-menu.
00256 
00257 ********************************************************************************************/
00258 
00259 wxMenu* CreatePopup(MenuItem* pCamSubMenu)
00260 {                  
00261     ERROR2IF(pCamSubMenu == 0, 0, "CreatePopup: null pCamSubMenu supplied");
00262 
00263     wxMenu*         pPopupMenu = new wxMenu( /*wxString( pCamSubMenu->GetMenuText() )*/ );  // Popup Menus in Windows
00264 
00265     ERROR2IF(pPopupMenu == 0, 0, "CreatePopup failed to allocate new menu");
00266     
00267     MenuItem* pSubMenu = pCamSubMenu->GetFirstMenuItem();                      
00268 
00269     // if menu popup hasn't got any sub menu items then setup a dummy menuitem to allow 
00270     // the OnMenuPopupInit() function to work when menu is selected!
00271     
00272     if (pSubMenu == 0)
00273     {
00274         if (!pPopupMenu->Append( pCamSubMenu->GetMenuId(),      // Use the Group Menu Id
00275                                TEXT("")))                   // Give it an empty string
00276         {
00277             TRACEUSER("luke", _T("Append failed\n"));
00278         }
00279     }
00280     
00281     while (pSubMenu != 0)
00282     {
00283         bool    fIsUnimpl = *pSubMenu->GetOpToken() == OPTOKEN_DO_NOTHING;
00284         bool    fNeedSep  = pSubMenu->IsFollowedBySeparator() && 
00285                             ( 0 != pCamSubMenu->GetNextMenuItem( pSubMenu ) );
00286 
00287         if (pSubMenu->IsMenuItemGroup())                    // Distinguish between group &
00288         {                                                   // single MenuItems
00289             wxMenu* pNewMenu = CreatePopup( pSubMenu );
00290             if (pNewMenu)
00291             {
00292 #if !defined(_DEBUG)
00293                 if( !fIsUnimpl )
00294                 {
00295 #endif
00296                     wxString sName((TCHAR *)pSubMenu->GetMenuText());
00297                     if (!pPopupMenu->Append( pSubMenu->GetMenuId(), sName, pNewMenu ))
00298                     {
00299                         TRACEUSER("luke", _T("Append failed\n"));
00300                     }
00301                 }
00302 #if !defined(_DEBUG)
00303             }
00304 #endif
00305         }
00306         else
00307         {
00308             wxItemKind  ItemKind = wxITEM_NORMAL;
00309             if( pSubMenu->IsCheckable() )
00310                 ItemKind = wxITEM_CHECK;
00311 
00312 #if !defined(_DEBUG)
00313             if( !fIsUnimpl )
00314             {
00315 #endif
00316                 // Set the leaf's label ... 
00317                 if (!pPopupMenu->Append( pSubMenu->GetMenuId(), 
00318                     wxString( (TCHAR*)pSubMenu->GetMenuText() ), wxEmptyString, ItemKind ))
00319                 {
00320                     TRACEUSER("luke", _T("Append failed\n"));
00321                 }
00322 #if !defined(_DEBUG)
00323             }
00324             else
00325                 fNeedSep = false;
00326 #else
00327             if( fIsUnimpl )
00328                 pPopupMenu->Enable( pSubMenu->GetMenuId(), false );
00329 #endif
00330             
00331 /*
00332             // ... and glyph, if any.
00333             UINT32 nSelBmpID = pSubMenu->GetMenuSelectedBitmapID();
00334             UINT32 nUnselBmpID = pSubMenu->GetMenuUnselectedBitmapID();
00335             if (nSelBmpID != 0 && nUnselBmpID != 0)
00336                 pPopupMenu->SetMenuItemBitmaps(pSubMenu->GetMenuId(), 0,
00337                                                &CBitmap(nSelBmpID),
00338                                                &CBitmap(nUnselBmpID));
00339 */      }
00340 
00341         // Add a separating line if required, BUT...
00342         // Don't allow a separator to be added if this is the last item in the menu...
00343         if( fNeedSep )
00344         {
00345             if (!pPopupMenu->AppendSeparator())
00346             {
00347                 TRACEUSER("luke", _T("AppendSeparator failed\n"));
00348             }
00349         }
00350         
00351         pSubMenu = pCamSubMenu->GetNextMenuItem(pSubMenu);
00352     }
00353     
00354     return pPopupMenu;
00355 }
00356 
00357 /********************************************************************************************
00358 
00359 >   BOOL DestroyCamMenu(MenuItem *CamMenu)
00360 
00361     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00362     Created:    30/6/93
00363     Inputs:     MenuItem - A platform-independent menu.
00364     Outputs:    None.
00365     Returns:    True - If all objects in menu system were destroyed successfully
00366     Purpose:    Destroys all dynamic objects in the menu system, freeing up memory. 
00367     Errors:     None
00368     Scope:      Private - can only be called from within the OilMenus module
00369     SeeAlso:    OilMenus
00370     SeeAlso:    MenuItem          
00371     SeeAlso:    DestroyWinMenu()
00372     SeeAlso:    DeInitMenuSystem()
00373 
00374 ********************************************************************************************/
00375 /* 
00376 Technical Notes:
00377 
00378 DestroyCamMenu is a recursive function. It calls itself whenever it comes across a sub-menu.
00379 
00380 ********************************************************************************************/
00381 
00382 BOOL DestroyCamMenu(MenuItem *CamMenu)
00383 {               
00384     MenuItem *subMenu;
00385     MenuItem *tempMenu;
00386     
00387     subMenu = CamMenu->GetFirstMenuItem();
00388 
00389     while (subMenu != NULL)
00390     {
00391         // if MenuItem is a group then delete all MenuItems within it
00392         if (subMenu->IsMenuItemGroup())
00393             DestroyCamMenu(subMenu);
00394                            
00395         // Get Next MenuItem before the current is deleted                   
00396         tempMenu = CamMenu->GetNextMenuItem(subMenu);
00397  
00398         // Object pointed to by subMenu is deleted and memory is freed.
00399         delete CamMenu->RemoveMenuItem(subMenu);
00400         
00401         // Submenu now points to next item
00402         subMenu = tempMenu;
00403     }
00404     return TRUE;
00405 }
00406 
00407 // Forward Declaration
00408 
00409 BOOL DestroyWinSubMenu(wxMenu *WinSubMenu);
00410 
00411 /********************************************************************************************
00412 
00413 >   BOOL DestroyWinMenu(wxMenu *WinMenu)
00414 
00415     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00416     Created:    30/6/93
00417     Inputs:     wxMenu - Windows menu object.
00418     Outputs:    None.
00419     Returns:    True - If all objects in menu system were destroyed successfully
00420     Purpose:    Destroys all dynamic objects in the menu system, freeing up memory. 
00421     Errors:     Does not work with nested, hierarchical menus yet!
00422     Scope:      Private - can only be called from within the OilMenus module
00423     SeeAlso:    OilMenus
00424     SeeAlso:    MenuItem
00425     SeeAlso:    DestroyCamMenu()
00426     SeeAlso:    DeInitMenuSystem()
00427 
00428 ********************************************************************************************/
00429 /* 
00430 Technical Notes:
00431 
00432 Assumes that all sub Menus are popups - only ok for the Menu Bar. Calls DestroyWinSubMenu()
00433 in order to destroy nested/hierarchical menus.
00434 ********************************************************************************************/
00435 
00436 BOOL DestroyWinMenu(wxMenu *WinMenu)
00437 {               
00438 PORTNOTE("other","Removed menu destruction - temporary!")
00439 #if 0
00440     wxMenu  *subMenu;
00441     INT32       position = 0;
00442     INT32       noItems = WinMenu->GetMenuItemCount();  
00443     
00444     while ((noItems > 0)  && (position < noItems))  
00445     {                                               
00446         subMenu = WinMenu->GetSubMenu(position);    
00447         if (subMenu != NULL)                        
00448         {
00449             DestroyWinSubMenu(subMenu);
00450             subMenu->Detach();
00451             delete subMenu;
00452         }
00453         position++;
00454     }
00455 #endif
00456     return TRUE;
00457 }
00458 
00459 /********************************************************************************************
00460 
00461 >   BOOL DestroyWinSubMenu(wxMenu *WinSubMenu)
00462 
00463     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00464     Created:    30/6/93
00465     Inputs:     wxMenu - Windows menu object.
00466     Outputs:    None.
00467     Returns:    True - If all objects in menu system were destroyed successfully
00468     Purpose:    Destroys all dynamic objects in the menu system, freeing up memory. 
00469     Errors:     None!
00470     Scope:      Private - can only be called from within the OilMenus module
00471     SeeAlso:    OilMenus
00472     SeeAlso:    MenuItem
00473     SeeAlso:    DestroyWinMenu()
00474     SeeAlso:    DeInitMenuSystem()
00475 
00476 ********************************************************************************************/
00477 /* 
00478 Technical Notes:
00479 
00480 This function calls itself recursively!
00481 ********************************************************************************************/
00482 
00483 BOOL DestroyWinSubMenu(wxMenu *WinSubMenu)
00484 {               
00485 PORTNOTE("other","Removed menu destruction - temporary!")
00486 #if 0
00487     wxMenu  *subMenu;
00488     UINT32  subMenuId;
00489     INT32       position = 0;
00490     INT32       noItems = WinSubMenu->GetMenuItemCount();  
00491     
00492     while ((noItems > 0)  && (position < noItems))  
00493     {                                               
00494         subMenuId = WinSubMenu->GetMenuItemID(position); 
00495         if (subMenuId == (UINT32)-1)
00496         {
00497             subMenu = WinSubMenu->GetSubMenu(position);    
00498             if (subMenu != NULL)                        
00499             {
00500                 DestroyWinSubMenu(subMenu);
00501                 subMenu->Detach();
00502                 delete subMenu;
00503             }
00504         }
00505         position++;
00506     }
00507 #endif
00508     return TRUE;
00509 }
00510 
00511 // Forward Declaration
00512 
00513 BOOL DestroyWinSubMenuMFC(wxMenu *pWinSubMenu);
00514 
00515 /********************************************************************************************
00516 
00517 >   BOOL DestroyWinMenuMFC(wxMenu *WinMenu)
00518 
00519     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00520     Created:    7/3/97
00521     Inputs:     wxMenu - Windows menu object.
00522     Outputs:    None.
00523     Returns:    True - If all objects in menu system were destroyed successfully
00524     Purpose:    Destroys all dynamic objects in the menu system, freeing up memory. 
00525     Errors:     Does not work with nested, hierarchical menus yet!
00526     Scope:      Private - can only be called from within the OilMenus module
00527     SeeAlso:    OilMenus
00528     SeeAlso:    MenuItem
00529     SeeAlso:    DestroyCamMenu()
00530     SeeAlso:    DeInitMenuSystem()
00531 
00532 ********************************************************************************************/
00533 /* 
00534 Technical Notes:
00535 
00536 Assumes that all sub Menus are popups - only ok for the Menu Bar. Calls DestroyWinSubMenu()
00537 in order to destroy nested/hierarchical menus.
00538 ********************************************************************************************/
00539 
00540 BOOL DestroyWinMenuMFC(wxMenu *pWinMenu)
00541 {               
00542 PORTNOTE("other","Removed menu destruction - temporary!")
00543 #if 0
00544     ERROR2IF(pWinMenu == NULL, FALSE,"DestroyWinMenuMFC bad pWinMenu supplied");
00545     wxMenu  *pSubMenu = NULL;
00546     INT32       noItems = pWinMenu->GetMenuItemCount();  
00547     
00548     // Walk backwards through the list removing items from the end, otherwise
00549     // we would need to recalculate the position after each menu deletion as the
00550     // position will have changed.
00551     BOOL ok = TRUE;
00552     INT32   position = noItems - 1;
00553     while (position >= 0)
00554     {                                               
00555         pSubMenu = pWinMenu->GetSubMenu(position);    
00556         if (pSubMenu != NULL)                        
00557             ok = DestroyWinSubMenuMFC(pSubMenu);
00558         // now delete the menu item
00559         ok = pWinMenu->DeleteMenu( position, MF_BYPOSITION );
00560         if (pSubMenu != NULL)                        
00561         {
00562             pSubMenu->Detach();
00563             delete pSubMenu;
00564         }
00565 
00566         position--;
00567     }
00568 #endif
00569     return TRUE;
00570 }
00571 
00572 /********************************************************************************************
00573 
00574 >   BOOL DestroyWinSubMenuMFC(wxMenu *WinSubMenu)
00575 
00576     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00577     Created:    7/3/97
00578     Inputs:     wxMenu - Windows menu object.
00579     Outputs:    None.
00580     Returns:    True - If all objects in menu system were destroyed successfully
00581     Purpose:    Destroys all dynamic objects in the menu system, freeing up memory. 
00582     Errors:     None!
00583     Scope:      Private - can only be called from within the OilMenus module
00584     SeeAlso:    OilMenus
00585     SeeAlso:    MenuItem
00586     SeeAlso:    DestroyWinMenu()
00587     SeeAlso:    DeInitMenuSystem()
00588 
00589 ********************************************************************************************/
00590 /* 
00591 Technical Notes:
00592 
00593 This function calls itself recursively!
00594 ********************************************************************************************/
00595 
00596 BOOL DestroyWinSubMenuMFC(wxMenu *pWinSubMenu)
00597 {               
00598 PORTNOTE("other","Removed menu destruction - temporary!")
00599 #if 0
00600     ERROR2IF(pWinSubMenu == NULL, FALSE,"DestroyWinMenuMFC bad pWinSubMenu supplied");
00601     wxMenu  *pSubMenu = NULL;
00602     INT32       noItems = pWinSubMenu->GetMenuItemCount();  
00603     
00604     // Walk backwards through the list removing items from the end, otherwise
00605     // we would need to recalculate the position after each menu deletion as the
00606     // position will have changed.
00607     BOOL ok = TRUE;
00608     INT32   position = noItems - 1;
00609     while (position >= 0)
00610     {                                               
00611         pSubMenu = pWinSubMenu->GetSubMenu(position);    
00612         if (pSubMenu != NULL)                        
00613             ok = DestroyWinSubMenuMFC(pSubMenu);
00614         // now delete the menu item
00615         ok = pWinSubMenu->DeleteMenu( position, MF_BYPOSITION );
00616         if (pSubMenu != NULL)                        
00617         {
00618             pSubMenu->Detach();
00619             delete pSubMenu;
00620         }
00621 
00622         position--;
00623     }
00624 #endif
00625     return TRUE;
00626 }
00627 
00628 
00629 /********************************************************************************************
00630 
00631 >   BOOL InitMenuSystem()
00632 
00633     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00634     Created:    30/6/93
00635     Inputs:     None.
00636     Outputs:    None.
00637     Returns:    TRUE if initialisation was successful
00638     Purpose:    Creates both the platform-independent and windows specific menu systems.
00639     Errors:     None.
00640     SeeAlso:    OilMenus
00641     SeeAlso:    MenuItem
00642     SeeAlso:    SetupDefaultMenu()
00643     SeeAlso:    SetupSharedMenu()
00644     SeeAlso:    ConvertToWinMenu()
00645     SeeAlso:    DeInitMenuSystem()
00646 
00647 ********************************************************************************************/
00648 
00649 BOOL InitMenuSystem()
00650 {
00651     CamelotDefMenu = SetupDefaultMenu();            //MainFrame Menu
00652     CamelotMDIMenu = SetupSharedMenu();             //MDI Menu
00653     CamelotContextMenu = NULL;
00654 
00655     if (CamelotDefMenu)
00656         WinDefMenu = ConvertToWinMenu(CamelotDefMenu);  //Windows MainFrame Menu        
00657     else
00658         return FALSE;
00659         
00660     if (CamelotMDIMenu)
00661         WinMDIMenu = ConvertToWinMenu(CamelotMDIMenu);  //Windows MDI Menu
00662     else
00663         return FALSE;
00664     
00665     return TRUE;
00666 }
00667 
00668 /********************************************************************************************
00669 
00670 >   void DeInitMenuSystem()
00671 
00672     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00673     Created:    30/6/93
00674     Inputs:     None.
00675     Outputs:    None.
00676     Returns:    Nothing.
00677     Purpose:    Destroys both the platform-independent and windows specific menu systems.
00678     Errors:     None.
00679     SeeAlso:    OilMenus
00680     SeeAlso:    MenuItem
00681     SeeAlso:    DestroyCamMenu()    
00682     SeeAlso:    DestroyWinMenu()    
00683     SeeAlso:    InitMenuSystem()
00684 
00685 ********************************************************************************************/
00686 
00687 void DeinitMenuSystem()
00688 {
00689     if (CamelotDefMenu)
00690     {
00691         DestroyCamMenu(CamelotDefMenu);     //Destroy Platform-Independent
00692         delete CamelotDefMenu;
00693         CamelotDefMenu = NULL;
00694     }
00695 
00696     if (CamelotMDIMenu)
00697     {
00698         DestroyCamMenu(CamelotMDIMenu);     //Menu System
00699         delete CamelotMDIMenu; 
00700         CamelotMDIMenu = NULL;
00701     }
00702 
00703 PORTNOTE("other","Removed menu destruction - temporary!")
00704 #if 0
00705     if (WinMDIMenu)
00706     {
00707         DestroyWinMenu(WinMDIMenu);         //Destroy The MDI Frame Menu
00708 
00709         WinMDIMenu->Detach();
00710         delete WinMDIMenu;
00711         WinMDIMenu = NULL;
00712     }
00713 #endif
00714     //----------------------------------------------------------
00715     // If the context-sensitive menu is left around delete it...
00716 /*  if (CamelotContextMenu)
00717     {
00718         DestroyCamMenu(CamelotContextMenu);     //Menu System
00719         delete CamelotContextMenu; 
00720         CamelotContextMenu = NULL;
00721     }
00722 
00723 
00724     if (WinContextMenu)
00725     {
00726         DestroyWinMenu(WinContextMenu);         //Destroy The MDI Frame Menu
00727 //      WinContextMenu->Detach();
00728         WinContextMenu->DestroyMenu();          // DestroyMenu releases Windows resources and calls Detach
00729         delete WinContextMenu;
00730         WinContextMenu = NULL;
00731     }
00732 */
00733     ContextMenu::HideCurrent();
00734 
00735 }
00736 
00737 
00738 // Functions Used For Performing Menu Actions and Updates
00739 
00740 /********************************************************************************************
00741 
00742 >   BOOL IsMenuCommand(WPARAM wParam, LPARAM lParam)
00743 
00744     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00745     Created:    2/7/93
00746     Inputs:     wParam & lParam - Windows API command parameters.
00747     Outputs:    None.
00748     Returns:    TRUE if command is a menu command
00749                 FALSE otherwise
00750     Purpose:    To identify menu item commands
00751     Errors:     None.
00752     SeeAlso:    CMainFrame
00753 
00754 ********************************************************************************************/
00755 
00756 BOOL IsMenuCommand( wxCommandEvent& event )
00757 {
00758     return event.GetEventType() == wxEVT_COMMAND_MENU_SELECTED;
00759 }
00760 
00761 
00762 /********************************************************************************************
00763 
00764 >   MenuItem *FindMenuItem(UINT32 menuId, MenuItem* GroupSubMenu)
00765 
00766     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00767     Created:    2/7/93
00768     Inputs:     Menu ID & Group Sub Menu
00769     Outputs:    None.
00770     Returns:    MenuItem if found
00771                 NULL if menu item is not found
00772     Purpose:    To find a menu item in the platform independent menu system.
00773     Scope:      Private To OilMenus
00774     Errors:     None.
00775     SeeAlso:    MenuItem
00776 
00777 ********************************************************************************************/
00778 /*
00779 Technical Notes:
00780 
00781 Recursively Called For each subMenu;
00782 
00783 ********************************************************************************************/
00784 
00785 MenuItem *FindMenuItem(UINT32 menuId, MenuItem* GroupSubMenu)
00786 {      
00787     if (GroupSubMenu==NULL)
00788         return NULL;
00789 
00790     if (GroupSubMenu->GetMenuId() == menuId)
00791         return GroupSubMenu;
00792 
00793     MenuItem* subsubMenu;
00794     MenuItem* subMenu = GroupSubMenu->GetFirstMenuItem();
00795 
00796     while (subMenu != NULL)
00797     {
00798         if (subMenu->GetMenuId() == menuId)
00799             return subMenu;
00800 
00801         if (subMenu->IsMenuItemGroup())
00802         {
00803             subsubMenu = FindMenuItem(menuId, subMenu);
00804             if (subsubMenu != NULL)
00805                 return subsubMenu;          
00806         }
00807               
00808         subMenu = GroupSubMenu->GetNextMenuItem(subMenu);
00809     }                       
00810     
00811     return NULL;
00812 }
00813 
00814 /********************************************************************************************
00815 
00816 >   MenuItem *GetMenuItem(UINT32 menuId, BOOL* pShowHotKeysFlag = NULL)
00817 
00818     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00819     Created:    28/9/93
00820     Inputs:     Menu ID
00821     Outputs:    None.
00822     Returns:    MenuItem if found
00823                 NULL if menu item is not found
00824     Purpose:    To find a menu item in one of the platform independent menu systems.
00825     Errors:     None.
00826     SeeAlso:    MenuItem
00827     SeeAlso:    FindMenuItem
00828 
00829 ********************************************************************************************/
00830 
00831 MenuItem *GetMenuItem(UINT32 menuId, BOOL* pShowHotKeysFlag)
00832 {      
00833     // If There are no active child windows Then search for menu option in default menu
00834     // Else search for menu option in MDI shared menu.
00835     
00836     MenuItem* pItem = NULL;
00837     if (pShowHotKeysFlag) *pShowHotKeysFlag = TRUE;
00838 
00839 PORTNOTE( "other", "We always use MDIMenu" )
00840 /*  if( NULL == ( (wxDocMDIParentFrame *)CCamFrame::GetMainFrame() )->GetActiveChild() )
00841     {
00842         // There is no document (MDI child) window, so we want to look only in the 
00843         // current context-sensitive menu (if any), and then (if that fails), in the
00844         // default camelot menu.
00845 
00846         pItem = FindMenuItem(menuId, CamelotContextMenu);   // Look in Context sensitive menu first
00847         if (pItem == NULL)
00848             pItem = FindMenuItem(menuId, CamelotDefMenu);   // Look in default menu
00849     }
00850     else */
00851     {
00852         pItem = FindMenuItem(menuId, CamelotContextMenu);   // Look in Context sensitive menu first
00853         if (pItem == NULL)
00854             pItem = FindMenuItem(menuId, CamelotMDIMenu);
00855         else
00856             if (pShowHotKeysFlag) *pShowHotKeysFlag = FALSE;    // ContextMenu shouldn't show hot keys
00857     }
00858 
00859     return pItem;
00860 }
00861 
00862 /********************************************************************************************
00863 
00864 >   BOOL PerformMenuCommand(WPARAM wParam, LPARAM lParam)
00865 
00866     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00867     Created:    2/7/93
00868     Inputs:     wParam & lParam - Windows API command parameters.
00869     Outputs:    None.
00870     Returns:    TRUE if MenuItem found and command is performed
00871                 FALSE otherwise
00872     Purpose:    To perform menu item command
00873     Errors:     None.
00874     SeeAlso:    CMainFrame
00875     SeeAlso:    MenuItem
00876     SeeAlso:    FindMenuItem()
00877     SeeAlso:    MenuItem::PerformAction()
00878 
00879 ********************************************************************************************/
00880 
00881 BOOL PerformMenuCommand( wxCommandEvent& event )
00882 {                     
00883     MenuItem* TargetItem;
00884                            
00885     // Get appropriate menu item given the menu id
00886     TargetItem = GetMenuItem( event.GetId() );
00887 
00888     if (TargetItem)
00889     {
00890         TargetItem->PerformAction();
00891         return TRUE;
00892     }               
00893     
00894     return FALSE;
00895 }
00896 
00897 /********************************************************************************************
00898 
00899 >   BOOL FindMenu(MenuItem **TargetMenu, wxMenu* pMenu, BOOL* pShowHotKeysFlag = NULL)
00900 
00901     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00902     Created:    29/9/93
00903     Inputs:     A pointer to a Windows wxMenu
00904     Outputs:    A pointer to a Camelot MenuItem.
00905     Returns:    TRUE if found successfully
00906                 FALSE otherwise
00907     Purpose:    To find kernel menu equivalent to Windows menu that is passed in. 
00908     Scope:      Private to be called by UpdateMenu() only!
00909     Errors:     None.
00910     SeeAlso:    CMainFrame
00911     SeeAlso:    wxMenu
00912     SeeAlso:    MenuItem
00913 
00914 ********************************************************************************************/
00915 
00916 BOOL FindMenu(MenuItem **TargetMenu, wxMenu* pMenu, BOOL* pShowHotKeysFlag)
00917 {
00918     UINT32  TargetMenuId = (UINT32)-1;
00919     size_t  position = 0;
00920     size_t  noItems = pMenu->GetMenuItemCount();
00921     
00922     // Get id of first non sub-menu item in Windows wxMenu
00923     // TargetMenuID is -1 if its a sub-menu item and 0 if its a separator
00924     // No separator check present, added by Neville 31/10/97
00925     TargetMenuId = pMenu->FindItemByPosition( position )->GetId(); 
00926     while (
00927             (noItems > 0) && (position < noItems) &&
00928             ((TargetMenuId == (UINT32)-1) || (TargetMenuId == 0))
00929             )
00930     {
00931         TargetMenuId = pMenu->FindItemByPosition( position )->GetId(); 
00932         position++;
00933     }
00934      
00935     if (TargetMenuId != (UINT32)-1)
00936     {                                                           
00937         //Use ID to get MenuItem object 
00938         *TargetMenu = GetMenuItem(TargetMenuId, pShowHotKeysFlag);
00939     
00940         if (*TargetMenu != NULL)                        // couldn't find it, probably
00941         {                                               // the system menu on the close box
00942             //Get Parent Id of MenuItem
00943             TargetMenuId = (*TargetMenu)->GetMenuItemParentId();
00944 
00945             //Use Parent Id to get menu we want!
00946             *TargetMenu = GetMenuItem(TargetMenuId, pShowHotKeysFlag);
00947             if (*TargetMenu)
00948                 return TRUE;
00949             else
00950                 return FALSE;
00951         }
00952     }   
00953     return FALSE;
00954 }
00955                                                        
00956 /********************************************************************************************
00957 
00958 >   BOOL UpdateMenu(wxMenu* pMenu)
00959 
00960     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00961     Created:    8/7/93
00962     Inputs:     A pointer to a wxMenu
00963     Outputs:    None.
00964     Returns:    FALSE if Menu is not found in the Kernel
00965                 TRUE otherwize.
00966     Purpose:    To update menu 
00967     Errors:     None.
00968     SeeAlso:    CMainFrame
00969     SeeAlso:    wxMenu
00970     SeeAlso:    MenuItem
00971 
00972 ********************************************************************************************/
00973 
00974 BOOL UpdateMenu(wxMenu* pMenu)
00975 {                     
00976     MenuItem*   TargetMenu = NULL;
00977     BOOL        ShowHotKeys = TRUE;
00978     
00979     if (FindMenu(&TargetMenu, pMenu, &ShowHotKeys))
00980     {
00981         ERROR3IF(TargetMenu==NULL,"FindMenu returned TRUE but didn't fill in menu pointer");
00982 
00983 #ifdef PHOTOSHOPPLUGINS
00984 // Only add in if required - general plug-in removal at present
00985 //#ifdef NEW_NATIVE_FILTER
00986         // Must check if we are going to drop down the Plug-Ins menu item
00987         // If so then check that we have parsed the plug-ins.
00988         PlugInManager* pManager = GetApplication()->GetPlugInManager();
00989         if (pManager != NULL && !pManager->SearchedPathsYet())
00990         {
00991             MenuItem * pPlugInsMenu = pManager->FindPlugInMainMenuItem();
00992             // a pointer compare should be an adequote test
00993             if (pPlugInsMenu != NULL && TargetMenu != NULL && pPlugInsMenu == TargetMenu)
00994             {
00995                 pManager->CheckHaveDetailsOnPlugIns();
00996                 // Now done in UpdatePlugInsWinMenu
00997                 // Force the menu bar to be redrawn as we are in the middle of pulling the
00998                 // menu down and we have changed it.
00999                 //HWND hwnd = GetMainFrame()->GetSafeHwnd();
01000                 //DrawMenuBar(hwnd);
01001                 // Cannot fall through to the code below as the pMenu we have had passed in
01002                 // may now be completely false. This will cause problems in the UpdateWinMenu call.
01003                 // So return now.
01004                 return TRUE;
01005             }
01006         }
01007 //#endif
01008 #endif
01009         // Update Kernel Menu 
01010         TargetMenu->UpdateMenuState(ShowHotKeys);
01011     
01012         // Update OIL Menu 
01013         UpdateWinMenu(pMenu, TargetMenu);
01014         
01015         return TRUE;
01016     }
01017     else
01018         return FALSE;
01019 }
01020 
01021 /********************************************************************************************
01022 
01023 >   void UpdateWinMenu(wxMenu* pMenu, MenuItem* kernelMenu)
01024 
01025     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
01026     Created:    8/7/93
01027     Inputs:     A pointer to a wxMenu and a kernel menu object
01028     Outputs:    None.
01029     Returns:    None.
01030     Purpose:    To update windows menu system. It is also a Friend of the MenuItem Class.
01031     Errors:     None.
01032     SeeAlso:    CMainFrame
01033     SeeAlso:    wxMenu
01034     SeeAlso:    MenuItem
01035 
01036 ********************************************************************************************/
01037 
01038 void UpdateWinMenu(wxMenu* pMenu, MenuItem* kernelMenu)
01039 {
01040     if (kernelMenu == NULL) return;
01041 
01042     MenuItem* subMenu = (kernelMenu->GetFirstMenuItem());
01043     
01044     //Read through list of Kernel MenuItems updating their state
01045     while (subMenu != NULL)
01046     {
01047         if (!subMenu->IsMenuItemGroup())
01048         {
01049             wxItemKind  ItemKind = wxITEM_NORMAL;
01050             if( subMenu->IsCheckable() )
01051                 ItemKind = wxITEM_CHECK;
01052             
01053             // Make sure the wxMenu has this menu item in it...
01054             wxMenuItem  *pItem = pMenu->FindItem( subMenu->GetMenuId() );
01055             if( NULL == pItem )
01056             {
01057                 // This menu item is missing, probably deleted by the bit of code below
01058                 // We have to put it back in again to be on the safe side
01059                 // Find out the position of the next visible menu item, so we can insert just before it
01060                 MenuItem* NextMenu = subMenu;
01061                 while( NULL != NextMenu && 
01062                     NULL == pMenu->FindItem( NextMenu->GetMenuId() ) )
01063                 {
01064                     NextMenu = (kernelMenu->GetNextMenuItem(NextMenu));
01065                 }
01066                 
01067                 // If there was a next item, insert before it, else append to the end of the menu
01068                 if (NextMenu!=NULL)
01069                 {
01070                     BOOL    MenuAdded = FALSE;
01071                     BOOL    PrevWasSeparator = FALSE;
01072                     size_t  NumMenuItems = pMenu->GetMenuItemCount();
01073                     for( size_t i=0; (!MenuAdded) && (i<NumMenuItems); i++ )
01074                     {
01075                         // loop through all the menu items to try and find our ID
01076                         wxMenuItem* pMenuItem = pMenu->FindItemByPosition( i );
01077                         UINT32 MenuID = pMenuItem->GetId();
01078                         if (MenuID == NextMenu->GetMenuId())
01079                         {
01080                             // We will be wanting to insert just before this one
01081                             size_t InsertPos = i;
01082 
01083                             // but was the previous item was a separator
01084                             if (PrevWasSeparator)
01085                                 InsertPos--;
01086                             
01087                             // Insert the menu and set the flag to say it was inserted
01088                             pMenu->Insert( InsertPos, subMenu->GetMenuId(), subMenu->GetMenuText(), 
01089                                 _T(""), ItemKind );
01090                             MenuAdded = TRUE;
01091                         }
01092 
01093                         // Unset the Prev Separator flag
01094                         PrevWasSeparator = FALSE;
01095 
01096                         // if this was a separator, then remember for the next loop
01097                         if( pMenuItem->IsSeparator() )
01098                             PrevWasSeparator = TRUE;
01099                     }
01100                 }
01101                 else
01102                     pMenu->Append( subMenu->GetMenuId(), subMenu->GetMenuText(), _T(""),
01103                         ItemKind );
01104             }
01105 
01106 PORTNOTE( "menu", "Remove Unimplemented menuitems from menu, under Release" )
01107 #if !defined(_DEBUG)
01108             if( subMenu->Description == _T("Unimplemented") )
01109                 subMenu->ControlState.RemoveFromMenu = true;
01110 #endif
01111 
01112             if( !subMenu->ControlState.RemoveFromMenu )
01113             {
01114                 //Update the Menu Text
01115                 pMenu->FindItem( subMenu->GetMenuId() )->SetText( wxString( (TCHAR *)subMenu->GetMenuText() ) );
01116 
01117                 if (subMenu->ControlState.Greyed)
01118                     //Disable and Grey Menu Item 
01119                     pMenu->Enable( subMenu->GetMenuId(), false );
01120                 else
01121                 {
01122                     //Enable Menu Item and UnGrey
01123                     pMenu->Enable( subMenu->GetMenuId(), true );
01124 
01125                     if (subMenu->ControlState.Ticked)
01126                     {
01127                         TRACE( _T("Check %s\n"), (PCTSTR)subMenu->GetMenuText() );
01128                         
01129                         //Tick Menu Item
01130                         if (pMenu->FindItem(subMenu->GetMenuId())->IsCheckable())
01131                             pMenu->Check( subMenu->GetMenuId(), true );
01132                     }
01133                     else
01134                         //UnTick Menu Item
01135                         if (pMenu->FindItem(subMenu->GetMenuId())->IsCheckable())
01136                             pMenu->Check( subMenu->GetMenuId(), false );
01137                 }
01138             }
01139             else
01140             // See if this menu item want itself removed from the menu
01141             {
01142                 // take it out of the menu
01143                 pMenu->Delete( subMenu->GetMenuId() );
01144             }
01145         }
01146         else
01147         {
01148             // It's a menu item group, so we need to recurse down
01149             wxMenuItem  *pItem = pMenu->FindItem( subMenu->GetMenuId() );
01150             if (pItem)
01151             {
01152                 wxMenu * pwxSubMenu = pItem->GetSubMenu();
01153                 if (pwxSubMenu)
01154                 {
01155                     UpdateWinMenu(pwxSubMenu,subMenu);
01156                 }
01157             }
01158         }   
01159         subMenu = (kernelMenu->GetNextMenuItem(subMenu));
01160     }
01161 }
01162 
01163 
01164 
01165 
01166 /********************************************************************************************
01167 
01168 >   BOOL CreateContextMenu(MenuItem* pContextMenu)
01169 
01170     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01171     Created:    13/03/95
01172     Inputs:     pContextMenu    Pointer to a context-sensitive menu
01173     Outputs:    -
01174     Returns:    TRUE if menu was created and opened on screen succesfully.
01175                 FALSE otherwise
01176     Purpose:    To put a popup menu on screen.
01177     Errors:     None.
01178 
01179 ********************************************************************************************/
01180 
01181 BOOL CreateContextMenu(MenuItem* pContextMenu)
01182 {
01183     BOOL worked = FALSE;
01184 
01185     // If the previous context menu is hanging around for some reason
01186     // get rid of it.
01187     DestroyContextMenu();
01188 
01189     // Now setup the new context menu
01190     CamelotContextMenu = pContextMenu;
01191     WinContextMenu = CreatePopup(CamelotContextMenu);
01192 
01193     if (WinContextMenu==NULL)
01194         worked = FALSE;
01195     else
01196     {
01197         // Set the menu states correctly
01198 //      CamelotContextMenu->UpdateMenuState(FALSE);
01199 //      UpdateWinMenu(WinContextMenu, CamelotContextMenu);
01200 
01201         if( CCamFrame::GetMainFrame()->PopupMenu( WinContextMenu ) )
01202             worked = TRUE;
01203         else
01204         {
01205             DestroyCamMenu(CamelotContextMenu);
01206             delete CamelotContextMenu; 
01207             CamelotContextMenu = NULL;
01208         }
01209     }
01210 
01211     return worked;
01212 }
01213 
01214 
01215 
01216 
01217 /********************************************************************************************
01218 
01219 >   BOOL DestroyContextMenu()
01220 
01221     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01222     Created:    14/03/95
01223     Inputs:     -
01224     Outputs:    -
01225     Returns:    TRUE if menu was destroyed succesfully.
01226                 FALSE otherwise
01227     Purpose:    To remove a popup menu from the screen.
01228     Errors:     None.
01229 
01230 ********************************************************************************************/
01231 
01232 BOOL DestroyContextMenu()
01233 {
01234     // If the previous context menu is hanging around for some reason
01235     // get rid of it.
01236     if (WinContextMenu)
01237     {
01238         DestroyWinMenu(WinContextMenu);
01239 //      WinContextMenu->Detach();
01240 //      WinContextMenu->Destroy();      // DestroyMenu releases Windows resources and calls Detach
01241         delete WinContextMenu;
01242         WinContextMenu = NULL;
01243     }
01244 
01245     if (CamelotContextMenu)
01246     {
01247         DestroyCamMenu(CamelotContextMenu);
01248         delete CamelotContextMenu; 
01249         CamelotContextMenu = NULL;
01250     }
01251 
01252     return TRUE;
01253 }
01254 
01255 
01256 
01257 
01258 /********************************************************************************************
01259 
01260 >   MenuItem* GetCurrentContextMenu()
01261 
01262     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01263     Created:    14/03/95
01264     Inputs:     -
01265     Outputs:    -
01266     Returns:    A pointer to the current context menu (kernel form) if it exists AND the 
01267                 Windows equivalent exists AND it's currently on screen.
01268     Purpose:    Find out whether the popup menu is open or not and what it is...
01269     Errors:     None.
01270 
01271 ********************************************************************************************/
01272 
01273 MenuItem* GetCurrentContextMenu()
01274 {
01275     if (WinContextMenu!=NULL && CamelotContextMenu!=NULL)
01276         return CamelotContextMenu;
01277     else
01278         return NULL;
01279 }
01280 
01281 /********************************************************************************************
01282 
01283 >   MenuItem* GetMainMDIMenu()
01284 
01285     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01286     Created:    17/1/97
01287     Inputs:     -
01288     Outputs:    -
01289     Returns:    A pointer to the main MDI menu.
01290     Purpose:    To find the menu item associated with the main kernelly MDI menu.
01291     Errors:     None.
01292 
01293 ********************************************************************************************/
01294 
01295 MenuItem* GetMainMDIMenu()
01296 {
01297     return CamelotMDIMenu;
01298 }
01299 
01300 /********************************************************************************************
01301 
01302 >   BOOL UpdatePlugInsWinMenu(MenuItem* pPlugInsMenu)
01303 
01304     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01305     Created:    20/1/97
01306     Inputs:     pPlugInsMenu    Pointer to the plug-ins kernel menu structure
01307     Outputs:    -
01308     Returns:    TRUE if win menu was updated succesfully.
01309                 FALSE otherwise
01310     Purpose:    This searches for the equivalent Win menu in the main MDI menu structure,
01311                 destroys anything that is there already and then puts in the new structure.
01312     Errors:     None.
01313 
01314 ********************************************************************************************/
01315 BOOL UpdatePlugInsWinMenu(MenuItem* pPlugInsMenu)
01316 {
01317 #ifdef PHOTOSHOPPLUGINS
01318 // Only add in if required - general plug-in removal at present
01319     ERROR2IF(pPlugInsMenu == NULL,FALSE,"UpdatePlugInsWinMenu null plug-ins menu supplied");
01320 
01321     BOOL worked = FALSE;
01322 
01323     // Find the section in the current MDI main win menu
01324     INT32 PlugInMenuPos = -1;
01325     wxMenu * pWinMainMenu = FindSubMenu(WinMDIMenu, PlugInMenuPos, (TCHAR *) pPlugInsMenu->GetMenuText());
01326 
01327     if (pWinMainMenu == NULL)
01328         return FALSE;
01329     wxMenu * pPlugInsWinMenu = pWinMainMenu->GetSubMenu(PlugInMenuPos);
01330     if (pPlugInsWinMenu == NULL)
01331         return FALSE;
01332 
01333     // If the previous plug-ins menu is hanging around for some reason
01334     // get rid of it.
01335     // Try and destroy all the sub-menu items first
01336     BOOL ok = DestroyWinMenuMFC(pPlugInsWinMenu);
01337     ok = ok && pWinMainMenu->DeleteMenu( PlugInMenuPos, MF_BYPOSITION );
01338     pPlugInsWinMenu->Detach();
01339     delete pPlugInsWinMenu;
01340 
01341     // Now setup the new plug-ins menu inserting it at the old position
01342     // First create the new windows menu from the kernel version
01343     wxMenu * pNewWinMenu = CreatePopup(pPlugInsMenu);
01344     ERROR3IF(pNewWinMenu == NULL,"Failed to create new plug-ins main menu item");
01345     if (pNewWinMenu)
01346     {
01347         // That went ok so now add it in at the old position in the main menu
01348         pWinMainMenu->InsertMenu(PlugInMenuPos,
01349                                  MF_POPUP | MF_BYPOSITION, 
01350                                  (UINT32)(pNewWinMenu->GetSafeHmenu()), 
01351                                  pPlugInsMenu->GetMenuText()
01352                                  );                      
01353     }
01354 
01355     // Force the menu bar to be redrawn as we are in the middle of pulling the
01356     // menu down and we have changed it.
01357     HWND hwnd = GetMainFrame()->GetSafeHwnd();
01358     DrawMenuBar(hwnd);
01359 
01360     // This code should happen in the UpdateMenu after our issuing of the DrawMenuBar command
01361     // Update Kernel Menu 
01362     pPlugInsMenu->UpdateMenuState(FALSE);
01363 
01364     // Update OIL Menu 
01365     UpdateWinMenu(pNewWinMenu, pPlugInsMenu);
01366 
01367     return worked;
01368 #else
01369     return TRUE;
01370 #endif // PHOTOSHOPPLUGINS
01371 }

Generated on Sat Nov 10 03:48:42 2007 for Camelot by  doxygen 1.4.4