xref: /aoo42x/main/vcl/inc/aqua/salmenu.h (revision 24f6443d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_SALMENU_H
25 #define _SV_SALMENU_H
26 
27 #include "premac.h"
28 #include <Cocoa/Cocoa.h>
29 #include "postmac.h"
30 
31 #include "salmenu.hxx"
32 
33 #include <vector>
34 
35 class AquaSalFrame;
36 class AquaSalMenuItem;
37 
38 class AquaSalMenu : public SalMenu
39 {
40     std::vector< AquaSalMenuItem* >     maItems;
41 
42 public: // for OOStatusView
43     struct MenuBarButtonEntry
44     {
45         SalMenuButtonItem       maButton;
46         NSImage*                mpNSImage;      // cached image
47         NSString*               mpToolTipString;
48 
MenuBarButtonEntryAquaSalMenu::MenuBarButtonEntry49         MenuBarButtonEntry() : mpNSImage( nil ), mpToolTipString( nil ) {}
MenuBarButtonEntryAquaSalMenu::MenuBarButtonEntry50         MenuBarButtonEntry( const SalMenuButtonItem& i_rItem )
51         : maButton( i_rItem), mpNSImage( nil ), mpToolTipString( nil ) {}
52     };
53 private:
54     std::vector< MenuBarButtonEntry >   maButtons;
55 
56     MenuBarButtonEntry* findButtonItem( sal_uInt16 i_nItemId );
57     void releaseButtonEntry( MenuBarButtonEntry& i_rEntry );
58     static void statusLayout();
59 public:
60     AquaSalMenu( bool bMenuBar );
61     virtual ~AquaSalMenu();
62 
63     virtual sal_Bool VisibleMenuBar();  // must return TRUE to actually DISPLAY native menu bars
64                                     // otherwise only menu messages are processed (eg, OLE on Windows)
65 
66     virtual void InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos );
67     virtual void RemoveItem( unsigned nPos );
68     virtual void SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos );
69     virtual void SetFrame( const SalFrame* pFrame );
70     virtual void CheckItem( unsigned nPos, sal_Bool bCheck );
71     virtual void EnableItem( unsigned nPos, sal_Bool bEnable );
72     virtual void SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const XubString& rText );
73     virtual void SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage);
74     virtual void SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const KeyCode& rKeyCode, const XubString& rKeyName );
75     virtual void GetSystemMenuData( SystemMenuData* pData );
76 	virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const Rectangle& rRect, sal_uLong nFlags);
77     virtual bool AddMenuBarButton( const SalMenuButtonItem& );
78     virtual void RemoveMenuBarButton( sal_uInt16 nId );
79     virtual Rectangle GetMenuBarButtonRectPixel( sal_uInt16 i_nItemId, SalFrame* i_pReferenceFrame );
80 
81     int getItemIndexByPos( sal_uInt16 nPos ) const;
82     const AquaSalFrame* getFrame() const;
83 
84     void setMainMenu();
85     static void unsetMainMenu();
86     static void setDefaultMenu();
87     static void enableMainMenu( bool bEnable );
88     static void addFallbackMenuItem( NSMenuItem* NewItem );
89     static void removeFallbackMenuItem( NSMenuItem* pOldItem );
90 
getButtons() const91     const std::vector< MenuBarButtonEntry >& getButtons() const { return maButtons; }
92 
93     bool                    mbMenuBar;          // true - Menubar, false - Menu
94     NSMenu*                 mpMenu;             // The Carbon reference to this menu
95     Menu*                   mpVCLMenu;          // the corresponding vcl Menu object
96     const AquaSalFrame*     mpFrame;            // the frame to dispatch the menu events to
97     AquaSalMenu*            mpParentSalMenu;    // the parent menu that contains us (and perhaps has a frame)
98 
99     static const AquaSalMenu* pCurrentMenuBar;
100 
101 };
102 
103 class AquaSalMenuItem : public SalMenuItem
104 {
105 public:
106     AquaSalMenuItem( const SalItemParams* );
107     virtual ~AquaSalMenuItem();
108 
109     sal_uInt16          mnId;                 // Item ID
110     Menu*               mpVCLMenu;            // VCL Menu into which this MenuItem is inserted
111     AquaSalMenu*        mpParentMenu;         // The menu in which this menu item is inserted
112     AquaSalMenu*        mpSubMenu;            // Sub menu of this item (if defined)
113     NSMenuItem*         mpMenuItem;           // The NSMenuItem
114 };
115 
116 #endif // _SV_SALMENU_H
117