2006-07-25 18:51:41 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-11-06 15:35:24 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 22:01:16 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-11-06 15:35:24 +00:00
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2001-11-06 15:35:24 +00:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-11-06 15:35:24 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
2006-01-05 17:07:01 +00:00
|
|
|
* Contributor(s):
|
|
|
|
* Josh Aas <josh@mozilla.com>
|
2007-10-30 04:03:42 +00:00
|
|
|
* Colin Barrett <cbarrett@mozilla.com>
|
2001-11-06 15:35:24 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 22:01:16 +00:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-11-06 15:35:24 +00:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 22:01:16 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-11-06 15:35:24 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 22:01:16 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-11-06 15:35:24 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2007-01-18 06:34:07 +00:00
|
|
|
|
|
|
|
#ifndef nsCocoaWindow_h_
|
|
|
|
#define nsCocoaWindow_h_
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2002-12-13 08:43:18 +00:00
|
|
|
#undef DARWIN
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
#import <Cocoa/Cocoa.h>
|
2001-11-06 15:35:24 +00:00
|
|
|
|
|
|
|
#include "nsBaseWidget.h"
|
2006-05-17 18:53:58 +00:00
|
|
|
#include "nsPIWidgetCocoa.h"
|
2001-11-06 15:35:24 +00:00
|
|
|
|
|
|
|
class nsCocoaWindow;
|
2006-07-25 18:51:41 +00:00
|
|
|
class nsChildView;
|
2001-11-06 15:35:24 +00:00
|
|
|
|
|
|
|
|
2007-07-17 20:29:39 +00:00
|
|
|
@interface NSApplication (Undocumented)
|
|
|
|
|
|
|
|
// It's sometimes necessary to explicitly remove a window from the "window
|
|
|
|
// cache" in order to deactivate it. The "window cache" is an undocumented
|
|
|
|
// subsystem, all of whose methods are included in the NSWindowCache category
|
|
|
|
// of the NSApplication class (in header files generated using class-dump).
|
|
|
|
- (void)_removeWindowFromCache:(NSWindow *)aWindow;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@interface NSWindow (Undocumented)
|
|
|
|
|
|
|
|
// If a window has been explicitly removed from the "window cache" (to
|
|
|
|
// deactivate it), it's sometimes necessary to "reset" it to reactivate it
|
|
|
|
// (and put it back in the "window cache"). One way to do this, which Apple
|
|
|
|
// often uses, is to set the "window number" to '-1' and then back to its
|
|
|
|
// original value.
|
|
|
|
- (void)_setWindowNumber:(int)aNumber;
|
|
|
|
|
2007-10-30 04:03:42 +00:00
|
|
|
// If we set the window's stylemask to be textured, the corners on the bottom of
|
|
|
|
// the window are rounded by default. We use this private method to make
|
|
|
|
// the corners square again, a la Safari.
|
|
|
|
- (void)setBottomCornerRounded:(BOOL)rounded;
|
|
|
|
|
2007-07-17 20:29:39 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@interface PopupWindow : NSWindow
|
|
|
|
{
|
|
|
|
@private
|
|
|
|
BOOL mIsContextMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
|
|
|
|
backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation;
|
|
|
|
- (BOOL)isContextMenu;
|
|
|
|
- (void)setIsContextMenu:(BOOL)flag;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
2007-10-19 15:47:58 +00:00
|
|
|
@interface BorderlessWindow : NSWindow
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canBecomeKeyWindow;
|
|
|
|
- (BOOL)canBecomeMainWindow;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
@interface WindowDelegate : NSObject
|
|
|
|
{
|
2007-04-06 00:26:53 +00:00
|
|
|
nsCocoaWindow* mGeckoWindow; // [WEAK] (we are owned by the window)
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
- (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind;
|
2006-04-25 19:20:31 +00:00
|
|
|
- (void)windowDidResize:(NSNotification*)aNotification;
|
2007-08-02 23:01:32 +00:00
|
|
|
- (void)sendFocusEvent:(PRUint32)eventType;
|
2006-12-19 19:26:41 +00:00
|
|
|
- (nsCocoaWindow*)geckoWidget;
|
2001-11-06 15:35:24 +00:00
|
|
|
@end
|
|
|
|
|
2007-10-30 04:03:42 +00:00
|
|
|
|
|
|
|
// NSColor subclass that allows us to draw separate colors both in the titlebar
|
|
|
|
// and for background of the window.
|
|
|
|
@interface TitlebarAndBackgroundColor : NSColor
|
|
|
|
{
|
|
|
|
NSColor *mTitlebarColor;
|
|
|
|
NSColor *mBackgroundColor;
|
|
|
|
NSWindow *mWindow; // [WEAK] (we are owned by the window)
|
|
|
|
float mTitlebarHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithTitlebarColor:(NSColor*)aTitlebarColor
|
|
|
|
andBackgroundColor:(NSColor*)aBackgroundColor
|
|
|
|
forWindow:(NSWindow*)aWindow;
|
|
|
|
|
|
|
|
// Pass nil here to get the default appearance.
|
|
|
|
- (void)setTitlebarColor:(NSColor*)aColor;
|
|
|
|
- (NSColor*)titlebarColor;
|
|
|
|
|
|
|
|
- (void)setBackgroundColor:(NSColor*)aColor;
|
|
|
|
- (NSColor*)backgroundColor;
|
|
|
|
|
|
|
|
- (NSWindow*)window;
|
|
|
|
- (float)titlebarHeight;
|
|
|
|
@end
|
|
|
|
|
|
|
|
// NSWindow subclass for handling windows with toolbars.
|
2007-05-31 05:07:18 +00:00
|
|
|
@interface ToolbarWindow : NSWindow
|
|
|
|
{
|
2007-10-30 04:03:42 +00:00
|
|
|
TitlebarAndBackgroundColor *mColor;
|
2007-05-31 05:07:18 +00:00
|
|
|
}
|
2007-10-30 04:03:42 +00:00
|
|
|
- (void)setTitlebarColor:(NSColor*)aColor;
|
|
|
|
- (NSColor*)titlebarColor;
|
|
|
|
// This method is also available on NSWindows (via a category), and is the
|
|
|
|
// preferred way to check the background color of a window.
|
|
|
|
- (NSColor*)windowBackgroundColor;
|
2007-05-31 05:07:18 +00:00
|
|
|
@end
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-05-17 18:53:58 +00:00
|
|
|
class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa
|
2001-11-06 15:35:24 +00:00
|
|
|
{
|
|
|
|
private:
|
2006-12-23 20:25:51 +00:00
|
|
|
|
2006-02-02 01:20:54 +00:00
|
|
|
typedef nsBaseWidget Inherited;
|
2001-11-06 15:35:24 +00:00
|
|
|
|
|
|
|
public:
|
2001-11-14 22:29:25 +00:00
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
nsCocoaWindow();
|
|
|
|
virtual ~nsCocoaWindow();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2006-05-17 18:53:58 +00:00
|
|
|
NS_DECL_NSPIWIDGETCOCOA
|
2001-11-06 15:35:24 +00:00
|
|
|
|
|
|
|
NS_IMETHOD Create(nsNativeWidget aParent,
|
2006-02-02 01:20:54 +00:00
|
|
|
const nsRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
|
|
|
nsIDeviceContext *aContext,
|
|
|
|
nsIAppShell *aAppShell = nsnull,
|
|
|
|
nsIToolkit *aToolkit = nsnull,
|
|
|
|
nsWidgetInitData *aInitData = nsnull);
|
2001-11-06 15:35:24 +00:00
|
|
|
|
|
|
|
NS_IMETHOD Create(nsIWidget* aParent,
|
2006-02-02 01:20:54 +00:00
|
|
|
const nsRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
|
|
|
nsIDeviceContext *aContext,
|
|
|
|
nsIAppShell *aAppShell = nsnull,
|
|
|
|
nsIToolkit *aToolkit = nsnull,
|
|
|
|
nsWidgetInitData *aInitData = nsnull);
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-07-25 18:51:41 +00:00
|
|
|
NS_IMETHOD Destroy();
|
2001-11-06 15:35:24 +00:00
|
|
|
// Utility method for implementing both Create(nsIWidget ...) and
|
|
|
|
// Create(nsNativeWidget...)
|
|
|
|
|
|
|
|
virtual nsresult StandardCreate(nsIWidget *aParent,
|
2006-02-02 01:20:54 +00:00
|
|
|
const nsRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
|
|
|
nsIDeviceContext *aContext,
|
|
|
|
nsIAppShell *aAppShell,
|
|
|
|
nsIToolkit *aToolkit,
|
|
|
|
nsWidgetInitData *aInitData,
|
2006-02-10 21:39:30 +00:00
|
|
|
nsNativeWidget aNativeWindow = nsnull);
|
2001-11-06 15:35:24 +00:00
|
|
|
|
|
|
|
NS_IMETHOD Show(PRBool aState);
|
2006-07-25 18:51:41 +00:00
|
|
|
NS_IMETHOD AddMouseListener(nsIMouseListener * aListener);
|
|
|
|
NS_IMETHOD AddEventListener(nsIEventListener * aListener);
|
2002-02-28 23:10:04 +00:00
|
|
|
NS_IMETHOD Enable(PRBool aState);
|
|
|
|
NS_IMETHOD IsEnabled(PRBool *aState);
|
2007-09-19 19:17:06 +00:00
|
|
|
NS_IMETHOD SetModal(PRBool aState);
|
2002-02-12 08:30:01 +00:00
|
|
|
NS_IMETHOD IsVisible(PRBool & aState);
|
2006-07-25 18:51:41 +00:00
|
|
|
NS_IMETHOD SetFocus(PRBool aState=PR_FALSE);
|
2005-10-07 23:31:45 +00:00
|
|
|
NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar);
|
|
|
|
virtual nsIMenuBar* GetMenuBar();
|
|
|
|
NS_IMETHOD ShowMenuBar(PRBool aShow);
|
2007-01-25 19:19:48 +00:00
|
|
|
NS_IMETHOD WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
|
|
|
|
NS_IMETHOD ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
|
2001-11-06 15:35:24 +00:00
|
|
|
|
|
|
|
virtual void* GetNativeData(PRUint32 aDataType) ;
|
|
|
|
|
2002-01-09 01:29:18 +00:00
|
|
|
NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
|
|
|
|
PRInt32 *aX, PRInt32 *aY);
|
2001-11-06 15:35:24 +00:00
|
|
|
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
|
2003-10-07 01:19:51 +00:00
|
|
|
NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
|
|
|
nsIWidget *aWidget, PRBool aActivate);
|
2001-11-06 15:35:24 +00:00
|
|
|
NS_IMETHOD SetSizeMode(PRInt32 aMode);
|
|
|
|
|
|
|
|
NS_IMETHOD Resize(PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
|
|
|
|
NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint);
|
2006-02-02 01:20:54 +00:00
|
|
|
NS_IMETHOD GetScreenBounds(nsRect &aRect);
|
2001-11-06 15:35:24 +00:00
|
|
|
virtual PRBool OnPaint(nsPaintEvent &event);
|
2007-11-27 00:24:13 +00:00
|
|
|
void ReportSizeEvent(NSRect *overrideRect = nsnull);
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-02-02 01:20:54 +00:00
|
|
|
NS_IMETHOD SetTitle(const nsAString& aTitle);
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-07-25 18:51:41 +00:00
|
|
|
NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous);
|
|
|
|
NS_IMETHOD Invalidate(PRBool aIsSynchronous);
|
|
|
|
NS_IMETHOD Update();
|
|
|
|
NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *alCipRect) { return NS_OK; }
|
2001-11-06 15:35:24 +00:00
|
|
|
NS_IMETHOD SetColorMap(nsColorMap *aColorMap) { return NS_OK; }
|
|
|
|
NS_IMETHOD BeginResizingChildren(void) { return NS_OK; }
|
|
|
|
NS_IMETHOD EndResizingChildren(void) { return NS_OK; }
|
|
|
|
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) { return NS_OK; }
|
|
|
|
NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) { return NS_OK; }
|
|
|
|
NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) ;
|
2006-03-07 20:02:09 +00:00
|
|
|
NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
|
2006-07-11 19:51:56 +00:00
|
|
|
NS_IMETHOD GetAttention(PRInt32 aCycleCount);
|
2007-10-30 04:03:42 +00:00
|
|
|
NS_IMETHOD SetWindowTitlebarColor(nscolor aColor);
|
2007-04-06 00:11:41 +00:00
|
|
|
|
2007-08-02 18:48:28 +00:00
|
|
|
virtual gfxASurface* GetThebesSurface();
|
|
|
|
|
2006-02-02 01:20:54 +00:00
|
|
|
// be notified that a some form of drag event needs to go into Gecko
|
2006-03-07 20:02:09 +00:00
|
|
|
virtual PRBool DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers);
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
// Helpers to prevent recursive resizing during live-resize
|
|
|
|
PRBool IsResizing () const { return mIsResizing; }
|
|
|
|
void StartResizing () { mIsResizing = PR_TRUE; }
|
|
|
|
void StopResizing () { mIsResizing = PR_FALSE; }
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-02-02 01:20:54 +00:00
|
|
|
// nsIKBStateControl interface
|
|
|
|
NS_IMETHOD ResetInputState();
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2007-09-27 16:01:32 +00:00
|
|
|
NS_IMETHOD BeginSecureKeyboardInput();
|
|
|
|
NS_IMETHOD EndSecureKeyboardInput();
|
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
protected:
|
|
|
|
|
2006-02-07 19:15:42 +00:00
|
|
|
nsIWidget* mParent; // if we're a popup, this is our parent [WEAK]
|
2005-10-07 23:31:45 +00:00
|
|
|
NSWindow* mWindow; // our cocoa window [STRONG]
|
|
|
|
WindowDelegate* mDelegate; // our delegate for processing window msgs [STRONG]
|
|
|
|
nsCOMPtr<nsIMenuBar> mMenuBar;
|
2006-06-08 17:29:18 +00:00
|
|
|
NSWindow* mSheetWindowParent; // if this is a sheet, this is the NSWindow it's attached to
|
2007-08-25 01:55:28 +00:00
|
|
|
nsChildView* mPopupContentView; // if this is a popup, this is its content widget
|
2006-07-25 18:51:41 +00:00
|
|
|
|
2006-02-07 19:15:42 +00:00
|
|
|
PRPackedBool mIsResizing; // we originated the resize, prevent infinite recursion
|
|
|
|
PRPackedBool mWindowMadeHere; // true if we created the window, false for embedding
|
|
|
|
PRPackedBool mVisible; // Whether or not we're visible.
|
2006-06-08 17:29:18 +00:00
|
|
|
PRPackedBool mSheetNeedsShow; // if this is a sheet, are we waiting to be shown?
|
2007-09-19 19:17:06 +00:00
|
|
|
PRPackedBool mModal;
|
2001-11-06 15:35:24 +00:00
|
|
|
};
|
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
|
2007-01-18 06:34:07 +00:00
|
|
|
#endif // nsCocoaWindow_h_
|