You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openoffice.apache.org by lou ql <lo...@gmail.com> on 2012/08/27 10:47:29 UTC

[HELP]usage of XIndexReplace.replaceByIndex()?

I'm using UNO API to set graphic bullet for a piece of text in SD, the
graphic is from gallery "Bullets".

There are 62 gif graphics in gallery "Bullets", and I set them as the
bullet graphic one by one. Most work fine, but the last 3 gif graphics
fails: the value of GraphicURL is
vnd.sun.star.GraphicObject:00000000000000000000000000000000 after
"replaceByIndex", but not the value I set.

Then I tried use only the last 4 gif graphics as parameters then run again,
all work...

 setGraphicBullets(String inputUniqueID){
       Object numberingrules =
m_xtextProps.getPropertyValue("NumberingRules");
        XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
                 XIndexReplace.class, numberingrules);

        PropertyValue[] props = new PropertyValue[3];
        props[0] = new PropertyValue();
        props[0].Name = "NumberingType";
        props[0].Value = new Short(NumberingType.BITMAP );

        props[1] = new PropertyValue();
        props[1].Name = "GraphicURL";
        props[1].Value = "vnd.sun.star.GraphicObject:"+inputUniqueID;

        props[2] = new PropertyValue();
        props[2].Name = "GraphicSize";
        props[2].Value = new Size(500,500);

//        set numberingType
        xReplace.replaceByIndex(0, props);
*//failure: for the last 3 gifs, after this, I tried to get the GraphicURL
value, it's vnd.sun.star.GraphicObject:00000000000000000000000000000000*

        m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
      //set numbering level to 0
        m_xtextProps.setPropertyValue("NumberingLevel", new
Short((short)0));
}

the parameter "inputUniqueID" is the uniqueID of the gallery items in
"Bullets" theme:
String[] getUniqueID()
{
        Object ogalleryThemeProvider =
app.getServiceFactory().createInstance("com.sun.star.gallery.GalleryThemeProvider");
        XGalleryThemeProvider xgalleryThemeProvider =
(XGalleryThemeProvider)UnoRuntime.queryInterface(XGalleryThemeProvider.class,
ogalleryThemeProvider);

        //get the "Bullets" theme
        Object bulletTheme = xgalleryThemeProvider.getByName("Bullets");
        XGalleryTheme xbulletTheme =
(XGalleryTheme)UnoRuntime.queryInterface(XGalleryTheme.class, bulletTheme);

        //get the items in "Bullets" theme one by one, set as parameter
        int count = xbulletTheme.getCount();
        String[] uniqueID = new String[count];
        for(int i=0; i<count;i++)
        {
//            if(i<58) continue;

            Object galleryItem = xbulletTheme.getByIndex(i);
            XGalleryItem xGalleryItem =
(XGalleryItem)UnoRuntime.queryInterface(XGalleryItem.class, galleryItem);
            XPropertySet galleryItemPro = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xGalleryItem);
            String URL = (String)galleryItemPro.getPropertyValue("URL");
            Object graphic = galleryItemPro.getPropertyValue("Graphic");

            XGraphic xgraphic =
(XGraphic)UnoRuntime.queryInterface(XGraphic.class, graphic);

            Object graphicObj =
app.getServiceFactory().createInstance("com.sun.star.graphic.GraphicObject");
            XGraphicObject xgraphicObj =
(XGraphicObject)UnoRuntime.queryInterface(XGraphicObject.class, graphicObj);
            xgraphicObj.setGraphic(xgraphic);

            uniqueID[i] = xgraphicObj.getUniqueID();
        }
       return uniqueID;
}
-- 
Regards,
Lou QingLe