Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / widget / src / cocoa / nsCocoaWindow.h
blob04619a7ed2ddd847dcc44c9f6344e55017f433c1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Josh Aas <josh@mozilla.com>
24 * Colin Barrett <cbarrett@mozilla.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef nsCocoaWindow_h_
41 #define nsCocoaWindow_h_
43 #undef DARWIN
45 #import <Cocoa/Cocoa.h>
47 #include "nsBaseWidget.h"
48 #include "nsPIWidgetCocoa.h"
49 #include "nsAutoPtr.h"
51 class nsCocoaWindow;
52 class nsChildView;
53 class nsMenuBarX;
55 typedef struct _nsCocoaWindowList {
56 _nsCocoaWindowList() : prev(NULL), window(NULL) {}
57 struct _nsCocoaWindowList *prev;
58 nsCocoaWindow *window; // Weak
59 } nsCocoaWindowList;
62 @interface NSWindow (Undocumented)
64 // If a window has been explicitly removed from the "window cache" (to
65 // deactivate it), it's sometimes necessary to "reset" it to reactivate it
66 // (and put it back in the "window cache"). One way to do this, which Apple
67 // often uses, is to set the "window number" to '-1' and then back to its
68 // original value.
69 - (void)_setWindowNumber:(int)aNumber;
71 // If we set the window's stylemask to be textured, the corners on the bottom of
72 // the window are rounded by default. We use this private method to make
73 // the corners square again, a la Safari.
74 - (void)setBottomCornerRounded:(BOOL)rounded;
76 @end
79 @interface PopupWindow : NSWindow
81 @private
82 BOOL mIsContextMenu;
85 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
86 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation;
87 - (BOOL)isContextMenu;
88 - (void)setIsContextMenu:(BOOL)flag;
90 @end
93 @interface BorderlessWindow : NSWindow
97 - (BOOL)canBecomeKeyWindow;
98 - (BOOL)canBecomeMainWindow;
100 @end
103 @interface WindowDelegate : NSObject
105 nsCocoaWindow* mGeckoWindow; // [WEAK] (we are owned by the window)
106 // Used to avoid duplication when we send NS_ACTIVATE/NS_GOTFOCUS and
107 // NS_DEACTIVATE/NS_LOSTFOCUS to Gecko for toplevel widgets. Starts out
108 // PR_FALSE.
109 PRBool mToplevelActiveState;
111 + (void)paintMenubarForWindow:(NSWindow*)aWindow;
112 - (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind;
113 - (void)windowDidResize:(NSNotification*)aNotification;
114 - (void)sendFocusEvent:(PRUint32)eventType;
115 - (nsCocoaWindow*)geckoWidget;
116 - (PRBool)toplevelActiveState;
117 - (void)sendToplevelActivateEvents;
118 - (void)sendToplevelDeactivateEvents;
119 @end
121 struct UnifiedGradientInfo {
122 float titlebarHeight;
123 float toolbarHeight;
124 BOOL windowIsMain;
125 BOOL drawTitlebar; // NO for toolbar, YES for titlebar
128 // NSColor subclass that allows us to draw separate colors both in the titlebar
129 // and for background of the window.
130 @interface TitlebarAndBackgroundColor : NSColor
132 NSColor *mActiveTitlebarColor;
133 NSColor *mInactiveTitlebarColor;
134 NSColor *mBackgroundColor;
135 NSWindow *mWindow; // [WEAK] (we are owned by the window)
138 - (id)initWithActiveTitlebarColor:(NSColor*)aActiveTitlebarColor
139 inactiveTitlebarColor:(NSColor*)aInactiveTitlebarColor
140 backgroundColor:(NSColor*)aBackgroundColor
141 forWindow:(NSWindow*)aWindow;
143 // Pass nil here to get the default appearance.
144 - (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive;
145 - (NSColor*)activeTitlebarColor;
146 - (NSColor*)inactiveTitlebarColor;
148 - (void)setBackgroundColor:(NSColor*)aColor;
149 - (NSColor*)backgroundColor;
151 - (NSWindow*)window;
152 @end
154 // NSWindow subclass for handling windows with toolbars.
155 @interface ToolbarWindow : NSWindow
157 TitlebarAndBackgroundColor *mColor;
158 float mUnifiedToolbarHeight;
159 BOOL mSuppressPainting;
161 - (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive;
162 - (void)setUnifiedToolbarHeight:(float)aToolbarHeight;
163 - (float)unifiedToolbarHeight;
164 - (float)titlebarHeight;
165 - (BOOL)isPaintingSuppressed;
166 // This method is also available on NSWindows (via a category), and is the
167 // preferred way to check the background color of a window.
168 - (NSColor*)windowBackgroundColor;
169 @end
171 class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa
173 private:
175 typedef nsBaseWidget Inherited;
177 public:
179 nsCocoaWindow();
180 virtual ~nsCocoaWindow();
182 NS_DECL_ISUPPORTS_INHERITED
183 NS_DECL_NSPIWIDGETCOCOA
185 NS_IMETHOD Create(nsNativeWidget aParent,
186 const nsRect &aRect,
187 EVENT_CALLBACK aHandleEventFunction,
188 nsIDeviceContext *aContext,
189 nsIAppShell *aAppShell = nsnull,
190 nsIToolkit *aToolkit = nsnull,
191 nsWidgetInitData *aInitData = nsnull);
193 NS_IMETHOD Create(nsIWidget* aParent,
194 const nsRect &aRect,
195 EVENT_CALLBACK aHandleEventFunction,
196 nsIDeviceContext *aContext,
197 nsIAppShell *aAppShell = nsnull,
198 nsIToolkit *aToolkit = nsnull,
199 nsWidgetInitData *aInitData = nsnull);
201 NS_IMETHOD Destroy();
202 // Utility method for implementing both Create(nsIWidget ...) and
203 // Create(nsNativeWidget...)
205 virtual nsresult StandardCreate(nsIWidget *aParent,
206 const nsRect &aRect,
207 EVENT_CALLBACK aHandleEventFunction,
208 nsIDeviceContext *aContext,
209 nsIAppShell *aAppShell,
210 nsIToolkit *aToolkit,
211 nsWidgetInitData *aInitData,
212 nsNativeWidget aNativeWindow = nsnull);
214 NS_IMETHOD Show(PRBool aState);
215 virtual nsIWidget* GetSheetWindowParent(void);
216 NS_IMETHOD AddEventListener(nsIEventListener * aListener);
217 NS_IMETHOD Enable(PRBool aState);
218 NS_IMETHOD IsEnabled(PRBool *aState);
219 NS_IMETHOD SetModal(PRBool aState);
220 NS_IMETHOD IsVisible(PRBool & aState);
221 NS_IMETHOD SetFocus(PRBool aState=PR_FALSE);
222 NS_IMETHOD SetMenuBar(void* aMenuBar);
223 virtual nsMenuBarX* GetMenuBar();
224 NS_IMETHOD ShowMenuBar(PRBool aShow);
225 NS_IMETHOD WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
226 NS_IMETHOD ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
228 virtual void* GetNativeData(PRUint32 aDataType) ;
230 NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
231 PRInt32 *aX, PRInt32 *aY);
232 NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
233 NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
234 nsIWidget *aWidget, PRBool aActivate);
235 NS_IMETHOD SetSizeMode(PRInt32 aMode);
237 NS_IMETHOD Resize(PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
238 NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint);
239 NS_IMETHOD GetScreenBounds(nsRect &aRect);
240 virtual PRBool OnPaint(nsPaintEvent &event);
241 void ReportSizeEvent(NSRect *overrideRect = nsnull);
243 NS_IMETHOD SetTitle(const nsAString& aTitle);
245 NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous);
246 NS_IMETHOD Invalidate(PRBool aIsSynchronous);
247 NS_IMETHOD Update();
248 NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *alCipRect) { return NS_OK; }
249 NS_IMETHOD SetColorMap(nsColorMap *aColorMap) { return NS_OK; }
250 NS_IMETHOD BeginResizingChildren(void) { return NS_OK; }
251 NS_IMETHOD EndResizingChildren(void) { return NS_OK; }
252 NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) { return NS_OK; }
253 NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) { return NS_OK; }
254 NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) ;
255 NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
256 NS_IMETHOD GetAttention(PRInt32 aCycleCount);
257 virtual nsTransparencyMode GetTransparencyMode();
258 virtual void SetTransparencyMode(nsTransparencyMode aMode);
259 NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle);
260 NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, PRBool aActive);
262 // dispatch an NS_SIZEMODE event on miniaturize or deminiaturize
263 void DispatchSizeModeEvent(nsSizeMode aSizeMode);
265 virtual gfxASurface* GetThebesSurface();
267 // be notified that a some form of drag event needs to go into Gecko
268 virtual PRBool DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers);
270 // Helpers to prevent recursive resizing during live-resize
271 PRBool IsResizing () const { return mIsResizing; }
272 void StartResizing () { mIsResizing = PR_TRUE; }
273 void StopResizing () { mIsResizing = PR_FALSE; }
275 PRBool HasModalDescendents() { return mNumModalDescendents > 0; }
276 NSWindow *GetCocoaWindow() { return mWindow; }
278 // nsIKBStateControl interface
279 NS_IMETHOD ResetInputState();
281 void MakeBackgroundTransparent(PRBool aTransparent);
283 NS_IMETHOD BeginSecureKeyboardInput();
284 NS_IMETHOD EndSecureKeyboardInput();
286 static void UnifiedShading(void* aInfo, const float* aIn, float* aOut);
288 protected:
290 nsIWidget* mParent; // if we're a popup, this is our parent [WEAK]
291 NSWindow* mWindow; // our cocoa window [STRONG]
292 WindowDelegate* mDelegate; // our delegate for processing window msgs [STRONG]
293 nsRefPtr<nsMenuBarX> mMenuBar;
294 NSWindow* mSheetWindowParent; // if this is a sheet, this is the NSWindow it's attached to
295 nsChildView* mPopupContentView; // if this is a popup, this is its content widget
297 PRPackedBool mIsResizing; // we originated the resize, prevent infinite recursion
298 PRPackedBool mWindowMadeHere; // true if we created the window, false for embedding
299 PRPackedBool mSheetNeedsShow; // if this is a sheet, are we waiting to be shown?
300 // this is used for sibling sheet contention only
301 PRPackedBool mModal;
303 PRInt32 mNumModalDescendents;
307 #endif // nsCocoaWindow_h_