Hi,
I've grepped around in the Dev Guide in order to find some example of the use
of com.sun.star.awtXGraphics but with no success.
After some testing I've learned how to draw some nice shapes :-) on a Uno
Dialog and I've summarized my testing in the attached code snippet
ciao
Paolo M.
drawing
dialog
listener
com.sun.star.awt.XWindowPeer
com.sun.star.awt.XDevice
com.sun.star.awt.XGraphics
com.sun.star.awt.XPaintListener
Paolo Mantovani
Is it possible to draw lines or shapes (or text) directly on a Uno dialog ?
Yes, it is.
the com.sun.star.awt.XGraphics provide methods for drawing.
If you want your draw to be persistent you shall register an com.sun.star.awt.XPaintListener and place your drawing instructions in the method XPaintListener.windowPaint.
To see the whole thing at work, create an empty dialog in the OOBasic IDE and run the example code below:
REM ***** BASIC *****
Dim oDlg As Object
Dim oPaintListener As Object
Dim oDlgGraph As Object
'__________________________________________________________________________________________________________
Sub Main
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
oDlgGraph = oDlg.getPeer.createGraphics
' setup some defaults
With oDlgGraph
' .setFillColor(RGB(255,255,255))
.setLineColor(RGB(200,200,200))
End With
oPaintListener = CreateUnoListener("ThisDialog_", "com.sun.star.awt.XPaintListener"
oDlg.addPaintListener( oPaintListener )
oDlg.execute
oDlg.removePaintListener( oPaintListener )
End Sub
'__________________________________________________________________________________________________________
' This is a good place for drawing instructions.
' This routine is called whenever the dialof has to be repainted
Sub ThisDialog_windowPaint(oEvt)
'skip if there are other paint events in queue
If oEvt.count > 0 Then Exit Sub
Dim oGrad As New com.sun.star.awt.Gradient
With oGrad
.Style = com.sun.star.awt.GradientStyle.LINEAR
.StartColor = RGB( 255, 255, 255 )
.EndColor = RGB( 200, 230, 230 )
.Angle = 450 ' 45.0 degrees
' .Border = 0
' .XOffset = 0
' .YOffset = 0
.StartIntensity = 100
.EndIntensity = 100
.StepCount = 100
End With
nDlgWidth = oDlg.Peer.Size.Width
nDlgHeight = oDlg.Peer.Size.Height
'draw something
With oDlgGraph
.drawGradient(0,0, 100,220, oGrad)
.drawGradient(100,220, nDlgWidth,nDlgHeight, oGrad)
.drawText(10,10,"ciao a tutti")
.DrawLine(100,0,100,nDlgHeight)
.DrawLine(0,220,nDlgWidth,220)
End With
'some nested rounded rect
For I = 10 To 100 Step 10
nX = 100 + I
nY = 0 + I
nWidth = nDlgWidth - 100 - 2*I
nHeight = 220 - 2*I
nRound = 110-I
oDlgGraph.setFillColor(RGB(255-I, 255, 255-I))
oDlgGraph.drawRoundedRect(nX, nY, nWidth, nHeight ,nRound, nRound)
Next I
End Sub
'__________________________________________________________________________________________________________
Sub ThisDialog_disposing(oEvt As Object)
'nothing to do
End Sub
Initial version
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]