android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / doc / docdraw.cxx
blobcd1883ee346bfc4518ecdff885c9427ce5bd6961
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include <hintids.hxx>
20 #include <editeng/flditem.hxx>
21 #include <editeng/editeng.hxx>
22 #include <editeng/colritem.hxx>
23 #include <svx/svdpage.hxx>
24 #include <svx/svdogrp.hxx>
25 #include <editeng/measfld.hxx>
26 #include <sal/log.hxx>
27 #include <osl/diagnose.h>
28 #include <fmtanchr.hxx>
29 #include <charatr.hxx>
30 #include <frmfmt.hxx>
31 #include <charfmt.hxx>
32 #include <viewimp.hxx>
33 #include <doc.hxx>
34 #include <docfunc.hxx>
35 #include <IDocumentUndoRedo.hxx>
36 #include <IDocumentDrawModelAccess.hxx>
37 #include <IDocumentState.hxx>
38 #include <IDocumentLayoutAccess.hxx>
39 #include <IDocumentStylePoolAccess.hxx>
40 #include <poolfmt.hxx>
41 #include <drawdoc.hxx>
42 #include <UndoDraw.hxx>
43 #include <swundo.hxx>
44 #include <dcontact.hxx>
45 #include <dview.hxx>
46 #include <mvsave.hxx>
47 #include <flyfrm.hxx>
48 #include <dflyobj.hxx>
49 #include <txtfrm.hxx>
50 #include <editeng/frmdiritem.hxx>
51 #include <fmtornt.hxx>
52 #include <svx/svditer.hxx>
54 #include <vector>
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::linguistic2;
59 /** local method to determine positioning and alignment attributes for a drawing
60 * object, which is newly connected to the layout.
62 * Used for a newly formed group object <SwDoc::GroupSelection(..)>
63 * and the members of a destroyed group <SwDoc::UnGroupSelection(..)>
65 static void lcl_AdjustPositioningAttr( SwDrawFrameFormat* _pFrameFormat,
66 const SdrObject& _rSdrObj )
68 const SwContact* pContact = GetUserCall( &_rSdrObj );
69 OSL_ENSURE( pContact, "<lcl_AdjustPositioningAttr(..)> - missing contact object." );
71 // determine position of new group object relative to its anchor frame position
72 SwTwips nHoriRelPos = 0;
73 SwTwips nVertRelPos = 0;
75 const SwFrame* pAnchorFrame = pContact->GetAnchoredObj( &_rSdrObj )->GetAnchorFrame();
76 OSL_ENSURE( !pAnchorFrame ||
77 !pAnchorFrame->IsTextFrame() ||
78 !static_cast<const SwTextFrame*>(pAnchorFrame)->IsFollow(),
79 "<lcl_AdjustPositioningAttr(..)> - anchor frame is a follow." );
80 bool bVert = false;
81 bool bR2L = false;
82 // #i45952# - use anchor position of anchor frame, if it exist.
83 Point aAnchorPos;
84 if ( pAnchorFrame )
86 // #i45952#
87 aAnchorPos = pAnchorFrame->GetFrameAnchorPos( ::HasWrap( &_rSdrObj ) );
88 bVert = pAnchorFrame->IsVertical();
89 bR2L = pAnchorFrame->IsRightToLeft();
91 else
93 // #i45952#
94 aAnchorPos = _rSdrObj.GetAnchorPos();
95 // If no anchor frame exist - e.g. because no layout exists - the
96 // default layout direction is taken.
97 const SvxFrameDirectionItem& rDirItem =
98 _pFrameFormat->GetAttrSet().GetPool()->GetDefaultItem( RES_FRAMEDIR );
99 switch ( rDirItem.GetValue() )
101 case SvxFrameDirection::Vertical_LR_TB:
103 // vertical from left-to-right
104 bVert = true;
105 bR2L = true;
106 OSL_FAIL( "<lcl_AdjustPositioningAttr(..)> - vertical from left-to-right not supported." );
108 break;
109 case SvxFrameDirection::Vertical_RL_TB:
111 // vertical from right-to-left
112 bVert = true;
113 bR2L = false;
115 break;
116 case SvxFrameDirection::Horizontal_RL_TB:
118 // horizontal from right-to-left
119 bVert = false;
120 bR2L = true;
122 break;
123 case SvxFrameDirection::Horizontal_LR_TB:
125 // horizontal from left-to-right
126 bVert = false;
127 bR2L = false;
129 break;
130 case SvxFrameDirection::Environment:
131 SAL_WARN("sw.core", "lcl_AdjustPositioningAttr(..) SvxFrameDirection::Environment not supported");
132 break;
133 default: break;
137 // use geometry of drawing object
138 const tools::Rectangle aObjRect = _rSdrObj.GetSnapRect();
140 if ( bVert )
142 if ( bR2L ) {
143 //SvxFrameDirection::Vertical_LR_TB
144 nHoriRelPos = aObjRect.Left() - aAnchorPos.getX();
145 nVertRelPos = aObjRect.Top() - aAnchorPos.getY();
146 } else {
147 //SvxFrameDirection::Vertical_RL_TB
148 nHoriRelPos = aObjRect.Top() - aAnchorPos.getY();
149 nVertRelPos = aAnchorPos.getX() - aObjRect.Right();
152 else if ( bR2L )
154 nHoriRelPos = aAnchorPos.getX() - aObjRect.Right();
155 nVertRelPos = aObjRect.Top() - aAnchorPos.getY();
157 else
159 nHoriRelPos = aObjRect.Left() - aAnchorPos.getX();
160 nVertRelPos = aObjRect.Top() - aAnchorPos.getY();
164 _pFrameFormat->SetFormatAttr( SwFormatHoriOrient( nHoriRelPos, text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
165 _pFrameFormat->SetFormatAttr( SwFormatVertOrient( nVertRelPos, text::VertOrientation::NONE, text::RelOrientation::FRAME ) );
166 // #i44334#, #i44681# - positioning attributes already set
167 _pFrameFormat->PosAttrSet();
168 // #i34750# - keep current object rectangle for drawing
169 // objects. The object rectangle is used on events from the drawing layer
170 // to adjust the positioning attributes - see <SwDrawContact::Changed_(..)>.
172 const SwAnchoredObject* pAnchoredObj = pContact->GetAnchoredObj( &_rSdrObj );
173 if ( auto pAnchoredDrawObj = dynamic_cast<const SwAnchoredDrawObject*>( pAnchoredObj) )
175 const tools::Rectangle aObjRect = _rSdrObj.GetSnapRect();
176 const_cast<SwAnchoredDrawObject*>(pAnchoredDrawObj)
177 ->SetLastObjRect( aObjRect );
182 SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView )
184 // replace marked 'virtual' drawing objects by the corresponding 'master'
185 // drawing objects.
186 SwDrawView::ReplaceMarkedDrawVirtObjs( rDrawView );
188 const SdrMarkList &rMrkList = rDrawView.GetMarkedObjectList();
189 SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
190 bool bNoGroup = ( nullptr == pObj->getParentSdrObjectFromSdrObject() );
191 SwDrawContact* pNewContact = nullptr;
192 if( bNoGroup )
194 SwDrawFrameFormat *pFormat = nullptr;
196 // Revoke anchor attribute.
197 SwDrawContact *pMyContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
198 const SwFormatAnchor aAnch( pMyContact->GetFormat()->GetAnchor() );
200 std::unique_ptr<SwUndoDrawGroup> pUndo;
201 if (GetIDocumentUndoRedo().DoesUndo())
202 pUndo.reset(new SwUndoDrawGroup( o3tl::narrowing<sal_uInt16>(rMrkList.GetMarkCount()), *this));
204 // #i53320#
205 bool bGroupMembersNotPositioned( false );
207 SwAnchoredDrawObject* pAnchoredDrawObj =
208 static_cast<SwAnchoredDrawObject*>(pMyContact->GetAnchoredObj( pObj ));
209 bGroupMembersNotPositioned = pAnchoredDrawObj->NotYetPositioned();
212 std::map<const SdrObject*, SwFrameFormat*> vSavedTextBoxes;
213 // Destroy ContactObjects and formats.
214 for( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
216 pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
217 SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
219 // #i53320#
220 #if OSL_DEBUG_LEVEL > 0
221 SwAnchoredDrawObject* pAnchoredDrawObj =
222 static_cast<SwAnchoredDrawObject*>(pContact->GetAnchoredObj( pObj ));
223 OSL_ENSURE( bGroupMembersNotPositioned == pAnchoredDrawObj->NotYetPositioned(),
224 "<SwDoc::GroupSelection(..)> - group members have different positioning status!" );
225 #endif
226 // Before the format will be killed, save its textbox for later use.
227 if (auto pShapeFormat = pContact->GetFormat())
228 if (auto pTextBoxNode = pShapeFormat->GetOtherTextBoxFormats())
229 for (const auto& rTextBoxElement : pTextBoxNode->GetAllTextBoxes())
230 vSavedTextBoxes.emplace(rTextBoxElement);
232 pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
233 // Deletes itself!
234 pContact->Changed(*pObj, SdrUserCallType::Delete, pObj->GetLastBoundRect() );
235 pObj->SetUserCall( nullptr );
237 if( pUndo )
238 pUndo->AddObj( i, pFormat, pObj );
239 else
240 DelFrameFormat( pFormat );
242 // #i45952# - re-introduce position normalization of group member
243 // objects, because its anchor position is cleared, when they are
244 // grouped.
245 Point aAnchorPos( pObj->GetAnchorPos() );
246 pObj->NbcSetAnchorPos( Point( 0, 0 ) );
247 pObj->NbcMove( Size( aAnchorPos.getX(), aAnchorPos.getY() ) );
250 pFormat = MakeDrawFrameFormat( GetUniqueDrawObjectName(),
251 GetDfltFrameFormat() );
252 pFormat->SetFormatAttr( aAnch );
253 // #i36010# - set layout direction of the position
254 pFormat->SetPositionLayoutDir(
255 text::PositionLayoutDir::PositionInLayoutDirOfAnchor );
257 // Add the saved textboxes to the new format.
258 auto pTextBoxNode = std::make_shared<SwTextBoxNode>(
259 SwTextBoxNode(static_cast<SwFrameFormat*>(pFormat)));
260 for (const auto& pTextBoxEntry : vSavedTextBoxes)
262 pTextBoxNode->AddTextBox(const_cast<SdrObject*>(pTextBoxEntry.first),
263 pTextBoxEntry.second);
264 pTextBoxEntry.second->SetOtherTextBoxFormats(pTextBoxNode);
266 pFormat->SetOtherTextBoxFormats(pTextBoxNode);
267 vSavedTextBoxes.clear();
269 rDrawView.GroupMarked();
270 OSL_ENSURE( rMrkList.GetMarkCount() == 1, "GroupMarked more or none groups." );
272 SdrObject* pNewGroupObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
273 pNewGroupObj->SetName(pFormat->GetName());
274 pNewContact = new SwDrawContact( pFormat, pNewGroupObj );
275 // #i35635#
276 pNewContact->MoveObjToVisibleLayer( pNewGroupObj );
277 pNewContact->ConnectToLayout();
278 // #i53320# - No adjustment of the positioning and alignment
279 // attributes, if group members aren't positioned yet.
280 if ( !bGroupMembersNotPositioned )
282 // #i26791# - Adjust positioning and alignment attributes.
283 lcl_AdjustPositioningAttr( pFormat, *pNewGroupObj );
286 if( pUndo )
288 pUndo->SetGroupFormat( pFormat );
289 GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) );
292 else
294 if (GetIDocumentUndoRedo().DoesUndo())
296 GetIDocumentUndoRedo().ClearRedo();
299 rDrawView.GroupMarked();
300 OSL_ENSURE( rMrkList.GetMarkCount() == 1, "GroupMarked more or none groups." );
303 return pNewContact;
306 static void lcl_CollectTextBoxesForSubGroupObj(SwFrameFormat* pTargetFormat, std::shared_ptr<SwTextBoxNode> pTextBoxNode,
307 SdrObject* pSourceObjs)
309 if (auto pChildrenObjs = pSourceObjs->getChildrenOfSdrObject())
310 for (size_t i = 0; i < pChildrenObjs->GetObjCount(); ++i)
311 lcl_CollectTextBoxesForSubGroupObj(pTargetFormat, pTextBoxNode, pChildrenObjs->GetObj(i));
312 else
314 if (auto pTextBox = pTextBoxNode->GetTextBox(pSourceObjs))
316 if (!pTargetFormat->GetOtherTextBoxFormats())
318 pTargetFormat->SetOtherTextBoxFormats(std::make_shared<SwTextBoxNode>(SwTextBoxNode(pTargetFormat)));
320 pTargetFormat->GetOtherTextBoxFormats()->AddTextBox(pSourceObjs, pTextBox);
321 pTextBox->SetOtherTextBoxFormats(pTargetFormat->GetOtherTextBoxFormats());
327 void SwDoc::UnGroupSelection( SdrView& rDrawView )
329 bool const bUndo = GetIDocumentUndoRedo().DoesUndo();
330 if( bUndo )
332 GetIDocumentUndoRedo().ClearRedo();
335 // replace marked 'virtual' drawing objects by the corresponding 'master'
336 // drawing objects.
337 SwDrawView::ReplaceMarkedDrawVirtObjs( rDrawView );
339 const SdrMarkList &rMrkList = rDrawView.GetMarkedObjectList();
340 std::unique_ptr<std::vector< std::pair< SwDrawFrameFormat*, SdrObject* > >[]> pFormatsAndObjs;
341 const size_t nMarkCount( rMrkList.GetMarkCount() );
342 if ( nMarkCount )
344 pFormatsAndObjs.reset( new std::vector< std::pair< SwDrawFrameFormat*, SdrObject* > >[nMarkCount] );
345 SdrObject *pMyObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
346 if( !pMyObj->getParentSdrObjectFromSdrObject() )
348 for ( size_t i = 0; i < nMarkCount; ++i )
350 SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
351 if ( auto pObjGroup = dynamic_cast<SdrObjGroup*>(pObj) )
353 SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
355 std::shared_ptr<SwTextBoxNode> pTextBoxNode;
356 if (auto pGroupFormat = pContact->GetFormat())
357 pTextBoxNode = pGroupFormat->GetOtherTextBoxFormats();
359 SwFormatAnchor aAnch( pContact->GetFormat()->GetAnchor() );
360 SdrObjList *pLst = pObjGroup->GetSubList();
362 SwUndoDrawUnGroup* pUndo = nullptr;
363 if( bUndo )
365 pUndo = new SwUndoDrawUnGroup( pObjGroup, *this );
366 GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo));
369 for ( size_t i2 = 0; i2 < pLst->GetObjCount(); ++i2 )
371 SdrObject* pSubObj = pLst->GetObj( i2 );
372 SwDrawFrameFormat *pFormat = MakeDrawFrameFormat( GetUniqueShapeName(),
373 GetDfltFrameFormat() );
374 pFormat->SetFormatAttr( aAnch );
376 if (pTextBoxNode)
378 if (!pObj->getChildrenOfSdrObject())
380 if (auto pTextBoxFormat = pTextBoxNode->GetTextBox(pSubObj))
382 auto pNewTextBoxNode =std::make_shared<SwTextBoxNode>(SwTextBoxNode(pFormat));
383 pNewTextBoxNode->AddTextBox(pSubObj, pTextBoxFormat);
384 pFormat->SetOtherTextBoxFormats(pNewTextBoxNode);
385 pTextBoxFormat->SetOtherTextBoxFormats(pNewTextBoxNode);
388 else
390 lcl_CollectTextBoxesForSubGroupObj(pFormat, pTextBoxNode, pSubObj);
393 // #i36010# - set layout direction of the position
394 pFormat->SetPositionLayoutDir(
395 text::PositionLayoutDir::PositionInLayoutDirOfAnchor );
396 if (pSubObj->GetName().isEmpty())
397 pSubObj->SetName(pFormat->GetName());
398 pFormatsAndObjs[i].emplace_back( pFormat, pSubObj );
400 if( bUndo )
401 pUndo->AddObj( o3tl::narrowing<sal_uInt16>(i2), pFormat );
407 rDrawView.UnGroupMarked();
408 // creation of <SwDrawContact> instances for the former group members and
409 // its connection to the Writer layout.
410 for ( size_t i = 0; i < nMarkCount; ++i )
412 SwUndoDrawUnGroupConnectToLayout* pUndo = nullptr;
413 if( bUndo )
415 pUndo = new SwUndoDrawUnGroupConnectToLayout(*this);
416 GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo));
419 while ( !pFormatsAndObjs[i].empty() )
421 SwDrawFrameFormat* pFormat( pFormatsAndObjs[i].back().first );
422 SdrObject* pObj( pFormatsAndObjs[i].back().second );
423 pFormatsAndObjs[i].pop_back();
425 SwDrawContact* pContact = new SwDrawContact( pFormat, pObj );
426 pContact->MoveObjToVisibleLayer( pObj );
427 pContact->ConnectToLayout();
428 lcl_AdjustPositioningAttr( pFormat, *pObj );
430 if ( bUndo )
432 pUndo->AddFormatAndObj( pFormat, pObj );
438 bool SwDoc::DeleteSelection( SwDrawView& rDrawView )
440 bool bCallBase = false;
441 const SdrMarkList &rMrkList = rDrawView.GetMarkedObjectList();
442 if( rMrkList.GetMarkCount() )
444 GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr);
445 bool bDelMarked = true;
447 if( 1 == rMrkList.GetMarkCount() )
449 SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
450 if( auto pDrawObj = dynamic_cast<SwVirtFlyDrawObj*>( pObj) )
452 SwFlyFrameFormat* pFrameFormat = pDrawObj->GetFlyFrame()->GetFormat();
453 if( pFrameFormat )
455 getIDocumentLayoutAccess().DelLayoutFormat( pFrameFormat );
456 bDelMarked = false;
461 for( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
463 SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
464 if( dynamic_cast<const SwVirtFlyDrawObj*>( pObj) == nullptr )
466 SwDrawContact *pC = static_cast<SwDrawContact*>(GetUserCall(pObj));
467 SwDrawFrameFormat *pFrameFormat = static_cast<SwDrawFrameFormat*>(pC->GetFormat());
468 if( pFrameFormat &&
469 RndStdIds::FLY_AS_CHAR == pFrameFormat->GetAnchor().GetAnchorId() )
471 rDrawView.MarkObj( pObj, rDrawView.Imp().GetPageView(), true );
472 --i;
473 getIDocumentLayoutAccess().DelLayoutFormat( pFrameFormat );
478 if( rMrkList.GetMarkCount() && bDelMarked )
480 SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
481 if( !pObj->getParentSdrObjectFromSdrObject() )
483 std::unique_ptr<SwUndoDrawDelete> pUndo;
484 if (GetIDocumentUndoRedo().DoesUndo())
485 pUndo.reset(new SwUndoDrawDelete( o3tl::narrowing<sal_uInt16>(rMrkList.GetMarkCount()), *this ));
487 // Destroy ContactObjects, save formats.
488 for( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
490 const SdrMark& rMark = *rMrkList.GetMark( i );
491 pObj = rMark.GetMarkedSdrObj();
492 SwDrawContact *pContact = static_cast<SwDrawContact*>(pObj->GetUserCall());
493 if( pContact ) // of course not for grouped objects
495 SwDrawFrameFormat *pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
496 // before delete of selection is performed, marked
497 // <SwDrawVirtObj>-objects have to be replaced by its
498 // reference objects. Thus, assert, if a
499 // <SwDrawVirt>-object is found in the mark list.
500 if ( dynamic_cast<const SwDrawVirtObj*>( pObj) != nullptr )
502 OSL_FAIL( "<SwDrawVirtObj> is still marked for delete. application will crash!" );
504 // Deletes itself!
505 pContact->Changed(*pObj, SdrUserCallType::Delete, pObj->GetLastBoundRect() );
506 pObj->SetUserCall( nullptr );
508 if( pUndo )
509 pUndo->AddObj( pFormat, rMark );
510 else
511 DelFrameFormat( pFormat );
515 if( pUndo )
517 GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) );
520 bCallBase = true;
522 getIDocumentState().SetModified();
524 GetIDocumentUndoRedo().EndUndo(SwUndoId::EMPTY, nullptr);
527 return bCallBase;
530 ZSortFly::ZSortFly(const SwFrameFormat* pFrameFormat, const SwFormatAnchor* pFlyAn, sal_uInt32 nArrOrdNum)
531 : m_pFormat(pFrameFormat)
532 , m_pAnchor(pFlyAn)
533 , m_nOrdNum(nArrOrdNum)
535 SAL_WARN_IF(m_pFormat->Which() != RES_FLYFRMFMT && m_pFormat->Which() != RES_DRAWFRMFMT, "sw.core", "What kind of format is this?");
536 m_pFormat->CallSwClientNotify(sw::GetZOrderHint(m_nOrdNum));
539 /// In the Outliner, set a link to the method for field display in edit objects.
540 void SwDoc::SetCalcFieldValueHdl(Outliner* pOutliner)
542 pOutliner->SetCalcFieldValueHdl(LINK(this, SwDoc, CalcFieldValueHdl));
545 /// Recognise fields/URLs in the Outliner and set how they are displayed.
546 IMPL_LINK(SwDoc, CalcFieldValueHdl, EditFieldInfo*, pInfo, void)
548 if (!pInfo)
549 return;
551 const SvxFieldItem& rField = pInfo->GetField();
552 const SvxFieldData* pField = rField.GetField();
554 if (auto pDateField = dynamic_cast<const SvxDateField*>( pField))
556 // Date field
557 pInfo->SetRepresentation(
558 pDateField->GetFormatted(
559 *GetNumberFormatter(), LANGUAGE_SYSTEM) );
561 else if (auto pURLField = dynamic_cast<const SvxURLField*>( pField))
563 // URL field
564 switch ( pURLField->GetFormat() )
566 case SvxURLFormat::AppDefault: //!!! Can be set in App???
567 case SvxURLFormat::Repr:
568 pInfo->SetRepresentation(pURLField->GetRepresentation());
569 break;
571 case SvxURLFormat::Url:
572 pInfo->SetRepresentation(pURLField->GetURL());
573 break;
576 sal_uInt16 nChrFormat;
578 if (IsVisitedURL(pURLField->GetURL()))
579 nChrFormat = RES_POOLCHR_INET_VISIT;
580 else
581 nChrFormat = RES_POOLCHR_INET_NORMAL;
583 SwFormat *pFormat = getIDocumentStylePoolAccess().GetCharFormatFromPool(nChrFormat);
585 Color aColor(COL_LIGHTBLUE);
586 if (pFormat)
587 aColor = pFormat->GetColor().GetValue();
589 pInfo->SetTextColor(aColor);
591 else if (dynamic_cast<const SdrMeasureField*>( pField))
593 // Clear measure field
594 pInfo->SetFieldColor(std::optional<Color>());
596 else if ( auto pTimeField = dynamic_cast<const SvxExtTimeField*>( pField) )
598 // Time field
599 pInfo->SetRepresentation(
600 pTimeField->GetFormatted(*GetNumberFormatter(), LANGUAGE_SYSTEM) );
602 else
604 OSL_FAIL("unknown field command");
605 pInfo->SetRepresentation( OUString( '?' ) );
609 // #i62875#
610 namespace docfunc
612 bool ExistsDrawObjs( SwDoc& p_rDoc )
614 bool bExistsDrawObjs( false );
616 if ( p_rDoc.getIDocumentDrawModelAccess().GetDrawModel() &&
617 p_rDoc.getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 ) )
619 const SdrPage& rSdrPage( *(p_rDoc.getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 )) );
621 SdrObjListIter aIter( &rSdrPage, SdrIterMode::Flat );
622 while( aIter.IsMore() )
624 SdrObject* pObj( aIter.Next() );
625 if ( !dynamic_cast<SwVirtFlyDrawObj*>(pObj) &&
626 !dynamic_cast<SwFlyDrawObj*>(pObj) )
628 bExistsDrawObjs = true;
629 break;
634 return bExistsDrawObjs;
637 bool AllDrawObjsOnPage( SwDoc& p_rDoc )
639 bool bAllDrawObjsOnPage( true );
641 if ( p_rDoc.getIDocumentDrawModelAccess().GetDrawModel() &&
642 p_rDoc.getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 ) )
644 const SdrPage& rSdrPage( *(p_rDoc.getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 )) );
646 SdrObjListIter aIter( &rSdrPage, SdrIterMode::Flat );
647 while( aIter.IsMore() )
649 SdrObject* pObj( aIter.Next() );
650 if ( !dynamic_cast<SwVirtFlyDrawObj*>(pObj) &&
651 !dynamic_cast<SwFlyDrawObj*>(pObj) )
653 SwDrawContact* pDrawContact =
654 dynamic_cast<SwDrawContact*>(::GetUserCall( pObj ));
655 if ( pDrawContact )
657 SwAnchoredDrawObject* pAnchoredDrawObj =
658 dynamic_cast<SwAnchoredDrawObject*>(pDrawContact->GetAnchoredObj( pObj ));
660 // error handling
662 if ( !pAnchoredDrawObj )
664 OSL_FAIL( "<docfunc::AllDrawObjsOnPage() - missing anchored draw object" );
665 bAllDrawObjsOnPage = false;
666 break;
670 if ( pAnchoredDrawObj->NotYetPositioned() )
672 // The drawing object isn't yet layouted.
673 // Thus, it isn't known, if all drawing objects are on page.
674 bAllDrawObjsOnPage = false;
675 break;
677 else if ( pAnchoredDrawObj->IsOutsidePage() )
679 bAllDrawObjsOnPage = false;
680 break;
683 else
685 // contact object of drawing object doesn't exists.
686 // Thus, the drawing object isn't yet positioned.
687 // Thus, it isn't known, if all drawing objects are on page.
688 bAllDrawObjsOnPage = false;
689 break;
695 return bAllDrawObjsOnPage;
699 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */