xref: /aoo41x/main/sw/source/core/draw/dpage.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_sw.hxx"
30 #include <basic/basmgr.hxx>
31 #include <svtools/imapobj.hxx>
32 #include <svl/urihelper.hxx>
33 #include <unotools/securityoptions.hxx>
34 #include <vcl/help.hxx>
35 #include <svx/svdview.hxx>
36 #include <fmturl.hxx>
37 #include <frmfmt.hxx>
38 #include <doc.hxx>
39 #ifndef _DOCSH_HXX
40 #include <docsh.hxx>
41 #endif
42 #include <shellres.hxx>
43 #include <viewimp.hxx>
44 #include <pagefrm.hxx>
45 #include <cntfrm.hxx>
46 #include <rootfrm.hxx>
47 #include <frmatr.hxx>
48 #include <viewsh.hxx>
49 #include <drawdoc.hxx>
50 #include <dpage.hxx>
51 #include <dcontact.hxx>
52 #include <dflyobj.hxx>
53 #ifndef _DOCSH_HXX
54 #include <docsh.hxx>
55 #endif
56 #include <usrfld.hxx>
57 #include <flyfrm.hxx>
58 #include <ndnotxt.hxx>
59 #include <grfatr.hxx>
60 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
61 
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::drawing;
64 using namespace ::com::sun::star::frame;
65 
66 SwDPage::SwDPage(SwDrawDocument& rNewModel, sal_Bool bMasterPage) :
67 	FmFormPage(rNewModel, 0, bMasterPage),
68 	pGridLst( 0 ),
69 	rDoc(rNewModel.GetDoc())
70 {
71 }
72 
73 
74 SwDPage::~SwDPage()
75 {
76 	delete pGridLst;
77 }
78 
79 /*************************************************************************
80 |*
81 |*	SwDPage::ReplaceObject()
82 |*
83 |*	Ersterstellung		MA 07. Aug. 95
84 |*	Letzte Aenderung	MA 07. Aug. 95
85 |*
86 *************************************************************************/
87 
88 SdrObject*  SwDPage::ReplaceObject( SdrObject* pNewObj, sal_uLong nObjNum )
89 {
90 	SdrObject *pOld = GetObj( nObjNum );
91 	ASSERT( pOld, "Oups, Object not replaced" );
92 	SdrObjUserCall* pContact;
93 	if ( 0 != ( pContact = GetUserCall(pOld) ) &&
94 		 RES_DRAWFRMFMT == ((SwContact*)pContact)->GetFmt()->Which())
95 		((SwDrawContact*)pContact)->ChangeMasterObject( pNewObj );
96 	return FmFormPage::ReplaceObject( pNewObj, nObjNum );
97 }
98 
99 /*************************************************************************
100 |*
101 |*	SwDPage::GetGridFrameList()
102 |*
103 |*	Ersterstellung		MA 04. Sep. 95
104 |*	Letzte Aenderung	MA 15. Feb. 96
105 |*
106 *************************************************************************/
107 
108 void InsertGridFrame( SdrPageGridFrameList *pLst, const SwFrm *pPg )
109 {
110 	SwRect aPrt( pPg->Prt() );
111 	aPrt += pPg->Frm().Pos();
112 	const Rectangle aUser( aPrt.SVRect() );
113 	const Rectangle aPaper( pPg->Frm().SVRect() );
114 	pLst->Insert( SdrPageGridFrame( aPaper, aUser ) );
115 }
116 
117 
118 const SdrPageGridFrameList*  SwDPage::GetGridFrameList(
119 						const SdrPageView* pPV, const Rectangle *pRect ) const
120 {
121 	ViewShell *pSh = ((SwDrawDocument*)GetModel())->GetDoc().GetCurrentViewShell();	//swmod 071108//swmod 071225
122 	if ( pSh )
123 	{
124 		while ( pSh->Imp()->GetPageView() != pPV )
125 			pSh = (ViewShell*)pSh->GetNext();
126 		if ( pSh )
127 		{
128 			if ( pGridLst )
129 				((SwDPage*)this)->pGridLst->Clear();
130 			else
131 				((SwDPage*)this)->pGridLst = new SdrPageGridFrameList;
132 
133 			if ( pRect )
134 			{
135 				//Das Drawing verlang alle Seiten, die mit dem Rect ueberlappen.
136 				const SwRect aRect( *pRect );
137 				const SwFrm *pPg = pSh->GetLayout()->Lower();
138 				do
139 				{	if ( pPg->Frm().IsOver( aRect ) )
140 						::InsertGridFrame( ((SwDPage*)this)->pGridLst, pPg );
141 					pPg = pPg->GetNext();
142 				} while ( pPg );
143 			}
144 			else
145 			{
146 				//Das Drawing verlangt alle sichbaren Seiten
147 				const SwFrm *pPg = pSh->Imp()->GetFirstVisPage();
148 				if ( pPg )
149 					do
150 					{	::InsertGridFrame( ((SwDPage*)this)->pGridLst, pPg );
151 						pPg = pPg->GetNext();
152 					} while ( pPg && pPg->Frm().IsOver( pSh->VisArea() ) );
153 			}
154 		}
155 	}
156 	return pGridLst;
157 }
158 
159 sal_Bool SwDPage::RequestHelp( Window* pWindow, SdrView* pView,
160 						   const HelpEvent& rEvt )
161 {
162 	sal_Bool bWeiter = sal_True;
163 
164 	if( rEvt.GetMode() & ( HELPMODE_QUICK | HELPMODE_BALLOON ))
165 	{
166 		Point aPos( rEvt.GetMousePosPixel() );
167 		aPos = pWindow->ScreenToOutputPixel( aPos );
168 		aPos = pWindow->PixelToLogic( aPos );
169 
170 		SdrPageView* pPV;
171 		SdrObject* pObj;
172 		if( pView->PickObj( aPos, 0, pObj, pPV, SDRSEARCH_PICKMACRO ) &&
173 			 pObj->ISA(SwVirtFlyDrawObj) )
174 		{
175 			SwFlyFrm *pFly = ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm();
176 			const SwFmtURL &rURL = pFly->GetFmt()->GetURL();
177 			String sTxt;
178 			if( rURL.GetMap() )
179 			{
180                 IMapObject *pTmpObj = pFly->GetFmt()->GetIMapObject( aPos, pFly );
181                 if( pTmpObj )
182 				{
183                     sTxt = pTmpObj->GetAltText();
184 					if ( !sTxt.Len() )
185                         sTxt = URIHelper::removePassword( pTmpObj->GetURL(),
186 										INetURLObject::WAS_ENCODED,
187 			   							INetURLObject::DECODE_UNAMBIGUOUS);
188 				}
189 			}
190 			else if ( rURL.GetURL().Len() )
191 			{
192 				sTxt = URIHelper::removePassword( rURL.GetURL(),
193 										INetURLObject::WAS_ENCODED,
194 			   							INetURLObject::DECODE_UNAMBIGUOUS);
195 
196 				if( rURL.IsServerMap() )
197 				{
198 					// dann die rel. Pixel Position anhaengen !!
199 					Point aPt( aPos );
200 					aPt -= pFly->Frm().Pos();
201 					// ohne MapMode-Offset !!!!!
202 					// ohne MapMode-Offset, ohne Offset, o ... !!!!!
203 					aPt = pWindow->LogicToPixel(
204 							aPt, MapMode( MAP_TWIP ) );
205 					((( sTxt += '?' ) += String::CreateFromInt32( aPt.X() ))
206 							 += ',' ) += String::CreateFromInt32( aPt.Y() );
207 				}
208 			}
209 
210 			if ( sTxt.Len() )
211 			{
212                 // --> OD 2007-07-26 #i80029#
213                 sal_Bool bExecHyperlinks = rDoc.GetDocShell()->IsReadOnly();
214                 if ( !bExecHyperlinks )
215                 {
216                     SvtSecurityOptions aSecOpts;
217                     bExecHyperlinks = !aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
218 
219                     if ( !bExecHyperlinks )
220                     {
221                         sTxt.InsertAscii( ": ", 0 );
222                         sTxt.Insert( ViewShell::GetShellRes()->aHyperlinkClick, 0 );
223                     }
224                 }
225 
226                 // <--
227 
228 				if( rEvt.GetMode() & HELPMODE_BALLOON )
229 				{
230 					Help::ShowBalloon( pWindow, rEvt.GetMousePosPixel(), sTxt );
231                 }
232                 else
233                 {
234 			// dann zeige die Hilfe mal an:
235 					Rectangle aRect( rEvt.GetMousePosPixel(), Size(1,1) );
236 					Help::ShowQuickHelp( pWindow, aRect, sTxt );
237 				}
238 				bWeiter = sal_False;
239 			}
240 		}
241 	}
242 
243 	if( bWeiter )
244 		bWeiter = !FmFormPage::RequestHelp( pWindow, pView, rEvt );
245 
246 	return bWeiter;
247 }
248 /* -----------------------------27.11.00 07:35--------------------------------
249 
250  ---------------------------------------------------------------------------*/
251 Reference< XInterface > SwDPage::createUnoPage()
252 {
253 	Reference < XInterface > xRet;
254 	SwDocShell* pDocShell = rDoc.GetDocShell();
255 	if ( pDocShell )
256 	{
257 		Reference<XModel> xModel = pDocShell->GetBaseModel();
258 		Reference<XDrawPageSupplier> xPageSupp(xModel, UNO_QUERY);
259 		xRet = xPageSupp->getDrawPage();
260 	}
261 	return xRet;
262 }
263 
264 
265 
266