 | OO-Snippets: MessageBox with the UNO based toolkit (ooRexx)Commons| Keywords | MessageBox |
|---|
| Language | ooRexx |
|---|
| Application | Office |
|---|
| Authors | Rony G. Flatscher (initial)
|
|---|
| Supported Versions | 2.0.x |
|---|
| Supported OS | All |
|---|
| Question | How do I display a message box from an ooRexx script ?
I'm wondering if it is possible to display message boxes (similar to those displayed by Basic's MsgBox function) using the OpenOffice.org API.
(Also you could use ".bsf.dialog~messageBox()", ".bsf.dialog~dialogBox()" and/or
"bsf.dialog~inputBox()".)
|
|---|
| Answer | You can use the following function as a replacement for the Msgbox StarBasic function: |
|---|
xScriptContext=uno.getScriptContext()
oDoc=xScriptContext~getDocument
.local~vwpa=bsf.wrapStaticFields('com.sun.star.awt.VclWindowPeerAttribute')
call testMessageBox oDoc
::requires UNO.CLS
::routine TestMessageBox
use arg doc
numeric digits 10
parentWin=doc~XModel~getCurrentController~getFrame~getContainerWindow
s = "This is a test"
t = "Test"
res = MessageBox(parentWin, s, t, "querybox", .vwpa~YES_NO_CANCEL + .vwpa~DEF_NO)
call MessageBox parentWin, "The previous querybox returned:" res, t, "infobox"
::routine MessageBox
use arg ParentWin, MsgText, MsgTitle, MsgType, MsgButtons
if pos(msgType, "messbox infobox errorbox warningbox querybox")=0 then
MsgType="messbox"
if arg(5, "Omitted") then
MsgButtons=.vwpa~ok
aDescriptor=.bsf~new("com.sun.star.awt.WindowDescriptor")
aDescriptor~Type = bsf.getConstant("com.sun.star.awt.WindowClass", "MODALTOP")
aDescriptor~WindowServiceName = MsgType
aDescriptor~ParentIndex = -1
aDescriptor~Parent = ParentWin~XWindowPeer
aDescriptor~WindowAttributes = MsgButtons
tk = ParentWin~XWindowPeer~getToolkit
msgbox = tk~createWindow(aDescriptor)~xMessageBox
msgbox~setMessageText(MsgText)
if arg(3,"exists") then
msgbox~setCaptionText(MsgTitle)
return msgbox~execute
|
|