wxcore-0.12.1.5: wxHaskell core

Portabilityportable
Stabilityprovisional
Maintainerwxhaskell-devel@lists.sourceforge.net

Graphics.UI.WXCore.WxcObject

Contents

Description

Basic object type.

Synopsis

Object types

data Object a Source

An Object a is a pointer to an object of type a. The a parameter is used to encode the inheritance relation. When the type parameter is unit (), it denotes an object of exactly that class, when the parameter is a type variable a, it specifies an object that is at least an instance of that class. For example in wxWindows, we have the following class hierarchy:

 EvtHandler
   |- Window
        |- Frame
        |- Control
            |- Button
            |- Radiobox

In wxHaskell, all the creation functions will return objects of exactly that class and use the () type:

 frameCreate :: Window a -> ... -> IO (Frame ())
 buttonCreate :: Window a -> ... -> IO (Button ())
 ...

In contrast, all the this (or self) pointers of methods can take objects of any instance of that class and have a type variable, for example:

 windowSetClientSize :: Window a -> Size -> IO ()
 controlSetLabel     :: Control a -> String -> IO ()
 buttonSetDefault    :: Button a -> IO ()

This means that we can use windowSetClientSize on any window, including buttons and frames, but we can only use controlSetLabel on controls, not includeing frames.

In wxHaskell, this works since a Frame () is actually a type synonym for Window (CFrame ()) (where CFrame is an abstract data type). We can thus pass a value of type Frame () to anything that expects some Window a. For a button this works too, as it is a synonym for Control (CButton ()) which is in turn a synonym for Window (CControl (CButton ())). Note that we can't pass a frame to something that expects a value of type Control a. Of course, a Window a is actually a type synonym for EvtHandler (CWindow a). If you study the documentation in Graphics.UI.WXH.WxcClasses closely, you can discover where this chain ends :-).

Objects are not automatically deleted. Normally you can use a delete function like windowDelete to delete an object. However, almost all objects in the wxWindows library are automatically deleted by the library. The only objects that should be used with care are resources as bitmaps, fonts and brushes.

Instances

Eq (Object a) 
Ord (Object a) 
Show (Object a) 

objectNull :: Object aSource

A null object. Use with care.

objectIsNull :: Object a -> BoolSource

Test for null object.

objectCast :: Object a -> Object bSource

Cast an object to another type. Use with care.

objectIsManaged :: Object a -> BoolSource

Is this a managed object.

objectFromPtr :: Ptr a -> Object aSource

Create an unmanaged object.

objectFromManagedPtr :: ManagedPtr a -> IO (Object a)Source

Create a managed object with a given finalizer.

withObjectPtr :: Object a -> (Ptr a -> IO b) -> IO bSource

Do something with the object pointer.

objectFinalize :: Object a -> IO ()Source

Finalize a managed object manually. (no effect on unmanaged objects)

objectNoFinalize :: Object a -> IO ()Source

Remove the finalizer on a managed object. (no effect on unmanaged objects)

Managed objects

type ManagedPtr a = Ptr (CManagedPtr a)Source

Managed pointer (proxy) objects