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 <hintids.hxx>
21 : #include <vcl/outdev.hxx>
22 : #include <sfx2/printer.hxx>
23 : #include <editeng/eeitem.hxx>
24 : #include <editeng/flditem.hxx>
25 : #include <editeng/editeng.hxx>
26 : #include <svx/svdoutl.hxx>
27 : #include <editeng/colritem.hxx>
28 : #include <svx/svdpage.hxx>
29 : #include <svx/svdogrp.hxx>
30 : #include <editeng/langitem.hxx>
31 : #include <editeng/unolingu.hxx>
32 : #include <editeng/measfld.hxx>
33 : #include <svx/svdpool.hxx>
34 : #include <fmtanchr.hxx>
35 : #include <charatr.hxx>
36 : #include <frmfmt.hxx>
37 : #include <charfmt.hxx>
38 : #include <viewimp.hxx>
39 : #include <swhints.hxx>
40 : #include <doc.hxx>
41 : #include <docfunc.hxx>
42 : #include <IDocumentUndoRedo.hxx>
43 : #include <DocumentSettingManager.hxx>
44 : #include <IDocumentDeviceAccess.hxx>
45 : #include <IDocumentDrawModelAccess.hxx>
46 : #include <IDocumentState.hxx>
47 : #include <IDocumentLayoutAccess.hxx>
48 : #include <IDocumentStylePoolAccess.hxx>
49 : #include <docsh.hxx>
50 : #include <rootfrm.hxx>
51 : #include <poolfmt.hxx>
52 : #include <viewsh.hxx>
53 : #include <drawdoc.hxx>
54 : #include <UndoDraw.hxx>
55 : #include <swundo.hxx>
56 : #include <dcontact.hxx>
57 : #include <dview.hxx>
58 : #include <mvsave.hxx>
59 : #include <flyfrm.hxx>
60 : #include <dflyobj.hxx>
61 : #include <svx/svdetc.hxx>
62 : #include <editeng/fhgtitem.hxx>
63 : #include <svx/svdpagv.hxx>
64 : #include <txtfrm.hxx>
65 : #include <editeng/frmdiritem.hxx>
66 : #include <fmtornt.hxx>
67 : #include <svx/svditer.hxx>
68 :
69 : #include <vector>
70 : #include <calbck.hxx>
71 :
72 : using namespace ::com::sun::star;
73 : using namespace ::com::sun::star::linguistic2;
74 :
75 : /** local method to determine positioning and alignment attributes for a drawing
76 : * object, which is newly connected to the layout.
77 : *
78 : * Used for a newly formed group object <SwDoc::GroupSelection(..)>
79 : * and the members of a destroyed group <SwDoc::UnGroupSelection(..)>
80 : */
81 0 : static void lcl_AdjustPositioningAttr( SwDrawFrameFormat* _pFrameFormat,
82 : const SdrObject& _rSdrObj )
83 : {
84 0 : const SwContact* pContact = GetUserCall( &_rSdrObj );
85 : OSL_ENSURE( pContact, "<lcl_AdjustPositioningAttr(..)> - missing contact object." );
86 :
87 : // determine position of new group object relative to its anchor frame position
88 0 : SwTwips nHoriRelPos = 0;
89 0 : SwTwips nVertRelPos = 0;
90 : {
91 0 : const SwFrm* pAnchorFrm = pContact->GetAnchoredObj( &_rSdrObj )->GetAnchorFrm();
92 : OSL_ENSURE( !pAnchorFrm ||
93 : !pAnchorFrm->IsTextFrm() ||
94 : !static_cast<const SwTextFrm*>(pAnchorFrm)->IsFollow(),
95 : "<lcl_AdjustPositioningAttr(..)> - anchor frame is a follow. Please inform OD." );
96 0 : bool bVert = false;
97 0 : bool bR2L = false;
98 : // #i45952# - use anchor position of anchor frame, if it exist.
99 0 : Point aAnchorPos;
100 0 : if ( pAnchorFrm )
101 : {
102 : // #i45952#
103 0 : aAnchorPos = pAnchorFrm->GetFrmAnchorPos( ::HasWrap( &_rSdrObj ) );
104 0 : bVert = pAnchorFrm->IsVertical();
105 0 : bR2L = pAnchorFrm->IsRightToLeft();
106 : }
107 : else
108 : {
109 : // #i45952#
110 0 : aAnchorPos = _rSdrObj.GetAnchorPos();
111 : // If no anchor frame exist - e.g. because no layout exists - the
112 : // default layout direction is taken.
113 : const SvxFrameDirectionItem* pDirItem =
114 0 : static_cast<const SvxFrameDirectionItem*>(&(_pFrameFormat->GetAttrSet().GetPool()->GetDefaultItem( RES_FRAMEDIR )));
115 0 : switch ( pDirItem->GetValue() )
116 : {
117 : case FRMDIR_VERT_TOP_LEFT:
118 : {
119 : // vertical from left-to-right
120 0 : bVert = true;
121 0 : bR2L = true;
122 : OSL_FAIL( "<lcl_AdjustPositioningAttr(..)> - vertical from left-to-right not supported." );
123 : }
124 0 : break;
125 : case FRMDIR_VERT_TOP_RIGHT:
126 : {
127 : // vertical from right-to-left
128 0 : bVert = true;
129 0 : bR2L = false;
130 : }
131 0 : break;
132 : case FRMDIR_HORI_RIGHT_TOP:
133 : {
134 : // horizontal from right-to-left
135 0 : bVert = false;
136 0 : bR2L = true;
137 : }
138 0 : break;
139 : case FRMDIR_HORI_LEFT_TOP:
140 : {
141 : // horizontal from left-to-right
142 0 : bVert = false;
143 0 : bR2L = false;
144 : }
145 0 : break;
146 : }
147 :
148 : }
149 : // use geometry of drawing object
150 0 : const SwRect aObjRect = _rSdrObj.GetSnapRect();
151 :
152 0 : if ( bVert )
153 : {
154 0 : if ( bR2L ) {
155 : //FRMDIR_VERT_TOP_LEFT
156 0 : nHoriRelPos = aObjRect.Left() - aAnchorPos.getX();
157 0 : nVertRelPos = aObjRect.Top() - aAnchorPos.getY();
158 : } else {
159 : //FRMDIR_VERT_TOP_RIGHT
160 0 : nHoriRelPos = aObjRect.Top() - aAnchorPos.getY();
161 0 : nVertRelPos = aAnchorPos.getX() - aObjRect.Right();
162 : }
163 : }
164 0 : else if ( bR2L )
165 : {
166 0 : nHoriRelPos = aAnchorPos.getX() - aObjRect.Right();
167 0 : nVertRelPos = aObjRect.Top() - aAnchorPos.getY();
168 : }
169 : else
170 : {
171 0 : nHoriRelPos = aObjRect.Left() - aAnchorPos.getX();
172 0 : nVertRelPos = aObjRect.Top() - aAnchorPos.getY();
173 : }
174 : }
175 :
176 0 : _pFrameFormat->SetFormatAttr( SwFormatHoriOrient( nHoriRelPos, text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
177 0 : _pFrameFormat->SetFormatAttr( SwFormatVertOrient( nVertRelPos, text::VertOrientation::NONE, text::RelOrientation::FRAME ) );
178 : // #i44334#, #i44681# - positioning attributes already set
179 0 : _pFrameFormat->PosAttrSet();
180 : // #i34750# - keep current object rectangle for drawing
181 : // objects. The object rectangle is used on events from the drawing layer
182 : // to adjust the positioning attributes - see <SwDrawContact::_Changed(..)>.
183 : {
184 0 : const SwAnchoredObject* pAnchoredObj = pContact->GetAnchoredObj( &_rSdrObj );
185 0 : if ( pAnchoredObj->ISA(SwAnchoredDrawObject) )
186 : {
187 : const SwAnchoredDrawObject* pAnchoredDrawObj =
188 0 : static_cast<const SwAnchoredDrawObject*>(pAnchoredObj);
189 0 : const SwRect aObjRect = _rSdrObj.GetSnapRect();
190 : const_cast<SwAnchoredDrawObject*>(pAnchoredDrawObj)
191 0 : ->SetLastObjRect( aObjRect.SVRect() );
192 : }
193 : }
194 0 : }
195 :
196 0 : SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView )
197 : {
198 : // replace marked 'virtual' drawing objects by the corresponding 'master'
199 : // drawing objects.
200 0 : SwDrawView::ReplaceMarkedDrawVirtObjs( rDrawView );
201 :
202 0 : const SdrMarkList &rMrkList = rDrawView.GetMarkedObjectList();
203 0 : SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
204 0 : bool bNoGroup = ( 0 == pObj->GetUpGroup() );
205 0 : SwDrawContact* pNewContact = 0;
206 0 : if( bNoGroup )
207 : {
208 0 : SwDrawFrameFormat *pFormat = 0L;
209 :
210 : // Revoke anchor attribute.
211 0 : SwDrawContact *pMyContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
212 0 : const SwFormatAnchor aAnch( pMyContact->GetFormat()->GetAnchor() );
213 :
214 0 : SwUndoDrawGroup *const pUndo = (!GetIDocumentUndoRedo().DoesUndo())
215 : ? 0
216 0 : : new SwUndoDrawGroup( (sal_uInt16)rMrkList.GetMarkCount() );
217 :
218 : // #i53320#
219 0 : bool bGroupMembersNotPositioned( false );
220 : {
221 : SwAnchoredDrawObject* pAnchoredDrawObj =
222 0 : static_cast<SwAnchoredDrawObject*>(pMyContact->GetAnchoredObj( pObj ));
223 0 : bGroupMembersNotPositioned = pAnchoredDrawObj->NotYetPositioned();
224 : }
225 : // Destroy ContactObjects and formats.
226 0 : for( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
227 : {
228 0 : pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
229 0 : SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
230 :
231 : // #i53320#
232 : #if OSL_DEBUG_LEVEL > 0
233 : SwAnchoredDrawObject* pAnchoredDrawObj =
234 : static_cast<SwAnchoredDrawObject*>(pContact->GetAnchoredObj( pObj ));
235 : OSL_ENSURE( bGroupMembersNotPositioned == pAnchoredDrawObj->NotYetPositioned(),
236 : "<SwDoc::GroupSelection(..)> - group members have different positioning status!" );
237 : #endif
238 :
239 0 : pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
240 : // Deletes itself!
241 0 : pContact->Changed(*pObj, SDRUSERCALL_DELETE, pObj->GetLastBoundRect() );
242 0 : pObj->SetUserCall( 0 );
243 :
244 0 : if( pUndo )
245 0 : pUndo->AddObj( i, pFormat, pObj );
246 : else
247 0 : DelFrameFormat( pFormat );
248 :
249 : // #i45952# - re-introduce position normalization of group member
250 : // objects, because its anchor position is cleared, when they are
251 : // grouped.
252 0 : Point aAnchorPos( pObj->GetAnchorPos() );
253 0 : pObj->NbcSetAnchorPos( Point( 0, 0 ) );
254 0 : pObj->NbcMove( Size( aAnchorPos.getX(), aAnchorPos.getY() ) );
255 : }
256 :
257 : pFormat = MakeDrawFrameFormat( OUString("DrawObject"),
258 0 : GetDfltFrameFormat() );
259 0 : pFormat->SetFormatAttr( aAnch );
260 : // #i36010# - set layout direction of the position
261 : pFormat->SetPositionLayoutDir(
262 0 : text::PositionLayoutDir::PositionInLayoutDirOfAnchor );
263 :
264 0 : rDrawView.GroupMarked();
265 : OSL_ENSURE( rMrkList.GetMarkCount() == 1, "GroupMarked more or none groups." );
266 :
267 0 : SdrObject* pNewGroupObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
268 0 : pNewContact = new SwDrawContact( pFormat, pNewGroupObj );
269 : // #i35635#
270 0 : pNewContact->MoveObjToVisibleLayer( pNewGroupObj );
271 0 : pNewContact->ConnectToLayout();
272 : // #i53320# - No adjustment of the positioning and alignment
273 : // attributes, if group members aren't positioned yet.
274 0 : if ( !bGroupMembersNotPositioned )
275 : {
276 : // #i26791# - Adjust positioning and alignment attributes.
277 0 : lcl_AdjustPositioningAttr( pFormat, *pNewGroupObj );
278 : }
279 :
280 0 : if( pUndo )
281 : {
282 0 : pUndo->SetGroupFormat( pFormat );
283 0 : GetIDocumentUndoRedo().AppendUndo( pUndo );
284 0 : }
285 : }
286 : else
287 : {
288 0 : if (GetIDocumentUndoRedo().DoesUndo())
289 : {
290 0 : GetIDocumentUndoRedo().ClearRedo();
291 : }
292 :
293 0 : rDrawView.GroupMarked();
294 : OSL_ENSURE( rMrkList.GetMarkCount() == 1, "GroupMarked more or none groups." );
295 : }
296 :
297 0 : return pNewContact;
298 : }
299 :
300 0 : void SwDoc::UnGroupSelection( SdrView& rDrawView )
301 : {
302 0 : bool const bUndo = GetIDocumentUndoRedo().DoesUndo();
303 0 : if( bUndo )
304 : {
305 0 : GetIDocumentUndoRedo().ClearRedo();
306 : }
307 :
308 : // replace marked 'virtual' drawing objects by the corresponding 'master'
309 : // drawing objects.
310 0 : SwDrawView::ReplaceMarkedDrawVirtObjs( rDrawView );
311 :
312 0 : const SdrMarkList &rMrkList = rDrawView.GetMarkedObjectList();
313 0 : std::vector< std::pair< SwDrawFrameFormat*, SdrObject* > >* pFormatsAndObjs( 0L );
314 0 : const size_t nMarkCount( rMrkList.GetMarkCount() );
315 0 : if ( nMarkCount )
316 : {
317 0 : pFormatsAndObjs = new std::vector< std::pair< SwDrawFrameFormat*, SdrObject* > >[nMarkCount];
318 0 : SdrObject *pMyObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
319 0 : if( !pMyObj->GetUpGroup() )
320 : {
321 0 : OUString sDrwFormatNm("DrawObject");
322 0 : for ( size_t i = 0; i < nMarkCount; ++i )
323 : {
324 0 : SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
325 0 : if ( pObj->IsA( TYPE(SdrObjGroup) ) )
326 : {
327 0 : SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
328 0 : SwFormatAnchor aAnch( pContact->GetFormat()->GetAnchor() );
329 0 : SdrObjList *pLst = static_cast<SdrObjGroup*>(pObj)->GetSubList();
330 :
331 0 : SwUndoDrawUnGroup* pUndo = 0;
332 0 : if( bUndo )
333 : {
334 0 : pUndo = new SwUndoDrawUnGroup( static_cast<SdrObjGroup*>(pObj) );
335 0 : GetIDocumentUndoRedo().AppendUndo(pUndo);
336 : }
337 :
338 0 : for ( size_t i2 = 0; i2 < pLst->GetObjCount(); ++i2 )
339 : {
340 0 : SdrObject* pSubObj = pLst->GetObj( i2 );
341 : SwDrawFrameFormat *pFormat = MakeDrawFrameFormat( sDrwFormatNm,
342 0 : GetDfltFrameFormat() );
343 0 : pFormat->SetFormatAttr( aAnch );
344 : // #i36010# - set layout direction of the position
345 : pFormat->SetPositionLayoutDir(
346 0 : text::PositionLayoutDir::PositionInLayoutDirOfAnchor );
347 0 : pFormatsAndObjs[i].push_back( std::pair< SwDrawFrameFormat*, SdrObject* >( pFormat, pSubObj ) );
348 :
349 0 : if( bUndo )
350 0 : pUndo->AddObj( static_cast<sal_uInt16>(i2), pFormat );
351 0 : }
352 : }
353 0 : }
354 : }
355 : }
356 0 : rDrawView.UnGroupMarked();
357 : // creation of <SwDrawContact> instances for the former group members and
358 : // its connection to the Writer layout.
359 0 : for ( size_t i = 0; i < nMarkCount; ++i )
360 : {
361 0 : SwUndoDrawUnGroupConnectToLayout* pUndo = 0;
362 0 : if( bUndo )
363 : {
364 0 : pUndo = new SwUndoDrawUnGroupConnectToLayout();
365 0 : GetIDocumentUndoRedo().AppendUndo(pUndo);
366 : }
367 :
368 0 : while ( pFormatsAndObjs[i].size() > 0 )
369 : {
370 0 : SwDrawFrameFormat* pFormat( pFormatsAndObjs[i].back().first );
371 0 : SdrObject* pObj( pFormatsAndObjs[i].back().second );
372 0 : pFormatsAndObjs[i].pop_back();
373 :
374 0 : SwDrawContact* pContact = new SwDrawContact( pFormat, pObj );
375 0 : pContact->MoveObjToVisibleLayer( pObj );
376 0 : pContact->ConnectToLayout();
377 0 : lcl_AdjustPositioningAttr( pFormat, *pObj );
378 :
379 0 : if ( bUndo )
380 : {
381 0 : pUndo->AddFormatAndObj( pFormat, pObj );
382 : }
383 : }
384 : }
385 0 : delete [] pFormatsAndObjs;
386 0 : }
387 :
388 1 : bool SwDoc::DeleteSelection( SwDrawView& rDrawView )
389 : {
390 1 : bool bCallBase = false;
391 1 : const SdrMarkList &rMrkList = rDrawView.GetMarkedObjectList();
392 1 : if( rMrkList.GetMarkCount() )
393 : {
394 1 : GetIDocumentUndoRedo().StartUndo(UNDO_EMPTY, NULL);
395 1 : bool bDelMarked = true;
396 :
397 1 : if( 1 == rMrkList.GetMarkCount() )
398 : {
399 1 : SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
400 1 : if( pObj->ISA(SwVirtFlyDrawObj) )
401 : {
402 : SwFlyFrameFormat* pFrameFormat =
403 0 : static_cast<SwVirtFlyDrawObj*>(pObj)->GetFlyFrm()->GetFormat();
404 0 : if( pFrameFormat )
405 : {
406 0 : getIDocumentLayoutAccess().DelLayoutFormat( pFrameFormat );
407 0 : bDelMarked = false;
408 : }
409 : }
410 : }
411 :
412 2 : for( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
413 : {
414 1 : SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
415 1 : if( !pObj->ISA(SwVirtFlyDrawObj) )
416 : {
417 1 : SwDrawContact *pC = static_cast<SwDrawContact*>(GetUserCall(pObj));
418 1 : SwDrawFrameFormat *pFrameFormat = static_cast<SwDrawFrameFormat*>(pC->GetFormat());
419 2 : if( pFrameFormat &&
420 1 : FLY_AS_CHAR == pFrameFormat->GetAnchor().GetAnchorId() )
421 : {
422 0 : rDrawView.MarkObj( pObj, rDrawView.Imp().GetPageView(), true );
423 0 : --i;
424 0 : getIDocumentLayoutAccess().DelLayoutFormat( pFrameFormat );
425 : }
426 : }
427 : }
428 :
429 1 : if( rMrkList.GetMarkCount() && bDelMarked )
430 : {
431 1 : SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
432 1 : if( !pObj->GetUpGroup() )
433 : {
434 : SwUndoDrawDelete *const pUndo =
435 1 : (!GetIDocumentUndoRedo().DoesUndo())
436 : ? 0
437 1 : : new SwUndoDrawDelete( (sal_uInt16)rMrkList.GetMarkCount() );
438 :
439 : // Destroy ContactObjects, save formats.
440 2 : for( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
441 : {
442 1 : const SdrMark& rMark = *rMrkList.GetMark( i );
443 1 : pObj = rMark.GetMarkedSdrObj();
444 1 : SwDrawContact *pContact = static_cast<SwDrawContact*>(pObj->GetUserCall());
445 1 : if( pContact ) // of course not for grouped objects
446 : {
447 1 : SwDrawFrameFormat *pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
448 : // before delete of selection is performed, marked
449 : // <SwDrawVirtObj>-objects have to be replaced by its
450 : // reference objects. Thus, assert, if a
451 : // <SwDrawVirt>-object is found in the mark list.
452 1 : if ( pObj->ISA(SwDrawVirtObj) )
453 : {
454 : OSL_FAIL( "<SwDrawVirtObj> is still marked for delete. application will crash!" );
455 : }
456 : // Deletes itself!
457 1 : pContact->Changed(*pObj, SDRUSERCALL_DELETE, pObj->GetLastBoundRect() );
458 1 : pObj->SetUserCall( 0 );
459 :
460 1 : if( pUndo )
461 1 : pUndo->AddObj( i, pFormat, rMark );
462 : else
463 0 : DelFrameFormat( pFormat );
464 : }
465 : }
466 :
467 1 : if( pUndo )
468 : {
469 1 : GetIDocumentUndoRedo().AppendUndo( pUndo );
470 : }
471 : }
472 1 : bCallBase = true;
473 : }
474 1 : getIDocumentState().SetModified();
475 :
476 1 : GetIDocumentUndoRedo().EndUndo(UNDO_EMPTY, NULL);
477 : }
478 :
479 1 : return bCallBase;
480 : }
481 :
482 542 : _ZSortFly::_ZSortFly( const SwFrameFormat* pFrameFormat, const SwFormatAnchor* pFlyAn,
483 : sal_uInt32 nArrOrdNum )
484 542 : : pFormat( pFrameFormat ), pAnchor( pFlyAn ), nOrdNum( nArrOrdNum )
485 : {
486 : // #i11176#
487 : // This also needs to work when no layout exists. Thus, for
488 : // FlyFrames an alternative method is used now in that case.
489 542 : if( RES_FLYFRMFMT == pFormat->Which() )
490 : {
491 297 : if( pFormat->getIDocumentLayoutAccess()->GetCurrentViewShell() )
492 : {
493 : // See if there is an SdrObject for it
494 11 : SwFlyFrm* pFly = SwIterator<SwFlyFrm,SwFormat>( *pFrameFormat ).First();
495 11 : if( pFly )
496 11 : nOrdNum = pFly->GetVirtDrawObj()->GetOrdNum();
497 : }
498 : else
499 : {
500 : // See if there is an SdrObject for it
501 286 : SwFlyDrawContact* pContact = SwIterator<SwFlyDrawContact,SwFormat>( *pFrameFormat ).First();
502 286 : if( pContact )
503 286 : nOrdNum = pContact->GetMaster()->GetOrdNum();
504 : }
505 : }
506 245 : else if( RES_DRAWFRMFMT == pFormat->Which() )
507 : {
508 : // See if there is an SdrObject for it
509 245 : SwDrawContact* pContact = SwIterator<SwDrawContact,SwFormat>( *pFrameFormat ).First();
510 245 : if( pContact )
511 245 : nOrdNum = pContact->GetMaster()->GetOrdNum();
512 : }
513 : else {
514 : OSL_ENSURE( false, "what kind of format is this?" );
515 : }
516 542 : }
517 :
518 : /// In the Outliner, set a link to the method for field display in edit objects.
519 6093 : void SwDoc::SetCalcFieldValueHdl(Outliner* pOutliner)
520 : {
521 6093 : pOutliner->SetCalcFieldValueHdl(LINK(this, SwDoc, CalcFieldValueHdl));
522 6093 : }
523 :
524 : /// Recognise fields/URLs in the Outliner and set how they are displayed.
525 6 : IMPL_LINK(SwDoc, CalcFieldValueHdl, EditFieldInfo*, pInfo)
526 : {
527 3 : if (pInfo)
528 : {
529 3 : const SvxFieldItem& rField = pInfo->GetField();
530 3 : const SvxFieldData* pField = rField.GetField();
531 :
532 3 : if (pField && pField->ISA(SvxDateField))
533 : {
534 : // Date field
535 : pInfo->SetRepresentation(
536 : static_cast<const SvxDateField*>( pField)->GetFormatted(
537 0 : *GetNumberFormatter( true ), LANGUAGE_SYSTEM) );
538 : }
539 3 : else if (pField && pField->ISA(SvxURLField))
540 : {
541 : // URL field
542 3 : switch ( static_cast<const SvxURLField*>( pField)->GetFormat() )
543 : {
544 : case SVXURLFORMAT_APPDEFAULT: //!!! Can be set in App???
545 : case SVXURLFORMAT_REPR:
546 : {
547 : pInfo->SetRepresentation(
548 3 : static_cast<const SvxURLField*>(pField)->GetRepresentation());
549 : }
550 3 : break;
551 :
552 : case SVXURLFORMAT_URL:
553 : {
554 : pInfo->SetRepresentation(
555 0 : static_cast<const SvxURLField*>(pField)->GetURL());
556 : }
557 0 : break;
558 : }
559 :
560 : sal_uInt16 nChrFormat;
561 :
562 3 : if (IsVisitedURL(static_cast<const SvxURLField*>(pField)->GetURL()))
563 0 : nChrFormat = RES_POOLCHR_INET_VISIT;
564 : else
565 3 : nChrFormat = RES_POOLCHR_INET_NORMAL;
566 :
567 3 : SwFormat *pFormat = getIDocumentStylePoolAccess().GetCharFormatFromPool(nChrFormat);
568 :
569 3 : Color aColor(COL_LIGHTBLUE);
570 3 : if (pFormat)
571 3 : aColor = pFormat->GetColor().GetValue();
572 :
573 3 : pInfo->SetTextColor(aColor);
574 : }
575 0 : else if (pField && pField->ISA(SdrMeasureField))
576 : {
577 : // Measure field
578 0 : pInfo->ClearFieldColor();
579 : }
580 0 : else if ( pField && pField->ISA(SvxExtTimeField))
581 : {
582 : // Time field
583 : pInfo->SetRepresentation(
584 : static_cast<const SvxExtTimeField*>( pField)->GetFormatted(
585 0 : *GetNumberFormatter( true ), LANGUAGE_SYSTEM) );
586 : }
587 : else
588 : {
589 : OSL_FAIL("unknown field command");
590 0 : pInfo->SetRepresentation( OUString( '?' ) );
591 : }
592 : }
593 :
594 3 : return 0;
595 : }
596 :
597 : // #i62875#
598 : namespace docfunc
599 : {
600 3 : bool ExistsDrawObjs( SwDoc& p_rDoc )
601 : {
602 3 : bool bExistsDrawObjs( false );
603 :
604 6 : if ( p_rDoc.getIDocumentDrawModelAccess().GetDrawModel() &&
605 3 : p_rDoc.getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 ) )
606 : {
607 3 : const SdrPage& rSdrPage( *(p_rDoc.getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 )) );
608 :
609 3 : SdrObjListIter aIter( rSdrPage, IM_FLAT );
610 6 : while( aIter.IsMore() )
611 : {
612 0 : SdrObject* pObj( aIter.Next() );
613 0 : if ( !dynamic_cast<SwVirtFlyDrawObj*>(pObj) &&
614 0 : !dynamic_cast<SwFlyDrawObj*>(pObj) )
615 : {
616 0 : bExistsDrawObjs = true;
617 0 : break;
618 : }
619 3 : }
620 : }
621 :
622 3 : return bExistsDrawObjs;
623 : }
624 :
625 0 : bool AllDrawObjsOnPage( SwDoc& p_rDoc )
626 : {
627 0 : bool bAllDrawObjsOnPage( true );
628 :
629 0 : if ( p_rDoc.getIDocumentDrawModelAccess().GetDrawModel() &&
630 0 : p_rDoc.getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 ) )
631 : {
632 0 : const SdrPage& rSdrPage( *(p_rDoc.getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 )) );
633 :
634 0 : SdrObjListIter aIter( rSdrPage, IM_FLAT );
635 0 : while( aIter.IsMore() )
636 : {
637 0 : SdrObject* pObj( aIter.Next() );
638 0 : if ( !dynamic_cast<SwVirtFlyDrawObj*>(pObj) &&
639 0 : !dynamic_cast<SwFlyDrawObj*>(pObj) )
640 : {
641 : SwDrawContact* pDrawContact =
642 0 : dynamic_cast<SwDrawContact*>(::GetUserCall( pObj ));
643 0 : if ( pDrawContact )
644 : {
645 : SwAnchoredDrawObject* pAnchoredDrawObj =
646 0 : dynamic_cast<SwAnchoredDrawObject*>(pDrawContact->GetAnchoredObj( pObj ));
647 :
648 : // error handling
649 : {
650 0 : if ( !pAnchoredDrawObj )
651 : {
652 : OSL_FAIL( "<docfunc::AllDrawObjsOnPage() - missing anchored draw object" );
653 0 : bAllDrawObjsOnPage = false;
654 0 : break;
655 : }
656 : }
657 :
658 0 : if ( pAnchoredDrawObj->NotYetPositioned() )
659 : {
660 : // The drawing object isn't yet layouted.
661 : // Thus, it isn't known, if all drawing objects are on page.
662 0 : bAllDrawObjsOnPage = false;
663 0 : break;
664 : }
665 0 : else if ( pAnchoredDrawObj->IsOutsidePage() )
666 : {
667 0 : bAllDrawObjsOnPage = false;
668 0 : break;
669 : }
670 : }
671 : else
672 : {
673 : // contact object of drawing object doesn't exists.
674 : // Thus, the drawing object isn't yet positioned.
675 : // Thus, it isn't known, if all drawing objects are on page.
676 0 : bAllDrawObjsOnPage = false;
677 0 : break;
678 : }
679 : }
680 0 : }
681 : }
682 :
683 0 : return bAllDrawObjsOnPage;
684 : }
685 177 : }
686 :
687 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|