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

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
ZENQC
Posts: 2
Joined: Tue Apr 11, 2023 2:31 pm

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

Post 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 3142 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 !
Last edited by Hagar Delest on Tue Apr 11, 2023 10:38 pm, edited 1 time in total.
LibreOffice 7.5.2 Windows 10
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Disable items from Toolbar with C++ sdk

Post 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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
ZENQC
Posts: 2
Joined: Tue Apr 11, 2023 2:31 pm

Re: Disable items from Toolbar with C++ sdk

Post 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
LibreOffice 7.5.2 Windows 10
dom19191
Posts: 6
Joined: Sat Apr 08, 2023 12:45 am

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

Post 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;
		}
	}           
}
LibreOffice 7.5.2 WINDOWS
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

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

Post 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




Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply