Detailed Description

wxWindow is the base class for all windows and represents any visible object on screen.

All controls, top level windows and so on are windows. Sizers and device contexts are not, however, as they don't appear on screen themselves.

Please note that all children of the window will be deleted automatically by the destructor before the window itself is deleted which means that you don't have to worry about deleting them manually. Please see the window deletion overview for more information.

Also note that in this, and many others, wxWidgets classes some GetXXX() methods may be overloaded (as, for example, wxWindow::GetSize or wxWindow::GetClientSize). In this case, the overloads are non-virtual because having multiple virtual functions with the same name results in a virtual function name hiding at the derived class level (in English, this means that the derived class has to override all overloaded variants if it overrides any of them). To allow overriding them in the derived class, wxWidgets uses a unique protected virtual DoGetXXX() method and all GetXXX() ones are forwarded to it, so overriding the former changes the behaviour of the latter.

Styles

This class supports the following styles:

wxBORDER_DEFAULT:

The window class will decide the kind of border to show, if any.

wxBORDER_SIMPLE:

Displays a thin border around the window. wxSIMPLE_BORDER is the old name for this style.

wxBORDER_SUNKEN:

Displays a sunken border. wxSUNKEN_BORDER is the old name for this style.

wxBORDER_RAISED:

Displays a raised border. wxRAISED_BORDER is the old name for this style.

wxBORDER_STATIC:

Displays a border suitable for a static control. wxSTATIC_BORDER is the old name for this style. Windows only.

wxBORDER_THEME:

Displays a native border suitable for a control, on the current platform. On Windows XP or Vista, this will be a themed border; on most other platforms a sunken border will be used. For more information for themed borders on Windows, please see Themed borders on Windows.

wxBORDER_NONE:

Displays no border, overriding the default border style for the window. wxNO_BORDER is the old name for this style.

wxBORDER_DOUBLE:

This style is obsolete and should not be used.

wxTRANSPARENT_WINDOW:

The window is transparent, that is, it will not receive paint events. Windows only.

wxTAB_TRAVERSAL:

Use this to enable tab traversal for non-dialog windows.

wxWANTS_CHARS:

Use this to indicate that the window wants to get all char/key events for all keys - even for keys like TAB or ENTER which are usually used for dialog navigation and which wouldn't be generated without this style. If you need to use this style in order to get the arrows or etc., but would still like to have normal keyboard navigation take place, you should call Navigate in response to the key events for Tab and Shift-Tab.

wxNO_FULL_REPAINT_ON_RESIZE:

On Windows, this style used to disable repainting the window completely when its size is changed. Since this behaviour is now the default, the style is now obsolete and no longer has an effect.

wxVSCROLL:

Use this style to enable a vertical scrollbar. Notice that this style cannot be used with native controls which don't support scrollbars nor with top-level windows in most ports.

wxHSCROLL:

Use this style to enable a horizontal scrollbar. The same limitations as for wxVSCROLL apply to this style.

wxALWAYS_SHOW_SB:

If a window has scrollbars, disable them instead of hiding them when they are not needed (i.e. when the size of the window is big enough to not require the scrollbars to navigate it). This style is currently implemented for wxMSW, wxGTK and wxUniversal and does nothing on the other platforms.

wxCLIP_CHILDREN:

Use this style to eliminate flicker caused by the background being repainted, then children being painted over them. Windows only.

wxFULL_REPAINT_ON_RESIZE:

Use this style to force a complete redraw of the window whenever it is resized instead of redrawing just the part of the window affected by resizing. Note that this was the behaviour by default before 2.5.1 release and that if you experience redraw problems with code which previously used to work you may want to try this. Currently this style applies on GTK+ 2 and Windows only, and full repainting is always done on other platforms.

wxCommandEvents and the objects of the derived classes are forwarded to the parent window and so on recursively by default. Using this flag for the given window allows to block this propagation at this window, i.e. prevent the events from being propagated further upwards. Dialogs have this flag on by default for the reasons explained in the Events and Event Handling.

wxWS_EX_TRANSIENT:

Don't use this window as an implicit parent for the other windows: this must be used with transient windows as otherwise there is the risk of creating a dialog/frame with this window as a parent, which would lead to a crash if the parent were destroyed before the child.

wxWS_EX_CONTEXTHELP:

Under Windows, puts a query button on the caption. When pressed, Windows will go into a context-sensitive help mode and wxWidgets will send a wxEVT_HELP event if the user clicked on an application window. This style cannot be used (because of the underlying native behaviour) together with wxMAXIMIZE_BOX or wxMINIMIZE_BOX, so these two styles are automatically turned off if this one is used.

wxWS_EX_PROCESS_IDLE:

This window should always process idle events, even if the mode set by wxIdleEvent::SetMode is wxIDLE_PROCESS_SPECIFIED.

wxWS_EX_PROCESS_UI_UPDATES:

This window should always process UI update events, even if the mode set by wxUpdateUIEvent::SetMode is wxUPDATE_UI_PROCESS_SPECIFIED.

This method may be overridden in the derived classes to return false to indicate that while this control can, in principle, have focus if the user clicks it with the mouse, it shouldn't be included in the TAB traversal chain when using the keyboard. More...

This method calls SetSizer() and then wxSizer::SetSizeHints which sets the initial window size to the size needed to accommodate all sizer elements and sets the size hints which, if this window is a top level one, prevent the user from resizing it to be less than this minimal size. More...

Get the window border style from the given flags: this is different from simply doing flags & wxBORDER_MASK because it uses GetDefaultBorder() to translate wxBORDER_DEFAULT to something reasonable. More...

This function is (or should be, in case of custom controls) called during window creation to intelligently set up the window visual attributes, that is the font and the foreground and background colours. More...

Returns true if the window contents is double-buffered by the system, i.e. if any drawing done on the window is really done on a temporary backing surface and transferred to the screen all at once later. More...

This virtual function is normally only used internally, but sometimes an application may need it to implement functionality that should not be disabled by an application defining an OnIdle handler in a derived class. More...

Processes the pending events previously queued using QueueEvent() or AddPendingEvent(); you must call this function only if you are sure there are pending events for this handler, otherwise a wxCHECK will fail. More...

Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed. More...

Constructs a window, which can be a child of a frame, dialog or any other non-control window.

Parameters

parent

Pointer to a parent window.

id

Window identifier. If wxID_ANY, will automatically create an identifier.

pos

Window position. wxDefaultPosition indicates that wxWidgets should generate a default position for the window. If using the wxWindow class directly, supply an actual position.

size

Window size. wxDefaultSize indicates that wxWidgets should generate a default size for the window. If no suitable size can be found, the window will be sized to 20x20 pixels so that the window is visible but obviously not correctly sized.

Deletes all sub-windows, then deletes itself. Instead of using the delete operator explicitly, you should normally use Destroy() so that wxWidgets can delete a window only when it is safe to do so, in idle time.

This method may be overridden in the derived classes to return false to indicate that while this control can, in principle, have focus if the user clicks it with the mouse, it shouldn't be included in the TAB traversal chain when using the keyboard.

virtual bool wxWindow::AcceptsFocusRecursively

(

)

const

virtual

Overridden to indicate whether this window or one of its children accepts focus.

Usually it's the same as AcceptsFocus() but is overridden for container windows.

This is called automatically by window creation functions so should not be required by the application programmer. Notice that this function is mostly internal to wxWidgets and shouldn't be called by the user code.

Mirror coordinates for RTL layout if this window uses it and if the mirroring is not done automatically like Win32.

virtual void wxWindow::AlwaysShowScrollbars

(

bool

hflag = true,

bool

vflag = true

)

virtual

Call this function to force one or both scrollbars to be always shown, even if the window is big enough to show its entire contents without scrolling.

Since

2.9.0

Parameters

hflag

Whether the horizontal scroll bar should always be visible.

vflag

Whether the vertical scroll bar should always be visible.

Remarks

This function is currently only implemented under Mac/Carbon.

bool wxWindow::BeginRepositioningChildren

(

)

Prepare for changing positions of multiple child windows.

This method should be called before changing positions of multiple child windows to reduce flicker and, in MSW case, even avoid display corruption in some cases. It is used internally by wxWidgets and called automatically when the window size changes but it can also be useful to call it from outside of the library if a repositioning involving multiple children is done without changing the window size.

If this method returns true, it means that calling SetFocus() will put focus either to this window or one of its children, if you need to know whether this window accepts focus itself, use IsFocusable()

bool wxWindow::CanAcceptFocusFromKeyboard

(

)

const

Can this window be assigned focus from keyboard right now?

bool wxWindow::CanScroll

(

int

orient

)

const

Returns true if this window can have a scroll bar in this orientation.

Parameters

orient

Orientation to check, either wxHORIZONTAL or wxVERTICAL.

Since

2.9.1

virtual bool wxWindow::CanSetTransparent

(

)

virtual

Returns true if the system supports transparent windows and calling SetTransparent() may succeed.

If this function returns false, transparent windows are definitely not supported by the current system.

Note that wxWidgets maintains the stack of windows having captured the mouse and when the mouse is released the capture returns to the window which had had captured it previously and it is only really released if there were no previous window. In particular, this means that you must release the mouse as many times as you capture it, unless the window receives the wxMouseCaptureLostEvent event.

Any application which captures the mouse in the beginning of some operation must handle wxMouseCaptureLostEvent and cancel this operation when it receives the event. The event handler must not recapture mouse.

Specifies the direction for the centring. May be wxHORIZONTAL, wxVERTICAL or wxBOTH. It may also include the wxCENTRE_ON_SCREEN flag if you want to centre the window on the entire screen and not on its parent window.

Remarks

If the window is a top level one (i.e. doesn't have a parent), it will be centred relative to the screen anyhow.

Specifies the direction for the centring. May be wxHORIZONTAL, wxVERTICAL or wxBOTH.

Remarks

This methods provides for a way to centre top level windows over their parents instead of the entire screen. If there is no parent or if the window is not a top level window, then behaviour is the same as Centre().

Notice that this uses wxClientDC to draw on the window and the results of doing it while also drawing on wxPaintDC for this window are undefined. Hence this method shouldn't be used from EVT_PAINT handlers, just use wxDC::Clear() on the wxPaintDC you already use there instead.

void wxWindow::ClientToScreen

(

int *

x,

int *

y

)

const

Converts to screen coordinates from coordinates relative to this window.

Parameters

x

A pointer to a integer value for the x coordinate. Pass the client coordinate in, and a screen coordinate will be passed out.

y

A pointer to a integer value for the y coordinate. Pass the client coordinate in, and a screen coordinate will be passed out.

wxPerl Note: In wxPerl this method returns a 2-element list instead of modifying its parameters.

In other words, the returned value is what would GetSize() return if this window had client area of given size. Components with wxDefaultCoord value are left unchanged. Note that the conversion is not always exact, it assumes that non-client area doesn't change and so doesn't take into account things like menu bar (un)wrapping or (dis)appearance of the scrollbars.

This function simply generates a wxCloseEvent whose handler usually tries to close the window.

It doesn't close the window itself, however.

Parameters

force

false if the window's close handler should be able to veto the destruction of this window, true if it cannot.

Returns

true if the event was handled and not vetoed, false otherwise.

Remarks

Close calls the close handler for the window, providing an opportunity for the window to choose whether to destroy the window. Usually it is only used with the top level windows (wxFrame and wxDialog classes) as the others are not supposed to have any special OnClose() logic. The close handler should check whether the window is being deleted forcibly, using wxCloseEvent::CanVeto, in which case it should destroy the window using wxWindow::Destroy. Note that calling Close does not guarantee that the window will be destroyed; but it provides a way to simulate a manual close of a window, which may or may not be implemented by destroying the window. The default implementation of wxDialog::OnCloseWindow does not necessarily delete the dialog, since it will simply simulate an wxID_CANCEL event which is handled by the appropriate button event handler and may do anything at all. To guarantee that the window will be destroyed, call wxWindow::Destroy instead

For the x dimension, the dialog units are multiplied by the average character width and then divided by 4. For the y dimension, the dialog units are multiplied by the average character height and then divided by 8.

Remarks

Dialog units are used for maintaining a dialog's proportions even if the font changes. You can also use these functions programmatically. A convenience macro is defined:

For the x dimension, the pixels are multiplied by 4 and then divided by the average character width. For the y dimension, the pixels are multiplied by 8 and then divided by the average character height.

Remarks

Dialog units are used for maintaining a dialog's proportions even if the font changes.

Use this function instead of the delete operator, since different window classes can be destroyed differently. Frames and dialogs are not destroyed immediately when this function is called – they are added to a list of windows to be deleted on idle time, when all the window's events have been processed. This prevents problems with events being sent to non-existent windows.

Returns

true if the window has either been successfully deleted, or it has been added to the list of windows pending real deletion.

Returns true if the window has been disabled, false if it had been already disabled before the call to this function.

virtual void wxWindow::DoCentre

(

int

direction

)

protectedvirtual

Centres the window.

Parameters

direction

Specifies the direction for the centring. May be wxHORIZONTAL, wxVERTICAL or wxBOTH. It may also include the wxCENTRE_ON_SCREEN flag.

Remarks

This function is not meant to be called directly by user code, but via Centre, Center, CentreOnParent, or CenterOnParent. This function can be overridden to fine-tune centring behaviour.

virtual int wxWindow::DoGetBestClientHeight

(

int

width

)

const

protectedvirtual

Override this method to implement height-for-width best size calculation.

Return the height needed to fully display the control contents if its width is fixed to the given value. Custom classes implementing wrapping should override this method and return the height corresponding to the number of lines needed to lay out the control contents at this width.

Currently this method is not used by wxWidgets yet, however it is planned that it will be used by the new sizer classes implementing height-for-width layout strategy in the future.

Notice that implementing this method or even implementing both it and DoGetBestClientWidth() doesn't replace overriding DoGetBestClientSize(), i.e. you still need to implement the latter as well in order to provide the best size when neither width nor height are constrained.

A typical implementation of this method should compute the minimal size needed to fully display the control contents taking into account the current font size.

The default implementation simply returns wxDefaultSize and GetBestSize() returns an arbitrary hardcoded size for the window, so you must override it when implementing a custom window class.

Notice that the best size returned by this function is cached internally, so if anything that results in the best size changing (e.g. change to the control contents) happens, you need to call InvalidateBestSize() to notify wxWidgets about it.

This function is called by UpdateWindowUI() in order to check return values in the wxUpdateUIEvent and act appropriately. For example, to allow frame and dialog title updating, wxWidgets implements this function as follows:

// do the window-specific processing after processing the update event

Depending on the type of window, the label may be a window title or panel item label. If parent is NULL, the search will start from all top-level frames and dialog boxes; if non-NULL, the search will be limited to the given window hierarchy. The search is recursive in both cases.

Mainly useful with scrolled windows to reset scrollbars after sizing changes that do not trigger a size event, and/or scrolled windows without an interior sizer. This function similarly won't do anything if there are no subwindows.

void wxWindow::Freeze

(

)

Freezes the window or, in other words, prevents any updates from taking place on screen, the window is not redrawn at all.

Thaw() must be called to reenable window redrawing. Calls to these two functions may be nested but to ensure that the window is properly repainted again, you must thaw it exactly as many times as you froze it.

If the window has any children, they are recursively frozen too.

This method is useful for visual appearance optimization (for example, it is a good idea to use it before doing many large text insertions in a row into a wxTextCtrl under wxGTK) but is not implemented on all platforms nor for all controls so it is mostly just a hint to wxWidgets and not a mandatory directive.

Convert DPI-independent pixel values to the value in pixels appropriate for the current toolkit.

A DPI-independent pixel is just a pixel at the standard 96 DPI resolution. To keep the same physical size at higher resolution, the physical pixel value must be scaled by GetContentScaleFactor() but this scaling may be already done by the underlying toolkit (GTK+, Cocoa, ...) automatically. This method performs the conversion only if it is not already done by the lower level toolkit and so by using it with pixel values you can guarantee that the physical size of the corresponding elements will remain the same in all resolutions under all platforms. For example, instead of creating a bitmap of the hard coded size of 32 pixels you should use

Notice that this function is only needed when using hard coded pixel values. It is not necessary if the sizes are already based on the DPI-independent units such as dialog units or if you are relying on the controls automatic best size determination and using sizers to lay out them.

The display resolution depends on the window in general as different windows can appear on different monitors using different resolutions, however sometimes no window is available for converting the resolution independent pixels to the physical values and in this case these static overloads can be used with NULL value for w argument.

Using these methods is discouraged as passing NULL will prevent your application from correctly supporting monitors with different resolutions even in the future wxWidgets versions which will add support for them, and passing non-NULL window is just a less convenient way of calling the non-static FromDIP() method.

This functions returns the best acceptable minimal size for the window.

For example, for a static control, it will be the minimal size such that the control label is not truncated. For windows containing subwindows (typically wxPanel), the size returned by this function will be the same as the size the window would have had after calling Fit().

Override virtual DoGetBestSize() or, better, because it's usually more convenient, DoGetBestClientSize() when writing your own custom window class to change the value returned by this public non-virtual method.

Notice that the best size respects the minimal and maximal size explicitly set for the window, if any. So even if some window believes that it needs 200 pixels horizontally, calling SetMaxSize() with a width of 100 would ensure that GetBestSize() returns the width of at most 100 pixels.

This is useful if you want to use the same font or colour in your own control as in a standard control – which is a much better idea than hard coding specific colours or fonts which might look completely out of place on the users system, especially if it uses themes.

The variant parameter is only relevant under Mac currently and is ignore under other platforms. Under Mac, it will change the size of the returned font. See SetWindowVariant() for more about this.

The wxVisualAttributes structure has at least the fields font, colFg and colBg. All of them may be invalid if it was not possible to determine the default control appearance or, especially for the background colour, if the field doesn't make sense as is the case for colBg for the controls with themed background.

The client area is the area which may be drawn on by the programmer, excluding title bar, border, scrollbars, etc. Note that if this window is a top-level one and it is currently minimized, the return size is empty (both width and height are 0).

wxPerl Note: In wxPerl this method takes no parameters and returns a 2-element list (width, height).

Returns the sizer of which this window is a member, if any, otherwise NULL.

double wxWindow::GetContentScaleFactor

(

)

const

Returns the magnification of the backing store of this window, eg 2.0 for a window on a retina screen.

This factor should be used to determine the size of bitmaps and similar "content-containing" windows appropriate for the current resolution. E.g. the program may load a 32px bitmap if the content scale factor is 1.0 or 64px version of the same bitmap if it is 2.0 or bigger.

Notice that this method should not be used for window sizes, as they are already scaled by this factor by the underlying toolkit under some platforms. Use FromDIP() for anything window-related instead.

Currently this is the same as calling wxWindow::GetClassDefaultAttributes(wxWindow::GetWindowVariant()).

One advantage of using this function compared to the static version is that the call is automatically dispatched to the correct class (as usual with virtual functions) and you don't have to specify the class name explicitly.

The other one is that in the future this function could return different results, for example it might return a different font for an "Ok" button than for a generic button if the users GUI is configured to show such buttons in bold font. Of course, the down side is that it is impossible to call this function without actually having an object to apply it to whereas the static version can be used without having to create an object first.

Generic way of getting a label from any window, for identification purposes.

Remarks

The interpretation of this function differs from class to class. For frames and dialogs, the value returned is the title. For buttons or static text controls, it is the button text. This function can be useful for meta-programs (such as testing tools or special-needs access programs) which need to identify windows by name.

This function shows a popup menu at the given position in this window and returns the selected id.

It can be more convenient than the general purpose PopupMenu() function for simple menus proposing a choice in a list of strings to the user.

Notice that to avoid unexpected conflicts between the (usually consecutive range of) ids used by the menu passed to this function and the existing EVT_UPDATE_UI() handlers, this function temporarily disables UI updates for the window, so you need to manually disable (or toggle or ...) any items which should be disabled in the menu before showing it.

The parameter menu is the menu to show. The parameter pos (or the parameters x and y) is the position at which to show the menu in client coordinates. It is recommended to not explicitly specify coordinates when calling this method in response to mouse click, because some of the ports (namely, wxGTK) can do a better job of positioning the menu in that case.

Returns

The selected menu item id or wxID_NONE if none selected or an error occurred.

Gets the dimensions of the string as it would be drawn on the window with the currently selected font.

virtual bool wxWindow::GetThemeEnabled

(

)

const

virtual

Clears the window by filling it with the current background colour.

Does not cause an erase background event to be generated.

Notice that this uses wxClientDC to draw on the window and the results of doing it while also drawing on wxPaintDC for this window are undefined. Hence this method shouldn't be used from EVT_PAINT handlers, just use wxDC::Clear() on the wxPaintDC you already use there instead.

This method should be overridden to return true if this window has multiple pages.

All standard class with multiple pages such as wxNotebook, wxListbook and wxTreebook already override it to return true and user-defined classes with similar behaviour should also do so, to allow the library to handle such windows appropriately.

bool wxWindow::HasScrollbar

(

int

orient

)

const

Returns true if this window currently has a scroll bar for this orientation.

This method may return false even when CanScroll() for the same orientation returns true, but if CanScroll() returns false, i.e. scrolling in this direction is not enabled at all, HasScrollbar() always returns false as well.

Parameters

orient

Orientation to check, either wxHORIZONTAL or wxVERTICAL.

virtual bool wxWindow::HasTransparentBackground

(

)

virtual

Returns true if this window background is transparent (as, for example, for wxStaticText) and should show the parent window background.

This method is mostly used internally by the library itself and you normally shouldn't have to call it. You may, however, have to override it in your wxWindow-derived class to ensure that background is painted correctly.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

virtual bool wxWindow::InformFirstDirection

(

int

direction,

int

size,

int

availableOtherDir

)

virtual

wxSizer and friends use this to give a chance to a component to recalc its min size once one of the final size components is known.

Override this function when that is useful (such as for wxStaticText which can stretch over several lines). Parameter availableOtherDir tells the item how much more space there is available in the opposite direction (-1 if unknown).

virtual void wxWindow::InheritAttributes

(

)

virtual

This function is (or should be, in case of custom controls) called during window creation to intelligently set up the window visual attributes, that is the font and the foreground and background colours.

By "intelligently" the following is meant: by default, all windows use their own GetClassDefaultAttributes() default attributes. However if some of the parents attributes are explicitly (that is, using SetFont() and not wxWindow::SetOwnFont) changed and if the corresponding attribute hadn't been explicitly set for this window itself, then this window takes the same value as used by the parent. In addition, if the window overrides ShouldInheritColours() to return false, the colours will not be changed no matter what and only the font might.

This rather complicated logic is necessary in order to accommodate the different usage scenarios. The most common one is when all default attributes are used and in this case, nothing should be inherited as in modern GUIs different controls use different fonts (and colours) than their siblings so they can't inherit the same value from the parent. However it was also deemed desirable to allow to simply change the attributes of all children at once by just changing the font or colour of their common parent, hence in this case we do inherit the parents attributes.

bool wxWindow::InheritsBackgroundColour

(

)

const

Return true if this window inherits the background colour from its parent.

Top level windows are not deleted immediately but are rather scheduled for later destruction to give them time to process any pending messages; see Destroy() description.

This function returns true if this window, or one of its parent windows, is scheduled for destruction and can be useful to avoid manipulating it as it's usually useless to do something with a window which is at the point of disappearing anyhow.

bool wxWindow::IsDescendant

(

wxWindowBase *

win

)

const

Check if the specified window is a descendant of this one.

Returns true if the window is a descendant (i.e. a child or grand-child or grand-grand-child or ...) of this one.

Notice that a window can never be a descendant of another one if they are in different top level windows, i.e. a child of a wxDialog is not considered to be a descendant of dialogs parent wxFrame.

Parameters

win

Any window, possible NULL (false is always returned then).

Since

2.9.4

virtual bool wxWindow::IsDoubleBuffered

(

)

const

virtual

Returns true if the window contents is double-buffered by the system, i.e. if any drawing done on the window is really done on a temporary backing surface and transferred to the screen all at once later.

Returns true if the window is enabled, i.e. if it accepts user input, false otherwise.

Notice that this method can return false even if this window itself hadn't been explicitly disabled when one of its parent windows is disabled. To get the intrinsic status of this window, use IsThisEnabled()

Notice that this function would typically be called on the parent of a window you want to set transparent background style for as the window for which this method is called must be fully created.

Parameters

reason

If not NULL, a reason message is provided if transparency is not supported.

Returns

true if background transparency is supported.

Since

2.9.4

virtual bool wxWindow::Layout

(

)

virtual

Invokes the constraint-based layout algorithm or the sizer-based algorithm for this window.

This function does not get called automatically when the window is resized because lots of windows deriving from wxWindow does not need this functionality. If you want to have Layout() called automatically, you should derive from wxPanel (see wxPanel::Layout).

Returns true if the focus was moved to another window or false if nothing changed.

Remarks

You may wish to call this from a text control custom keypress handler to do the default navigation behaviour for the tab key, since the standard default behaviour for a multiline text control with the wxTE_PROCESS_TAB style is to insert a tab and not navigate to the next control. See also wxNavigationKeyEvent and HandleAsNavigationKey.

This virtual function is normally only used internally, but sometimes an application may need it to implement functionality that should not be disabled by an application defining an OnIdle handler in a derived class.

This function may be used to do delayed painting, for example, and most implementations call UpdateWindowUI() in order to send update events to the window in idle time.

Pops up the given menu at the specified coordinates, relative to this window, and returns control when the user has dismissed the menu.

If a menu item is selected, the corresponding menu event is generated and will be processed as usual. If coordinates are not specified, the current mouse cursor position is used.

menu is the menu to pop up.

The position where the menu will appear can be specified either as a wxPointpos or by two integers (x and y).

Remarks

Just before the menu is popped up, wxMenu::UpdateUI is called to ensure that the menu items are in the correct state. The menu does not get deleted by the window. It is recommended to not explicitly specify coordinates when calling PopupMenu in response to mouse click, because some of the ports (namely, wxGTK) can do a better job of positioning the menu in that case.

Note that it's still possible to call these functions directly on the wxWindow object (e.g. casting it to wxEvtHandler) but doing that will create subtle bugs when windows with event handlers pushed on them are involved.

This method is similar to ProcessWindowEvent() but can be used to search for the event handler only in this window and any event handlers pushed on top of it. Unlike ProcessWindowEvent() it won't propagate the event upwards. But it will use the validator and event handlers associated with this window, if any.

An event handler is an object that is capable of processing the events sent to a window. By default, the window is its own event handler, but an application may wish to substitute another, for example to allow central implementation of event-handling for a variety of different window classes.

wxWindow::PushEventHandler allows an application to set up a stack of event handlers, where an event not handled by one event handler is handed to the next one in the chain.

E.g. if you have two event handlers A and B and a wxWindow instance W and you call:

Notice that this function only requests the window manager to raise this window to the top of Z-order. Depending on its configuration, the window manager may raise the window, not do it at all or indicate that a window requested to be raised in some other way, e.g. by flashing its icon if it is minimized.

Redraws the contents of the given rectangle: only the area inside it will be repainted.

This is the same as Refresh() but has a nicer syntax as it can be called with a temporary wxRect object as argument like this RefreshRect(wxRect(x, y, w, h)).

virtual bool wxWindow::RegisterHotKey

(

int

hotkeyId,

int

modifiers,

int

virtualKeyCode

)

virtual

Registers a system wide hotkey.

Every time the user presses the hotkey registered here, this window will receive a hotkey event.

It will receive the event even if the application is in the background and does not have the input focus because the user is working with some other application.

Parameters

hotkeyId

Numeric identifier of the hotkey. For applications this must be between 0 and 0xBFFF. If this function is called from a shared DLL, it must be a system wide unique identifier between 0xC000 and 0xFFFF. This is a MSW specific detail.

modifiers

A bitwise combination of wxMOD_SHIFT, wxMOD_CONTROL, wxMOD_ALT or wxMOD_WIN specifying the modifier keys that have to be pressed along with the key.

virtualKeyCode

The virtual key code of the hotkey.

Returns

true if the hotkey was registered successfully. false if some other application already registered a hotkey with this modifier/virtualKeyCode combination.

Remarks

Use EVT_HOTKEY(hotkeyId, fnc) in the event table to capture the event. This function is currently only implemented under MSW and OSX and always returns false in the other ports.

This is called automatically by window deletion functions so should not be required by the application programmer. Notice that this function is mostly internal to wxWidgets and shouldn't be called by the user code.

This function sends a dummy size event to the window allowing it to re-layout its children positions.

It is sometimes useful to call this function after adding or deleting a children after the frame creation or if a child size changes. Note that if the frame is using either sizers or constraints for the children layout, it is enough to call wxWindow::Layout() directly and this function should not be used in this case.

If flags includes wxSEND_EVENT_POST value, this function posts the event, i.e. schedules it for later processing, instead of dispatching it directly. You can also use PostSizeEvent() as a more readable equivalent of calling this function with this flag.

This function simply checks that the window has a valid parent which is not in process of being deleted and calls SendSizeEvent() on it. It is used internally by windows such as toolbars changes to whose state should result in parent re-layout (e.g. when a toolbar is added to the top of the window, all the other windows must be shifted down).

The colour to be used as the background colour; pass wxNullColour to reset to the default colour. Note that you may want to use wxSystemSettings::GetColour() to retrieve a suitable colour to use rather than setting an hard-coded one.

Remarks

The background colour is usually painted by the default wxEraseEvent event handler function under Windows and automatically under GTK. Note that setting the background colour does not cause an immediate refresh, so you may wish to call wxWindow::ClearBackground or wxWindow::Refresh after calling this function. Using this function will disable attempts to use themes for this window, if the system supports them. Use with care since usually the themes represent the appearance chosen by the user to be used for all applications on the system.

Returns

true if the colour was really changed, false if it was already set to this colour and nothing was done.

The default background style is wxBG_STYLE_ERASE which indicates that the window background may be erased in EVT_ERASE_BACKGROUND handler. This is a safe, compatibility default; however you may want to change it to wxBG_STYLE_SYSTEM if you don't define any erase background event handlers at all, to avoid unnecessary generation of erase background events and always let system erase the background. And you should change the background style to wxBG_STYLE_PAINT if you define an EVT_PAINT handler which completely overwrites the window background as in this case erasing it previously, either in EVT_ERASE_BACKGROUND handler or in the system default handler, would result in flicker as the background pixels will be repainted twice every time the window is redrawn. Do ensure that the background is entirely erased by your EVT_PAINT handler in this case however as otherwise garbage may be left on screen.

Notice that in previous versions of wxWidgets a common way to work around the above mentioned flickering problem was to define an empty EVT_ERASE_BACKGROUND handler. Setting background style to wxBG_STYLE_PAINT is a simpler and more efficient solution to the same problem.

Also, in order for SetBackgroundStyle(wxBG_STYLE_TRANSPARENT) to work, it must be called before Create(). If you're using your own wxWindow-derived class you should write your code in the following way:

This method is only implemented by ports which have support for native TAB traversal (such as GTK+ 2.0).

It is called by wxWidgets' container control code to give the native system a hint when doing TAB traversal. A call to this does not disable or change the effect of programmatically calling SetFocus().

Using this function to size a window tends to be more device-independent than SetSize(), since the application need not worry about what dimensions the border or title bar have when trying to fit the window around panel items, for example.

The window will then own the object, and will take care of its deletion. If an existing layout constraints object is already owned by the window, it will be deleted.

Parameters

constraints

The constraints to set. Pass NULL to disassociate and delete the window's constraints.

Remarks

You must call SetAutoLayout() to tell a window to use the constraints automatically in OnSize; otherwise, you must override OnSize and call Layout() explicitly. When setting both a wxLayoutConstraints and a wxSizer, only the sizer will have effect.

Note that if you use this function you may want to use as the "next" handler of handler the window itself; in this way when handler doesn't process an event, the window itself will have a chance to do it.

This function should not be called for the parent window if you don't want its font to be inherited by its children, use SetOwnFont() instead in this case and see InheritAttributes() for more explanations.

Please notice that the given font is not automatically used for wxPaintDC objects associated with this window, you need to call wxDC::SetFont too. However this font is used by any standard controls for drawing their text as well as by GetTextExtent().

Parameters

font

Font to associate with this window, pass wxNullFont to reset to the default font.

Returns

true if the font was really changed, false if it was already set to this font and nothing was done.

The meaning of foreground colour varies according to the window class; it may be the text colour or other colour, or it may not be used at all. Additionally, not all native controls support changing their foreground colour so this method may change their colour only partially or even not at all.

Each window has an integer identifier. If the application has not provided one, an identifier will be generated. Normally, the identifier should be provided on creation and should not be modified subsequently.

A smart SetSize that will fill in default size components with the window's best size values.

Also sets the window's minsize to the value passed in for use with sizers. This means that if a full or partial size is passed to this function then the sizers will use that size instead of the results of GetBestSize() to determine the minimum needs of the window for layout.

Most controls will use this to set their initial size, and their min size to the passed in value (if any.)

Sets the minimum size of the window, to indicate to the sizer layout mechanism that this is the minimum required size.

You may need to call this if you change the window size after construction and before adding to its parent sizer.

Notice that calling this method doesn't prevent the program from making the window explicitly smaller than the specified size by calling SetSize(), it just ensures that it won't become smaller than this size during the automatic layout.

Determines the scrollbar whose page size is to be set. May be wxHORIZONTAL or wxVERTICAL.

position

The position of the scrollbar in scroll units.

thumbSize

The size of the thumb, or visible portion of the scrollbar, in scroll units.

range

The maximum position of the scrollbar. Value of -1 can be used to ask for the scrollbar to be shown but in the disabled state: this can be used to avoid removing the scrollbar even when it is not needed (currently this is only implemented in wxMSW port).

refresh

true to redraw the scrollbar, false otherwise.

Remarks

Let's say you wish to display 50 lines of text, using the same font. The window is sized so that you can only see 16 lines at a time. You would use:

Note that with the window at this size, the thumb position can never go above 50 minus 16, or 34. You can determine how many lines are currently visible by dividing the current view size by the character height in pixels. When defining your own scrollbar behaviour, you will always need to recalculate the scrollbar settings when the window size changes. You could therefore put your scrollbar calculations and SetScrollbar call into a function named AdjustScrollbars, which can be called initially and also from your wxSizeEvent handler function.

wxSIZE_FORCE: normally, if the position and the size of the window are already the same as the parameters of this function, nothing is done. but with this flag a window resize may be forced even in this case (supported in wx 2.6.2 and later and only implemented for MSW and ignored elsewhere currently).

Remarks

This overload sets the position and optionally size, of the window. Parameters may be wxDefaultCoord to indicate either that a default should be supplied by wxWidgets, or that the current value of the dimension should be used.

The window will then own the object, and will take care of its deletion. If an existing layout constraints object is already owned by the window, it will be deleted if the deleteOld parameter is true.

Note that this function will also call SetAutoLayout() implicitly with true parameter if the sizer is non-NULL and false otherwise so that the sizer will be effectively used to layout the window children whenever it is resized.

Parameters

sizer

The sizer to set. Pass NULL to disassociate and conditionally delete the window's sizer. See below.

deleteOld

If true (the default), this will delete any pre-existing sizer. Pass false if you wish to handle deleting the old sizer yourself but remember to do it yourself in this case to avoid memory leaks.

This method calls SetSizer() and then wxSizer::SetSizeHints which sets the initial window size to the size needed to accommodate all sizer elements and sets the size hints which, if this window is a top level one, prevent the user from resizing it to be less than this minimal size.

virtual void wxWindow::SetThemeEnabled

(

bool

enable

)

virtual

This function tells a window if it should use the system's "theme" code to draw the windows' background instead of its own background drawing code.

This does not always have any effect since the underlying platform obviously needs to support the notion of themes in user defined windows. One such platform is GTK+ where windows can have (very colourful) backgrounds defined by a user's selected theme.

Dialogs, notebook pages and the status bar have this flag set to true by default so that the default look and feel is simulated best.

If the system supports transparent windows, returns true, otherwise returns false and the window remains fully opaque. See also CanSetTransparent().

The parameter alpha is in the range 0..255 where 0 corresponds to a fully transparent window and 255 to the fully opaque one. The constants wxIMAGE_ALPHA_TRANSPARENT and wxIMAGE_ALPHA_OPAQUE can be used.

Window variants currently just differ in size, as can be seen from wxWindowVariant documentation. Under all platforms but OS X, this function does nothing more than change the font used by the window. However under OS X it is implemented natively and selects the appropriate variant of the native widget, which has better appearance than just scaled down or up version of the normal variant, so it should be preferred to directly tweaking the font size.

By default the controls naturally use the normal variant.

virtual bool wxWindow::ShouldInheritColours

(

)

const

virtual

Return true from here to allow the colours of this window to be changed by InheritAttributes().

Returning false forbids inheriting them from the parent window.

The base class version returns false, but this method is overridden in wxControl where it returns true.

You may need to call Raise() for a top level window if you want to bring it to top, although this is not needed if Show() is called immediately after the frame creation.

Notice that the default state of newly created top level windows is hidden (to allow you to create their contents without flicker) unlike for all the other, not derived from wxTopLevelWindow, windows that are by default created in the shown state.

Parameters

show

If true displays the window. Otherwise, hides it.

Returns

true if the window has been shown or hidden or false if nothing was done because it already was in the requested state.

Calling this method immediately repaints the invalidated area of the window and all of its children recursively (this normally only happens when the flow of control returns to the event loop).

Notice that this function doesn't invalidate any area of the window so nothing happens if nothing has been invalidated (i.e. marked as requiring a redraw). Use Refresh() first if you want to immediately redraw the window unconditionally.

The particular implementation depends on the window; for example a wxToolBar will send an update UI event for each toolbar button, and a wxFrame will send an update UI event for each menubar menu item.

If you are calling this function from an OnInternalIdle or OnIdle function, make sure you pass the wxUPDATE_UI_FROMIDLE flag, since this tells the window to only update the UI elements that need to be updated in idle time. Some windows update their elements only when necessary, for example when a menu is about to be shown. The following is an example of how to call UpdateWindowUI from an idle function.

Apple Human Interface Guidelines forbid moving the mouse cursor programmatically so you should avoid using this function in Mac applications (and probably avoid using it under the other platforms without good reason as well).