MinWin
MinWin is a "minimal window toolkit" for the D
programming language. For more info about D see DigitalMars D home page. The
library can be downloaded here.
This library is in the public domain.
Written by
Ben Hinkle, 2005.
Email comments and bug reports to ben.hinkle@gmail.com
This documentation is incomplete
Overview
The philosophy of the library is to be a minimal layer on top
of the native GUI toolkit. Developers benefit by reducing the amount
of platform-specific code they have to maintain. Users benefit
by having the native look and feel of the platform the use.
Supported backend tookits so far include Windows, Motif and GTK.
The goal of MinWin is not to eliminate platform specific code from
GUI development. The goals are:
be as small and simple as possible while still being useful
support multi-platform development by providing a cross-platform base where the peers exist and have similar behavior
seemlessly integrate with peers and platform-specific code
minimize the dependencies on other large libraries to avoid complex install and license issues
make it public domain (or make the core parts public domain)
Screenshots
Empire ported to MinWin:
GTK
Motif
Windows
Conventions
One Truth
The MinWin objects store as little state as possible and
query the peer for information in order to prevent situations
where the MinWin wrapper and the peer get out of sync.
Peer Management
Structs and aliases are used for resources not managed by the OS.
For example, Point, Rect, FontData, PenData and Event are structs with
a single field native that stores the native type or if
the native type doesn't exist it contains the fields such a type would
have.
Most types are classes that wrap a peer or sometimes multiple peers.
peer property.
The member variable hasPeer
with values blah.
These classes define a member function disposePeer
that
Destructors call disposePeer().
dispose()
Layout Management
preferredWidth, preferredHeight
Class Hierarchy
Component
AbstractWindow
Window
Dialog
PeerWrapper
Group
WindowChild
Label
Text
MultiLineText
ComboBox
ListBox
GroupBox
ScrollBar
ScrollPane
AbstractButton
Button
AbstractToggleButton
RadioButton
CheckBox
ToggleButton
MenuBar
Menu
GContext
GXContext
Pen
Brush
Image
Region
LayoutManager (interface)
FlowLayout
TableLayout
BorderLayout
ToggleGroup
MinWinException
Structures
Application
MultiDelegate
MultiBoolDelegate
Point
Rect
Color
Event
KeyEvent
MouseEvent
WindowEvent
FontData
FontMetrics
PenData
Modules
minwin.app
- Application gApp
- Global data and routines for the entire application
- struct Application
- Representation of application-level data and functions.
- char[] rsrc(char[] id, char[] group = "strings")
- Return the string resource with given id and group, if supported.
- char[][] cmdLineArgs
- Return the strings passed to the application at startup
- MultiDelegate!() idleDelegate
- A multi-delegate that gets called during idle time in the event queue.
- uint idleTime
- Read/write property to specify the idle time between calls to the idleDelegate.
- int enterEventLoop()
- Begin processing events from the event queue and stop when an exit message
is processed. Returns 0 if an error occurred.
- void exitEventLoop()
- Post a request to the event queue to exit the event loop.
- HINSTANCE hInstance
- Windows-only global hInstance passed to WinMain.
- HINSTANCE hPrevInstance
- Windows-only global hPrevInstance passed to WinMain.
- LPSTR lpCmdLine
- Windows-only global lpCmdLine passed to WinMain.
- int nCmdShow
- Windows-only global nCmdShow passed to WinMain.
- Event event
- Windows-only current event being processed by the main loop.
- XtAppContext context
- Motif-only global AppContext.
- Display* display
- Motif-only global display used to initialize the AppContext.
- ImlibData* imlibdata
- Motif-only global Imlib initialiation data.
- void sysAssert(bool passed, char[] msg, int id=0)
- If passed is false then throw a MinWinException with the given
message and possible error code. If the error code is 0 then the
system will be queried for the error code if supported. For example
on Windows GetLastError will be called to get the error code.
- const int NO_ID = -1
- Constant indicating the system error does not have an error code.
- class MinWinException : Exception
- Exception raised when a system call fails.
- this(char[] msg)
- Construct an exception with the given message.
- this(char[] msg, int id)
- Construct an exception with the given message and system error code.
minwin.button
- abstract class AbstractButton : WindowChild
- Abstract button base class
- int cmd
- The command to send when this button is pressed (activated).
- MultiDelegate!(Component) actionDelegate
- char[] text
- Read/write property for the text to display in the button.
- Icon icon
- Read/write property for the icon to display in the button (if supported).
- Delegates to fire when the button is pressed.
- void doCommand(int cmd)
- Fire the actionDelegate if the command is the button activation command.
If the button's cmd value is non-zero call the parent's doCommand function.
- abstract class AbstractToggleButton : AbstractButton
- Abstract base class of buttons that toggle on and off
- bool selected
- Read/write property for if the button is selected or not.
- class Button : AbstractButton
- A pushbutton.
- this(Component parent, char[] text, char[] name = "")
- Construct a pushbutton with given parent and text and optional name.
- Implement abstract Component and WindowChild functions.
- class CheckBox : AbstractToggleButton
- A checkbox.
- this(Component parent, char[] text, char[] name = "")
- Construct a checkbox with given parent and text and optional name.
- Implement abstract Component and WindowChild functions.
- class RadioButton : AbstractToggleButton
- A radio button.
- this(Component parent, char[] text, char[] name = "")
- Construct a radio button with given parent and text and optional name.
- Implement abstract Component and WindowChild functions.
- class ToggleButton : AbstractToggleButton
- A toggle button.
- this(Component parent, char[] text, char[] name = "")
- Construct a toggle button with given parent and text and optional name.
- Implement abstract Component and WindowChild functions.
- class ToggleGroup
- A collection of mutually-exclusive AbstractToggleButtons.
- AbstractToggleButton[] buttons
- The buttons in the group.
- void addButton(AbstractToggleButton b)
- Adds the button to the group of buttons managed by this ToggleGroup
- void select(Component c)
- Select c and deselect the other buttons in the group.
- void select(int n)
- Select the buttons[n] and deselect the other buttons in the group.
- int selected
- Return the index of the selected button.
minwin.component
- abstract class Component
- Abstract base-class for MinWin screen components. Each component
has a rectangular bounds, a layout manager, a parent (possibly null),
children (possibly none) and siblings (possibly none).
- mixin PeerMixin!()
- Mix in basic peer support hasPeer
and ~this.
- void dispose()
- Dispose of the component's children and peer
- abstract void disposePeer()
- Dispose of the system resource associated
with this object if it owns the peer and the object does
not have any parent. It is assumed that an object with a
parent will have its peer disposed when the parent is disposed.
- char[] name
- Name property used for resource lookup on XWindows and debugging
- void*[char[]] userdata
- Associative array indexed by strings for storing arbitrary data that
is associated with the component
- void doCommand(int cmd)
- Perform the action defined by cmd. By default the command is passed
to the parent.
- void requestFocus()
- If allowed request the keyboard focus for this component.
- abstract void getBounds(inout Rect r)
- Fill the rectangle r with the bounds of the component relative to
its parent.
- abstract void setBounds(inout Rect r)
- Move and resize the component to the specified rectangle.
- Rect bounds
- Read/write property for bounds.
- Point size
- Read/write property for the width and height
- int width
- Read-only property for the width of the component
- int height
- Read-only property for the height of the component
- int userPreferredWidth
- Read/write property for preferred custom width of the component
- int userPreferredHeight
- Read/write property for preferred custom height of the component
- void userPreferredSize(int width, int height)
- Set the preferred custom width and height
- Point preferredSize
- Read-only property for the preferred size of the component as
computed by the layout manager and/or the custom preferred size
- bool visible
- Read/write property for the visibility of the component and its
children
- Component getRootAncestor
- Read-only property to return the root of the component tree
- PeerForAdd getPeerForAdd()
- Get the native object that serves as the parent to the peers of
the children of this component. The peer of a component does not
have to directly contain the peers of its children. The symbol PeerForAdd
is an alias for a native peer type (eg, HWND or Widget).
- void getPeerOffset(inout int x, inout int y)
- Compute the offset of the client area's top left corner in the
peer coordinate system.
- LayoutManager layoutMgr
- Read/write property for layout manager of the component's children
- bool childLayoutDirty
- Read/write property indicating the child layout needs to be refreshed
- bool parentOwnsLayout
- Read/write property indicating the parent can position this component
- bool parentOwnsVisiblity
- Read/write property indicating the parent can hide or show this component
- void layout(bool validateParent)
- Layout children and optionally request parent layout first.
- void pack()
- Resize component and layout children to honor children's preferred sizes.
- void repaint()
- Mark the component as needing to be repainted.
- void repaint(inout Rect r)
- Mark the rectangle r in the component as needing to be repainted.
- bool clearBackgroundOnPaint
- Read/write property indicating the component should first repaint
the background before calling any paintDelegate.
- Component getRootAncestor
- Find the top-most parent of this object
- Component parent
- Read-only property for the parent component or null if no parent
- Component child
- Read-only property for the first child component or null if none
- Component last
- Read-only property for the last child component or null if none
- Component next
- Read-only property for the next sibling component or null if none
- Component prev
- Read-only property for the previous sibling component or null if none
- int opApply(int delegate(inout Component c) dg)
- Iterate over children from first to last and apply dg
- void link(Component first, Component second)
- Link the next/prev pointers so that first comes before second
- void opCatAssign(Component x)
- Catenate x to the end of the child list
- void addChild(Component x)
- Add x to the end of the child list
- void removeChild(Component x)
- Remove x from the child list
- abstract class WindowChild : Component
- Abstract class for a component that is a window child. MinWin assumes
all heavyweight window children have a common peer type.
- WindowChildPeer getPeer()
- get the top-most peer, if any, of this component
minwin.dialog
- class Dialog : AbstractWindow
- A dialog box for modal interactions.
- this(AbstractWindow owner, char[] title,
bool modal = true, char[] name = "")
- Construct a dialog owned by the given window and
having the specified modality. If the dialog is modal
setting the visibility to true will block execution
until the dialog is closed.
- this(WindowPeer peer)
- Wrap a preconstucted peer as a MinWin Dialog.
- bool visible
- Override read/write property to implement modal
dialogs. A modal dialog will block execution and events
to the other windows in the application until the dialog is
closed by setting visible off or destroying the dialog.
- struct FileFilter
- Structure for specifying a filter in a file dialog.
- char[] description
- Textual description of the filter to show to user.
- char[][] extensions
- Array of extensions to filter (eg, txt).
- struct FileDialogData
- Structure for communicating with open/save file dialogs.
- char[] title
- Read/write property for the title of the dialog.
- FileFilter[] filter
- Writable property for the array of filters to display.
- char[] initialDir
- Writable property for the initial directory to start in.
- char[] initialFile
- Writable property for the initial file name.
- char[] result
- Readable property for the output file name.
- int filterIndex
- Readable property for the output filter selected.
- bool openFileDialog(AbstractWindow owner,
inout FileDialogData data)
- Display a dialog to choose a file. Returns true if the user
closed the dialog with OK or Open.
- bool saveFileDialog(AbstractWindow owner,
inout FileDialogData data)
- Display a dialog to save a file. Returns true if the user
closed the dialog with OK or Save.
- void informationDialog(AbstractWindow owner,
char[] text, char[] title)
- Show a modal information dialog with given text, title and owner.
- void warningDialog(AbstractWindow owner,
char[] text, char[] title)
- Show a modal warning dialog with given text, title and owner.
- void errorDialog(AbstractWindow owner,
char[] text, char[] title)
- Show a modal error dialog with given text, title and owner.
- void messageDialog(AbstractWindow owner,
char[] text, char[] title)
- Show a modal message dialog with given text, title and owner.
minwin.event
- enum Modifier
- Shift = 1
- The shift key was held down during the event
- Alt = 2
- The alt key was held down during the event
- Ctrl = 4
- The control key was held down during the event
- Command = 8
- The command key was held down during the event (if supported)
- Meta = 16
- The meta key was held down during the event (if supported)
- alias EventNative
- Platform-specific generic event type (eg, MSG, XEvent, GdkEvent)
- struct Event
- Struct wrapping the native generic event type
- EventNative native
- The native event.
- int id
- Read-only property for the platform-specific event type.
- int modifiers
- Read-only property for the keyboard modifiers held down during the event
- alias KeyEventNative
- Platform-specific generic key event type (eg, MSG, XKeyEvent, GdkKeyEvent)
- struct KeyEvent
- Struct wrapping the native key event type
- KeyEventNative native
- The native key event
- int id
- Read-only property for the platform-specific event type.
- int modifiers
- Read-only property for the keyboard modifiers held down during the event
- dchar keyChar
- The character typed.
- alias KeyPressedEvent
- alias KeyDownEvent
- alias KeyUpEvent
- alias MouseEventNative
- Platform-specific generic mouse event type (eg, MSG, XMouseEvent, GdkMouseEvent).
- struct MouseEvent
- Struct wrapping the native mouse event type.
- EventNative native
- The native event
- int id
- Read-only property for the platform-specific event type.
- int modifiers
- Read-only property for the keyboard modifiers held down during the event.
- Point point
- The location of the event in source component coordinates.
- alias MouseMovedEvent
- alias MouseDownEvent
- alias MouseUpEvent
- alias MouseAlt1DownEvent
- alias MouseAlt1UpEvent
- alias MouseAlt2DownEvent
- alias MouseAlt2UpEvent
minwin.geometry
- alias RectNative
- Platform-specific rectangle type (RECT,XRect,GdkRect).
- struct Rect
- Struct wrapping the native integer rectangle type.
- RectNative native
- The native rectangle.
- void LTWH(int left, int top, int width, int height)
- Set the rectangle's data to left,top,width,height.
- void LTRB(int left, int top, int right, int bottom)
- Set the rectangle's data to left,top,right,bottom.
- int left
- Read/write property for left value of rectangle
Setting left might preserve either right or width depending on the platform.
- int top
- Read/write property for top value of rectangle.
Setting top might preserve either bottom or height depending on the platform.
- int right
- Read/write property for right value of rectangle.
- int bottom
- Read/write property for bottom value of rectangle.
- int width
- Read/write property for width of rectangle.
- int height
- Read/write property for height of rectangle.
- bool contains(Point pt)
- Test if a point is inside the rectangle.
- Rect LTWH(int left, int top, int width, int height)
- Construct a rectangle with data left,top,width,height.
- Rect LTRB(int left, int top, int right, int bottom)
- Construct a rectangle with data left,top,right,bottom.
- Rect toRect(RectNative c)
- Construct a rect from a native rect.
- alias PointNative
- Platform-specific point type (POINT,XPoint,GdkPoint).
- struct Point
- Struct wrapping the native integer point type.
- PointNative native
- The native point.
- void XY(int x, int y)
- Set the point's data to x,y.
- int x
- Read/write property for the x coordinate
- int y
- Read/write property for the y coordinate.
- Point XY(int x, int y)
- Construct a point with data x,y.
- Point toPoint(PointNative c)
- Construct a point from a native point.
- alias ColorNative
- Platform-specific color type for RGB tuples (COLORREF,uint). On X-based
systems a uint is used to pack the red, green and blue components.
- struct Color
- Struct wrapping the native color type.
- ColorNative native
- The native color.
- void RGB(ubyte r, ubyte g, ubyte b)
- Set a color's data to r,g,b.
- int red
- Read/write property for the red component.
- int blue
- Read/write property for the blue component.
- int green
- Read/write property for the green component.
- Color RGB(ubyte r, ubyte g, ubyte b)
- Construct a color with data r,g,b.
- Color toColor(ColorNative c)
- Construct a color from a native color.
- alias RegionPeer
- Alias for native region type.
- class Region
- A region is an area made of combining graphics primitives like rectangles.
- mixin SimplePeerMixin!()
- Mix in basic peer support hasPeer, ~this and the dispose functions.
- this(inout Rect r)
- Construct a region from rectangle r.
- this(Point[] pts, FillRule rule = FillRule.Winding)
- Construct a region from the filled polygon pts.
- this(RegionPeer rgn)
- Construct a region object for the given native region.
- int opEquals(Object o)
- Test equality of two regions.
- Region unionRgn(Region r)
- Add the region r to this region and return this.
- Region unionRect(inout Rect r)
- Add the rectangle r to this region and return this.
- Region intersectRgn(Region r)
- Intersect the region r with this region and return this.
- bool contains(Point p)
- Test if a point is in the region.
- Region dup()
- Duplicate the native region.
minwin.group
- class Group : Component
- A lightweight (meaning it has no peer) group of components layed out
in a rectanguluar area.
- this(Component parent, char[] name = "")
- Construct an empty group with given parent and name.
- bool visible
- Read/write property to show or hide all the components in the group.
The group is visible if any of the children are visible.
- class GroupBox : WindowChild
- A group of components layed out in a rectanguluar area with a border
and title around the edge
- this(Component parent, char[] text, char[] name = "")
- Construct an empty GroupBox with given parent, title and name. The
title is usually placed in the top left corner and a border is drawn
around the contents of the GroupBox.
- char[] text
- Read/write property for the text label displayed at the top of the box
minwin.layout
- interface LayoutManager
- Interface for positioning out children in a component
- void layout(Component c)
- Position children of c. Can reuse cached information from previous
preferredSize() or layout() calls.
- Point preferredSize(Component c)
- Compute preferred layout size. Does not reuse cached information.
- void reset()
- Clear cache if present.
- enum Dir
- Horizontal
- Flow left to right, then right to left
- Vertical
- Flow top to bottom, then bottom to top
- class FlowLayout
: LayoutManager
- A layout manager that positiions children in a row vertically
or horizontally. The "flow" refers to the direction along which
the children are being positioned and "side" refers to the
orthogonal direction.
- Dir dir
- Read/write property for the orientation and direction of the flow.
- int flowGap
- Read/write property for the gap in pixels between children.
- int sideGap
- Read/write property for the gap in pixels around the sides
of the children.
- bool sideStretch
- If true stretch the children sides to be the same size.
- int flowReverse
- Read/write property for the number of items to position
before flipping to the other side of the component and reversing
direction.
- double endGap
- Gap at the ends of the layout. If the value is greater than one
it is in absolute pixels. If the value is less than one it is the
percentage of extra space between the actual size and the preferred size.
- this(Dir dir = Dir.Vertical)
- Construct a FlowLayout in the requested direction.
- void layout(Component c)
- Position children in a row in the specified direction possibly
flipping sides to position from the other side of the component.
- Point preferredSize(Component c)
- Compute preferred layout size and caches result.
- void reset()
- Clear the preferred size cache.
- class TableLayout
: LayoutManager
- A layout manager that positiions children in a grid.
- double[] colScales
- Read/write property for the spacing of the columns.
- double[] rowScales
- Read/write property for the spacing of the rows.
- this(double[] colScales, double[] rowScales, int gap = 0)
- Construct a TableLayout with extra width distributed among the
columns according to colScales and the extra height among the rows
according to rowScales. The scale values must be between 0 and 1
and must total 1. The gap is the space in pixels to leave between
children.
- void layout(Component c)
- Position children in the grid starting from the upper left
and moving initially along the first row.
- Point preferredSize(Component c)
- Compute preferred layout size and caches result.
- void reset()
- Clear the cache of preferred size.
- enum Loc
- Enumeration for the location of a child in a BorderLayout.
- North
- South
- East
- West
- Center
- class BorderLayout
: LayoutManager
- A layout manager that positiions children like Java's BorderLayout:
---------------
| N |
|-------------|
| | | |
|W | C | E|
| | | |
|-------------|
| S |
---------------
- Component[Loc.max+1] location
- Read/write property of the locations of children to position.
- void layout(Component c)
- Position children according to their locations. If a child is
not in the location array it is not positioned.
- Point preferredSize(Component c)
- Compute preferred layout size.
- void reset()
- Clear the cache if any.
minwin.multidg
- struct MultiDelegate(...)
- Store multiple delegates with 0,1,2,3 or 4 arguments. The source
defines a parametrized struct for each number of arguments. To make
the documentation simpler the number of arguments and their
types will be represented by "...".
- alias void delegate(...) Callback
- Alias for delegate type.
- Callback[] dgs
- Array of delegates making up this multi-delegate.
- void opCall(...)
- Call each delegate.
- void opCatAssign(Callback dg)
- Add the given delegate.
- void remove(Callback dg)
- Remove the given delegate, if present.
- bool isEmpty
- Read-only property returns true if no delegates are in this multi-delegate.
- struct MultiBoolDelegate(...)
- Multi-delegate where the delegates return a bool result.
- alias bool delegate(...) Callback
- Alias for delegate type.
- Callback[] dgs
- Array of delegates making up this multi-delegate.
- bool opCall(...)
- Call each delegate and return the logical-or of the results.
- void opCatAssign(Callback dg)
- Add the given delegate.
- void remove(Callback dg)
- Remove the given delegate, if present.
- bool isEmpty
- Read-only property returns true if no delegates are in this multi-delegate.
minwin.peer
- alias WindowChildPeer
- Alias for the native type for a control or window child
(eg, HWND, Widget, GdkWidget*).
- alias PeerForAdd
- Alias for the native type for parenting controls
(eg, HWND, Widget, GdkWidget*).
- enum
- Enumeration of possible peer ownership states for hasPeer
- NO_PEER
- Object has no peer
- FOREIGN_PEER
- Object has a peer but should not destroy the peer when finished with it
- OWNS_PEER
- Object has a peer and should destroy the peer when finished with it
- template PeerMixin()
- Abstract peer support for mixing with objects that define disposePeer
- ~this()
- Destructor that only calls disposePeer
- int hasPeer
- Peer ownership state
- template SimplePeerMixin()
- Basic peer support for mixing with objects
- ~this()
- Destructor that only calls disposePeer
- int hasPeer
- Peer ownership state
- void dispose()
- Dispose of resources and possibly children resources. Calls disposePeer.
- void disposePeer()
- Dispose of the peer if the object owns the peer and set hasPeer to NO_PEER
minwin.peerimpl
- WindowChild PeerToWindowChild(WindowChildPeer peer)
- Get the Component associated with the given peer. Return
null if none.
- void setWindowChildPeer(WindowChild c, WindowChildPeer peer)
- Associate the given peer with the given WindowChild.
The association
must be broken when the peer is destroyed.
- template WindowChildImpl()
- Basic peer support for heavyweight WindowChild subclasses
- Implement and override WindowChild functions to handle
a peer.
- class PeerWrapper : WindowChild
- blah blah
- this(Component parent, WindowChildPeer peer)
- Construct a MinWin wrapper for a window child peer
and insert it into the MinWin component tree. The peer
must already be parented to the result of calling
parent.getPeerForAdd
.
The peer is stored as a FOREIGN_PEER so it will not be destroyed
if the PeerWrapper is destroyed.
minwin.window
- alias WindowPeer
- Alias for the native type for a top-level window or dialog
(eg, HWND, Widget, GdkWidget).
- AbstractWindow PeerToWindow(WindowPeer peer)
- Get the AbstractWindow associated with the given peer. Return
null if none.
- void setWindowPeer(AbstractWindow w, WindowPeer peer)
- Associate the given peer with the given AbstractWindow. The association
must be broken when the peer is destroyed. The builtin MinWin AbstractWindow
subclasses automatically break the association on the peer Destroy event.
- abstract class AbstractWindow : Component
- Base class for Windows and Dialogs.
- WindowPeer peer
- Read/write property for peer.
- MenuBar menubar
- Read/write property for the menu bar for this window.
- bool quitOnDestroy
- Read/write property to indicate the application should request to quit
when the window is destroyed.
- void doCommand(int cmd)
- Override of Component doCommand to call commandDelegates, if any.
- MultiDelegate!(Component, GContext) paintDelegate
- Multi-delegate for paint processing.
- MultiDelegate!(Component, GXContext) paintXDelegate
- Multi-delegate for extended-paint processing.
- MultiDelegate!(Component, int) commandDelegate
- Multi-delegate for command processing
- MultiBoolDelegate!(Component) cancelCloseDelegate
- Multi-delegate for cancelling close requests.
- MultiDelegate!(Component, KeyEvent*) keyDelegate
- Multi-delegate for key events.
- MultiDelegate!(Component, MouseEvent*) mouseDelegate
- Multi-delegate for mouse events.
- MultiDelegate!(Component, WindowEvent*) windowDelegate
- Multi-delegate for window events.
- char[] title
- Read/write property for the window title.
- GContext getGContext()
- Return a graphics context GContext for this window.
- Image getCompatibleImage(int width, int height)
- Create an Image compatible with this window.
- Image loadCompatibleImage(char[] imageKey, char[] fmt = "bmp")
- Load a picture resource with the specified name and file format
into an Image compatible with this window.
- void close()
- Close the window.
- Color backgroundColor
- Read/write property for the window background color.
- void toFront()
- Raise this window's peer to the top of the stacking order.
- class Window : AbstractWindow
- Top-level window class.
- this(char[] title = "", char[] name = "")
- Construct a top-level window with given title and name.
- this(WindowPeer peer)
- Construct a top-level window wrapping the given peer. The
peer is stored as a FOREIGN_PEER so it will not be destroyed
if the Window is destroyed. The peer must have the appropriate
infrastructure in place to forward events and behaviors
to the Window object.