xref: /aoo42x/main/sw/source/ui/shells/drwbassh.cxx (revision cb0cd92e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <tools/shl.hxx>
29 #include <hintids.hxx>
30 #include <helpid.h>
31 #include <swtypes.hxx>
32 #include <sfx2/objface.hxx>
33 #include <sfx2/request.hxx>
34 #include <sfx2/bindings.hxx>
35 #include <svl/aeitem.hxx>
36 #include <svx/svdview.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <svl/srchitem.hxx>
39 #include <svl/whiter.hxx>
40 #include <svx/swframevalidation.hxx>
41 #include <svx/anchorid.hxx>
42 #include <svx/htmlmode.hxx>
43 #include <uitool.hxx>
44 #include <fmtornt.hxx>
45 #include <cmdid.h>
46 #include <swmodule.hxx>
47 #include <wrtsh.hxx>
48 #include <wview.hxx>
49 #include <edtwin.hxx>
50 #include <viewopt.hxx>
51 #include <dcontact.hxx>
52 #include <frmfmt.hxx>
53 #include <wrap.hxx>
54 #include <drawbase.hxx>
55 #include <drwbassh.hxx>
56 #include <swdtflvr.hxx>
57 #include <svx/svdogrp.hxx>
58 #include <svx/svdpage.hxx>
59 #include <svx/svditer.hxx>
60 
61 #include <shells.hrc>
62 #define SwDrawBaseShell
63 #include <sfx2/msg.hxx>
64 #include <swslots.hxx>
65 #include <svx/svxdlg.hxx>
66 #include <svx/dialogs.hrc>
67 #include "swabstdlg.hxx"
68 #include "dialog.hrc"
69 #include <swundo.hxx>
70 #include <com/sun/star/text/HoriOrientation.hpp>
71 #include <com/sun/star/text/VertOrientation.hpp>
72 #include <com/sun/star/text/RelOrientation.hpp>
73 
74 #include <IDocumentDrawModelAccess.hxx>
75 
76 using namespace ::com::sun::star;
77 
78 SFX_IMPL_INTERFACE(SwDrawBaseShell, SwBaseShell, SW_RES(0))
79 {
80 }
81 
82 TYPEINIT1(SwDrawBaseShell,SwBaseShell)
83 
84 /*--------------------------------------------------------------------
85 	Beschreibung:
86  --------------------------------------------------------------------*/
87 
88 
89 SwDrawBaseShell::SwDrawBaseShell(SwView &_rView):
90     SwBaseShell( _rView )
91 {
92 	GetShell().NoEdit(sal_True);
93 
94 	SwEditWin& rWin = GetView().GetEditWin();
95 
96 	rWin.SetBezierMode(SID_BEZIER_MOVE);
97 
98     if ( !_rView.GetDrawFuncPtr() )
99         _rView.GetEditWin().StdDrawMode( OBJ_NONE, sal_True );
100 
101 	SwTransferable::CreateSelection( GetShell() );
102 }
103 
104 /*--------------------------------------------------------------------
105 	Beschreibung:
106  --------------------------------------------------------------------*/
107 
108 
109 SwDrawBaseShell::~SwDrawBaseShell()
110 {
111 	GetView().ExitDraw();
112 	GetShell().Edit();
113 	SwTransferable::ClearSelection( GetShell() );
114 }
115 
116 /*--------------------------------------------------------------------
117 	Beschreibung:
118  --------------------------------------------------------------------*/
119 
120 
121 void SwDrawBaseShell::Execute(SfxRequest &rReq)
122 {
123 	SwWrtShell *pSh = &GetShell();
124 	SdrView*	pSdrView = pSh->GetDrawView();
125 	const SfxItemSet *pArgs = rReq.GetArgs();
126 	sal_uInt16		nSlotId = rReq.GetSlot();
127 	sal_Bool		bChanged = pSdrView->GetModel()->IsChanged();
128 	pSdrView->GetModel()->SetChanged(sal_False);
129 	const SfxPoolItem* pItem = 0;
130 	if(pArgs)
131 		pArgs->GetItemState(nSlotId, sal_False, &pItem);
132 
133 	//Sonderfall Align per Menue
134 	if(pItem && nSlotId == SID_OBJECT_ALIGN)
135 	{
136 		DBG_ASSERT(PTR_CAST(SfxEnumItem, pItem),"SfxEnumItem erwartet");
137         nSlotId = nSlotId + ((const SfxEnumItem*)pItem)->GetValue();
138 		nSlotId++;
139 	}
140 
141 	sal_Bool bAlignPossible = pSh->IsAlignPossible();
142 
143 	sal_Bool bTopParam = sal_True, bBottomParam = sal_True;
144 	sal_Bool bNotify = sal_False;
145 	sal_Bool bDone = sal_False;
146 	SfxBindings& rBind = GetView().GetViewFrame()->GetBindings();
147 
148 	switch (nSlotId)
149 	{
150 		case FN_DRAW_WRAP_DLG:
151 		{
152 			if(pSdrView->AreObjectsMarked())
153 			{
154 				if(!pArgs)
155 				{
156 					const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
157 					if( rMarkList.GetMark(0) != 0 )
158 					{
159 						SfxItemSet aSet(GetPool(),	RES_SURROUND, RES_SURROUND,
160 													RES_ANCHOR, RES_ANCHOR,
161 													RES_LR_SPACE, RES_UL_SPACE,
162 													SID_HTML_MODE, SID_HTML_MODE,
163 													FN_DRAW_WRAP_DLG, FN_DRAW_WRAP_DLG,
164 													0);
165 
166 						aSet.Put(SfxBoolItem(SID_HTML_MODE,
167 							0 != ::GetHtmlMode(pSh->GetView().GetDocShell())));
168 
169 						aSet.Put(SfxInt16Item(FN_DRAW_WRAP_DLG, pSh->GetLayerId()));
170 
171 						pSh->GetObjAttr(aSet);
172                         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
173                         DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
174 
175                         SfxAbstractDialog* pDlg = pFact->CreateSwWrapDlg( GetView().GetWindow(), aSet, pSh, sal_True, RC_DLG_SWWRAPDLG );
176                         DBG_ASSERT(pDlg, "Dialogdiet fail!");
177 
178                         if (pDlg->Execute() == RET_OK)
179 						{
180                             const SfxPoolItem* pWrapItem;
181                             const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
182                             if(SFX_ITEM_SET == pOutSet->GetItemState(FN_DRAW_WRAP_DLG, sal_False, &pWrapItem))
183 							{
184                                 short nLayer = ((const SfxInt16Item*)pWrapItem)->GetValue();
185 								if (nLayer == 1)
186 									pSh->SelectionToHeaven();
187 								else
188 									pSh->SelectionToHell();
189 							}
190 
191 							pSh->SetObjAttr(*pOutSet);
192 						}
193                     delete pDlg;
194 					}
195 				}
196 			}
197 		}
198 		break;
199 
200 		case SID_ATTR_TRANSFORM:
201 		{
202 			if(pSdrView->AreObjectsMarked())
203 			{
204 				if(!pArgs)
205 				{
206 					const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
207 					if( rMarkList.GetMark(0) != 0 )
208 					{
209 						SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
210                         SfxAbstractTabDialog *pDlg=NULL;
211 						sal_Bool bCaption = sal_False;
212 
213 						// Erlaubte Verankerungen:
214                         short nAnchor = pSh->GetAnchorId();
215 						sal_uInt16 nAllowedAnchors = SVX_OBJ_AT_CNTNT|SVX_OBJ_IN_CNTNT;
216 						sal_uInt16 nHtmlMode = ::GetHtmlMode(pSh->GetView().GetDocShell());
217 
218                         if( !((HTMLMODE_ON & nHtmlMode) && (0 == (nHtmlMode & HTMLMODE_SOME_ABS_POS))) )
219 							nAllowedAnchors |= SVX_OBJ_PAGE;
220 						if ( pSh->IsFlyInFly() )
221 							nAllowedAnchors |= SVX_OBJ_AT_FLY;
222 
223 						if (pObj->GetObjIdentifier() == OBJ_CAPTION )
224 							bCaption = sal_True;
225 
226 						if (bCaption)
227                         {
228 							SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
229 							if ( pFact )
230 							{
231                                 AbstractSvxCaptionDialog* pCaptionDlg =
232                                         pFact->CreateCaptionDialog( NULL, pSdrView, nAllowedAnchors );
233                                 pCaptionDlg->SetValidateFramePosLink( LINK(this, SwDrawBaseShell, ValidatePosition) );
234                                 pDlg = pCaptionDlg;
235                                 DBG_ASSERT(pDlg, "Dialogdiet fail!");
236 							}
237 						}
238 						else
239 						{
240 							SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
241 							if ( pFact )
242 							{
243 
244                                 AbstractSvxTransformTabDialog* pTransform =
245                                             pFact->CreateSvxTransformTabDialog( NULL, NULL, pSdrView, nAllowedAnchors );
246                                 pTransform->SetValidateFramePosLink( LINK(this, SwDrawBaseShell, ValidatePosition) );
247                                 pDlg = pTransform;
248                                 DBG_ASSERT(pDlg, "Dialogdiet fail!");
249 							}
250 						}
251 						SfxItemSet aNewAttr(pSdrView->GetGeoAttrFromMarked());
252 
253 						const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
254 						SfxItemSet aSet( *aNewAttr.GetPool(), pRange );
255                         FieldUnit eMetric = ::GetDfltMetric(0 != dynamic_cast<SwWebView*>(&GetView()));
256                         SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
257 
258 						aSet.Put( aNewAttr, sal_False );
259 
260 						if (bCaption)
261 							pSdrView->GetAttributes( aSet );
262 
263                         aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_ANCHOR, nAnchor));
264                         sal_Bool bRTL;
265                         sal_Bool bVertL2R;
266                         aSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_IN_VERTICAL_TEXT, pSh->IsFrmVertical(sal_True, bRTL, bVertL2R)));
267                         aSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_IN_RTL_TEXT, bRTL));
268 
269                         SwFrmFmt* pFrmFmt = FindFrmFmt( pObj );
270 
271                         aSet.Put( pFrmFmt->GetFmtAttr(RES_FOLLOW_TEXT_FLOW) );
272 
273                         SwFmtVertOrient aVOrient((const SwFmtVertOrient&)pFrmFmt->GetFmtAttr(RES_VERT_ORIENT));
274                         aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_VERT_ORIENT, aVOrient.GetVertOrient()));
275                         aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_VERT_RELATION, aVOrient.GetRelationOrient() ));
276                         aSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_VERT_POSITION, aVOrient.GetPos()));
277 
278                         SwFmtHoriOrient aHOrient((const SwFmtHoriOrient&)pFrmFmt->GetFmtAttr(RES_HORI_ORIENT));
279                         aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_HORI_ORIENT, aHOrient.GetHoriOrient()));
280                         aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_HORI_RELATION, aHOrient.GetRelationOrient() ));
281                         aSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_HORI_MIRROR, aHOrient.IsPosToggle()));
282                         aSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_HORI_POSITION, aHOrient.GetPos()));
283 
284                         aSet.Put(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
285 
286 						pDlg->SetInputSet( &aSet );
287 
288 						if (pDlg->Execute() == RET_OK)
289 						{
290 							const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
291 							pSh->StartAllAction();
292 
293                             // --> OD 2004-07-14 #i30451#
294                             pSh->StartUndo(UNDO_INSFMTATTR);
295 
296                             pSdrView->SetGeoAttrToMarked(*pOutSet);
297 
298 							if (bCaption)
299 								pSdrView->SetAttributes(*pOutSet);
300 
301 							sal_Bool bPosCorr =
302 								SFX_ITEM_SET != pOutSet->GetItemState(
303 									SID_ATTR_TRANSFORM_POS_X, sal_False ) &&
304 								SFX_ITEM_SET != pOutSet->GetItemState(
305 									SID_ATTR_TRANSFORM_POS_Y, sal_False );
306 
307                             SfxItemSet aFrmAttrSet(GetPool(), RES_FRMATR_BEGIN, RES_FRMATR_END - 1);
308 
309                             bool bSingleSelection = rMarkList.GetMarkCount() == 1;
310 
311                             const SfxPoolItem* pAnchorItem;
312                             if(SFX_ITEM_SET == pOutSet->GetItemState(
313                                 SID_ATTR_TRANSFORM_ANCHOR, sal_False, &pAnchorItem))
314                             {
315                                 if(!bSingleSelection)
316                                     pSh->ChgAnchor(((const SfxInt16Item*)pAnchorItem)
317                                             ->GetValue(), sal_False, bPosCorr );
318                                 else
319                                 {
320                                     SwFmtAnchor aAnchor(pFrmFmt->GetAnchor());
321                                     aAnchor.SetType((RndStdIds)((const SfxInt16Item*)pAnchorItem)->GetValue());
322                                     aFrmAttrSet.Put( aAnchor );
323                                 }
324                             }
325                             const SfxPoolItem* pHoriOrient = 0;
326                             const SfxPoolItem* pHoriRelation = 0;
327                             const SfxPoolItem* pHoriPosition = 0;
328                             const SfxPoolItem* pHoriMirror = 0;
329                             pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_ORIENT, sal_False, &pHoriOrient);
330                             pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_RELATION, sal_False, &pHoriRelation);
331                             pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_POSITION, sal_False, &pHoriPosition);
332                             pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_MIRROR, sal_False, &pHoriMirror);
333                             if(pHoriOrient || pHoriRelation || pHoriPosition || pHoriMirror)
334                             {
335                                 if(pHoriOrient)
336                                     aHOrient.SetHoriOrient(
337                                           static_cast<const SfxInt16Item*>(pHoriOrient)->GetValue());
338                                 if(pHoriRelation)
339                                     aHOrient.SetRelationOrient(
340                                               static_cast<const SfxInt16Item*>(pHoriRelation)->GetValue());
341                                 if(pHoriPosition)
342                                     aHOrient.SetPos( static_cast<const SfxInt32Item*>(pHoriPosition)->GetValue());
343                                 if(pHoriMirror)
344                                     aHOrient.SetPosToggle( static_cast<const SfxBoolItem*>(pHoriMirror)->GetValue());
345                                 aFrmAttrSet.Put(aHOrient);
346                             }
347 
348                             const SfxPoolItem* pVertOrient = 0;
349                             const SfxPoolItem* pVertRelation = 0;
350                             const SfxPoolItem* pVertPosition = 0;
351                             pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_ORIENT, sal_False, &pVertOrient);
352                             pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_RELATION, sal_False, &pVertRelation);
353                             pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_POSITION, sal_False, &pVertPosition);
354                             if(pVertOrient || pVertRelation || pVertPosition )
355                             {
356                                 if(pVertOrient)
357                                     aVOrient.SetVertOrient(
358                                         static_cast<const SfxInt16Item*>(pVertOrient)->GetValue());
359                                 if(pVertRelation)
360                                     aVOrient.SetRelationOrient(
361                                         static_cast<const SfxInt16Item*>(pVertRelation)->GetValue());
362                                 if(pVertPosition)
363                                     aVOrient.SetPos( static_cast<const SfxInt32Item*>(pVertPosition)->GetValue());
364                                 aFrmAttrSet.Put( aVOrient );
365                             }
366                             const SfxPoolItem* pFollowItem = 0;
367                             pOutSet->GetItemState(RES_FOLLOW_TEXT_FLOW, sal_False, &pFollowItem);
368                             if(pFollowItem)
369                                 aFrmAttrSet.Put(*pFollowItem);
370 
371                             if(aFrmAttrSet.Count())
372                                 pSh->SetDrawingAttr(aFrmAttrSet);
373 
374 							rBind.InvalidateAll(sal_False);
375 
376                             // --> OD 2004-07-14 #i30451#
377                             pSh->EndUndo( UNDO_INSFMTATTR );
378 
379                             pSh->EndAllAction();
380 						}
381 						delete pDlg;
382 
383 					}
384 				}
385                 else
386                 {
387                     pSdrView->SetGeoAttrToMarked( *pArgs );
388                 }
389 			}
390 		}
391 		break;
392 
393 		case SID_DELETE:
394 		case FN_BACKSPACE:
395 			if (pSh->IsObjSelected() && !pSdrView->IsTextEdit())
396 			{
397 				bDone = sal_True;
398 
399 				if( GetView().IsDrawRotate() )
400 				{
401 					pSh->SetDragMode( SDRDRAG_MOVE );
402 					GetView().FlipDrawRotate();
403 				}
404 
405 				pSh->SetModified();
406 				pSh->DelSelectedObj();
407 
408                 if (rReq.IsAPI() ||
409                     GetView().GetEditWin().IsObjectSelect() )
410 				{
411                     // Wenn Basic-Aufruf, dann zurueck in die Textshell, da das
412                     // Basic sonst keine Rueckkehrmoeglichkeit hat.
413 					if (GetView().GetDrawFuncPtr())
414 					{
415 						GetView().GetDrawFuncPtr()->Deactivate();
416 						GetView().SetDrawFuncPtr(NULL);
417 					}
418 					GetView().LeaveDrawCreate();	// In Selektionsmode wechseln
419 				}
420 
421 				if (pSh->IsSelFrmMode())
422 				{
423 					pSh->LeaveSelFrmMode();
424                     // #105852# FME
425 //                   pSh->NoEdit();
426 				}
427 				bNotify = sal_True;
428 			}
429 			break;
430 
431 		case SID_GROUP:
432 			if (pSh->IsObjSelected() > 1 && pSh->IsGroupAllowed())
433 			{
434 				pSh->GroupSelection();	// Objekt gruppieren
435 				rBind.Invalidate(SID_UNGROUP);
436 			}
437 			break;
438 
439 		case SID_UNGROUP:
440 			if (pSh->IsGroupSelected())
441 			{
442 				pSh->UnGroupSelection();	// Objektgruppierung aufheben
443 				rBind.Invalidate(SID_GROUP);
444 			}
445 			break;
446 
447 		case SID_ENTER_GROUP:
448 			if (pSh->IsGroupSelected())
449 			{
450 				pSdrView->EnterMarkedGroup();
451 				rBind.InvalidateAll(sal_False);
452 			}
453 			break;
454 
455 		case SID_LEAVE_GROUP:
456 			if (pSdrView->IsGroupEntered())
457 			{
458 				pSdrView->LeaveOneGroup();
459 				rBind.Invalidate(SID_ENTER_GROUP);
460 				rBind.Invalidate(SID_UNGROUP);
461 			}
462 			break;
463 
464 		case SID_OBJECT_ALIGN_LEFT:
465 		case SID_OBJECT_ALIGN_CENTER:
466 		case SID_OBJECT_ALIGN_RIGHT:
467 		case SID_OBJECT_ALIGN_UP:
468 		case SID_OBJECT_ALIGN_MIDDLE:
469 		case SID_OBJECT_ALIGN_DOWN:
470 		{
471 			if ( bAlignPossible )
472 			{
473 				const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
474 				if( rMarkList.GetMarkCount() == 1 && bAlignPossible )
475 				{	// Objekte nicht aneinander ausrichten
476 
477 					sal_uInt16 nAnchor = pSh->GetAnchorId();
478                     if (nAnchor == FLY_AS_CHAR)
479                     {
480                         sal_Int16 nVertOrient = -1;
481 
482 						switch (nSlotId)
483 						{
484 							case SID_OBJECT_ALIGN_UP:
485                                 nVertOrient = text::VertOrientation::TOP;
486 								break;
487 							case SID_OBJECT_ALIGN_MIDDLE:
488                                 nVertOrient = text::VertOrientation::CENTER;
489 								break;
490 							case SID_OBJECT_ALIGN_DOWN:
491                                 nVertOrient = text::VertOrientation::BOTTOM;
492 								break;
493 							default:
494 								break;
495 						}
496 						if (nVertOrient != -1)
497 						{
498 							pSh->StartAction();
499 							SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
500 							SwFrmFmt* pFrmFmt = FindFrmFmt( pObj );
501                             SwFmtVertOrient aVOrient((SwFmtVertOrient&)pFrmFmt->GetFmtAttr(RES_VERT_ORIENT));
502                             aVOrient.SetVertOrient( nVertOrient );
503                             pFrmFmt->SetFmtAttr(aVOrient);
504 							pSh->EndAction();
505 						}
506 						break;
507                     }
508                     if (nAnchor == FLY_AT_PARA)
509 						break;	// Absatzverankerte Rahmen nicht ausrichten
510 				}
511 
512 				pSh->StartAction();
513 				switch (nSlotId)
514 				{
515 					case SID_OBJECT_ALIGN_LEFT:
516 						pSdrView->AlignMarkedObjects(SDRHALIGN_LEFT, SDRVALIGN_NONE);
517 						break;
518 					case SID_OBJECT_ALIGN_CENTER:
519 						pSdrView->AlignMarkedObjects(SDRHALIGN_CENTER, SDRVALIGN_NONE);
520 						break;
521 					case SID_OBJECT_ALIGN_RIGHT:
522 						pSdrView->AlignMarkedObjects(SDRHALIGN_RIGHT, SDRVALIGN_NONE);
523 						break;
524 					case SID_OBJECT_ALIGN_UP:
525 						pSdrView->AlignMarkedObjects(SDRHALIGN_NONE, SDRVALIGN_TOP);
526 						break;
527 					case SID_OBJECT_ALIGN_MIDDLE:
528 						pSdrView->AlignMarkedObjects(SDRHALIGN_NONE, SDRVALIGN_CENTER);
529 						break;
530 					case SID_OBJECT_ALIGN_DOWN:
531 						pSdrView->AlignMarkedObjects(SDRHALIGN_NONE, SDRVALIGN_BOTTOM);
532 						break;
533 				}
534 				pSh->EndAction();
535 			}
536 		}
537 		break;
538 
539 		case FN_FRAME_UP:
540 			bTopParam = sal_False;
541 			/* no break */
542 		case SID_FRAME_TO_TOP:
543 			pSh->SelectionToTop( bTopParam );
544 			break;
545 
546 		case FN_FRAME_DOWN:
547 			bBottomParam = sal_False;
548 			/* no break */
549 		case SID_FRAME_TO_BOTTOM:
550 			pSh->SelectionToBottom( bBottomParam );
551 			break;
552 
553 		case FN_NAME_SHAPE:
554 		{
555             bDone = sal_True;
556 
557 			if(1L == pSdrView->GetMarkedObjectCount())
558 			{
559 				// #i68101#
560 				SdrObject* pSelected = pSdrView->GetMarkedObjectByIndex(0L);
561 				OSL_ENSURE(pSelected, "DrawViewShell::FuTemp03: nMarkCount, but no object (!)");
562 				String aName(pSelected->GetName());
563 
564 				SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
565 				OSL_ENSURE(pFact, "Dialogdiet fail!");
566 				AbstractSvxObjectNameDialog* pDlg = pFact->CreateSvxObjectNameDialog(NULL, aName);
567 				OSL_ENSURE(pDlg, "Dialogdiet fail!");
568 
569 	            pDlg->SetCheckNameHdl(LINK(this, SwDrawBaseShell, CheckGroupShapeNameHdl));
570 
571 				if(RET_OK == pDlg->Execute())
572 				{
573 					pDlg->GetName(aName);
574 					pSelected->SetName(aName);
575 					pSh->SetModified();
576 				}
577 
578 				delete pDlg;
579 			}
580 
581 			break;
582 		}
583 
584 		// #i68101#
585 		case FN_TITLE_DESCRIPTION_SHAPE:
586 		{
587             bDone = sal_True;
588 
589 			if(1L == pSdrView->GetMarkedObjectCount())
590 			{
591 				SdrObject* pSelected = pSdrView->GetMarkedObjectByIndex(0L);
592 				OSL_ENSURE(pSelected, "DrawViewShell::FuTemp03: nMarkCount, but no object (!)");
593 				String aTitle(pSelected->GetTitle());
594 				String aDescription(pSelected->GetDescription());
595 
596 				SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
597 				OSL_ENSURE(pFact, "Dialogdiet fail!");
598 				AbstractSvxObjectTitleDescDialog* pDlg = pFact->CreateSvxObjectTitleDescDialog(NULL, aTitle, aDescription);
599 				OSL_ENSURE(pDlg, "Dialogdiet fail!");
600 
601 				if(RET_OK == pDlg->Execute())
602 				{
603 					pDlg->GetTitle(aTitle);
604 					pDlg->GetDescription(aDescription);
605 
606 					pSelected->SetTitle(aTitle);
607 					pSelected->SetDescription(aDescription);
608 
609 					pSh->SetModified();
610 				}
611 
612 				delete pDlg;
613 			}
614 
615 			break;
616 		}
617 
618 		default:
619 			DBG_ASSERT(!this, "falscher Dispatcher");
620 			return;
621 	}
622 	if(!bDone)
623 	{
624 		if(nSlotId >= SID_OBJECT_ALIGN_LEFT && nSlotId <= SID_OBJECT_ALIGN_DOWN)
625 			rBind.Invalidate(SID_ATTR_LONG_LRSPACE);
626 		if (pSdrView->GetModel()->IsChanged())
627 			pSh->SetModified();
628 		else if (bChanged)
629 			pSdrView->GetModel()->SetChanged(sal_True);
630 		// 40220: Nach dem Loeschen von DrawObjekten ueber die API GPF durch Selbstzerstoerung
631 		if(bNotify)
632 			GetView().AttrChangedNotify(pSh); // ggf Shellwechsel...
633 	}
634 }
635 /* -----------------------------27.02.2002 15:27------------------------------
636     Checks whether a given name is allowed for a group shape
637  ---------------------------------------------------------------------------*/
638 IMPL_LINK( SwDrawBaseShell, CheckGroupShapeNameHdl, AbstractSvxNameDialog*, pNameDialog )
639 {
640     SwWrtShell          &rSh = GetShell();
641     SdrView *pSdrView = rSh.GetDrawView();
642     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
643     DBG_ASSERT(rMarkList.GetMarkCount() == 1, "wrong draw selection");
644     SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
645     const String sCurrentName = pObj->GetName();
646     String sNewName;
647     pNameDialog->GetName(sNewName);
648     long nRet = 0;
649     if(!sNewName.Len() || sCurrentName == sNewName)
650         nRet = 1;
651     else
652     {
653         nRet = 1;
654         SdrModel* pModel = rSh.getIDocumentDrawModelAccess()->GetDrawModel();
655         // --> OD 2006-03-09 #i51726# - all drawing objects can be named now.
656         // consider also drawing objects inside group objects
657 //        SdrPage* pPage = pModel->GetPage(0);
658 //        sal_uInt32 nCount = pPage->GetObjCount();
659 //        for( sal_uInt32 i=0; i< nCount; i++ )
660 //        {
661 //            SdrObject* pTemp = pPage->GetObj(i);
662 //            if(pObj != pTemp && pTemp->ISA(SdrObjGroup) && pTemp->GetName() == sNewName)
663 //            {
664 //                nRet = 0;
665 //                break;
666 //            }
667 //        }
668         SdrObjListIter aIter( *(pModel->GetPage(0)), IM_DEEPWITHGROUPS );
669         while( aIter.IsMore() )
670         {
671             SdrObject* pTempObj = aIter.Next();
672             if ( pObj != pTempObj && pTempObj->GetName() == sNewName )
673             {
674                 nRet = 0;
675                 break;
676             }
677         }
678         // <--
679     }
680     return nRet;
681 }
682 /*--------------------------------------------------------------------
683 	Beschreibung:
684  --------------------------------------------------------------------*/
685 void SwDrawBaseShell::GetState(SfxItemSet& rSet)
686 {
687 	SwWrtShell &rSh = GetShell();
688 	SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
689 	SfxWhichIter aIter( rSet );
690 	sal_uInt16 nWhich = aIter.FirstWhich();
691 	sal_Bool bProtected = rSh.IsSelObjProtected(FLYPROTECT_CONTENT);
692 
693 	if (!bProtected)	// Im Parent nachsehen
694 		bProtected |= rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
695 
696 	while( nWhich )
697 	{
698 		switch( nWhich )
699 		{
700 			case FN_DRAW_WRAP_DLG:
701 			case SID_ATTR_TRANSFORM:
702 			case SID_FRAME_TO_TOP:
703 			case SID_FRAME_TO_BOTTOM:
704 			case FN_FRAME_UP:
705 			case FN_FRAME_DOWN:
706 			case SID_DELETE:
707 			case FN_BACKSPACE:
708 				if( bProtected || !rSh.IsObjSelected() )
709 					rSet.DisableItem( nWhich );
710 				break;
711 			case SID_GROUP:
712 				if ( rSh.IsObjSelected() < 2 || bProtected || !rSh.IsGroupAllowed() )
713 					rSet.DisableItem( nWhich );
714 				break;
715 			case SID_UNGROUP:
716 				if ( !rSh.IsGroupSelected() || bProtected )
717 					rSet.DisableItem( nWhich );
718 				break;
719 			case SID_ENTER_GROUP:
720 				if ( !rSh.IsGroupSelected() )
721 					rSet.DisableItem( nWhich );
722 				break;
723 			case SID_LEAVE_GROUP:
724 				if ( !pSdrView->IsGroupEntered() )
725 					rSet.DisableItem( nWhich );
726 				break;
727 			case SID_OBJECT_ALIGN_LEFT:
728 			case SID_OBJECT_ALIGN_CENTER:
729 			case SID_OBJECT_ALIGN_RIGHT:
730 			case SID_OBJECT_ALIGN_UP:
731 			case SID_OBJECT_ALIGN_MIDDLE:
732 			case SID_OBJECT_ALIGN_DOWN:
733 			case SID_OBJECT_ALIGN:
734 				if ( !rSh.IsAlignPossible() || bProtected )
735 					rSet.DisableItem( nWhich );
736 				else
737 				{
738                     SfxAllEnumItem aEnumItem(nWhich, USHRT_MAX);
739                     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
740                     //if only one object is selected it can only be vertically
741                     // aligned because it is character bound
742                     if( rMarkList.GetMarkCount() == 1 )
743                     {
744                         aEnumItem.DisableValue(SID_OBJECT_ALIGN_LEFT);
745                         aEnumItem.DisableValue(SID_OBJECT_ALIGN_CENTER);
746                         aEnumItem.DisableValue(SID_OBJECT_ALIGN_RIGHT);
747                     }
748                     rSet.Put(aEnumItem);
749 				}
750 				break;
751 
752 			case FN_NAME_SHAPE :
753 				{
754 					if(1L != pSdrView->GetMarkedObjectCount())
755 					{
756 						rSet.DisableItem( nWhich );
757 					}
758 				}
759 				break;
760 
761 			// #i68101#
762 			case FN_TITLE_DESCRIPTION_SHAPE:
763 				{
764                     const bool bIsWebView(NULL != dynamic_cast<SwWebView*>(&GetView()));
765 
766 					if(!bIsWebView && 1L != pSdrView->GetMarkedObjectCount())
767 					{
768 						rSet.DisableItem( nWhich );
769 					}
770 				}
771 				break;
772         }
773 		nWhich = aIter.NextWhich();
774 	}
775 }
776 
777 
778 void SwDrawBaseShell::GetDrawAttrStateForIFBX( SfxItemSet& rSet )
779 {
780  	SwWrtShell *pSh = &GetShell();
781  	SdrView*	pSdrView = pSh->GetDrawView();
782  	const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
783  	if( rMarkList.GetMark(0) != 0 )
784  	{
785 		// SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();//OST_IFBX@WL2
786  		SfxItemSet aNewAttr(pSdrView->GetGeoAttrFromMarked());
787  		rSet.Put(aNewAttr,false);
788  	}
789 }
790 
791 
792 sal_Bool SwDrawBaseShell::Disable(SfxItemSet& rSet, sal_uInt16 nWhich)
793 {
794 	sal_Bool bDisable = GetShell().IsSelObjProtected(FLYPROTECT_CONTENT);
795 
796 	if (bDisable)
797 	{
798 		if (nWhich)
799 			rSet.DisableItem( nWhich );
800 		else
801 		{
802 			SfxWhichIter aIter( rSet );
803 			nWhich = aIter.FirstWhich();
804 			while (nWhich)
805 			{
806 				rSet.DisableItem( nWhich );
807 				nWhich = aIter.NextWhich();
808 			}
809 		}
810 	}
811 
812 	return bDisable;
813 }
814 
815 /*-- 09.03.2004 13:15:03---------------------------------------------------
816     Validate of drawing positions
817   -----------------------------------------------------------------------*/
818 IMPL_LINK(SwDrawBaseShell, ValidatePosition, SvxSwFrameValidation*, pValidation )
819 {
820     SwWrtShell *pSh = &GetShell();
821     pValidation->nMinHeight = MINFLY;
822     pValidation->nMinWidth =  MINFLY;
823 
824     SwRect aBoundRect;
825 
826     // OD 18.09.2003 #i18732# - adjustment for allowing vertical position
827     //      aligned to page for fly frame anchored to paragraph or to character.
828     const RndStdIds eAnchorType = static_cast<RndStdIds >(pValidation->nAnchorType);
829     const SwPosition* pCntntPos = 0;
830     SdrView*  pSdrView = pSh->GetDrawView();
831     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
832     if( rMarkList.GetMarkCount() == 1 )
833     {
834         SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
835         SwFrmFmt* pFrmFmt = FindFrmFmt( pObj );
836         pCntntPos = pFrmFmt->GetAnchor().GetCntntAnchor();
837     }
838 
839     pSh->CalcBoundRect( aBoundRect, eAnchorType,
840                            pValidation->nHRelOrient,
841                            pValidation->nVRelOrient,
842                            pCntntPos,
843                            pValidation->bFollowTextFlow,
844                            pValidation->bMirror, NULL, &pValidation->aPercentSize);
845 
846     sal_Bool bIsInVertical( sal_False );
847     {
848         sal_Bool bRTL;
849         sal_Bool bVertL2R;
850         bIsInVertical = pSh->IsFrmVertical(sal_True, bRTL, bVertL2R);
851     }
852     if(bIsInVertical)
853     {
854         Point aPos(aBoundRect.Pos());
855         long nTmp = aPos.X();
856         aPos.X() = aPos.Y();
857         aPos.Y() = nTmp;
858         Size aSize(aBoundRect.SSize());
859         nTmp = aSize.Width();
860         aSize.Width() = aSize.Height();
861         aSize.Height() = nTmp;
862         aBoundRect.Chg( aPos, aSize );
863         //exchange width/height to enable correct values
864         nTmp = pValidation->nWidth;
865         pValidation->nWidth = pValidation->nHeight;
866         pValidation->nHeight = nTmp;
867     }
868     if ((eAnchorType == FLY_AT_PAGE) || (eAnchorType == FLY_AT_FLY))
869     {
870         // MinimalPosition
871         pValidation->nMinHPos = aBoundRect.Left();
872         pValidation->nMinVPos = aBoundRect.Top();
873         SwTwips nH = pValidation->nHPos;
874         SwTwips nV = pValidation->nVPos;
875 
876         if (pValidation->nHPos + pValidation->nWidth > aBoundRect.Right())
877         {
878             if (pValidation->nHoriOrient == text::HoriOrientation::NONE)
879             {
880                 pValidation->nHPos -= ((pValidation->nHPos + pValidation->nWidth) - aBoundRect.Right());
881                 nH = pValidation->nHPos;
882             }
883             else
884                 pValidation->nWidth = aBoundRect.Right() - pValidation->nHPos;
885         }
886 
887         if (pValidation->nHPos + pValidation->nWidth > aBoundRect.Right())
888             pValidation->nWidth = aBoundRect.Right() - pValidation->nHPos;
889 
890         if (pValidation->nVPos + pValidation->nHeight > aBoundRect.Bottom())
891         {
892             if (pValidation->nVertOrient == text::VertOrientation::NONE)
893             {
894                 pValidation->nVPos -= ((pValidation->nVPos + pValidation->nHeight) - aBoundRect.Bottom());
895                 nV = pValidation->nVPos;
896             }
897             else
898                 pValidation->nHeight = aBoundRect.Bottom() - pValidation->nVPos;
899         }
900 
901         if (pValidation->nVPos + pValidation->nHeight > aBoundRect.Bottom())
902             pValidation->nHeight = aBoundRect.Bottom() - pValidation->nVPos;
903 
904         if ( pValidation->nVertOrient != text::VertOrientation::NONE )
905             nV = aBoundRect.Top();
906 
907         if ( pValidation->nHoriOrient != text::HoriOrientation::NONE )
908             nH = aBoundRect.Left();
909 
910         pValidation->nMaxHPos   = aBoundRect.Right()  - pValidation->nWidth;
911         pValidation->nMaxHeight = aBoundRect.Bottom() - nV;
912 
913         pValidation->nMaxVPos   = aBoundRect.Bottom() - pValidation->nHeight;
914         pValidation->nMaxWidth  = aBoundRect.Right()  - nH;
915     }
916     else if ((eAnchorType == FLY_AT_PARA) || (eAnchorType == FLY_AT_CHAR))
917     {
918         if (pValidation->nHPos + pValidation->nWidth > aBoundRect.Right())
919         {
920             if (pValidation->nHoriOrient == text::HoriOrientation::NONE)
921             {
922                 pValidation->nHPos -= ((pValidation->nHPos + pValidation->nWidth) - aBoundRect.Right());
923             }
924             else
925                 pValidation->nWidth = aBoundRect.Right() - pValidation->nHPos;
926         }
927 
928         // OD 29.09.2003 #i17567#, #i18732# - consider following the text flow
929         // and alignment at page areas.
930         const bool bMaxVPosAtBottom = !pValidation->bFollowTextFlow ||
931                                       pValidation->nVRelOrient == text::RelOrientation::PAGE_FRAME ||
932                                       pValidation->nVRelOrient == text::RelOrientation::PAGE_PRINT_AREA;
933         {
934             SwTwips nTmpMaxVPos = ( bMaxVPosAtBottom
935                                     ? aBoundRect.Bottom()
936                                     : aBoundRect.Height() ) -
937                                   pValidation->nHeight;
938             if ( pValidation->nVPos > nTmpMaxVPos )
939             {
940                 if (pValidation->nVertOrient == text::VertOrientation::NONE)
941                 {
942                     pValidation->nVPos = nTmpMaxVPos;
943                 }
944                 else
945                 {
946                     pValidation->nHeight = ( bMaxVPosAtBottom
947                                      ? aBoundRect.Bottom()
948                                      : aBoundRect.Height() ) - pValidation->nVPos;
949                 }
950             }
951         }
952 
953         pValidation->nMinHPos  = aBoundRect.Left();
954         pValidation->nMaxHPos  = aBoundRect.Right() - pValidation->nWidth;
955 
956         pValidation->nMinVPos  = aBoundRect.Top();
957         // OD 26.09.2003 #i17567#, #i18732# - determine maximum vertical position
958         if ( bMaxVPosAtBottom )
959         {
960             pValidation->nMaxVPos  = aBoundRect.Bottom() - pValidation->nHeight;
961         }
962         else
963         {
964             pValidation->nMaxVPos  = aBoundRect.Height() - pValidation->nHeight;
965         }
966 
967         // Maximale Breite Hoehe
968         const SwTwips nH = ( pValidation->nHoriOrient != text::HoriOrientation::NONE )
969                            ? aBoundRect.Left()
970                            : pValidation->nHPos;
971         const SwTwips nV = ( pValidation->nVertOrient != text::VertOrientation::NONE )
972                            ? aBoundRect.Top()
973                            : pValidation->nVPos;
974         pValidation->nMaxHeight  = pValidation->nMaxVPos + pValidation->nHeight - nV;
975         pValidation->nMaxWidth   = pValidation->nMaxHPos + pValidation->nWidth - nH;
976     }
977     else if (eAnchorType == FLY_AS_CHAR)
978     {
979         pValidation->nMinHPos = 0;
980         pValidation->nMaxHPos = 0;
981 
982         pValidation->nMaxHeight = aBoundRect.Height();
983         pValidation->nMaxWidth  = aBoundRect.Width();
984 
985         pValidation->nMaxVPos   = aBoundRect.Height();
986         pValidation->nMinVPos   = -aBoundRect.Height() + pValidation->nHeight;
987         if (pValidation->nMaxVPos < pValidation->nMinVPos)
988         {
989             pValidation->nMinVPos = pValidation->nMaxVPos;
990             pValidation->nMaxVPos = -aBoundRect.Height();
991         }
992     }
993     if(bIsInVertical)
994     {
995         //restore width/height exchange
996         long nTmp = pValidation->nWidth;
997         pValidation->nWidth = pValidation->nHeight;
998         pValidation->nHeight = nTmp;
999     }
1000 
1001     if (pValidation->nMaxWidth < pValidation->nWidth)
1002         pValidation->nWidth = pValidation->nMaxWidth;
1003     if (pValidation->nMaxHeight < pValidation->nHeight)
1004         pValidation->nHeight = pValidation->nMaxHeight;
1005     return 0;
1006 }
1007