Back to index

lightning-sunbird  0.9+nobinonly
nsToolkit.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 
00038 #ifndef TOOLKIT_H      
00039 #define TOOLKIT_H
00040 
00041 #include "nsdefs.h"
00042 #include "nsIToolkit.h"
00043 
00044 struct IActiveIMMApp;
00045 
00046 #include "nsWindowAPI.h"
00047 #include "nsITimer.h"
00048 #include "nsCOMPtr.h"
00049 
00050 struct MethodInfo;
00051 class nsIEventQueue;
00052 
00053 // we used to use MAX_PATH
00054 // which works great for one file
00055 // but for multiple files, the format is
00056 // dirpath\0\file1\0file2\0...filen\0\0
00057 // and that can quickly be more than MAX_PATH (260)
00058 // see bug #172001 for more details
00059 #define FILE_BUFFER_SIZE 4096 
00060 
00061 
00068 class nsToolkit : public nsIToolkit
00069 {
00070 
00071   public:
00072 
00073             NS_DECL_ISUPPORTS
00074 
00075                             nsToolkit();
00076             NS_IMETHOD      Init(PRThread *aThread);
00077             void            CallMethod(MethodInfo *info);
00078             // Return whether the current thread is the application's Gui thread.  
00079             PRBool          IsGuiThread(void)      { return (PRBool)(mGuiThread == PR_GetCurrentThread());}
00080             PRThread*       GetGuiThread(void)       { return mGuiThread;   }
00081             HWND            GetDispatchWindow(void)  { return mDispatchWnd; }
00082             void            CreateInternalWindow(PRThread *aThread);
00083             // Return whether the user is currently moving any application window
00084             PRBool          UserIsMovingWindow(void);
00085             nsIEventQueue*  GetEventQueue(void);
00086 
00087 private:
00088                             ~nsToolkit();
00089             void            CreateUIThread(void);
00090 
00091 public:
00092     // Window procedure for the internal window
00093     static LRESULT CALLBACK WindowProc(HWND hWnd, 
00094                                         UINT Msg, 
00095                                         WPARAM WParam, 
00096                                         LPARAM lParam);
00097 
00098 protected:
00099     // Handle of the window used to receive dispatch messages.
00100     HWND        mDispatchWnd;
00101     // Thread Id of the "main" Gui thread.
00102     PRThread    *mGuiThread;
00103 
00104 public:
00105     static HINSTANCE mDllInstance;
00106     // OS flag
00107     static PRBool    mIsNT;
00108     static PRBool    mIsWinXP;
00109     static PRBool    mUseImeApiW;
00110     static PRBool    mW2KXP_CP936;
00111 
00112     static void Startup(HINSTANCE hModule);
00113     static void Shutdown();
00114 
00115     // Active Input Method support
00116     static IActiveIMMApp *gAIMMApp;
00117     static PRInt32       gAIMMCount;
00118 
00119     // Ansi API support
00120     static HMODULE              mShell32Module;
00121     static NS_DefWindowProc     mDefWindowProc;
00122     static NS_CallWindowProc    mCallWindowProc;
00123     static NS_SetWindowLong     mSetWindowLong;
00124     static NS_GetWindowLong     mGetWindowLong;
00125     static NS_SendMessage       mSendMessage;
00126     static NS_DispatchMessage   mDispatchMessage;
00127     static NS_GetMessage        mGetMessage;
00128     static NS_PeekMessage       mPeekMessage;
00129     static NS_GetOpenFileName   mGetOpenFileName;
00130     static NS_GetSaveFileName   mGetSaveFileName;
00131     static NS_GetClassName      mGetClassName;
00132     static NS_CreateWindowEx    mCreateWindowEx;
00133     static NS_RegisterClass     mRegisterClass;
00134     static NS_UnregisterClass   mUnregisterClass;
00135 #ifndef WINCE
00136     static NS_DragQueryFile       mDragQueryFile;
00137     static NS_SHGetPathFromIDList mSHGetPathFromIDList;
00138     static NS_SHBrowseForFolder   mSHBrowseForFolder;
00139 #endif
00140 };
00141 
00142 #define WM_CALLMETHOD   (WM_USER+1)
00143 
00144 inline void nsToolkit::CallMethod(MethodInfo *info)
00145 {
00146     NS_PRECONDITION(::IsWindow(mDispatchWnd), "Invalid window handle");
00147     ::SendMessage(mDispatchWnd, WM_CALLMETHOD, (WPARAM)0, (LPARAM)info);
00148 }
00149 
00150 class  nsWindow;
00151 
00159 class MouseTrailer 
00160 {
00161 public:
00162     static MouseTrailer  &GetSingleton() { return mSingleton; }
00163     
00164     nsWindow             *GetMouseTrailerWindow() { return mHoldMouseWindow; }
00165     nsWindow             *GetCaptureWindow() { return mCaptureWindow; }
00166 
00167     void                  SetMouseTrailerWindow(nsWindow * aNSWin);
00168     void                  SetCaptureWindow(nsWindow * aNSWin);
00169     void                  IgnoreNextCycle() { mIgnoreNextCycle = PR_TRUE; } 
00170     void                  DestroyTimer();
00171                           ~MouseTrailer();
00172 
00173 private:
00174                           MouseTrailer();
00175 
00176     nsresult              CreateTimer();
00177 
00178     static void           TimerProc(nsITimer* aTimer, void* aClosure);
00179 
00180     // Global nsToolkit Instance
00181     static MouseTrailer   mSingleton;
00182 
00183     // information for mouse enter/exit events
00184     // last window
00185     nsWindow             *mHoldMouseWindow;
00186     nsWindow             *mCaptureWindow;
00187     PRBool                mIsInCaptureMode;
00188     PRBool                mIgnoreNextCycle;
00189     // timer
00190     nsCOMPtr<nsITimer>    mTimer;
00191 
00192 };
00193 
00194 #endif  // TOOLKIT_H