xref: /trunk/main/sd/source/ui/view/drviewsh.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "DrawViewShell.hxx"
32 #include <svl/aeitem.hxx>
33 #include <svl/itemset.hxx>
34 #include <sfx2/request.hxx>
35 #ifndef _SVXIDS_HRC
36 #include <svx/svxids.hrc>
37 #endif
38 
39 
40 #include <svx/fmshell.hxx>
41 #include <sfx2/dispatch.hxx>
42 
43 #include "app.hrc"
44 #include "strings.hrc"
45 #include "sdpage.hxx"
46 #ifndef SD_FRAME_VIEW
47 #include "FrameView.hxx"
48 #endif
49 #include "sdresid.hxx"
50 #include "drawdoc.hxx"
51 #include "DrawDocShell.hxx"
52 #include "Window.hxx"
53 #include "GraphicViewShell.hxx"
54 #include "drawview.hxx"
55 
56 #include "slideshow.hxx"
57 
58 namespace sd {
59 
60 #define TABCONTROL_INITIAL_SIZE 	500
61 
62 /*************************************************************************
63 |*
64 |* Sprung zu Bookmark
65 |*
66 \************************************************************************/
67 
68 sal_Bool DrawViewShell::GotoBookmark(const String& rBookmark)
69 {
70     sal_Bool bRet = sal_False;
71     ::sd::DrawDocShell* pDocSh = GetDocSh();
72     if( pDocSh )
73     {
74         if( !pDocSh->GetViewShell() ) //#i26016# this case occurs if the jump-target-document was opened already with file open dialog before triggering the jump via hyperlink
75             pDocSh->Connect(this);
76 	    bRet = (pDocSh->GotoBookmark(rBookmark));
77     }
78     return bRet;
79 }
80 
81 /*************************************************************************
82 |*
83 |* Bereich sichtbar machen (Bildausschnitt scrollen)
84 |*
85 \************************************************************************/
86 
87 void DrawViewShell::MakeVisible(const Rectangle& rRect, ::Window& rWin)
88 {
89 	// #98568# In older versions, if in X or Y the size of the object was
90 	// smaller than the visible area, the user-defined zoom was
91 	// changed. This was decided to be a bug for 6.x, thus I developed a
92 	// version which instead handles X/Y bigger/smaller and visibility
93 	// questions seperately. The new behaviour is triggered with the
94 	// bZoomAllowed parameter which for old behaviour should be set to
95 	// sal_True. I looked at all uses of MakeVisible() in the application
96 	// and found no valid reason for really changing the zoom factor, thus I
97 	// decided to NOT expand (incompatible) this virtual method to get one
98 	// more parameter. If this is wanted in later versions, feel free to add
99 	// that bool to the parameter list.
100 	sal_Bool bZoomAllowed(sal_False);
101 	Size aLogicSize(rRect.GetSize());
102 
103 	// Sichtbarer Bereich
104 	Size aVisSizePixel(rWin.GetOutputSizePixel());
105 	Rectangle aVisArea(rWin.PixelToLogic(Rectangle(Point(0,0), aVisSizePixel)));
106 	Size aVisAreaSize(aVisArea.GetSize());
107 
108 	if(!aVisArea.IsInside(rRect) && !SlideShow::IsRunning( GetViewShellBase() ) )
109 	{
110 		// Objekt liegt nicht komplett im sichtbaren Bereich
111 		sal_Int32 nFreeSpaceX(aVisAreaSize.Width() - aLogicSize.Width());
112 		sal_Int32 nFreeSpaceY(aVisAreaSize.Height() - aLogicSize.Height());
113 
114 		if(bZoomAllowed && (nFreeSpaceX < 0 || nFreeSpaceY < 0))
115 		{
116 			// Objekt passt nicht in sichtbaren Bereich -> auf Objektgroesse zoomen
117 			SetZoomRect(rRect);
118 		}
119 		else
120 		{
121 			// #98568# allow a mode for move-only visibility without zooming.
122 			const sal_Int32 nPercentBorder(30);
123 			const Rectangle aInnerRectangle(
124 				aVisArea.Left() + ((aVisAreaSize.Width() * nPercentBorder) / 200),
125 				aVisArea.Top() + ((aVisAreaSize.Height() * nPercentBorder) / 200),
126 				aVisArea.Right() - ((aVisAreaSize.Width() * nPercentBorder) / 200),
127 				aVisArea.Bottom() - ((aVisAreaSize.Height() * nPercentBorder) / 200)
128 				);
129 			Point aNewPos(aVisArea.TopLeft());
130 
131 			if(nFreeSpaceX < 0)
132 			{
133 				if(aInnerRectangle.Left() > rRect.Right())
134 				{
135 					// object moves out to the left
136 					aNewPos.X() -= aVisAreaSize.Width() / 2;
137 				}
138 
139 				if(aInnerRectangle.Right() < rRect.Left())
140 				{
141 					// object moves out to the right
142 					aNewPos.X() += aVisAreaSize.Width() / 2;
143 				}
144 			}
145 			else
146 			{
147 				if(nFreeSpaceX > rRect.GetWidth())
148 					nFreeSpaceX = rRect.GetWidth();
149 
150 				while(rRect.Right() > aNewPos.X() + aVisAreaSize.Width())
151 					aNewPos.X() += nFreeSpaceX;
152 
153 				while(rRect.Left() < aNewPos.X())
154 					aNewPos.X() -= nFreeSpaceX;
155 			}
156 
157 			if(nFreeSpaceY < 0)
158 			{
159 				if(aInnerRectangle.Top() > rRect.Bottom())
160 				{
161 					// object moves out to the top
162 					aNewPos.Y() -= aVisAreaSize.Height() / 2;
163 				}
164 
165 				if(aInnerRectangle.Bottom() < rRect.Top())
166 				{
167 					// object moves out to the right
168 					aNewPos.Y() += aVisAreaSize.Height() / 2;
169 				}
170 			}
171 			else
172 			{
173 				if(nFreeSpaceY > rRect.GetHeight())
174 					nFreeSpaceY = rRect.GetHeight();
175 
176 				while(rRect.Bottom() > aNewPos.Y() + aVisAreaSize.Height())
177 					aNewPos.Y() += nFreeSpaceY;
178 
179 				while(rRect.Top() < aNewPos.Y())
180 					aNewPos.Y() -= nFreeSpaceY;
181 			}
182 
183 			// did position change? Does it need to be set?
184 			if(aNewPos != aVisArea.TopLeft())
185 			{
186 				aVisArea.SetPos(aNewPos);
187 				SetZoomRect(aVisArea);
188 			}
189 		}
190 	}
191 }
192 
193 }
194