Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <basic/basmgr.hxx>
21 : #include <svtools/imapobj.hxx>
22 : #include <svl/urihelper.hxx>
23 : #include <unotools/securityoptions.hxx>
24 : #include <vcl/help.hxx>
25 : #include <svx/svdview.hxx>
26 : #include <fmturl.hxx>
27 : #include <frmfmt.hxx>
28 : #include <doc.hxx>
29 : #include <IDocumentLayoutAccess.hxx>
30 : #include <shellres.hxx>
31 : #include <viewimp.hxx>
32 : #include <pagefrm.hxx>
33 : #include <cntfrm.hxx>
34 : #include <rootfrm.hxx>
35 : #include <frmatr.hxx>
36 : #include <viewsh.hxx>
37 : #include <drawdoc.hxx>
38 : #include <dpage.hxx>
39 : #include <dcontact.hxx>
40 : #include <dflyobj.hxx>
41 : #include <docsh.hxx>
42 : #include <usrfld.hxx>
43 : #include <flyfrm.hxx>
44 : #include <ndnotxt.hxx>
45 : #include <grfatr.hxx>
46 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
47 :
48 : using namespace ::com::sun::star::uno;
49 : using namespace ::com::sun::star::drawing;
50 : using namespace ::com::sun::star::frame;
51 :
52 2958 : SwDPage::SwDPage(SwDrawModel& rNewModel, bool bMasterPage) :
53 : FmFormPage(rNewModel, bMasterPage),
54 : pGridLst( 0 ),
55 2958 : pDoc(&rNewModel.GetDoc())
56 : {
57 2958 : }
58 :
59 0 : SwDPage::SwDPage(const SwDPage& rSrcPage) :
60 : FmFormPage( rSrcPage ),
61 : pGridLst( 0 ),
62 0 : pDoc( 0 )
63 : {
64 0 : if ( rSrcPage.pGridLst )
65 : {
66 0 : pGridLst = new SdrPageGridFrameList;
67 0 : for ( sal_uInt16 i = 0; i != rSrcPage.pGridLst->GetCount(); ++i )
68 0 : pGridLst->Insert( ( *rSrcPage.pGridLst )[ i ] );
69 : }
70 0 : }
71 :
72 8847 : SwDPage::~SwDPage()
73 : {
74 2949 : delete pGridLst;
75 5898 : }
76 :
77 0 : void SwDPage::lateInit(const SwDPage& rPage, SwDrawModel* const pNewModel)
78 : {
79 0 : FmFormPage::lateInit( rPage, pNewModel );
80 :
81 0 : SwDrawModel* pSwDrawModel = pNewModel;
82 0 : if (!pSwDrawModel)
83 : {
84 0 : pSwDrawModel = &dynamic_cast<SwDrawModel&>(*GetModel());
85 : assert( pSwDrawModel );
86 : }
87 0 : pDoc = &pSwDrawModel->GetDoc();
88 0 : }
89 :
90 0 : SwDPage* SwDPage::Clone() const
91 : {
92 0 : return Clone( 0 );
93 : }
94 :
95 0 : SwDPage* SwDPage::Clone(SdrModel* const pNewModel) const
96 : {
97 0 : SwDPage* const pNewPage = new SwDPage( *this );
98 0 : SwDrawModel* pSwDrawModel = 0;
99 0 : if ( pNewModel )
100 : {
101 0 : pSwDrawModel = &dynamic_cast<SwDrawModel&>(*pNewModel);
102 : assert( pSwDrawModel );
103 : }
104 0 : pNewPage->lateInit( *this, pSwDrawModel );
105 0 : return pNewPage;
106 : }
107 :
108 1041 : SdrObject* SwDPage::ReplaceObject( SdrObject* pNewObj, size_t nObjNum )
109 : {
110 1041 : SdrObject *pOld = GetObj( nObjNum );
111 : OSL_ENSURE( pOld, "Oups, Object not replaced" );
112 : SdrObjUserCall* pContact;
113 2082 : if ( 0 != ( pContact = GetUserCall(pOld) ) &&
114 1041 : RES_DRAWFRMFMT == static_cast<SwContact*>(pContact)->GetFormat()->Which())
115 0 : static_cast<SwDrawContact*>(pContact)->ChangeMasterObject( pNewObj );
116 1041 : return FmFormPage::ReplaceObject( pNewObj, nObjNum );
117 : }
118 :
119 40 : void InsertGridFrame( SdrPageGridFrameList *pLst, const SwFrm *pPg )
120 : {
121 40 : SwRect aPrt( pPg->Prt() );
122 40 : aPrt += pPg->Frm().Pos();
123 40 : const Rectangle aUser( aPrt.SVRect() );
124 40 : const Rectangle aPaper( pPg->Frm().SVRect() );
125 40 : pLst->Insert( SdrPageGridFrame( aPaper, aUser ) );
126 40 : }
127 :
128 40 : const SdrPageGridFrameList* SwDPage::GetGridFrameList(
129 : const SdrPageView* pPV, const Rectangle *pRect ) const
130 : {
131 40 : SwViewShell* pSh = static_cast< SwDrawModel* >(GetModel())->GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell();
132 40 : if(pSh)
133 : {
134 40 : for(SwViewShell& rShell : pSh->GetRingContainer())
135 : {
136 40 : if(rShell.Imp()->GetPageView() == pPV)
137 : {
138 40 : pSh = &rShell;
139 40 : break;
140 : }
141 : }
142 40 : if ( pGridLst )
143 39 : const_cast<SwDPage*>(this)->pGridLst->Clear();
144 : else
145 1 : const_cast<SwDPage*>(this)->pGridLst = new SdrPageGridFrameList;
146 :
147 40 : if ( pRect )
148 : {
149 : //The drawing demands all pages which overlap with the rest.
150 0 : const SwRect aRect( *pRect );
151 0 : const SwFrm *pPg = pSh->GetLayout()->Lower();
152 0 : do
153 0 : { if ( pPg->Frm().IsOver( aRect ) )
154 0 : ::InsertGridFrame( const_cast<SwDPage*>(this)->pGridLst, pPg );
155 0 : pPg = pPg->GetNext();
156 : } while ( pPg );
157 : }
158 : else
159 : {
160 : //The drawing demands all visible pages
161 40 : const SwFrm *pPg = pSh->Imp()->GetFirstVisPage();
162 40 : if ( pPg )
163 40 : do
164 40 : { ::InsertGridFrame( const_cast<SwDPage*>(this)->pGridLst, pPg );
165 40 : pPg = pPg->GetNext();
166 40 : } while ( pPg && pPg->Frm().IsOver( pSh->VisArea() ) );
167 : }
168 : }
169 40 : return pGridLst;
170 : }
171 :
172 0 : bool SwDPage::RequestHelp( vcl::Window* pWindow, SdrView* pView,
173 : const HelpEvent& rEvt )
174 : {
175 : assert( pDoc );
176 :
177 0 : bool bContinue = true;
178 :
179 0 : if( rEvt.GetMode() & ( HelpEventMode::QUICK | HelpEventMode::BALLOON ))
180 : {
181 0 : Point aPos( rEvt.GetMousePosPixel() );
182 0 : aPos = pWindow->ScreenToOutputPixel( aPos );
183 0 : aPos = pWindow->PixelToLogic( aPos );
184 :
185 : SdrPageView* pPV;
186 : SdrObject* pObj;
187 0 : if( pView->PickObj( aPos, 0, pObj, pPV, SdrSearchOptions::PICKMACRO ) &&
188 0 : pObj->ISA(SwVirtFlyDrawObj) )
189 : {
190 0 : SwFlyFrm *pFly = static_cast<SwVirtFlyDrawObj*>(pObj)->GetFlyFrm();
191 0 : const SwFormatURL &rURL = pFly->GetFormat()->GetURL();
192 0 : OUString sText;
193 0 : if( rURL.GetMap() )
194 : {
195 0 : IMapObject *pTmpObj = pFly->GetFormat()->GetIMapObject( aPos, pFly );
196 0 : if( pTmpObj )
197 : {
198 0 : sText = pTmpObj->GetAltText();
199 0 : if ( sText.isEmpty() )
200 0 : sText = URIHelper::removePassword( pTmpObj->GetURL(),
201 : INetURLObject::WAS_ENCODED,
202 0 : INetURLObject::DECODE_UNAMBIGUOUS);
203 : }
204 : }
205 0 : else if ( !rURL.GetURL().isEmpty() )
206 : {
207 0 : sText = URIHelper::removePassword( rURL.GetURL(),
208 : INetURLObject::WAS_ENCODED,
209 0 : INetURLObject::DECODE_UNAMBIGUOUS);
210 :
211 0 : if( rURL.IsServerMap() )
212 : {
213 : // then append the relative pixel position!!
214 0 : Point aPt( aPos );
215 0 : aPt -= pFly->Frm().Pos();
216 : // without MapMode-Offset !!!!!
217 : // without MapMode-Offset, without Offset, w ... !!!!!
218 : aPt = pWindow->LogicToPixel(
219 0 : aPt, MapMode( MAP_TWIP ) );
220 0 : sText += "?" + OUString::number( aPt.getX() )
221 0 : + "," + OUString::number( aPt.getY() );
222 : }
223 : }
224 :
225 0 : if ( !sText.isEmpty() )
226 : {
227 : // #i80029#
228 0 : bool bExecHyperlinks = pDoc->GetDocShell()->IsReadOnly();
229 0 : if ( !bExecHyperlinks )
230 : {
231 0 : SvtSecurityOptions aSecOpts;
232 0 : bExecHyperlinks = !aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
233 :
234 0 : if ( !bExecHyperlinks )
235 0 : sText = SwViewShell::GetShellRes()->aLinkCtrlClick + ": " + sText;
236 : else
237 0 : sText = SwViewShell::GetShellRes()->aLinkClick + ": " + sText;
238 : }
239 :
240 0 : if( rEvt.GetMode() & HelpEventMode::BALLOON )
241 : {
242 0 : Help::ShowBalloon( pWindow, rEvt.GetMousePosPixel(), sText );
243 : }
244 : else
245 : {
246 : // then display the help:
247 0 : Rectangle aRect( rEvt.GetMousePosPixel(), Size(1,1) );
248 0 : Help::ShowQuickHelp( pWindow, aRect, sText );
249 : }
250 0 : bContinue = false;
251 0 : }
252 : }
253 : }
254 :
255 0 : if( bContinue )
256 0 : bContinue = !FmFormPage::RequestHelp( pWindow, pView, rEvt );
257 :
258 0 : return bContinue;
259 : }
260 :
261 1558 : Reference< XInterface > SwDPage::createUnoPage()
262 : {
263 : assert( pDoc );
264 :
265 1558 : Reference < XInterface > xRet;
266 1558 : SwDocShell* pDocShell = pDoc->GetDocShell();
267 1558 : if ( pDocShell )
268 : {
269 1557 : Reference<XModel> xModel = pDocShell->GetBaseModel();
270 3114 : Reference<XDrawPageSupplier> xPageSupp(xModel, UNO_QUERY);
271 3114 : xRet = xPageSupp->getDrawPage();
272 : }
273 1558 : return xRet;
274 177 : }
275 :
276 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|