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 <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>
52 :
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>
65 :
66 : #include <IDocumentDrawModelAccess.hxx>
67 :
68 : using namespace ::com::sun::star;
69 :
70 165 : SFX_IMPL_INTERFACE(SwDrawBaseShell, SwBaseShell, SW_RES(0))
71 : {
72 33 : }
73 :
74 0 : TYPEINIT1(SwDrawBaseShell,SwBaseShell)
75 :
76 0 : SwDrawBaseShell::SwDrawBaseShell(SwView &_rView):
77 0 : SwBaseShell( _rView )
78 : {
79 0 : GetShell().NoEdit(true);
80 :
81 0 : SwEditWin& rWin = GetView().GetEditWin();
82 :
83 0 : rWin.SetBezierMode(SID_BEZIER_MOVE);
84 :
85 0 : if ( !_rView.GetDrawFuncPtr() )
86 0 : _rView.GetEditWin().StdDrawMode( OBJ_NONE, sal_True );
87 :
88 0 : SwTransferable::CreateSelection( GetShell() );
89 0 : }
90 :
91 0 : SwDrawBaseShell::~SwDrawBaseShell()
92 : {
93 0 : GetView().ExitDraw();
94 0 : GetShell().Edit();
95 0 : SwTransferable::ClearSelection( GetShell() );
96 0 : }
97 :
98 0 : void SwDrawBaseShell::Execute(SfxRequest &rReq)
99 : {
100 0 : SwWrtShell *pSh = &GetShell();
101 0 : SdrView* pSdrView = pSh->GetDrawView();
102 0 : const SfxItemSet *pArgs = rReq.GetArgs();
103 0 : sal_uInt16 nSlotId = rReq.GetSlot();
104 0 : sal_Bool bChanged = pSdrView->GetModel()->IsChanged();
105 0 : pSdrView->GetModel()->SetChanged(sal_False);
106 0 : const SfxPoolItem* pItem = 0;
107 0 : if(pArgs)
108 0 : pArgs->GetItemState(nSlotId, sal_False, &pItem);
109 :
110 : //Special case align by menu
111 0 : if(pItem && nSlotId == SID_OBJECT_ALIGN)
112 : {
113 : OSL_ENSURE(PTR_CAST(SfxEnumItem, pItem),"SfxEnumItem expected");
114 0 : nSlotId = nSlotId + ((const SfxEnumItem*)pItem)->GetValue();
115 0 : nSlotId++;
116 : }
117 :
118 0 : sal_Bool bAlignPossible = pSh->IsAlignPossible();
119 :
120 0 : sal_Bool bTopParam = sal_True, bBottomParam = sal_True;
121 0 : bool bNotify = false;
122 0 : bool bDone = false;
123 0 : SfxBindings& rBind = GetView().GetViewFrame()->GetBindings();
124 :
125 0 : switch (nSlotId)
126 : {
127 : case FN_DRAW_WRAP_DLG:
128 : {
129 0 : if(pSdrView->AreObjectsMarked())
130 : {
131 0 : if(!pArgs)
132 : {
133 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
134 0 : if( rMarkList.GetMark(0) != 0 )
135 : {
136 0 : 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,
141 0 : 0);
142 :
143 : aSet.Put(SfxBoolItem(SID_HTML_MODE,
144 0 : 0 != ::GetHtmlMode(pSh->GetView().GetDocShell())));
145 :
146 0 : aSet.Put(SfxInt16Item(FN_DRAW_WRAP_DLG, pSh->GetLayerId()));
147 :
148 0 : pSh->GetObjAttr(aSet);
149 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
150 : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
151 :
152 0 : SfxAbstractDialog* pDlg = pFact->CreateSwWrapDlg( GetView().GetWindow(), aSet, pSh, sal_True, RC_DLG_SWWRAPDLG );
153 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
154 :
155 0 : if (pDlg->Execute() == RET_OK)
156 : {
157 : const SfxPoolItem* pWrapItem;
158 0 : const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
159 0 : if(SFX_ITEM_SET == pOutSet->GetItemState(FN_DRAW_WRAP_DLG, sal_False, &pWrapItem))
160 : {
161 0 : short nLayer = ((const SfxInt16Item*)pWrapItem)->GetValue();
162 0 : if (nLayer == 1)
163 0 : pSh->SelectionToHeaven();
164 : else
165 0 : pSh->SelectionToHell();
166 : }
167 :
168 0 : pSh->SetObjAttr(*pOutSet);
169 : }
170 0 : delete pDlg;
171 : }
172 : }
173 : }
174 : }
175 0 : break;
176 :
177 : case SID_ATTR_TRANSFORM:
178 : {
179 0 : if(pSdrView->AreObjectsMarked())
180 : {
181 0 : if(!pArgs)
182 : {
183 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
184 0 : if( rMarkList.GetMark(0) != 0 )
185 : {
186 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
187 0 : SfxAbstractTabDialog *pDlg=NULL;
188 0 : bool bCaption = false;
189 :
190 : // Allowed anchorages:
191 0 : short nAnchor = pSh->GetAnchorId();
192 0 : sal_uInt16 nAllowedAnchors = SVX_OBJ_AT_CNTNT | SVX_OBJ_IN_CNTNT | SVX_OBJ_PAGE;
193 0 : sal_uInt16 nHtmlMode = ::GetHtmlMode(pSh->GetView().GetDocShell());
194 :
195 0 : if ( pSh->IsFlyInFly() )
196 0 : nAllowedAnchors |= SVX_OBJ_AT_FLY;
197 :
198 0 : if (pObj->GetObjIdentifier() == OBJ_CAPTION )
199 0 : bCaption = true;
200 :
201 0 : if (bCaption)
202 : {
203 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
204 0 : if ( pFact )
205 : {
206 : AbstractSvxCaptionDialog* pCaptionDlg =
207 0 : pFact->CreateCaptionDialog( NULL, pSdrView, nAllowedAnchors );
208 0 : pCaptionDlg->SetValidateFramePosLink( LINK(this, SwDrawBaseShell, ValidatePosition) );
209 0 : pDlg = pCaptionDlg;
210 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
211 : }
212 : }
213 : else
214 : {
215 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
216 0 : if ( pFact )
217 : {
218 :
219 : AbstractSvxTransformTabDialog* pTransform =
220 0 : pFact->CreateSvxTransformTabDialog( NULL, NULL, pSdrView, nAllowedAnchors );
221 0 : pTransform->SetValidateFramePosLink( LINK(this, SwDrawBaseShell, ValidatePosition) );
222 0 : pDlg = pTransform;
223 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
224 : }
225 : }
226 0 : SfxItemSet aNewAttr(pSdrView->GetGeoAttrFromMarked());
227 :
228 0 : const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
229 0 : SfxItemSet aSet( *aNewAttr.GetPool(), pRange );
230 0 : FieldUnit eMetric = ::GetDfltMetric(0 != dynamic_cast<SwWebView*>(&GetView()));
231 0 : SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
232 :
233 0 : aSet.Put( aNewAttr, sal_False );
234 :
235 0 : if (bCaption)
236 0 : pSdrView->GetAttributes( aSet );
237 :
238 0 : aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_ANCHOR, nAnchor));
239 : sal_Bool bRTL;
240 : sal_Bool bVertL2R;
241 0 : aSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_IN_VERTICAL_TEXT, pSh->IsFrmVertical(sal_True, bRTL, bVertL2R)));
242 0 : aSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_IN_RTL_TEXT, bRTL));
243 :
244 0 : SwFrmFmt* pFrmFmt = FindFrmFmt( pObj );
245 :
246 0 : aSet.Put( pFrmFmt->GetFmtAttr(RES_FOLLOW_TEXT_FLOW) );
247 :
248 0 : SwFmtVertOrient aVOrient((const SwFmtVertOrient&)pFrmFmt->GetFmtAttr(RES_VERT_ORIENT));
249 0 : aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_VERT_ORIENT, aVOrient.GetVertOrient()));
250 0 : aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_VERT_RELATION, aVOrient.GetRelationOrient() ));
251 0 : aSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_VERT_POSITION, aVOrient.GetPos()));
252 :
253 0 : SwFmtHoriOrient aHOrient((const SwFmtHoriOrient&)pFrmFmt->GetFmtAttr(RES_HORI_ORIENT));
254 0 : aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_HORI_ORIENT, aHOrient.GetHoriOrient()));
255 0 : aSet.Put(SfxInt16Item(SID_ATTR_TRANSFORM_HORI_RELATION, aHOrient.GetRelationOrient() ));
256 0 : aSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_HORI_MIRROR, aHOrient.IsPosToggle()));
257 0 : aSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_HORI_POSITION, aHOrient.GetPos()));
258 :
259 0 : aSet.Put(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
260 :
261 0 : pDlg->SetInputSet( &aSet );
262 :
263 0 : if (pDlg->Execute() == RET_OK)
264 : {
265 0 : const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
266 0 : pSh->StartAllAction();
267 :
268 : // #i30451#
269 0 : pSh->StartUndo(UNDO_INSFMTATTR);
270 :
271 0 : pSdrView->SetGeoAttrToMarked(*pOutSet);
272 :
273 0 : if (bCaption)
274 0 : pSdrView->SetAttributes(*pOutSet);
275 :
276 : bool bPosCorr =
277 : SFX_ITEM_SET != pOutSet->GetItemState(
278 0 : SID_ATTR_TRANSFORM_POS_X, sal_False ) &&
279 : SFX_ITEM_SET != pOutSet->GetItemState(
280 0 : SID_ATTR_TRANSFORM_POS_Y, sal_False );
281 :
282 0 : SfxItemSet aFrmAttrSet(GetPool(), RES_FRMATR_BEGIN, RES_FRMATR_END - 1);
283 :
284 0 : bool bSingleSelection = rMarkList.GetMarkCount() == 1;
285 :
286 : const SfxPoolItem* pAnchorItem;
287 0 : if(SFX_ITEM_SET == pOutSet->GetItemState(
288 0 : SID_ATTR_TRANSFORM_ANCHOR, sal_False, &pAnchorItem))
289 : {
290 0 : if(!bSingleSelection)
291 : pSh->ChgAnchor(((const SfxInt16Item*)pAnchorItem)
292 0 : ->GetValue(), false, bPosCorr );
293 : else
294 : {
295 0 : SwFmtAnchor aAnchor(pFrmFmt->GetAnchor());
296 0 : aAnchor.SetType((RndStdIds)((const SfxInt16Item*)pAnchorItem)->GetValue());
297 0 : aFrmAttrSet.Put( aAnchor );
298 : }
299 : }
300 0 : const SfxPoolItem* pHoriOrient = 0;
301 0 : const SfxPoolItem* pHoriRelation = 0;
302 0 : const SfxPoolItem* pHoriPosition = 0;
303 0 : const SfxPoolItem* pHoriMirror = 0;
304 0 : pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_ORIENT, sal_False, &pHoriOrient);
305 0 : pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_RELATION, sal_False, &pHoriRelation);
306 0 : pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_POSITION, sal_False, &pHoriPosition);
307 0 : pOutSet->GetItemState(SID_ATTR_TRANSFORM_HORI_MIRROR, sal_False, &pHoriMirror);
308 0 : if(pHoriOrient || pHoriRelation || pHoriPosition || pHoriMirror)
309 : {
310 0 : if(pHoriOrient)
311 : aHOrient.SetHoriOrient(
312 0 : static_cast<const SfxInt16Item*>(pHoriOrient)->GetValue());
313 0 : if(pHoriRelation)
314 : aHOrient.SetRelationOrient(
315 0 : static_cast<const SfxInt16Item*>(pHoriRelation)->GetValue());
316 0 : if(pHoriPosition)
317 0 : aHOrient.SetPos( static_cast<const SfxInt32Item*>(pHoriPosition)->GetValue());
318 0 : if(pHoriMirror)
319 0 : aHOrient.SetPosToggle( static_cast<const SfxBoolItem*>(pHoriMirror)->GetValue());
320 0 : aFrmAttrSet.Put(aHOrient);
321 : }
322 :
323 0 : const SfxPoolItem* pVertOrient = 0;
324 0 : const SfxPoolItem* pVertRelation = 0;
325 0 : const SfxPoolItem* pVertPosition = 0;
326 0 : pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_ORIENT, sal_False, &pVertOrient);
327 0 : pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_RELATION, sal_False, &pVertRelation);
328 0 : pOutSet->GetItemState(SID_ATTR_TRANSFORM_VERT_POSITION, sal_False, &pVertPosition);
329 0 : if(pVertOrient || pVertRelation || pVertPosition )
330 : {
331 0 : if(pVertOrient)
332 : aVOrient.SetVertOrient(
333 0 : static_cast<const SfxInt16Item*>(pVertOrient)->GetValue());
334 0 : if(pVertRelation)
335 : aVOrient.SetRelationOrient(
336 0 : static_cast<const SfxInt16Item*>(pVertRelation)->GetValue());
337 0 : if(pVertPosition)
338 0 : aVOrient.SetPos( static_cast<const SfxInt32Item*>(pVertPosition)->GetValue());
339 0 : aFrmAttrSet.Put( aVOrient );
340 : }
341 0 : const SfxPoolItem* pFollowItem = 0;
342 0 : pOutSet->GetItemState(RES_FOLLOW_TEXT_FLOW, sal_False, &pFollowItem);
343 0 : if(pFollowItem)
344 0 : aFrmAttrSet.Put(*pFollowItem);
345 :
346 0 : if(aFrmAttrSet.Count())
347 0 : pSh->SetDrawingAttr(aFrmAttrSet);
348 :
349 0 : rBind.InvalidateAll(sal_False);
350 :
351 : // #i30451#
352 0 : pSh->EndUndo( UNDO_INSFMTATTR );
353 :
354 0 : pSh->EndAllAction();
355 : }
356 0 : delete pDlg;
357 :
358 : }
359 : }
360 : else
361 : {
362 0 : pSdrView->SetGeoAttrToMarked( *pArgs );
363 : }
364 : }
365 : }
366 0 : break;
367 :
368 : case SID_DELETE:
369 : case FN_BACKSPACE:
370 0 : if (pSh->IsObjSelected() && !pSdrView->IsTextEdit())
371 : {
372 0 : bDone = true;
373 :
374 0 : if( GetView().IsDrawRotate() )
375 : {
376 0 : pSh->SetDragMode( SDRDRAG_MOVE );
377 0 : GetView().FlipDrawRotate();
378 : }
379 :
380 0 : pSh->SetModified();
381 0 : pSh->DelSelectedObj();
382 :
383 0 : if (rReq.IsAPI() ||
384 0 : GetView().GetEditWin().IsObjectSelect() )
385 : {
386 : // If basic call, then back to the text shell, because the
387 : // Basic otherwise has no possibility to return.
388 0 : if (GetView().GetDrawFuncPtr())
389 : {
390 0 : GetView().GetDrawFuncPtr()->Deactivate();
391 0 : GetView().SetDrawFuncPtr(NULL);
392 : }
393 0 : GetView().LeaveDrawCreate(); // Switch to selection mode
394 : }
395 :
396 0 : if (pSh->IsSelFrmMode())
397 : {
398 0 : pSh->LeaveSelFrmMode();
399 : // #105852# FME
400 : }
401 0 : bNotify = true;
402 : }
403 0 : break;
404 :
405 : case SID_GROUP:
406 0 : if (pSh->IsObjSelected() > 1 && pSh->IsGroupAllowed())
407 : {
408 0 : pSh->GroupSelection();
409 0 : rBind.Invalidate(SID_UNGROUP);
410 : }
411 0 : break;
412 :
413 : case SID_UNGROUP:
414 0 : if (pSh->IsGroupSelected())
415 : {
416 0 : pSh->UnGroupSelection();
417 0 : rBind.Invalidate(SID_GROUP);
418 : }
419 0 : break;
420 :
421 : case SID_ENTER_GROUP:
422 0 : if (pSh->IsGroupSelected())
423 : {
424 0 : pSdrView->EnterMarkedGroup();
425 0 : rBind.InvalidateAll(sal_False);
426 : }
427 0 : break;
428 :
429 : case SID_LEAVE_GROUP:
430 0 : if (pSdrView->IsGroupEntered())
431 : {
432 0 : pSdrView->LeaveOneGroup();
433 0 : rBind.Invalidate(SID_ENTER_GROUP);
434 0 : rBind.Invalidate(SID_UNGROUP);
435 : }
436 0 : break;
437 :
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:
444 : {
445 0 : if ( bAlignPossible )
446 : {
447 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
448 0 : if( rMarkList.GetMarkCount() == 1 && bAlignPossible )
449 : { // Do not align objects to each other
450 0 : sal_uInt16 nAnchor = pSh->GetAnchorId();
451 0 : if (nAnchor == FLY_AS_CHAR)
452 : {
453 0 : sal_Int16 nVertOrient = -1;
454 :
455 0 : switch (nSlotId)
456 : {
457 : case SID_OBJECT_ALIGN_UP:
458 0 : nVertOrient = text::VertOrientation::TOP;
459 0 : break;
460 : case SID_OBJECT_ALIGN_MIDDLE:
461 0 : nVertOrient = text::VertOrientation::CENTER;
462 0 : break;
463 : case SID_OBJECT_ALIGN_DOWN:
464 0 : nVertOrient = text::VertOrientation::BOTTOM;
465 0 : break;
466 : default:
467 0 : break;
468 : }
469 0 : if (nVertOrient != -1)
470 : {
471 0 : pSh->StartAction();
472 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
473 0 : SwFrmFmt* pFrmFmt = FindFrmFmt( pObj );
474 0 : SwFmtVertOrient aVOrient((SwFmtVertOrient&)pFrmFmt->GetFmtAttr(RES_VERT_ORIENT));
475 0 : aVOrient.SetVertOrient( nVertOrient );
476 0 : pFrmFmt->SetFmtAttr(aVOrient);
477 0 : pSh->EndAction();
478 : }
479 0 : break;
480 : }
481 0 : if (nAnchor == FLY_AT_PARA)
482 0 : break; // Do not align frames of an anchored paragraph
483 : }
484 :
485 0 : pSh->StartAction();
486 0 : switch (nSlotId)
487 : {
488 : case SID_OBJECT_ALIGN_LEFT:
489 0 : pSdrView->AlignMarkedObjects(SDRHALIGN_LEFT, SDRVALIGN_NONE);
490 0 : break;
491 : case SID_OBJECT_ALIGN_CENTER:
492 0 : pSdrView->AlignMarkedObjects(SDRHALIGN_CENTER, SDRVALIGN_NONE);
493 0 : break;
494 : case SID_OBJECT_ALIGN_RIGHT:
495 0 : pSdrView->AlignMarkedObjects(SDRHALIGN_RIGHT, SDRVALIGN_NONE);
496 0 : break;
497 : case SID_OBJECT_ALIGN_UP:
498 0 : pSdrView->AlignMarkedObjects(SDRHALIGN_NONE, SDRVALIGN_TOP);
499 0 : break;
500 : case SID_OBJECT_ALIGN_MIDDLE:
501 0 : pSdrView->AlignMarkedObjects(SDRHALIGN_NONE, SDRVALIGN_CENTER);
502 0 : break;
503 : case SID_OBJECT_ALIGN_DOWN:
504 0 : pSdrView->AlignMarkedObjects(SDRHALIGN_NONE, SDRVALIGN_BOTTOM);
505 0 : break;
506 : }
507 0 : pSh->EndAction();
508 : }
509 : }
510 0 : break;
511 :
512 : case FN_FRAME_UP:
513 0 : bTopParam = sal_False;
514 : /* no break */
515 : case SID_FRAME_TO_TOP:
516 0 : pSh->SelectionToTop( bTopParam );
517 0 : break;
518 :
519 : case FN_FRAME_DOWN:
520 0 : bBottomParam = sal_False;
521 : /* no break */
522 : case SID_FRAME_TO_BOTTOM:
523 0 : pSh->SelectionToBottom( bBottomParam );
524 0 : break;
525 :
526 : case FN_NAME_SHAPE:
527 : {
528 0 : bDone = true;
529 :
530 0 : if(1L == pSdrView->GetMarkedObjectCount())
531 : {
532 : // #i68101#
533 0 : SdrObject* pSelected = pSdrView->GetMarkedObjectByIndex(0L);
534 : OSL_ENSURE(pSelected, "DrawViewShell::FuTemp03: nMarkCount, but no object (!)");
535 0 : String aName(pSelected->GetName());
536 :
537 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
538 : OSL_ENSURE(pFact, "Dialogdiet fail!");
539 0 : AbstractSvxObjectNameDialog* pDlg = pFact->CreateSvxObjectNameDialog(NULL, aName);
540 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
541 :
542 0 : pDlg->SetCheckNameHdl(LINK(this, SwDrawBaseShell, CheckGroupShapeNameHdl));
543 :
544 0 : if(RET_OK == pDlg->Execute())
545 : {
546 0 : pDlg->GetName(aName);
547 0 : pSelected->SetName(aName);
548 0 : pSh->SetModified();
549 : }
550 :
551 0 : delete pDlg;
552 : }
553 :
554 0 : break;
555 : }
556 :
557 : // #i68101#
558 : case FN_TITLE_DESCRIPTION_SHAPE:
559 : {
560 0 : bDone = true;
561 :
562 0 : if(1L == pSdrView->GetMarkedObjectCount())
563 : {
564 0 : SdrObject* pSelected = pSdrView->GetMarkedObjectByIndex(0L);
565 : OSL_ENSURE(pSelected, "DrawViewShell::FuTemp03: nMarkCount, but no object (!)");
566 0 : String aTitle(pSelected->GetTitle());
567 0 : String aDescription(pSelected->GetDescription());
568 :
569 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
570 : OSL_ENSURE(pFact, "Dialogdiet fail!");
571 0 : AbstractSvxObjectTitleDescDialog* pDlg = pFact->CreateSvxObjectTitleDescDialog(NULL, aTitle, aDescription);
572 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
573 :
574 0 : if(RET_OK == pDlg->Execute())
575 : {
576 0 : pDlg->GetTitle(aTitle);
577 0 : pDlg->GetDescription(aDescription);
578 :
579 0 : pSelected->SetTitle(aTitle);
580 0 : pSelected->SetDescription(aDescription);
581 :
582 0 : pSh->SetModified();
583 : }
584 :
585 0 : delete pDlg;
586 : }
587 :
588 0 : break;
589 : }
590 :
591 : default:
592 : OSL_ENSURE(!this, "wrong Dispatcher");
593 0 : return;
594 : }
595 0 : if(!bDone)
596 : {
597 0 : if(nSlotId >= SID_OBJECT_ALIGN_LEFT && nSlotId <= SID_OBJECT_ALIGN_DOWN)
598 0 : rBind.Invalidate(SID_ATTR_LONG_LRSPACE);
599 0 : if (pSdrView->GetModel()->IsChanged())
600 0 : pSh->SetModified();
601 0 : else if (bChanged)
602 0 : pSdrView->GetModel()->SetChanged(sal_True);
603 : // 40220: After Delete from DrawObjecs over the API GPF through self-destruction
604 0 : if(bNotify)
605 0 : GetView().AttrChangedNotify(pSh); // Shell switch if applicable...
606 : }
607 : }
608 :
609 : // Checks whether a given name is allowed for a group shape
610 :
611 0 : IMPL_LINK( SwDrawBaseShell, CheckGroupShapeNameHdl, AbstractSvxNameDialog*, pNameDialog )
612 : {
613 0 : SwWrtShell &rSh = GetShell();
614 0 : SdrView *pSdrView = rSh.GetDrawView();
615 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
616 : OSL_ENSURE(rMarkList.GetMarkCount() == 1, "wrong draw selection");
617 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
618 0 : const String sCurrentName = pObj->GetName();
619 0 : String sNewName;
620 0 : pNameDialog->GetName(sNewName);
621 0 : long nRet = 0;
622 0 : if(!sNewName.Len() || sCurrentName == sNewName)
623 0 : nRet = 1;
624 : else
625 : {
626 0 : nRet = 1;
627 0 : SdrModel* pModel = rSh.getIDocumentDrawModelAccess()->GetDrawModel();
628 0 : SdrObjListIter aIter( *(pModel->GetPage(0)), IM_DEEPWITHGROUPS );
629 0 : while( aIter.IsMore() )
630 : {
631 0 : SdrObject* pTempObj = aIter.Next();
632 0 : if ( pObj != pTempObj && pTempObj->GetName().equals(sNewName) )
633 : {
634 0 : nRet = 0;
635 0 : break;
636 : }
637 0 : }
638 : }
639 0 : return nRet;
640 : }
641 :
642 0 : void SwDrawBaseShell::GetState(SfxItemSet& rSet)
643 : {
644 0 : SwWrtShell &rSh = GetShell();
645 0 : SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
646 0 : SfxWhichIter aIter( rSet );
647 0 : sal_uInt16 nWhich = aIter.FirstWhich();
648 0 : sal_Bool bProtected = rSh.IsSelObjProtected(FLYPROTECT_CONTENT);
649 :
650 0 : if (!bProtected) // Look in the parent
651 0 : bProtected |= rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
652 :
653 0 : while( nWhich )
654 : {
655 0 : switch( nWhich )
656 : {
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 0 : if( bProtected || !rSh.IsObjSelected() )
666 0 : rSet.DisableItem( nWhich );
667 0 : break;
668 : case SID_GROUP:
669 0 : if ( rSh.IsObjSelected() < 2 || bProtected || !rSh.IsGroupAllowed() )
670 0 : rSet.DisableItem( nWhich );
671 0 : break;
672 : case SID_UNGROUP:
673 0 : if ( !rSh.IsGroupSelected() || bProtected )
674 0 : rSet.DisableItem( nWhich );
675 0 : break;
676 : case SID_ENTER_GROUP:
677 0 : if ( !rSh.IsGroupSelected() )
678 0 : rSet.DisableItem( nWhich );
679 0 : break;
680 : case SID_LEAVE_GROUP:
681 0 : if ( !pSdrView->IsGroupEntered() )
682 0 : rSet.DisableItem( nWhich );
683 0 : 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 0 : if ( !rSh.IsAlignPossible() || bProtected )
692 0 : rSet.DisableItem( nWhich );
693 : else
694 : {
695 0 : SfxAllEnumItem aEnumItem(nWhich, USHRT_MAX);
696 0 : 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 0 : if( rMarkList.GetMarkCount() == 1 )
700 : {
701 0 : aEnumItem.DisableValue(SID_OBJECT_ALIGN_LEFT);
702 0 : aEnumItem.DisableValue(SID_OBJECT_ALIGN_CENTER);
703 0 : aEnumItem.DisableValue(SID_OBJECT_ALIGN_RIGHT);
704 : }
705 0 : rSet.Put(aEnumItem);
706 : }
707 0 : break;
708 :
709 : case FN_NAME_SHAPE :
710 : {
711 0 : if(1L != pSdrView->GetMarkedObjectCount())
712 : {
713 0 : rSet.DisableItem( nWhich );
714 : }
715 : }
716 0 : break;
717 :
718 : // #i68101#
719 : case FN_TITLE_DESCRIPTION_SHAPE:
720 : {
721 0 : const bool bIsWebView(NULL != dynamic_cast<SwWebView*>(&GetView()));
722 :
723 0 : if(!bIsWebView && 1L != pSdrView->GetMarkedObjectCount())
724 : {
725 0 : rSet.DisableItem( nWhich );
726 : }
727 : }
728 0 : break;
729 : }
730 0 : nWhich = aIter.NextWhich();
731 0 : }
732 0 : }
733 :
734 0 : void SwDrawBaseShell::GetDrawAttrStateForIFBX( SfxItemSet& rSet )
735 : {
736 0 : SwWrtShell *pSh = &GetShell();
737 0 : SdrView* pSdrView = pSh->GetDrawView();
738 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
739 0 : if( rMarkList.GetMark(0) != 0 )
740 : {
741 0 : SfxItemSet aNewAttr(pSdrView->GetGeoAttrFromMarked());
742 0 : rSet.Put(aNewAttr,false);
743 : }
744 0 : }
745 :
746 0 : sal_Bool SwDrawBaseShell::Disable(SfxItemSet& rSet, sal_uInt16 nWhich)
747 : {
748 0 : sal_Bool bDisable = GetShell().IsSelObjProtected(FLYPROTECT_CONTENT);
749 :
750 0 : if (bDisable)
751 : {
752 0 : if (nWhich)
753 0 : rSet.DisableItem( nWhich );
754 : else
755 : {
756 0 : SfxWhichIter aIter( rSet );
757 0 : nWhich = aIter.FirstWhich();
758 0 : while (nWhich)
759 : {
760 0 : rSet.DisableItem( nWhich );
761 0 : nWhich = aIter.NextWhich();
762 0 : }
763 : }
764 : }
765 :
766 0 : return bDisable;
767 : }
768 :
769 : // Validate of drawing positions
770 :
771 0 : IMPL_LINK(SwDrawBaseShell, ValidatePosition, SvxSwFrameValidation*, pValidation )
772 : {
773 0 : SwWrtShell *pSh = &GetShell();
774 0 : pValidation->nMinHeight = MINFLY;
775 0 : pValidation->nMinWidth = MINFLY;
776 :
777 0 : SwRect aBoundRect;
778 :
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 0 : const RndStdIds eAnchorType = static_cast<RndStdIds >(pValidation->nAnchorType);
782 0 : const SwPosition* pCntntPos = 0;
783 0 : SdrView* pSdrView = pSh->GetDrawView();
784 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
785 0 : if( rMarkList.GetMarkCount() == 1 )
786 : {
787 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
788 0 : SwFrmFmt* pFrmFmt = FindFrmFmt( pObj );
789 0 : pCntntPos = pFrmFmt->GetAnchor().GetCntntAnchor();
790 : }
791 :
792 : pSh->CalcBoundRect( aBoundRect, eAnchorType,
793 : pValidation->nHRelOrient,
794 : pValidation->nVRelOrient,
795 : pCntntPos,
796 : pValidation->bFollowTextFlow,
797 0 : pValidation->bMirror, NULL, &pValidation->aPercentSize);
798 :
799 0 : sal_Bool bIsInVertical( sal_False );
800 : {
801 : sal_Bool bRTL;
802 : sal_Bool bVertL2R;
803 0 : bIsInVertical = pSh->IsFrmVertical(sal_True, bRTL, bVertL2R);
804 : }
805 0 : if(bIsInVertical)
806 : {
807 0 : Point aPos(aBoundRect.Pos());
808 0 : long nTmp = aPos.X();
809 0 : aPos.X() = aPos.Y();
810 0 : aPos.Y() = nTmp;
811 0 : Size aSize(aBoundRect.SSize());
812 0 : nTmp = aSize.Width();
813 0 : aSize.Width() = aSize.Height();
814 0 : aSize.Height() = nTmp;
815 0 : aBoundRect.Chg( aPos, aSize );
816 : //exchange width/height to enable correct values
817 0 : nTmp = pValidation->nWidth;
818 0 : pValidation->nWidth = pValidation->nHeight;
819 0 : pValidation->nHeight = nTmp;
820 : }
821 0 : if ((eAnchorType == FLY_AT_PAGE) || (eAnchorType == FLY_AT_FLY))
822 : {
823 : // MinimalPosition
824 0 : pValidation->nMinHPos = aBoundRect.Left();
825 0 : pValidation->nMinVPos = aBoundRect.Top();
826 0 : SwTwips nH = pValidation->nHPos;
827 0 : SwTwips nV = pValidation->nVPos;
828 :
829 0 : if (pValidation->nHPos + pValidation->nWidth > aBoundRect.Right())
830 : {
831 0 : if (pValidation->nHoriOrient == text::HoriOrientation::NONE)
832 : {
833 0 : pValidation->nHPos -= ((pValidation->nHPos + pValidation->nWidth) - aBoundRect.Right());
834 0 : nH = pValidation->nHPos;
835 : }
836 : else
837 0 : pValidation->nWidth = aBoundRect.Right() - pValidation->nHPos;
838 : }
839 :
840 0 : if (pValidation->nHPos + pValidation->nWidth > aBoundRect.Right())
841 0 : pValidation->nWidth = aBoundRect.Right() - pValidation->nHPos;
842 :
843 0 : if (pValidation->nVPos + pValidation->nHeight > aBoundRect.Bottom())
844 : {
845 0 : if (pValidation->nVertOrient == text::VertOrientation::NONE)
846 : {
847 0 : pValidation->nVPos -= ((pValidation->nVPos + pValidation->nHeight) - aBoundRect.Bottom());
848 0 : nV = pValidation->nVPos;
849 : }
850 : else
851 0 : pValidation->nHeight = aBoundRect.Bottom() - pValidation->nVPos;
852 : }
853 :
854 0 : if (pValidation->nVPos + pValidation->nHeight > aBoundRect.Bottom())
855 0 : pValidation->nHeight = aBoundRect.Bottom() - pValidation->nVPos;
856 :
857 0 : if ( pValidation->nVertOrient != text::VertOrientation::NONE )
858 0 : nV = aBoundRect.Top();
859 :
860 0 : if ( pValidation->nHoriOrient != text::HoriOrientation::NONE )
861 0 : nH = aBoundRect.Left();
862 :
863 0 : pValidation->nMaxHPos = aBoundRect.Right() - pValidation->nWidth;
864 0 : pValidation->nMaxHeight = aBoundRect.Bottom() - nV;
865 :
866 0 : pValidation->nMaxVPos = aBoundRect.Bottom() - pValidation->nHeight;
867 0 : pValidation->nMaxWidth = aBoundRect.Right() - nH;
868 : }
869 0 : else if ((eAnchorType == FLY_AT_PARA) || (eAnchorType == FLY_AT_CHAR))
870 : {
871 0 : if (pValidation->nHPos + pValidation->nWidth > aBoundRect.Right())
872 : {
873 0 : if (pValidation->nHoriOrient == text::HoriOrientation::NONE)
874 : {
875 0 : pValidation->nHPos -= ((pValidation->nHPos + pValidation->nWidth) - aBoundRect.Right());
876 : }
877 : else
878 0 : pValidation->nWidth = aBoundRect.Right() - pValidation->nHPos;
879 : }
880 :
881 : // OD 29.09.2003 #i17567#, #i18732# - consider following the text flow
882 : // and alignment at page areas.
883 0 : const bool bMaxVPosAtBottom = !pValidation->bFollowTextFlow ||
884 0 : pValidation->nVRelOrient == text::RelOrientation::PAGE_FRAME ||
885 0 : pValidation->nVRelOrient == text::RelOrientation::PAGE_PRINT_AREA;
886 : {
887 : SwTwips nTmpMaxVPos = ( bMaxVPosAtBottom
888 : ? aBoundRect.Bottom()
889 0 : : aBoundRect.Height() ) -
890 0 : pValidation->nHeight;
891 0 : if ( pValidation->nVPos > nTmpMaxVPos )
892 : {
893 0 : if (pValidation->nVertOrient == text::VertOrientation::NONE)
894 : {
895 0 : pValidation->nVPos = nTmpMaxVPos;
896 : }
897 : else
898 : {
899 : pValidation->nHeight = ( bMaxVPosAtBottom
900 : ? aBoundRect.Bottom()
901 0 : : aBoundRect.Height() ) - pValidation->nVPos;
902 : }
903 : }
904 : }
905 :
906 0 : pValidation->nMinHPos = aBoundRect.Left();
907 0 : pValidation->nMaxHPos = aBoundRect.Right() - pValidation->nWidth;
908 :
909 0 : pValidation->nMinVPos = aBoundRect.Top();
910 : // OD 26.09.2003 #i17567#, #i18732# - determine maximum vertical position
911 0 : if ( bMaxVPosAtBottom )
912 : {
913 0 : pValidation->nMaxVPos = aBoundRect.Bottom() - pValidation->nHeight;
914 : }
915 : else
916 : {
917 0 : pValidation->nMaxVPos = aBoundRect.Height() - pValidation->nHeight;
918 : }
919 :
920 : // Maximum width height
921 0 : const SwTwips nH = ( pValidation->nHoriOrient != text::HoriOrientation::NONE )
922 : ? aBoundRect.Left()
923 0 : : pValidation->nHPos;
924 0 : const SwTwips nV = ( pValidation->nVertOrient != text::VertOrientation::NONE )
925 : ? aBoundRect.Top()
926 0 : : pValidation->nVPos;
927 0 : pValidation->nMaxHeight = pValidation->nMaxVPos + pValidation->nHeight - nV;
928 0 : pValidation->nMaxWidth = pValidation->nMaxHPos + pValidation->nWidth - nH;
929 : }
930 0 : else if (eAnchorType == FLY_AS_CHAR)
931 : {
932 0 : pValidation->nMinHPos = 0;
933 0 : pValidation->nMaxHPos = 0;
934 :
935 0 : pValidation->nMaxHeight = aBoundRect.Height();
936 0 : pValidation->nMaxWidth = aBoundRect.Width();
937 :
938 0 : pValidation->nMaxVPos = aBoundRect.Height();
939 0 : pValidation->nMinVPos = -aBoundRect.Height() + pValidation->nHeight;
940 0 : if (pValidation->nMaxVPos < pValidation->nMinVPos)
941 : {
942 0 : pValidation->nMinVPos = pValidation->nMaxVPos;
943 0 : pValidation->nMaxVPos = -aBoundRect.Height();
944 : }
945 : }
946 0 : if(bIsInVertical)
947 : {
948 : //restore width/height exchange
949 0 : long nTmp = pValidation->nWidth;
950 0 : pValidation->nWidth = pValidation->nHeight;
951 0 : pValidation->nHeight = nTmp;
952 : }
953 :
954 0 : if (pValidation->nMaxWidth < pValidation->nWidth)
955 0 : pValidation->nWidth = pValidation->nMaxWidth;
956 0 : if (pValidation->nMaxHeight < pValidation->nHeight)
957 0 : pValidation->nHeight = pValidation->nMaxHeight;
958 0 : return 0;
959 99 : }
960 :
961 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|