Back to index

lightning-sunbird  0.9+nobinonly
nsCommonWidget.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* vim:expandtab:shiftwidth=4:tabstop=4:
00003  */
00004 /* ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is mozilla.org code.
00018  *
00019  * The Initial Developer of the Original Code is Christopher Blizzard
00020  * <blizzard@mozilla.org>.  Portions created by the Initial Developer
00021  * are Copyright (C) 2001 the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef __nsCommonWidget_h__
00040 #define __nsCommonWidget_h__
00041 
00042 #include "nsBaseWidget.h"
00043 #include "nsGUIEvent.h"
00044 #include <gdk/gdkevents.h>
00045 
00046 #ifdef MOZ_LOGGING
00047 
00048 // make sure that logging is enabled before including prlog.h
00049 #define FORCE_PR_LOG
00050 
00051 #include "prlog.h"
00052 
00053 extern PRLogModuleInfo *gWidgetLog;
00054 extern PRLogModuleInfo *gWidgetFocusLog;
00055 extern PRLogModuleInfo *gWidgetIMLog;
00056 extern PRLogModuleInfo *gWidgetDrawLog;
00057 
00058 #define LOG(args) PR_LOG(gWidgetLog, 4, args)
00059 #define LOGFOCUS(args) PR_LOG(gWidgetFocusLog, 4, args)
00060 #define LOGIM(args) PR_LOG(gWidgetIMLog, 4, args)
00061 #define LOGDRAW(args) PR_LOG(gWidgetDrawLog, 4, args)
00062 
00063 #else
00064 
00065 #define LOG(args)
00066 #define LOGFOCUS(args)
00067 #define LOGIM(args)
00068 #define LOGDRAW(args)
00069 
00070 #endif /* MOZ_LOGGING */
00071 
00072 class nsCommonWidget : public nsBaseWidget {
00073 public:
00074     nsCommonWidget();
00075     virtual ~nsCommonWidget();
00076 
00077     virtual nsIWidget *GetParent(void);
00078 
00079     void CommonCreate(nsIWidget *aParent, PRBool aListenForResizes);
00080 
00081     // event handling code
00082     void InitButtonEvent(nsMouseEvent &aEvent,
00083                          GdkEventButton *aGdkEvent);
00084     void InitMouseScrollEvent(nsMouseScrollEvent &aEvent,
00085                               GdkEventScroll *aGdkEvent);
00086     void InitKeyEvent(nsKeyEvent &aEvent, GdkEventKey *aGdkEvent);
00087 
00088     void DispatchGotFocusEvent(void);
00089     void DispatchLostFocusEvent(void);
00090     void DispatchActivateEvent(void);
00091     void DispatchDeactivateEvent(void);
00092     void DispatchResizeEvent(nsRect &aRect, nsEventStatus &aStatus);
00093 
00094     NS_IMETHOD DispatchEvent(nsGUIEvent *aEvent, nsEventStatus &aStatus);
00095 
00096     // virtual interfaces for some nsIWidget methods
00097     virtual void NativeResize(PRInt32 aWidth,
00098                               PRInt32 aHeight,
00099                               PRBool  aRepaint) = 0;
00100 
00101     virtual void NativeResize(PRInt32 aX,
00102                               PRInt32 aY,
00103                               PRInt32 aWidth,
00104                               PRInt32 aHeight,
00105                               PRBool  aRepaint) = 0;
00106 
00107     virtual void NativeShow  (PRBool  aAction) = 0;
00108 
00109     // Some of the nsIWidget methods
00110     NS_IMETHOD         Show             (PRBool aState);
00111     NS_IMETHOD         Resize           (PRInt32 aWidth,
00112                                          PRInt32 aHeight,
00113                                          PRBool  aRepaint);
00114     NS_IMETHOD         Resize           (PRInt32 aX,
00115                                          PRInt32 aY,
00116                                          PRInt32 aWidth,
00117                                          PRInt32 aHeight,
00118                                          PRBool   aRepaint);
00119     NS_IMETHOD         GetPreferredSize (PRInt32 &aWidth,
00120                                          PRInt32 &aHeight);
00121     NS_IMETHOD         SetPreferredSize (PRInt32 aWidth,
00122                                          PRInt32 aHeight);
00123     NS_IMETHOD         Enable           (PRBool  aState);
00124     NS_IMETHOD         IsEnabled        (PRBool *aState);
00125 
00126     // called when we are destroyed
00127     void OnDestroy(void);
00128 
00129     // called to check and see if a widget's dimensions are sane
00130     PRBool AreBoundsSane(void);
00131 
00132 protected:
00133     nsCOMPtr<nsIWidget> mParent;
00134     // Is this a toplevel window?
00135     PRPackedBool        mIsTopLevel;
00136     // Has this widget been destroyed yet?
00137     PRPackedBool        mIsDestroyed;
00138 
00139     // This is a flag that tracks if we need to resize a widget or
00140     // window when we show it.
00141     PRPackedBool        mNeedsResize;
00142     // This is a flag that tracks if we need to move a widget or
00143     // window when we show it.
00144     PRPackedBool        mNeedsMove;
00145     // Should we send resize events on all resizes?
00146     PRPackedBool        mListenForResizes;
00147     // This flag tracks if we're hidden or shown.
00148     PRPackedBool        mIsShown;
00149     PRPackedBool        mNeedsShow;
00150     // is this widget enabled?
00151     PRBool              mEnabled;
00152     // has the native window for this been created yet?
00153     PRBool              mCreated;
00154     // Has anyone set an x/y location for this widget yet? Toplevels
00155     // shouldn't be automatically set to 0,0 for first show.
00156     PRBool              mPlaced;
00157 
00158     // Preferred sizes
00159     PRUint32            mPreferredWidth;
00160     PRUint32            mPreferredHeight;
00161 };
00162 
00163 #endif /* __nsCommonWidget_h__ */