Add copy of .ttf font with .eot extension for testing
[wine-gecko.git] / widget / src / xpwidgets / nsBaseWidget.h
blob0ca274fbdb67f335638f88f5e988e13583b90b6d
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 #ifndef nsBaseWidget_h__
38 #define nsBaseWidget_h__
40 #include "nsRect.h"
41 #include "nsIWidget.h"
42 #include "nsIEventListener.h"
43 #include "nsIToolkit.h"
44 #include "nsIAppShell.h"
45 #include "nsILocalFile.h"
46 #include "nsString.h"
47 #include "nsVoidArray.h"
48 #include "nsCOMPtr.h"
49 #include "nsGUIEvent.h"
51 class nsIContent;
52 class nsAutoRollup;
54 /**
55 * Common widget implementation used as base class for native
56 * or crossplatform implementations of Widgets.
57 * All cross-platform behavior that all widgets need to implement
58 * should be placed in this class.
59 * (Note: widget implementations are not required to use this
60 * class, but it gives them a head start.)
63 class nsBaseWidget : public nsIWidget
65 friend class nsAutoRollup;
67 public:
68 nsBaseWidget();
69 virtual ~nsBaseWidget();
71 NS_DECL_ISUPPORTS
73 NS_IMETHOD PreCreateWidget(nsWidgetInitData *aWidgetInitData) { return NS_OK;}
75 // nsIWidget interface
76 NS_IMETHOD CaptureMouse(PRBool aCapture);
77 NS_IMETHOD Validate();
78 NS_IMETHOD InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous);
79 NS_IMETHOD GetClientData(void*& aClientData);
80 NS_IMETHOD SetClientData(void* aClientData);
81 NS_IMETHOD Destroy();
82 NS_IMETHOD SetParent(nsIWidget* aNewParent);
83 virtual nsIWidget* GetParent(void);
84 virtual nsIWidget* GetTopLevelWidget(PRInt32* aLevelsUp = NULL);
85 virtual nsIWidget* GetSheetWindowParent(void);
86 virtual void AddChild(nsIWidget* aChild);
87 virtual void RemoveChild(nsIWidget* aChild);
89 NS_IMETHOD SetZIndex(PRInt32 aZIndex);
90 NS_IMETHOD GetZIndex(PRInt32* aZIndex);
91 NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
92 nsIWidget *aWidget, PRBool aActivate);
94 NS_IMETHOD SetSizeMode(PRInt32 aMode);
95 NS_IMETHOD GetSizeMode(PRInt32* aMode);
97 virtual nscolor GetForegroundColor(void);
98 NS_IMETHOD SetForegroundColor(const nscolor &aColor);
99 virtual nscolor GetBackgroundColor(void);
100 NS_IMETHOD SetBackgroundColor(const nscolor &aColor);
101 virtual nsCursor GetCursor();
102 NS_IMETHOD SetCursor(nsCursor aCursor);
103 NS_IMETHOD SetCursor(imgIContainer* aCursor,
104 PRUint32 aHotspotX, PRUint32 aHotspotY);
105 NS_IMETHOD GetWindowType(nsWindowType& aWindowType);
106 NS_IMETHOD SetWindowType(nsWindowType aWindowType);
107 virtual void SetTransparencyMode(nsTransparencyMode aMode);
108 virtual nsTransparencyMode GetTransparencyMode();
109 NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle);
110 NS_IMETHOD HideWindowChrome(PRBool aShouldHide);
111 NS_IMETHOD MakeFullScreen(PRBool aFullScreen);
112 virtual nsIRenderingContext* GetRenderingContext();
113 virtual nsIDeviceContext* GetDeviceContext();
114 virtual nsIToolkit* GetToolkit();
115 virtual gfxASurface* GetThebesSurface();
116 NS_IMETHOD SetModal(PRBool aModal);
117 NS_IMETHOD ModalEventFilter(PRBool aRealEvent, void *aEvent,
118 PRBool *aForWindow);
119 NS_IMETHOD SetWindowClass(const nsAString& xulWinType);
120 NS_IMETHOD SetBorderStyle(nsBorderStyle aBorderStyle);
121 NS_IMETHOD AddEventListener(nsIEventListener * aListener);
122 NS_IMETHOD SetBounds(const nsRect &aRect);
123 NS_IMETHOD GetBounds(nsRect &aRect);
124 NS_IMETHOD GetClientBounds(nsRect &aRect);
125 NS_IMETHOD GetScreenBounds(nsRect &aRect);
126 NS_IMETHOD GetBorderSize(PRInt32 &aWidth, PRInt32 &aHeight);
127 NS_IMETHOD ScrollRect(nsRect &aRect, PRInt32 aDx, PRInt32 aDy);
128 NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy);
129 NS_IMETHOD EnableDragDrop(PRBool aEnable);
130 NS_IMETHOD GetAttention(PRInt32 aCycleCount);
131 NS_IMETHOD GetLastInputEventTime(PRUint32& aTime);
132 NS_IMETHOD SetIcon(const nsAString &anIconSpec);
133 NS_IMETHOD BeginSecureKeyboardInput();
134 NS_IMETHOD EndSecureKeyboardInput();
135 NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, PRBool aActive);
136 virtual PRBool ShowsResizeIndicator(nsIntRect* aResizerRect);
137 virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
138 virtual void FreeNativeData(void * data, PRUint32 aDataType) {}
139 NS_IMETHOD BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical);
140 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) { return NS_ERROR_NOT_IMPLEMENTED; }
141 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) { return NS_ERROR_NOT_IMPLEMENTED; }
142 NS_IMETHOD ResetInputState() { return NS_ERROR_NOT_IMPLEMENTED; }
143 NS_IMETHOD SetIMEOpenState(PRBool aState) { return NS_ERROR_NOT_IMPLEMENTED; }
144 NS_IMETHOD GetIMEOpenState(PRBool* aState) { return NS_ERROR_NOT_IMPLEMENTED; }
145 NS_IMETHOD SetIMEEnabled(PRUint32 aState) { return NS_ERROR_NOT_IMPLEMENTED; }
146 NS_IMETHOD GetIMEEnabled(PRUint32* aState) { return NS_ERROR_NOT_IMPLEMENTED; }
147 NS_IMETHOD CancelIMEComposition() { return NS_ERROR_NOT_IMPLEMENTED; }
148 NS_IMETHOD GetToggledKeyState(PRUint32 aKeyCode, PRBool* aLEDState) { return NS_ERROR_NOT_IMPLEMENTED; }
150 protected:
152 virtual void ResolveIconName(const nsAString &aIconName,
153 const nsAString &aIconSuffix,
154 nsILocalFile **aResult);
155 virtual void OnDestroy();
156 virtual void BaseCreate(nsIWidget *aParent,
157 const nsRect &aRect,
158 EVENT_CALLBACK aHandleEventFunction,
159 nsIDeviceContext *aContext,
160 nsIAppShell *aAppShell,
161 nsIToolkit *aToolkit,
162 nsWidgetInitData *aInitData);
164 virtual nsIContent* GetLastRollup()
166 return mLastRollup;
169 virtual nsresult SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
170 PRInt32 aNativeKeyCode,
171 PRUint32 aModifierFlags,
172 const nsAString& aCharacters,
173 const nsAString& aUnmodifiedCharacters)
174 { return NS_ERROR_UNEXPECTED; }
176 protected:
177 void* mClientData;
178 EVENT_CALLBACK mEventCallback;
179 nsIDeviceContext *mContext;
180 nsIToolkit *mToolkit;
181 nsIEventListener *mEventListener;
182 nscolor mBackground;
183 nscolor mForeground;
184 nsCursor mCursor;
185 nsWindowType mWindowType;
186 nsBorderStyle mBorderStyle;
187 PRPackedBool mIsShiftDown;
188 PRPackedBool mIsControlDown;
189 PRPackedBool mIsAltDown;
190 PRPackedBool mIsDestroying;
191 PRPackedBool mOnDestroyCalled;
192 nsRect mBounds;
193 nsRect* mOriginalBounds;
194 PRInt32 mZIndex;
195 nsSizeMode mSizeMode;
197 // the last rolled up popup. Only set this when an nsAutoRollup is in scope,
198 // so it can be cleared automatically.
199 static nsIContent* mLastRollup;
201 // Enumeration of the methods which are accessible on the "main GUI thread"
202 // via the CallMethod(...) mechanism...
203 // see nsSwitchToUIThread
204 enum {
205 CREATE = 0x0101,
206 CREATE_NATIVE,
207 DESTROY,
208 SET_FOCUS,
209 SET_CURSOR,
210 CREATE_HACK
213 #ifdef DEBUG
214 protected:
215 static nsAutoString debug_GuiEventToString(nsGUIEvent * aGuiEvent);
216 static PRBool debug_WantPaintFlashing();
218 static void debug_DumpInvalidate(FILE * aFileOut,
219 nsIWidget * aWidget,
220 const nsRect * aRect,
221 PRBool aIsSynchronous,
222 const nsCAutoString & aWidgetName,
223 PRInt32 aWindowID);
225 static void debug_DumpEvent(FILE * aFileOut,
226 nsIWidget * aWidget,
227 nsGUIEvent * aGuiEvent,
228 const nsCAutoString & aWidgetName,
229 PRInt32 aWindowID);
231 static void debug_DumpPaintEvent(FILE * aFileOut,
232 nsIWidget * aWidget,
233 nsPaintEvent * aPaintEvent,
234 const nsCAutoString & aWidgetName,
235 PRInt32 aWindowID);
237 static PRBool debug_GetCachedBoolPref(const char* aPrefName);
238 #endif
241 // A situation can occur when a mouse event occurs over a menu label while the
242 // menu popup is already open. The expected behaviour is to close the popup.
243 // This happens by calling nsIRollupListener::Rollup before the mouse event is
244 // processed. However, in cases where the mouse event is not consumed, this
245 // event will then get targeted at the menu label causing the menu to open
246 // again. To prevent this, we store in mLastRollup a reference to the popup
247 // that was closed during the Rollup call, and prevent this popup from
248 // reopening while processing the mouse event.
249 // mLastRollup should only be set while an nsAutoRollup is in scope;
250 // when it goes out of scope mLastRollup is cleared automatically.
251 // As mLastRollup is static, it can be retrieved by calling
252 // nsIWidget::GetLastRollup on any widget.
253 class nsAutoRollup
255 PRBool wasClear;
257 public:
259 nsAutoRollup();
260 ~nsAutoRollup();
263 #endif // nsBaseWidget_h__