 | OO-Snippets: Drawing directly on Uno DialogsCommons| Keywords | drawing, dialog, listener, com.sun.star.awt.XWindowPeer, com.sun.star.awt.XDevice, com.sun.star.awt.XGraphics, com.sun.star.awt.XPaintListener |
|---|
| Language | OOBasic |
|---|
| Application | Office |
|---|
| Authors | Paolo Mantovani (initial)
|
|---|
| Supported Versions | 1.1.4 1.1.x |
|---|
| Supported OS | All |
|---|
| Question |
Is it possible to draw lines or shapes (or text) directly on a Uno dialog ?
|
|---|
| Answer | 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: |
|---|
Dim oDlg As Object
Dim oPaintListener As Object
Dim oDlgGraph As Object
Sub Main
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
oDlgGraph = oDlg.getPeer.createGraphics
With oDlgGraph
.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
Sub ThisDialog_windowPaint(oEvt)
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
.StartIntensity = 100
.EndIntensity = 100
.StepCount = 100
End With
nDlgWidth = oDlg.Peer.Size.Width
nDlgHeight = oDlg.Peer.Size.Height
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
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)
End Sub
|
Changelog| Date | User | Modification |
|---|
| 2005-03-11 | paolomantovani | Initial version |
|