Back to index

lightning-sunbird  0.9+nobinonly
nsWindow.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  *   Robert O'Callahan <roc+moz@cs.cmu.edu>
00024  *   Dean Tessman <dean_tessman@hotmail.com>
00025  *   Makoto Kato  <m_kato@ga2.so-net.ne.jp>
00026  *   Dainis Jonitis <Dainis_Jonitis@swh-t.lv>
00027  *   Masayuki Nakano <masayuki@d-toybox.com>
00028  *
00029  * Alternatively, the contents of this file may be used under the terms of
00030  * either the GNU General Public License Version 2 or later (the "GPL"), or
00031  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00032  * in which case the provisions of the GPL or the LGPL are applicable instead
00033  * of those above. If you wish to allow use of your version of this file only
00034  * under the terms of either the GPL or the LGPL, and not to allow others to
00035  * use your version of this file under the terms of the MPL, indicate your
00036  * decision by deleting the provisions above and replace them with the notice
00037  * and other provisions required by the GPL or the LGPL. If you do not delete
00038  * the provisions above, a recipient may use your version of this file under
00039  * the terms of any one of the MPL, the GPL or the LGPL.
00040  *
00041  * ***** END LICENSE BLOCK ***** */
00042 
00043 #ifndef Window_h__
00044 #define Window_h__
00045 
00046 #include "nsBaseWidget.h"
00047 #include "nsdefs.h"
00048 #include "nsSwitchToUIThread.h"
00049 #include "nsToolkit.h"
00050 
00051 #include "nsIWidget.h"
00052 #include "nsIKBStateControl.h"
00053 
00054 #include "nsIMouseListener.h"
00055 #include "nsIEventListener.h"
00056 #include "nsString.h"
00057 
00058 #include "nsVoidArray.h"
00059 
00060 #include <imm.h>
00061 
00062 class nsNativeDragTarget;
00063 class nsIRollupListener;
00064 
00065 class nsIMenuBar;
00066 class nsIFile;
00067 
00068 class imgIContainer;
00069 
00070 #ifdef ACCESSIBILITY
00071 #include "OLEACC.H"
00072 #include "nsIAccessible.h"
00073 #endif
00074 
00075 #define IME_MAX_CHAR_POS       64
00076 
00077 #define NSRGB_2_COLOREF(color) \
00078             RGB(NS_GET_R(color),NS_GET_G(color),NS_GET_B(color))
00079 #define COLOREF_2_NSRGB(color) \
00080             NS_RGB(GetRValue(color), GetGValue(color), GetBValue(color))
00081 
00082 /*
00083  * ::: IMPORTANT :::
00084  * External apps and drivers depend on window class names.
00085  * For example, changing the window classes
00086  * could break touchpad scrolling or screen readers.
00087  */
00088 const PRUint32 kMaxClassNameLength    = 40;
00089 const LPCWSTR kWClassNameHidden       = L"MozillaHiddenWindowClass";
00090 const LPCWSTR kWClassNameUI           = L"MozillaUIWindowClass";
00091 const LPCWSTR kWClassNameContent      = L"MozillaContentWindowClass";
00092 const LPCWSTR kWClassNameContentFrame = L"MozillaContentFrameWindowClass";
00093 const LPCWSTR kWClassNameGeneral      = L"MozillaWindowClass";
00094 const LPCSTR kClassNameHidden         = "MozillaHiddenWindowClass";
00095 const LPCSTR kClassNameUI             = "MozillaUIWindowClass";
00096 const LPCSTR kClassNameContent        = "MozillaContentWindowClass";
00097 const LPCSTR kClassNameContentFrame   = "MozillaContentFrameWindowClass";
00098 const LPCSTR kClassNameGeneral        = "MozillaWindowClass";
00099 
00103 class nsIMM
00104 {
00105   //prototypes for DLL function calls...
00106   typedef LONG (CALLBACK *GetCompStrPtr)  (HIMC, DWORD, LPVOID, DWORD);
00107   typedef LONG (CALLBACK *GetContextPtr)  (HWND);
00108   typedef LONG (CALLBACK *RelContextPtr)  (HWND, HIMC);
00109   typedef LONG (CALLBACK *NotifyIMEPtr)   (HIMC, DWORD, DWORD, DWORD);
00110   typedef LONG (CALLBACK *SetCandWindowPtr)(HIMC, LPCANDIDATEFORM);
00111   typedef LONG (CALLBACK *SetCompWindowPtr)(HIMC, LPCOMPOSITIONFORM);
00112   typedef LONG (CALLBACK *GetCompWindowPtr)(HIMC, LPCOMPOSITIONFORM);
00113   typedef LONG (CALLBACK *GetPropertyPtr)  (HKL, DWORD);
00114   typedef LONG (CALLBACK *GetDefaultIMEWndPtr) (HWND);
00115   typedef BOOL (CALLBACK *GetOpenStatusPtr)  (HIMC);
00116   typedef BOOL (CALLBACK *SetOpenStatusPtr)  (HIMC, BOOL);
00117 public:
00118 
00119   static nsIMM& LoadModule() {
00120     static nsIMM gIMM;
00121     return gIMM;
00122   }
00123 
00124   nsIMM(const char* aModuleName="IMM32.DLL") {
00125 #ifndef WINCE
00126     mInstance=::LoadLibrary(aModuleName);
00127     NS_ASSERTION(mInstance!=NULL, "nsIMM.LoadLibrary failed.");
00128 
00129     mGetCompositionStringA=(mInstance) ? (GetCompStrPtr)GetProcAddress(mInstance, "ImmGetCompositionStringA") : 0;
00130     NS_ASSERTION(mGetCompositionStringA!=NULL, "nsIMM.ImmGetCompositionStringA failed.");
00131 
00132     mGetCompositionStringW=(mInstance) ? (GetCompStrPtr)GetProcAddress(mInstance, "ImmGetCompositionStringW") : 0;
00133     NS_ASSERTION(mGetCompositionStringW!=NULL, "nsIMM.ImmGetCompositionStringW failed.");
00134 
00135     mGetContext=(mInstance) ? (GetContextPtr)GetProcAddress(mInstance, "ImmGetContext") : 0;
00136     NS_ASSERTION(mGetContext!=NULL, "nsIMM.ImmGetContext failed.");
00137 
00138     mReleaseContext=(mInstance) ? (RelContextPtr)GetProcAddress(mInstance, "ImmReleaseContext") : 0;
00139     NS_ASSERTION(mReleaseContext!=NULL, "nsIMM.ImmReleaseContext failed.");
00140 
00141     mNotifyIME=(mInstance) ? (NotifyIMEPtr)GetProcAddress(mInstance, "ImmNotifyIME") : 0;
00142     NS_ASSERTION(mNotifyIME!=NULL, "nsIMM.ImmNotifyIME failed.");
00143 
00144     mSetCandiateWindow=(mInstance) ? (SetCandWindowPtr)GetProcAddress(mInstance, "ImmSetCandidateWindow") : 0;
00145     NS_ASSERTION(mSetCandiateWindow!=NULL, "nsIMM.ImmSetCandidateWindow failed.");
00146 
00147     mGetCompositionWindow=(mInstance) ? (GetCompWindowPtr)GetProcAddress(mInstance, "ImmGetCompositionWindow") : 0;
00148     NS_ASSERTION(mGetCompositionWindow!=NULL, "nsIMM.ImmGetCompositionWindow failed.");
00149 
00150     mSetCompositionWindow=(mInstance) ? (SetCompWindowPtr)GetProcAddress(mInstance, "ImmSetCompositionWindow") : 0;
00151     NS_ASSERTION(mSetCompositionWindow!=NULL, "nsIMM.ImmSetCompositionWindow failed.");
00152 
00153     mGetProperty=(mInstance) ? (GetPropertyPtr)GetProcAddress(mInstance, "ImmGetProperty") : 0;
00154     NS_ASSERTION(mGetProperty!=NULL, "nsIMM.ImmGetProperty failed.");
00155 
00156     mGetDefaultIMEWnd=(mInstance) ? (GetDefaultIMEWndPtr)GetProcAddress(mInstance, "ImmGetDefaultIMEWnd") : 0;
00157     NS_ASSERTION(mGetDefaultIMEWnd!=NULL, "nsIMM.ImmGetDefaultIMEWnd failed.");
00158 
00159     mGetOpenStatus=(mInstance) ? (GetOpenStatusPtr)GetProcAddress(mInstance,"ImmGetOpenStatus") : 0;
00160     NS_ASSERTION(mGetOpenStatus!=NULL, "nsIMM.ImmGetOpenStatus failed.");
00161 
00162     mSetOpenStatus=(mInstance) ? (SetOpenStatusPtr)GetProcAddress(mInstance,"ImmSetOpenStatus") : 0;
00163     NS_ASSERTION(mSetOpenStatus!=NULL, "nsIMM.ImmSetOpenStatus failed.");
00164 #elif WINCE_EMULATOR
00165     mInstance=NULL;
00166     mGetCompositionStringA=NULL;
00167     mGetCompositionStringW=NULL;
00168     mGetContext=NULL;
00169     mReleaseContext=NULL;
00170     mNotifyIME=NULL;
00171     mSetCandiateWindow=NULL;
00172     mGetCompositionWindow=NULL;
00173     mSetCompositionWindow=NULL;
00174     mGetProperty=NULL;
00175     mGetDefaultIMEWnd=NULL;
00176     mGetOpenStatus=NULL;
00177     mSetOpenStatus=NULL;
00178 #else // WinCE
00179     mInstance=NULL;
00180 
00181     mGetCompositionStringA=NULL;
00182     mGetCompositionStringW=(GetCompStrPtr)ImmGetCompositionStringW;
00183     mGetContext=(GetContextPtr)ImmGetContext;
00184     mReleaseContext=(RelContextPtr)ImmReleaseContext;
00185     mNotifyIME=(NotifyIMEPtr)ImmNotifyIME;
00186     mSetCandiateWindow=(SetCandWindowPtr)ImmSetCandidateWindow;
00187     mGetCompositionWindow=(GetCompWindowPtr)ImmGetCompositionWindow;
00188     mSetCompositionWindow=(SetCompWindowPtr)ImmSetCompositionWindow;
00189     mGetProperty=(GetPropertyPtr)ImmGetProperty;
00190     mGetDefaultIMEWnd=(GetDefaultIMEWndPtr)ImmGetDefaultIMEWnd;
00191     mGetOpenStatus=(GetOpenStatusPtr)ImmGetOpenStatus;
00192     mSetOpenStatus=(SetOpenStatusPtr)ImmSetOpenStatus;
00193 #endif
00194   }
00195 
00196   ~nsIMM() {
00197     if(mInstance) {
00198       ::FreeLibrary(mInstance);
00199     }
00200     mGetCompositionStringA=0;
00201     mGetCompositionStringW=0;
00202     mGetContext=0;
00203     mReleaseContext=0;
00204     mNotifyIME=0;
00205     mSetCandiateWindow=0;
00206     mGetCompositionWindow=0;
00207     mSetCompositionWindow=0;
00208     mGetProperty=0;
00209     mGetDefaultIMEWnd=0;
00210     mGetOpenStatus=0;
00211     mSetOpenStatus=0;
00212   }
00213 
00214   LONG GetCompositionStringA(HIMC h, DWORD d1, LPVOID v, DWORD d2) {
00215     return (mGetCompositionStringA) ? mGetCompositionStringA(h, d1, v, d2) : 0L;
00216   }
00217 
00218   LONG GetCompositionStringW(HIMC h, DWORD d1, LPVOID v, DWORD d2) {
00219     return (mGetCompositionStringW) ? mGetCompositionStringW(h, d1, v, d2) : 0L;
00220   }
00221 
00222   LONG GetContext(HWND anHWND) {
00223     return (mGetContext) ? mGetContext(anHWND) : 0L;
00224   }
00225 
00226   LONG ReleaseContext(HWND anHWND, HIMC anIMC) {
00227     return (mReleaseContext) ? mReleaseContext(anHWND, anIMC) : 0L;
00228   }
00229 
00230   LONG NotifyIME(HIMC h, DWORD d1, DWORD d2, DWORD d3) {
00231     return (mNotifyIME) ? mNotifyIME(h, d1, d2, d3) : 0L;
00232   }
00233 
00234   LONG SetCandidateWindow(HIMC h, LPCANDIDATEFORM l) {
00235     return (mSetCandiateWindow) ? mSetCandiateWindow(h, l) : 0L;
00236   }
00237 
00238   LONG SetCompositionWindow(HIMC h, LPCOMPOSITIONFORM l) {
00239     return (mSetCompositionWindow) ? mSetCompositionWindow(h, l) : 0L;
00240   }
00241 
00242   LONG GetCompositionWindow(HIMC h,LPCOMPOSITIONFORM l) {
00243     return (mGetCompositionWindow) ? mGetCompositionWindow(h, l) : 0L;
00244   }
00245 
00246   LONG GetProperty(HKL hKL, DWORD dwIndex) {
00247     return (mGetProperty) ? mGetProperty(hKL, dwIndex) : 0L;
00248   }
00249 
00250   LONG GetDefaultIMEWnd(HWND hWnd) {
00251     return (mGetDefaultIMEWnd) ? mGetDefaultIMEWnd(hWnd) : 0L;
00252   }
00253 
00254   BOOL GetOpenStatus(HIMC h) {
00255     return (mGetOpenStatus) ? mGetOpenStatus(h) : FALSE;
00256   }
00257 
00258   BOOL SetOpenStatus(HIMC h, BOOL b) {
00259     return (mSetOpenStatus) ? mSetOpenStatus(h,b) : FALSE;
00260   }
00261 
00262 private:
00263 
00264   HINSTANCE           mInstance;
00265   GetCompStrPtr       mGetCompositionStringA;
00266   GetCompStrPtr       mGetCompositionStringW;
00267   GetContextPtr       mGetContext;
00268   RelContextPtr       mReleaseContext;
00269   NotifyIMEPtr        mNotifyIME;
00270   SetCandWindowPtr    mSetCandiateWindow;
00271   SetCompWindowPtr    mSetCompositionWindow;
00272   GetCompWindowPtr    mGetCompositionWindow;
00273   GetPropertyPtr      mGetProperty;
00274   GetDefaultIMEWndPtr mGetDefaultIMEWnd;
00275   GetOpenStatusPtr    mGetOpenStatus;
00276   SetOpenStatusPtr    mSetOpenStatus;
00277 };
00278 
00283 class nsWindow : public nsSwitchToUIThread,
00284                  public nsBaseWidget,
00285                  public nsIKBStateControl
00286 {
00287 public:
00288   nsWindow();
00289   virtual ~nsWindow();
00290 
00291   // nsISupports
00292   NS_IMETHOD_(nsrefcnt) AddRef(void);
00293   NS_IMETHOD_(nsrefcnt) Release(void);
00294   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
00295 
00296   // nsIWidget interface
00297   NS_IMETHOD              Create(nsIWidget *aParent,
00298                                  const nsRect &aRect,
00299                                  EVENT_CALLBACK aHandleEventFunction,
00300                                  nsIDeviceContext *aContext,
00301                                  nsIAppShell *aAppShell = nsnull,
00302                                  nsIToolkit *aToolkit = nsnull,
00303                                  nsWidgetInitData *aInitData = nsnull);
00304   NS_IMETHOD              Create(nsNativeWidget aParent,
00305                                  const nsRect &aRect,
00306                                  EVENT_CALLBACK aHandleEventFunction,
00307                                  nsIDeviceContext *aContext,
00308                                  nsIAppShell *aAppShell = nsnull,
00309                                  nsIToolkit *aToolkit = nsnull,
00310                                  nsWidgetInitData *aInitData = nsnull);
00311 
00312   // Utility method for implementing both Create(nsIWidget ...) and
00313   // Create(nsNativeWidget...)
00314 
00315   virtual nsresult        StandardWindowCreate(nsIWidget *aParent,
00316                                                const nsRect &aRect,
00317                                                EVENT_CALLBACK aHandleEventFunction,
00318                                                nsIDeviceContext *aContext,
00319                                                nsIAppShell *aAppShell,
00320                                                nsIToolkit *aToolkit,
00321                                                nsWidgetInitData *aInitData,
00322                                                nsNativeWidget aNativeParent = nsnull);
00323 
00324   NS_IMETHOD              Destroy();
00325   NS_IMETHOD              SetParent(nsIWidget *aNewParent);
00326   virtual nsIWidget*      GetParent(void);
00327   NS_IMETHOD              Show(PRBool bState);
00328   NS_IMETHOD              IsVisible(PRBool & aState);
00329   NS_IMETHOD              PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, nsIWidget *aWidget, PRBool aActivate);
00330   NS_IMETHOD              SetSizeMode(PRInt32 aMode);
00331   NS_IMETHOD              ModalEventFilter(PRBool aRealEvent, void *aEvent, PRBool *aForWindow);
00332   NS_IMETHOD              CaptureMouse(PRBool aCapture);
00333   NS_IMETHOD              ConstrainPosition(PRBool aAllowSlop, PRInt32 *aX, PRInt32 *aY);
00334   NS_IMETHOD              Move(PRInt32 aX, PRInt32 aY);
00335   NS_IMETHOD              Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint);
00336   NS_IMETHOD              Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint);
00337   NS_IMETHOD              Enable(PRBool aState);
00338   NS_IMETHOD              IsEnabled(PRBool *aState);
00339   NS_IMETHOD              SetFocus(PRBool aRaise);
00340   NS_IMETHOD              GetBounds(nsRect &aRect);
00341   NS_IMETHOD              GetClientBounds(nsRect &aRect);
00342   NS_IMETHOD              GetScreenBounds(nsRect &aRect);
00343   NS_IMETHOD              SetBackgroundColor(const nscolor &aColor);
00344   virtual nsIFontMetrics* GetFont(void);
00345   NS_IMETHOD              SetFont(const nsFont &aFont);
00346   NS_IMETHOD              SetCursor(nsCursor aCursor);
00347   NS_IMETHOD              SetCursor(imgIContainer* aCursor,
00348                                     PRUint32 aHotspotX, PRUint32 aHotspotY);
00349   NS_IMETHOD              HideWindowChrome(PRBool aShouldHide);
00350   NS_IMETHOD              Validate();
00351   NS_IMETHOD              Invalidate(PRBool aIsSynchronous);
00352   NS_IMETHOD              Invalidate(const nsRect & aRect, PRBool aIsSynchronous);
00353   NS_IMETHOD              InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous);
00354   NS_IMETHOD              Update();
00355   virtual void*           GetNativeData(PRUint32 aDataType);
00356   virtual void            FreeNativeData(void * data, PRUint32 aDataType);//~~~
00357   NS_IMETHOD              SetColorMap(nsColorMap *aColorMap);
00358   //XXX-Scroll is obsolete it is going away soon
00359   NS_IMETHOD              Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
00360   NS_IMETHOD              ScrollWidgets(PRInt32 aDx, PRInt32 aDy);
00361   NS_IMETHOD              ScrollRect(nsRect &aRect, PRInt32 aDx, PRInt32 aDy);
00362   NS_IMETHOD              SetTitle(const nsAString& aTitle);
00363   NS_IMETHOD              SetIcon(const nsAString& aIconSpec);
00364   NS_IMETHOD              SetMenuBar(nsIMenuBar * aMenuBar) { return NS_ERROR_FAILURE; }
00365   NS_IMETHOD              ShowMenuBar(PRBool aShow)         { return NS_ERROR_FAILURE; }
00366   NS_IMETHOD              WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
00367   NS_IMETHOD              ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
00368   NS_IMETHOD              BeginResizingChildren(void);
00369   NS_IMETHOD              EndResizingChildren(void);
00370   NS_IMETHOD              GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
00371   NS_IMETHOD              SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
00372   NS_IMETHOD              DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
00373   NS_IMETHOD              EnableDragDrop(PRBool aEnable);
00374 
00375   virtual void            SetUpForPaint(HDC aHDC);
00376   virtual void            ConvertToDeviceCoordinates(nscoord& aX,nscoord& aY) {}
00377 
00378   NS_IMETHOD              CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
00379 
00380   NS_IMETHOD              GetAttention(PRInt32 aCycleCount);
00381   NS_IMETHOD              GetLastInputEventTime(PRUint32& aTime);
00382   nsWindow*               GetTopLevelWindow();
00383 
00384 #ifdef MOZ_XUL
00385   NS_IMETHOD              SetWindowTranslucency(PRBool aTransparent);
00386   NS_IMETHOD              GetWindowTranslucency(PRBool& aTransparent);
00387   NS_IMETHOD              UpdateTranslucentWindowAlpha(const nsRect& aRect, PRUint8* aAlphas);
00388 private:
00389   nsresult                SetWindowTranslucencyInner(PRBool aTransparent);
00390   PRBool                  GetWindowTranslucencyInner() { return mIsTranslucent; }
00391   void                    UpdateTranslucentWindowAlphaInner(const nsRect& aRect, PRUint8* aAlphas);
00392   void                    ResizeTranslucentWindow(PRInt32 aNewWidth, PRInt32 aNewHeight);
00393   nsresult                UpdateTranslucentWindow();
00394   nsresult                SetupTranslucentWindowMemoryBitmap(PRBool aTranslucent);
00395   void                    SetWindowRegionToAlphaMask();
00396 public:
00397 #endif
00398 
00399   // nsIKBStateControl interface
00400 
00401   NS_IMETHOD ResetInputState();
00402   NS_IMETHOD SetIMEOpenState(PRBool aState);
00403   NS_IMETHOD GetIMEOpenState(PRBool* aState);
00404   NS_IMETHOD CancelIMEComposition();
00405 
00406   PRBool IMEMouseHandling(PRUint32 aEventType, PRInt32 aAction, LPARAM lParam);
00407   PRBool IMECompositionHitTest(PRUint32 aEventType, POINT * ptPos);
00408   PRBool HandleMouseActionOfIME(PRInt32 aAction, POINT* ptPos);
00409   void GetCompositionWindowPos(HIMC hIMC, PRUint32 aEventType, COMPOSITIONFORM *cpForm);
00410 
00411   // nsSwitchToUIThread interface
00412   virtual BOOL            CallMethod(MethodInfo *info);
00413 
00414   HWND                    GetWindowHandle() { return mWnd; }
00415   WNDPROC                 GetPrevWindowProc() { return mPrevWndProc; }
00416 
00417   virtual PRBool          DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam = NULL, nsPoint* aPoint = nsnull);
00418 #ifdef ACCESSIBILITY
00419   virtual PRBool          DispatchAccessibleEvent(PRUint32 aEventType, nsIAccessible** aAccessible, nsPoint* aPoint = nsnull);
00420   already_AddRefed<nsIAccessible> GetRootAccessible();
00421 #endif
00422   virtual PRBool          AutoErase();
00423   nsPoint*                GetLastPoint() { return &mLastPoint; }
00424 
00425   PRInt32                 GetNewCmdMenuId() { mMenuCmdId++; return mMenuCmdId; }
00426 
00427   void                    InitEvent(nsGUIEvent& event, nsPoint* aPoint = nsnull);
00428 
00429   void                    SuppressBlurEvents(PRBool aSuppress);
00430   PRBool                  BlurEventsSuppressed();
00431 
00432 protected:
00433 
00434 #ifndef WINCE
00435 
00436   // special callback hook methods for pop ups
00437   static LRESULT CALLBACK MozSpecialMsgFilter(int code, WPARAM wParam, LPARAM lParam);
00438   static LRESULT CALLBACK MozSpecialWndProc(int code, WPARAM wParam, LPARAM lParam);
00439   static LRESULT CALLBACK MozSpecialMouseProc(int code, WPARAM wParam, LPARAM lParam);
00440   static VOID    CALLBACK HookTimerForPopups( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime );
00441   static void             ScheduleHookTimer(HWND aWnd, UINT aMsgId);
00442 
00443   static void             RegisterSpecialDropdownHooks();
00444   static void             UnregisterSpecialDropdownHooks();
00445 
00446   static void             PostSleepWakeNotification(const char* aNotification);
00447 #endif
00448   static BOOL             DealWithPopups (HWND inWnd, UINT inMsg, WPARAM inWParam, LPARAM inLParam, LRESULT* outResult);
00449 
00450   static PRBool           EventIsInsideWindow(UINT Msg, nsWindow* aWindow);
00451 
00452   static nsWindow*        GetNSWindowPtr(HWND aWnd);
00453   static BOOL             SetNSWindowPtr(HWND aWnd, nsWindow * ptr);
00454   nsWindow*               GetParent(PRBool aStopOnFirstTopLevel);
00455 
00456   void                    DispatchPendingEvents();
00457   virtual PRBool          ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue);
00458   virtual PRBool          DispatchWindowEvent(nsGUIEvent* event);
00459   virtual PRBool          DispatchWindowEvent(nsGUIEvent*event, nsEventStatus &aStatus);
00460 
00461    // Allow Derived classes to modify the height that is passed
00462    // when the window is created or resized.
00463   virtual PRInt32         GetHeight(PRInt32 aProposedHeight);
00464   virtual LPCWSTR         WindowClassW();
00465   virtual LPCWSTR         WindowPopupClassW();
00466   virtual LPCTSTR         WindowClass();
00467   virtual LPCTSTR         WindowPopupClass();
00468   virtual DWORD           WindowStyle();
00469   virtual DWORD           WindowExStyle();
00470 
00471   virtual void            SubclassWindow(BOOL bState);
00472 
00473   virtual void            OnDestroy();
00474   virtual PRBool          OnMove(PRInt32 aX, PRInt32 aY);
00475   virtual PRBool          OnPaint(HDC aDC = nsnull);
00476   virtual PRBool          OnResize(nsRect &aWindowRect);
00477 
00478   BOOL                    OnChar(UINT charCode, LPARAM keyData, PRUint32 aFlags = 0);
00479 
00480   BOOL                    OnKeyDown( UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyCode);
00481   BOOL                    OnKeyUp( UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyCode);
00482   UINT                    MapFromNativeToDOM(UINT aNativeKeyCode);
00483 
00484 
00485   BOOL                    OnInputLangChange(HKL aHKL, LRESULT *oResult);
00486   BOOL                    OnIMEChar(BYTE aByte1, BYTE aByte2, LPARAM aKeyState);
00487   BOOL                    OnIMEComposition(LPARAM  aGCS);
00488   BOOL                    OnIMECompositionFull();
00489   BOOL                    OnIMEEndComposition();
00490   BOOL                    OnIMENotify(WPARAM  aIMN, LPARAM aData, LRESULT *oResult);
00491   BOOL                    OnIMERequest(WPARAM  aIMR, LPARAM aData, LRESULT *oResult, PRBool aUseUnicode);
00492   BOOL                    OnIMESelect(BOOL  aSelected, WORD aLangID);
00493   BOOL                    OnIMESetContext(BOOL aActive, LPARAM& aISC);
00494   BOOL                    OnIMEStartComposition();
00495   BOOL                    OnIMEReconvert(LPARAM aData, LRESULT *oResult, PRBool aUseUnicode);
00496   BOOL                    OnIMEQueryCharPosition(LPARAM aData, LRESULT *oResult, PRBool aUseUnicode);
00497 
00498   void                    GetCompositionString(HIMC aHIMC, DWORD aIndex, nsString* aStrUnicode, nsCString* aStrAnsi);
00499   void                    ResolveIMECaretPos(nsWindow* aClient,
00500                                              nsRect&   aEventResult,
00501                                              nsRect&   aResult);
00502 
00503   virtual PRBool          DispatchKeyEvent(PRUint32 aEventType, WORD aCharCode, UINT aVirtualCharCode,
00504                                            LPARAM aKeyCode, PRUint32 aFlags = 0);
00505 
00506   virtual PRBool          DispatchFocus(PRUint32 aEventType, PRBool isMozWindowTakingFocus);
00507   virtual PRBool          OnScroll(UINT scrollCode, int cPos);
00508   virtual HBRUSH          OnControlColor();
00509 
00510   static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
00511   static LRESULT CALLBACK DefaultWindowProc(HWND hWns, UINT msg, WPARAM wParam, LPARAM lParam);
00512 
00513   static PRBool ConvertStatus(nsEventStatus aStatus);
00514 
00515   PRBool DispatchStandardEvent(PRUint32 aMsg);
00516   PRBool DispatchAppCommandEvent(PRUint32 aEventCommand);
00517   void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
00518 
00519   void GetNonClientBounds(nsRect &aRect);
00520   void HandleTextEvent(HIMC hIMEContext, PRBool aCheckAttr=PR_TRUE);
00521   BOOL HandleStartComposition(HIMC hIMEContext);
00522   void HandleEndComposition(void);
00523   void GetTextRangeList(PRUint32* textRangeListLengthResult, nsTextRangeArray* textRangeListResult);
00524 
00525   void ConstrainZLevel(HWND *aAfter);
00526 
00527   PRBool CanTakeFocus();
00528 
00529 private:
00530 
00531 
00532 #ifdef DEBUG
00533   void DebugPrintEvent(nsGUIEvent& aEvent, HWND aWnd);
00534 #endif
00535 
00536 protected:
00537   // Count of nsWindow instances. Used to manage IME buffers
00538   static PRUint32   sInstanceCount;
00539 
00540   // For Input Method Support
00541   // Only one set of IME buffers is needed for a process.
00542   static PRBool     sIMEIsComposing;
00543   static PRBool     sIMEIsStatusChanged;
00544 
00545   static DWORD      sIMEProperty;
00546   static nsString*  sIMECompUnicode;
00547   static PRUint8*   sIMEAttributeArray;
00548   static PRInt32    sIMEAttributeArrayLength;
00549   static PRInt32    sIMEAttributeArraySize;
00550   static PRUint32*  sIMECompClauseArray;
00551   static PRInt32    sIMECompClauseArrayLength;
00552   static PRInt32    sIMECompClauseArraySize;
00553   static long       sIMECursorPosition;
00554   static PRUnichar* sIMEReconvertUnicode; // reconvert string
00555 
00556   // For describing composing frame
00557   static RECT*      sIMECompCharPos;
00558   static PRInt32    sIMECaretHeight;
00559 
00560   nsSize        mLastSize;
00561   static        nsWindow* gCurrentWindow;
00562   nsPoint       mLastPoint;
00563   HWND          mWnd;
00564   HWND          mBorderlessParent;
00565 #if 0
00566   HPALETTE      mPalette;
00567 #endif
00568   WNDPROC       mPrevWndProc;
00569   HBRUSH        mBrush;
00570 
00571 #ifdef MOZ_XUL
00572   union
00573   {
00574     // Windows 2000 and newer use layered windows to support full 256 level alpha translucency
00575     struct
00576     {
00577       HDC       mMemoryDC;
00578       HBITMAP   mMemoryBitmap;
00579       PRUint8*  mMemoryBits;
00580     } w2k;
00581     // Windows NT and 9x use complex shaped window regions to support 1-bit transparency masks
00582     struct
00583     {
00584       PRPackedBool mPerformingSetWindowRgn;
00585     } w9x;
00586   };
00587   PRUint8*      mAlphaMask;
00588   PRPackedBool  mIsTranslucent;
00589   PRPackedBool  mIsTopTranslucent;     // Topmost window itself or any of it's child windows has tranlucency enabled
00590 #endif
00591   PRPackedBool  mIsTopWidgetWindow;
00592   PRPackedBool  mHas3DBorder;
00593   PRPackedBool  mIsShiftDown;
00594   PRPackedBool  mIsControlDown;
00595   PRPackedBool  mIsAltDown;
00596   PRPackedBool  mIsDestroying;
00597   PRPackedBool  mOnDestroyCalled;
00598   PRPackedBool  mIsVisible;
00599   PRPackedBool  mIsInMouseCapture;
00600   PRPackedBool  mIsInMouseWheelProcessing;
00601   PRPackedBool  mUnicodeWidget;
00602 
00603   PRPackedBool  mPainting;
00604   char          mLeadByte;
00605   PRUint32      mBlurEventSuppressionLevel;
00606   nsContentType mContentType;
00607 
00608   // XXX Temporary, should not be caching the font
00609   nsFont *      mFont;
00610 
00611   PRInt32       mPreferredWidth;
00612   PRInt32       mPreferredHeight;
00613 
00614   PRInt32       mMenuCmdId;
00615 
00616     // Window styles used by this window before chrome was hidden
00617   DWORD         mOldStyle;
00618   DWORD         mOldExStyle;
00619 
00620   static UINT   gCurrentKeyboardCP;
00621   static HKL    gKeyboardLayout;
00622   static PRBool gSwitchKeyboardLayout;
00623 
00624   HKL           mLastKeyboardLayout;
00625 
00626   // Drag & Drop
00627   nsNativeDragTarget * mNativeDragTarget;
00628 
00629   // Enumeration of the methods which are accessible on the "main GUI thread"
00630   // via the CallMethod(...) mechanism...
00631   // see nsSwitchToUIThread
00632   enum {
00633     CREATE = 0x0101,
00634     CREATE_NATIVE,
00635     DESTROY,
00636     SET_FOCUS,
00637     SET_CURSOR,
00638     CREATE_HACK
00639   };
00640 
00641   static BOOL   sIsRegistered;
00642   static BOOL   sIsPopupClassRegistered;
00643 
00644   HDWP mDeferredPositioner;
00645   static UINT   uMSH_MOUSEWHEEL;
00646 
00647   // IME special message
00648   static UINT   uWM_MSIME_RECONVERT; // reconvert message for MSIME
00649   static UINT   uWM_MSIME_MOUSE;     // mouse message for MSIME
00650   static UINT   uWM_ATOK_RECONVERT;  // reconvert message for ATOK
00651 
00652   // Heap dump
00653   static UINT   uWM_HEAP_DUMP;       // Dump heap to a file
00654 
00655   // Cursor caching
00656   static HCURSOR        gHCursor;
00657   static imgIContainer* gCursorImgContainer;
00658 
00669   static PRUint8* Data8BitTo1Bit(PRUint8* aAlphaData, PRUint32 aAlphaBytesPerRow,
00670                                  PRUint32 aWidth, PRUint32 aHeight);
00671 
00678   static PRUint8* DataToAData(PRUint8* aImageData, PRUint32 aImageBytesPerRow,
00679                               PRUint8* aAlphaData, PRUint32 aAlphaBytesPerRow,
00680                               PRUint32 aWidth, PRUint32 aHeight);
00696   static HBITMAP DataToBitmap(PRUint8* aImageData,
00697                               PRUint32 aWidth,
00698                               PRUint32 aHeight,
00699                               PRUint32 aDepth);
00700 
00708   static HBITMAP CreateOpaqueAlphaChannel(PRUint32 aWidth, PRUint32 aHeight);
00709 
00710 
00711 #ifdef ACCESSIBILITY
00712   static BOOL gIsAccessibilityOn;
00713   static HINSTANCE gmAccLib;
00714   static LPFNLRESULTFROMOBJECT gmLresultFromObject;
00715   static STDMETHODIMP_(LRESULT) LresultFromObject(REFIID riid, WPARAM wParam, LPUNKNOWN pAcc);
00716 #endif
00717 
00718   static BOOL CALLBACK BroadcastMsgToChildren(HWND aWnd, LPARAM aMsg);
00719   static BOOL CALLBACK BroadcastMsg(HWND aTopWindow, LPARAM aMsg);
00720   static BOOL CALLBACK DispatchStarvedPaints(HWND aTopWindow, LPARAM aMsg);
00721 
00722 public:
00723   static void GlobalMsgWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
00724   static HWND GetTopLevelHWND(HWND aWnd, PRBool aStopOnFirstTopLevel = PR_FALSE);
00725 };
00726 
00727 //
00728 // A child window is a window with different style
00729 //
00730 class ChildWindow : public nsWindow {
00731 
00732 public:
00733   ChildWindow() {}
00734   PRBool DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam = NULL, nsPoint* aPoint = nsnull);
00735 
00736 protected:
00737   virtual DWORD WindowStyle();
00738 };
00739 
00740 
00741 #endif // Window_h__