Difference between revisions of "FR/Documentation/Les formes (shapes)"
SergeMoutou (Talk | contribs) m (→La Rotation de la forme et sa déformation) |
SergeMoutou (Talk | contribs) m |
||
(25 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | Nous | + | =Introduction= |
+ | Nous allons, dans ce chapitre, utiliser un nouveau code initial. Il est identique aux codes précédents mais on ajoute quelques procédures pour simplifier le code qui suivra dans ce chapitre (d'après Christian Junker [http://www.oooforum.org/forum/viewtopic.phtml?t=11128 ici]). | ||
+ | |||
+ | Commençons par les procédures en question qui utilisent les interfaces <idl>com.sun.star.drawing.XShapes</idl>, <idl>com.sun.star.drawing.XShape</idl>, <idl>com.sun.star.drawing.XDrawPage</idl> et <idl>com.sun.star.beans.XPropertySet</idl> ainsi que les structures <idl>com.sun.star.awt.Point</idl> et <idl>com.sun.star.awt.Size</idl> : | ||
<source lang="cpp"> | <source lang="cpp"> | ||
//Listing 1 | //Listing 1 | ||
Line 9: | Line 12: | ||
// Ne pas oublier la directive : #include <com/sun/star/beans/XPropertySet.hpp> | // Ne pas oublier la directive : #include <com/sun/star/beans/XPropertySet.hpp> | ||
// N'oubliez pas d'ajouter "com.sun.star.beans.XPropertySet \" in the makefile | // N'oubliez pas d'ajouter "com.sun.star.beans.XPropertySet \" in the makefile | ||
− | + | // .... | |
+ | // quelques commentaires ont été volontairement retirés | ||
+ | // .... | ||
// Christian Junker code | // Christian Junker code | ||
void MakePosition(sal_Int32 x, sal_Int32 y, ::com::sun::star::awt::Point *Pos) | void MakePosition(sal_Int32 x, sal_Int32 y, ::com::sun::star::awt::Point *Pos) | ||
Line 34: | Line 39: | ||
</source> | </source> | ||
− | Avec ces procédures nous commençons maintenant d'une forme de rectangle : notre nouveau code initial principal | + | Avec ces procédures nous commençons maintenant le dessin d'une forme de rectangle : notre nouveau code initial principal utilise un certain nombres d'interfaces <idl>com.sun.star.drawing.XDrawPagesSupplier</idl>, <idl>com.sun.star.drawing.XDrawPages</idl>, <idl>com.sun.star.beans.XIndexAccess</idl>, <idl>com.sun.star.drawing.XDrawPage</idl>, <idl>com.sun.star.drawing.XShape</idl>, <idl>com.sun.star.container.XNamed</idl> et un service <idl>com.sun.star.drawing.RectangleShape</idl>, ce qui donne : |
<source lang="cpp"> | <source lang="cpp"> | ||
//Listing 2 | //Listing 2 | ||
Line 93: | Line 98: | ||
DrawMe(rRectShape, rDrawPage, "My TextShape"); | DrawMe(rRectShape, rDrawPage, "My TextShape"); | ||
− | // | + | //**************************** |
+ | // ajouter votre code ici | ||
+ | //**************************** | ||
return 0; | return 0; | ||
} | } | ||
</source> | </source> | ||
− | Ce code dessine un rectangle coloré en bleu. | + | Ce code dessine un rectangle coloré en bleu et utilise la fonction ooConnect() déjà présentée dans ce document mais que l'on donne encore une fois : |
+ | |||
+ | {{:OOConnectFR}} | ||
+ | |||
+ | Examinons maintenant les propriétés des formes. | ||
+ | |||
=Les propriétés de la forme= | =Les propriétés de la forme= | ||
==Couleurs d'arrière plan et des formes== | ==Couleurs d'arrière plan et des formes== | ||
− | La forme est créée habituellement avec une couleur uniforme d'arrière plan par défaut. Il est naturellement possible de changer ceci. Pour comprendre comment cela fonctionne, un petit tour vers le fichier IDL <OpenOffice.org1.1_SDK>/idl/com/sun/star/drawing/fillstyle.idl nous sera nécessaire : | + | La forme est créée habituellement avec une couleur uniforme d'arrière plan par défaut. Il est naturellement possible de changer ceci. Pour comprendre comment cela fonctionne, un petit tour vers le fichier IDL <OpenOffice.org1.1_SDK>/idl/com/sun/star/drawing/fillstyle.idl nous sera nécessaire (visible aussi ici :<idl>com.sun.star.drawing.fillstyle</idl>) : |
<source lang="idl"> | <source lang="idl"> | ||
//Listing 3 Détail du fichier FillStyle.idl | //Listing 3 Détail du fichier FillStyle.idl | ||
Line 124: | Line 136: | ||
MaForme.FillStyle = com.sun.star.drawing.FillStyle.NONE | MaForme.FillStyle = com.sun.star.drawing.FillStyle.NONE | ||
</source> | </source> | ||
− | Est-ce que le FillStyle est une propriété et qu'en est-il du FillColor? Pour chercher une réponse nous retournons à un fichier IDL qui se nomme FillProperties.idl : | + | Est-ce que le FillStyle est une propriété et qu'en est-il du FillColor? Pour chercher une réponse nous retournons à un fichier IDL qui se nomme FillProperties.idl (accessible en <idl>com.sun.star.drawing.FillProperties</idl>): |
<source lang="idl"> | <source lang="idl"> | ||
//Listing 5 | //Listing 5 | ||
Line 156: | Line 168: | ||
}; }; }; }; | }; }; }; }; | ||
</source> | </source> | ||
− | Les deux premières propriétés semblent intéressantes pour nous. Nous commençons avec FillColor. Si nous ajoutons ce code nous obtenons un rectangle avec une autre couleur. | + | Les deux premières propriétés semblent intéressantes pour nous. Nous commençons avec FillColor. Si nous ajoutons ce code nous obtenons un rectangle avec une autre couleur (vert ici) en utilisant l'interface <idl>com.sun.star.beans.XPropertySet</idl>. |
<source lang="cpp"> | <source lang="cpp"> | ||
//Listing 6 | //Listing 6 | ||
Line 186: | Line 198: | ||
==Forme et Ombre== | ==Forme et Ombre== | ||
− | L'ombre est décrite par le fichier | + | L'ombre est décrite par le fichier <idl>com.sun.star.drawing.ShadowProperties</idl> que nous présentons maintenant : |
<source lang="idl"> | <source lang="idl"> | ||
//Listing 8 Fichier ShadowProperties.idl | //Listing 8 Fichier ShadowProperties.idl | ||
Line 218: | Line 230: | ||
lequel dessine une ombre rouge à la forme rectangulaire. | lequel dessine une ombre rouge à la forme rectangulaire. | ||
− | ==La | + | ==La rotation et le cisaillement de la forme== |
Pour une rotation, le fichier IDL correspondant est : | Pour une rotation, le fichier IDL correspondant est : | ||
<source lang="idl"> | <source lang="idl"> | ||
Line 242: | Line 254: | ||
rShapeProps->setPropertyValue(OUString::createFromAscii("RotateAngle"),Angle); | rShapeProps->setPropertyValue(OUString::createFromAscii("RotateAngle"),Angle); | ||
</source> | </source> | ||
+ | Rappelons pour être complet que la variable rShapeProps est une interface <idl>com.sun.star.beans.XPropertySet</idl>. | ||
+ | |||
Abordons maintenant un problème différent, celui des styles de lignes. | Abordons maintenant un problème différent, celui des styles de lignes. | ||
==Style des lignes== | ==Style des lignes== | ||
− | Les fichiers IDL correspondants sont donnés maintenant. Commençons par le fichier LineProperties.idl | + | Les fichiers IDL correspondants sont donnés maintenant : <idl>com.sun.star.drawing.LineProperties</idl>, <idl>com.sun.star.drawing.LineStyle</idl> et <idl>com.sun.star.drawing.LineDash</idl>. Commençons par le fichier LineProperties.idl |
<source lang="idl"> | <source lang="idl"> | ||
// Listing 12 Le fichier LineProperties.idl | // Listing 12 Le fichier LineProperties.idl | ||
Line 330: | Line 344: | ||
|} | |} | ||
− | Les styles en tirets sont donnés par une énumération comme le montre le fichier | + | Les styles en tirets sont donnés par une énumération comme le montre le fichier <idl>com.sun.star.drawing.DashStyle</idl> ci-dessous : |
<source lang="idl"> | <source lang="idl"> | ||
//Listing 15 Enumération définie par le fichier DashStyle.idl | //Listing 15 Enumération définie par le fichier DashStyle.idl | ||
Line 373: | Line 387: | ||
[[Image:shape1.png|center]] | [[Image:shape1.png|center]] | ||
Voir aussi <idl>com.sun.star.drawing.LineDash</idl> and <idl>com.sun.star.drawing.LineStyle</idl>. | Voir aussi <idl>com.sun.star.drawing.LineDash</idl> and <idl>com.sun.star.drawing.LineStyle</idl>. | ||
− | + | ||
=Dessiner des formes= | =Dessiner des formes= | ||
==La forme “polyligne”== | ==La forme “polyligne”== | ||
La première fois que nous abordons les polylignes il nous faut comprendre la notion de | La première fois que nous abordons les polylignes il nous faut comprendre la notion de | ||
− | Sequence < Sequence < Point >> ? Pour ce faire une description à l'aide des classiques fichiers IDL s'impose. Nous en donnons deux dans les listings | + | Sequence < Sequence < Point >> ? Pour ce faire une description à l'aide des classiques fichiers IDL s'impose. Nous en donnons deux dans les listings 17 et 18 qui suivent (<idl>com.sun.star.drawing.PointSequenceSequence</idl> et <idl>com.sun.star.drawing.PointSequence</idl>) : |
<source lang="idl"> | <source lang="idl"> | ||
//Listing 17 PointSequenceSequence IDL File | //Listing 17 PointSequenceSequence IDL File | ||
Line 393: | Line 407: | ||
}; }; }; }; | }; }; }; }; | ||
</source> | </source> | ||
− | On peut jeter un oeil dans le PolyLineShape maintenant : | + | On peut jeter un oeil dans le <idl>com.sun.star.drawing.PolyLineShape</idl> maintenant : |
<source lang="idl"> | <source lang="idl"> | ||
//Listing 19 PolyLineShape IDL File | //Listing 19 PolyLineShape IDL File | ||
Line 409: | Line 423: | ||
}; }; }; }; | }; }; }; }; | ||
</source> | </source> | ||
− | Les autres fichiers IDL fque nous avons à inspecter sont le service PolyPolygonDescriptor : | + | Les autres fichiers IDL fque nous avons à inspecter sont le service <idl>com.sun.star.drawing.PolyPolygonDescriptor</idl> : |
<source lang="idl"> | <source lang="idl"> | ||
//Listing 20 Fichier IDL du service PolyPolygonDescriptor | //Listing 20 Fichier IDL du service PolyPolygonDescriptor | ||
Line 425: | Line 439: | ||
* Construire en premier lieu une séquence de séquence de points et mettre des valeurs dedans. | * Construire en premier lieu une séquence de séquence de points et mettre des valeurs dedans. | ||
* En second lieu la transformer en un type any | * En second lieu la transformer en un type any | ||
− | * En dernier lieu utiliser l'interface | + | * En dernier lieu utiliser l'interface <idl>com.sun.star.beans.XPropertySet</idl> pour donner des valeurs à la propriété PolyPolygon. |
Cela nous conduit au final à l'exemple suivant : | Cela nous conduit au final à l'exemple suivant : | ||
<source lang="cpp"> | <source lang="cpp"> | ||
Line 463: | Line 477: | ||
[[Image:Shape2.png|center|Polyline Example]] | [[Image:Shape2.png|center|Polyline Example]] | ||
− | Si vous remplacez la forme PolyLineShape par la forme PolyPolygonShape dans le code du Listing 21 vous obtiendrez la même forme mais cette fois-ci fermée (et remplie par la couleur par défaut). | + | Si vous remplacez la forme <idl>com.sun.star.drawing.PolyLineShape</idl> par la forme <idl>com.sun.star.drawing.PolyPolygonShape</idl> dans le code du Listing 21 vous obtiendrez la même forme mais cette fois-ci fermée (et remplie par la couleur par défaut). |
==Les formes de Bezier== | ==Les formes de Bezier== | ||
− | Commençons maintenant par décrire la structure centrale de ce genre de forme, à savoir la structure PolyPolygonBezierCoords. Le fichier IDL correspondant est présenté : | + | Commençons maintenant par décrire la structure centrale de ce genre de forme, à savoir la structure <idl>com.sun.star.drawing.PolyPolygonBezierCoords</idl>. Le fichier IDL correspondant est présenté : |
<source lang="idl"> | <source lang="idl"> | ||
//Listing 22 PolyPolygonBezierCoords IDL File | //Listing 22 PolyPolygonBezierCoords IDL File | ||
Line 483: | Line 497: | ||
}; }; }; }; | }; }; }; }; | ||
</source> | </source> | ||
− | PointSequenceSequence a déjà été présenté dans la section précédente. Plus de précision sur les drapeaux (flags) est maintenant attendue par le lecteur impatient. Encore une fois, c'est un fichier IDL qui vient à notre secours : | + | <idl>com.sun.star.drawing.PointSequenceSequence</idl> a déjà été présenté dans la section précédente. Plus de précision sur les drapeaux (flags) est maintenant attendue par le lecteur impatient. Encore une fois, c'est un fichier IDL qui vient à notre secours (<idl>com.sun.star.drawing.PolygonFlags</idl>) : |
<source lang="idl"> | <source lang="idl"> | ||
//Listing 23 Fichier IDL pour l'énumération PolygonFlags | //Listing 23 Fichier IDL pour l'énumération PolygonFlags | ||
Line 497: | Line 511: | ||
}; }; }; }; | }; }; }; }; | ||
</source> | </source> | ||
− | Le service ClosedBezierShape est lui aussi intéressant : | + | Le service <idl>com.sun.star.drawing.ClosedBezierShape</idl> est lui aussi intéressant : |
<source lang="idl"> | <source lang="idl"> | ||
Listing 24 ClosedBezierShape Service : IDL File | Listing 24 ClosedBezierShape Service : IDL File | ||
Line 514: | Line 528: | ||
}; }; }; }; | }; }; }; }; | ||
</source> | </source> | ||
− | et encore le service PolyPolygonDescriptor : | + | et encore le service <idl>com.sun.star.drawing.PolyPolygonDescriptor</idl> : |
<source lang="idl"> | <source lang="idl"> | ||
Listing 25 PolyPolygonBezierDescriptor Service : IDL File | Listing 25 PolyPolygonBezierDescriptor Service : IDL File | ||
Line 527: | Line 541: | ||
}; }; }; }; | }; }; }; }; | ||
</source> | </source> | ||
− | Ce service est comme au chapitre précédent caractérisé par un ensemble de propriétés. Nous n'avons pas encore rencontré la première | + | Ce service est comme au chapitre précédent caractérisé par un ensemble de propriétés. Nous n'avons pas encore rencontré la première (<idl>com.sun.star.drawing.PolygonKind</idl>), et donc nous sommes obligés d'aller plus avant dans notre quête aux fichiers IDL : |
<source lang="idl"> | <source lang="idl"> | ||
//Listing 26 PolygonKind Enumeration : IDL File | //Listing 26 PolygonKind Enumeration : IDL File | ||
Line 608: | Line 622: | ||
("PolyPolygonBezier"), ClosedBezierProperty); | ("PolyPolygonBezier"), ClosedBezierProperty); | ||
</source> | </source> | ||
− | En lisant le fichier IDL | + | En lisant le fichier IDL <idl>com.sun.star.drawing.PolyPolygonBezierShape</idl> je déduis que je n'ai qu'à remplacer “<idl>com.sun.star.drawing.ClosedBezierShape</idl>” par “<idl>com.sun.star.drawing.PolyPolygonBezierShape</idl>" pour avoir une forme de Bezier ouverte. Mais cela ne fonctionne pas et je ne sais pas pourquoi pour le moment. Andrew Pitonyak a écrit dans son livre : “toutes les combinaisons de points et de drapeaux ne sont pas valides” et je suppose avoir une mauvaise combinaison des deux. |
Voir aussi <idl>com.sun.star.drawing.PolyPolygonBezierCoords</idl>, <idl>com.sun.star.drawing.FlagSequenceSequence</idl>, <idl>com.sun.star.drawing.FlagSequence</idl>, <idl>com.sun.star.drawing.PolygonFlags</idl> et <idl>com.sun.star.drawing.ClosedBezierShape</idl> | Voir aussi <idl>com.sun.star.drawing.PolyPolygonBezierCoords</idl>, <idl>com.sun.star.drawing.FlagSequenceSequence</idl>, <idl>com.sun.star.drawing.FlagSequence</idl>, <idl>com.sun.star.drawing.PolygonFlags</idl> et <idl>com.sun.star.drawing.ClosedBezierShape</idl> | ||
Line 618: | Line 632: | ||
= Voir aussi= | = Voir aussi= | ||
* Drawing Documents and Presentation Documents [[Documentation/DevGuide/Drawings/Drawing_Documents_and_Presentation_Documents|in Developer's Guide]] | * Drawing Documents and Presentation Documents [[Documentation/DevGuide/Drawings/Drawing_Documents_and_Presentation_Documents|in Developer's Guide]] | ||
+ | *[[FR/Documentation/BASIC_Guide/Drawings_Presentations|Dessins et présentations en OOoBasic]] | ||
* [[Uno/Cpp/Tutorials/Introduction_to_Cpp_Uno|C++ and UNO tutorial]] | * [[Uno/Cpp/Tutorials/Introduction_to_Cpp_Uno|C++ and UNO tutorial]] | ||
* Writing a Program to Control OpenOffice.org, by Franco Pingiori — [http://www.linuxjournal.com/article/8550 Part 1] and [http://www.linuxjournal.com/article/8608 Part 2], Linux Journal | * Writing a Program to Control OpenOffice.org, by Franco Pingiori — [http://www.linuxjournal.com/article/8550 Part 1] and [http://www.linuxjournal.com/article/8608 Part 2], Linux Journal | ||
+ | |||
+ | [[Category:FR/Cpp_Guide]] |
Latest revision as of 13:29, 11 May 2009
Contents
Introduction
Nous allons, dans ce chapitre, utiliser un nouveau code initial. Il est identique aux codes précédents mais on ajoute quelques procédures pour simplifier le code qui suivra dans ce chapitre (d'après Christian Junker ici).
Commençons par les procédures en question qui utilisent les interfaces com.sun.star.drawing.XShapes, com.sun.star.drawing.XShape, com.sun.star.drawing.XDrawPage et com.sun.star.beans.XPropertySet ainsi que les structures com.sun.star.awt.Point et com.sun.star.awt.Size :
//Listing 1 // C++ // Ne pas oublier la directive : #include <com/sun/star/drawing/XShapes.hpp> // N'oubliez pas d'ajouter "com.sun.star.drawing.XShapes \" in the makefile // N'oubliez pas d'ajouter : using namespace com::sun::star::beans; // Ne pas oublier la directive : #include <com/sun/star/beans/XPropertySet.hpp> // N'oubliez pas d'ajouter "com.sun.star.beans.XPropertySet \" in the makefile // .... // quelques commentaires ont été volontairement retirés // .... // Christian Junker code void MakePosition(sal_Int32 x, sal_Int32 y, ::com::sun::star::awt::Point *Pos) { Pos->X = x; Pos->Y = y; } void MakeSize(sal_Int32 width, sal_Int32 height, ::com::sun::star::awt::Size *Size) { Size->Width = width; Size->Height = height; } void DrawMe(Reference< XShape > &Shape, Reference< XDrawPage > &page, const char *shapename) { Reference< XShapes > Shapes(page, UNO_QUERY); Shapes->add(Shape); Reference< XPropertySet > shapeprops(Shape, UNO_QUERY); shapeprops->setPropertyValue(OUString::createFromAscii("Name"), makeAny(OUString::createFromAscii(shapename))); }
Avec ces procédures nous commençons maintenant le dessin d'une forme de rectangle : notre nouveau code initial principal utilise un certain nombres d'interfaces com.sun.star.drawing.XDrawPagesSupplier, com.sun.star.drawing.XDrawPages, com.sun.star.beans.XIndexAccess, com.sun.star.drawing.XDrawPage, com.sun.star.drawing.XShape, com.sun.star.container.XNamed et un service com.sun.star.drawing.RectangleShape, ce qui donne :
//Listing 2 int main( ) { //retrieve an instance of the remote service manager Reference< XMultiServiceFactory > rOfficeServiceManager; rOfficeServiceManager = ooConnect(); if( rOfficeServiceManager.is() ){ printf( "Connected sucessfully to the office\n" ); } //get the desktop service using createInstance returns an XInterface type Reference< XInterface > Desktop = rOfficeServiceManager->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" )); //query for the XComponentLoader interface Reference< XComponentLoader > rComponentLoader (Desktop, UNO_QUERY); if( rComponentLoader.is() ){ printf( "XComponentloader successfully instanciated\n" ); } //get an instance of the OOowriter document Reference< XComponent > xcomponent = rComponentLoader->loadComponentFromURL( OUString::createFromAscii("private:factory/sdraw"), OUString::createFromAscii("_blank"), 0, Sequence < ::com::sun::star::beans::PropertyValue >()); // added code here Reference< XDrawPagesSupplier > rDrawDoc(xcomponent, UNO_QUERY); // query the XDrawPages Interface Reference< XDrawPages > rDrawPages = rDrawDoc->getDrawPages(); // query the XIndexAccess Interface Reference< XIndexAccess > rPageIndexAccess(rDrawPages, UNO_QUERY); Any DrawPage = rPageIndexAccess->getByIndex(0); // Query the XDrawPage Interface Reference< XDrawPage > rDrawPage(DrawPage, UNO_QUERY); // query for the XNamed Interface Reference< XNamed > rNamed(DrawPage, UNO_QUERY); rNamed->setName(OUString::createFromAscii("My first page")); Reference< XMultiServiceFactory > DocFactory(xcomponent, UNO_QUERY); Point *Pos = new (Point); Size *TheSize = new ( Size ); Reference< XInterface > RectangleShape = DocFactory->createInstance( OUString::createFromAscii("com.sun.star.drawing.RectangleShape") ); Reference< XShape > rRectShape(RectangleShape, UNO_QUERY); MakePosition(2000, 6000, Pos); MakeSize(7000, 2000, TheSize); rRectShape->setPosition(*Pos); rRectShape->setSize(*TheSize); DrawMe(rRectShape, rDrawPage, "My TextShape"); //**************************** // ajouter votre code ici //**************************** return 0; }
Ce code dessine un rectangle coloré en bleu et utilise la fonction ooConnect() déjà présentée dans ce document mais que l'on donne encore une fois :
// Listing 0 // C++ #include <stdio.h> #include <cppuhelper/bootstrap.hxx> #include <com/sun/star/bridge/XUnoUrlResolver.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> // on ajoute la ligne ci-apres #include <com/sun/star/frame/XComponentLoader.hpp> using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::bridge; // ajouté aussi : using namespace com::sun::star::frame; using namespace rtl; using namespace cppu; // appel de la fonction de démarrage Reference< XMultiServiceFactory > ooConnect(){ // create the initial component context Reference< XComponentContext > rComponentContext = defaultBootstrap_InitialComponentContext(); // obtention du servicemanager à partir du context Reference< XMultiComponentFactory > rServiceManager = rComponentContext->getServiceManager(); // instantiate a sample service with the servicemanager. Reference< XInterface > rInstance = rServiceManager->createInstanceWithContext( OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver" ),rComponentContext ); // Query for the XUnoUrlResolver interface Reference< XUnoUrlResolver > rResolver( rInstance, UNO_QUERY ); if( ! rResolver.is() ){ printf( "Error: Couldn't instantiate com.sun.star.bridge.UnoUrlResolver service\n" ); return NULL; } try { // resolve the uno-url rInstance = rResolver->resolve( OUString::createFromAscii( "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" ) ); if( ! rInstance.is() ){ printf( "StarOffice.ServiceManager is not exported from remote counterpart\n" ); return NULL; } // query for the simpler XMultiServiceFactory interface, sufficient for scripting Reference< XMultiServiceFactory > rOfficeServiceManager (rInstance, UNO_QUERY); if( ! rOfficeServiceManager.is() ){ printf( "XMultiServiceFactory interface is not exported for StarOffice.ServiceManager\n" ); return NULL; } return rOfficeServiceManager; } catch( Exception &e ){ OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ); printf( "Error: %s\n", o.pData->buffer ); return NULL; } return NULL; }
Il serait bon de regarder aussi :
- les interfaces com.sun.star.uno.XComponentContext, com.sun.star.lang.XMultiComponentFactory, com.sun.star.uno.XInterface, com.sun.star.bridge.XUnoUrlResolver et com.sun.star.lang.XMultiServiceFactory,
- et aussi le service com.sun.star.bridge.UnoUrlResolver.
Examinons maintenant les propriétés des formes.
Les propriétés de la forme
Couleurs d'arrière plan et des formes
La forme est créée habituellement avec une couleur uniforme d'arrière plan par défaut. Il est naturellement possible de changer ceci. Pour comprendre comment cela fonctionne, un petit tour vers le fichier IDL <OpenOffice.org1.1_SDK>/idl/com/sun/star/drawing/fillstyle.idl nous sera nécessaire (visible aussi ici :com.sun.star.drawing.fillstyle) :
//Listing 3 Détail du fichier FillStyle.idl // IDL module com { module sun { module star { module drawing { enum FillStyle { NONE, SOLID, GRADIENT, HATCH, BITMAP }; }; }; }; };
Ce problème des types énumérés a déjà été abordé dans Aller plus loin avec le problème des types énumérés : nous pouvons déduire de ce fichier IDL que nos constantes dans C++ seront : FillStyle_NONE, FillStyle_SOLID,... et FillStyle_BITMAP et nous devons construire les fichiers hpp et hxx correspondants. Le deuxième problème est de savoir comment traduire ce bout de code OOoBasic :
'Listing 4 REM ***** BASIC ***** MaForme.FillColor = RGB(255,200,255) MaForme.FillStyle = com.sun.star.drawing.FillStyle.NONE
Est-ce que le FillStyle est une propriété et qu'en est-il du FillColor? Pour chercher une réponse nous retournons à un fichier IDL qui se nomme FillProperties.idl (accessible en com.sun.star.drawing.FillProperties):
//Listing 5 // IDL module com { module sun { module star { module drawing { service FillProperties { [property] com::sun::star::drawing::FillStyle FillStyle; [property] long FillColor; [property] short FillTransparence; [property] string FillTransparenceGradientName; [optional, property] com::sun::star::awt::Gradient FillTransparenceGradient; [property] string FillGradientName; [optional, property] com::sun::star::awt::Gradient FillGradient; [property] string FillHatchName; [optional, property] com::sun::star::drawing::Hatch FillHatch; [property] string FillBitmapName; [optional, property] com::sun::star::awt::XBitmap FillBitmap; [optional, property] string FillBitmapURL; [property] short FillBitmapOffsetX; [property] short FillBitmapOffsetY; [property] short FillBitmapPositionOffsetX; [property] short FillBitmapPositionOffsetY; [property] com::sun::star::drawing::RectanglePoint FillBitmapRectanglePoint; [property] boolean FillBitmapLogicalSize; [property] long FillBitmapSizeX; [property] long FillBitmapSizeY; [property] com::sun::star::drawing::BitmapMode FillBitmapMode; [property] boolean FillBackground; }; }; }; }; };
Les deux premières propriétés semblent intéressantes pour nous. Nous commençons avec FillColor. Si nous ajoutons ce code nous obtenons un rectangle avec une autre couleur (vert ici) en utilisant l'interface com.sun.star.beans.XPropertySet.
//Listing 6 // C++ // N'oubliez pas d'ajouter : using namespace com::sun::star::beans; // N'oubliez pas d'ajouter la directive : #include <com/sun/star/beans/XPropertySet.hpp> // N'oubliez pas d'ajouter "com.sun.star.beans.XPropertySet \" dans le makefile // Get the property set of the rRectShape Reference< XPropertySet > rShapeProps(rRectShape,UNO_QUERY); Any color; color<<=(long)0xFF00; //green rShapeProps->setPropertyValue(OUString::createFromAscii("FillColor"),color);
La couleur est définie en RVB (Rouge Vert Bleu) : un octet pour chaque couleur : 0xff0000 est rouge, 0x00ff00 est vert et 0x0000ff est bleu. Il est temps de changer la couleur de l'arrière plan avec la constante prédéfinie FillStyle_NONE. Cela se fait simplement en ajoutant ce code :
//Listing 7 Positionner la couleur // C++ // N'oubliez pas d'ajouter la directive : #include <com/sun/star/drawing/FillStyle.hpp> // N'oubliez pas d'ajouter "com.sun.star.drawing.FillStyle \" in the makefile Any FillStyle; FillStyle <<= FillStyle_NONE; rShapeProps->setPropertyValue(OUString::createFromAscii("FillStyle"),FillStyle);
Nous arrêtons ici mais il y a beaucoup à faire avec les autres constantes FillStyle.
Forme et Ombre
L'ombre est décrite par le fichier com.sun.star.drawing.ShadowProperties que nous présentons maintenant :
//Listing 8 Fichier ShadowProperties.idl // IDL module com { module sun { module star { module drawing { service ShadowProperties { [property] boolean Shadow; [property] long ShadowColor; [property] short ShadowTransparence; [property] long ShadowXDistance; [property] long ShadowYDistance; }; }; }; }; };
Ensuite le code correspondant en C++ pour manipuler ces propriétés peut être :
//Listing 9 Manipuler les ombres // C++ // Shadow Any ShadowProperties[4]; ShadowProperties[0] <<= (sal_Bool)true; ShadowProperties[1] <<= (long) 0xFF0000; // rouge ShadowProperties[2] <<= (long) 300; ShadowProperties[3] <<= (long) 300; rShapeProps->setPropertyValue(OUString::createFromAscii("Shadow"),ShadowProperties[0]); rShapeProps->setPropertyValue(OUString::createFromAscii("ShadowColor"),ShadowProperties[1]); rShapeProps->setPropertyValue(OUString::createFromAscii("ShadowXDistance"),ShadowProperties[2]); rShapeProps->setPropertyValue(OUString::createFromAscii("ShadowYDistance"),ShadowProperties[3]);
lequel dessine une ombre rouge à la forme rectangulaire.
La rotation et le cisaillement de la forme
Pour une rotation, le fichier IDL correspondant est :
//Listing 10 Fichier RotationDescriptor.idl // IDL module com { module sun { module star { module drawing { service RotationDescriptor { /** This is the angle for rotation of this Shape. The shape is rotated counter-clockwise around the center of the bounding box. */ [property] long RotateAngle; [optional, property] long ShearAngle; }; }; }; }; };
L'angle est donné en 1/100° commençant d'une ligne horizontale. Ainsi le code du Listing 11 ci-dessous donne une rotation de 30°.
//Listing 11 // C++ Any Angle; Angle <<= (long)3000; // 30 degres rShapeProps->setPropertyValue(OUString::createFromAscii("RotateAngle"),Angle);
Rappelons pour être complet que la variable rShapeProps est une interface com.sun.star.beans.XPropertySet.
Abordons maintenant un problème différent, celui des styles de lignes.
Style des lignes
Les fichiers IDL correspondants sont donnés maintenant : com.sun.star.drawing.LineProperties, com.sun.star.drawing.LineStyle et com.sun.star.drawing.LineDash. Commençons par le fichier LineProperties.idl
// Listing 12 Le fichier LineProperties.idl // IDL module com { module sun { module star { module drawing { service LineProperties { [property] com::sun::star::drawing::LineStyle LineStyle; [property] com::sun::star::drawing::LineDash LineDash; [property] long LineColor; [property] short LineTransparence; [property] long LineWidth; [property] com::sun::star::drawing::LineJoint LineJoint; [optional, property] string LineStartName; [optional, property] com::sun::star::drawing::PolyPolygonBezierCoords LineStart; [optional, property] com::sun::star::drawing::PolyPolygonBezierCoords LineEnd; [optional, property] boolean LineStartCenter; [optional, property] long LineStartWidth; [optional, property] boolean LineEndCenter; [optional, property] long LineEndWidth; }; }; }; }; };
Regardons maintenant le fichier LineStyle.idl : il définit une énumération qui est maintenant présentée.
//Listing 13 L'énumération LineStyle // IDL module com { module sun { module star { module drawing { enum LineStyle { NONE, SOLID, DASH }; }; }; }; };
Nous donnons la signification de ces constantes :
- styles de lignes
Constante | Signification |
NONE | La ligne est invisible |
SOLID | Ligne continue (valeur par défaut) |
DASH | Ligne en tirets; La propriété LineDash contrôle la forme du tiret |
Pour être complet, il nous faut maintenant regarder le fichier LineDash.idl qui définit une structure.
//Listing 14 Le fichier LineDash.idl // IDL module com { module sun { module star { module drawing { struct LineDash { com::sun::star::drawing::DashStyle Style; short Dots; long DotLen; short Dashes; long DashLen; long Distance; }; }; }; }; };
Regardons les significations de chacun des champs :
- lineDash properties
Propriété | Signification |
Style | Une constante ( com.sun.star.drawing.DashStyle.xxx) qui donne le style de tirets |
Dots | Combien de points |
DotLen | Longueur des points en 1/100 mm |
Dashes | Combien de tirets |
DashLen | Longueur des tirets en 1/100 mm |
Distance | distance entre les points en 1/100 mm |
Les styles en tirets sont donnés par une énumération comme le montre le fichier com.sun.star.drawing.DashStyle ci-dessous :
//Listing 15 Enumération définie par le fichier DashStyle.idl // IDL module com { module sun { module star { module drawing { enum DashStyle { RECT, ROUND, RECTRELATIVE, ROUNDRELATIVE }; }; }; }; };
Voici un exemple en C++ qui utilise le style des lignes :
//Listing 16 Exemple complet d'utilisation des styles des lignes // C++ // Line dash // N'oubliez pas d'ajouter : #include <com/sun/star/drawing/LineDash.hpp> // N'oubliez pas d'ajouter "com.sun.star.drawing.LineDash \" dans le makefile // N'oubliez pas d'ajouter : #include <com/sun/star/drawing/LineStyle.hpp> // N'oubliez pas d'ajouter "com.sun.star.drawing.LineStyle \" dans le makefile LineDash *Tirets = new (LineDash); Tirets->Style = DashStyle_RECT; Tirets->Dots = 3; Tirets->DotLen = 50; Tirets->Dashes = 2; Tirets->DashLen = 200; Tirets->Distance = 150; Any LineStyle,LineDash,LineWidth; LineStyle <<= LineStyle_DASH; rShapeProps->setPropertyValue(OUString::createFromAscii("LineStyle"),LineStyle); LineDash <<= *Tirets; rShapeProps->setPropertyValue(OUString::createFromAscii("LineDash"),LineDash); color <<= (long)0xFF00; rShapeProps->setPropertyValue(OUString::createFromAscii("LineColor"),color); LineWidth <<= (long) 50; rShapeProps->setPropertyValue(OUString::createFromAscii("LineWidth"),LineWidth);
Ajouter ce code au précédent donne cette figure :
Voir aussi com.sun.star.drawing.LineDash and com.sun.star.drawing.LineStyle.
Dessiner des formes
La forme “polyligne”
La première fois que nous abordons les polylignes il nous faut comprendre la notion de Sequence < Sequence < Point >> ? Pour ce faire une description à l'aide des classiques fichiers IDL s'impose. Nous en donnons deux dans les listings 17 et 18 qui suivent (com.sun.star.drawing.PointSequenceSequence et com.sun.star.drawing.PointSequence) :
//Listing 17 PointSequenceSequence IDL File // IDL module com { module sun { module star { module drawing { typedef sequence<PointSequence> PointSequenceSequence; }; }; }; };
Qu'est-ce alors qu'une PointSequence ?
//Listing 18 PointSequence IDL File // IDL module com { module sun { module star { module drawing { typedef sequence<com::sun::star::awt::Point> PointSequence; }; }; }; };
On peut jeter un oeil dans le com.sun.star.drawing.PolyLineShape maintenant :
//Listing 19 PolyLineShape IDL File // IDL module com { module sun { module star { module drawing { service PolyLineShape { service com::sun::star::drawing::Shape; service com::sun::star::drawing::LineProperties; service com::sun::star::drawing::PolyPolygonDescriptor; service com::sun::star::drawing::Text; service com::sun::star::drawing::ShadowProperties; service com::sun::star::drawing::RotationDescriptor; }; }; }; }; };
Les autres fichiers IDL fque nous avons à inspecter sont le service com.sun.star.drawing.PolyPolygonDescriptor :
//Listing 20 Fichier IDL du service PolyPolygonDescriptor // IDL module com { module sun { module star { module drawing { service PolyPolygonDescriptor { [readonly, property] com::sun::star::drawing::PolygonKind PolygonKind; [property] com::sun::star::drawing::PointSequenceSequence PolyPolygon; [property] com::sun::star::drawing::PointSequenceSequence Geometry; }; }; }; }; };
où nous voyons que PolyPolygon est une propriété. Ces fichiers nous permettent de tirer des règles quant à leurs utilisations.
- Construire en premier lieu une séquence de séquence de points et mettre des valeurs dedans.
- En second lieu la transformer en un type any
- En dernier lieu utiliser l'interface com.sun.star.beans.XPropertySet pour donner des valeurs à la propriété PolyPolygon.
Cela nous conduit au final à l'exemple suivant :
//Listing 21 Using a Polyline Shape // C++ Sequence< Sequence< Point > > PointsSeqSeq(2); Sequence< Point > PointsArray(4); //Size *TheSize = new ( Size ); Reference< XInterface > PolyLineShape = DocFactory->createInstance( OUString::createFromAscii("com.sun.star.drawing.PolyLineShape") ); Reference< XShape > rPolyLineShape(PolyLineShape, UNO_QUERY); MakePosition(1100, 8000, &PointsArray[0]); MakePosition(1500, 6000, &PointsArray[1]); MakePosition(1900, 8000, &PointsArray[2]); MakePosition(2300, 6000, &PointsArray[3]); PointsSeqSeq[0]=PointsArray; PointsArray.realloc(5); MakePosition(1100, 9000, &PointsArray[0]); MakePosition(1500, 7000, &PointsArray[1]); MakePosition(1900, 9000, &PointsArray[2]); MakePosition(2300, 7000, &PointsArray[3]); MakePosition(2700, 9000, &PointsArray[4]); PointsSeqSeq[1]=PointsArray; DrawMe(rPolyLineShape, rDrawPage, ""); Any PropspolyPoly; PropspolyPoly <<= PointsSeqSeq; Reference< XPropertySet > rPolyShapeProps(rPolyLineShape,UNO_QUERY); rPolyShapeProps->setPropertyValue(OUString::createFromAscii("PolyPolygon"),PropspolyPoly);
Exécuter cet exemple nous donnera la figure présentée ci-dessous.
Si vous remplacez la forme com.sun.star.drawing.PolyLineShape par la forme com.sun.star.drawing.PolyPolygonShape dans le code du Listing 21 vous obtiendrez la même forme mais cette fois-ci fermée (et remplie par la couleur par défaut).
Les formes de Bezier
Commençons maintenant par décrire la structure centrale de ce genre de forme, à savoir la structure com.sun.star.drawing.PolyPolygonBezierCoords. Le fichier IDL correspondant est présenté :
//Listing 22 PolyPolygonBezierCoords IDL File // IDL module com { module sun { module star { module drawing { struct PolyPolygonBezierCoords { // DocMerge: empty anyway com::sun::star::drawing::PointSequenceSequence Coordinates; // DocMerge: empty anyway com::sun::star::drawing::FlagSequenceSequence Flags; }; }; }; }; };
com.sun.star.drawing.PointSequenceSequence a déjà été présenté dans la section précédente. Plus de précision sur les drapeaux (flags) est maintenant attendue par le lecteur impatient. Encore une fois, c'est un fichier IDL qui vient à notre secours (com.sun.star.drawing.PolygonFlags) :
//Listing 23 Fichier IDL pour l'énumération PolygonFlags // IDL module com { module sun { module star { module drawing { enum PolygonFlags { NORMAL, SMOOTH, CONTROL, SYMMETRIC }; }; }; }; };
Le service com.sun.star.drawing.ClosedBezierShape est lui aussi intéressant :
Listing 24 ClosedBezierShape Service : IDL File // IDL module com { module sun { module star { module drawing { service ClosedBezierShape { service com::sun::star::drawing::Shape; service com::sun::star::drawing::LineProperties; service com::sun::star::drawing::FillProperties; service com::sun::star::drawing::PolyPolygonBezierDescriptor; service com::sun::star::drawing::Text; service com::sun::star::drawing::ShadowProperties; service com::sun::star::drawing::RotationDescriptor; }; }; }; }; };
et encore le service com.sun.star.drawing.PolyPolygonDescriptor :
Listing 25 PolyPolygonBezierDescriptor Service : IDL File // IDL module com { module sun { module star { module drawing { service PolyPolygonBezierDescriptor { [readonly, property] com::sun::star::drawing::PolygonKind PolygonKind; [property] com::sun::star::drawing::PolyPolygonBezierCoords PolyPolygonBezier; [property] com::sun::star::drawing::PolyPolygonBezierCoords Geometry; }; }; }; }; };
Ce service est comme au chapitre précédent caractérisé par un ensemble de propriétés. Nous n'avons pas encore rencontré la première (com.sun.star.drawing.PolygonKind), et donc nous sommes obligés d'aller plus avant dans notre quête aux fichiers IDL :
//Listing 26 PolygonKind Enumeration : IDL File // IDL module com { module sun { module star { module drawing { enum PolygonKind { /** This is the PolygonKind for a LineShape. */ LINE, /** This is the PolygonKind for a PolyPolygonShape. */ POLY, /** This is the PolygonKind for a PolyLineShape. */ PLIN, /** This is the PolygonKind for an OpenBezierShape. */ PATHLINE, /** This is the PolygonKind for a ClosedBezierShape. */ PATHFILL, /** This is the PolygonKind for an OpenFreeHandShape. */ FREELINE, /** This is the PolygonKind for a ClosedFreeHandShape. */ FREEFILL, /** This is the PolygonKind for a PolyPolygonPathShape. */ PATHPOLY, /** This is the PolygonKind for a PolyLinePathShape. */ PATHPLIN }; }; }; }; };
Notez que cette propriété est en lecture seule. Nous avons pour une fois laissé les commentaires pour comprendre les significations des valeurs pas toujours très simple à inférer à partir des seuls noms. Le code suivant est une illustration de tout cela par une courbe de Bezier fermée :
//Listing 27 Forme de Bezier fermée : un exemple // C++ // Bezier // Don't forget to add : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> // Don't forget to add "com.sun.star.drawing.PolyPolygonBezierCoords \" in the makefile struct PolyPolygonBezierCoords BezierCords; // we suppose we use the previous declarations of PointsSeqSeq and PointsArray // (previous chapter on PolyPolygonShape) : we then only realloc PointsSeqSeq.realloc(1); PointsArray.realloc(4); MakePosition(1000, 1000, &PointsArray[0]); MakePosition(3000, 4000, &PointsArray[1]); MakePosition(3000, 4000, &PointsArray[2]); MakePosition(5000, 1000, &PointsArray[3]); PointsSeqSeq[0]=PointsArray; BezierCords.Coordinates = PointsSeqSeq; // Don't forget to add : #include <com/sun/star/drawing/FlagSequenceSequence.hpp> // Don't forget to add "com.sun.star.drawing.FlagSequenceSequence \" in the makefile // Don't forget to add : #include <com/sun/star/drawing/FlagSequence.hpp> // Don't forget to add "com.sun.star.drawing.FlagSequence \" in the makefile FlagSequenceSequence flagsSeqSeq(1); FlagSequence flagsSeq(4); // Don't forget to add : #include <com/sun/star/drawing/PolygonFlags.hpp> // Don't forget to add "com.sun.star.drawing.PolygonFlags \" in the makefile flagsSeq[0] = PolygonFlags_NORMAL; flagsSeq[1] = PolygonFlags_CONTROL; flagsSeq[2] = PolygonFlags_CONTROL; flagsSeq[3] = PolygonFlags_NORMAL; flagsSeqSeq[0] = flagsSeq; BezierCords.Flags = flagsSeqSeq; // PolyPolygonBezier is a property => construct a Any type; Any ClosedBezierProperty; ClosedBezierProperty <<= BezierCords; // create the PolyPolygonBezierShape Service Reference< XInterface > closedBezierShape = DocFactory->createInstance( OUString::createFromAscii("com.sun.star.drawing.ClosedBezierShape") ); Reference< XShape > rClosedBezierShape(closedBezierShape, UNO_QUERY); if (! rClosedBezierShape.is()) printf("****Pb with Bezier\n"); DrawMe(rClosedBezierShape, rDrawPage, ""); // Adjust the properties : Reference< XPropertySet > rClosedBezierShapeProps(rClosedBezierShape,UNO_QUERY); rClosedBezierShapeProps->setPropertyValue(OUString::createFromAscii ("PolyPolygonBezier"), ClosedBezierProperty);
En lisant le fichier IDL com.sun.star.drawing.PolyPolygonBezierShape je déduis que je n'ai qu'à remplacer “com.sun.star.drawing.ClosedBezierShape” par “com.sun.star.drawing.PolyPolygonBezierShape" pour avoir une forme de Bezier ouverte. Mais cela ne fonctionne pas et je ne sais pas pourquoi pour le moment. Andrew Pitonyak a écrit dans son livre : “toutes les combinaisons de points et de drapeaux ne sont pas valides” et je suppose avoir une mauvaise combinaison des deux.
Voir aussi com.sun.star.drawing.PolyPolygonBezierCoords, com.sun.star.drawing.FlagSequenceSequence, com.sun.star.drawing.FlagSequence, com.sun.star.drawing.PolygonFlags et com.sun.star.drawing.ClosedBezierShape
Retour à la page d'accueil
Page d'accueil du développement C++ à l'aide du SDK
Voir aussi
- Drawing Documents and Presentation Documents in Developer's Guide
- Dessins et présentations en OOoBasic
- C++ and UNO tutorial
- Writing a Program to Control OpenOffice.org, by Franco Pingiori — Part 1 and Part 2, Linux Journal