Back to index

lightning-sunbird  0.9+nobinonly
nsWindow.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Mozilla OS/2 libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * John Fairhurst, <john_fairhurst@iname.com>.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Rich Walsh <dragtext@e-vertise.com>
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  * This Original Code has been modified by IBM Corporation.
00038  * Modifications made by IBM described herein are
00039  * Copyright (c) International Business Machines
00040  * Corporation, 2000
00041  *
00042  * Modifications to Mozilla code or documentation
00043  * identified per MPL Section 3.3
00044  *
00045  * Date             Modified by     Description of modification
00046  * 03/23/2000       IBM Corp.      Added InvalidateRegion method.
00047  * 04/12/2000       IBM Corp.      Changed params on DispatchMouseEvent to match Windows..
00048  * 04/14/2000       IBM Corp.      Declared EventIsInsideWindow for CaptureRollupEvents
00049  * 06/15/2000       IBM Corp.      Added NS2PM for rectangles
00050  * 06/21/2000       IBM Corp.      Added CaptureMouse
00051  *
00052  */
00053 
00054 #ifndef _nswindow_h
00055 #define _nswindow_h
00056 
00057 #include "nsWidgetDefs.h"
00058 #include "nsBaseWidget.h"
00059 #include "nsToolkit.h"
00060 #include "nsSwitchToUIThread.h"
00061 
00062 class imgIContainer;
00063 
00064 //#define DEBUG_FOCUS
00065 
00066 #ifdef DEBUG_FOCUS
00067   #define DEBUGFOCUS(what) printf("[%x] "#what" (%d)\n", (int)this, mWindowIdentifier)
00068 #else
00069   #define DEBUGFOCUS(what)
00070 #endif
00071 
00072 // Base widget class.
00073 // This is abstract.  Controls (labels, radio buttons, listboxen) derive
00074 // from here.  A thing called a child window derives from here, and the
00075 // frame window class derives from the child.  The content-displaying
00076 // classes are off on their own branch to avoid creating a palette for
00077 // every window we create.  This may turn out to be what's required, in
00078 // which case the paint & palette code from nsChildWindow needs to be
00079 // munged in here.  nsFrameWindow is separate because work needs to be done
00080 // there to decide whether methods apply to frame or client.
00081 
00082 /* Possible states of the window, used to emulate windows better... */
00083    // default state; Create() not called 
00084    #define   nsWindowState_ePrecreate      0x00000001
00085    // processing Create() method          
00086    #define   nsWindowState_eInCreate       0x00000002
00087    // active, existing window             
00088    #define      nsWindowState_eLive        0x00000004
00089    //processing Close() method            
00090    #define      nsWindowState_eClosing     0x00000008
00091    // object destructor running 
00092    #define      nsWindowState_eDoingDelete 0x00000010
00093    // window destroyed 
00094    #define      nsWindowState_eDead        0x00000100         
00095 
00096 MRESULT EXPENTRY fnwpNSWindow( HWND, ULONG, MPARAM, MPARAM);
00097 MRESULT EXPENTRY fnwpFrame( HWND, ULONG, MPARAM, MPARAM);
00098 
00099 class nsWindow : public nsBaseWidget,
00100                  public nsSwitchToUIThread
00101 {
00102  public:
00103    // Scaffolding
00104    nsWindow();
00105    virtual ~nsWindow();
00106 
00107   static void ReleaseGlobals();
00108 
00109    // nsIWidget
00110 
00111    // Creation from native (eh?) or widget parent, destroy
00112    NS_IMETHOD Create( nsIWidget *aParent,
00113                       const nsRect &aRect,
00114                       EVENT_CALLBACK aHandleEventFunction,
00115                       nsIDeviceContext *aContext,
00116                       nsIAppShell *aAppShell = nsnull,
00117                       nsIToolkit *aToolkit = nsnull,
00118                       nsWidgetInitData *aInitData = nsnull);
00119    NS_IMETHOD Create( nsNativeWidget aParent,
00120                       const nsRect &aRect,
00121                       EVENT_CALLBACK aHandleEventFunction,
00122                       nsIDeviceContext *aContext,
00123                       nsIAppShell *aAppShell = nsnull,
00124                       nsIToolkit *aToolkit = nsnull,
00125                       nsWidgetInitData *aInitData = nsnull);
00126    NS_IMETHOD Destroy(); // call before releasing
00127 
00128    // Hierarchy: only interested in widget children (it seems)
00129    virtual nsIWidget *GetParent();
00130 
00131     NS_IMETHOD              SetSizeMode(PRInt32 aMode);
00132 
00133    // Physical properties
00134    NS_IMETHOD Show( PRBool bState);
00135    NS_IMETHOD ConstrainPosition(PRBool aAllowSlop, PRInt32 *aX, PRInt32 *aY);
00136    NS_IMETHOD Move( PRInt32 aX, PRInt32 aY);
00137    NS_IMETHOD Resize( PRInt32 aWidth,
00138                       PRInt32 aHeight,
00139                       PRBool   aRepaint);
00140    NS_IMETHOD Resize( PRInt32 aX,
00141                       PRInt32 aY,
00142                       PRInt32 aWidth,
00143                       PRInt32 aHeight,
00144                       PRBool   aRepaint);
00145    NS_IMETHOD GetClientBounds( nsRect &aRect);
00146    NS_IMETHOD Enable( PRBool aState);
00147    NS_IMETHOD IsEnabled(PRBool *aState);
00148    NS_IMETHOD SetFocus(PRBool aRaise);
00149    NS_IMETHOD GetBounds(nsRect &aRect);
00150    NS_IMETHOD IsVisible( PRBool &aState);
00151    PRBool     IsShown();
00152    NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
00153                           nsIWidget *aWidget, PRBool aActivate);
00154 
00155    NS_IMETHOD CaptureMouse(PRBool aCapture);
00156 
00157    NS_IMETHOD ModalEventFilter( PRBool aRealEvent, void *aEvent,
00158                                 PRBool *aForWindow );
00159 
00160    NS_IMETHOD GetPreferredSize( PRInt32 &aWidth, PRInt32 &aHeight);
00161    NS_IMETHOD SetPreferredSize( PRInt32 aWidth, PRInt32 aHeight);
00162 
00163    NS_IMETHOD BeginResizingChildren();
00164    NS_IMETHOD EndResizingChildren();
00165    NS_IMETHOD WidgetToScreen( const nsRect &aOldRect, nsRect &aNewRect);
00166    NS_IMETHOD ScreenToWidget( const nsRect &aOldRect, nsRect &aNewRect);
00167    NS_IMETHOD DispatchEvent( struct nsGUIEvent *event, nsEventStatus &aStatus);
00168    NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
00169 
00170    NS_IMETHOD              GetLastInputEventTime(PRUint32& aTime);
00171 
00172    // Widget appearance
00173    virtual nsIFontMetrics *GetFont();
00174    NS_IMETHOD              SetFont( const nsFont &aFont);
00175    NS_IMETHOD              SetColorMap( nsColorMap *aColorMap);
00176    NS_IMETHOD              SetCursor( nsCursor aCursor);
00177    NS_IMETHOD              SetCursor(imgIContainer* aCursor,
00178                                      PRUint32 aHotspotX, PRUint32 aHotspotY);
00179    NS_IMETHOD              HideWindowChrome(PRBool aShouldHide);
00180    NS_IMETHOD              SetTitle( const nsAString& aTitle); 
00181    NS_IMETHOD              SetIcon(const nsAString& aIconSpec); 
00182    NS_IMETHOD              SetMenuBar(nsIMenuBar * aMenuBar) { return NS_ERROR_FAILURE; } 
00183    NS_IMETHOD              ShowMenuBar(PRBool aShow)         { return NS_ERROR_FAILURE; } 
00184    NS_IMETHOD              Invalidate( PRBool aIsSynchronous);
00185    NS_IMETHOD              Invalidate( const nsRect & aRect, PRBool aIsSynchronous);
00186    NS_IMETHOD              InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous);
00187    NS_IMETHOD              Update();
00188    NS_IMETHOD              Scroll( PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
00189    NS_IMETHOD              ScrollWidgets(PRInt32 aDx, PRInt32 aDy);
00190    NS_IMETHOD              ScrollRect(nsRect &aRect, PRInt32 aDx, PRInt32 aDy);
00191 
00192 #if 0 // Handled by XP code now
00193    // Tooltips
00194    NS_IMETHOD SetTooltips( PRUint32 aNumberOfTips, nsRect *aTooltipAreas[]);   
00195    NS_IMETHOD RemoveTooltips();
00196    NS_IMETHOD UpdateTooltips( nsRect* aNewTips[]);
00197 #endif
00198 
00199    // Get a HWND or a HPS.
00200    virtual void  *GetNativeData( PRUint32 aDataType);
00201    virtual void   FreeNativeData( void *aDatum, PRUint32 aDataType);
00202    virtual HWND   GetMainWindow() const           { return mWnd; }
00203 
00204    // nsSwitchToPMThread interface
00205     virtual BOOL            CallMethod(MethodInfo *info);
00206 
00207    // PM methods which need to be public (menus, etc)
00208    ULONG  GetNextID()    { return mNextID++; }
00209    void   NS2PM_PARENT( POINTL &ptl);
00210    void   NS2PM( POINTL &ptl);
00211    void   NS2PM( RECTL &rcl);
00212 
00213 protected:
00214     static  BOOL            DealWithPopups ( ULONG inMsg, MRESULT* outResult ) ;
00215 
00216     static  PRBool          EventIsInsideWindow(nsWindow* aWindow); 
00217 
00218     static  nsWindow *      GetNSWindowPtr(HWND aWnd);
00219     static  BOOL            SetNSWindowPtr(HWND aWnd, nsWindow * ptr);
00220 
00221    static  nsWindow*   gCurrentWindow;
00222    // nsWindow methods subclasses must provide for creation to work
00223    virtual PCSZ  WindowClass();
00224    virtual ULONG WindowStyle();
00225 
00226    // hooks subclasses may wish to override!
00227    virtual void     PostCreateWidget()            {}
00228    virtual PRInt32  GetClientHeight()             { return mBounds.height; }
00229    virtual ULONG    GetSWPFlags( ULONG flags)     { return flags; }
00230    virtual void     SetupForPrint( HWND /*hwnd*/) {}
00231 
00232    // Useful functions for subclasses to use, threaded as necessary.
00233    virtual nsresult GetWindowText( nsString &str, PRUint32 *rc);
00234    virtual void     AddToStyle( ULONG style);
00235    virtual void     RemoveFromStyle( ULONG style);
00236    // return true if deferred
00237    virtual BOOL     SetWindowPos( HWND hwndInsertBehind, long x, long y,
00238                                   long cx, long cy, unsigned long flags);
00239 
00240    // Message handlers - may wish to override.  Default implementation for
00241    // palette, control, paint & scroll is to do nothing.
00242 
00243    // Return whether message has been processed.
00244    virtual PRBool ProcessMessage( ULONG m, MPARAM p1, MPARAM p2, MRESULT &r);
00245    virtual PRBool OnPaint();
00246    virtual void   OnDestroy();
00247    virtual PRBool OnReposition( PSWP pNewSwp);
00248    virtual PRBool OnResize( PRInt32 aX, PRInt32 aY);
00249    virtual PRBool OnMove( PRInt32 aX, PRInt32 aY);
00250    virtual PRBool OnKey( MPARAM mp1, MPARAM mp2);
00251    virtual PRBool OnRealizePalette();
00252    virtual PRBool DispatchFocus( PRUint32 aEventType, PRBool isMozWindowTakingFocus);
00253    virtual PRBool OnScroll( ULONG msgid, MPARAM mp1, MPARAM mp2);
00254    virtual PRBool OnVScroll( MPARAM mp1, MPARAM mp2);
00255    virtual PRBool OnHScroll( MPARAM mp1, MPARAM mp2);
00256    virtual PRBool OnControl( MPARAM mp1, MPARAM mp2);
00257 //   virtual PRBool OnMenuClick( USHORT aCmd);
00258 //   virtual PRBool OnActivateMenu( HWND aMenu, BOOL aActivate);
00259    // called after param has been set...
00260    virtual PRBool OnPresParamChanged( MPARAM mp1, MPARAM mp2);
00261    virtual PRBool OnDragDropMsg(ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT &mr);
00262 
00263    static BOOL sIsRegistered;
00264 
00265    // PM data members
00266    HWND      mWnd;            // window handle
00267    HWND      mFrameWnd;       // frame window handle
00268    PFNWP     mPrevWndProc;    // previous window procedure
00269    nsWindow *mParent;         // parent widget
00270    ULONG     mNextID;         // next child window id
00271    PSWP      mSWPs;           // SWPs for deferred window positioning
00272    ULONG     mlHave, mlUsed;  // description of mSWPs array
00273    HPOINTER  mFrameIcon;      // current frame icon
00274    VDKEY     mDeadKey;        // dead key from previous keyevent
00275    BOOL      mHaveDeadKey;    // is mDeadKey valid [0 may be a valid dead key, for all I know]
00276    QMSG      mQmsg;
00277    PRBool    mIsTopWidgetWindow;
00278    BOOL      mIsScrollBar;
00279    BOOL      mInSetFocus;
00280    BOOL      mChromeHidden;
00281    nsContentType mContentType;
00282    HPS       mDragHps;        // retrieved by DrgGetPS() during a drag
00283    PRUint32  mDragStatus;     // set while this object is being dragged over
00284    HPOINTER  mCssCursorHPtr;  // created by SetCursor(imgIContainer*)
00285    nsCOMPtr<imgIContainer> mCssCursorImg;  // saved by SetCursor(imgIContainer*)
00286    BOOL      mIsVisible;
00287 
00288    HWND      GetParentHWND() const;
00289    HWND      GetHWND() const   { return mWnd; }
00290    PFNWP     GetPrevWP() const { return mPrevWndProc; }
00291 
00292    // nglayout data members
00293    PRInt32        mPreferredHeight;
00294    PRInt32        mPreferredWidth;
00295    nsToolkit     *mOS2Toolkit;
00296    nsFont        *mFont;
00297    nsIMenuBar    *mMenuBar;
00298    PRInt32        mWindowState;
00299 
00300    // Implementation ------------------------------
00301    void DoCreate( HWND hwndP, nsWindow *wndP, const nsRect &rect,
00302                   EVENT_CALLBACK aHandleEventFunction,
00303                   nsIDeviceContext *aContext, nsIAppShell *aAppShell,
00304                   nsIToolkit *aToolkit, nsWidgetInitData *aInitData);
00305 
00306    virtual void RealDoCreate( HWND hwndP, nsWindow *aParent,
00307                               const nsRect &aRect,
00308                               EVENT_CALLBACK aHandleEventFunction,
00309                               nsIDeviceContext *aContext,
00310                               nsIAppShell *aAppShell,
00311                               nsWidgetInitData *aInitData,
00312                               HWND hwndOwner = 0);
00313 
00314    // hook so dialog can be created looking like a dialog
00315    virtual ULONG GetFCFlags();
00316 
00317    virtual void SubclassWindow(BOOL bState);
00318 
00319    PRBool  ConvertStatus( nsEventStatus aStatus);
00320    void    InitEvent( nsGUIEvent &event, nsPoint *pt = 0);
00321    virtual PRBool DispatchWindowEvent(nsGUIEvent* event);
00322    virtual PRBool DispatchWindowEvent(nsGUIEvent*event, nsEventStatus &aStatus);
00323    PRBool  DispatchStandardEvent( PRUint32 aMsg);
00324    PRBool  DispatchAppCommandEvent(PRUint32 aEventCommand);
00325    PRBool  DispatchDragDropEvent(PRUint32 aMsg);
00326    virtual PRBool DispatchMouseEvent( PRUint32 aEventType, MPARAM mp1, MPARAM mp2);
00327    virtual PRBool DispatchResizeEvent( PRInt32 aClientX, PRInt32 aClientY);
00328    void GetNonClientBounds(nsRect &aRect);
00329    void    DeferPosition( HWND, HWND, long, long, long, long, ULONG);
00330    void ConstrainZLevel(HWND *aAfter);
00331 
00332    PRBool   CheckDragStatus(PRUint32 aAction, HPS * oHps);
00333    PRBool   ReleaseIfDragHPS(HPS aHps);
00334 
00335    HBITMAP DataToBitmap(PRUint8* aImageData, PRUint32 aWidth,
00336                         PRUint32 aHeight, PRUint32 aDepth);
00337    // 'format' should be 'gfx_format' which is a PRInt32
00338    HBITMAP CreateTransparencyMask(PRInt32  format, PRUint8* aImageData,
00339                                   PRUint32 aWidth, PRUint32 aHeight);
00340 
00341    BOOL NotifyForeignChildWindows(HWND aWnd);
00342 
00343    // Enumeration of the methods which are accessable on the PM thread
00344    enum {
00345       CREATE,
00346       DESTROY,
00347       SET_FOCUS,
00348       UPDATE_WINDOW,
00349       SET_TITLE,
00350       GET_TITLE
00351    };
00352    friend MRESULT EXPENTRY fnwpNSWindow( HWND, ULONG, MPARAM, MPARAM);
00353    friend MRESULT EXPENTRY fnwpFrame( HWND, ULONG, MPARAM, MPARAM);
00354 #ifdef DEBUG_FOCUS
00355    int mWindowIdentifier;
00356 #endif
00357 };
00358 
00359 #define PM2NS_PARENT NS2PM_PARENT
00360 #define PM2NS NS2PM
00361 
00362 #define PMSCAN_PADMULT      0x37
00363 #define PMSCAN_PAD7         0x47
00364 #define PMSCAN_PAD8         0x48
00365 #define PMSCAN_PAD9         0x49
00366 #define PMSCAN_PADMINUS     0x4A
00367 #define PMSCAN_PAD4         0x4B
00368 #define PMSCAN_PAD5         0x4C
00369 #define PMSCAN_PAD6         0x4D
00370 #define PMSCAN_PADPLUS      0x4E
00371 #define PMSCAN_PAD1         0x4F
00372 #define PMSCAN_PAD2         0x50
00373 #define PMSCAN_PAD3         0x51
00374 #define PMSCAN_PAD0         0x52
00375 #define PMSCAN_PADPERIOD    0x53
00376 #define PMSCAN_PADDIV       0x5c
00377 
00378 #define isNumPadScanCode(scanCode) !( (scanCode < PMSCAN_PAD7) ||      \
00379                                       (scanCode > PMSCAN_PADPERIOD) || \
00380                                       (scanCode == PMSCAN_PADMULT) ||  \
00381                                       (scanCode == PMSCAN_PADDIV) ||   \
00382                                       (scanCode == PMSCAN_PADMINUS) || \
00383                                       (scanCode == PMSCAN_PADPLUS) )
00384 #define isNumlockOn (BOOL)WinGetKeyState(HWND_DESKTOP, VK_NUMLOCK) & 0x0001
00385 
00386 extern PRUint32 WMChar2KeyCode( MPARAM mp1, MPARAM mp2);
00387 
00388 extern nsWindow *NS_HWNDToWindow( HWND hwnd);
00389 
00390 #define NSCANVASCLASS "WarpzillaCanvas"
00391 
00392 #if 0
00393 
00394 // Need to do this because the cross-platform widgets (toolbars) assume
00395 // that the name of the NS_CHILD_CID is ChildWindow and that it gets
00396 // defined in "nsWindow.h".
00397 //
00398 // However, if we've included this header *from nsCanvas.h*, then we
00399 // get a lovely circular dependency, and so special-case this.
00400 //
00401 // Yes, I suppose I'm just being perverse by having three separate classes
00402 // here, but I just baulk at naming a class 'ChildWindow'.
00403 //
00404 // (and don't tell me there's a JLib class called JMother.  Believe me,
00405 //  I know, and I regret it at least twice a week...)
00406 //
00407 #ifndef _nscanvas_h
00408 #include "nsCanvas.h"
00409 typedef nsCanvas ChildWindow;
00410 #endif
00411 
00412 #endif
00413 
00414 #endif