wxRuby Documentation Home

# Wx::Window

Window 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 before the window itself is deleted which means that you
don’t have to worry about deleting them manually.

## Derived from

EvtHandler

Object

## Window styles

The following styles can apply to all windows, although they will not always make sense for a particular
window class or on all platforms.

`SIMPLE_BORDER` | Displays a thin border around the window. BORDER is the old namefor this style.
`DOUBLE_BORDER` | Displays a double border. Windows and Mac only.
`SUNKEN_BORDER` | Displays a sunken border.
`RAISED_BORDER` | Displays a raised border.
`STATIC_BORDER` | Displays a border suitable for a static control. Windows only.
`NO_BORDER` | Displays no border, overriding the default border style for the window.
`TRANSPARENT_WINDOW` | The window is transparent, that is, it will not receive paintevents. Windows only.
`TAB_TRAVERSAL` | Use this to enable tab traversal for non-dialog windows.

`WANTS_CHARS`

Use this to indicate thatthe window wants to get all char/key events for all keys – even forkeys like TAB or ENTER which are usually used for dialog navigationand which wouldn’t be generated without this style. If you need touse this style in order to get the arrows or etc., but would still like to havenormal keyboard navigation take place, you should create and send aNavigationKeyEvent in response to the key events for Tab andShift-Tab.

`NO_FULL_REPAINT_ON_RESIZE` | On Windows, this style used to disable repaintingthe window completely when its size is changed. Since this behaviour is now the default, the style is now obsoleteand no longer has an effect.
`VSCROLL` | Use this style to enable a vertical scrollbar.
`HSCROLL` | Use this style to enable a horizontal scrollbar.
`ALWAYS_SHOW_SB` | If a window has scrollbars,disable them instead of hiding them when they are not needed (i.e. when thesize of the window is big enough to not require the scrollbars to navigate it).This style is currently implemented for MSW, GTK and Universal and doesnothing on the other platforms.
`CLIP_CHILDREN` | Use this style to eliminate flicker caused by the background beingrepainted, then children being painted over them. Windows only.

`FULL_REPAINT_ON_RESIZE`

Use this style to forcea complete redraw of the window whenever it is resized instead of redrawingjust the part of the window affected by resizing. Note that this was thebehaviour by default before 2.5.1 release and that if you experience redrawproblems 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 alwaysdone on other platforms.

See also window styles overview.

## Extra window styles

The following are extra styles, set using Window#set_extra_style.

`WS_EX_BLOCK_EVENTS` | CommandEvents and the objects of the derived classes are forwarded to theparent window and so on recursively by default. Using this flag for thegiven window allows to block this propagation at this window, i.e. preventthe events from being propagated further upwards. Dialogs have thisflag on by default.
`WS_EX_TRANSIENT` | Don’t use this window as an implicit parent for the other windows: this mustbe used with transient windows as otherwise there is the risk of creating adialog/frame with this window as a parent which would lead to a crash if theparent is destroyed before the child.
`WS_EX_PROCESS_IDLE` | This window should always process idle events, evenif the mode set by IdleEvent#set_mode is IDLE_PROCESS_SPECIFIED.
`WS_EX_PROCESS_UI_UPDATES` | This window should always process UI update events,even if the mode set by UpdateUIEvent#set_mode is UPDATE_UI_PROCESS_SPECIFIED.

## See also

Event handling overview

Window sizing overview

## Methods

- Window.new
- Window.find_focus
- Window#add_child
- Window#bring_to_front
- Window#cache_best_size
- Window#capture_mouse
- Window#center
- Window#center_on_parent
- Window#centre
- Window#centre_on_parent
- Window#clear_background
- Window#client_to_screen
- Window#close
- Window#convert_dialog_to_pixels
- Window#convert_pixels_to_dialog
- Window#destroy
- Window#destroy_children
- Window#disable
- Window#do_get_best_size
- Window#do_update_window_ui
- Window#enable
- Window#find_window
- Window#find_window_by_id
- Window#find_window_by_label
- Window#find_window_by_name
- Window#fit
- Window#fit_inside
- Window#freeze
- Window#get_accelerator_table
- Window#get_accessible
- Window#get_background_colour
- Window#get_background_style
- Window#get_effective_min_size
- Window#get_best_size
- Window#get_capture
- Window#get_caret
- Window#get_char_height
- Window#get_char_width
- Window#get_children
- Window#get_class_default_attributes
- Window#get_client_size
- Window#get_client_rect
- Window#get_constraints
- Window#get_containing_sizer
- Window#get_cursor
- Window#get_default_attributes
- Window#get_drop_target
- Window#get_effective_best_size
- Window#get_event_handler
- Window#get_extra_style
- Window#get_font
- Window#get_foreground_colour
- Window#get_grand_parent
- Window#get_handle
- Window#get_help_text_at_point
- Window#get_help_text
- Window#get_id
- Window#get_label
- Window#get_max_size
- Window#get_min_size
- Window#get_name
- Window#get_parent
- Window#get_position
- Window#get_rect
- Window#get_screen_position
- Window#get_screen_rect
- Window#get_scroll_pos
- Window#get_scroll_range
- Window#get_scroll_thumb
- Window#get_size
- Window#get_sizer
- Window#get_text_extent
- Window#get_tool_tip
- Window#get_update_region
- Window#get_validator
- Window#get_virtual_size
- Window#get_window_border_size
- Window#get_window_style_flag
- Window#get_window_variant
- Window#has_capture
- Window#has_flag
- Window#has_multiple_pages
- Window#has_scrollbar
- Window#has_transparent_background
- Window#hide
- Window#inherit_attributes
- Window#init_dialog
- Window#invalidate_best_size
- Window#is_double_buffered
- Window#is_enabled
- Window#is_exposed
- Window#is_frozen
- Window#is_retained
- Window#is_shown
- Window#is_shown_on_screen
- Window#is_top_level
- Window#layout
- Window#line_down
- Window#line_up
- Window#lower
- Window#make_modal
- Window#move
- Window#move_after_in_tab_order
- Window#move_before_in_tab_order
- Window#navigate
- Window#on_internal_idle
- Window#page_down
- Window#page_up
- Window#paint
- Window#paint_buffered
- Window#pop_event_handler
- Window#popup_menu
- Window#push_event_handler
- Window#raise
- Window#refresh
- Window#refresh_rect
- Window#register_hot_key
- Window#release_mouse
- Window#remove_child
- Window#remove_event_handler
- Window#reparent
- Window#screen_to_client
- Window#scroll_lines
- Window#scroll_pages
- Window#scroll_window
- Window#send_to_back
- Window#set_accelerator_table
- Window#set_accessible
- Window#set_auto_layout
- Window#set_background_colour
- Window#set_background_style
- Window#set_initial_size
- Window#set_caret
- Window#set_client_size
- Window#set_constraints
- Window#set_containing_sizer
- Window#set_cursor
- Window#set_drop_target
- Window#set_initial_best_size
- Window#set_event_handler
- Window#set_extra_style
- Window#set_focus
- Window#set_focus_from_kbd
- Window#set_font
- Window#set_foreground_colour
- Window#set_help_text
- Window#set_id
- Window#set_label
- Window#set_max_size
- Window#set_min_size
- Window#set_name
- Window#set_own_background_colour
- Window#set_own_font
- Window#set_own_foreground_colour
- Window#set_palette
- Window#set_scrollbar
- Window#set_scroll_page
- Window#set_scroll_pos
- Window#set_scroll_range
- Window#set_size
- Window#set_size_hints
- Window#set_sizer
- Window#set_sizer_and_fit
- Window#set_theme_enabled
- Window#set_tool_tip
- Window#set_validator
- Window#set_virtual_size
- Window#set_virtual_size_hints
- Window#set_window_style
- Window#set_window_style_flag
- Window#set_window_variant
- Window#should_inherit_colours
- Window#show
- Window#thaw
- Window#toggle_window_style
- Window#unregister_hot_key
- Window#update
- Window#update_window_ui
- Window#validate
- Window#warp_pointer

### Window.new

Window.new(%(arg-type)Window% parent, Integer id, Point pos = DEFAULT_POSITION, Size size = DEFAULT_SIZE, Integer style = 0, String name = "") { … }

Constructs a window, which can be a child of a frame, dialog or any
other non-control window. All Windows apart from
top-level main windows must have another window as parent – this
argument cannot be `nil`.

Any constructor for a Window can be passed a block to do further set-up
of the Window. If no argument is specifid for the block, it will be run
in the context of the newly created instance, with the Window as `self`.
If an explicit parameter is passeed, the new Window will be passed as that
argument to this block. ie, either of the following is allowed:

Wx::Button.new(…) do self.label = ‘Foo’ end

or

Wx::Button.new(…) do | button | button.label = ‘Foo’ end

#### Parameters

- parent Pointer to a parent window.
- id Window identifier. If ID_ANY, will automatically create an identifier.
- pos Window position. DefaultPosition indicates that Widgets
  should generate a default position for the window. If using the Window class directly, supply
  an actual position.
- size Window size. DefaultSize indicates that Widgets
  should generate a default size for the window. If no suitable size can be found, the
  window will be sized to 20×20 pixels so that the window is visible but obviously not
  correctly sized.
- style Window style. For generic window styles, please see Window.
- name Window name.

#### See also

Window deletion overview, Window#destroy, CloseEvent

### Window.find_focus

Window find_focus()

Finds the window or control which currently has the keyboard focus.

#### Remarks

Note that this is a class method, so it can be called without needing a
Window receiver.

#### See also

Window#set_focus

### Window#add_child

add_child(%(arg-type)Window% child)

Adds a child window. 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 Widgets and shouldn’t be
called by the user code.

#### Parameters

- child Child window to add.

### Window#bring_to_front

bring_to_front()

Raises the window to the top of the window hierarchy (z-order). In the
current version of wxRuby this works both for managed windows (Frames)
and child windows, although it is most often useful for Frames.

#### See also

lower

### Window#cache_best_size

cache_best_size(%(arg-type)Size% size)

Sets the cached best size value.

### Window#capture_mouse

capture_mouse()

Directs all mouse input to this window. Call Window#release_mouse to
release the capture.

Note that Widgets 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 MouseCaptureLostEvent event.

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

#### See also

Window#release_mouse
MouseCaptureLostEvent

### Window#center

center(%(arg-type)Integer% direction)

A synonym for Centre.

### Window#center_on_parent

center_on_parent(%(arg-type)Integer% direction)

A synonym for centre_on_parent.

### Window#centre

centre(%(arg-type)Integer% direction = BOTH)

Centres the window.

#### Parameters

- direction Specifies the direction for the centering. May be `HORIZONTAL`, `VERTICAL` or `BOTH`. It may also include `CENTRE_ON_SCREEN` flag
  if you want to center the window on the entire screen and not on its
  parent window.

The flag `CENTRE_FRAME` is obsolete and should not be used any longer
(it has no effect).

#### Remarks

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

#### See also

Window#center

### Window#centre_on_parent

centre_on_parent(%(arg-type)Integer% direction = BOTH)

Centres the window on its parent. This is a more readable synonym for
Centre.

#### Parameters

- direction Specifies the direction for the centering. May be `HORIZONTAL`, `VERTICAL` or `BOTH`.

#### Remarks

This methods provides for a way to center 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
Window#centre.

#### See also

Window#centre_on_screen

### Window#clear_background

clear_background()

Clears the window by filling it with the current background colour. Does not
cause an erase background event to be generated.

### Window#client_to_screen

x, y = client_to_screen(%(arg-type)Integer% x, Integer y) Point = client_to_screen(%(arg-type)Point% pt)

Converts to screen coordinates from coordinates relative to this
window. The method may be passed either two integers, representing the
x and y coordinates, or a single Point object. If a
Point is passed in, one will be returned; if two integers are passed in,
two co-ordinates will be returned.

### Window#close

Boolean close(%(arg-type)Boolean% force = `false`)

This function simply generates a CloseEvent 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.

#### 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 (Frame and Dialog
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 CloseEvent#can_veto, in which case it
should destroy the window using Window#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 Dialog::OnCloseWindow does not necessarily delete the
dialog, since it will simply simulate an ID_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
Window#destroy instead

#### See also

Window deletion overview, Window#destroy, CloseEvent

### Window#convert_dialog_to_pixels

Point convert_dialog_to_pixels(%(arg-type)Point% pt) Size convert_dialog_to_pixels(%(arg-type)Size% sz)

Converts a point or size from dialog units to pixels.

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.

#### See also

Window#convert_pixels_to_dialog

### Window#convert_pixels_to_dialog

Point convert_pixels_to_dialog(%(arg-type)Point% pt) Size convert_pixels_to_dialog(%(arg-type)Size% sz)

Converts a point or size from pixels to dialog units.

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.

#### See also

Window#convert_dialog_to_pixels

### Window#destroy

Boolean destroy()

Destroys the window. 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.

Note that it is unusual for wxRuby code to need to explicitly call this
method; normally, windows are automatically destroyed when their
containing Frame or Dialog is closed.

Two circumstances where it can be important to call destroy are firstly,
if a window is detached from a Sizer and replaced with
another window. In this case destroy will immediately dispose of the
detached window. Secondly, if a dialog is created with no
parent argument, it can be necessary to call destroy when the dialog is
finished to signal that the dialog will not be re-used.

#### Return value

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

### Window#destroy_children

destroy_children()

Destroys all children of a window. Called automatically by the destructor.

### Window#disable

Boolean disable()

Disables the window, same as enable.

#### Return value

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

### Window#do_get_best_size

Size do_get_best_size()

Gets the size which best suits the window: for a control, it would be
the minimal size which doesn’t truncate the control, for a panel – the
same size as it would have after a call to fit.

### Window#do_update_window_ui

do_update_window_ui(%(arg-type)UpdateUIEvent% event)

Does the window-specific updating after processing the update event.
This function is called by
Window#update_window_ui in order to
check return values in the UpdateUIEvent and act
appropriately. For example, to allow frame and dialog title updating,
Widgets implements this function as follows:

// do the window-specific processing after processing the update event void TopLevelWindowBase::DoUpdateWindowUI(UpdateUIEvent& event) { if ( event.GetSetEnabled() ) Enable(event.GetEnabled()); if ( event.GetSetText() ) { if ( event.GetText() != GetTitle() ) SetTitle(event.GetText()); } }

### Window#enable

Boolean enable(%(arg-type)Boolean% enable = `true`)

Enable or disable the window for user input. Note that when a parent window is
disabled, all of its children are disabled as well and they are reenabled again
when the parent is.

#### Parameters

- enable If `true`, enables the window for input. If `false`, disables the window.

#### Return value

Returns `true` if the window has been enabled or disabled, `false` if
nothing was done, i.e. if the window had already been in the specified state.

#### See also

Window#is_enabled, Window#disable, RadioBox#enable

### Window#find_window

Window find_window(%(arg-type)Integer% id)

Find a child of this window, by identifier.

Window find_window(%(arg-type)String% name)

Find a child of this window, by name.

### Window#find_window_by_id

Window find_window_by_id(%(arg-type)Integer% id, Window parent = nil)

Find the first window with the given id.

If parent is `nil`, the search will start from all top-level frames
and dialog boxes; otherwise, the search will be limited to the given
window hierarchy. The search is recursive in both cases.

#### See also

find_window

### Window#find_window_by_name

Window find_window_by_name(%(arg-type)String% name, Window parent = nil)

Find a window by its name (as given in a window constructor or create
function call). If parent is `nil`, the search will start from all
top-level frames and dialog boxes; otherwise, the search will be limited
to the given window hierarchy. The search is recursive in both cases.

If no window with such name is found,
find_window_by_label is called.

#### See also

find_window

### Window#find_window_by_label

Window find_window_by_label(%(arg-type)String% label, Window parent = nil)

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

#### See also

find_window

### Window#fit

fit()

Sizes the window so that it fits around its subwindows. This function
won’t do anything if there are no subwindows and will only really work
correctly if the sizers are used for the subwindows layout. Also, if the
window has exactly one subwindow it is better (faster and the result is
more precise as fit adds some margin to account for
fuzziness of its calculations) to call

window.client_size = child.size

instead of calling Fit.

### Window#fit_inside

fit_inside()

Similar to fit, but sizes the interior (virtual) size
of a window. 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.

### Window#freeze

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 re-enable window redrawing. Calls to these two functions may be
nested.

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 TextCtrl under GTK) but is not implemented on all platforms nor for all
controls so it is mostly just a hint to Widgets and not a mandatory
directive.

#### See also

WindowUpdateLocker

### Window#get_accelerator_table

AcceleratorTable get_accelerator_table()

Gets the accelerator table for this window. See AcceleratorTable.

### Window#get_accessible

Accessible get_accessible()

Returns the accessible object for this window, if any.

See also Accessible.

### Window#get_background_colour

Colour get_background_colour()

Returns the background colour of the window.

#### See also

Window#set_background_colour, Window#set_foreground_colour, Window#get_foreground_colour

### Window#get_background_style

BackgroundStyle get_background_style()

Returns the background style of the window. The background style indicates
whether background colour should be determined by the system (BG_STYLE_SYSTEM),
be set to a specific colour (BG_STYLE_COLOUR), or should be left to the
application to implement (BG_STYLE_CUSTOM).

On GTK+, use of BG_STYLE_CUSTOM allows the flicker-free drawing of a custom
background, such as a tiled bitmap. Currently the style has no effect on other platforms.

#### See also

Window#set_background_colour, Window#get_foreground_colour, Window#set_background_style

### Window#get_effective_min_size

Size get_effective_min_size()

Merges the window’s best size into the min size and returns the
result. This is the value used by sizers to determine the appropriate
ammount of sapce to allocate for the widget.

#### See also

Window#get_best_size, Window#set_initial_size

### Window#get_best_size

Size get_best_size()

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
Panel), the size returned by this function will be the
same as the size the window would have had after calling
Fit.

### Window#get_capture

Window get_capture()

Returns the currently captured window.

#### See also

Window#has_capture,
Window#capture_mouse,
Window#release_mouse,
MouseCaptureLostEvent
MouseCaptureChangedEvent

### Window#get_caret

Caret get_caret()

Returns the caret associated with the window.

### Window#get_char_height

Integer get_char_height()

Returns the character height for this window.

### Window#get_char_width

Integer get_char_width()

Returns the average character width for this window.

### Window#get_children

List get_children()

Returns a reference to the list of the window’s children.

### Window#get_class_default_attributes

VisualAttributes get_class_default_attributes(%(arg-type)WindowVariant% variant = `WINDOW_VARIANT_NORMAL`)

Returns the default font and colours which are used by the control. 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 Window#set_window_variant
for more about this.

This static method is ’’overridden’’ in many derived classes and so calling,
for example, Button#get_class_default_attributes will typically
return the values appropriate for a button which will be normally different
from those returned by, say, ListCtrl#get_class_default_attributes.

The `VisualAttributes` 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.

#### See also

inherit_attributes

### Window#get_client_size

get_client_size(%(arg-type)Integer% width, Integer height) Size get_client_size()

This gets the size of the window ‘client area’ in pixels.
The client area is the area which may be drawn on by the programmer,
excluding title bar, border, scrollbars, etc.

#### Parameters

- width Receives the client width in pixels.
- height Receives the client height in pixels.

#### See also

get_size, get_virtual_size

### Window#get_client_rect

Rect get_client_rect()

Returns the client area position and size as a Rect
object. The client area is the window space available for drawing -
i.e. its whole size minus window decorations like scrollbars, title bars
and so on.

#### See also

get_client_size

### Window#get_constraints

LayoutConstraints get_constraints()

Returns a pointer to the window’s layout constraints, or `nil` if there are none.

### Window#get_containing_sizer

Sizer get_containing_sizer()

Return the sizer that this window is a member of, if any, otherwise
`nil`.

### Window#get_cursor

Cursor get_cursor()

Return the cursor associated with this window.

#### See also

Window#set_cursor

### Window#get_default_attributes

VisualAttributes get_default_attributes()

Currently this is the same as calling
get_class_default_attributes (get_window_variant).

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.

### Window#get_drop_target

DropTarget get_drop_target()

Returns the associated drop target, which may be `nil`.

#### See also

Window#set_drop_target,
Drag and drop overview

### Window#get_effective_best_size

Size get_effective_best_size()

Merges the window’s best size into the min size and returns the
result. This is the value used by sizers to determine the appropriate
ammount of sapce to allocate for the widget.

#### See also

Window#get_best_size, Window#set_initial_size

### Window#get_event_handler

EvtHandler get_event_handler()

Returns the event handler for this window. By default, the window is its
own event handler.

#### See also

Window#set_event_handler, Window#push_event_handler, Window#pop_event_handler, EvtHandler#process_event, EvtHandler

### Window#get_extra_style

Integer get_extra_style()

Returns the extra style bits for the window.

### Window#get_font

Font get_font()

Returns the font for this window.

#### See also

Window#set_font

### Window#get_foreground_colour

Colour get_foreground_colour()

Returns the foreground colour of the window.

#### Remarks

The interpretation of foreground colour is open to interpretation according
to the window class; it may be the text colour or other colour, or it may not
be used at all.

#### See also

Window#set_foreground_colour, Window#set_background_colour, Window#get_background_colour

### Window#get_grand_parent

Window get_grand_parent()

Returns the grandparent of a window, or `nil` if there isn’t one.

### Window#get_handle

Integer get_handle()

Returns the platform-specific handle of the physical window. This is a
platform-specific Integer, which may be used to make native API calls,
eg via Ruby’s Win32API library. It will correspond to a HWND for
Windows, Widget for Motif, GtkWidget for GTK or WinHandle for
PalmOS.

### Window#get_help_text_at_point

String get_help_text_at_point(%(arg-type)Point% point, HelpEvent::Origin origin)

Gets the help text to be used as context-sensitive help for this window. This
method should be overridden if the help message depends on the position inside
the window, otherwise get_help_text can be used.

#### Parameters

- point Coordinates of the mouse at the moment of help event emission.
- origin Help event origin, see also HelpEvent#get_origin.

2.7.0

### Window#get_help_text

String get_help_text()

Gets the help text to be used as context-sensitive help for this window.

Note that the text is actually stored by the current HelpProvider implementation,
and not in the window object itself.

#### See also

set_help_text, get_help_text_at_point, HelpProvider

### Window#get_id

Integer get_id()

Returns the identifier of the window.

#### Remarks

Each window has an integer identifier. If the application has not provided one
(or the default ID_ANY) an unique identifier with a negative value will be generated.

#### See also

Window#set_id, Window identifiers

### Window#get_label

String get_label()

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.

### Window#get_max_size

Size get_max_size()

Returns the maximum size of the window, an indication to the sizer layout mechanism
that this is the maximum possible size.

### Window#get_min_size

Size get_min_size()

Returns the minimum size of the window, an indication to the sizer layout mechanism
that this is the minimum required size. It normally just returns the value set
by set_min_size, but it can be overridden to do the
calculation on demand.

### Window#get_name

String get_name()

Returns the window’s name.

#### Remarks

This name is not guaranteed to be unique; it is up to the programmer to supply an appropriate
name in the window constructor or via Window#set_name.

#### See also

Window#set_name

### Window#get_parent

Window get_parent()

Returns the parent of the window, or `nil` if there is no parent.

### Window#get_position

get_position(%(arg-type)Integer% x, Integer y) Point get_position()

This gets the position of the window in pixels, relative to the parent window
for the child windows or relative to the display origin for the top level
windows.

#### Parameters

- x Receives the x position of the window if non-.
- y Receives the y position of the window if non-.

#### See also

get_screen_position

### Window#get_rect

Rect get_rect()

Returns the size and position of the window as a Rect object.

#### See also

get_screen_rect

### Window#get_screen_position

get_screen_position(%(arg-type)Integer% x, Integer y) Point get_screen_position()

Returns the window position in screen coordinates, whether the window is a
child window or a top level one.

#### Parameters

- x Receives the x position of the window on the screen if non-.
- y Receives the y position of the window on the screen if non-.

#### See also

get_position

### Window#get_screen_rect

Rect get_screen_rect()

Returns the size and position of the window on the screen as a
Rect object.

#### See also

get_rect

### Window#get_scroll_pos

Integer get_scroll_pos(%(arg-type)Integer% orientation)

Returns the built-in scrollbar position.

#### See also

See Window#set_scrollbar

### Window#get_scroll_range

Integer get_scroll_range(%(arg-type)Integer% orientation)

Returns the built-in scrollbar range.

#### See also

Window#set_scrollbar

### Window#get_scroll_thumb

Integer get_scroll_thumb(%(arg-type)Integer% orientation)

Returns the built-in scrollbar thumb size.

#### See also

Window#set_scrollbar

### Window#get_size

get_size(%(arg-type)Integer% width, Integer height) Size get_size()

This gets the size of the entire window in pixels,
including title bar, border, scrollbars, etc.

#### Parameters

- width Receives the window width.
- height Receives the window height.

#### See also

get_client_size, get_virtual_size

### Window#get_sizer

Sizer get_sizer()

Return the sizer associated with the window by a previous call to
set_sizer or `nil`.

### Window#get_text_extent

Integer x, Integer y, Integer descent, Integer external_leading = get_text_extent(%(arg-type)String% string, Font font = nil, Boolean use16 = `false`)

Gets the dimensions of the string as it would be drawn on the
window with the currently selected font. The dimensions are returned as
a four-element array.

The first two elements are the width and height, in pixels, of the
string. The third and fourth values are the descent and external
leading – which are not normally needed.

The `font` parameter may optionally be passed to specify the font and
size for which the dimensions of the string will be calculated. If this
parameter is not passed, the current window font is used.

#### Parameters

- string String whose extent is to be measured.
- font Font to use instead of the current window font (optional).
- use16 If `true`, string contains 16-bit characters. The default is `false`.

### Window#get_tool_tip

ToolTip get_tool_tip()

Get the associated tooltip or `nil` if none.

### Window#get_update_region

Region get_update_region()

Returns the region specifying which parts of the window have been damaged. Should
only be called within an PaintEvent handler.

#### See also

Region, RegionIterator

### Window#get_validator

Validator get_validator()

Returns a pointer to the current validator for the window, or `nil` if there is none.

### Window#get_virtual_size

get_virtual_size(%(arg-type)Integer% width, Integer height) Size get_virtual_size()

This gets the virtual size of the window in pixels. By default it
returns the client size of the window, but after a call to
set_virtual_size it will return
that size.

#### Parameters

- width Receives the window virtual width.
- height Receives the window virtual height.

get_size, get_client_size

### Window#get_window_border_size

Size get_window_border_size()

Returns the size of the left/right and top/bottom borders of this window in x
and y components of the result respectively.

### Window#get_window_style_flag

Integer get_window_style_flag()

Gets the window style that was passed to the constructor or Create
method. GetWindowStyle() is another name for the same function.

### Window#get_window_variant

WindowVariant get_window_variant()

Returns the value previously passed to
Window#set_window_variant.

### Window#has_capture

Boolean has_capture()

Returns `true` if this window has the current mouse capture.

#### See also

Window#capture_mouse,
Window#release_mouse,
MouseCaptureLostEvent
MouseCaptureChangedEvent

### Window#has_flag

Boolean has_flag(%(arg-type)Integer% flag)

Returns `true` if the window has the given flag bit set.

### Window#has_multiple_pages

Boolean has_multiple_pages()

This method should be overridden to return `true` if this window has
multiple pages. All standard class with multiple pages such as
Notebook, Listbook and
Treebook already override it to return `true`
and user-defined classes with similar behaviour should do it as well to allow
the library to handle such windows appropriately.

### Window#has_scrollbar

Boolean has_scrollbar(%(arg-type)Integer% orient)

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

#### Parameters

- orient Orientation to check, either `HORIZONTAL` or `VERTICAL`.

### Window#has_transparent_background

Boolean has_transparent_background()

Returns if this window background is transparent (as, for example, for
StaticText) 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
Window-derived class to ensure that background is painted correctly.

### Window#hide

Boolean hide()

Equivalent to calling show (`false`).

### Window#inherit_attributes

inherit_attributes()

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 default attributes. However
if some of the parents attributes are explicitly (that is, using
set_font and not
set_own_font) 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 should_inherit_colours
to return , 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.

### Window#init_dialog

init_dialog()

Sends an `EVT_INIT_DIALOG` event.

### Window#invalidate_best_size

invalidate_best_size()

Resets the cached best size value so it will be recalculated the next time it is needed.

### Window#is_double_buffered

Boolean is_double_buffered()

Returns 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.

#### See also

BufferedDC

### Window#is_enabled

Boolean is_enabled()

Returns `true` if the window is enabled for input, `false` otherwise.

#### See also

Window#enable

### Window#is_exposed

Boolean is_exposed(%(arg-type)Integer% x, Integer y) Boolean is_exposed(%(arg-type)Point% &pt) Boolean is_exposed(%(arg-type)Integer% x, Integer y, Integer w, Integer h) Boolean is_exposed(%(arg-type)Rect% &rect)

Returns `true` if the given point or rectangle area has been exposed since the
last repaint. Call this in an paint event handler to optimize redrawing by
only redrawing those areas, which have been exposed.

### Window#is_frozen

Boolean is_frozen()

Returns if the window is currently frozen by a call to
Freeze.

#### See also

Thaw

### Window#is_retained

Boolean is_retained()

Returns `true` if the window is retained, `false` otherwise.

#### Remarks

Retained windows are only available on X platforms.

### Window#is_shown

Boolean is_shown()

Returns `true` if the window is shown, `false` if it has been hidden.

#### See also

Window#is_shown_on_screen

### Window#is_shown_on_screen

Boolean is_shown_on_screen()

Returns `true` if the window is physically visible on the screen, i.e. it
is shown and all its parents up to the toplevel window are shown as well.

#### See also

Window#is_shown

### Window#is_top_level

Boolean is_top_level()

Returns `true` if the given window is a top-level one. Currently all frames and
dialogs are considered to be top-level windows (even if they have a parent
window).

### Window#layout

layout()

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

See Window#set_auto_layout: when auto
layout is on, this function gets called automatically when the window is resized.

### Window#line_down

This is just a wrapper for scroll_lines (1).

### Window#line_up

This is just a wrapper for scroll_lines (-1).

### Window#lower

lower()

Lowers the window to the bottom of the window hierarchy (z-order). A
deprecated alias for send_to_back.

#### See also

raise

### Window#make_modal

make_modal(%(arg-type)Boolean% flag)

Disables all other windows in the application so that
the user can only interact with this window.

#### Parameters

- flag If `true`, this call disables all other windows in the application so that
  the user can only interact with this window. If `false`, the effect is reversed.

### Window#move

move(%(arg-type)Integer% x, Integer y) move(%(arg-type)Point% pt)

Moves the window to the given position.

#### Parameters

- x Required x position.
- y Required y position.
- pt Point object representing the position.

#### Remarks

Implementations of set_size can also implicitly implement the
Window::move function, which is defined in the base Window class
as the call:

set_size(x, y, -1, -1, SIZE_USE_EXISTING)

#### See also

Window#set_size

### Window#move_after_in_tab_order

move_after_in_tab_order(%(arg-type)Window% win)

Moves this window in the tab navigation order after the specified win.
This means that when the user presses `TAB` key on that other window,
the focus switches to this window.

Default tab order is the same as creation order, this function and
move_before_in_tab_order allow to change
it after creating all the windows.

#### Parameters

- win A sibling of this window which should precede it in tab order,
  must not be nil.

### Window#move_before_in_tab_order

move_before_in_tab_order(%(arg-type)Window% win)

Same as move_after_in_tab_order except that
it inserts this window just before win instead of putting it right after
it.

### Window#navigate

Boolean navigate(%(arg-type)Integer% flags = NavigationKeyEvent::IsForward)

Does keyboard navigation from this window to another, by sending
a NavigationKeyEvent.

#### Parameters

- flags A combination of NavigationKeyEvent::IsForward and NavigationKeyEvent::WinChange.

#### 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 TE_PROCESS_TAB style is to insert a tab
and not navigate to the next control.

### Window#on_internal_idle

on_internal_idle()

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 Window#update_window_ui
in order to send update events to the window in idle time.

### Window#page_down

This is just a convenience wrapper for
scroll_pages . It scrolls the window down one page

### Window#page_up

This is just a convenience wrapper for
scroll_pages . It scrolls the window up one page.

### Window#paint

paint { | device_context | … }

Run code to draws lines, shapes and bitmaps onto the Window. The block
should receive a DC (device context) object which can then be
used to do the actual drawing. See the DC documentation for
valid drawing methods.

The preferred usage of this method is within an `evt_paint` handler,
which is called whenever any part of the Window needs to be redrawn. In
this case, the block will receive a PaintDC object. If
`paint` is called outside a paint event handler, it will receive a
ClientDC object. These two classes support identical methods.

This is the correct way in wxRuby to draw directly upon, for example,
Panels. You should not attempt to instantiate a PaintDC or ClientDC
directly. This will raise an exception, as doing so can cause serious
errors on some platforms.

Note also that it is not possible to draw directly upon some core
controls, such as Wx::Button. Whilst this may work on some
platforms, it is not portable.

If the drawing block contains many separate drawing commands, using
paint_buffered may reduce flicker on some
platforms, in particular Windows.

### Window#paint_buffered

paint_buffered(buffer = nil) { | device_context | … }

Enables flicker-free drawing. All drawing commands are carried out on
an off-screen buffer, then copied en-masse to the on-screen Window when
the drawing is finished. The method otherwise works identically to
paint.

The method may be passed an existing bitmap as the buffer
to carry out drawing on, otherwise one will be created as required. It
may be more efficient to re-use an existing buffer for frequently
updated drawings.

Note that some platforms such as OS X and GTK support double-buffering
natively, and in this case no special buffer will be created.

### Window#pop_event_handler

EvtHandler pop_event_handler(%(arg-type)Boolean% deleteHandler = `false`)

Removes and returns the top-most event handler on the event handler stack.

#### Parameters

- deleteHandler If this is `true`, the handler will be deleted after it is removed. The
  default value is `false`.

#### See also

Window#set_event_handler, Window#get_event_handler, Window#push_event_handler, EvtHandler#process_event, EvtHandler

### Window#popup_menu

Boolean popup_menu(%(arg-type)Menu% menu, Point pos = DEFAULT_POSITION) Boolean popup_menu(%(arg-type)Menu% menu, Integer x, Integer y)

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 usually. If the coordinates are not specified, current mouse
cursor position is used.

#### Parameters

- menu Menu to pop up.
- pos The position where the menu will appear.
- x Required x position for the menu to appear.
- y Required y position for the menu to appear.

#### See also

Menu

#### Remarks

Just before the menu is popped up, Menu#update_ui
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, GTK) can do
a better job of positioning the menu in that case.

### Window#push_event_handler

push_event_handler(%(arg-type)EvtHandler% handler)

Pushes this event handler onto the event stack for the window.

#### Parameters

- handler Specifies the handler to be pushed.

#### Remarks

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.

Window#push_event_handler allows
an application to set up a chain of event handlers, where an event not handled by one event handler is
handed to the next one in the chain. Use Window#pop_event_handler to
remove the event handler.

#### See also

Window#set_event_handler, Window#get_event_handler, Window#pop_event_handler, EvtHandler#process_event, EvtHandler

### Window#raise

raise()

Raises the window to the top of the window hierarchy (z-order).

This is a deprecated alias for bring_to_front, as
the method name “raise” conflicts with Ruby’s core method for raising an
exception. It’s recommended to use “bring_to_front” in new code.

#### See also

lower, send_to_back

### Window#refresh

refresh(%(arg-type)Boolean% eraseBackground = `true`, Rect rect = nil)

Causes this window, and all of its children recursively (except under GTK1
where this is not implemented), to be repainted. Note that repainting doesn’t
happen immediately but only during the next event loop iteration, if you need
to update the window immediately you should use update
instead.

#### Parameters

- eraseBackground If `true`, the background will be
  erased.
- rect If non-nil, only the given rectangle will
  be treated as damaged.

#### See also

Window#refresh_rect

### Window#refresh_rect

refresh_rect(%(arg-type)Rect% rect, Boolean eraseBackground = `true`)

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 Rect object as argument like this
`refresh_rect(Rect(x, y, w, h))`.

### Window#register_hot_key

Boolean register_hot_key(%(arg-type)Integer% hotkeyId, Integer modifiers, Integer virtualKeyCode)

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 `MOD_SHIFT`, `MOD_CONTROL`, `MOD_ALT`
  or `MOD_WIN` specifying the modifier keys that have to be pressed along with the key.
- virtualKeyCode The virtual key code of the hotkey.

#### Return value

`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 Windows. It is used
in the Windows CE port for detecting hardware button presses.

#### See also

Window#unregister_hot_key

### Window#release_mouse

release_mouse()

Releases mouse input captured with Window#capture_mouse.

#### See also

Window#capture_mouse,
Window#has_capture,
Window#release_mouse,
MouseCaptureLostEvent
MouseCaptureChangedEvent

### Window#remove_child

remove_child(%(arg-type)Window% child)

Removes a child window. 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 Widgets and shouldn’t be
called by the user code.

#### Parameters

- child Child window to remove.

### Window#remove_event_handler

Boolean remove_event_handler(%(arg-type)EvtHandler% handler)

Find the given handler in the windows event handler chain and remove (but
not delete) it from it.

#### Parameters

- handler The event handler to remove, must be non `nil` and
  must be present in this windows event handlers chain

#### Return value

Returns `true` if it was found and `false` otherwise (this also results
in an assert failure so this function should only be called when the
handler is supposed to be there).

#### See also

push_event_handler, pop_event_handler

### Window#reparent

Boolean reparent(%(arg-type)Window% newParent)

Reparents the window, i.e the window will be removed from its
current parent window (e.g. a non-standard toolbar in a Frame)
and then re-inserted into another.

#### Parameters

- newParent New parent.

### Window#screen_to_client

x, y screen_to_client(%(arg-type)Integer% x, Integer y) Point screen_to_client(%(arg-type)Point% pt)

Converts from screen to client window coordinates. The method may be
passed either two integers, representing the x and y coordinates,
or a single Point object. If a Point is passed in, one
will be returned; if two integers are passed in, two co-ordinates will
be returned.

### Window#scroll_lines

Boolean scroll_lines(%(arg-type)Integer% lines)

Scrolls the window by the given number of lines down (if lines is
positive) or up.

#### Return value

Returns `true` if the window was scrolled, `false` if it was already
on top/bottom and nothing was done.

#### Remarks

This function is currently only implemented under MSW and TextCtrl under
GTK (it also works for ScrolledWindow derived classes under all
platforms).

#### See also

scroll_pages

### Window#scroll_pages

Boolean scroll_pages(%(arg-type)Integer% pages)

Scrolls the window by the given number of pages down (if pages is
positive) or up.

#### Return value

Returns `true` if the window was scrolled, `false` if it was already
on top/bottom and nothing was done.

#### Remarks

This function is currently only implemented under MSW and GTK.

#### See also

scroll_lines

### Window#scroll_window

scroll_window(%(arg-type)Integer% dx, Integer dy, Rect rect = nil)

Physically scrolls the pixels in the window and move child windows accordingly.

#### Parameters

- dx Amount to scroll horizontally.
- dy Amount to scroll vertically.
- rect Rectangle to scroll, if it is , the whole window is
  scrolled (this is always the case under GTK which doesn’t support this
  parameter)

#### Remarks

Note that you can often use ScrolledWindow
instead of using this function directly.

### Window#send_to_back

send_to_back()

Lowers the window – most often, a Frame – to the bottom of the window
hierarchy (z-order).

### Window#set_accelerator_table

set_accelerator_table(%(arg-type)AcceleratorTable% accel)

Sets the accelerator table for this window. See AcceleratorTable.

### Window#set_accessible

set_accessible(%(arg-type)Accessible% accessible)

Sets the accessible for this window. Any existing accessible for this window
will be deleted first, if not identical to accessible.

See also Accessible.

### Window#set_auto_layout

set_auto_layout(%(arg-type)Boolean% autoLayout)

Determines whether the Window#layout function will
be called automatically when the window is resized. Please note that this only
happens for the windows usually used to contain children, namely
Panel and TopLevelWindow
(and the classes deriving from them).

This method is called implicitly by
Window#set_sizer but if you use
Window#set_constraints you should call it
manually or otherwise the window layout won’t be correctly updated when its
size changes.

#### Parameters

- autoLayout Set this to if you wish the Layout function to be
  called automatically when the window is resized.

#### See also

Window#set_constraints

### Window#set_background_colour

Boolean set_background_colour(%(arg-type)Colour% colour)

Sets the background colour of the window.

Please see inherit_attributes for
explanation of the difference between this method and
set_own_background_colour.

#### Parameters

- colour The colour to be used as the background colour, pass
  `NullColour` to reset to the default colour.

#### Remarks

The background colour is usually painted by the default EraseEvent 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 Window#clear_background or Window#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.

#### See also

Window#get_background_colour, Window#set_foreground_colour, Window#get_foreground_colour, Window#clear_background, Window#refresh, EraseEvent

### Window#set_background_style

set_background_style(%(arg-type)BackgroundStyle% style)

Sets the background style of the window. The background style indicates
whether background colour should be determined by the system (BG_STYLE_SYSTEM),
be set to a specific colour (BG_STYLE_COLOUR), or should be left to the
application to implement (BG_STYLE_CUSTOM).

On GTK+, use of BG_STYLE_CUSTOM allows the flicker-free drawing of a custom
background, such as a tiled bitmap. Currently the style has no effect on other platforms.

#### See also

Window#set_background_colour, Window#get_foreground_colour, Window#get_background_style

### Window#set_initial_size

set_initial_size(%(arg-type)Size% size = DEFAULT_SIZE)

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.)

#### See also

Window#set_size, Window#get_best_size, Window#get_effective_min_size

### Window#set_caret

set_caret(%(arg-type)Caret% caret)

Sets the caret associated with the window.

### Window#set_client_size

set_client_size(%(arg-type)Integer% width, Integer height) set_client_size(%(arg-type)Size% size)

This sets the size of the window client area in pixels. Using this function to size a window
tends to be more device-independent than Window#set_size, 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.

#### Parameters

- width The required client area width.
- height The required client area height.
- size The required client size.

### Window#set_containing_sizer

set_containing_sizer(%(arg-type)Sizer% sizer)

This normally does not need to be called by user code. It is called
when a window is added to a sizer, and is used so the window can
remove itself from the sizer when it is destroyed.

### Window#set_cursor

set_cursor(%(arg-type)Cursor% cursor)

Sets the window’s cursor. Notice that the window cursor also sets it for the
children of the window implicitly.

The cursor may be `NullCursor` in which case the window cursor will
be reset back to default.

#### Parameters

- cursor Specifies the cursor that the window should normally display.

#### See also

::SetCursor, Cursor

### Window#set_dimensions

set_size(%(arg-type)Integer% x, Integer y, Integer width, Integer height, Integer sizeFlags = SIZE_AUTO)

Specifies the size and position of the window, in pixel units.

#### Parameters

- x Required x position in pixels, or -1 to indicate that the existing
  value should be used.
- y Required y position in pixels, or -1 to indicate that the existing
  value should be used.
- width Required width in pixels, or -1 to indicate that the existing
  value should be used.
- height Required height position in pixels, or -1 to indicate that the existing
  value should be used.
- sizeFlags Indicates the interpretation of other parameters. It is a bit list of the following:

SIZE_AUTO_WIDTH: a -1 width value is taken to indicate
a wxRuby-supplied default width.

SIZE_AUTO_HEIGHT: a -1 height value is taken to indicate
a wxRuby-supplied default width.

SIZE_AUTO: -1 size values are taken to indicate
a wxRuby-supplied default size.

SIZE_USE_EXISTING: existing dimensions should be used
if -1 values are supplied.

SIZE_ALLOW_MINUS_ONE: allow dimensions of -1 and less to be interpreted
as real dimensions, not default values.

SIZE_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)

#### See also

set_size

### Window#set_containing_sizer

set_containing_sizer(%(arg-type)Sizer% sizer)

This normally does not need to be called by user code. It is called
when a window is added to a sizer, and is used so the window can
remove itself from the sizer when it is destroyed.

### Window#set_cursor

set_cursor(%(arg-type)Cursor% cursor)

Sets the window’s cursor. Notice that the window cursor also sets it for the
children of the window implicitly.

The cursor may be `NullCursor` in which case the window cursor will
be reset back to default.

#### Parameters

- cursor Specifies the cursor that the window should normally display.

#### See also

::SetCursor, Cursor

### Window#set_drop_target

set_drop_target(%(arg-type)DropTarget% target)

Associates a drop target with this window.

If the window already has a drop target, it is deleted.

#### See also

Window#get_drop_target,

### Window#set_initial_best_size

set_initial_best_size(%(arg-type)Size% size)

Sets the initial window size if none is given (i.e. at least one of the
components of the size passed to ctor/Create() is DefaultCoord).

### Window#set_event_handler

set_event_handler(%(arg-type)EvtHandler% handler)

Sets the event handler for this window.

#### Parameters

- handler Specifies the handler to be set.

#### Remarks

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.

It is usually better to use Window#push_event_handler since
this sets up a chain of event handlers, where an event not handled by one event handler is
handed to the next one in the chain.

#### See also

Window#get_event_handler, Window#push_event_handler, Window#pop_event_handler, EvtHandler#process_event, EvtHandler

### Window#set_extra_style

set_extra_style(%(arg-type)Integer% exStyle)

Sets the extra style bits for the window. The currently defined extra style
bits are:

`WS_EX_BLOCK_EVENTS` | Normally, the commandevents are propagated upwards to the window parent recursively until a handlerfor them is found. Using this style allows to prevent them from beingpropagated beyond this window. Notice that Dialog has this style on bydefault for the reasons explained in the"event processing overview":eventprocessing.html.
`WS_EX_TRANSIENT` | This can be used to prevent awindow from being used as an implicit parent for the dialogs which werecreated without a parent. It is useful for the windows which can disappear atany moment as creating children of such windows results in fatal problems.

`FRAME_EX_CONTEXTHELP`

Under Windows, puts a query button on the caption. When pressed, Windows will go into a context-sensitive help mode and Widgets will send a EVT_HELP event if the user clicked on an application window. This style cannot be used together with `MAXIMIZE_BOX` or `MINIMIZE_BOX`, soyou should use the style of `DEFAULT_FRAME_STYLE` & (`MINIMIZE_BOX` | `MAXIMIZE_BOX`) for the frames having this style (the dialogs don’t have minimize nor maximize box bydefault)

`WS_EX_PROCESS_IDLE` | This window should always process idle events, evenif the mode set by IdleEvent#set_mode is `IDLE_PROCESS_SPECIFIED`.
`WS_EX_PROCESS_UI_UPDATES` | This window should always process UI update events,even if the mode set by UpdateUIEvent#set_mode is `UPDATE_UI_PROCESS_SPECIFIED`.

### Window#set_focus

set_focus()

This sets the window to receive keyboard input.

Note that on some platforms, the focus cannot be set until the Window is
visible. Therefore, ensure that show has been called on
the Window, or its containing Frame, before calling this method.

#### See also

FocusEvent
Panel#set_focus
Panel#set_focus_ignoring_children

### Window#set_focus_from_kbd

set_focus_from_kbd()

This function is called by Widgets keyboard navigation code when the user
gives the focus to this window from keyboard (e.g. using `TAB` key).
By default this method simply calls set_focus but
can be overridden to do something in addition to this in the derived classes.

### Window#set_font

set_font(%(arg-type)Font% font)

Sets the font for this window. This function should not be called for the
parent window if you don’t want its font to be inherited by its children,
use set_own_font instead in this case and
see inherit_attributes for more
explanations.

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

#### Parameters

- font Font to associate with this window, pass
  `Wx::NULL_FONT` reset to the default font.

#### See also

Window#get_font,

inherit_attributes

### Window#set_foreground_colour

set_foreground_colour(%(arg-type)Colour% colour)

Sets the foreground colour of the window.

Please see inherit_attributes for
explanation of the difference between this method and
set_own_foreground_colour.

#### Parameters

- colour The colour to be used as the foreground colour, pass
  `Wx::NULL_COLOUR` to reset to the default colour.

#### Remarks

The interpretation of foreground colour is open to interpretation according
to the window class; it may be the text colour or other colour, or it may not
be used at all.

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.

#### See also

Window#get_foreground_colour, Window#set_background_colour, Window#get_background_colour, Window#should_inherit_colours

### Window#set_help_text

set_help_text(%(arg-type)String% helpText)

Sets the help text to be used as context-sensitive help for this window.

Note that the text is actually stored by the current
HelpProvider by calling its
add_help method, and not in
the window object itself.

#### See also

get_help_text, HelpProvider

### Window#set_id

set_id(%(arg-type)Integer% id)

Sets the identifier of the window.

#### Remarks

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.

#### See also

Window#get_id, Window identifiers

### Window#set_label

set_label(%(arg-type)String% label)

Sets the window’s label.

#### Parameters

- label The window label.

#### See also

Window#get_label

### Window#set_max_size

set_max_size(%(arg-type)Size% size)

Sets the maximum size of the window, to indicate to the sizer layout mechanism
that this is the maximum possible size.

### Window#set_min_size

set_min_size(%(arg-type)Size% size)

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.

### Window#set_name

set_name(%(arg-type)String% name)

Sets the window’s name.

#### Parameters

- name A name to set for the window.

#### See also

Window#get_name

### Window#set_own_background_colour

set_own_background_colour(%(arg-type)Colour% colour)

Sets the background colour of the window but prevents it from being inherited
by the children of this window.

#### See also

set_background_colour, inherit_attributes

### Window#set_own_font

set_own_font(%(arg-type)Font% font)

Sets the font of the window but prevents it from being inherited by the
children of this window.

#### See also

set_font, inherit_attributes

### Window#set_own_foreground_colour

set_own_foreground_colour(%(arg-type)Colour% colour)

Sets the foreground colour of the window but prevents it from being inherited
by the children of this window.

#### See also

set_foreground_colour, inherit_attributes

### Window#set_palette

set_palette(%(arg-type)Palette% palette)

Obsolete – use DC#set_palette instead.

### Window#set_scrollbar

set_scrollbar(%(arg-type)Integer% orientation, Integer position, Integer thumbSize, Integer range, Boolean refresh = `true`)

Sets the scrollbar properties of a built-in scrollbar.

#### Parameters

- orientation Determines the scrollbar whose page size is to be set. May be HORIZONTAL or VERTICAL.
- 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.
- 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:

set_scrollbar(VERTICAL, 0, 16, 50)

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 set_scrollbar call
into a function named adjust_scrollbars, which can be called initially
and also from your SizeEvent handler function.

#### See also

Scrolling overview, ScrollBar, ScrolledWindow, ScrollWinEvent

### Window#set_scroll_page

set_scroll_page(%(arg-type)Integer% orientation, Integer pageSize, Boolean refresh = `true`)

Sets the page size of one of the built-in scrollbars.

#### Parameters

- orientation Determines the scrollbar whose page size is to be set. May be HORIZONTAL or VERTICAL.
- pageSize Page size in scroll units.
- refresh `true` to redraw the scrollbar, `false` otherwise.

#### Remarks

The page size of a scrollbar is the number of scroll units that the
scroll thumb travels when you click on the area above/left of or
below/right of the thumb. Normally you will want a whole visible page to
be scrolled, i.e. the size of the current view (perhaps the window
client size). This value has to be adjusted when the window is resized,
since the page size will have changed.

In addition to specifying how far the scroll thumb travels when paging,
in Motif and some versions of Windows the thumb changes size to reflect
the page size relative to the length of the document. When the document
size is only slightly bigger than the current view (window) size, almost
all of the scrollbar will be taken up by the thumb. When the two values
become the same, the scrollbar will (on some systems) disappear.

Currently, this function should be called before “set_page_range”, because
of a quirk in the Windows handling of pages and ranges.

#### See also

Window#set_scroll_pos, Window#get_scroll_pos, Window#get_scroll_page, ScrollBar, ScrolledWindow

### Window#set_scroll_pos

set_scroll_pos(%(arg-type)Integer% orientation, Integer pos, Boolean refresh = `true`)

Sets the position of one of the built-in scrollbars.

#### Parameters

- orientation Determines the scrollbar whose position is to be set. May be HORIZONTAL or VERTICAL.
- pos Position in scroll units.
- refresh `true` to redraw the scrollbar, `false` otherwise.

#### Remarks

This function does not directly affect the contents of the window: it is up to the
application to take note of scrollbar attributes and redraw contents accordingly.

#### See also

Window#set_scrollbar, Window#get_scroll_pos, Window#get_scroll_thumb, ScrollBar, ScrolledWindow

### Window#set_scroll_range

set_scroll_range(%(arg-type)Integer% orientation, Integer range, Boolean refresh = `true`)

Sets the range of one of the built-in scrollbars.

#### Parameters

- orientation Determines the scrollbar whose range is to be set. May be HORIZONTAL or VERTICAL.
- range Scroll range.
- refresh `true` to redraw the scrollbar, `false` otherwise.

#### Remarks

The range of a scrollbar is the number of steps that the thumb may travel, rather than the total
object length of the scrollbar. If you are implementing a scrolling window, for example, you
would adjust the scroll range when the window is resized, by subtracting the window view size from the
total virtual window size. When the two sizes are the same (all the window is visible), the range goes to zero
and usually the scrollbar will be automatically hidden.

#### See also

Window#set_scroll_pos, Window#set_scroll_page, Window#get_scroll_pos, Window#get_scroll_page, ScrollBar, ScrolledWindow

### Window#set_size

set_size(%(arg-type)Size% size) set_size(%(arg-type)Rect% rect)

Sets the size of the window using either a Size or Rect
object. The former just specifies the size of the window, in pixels; a
rect specifies a new size and position.

#### Parameters

- size Size object for setting the size.
- rect Rect object for setting the position and size.

#### See also

Window:set_dimensions , Window#move

### Window#set_size_hints

set_size_hints(%(arg-type)Integer% minW, Integer minH, Integer maxW=-1, Integer maxH=-1, Integer incW=-1, Integer incH=-1) set_size_hints(%(arg-type)Size% minSize, Size maxSize=DefaultSize, Size incSize=DefaultSize)

Allows specification of minimum and maximum window sizes, and window size increments.
If a pair of values is not set (or set to -1), the default values will be used.

#### Parameters

- minW Specifies the minimum width allowable.
- minH Specifies the minimum height allowable.
- maxW Specifies the maximum width allowable.
- maxH Specifies the maximum height allowable.
- incW Specifies the increment for sizing the width (Motif/Xt only).
- incH Specifies the increment for sizing the height (Motif/Xt only).
- minSize Minimum size.
- maxSize Maximum size.
- incSize Increment size (Motif/Xt only).

#### Remarks

If this function is called, the user will not be able to size the window outside the
given bounds.

The resizing increments are only significant under Motif or Xt.

### Window#set_sizer

set_sizer(%(arg-type)Sizer% sizer, Boolean deleteOld=true)

Sets the window to have the given layout sizer. 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
set_auto_layout implicitly with `true`
parameter if the sizer is non-nil and `false` otherwise.

#### Parameters

- sizer The sizer to set. Pass `nil` to disassociate and conditionally delete
  the window’s sizer. See below.
- deleteOld If true (the default), this will delete any prexisting sizer.
  Pass false if you wish to handle deleting the old sizer yourself.

#### Remarks

SetSizer now enables and disables Layout automatically, but prior to Widgets 2.3.3
the following applied:

You must call Window#set_auto_layout to tell a window to use
the sizer automatically in OnSize; otherwise, you must override OnSize and call Layout()
explicitly. When setting both a Sizer and a LayoutConstraints,
only the sizer will have effect.

### Window#set_sizer_and_fit

set_sizer_and_fit(%(arg-type)Sizer% sizer, Boolean deleteOld=true)

The same as set_sizer, except it also sets the size hints
for the window based on the sizer’s minimum size.

### Window#set_theme_enabled

set_theme_enabled(%(arg-type)Boolean% enable)

This function tells a window if it should use the system’s “theme” code
to draw the windows’ background instead if 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.

### Window#set_tool_tip

set_tool_tip(%(arg-type)String% tip) set_tool_tip(%(arg-type)ToolTip% tip)

Attach a tooltip to the window.

See also: get_tool_tip,
ToolTip

### Window#set_validator

set_validator(%(arg-type)Validator% validator)

Deletes the current validator (if any) and sets the window validator, having called Validator::Clone to
create a new validator of this type.

### Window#set_virtual_size

set_virtual_size(%(arg-type)Integer% width, Integer height) set_virtual_size(%(arg-type)Size% size)

Sets the virtual size of the window in pixels.

### Window#set_virtual_size_hints

set_virtual_size_hints(%(arg-type)Integer% minW, Integer minH, Integer maxW=-1, Integer maxH=-1) set_virtual_size_hints(%(arg-type)Size% minSize=DefaultSize, Size maxSize=DefaultSize)

Allows specification of minimum and maximum virtual window sizes.
If a pair of values is not set (or set to -1), the default values
will be used.

#### Parameters

- minW Specifies the minimum width allowable.
- minH Specifies the minimum height allowable.
- maxW Specifies the maximum width allowable.
- maxH Specifies the maximum height allowable.
- minSize Minimum size.
- maxSize Maximum size.

#### Remarks

If this function is called, the user will not be able to size the virtual area
of the window outside the given bounds.

### Window#set_window_style

set_window_style(%(arg-type)Integer% style)

Identical to set_window_style_flag.

### Window#set_window_style_flag

set_window_style_flag(%(arg-type)Integer% style)

Sets the style of the window. Please note that some styles cannot be changed
after the window creation and that refresh might
be called after changing the others for the change to take place immediately.

See Window styles for more information about flags.

#### See also

get_window_style_flag

### Window#set_window_variant

set_window_variant(%(arg-type)WindowVariant% variant)

This function can be called under all platforms but only does anything under
Mac OS X 10.3+ currently. Under this system, each of the standard control can
exist in several sizes which correspond to the elements of WindowVariant
enum:

WINDOW_VARIANT_NORMAL # Normal size WINDOW_VARIANT_SMALL # Smaller size (about 25% smaller) WINDOW_VARIANT_MINI # Mini size (about 33% smaller) WINDOW_VARIANT_LARGE # Large size (about 25% larger)

By default the controls use the normal size, of course, but this function can
be used to change this.

### Window#should_inherit_colours

Boolean should_inherit_colours()

Return from here to allow the colours of this window to be changed by
inherit_attributes, returning
forbids inheriting them from the parent window.

The base class version returns , but this method is overridden in
Control where it returns .

### Window#show

Boolean show(%(arg-type)Boolean% show = `true`)

Shows or hides the window. 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.

#### Parameters

- show If `true` displays the window. Otherwise, hides it.

#### Return value

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

#### See also

Window#is_shown, Window#hide, RadioBox#show

### Window#thaw

thaw()

Reenables window updating after a previous call to
freeze. To really thaw the control, it must be called
exactly the same number of times as freeze.

### Window#unregister_hot_key

Boolean unregister_hot_key(%(arg-type)Integer% hotkeyId)

Unregisters a system wide hotkey.

#### Parameters

- hotkeyId Numeric identifier of the hotkey. Must be the same id that was passed to register_hot_key.

#### Return value

`true` if the hotkey was unregistered successfully, `false` if the id was invalid.

#### Remarks

This function is currently only implemented under MSW.

#### See also

Window#register_hot_key

#### See also

WindowUpdateLocker

### Window#toggle_window_style

Boolean toggle_window_style(%(arg-type)Integer% flag)

Turns the given flag on if it’s currently turned off and vice versa.
This function cannot be used if the value of the flag is $0$ (which is often
the case for default flags).

Also, please notice that not all styles can be changed after the control
creation.

#### Return value

Returns if the style was turned on by this function, if it was
switched off.

#### See also

Window#set_window_style_flag, Window#has_flag

### Window#update

update()

Calling this method immediately repaints the invalidated area of the window and
all of its children recursively while this would usually only happen when the
flow of control returns to the event loop. Notice that this function doesn’t
refresh the window and does nothing if the window hadn’t been already
repainted. Use refresh first if you want to
immediately redraw the window unconditionally.

### Window#update_window_ui

update_window_ui(%(arg-type)Integer% flags = UPDATE_UI_NONE)

This function sends UpdateUIEvents to
the window. The particular implementation depends on the window; for
example a ToolBar will send an update UI event for each toolbar button,
and a Frame will send an update UI event for each menubar menu item.
You can call this function from your application to ensure that your
UI is up-to-date at this point (as far as your UpdateUIEvent handlers
are concerned). This may be necessary if you have called
UpdateUIEvent#set_mode or
UpdateUIEvent#set_update_interval to
limit the overhead that Widgets incurs by sending update UI events in idle time.

flags should be a bitlist of one or more of the following values.

enum UpdateUI { UPDATE_UI_NONE = 0×0000, // No particular value UPDATE_UI_RECURSE = 0×0001, // Call the function for descendants UPDATE_UI_FROMIDLE = 0×0002 // Invoked from On(Internal)Idle };

If you are calling this function from an on_internal_idle or on_idle
function, make sure you pass the UPDATE_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 update_window_ui from
an idle function.

void MyWindow::on_internal_idle() { if (UpdateUIEvent::CanUpdate(this)) UpdateWindowUI(UPDATE_UI_FROMIDLE); }

#### See also

UpdateUIEvent,
Window#do_update_window_ui,
Window#on_internal_idle

### Window#validate

Boolean validate()

Validates the current values of the child controls using their validators.

If the window has `WS_EX_VALIDATE_RECURSIVELY` extra style flag set,
the method will also call validate() of all child windows.

#### Return value

Returns `false` if any of the validations failed.

#### See also

Validator

### Window#warp_pointer

warp_pointer(%(arg-type)Integer% x, Integer y)

Moves the pointer to the given position on the window.

NB: This function is not supported under Mac because Apple Human
Interface Guidelines forbid moving the mouse cursor programmatically.

#### Parameters

- x The new x position for the cursor.
- y The new y position for the cursor.

[This page automatically generated from the Textile source at 2023-06-09 00:45:26 +0000]