Page 1 of 1

[Solved] Disable items from toolbar with C++ SDK

Posted: Tue Apr 11, 2023 2:43 pm
by ZENQC
Hi !

I try to find a way to disable buttons ( items ) from the toolbar using the C++ sdk. Between the red lines are items that I may want to remove/hide.
bar.jpg
bar.jpg (38.83 KiB) Viewed 6312 times
I've looked at this topic and I think it's gonna be similar.

For now I have something like this :

Code: Select all

                Reference<XLayoutManager> xLayoutManager;
                {
	                Reference< XPropertySet > xPropSet(xFrame, UNO_QUERY);                
	                xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("LayoutManager"))) >>= xLayoutManager;
                }

                Sequence<Reference<XUIElement>> elements = xLayoutManager->getElements();

                for (auto & e : elements)
                {
	                OUString url = e.get()->getResourceURL();

                    if (url == "private:resource/toolbar/standardbar")
	                {

                        Reference<css::drawing::framework::XToolBar> bar(e, UNO_QUERY_THROW);

                    }
I am not sure if the toolbar is called the standard bar thought and I don't know how to access items from there.

Thanks in advance !

Re: Disable items from Toolbar with C++ sdk

Posted: Tue Apr 11, 2023 4:10 pm
by JeJe
I suggest downloading Useful "Macro Information For OpenOffice.org2 By Andrew Pitonyak. Its for Basic, but there's plenty of toolbar code in there and you can see how to modify a toolbar with it.

Re: Disable items from Toolbar with C++ sdk

Posted: Tue Apr 11, 2023 9:31 pm
by ZENQC
Hey JeJe!

Thank you for the quick reply ! I got it and it is indeed really useful, I should be ok from now on. :D

Thanks

Re: [Solved] Disable items from Toolbar with C++ sdk

Posted: Thu Apr 13, 2023 1:06 am
by dom19191
Hi JeJe !

I see this post ... and it similar to my post viewtopic.php?t=109793&hilit=sdk

When you use 'getSettings', it creates some artifacts in the other instance.

Do you know how to access the Toolbar Object using a similar API to the MenuBar?
I tried using the MRI tool, but I was unable to pass through the objects.

Code: Select all

Reference<XLayoutManager> xLayoutManager;
{
	Reference< XPropertySet > xPropSet(xFrame, UNO_QUERY);                
	xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("LayoutManager"))) >>= xLayoutManager;
}

Sequence<Reference<XUIElement>> elements = xLayoutManager->getElements();

for (auto & e : elements)
{
	OUString url = e.get()->getResourceURL();

	if (url == "private:resource/toolbar/standardbar")
	{
		Reference<XMenuBar> xMenuBar; <<--- XToolBar ????
		{
			Reference< XPropertySet > xPropSet(e, UNO_QUERY);                
			xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("XMenuBar"))) >>= xMenuBar;
		}
	}           
}

Re: [Solved] Disable items from Toolbar with C++ sdk

Posted: Thu Apr 13, 2023 1:45 am
by JeJe
@ dom19191

Here's some Basic code I have to hide the first 3 items on the Findbar. Works for me in OO.

Code: Select all

Function Hidefirst3FindbarButtons()

lm = thiscomponent.currentcontroller.frame.layoutmanager
for i = 0 to ubound(lm.elements)
if instr(1, lm.elements(i).ResourceURL,"/findbar") then
settings = lm.elements(i).getsettings(true)

for j = 0 to 2
settings.replacebyindex j,ReplaceToolbarItem( settings.getbyindex(j), "IsVisible",false)
next

lm.elements(i).setsettings settings

lm.elements(i).updatesettings
exit for
end if
next

End function



Function ReplaceToolbarItem( toolbaritem, iname, newvalue ) 'as Variant
dim found as boolean,ub as long

ub = ubound(toolbaritem)
for i = 0 to ub
if 	ToolbarItem(i).Name = iname then
 	ToolbarItem(i).Value = newvalue
 	
found = true

exit for
end if
next

if found = false then
ub=ub+1
redim preserve toolbaritem(ub)
toolbaritem(ub).name = iname
toolbaritem(ub).value = newvalue
end if

	ReplaceToolbarItem=toolbaritem
	
End Function