Back to index

lightning-sunbird  0.9+nobinonly
nsCocoaWindow.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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef MacWindow_h__
00038 #define MacWindow_h__
00039 
00040 #undef DARWIN
00041 #import <Cocoa/Cocoa.h>
00042 
00043 
00044 //#include <memory>  // for auto_ptr
00045 #include <Controls.h>
00046 
00047 //using std::auto_ptr;
00048 
00049 #include "nsBaseWidget.h"
00050 
00051 //#include "nsMacEventHandler.h"
00052 
00053 class nsCocoaWindow;
00054 
00055 
00056 @interface WindowDelegate : NSObject
00057 {
00058   nsCocoaWindow* mGeckoWindow;
00059 }
00060 - (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind;
00061 - (void)windowDidResize:(NSNotification *)aNotification;
00062 @end
00063 
00064 
00065 
00066 //-------------------------------------------------------------------------
00067 //
00068 // nsCocoaWindow
00069 //
00070 //-------------------------------------------------------------------------
00071 //     Cocoa native window
00072 
00073 class nsCocoaWindow : public nsBaseWidget
00074 {
00075 private:
00076        typedef nsBaseWidget Inherited;
00077 
00078 public:
00079 
00080     enum { kTitleBarHeight = 20 };
00081 
00082     nsCocoaWindow();
00083     virtual ~nsCocoaWindow();
00084 
00085     NS_DECL_ISUPPORTS_INHERITED
00086       
00087     NS_IMETHOD              Create(nsNativeWidget aParent,
00088                                      const nsRect &aRect,
00089                                      EVENT_CALLBACK aHandleEventFunction,
00090                                      nsIDeviceContext *aContext,
00091                                      nsIAppShell *aAppShell = nsnull,
00092                                      nsIToolkit *aToolkit = nsnull,
00093                                      nsWidgetInitData *aInitData = nsnull);
00094 
00095     NS_IMETHOD              Create(nsIWidget* aParent,
00096                                      const nsRect &aRect,
00097                                      EVENT_CALLBACK aHandleEventFunction,
00098                                      nsIDeviceContext *aContext,
00099                                      nsIAppShell *aAppShell = nsnull,
00100                                      nsIToolkit *aToolkit = nsnull,
00101                                      nsWidgetInitData *aInitData = nsnull);
00102 
00103      // Utility method for implementing both Create(nsIWidget ...) and
00104      // Create(nsNativeWidget...)
00105 
00106     virtual nsresult        StandardCreate(nsIWidget *aParent,
00107                                                         const nsRect &aRect,
00108                                                         EVENT_CALLBACK aHandleEventFunction,
00109                                                         nsIDeviceContext *aContext,
00110                                                         nsIAppShell *aAppShell,
00111                                                         nsIToolkit *aToolkit,
00112                                                         nsWidgetInitData *aInitData,
00113                                                         nsNativeWidget aNativeParent = nsnull);
00114 
00115     NS_IMETHOD              Show(PRBool aState);
00116     
00117     NS_IMETHOD              Enable(PRBool aState);
00118     NS_IMETHOD              IsEnabled(PRBool *aState);
00119     NS_IMETHOD              SetModal(PRBool aState) { return NS_OK; }
00120     NS_IMETHOD              IsVisible(PRBool & aState);
00121     NS_IMETHOD              SetFocus(PRBool aState=PR_FALSE) { return NS_OK; }
00122     NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar) { return NS_OK; }
00123     NS_IMETHOD ShowMenuBar(PRBool aShow) { return NS_OK; }
00124     NS_IMETHOD WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) { return NS_OK; }
00125     NS_IMETHOD ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect) { return NS_OK; }
00126     
00127     virtual void* GetNativeData(PRUint32 aDataType) ;
00128 
00129     NS_IMETHOD              ConstrainPosition(PRBool aAllowSlop,
00130                                               PRInt32 *aX, PRInt32 *aY);
00131     NS_IMETHOD              Move(PRInt32 aX, PRInt32 aY);
00132     NS_IMETHOD              PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
00133                                         nsIWidget *aWidget, PRBool aActivate);
00134     NS_IMETHOD              SetSizeMode(PRInt32 aMode);
00135     void                    CalculateAndSetZoomedSize();
00136 
00137     NS_IMETHOD              Resize(PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
00138     NS_IMETHOD              Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint);
00139     NS_IMETHOD              GetScreenBounds(nsRect &aRect);
00140     virtual PRBool          OnPaint(nsPaintEvent &event);
00141     void                    ReportSizeEvent();
00142 
00143               NS_IMETHOD              SetTitle(const nsAString& aTitle);
00144 
00145     virtual nsIFontMetrics* GetFont(void) { return nsnull; }
00146     NS_IMETHOD SetFont(const nsFont &aFont) { return NS_OK; }
00147     NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous) { return NS_OK; }
00148     NS_IMETHOD Invalidate(PRBool aIsSynchronous) { return NS_OK; };
00149     NS_IMETHOD Update() { return NS_OK; }
00150     NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) { return NS_OK; }
00151     NS_IMETHOD SetColorMap(nsColorMap *aColorMap) { return NS_OK; }
00152     NS_IMETHOD BeginResizingChildren(void) { return NS_OK; }
00153     NS_IMETHOD EndResizingChildren(void) { return NS_OK; }
00154     NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) { return NS_OK; }
00155     NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) { return NS_OK; }
00156     NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) ;
00157     NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent) { return NS_OK; }
00158     
00159               // be notified that a some form of drag event needs to go into Gecko
00160        virtual PRBool                     DragEvent ( unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers ) ;
00161 
00162       // Helpers to prevent recursive resizing during live-resize
00163     PRBool IsResizing ( ) const { return mIsResizing; }
00164     void StartResizing ( ) { mIsResizing = PR_TRUE; }
00165     void StopResizing ( ) { mIsResizing = PR_FALSE; }
00166     
00167     void                    ComeToFront();
00168 
00169        // nsIKBStateControl interface
00170        NS_IMETHOD ResetInputState();
00171 
00172     void                           MoveToGlobalPoint(PRInt32 aX, PRInt32 aY);
00173 
00174     void IsActive(PRBool* aActive);
00175     void SetIsActive(PRBool aActive);
00176 protected:
00177 
00178 #if 0
00179        pascal static OSErr DragTrackingHandler ( DragTrackingMessage theMessage, WindowPtr theWindow, 
00180                                                                       void *handlerRefCon, DragReference theDrag );
00181        pascal static OSErr DragReceiveHandler (WindowPtr theWindow,
00182                                                                                     void *handlerRefCon, DragReference theDragRef) ;
00183        DragTrackingHandlerUPP mDragTrackingHandlerUPP;
00184        DragReceiveHandlerUPP mDragReceiveHandlerUPP;
00185 #endif
00186 
00187 #if 0
00188   pascal static OSStatus WindowEventHandler ( EventHandlerCallRef inHandlerChain, 
00189                                                EventRef inEvent, void* userData ) ;
00190   pascal static OSStatus ScrollEventHandler ( EventHandlerCallRef inHandlerChain, 
00191                                                EventRef inEvent, void* userData ) ;
00192 #endif
00193 
00194 #if 0
00195        auto_ptr<nsMacEventHandler>        mMacEventHandler;
00196        PRBool                          mAcceptsActivation;
00197        PRBool                          mIsActive;
00198        PRBool                          mZoomOnShow;     
00199 #endif // COCOA
00200 
00201        nsIWidget*        mOffsetParent;   // if we're a popup, this is our parent [WEAK]
00202        PRBool                          mIsDialog;       // true if the window is a dialog
00203        PRBool            mIsResizing;     // we originated the resize, prevent infinite recursion
00204        PRBool            mWindowMadeHere; // true if we created the window, false for embedding
00205   NSWindow*         mWindow;         // our cocoa window [STRONG]
00206   WindowDelegate*   mDelegate;       // our delegate for processing window msgs [STRONG]
00207 
00208   PRBool            mVisible;        // Whether or not we're visible.
00209 };
00210 
00211 #endif // MacWindow_h__