OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[c++] How to draw on dialog?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
ladyk
General User
General User


Joined: 16 Nov 2006
Posts: 6

PostPosted: Wed Dec 27, 2006 3:09 pm    Post subject: [c++] How to draw on dialog? Reply with quote

Hi,

I want to draw some simple things on a dialog using c++.
I found an example for OOoBasic (see below) that works well, and I can translate it to c++, but the following line gives me problems:
Code:
oDlgGraph = oDlg.getPeer.createGraphics


How can i get an XGraphics to draw on from a dialog when using c++?

Thanks in advance!
k




complete OOoBasic code listing:
Code:
REM  *****  BASIC  *****

Dim oDlg As Object
Dim oPaintListener As Object
Dim oDlgGraph As Object

Sub ShowDialog
    Dim oDlgModel As Object
    Dim oWindow As Object

    oDlgModel=CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
    oDlgModel.PositionX = 50
    oDlgModel.PositionY = 50
    oDlgModel.Width = 150
    oDlgModel.Height = 150
    oDlgModel.Title = "Dialog Example"

    oDlg = CreateUnoService("com.sun.star.awt.UnoControlDialog")
    oWindow = CreateUnoService("com.sun.star.awt.Toolkit")
    oDlg.setModel(oDlgModel)
    oDlg.createPeer(oWindow, null)
   
   
    oDlgGraph = oDlg.getPeer.createGraphics
   
    With oDlgGraph
      .setFillColor(RGB(255,255,255))
      .setLineColor(RGB(200,200,200))
      .drawRect(0,0,100,100)
   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 dialog 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)
      .drawRect(0,0,100,100)
   End With
   
   'some nested rounded rect
   For I = 10 To 100 Step 10
   
      nX = 100 + I
      nY = 0 + I
      nWidth = nDlgWidth - 100 - 2*I
'      nWidth = 300
      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

(modified example from code snippets)
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Thu Dec 28, 2006 3:44 am    Post subject: Reply with quote

XRaying oDlgGraph object doesn't help ?
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
ladyk
General User
General User


Joined: 16 Nov 2006
Posts: 6

PostPosted: Thu Dec 28, 2006 12:54 pm    Post subject: Reply with quote

SergeM wrote:
XRaying oDlgGraph object doesn't help ?

It did help Smile. Thanks for that hint.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group