Update ooo320-m1
[ooovba.git] / sw / source / ui / shells / frmsh.cxx
blobb7f9fc460088e1f59fa035ddcb5df84ccf0677b5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: frmsh.cxx,v $
10 * $Revision: 1.22.190.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <svtools/whiter.hxx>
37 #include <svtools/imapobj.hxx>
38 #include <svx/srchitem.hxx>
39 #include <svtools/imap.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <basic/sbstar.hxx>
42 #include <svtools/rectitem.hxx>
43 #include <svtools/ptitem.hxx>
44 #include <svtools/stritem.hxx>
45 #include <svx/colritem.hxx>
46 #include <svx/bolnitem.hxx>
47 #include <svx/boxitem.hxx>
48 #include <svx/protitem.hxx>
49 #include <sfx2/dispatch.hxx>
50 #include <sfx2/request.hxx>
51 #include <sfx2/objface.hxx>
52 #include <svx/hlnkitem.hxx>
53 // --> OD 2009-07-07 #i73249#
54 #include <svx/svdview.hxx>
55 #include <vcl/msgbox.hxx>
56 // <--
57 #include <com/sun/star/embed/EmbedVerbs.hpp>
59 #include <fmturl.hxx>
60 #include <fmtclds.hxx>
61 #include <fmtcnct.hxx>
62 #include <swmodule.hxx>
63 #include <wrtsh.hxx>
64 #include <wview.hxx>
65 #include <frmatr.hxx>
66 #include <uitool.hxx>
67 #include <frmfmt.hxx>
68 #include <frmsh.hxx>
69 #include <frmmgr.hxx>
70 #include <frmdlg.hxx>
71 #include <swevent.hxx>
72 #include <usrpref.hxx>
73 #include <edtwin.hxx>
74 #include <swdtflvr.hxx>
75 #include <swwait.hxx>
76 #include <docstat.hxx>
77 #include <IDocumentStatistics.hxx>
79 #include <comphelper/processfactory.hxx>
80 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
82 #include <helpid.h>
83 #include <cmdid.h>
84 #include <globals.hrc>
85 #include <popup.hrc>
86 #include <shells.hrc>
87 #include "swabstdlg.hxx"
88 #include "misc.hrc"
89 // --> OD 2009-07-14 #i73249#
90 #include <svx/dialogs.hrc>
91 // <--
93 using namespace ::com::sun::star;
94 using namespace ::com::sun::star::uno;
96 // Prototypen ------------------------------------------------------------
98 void lcl_FrmGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine);
99 const SwFrmFmt* lcl_GetFrmFmtByName(SwWrtShell& rSh, const String& rName)
101 sal_uInt16 nCount = rSh.GetFlyCount(FLYCNTTYPE_FRM);
102 for( sal_uInt16 i = 0; i < nCount; i++)
104 const SwFrmFmt* pFmt = rSh.GetFlyNum(i, FLYCNTTYPE_FRM);
105 if(pFmt->GetName() == rName)
106 return pFmt;
108 return 0;
111 #define SwFrameShell
112 #include <sfx2/msg.hxx>
113 #include "swslots.hxx"
115 SFX_IMPL_INTERFACE(SwFrameShell, SwBaseShell, SW_RES(STR_SHELLNAME_FRAME))
117 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_FRM_POPUPMENU));
118 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_FRAME_TOOLBOX));
123 void SwFrameShell::Execute(SfxRequest &rReq)
125 //Erstmal die, die keinen FrmMgr benoetigen.
126 SwWrtShell &rSh = GetShell();
127 BOOL bMore = FALSE;
128 const SfxItemSet* pArgs = rReq.GetArgs();
129 const SfxPoolItem* pItem;
130 USHORT nSlot = rReq.GetSlot();
132 switch ( nSlot )
134 case FN_FRAME_TO_ANCHOR:
135 if ( rSh.IsFrmSelected() )
137 rSh.GotoFlyAnchor();
138 rSh.EnterStdMode();
139 rSh.CallChgLnk();
141 break;
142 case SID_FRAME_TO_TOP:
143 rSh.SelectionToTop();
144 break;
146 case SID_FRAME_TO_BOTTOM:
147 rSh.SelectionToBottom();
148 break;
150 case FN_FRAME_UP:
151 rSh.SelectionToTop( FALSE );
152 break;
154 case FN_FRAME_DOWN:
155 rSh.SelectionToBottom( FALSE );
156 break;
157 case FN_INSERT_FRAME:
158 if (!pArgs)
160 // Rahmen existiert bereits, Rahmendialog zur Bearbeitung oeffnen
161 SfxUInt16Item aDefPage(FN_FORMAT_FRAME_DLG, TP_COLUMN);
162 rSh.GetView().GetViewFrame()->GetDispatcher()->Execute( FN_FORMAT_FRAME_DLG,
163 SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
164 &aDefPage, 0L );
167 else
169 // Rahmen existiert bereits, nur Spaltenanzahl wird geaendert
170 USHORT nCols = 1;
171 if(pArgs->GetItemState(SID_ATTR_COLUMNS, FALSE, &pItem) == SFX_ITEM_SET)
172 nCols = ((SfxUInt16Item *)pItem)->GetValue();
174 SfxItemSet aSet(GetPool(),RES_COL,RES_COL);
175 rSh.GetFlyFrmAttr( aSet );
176 SwFmtCol aCol((const SwFmtCol&)aSet.Get(RES_COL));
177 // GutterWidth wird nicht immer uebergeben, daher erst besorgen (siehe view2: Execute auf diesen Slot)
178 USHORT nGutterWidth = aCol.GetGutterWidth();
179 if(!nCols )
180 nCols++;
181 aCol.Init(nCols, nGutterWidth, aCol.GetWishWidth());
182 aSet.Put(aCol);
183 // Vorlagen-AutoUpdate
184 SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
185 if(pFmt && pFmt->IsAutoUpdateFmt())
187 rSh.AutoUpdateFrame(pFmt, aSet);
189 else
191 rSh.StartAllAction();
192 rSh.SetFlyFrmAttr( aSet );
193 rSh.SetModified();
194 rSh.EndAllAction();
198 return;
200 case SID_HYPERLINK_SETLINK:
202 if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_HYPERLINK_SETLINK, FALSE, &pItem))
204 const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
205 const String& rURL = rHLinkItem.GetURL();
206 const String& rTarget = rHLinkItem.GetTargetFrame();
208 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
209 rSh.GetFlyFrmAttr( aSet );
210 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
212 String sOldName(rHLinkItem.GetName());
213 String sFlyName(rSh.GetFlyName());
214 if (sOldName.ToUpperAscii() != sFlyName.ToUpperAscii())
216 String sName(sOldName);
217 USHORT i = 1;
218 while (rSh.FindFlyByName(sName))
220 sName = sOldName;
221 sName += '_';
222 sName += String::CreateFromInt32(i++);
224 rSh.SetFlyName(sName);
226 aURL.SetURL( rURL, FALSE );
227 aURL.SetTargetFrameName(rTarget);
229 aSet.Put( aURL );
230 rSh.SetFlyFrmAttr( aSet );
233 break;
235 case FN_FRAME_CHAIN:
236 rSh.GetView().GetEditWin().SetChainMode( !rSh.GetView().GetEditWin().IsChainMode() );
237 break;
239 case FN_FRAME_UNCHAIN:
240 rSh.Unchain( (SwFrmFmt&)*rSh.GetFlyFrmFmt() );
241 GetView().GetViewFrame()->GetBindings().Invalidate(FN_FRAME_CHAIN);
242 break;
243 case FN_FORMAT_FOOTNOTE_DLG:
245 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
246 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
248 VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( GetView().GetWindow(), GetView().GetWrtShell(), DLG_DOC_FOOTNOTE );
249 DBG_ASSERT(pDlg, "Dialogdiet fail!");
250 pDlg->Execute();
251 delete pDlg;
252 break;
254 case FN_NUMBERING_OUTLINE_DLG:
256 SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
257 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
258 DBG_ASSERT(pFact, "Dialogdiet fail!");
259 SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
260 GetView().GetWindow(), &aTmp, GetView().GetWrtShell());
261 DBG_ASSERT(pDlg, "Dialogdiet fail!");
262 pDlg->Execute();
263 delete pDlg;
264 rReq.Done();
265 break;
267 case SID_OPEN_XML_FILTERSETTINGS:
271 uno::Reference < ui::dialogs::XExecutableDialog > xDialog(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.comp.ui.XSLTFilterDialog")), uno::UNO_QUERY);
272 if( xDialog.is() )
274 xDialog->execute();
277 catch( uno::Exception& )
280 rReq.Ignore ();
282 break;
283 case FN_WORDCOUNT_DIALOG:
285 SwDocStat aCurr;
286 SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
288 SwWait aWait( *GetView().GetDocShell(), TRUE );
289 rSh.StartAction();
290 rSh.CountWords( aCurr );
291 rSh.UpdateDocStat( aDocStat );
292 rSh.EndAction();
295 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
296 DBG_ASSERT(pFact, "Dialogdiet fail!");
297 AbstractSwWordCountDialog* pDialog = pFact->CreateSwWordCountDialog( GetView().GetWindow() );
298 pDialog->SetValues(aCurr, aDocStat );
299 pDialog->Execute();
300 delete pDialog;
302 break;
303 default: bMore = TRUE;
306 if ( !bMore )
308 return;
311 SwFlyFrmAttrMgr aMgr( FALSE, &rSh, FRMMGR_TYPE_NONE );
312 BOOL bUpdateMgr = TRUE;
313 BOOL bCopyToFmt = FALSE;
314 switch ( nSlot )
316 case SID_OBJECT_ALIGN_MIDDLE:
317 case FN_FRAME_ALIGN_VERT_CENTER:
318 aMgr.SetVertOrientation( text::VertOrientation::CENTER );
319 break;
320 case SID_OBJECT_ALIGN_DOWN :
321 case FN_FRAME_ALIGN_VERT_BOTTOM:
322 aMgr.SetVertOrientation( text::VertOrientation::BOTTOM );
323 break;
324 case SID_OBJECT_ALIGN_UP :
325 case FN_FRAME_ALIGN_VERT_TOP:
326 aMgr.SetVertOrientation( text::VertOrientation::TOP );
327 break;
329 case FN_FRAME_ALIGN_VERT_CHAR_CENTER:
330 aMgr.SetVertOrientation( text::VertOrientation::CHAR_CENTER );
331 break;
333 case FN_FRAME_ALIGN_VERT_CHAR_BOTTOM:
334 aMgr.SetVertOrientation( text::VertOrientation::CHAR_BOTTOM );
335 break;
337 case FN_FRAME_ALIGN_VERT_CHAR_TOP:
338 aMgr.SetVertOrientation( text::VertOrientation::CHAR_TOP );
339 break;
341 case FN_FRAME_ALIGN_VERT_ROW_CENTER:
342 aMgr.SetVertOrientation( text::VertOrientation::LINE_CENTER );
343 break;
345 case FN_FRAME_ALIGN_VERT_ROW_BOTTOM:
346 aMgr.SetVertOrientation( text::VertOrientation::LINE_BOTTOM );
347 break;
349 case FN_FRAME_ALIGN_VERT_ROW_TOP:
350 aMgr.SetVertOrientation( text::VertOrientation::LINE_TOP );
351 break;
352 case SID_OBJECT_ALIGN_CENTER :
353 case FN_FRAME_ALIGN_HORZ_CENTER:
354 aMgr.SetHorzOrientation( text::HoriOrientation::CENTER );
355 break;
356 case SID_OBJECT_ALIGN_RIGHT:
357 case FN_FRAME_ALIGN_HORZ_RIGHT:
358 aMgr.SetHorzOrientation( text::HoriOrientation::RIGHT );
359 break;
360 case SID_OBJECT_ALIGN_LEFT:
361 case FN_FRAME_ALIGN_HORZ_LEFT:
362 aMgr.SetHorzOrientation( text::HoriOrientation::LEFT );
363 break;
365 case FN_SET_FRM_POSITION:
367 aMgr.SetAbsPos(((SfxPointItem &)pArgs->Get
368 (FN_SET_FRM_POSITION)).GetValue());
370 break;
371 case SID_ATTR_BRUSH:
373 if(pArgs)
375 aMgr.SetAttrSet( *pArgs );
376 bCopyToFmt = TRUE;
379 break;
380 case SID_ATTR_ULSPACE:
381 case SID_ATTR_LRSPACE:
383 if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(GetPool().GetWhich(nSlot), FALSE, &pItem))
385 aMgr.SetAttrSet( *pArgs );
386 if(SID_ATTR_ULSPACE == nSlot && SID_ATTR_ULSPACE == nSlot)
387 bCopyToFmt = TRUE;
390 break;
391 case FN_FORMAT_FRAME_DLG:
393 const int nSel = rSh.GetSelectionType();
394 if (nSel & nsSelectionType::SEL_GRF)
396 rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(FN_FORMAT_GRAFIC_DLG);
397 bUpdateMgr = FALSE;
399 else
401 SfxItemSet aSet(GetPool(), RES_FRMATR_BEGIN, RES_FRMATR_END-1,
402 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
403 FN_GET_PRINT_AREA, FN_GET_PRINT_AREA,
404 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
405 SID_ATTR_BRUSH, SID_ATTR_BRUSH,
406 SID_ATTR_LRSPACE, SID_ATTR_ULSPACE,
407 FN_SURROUND, FN_HORI_ORIENT,
408 FN_SET_FRM_NAME, FN_SET_FRM_NAME,
409 FN_KEEP_ASPECT_RATIO, FN_KEEP_ASPECT_RATIO,
410 SID_DOCFRAME, SID_DOCFRAME,
411 SID_HTML_MODE, SID_HTML_MODE,
412 FN_SET_FRM_ALT_NAME, FN_SET_FRM_ALT_NAME,
413 FN_PARAM_CHAIN_PREVIOUS, FN_PARAM_CHAIN_NEXT,
416 const SwViewOption* pVOpt = rSh.GetViewOptions();
417 if(nSel & nsSelectionType::SEL_OLE)
419 aSet.Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO,
420 pVOpt->IsKeepRatio()));
422 aSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(GetView().GetDocShell())));
423 aSet.Put(SfxStringItem(FN_SET_FRM_NAME, rSh.GetFlyName()));
424 if( nSel & nsSelectionType::SEL_OLE )
426 // --> OD 2009-07-13 #i73249#
427 // aSet.Put(SfxStringItem(FN_SET_FRM_ALT_NAME, rSh.GetAlternateText()));
428 aSet.Put( SfxStringItem( FN_SET_FRM_ALT_NAME, rSh.GetObjTitle() ) );
429 // <--
432 const SwRect &rPg = rSh.GetAnyCurRect(RECT_PAGE);
433 SwFmtFrmSize aFrmSize(ATT_VAR_SIZE, rPg.Width(), rPg.Height());
434 aFrmSize.SetWhich(GetPool().GetWhich(SID_ATTR_PAGE_SIZE));
435 aSet.Put(aFrmSize);
437 const SwRect &rPr = rSh.GetAnyCurRect(RECT_PAGE_PRT);
438 SwFmtFrmSize aPrtSize(ATT_VAR_SIZE, rPr.Width(), rPr.Height());
439 aPrtSize.SetWhich(GetPool().GetWhich(FN_GET_PRINT_AREA));
440 aSet.Put(aPrtSize);
442 aSet.Put(aMgr.GetAttrSet());
443 aSet.SetParent( aMgr.GetAttrSet().GetParent() );
445 // Bei %-Werten Groesse initialisieren
446 SwFmtFrmSize& rSize = (SwFmtFrmSize&)aSet.Get(RES_FRM_SIZE);
447 if (rSize.GetWidthPercent() && rSize.GetWidthPercent() != 0xff)
448 rSize.SetWidth(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Width());
449 if (rSize.GetHeightPercent() && rSize.GetHeightPercent() != 0xff)
450 rSize.SetHeight(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Height());
452 UINT16 nDefPage = 0;
453 if(pArgs && pArgs->GetItemState(FN_FORMAT_FRAME_DLG, FALSE, &pItem) == SFX_ITEM_SET)
454 nDefPage = ((SfxUInt16Item *)pItem)->GetValue();
456 aSet.Put(SfxFrameItem( SID_DOCFRAME, GetView().GetViewFrame()->GetTopFrame()));
457 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &GetView()));
458 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< UINT16 >(eMetric) ));
459 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
460 DBG_ASSERT(pFact, "Dialogdiet fail!");
461 SfxAbstractTabDialog* pDlg = pFact->CreateFrmTabDialog( DLG_FRM_STD,
462 GetView().GetViewFrame(),
463 GetView().GetWindow(),
464 aSet, FALSE,
465 nSel & nsSelectionType::SEL_GRF ? DLG_FRM_GRF :
466 nSel & nsSelectionType::SEL_OLE ? DLG_FRM_OLE :
467 DLG_FRM_STD,
468 FALSE,
469 nDefPage);
470 DBG_ASSERT(pDlg, "Dialogdiet fail!");
472 if ( pDlg->Execute() )
474 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
475 if(pOutSet)
477 rReq.Done(*pOutSet);
478 if(nSel & nsSelectionType::SEL_OLE &&
479 SFX_ITEM_SET == pOutSet->GetItemState(FN_KEEP_ASPECT_RATIO, TRUE, &pItem))
481 SwViewOption aUsrPref( *pVOpt );
482 aUsrPref.SetKeepRatio(((const SfxBoolItem*)pItem)->GetValue());
483 SW_MOD()->ApplyUsrPref(aUsrPref, &GetView());
485 if (SFX_ITEM_SET == pOutSet->GetItemState(FN_SET_FRM_ALT_NAME, TRUE, &pItem))
487 // --> OD 2009-07-13 #i73249#
488 // rSh.SetAlternateText(((const SfxStringItem*)pItem)->GetValue());
489 rSh.SetObjTitle(((const SfxStringItem*)pItem)->GetValue());
490 // <--
492 // Vorlagen-AutoUpdate
493 SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
494 if(pFmt && pFmt->IsAutoUpdateFmt())
496 rSh.AutoUpdateFrame(pFmt, *pOutSet);
497 // alles, dass das Format nicht kann, muss hart
498 // gesetzt werden
499 if(SFX_ITEM_SET == pOutSet->GetItemState(FN_SET_FRM_NAME, FALSE, &pItem))
500 rSh.SetFlyName(((SfxStringItem*)pItem)->GetValue());
501 SfxItemSet aShellSet(GetPool(), RES_FRM_SIZE, RES_FRM_SIZE,
502 RES_SURROUND, RES_SURROUND,
503 RES_ANCHOR, RES_ANCHOR,
504 RES_VERT_ORIENT,RES_HORI_ORIENT,
506 aShellSet.Put(*pOutSet);
507 aMgr.SetAttrSet(aShellSet);
508 if(SFX_ITEM_SET == pOutSet->GetItemState(FN_SET_FRM_NAME, FALSE, &pItem))
509 rSh.SetFlyName(((SfxStringItem*)pItem)->GetValue());
511 else
512 aMgr.SetAttrSet( *pOutSet );
514 const SwFrmFmt* pCurrFlyFmt = rSh.GetFlyFrmFmt();
515 if(SFX_ITEM_SET ==
516 pOutSet->GetItemState(FN_PARAM_CHAIN_PREVIOUS,
517 FALSE, &pItem))
519 rSh.HideChainMarker();
521 String sPrevName =
522 ((const SfxStringItem*)pItem)->GetValue();
523 const SwFmtChain &rChain = pCurrFlyFmt->GetChain();
524 //needs cast - no non-const method available
525 SwFlyFrmFmt* pFlyFmt =
526 (SwFlyFrmFmt*)rChain.GetPrev();
527 if(pFlyFmt)
529 if (pFlyFmt->GetName() != sPrevName)
531 rSh.Unchain(*pFlyFmt);
533 else
534 sPrevName.Erase();
537 if(sPrevName.Len())
539 //needs cast - no non-const method available
540 SwFrmFmt* pPrevFmt = (SwFrmFmt*)
541 lcl_GetFrmFmtByName(rSh, sPrevName);
542 DBG_ASSERT(pPrevFmt, "No frame found!");
543 if(pPrevFmt)
545 rSh.Chain(*pPrevFmt, *pCurrFlyFmt);
548 rSh.SetChainMarker();
550 if(SFX_ITEM_SET ==
551 pOutSet->GetItemState(FN_PARAM_CHAIN_NEXT, FALSE,
552 &pItem))
554 rSh.HideChainMarker();
555 String sNextName =
556 ((const SfxStringItem*)pItem)->GetValue();
557 const SwFmtChain &rChain = pCurrFlyFmt->GetChain();
558 //needs cast - no non-const method available
559 SwFlyFrmFmt* pFlyFmt =
560 (SwFlyFrmFmt*)rChain.GetNext();
561 if(pFlyFmt)
563 if (pFlyFmt->GetName() != sNextName)
565 rSh.Unchain(*((SwFlyFrmFmt*) pCurrFlyFmt));
567 else
568 sNextName.Erase();
571 if(sNextName.Len())
573 //needs cast - no non-const method available
574 SwFrmFmt* pNextFmt = (SwFrmFmt*)
575 lcl_GetFrmFmtByName(rSh, sNextName);
576 DBG_ASSERT(pNextFmt, "No frame found!");
577 if(pNextFmt)
579 rSh.Chain(*(SwFrmFmt*)
580 pCurrFlyFmt, *pNextFmt);
583 rSh.SetChainMarker();
587 else
588 bUpdateMgr = FALSE;
589 delete pDlg;
592 break;
593 case FN_INPLACE_OLE:
595 rSh.LaunchOLEObj();
597 break;
598 case FN_OUTPLACE_OLE:
600 rSh.LaunchOLEObj(embed::EmbedVerbs::MS_OLEVERB_OPEN);
602 break;
603 case FN_FRAME_MIRROR_ON_EVEN_PAGES:
605 SwFmtHoriOrient aHori(aMgr.GetHoriOrient());
606 BOOL bMirror = !aHori.IsPosToggle();
607 aHori.SetPosToggle(bMirror);
608 SfxItemSet aSet(GetPool(), RES_HORI_ORIENT, RES_HORI_ORIENT);
609 aSet.Put(aHori);
610 aMgr.SetAttrSet(aSet);
611 bCopyToFmt = TRUE;
612 rReq.SetReturnValue(SfxBoolItem(nSlot, bMirror));
614 break;
615 // --> OD 2009-07-14 #i73249#
616 case FN_TITLE_DESCRIPTION_SHAPE:
618 bUpdateMgr = FALSE;
619 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
620 if ( pSdrView &&
621 pSdrView->GetMarkedObjectCount() == 1 )
623 String aDescription(rSh.GetObjDescription());
624 String aTitle(rSh.GetObjTitle());
626 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
627 OSL_ENSURE(pFact, "Dialogdiet fail!");
628 AbstractSvxObjectTitleDescDialog* pDlg =
629 pFact->CreateSvxObjectTitleDescDialog( NULL,
630 aTitle,
631 aDescription,
632 RID_SVXDLG_OBJECT_TITLE_DESC );
633 OSL_ENSURE(pDlg, "Dialogdiet fail!");
635 if ( pDlg->Execute() == RET_OK )
637 pDlg->GetDescription(aDescription);
638 pDlg->GetTitle(aTitle);
640 rSh.SetObjDescription(aDescription);
641 rSh.SetObjTitle(aTitle);
644 delete pDlg;
647 break;
648 // <--
649 default:
650 ASSERT( !this, "falscher Dispatcher" );
651 return;
653 // Vorlagen-AutoUpdate
654 SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
655 if ( bUpdateMgr )
657 if(bCopyToFmt && pFmt && pFmt->IsAutoUpdateFmt())
659 rSh.AutoUpdateFrame(pFmt, aMgr.GetAttrSet());
661 else
662 aMgr.UpdateFlyFrm();
667 /*--------------------------------------------------------------------
668 Beschreibung:
669 --------------------------------------------------------------------*/
672 void SwFrameShell::GetState(SfxItemSet& rSet)
674 SwWrtShell &rSh = GetShell();
675 BOOL bHtmlMode = 0 != ::GetHtmlMode(rSh.GetView().GetDocShell());
676 if (rSh.IsFrmSelected())
678 SfxItemSet aSet( rSh.GetAttrPool(),
679 RES_LR_SPACE, RES_UL_SPACE,
680 RES_PROTECT, RES_HORI_ORIENT,
681 RES_OPAQUE, RES_OPAQUE,
682 RES_PRINT, RES_OPAQUE,
683 0 );
684 rSh.GetFlyFrmAttr( aSet );
686 BOOL bProtect = rSh.IsSelObjProtected(FLYPROTECT_POS);
687 BOOL bParentCntProt = rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
689 bProtect |= bParentCntProt;
691 const USHORT eFrmType = rSh.GetFrmType(0,TRUE);
692 SwFlyFrmAttrMgr aMgr( FALSE, &rSh, FRMMGR_TYPE_NONE );
694 SfxWhichIter aIter( rSet );
695 USHORT nWhich = aIter.FirstWhich();
696 while ( nWhich )
698 switch ( nWhich )
700 case RES_FRM_SIZE:
702 SwFmtFrmSize aSz(aMgr.GetFrmSize());
703 rSet.Put(aSz);
705 break;
706 case RES_VERT_ORIENT:
707 case RES_HORI_ORIENT:
708 case SID_ATTR_ULSPACE:
709 case SID_ATTR_LRSPACE:
710 case RES_LR_SPACE:
711 case RES_UL_SPACE:
712 case RES_PROTECT:
713 case RES_OPAQUE:
714 case RES_PRINT:
715 case RES_SURROUND:
717 rSet.Put(aSet.Get(GetPool().GetWhich(nWhich), TRUE ));
719 break;
720 case SID_OBJECT_ALIGN_LEFT :
721 case SID_OBJECT_ALIGN_CENTER :
722 case SID_OBJECT_ALIGN_RIGHT :
723 case FN_FRAME_ALIGN_HORZ_CENTER:
724 case FN_FRAME_ALIGN_HORZ_RIGHT:
725 case FN_FRAME_ALIGN_HORZ_LEFT:
726 if ( (eFrmType & FRMTYPE_FLY_INCNT) ||
727 bProtect ||
728 (nWhich == FN_FRAME_ALIGN_HORZ_CENTER || nWhich == SID_OBJECT_ALIGN_CENTER)&& bHtmlMode )
729 rSet.DisableItem( nWhich );
730 break;
731 case FN_FRAME_ALIGN_VERT_ROW_TOP:
732 case FN_FRAME_ALIGN_VERT_ROW_CENTER:
733 case FN_FRAME_ALIGN_VERT_ROW_BOTTOM:
734 case FN_FRAME_ALIGN_VERT_CHAR_TOP:
735 case FN_FRAME_ALIGN_VERT_CHAR_CENTER:
736 case FN_FRAME_ALIGN_VERT_CHAR_BOTTOM:
737 if ( !(eFrmType & FRMTYPE_FLY_INCNT) || bProtect
738 || bHtmlMode && FN_FRAME_ALIGN_VERT_CHAR_BOTTOM == nWhich )
739 rSet.DisableItem( nWhich );
740 break;
742 case SID_OBJECT_ALIGN_UP :
743 case SID_OBJECT_ALIGN_MIDDLE :
744 case SID_OBJECT_ALIGN_DOWN :
746 case FN_FRAME_ALIGN_VERT_TOP:
747 case FN_FRAME_ALIGN_VERT_CENTER:
748 case FN_FRAME_ALIGN_VERT_BOTTOM:
749 if ( bProtect || bHtmlMode && eFrmType & FRMTYPE_FLY_ATCNT)
750 rSet.DisableItem( nWhich );
751 else
753 USHORT nId = 0;
754 if (eFrmType & FRMTYPE_FLY_INCNT)
756 switch (nWhich)
758 case SID_OBJECT_ALIGN_UP :
759 case FN_FRAME_ALIGN_VERT_TOP:
760 nId = STR_TOP_BASE; break;
761 case SID_OBJECT_ALIGN_MIDDLE :
762 case FN_FRAME_ALIGN_VERT_CENTER:
763 nId = STR_CENTER_BASE; break;
764 case SID_OBJECT_ALIGN_DOWN :
765 case FN_FRAME_ALIGN_VERT_BOTTOM:
766 if(!bHtmlMode)
767 nId = STR_BOTTOM_BASE;
768 else
769 rSet.DisableItem( nWhich );
770 break;
773 else
775 if (nWhich != FN_FRAME_ALIGN_VERT_TOP &&
776 nWhich != SID_OBJECT_ALIGN_UP )
778 if (aMgr.GetAnchor() == FLY_AT_FLY)
780 const SwFrmFmt* pFmt = rSh.IsFlyInFly();
781 if (pFmt)
783 const SwFmtFrmSize& rFrmSz = pFmt->GetFrmSize();
784 if (rFrmSz.GetHeightSizeType() != ATT_FIX_SIZE)
786 rSet.DisableItem( nWhich );
787 break;
792 switch (nWhich)
794 case SID_OBJECT_ALIGN_UP :
795 case FN_FRAME_ALIGN_VERT_TOP:
796 nId = STR_TOP; break;
797 case SID_OBJECT_ALIGN_MIDDLE:
798 case FN_FRAME_ALIGN_VERT_CENTER:
799 nId = STR_CENTER_VERT; break;
800 case SID_OBJECT_ALIGN_DOWN:
801 case FN_FRAME_ALIGN_VERT_BOTTOM:
802 nId = STR_BOTTOM; break;
805 if ( nId )
806 rSet.Put( SfxStringItem( nWhich, SW_RES(nId) ));
808 break;
809 case SID_HYPERLINK_GETLINK:
811 String sURL;
812 SvxHyperlinkItem aHLinkItem;
813 const SfxPoolItem* pItem;
815 SfxItemSet aURLSet(GetPool(), RES_URL, RES_URL);
816 rSh.GetFlyFrmAttr( aURLSet );
818 if(SFX_ITEM_SET == aURLSet.GetItemState(RES_URL, TRUE, &pItem))
820 const SwFmtURL* pFmtURL = (const SwFmtURL*)pItem;
821 aHLinkItem.SetURL(pFmtURL->GetURL());
822 aHLinkItem.SetTargetFrame(pFmtURL->GetTargetFrameName());
823 aHLinkItem.SetName(rSh.GetFlyName());
826 aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
827 (bHtmlMode ? HLINK_HTMLMODE : 0)));
829 rSet.Put(aHLinkItem);
831 break;
833 case FN_FRAME_CHAIN:
835 const int nSel = rSh.GetSelectionType();
836 if (nSel & nsSelectionType::SEL_GRF || nSel & nsSelectionType::SEL_OLE)
837 rSet.DisableItem( FN_FRAME_CHAIN );
838 else
840 const SwFrmFmt *pFmt = rSh.GetFlyFrmFmt();
841 if ( bParentCntProt || rSh.GetView().GetEditWin().GetApplyTemplate() ||
842 !pFmt || pFmt->GetChain().GetNext() )
844 rSet.DisableItem( FN_FRAME_CHAIN );
846 else
848 BOOL bChainMode = rSh.GetView().GetEditWin().IsChainMode();
849 rSet.Put( SfxBoolItem( FN_FRAME_CHAIN, bChainMode ) );
853 break;
854 case FN_FRAME_UNCHAIN:
856 const int nSel = rSh.GetSelectionType();
857 if (nSel & nsSelectionType::SEL_GRF || nSel & nsSelectionType::SEL_OLE)
858 rSet.DisableItem( FN_FRAME_UNCHAIN );
859 else
861 const SwFrmFmt *pFmt = rSh.GetFlyFrmFmt();
862 if ( bParentCntProt || rSh.GetView().GetEditWin().GetApplyTemplate() ||
863 !pFmt || !pFmt->GetChain().GetNext() )
865 rSet.DisableItem( FN_FRAME_UNCHAIN );
869 break;
870 case SID_FRAME_TO_TOP:
871 case SID_FRAME_TO_BOTTOM:
872 case FN_FRAME_UP:
873 case FN_FRAME_DOWN:
874 if ( bParentCntProt )
875 rSet.DisableItem( nWhich );
876 break;
877 case FN_FORMAT_FRAME_DLG:
879 const int nSel = rSh.GetSelectionType();
880 if ( bParentCntProt || nSel & nsSelectionType::SEL_GRF)
881 rSet.DisableItem( nWhich );
883 break;
884 // --> OD 2009-07-07 #i73249#
885 case FN_TITLE_DESCRIPTION_SHAPE:
887 SwWrtShell &rWrtSh = GetShell();
888 SdrView* pSdrView = rWrtSh.GetDrawViewWithValidMarkList();
889 if ( !pSdrView ||
890 pSdrView->GetMarkedObjectCount() != 1 )
892 rSet.DisableItem( nWhich );
896 break;
897 // <--
898 default:
899 /* do nothing */;
900 break;
902 nWhich = aIter.NextWhich();
907 /*--------------------------------------------------------------------
908 Beschreibung: Ctor fuer FrameShell
909 --------------------------------------------------------------------*/
912 SwFrameShell::SwFrameShell(SwView &_rView) :
913 SwBaseShell( _rView )
915 SetName(String::CreateFromAscii("Frame"));
916 SetHelpId(SW_FRAMESHELL);
918 /* #96392# Use this to announce it is the frame shell who creates the
919 selection. */
920 SwTransferable::CreateSelection( _rView.GetWrtShell(), (ViewShell *) this );
923 SwFrameShell::~SwFrameShell()
925 /* #96392# Only clear the selection if it was this frame shell who created
926 it. */
927 SwTransferable::ClearSelection( GetShell(), (ViewShell *) this );
930 /*--------------------------------------------------------------------
931 Beschreibung:
932 --------------------------------------------------------------------*/
936 void SwFrameShell::ExecFrameStyle(SfxRequest& rReq)
938 SwWrtShell &rSh = GetShell();
939 BOOL bDefault = FALSE;
940 if (!rSh.IsFrmSelected())
941 return;
943 // Erst Default-BoxItem aus Pool holen. Wenn ungleich normalem Boxitem,
944 // dann ist es bereits geaendert worden (neues ist kein Default).
945 const SvxBoxItem* pPoolBoxItem = (const SvxBoxItem*)::GetDfltAttr(RES_BOX);
947 const SfxItemSet *pArgs = rReq.GetArgs();
948 SfxItemSet aFrameSet(rSh.GetAttrPool(), RES_BOX, RES_BOX);
950 rSh.GetFlyFrmAttr( aFrameSet );
951 const SvxBoxItem& rBoxItem = (const SvxBoxItem&)aFrameSet.Get(RES_BOX);
953 if (pPoolBoxItem == &rBoxItem)
954 bDefault = TRUE;
956 SvxBoxItem aBoxItem(rBoxItem);
958 SvxBorderLine aBorderLine;
959 const SfxPoolItem *pItem = 0;
961 if(pArgs) //irgendein Controller kann auch mal nichts liefern #48169#
963 switch (rReq.GetSlot())
965 case SID_ATTR_BORDER:
967 if (pArgs->GetItemState(RES_BOX, TRUE, &pItem) == SFX_ITEM_SET)
969 SvxBoxItem aNewBox(*((SvxBoxItem *)pItem));
970 const SvxBorderLine* pBorderLine;
972 if ((pBorderLine = aBoxItem.GetTop()) != NULL)
973 lcl_FrmGetMaxLineWidth(pBorderLine, aBorderLine);
974 if ((pBorderLine = aBoxItem.GetBottom()) != NULL)
975 lcl_FrmGetMaxLineWidth(pBorderLine, aBorderLine);
976 if ((pBorderLine = aBoxItem.GetLeft()) != NULL)
977 lcl_FrmGetMaxLineWidth(pBorderLine, aBorderLine);
978 if ((pBorderLine = aBoxItem.GetRight()) != NULL)
979 lcl_FrmGetMaxLineWidth(pBorderLine, aBorderLine);
981 if(aBorderLine.GetOutWidth() == 0)
983 aBorderLine.SetInWidth(0);
984 aBorderLine.SetOutWidth(DEF_LINE_WIDTH_0);
985 aBorderLine.SetDistance(0);
987 //Distance nur setzen, wenn der Request vom Controller kommt
989 if(!StarBASIC::IsRunning())
991 aNewBox.SetDistance( rBoxItem.GetDistance() );
994 aBoxItem = aNewBox;
995 SvxBorderLine aDestBorderLine;
997 if ((pBorderLine = aBoxItem.GetTop()) != NULL)
998 aBoxItem.SetLine(&aBorderLine, BOX_LINE_TOP);
999 if ((pBorderLine = aBoxItem.GetBottom()) != NULL)
1000 aBoxItem.SetLine(&aBorderLine, BOX_LINE_BOTTOM);
1001 if ((pBorderLine = aBoxItem.GetLeft()) != NULL)
1002 aBoxItem.SetLine(&aBorderLine, BOX_LINE_LEFT);
1003 if ((pBorderLine = aBoxItem.GetRight()) != NULL)
1004 aBoxItem.SetLine(&aBorderLine, BOX_LINE_RIGHT);
1007 break;
1009 case SID_FRAME_LINESTYLE:
1011 if (pArgs->GetItemState(SID_FRAME_LINESTYLE, FALSE, &pItem) == SFX_ITEM_SET)
1013 const SvxLineItem* pLineItem =
1014 (const SvxLineItem*)pItem;
1016 if ( pLineItem->GetLine() )
1018 aBorderLine = *(pLineItem->GetLine());
1020 if (!aBoxItem.GetTop() && !aBoxItem.GetBottom() &&
1021 !aBoxItem.GetLeft() && !aBoxItem.GetRight())
1023 aBoxItem.SetLine(&aBorderLine, BOX_LINE_TOP);
1024 aBoxItem.SetLine(&aBorderLine, BOX_LINE_BOTTOM);
1025 aBoxItem.SetLine(&aBorderLine, BOX_LINE_LEFT);
1026 aBoxItem.SetLine(&aBorderLine, BOX_LINE_RIGHT);
1028 else
1030 if( aBoxItem.GetTop() )
1032 aBorderLine.SetColor( aBoxItem.GetTop()->GetColor() );
1033 aBoxItem.SetLine(&aBorderLine, BOX_LINE_TOP);
1035 if( aBoxItem.GetBottom() )
1037 aBorderLine.SetColor( aBoxItem.GetBottom()->GetColor());
1038 aBoxItem.SetLine(&aBorderLine, BOX_LINE_BOTTOM);
1040 if( aBoxItem.GetLeft() )
1042 aBorderLine.SetColor( aBoxItem.GetLeft()->GetColor());
1043 aBoxItem.SetLine(&aBorderLine, BOX_LINE_LEFT);
1045 if( aBoxItem.GetRight() )
1047 aBorderLine.SetColor(aBoxItem.GetRight()->GetColor());
1048 aBoxItem.SetLine(&aBorderLine, BOX_LINE_RIGHT);
1052 else
1054 aBoxItem.SetLine(0, BOX_LINE_TOP);
1055 aBoxItem.SetLine(0, BOX_LINE_BOTTOM);
1056 aBoxItem.SetLine(0, BOX_LINE_LEFT);
1057 aBoxItem.SetLine(0, BOX_LINE_RIGHT);
1061 break;
1063 case SID_FRAME_LINECOLOR:
1065 if (pArgs->GetItemState(SID_FRAME_LINECOLOR, FALSE, &pItem) == SFX_ITEM_SET)
1067 const Color& rNewColor = ((const SvxColorItem*)pItem)->GetValue();
1069 if (!aBoxItem.GetTop() && !aBoxItem.GetBottom() &&
1070 !aBoxItem.GetLeft() && !aBoxItem.GetRight())
1072 aBorderLine.SetColor( rNewColor );
1073 aBoxItem.SetLine(&aBorderLine, BOX_LINE_TOP);
1074 aBoxItem.SetLine(&aBorderLine, BOX_LINE_BOTTOM);
1075 aBoxItem.SetLine(&aBorderLine, BOX_LINE_LEFT);
1076 aBoxItem.SetLine(&aBorderLine, BOX_LINE_RIGHT);
1078 else
1080 if ( aBoxItem.GetTop() )
1081 ((SvxBorderLine*)aBoxItem.GetTop())->SetColor( rNewColor );
1082 if ( aBoxItem.GetBottom() )
1083 ((SvxBorderLine*)aBoxItem.GetBottom())->SetColor( rNewColor );
1084 if ( aBoxItem.GetLeft() )
1085 ((SvxBorderLine*)aBoxItem.GetLeft())->SetColor( rNewColor );
1086 if ( aBoxItem.GetRight() )
1087 ((SvxBorderLine*)aBoxItem.GetRight())->SetColor( rNewColor );
1091 break;
1094 if (bDefault && (aBoxItem.GetTop() || aBoxItem.GetBottom() ||
1095 aBoxItem.GetLeft() || aBoxItem.GetRight()))
1097 aBoxItem.SetDistance(MIN_BORDER_DIST);
1099 aFrameSet.Put( aBoxItem );
1100 // Vorlagen-AutoUpdate
1101 SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
1102 if(pFmt && pFmt->IsAutoUpdateFmt())
1104 rSh.AutoUpdateFrame(pFmt, aFrameSet);
1106 else
1107 rSh.SetFlyFrmAttr( aFrameSet );
1113 void lcl_FrmGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine)
1115 if(pBorderLine->GetInWidth() > rBorderLine.GetInWidth())
1116 rBorderLine.SetInWidth(pBorderLine->GetInWidth());
1118 if(pBorderLine->GetOutWidth() > rBorderLine.GetOutWidth())
1119 rBorderLine.SetOutWidth(pBorderLine->GetOutWidth());
1121 if(pBorderLine->GetDistance() > rBorderLine.GetDistance())
1122 rBorderLine.SetDistance(pBorderLine->GetDistance());
1124 rBorderLine.SetColor(pBorderLine->GetColor());
1129 void SwFrameShell::GetLineStyleState(SfxItemSet &rSet)
1131 SwWrtShell &rSh = GetShell();
1132 BOOL bParentCntProt = rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
1134 if (bParentCntProt)
1136 if (rSh.IsFrmSelected())
1137 rSet.DisableItem( SID_FRAME_LINECOLOR );
1139 rSet.DisableItem( SID_ATTR_BORDER );
1140 rSet.DisableItem( SID_FRAME_LINESTYLE );
1142 else
1144 if (rSh.IsFrmSelected())
1146 SfxItemSet aFrameSet( rSh.GetAttrPool(), RES_BOX, RES_BOX );
1148 rSh.GetFlyFrmAttr(aFrameSet);
1150 const SvxBorderLine* pLine = ((const SvxBoxItem&)aFrameSet.Get(RES_BOX)).GetTop();
1151 rSet.Put(SvxColorItem(pLine ? pLine->GetColor() : Color(), SID_FRAME_LINECOLOR));
1156 void SwFrameShell::StateInsert(SfxItemSet &rSet)
1158 const int nSel = GetShell().GetSelectionType();
1160 if ((nSel & nsSelectionType::SEL_GRF) || (nSel & nsSelectionType::SEL_OLE))
1161 rSet.DisableItem(FN_INSERT_FRAME);