bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / shells / drwbassh.cxx
blob7d3c2802a30fa3a7a7fe056039b9f09bdf0e4810
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/shl.hxx>
21 #include <hintids.hxx>
22 #include <helpid.h>
23 #include <swtypes.hxx>
24 #include <sfx2/objface.hxx>
25 #include <sfx2/request.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <svl/aeitem.hxx>
28 #include <svx/svdview.hxx>
29 #include <vcl/msgbox.hxx>
30 #include <svl/srchitem.hxx>
31 #include <svl/whiter.hxx>
32 #include <svx/swframevalidation.hxx>
33 #include <svx/anchorid.hxx>
34 #include <sfx2/htmlmode.hxx>
35 #include <uitool.hxx>
36 #include <fmtornt.hxx>
37 #include <cmdid.h>
38 #include <swmodule.hxx>
39 #include <wrtsh.hxx>
40 #include <wview.hxx>
41 #include <edtwin.hxx>
42 #include <viewopt.hxx>
43 #include <dcontact.hxx>
44 #include <frmfmt.hxx>
45 #include <wrap.hxx>
46 #include <drawbase.hxx>
47 #include <drwbassh.hxx>
48 #include <swdtflvr.hxx>
49 #include <svx/svdogrp.hxx>
50 #include <svx/svdpage.hxx>
51 #include <svx/svditer.hxx>
53 #include <shells.hrc>
54 #define SwDrawBaseShell
55 #include <sfx2/msg.hxx>
56 #include <swslots.hxx>
57 #include <svx/svxdlg.hxx>
58 #include <svx/dialogs.hrc>
59 #include "swabstdlg.hxx"
60 #include "dialog.hrc"
61 #include <swundo.hxx>
62 #include <com/sun/star/text/HoriOrientation.hpp>
63 #include <com/sun/star/text/VertOrientation.hpp>
64 #include <com/sun/star/text/RelOrientation.hpp>
66 #include <IDocumentDrawModelAccess.hxx>
68 using namespace ::com::sun::star;
70 SFX_IMPL_INTERFACE(SwDrawBaseShell, SwBaseShell, SW_RES(0))
74 TYPEINIT1(SwDrawBaseShell,SwBaseShell)
76 SwDrawBaseShell::SwDrawBaseShell(SwView &_rView):
77 SwBaseShell( _rView )
79 GetShell().NoEdit(true);
81 SwEditWin& rWin = GetView().GetEditWin();
83 rWin.SetBezierMode(SID_BEZIER_MOVE);
85 if ( !_rView.GetDrawFuncPtr() )
86 _rView.GetEditWin().StdDrawMode( OBJ_NONE, sal_True );
88 SwTransferable::CreateSelection( GetShell() );
91 SwDrawBaseShell::~SwDrawBaseShell()
93 GetView().ExitDraw();
94 GetShell().Edit();
95 SwTransferable::ClearSelection( GetShell() );
98 void SwDrawBaseShell::Execute(SfxRequest &rReq)
100 SwWrtShell *pSh = &GetShell();
101 SdrView* pSdrView = pSh->GetDrawView();
102 const SfxItemSet *pArgs = rReq.GetArgs();
103 sal_uInt16 nSlotId = rReq.GetSlot();
104 sal_Bool bChanged = pSdrView->GetModel()->IsChanged();
105 pSdrView->GetModel()->SetChanged(sal_False);
106 const SfxPoolItem* pItem = 0;
107 if(pArgs)
108 pArgs->GetItemState(nSlotId, sal_False, &pItem);
110 //Special case align by menu
111 if(pItem && nSlotId == SID_OBJECT_ALIGN)
113 OSL_ENSURE(PTR_CAST(SfxEnumItem, pItem),"SfxEnumItem expected");
114 nSlotId = nSlotId + ((const SfxEnumItem*)pItem)->GetValue();
115 nSlotId++;
118 sal_Bool bAlignPossible = pSh->IsAlignPossible();
120 sal_Bool bTopParam = sal_True, bBottomParam = sal_True;
121 bool bNotify = false;
122 bool bDone = false;
123 SfxBindings& rBind = GetView().GetViewFrame()->GetBindings();
125 switch (nSlotId)
127 case FN_DRAW_WRAP_DLG:
129 if(pSdrView->AreObjectsMarked())
131 if(!pArgs)
133 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
134 if( rMarkList.GetMark(0) != 0 )
136 SfxItemSet aSet(GetPool(), RES_SURROUND, RES_SURROUND,
137 RES_ANCHOR, RES_ANCHOR,
138 RES_LR_SPACE, RES_UL_SPACE,
139 SID_HTML_MODE, SID_HTML_MODE,
140 FN_DRAW_WRAP_DLG, FN_DRAW_WRAP_DLG,
143 aSet.Put(SfxBoolItem(SID_HTML_MODE,
144 0 != ::GetHtmlMode(pSh->GetView().GetDocShell())));
146 aSet.Put(SfxInt16Item(FN_DRAW_WRAP_DLG, pSh->GetLayerId()));
148 pSh->GetObjAttr(aSet);
149 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
150 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
152 SfxAbstractDialog* pDlg = pFact->CreateSwWrapDlg( GetView().GetWindow(), aSet, pSh, sal_True, RC_DLG_SWWRAPDLG );
153 OSL_ENSURE(pDlg, "Dialogdiet fail!");
155 if (pDlg->Execute() == RET_OK)
157 const SfxPoolItem* pWrapItem;
158 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
159 if(SFX_ITEM_SET == pOutSet->GetItemState(FN_DRAW_WRAP_DLG, sal_False, &pWrapItem))
161 short nLayer = ((const SfxInt16Item*)pWrapItem)->GetValue();
162 if (nLayer == 1)
163 pSh->SelectionToHeaven();
164 else
165 pSh->SelectionToHell();
168 pSh->SetObjAttr(*pOutSet);
170 delete pDlg;
175 break;
177 case SID_ATTR_TRANSFORM:
179 if(pSdrView->AreObjectsMarked())
181 if(!pArgs)
183 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
184 if( rMarkList.GetMark(0) != 0 )
186 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
187 SfxAbstractTabDialog *pDlg=NULL;
188 bool bCaption = false;
190 // Allowed anchorages:
191 short nAnchor = pSh->GetAnchorId();
192 sal_uInt16 nAllowedAnchors = SVX_OBJ_AT_CNTNT | SVX_OBJ_IN_CNTNT | SVX_OBJ_PAGE;
193 sal_uInt16 nHtmlMode = ::GetHtmlMode(pSh->GetView().GetDocShell());
195 if ( pSh->IsFlyInFly() )
196 nAllowedAnchors |= SVX_OBJ_AT_FLY;
198 if (pObj->GetObjIdentifier() == OBJ_CAPTION )
199 bCaption = true;
201 if (bCaption)
203 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
204 if ( pFact )
206 AbstractSvxCaptionDialog* pCaptionDlg =
207 pFact->CreateCaptionDialog( NULL, pSdrView, nAllowedAnchors );
208 pCaptionDlg->SetValidateFramePosLink( LINK(this, SwDrawBaseShell, ValidatePosition) );
209 pDlg = pCaptionDlg;
210 OSL_ENSURE(pDlg, "Dialogdiet fail!");
213 else
215 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
216 if ( pFact )
219 AbstractSvxTransformTabDialog* pTransform =
220 pFact->CreateSvxTransformTabDialog( NULL, NULL, pSdrView, nAllowedAnchors );
221 pTransform->SetValidateFramePosLink( LINK(this, SwDrawBaseShell, ValidatePosition) );
222 pDlg = pTransform;
223 OSL_ENSURE(pDlg, "Dialogdiet fail!");
226 SfxItemSet aNewAttr(pSdrView->GetGeoAttrFromMarked());
228 const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
229 SfxItemSet aSet( *aNewAttr.GetPool(), pRange );
230 FieldUnit eMetric = ::GetDfltMetric(0 != dynamic_cast<SwWebView*>(&GetView()));
231 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
233 aSet.Put( aNewAttr, sal_False );
235 if (bCaption)
236 pSdrView->GetAttributes( aSet );
238 aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_ANCHOR, nAnchor));
239 sal_Bool bRTL;
240 sal_Bool bVertL2R;
241 aSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_IN_VERTICAL_TEXT, pSh->IsFrmVertical(sal_True, bRTL, bVertL2R)));
242 aSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_IN_RTL_TEXT, bRTL));
244 SwFrmFmt* pFrmFmt = FindFrmFmt( pObj );
246 aSet.Put( pFrmFmt->GetFmtAttr(RES_FOLLOW_TEXT_FLOW) );
248 SwFmtVertOrient aVOrient((const SwFmtVertOrient&)pFrmFmt->GetFmtAttr(RES_VERT_ORIENT));
249 aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_VERT_ORIENT, aVOrient.GetVertOrient()));
250 aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_VERT_RELATION, aVOrient.GetRelationOrient() ));
251 aSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_VERT_POSITION, aVOrient.GetPos()));
253 SwFmtHoriOrient aHOrient((const SwFmtHoriOrient&)pFrmFmt->GetFmtAttr(RES_HORI_ORIENT));
254 aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_HORI_ORIENT, aHOrient.GetHoriOrient()));
255 aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_HORI_RELATION, aHOrient.GetRelationOrient() ));
256 aSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_HORI_MIRROR, aHOrient.IsPosToggle()));
257 aSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_HORI_POSITION, aHOrient.GetPos()));
259 aSet.Put(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
261 pDlg->SetInputSet( &aSet );
263 if (pDlg->Execute() == RET_OK)
265 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
266 pSh->StartAllAction();
268 // #i30451#
269 pSh->StartUndo(UNDO_INSFMTATTR);
271 pSdrView->SetGeoAttrToMarked(*pOutSet);
273 if (bCaption)
274 pSdrView->SetAttributes(*pOutSet);
276 bool bPosCorr =
277 SFX_ITEM_SET != pOutSet->GetItemState(
278 SID_ATTR_TRANSFORM_POS_X, sal_False ) &&
279 SFX_ITEM_SET != pOutSet->GetItemState(
280 SID_ATTR_TRANSFORM_POS_Y, sal_False );
282 SfxItemSet aFrmAttrSet(GetPool(), RES_FRMATR_BEGIN, RES_FRMATR_END - 1);
284 bool bSingleSelection = rMarkList.GetMarkCount() == 1;
286 const SfxPoolItem* pAnchorItem;
287 if(SFX_ITEM_SET == pOutSet->GetItemState(
288 SID_ATTR_TRANSFORM_ANCHOR, sal_False, &pAnchorItem))
290 if(!bSingleSelection)
291 pSh->ChgAnchor(((const SfxInt16Item*)pAnchorItem)
292 ->GetValue(), false, bPosCorr );
293 else
295 SwFmtAnchor aAnchor(pFrmFmt->GetAnchor());
296 aAnchor.SetType((RndStdIds)((const SfxInt16Item*)pAnchorItem)->GetValue());
297 aFrmAttrSet.Put( aAnchor );
300 const SfxPoolItem* pHoriOrient = 0;
301 const SfxPoolItem* pHoriRelation = 0;
302 const SfxPoolItem* pHoriPosition = 0;
303 const SfxPoolItem* pHoriMirror = 0;
304 pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_ORIENT, sal_False, &pHoriOrient);
305 pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_RELATION, sal_False, &pHoriRelation);
306 pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_POSITION, sal_False, &pHoriPosition);
307 pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_MIRROR, sal_False, &pHoriMirror);
308 if(pHoriOrient || pHoriRelation || pHoriPosition || pHoriMirror)
310 if(pHoriOrient)
311 aHOrient.SetHoriOrient(
312 static_cast<const SfxInt16Item*>(pHoriOrient)->GetValue());
313 if(pHoriRelation)
314 aHOrient.SetRelationOrient(
315 static_cast<const SfxInt16Item*>(pHoriRelation)->GetValue());
316 if(pHoriPosition)
317 aHOrient.SetPos( static_cast<const SfxInt32Item*>(pHoriPosition)->GetValue());
318 if(pHoriMirror)
319 aHOrient.SetPosToggle( static_cast<const SfxBoolItem*>(pHoriMirror)->GetValue());
320 aFrmAttrSet.Put(aHOrient);
323 const SfxPoolItem* pVertOrient = 0;
324 const SfxPoolItem* pVertRelation = 0;
325 const SfxPoolItem* pVertPosition = 0;
326 pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_ORIENT, sal_False, &pVertOrient);
327 pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_RELATION, sal_False, &pVertRelation);
328 pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_POSITION, sal_False, &pVertPosition);
329 if(pVertOrient || pVertRelation || pVertPosition )
331 if(pVertOrient)
332 aVOrient.SetVertOrient(
333 static_cast<const SfxInt16Item*>(pVertOrient)->GetValue());
334 if(pVertRelation)
335 aVOrient.SetRelationOrient(
336 static_cast<const SfxInt16Item*>(pVertRelation)->GetValue());
337 if(pVertPosition)
338 aVOrient.SetPos( static_cast<const SfxInt32Item*>(pVertPosition)->GetValue());
339 aFrmAttrSet.Put( aVOrient );
341 const SfxPoolItem* pFollowItem = 0;
342 pOutSet->GetItemState(RES_FOLLOW_TEXT_FLOW, sal_False, &pFollowItem);
343 if(pFollowItem)
344 aFrmAttrSet.Put(*pFollowItem);
346 if(aFrmAttrSet.Count())
347 pSh->SetDrawingAttr(aFrmAttrSet);
349 rBind.InvalidateAll(sal_False);
351 // #i30451#
352 pSh->EndUndo( UNDO_INSFMTATTR );
354 pSh->EndAllAction();
356 delete pDlg;
360 else
362 pSdrView->SetGeoAttrToMarked( *pArgs );
366 break;
368 case SID_DELETE:
369 case FN_BACKSPACE:
370 if (pSh->IsObjSelected() && !pSdrView->IsTextEdit())
372 bDone = true;
374 if( GetView().IsDrawRotate() )
376 pSh->SetDragMode( SDRDRAG_MOVE );
377 GetView().FlipDrawRotate();
380 pSh->SetModified();
381 pSh->DelSelectedObj();
383 if (rReq.IsAPI() ||
384 GetView().GetEditWin().IsObjectSelect() )
386 // If basic call, then back to the text shell, because the
387 // Basic otherwise has no possibility to return.
388 if (GetView().GetDrawFuncPtr())
390 GetView().GetDrawFuncPtr()->Deactivate();
391 GetView().SetDrawFuncPtr(NULL);
393 GetView().LeaveDrawCreate(); // Switch to selection mode
396 if (pSh->IsSelFrmMode())
398 pSh->LeaveSelFrmMode();
399 // #105852# FME
401 bNotify = true;
403 break;
405 case SID_GROUP:
406 if (pSh->IsObjSelected() > 1 && pSh->IsGroupAllowed())
408 pSh->GroupSelection();
409 rBind.Invalidate(SID_UNGROUP);
411 break;
413 case SID_UNGROUP:
414 if (pSh->IsGroupSelected())
416 pSh->UnGroupSelection();
417 rBind.Invalidate(SID_GROUP);
419 break;
421 case SID_ENTER_GROUP:
422 if (pSh->IsGroupSelected())
424 pSdrView->EnterMarkedGroup();
425 rBind.InvalidateAll(sal_False);
427 break;
429 case SID_LEAVE_GROUP:
430 if (pSdrView->IsGroupEntered())
432 pSdrView->LeaveOneGroup();
433 rBind.Invalidate(SID_ENTER_GROUP);
434 rBind.Invalidate(SID_UNGROUP);
436 break;
438 case SID_OBJECT_ALIGN_LEFT:
439 case SID_OBJECT_ALIGN_CENTER:
440 case SID_OBJECT_ALIGN_RIGHT:
441 case SID_OBJECT_ALIGN_UP:
442 case SID_OBJECT_ALIGN_MIDDLE:
443 case SID_OBJECT_ALIGN_DOWN:
445 if ( bAlignPossible )
447 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
448 if( rMarkList.GetMarkCount() == 1 && bAlignPossible )
449 { // Do not align objects to each other
450 sal_uInt16 nAnchor = pSh->GetAnchorId();
451 if (nAnchor == FLY_AS_CHAR)
453 sal_Int16 nVertOrient = -1;
455 switch (nSlotId)
457 case SID_OBJECT_ALIGN_UP:
458 nVertOrient = text::VertOrientation::TOP;
459 break;
460 case SID_OBJECT_ALIGN_MIDDLE:
461 nVertOrient = text::VertOrientation::CENTER;
462 break;
463 case SID_OBJECT_ALIGN_DOWN:
464 nVertOrient = text::VertOrientation::BOTTOM;
465 break;
466 default:
467 break;
469 if (nVertOrient != -1)
471 pSh->StartAction();
472 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
473 SwFrmFmt* pFrmFmt = FindFrmFmt( pObj );
474 SwFmtVertOrient aVOrient((SwFmtVertOrient&)pFrmFmt->GetFmtAttr(RES_VERT_ORIENT));
475 aVOrient.SetVertOrient( nVertOrient );
476 pFrmFmt->SetFmtAttr(aVOrient);
477 pSh->EndAction();
479 break;
481 if (nAnchor == FLY_AT_PARA)
482 break; // Do not align frames of an anchored paragraph
485 pSh->StartAction();
486 switch (nSlotId)
488 case SID_OBJECT_ALIGN_LEFT:
489 pSdrView->AlignMarkedObjects(SDRHALIGN_LEFT, SDRVALIGN_NONE);
490 break;
491 case SID_OBJECT_ALIGN_CENTER:
492 pSdrView->AlignMarkedObjects(SDRHALIGN_CENTER, SDRVALIGN_NONE);
493 break;
494 case SID_OBJECT_ALIGN_RIGHT:
495 pSdrView->AlignMarkedObjects(SDRHALIGN_RIGHT, SDRVALIGN_NONE);
496 break;
497 case SID_OBJECT_ALIGN_UP:
498 pSdrView->AlignMarkedObjects(SDRHALIGN_NONE, SDRVALIGN_TOP);
499 break;
500 case SID_OBJECT_ALIGN_MIDDLE:
501 pSdrView->AlignMarkedObjects(SDRHALIGN_NONE, SDRVALIGN_CENTER);
502 break;
503 case SID_OBJECT_ALIGN_DOWN:
504 pSdrView->AlignMarkedObjects(SDRHALIGN_NONE, SDRVALIGN_BOTTOM);
505 break;
507 pSh->EndAction();
510 break;
512 case FN_FRAME_UP:
513 bTopParam = sal_False;
514 /* no break */
515 case SID_FRAME_TO_TOP:
516 pSh->SelectionToTop( bTopParam );
517 break;
519 case FN_FRAME_DOWN:
520 bBottomParam = sal_False;
521 /* no break */
522 case SID_FRAME_TO_BOTTOM:
523 pSh->SelectionToBottom( bBottomParam );
524 break;
526 case FN_NAME_SHAPE:
528 bDone = true;
530 if(1L == pSdrView->GetMarkedObjectCount())
532 // #i68101#
533 SdrObject* pSelected = pSdrView->GetMarkedObjectByIndex(0L);
534 OSL_ENSURE(pSelected, "DrawViewShell::FuTemp03: nMarkCount, but no object (!)");
535 String aName(pSelected->GetName());
537 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
538 OSL_ENSURE(pFact, "Dialogdiet fail!");
539 AbstractSvxObjectNameDialog* pDlg = pFact->CreateSvxObjectNameDialog(NULL, aName);
540 OSL_ENSURE(pDlg, "Dialogdiet fail!");
542 pDlg->SetCheckNameHdl(LINK(this, SwDrawBaseShell, CheckGroupShapeNameHdl));
544 if(RET_OK == pDlg->Execute())
546 pDlg->GetName(aName);
547 pSelected->SetName(aName);
548 pSh->SetModified();
551 delete pDlg;
554 break;
557 // #i68101#
558 case FN_TITLE_DESCRIPTION_SHAPE:
560 bDone = true;
562 if(1L == pSdrView->GetMarkedObjectCount())
564 SdrObject* pSelected = pSdrView->GetMarkedObjectByIndex(0L);
565 OSL_ENSURE(pSelected, "DrawViewShell::FuTemp03: nMarkCount, but no object (!)");
566 String aTitle(pSelected->GetTitle());
567 String aDescription(pSelected->GetDescription());
569 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
570 OSL_ENSURE(pFact, "Dialogdiet fail!");
571 AbstractSvxObjectTitleDescDialog* pDlg = pFact->CreateSvxObjectTitleDescDialog(NULL, aTitle, aDescription);
572 OSL_ENSURE(pDlg, "Dialogdiet fail!");
574 if(RET_OK == pDlg->Execute())
576 pDlg->GetTitle(aTitle);
577 pDlg->GetDescription(aDescription);
579 pSelected->SetTitle(aTitle);
580 pSelected->SetDescription(aDescription);
582 pSh->SetModified();
585 delete pDlg;
588 break;
591 default:
592 OSL_ENSURE(!this, "wrong Dispatcher");
593 return;
595 if(!bDone)
597 if(nSlotId >= SID_OBJECT_ALIGN_LEFT && nSlotId <= SID_OBJECT_ALIGN_DOWN)
598 rBind.Invalidate(SID_ATTR_LONG_LRSPACE);
599 if (pSdrView->GetModel()->IsChanged())
600 pSh->SetModified();
601 else if (bChanged)
602 pSdrView->GetModel()->SetChanged(sal_True);
603 // 40220: After Delete from DrawObjecs over the API GPF through self-destruction
604 if(bNotify)
605 GetView().AttrChangedNotify(pSh); // Shell switch if applicable...
609 // Checks whether a given name is allowed for a group shape
611 IMPL_LINK( SwDrawBaseShell, CheckGroupShapeNameHdl, AbstractSvxNameDialog*, pNameDialog )
613 SwWrtShell &rSh = GetShell();
614 SdrView *pSdrView = rSh.GetDrawView();
615 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
616 OSL_ENSURE(rMarkList.GetMarkCount() == 1, "wrong draw selection");
617 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
618 const String sCurrentName = pObj->GetName();
619 String sNewName;
620 pNameDialog->GetName(sNewName);
621 long nRet = 0;
622 if(!sNewName.Len() || sCurrentName == sNewName)
623 nRet = 1;
624 else
626 nRet = 1;
627 SdrModel* pModel = rSh.getIDocumentDrawModelAccess()->GetDrawModel();
628 SdrObjListIter aIter( *(pModel->GetPage(0)), IM_DEEPWITHGROUPS );
629 while( aIter.IsMore() )
631 SdrObject* pTempObj = aIter.Next();
632 if ( pObj != pTempObj && pTempObj->GetName().equals(sNewName) )
634 nRet = 0;
635 break;
639 return nRet;
642 void SwDrawBaseShell::GetState(SfxItemSet& rSet)
644 SwWrtShell &rSh = GetShell();
645 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
646 SfxWhichIter aIter( rSet );
647 sal_uInt16 nWhich = aIter.FirstWhich();
648 sal_Bool bProtected = rSh.IsSelObjProtected(FLYPROTECT_CONTENT);
650 if (!bProtected) // Look in the parent
651 bProtected |= rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
653 while( nWhich )
655 switch( nWhich )
657 case FN_DRAW_WRAP_DLG:
658 case SID_ATTR_TRANSFORM:
659 case SID_FRAME_TO_TOP:
660 case SID_FRAME_TO_BOTTOM:
661 case FN_FRAME_UP:
662 case FN_FRAME_DOWN:
663 case SID_DELETE:
664 case FN_BACKSPACE:
665 if( bProtected || !rSh.IsObjSelected() )
666 rSet.DisableItem( nWhich );
667 break;
668 case SID_GROUP:
669 if ( rSh.IsObjSelected() < 2 || bProtected || !rSh.IsGroupAllowed() )
670 rSet.DisableItem( nWhich );
671 break;
672 case SID_UNGROUP:
673 if ( !rSh.IsGroupSelected() || bProtected )
674 rSet.DisableItem( nWhich );
675 break;
676 case SID_ENTER_GROUP:
677 if ( !rSh.IsGroupSelected() )
678 rSet.DisableItem( nWhich );
679 break;
680 case SID_LEAVE_GROUP:
681 if ( !pSdrView->IsGroupEntered() )
682 rSet.DisableItem( nWhich );
683 break;
684 case SID_OBJECT_ALIGN_LEFT:
685 case SID_OBJECT_ALIGN_CENTER:
686 case SID_OBJECT_ALIGN_RIGHT:
687 case SID_OBJECT_ALIGN_UP:
688 case SID_OBJECT_ALIGN_MIDDLE:
689 case SID_OBJECT_ALIGN_DOWN:
690 case SID_OBJECT_ALIGN:
691 if ( !rSh.IsAlignPossible() || bProtected )
692 rSet.DisableItem( nWhich );
693 else
695 SfxAllEnumItem aEnumItem(nWhich, USHRT_MAX);
696 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
697 //if only one object is selected it can only be vertically
698 // aligned because it is character bound
699 if( rMarkList.GetMarkCount() == 1 )
701 aEnumItem.DisableValue(SID_OBJECT_ALIGN_LEFT);
702 aEnumItem.DisableValue(SID_OBJECT_ALIGN_CENTER);
703 aEnumItem.DisableValue(SID_OBJECT_ALIGN_RIGHT);
705 rSet.Put(aEnumItem);
707 break;
709 case FN_NAME_SHAPE :
711 if(1L != pSdrView->GetMarkedObjectCount())
713 rSet.DisableItem( nWhich );
716 break;
718 // #i68101#
719 case FN_TITLE_DESCRIPTION_SHAPE:
721 const bool bIsWebView(NULL != dynamic_cast<SwWebView*>(&GetView()));
723 if(!bIsWebView && 1L != pSdrView->GetMarkedObjectCount())
725 rSet.DisableItem( nWhich );
728 break;
730 nWhich = aIter.NextWhich();
734 void SwDrawBaseShell::GetDrawAttrStateForIFBX( SfxItemSet& rSet )
736 SwWrtShell *pSh = &GetShell();
737 SdrView* pSdrView = pSh->GetDrawView();
738 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
739 if( rMarkList.GetMark(0) != 0 )
741 SfxItemSet aNewAttr(pSdrView->GetGeoAttrFromMarked());
742 rSet.Put(aNewAttr,false);
746 sal_Bool SwDrawBaseShell::Disable(SfxItemSet& rSet, sal_uInt16 nWhich)
748 sal_Bool bDisable = GetShell().IsSelObjProtected(FLYPROTECT_CONTENT);
750 if (bDisable)
752 if (nWhich)
753 rSet.DisableItem( nWhich );
754 else
756 SfxWhichIter aIter( rSet );
757 nWhich = aIter.FirstWhich();
758 while (nWhich)
760 rSet.DisableItem( nWhich );
761 nWhich = aIter.NextWhich();
766 return bDisable;
769 // Validate of drawing positions
771 IMPL_LINK(SwDrawBaseShell, ValidatePosition, SvxSwFrameValidation*, pValidation )
773 SwWrtShell *pSh = &GetShell();
774 pValidation->nMinHeight = MINFLY;
775 pValidation->nMinWidth = MINFLY;
777 SwRect aBoundRect;
779 // OD 18.09.2003 #i18732# - adjustment for allowing vertical position
780 // aligned to page for fly frame anchored to paragraph or to character.
781 const RndStdIds eAnchorType = static_cast<RndStdIds >(pValidation->nAnchorType);
782 const SwPosition* pCntntPos = 0;
783 SdrView* pSdrView = pSh->GetDrawView();
784 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
785 if( rMarkList.GetMarkCount() == 1 )
787 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
788 SwFrmFmt* pFrmFmt = FindFrmFmt( pObj );
789 pCntntPos = pFrmFmt->GetAnchor().GetCntntAnchor();
792 pSh->CalcBoundRect( aBoundRect, eAnchorType,
793 pValidation->nHRelOrient,
794 pValidation->nVRelOrient,
795 pCntntPos,
796 pValidation->bFollowTextFlow,
797 pValidation->bMirror, NULL, &pValidation->aPercentSize);
799 sal_Bool bIsInVertical( sal_False );
801 sal_Bool bRTL;
802 sal_Bool bVertL2R;
803 bIsInVertical = pSh->IsFrmVertical(sal_True, bRTL, bVertL2R);
805 if(bIsInVertical)
807 Point aPos(aBoundRect.Pos());
808 long nTmp = aPos.X();
809 aPos.X() = aPos.Y();
810 aPos.Y() = nTmp;
811 Size aSize(aBoundRect.SSize());
812 nTmp = aSize.Width();
813 aSize.Width() = aSize.Height();
814 aSize.Height() = nTmp;
815 aBoundRect.Chg( aPos, aSize );
816 //exchange width/height to enable correct values
817 nTmp = pValidation->nWidth;
818 pValidation->nWidth = pValidation->nHeight;
819 pValidation->nHeight = nTmp;
821 if ((eAnchorType == FLY_AT_PAGE) || (eAnchorType == FLY_AT_FLY))
823 // MinimalPosition
824 pValidation->nMinHPos = aBoundRect.Left();
825 pValidation->nMinVPos = aBoundRect.Top();
826 SwTwips nH = pValidation->nHPos;
827 SwTwips nV = pValidation->nVPos;
829 if (pValidation->nHPos + pValidation->nWidth > aBoundRect.Right())
831 if (pValidation->nHoriOrient == text::HoriOrientation::NONE)
833 pValidation->nHPos -= ((pValidation->nHPos + pValidation->nWidth) - aBoundRect.Right());
834 nH = pValidation->nHPos;
836 else
837 pValidation->nWidth = aBoundRect.Right() - pValidation->nHPos;
840 if (pValidation->nHPos + pValidation->nWidth > aBoundRect.Right())
841 pValidation->nWidth = aBoundRect.Right() - pValidation->nHPos;
843 if (pValidation->nVPos + pValidation->nHeight > aBoundRect.Bottom())
845 if (pValidation->nVertOrient == text::VertOrientation::NONE)
847 pValidation->nVPos -= ((pValidation->nVPos + pValidation->nHeight) - aBoundRect.Bottom());
848 nV = pValidation->nVPos;
850 else
851 pValidation->nHeight = aBoundRect.Bottom() - pValidation->nVPos;
854 if (pValidation->nVPos + pValidation->nHeight > aBoundRect.Bottom())
855 pValidation->nHeight = aBoundRect.Bottom() - pValidation->nVPos;
857 if ( pValidation->nVertOrient != text::VertOrientation::NONE )
858 nV = aBoundRect.Top();
860 if ( pValidation->nHoriOrient != text::HoriOrientation::NONE )
861 nH = aBoundRect.Left();
863 pValidation->nMaxHPos = aBoundRect.Right() - pValidation->nWidth;
864 pValidation->nMaxHeight = aBoundRect.Bottom() - nV;
866 pValidation->nMaxVPos = aBoundRect.Bottom() - pValidation->nHeight;
867 pValidation->nMaxWidth = aBoundRect.Right() - nH;
869 else if ((eAnchorType == FLY_AT_PARA) || (eAnchorType == FLY_AT_CHAR))
871 if (pValidation->nHPos + pValidation->nWidth > aBoundRect.Right())
873 if (pValidation->nHoriOrient == text::HoriOrientation::NONE)
875 pValidation->nHPos -= ((pValidation->nHPos + pValidation->nWidth) - aBoundRect.Right());
877 else
878 pValidation->nWidth = aBoundRect.Right() - pValidation->nHPos;
881 // OD 29.09.2003 #i17567#, #i18732# - consider following the text flow
882 // and alignment at page areas.
883 const bool bMaxVPosAtBottom = !pValidation->bFollowTextFlow ||
884 pValidation->nVRelOrient == text::RelOrientation::PAGE_FRAME ||
885 pValidation->nVRelOrient == text::RelOrientation::PAGE_PRINT_AREA;
887 SwTwips nTmpMaxVPos = ( bMaxVPosAtBottom
888 ? aBoundRect.Bottom()
889 : aBoundRect.Height() ) -
890 pValidation->nHeight;
891 if ( pValidation->nVPos > nTmpMaxVPos )
893 if (pValidation->nVertOrient == text::VertOrientation::NONE)
895 pValidation->nVPos = nTmpMaxVPos;
897 else
899 pValidation->nHeight = ( bMaxVPosAtBottom
900 ? aBoundRect.Bottom()
901 : aBoundRect.Height() ) - pValidation->nVPos;
906 pValidation->nMinHPos = aBoundRect.Left();
907 pValidation->nMaxHPos = aBoundRect.Right() - pValidation->nWidth;
909 pValidation->nMinVPos = aBoundRect.Top();
910 // OD 26.09.2003 #i17567#, #i18732# - determine maximum vertical position
911 if ( bMaxVPosAtBottom )
913 pValidation->nMaxVPos = aBoundRect.Bottom() - pValidation->nHeight;
915 else
917 pValidation->nMaxVPos = aBoundRect.Height() - pValidation->nHeight;
920 // Maximum width height
921 const SwTwips nH = ( pValidation->nHoriOrient != text::HoriOrientation::NONE )
922 ? aBoundRect.Left()
923 : pValidation->nHPos;
924 const SwTwips nV = ( pValidation->nVertOrient != text::VertOrientation::NONE )
925 ? aBoundRect.Top()
926 : pValidation->nVPos;
927 pValidation->nMaxHeight = pValidation->nMaxVPos + pValidation->nHeight - nV;
928 pValidation->nMaxWidth = pValidation->nMaxHPos + pValidation->nWidth - nH;
930 else if (eAnchorType == FLY_AS_CHAR)
932 pValidation->nMinHPos = 0;
933 pValidation->nMaxHPos = 0;
935 pValidation->nMaxHeight = aBoundRect.Height();
936 pValidation->nMaxWidth = aBoundRect.Width();
938 pValidation->nMaxVPos = aBoundRect.Height();
939 pValidation->nMinVPos = -aBoundRect.Height() + pValidation->nHeight;
940 if (pValidation->nMaxVPos < pValidation->nMinVPos)
942 pValidation->nMinVPos = pValidation->nMaxVPos;
943 pValidation->nMaxVPos = -aBoundRect.Height();
946 if(bIsInVertical)
948 //restore width/height exchange
949 long nTmp = pValidation->nWidth;
950 pValidation->nWidth = pValidation->nHeight;
951 pValidation->nHeight = nTmp;
954 if (pValidation->nMaxWidth < pValidation->nWidth)
955 pValidation->nWidth = pValidation->nMaxWidth;
956 if (pValidation->nMaxHeight < pValidation->nHeight)
957 pValidation->nHeight = pValidation->nMaxHeight;
958 return 0;
961 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */