Page 1 of 1

Keyboard shortcut to zoom in and out

Posted: Tue Jan 31, 2012 3:00 pm
by rdr713
I want a keyboard shortcut to zoom in and out of spreadsheets, so I did this:

Tools>Customize>Keyboard
Selected Shortcut keys:Ctrl+Shift+I, Category:View, Function:Zoom In, then "Modify"
Selected Shortcut keys:Ctrl+Shift+O, Category:View, Function:Zoom Out, then "Modify"
Selected "Okay"

I thought this would allow me to zoom in with Ctrl+Shift+I and zoom out with Ctrl+Shift+O, but nothing happens when I press those key combinations. What did I do wrong and how do I fix it?

Robert

Re: Keyboard shortcut to zoom in and out

Posted: Tue Jan 31, 2012 3:15 pm
by floris v

Re: Keyboard shortcut to zoom in and out

Posted: Tue Jan 31, 2012 3:48 pm
by rdr713
My problem has not been solved, that's why I posted it here. I don't understand: what made you think it had been solved?

Re: Keyboard shortcut to zoom in and out

Posted: Tue Jan 31, 2012 3:50 pm
by RoryOF
It is good manners to link to your other postings on the same subject, so that a Solved query can readily be found if there is a solution.
 Edit: Try pulling the zoom slider, bottom right of screen. 

Re: Keyboard shortcut to zoom in and out

Posted: Tue Jan 31, 2012 3:54 pm
by floris v
I didn't tag is as solved, did I?

Re: Keyboard shortcut to zoom in and out

Posted: Tue Jan 31, 2012 4:04 pm
by rdr713
I don't know about tagging, but you wrote, "If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar." But I see now that you apparently add that to every comment you post.

To RoryOF's suggestion about dragging the zoom slider: if you can tell me how to do that with a single combination keystroke then my problem will be solved and I can execute floris_v's instructions regarding solved issues.

Re: Keyboard shortcut to zoom in and out

Posted: Tue Jan 31, 2012 4:05 pm
by floris v
That's in my signature. It's merely a reminder. And lots of people don't act on it, anyway. :(

Re: Keyboard shortcut to zoom in and out

Posted: Tue Jan 31, 2012 4:22 pm
by RoryOF
In Andrew Pitonyak's document on OpenOffice Macros, in table 211 he gives hooks to zoom properties of the current document. It may be that you will need to write a macro to engage with these properties, then assign the Zoom up and Zoom down macros to shortcut keys. The starting point for OpenOffice macros is Andrew's document
http://www.pitonyak.org/OOME_3_0.odt
it is not a trivial read. There are other recensions of this (and similar information) on his site.

Re: Keyboard shortcut to zoom in and out

Posted: Tue Jan 31, 2012 4:36 pm
by floris v
More to the point: Can anyone confirm that the Zoom in and Zoom out items that you can link to keyboard shortcuts in the Tools - Customize section don't work? Wait, this thread is about the same problem. Apparently it hasn't been linked to an issue report.

Re: Keyboard shortcut to zoom in and out

Posted: Tue Jan 31, 2012 5:17 pm
by Hagar Delest
+1. Can't set a shortcut to zoom in/out.
Definitively a bug.

Re: Keyboard shortcut to zoom in and out

Posted: Tue Jan 31, 2012 6:10 pm
by Robert Tucker
No, I can't get the zoom in or out to work assigning keyboard shortcuts on LibreOffice 3.4.4 on Fedora 16; tried when I saw the first two posts on the other forum.

Re: Keyboard shortcut to zoom in and out

Posted: Wed Feb 01, 2012 2:41 am
by qaz1qaz1qa
I have assigned Zoom in, Zoom out to all kinds of keys and there is no responce.
Zoom,Scale Screen Display (apparently same thing as zoom) Does Work
It is possible to record a macro that will do what you want.
After recording a macro I placed it under MY MACRO and called it ZOOMIN

I got the following code

Code: Select all

rem ----------------------------------------------------------------------
dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Zoom.Value"
args1(0).Value = 87   '<---This Value can be changed
args1(1).Name = "Zoom.ValueSet"
args1(1).Value = 28703
args1(2).Name = "Zoom.Type"
args1(2).Value = 0

dispatcher.executeDispatch(document, ".uno:Zoom", "", 0, args1())


end sub
I copied the code and pasted it into a new macro sheet named Zoomout and change the value noted above to a smaller number.

I then opened Tools > Customize > Keyboard >
Category + OpenOffice.OrgMacro + User + Zoomin and assigned it to the keyboard.
Ditto Zoom out.
Wala
Not sure if this does all that you want but you get the idea.

Was not that time consuming or just use the code above.

Re: Keyboard shortcut to zoom in and out

Posted: Sun Sep 02, 2012 5:02 am
by xerostomus
You may try this macros. Just link keyboard shortuts with macros ZoomIn or ZoomOut

Code: Select all

sub ZoomIn( )
Zoom(5)
end sub

sub ZoomOut( )
Zoom(-5)
end sub


function Zoom(SStep as Integer)
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
Maginfication= thiscomponent.currentcontroller.viewsettings.zoomvalue() 'get current zoom
Magnification = Magnification + SStep 
if (Magnification < 20) then Magnification =20 'controls limits of zoom
if (Magnification >600) then Magnification =600

dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Zoom.Value"
args1(0).Value = Magnification
args1(1).Name = "Zoom.ValueSet"
args1(1).Value = 28703
args1(2).Name = "Zoom.Type"
args1(2).Value = 0
dispatcher.executeDispatch(document, ".uno:Zoom", "", 0, args1())
end function

Re: Keyboard shortcut to zoom in and out

Posted: Sun Sep 02, 2012 4:00 pm
by acknak
Just for the record, there is a standard shortcut included, although it's not strictly a keyboard shortcut: Ctrl+Mousewheel changes the zoom.

Re: Keyboard shortcut to zoom in and out

Posted: Tue Sep 04, 2012 7:22 pm
by pahmer
Xerostamus, thanks for the code, but I'm getting 0 for the Magnification each time. Any idea what I'm doing wrong? I simply copied your whole code.

Re: Keyboard shortcut to zoom in and out

Posted: Tue Sep 04, 2012 8:06 pm
by Villeroy
Replace this line

Code: Select all

Maginfication= thiscomponent.currentcontroller.viewsettings.zoomvalue()
with these 3 lines:

Code: Select all

sv = thiscomponent.currentcontroller.viewdata
av = split(sv,"/")
Magnification = cInt(av(0))

Re: Keyboard shortcut to zoom in and out

Posted: Tue Sep 04, 2012 9:20 pm
by peterroots
Looking at LO bugs I found this https://bugs.freedesktop.org/show_bug.cgi?id=45705 which I have added a bit to

Re: Keyboard shortcut to zoom in and out

Posted: Wed Sep 05, 2012 5:31 pm
by pahmer
Villeroy, your code fix didn't work for me, but I DID get it to work thanks to your code with a few tweaks:

sv = thiscomponent.currentcontroller.viewdata
av = split(sv,";")
Magnification = cInt(av(2))

The viewdata string is parsed by semicolons, rather than slashes, and the the current zoom factor is in the third position of the array.

I'm so pleased that this worked, since I have been hunting this topic for many months, and I once found a nice, elegant macro that worked, but I lost it in an upgrade, and I can no longer find the post that contained it, but this thread is an example of the forum at its best!

Thanks, xerostomus and Villeroy!

Re: Keyboard shortcut to zoom in and out

Posted: Wed Sep 05, 2012 5:53 pm
by Villeroy
You posted in the Calc forum.
This instruction by xerostomus works perfectly well with Writer: Maginfication= thiscomponent.currentcontroller.viewsettings.zoomvalue()
your split(sv,";") works with Writer too.

Calc has no viewsettings. Calc has a ViewData string joined by slashes and the first element is the zoom. I tested this with a spreadsheet view.

In Impress and Draw ZoomValue is a direct property of the controller.

Re: Keyboard shortcut to zoom in and out

Posted: Wed Sep 05, 2012 6:01 pm
by pahmer
I just tried it with calc also, and discovered my error! I was using Writer, as you pointed out. Sorry! Thanks for the lesson as well.

Re: Keyboard shortcut to zoom in and out

Posted: Tue Jul 02, 2013 1:23 pm
by xerostomus
I bring the lates working version for Calk and Write.
:-)
xerostomus

Code: Select all

sub ZoomIn( )
Zoom(3)
end sub

sub ZoomOut( )
Zoom(-3)
end sub


function Zoom(SStep as Integer)
'this is for Libreoffice Write
rem ----------------------------------------------------------------------
rem define variables
dim Magnification as Integer
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
Magnification = thiscomponent.currentcontroller.viewsettings.zoomvalue() 
 	Magnification = Magnification + SStep
if (Magnification < 20) then Magnification = 20
'restore counting from 100
if ((Magnification > (100-abs(sstep))) and (Magnification < (100+abs(sstep)))) then Magnification =100
if (Magnification >600) then Magnification =600
'statusbar	
ThisComponent.CurrentController.StatusIndicator.setText("Magnification: " + Magnification)
'print typename(magnification)

'- new 2013-07-02 ------------------------------------------------------------
dim args3(3) as new com.sun.star.beans.PropertyValue
args3(0).Name = "ZoomSlider.CurrentZoom"
args3(0).Value = magnification
args3(1).Name = "ZoomSlider.SnappingPoints"
args3(1).Value = Array()
args3(2).Name = "ZoomSlider.SvxMinZoom"
args3(2).Value = 20
args3(3).Name = "ZoomSlider.SvxMaxZoom"
args3(3).Value = 600

dispatcher.executeDispatch(document, ".uno:ZoomSlider", "", 0, args3())
end function

sub Zoom_calc_In( )
Zoom_calc(3)
end sub

sub Zoom_calc_Out( )
Zoom_calc(-3)
end sub


function Zoom_calc(SStep as Integer)
'this is for Libreoffice Calc
rem ----------------------------------------------------------------------
rem define variables
dim Magnification as Integer
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
	sv = thiscomponent.currentcontroller.viewdata
	av = split(sv,"/")
	Magnification = cInt(av(0))
 	Magnification = Magnification + SStep
if (Magnification < 20) then Magnification =20
'restore counting from 100
if ((Magnification > (100-abs(sstep))) and (Magnification < (100+abs(sstep)))) then Magnification =100
if (Magnification >600) then Magnification =600
'statusbar
ThisComponent.CurrentController.StatusIndicator.setText("Magnification: " + Magnification)
'print typename(magnification)

'- new 2013-07-02 -----------------------------------------------------
dim args1(3) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ZoomSlider.CurrentZoom"
args1(0).Value = Magnification
args1(1).Name = "ZoomSlider.SnappingPoints"
args1(1).Value = Array()
args1(2).Name = "ZoomSlider.SvxMinZoom"
args1(2).Value = 20
args1(3).Name = "ZoomSlider.SvxMaxZoom"
args1(3).Value = 600

dispatcher.executeDispatch(document, ".uno:ZoomSlider", "", 0, args1())

end function

Re: Keyboard shortcut to zoom in and out

Posted: Sun Mar 02, 2014 3:11 pm
by xerostomus
There works following command in Calc too:
Magnification = ThisComponent.getCurrentController().getPropertyValue( "ZoomValue" )
instead of these lines in previeous macro:
sv = thiscomponent.currentcontroller.viewdata
av = split(sv,"/")
Magnification = cInt(av(0))

Re: Keyboard shortcut to zoom in and out

Posted: Mon Mar 20, 2017 5:12 pm
by daniloperetti
OH! Thank you :bravo: because I had the same problem and this post solved!

I needed this after using Chrome and Firefox, so I'm used to using the zoom!!!

Congratulations!

Re: Keyboard shortcut to zoom in and out

Posted: Tue Mar 16, 2021 2:22 pm
by visthespoon
Wow, really useful. long have I pulled my hair out at the lack of built in Zoom keys. So good to finally find this. Still can't believe there actually isn't one built in, and a you can't do the mousewheel shortcut with a laptop - I tried on the mousepad, but no dice.

Word of warning to noobs - I managed to competely overwrite all my existing macros as I had no idea how the macro code file worked. look into how to do it before just copying this code in ! but once it's in, it works a treat :)

https://neowiki.neooffice.org/index.php/Using_Macros