Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / widget / public / nsIWidget.h
blobfe2bfe59eb57afe5d2da4a373252e013c7a3a5ef
1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 ***** */
38 #ifndef nsIWidget_h__
39 #define nsIWidget_h__
41 #include "nsISupports.h"
42 #include "nsColor.h"
43 #include "nsCoord.h"
44 #include "nsRect.h"
46 #include "prthread.h"
47 #include "nsEvent.h"
48 #include "nsCOMPtr.h"
49 #include "nsITheme.h"
51 // forward declarations
52 class nsIAppShell;
53 class nsIToolkit;
54 class nsIFontMetrics;
55 class nsIRenderingContext;
56 class nsIDeviceContext;
57 class nsIRegion;
58 struct nsFont;
59 class nsIEventListener;
60 class nsIRollupListener;
61 class nsGUIEvent;
62 struct nsColorMap;
63 class imgIContainer;
64 class gfxASurface;
65 class nsIContent;
67 /**
68 * Callback function that processes events.
69 * The argument is actually a subtype (subclass) of nsEvent which carries
70 * platform specific information about the event. Platform specific code knows
71 * how to deal with it.
72 * The return value determines whether or not the default action should take place.
75 typedef nsEventStatus (* EVENT_CALLBACK)(nsGUIEvent *event);
77 /**
78 * Flags for the getNativeData function.
79 * See getNativeData()
81 #define NS_NATIVE_WINDOW 0
82 #define NS_NATIVE_GRAPHIC 1
83 #define NS_NATIVE_COLORMAP 2
84 #define NS_NATIVE_WIDGET 3
85 #define NS_NATIVE_DISPLAY 4
86 #define NS_NATIVE_REGION 5
87 #define NS_NATIVE_OFFSETX 6
88 #define NS_NATIVE_OFFSETY 7
89 #define NS_NATIVE_PLUGIN_PORT 8
90 #define NS_NATIVE_SCREEN 9
91 #define NS_NATIVE_SHELLWIDGET 10 // Get the shell GtkWidget
92 #ifdef XP_MACOSX
93 #define NS_NATIVE_PLUGIN_PORT_QD 100
94 #define NS_NATIVE_PLUGIN_PORT_CG 101
95 #endif
97 // 7E01D11D-DAFC-4A5E-8C0A-7442A2E17252
98 #define NS_IWIDGET_IID \
99 { 0x7E01D11D, 0xDAFC, 0x4A5E, \
100 { 0x8C, 0x0A, 0x74, 0x42, 0xA2, 0xE1, 0x72, 0x52 } }
102 // Hide the native window systems real window type so as to avoid
103 // including native window system types and APIs. This is necessary
104 // to ensure cross-platform code.
105 typedef void* nsNativeWidget;
108 * Window shadow styles
109 * Also used for the -moz-window-shadow CSS property
112 #define NS_STYLE_WINDOW_SHADOW_NONE 0
113 #define NS_STYLE_WINDOW_SHADOW_DEFAULT 1
116 * Border styles
119 enum nsWindowType { // Don't alter previously encoded enum values - 3rd party apps may look at these
120 // default top level window
121 eWindowType_toplevel,
122 // top level window but usually handled differently by the OS
123 eWindowType_dialog,
124 // used for combo boxes, etc
125 eWindowType_popup,
126 // child windows (contained inside a window on the desktop (has no border))
127 eWindowType_child,
128 // windows that are invisible or offscreen
129 eWindowType_invisible,
130 // plugin window
131 eWindowType_plugin,
132 // java plugin window
133 eWindowType_java,
134 // MacOSX sheet (special dialog class)
135 eWindowType_sheet
138 enum nsPopupType {
139 ePopupTypePanel,
140 ePopupTypeMenu,
141 ePopupTypeTooltip,
142 ePopupTypeAny = 0xF000 // used only to pass to nsXULPopupManager::GetTopPopup
145 enum nsBorderStyle
147 // no border, titlebar, etc.. opposite of all
148 eBorderStyle_none = 0,
150 // all window decorations
151 eBorderStyle_all = 1 << 0,
153 // enables the border on the window. these are only for decoration and are not resize hadles
154 eBorderStyle_border = 1 << 1,
156 // enables the resize handles for the window. if this is set, border is implied to also be set
157 eBorderStyle_resizeh = 1 << 2,
159 // enables the titlebar for the window
160 eBorderStyle_title = 1 << 3,
162 // enables the window menu button on the title bar. this being on should force the title bar to display
163 eBorderStyle_menu = 1 << 4,
165 // enables the minimize button so the user can minimize the window.
166 // turned off for tranient windows since they can not be minimized separate from their parent
167 eBorderStyle_minimize = 1 << 5,
169 // enables the maxmize button so the user can maximize the window
170 eBorderStyle_maximize = 1 << 6,
172 // show the close button
173 eBorderStyle_close = 1 << 7,
175 // whatever the OS wants... i.e. don't do anything
176 eBorderStyle_default = -1
180 * Cursor types.
183 enum nsCursor { ///(normal cursor, usually rendered as an arrow)
184 eCursor_standard,
185 ///(system is busy, usually rendered as a hourglass or watch)
186 eCursor_wait,
187 ///(Selecting something, usually rendered as an IBeam)
188 eCursor_select,
189 ///(can hyper-link, usually rendered as a human hand)
190 eCursor_hyperlink,
191 ///(north/south/west/east edge sizing)
192 eCursor_n_resize,
193 eCursor_s_resize,
194 eCursor_w_resize,
195 eCursor_e_resize,
196 ///(corner sizing)
197 eCursor_nw_resize,
198 eCursor_se_resize,
199 eCursor_ne_resize,
200 eCursor_sw_resize,
201 eCursor_crosshair,
202 eCursor_move,
203 eCursor_help,
204 eCursor_copy, // CSS3
205 eCursor_alias,
206 eCursor_context_menu,
207 eCursor_cell,
208 eCursor_grab,
209 eCursor_grabbing,
210 eCursor_spinning,
211 eCursor_zoom_in,
212 eCursor_zoom_out,
213 eCursor_not_allowed,
214 eCursor_col_resize,
215 eCursor_row_resize,
216 eCursor_no_drop,
217 eCursor_vertical_text,
218 eCursor_all_scroll,
219 eCursor_nesw_resize,
220 eCursor_nwse_resize,
221 eCursor_ns_resize,
222 eCursor_ew_resize,
223 eCursor_none,
224 // This one better be the last one in this list.
225 eCursorCount
228 enum nsContentType {
229 eContentTypeInherit = -1,
230 eContentTypeUI = 0,
231 eContentTypeContent = 1,
232 eContentTypeContentFrame = 2
235 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
236 eZPlacementBottom = 0, // bottom of the window stack
237 eZPlacementBelow, // just below another widget
238 eZPlacementTop // top of the window stack
242 * Basic struct for widget initialization data.
243 * @see Create member function of nsIWidget
246 struct nsWidgetInitData {
247 nsWidgetInitData()
248 : clipChildren(PR_FALSE),
249 clipSiblings(PR_FALSE),
250 mDropShadow(PR_FALSE),
251 mListenForResizes(PR_FALSE),
252 mWindowType(eWindowType_child),
253 mBorderStyle(eBorderStyle_default),
254 mContentType(eContentTypeInherit),
255 mUnicode(PR_TRUE),
256 mPopupHint(ePopupTypePanel)
260 // when painting exclude area occupied by child windows and sibling windows
261 PRPackedBool clipChildren, clipSiblings, mDropShadow;
262 PRPackedBool mListenForResizes;
263 nsWindowType mWindowType;
264 nsBorderStyle mBorderStyle;
265 nsContentType mContentType; // Exposed so screen readers know what's UI
266 PRPackedBool mUnicode;
267 nsPopupType mPopupHint;
271 * The base class for all the widgets. It provides the interface for
272 * all basic and necessary functionality.
274 class nsIWidget : public nsISupports {
276 public:
278 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
280 nsIWidget()
281 : mLastChild(nsnull)
282 , mPrevSibling(nsnull)
287 * Create and initialize a widget.
289 * The widget represents a window that can be drawn into. It also is the
290 * base class for user-interface widgets such as buttons and text boxes.
292 * All the arguments can be NULL in which case a top level window
293 * with size 0 is created. The event callback function has to be
294 * provided only if the caller wants to deal with the events this
295 * widget receives. The event callback is basically a preprocess
296 * hook called synchronously. The return value determines whether
297 * the event goes to the default window procedure or it is hidden
298 * to the os. The assumption is that if the event handler returns
299 * false the widget does not see the event. The widget should not
300 * automatically clear the window to the background color. The
301 * calling code must handle paint messages and clear the background
302 * itself.
304 * aInitData cannot be eWindowType_popup here; popups cannot be
305 * hooked into the nsIWidget hierarchy.
307 * @param parent or null if it's a top level window
308 * @param aRect the widget dimension
309 * @param aHandleEventFunction the event handler callback function
310 * @param aContext
311 * @param aAppShell the parent application shell. If nsnull,
312 * the parent window's application shell will be used.
313 * @param aToolkit
314 * @param aInitData data that is used for widget initialization
317 NS_IMETHOD Create(nsIWidget *aParent,
318 const nsRect &aRect,
319 EVENT_CALLBACK aHandleEventFunction,
320 nsIDeviceContext *aContext,
321 nsIAppShell *aAppShell = nsnull,
322 nsIToolkit *aToolkit = nsnull,
323 nsWidgetInitData *aInitData = nsnull) = 0;
326 * Create and initialize a widget with a native window parent
328 * The widget represents a window that can be drawn into. It also is the
329 * base class for user-interface widgets such as buttons and text boxes.
331 * All the arguments can be NULL in which case a top level window
332 * with size 0 is created. The event callback function has to be
333 * provided only if the caller wants to deal with the events this
334 * widget receives. The event callback is basically a preprocess
335 * hook called synchronously. The return value determines whether
336 * the event goes to the default window procedure or it is hidden
337 * to the os. The assumption is that if the event handler returns
338 * false the widget does not see the event.
340 * @param aParent native window.
341 * @param aRect the widget dimension
342 * @param aHandleEventFunction the event handler callback function
344 NS_IMETHOD Create(nsNativeWidget aParent,
345 const nsRect &aRect,
346 EVENT_CALLBACK aHandleEventFunction,
347 nsIDeviceContext *aContext,
348 nsIAppShell *aAppShell = nsnull,
349 nsIToolkit *aToolkit = nsnull,
350 nsWidgetInitData *aInitData = nsnull) = 0;
354 * Accessor functions to get and set the client data associated with the
355 * widget.
357 //@{
358 NS_IMETHOD GetClientData(void*& aClientData) = 0;
359 NS_IMETHOD SetClientData(void* aClientData) = 0;
360 //@}
363 * Close and destroy the internal native window.
364 * This method does not delete the widget.
367 NS_IMETHOD Destroy(void) = 0;
371 * Reparent a widget
373 * Change the widgets parent
375 * @param aNewParent new parent
377 NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0;
381 * Return the parent Widget of this Widget or nsnull if this is a
382 * top level window
384 * @return the parent widget or nsnull if it does not have a parent
387 virtual nsIWidget* GetParent(void) = 0;
390 * Return the top level Widget of this Widget
392 * @param aLevelsUp returns the number of GetParent() calls that
393 * were necessary to get to the top level widget
394 * @return the top level widget
396 virtual nsIWidget* GetTopLevelWidget(PRInt32* aLevelsUp = NULL) = 0;
399 * Return the top (non-sheet) parent of this Widget if it's a sheet,
400 * or nsnull if this isn't a sheet (or some other error occurred).
401 * Sheets are only supported on some platforms (currently only OS X).
403 * @return the top (non-sheet) parent widget or nsnull
406 virtual nsIWidget* GetSheetWindowParent(void) = 0;
409 * Return the first child of this widget. Will return null if
410 * there are no children.
412 nsIWidget* GetFirstChild() const {
413 return mFirstChild;
417 * Return the last child of this widget. Will return null if
418 * there are no children.
420 nsIWidget* GetLastChild() const {
421 return mLastChild;
425 * Return the next sibling of this widget
427 nsIWidget* GetNextSibling() const {
428 return mNextSibling;
432 * Set the next sibling of this widget
434 void SetNextSibling(nsIWidget* aSibling) {
435 mNextSibling = aSibling;
439 * Return the previous sibling of this widget
441 nsIWidget* GetPrevSibling() const {
442 return mPrevSibling;
446 * Set the previous sibling of this widget
448 void SetPrevSibling(nsIWidget* aSibling) {
449 mPrevSibling = aSibling;
453 * Show or hide this widget
455 * @param aState PR_TRUE to show the Widget, PR_FALSE to hide it
458 NS_IMETHOD Show(PRBool aState) = 0;
461 * Make the window modal
464 NS_IMETHOD SetModal(PRBool aModal) = 0;
467 * Returns whether the window is visible
470 NS_IMETHOD IsVisible(PRBool & aState) = 0;
473 * Perform platform-dependent sanity check on a potential window position.
474 * This is guaranteed to work only for top-level windows.
476 * @param aAllowSlop: if true, allow the window to slop offscreen;
477 * the window should be partially visible. if false,
478 * force the entire window onscreen (or at least
479 * the upper-left corner, if it's too large).
480 * @param aX in: an x position expressed in screen coordinates.
481 * out: the x position constrained to fit on the screen(s).
482 * @param aY in: an y position expressed in screen coordinates.
483 * out: the y position constrained to fit on the screen(s).
484 * @return vapid success indication. but see also the parameters.
487 NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
488 PRInt32 *aX,
489 PRInt32 *aY) = 0;
492 * Move this widget.
494 * @param aX the new x position expressed in the parent's coordinate system
495 * @param aY the new y position expressed in the parent's coordinate system
498 NS_IMETHOD Move(PRInt32 aX, PRInt32 aY) = 0;
501 * Resize this widget.
503 * @param aWidth the new width expressed in the parent's coordinate system
504 * @param aHeight the new height expressed in the parent's coordinate system
505 * @param aRepaint whether the widget should be repainted
508 NS_IMETHOD Resize(PRInt32 aWidth,
509 PRInt32 aHeight,
510 PRBool aRepaint) = 0;
513 * Move or resize this widget.
515 * @param aX the new x position expressed in the parent's coordinate system
516 * @param aY the new y position expressed in the parent's coordinate system
517 * @param aWidth the new width expressed in the parent's coordinate system
518 * @param aHeight the new height expressed in the parent's coordinate system
519 * @param aRepaint whether the widget should be repainted if the size changes
522 NS_IMETHOD Resize(PRInt32 aX,
523 PRInt32 aY,
524 PRInt32 aWidth,
525 PRInt32 aHeight,
526 PRBool aRepaint) = 0;
529 * Sets the widget's z-index.
531 NS_IMETHOD SetZIndex(PRInt32 aZIndex) = 0;
534 * Gets the widget's z-index.
536 NS_IMETHOD GetZIndex(PRInt32* aZIndex) = 0;
539 * Position this widget just behind the given widget. (Used to
540 * control z-order for top-level widgets. Get/SetZIndex by contrast
541 * control z-order for child widgets of other widgets.)
542 * @param aPlacement top, bottom, or below a widget
543 * (if top or bottom, param aWidget is ignored)
544 * @param aWidget widget to place this widget behind
545 * (only if aPlacement is eZPlacementBelow).
546 * null is equivalent to aPlacement of eZPlacementTop
547 * @param aActivate true to activate the widget after placing it
549 NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
550 nsIWidget *aWidget, PRBool aActivate) = 0;
553 * Minimize, maximize or normalize the window size.
554 * Takes a value from nsSizeMode (see nsGUIEvent.h)
556 NS_IMETHOD SetSizeMode(PRInt32 aMode) = 0;
559 * Return size mode (minimized, maximized, normalized).
560 * Returns a value from nsSizeMode (see nsGUIEvent.h)
562 NS_IMETHOD GetSizeMode(PRInt32* aMode) = 0;
565 * Enable or disable this Widget
567 * @param aState PR_TRUE to enable the Widget, PR_FALSE to disable it.
570 NS_IMETHOD Enable(PRBool aState) = 0;
573 * Ask whether the widget is enabled
574 * @param aState returns PR_TRUE if the widget is enabled
576 NS_IMETHOD IsEnabled(PRBool *aState) = 0;
579 * Give focus to this widget.
581 NS_IMETHOD SetFocus(PRBool aRaise = PR_FALSE) = 0;
584 * Get this widget's outside dimensions relative to its parent widget
586 * @param aRect on return it holds the x, y, width and height of this widget
589 NS_IMETHOD GetBounds(nsRect &aRect) = 0;
593 * Get this widget's outside dimensions in global coordinates. (One might think this
594 * could be accomplished by stringing together other methods in this interface, but
595 * then one would bloody one's nose on different coordinate system handling by different
596 * platforms.) This includes any title bar on the window.
599 * @param aRect on return it holds the x, y, width and height of this widget
602 NS_IMETHOD GetScreenBounds(nsRect &aRect) = 0;
606 * Get this widget's client area dimensions, if the window has a 3D border appearance
607 * this returns the area inside the border, The x and y are always zero
609 * @param aRect on return it holds the x. y, width and height of the client area of this widget
612 NS_IMETHOD GetClientBounds(nsRect &aRect) = 0;
615 * Gets the width and height of the borders
616 * @param aWidth the width of the border
617 * @param aHeight the height of the border
620 NS_IMETHOD GetBorderSize(PRInt32 &aWidth, PRInt32 &aHeight) = 0;
623 * Get the foreground color for this widget
625 * @return this widget's foreground color
628 virtual nscolor GetForegroundColor(void) = 0;
631 * Set the foreground color for this widget
633 * @param aColor the new foreground color
637 NS_IMETHOD SetForegroundColor(const nscolor &aColor) = 0;
640 * Get the background color for this widget
642 * @return this widget's background color
646 virtual nscolor GetBackgroundColor(void) = 0;
649 * Set the background color for this widget
651 * @param aColor the new background color
655 NS_IMETHOD SetBackgroundColor(const nscolor &aColor) = 0;
658 * Get the cursor for this widget.
660 * @return this widget's cursor.
663 virtual nsCursor GetCursor(void) = 0;
666 * Set the cursor for this widget
668 * @param aCursor the new cursor for this widget
671 NS_IMETHOD SetCursor(nsCursor aCursor) = 0;
674 * Sets an image as the cursor for this widget.
676 * @param aCursor the cursor to set
677 * @param aX the X coordinate of the hotspot (from left).
678 * @param aY the Y coordinate of the hotspot (from top).
679 * @retval NS_ERROR_NOT_IMPLEMENTED if setting images as cursors is not
680 * supported
682 NS_IMETHOD SetCursor(imgIContainer* aCursor,
683 PRUint32 aHotspotX, PRUint32 aHotspotY) = 0;
685 /**
686 * Get the window type of this widget
688 * @param aWindowType the window type of the widget
690 NS_IMETHOD GetWindowType(nsWindowType& aWindowType) = 0;
693 * Set the transparency mode of the top-level window containing this widget.
694 * So, e.g., if you call this on the widget for an IFRAME, the top level
695 * browser window containing the IFRAME actually gets set. Be careful.
697 * This can fail if the platform doesn't support
698 * transparency/glass. By default widgets are not
699 * transparent. This will also fail if the toplevel window is not
700 * a Mozilla window, e.g., if the widget is in an embedded
701 * context.
703 * After transparency/glass has been enabled, the initial alpha channel
704 * value for all pixels is 1, i.e., opaque.
705 * If the window is resized then the alpha channel values for
706 * all pixels are reset to 1.
707 * Pixel RGB color values are already premultiplied with alpha channel values.
709 virtual void SetTransparencyMode(nsTransparencyMode aMode) = 0;
712 * Get the transparency mode of the top-level window that contains this
713 * widget.
715 virtual nsTransparencyMode GetTransparencyMode() = 0;
718 * Set the shadow style of the window.
720 NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle) = 0;
722 /**
723 * Hide window chrome (borders, buttons) for this widget.
726 NS_IMETHOD HideWindowChrome(PRBool aShouldHide) = 0;
729 * Put the toplevel window into or out of fullscreen mode.
732 NS_IMETHOD MakeFullScreen(PRBool aFullScreen) = 0;
735 * Validate the widget.
738 NS_IMETHOD Validate() = 0;
741 * Invalidate the widget and repaint it.
743 * @param aIsSynchronous PR_TRUE then repaint synchronously. If PR_FALSE repaint later.
744 * @see #Update()
747 NS_IMETHOD Invalidate(PRBool aIsSynchronous) = 0;
750 * Invalidate a specified rect for a widget and repaints it.
752 * @param aIsSynchronouse PR_TRUE then repaint synchronously. If PR_FALSE repaint later.
753 * @see #Update()
756 NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous) = 0;
759 * Invalidate a specified region for a widget and repaints it.
761 * @param aIsSynchronouse PR_TRUE then repaint synchronously. If PR_FALSE repaint later.
762 * @see #Update()
765 NS_IMETHOD InvalidateRegion(const nsIRegion* aRegion, PRBool aIsSynchronous) = 0;
768 * Force a synchronous repaint of the window if there are dirty rects.
770 * @see Invalidate()
773 NS_IMETHOD Update() = 0;
776 * Adds an event listener to this widget
777 * Any existing event listener is replaced
779 * @param aListener event listener to add to this widget.
782 NS_IMETHOD AddEventListener(nsIEventListener * aListener) = 0;
785 * Return the widget's toolkit
787 * An AddRef has NOT been done for the caller.
789 * @return the toolkit this widget was created in. See nsToolkit.
792 virtual nsIToolkit* GetToolkit() = 0;
795 * Set the color map for this widget
797 * @param aColorMap color map for displaying this widget
801 NS_IMETHOD SetColorMap(nsColorMap *aColorMap) = 0;
804 * XXX (This is obsolete and will be removed soon, Use ScrollWidgets instead)
805 * Scroll this widget.
807 * @param aDx amount to scroll along the x-axis
808 * @param aDy amount to scroll along the y-axis.
809 * @param aClipRect clipping rectangle to limit the scroll to.
813 NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) = 0;
816 * Scroll the contents of the widget.
817 * All child widgets are also scrolled by offsetting their coordinates.
818 * A NS_PAINT message is synchronously dispatched for the newly exposed rectangle.
820 * @param aDx amount to scroll along the x-axis in pixels
821 * @param aDy amount to scroll along the y-axis in pixels
825 NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy) = 0;
828 * Scroll an area of this widget. Child widgets are not scrolled.
829 * A NS_PAINT message is synchronously dispatched for the newly exposed rectangle.
831 * @param aRect source rectangle to scroll in the widget in pixels
832 * @param aDx x offset from the source in pixels
833 * @param aDy y offset from the source in pixels
837 NS_IMETHOD ScrollRect(nsRect &aSrcRect, PRInt32 aDx, PRInt32 aDy) = 0;
839 /**
840 * Internal methods
843 //@{
844 virtual void AddChild(nsIWidget* aChild) = 0;
845 virtual void RemoveChild(nsIWidget* aChild) = 0;
846 virtual void* GetNativeData(PRUint32 aDataType) = 0;
847 virtual void FreeNativeData(void * data, PRUint32 aDataType) = 0;//~~~
848 virtual nsIRenderingContext* GetRenderingContext() = 0;
850 // GetDeviceContext returns a weak pointer to this widget's device context
851 virtual nsIDeviceContext* GetDeviceContext() = 0;
853 //@}
856 * Set border style
857 * Must be called before Create.
858 * @param aBorderStyle @see nsBorderStyle
861 NS_IMETHOD SetBorderStyle(nsBorderStyle aBorderStyle) = 0;
864 * Set the widget's title.
865 * Must be called after Create.
867 * @param aTitle string displayed as the title of the widget
870 NS_IMETHOD SetTitle(const nsAString& aTitle) = 0;
873 * Set the widget's icon.
874 * Must be called after Create.
876 * @param anIconSpec string specifying the icon to use; convention is to pass
877 * a resource: URL from which a platform-dependent resource
878 * file name will be constructed
881 NS_IMETHOD SetIcon(const nsAString& anIconSpec) = 0;
884 * Set the widget's MenuBar.
885 * Must be called after Create.
887 * @param aMenuBar the menubar
890 NS_IMETHOD SetMenuBar(void* aMenuBar) = 0;
893 * Set the widget's MenuBar's visibility
895 * @param aShow PR_TRUE to show, PR_FALSE to hide
898 NS_IMETHOD ShowMenuBar(PRBool aShow) = 0;
901 * Convert from this widget coordinates to screen coordinates.
903 * @param aOldRect widget coordinates stored in the x,y members
904 * @param aNewRect screen coordinates stored in the x,y members
907 NS_IMETHOD WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) = 0;
910 * Convert from screen coordinates to this widget's coordinates.
912 * @param aOldRect screen coordinates stored in the x,y members
913 * @param aNewRect widget's coordinates stored in the x,y members
916 NS_IMETHOD ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect) = 0;
919 * When adjustments are to made to a whole set of child widgets, call this
920 * before resizing/positioning the child windows to minimize repaints. Must
921 * be followed by EndResizingChildren() after child windows have been
922 * adjusted.
926 NS_IMETHOD BeginResizingChildren(void) = 0;
929 * Call this when finished adjusting child windows. Must be preceded by
930 * BeginResizingChildren().
934 NS_IMETHOD EndResizingChildren(void) = 0;
937 * Returns the preferred width and height for the widget
940 NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) = 0;
943 * Set the preferred width and height for the widget
946 NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) = 0;
949 * Dispatches an event to the widget
952 NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) = 0;
955 * Enables the dropping of files to a widget (XXX this is temporary)
958 NS_IMETHOD EnableDragDrop(PRBool aEnable) = 0;
960 virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) = 0;
963 * Enables/Disables system mouse capture.
964 * @param aCapture PR_TRUE enables mouse capture, PR_FALSE disables mouse capture
967 NS_IMETHOD CaptureMouse(PRBool aCapture) = 0;
970 * Classify the window for the window manager. Mostly for X11.
972 NS_IMETHOD SetWindowClass(const nsAString& xulWinType) = 0;
975 * Enables/Disables system capture of any and all events that would cause a
976 * dropdown to be rolled up, This method ignores the aConsumeRollupEvent
977 * parameter when aDoCapture is FALSE
978 * @param aDoCapture PR_TRUE enables capture, PR_FALSE disables capture
979 * @param aConsumeRollupEvent PR_TRUE consumes the rollup event, PR_FALSE dispatches rollup event
982 NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent) = 0;
985 * Determine whether a given event should be processed assuming we are
986 * the currently active modal window.
987 * Note that the exact semantics of this method are platform-dependent.
988 * The Macintosh, for instance, cares deeply that this method do exactly
989 * as advertised. Gtk, for instance, handles modality in a completely
990 * different fashion and does little if anything with this method.
991 * @param aRealEvent event is real or a null placeholder (Macintosh)
992 * @param aEvent void pointer to native event structure
993 * @param aForWindow return value. PR_TRUE iff event should be processed.
995 NS_IMETHOD ModalEventFilter(PRBool aRealEvent, void *aEvent, PRBool *aForWindow) = 0;
998 * Bring this window to the user's attention. This is intended to be a more
999 * gentle notification than popping the window to the top or putting up an
1000 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
1001 * the Mac. The notification should be suppressed if the window is already
1002 * in the foreground and should be dismissed when the user brings this window
1003 * to the foreground.
1004 * @param aCycleCount Maximum number of times to animate the window per system
1005 * conventions. If set to -1, cycles indefinitely until
1006 * window is brought into the foreground.
1008 NS_IMETHOD GetAttention(PRInt32 aCycleCount) = 0;
1011 * Get the last user input event time in milliseconds. If there are any pending
1012 * native toolkit input events it returns the current time. All input events are
1013 * included (ie. it is *not* limited to events targeted at this nsIWidget instance.
1015 * @param aTime Last user input time in milliseconds. This value can be used to compare
1016 * durations but can not be used for determining wall clock time. The value returned
1017 * is platform dependent, but is compatible with the expression
1018 * PR_IntervalToMicroseconds(PR_IntervalNow()).
1020 NS_IMETHOD GetLastInputEventTime(PRUint32& aTime) = 0;
1023 * Called when when we need to begin secure keyboard input, such as when a password field
1024 * gets focus.
1026 * NOTE: Calls to this method may not be nested and you can only enable secure keyboard input
1027 * for one widget at a time.
1029 NS_IMETHOD BeginSecureKeyboardInput() = 0;
1032 * Called when when we need to end secure keyboard input, such as when a password field
1033 * loses focus.
1035 * NOTE: Calls to this method may not be nested and you can only enable secure keyboard input
1036 * for one widget at a time.
1038 NS_IMETHOD EndSecureKeyboardInput() = 0;
1041 * Set the background color of the window titlebar for this widget. On Mac,
1042 * for example, this will remove the grey gradient and bottom border and
1043 * instead show a single, solid color.
1045 * Ignored on any platform that does not support it. Ignored by widgets that
1046 * do not represent windows.
1048 * @param aColor The color to set the title bar background to. Alpha values
1049 * other than fully transparent (0) are respected if possible
1050 * on the platform. An alpha of 0 will cause the window to
1051 * draw with the default style for the platform.
1053 * @param aActive Whether the color should be applied to active or inactive
1054 * windows.
1056 NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, PRBool aActive) = 0;
1059 * Determine whether the widget shows a resize widget. If it does,
1060 * aResizerRect returns the resizer's rect.
1062 * Returns false on any platform that does not support it.
1064 * @param aResizerRect The resizer's rect in device pixels.
1065 * @return Whether a resize widget is shown.
1067 virtual PRBool ShowsResizeIndicator(nsIntRect* aResizerRect) = 0;
1070 * Get the Thebes surface associated with this widget.
1072 virtual gfxASurface *GetThebesSurface() = 0;
1075 * Return the popup that was last rolled up, or null if there isn't one.
1077 virtual nsIContent* GetLastRollup() = 0;
1080 * Begin a window resizing drag, based on the event passed in.
1082 NS_IMETHOD BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical) = 0;
1084 enum Modifiers {
1085 CAPS_LOCK = 0x01, // when CapsLock is active
1086 NUM_LOCK = 0x02, // when NumLock is active
1087 SHIFT_L = 0x0100,
1088 SHIFT_R = 0x0200,
1089 CTRL_L = 0x0400,
1090 CTRL_R = 0x0800,
1091 ALT_L = 0x1000, // includes Option
1092 ALT_R = 0x2000,
1093 COMMAND_L = 0x4000,
1094 COMMAND_R = 0x8000,
1095 HELP = 0x10000,
1096 FUNCTION = 0x100000,
1097 NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad
1100 * Utility method intended for testing. Dispatches native key events
1101 * to this widget to simulate the press and release of a key.
1102 * @param aNativeKeyboardLayout a *platform-specific* constant.
1103 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
1104 * On Windows, it is converted to a hex string and passed to
1105 * LoadKeyboardLayout, see
1106 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
1107 * @param aNativeKeyCode a *platform-specific* keycode.
1108 * On Windows, this is the virtual key code.
1109 * @param aModifiers some combination of the above 'Modifiers' flags;
1110 * not all flags will apply to all platforms. Mac ignores the _R
1111 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
1112 * FUNCTION.
1113 * @param aCharacters characters that the OS would decide to generate
1114 * from the event. On Windows, this is the charCode passed by
1115 * WM_CHAR.
1116 * @param aUnmodifiedCharacters characters that the OS would decide
1117 * to generate from the event if modifier keys (other than shift)
1118 * were assumed inactive. Needed on Mac, ignored on Windows.
1119 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
1120 * layout is not supported and the event was not fired
1122 virtual nsresult SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
1123 PRInt32 aNativeKeyCode,
1124 PRUint32 aModifierFlags,
1125 const nsAString& aCharacters,
1126 const nsAString& aUnmodifiedCharacters) = 0;
1129 * Activates a native menu item at the position specified by the index
1130 * string. The index string is a string of positive integers separated
1131 * by the "|" (pipe) character. The last integer in the string represents
1132 * the item index in a submenu located using the integers preceeding it.
1134 * Example: 1|0|4
1135 * In this string, the first integer represents the top-level submenu
1136 * in the native menu bar. Since the integer is 1, it is the second submeu
1137 * in the native menu bar. Within that, the first item (index 0) is a
1138 * submenu, and we want to activate the 5th item within that submenu.
1140 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0;
1143 * This is used for native menu system testing.
1145 * Updates a native menu at the position specified by the index string.
1146 * The index string is a string of positive integers separated by the "|"
1147 * (pipe) character.
1149 * Example: 1|0|4
1150 * In this string, the first integer represents the top-level submenu
1151 * in the native menu bar. Since the integer is 1, it is the second submeu
1152 * in the native menu bar. Within that, the first item (index 0) is a
1153 * submenu, and we want to update submenu at index 4 within that submenu.
1155 * If this is called with an empty string it forces a full reload of the
1156 * menu system.
1158 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0;
1161 * Force Input Method Editor to commit the uncommited input
1163 NS_IMETHOD ResetInputState()=0;
1166 * Following methods relates to IME 'Opened'/'Closed' state.
1167 * 'Opened' means the user can input any character. I.e., users can input Japanese
1168 * and other characters. The user can change the state to 'Closed'.
1169 * 'Closed' means the user can input ASCII characters only. This is the same as a
1170 * non-IME environment. The user can change the state to 'Opened'.
1171 * For more information is here.
1172 * http://bugzilla.mozilla.org/show_bug.cgi?id=16940#c48
1176 * Set the state to 'Opened' or 'Closed'.
1177 * If aState is TRUE, IME open state is set to 'Opened'.
1178 * If aState is FALSE, set to 'Closed'.
1180 NS_IMETHOD SetIMEOpenState(PRBool aState) = 0;
1183 * Get IME is 'Opened' or 'Closed'.
1184 * If IME is 'Opened', aState is set PR_TRUE.
1185 * If IME is 'Closed', aState is set PR_FALSE.
1187 NS_IMETHOD GetIMEOpenState(PRBool* aState) = 0;
1190 * IME enabled states, the aState value of SetIMEEnabled/GetIMEEnabled
1191 * should be one value of following values.
1193 enum IMEStatus {
1195 * 'Disabled' means the user cannot use IME. So, the open state should be
1196 * 'closed' during 'disabled'.
1198 IME_STATUS_DISABLED = 0,
1200 * 'Enabled' means the user can use IME.
1202 IME_STATUS_ENABLED = 1,
1204 * 'Password' state is a special case for the password editors.
1205 * E.g., on mac, the password editors should disable the non-Roman
1206 * keyboard layouts at getting focus. Thus, the password editor may have
1207 * special rules on some platforms.
1209 IME_STATUS_PASSWORD = 2,
1211 * This state is used when a plugin is focused.
1212 * When a plug-in is focused content, we should send native events
1213 * directly. Because we don't process some native events, but they may
1214 * be needed by the plug-in.
1216 IME_STATUS_PLUGIN = 3
1220 * Set the state to 'Enabled' or 'Disabled' or 'Password'.
1222 NS_IMETHOD SetIMEEnabled(PRUint32 aState) = 0;
1225 * Get IME is 'Enabled' or 'Disabled' or 'Password'.
1227 NS_IMETHOD GetIMEEnabled(PRUint32* aState) = 0;
1230 * Destruct and don't commit the IME composition string.
1232 NS_IMETHOD CancelIMEComposition() = 0;
1235 * Get toggled key states.
1236 * aKeyCode should be NS_VK_CAPS_LOCK or NS_VK_NUM_LOCK or
1237 * NS_VK_SCROLL_LOCK.
1238 * aLEDState is the result for current LED state of the key.
1239 * If the LED is 'ON', it returns TRUE, otherwise, FALSE.
1240 * If the platform doesn't support the LED state (or we cannot get the
1241 * state), this method returns NS_ERROR_NOT_IMPLEMENTED.
1243 NS_IMETHOD GetToggledKeyState(PRUint32 aKeyCode, PRBool* aLEDState) = 0;
1245 protected:
1246 // keep the list of children. We also keep track of our siblings.
1247 // The ownership model is as follows: parent holds a strong ref to
1248 // the first element of the list, and each element holds a strong
1249 // ref to the next element in the list. The prevsibling and
1250 // lastchild pointers are weak, which is fine as long as they are
1251 // maintained properly.
1252 nsCOMPtr<nsIWidget> mFirstChild;
1253 nsIWidget* mLastChild;
1254 nsCOMPtr<nsIWidget> mNextSibling;
1255 nsIWidget* mPrevSibling;
1258 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID)
1260 #endif // nsIWidget_h__