thom314 OOo Enthusiast


Joined: 03 Aug 2005 Posts: 186 Location: Denver, Colorado
|
Posted: Mon Jul 31, 2006 7:48 pm Post subject: issues with awt toolkit |
|
|
I have been exploring the awt toolkit (borrowing heavily from other threads on the forum) just to see what I could get it to do. I have run into some interesting (to me) roadblocks. The following code creates a non-modal window and adds several elements (this window should look very familiar to everyone .
Questions:
a) I had to apply my own listeners to achieve the dropdown listbox behavior. There did not seem to be a way for me to enable that behavior without "building it from scratch". Is that to be expected? That was also true for ComboBoxes. And on line 152 I had to put a 200 msec wait to make it work with my listeners too! Otherwise, whenever the listbox collapsed down to one line it would select the zero'th element.
b) Although the Edit text box lets you set the "Multiline" property to TRUE (on line 83), I can not get it to respect carriage returns or line feeds. Does anyone know what is the trick to make multiline text work?
| Code: | Option Explicit
Global oWindow
Sub sbMakeNonModalXRayWindow
Dim oAwtToolkit
oAwtToolkit = CreateUnoService( "com.sun.star.awt.Toolkit" )
Dim xTopWindowListener
oWindow = fnCreateTopWindow( "My Non-Modal Xray", oAwtToolkit, fnNewRectangleXYWH( 300, 300, 500, 270 ) )
REM make all event listeners for the controls
Dim xActionListener As Variant
xActionListener = CreateUnoListener( "cbActionListener_", "com.sun.star.awt.XActionListener" )
Dim xItemListener As Variant
xItemListener = CreateUnoListener( "cbItemListener_", "com.sun.star.awt.XItemListener" )
Dim xMouseListener As Variant
xMouseListener = CreateUnoListener( "cbMouseListener_", "com.sun.star.awt.XMouseListener" )
REM now start adding controls
Dim oControl As Variant
With oControl
oControl = fnMakeAwtControl( "ListBox", oAwtToolkit, oWindow, fnNewRectangleXYWH( 10, 10, 100, 60 ))
.Model.HelpText = "Display what?"
.Model.StringItemList = Array( "Properties", "Methods", "Services", "Interfaces" )
.selectItemPos( 0, TRUE )
.addItemListener( xItemListener )
oControl = fnMakeAwtControl( "GroupBox", oAwtToolkit, oWindow, fnNewRectangleXYWH( 120, 10, 70, 60 ))
.Model.Label = "Display"
oControl = fnMakeAwtControl( "CheckBox", oAwtToolkit, oWindow, fnNewRectangleXYWH( 125, 25, 50, 15 ))
.Model.Label = "Sort"
.Model.State = 1
.addItemListener( xItemListener )
oControl = fnMakeAwtControl( "CheckBox", oAwtToolkit, oWindow, fnNewRectangleXYWH( 125, 45, 50, 15 ))
.Model.Label = "Details"
.Model.State = 1
.addItemListener( xItemListener )
oControl = fnMakeAwtControl( "FixedText", oAwtToolkit, oWindow, fnNewRectangleXYWH( 200, 10, 300, 15 ))
.Model.Label = "Internal Name"
.Model.HelpText = "This is the internal name of the object"
oControl = fnMakeAwtControl( "Button", oAwtToolkit, oWindow, fnNewRectangleXYWH( 200, 25, 175, 20 ))
.Model.Label = "SDK Docomentation"
.Model.HelpText = "This will display SDK documentation for the selected item"
.setActionCommand( "hello tom!" )
.addActionListener( xActionListener )
oControl = fnMakeAwtControl( "Button", oAwtToolkit, oWindow, fnNewRectangleXYWH( 200, 50, 175, 20 ))
.Model.Label = "Xray on the property/method"
.Model.HelpText = "This will display SDK documentation for the selected item"
.setActionCommand( "xray deeper!" )
.addActionListener( xActionListener )
oControl = fnMakeAwtControl( "Button", oAwtToolkit, oWindow, fnNewRectangleXYWH( 380, 25, 110, 20 ))
.Model.Label = "Close"
.Model.HelpText = "This will close Xray"
.setActionCommand( "Close!" )
.addActionListener( xActionListener )
oControl = fnMakeAwtControl( "Button", oAwtToolkit, oWindow, fnNewRectangleXYWH( 380, 50, 110, 20 ))
.Model.Label = "Configuration"
.Model.HelpText = "Set Xray's configuration options"
.setActionCommand( "configure Xray" )
.addActionListener( xActionListener )
oControl = fnMakeAwtControl( "FixedText", oAwtToolkit, oWindow, fnNewRectangleXYWH( 10, 80, 300, 15 ))
.Model.Label = "Currently displayed object:"
oControl = fnMakeAwtControl( "ListBox", oAwtToolkit, oWindow, fnNewRectangleXYWH( 10, 95, 400, 20 ))
.Model.HelpText = "Current xray object"
.Model.StringItemList = Array( "Original Object", "another", "and another", "and more" )
'.selectItemPos( 0, TRUE )
.addItemListener( xItemListener )
.addMouseListener( xMouseListener )
oControl = fnMakeAwtControl( "Edit", oAwtToolkit, oWindow, fnNewRectangleXYWH( 10, 115, 400, 100 ))
.setEditable( FALSE )
.Model.MultiLine = TRUE
' .Model.VScroll = TRUE
.Text = "what is the trick" & CHR(13) & "to making this multiline?" & CHR(10) & "It does not work!"
End With
'Xray GetDefaultContext()
'Xray oControl
'Xray oWindow
End Sub
Sub cbItemListener_itemStateChanged( oEvent )
' Xray oEvent
Dim sSelected As String
With oEvent.Source
Select Case .ImplementationName
Case "stardiv.Toolkit.UnoCheckBoxControl"
Select Case .Model.Label
Case "Sort"
MsgBox "Sort is " & cStr( .Model.State )
Case "Details"
MsgBox "Details is " & cStr( .Model.State )
End Select
Case "stardiv.Toolkit.UnoListBoxControl"
Select Case .Model.HelpText
Case "Display what?"
MsgBox "Display " & .SelectedItem
Case "Current xray object"
If .SelectedItem <> "" Then MsgBox "Item State Changed To: " & .SelectedItem
End Select
End Select
End With
' Xray oEvent
End Sub
Sub cbItemListener_disposing( oEvent )
End Sub
Sub cbActionListener_actionPerformed( oEvent )
'Xray oEvent
Select Case oEvent.ActionCommand
Case "Close!"
oEvent.Source.AccessibleContext.AccessibleParent.dispose()
Case Else
MsgBox oEvent.ActionCommand
End Select
End Sub
Sub cbActionListener_disposing( oEvent )
End Sub
Sub cbMouseListener_mousePressed( oEvent )
' Xray oEvent.Source
' MsgBox "MousePressed"
Dim sSelection As String
With oEvent.Source
If .Size.Height <> .PreferredSize.Height Then
.setPosSize( _
0, 0,_
0, .PreferredSize.Height,_
com.sun.star.awt.PosSize.HEIGHT )
Else
sSelection = .SelectedItem
.setPosSize( _
0, 0,_
0, 20,_
com.sun.star.awt.PosSize.HEIGHT )
Wait 200 'tune out race condition in collapsing the drop down listbox
.selectItem( sSelection, TRUE )
End If
End With
End Sub
Sub cbMouseListener_mouseReleased( oEvent )
End Sub
Sub cbMouseListener_mouseEntered( oEvent )
End Sub
Sub cbMouseListener_mouseExited( oEvent )
End Sub
Sub cbMouseListener_disposing( oEvent )
End Sub
Function fnMakeAwtControl( sType As String, oAwtToolkit, oWindow, _
Optional aPosSizeRect, Optional mArgs )
Dim oControl As Variant : Dim oControlModel As Variant
oControl = CreateUnoService( "com.sun.star.awt.UnoControl" & sType )
oControlModel = CreateUnoService( "com.sun.star.awt.UnoControl" & sType & "Model" )
oControl.setModel( oControlModel )
oControl.createPeer( oAwtToolkit, oWindow )
If Not IsMissing( aPosSizeRect ) Then
oControl.setPosSize( _
aPosSizeRect.X, aPosSizeRect.Y,_
aPosSizeRect.Width, aPosSizeRect.Height,_
com.sun.star.awt.PosSize.POSSIZE )
EndIf
fnMakeAwtControl = oControl
If isMissing( mArgs ) Then Exit Function
Dim sArg As String : Dim msAction() As String
For Each sArg In mArgs()
msAction = Split( sArg, "=" )
Select Case msAction(0)
Case "Property"
If oControlModel.PropertySetInfo.hasPropertyByName( msAction(1) ) Then
oControlModel.setPropertyValue( msAction(1), msAction(2) )
End If
Case "PropertyInt"
If oControlModel.PropertySetInfo.hasPropertyByName( msAction(1) ) Then
oControlModel.setPropertyValue( msAction(1), cInt( msAction(2) ))
End If
Case "PropertyBool"
If oControlModel.PropertySetInfo.hasPropertyByName( msAction(1) ) Then
oControlModel.setPropertyValue( msAction(1), cBool( msAction(2) ))
End If
End Select
ReDim msAction()
Next sArg
End Function
Function fnCreateTopWindow( sTitle As String, oAwtToolkit, aRectangle ) As Variant
Dim aWindowDesc As New com.sun.star.awt.WindowDescriptor
With aWindowDesc
.Type = com.sun.star.awt.WindowClass.TOP
.WindowServiceName = ""
.Parent = oAwtToolkit.getDesktopWindow()
.Bounds = aRectangle
.WindowAttributes = 0
.WindowAttributes = .WindowAttributes + com.sun.star.awt.WindowAttribute.SHOW
.WindowAttributes = .WindowAttributes + com.sun.star.awt.WindowAttribute.BORDER
.WindowAttributes = .WindowAttributes + com.sun.star.awt.WindowAttribute.SIZEABLE
.WindowAttributes = .WindowAttributes + com.sun.star.awt.WindowAttribute.MOVEABLE
.WindowAttributes = .WindowAttributes + com.sun.star.awt.WindowAttribute.CLOSEABLE
End With
Dim oWindow : Dim oFrame
oWindow = oAwtToolkit.createWindow( aWindowDesc )
oWindow.setBackground( RGB( 175, 175, 175 ) )
oFrame = CreateUnoService( "com.sun.star.frame.Frame" )
oFrame.initialize( oWindow )
oFrame.setCreator( StarDesktop )
oFrame.Title = sTitle
fnCreateTopWindow = oWindow
End Function
Function fnNewRectangleXYWH( ByVal nX As Long, ByVal nY As Long,_
ByVal nWidth As Long, ByVal nHeight As Long ) As com.sun.star.awt.Rectangle
Dim aRectangle As New "com.sun.star.awt.Rectangle"
With aRectangle
.X = nX
.Y = nY
.Width = nWidth
.Height = nHeight
End With
fnNewRectangleXYWH = aRectangle
End Function |
|
|