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  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  *  Zack Rusin <zack@kde.org>.
00020  * Portions created by the Initial Developer are Copyright (C) 2004
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Lars Knoll <knoll@kde.org>
00025  *   Zack Rusin <zack@kde.org>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 #ifndef NSCOMMONWIDGET_H
00041 #define NSCOMMONWIDGET_H
00042 
00043 #include "nsBaseWidget.h"
00044 
00045 #include "nsEvent.h"
00046 
00047 #include <qevent.h> //XXX switch for forward-decl
00048 
00049 class nsIToolkit;
00050 class nsWidgetInitData;
00051 class nsIDeviceContext;
00052 class nsIAppShell;
00053 class nsIFontMetrics;
00054 class nsColorMap;
00055 class nsFont;
00056 class nsRect;
00057 class nsAString;
00058 class nsIMenuBar;
00059 class nsGUIEvent;
00060 class nsIRollupListener;
00061 class QWidget;
00062 class nsQtEventDispatcher;
00063 
00064 class nsCommonWidget : public nsBaseWidget
00065 {
00066 public:
00067     nsCommonWidget();
00068     ~nsCommonWidget();
00069 
00070     NS_DECL_ISUPPORTS_INHERITED
00071 
00072     NS_IMETHOD Show(PRBool);
00073     NS_IMETHOD IsVisible(PRBool&);
00074 
00075     NS_IMETHOD ConstrainPosition(PRBool, PRInt32*, PRInt32*);
00076     NS_IMETHOD Move(PRInt32, PRInt32);
00077     NS_IMETHOD Resize(PRInt32, PRInt32, PRBool);
00078     NS_IMETHOD Resize(PRInt32, PRInt32, PRInt32, PRInt32, PRBool);
00079     NS_IMETHOD Enable(PRBool);
00080     NS_IMETHOD IsEnabled(PRBool*);
00081     NS_IMETHOD SetFocus(PRBool araise = PR_FALSE);
00082 
00083     virtual nsIFontMetrics* GetFont();
00084 
00085     NS_IMETHOD SetFont(const nsFont&);
00086     NS_IMETHOD Invalidate(PRBool);
00087     NS_IMETHOD Invalidate(const nsRect&, int);
00088     NS_IMETHOD Update();
00089     NS_IMETHOD SetColorMap(nsColorMap*);
00090     NS_IMETHOD Scroll(PRInt32, PRInt32, nsRect*);
00091     NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy);
00092 
00093     NS_IMETHOD SetModal(PRBool aModal);
00094 
00095     virtual void* GetNativeData(PRUint32);
00096 
00097     NS_IMETHOD SetTitle(const nsAString&);
00098     NS_IMETHOD SetMenuBar(nsIMenuBar*);
00099     NS_IMETHOD ShowMenuBar(PRBool);
00100     NS_IMETHOD GetScreenBounds(nsRect &aRect);
00101     NS_IMETHOD WidgetToScreen(const nsRect&, nsRect&);
00102     NS_IMETHOD ScreenToWidget(const nsRect&, nsRect&);
00103     NS_IMETHOD BeginResizingChildren();
00104     NS_IMETHOD EndResizingChildren();
00105     NS_IMETHOD GetPreferredSize(PRInt32&, PRInt32&);
00106     NS_IMETHOD SetPreferredSize(PRInt32, PRInt32);
00107     NS_IMETHOD DispatchEvent(nsGUIEvent*, nsEventStatus&);
00108     NS_IMETHOD CaptureRollupEvents(nsIRollupListener*, PRBool, PRBool);
00109 
00110     // nsIWidget
00111     NS_IMETHOD         Create(nsIWidget        *aParent,
00112                               const nsRect     &aRect,
00113                               EVENT_CALLBACK   aHandleEventFunction,
00114                               nsIDeviceContext *aContext,
00115                               nsIAppShell      *aAppShell,
00116                               nsIToolkit       *aToolkit,
00117                               nsWidgetInitData *aInitData);
00118     NS_IMETHOD         Create(nsNativeWidget aParent,
00119                               const nsRect     &aRect,
00120                               EVENT_CALLBACK   aHandleEventFunction,
00121                               nsIDeviceContext *aContext,
00122                               nsIAppShell      *aAppShell,
00123                               nsIToolkit       *aToolkit,
00124                               nsWidgetInitData *aInitData);
00125 
00126     nsCursor GetCursor();
00127     NS_METHOD SetCursor(nsCursor aCursor);
00128 
00129 protected:
00134     friend class nsQtEventDispatcher;
00135     friend class InterceptContainer;
00136     friend class MozQWidget;
00137 
00138     virtual bool mousePressEvent(QMouseEvent *);
00139     virtual bool mouseReleaseEvent(QMouseEvent *);
00140     virtual bool mouseDoubleClickEvent(QMouseEvent *);
00141     virtual bool mouseMoveEvent(QMouseEvent *);
00142     virtual bool wheelEvent(QWheelEvent *);
00143     virtual bool keyPressEvent(QKeyEvent *);
00144     virtual bool keyReleaseEvent(QKeyEvent *);
00145     virtual bool focusInEvent(QFocusEvent *);
00146     virtual bool focusOutEvent(QFocusEvent *);
00147     virtual bool enterEvent(QEvent *);
00148     virtual bool leaveEvent(QEvent *);
00149     virtual bool paintEvent(QPaintEvent *);
00150     virtual bool moveEvent(QMoveEvent *);
00151     virtual bool resizeEvent(QResizeEvent *);
00152     virtual bool closeEvent(QCloseEvent *);
00153     virtual bool contextMenuEvent(QContextMenuEvent *);
00154     virtual bool imStartEvent(QIMEvent *);
00155     virtual bool imComposeEvent(QIMEvent *);
00156     virtual bool imEndEvent(QIMEvent *);
00157     virtual bool dragEnterEvent(QDragEnterEvent *);
00158     virtual bool dragMoveEvent(QDragMoveEvent *);
00159     virtual bool dragLeaveEvent(QDragLeaveEvent *);
00160     virtual bool dropEvent(QDropEvent *);
00161     virtual bool showEvent(QShowEvent *);
00162     virtual bool hideEvent(QHideEvent *);
00163 
00164 protected:
00165     virtual QWidget  *createQWidget(QWidget *parent, nsWidgetInitData *aInitData) = 0;
00166     virtual void NativeResize(PRInt32, PRInt32, PRInt32, PRInt32, PRBool);
00167     virtual void NativeResize(PRInt32, PRInt32, PRBool);
00168     virtual void NativeShow(PRBool);
00169 
00170     bool ignoreEvent(nsEventStatus aStatus) const;
00171 
00177     void Initialize(QWidget *widget);
00178 
00179     void DispatchGotFocusEvent(void);
00180     void DispatchLostFocusEvent(void);
00181     void DispatchActivateEvent(void);
00182     void DispatchDeactivateEvent(void);
00183     void DispatchResizeEvent(nsRect &aRect, nsEventStatus &aStatus);
00184 
00185     void InitKeyEvent(nsKeyEvent *nsEvent, QKeyEvent *qEvent);
00186     void InitMouseEvent(nsMouseEvent *nsEvent, QMouseEvent *qEvent, int aClickCount);
00187     void InitMouseWheelEvent(nsMouseScrollEvent *aEvent, QWheelEvent *qEvent);
00188 
00189     void CommonCreate(nsIWidget *aParent, PRBool aListenForResizes);
00190 
00191     PRBool AreBoundsSane() const;
00192 
00193 protected:
00194     QWidget *mContainer;
00195     QWidget *mWidget;
00196     PRPackedBool   mListenForResizes;
00197     PRPackedBool   mNeedsResize;
00198     PRPackedBool   mNeedsShow;
00199     PRPackedBool   mIsShown;
00200     nsCOMPtr<nsIWidget> mParent;
00201 
00202 private:
00203     nsresult NativeCreate(nsIWidget        *aParent,
00204                           QWidget          *aNativeParent,
00205                           const nsRect     &aRect,
00206                           EVENT_CALLBACK    aHandleEventFunction,
00207                           nsIDeviceContext *aContext,
00208                           nsIAppShell      *aAppShell,
00209                           nsIToolkit       *aToolkit,
00210                           nsWidgetInitData *aInitData);
00211 
00212 };
00213 
00214 #endif