Search documentation of wx

# View Source wx (wx v2.4.2)

A port of wxWidgets.

A port of wxWidgets.

This is the base api of wxWidgets. This module contains functions for starting and stopping the wx-server, as well as other utility functions.

wxWidgets is object oriented, and not functional. Thus, in Wx a module represents a class, and the object created by this class has an own type, wxCLASS(). This module represents the base class, and all other wxMODULE's are sub-classes of this class.

Objects of a class are created with wxCLASS:new(...) and destroyed with wxCLASS:destroy(). Member functions are called with wxCLASS:member(Object, ...) instead of as in C++ Object.member(...).

Sub class modules inherit (non static) functions from their parents. The inherited functions are not documented in the sub-classes.

This erlang port of wxWidgets tries to be a one-to-one mapping with the original wxWidgets library. Some things are different though, as the optional arguments use property lists and can be in any order. The main difference is the event handling which is different from the original library. See `wxEvtHandler`.

The following classes are implemented directly as erlang types:
wxPoint={x,y},wxSize={w,h},wxRect={x,y,w,h},wxColour={r,g,b [,a]}, wxString=unicode:chardata(), wxGBPosition={r,c},wxGBSpan={rs,cs},wxGridCellCoords={r,c}.

wxWidgets uses a process specific environment, which is created by wx:new/0. To be able to use the environment from other processes, call `get_env/0` to retrieve the environment and `set_env/1` to assign the environment in the other process.

Global (classless) functions are located in the wx_misc module.

## DATA TYPES

- wx_colour() = {R::byte(), G::byte(), B::byte()} | wx_colour4()

- wx_colour4() = {R::byte(), G::byte(), B::byte(), A::byte()}

- wx_datetime() = {{Year::integer(), Month::integer(), Day::integer()}, {Hour::integer(), Minute::integer(), Second::integer()}}

  In Local Timezone

- wx_enum() = integer()

  Constant defined in wx.hrl

- wx_env() = #wx_env{}

  Opaque process environment

- wx_memory() = binary() | #wx_mem{}

  Opaque memory reference

- wx_object() = #wx_ref{}

  Opaque object reference

- wx_wxHtmlLinkInfo() = #wxHtmlLinkInfo{href=unicode:chardata(), target=unicode:chardata()}

- wx_wxMouseState() = #wxMouseState{x=integer(), y=integer(), leftDown=boolean(), middleDown=boolean(), rightDown=boolean(), controlDown=boolean(), shiftDown=boolean(), altDown=boolean(), metaDown=boolean(), cmdDown=boolean()}

  See #wxMouseState{} defined in wx.hrl

# Summary

## Types

wx_colour4()
wx_colour()
wx_datetime()
wx_enum()
wx_env()
wx_memory()
wx_object()
wx_wxHtmlLinkInfo()
wx_wxMouseState()

## Functions

batch(Fun)

batch(Fun::function()) -> term()

create_memory/1

create_memory(Size::integer()) -> wx_memory()

debug(Debug)

debug(Debug::Level | [Level]) -> ok

demo()

demo() -> ok | {error, atom()}

destroy()

destroy() -> ok

equal/2

equal(Wx_ref::wx_object(), X2::wx_object()) -> boolean()

foldl(Fun, Acc, List)

foldl(Fun::function(), Acc::term(), List::list()) -> term()

foldr(Fun, Acc, List)

foldr(Fun::function(), Acc::term(), List::list()) -> term()

foreach(Fun, List)

foreach(Fun::function(), List::list()) -> ok

get_env()

get_env() -> wx_env()

get_memory_bin/1

get_memory_bin(Wx_mem::wx_memory()) -> binary()

getObjectType/1

getObjectType(Wx_ref::wx_object()) -> atom()

is_null/1

is_null(Wx_ref::wx_object()) -> boolean()

map(Fun, List)

map(Fun::function(), List::list()) -> list()

new()

new() -> wx_object()

new(Options)

new(Options::[Option]) -> wx_object()

null()

null() -> wx_object()

parent_class/1

parent_class(X1) -> term()

release_memory/1

release_memory(Wx_mem::wx_memory()) -> ok

retain_memory/1

retain_memory(Wx_mem::wx_memory()) -> ok

set_env/1

set_env(Wx_env::wx_env()) -> ok

subscribe_events()

subscribe_events() -> ok

typeCast/2

typeCast(Old::wx_object(), NewType::atom()) -> wx_object()

# Types

Link to this type

# wx_colour4()

View Source

    -type wx_colour4() :: {R :: byte(), G :: byte(), B :: byte(), A :: byte()}.

Link to this type

# wx_colour()

View Source

    -type wx_colour() :: {R :: byte(), G :: byte(), B :: byte()} | wx_colour4().

Link to this type

# wx_datetime()

View Source

    -type wx_datetime() ::
              {{Year :: integer(), Month :: integer(), Day :: integer()},
               {Hour :: integer(), Minute :: integer(), Second :: integer()}}.

Link to this type

# wx_enum()

View Source

    -type wx_enum() :: integer().

Link to this type

# wx_env()

View Source

    -type wx_env() :: #wx_env{ref :: term(), sv :: term(), debug :: term()}.

Link to this type

# wx_memory()

View Source

    -type wx_memory() :: binary() | #wx_mem{bin :: term(), size :: term()}.

Link to this type

# wx_object()

View Source

    -type wx_object() :: #wx_ref{ref :: term(), type :: term(), state :: term()}.

Link to this type

# wx_wxHtmlLinkInfo()

View Source

    -type wx_wxHtmlLinkInfo() :: #wxHtmlLinkInfo{href :: unicode:chardata(), target :: unicode:chardata()}.

Link to this type

# wx_wxMouseState()

View Source

    -type wx_wxMouseState() ::
              #wxMouseState{x :: integer(),
                            y :: integer(),
                            leftDown :: boolean(),
                            middleDown :: boolean(),
                            rightDown :: boolean(),
                            controlDown :: boolean(),
                            shiftDown :: boolean(),
                            altDown :: boolean(),
                            metaDown :: boolean(),
                            cmdDown :: boolean(),
                            aux1Down :: boolean(),
                            aux2Down :: boolean()}.

# Functions

Link to this function

# batch(Fun)

View Source

    -spec batch(function()) -> term().

batch(Fun::function()) -> term()

Batches all `wx` commands used in the fun. Improves performance of the command processing by grabbing the wxWidgets thread so that no event processing will be done before the complete batch of commands is invoked.

See also: `foldl/3`, `foldr/3`, `foreach/2`, `map/2`.

Link to this function

# create_memory/1

View Source

    -spec create_memory(integer()) -> wx_memory().

create_memory(Size::integer()) -> wx_memory()

Creates a memory area (of Size in bytes) which can be used by an external library (i.e. opengl). It is up to the client to keep a reference to this object so it does not get garbage collected by erlang while still in use by the external library.

This is far from erlang's intentional usage and can crash the erlang emulator. Use it carefully.

Link to this function

# debug(Debug)

View Source

    -spec debug(Level | [Level]) -> ok when Level :: none | verbose | trace | driver | integer().

debug(Debug::Level | [Level]) -> ok

Sets debug level. If debug level is 'verbose' or 'trace' each call is printed on console. If Level is 'driver' each allocated object and deletion is printed on the console.

Link to this function

# demo()

View Source

    -spec demo() -> ok | {error, atom()}.

demo() -> ok | {error, atom()}

Starts a Wx demo if examples directory exists and is compiled

Link to this function

# destroy()

View Source

    -spec destroy() -> ok.

destroy() -> ok

Stops a wx server.

Link to this function

# equal/2

View Source

    -spec equal(wx_object(), wx_object()) -> boolean().

equal(Wx_ref::wx_object(), X2::wx_object()) -> boolean()

Returns true if both arguments references the same object, false otherwise

Link to this function

# foldl(Fun, Acc, List)

View Source

    -spec foldl(function(), term(), list()) -> term().

foldl(Fun::function(), Acc::term(), List::list()) -> term()

Behaves like `lists:foldl/3` but batches wx commands. See `batch/1`.

Link to this function

# foldr(Fun, Acc, List)

View Source

    -spec foldr(function(), term(), list()) -> term().

foldr(Fun::function(), Acc::term(), List::list()) -> term()

Behaves like `lists:foldr/3` but batches wx commands. See `batch/1`.

Link to this function

# foreach(Fun, List)

View Source

    -spec foreach(function(), list()) -> ok.

foreach(Fun::function(), List::list()) -> ok

Behaves like `lists:foreach/2` but batches wx commands. See `batch/1`.

Link to this function

# get_env()

View Source

    -spec get_env() -> wx_env().

get_env() -> wx_env()

Gets this process's current wx environment. Can be sent to other processes to allow them use this process wx environment.

See also: `set_env/1`.

Link to this function

# get_memory_bin/1

View Source

    -spec get_memory_bin(wx_memory()) -> binary().

get_memory_bin(Wx_mem::wx_memory()) -> binary()

Returns the memory area as a binary.

Link to this function

# getObjectType/1

View Source

    -spec getObjectType(wx_object()) -> atom().

getObjectType(Wx_ref::wx_object()) -> atom()

Returns the object type

Link to this function

# is_null/1

View Source

    -spec is_null(wx_object()) -> boolean().

is_null(Wx_ref::wx_object()) -> boolean()

Returns true if object is null, false otherwise

Link to this function

# map(Fun, List)

View Source

    -spec map(function(), list()) -> list().

map(Fun::function(), List::list()) -> list()

Behaves like `lists:map/2` but batches wx commands. See `batch/1`.

Link to this function

# new()

View Source

    -spec new() -> wx_object().

new() -> wx_object()

Starts a wx server.

Link to this function

# new(Options)

View Source

    -spec new([Option]) -> wx_object() when Option :: {debug, list() | atom()} | {silent_start, boolean()}.

new(Options::[Option]) -> wx_object()

Starts a wx server. Option may be {debug, Level}, see debug/1. Or {silent_start, Bool}, which causes error messages at startup to be suppressed. The latter can be used as a silent test of whether wx is properly installed or not.

Link to this function

# null()

View Source

    -spec null() -> wx_object().

null() -> wx_object()

Returns the null object

Link to this function

# parent_class/1

View Source

    -spec parent_class(wx_object()) -> boolean().

parent_class(X1) -> term()

Link to this function

# release_memory/1

View Source

    -spec release_memory(wx_memory()) -> ok.

release_memory(Wx_mem::wx_memory()) -> ok

Link to this function

# retain_memory/1

View Source

    -spec retain_memory(wx_memory()) -> ok.

retain_memory(Wx_mem::wx_memory()) -> ok

Saves the memory from deletion until release_memory/1 is called. If release_memory/1 is not called the memory will not be garbage collected.

Link to this function

# set_env/1

View Source

    -spec set_env(wx_env()) -> ok.

set_env(Wx_env::wx_env()) -> ok

Sets the process wx environment, allows this process to use another process wx environment.

Link to this function

# subscribe_events()

View Source

    -spec subscribe_events() -> ok.

subscribe_events() -> ok

Adds the calling process to the list of of processes that are listening to wx application events.

At the moment these are all MacOSX specific events corresponding to `MacNewFile()` and friends from wxWidgets wxApp:

- `{new_file, ""}`
- `{open_file, Filename}`
- `{print_file, Filename}`
- `{open_url, Url}`
- `{reopen_app, ""}`

The call always returns ok but will have sent any already received events to the calling process.

Link to this function

# typeCast/2

View Source

    -spec typeCast(wx_object(), atom()) -> wx_object().

typeCast(Old::wx_object(), NewType::atom()) -> wx_object()

Casts the object to class NewType. It is needed when using functions like wxWindow:findWindow/2, which returns a generic wxObject type.