wxRuby Documentation Home

# Wx::XmlResource

This is the main class for interacting with the XML-based resource system.

The class holds XML resources from one or more .xml files, binary files or zip archive files.

See XML-based resource system overview for details.

## Derived from

Object

## Constants

Wx::XRC_USE_LOCALE = 1 Wx::XRC_NO_SUBCLASSING = 2 Wx::XRC_NO_RELOADING = 4

## Methods

- XmlResource.new
- XmlResource.get
- XmlResource.set
- XmlResource#add_handler
- XmlResource#attach_unknown_control
- XmlResource#clear_handlers
- XmlResource#compare_version
- XmlResource#get_flags
- XmlResource#get_version
- XmlResource#get_xrcid
- XmlResource#init_all_handlers
- XmlResource#load
- XmlResource#load_bitmap
- XmlResource#load_dialog
- XmlResource#load_dialog_subclass
- XmlResource#load_frame
- XmlResource#load_frame_subclass
- XmlResource#load_icon
- XmlResource#load_menu
- XmlResource#load_menu_bar
- XmlResource#load_object
- XmlResource#load_panel
- XmlResource#load_panel_subclass
- XmlResource#load_tool_bar
- XmlResource#load_wizard
- XmlResource#load_wizard_subclass
- XmlResource#set_flags
- XmlResource#unload

### XmlResource.new

XmlResource.new(%(arg-type)String% filemask, Integer flags = XRC_USE_LOCALE)

Constructor.

- filemask The XRC file, archive file, or wildcard specification that will be used to
  load all resource files inside a zip archive.
- flags XRC_USE_LOCALE: translatable strings will be translated via ().
  XRC_NO SUBCLASSING: subclass property of object nodes will be ignored
  (useful for previews in XRC editors).

XmlResource.new(%(arg-type)Integer% flags = XRC_USE_LOCALE)

The flags in Wx::XmlResource are not useful in ruby. All XmlResources
created will have the optimal flags.

- `Wx::XRC_USE_LOCALE`: translatable strings will be translated via _().
- `Wx::XRC_NO_SUBCLASSING`: subclass property of object nodes will be ignored (useful for previews in XRC editors).
- `Wx::XRC_NO_RELOADING` will prevent the XRC files from being reloaded from disk in case they have been modified there since being last loaded (may slightly speed up loading them).

### XmlResource#get

XmlResource XmlResource.get()

Class method to get the global XmlResource object.

### XmlResource#set

XmlResource XmlResource.set(%(arg-type)XmlResource% res)

Class method to set the global resources object. Returns the pointer to
the previous one, or nil if there was not one.

### XmlResource#attach_unknown_control

Boolean attach_unknown_control(%(arg-type)String% name, Window control, Window parent = nil)

Attaches an unknown control to the given panel/window/dialog.
Unknown controls are used in conjunction with `<object class="unknown">`.

### XmlResource#compare_version

Integer compare_version(%(arg-type)Integer% major, Integer minor, Integer release, Integer revision)

Compares the XRC version to the argument. Returns -1 if the XRC version
is less than the argument, +1 if greater, and 0 if they equal.

### XmlResource#get_flags

Integer get_flags()

Returns flags, which may be a bitlist of XRC_USE_LOCALE and XRC_NO_SUBCLASSING.

### XmlResource#get_version

Integer get_version()

Returns version information (a.b.c.d = d+ 256*c + 256*b + 256*a).

### XmlResource#get_xrcid

Integer get_xrcid(%(arg-type)Char% str_id)

Returns a numeric ID that is equivalent to the string ID used in an XML
resource. To be used in event tables.
The module method `Wx::xrcid(name)` is provided for convenience.

### XmlResource#init_all_handlers

init_all_handlers()

Initializes handlers for all supported controls/windows. In wxRuby
versions 1.9.6 and later, this is called automatically for you, so there
is no need to call this method

### XmlResource#load

Boolean load(%(arg-type)String% file)

Loads resources from the XML file `file`. If this file does not exist,
or contains invalid XML, an exception will be raised; if successful, the
loaded file name will be returneed.

### XmlResource#load_bitmap

Bitmap load_bitmap(%(arg-type)String% name)

Loads a bitmap resource from a file.

### XmlResource#load_dialog

Dialog load_dialog(%(arg-type)Window% parent, String name)

Loads a dialog. dlg points to a parent window (if any).

### XmlResource#load_dialog_subclass

Boolean load_dialog_subclass(%(arg-type)Dialog% dlg, Window parent, String name)

Loads a dialog. dlg points to parent window (if any).

This form is used to finish creation of an already existing instance (the main reason
for this is that you may want to use derived class with a new event table).

Example:

dlg = MyDialog.new the_xml_resource.load_dialog_subclass(dlg, main_frame, “my_dialog”) dlg.show_modal

### XmlResource#load_frame

Frame load_frame(%(arg-type)Window% parent, String name)

Loads a frame.

### XmlResource#load_frame_subclass

Boolean load_frame_subclass(%(arg-type)Frame% frame, Window parent, String name)

Loads a frame. This form is used to finish creation of an already existing instance.

### XmlResource#load_icon

Icon load_icon(%(arg-type)String% name)

Loads an icon resource from a file.

### XmlResource#load_menu

Menu load_menu(%(arg-type)String% name)

Loads menu from resource. Returns NULL on failure.

### XmlResource#load_menu_bar

MenuBar load_menu_bar(%(arg-type)Window% parent, String name)

Loads a menubar from resource. Returns NULL on failure.

MenuBar load_menu_bar(%(arg-type)String% name)

Loads a menubar from resource. Returns NULL on failure.

### XmlResource#load_object

Boolean load_object(%(arg-type)Object% instance, %(arg-type)Window parent, String name, String class_name)

Loads any arbitrary object from the XML resource. The object should be
some Window (or a subclass) created with the no-arguments version of the
constructor – ie, an incomplete instance. The layout definition in the
XRC will complete the instance.

The argument instance is the incomplete object, and parent is the
Window to which it will be attached. name is the name attribute of the
object in the XML file, and class_name is the wxWidgets name of the
class of the instance being loaded. The class_name needs to be in C++
form, for example “wxWizard”.

### XmlResource#load_panel

Panel load_panel(%(arg-type)Window% parent, String name)

Loads a panel. panel points to parent window (if any).

### XmlResource#load_panel_subclass

Boolean load_panel_subclass(%(arg-type)Panel% panel, Window parent, String name)

Loads a panel. panel points to parent window (if any). This form
is used to finish creation of an already existing instance.

### XmlResource#load_tool_bar

ToolBar load_tool_bar(%(arg-type)Window% parent, String name)

Loads a toolbar.

### XmlResource#load_wizard

Wizard load_wizard(%(arg-type)Window% parent, String name)

Creates a wizard from the item named name in the XRC.

### XmlResource#load_wizard_subclass

Boolean load_panel_subclass(%(arg-type)Wizard% panel, Window parent, String name)

Loads a wizard. This form is used to finish creation of an already
existing instance – which may be a custom Ruby subclass.

### XmlResource#set_flags

set_flags(%(arg-type)Integer% flags)

Sets flags (bitlist of XRC_USE_LOCALE and XRC_NO_SUBCLASSING).

### XmlResource#unload

Boolean unload(%(arg-type)String% filename)

This function unloads a resource previously loaded by
load.

Returns if the resource was successfully unloaded and if it hasn’t
been found in the list of loaded resources.

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