Hi Christian,
Alle 15:40, venerd� 11 marzo 2005, Christian Junker ha scritto:
> Tom, or whoever is responsible that this codesnippet works, please
> check the syntax before posting it online.
> I quickly looked over it to see how Paolo managed to draw on a dialog,
> but found this line
> <code>
> oPaintListener = CreateUnoListener("ThisDialog_",
> "com.sun.star.awt.XPaintListener"
> </code>
> There is no closing parenthesis.
> ->
> http://codesnippets.services.openoffice.org/Office/Office.DrawingOnDialogs.
>snip
Thank you for corrections.
...and shame on me!
I've attached an updated version of the snippet in the hope that Tom will
upload it ASAP.
> Also do check the comments, because there were spelling errors too. (I
> know this happens easily, but remember that these snippets should be
> good exercises for others out there.
You missed the closing parenthesis! ;-)
ciao
Paolo M.
<?xml version="1.0"?>
<!--
$RCSfile: Office.DrawingOnDialogs.snip,v $
last change: $Revision: 1.1 $ $Author: tomsontom $ $Date: 2005/03/11 12:29:14 $
(c)2003 by the copyright holders listed with the author-tags.
If no explicit copyright holder is mentioned with a certain author,
the author him-/herself is the copyright holder. All rights reserved.
Public Documentation License Notice:
The contents of this Documentation are subject to the
Public Documentation License Version 1.0 (the "License");
you may only use this Documentation if you comply with
the terms of this License. A copy of the License is
available at http://www.openoffice.org/licenses/PDL.html
The Original Documentation can be found in the CVS archives
of openoffice.org at the place specified by RCSfile: in this header.
The Initial Writer(s) of the Original Documentation are listed
with the author-tags below.
The Contributor(s) are listed with the author-tags below
without the marker for being an initial author.
All Rights Reserved.
-->
<snippet language="OOBasic" application="Office">
<keywords>
<keyword>drawing</keyword>
<keyword>dialog</keyword>
<keyword>listener</keyword>
<keyword>com.sun.star.awt.XWindowPeer</keyword>
<keyword>com.sun.star.awt.XDevice</keyword>
<keyword>com.sun.star.awt.XGraphics</keyword>
<keyword>com.sun.star.awt.XPaintListener</keyword>
</keywords>
<authors>
<author id="paolomantovani" initial="true" email="[EMAIL
PROTECTED]">Paolo Mantovani</author>
</authors>
<versions>
<version number="1.1.4" status="tested"/>
<version number="1.1.x" status="may_work"/>
</versions>
<operating-systems>
<operating-system name="All"/>
</operating-systems>
<question heading="Drawing directly on Uno Dialogs">
Is it possible to draw lines or shapes (or text) directly on a Uno dialog ?
</question>
<answer>
<p>Yes, it is.</p>
<p>the com.sun.star.awt.XGraphics provide methods for drawing.</p>
<p>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.</p>
<p>To see the whole thing at work, create an empty dialog in the OOBasic IDE
and run the example code below:</p>
<listing><syn:syntax xmlns:syn="http://ns.laxan.com/text-vimcolor/1">
<syn:Comment>REM ***** BASIC *****</syn:Comment>
<syn:Statement>Dim</syn:Statement> oDlg <syn:Statement>As</syn:Statement> Object
<syn:Statement>Dim</syn:Statement> oPaintListener
<syn:Statement>As</syn:Statement> Object
<syn:Statement>Dim</syn:Statement> oDlgGraph <syn:Statement>As</syn:Statement>
Object
<syn:Comment>'__________________________________________________________________________________________________________</syn:Comment>
<syn:Statement>Sub</syn:Statement> Main
oDlg =
<syn:Identifier>CreateUnoDialog</syn:Identifier>(DialogLibraries.Standard.Dialog1)
oDlgGraph = oDlg.getPeer.createGraphics
<syn:Comment>' setup some defaults</syn:Comment>
<syn:Statement>With</syn:Statement> oDlgGraph
<syn:Comment>' .setFillColor(RGB(255,255,255))</syn:Comment>
.setLineColor(<syn:Identifier>RGB</syn:Identifier>(<syn:Constant>200</syn:Constant>,<syn:Constant>200</syn:Constant>,<syn:Constant>200</syn:Constant>))
<syn:Statement>End</syn:Statement> <syn:Statement>With</syn:Statement>
oPaintListener =
<syn:Identifier>CreateUnoListener</syn:Identifier>(<syn:Constant>"ThisDialog_"</syn:Constant>,
<syn:Constant>"com.sun.star.awt.XPaintListener"</syn:Constant>)
oDlg.addPaintListener( oPaintListener )
oDlg.execute
oDlg.removePaintListener( oPaintListener )
<syn:Statement>End</syn:Statement> <syn:Statement>Sub</syn:Statement>
<syn:Comment>'__________________________________________________________________________________________________________</syn:Comment>
<syn:Comment>' This is a good place for drawing instructions. </syn:Comment>
<syn:Comment>' This routine is called whenever the dialog has to be
repainted</syn:Comment>
<syn:Statement>Sub</syn:Statement> ThisDialog_windowPaint(oEvt)
<syn:Comment> 'skip if there are other paint events in queue</syn:Comment>
<syn:Statement>If</syn:Statement> oEvt.count >
<syn:Constant>0</syn:Constant> <syn:Statement>Then</syn:Statement>
<syn:Statement>Exit</syn:Statement> <syn:Statement>Sub</syn:Statement>
<syn:Statement>Dim</syn:Statement> oGrad
<syn:Statement>As</syn:Statement> <syn:Statement>New</syn:Statement>
com.sun.star.awt.Gradient
<syn:Statement>With</syn:Statement> oGrad
.Style = com.sun.star.awt.GradientStyle.LINEAR
.StartColor = <syn:Identifier>RGB</syn:Identifier>(
<syn:Constant>255</syn:Constant>, <syn:Constant>255</syn:Constant>,
<syn:Constant>255</syn:Constant> )
.EndColor = <syn:Identifier>RGB</syn:Identifier>(
<syn:Constant>200</syn:Constant>, <syn:Constant>230</syn:Constant>,
<syn:Constant>230</syn:Constant> )
.Angle = <syn:Constant>450</syn:Constant> '
<syn:Constant>45.0</syn:Constant> degrees
<syn:Comment>' .Border = 0</syn:Comment>
<syn:Comment>' .XOffset = 0</syn:Comment>
<syn:Comment>' .YOffset = 0</syn:Comment>
.StartIntensity = <syn:Constant>100</syn:Constant>
.EndIntensity = <syn:Constant>100</syn:Constant>
.StepCount = <syn:Constant>100</syn:Constant>
<syn:Statement>End</syn:Statement> <syn:Statement>With</syn:Statement>
nDlgWidth = oDlg.Peer.Size.Width
nDlgHeight = oDlg.Peer.Size.Height
<syn:Comment> 'draw something</syn:Comment>
<syn:Statement>With</syn:Statement> oDlgGraph
.drawGradient(<syn:Constant>0</syn:Constant>,<syn:Constant>0</syn:Constant>,
<syn:Constant>100</syn:Constant>,<syn:Constant>220</syn:Constant>, oGrad)
.drawGradient(<syn:Constant>100</syn:Constant>,<syn:Constant>220</syn:Constant>,
nDlgWidth,nDlgHeight, oGrad)
.drawText(<syn:Constant>10</syn:Constant>,<syn:Constant>10</syn:Constant>,<syn:Constant>"ciao
a tutti"</syn:Constant>)
.DrawLine(<syn:Constant>100</syn:Constant>,<syn:Constant>0</syn:Constant>,<syn:Constant>100</syn:Constant>,nDlgHeight)
.DrawLine(<syn:Constant>0</syn:Constant>,<syn:Constant>220</syn:Constant>,nDlgWidth,<syn:Constant>220</syn:Constant>)
<syn:Statement>End</syn:Statement> <syn:Statement>With</syn:Statement>
<syn:Comment> 'some nested rounded rect</syn:Comment>
<syn:Statement>For</syn:Statement> I = <syn:Constant>10</syn:Constant>
<syn:Statement>To</syn:Statement> <syn:Constant>100</syn:Constant>
<syn:Statement>Step</syn:Statement> <syn:Constant>10</syn:Constant>
nX = <syn:Constant>100</syn:Constant> + I
nY = <syn:Constant>0</syn:Constant> + I
nWidth = nDlgWidth - <syn:Constant>100</syn:Constant> -
<syn:Constant>2</syn:Constant>*I
nHeight = <syn:Constant>220</syn:Constant> -
<syn:Constant>2</syn:Constant>*I
nRound = <syn:Constant>110</syn:Constant>-I
oDlgGraph.setFillColor(<syn:Identifier>RGB</syn:Identifier>(<syn:Constant>255</syn:Constant>-I,
<syn:Constant>255</syn:Constant>, <syn:Constant>255</syn:Constant>-I))
oDlgGraph.drawRoundedRect(nX, nY, nWidth, nHeight ,nRound,
nRound)
<syn:Statement>Next</syn:Statement> I
<syn:Statement>End</syn:Statement> <syn:Statement>Sub</syn:Statement>
<syn:Comment>'__________________________________________________________________________________________________________</syn:Comment>
<syn:Statement>Sub</syn:Statement> ThisDialog_disposing(oEvt
<syn:Statement>As</syn:Statement> Object)
<syn:Comment> 'nothing to do </syn:Comment>
<syn:Statement>End</syn:Statement> <syn:Statement>Sub</syn:Statement>
</syn:syntax></listing>
</answer>
<changelog>
<change author-id="paolomantovani" date="2005-03-11">Initial
version</change>
<change author-id="paolomantovani" date="2005-03-11">Corrected a
missing parenthesis in the code and a mispelling in comments</change>
</changelog>
</snippet>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]