Hello,

As proof of concept, I'd like to add new toolbars (first in Writer, later in other applications). The problem is, I'm not sure to do that the right way. Of course, this can seriously be improved, but what I need is a proof of concept, not a final product for the moment

First, I created e.g. writercycle2.xml, writercycle3.xml, two custom toolbars. Putting those .xml file in sw/uiconfig/swriter/toolbar, they are correctly packaged, and bundled. No problem with that.


*Question 1* : shall I register those new toolbar. e.g. in framework/ collector/cmduicollector.cxx or somewhere else ? (currently : I didn't register them, since they are automagically packaged in postprocess, but maybe this is not sufficient)


For Writer, the choice was to modify WriterWindowState.xcu , located in org/openoffice/Office/UI path

The idea is to display only one between 3 toolbars :

- writercycle2.xml for the Beginner level
- writercycle3.xml for the Average level
- standardbar.xml (already existing), for the Expert level

... means have only the "Visible" property == true, in same time for one toolbar only, while the other have false (e.g. writercycle2 and writercycle3 have Visible=false, standardbar has visible == true, when the "Expert" level is checked).


In the code (in svx/source/cui/optgdlg.cxx), I proceeed as follow, e.g. for the getToolbarState (the setter is similar)


static const OUString sULConfigSrvc( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.configuration.ConfigurationProvider" ) ); static const OUString sULAccessSrvc( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.configuration.ConfigurationUpdateAccess" ) );

/* adapt the toolbars to the level */

// The standard toolbar
static const OUString sStandardbarToolbarNode ( RTL_CONSTASCII_USTRINGPARAM( "/ org.openoffice.Office.UI.WriterWindowState/UIElements/States/ private:resource/toolbar/standardbar" ) );

// Writer toolbars
static const OUString sWriterCycle2ToolbarNode ( RTL_CONSTASCII_USTRINGPARAM( "/ org.openoffice.Office.UI.WriterWindowState/UIElements/States/ private:resource/toolbar/writercycle2" ) ); static const OUString sWriterCycle3ToolbarNode ( RTL_CONSTASCII_USTRINGPARAM( "/ org.openoffice.Office.UI.WriterWindowState/UIElements/States/ private:resource/toolbar/writercycle3" ) );



//*Question 2* : is the path above correct ? WriterWindowState does contain the nodes, themselves containing the property "Visible" (see below), I'd like to set as true/false, as an OUString (is the type correct btw, because the .xcs is not clear about that ?)


// Visible property
static const OUString sToolbarPropertyNameVisible( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) ) );


I pasted the getter below. The problem is, there is no crash, but it does not work,, I don't see why an exception is caught. The line causing that is : Reference< XNameAccess > xConfigAccess( Reference< XNameAccess > (xConfigProvider->createInstanceWithArguments( sULAccessSrvc, aArgs ), UNO_QUERY ));


*Question 3*: is something obviously wrong ? Is the WriterWindowState in read only mode ? ( or lazy_write ? )

*Question 4* : I was searching with OpenGrok since yesterday, and the most usefull example I found, is windowstateconfiguration.cxx (located in framework/source/uiconfiguration), but the interface is not public, so, looks like a bad track :-/ Is there something usefull on tools ?

*Question 5* : I'd like to see the toolbar change *immediately* visible, i.e. without the need to relaunch the office. How proceed ? Which event, signal has to be sent ? and is there an example in the code I could reuse ? Any idea or suggestion ?



Must be obvious, but any hint would help me a lot. Thanks a lot in advance !!

Eric Bachard



#ifdef DEBUG
static OUString getToolbarState( const OUString saGetToolbarNode )
{
    // Helpfull for debugging
OUString sToolbarValueContent = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "not found" ) ); OUString aString = saGetToolbarNode; // e.g. WriterCycle2ToolbarNode or WriterCycle3ToolbarNode

fprintf( stderr, " Argument : %s in %s \n\n",dbg_dump(aString), __func__ );
    try
    {
        // get service provider
Reference< XMultiServiceFactory > xSMgr ( vcl::unohelper::GetMultiServiceFactory() );
        // create configuration hierachical access name
        if( xSMgr.is() )
        {
            fprintf ( stderr, "XMultiServiceFactory xSMgr created \n\n");
            try
            {
                Reference< XMultiServiceFactory > xConfigProvider(
                    Reference< XMultiServiceFactory >(
                        xSMgr->createInstance( sULConfigSrvc ),
                        UNO_QUERY )
                    );
                if( xConfigProvider.is() )
                {

                    fprintf ( stderr, "xConfigProvider created \n\n");

                    Sequence< Any > aArgs(1);
                    PropertyValue aVal;
aVal.Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "nodepath" ) );
                    aVal.Value <<= saGetToolbarNode;

                    aArgs.getArray()[0] <<= aVal;
                    Reference< XNameAccess > xConfigAccess(
                        Reference< XNameAccess >(
xConfigProvider- >createInstanceWithArguments( sULAccessSrvc, aArgs ), UNO_QUERY )
                        );

fprintf ( stderr, "xConfigAccess.is() value is : %d \n\n", xConfigAccess.is() );

                    if( xConfigAccess.is() )
                    {

fprintf ( stderr, "xConfigAccess.is() is true \n\n");
                        try
                        {
                            OUString bValue;
Any aAny = xConfigAccess->getByName ( sToolbarPropertyNameVisible );
                            if( aAny >>= bValue )
                            {
fprintf ( stderr, "aAny >>= bValue was successfull \n\n");
                                sToolbarValueContent = bValue;
fprintf( stderr, " Argument : %s in % s \n\n",dbg_dump(bValue), __func__ );
                            }
                        }
                        catch( NoSuchElementException& )
                        {
                        }
                        catch( WrappedTargetException& )
                        {
                        }
                    }
                }
            }
            catch( Exception& )
            {
            }
        }
    }
    catch( WrappedTargetException& )
    {
    }
    return sToolbarValueContent;
}

#endif


--
qɔᴉɹə




Reply via email to