Back to index

lightning-sunbird  0.9+nobinonly
nsMacEventHandler.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 MacMacEventHandler_h__
00038 #define MacMacEventHandler_h__
00039 
00040 #include <ConditionalMacros.h>
00041 #include <Events.h>
00042 #include <MacWindows.h>
00043 #include <TextServices.h>
00044 #include <Controls.h>
00045 #include "prtypes.h"
00046 #include "nsCOMPtr.h"
00047 #include "nsGUIEvent.h"
00048 #include "nsDeleteObserver.h"
00049 #include "nsString.h"
00050 
00051 class nsWindow;
00052 class nsMacWindow;
00053 
00054 //-------------------------------------------------------------------------
00055 //
00056 //-------------------------------------------------------------------------
00057 
00058 class nsMacEventDispatchHandler : public nsDeleteObserver
00059 {
00060 public:
00061        nsMacEventDispatchHandler();
00062        virtual                     ~nsMacEventDispatchHandler();
00063 
00064        void                 DispatchGuiEvent(nsWindow *aWidget, PRUint32 aEventType);
00065        void                 DispatchSizeModeEvent(nsWindow *aWidget, nsSizeMode aMode);
00066 
00067     void                    SetFocus(nsWindow *aFocusedWidget);
00068 
00069        void                 SetActivated(nsWindow *aActiveWidget);
00070        nsWindow*            GetActive()   {return(mActiveWidget);}
00071        void                 SetDeactivated(nsWindow *aActiveWidget);
00072 
00073        void                 SetWidgetHit(nsWindow *aWidgetHit);
00074        void                 SetWidgetPointed(nsWindow *aWidgetPointed);
00075 
00076        nsWindow*            GetWidgetHit()              {return(mWidgetHit);}
00077        nsWindow*            GetWidgetPointed()   {return(mWidgetPointed);}
00078 
00079        // DeleteObserver
00080        virtual void  NotifyDelete(void* aDeletedObject);
00081 
00082 #if TRACK_MOUSE_LOC
00083   void     SetGlobalPoint(Point inPoint);
00084   Point    GetGlobalPoint() { return mLastGlobalMouseLoc; }
00085 #endif
00086   
00087 private:
00088 
00089   nsWindow*   mActiveWidget;
00090   nsWindow*   mWidgetHit;
00091   nsWindow*   mWidgetPointed;
00092 #if TRACK_MOUSE_LOC
00093   Point   mLastGlobalMouseLoc;
00094 #endif
00095 };
00096 
00097 
00098 //-------------------------------------------------------------------------
00099 //
00100 //-------------------------------------------------------------------------
00101 
00102 class nsMacEventHandler
00103 {
00104 public:
00105               nsMacEventHandler(nsMacWindow* aTopLevelWidget,
00106                                   nsMacEventDispatchHandler* aEventDispatchHandler);
00107               virtual ~nsMacEventHandler();
00108 
00109               virtual PRBool       HandleOSEvent(EventRecord& aOSEvent);
00110 #if USE_MENUSELECT
00111               virtual PRBool       HandleMenuCommand(EventRecord& aOSEvent, long aMenuResult);
00112 #endif
00113               
00114               // Tell Gecko that a drag event has occurred and should go into Gecko
00115               virtual PRBool       DragEvent ( unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers ) ;
00116               //virtual PRBool     TrackDrag ( Point aMouseGlobal, UInt32 aKeyModifiers ) ;
00117 
00118               //
00119               // TSM Event Handlers
00120               //
00121               virtual long         HandlePositionToOffset(Point aPoint,short* regionClass);
00122               virtual nsresult     HandleOffsetToPosition(long offset,Point* position);
00123               virtual nsresult     UnicodeHandleUpdateInputArea(const PRUnichar* text, long charCount, long fixedLength,TextRangeArray* textRangeArray);
00124               virtual nsresult     HandleUnicodeGetSelectedText(nsAString& outString);
00125               virtual nsresult     ResetInputState();
00126               virtual PRBool              HandleUKeyEvent(const PRUnichar* text, long charCount, EventRecord& aOSEvent);
00127               virtual PRBool              HandleKeyUpDownEvent(EventHandlerCallRef aHandlerCallRef,
00128                                                         EventRef aEvent);
00129               virtual PRBool              HandleKeyModifierEvent(EventHandlerCallRef aHandlerCallRef,
00130                                                           EventRef aEvent);
00131               
00132               //
00133               // Synthetic events, generated internally to do things at specific times and
00134               // not have to rely on hacking up EventRecords to fake it.
00135               //
00136               virtual PRBool ResizeEvent ( WindowRef inWindow ) ;
00137               virtual PRBool Scroll (PRInt32 aDeltaY, PRInt32 aDeltaX,
00138                                        PRBool aIsPixels,
00139                                        const Point& aMouseLoc,
00140                                        nsWindow* aWindow, PRUint32 aModifiers);
00141                
00142               virtual void  HandleActivateEvent(EventRef aEvent);
00143               inline nsMacEventDispatchHandler* GetEventDispatchHandler() { return mEventDispatchHandler; }
00144               void ClearWindowRefs(nsWindow* aWindow);
00145 protected:
00146               void InitializeMouseEvent(nsMouseEvent& aMouseEvent,
00147                                           nsPoint&      aPoint,
00148                                           PRInt16       aModifiers,
00149                                           PRUint32      aClickCount);
00150               void InitializeKeyEvent(nsKeyEvent& aKeyEvent, EventRecord& aOSEvent, 
00151                               nsWindow* aFocusedWidget, PRUint32 aMessage, 
00152                               PRBool aConvertChar=PR_TRUE);
00153               virtual PRBool              IsSpecialRaptorKey(UInt32 macKeyCode);
00154               virtual PRUint32     ConvertKeyEventToUnicode(EventRecord& aOSEvent);
00155               virtual PRBool       HandleMouseDownEvent(EventRecord& aOSEvent);
00156               virtual PRBool       HandleMouseUpEvent(EventRecord& aOSEvent);
00157               virtual PRBool       HandleMouseMoveEvent(EventRecord& aOSEvent);
00158 
00159               virtual void         ConvertOSEventToMouseEvent(
00160                                                                                     EventRecord&  aOSEvent,
00161                                                                                     nsMouseEvent& aMouseEvent,
00162                                                                                     PRUint32             aMessage);
00163               virtual nsresult     HandleStartComposition(void);
00164               virtual nsresult     HandleEndComposition(void);
00165               virtual nsresult  HandleTextEvent(PRUint32 textRangeCount, nsTextRangeArray textRangeArray);
00166               virtual PRBool ScrollAxis (nsMouseScrollEvent::nsMouseScrollFlags aAxis,
00167                                          PRInt32 aDelta, PRBool aIsPixels,
00168                                          const Point& aMouseLoc,
00169                                          nsWindow* aWindow,
00170                                          PRUint32 aModifiers);
00171               void ClearLastMouseUp();
00172 
00173               PRBool IsPluginFocused();
00174 
00175 protected:
00176        nsMacEventDispatchHandler* mEventDispatchHandler;
00177        nsMacWindow*  mTopLevelWidget;
00178        RgnHandle                   mUpdateRgn;
00179        TSMDocumentID mTSMDocument;
00180        nsPoint              mIMEPos;
00181        nsAutoString         *mIMECompositionStr;
00182        Point                       mLastMouseUpWhere;
00183        UInt32                      mLastMouseUpWhen;
00184        PRUint32                    mClickCount;
00185        PRUint32                    mLastModifierState;
00186        PRPackedBool                mIMEIsComposing;
00187        PRPackedBool                mKeyIgnore;
00188        PRPackedBool                mKeyHandled;
00189        PRPackedBool                mMouseInWidgetHit;
00190        PRPackedBool                mOwnEventDispatchHandler;
00191 };
00192 
00193 #endif // MacMacEventHandler_h__