xref: /trunk/main/sd/source/ui/view/drviewsh.cxx (revision 86e1cf34)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "DrawViewShell.hxx"
28 #include <svl/aeitem.hxx>
29 #include <svl/itemset.hxx>
30 #include <sfx2/request.hxx>
31 #ifndef _SVXIDS_HRC
32 #include <svx/svxids.hrc>
33 #endif
34 
35 
36 #include <svx/fmshell.hxx>
37 #include <sfx2/dispatch.hxx>
38 
39 #include "app.hrc"
40 #include "strings.hrc"
41 #include "sdpage.hxx"
42 #ifndef SD_FRAME_VIEW
43 #include "FrameView.hxx"
44 #endif
45 #include "sdresid.hxx"
46 #include "drawdoc.hxx"
47 #include "DrawDocShell.hxx"
48 #include "Window.hxx"
49 #include "GraphicViewShell.hxx"
50 #include "drawview.hxx"
51 
52 #include "slideshow.hxx"
53 
54 namespace sd {
55 
56 #define TABCONTROL_INITIAL_SIZE 	500
57 
58 /*************************************************************************
59 |*
60 |* Sprung zu Bookmark
61 |*
62 \************************************************************************/
63 
GotoBookmark(const String & rBookmark)64 sal_Bool DrawViewShell::GotoBookmark(const String& rBookmark)
65 {
66     sal_Bool bRet = sal_False;
67     ::sd::DrawDocShell* pDocSh = GetDocSh();
68     if( pDocSh )
69     {
70         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
71             pDocSh->Connect(this);
72 	    bRet = (pDocSh->GotoBookmark(rBookmark));
73     }
74     return bRet;
75 }
76 
77 /*************************************************************************
78 |*
79 |* Bereich sichtbar machen (Bildausschnitt scrollen)
80 |*
81 \************************************************************************/
82 
MakeVisible(const Rectangle & rRect,::Window & rWin)83 void DrawViewShell::MakeVisible(const Rectangle& rRect, ::Window& rWin)
84 {
85 	// #98568# In older versions, if in X or Y the size of the object was
86 	// smaller than the visible area, the user-defined zoom was
87 	// changed. This was decided to be a bug for 6.x, thus I developed a
88 	// version which instead handles X/Y bigger/smaller and visibility
89 	// questions separately. The new behaviour is triggered with the
90 	// bZoomAllowed parameter which for old behaviour should be set to
91 	// sal_True. I looked at all uses of MakeVisible() in the application
92 	// and found no valid reason for really changing the zoom factor, thus I
93 	// decided to NOT expand (incompatible) this virtual method to get one
94 	// more parameter. If this is wanted in later versions, feel free to add
95 	// that bool to the parameter list.
96 	sal_Bool bZoomAllowed(sal_False);
97 	Size aLogicSize(rRect.GetSize());
98 
99 	// Sichtbarer Bereich
100 	Size aVisSizePixel(rWin.GetOutputSizePixel());
101 	Rectangle aVisArea(rWin.PixelToLogic(Rectangle(Point(0,0), aVisSizePixel)));
102 	Size aVisAreaSize(aVisArea.GetSize());
103 
104 	if(!aVisArea.IsInside(rRect) && !SlideShow::IsRunning( GetViewShellBase() ) )
105 	{
106 		// Objekt liegt nicht komplett im sichtbaren Bereich
107 		sal_Int32 nFreeSpaceX(aVisAreaSize.Width() - aLogicSize.Width());
108 		sal_Int32 nFreeSpaceY(aVisAreaSize.Height() - aLogicSize.Height());
109 
110 		if(bZoomAllowed && (nFreeSpaceX < 0 || nFreeSpaceY < 0))
111 		{
112 			// Objekt passt nicht in sichtbaren Bereich -> auf Objektgroesse zoomen
113 			SetZoomRect(rRect);
114 		}
115 		else
116 		{
117 			// #98568# allow a mode for move-only visibility without zooming.
118 			const sal_Int32 nPercentBorder(30);
119 			const Rectangle aInnerRectangle(
120 				aVisArea.Left() + ((aVisAreaSize.Width() * nPercentBorder) / 200),
121 				aVisArea.Top() + ((aVisAreaSize.Height() * nPercentBorder) / 200),
122 				aVisArea.Right() - ((aVisAreaSize.Width() * nPercentBorder) / 200),
123 				aVisArea.Bottom() - ((aVisAreaSize.Height() * nPercentBorder) / 200)
124 				);
125 			Point aNewPos(aVisArea.TopLeft());
126 
127 			if(nFreeSpaceX < 0)
128 			{
129 				if(aInnerRectangle.Left() > rRect.Right())
130 				{
131 					// object moves out to the left
132 					aNewPos.X() -= aVisAreaSize.Width() / 2;
133 				}
134 
135 				if(aInnerRectangle.Right() < rRect.Left())
136 				{
137 					// object moves out to the right
138 					aNewPos.X() += aVisAreaSize.Width() / 2;
139 				}
140 			}
141 			else
142 			{
143 				if(nFreeSpaceX > rRect.GetWidth())
144 					nFreeSpaceX = rRect.GetWidth();
145 
146 				while(rRect.Right() > aNewPos.X() + aVisAreaSize.Width())
147 					aNewPos.X() += nFreeSpaceX;
148 
149 				while(rRect.Left() < aNewPos.X())
150 					aNewPos.X() -= nFreeSpaceX;
151 			}
152 
153 			if(nFreeSpaceY < 0)
154 			{
155 				if(aInnerRectangle.Top() > rRect.Bottom())
156 				{
157 					// object moves out to the top
158 					aNewPos.Y() -= aVisAreaSize.Height() / 2;
159 				}
160 
161 				if(aInnerRectangle.Bottom() < rRect.Top())
162 				{
163 					// object moves out to the right
164 					aNewPos.Y() += aVisAreaSize.Height() / 2;
165 				}
166 			}
167 			else
168 			{
169 				if(nFreeSpaceY > rRect.GetHeight())
170 					nFreeSpaceY = rRect.GetHeight();
171 
172 				while(rRect.Bottom() > aNewPos.Y() + aVisAreaSize.Height())
173 					aNewPos.Y() += nFreeSpaceY;
174 
175 				while(rRect.Top() < aNewPos.Y())
176 					aNewPos.Y() -= nFreeSpaceY;
177 			}
178 
179 			// did position change? Does it need to be set?
180 			if(aNewPos != aVisArea.TopLeft())
181 			{
182 				aVisArea.SetPos(aNewPos);
183 				SetZoomRect(aVisArea);
184 			}
185 		}
186 	}
187 }
188 
189 }
190