Hi,
I'm trying to put a button on a slide of OOImpress document.
I got the
code from Developer's Guide and altered it a bit. But when I
run the
following function I see nothing on the slide. I want a
button to
appear on the slide as I run following function:
/***********************************************************
********************
createButton funtion starts
************************************************************
********************/
public static XPropertySet createButton( XComponent
xDrawComponent, int nXPos, int nYPos, int nWidth, int
nHeight,
XDrawPage pageWhereToInsert, XIndexContainer xParentForm )
throws
java.lang.Exception
{
System.out.println("Entering createButton");
//query the document for the document-internal service
factory and
let the document create a control shape
XMultiServiceFactory xDocAsFactory =
(XMultiServiceFactory)UnoRuntime.queryInterface(
XMultiServiceFactory.class, xDrawComponent );
XControlShape xShape =
(XControlShape)UnoRuntime.queryInterface(
XControlShape.class,
xDocAsFactory.createInstance(
"com.sun.star.drawing.ControlShape" ) );
// position and size of the shape
xShape.setSize( new Size( nWidth * 100, nHeight *
100 ) );
xShape.setPosition( new Point( nXPos * 100, nYPos *
100 ) );
// adjust the anchor so that the control is tied to the
page
XPropertySet xShapeProps =
(XPropertySet)UnoRuntime.queryInterface( XPropertySet.class,
xShape );
TextContentAnchorType eAnchorType =
TextContentAnchorType.AT_PARAGRAPH;
xShapeProps.setPropertyValue(
"AnchorType", eAnchorType );
// create the form component (the model of a form control)
String sQualifiedComponentName =
"com.sun.star.form.component.CommandButton";
XControlModel xModel =
(XControlModel)UnoRuntime.queryInterface(
XControlModel.class,
xDocAsFactory.createInstance(
sQualifiedComponentName ) );
// insert the model into the form component hierarchy, if
the caller
gave us a location
if ( null != xParentForm )
{
xParentForm.insertByIndex(
xParentForm.getCount(), xModel );
}
// knitt them
xShape.setControl( xModel );
// add the shape to the shapes collection of the document
XShapes xDocShapes =
(XShapes)UnoRuntime.queryInterface(
XShapes.class, pageWhereToInsert );
xDocShapes.add( xShape );
// some initializations which are the same for all controls
XPropertySet xModelProps =
(XPropertySet)UnoRuntime.queryInterface( XPropertySet.class,
xModel );
try
{
XPropertySetInfo xPSI =
xModelProps.getPropertySetInfo();
if ( xPSI.hasPropertyByName( "Border"
) )
{
if ( ((Short)xModelProps.getPropertyValue(
"Border"
)).shortValue() == com.sun.star.awt.VisualEffect.LOOK3D )
xModelProps.setPropertyValue(
"Border", new Short(
com.sun.star.awt.VisualEffect.FLAT ) );
}
if ( xPSI.hasPropertyByName(
"VisualEffect" ) )
xModelProps.setPropertyValue(
"VisualEffect", new
Short( com.sun.star.awt.VisualEffect.FLAT ) );
}
catch( com.sun.star.uno.Exception e )
{
System.err.println(e);
e.printStackTrace( System.err );
}
System.out.println("leaving createButton");
return xModelProps;
}
// **************** createButton function end
*******************************
Please tell me what should I add or change in order to make
button
appear on the slide. I also want to hook this button with an
eventlistener, I need help with this as well. I'm working on
OOImpress
using JAVA.
Regards,
Zeeshan.
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|