Back to index

lightning-sunbird  0.9+nobinonly
nsMenuBarFrame.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Original Author: David W. Hyatt (hyatt@netscape.com)
00024  *   Dean Tessman <dean_tessman@hotmail.com>
00025  *   Dan Rosen <dr@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 //
00042 // nsMenuBarFrame
00043 //
00044 
00045 #ifndef nsMenuBarFrame_h__
00046 #define nsMenuBarFrame_h__
00047 
00048 #include "prtypes.h"
00049 #include "nsIAtom.h"
00050 #include "nsCOMPtr.h"
00051 #include "nsBoxFrame.h"
00052 #include "nsMenuBarListener.h"
00053 #include "nsMenuListener.h"
00054 #include "nsIMenuParent.h"
00055 #include "nsIWidget.h"
00056 
00057 class nsIContent;
00058 class nsIMenuFrame;
00059 
00060 nsresult NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsIFrame** aResult) ;
00061 
00062 class nsMenuBarFrame : public nsBoxFrame, public nsIMenuParent
00063 {
00064 public:
00065   nsMenuBarFrame(nsIPresShell* aShell);
00066   virtual ~nsMenuBarFrame();
00067 
00068   NS_DECL_ISUPPORTS
00069 
00070   // nsIMenuParentInterface
00071   virtual nsIMenuFrame* GetCurrentMenuItem();
00072   NS_IMETHOD SetCurrentMenuItem(nsIMenuFrame* aMenuItem);
00073   virtual nsIMenuFrame* GetNextMenuItem(nsIMenuFrame* aStart);
00074   virtual nsIMenuFrame* GetPreviousMenuItem(nsIMenuFrame* aStart);
00075   NS_IMETHOD SetActive(PRBool aActiveFlag); 
00076   NS_IMETHOD GetIsActive(PRBool& isActive) { isActive = IsActive(); return NS_OK; };
00077   NS_IMETHOD IsMenuBar(PRBool& isMenuBar) { isMenuBar = PR_TRUE; return NS_OK; };
00078   NS_IMETHOD ConsumeOutsideClicks(PRBool& aConsumeOutsideClicks) \
00079     {aConsumeOutsideClicks = PR_FALSE; return NS_OK;};
00080   NS_IMETHOD ClearRecentlyRolledUp();
00081   NS_IMETHOD RecentlyRolledUp(nsIMenuFrame *aMenuFrame, PRBool *aJustRolledUp);
00082 
00083   NS_IMETHOD SetIsContextMenu(PRBool aIsContextMenu) { return NS_OK; };
00084   NS_IMETHOD GetIsContextMenu(PRBool& aIsContextMenu) { aIsContextMenu = PR_FALSE; return NS_OK; }; 
00085   
00086   NS_IMETHOD IsActive() { return mIsActive; };
00087 
00088   NS_IMETHOD IsOpen();
00089   NS_IMETHOD KillPendingTimers();
00090 
00091   // Closes up the chain of open cascaded menus.
00092   NS_IMETHOD DismissChain();
00093 
00094   // Hides the chain of cascaded menus without closing them up.
00095   NS_IMETHOD HideChain();
00096 
00097   NS_IMETHOD InstallKeyboardNavigator();
00098   NS_IMETHOD RemoveKeyboardNavigator();
00099 
00100   NS_IMETHOD GetWidget(nsIWidget **aWidget);
00101   // The dismissal listener gets created and attached to the window.
00102   NS_IMETHOD CreateDismissalListener();
00103 
00104   NS_IMETHOD Init(nsPresContext*  aPresContext,
00105                   nsIContent*      aContent,
00106                   nsIFrame*        aParent,
00107                   nsStyleContext*  aContext,
00108                   nsIFrame*        aPrevInFlow);
00109 
00110   NS_IMETHOD Destroy(nsPresContext* aPresContext);
00111 
00112 // Non-interface helpers
00113 
00114   // Called when a menu on the menu bar is clicked on.
00115   void ToggleMenuActiveState();
00116   
00117   // Used to move up, down, left, and right in menus.
00118   NS_IMETHOD KeyboardNavigation(PRUint32 aKeyCode, PRBool& aHandledFlag);
00119   NS_IMETHOD ShortcutNavigation(nsIDOMKeyEvent* aKeyEvent, PRBool& aHandledFlag);
00120   // Called when the ESC key is held down to close levels of menus.
00121   NS_IMETHOD Escape(PRBool& aHandledFlag);
00122   // Called to execute a menu item.
00123   NS_IMETHOD Enter();
00124 
00125   // Used to handle ALT+key combos
00126   nsIMenuFrame* FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent);
00127 
00128   PRBool IsValidItem(nsIContent* aContent);
00129   PRBool IsDisabled(nsIContent* aContent);
00130 
00131 #ifdef DEBUG
00132   NS_IMETHOD GetFrameName(nsAString& aResult) const
00133   {
00134       return MakeFrameName(NS_LITERAL_STRING("MenuBar"), aResult);
00135   }
00136 #endif
00137 
00138 protected:
00139   nsMenuBarListener* mMenuBarListener; // The listener that tells us about key and mouse events.
00140   nsMenuListener* mKeyboardNavigator;
00141 
00142   PRBool mIsActive; // Whether or not the menu bar is active (a menu item is highlighted or shown).
00143   nsIMenuFrame* mCurrentMenu; // The current menu that is active.
00144 
00145   // Can contain a menu that was rolled up via nsIMenuDismissalListener::Rollup()
00146   // if nothing has happened since the last click. Otherwise, contains nsnull.
00147   nsIMenuFrame* mRecentRollupMenu; 
00148 
00149   nsIDOMEventReceiver* mTarget;
00150 
00151   // XXX Hack
00152   nsPresContext* mPresContext;  // weak reference
00153 
00154 private:
00155   PRBool mCaretWasVisible;
00156 
00157 }; // class nsMenuBarFrame
00158 
00159 #endif