1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _SV_SALMENU_H 29 #define _SV_SALMENU_H 30 31 #include "premac.h" 32 #include <Cocoa/Cocoa.h> 33 #include "postmac.h" 34 35 #include "salmenu.hxx" 36 37 #include <vector> 38 39 class AquaSalFrame; 40 class AquaSalMenuItem; 41 42 class AquaSalMenu : public SalMenu 43 { 44 std::vector< AquaSalMenuItem* > maItems; 45 46 public: // for OOStatusView 47 struct MenuBarButtonEntry 48 { 49 SalMenuButtonItem maButton; 50 NSImage* mpNSImage; // cached image 51 NSString* mpToolTipString; 52 53 MenuBarButtonEntry() : mpNSImage( nil ), mpToolTipString( nil ) {} 54 MenuBarButtonEntry( const SalMenuButtonItem& i_rItem ) 55 : maButton( i_rItem), mpNSImage( nil ), mpToolTipString( nil ) {} 56 }; 57 private: 58 std::vector< MenuBarButtonEntry > maButtons; 59 60 MenuBarButtonEntry* findButtonItem( sal_uInt16 i_nItemId ); 61 void releaseButtonEntry( MenuBarButtonEntry& i_rEntry ); 62 static void statusLayout(); 63 public: 64 AquaSalMenu( bool bMenuBar ); 65 virtual ~AquaSalMenu(); 66 67 virtual sal_Bool VisibleMenuBar(); // must return TRUE to actually DISPLAY native menu bars 68 // otherwise only menu messages are processed (eg, OLE on Windows) 69 70 virtual void InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ); 71 virtual void RemoveItem( unsigned nPos ); 72 virtual void SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos ); 73 virtual void SetFrame( const SalFrame* pFrame ); 74 virtual void CheckItem( unsigned nPos, sal_Bool bCheck ); 75 virtual void EnableItem( unsigned nPos, sal_Bool bEnable ); 76 virtual void SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const XubString& rText ); 77 virtual void SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage); 78 virtual void SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const KeyCode& rKeyCode, const XubString& rKeyName ); 79 virtual void GetSystemMenuData( SystemMenuData* pData ); 80 virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const Rectangle& rRect, sal_uLong nFlags); 81 virtual bool AddMenuBarButton( const SalMenuButtonItem& ); 82 virtual void RemoveMenuBarButton( sal_uInt16 nId ); 83 virtual Rectangle GetMenuBarButtonRectPixel( sal_uInt16 i_nItemId, SalFrame* i_pReferenceFrame ); 84 85 int getItemIndexByPos( sal_uInt16 nPos ) const; 86 const AquaSalFrame* getFrame() const; 87 88 void setMainMenu(); 89 static void unsetMainMenu(); 90 static void setDefaultMenu(); 91 static void enableMainMenu( bool bEnable ); 92 static void addFallbackMenuItem( NSMenuItem* NewItem ); 93 static void removeFallbackMenuItem( NSMenuItem* pOldItem ); 94 95 const std::vector< MenuBarButtonEntry >& getButtons() const { return maButtons; } 96 97 bool mbMenuBar; // true - Menubar, false - Menu 98 NSMenu* mpMenu; // The Carbon reference to this menu 99 Menu* mpVCLMenu; // the corresponding vcl Menu object 100 const AquaSalFrame* mpFrame; // the frame to dispatch the menu events to 101 AquaSalMenu* mpParentSalMenu; // the parent menu that contains us (and perhaps has a frame) 102 103 static const AquaSalMenu* pCurrentMenuBar; 104 105 }; 106 107 class AquaSalMenuItem : public SalMenuItem 108 { 109 public: 110 AquaSalMenuItem( const SalItemParams* ); 111 virtual ~AquaSalMenuItem(); 112 113 sal_uInt16 mnId; // Item ID 114 Menu* mpVCLMenu; // VCL Menu into which this MenuItem is inserted 115 AquaSalMenu* mpParentMenu; // The menu in which this menu item is inserted 116 AquaSalMenu* mpSubMenu; // Sub menu of this item (if defined) 117 NSMenuItem* mpMenuItem; // The NSMenuItem 118 }; 119 120 #endif // _SV_SALMENU_H 121