Back to index

lightning-sunbird  0.9+nobinonly
nsIWidget.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 nsIWidget_h__
00039 #define nsIWidget_h__
00040 
00041 #include "nsISupports.h"
00042 #include "nsColor.h"
00043 #include "nsIMouseListener.h"
00044 #include "nsIMenuListener.h"
00045 #include "nsCoord.h"
00046 
00047 #include "prthread.h"
00048 #include "nsEvent.h"
00049 #include "nsCOMPtr.h"
00050 
00051 // forward declarations
00052 class   nsIAppShell;
00053 class   nsIToolkit;
00054 class   nsIFontMetrics;
00055 class   nsIToolkit;
00056 class   nsIRenderingContext;
00057 class   nsIEnumerator;
00058 class   nsIDeviceContext;
00059 class   nsIRegion;
00060 struct  nsRect;
00061 struct  nsFont;
00062 class   nsIMenuBar;
00063 class   nsIEventListener;
00064 class   nsIRollupListener;
00065 class   nsGUIEvent;
00066 struct  nsColorMap;
00067 class   imgIContainer;
00068 
00077 typedef nsEventStatus (*PR_CALLBACK EVENT_CALLBACK)(nsGUIEvent *event);
00078 
00083 #define NS_NATIVE_WINDOW      0
00084 #define NS_NATIVE_GRAPHIC     1
00085 #define NS_NATIVE_COLORMAP    2
00086 #define NS_NATIVE_WIDGET      3
00087 #define NS_NATIVE_DISPLAY     4
00088 #define NS_NATIVE_REGION      5
00089 #define NS_NATIVE_OFFSETX     6
00090 #define NS_NATIVE_OFFSETY     7
00091 #define NS_NATIVE_PLUGIN_PORT 8
00092 #define NS_NATIVE_SCREEN      9
00093 #define NS_NATIVE_SHELLWIDGET 10      // Get the shell GtkWidget
00094 
00095 // e7f09105-d21b-406a-89d5-e6b731b8f665
00096 #define NS_IWIDGET_IID \
00097 { 0xe7f09105, 0xd21b, 0x406a, \
00098   { 0x89, 0xd5, 0xe6, 0xb7, 0x31, 0xb8, 0xf6, 0x65 } }
00099 
00100 
00101 // Hide the native window systems real window type so as to avoid
00102 // including native window system types and api's. This is necessary
00103 // to ensure cross-platform code.
00104 typedef void* nsNativeWidget;
00105 
00110 enum nsWindowType {     // Don't alter previously encoded enum values - 3rd party apps may look at these
00111   // default top level window
00112   eWindowType_toplevel,
00113   // top level window but usually handled differently by the OS
00114   eWindowType_dialog,
00115   // used for combo boxes, etc
00116   eWindowType_popup,
00117   // child windows (contained inside a window on the desktop (has no border))
00118   eWindowType_child,
00119   // windows that are invisible or offscreen
00120   eWindowType_invisible,
00121   // plugin window
00122   eWindowType_plugin,
00123   // java plugin window
00124   eWindowType_java,
00125   // MacOSX sheet (special dialog class)
00126   eWindowType_sheet
00127 };
00128 
00129 enum nsBorderStyle
00130 {
00131   // no border, titlebar, etc.. opposite of all
00132   eBorderStyle_none     = 0,
00133 
00134   // all window decorations
00135   eBorderStyle_all      = 1 << 0,
00136 
00137   // enables the border on the window.  these are only for decoration and are not resize hadles
00138   eBorderStyle_border   = 1 << 1,
00139 
00140   // enables the resize handles for the window.  if this is set, border is implied to also be set
00141   eBorderStyle_resizeh  = 1 << 2,
00142 
00143   // enables the titlebar for the window
00144   eBorderStyle_title    = 1 << 3,
00145 
00146   // enables the window menu button on the title bar.  this being on should force the title bar to display
00147   eBorderStyle_menu     = 1 << 4,
00148 
00149   // enables the minimize button so the user can minimize the window.
00150   //   turned off for tranient windows since they can not be minimized separate from their parent
00151   eBorderStyle_minimize = 1 << 5,
00152 
00153   // enables the maxmize button so the user can maximize the window
00154   eBorderStyle_maximize = 1 << 6,
00155 
00156   // show the close button
00157   eBorderStyle_close    = 1 << 7,
00158 
00159   // whatever the OS wants... i.e. don't do anything
00160   eBorderStyle_default  = -1
00161 };
00162 
00167 enum nsCursor {   
00168                 eCursor_standard, 
00170                 eCursor_wait, 
00172                 eCursor_select, 
00174                 eCursor_hyperlink, 
00176                 eCursor_n_resize,
00177                 eCursor_s_resize,
00178                 eCursor_w_resize,
00179                 eCursor_e_resize,
00181                 eCursor_nw_resize,
00182                 eCursor_se_resize,
00183                 eCursor_ne_resize,
00184                 eCursor_sw_resize,
00185                 eCursor_crosshair,
00186                 eCursor_move,
00187                 eCursor_help,
00188                 eCursor_copy, // CSS3
00189                 eCursor_alias,
00190                 eCursor_context_menu,
00191                 eCursor_cell,
00192                 eCursor_grab,
00193                 eCursor_grabbing,
00194                 eCursor_spinning,
00195                 eCursor_zoom_in,
00196                 eCursor_zoom_out,
00197                 eCursor_not_allowed,
00198                 eCursor_col_resize,
00199                 eCursor_row_resize,
00200                 eCursor_no_drop,
00201                 eCursor_vertical_text,
00202                 eCursor_all_scroll,
00203                 eCursor_nesw_resize,
00204                 eCursor_nwse_resize,
00205                 eCursor_ns_resize,
00206                 eCursor_ew_resize,
00207                 // This one better be the last one in this list.
00208                 eCursorCount
00209                 }; 
00210 
00211 enum nsContentType {
00212   eContentTypeInherit = -1,
00213   eContentTypeUI = 0,
00214   eContentTypeContent = 1,
00215   eContentTypeContentFrame = 2
00216 };
00217 
00218 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
00219   eZPlacementBottom = 0,  // bottom of the window stack
00220   eZPlacementBelow,       // just below another widget
00221   eZPlacementTop          // top of the window stack
00222 };
00223 
00229 struct nsWidgetInitData {
00230   nsWidgetInitData()
00231     : clipChildren(PR_FALSE), 
00232       clipSiblings(PR_FALSE), 
00233       mDropShadow(PR_FALSE),
00234       mListenForResizes(PR_FALSE),
00235       mWindowType(eWindowType_child),
00236       mBorderStyle(eBorderStyle_default),
00237       mContentType(eContentTypeInherit),
00238       mUnicode(PR_TRUE)
00239   {
00240   }
00241 
00242   // when painting exclude area occupied by child windows and sibling windows
00243   PRPackedBool  clipChildren, clipSiblings, mDropShadow;
00244   PRPackedBool  mListenForResizes;
00245   nsWindowType mWindowType;
00246   nsBorderStyle mBorderStyle;
00247   nsContentType mContentType;  // Exposed so screen readers know what's UI
00248   PRPackedBool mUnicode;
00249 };
00250 
00255 class nsIWidget : public nsISupports {
00256 
00257   public:
00258 
00259     NS_DEFINE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
00260 
00261     nsIWidget()
00262       : mLastChild(nsnull)
00263       , mPrevSibling(nsnull)
00264     {}
00265 
00266         
00298     NS_IMETHOD Create(nsIWidget        *aParent,
00299                         const nsRect     &aRect,
00300                         EVENT_CALLBACK   aHandleEventFunction,
00301                         nsIDeviceContext *aContext,
00302                         nsIAppShell      *aAppShell = nsnull,
00303                         nsIToolkit       *aToolkit = nsnull,
00304                         nsWidgetInitData *aInitData = nsnull) = 0;
00305 
00325     NS_IMETHOD Create(nsNativeWidget aParent,
00326                         const nsRect     &aRect,
00327                         EVENT_CALLBACK   aHandleEventFunction,
00328                         nsIDeviceContext *aContext,
00329                         nsIAppShell      *aAppShell = nsnull,
00330                         nsIToolkit       *aToolkit = nsnull,
00331                         nsWidgetInitData *aInitData = nsnull) = 0;
00332 
00333 
00339     NS_IMETHOD  GetClientData(void*& aClientData) = 0;
00340     NS_IMETHOD  SetClientData(void* aClientData) = 0;
00342 
00348     NS_IMETHOD Destroy(void) = 0;
00349 
00350 
00358     NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0;
00359 
00360 
00368     virtual nsIWidget* GetParent(void) = 0;
00369 
00374     nsIWidget* GetFirstChild() const {
00375         return mFirstChild;
00376     }
00377     
00382     nsIWidget* GetLastChild() const {
00383         return mLastChild;
00384     }
00385 
00389     nsIWidget* GetNextSibling() const {
00390         return mNextSibling;
00391     }
00392     
00396     void SetNextSibling(nsIWidget* aSibling) {
00397         mNextSibling = aSibling;
00398     }
00399     
00403     nsIWidget* GetPrevSibling() const {
00404         return mPrevSibling;
00405     }
00406 
00410     void SetPrevSibling(nsIWidget* aSibling) {
00411         mPrevSibling = aSibling;
00412     }
00413 
00420     NS_IMETHOD Show(PRBool aState) = 0;
00421 
00426     NS_IMETHOD SetModal(PRBool aModal) = 0;
00427 
00432     NS_IMETHOD IsVisible(PRBool & aState) = 0;
00433 
00449     NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
00450                                  PRInt32 *aX,
00451                                  PRInt32 *aY) = 0;
00452 
00460     NS_IMETHOD Move(PRInt32 aX, PRInt32 aY) = 0;
00461 
00470     NS_IMETHOD Resize(PRInt32 aWidth,
00471                       PRInt32 aHeight,
00472                       PRBool   aRepaint) = 0;
00473 
00484     NS_IMETHOD Resize(PRInt32 aX,
00485                       PRInt32 aY,
00486                       PRInt32 aWidth,
00487                       PRInt32 aHeight,
00488                       PRBool   aRepaint) = 0;
00489 
00493     NS_IMETHOD SetZIndex(PRInt32 aZIndex) = 0;
00494 
00498     NS_IMETHOD GetZIndex(PRInt32* aZIndex) = 0;
00499 
00511     NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
00512                            nsIWidget *aWidget, PRBool aActivate) = 0;
00513 
00518     NS_IMETHOD SetSizeMode(PRInt32 aMode) = 0;
00519 
00524     NS_IMETHOD GetSizeMode(PRInt32* aMode) = 0;
00525 
00532     NS_IMETHOD Enable(PRBool aState) = 0;
00533 
00538     NS_IMETHOD IsEnabled(PRBool *aState) = 0;
00539 
00543     NS_IMETHOD SetFocus(PRBool aRaise = PR_FALSE) = 0;
00544 
00551     NS_IMETHOD GetBounds(nsRect &aRect) = 0;
00552 
00553 
00563     NS_IMETHOD GetScreenBounds(nsRect &aRect) = 0;
00564 
00565 
00573     NS_IMETHOD GetClientBounds(nsRect &aRect) = 0;
00574 
00581     NS_IMETHOD GetBorderSize(PRInt32 &aWidth, PRInt32 &aHeight) = 0;
00582 
00589     virtual nscolor GetForegroundColor(void) = 0;
00590 
00598     NS_IMETHOD SetForegroundColor(const nscolor &aColor) = 0;
00599 
00607     virtual nscolor GetBackgroundColor(void) = 0;
00608 
00616     NS_IMETHOD SetBackgroundColor(const nscolor &aColor) = 0;
00617 
00624     virtual nsIFontMetrics* GetFont(void) = 0;
00625 
00632     NS_IMETHOD SetFont(const nsFont &aFont) = 0;
00633 
00640     virtual nsCursor GetCursor(void) = 0;
00641 
00648     NS_IMETHOD SetCursor(nsCursor aCursor) = 0;
00649 
00659     NS_IMETHOD SetCursor(imgIContainer* aCursor,
00660                          PRUint32 aHotspotX, PRUint32 aHotspotY) = 0;
00661 
00667     NS_IMETHOD GetWindowType(nsWindowType& aWindowType) = 0;
00668 
00688     NS_IMETHOD SetWindowTranslucency(PRBool aTranslucent) = 0;
00689 
00696     NS_IMETHOD GetWindowTranslucency(PRBool& aTranslucent) = 0;
00697 
00707     NS_IMETHOD UpdateTranslucentWindowAlpha(const nsRect& aRect, PRUint8* aAlphas) = 0;
00708 
00713     NS_IMETHOD HideWindowChrome(PRBool aShouldHide) = 0;
00714 
00719     NS_IMETHOD MakeFullScreen(PRBool aFullScreen) = 0;
00720 
00725     NS_IMETHOD Validate() = 0;
00726 
00734     NS_IMETHOD Invalidate(PRBool aIsSynchronous) = 0;
00735 
00743     NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous) = 0;
00744 
00752     NS_IMETHOD InvalidateRegion(const nsIRegion* aRegion, PRBool aIsSynchronous) = 0;
00753 
00760      NS_IMETHOD Update() = 0;
00761 
00769     NS_IMETHOD AddMouseListener(nsIMouseListener * aListener) = 0;
00770 
00778     NS_IMETHOD AddEventListener(nsIEventListener * aListener) = 0;
00779 
00787     NS_IMETHOD AddMenuListener(nsIMenuListener * aListener) = 0;
00788     
00795     virtual nsIToolkit* GetToolkit() = 0;    
00796 
00804     NS_IMETHOD SetColorMap(nsColorMap *aColorMap) = 0;
00805 
00816     NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) = 0;
00817 
00828     NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy) = 0;
00829 
00840     NS_IMETHOD ScrollRect(nsRect &aSrcRect, PRInt32 aDx, PRInt32 aDy) = 0;
00841 
00847     virtual void AddChild(nsIWidget* aChild) = 0;
00848     virtual void RemoveChild(nsIWidget* aChild) = 0;
00849     virtual void* GetNativeData(PRUint32 aDataType) = 0;
00850     virtual void FreeNativeData(void * data, PRUint32 aDataType) = 0;//~~~
00851     virtual nsIRenderingContext* GetRenderingContext() = 0;
00852     virtual nsIDeviceContext* GetDeviceContext() = 0;
00853     virtual nsIAppShell *GetAppShell() = 0;
00855 
00862     NS_IMETHOD SetBorderStyle(nsBorderStyle aBorderStyle) = 0;
00863 
00871     NS_IMETHOD SetTitle(const nsAString& aTitle) = 0;
00872 
00882     NS_IMETHOD SetIcon(const nsAString& anIconSpec) = 0;
00883 
00891     NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar) = 0;
00892 
00899     NS_IMETHOD ShowMenuBar(PRBool aShow) = 0;
00900 
00908     NS_IMETHOD WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) = 0;
00909 
00917     NS_IMETHOD ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect) = 0;
00918 
00927     NS_IMETHOD BeginResizingChildren(void) = 0;
00928 
00935     NS_IMETHOD EndResizingChildren(void) = 0;
00936 
00941     NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) = 0;
00942 
00947     NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) = 0;
00948 
00953     NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) = 0;
00954 
00955 
00960     NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
00961                      const nsRect& aDirtyRect) = 0;
00962    
00967     NS_IMETHOD EnableDragDrop(PRBool aEnable) = 0;
00968    
00969     virtual void  ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) = 0;
00970 
00976     NS_IMETHOD CaptureMouse(PRBool aCapture) = 0;
00977 
00982     NS_IMETHOD GetWindowClass(char *aClass) = 0;
00983 
00988     NS_IMETHOD SetWindowClass(char *aClass) = 0;
00989 
00998     NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent) = 0;
00999 
01011     NS_IMETHOD ModalEventFilter(PRBool aRealEvent, void *aEvent, PRBool *aForWindow) = 0;
01012 
01024     NS_IMETHOD GetAttention(PRInt32 aCycleCount) = 0;
01025 
01036     NS_IMETHOD GetLastInputEventTime(PRUint32& aTime) = 0;
01037 
01038 
01039 protected:
01040     // keep the list of children.  We also keep track of our siblings.
01041     // The ownership model is as follows: parent holds a strong ref to
01042     // the first element of the list, and each element holds a strong
01043     // ref to the next element in the list.  The prevsibling and
01044     // lastchild pointers are weak, which is fine as long as they are
01045     // maintained properly.
01046     nsCOMPtr<nsIWidget> mFirstChild;
01047     nsIWidget* mLastChild;
01048     nsCOMPtr<nsIWidget> mNextSibling;
01049     nsIWidget* mPrevSibling;
01050 };
01051 
01052 #endif // nsIWidget_h__