Show TOC Welcome to the QLIB 1.0 Online Reference
QLIB 

QMessageBox


Extends:QBoxCtrl
Requires:
<script language="JavaScript" src="js/qlib/control.js"></script>
<script language="JavaScript" src="js/qlib/wndctrl.js"></script>
<script language="JavaScript" src="js/qlib/boxctrl.js"></script>
<script language="JavaScript" src="js/qlib/messagebox.js"></script>
<script language="JavaScript" src="js/qlib/label.js"></script>
<script language="JavaScript" src="js/qlib/button.js"></script>
Show Demo

Description

A message box is a window control derived from QBox and basically used to display short messages to user. It inherits all properties of QBox and its behavior. This control displays a text message and a button that closes the box when clicked. It automatically adjusts the size to best fit the text on it. In addition it centers itself on the page when alert method is invoked.

A message box requires two resources: a box resource and the close button resource.

Implementation Notes

For details of cross-browser support refer to Implementation Notes to QWndCtrl class.

See Also

QBoxRes, QButtonRes, QWndCtrl, Windowing

Constructor

QMessageBox(parent, name, box, btn, msgopt, effectsopt, opacityopt)
Creates a message box. Initially it's not visible. Use alert method to display different messages after it's created. If the box is created as a child control, valid parent object must be specified. If the box is assigned to global variable, parent should be null. The name should be the same as the name of variable or property that has been assigned by newly created object.
Parameters
parent - Parent control (if any, null otherwise).
name - The object reference name.
box - Resource for the box (refer to QBoxRes for details).
btn - Resource for the close button (refer to QButtonRes for details).
msg - Optional default message to display.
effects - Optional effects mask. By default the box is created with no effects. For complete list of effects refer to QWndCtrl.
opacity - Optional opacity from 0 to 100. Default value is 100 that corresponds to 100% opaqueness.

Properties

PropertyAccessDescription
valueRThe message that's currently displayed by the box.
 
Properties inherited from QBoxCtrl
resRThe box resource (see QBoxRes).
cwidthRWidth in pixels of the box client area.
cheightRHeight in pixels of the box client area (is null if box is an auto-sized).
 
Properties inherited from QWndCtrl
xRX coordinate of the top left corner (pixels).
yRY coordinate of the top left corner (pixels).
widthRWidth in pixels of the surrounding window.
heightRHeight in pixels of the surrounding window (is null if box is an auto-sized).
visibleRVisibility state.
effectsREffects mask (can be a mix of effects).
opacityRThe window opacity from 0 (transparent) to 100 (opaque).
zindexRThe window stacking order. Can be null for auto-stack.
 
Properties inherited from QControl
nameRName of the control. Serves as a direct reference to this object when evaluated.
idRAlphanumerical unique identifier of the control.
parentRReference to the parent control (if any, null otherwise).
tagR / WCan refer any value or object, tag is always passed to all event handlers as the last parameter.
windowRThis property is a reference to JavaScript window object in which the control exists.
documentRRefers to document object in which the corresponding HTML elements exist. Normally all elements of a DOM2 compatible browser are children of the top document object. If the control creates new document scope (i.e. printing tags like <IFRAME>, <LAYER>), it should assign this document to this property.

Methods

alert(msgopt)
Shows up the message. Each time this method is called, the box position is adjusted to be centered on the page.
Parameters
msg - Optional message to display to user.
center()
Centers the box on page.
show(show)
Shows or hides the box. "IN" and "OUT" transitions can be assigned to show and hide actions respectively (see setEffects method). In this case the window does not show/hide promptly, instead the window smoothly changes its visibility through animation.
Parameters
show - Desirable state as follows: true - make it visible, false - hide the window.
focus()
Gives the focus to the box. This brings it to the top of the stacking order.
moveTo(x, y)
Moves the window to specified position. If the window has been created in document context, it gets positioned in absolute page coordinates. If the window is nested in another one, it's positioned in relative coordinates of the parent window (see CSS positon property for more details).
Parameters
x - X coordinate in pixels.
y - Y coordinate in pixels.
setSize(w, hopt)
This method has no effect for this control, see Implementation Notes.
setZIndex(z)
Changes the stacking order of the window. Window with higher index appear on the screen first obscuring underlying windows with lower indices.
Parameters
z - Desirable stacking index (starting from 1).
setOpacity(op)
Changes the window opacity. See Implementation Notes for details and how this method is supported.
Parameters
op - Desirable opacity as follows: 0 - transparent, 100 - opaque.
setEffects(fx)
Sets effects mask. There're two kinds of effects: static and dynamic. Static effects change the default appearance of the window (for example, a window casts shadow when it's set by QWndCtrl.SHADOW). On the other hand, dynamic effects are transitions that get activated when window changes its visibility state. A dynamic effect can be either "IN" or "OUT". The first type is played when a window appears. The second one is activated on the hiding. Effects of all types can be mixed together to bring up a composite effect (example: "QWndCtrl.SHADOW + QWndCtrl.BOXIN + QWndCtrl.FADEOUT" - makes a window to cast shadow, it appears with "box" effect, hides itself fading out from view).
Parameters
fx - Mix of effects to apply.

Event Handlers

onClose(tag)
This handler is fired when the box is about to close.
Parameters
tag - Tag is commonly used to parameterize the event handler. Each control can be optionally assigned by a tag.
Returns
The box gets closed if the handler returns nothing or false. Otherwise the close action is considered to be canceled and the box remains visible.
onShow(visible, tag)
This handler is fired when the window becomes visible or vanishes. When transitions are enabled, the handler is fired after the animation completes.
Parameters
visible - Visibility state of the window.
tag - Tag is commonly used to parameterize the event handler. Each control can be optionally assigned by a tag.
Returns
The return value is ignored.

CSS Class Selectors

CSS ClassDescriptionExample (defined in a CSS file)
TABLE.qboxDefines style of the box TABLE element.TABLE.qbox { margin: 10px } /* sets margins around the box. */
TABLE TD.bodyDefines style of the body cell.TABLE TD.body { text-align: center } /* sets center alignment of the body. */