xref: /aoo41x/main/sw/source/ui/shells/frmsh.cxx (revision 8ef2f12b)
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 <hintids.hxx>
29 #include <svl/whiter.hxx>
30 #include <svtools/imapobj.hxx>
31 #include <svl/srchitem.hxx>
32 #include <svtools/imap.hxx>
33 #include <sfx2/viewfrm.hxx>
34 #include <basic/sbstar.hxx>
35 #include <svl/rectitem.hxx>
36 #include <svl/ptitem.hxx>
37 #include <svl/stritem.hxx>
38 #include <svl/intitem.hxx>
39 #include <svl/eitem.hxx>
40 #include <editeng/colritem.hxx>
41 #include <editeng/bolnitem.hxx>
42 #include <editeng/boxitem.hxx>
43 #include <editeng/protitem.hxx>
44 #include <sfx2/dispatch.hxx>
45 #include <sfx2/request.hxx>
46 #include <sfx2/objface.hxx>
47 #include <sfx2/sidebar/EnumContext.hxx>
48 #include <svx/hlnkitem.hxx>
49 // --> OD 2009-07-07 #i73249#
50 #include <svx/svdview.hxx>
51 #include <vcl/msgbox.hxx>
52 // <--
53 
54 #include <doc.hxx>
55 #include <fmturl.hxx>
56 #include <fmtclds.hxx>
57 #include <fmtcnct.hxx>
58 #include <swmodule.hxx>
59 #include <wrtsh.hxx>
60 #include <wview.hxx>
61 #include <frmatr.hxx>
62 #include <uitool.hxx>
63 #include <frmfmt.hxx>
64 #include <frmsh.hxx>
65 #include <frmmgr.hxx>
66 #include <frmdlg.hxx>
67 #include <swevent.hxx>
68 #include <usrpref.hxx>
69 #include <edtwin.hxx>
70 #include <swdtflvr.hxx>
71 #include <swwait.hxx>
72 #include <docstat.hxx>
73 #include <IDocumentStatistics.hxx>
74 
75 #include <comphelper/processfactory.hxx>
76 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
77 
78 #include <helpid.h>
79 #include <cmdid.h>
80 #include <cfgitems.hxx>
81 #include <globals.hrc>
82 #include <popup.hrc>
83 #include <shells.hrc>
84 #include "swabstdlg.hxx"
85 #include "misc.hrc"
86 // --> OD 2009-07-14 #i73249#
87 #include <svx/dialogs.hrc>
88 // <--
89 
90 using namespace ::com::sun::star;
91 using namespace ::com::sun::star::uno;
92 
93 // Prototypen ------------------------------------------------------------
94 
95 void lcl_FrmGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine);
lcl_GetFrmFmtByName(SwWrtShell & rSh,const String & rName)96 const SwFrmFmt* lcl_GetFrmFmtByName(SwWrtShell& rSh, const String& rName)
97 {
98     sal_uInt16 nCount = rSh.GetFlyCount(FLYCNTTYPE_FRM);
99     for( sal_uInt16 i = 0; i < nCount; i++)
100     {
101         const SwFrmFmt* pFmt = rSh.GetFlyNum(i, FLYCNTTYPE_FRM);
102 		if(pFmt->GetName() == rName)
103 			return pFmt;
104     }
105     return 0;
106 }
107 
108 #define SwFrameShell
109 #include <sfx2/msg.hxx>
110 #include "swslots.hxx"
111 
SFX_IMPL_INTERFACE(SwFrameShell,SwBaseShell,SW_RES (STR_SHELLNAME_FRAME))112 SFX_IMPL_INTERFACE(SwFrameShell, SwBaseShell, SW_RES(STR_SHELLNAME_FRAME))
113 {
114 	SFX_POPUPMENU_REGISTRATION(SW_RES(MN_FRM_POPUPMENU));
115 	SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_FRAME_TOOLBOX));
116 }
117 
118 
119 
Execute(SfxRequest & rReq)120 void SwFrameShell::Execute(SfxRequest &rReq)
121 {
122 	//Erstmal die, die keinen FrmMgr benoetigen.
123 	SwWrtShell &rSh = GetShell();
124 	sal_Bool bMore = sal_False;
125 	const SfxItemSet* pArgs = rReq.GetArgs();
126 	const SfxPoolItem* pItem;
127 	sal_uInt16 nSlot = rReq.GetSlot();
128 
129 	switch ( nSlot )
130 	{
131 		case FN_FRAME_TO_ANCHOR:
132 			if ( rSh.IsFrmSelected() )
133 			{
134 				rSh.GotoFlyAnchor();
135 				rSh.EnterStdMode();
136 				rSh.CallChgLnk();
137 			}
138 			break;
139 		case SID_FRAME_TO_TOP:
140 			rSh.SelectionToTop();
141 			break;
142 
143 		case SID_FRAME_TO_BOTTOM:
144 			rSh.SelectionToBottom();
145 			break;
146 
147 		case FN_FRAME_UP:
148 			rSh.SelectionToTop( sal_False );
149 			break;
150 
151 		case FN_FRAME_DOWN:
152 			rSh.SelectionToBottom( sal_False );
153 			break;
154 		case FN_INSERT_FRAME:
155 			if (!pArgs)
156 			{
157 				// Rahmen existiert bereits, Rahmendialog zur Bearbeitung oeffnen
158 				SfxUInt16Item aDefPage(FN_FORMAT_FRAME_DLG, TP_COLUMN);
159 				rSh.GetView().GetViewFrame()->GetDispatcher()->Execute( FN_FORMAT_FRAME_DLG,
160 								SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
161 								&aDefPage, 0L );
162 
163 			}
164 			else
165 			{
166 				// Rahmen existiert bereits, nur Spaltenanzahl wird geaendert
167 				sal_uInt16 nCols = 1;
168 				if(pArgs->GetItemState(SID_ATTR_COLUMNS, sal_False, &pItem) == SFX_ITEM_SET)
169 					nCols = ((SfxUInt16Item *)pItem)->GetValue();
170 
171 				SfxItemSet aSet(GetPool(),RES_COL,RES_COL);
172 				rSh.GetFlyFrmAttr( aSet );
173 				SwFmtCol aCol((const SwFmtCol&)aSet.Get(RES_COL));
174 				// GutterWidth wird nicht immer uebergeben, daher erst besorgen (siehe view2: Execute auf diesen Slot)
175 				sal_uInt16 nGutterWidth = aCol.GetGutterWidth();
176 				if(!nCols )
177 					nCols++;
178 				aCol.Init(nCols, nGutterWidth, aCol.GetWishWidth());
179 				aSet.Put(aCol);
180 				// Vorlagen-AutoUpdate
181 				SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
182 				if(pFmt && pFmt->IsAutoUpdateFmt())
183 				{
184 					rSh.AutoUpdateFrame(pFmt, aSet);
185 				}
186 				else
187 				{
188 					rSh.StartAllAction();
189 					rSh.SetFlyFrmAttr( aSet );
190 					rSh.SetModified();
191 					rSh.EndAllAction();
192 				}
193 
194 			}
195 			return;
196 
197 		case SID_HYPERLINK_SETLINK:
198 		{
199 			if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_HYPERLINK_SETLINK, sal_False, &pItem))
200 			{
201 				const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
202 				const String& rURL = rHLinkItem.GetURL();
203 				const String& rTarget = rHLinkItem.GetTargetFrame();
204 
205 				SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
206 				rSh.GetFlyFrmAttr( aSet );
207 				SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
208 
209 				String sOldName(rHLinkItem.GetName());
210 				String sFlyName(rSh.GetFlyName());
211 				if (sOldName.ToUpperAscii() != sFlyName.ToUpperAscii())
212 				{
213 					String sName(sOldName);
214 					sal_uInt16 i = 1;
215 					while (rSh.FindFlyByName(sName))
216 					{
217 						sName = sOldName;
218 						sName += '_';
219 						sName += String::CreateFromInt32(i++);
220 					}
221 					rSh.SetFlyName(sName);
222 				}
223 				aURL.SetURL( rURL, sal_False );
224 				aURL.SetTargetFrameName(rTarget);
225 
226 				aSet.Put( aURL );
227 				rSh.SetFlyFrmAttr( aSet );
228 			}
229 		}
230 		break;
231 
232 		case FN_FRAME_CHAIN:
233 			rSh.GetView().GetEditWin().SetChainMode( !rSh.GetView().GetEditWin().IsChainMode() );
234 			break;
235 
236 		case FN_FRAME_UNCHAIN:
237 			rSh.Unchain( (SwFrmFmt&)*rSh.GetFlyFrmFmt() );
238 			GetView().GetViewFrame()->GetBindings().Invalidate(FN_FRAME_CHAIN);
239 			break;
240 		case FN_FORMAT_FOOTNOTE_DLG:
241 		{
242             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
243             DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
244 
245             VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( GetView().GetWindow(), GetView().GetWrtShell(), DLG_DOC_FOOTNOTE );
246             DBG_ASSERT(pDlg, "Dialogdiet fail!");
247 			pDlg->Execute();
248 			delete pDlg;
249 			break;
250 		}
251 		case FN_NUMBERING_OUTLINE_DLG:
252 		{
253 			SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
254 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
255             DBG_ASSERT(pFact, "Dialogdiet fail!");
256             SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
257 														GetView().GetWindow(), &aTmp, GetView().GetWrtShell());
258             DBG_ASSERT(pDlg, "Dialogdiet fail!");
259 			pDlg->Execute();
260 			delete pDlg;
261 			rReq.Done();
262 			break;
263 		}
264 		case SID_OPEN_XML_FILTERSETTINGS:
265 		{
266 			try
267 			{
268 				uno::Reference < ui::dialogs::XExecutableDialog > xDialog(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.comp.ui.XSLTFilterDialog")), uno::UNO_QUERY);
269 				if( xDialog.is() )
270 				{
271 					xDialog->execute();
272 				}
273 			}
274 			catch( uno::Exception& )
275 			{
276 			}
277 			rReq.Ignore ();
278 		}
279 		break;
280 		case FN_WORDCOUNT_DIALOG:
281 		{
282 			SwDocStat aCurr;
283 			SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
284 			{
285 				SwWait aWait( *GetView().GetDocShell(), true );
286 				rSh.StartAction();
287 				rSh.CountWords( aCurr );
288 				rSh.UpdateDocStat( aDocStat );
289 				rSh.EndAction();
290 			}
291 
292 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
293 			DBG_ASSERT(pFact, "Dialogdiet fail!");
294 			AbstractSwWordCountDialog* pDialog = pFact->CreateSwWordCountDialog( GetView().GetWindow() );
295 			pDialog->SetValues(aCurr, aDocStat );
296 			pDialog->Execute();
297 			delete pDialog;
298 		}
299 		break;
300 		default: bMore = sal_True;
301 	}
302 
303 	if ( !bMore )
304 	{
305 		return;
306 	}
307 
308 	SwFlyFrmAttrMgr aMgr( sal_False, &rSh, FRMMGR_TYPE_NONE );
309 	sal_Bool bUpdateMgr = sal_True;
310 	sal_Bool bCopyToFmt = sal_False;
311 	switch ( nSlot )
312 	{
313         case SID_OBJECT_ALIGN_MIDDLE:
314         case FN_FRAME_ALIGN_VERT_CENTER:
315             aMgr.SetVertOrientation( text::VertOrientation::CENTER );
316 			break;
317         case SID_OBJECT_ALIGN_DOWN :
318 		case FN_FRAME_ALIGN_VERT_BOTTOM:
319             aMgr.SetVertOrientation( text::VertOrientation::BOTTOM );
320 			break;
321         case SID_OBJECT_ALIGN_UP :
322 		case FN_FRAME_ALIGN_VERT_TOP:
323             aMgr.SetVertOrientation( text::VertOrientation::TOP );
324 			break;
325 
326 		case FN_FRAME_ALIGN_VERT_CHAR_CENTER:
327             aMgr.SetVertOrientation( text::VertOrientation::CHAR_CENTER );
328 			break;
329 
330 		case FN_FRAME_ALIGN_VERT_CHAR_BOTTOM:
331             aMgr.SetVertOrientation( text::VertOrientation::CHAR_BOTTOM );
332 			break;
333 
334 		case FN_FRAME_ALIGN_VERT_CHAR_TOP:
335             aMgr.SetVertOrientation( text::VertOrientation::CHAR_TOP );
336 			break;
337 
338 		case FN_FRAME_ALIGN_VERT_ROW_CENTER:
339             aMgr.SetVertOrientation( text::VertOrientation::LINE_CENTER );
340 			break;
341 
342 		case FN_FRAME_ALIGN_VERT_ROW_BOTTOM:
343             aMgr.SetVertOrientation( text::VertOrientation::LINE_BOTTOM );
344 			break;
345 
346 		case FN_FRAME_ALIGN_VERT_ROW_TOP:
347             aMgr.SetVertOrientation( text::VertOrientation::LINE_TOP );
348 			break;
349         case SID_OBJECT_ALIGN_CENTER :
350 		case FN_FRAME_ALIGN_HORZ_CENTER:
351             aMgr.SetHorzOrientation( text::HoriOrientation::CENTER );
352 			break;
353         case SID_OBJECT_ALIGN_RIGHT:
354 		case FN_FRAME_ALIGN_HORZ_RIGHT:
355             aMgr.SetHorzOrientation( text::HoriOrientation::RIGHT );
356 			break;
357         case SID_OBJECT_ALIGN_LEFT:
358 		case FN_FRAME_ALIGN_HORZ_LEFT:
359             aMgr.SetHorzOrientation( text::HoriOrientation::LEFT );
360 			break;
361 
362 		case FN_SET_FRM_POSITION:
363 		{
364 			aMgr.SetAbsPos(((SfxPointItem &)pArgs->Get
365 								(FN_SET_FRM_POSITION)).GetValue());
366 		}
367 		break;
368 		case SID_ATTR_BRUSH:
369 		{
370 			if(pArgs)
371 			{
372 				aMgr.SetAttrSet( *pArgs );
373 				bCopyToFmt = sal_True;
374 			}
375 		}
376 		break;
377 		case SID_ATTR_ULSPACE:
378 		case SID_ATTR_LRSPACE:
379 		{
380 			if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(GetPool().GetWhich(nSlot), sal_False, &pItem))
381 			{
382 				aMgr.SetAttrSet( *pArgs );
383 				if(SID_ATTR_ULSPACE == nSlot && SID_ATTR_ULSPACE == nSlot)
384 					bCopyToFmt = sal_True;
385 			}
386 		}
387 		break;
388 
389         case SID_ATTR_TRANSFORM:
390         {
391             bool bApplyNewSize = false;
392 
393             Size aNewSize = aMgr.GetSize();
394             if ( SFX_ITEM_SET == pArgs->GetItemState( SID_ATTR_TRANSFORM_WIDTH, sal_False, &pItem ) )
395             {
396                 aNewSize.setWidth( static_cast< const SfxUInt32Item* >(pItem)->GetValue() );
397                 bApplyNewSize = true;
398             }
399 
400             if ( SFX_ITEM_SET == pArgs->GetItemState( SID_ATTR_TRANSFORM_HEIGHT, sal_False, &pItem ) )
401             {
402                 aNewSize.setHeight( static_cast< const SfxUInt32Item* >(pItem)->GetValue() );
403                 bApplyNewSize = true;
404             }
405 
406             if ( bApplyNewSize )
407             {
408                 aMgr.SetSize( aNewSize );
409             }
410             else
411             {
412                 bUpdateMgr = sal_False;
413             }
414 
415         }
416         break;
417 
418         case FN_FORMAT_FRAME_DLG:
419         case FN_DRAW_WRAP_DLG:
420 		{
421 			const int nSel = rSh.GetSelectionType();
422 			if (nSel & nsSelectionType::SEL_GRF)
423 			{
424 				rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(FN_FORMAT_GRAFIC_DLG);
425 				bUpdateMgr = sal_False;
426 			}
427 			else
428 			{
429                 SfxItemSet aSet(GetPool(), 	RES_FRMATR_BEGIN, 		RES_FRMATR_END-1,
430                                             SID_ATTR_BORDER_INNER, 	SID_ATTR_BORDER_INNER,
431                                             FN_GET_PRINT_AREA, 		FN_GET_PRINT_AREA,
432                                             SID_ATTR_PAGE_SIZE, 	SID_ATTR_PAGE_SIZE,
433                                             SID_ATTR_BRUSH, 		SID_ATTR_BRUSH,
434                                             SID_ATTR_LRSPACE,		SID_ATTR_ULSPACE,
435                                             FN_SURROUND, 			FN_HORI_ORIENT,
436                                             FN_SET_FRM_NAME, 		FN_SET_FRM_NAME,
437                                             FN_KEEP_ASPECT_RATIO, 	FN_KEEP_ASPECT_RATIO,
438                                             SID_DOCFRAME, 			SID_DOCFRAME,
439                                             SID_HTML_MODE, 			SID_HTML_MODE,
440                                             FN_SET_FRM_ALT_NAME, 	FN_SET_FRM_ALT_NAME,
441                                             FN_PARAM_CHAIN_PREVIOUS, FN_PARAM_CHAIN_NEXT,
442                                             FN_OLE_IS_MATH,         FN_OLE_IS_MATH,
443                                             FN_MATH_BASELINE_ALIGNMENT, FN_MATH_BASELINE_ALIGNMENT,
444                                             0);
445 
446                 const SwViewOption* pVOpt = rSh.GetViewOptions();
447                 if(nSel & nsSelectionType::SEL_OLE)
448                     aSet.Put( SfxBoolItem(FN_KEEP_ASPECT_RATIO, pVOpt->IsKeepRatio()) );
449                 aSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(GetView().GetDocShell())));
450                 aSet.Put(SfxStringItem(FN_SET_FRM_NAME, rSh.GetFlyName()));
451                 if( nSel & nsSelectionType::SEL_OLE )
452                 {
453                     aSet.Put( SfxStringItem( FN_SET_FRM_ALT_NAME, rSh.GetObjTitle() ) );
454                 }
455 
456 				const SwRect &rPg = rSh.GetAnyCurRect(RECT_PAGE);
457 				SwFmtFrmSize aFrmSize(ATT_VAR_SIZE, rPg.Width(), rPg.Height());
458 				aFrmSize.SetWhich(GetPool().GetWhich(SID_ATTR_PAGE_SIZE));
459 				aSet.Put(aFrmSize);
460 
461 				const SwRect &rPr = rSh.GetAnyCurRect(RECT_PAGE_PRT);
462 				SwFmtFrmSize aPrtSize(ATT_VAR_SIZE, rPr.Width(), rPr.Height());
463 				aPrtSize.SetWhich(GetPool().GetWhich(FN_GET_PRINT_AREA));
464 				aSet.Put(aPrtSize);
465 
466 				aSet.Put(aMgr.GetAttrSet());
467 				aSet.SetParent( aMgr.GetAttrSet().GetParent() );
468 
469 				// Bei %-Werten Groesse initialisieren
470 				SwFmtFrmSize& rSize = (SwFmtFrmSize&)aSet.Get(RES_FRM_SIZE);
471 				if (rSize.GetWidthPercent() && rSize.GetWidthPercent() != 0xff)
472 					rSize.SetWidth(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Width());
473 				if (rSize.GetHeightPercent() && rSize.GetHeightPercent() != 0xff)
474 					rSize.SetHeight(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Height());
475 
476                 // disable vertical positioning for Math Objects anchored 'as char' if baseline alignment is activated
477                 aSet.Put( SfxBoolItem( FN_MATH_BASELINE_ALIGNMENT,
478                         rSh.GetDoc()->get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT ) ) );
479                 const uno::Reference < embed::XEmbeddedObject > xObj( rSh.GetOleRef() );
480                 aSet.Put( SfxBoolItem( FN_OLE_IS_MATH, xObj.is() && SotExchange::IsMath( xObj->getClassID() ) ) );
481 
482 				sal_uInt16 nDefPage = 0;
483 				if(pArgs && pArgs->GetItemState(FN_FORMAT_FRAME_DLG, sal_False, &pItem) == SFX_ITEM_SET)
484 					nDefPage = ((SfxUInt16Item *)pItem)->GetValue();
485 
486 				aSet.Put(SfxFrameItem( SID_DOCFRAME, &GetView().GetViewFrame()->GetTopFrame()));
487                 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &GetView()));
488                 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric) ));
489 				SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
490                 DBG_ASSERT(pFact, "Dialogdiet fail!");
491                 SfxAbstractTabDialog* pDlg = pFact->CreateFrmTabDialog( DLG_FRM_STD,
492 														GetView().GetViewFrame(),
493 														GetView().GetWindow(),
494 														aSet, sal_False,
495 														nSel & nsSelectionType::SEL_GRF ? DLG_FRM_GRF :
496 														nSel & nsSelectionType::SEL_OLE ? DLG_FRM_OLE :
497 																						DLG_FRM_STD,
498 														sal_False,
499 														nDefPage);
500                 DBG_ASSERT(pDlg, "Dialogdiet fail!");
501 
502                 if ( nSlot == FN_DRAW_WRAP_DLG )
503                 {
504                     pDlg->SetCurPageId(TP_FRM_WRAP);
505                 }
506 
507 				if ( pDlg->Execute() )
508 				{
509 					const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
510 					if(pOutSet)
511 					{
512                         rReq.Done(*pOutSet);
513                         if(nSel & nsSelectionType::SEL_OLE &&
514 						SFX_ITEM_SET == pOutSet->GetItemState(FN_KEEP_ASPECT_RATIO, sal_True, &pItem))
515 						{
516 							SwViewOption aUsrPref( *pVOpt );
517 							aUsrPref.SetKeepRatio(((const SfxBoolItem*)pItem)->GetValue());
518 							SW_MOD()->ApplyUsrPref(aUsrPref, &GetView());
519 						}
520 						if (SFX_ITEM_SET == pOutSet->GetItemState(FN_SET_FRM_ALT_NAME, sal_True, &pItem))
521 						{
522                             // --> OD 2009-07-13 #i73249#
523 //                            rSh.SetAlternateText(((const SfxStringItem*)pItem)->GetValue());
524                             rSh.SetObjTitle(((const SfxStringItem*)pItem)->GetValue());
525                             // <--
526 						}
527 						// Vorlagen-AutoUpdate
528 						SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
529 						if(pFmt && pFmt->IsAutoUpdateFmt())
530 						{
531 							rSh.AutoUpdateFrame(pFmt, *pOutSet);
532 							// alles, dass das Format nicht kann, muss hart
533 							// gesetzt werden
534 							if(SFX_ITEM_SET == pOutSet->GetItemState(FN_SET_FRM_NAME, sal_False, &pItem))
535 								rSh.SetFlyName(((SfxStringItem*)pItem)->GetValue());
536 							SfxItemSet aShellSet(GetPool(), RES_FRM_SIZE,	RES_FRM_SIZE,
537 															RES_SURROUND, 	RES_SURROUND,
538 															RES_ANCHOR,		RES_ANCHOR,
539 															RES_VERT_ORIENT,RES_HORI_ORIENT,
540 															0);
541 							aShellSet.Put(*pOutSet);
542 							aMgr.SetAttrSet(aShellSet);
543 							if(SFX_ITEM_SET == pOutSet->GetItemState(FN_SET_FRM_NAME, sal_False, &pItem))
544 								rSh.SetFlyName(((SfxStringItem*)pItem)->GetValue());
545 						}
546 						else
547 							aMgr.SetAttrSet( *pOutSet );
548 
549                         const SwFrmFmt* pCurrFlyFmt = rSh.GetFlyFrmFmt();
550                         if(SFX_ITEM_SET ==
551                            pOutSet->GetItemState(FN_PARAM_CHAIN_PREVIOUS,
552                                                  sal_False, &pItem))
553                         {
554                             rSh.HideChainMarker();
555 
556                             String sPrevName =
557                                 ((const SfxStringItem*)pItem)->GetValue();
558                             const SwFmtChain &rChain = pCurrFlyFmt->GetChain();
559                             //needs cast - no non-const method available
560                             SwFlyFrmFmt* pFlyFmt =
561                                 (SwFlyFrmFmt*)rChain.GetPrev();
562                             if(pFlyFmt)
563                             {
564                                 if (pFlyFmt->GetName() != sPrevName)
565                                 {
566                                     rSh.Unchain(*pFlyFmt);
567                                 }
568                                 else
569                                     sPrevName.Erase();
570                             }
571 
572                             if(sPrevName.Len())
573                             {
574                                 //needs cast - no non-const method available
575                                 SwFrmFmt* pPrevFmt = (SwFrmFmt*)
576                                     lcl_GetFrmFmtByName(rSh, sPrevName);
577                                 DBG_ASSERT(pPrevFmt, "No frame found!");
578                                 if(pPrevFmt)
579                                 {
580                                     rSh.Chain(*pPrevFmt, *pCurrFlyFmt);
581                                 }
582                             }
583                             rSh.SetChainMarker();
584                         }
585                         if(SFX_ITEM_SET ==
586                            pOutSet->GetItemState(FN_PARAM_CHAIN_NEXT, sal_False,
587                                                  &pItem))
588                         {
589                             rSh.HideChainMarker();
590                             String sNextName =
591                                 ((const SfxStringItem*)pItem)->GetValue();
592                             const SwFmtChain &rChain = pCurrFlyFmt->GetChain();
593                             //needs cast - no non-const method available
594                             SwFlyFrmFmt* pFlyFmt =
595                                 (SwFlyFrmFmt*)rChain.GetNext();
596                             if(pFlyFmt)
597                             {
598                                 if (pFlyFmt->GetName() != sNextName)
599                                 {
600                                     rSh.Unchain(*((SwFlyFrmFmt*) pCurrFlyFmt));
601                                 }
602                                 else
603                                     sNextName.Erase();
604                             }
605 
606                             if(sNextName.Len())
607                             {
608                                 //needs cast - no non-const method available
609                                 SwFrmFmt* pNextFmt = (SwFrmFmt*)
610                                     lcl_GetFrmFmtByName(rSh, sNextName);
611                                 DBG_ASSERT(pNextFmt, "No frame found!");
612                                 if(pNextFmt)
613                                 {
614                                     rSh.Chain(*(SwFrmFmt*)
615                                               pCurrFlyFmt, *pNextFmt);
616                                 }
617                             }
618                             rSh.SetChainMarker();
619                         }
620 					}
621 				}
622 				else
623 					bUpdateMgr = sal_False;
624 				delete pDlg;
625 			}
626 		}
627 		break;
628 		case FN_FRAME_MIRROR_ON_EVEN_PAGES:
629 		{
630 			SwFmtHoriOrient aHori(aMgr.GetHoriOrient());
631 			sal_Bool bMirror = !aHori.IsPosToggle();
632 			aHori.SetPosToggle(bMirror);
633 			SfxItemSet aSet(GetPool(), RES_HORI_ORIENT, RES_HORI_ORIENT);
634 			aSet.Put(aHori);
635 			aMgr.SetAttrSet(aSet);
636 			bCopyToFmt = sal_True;
637 			rReq.SetReturnValue(SfxBoolItem(nSlot, bMirror));
638 		}
639 		break;
640         // --> OD 2009-07-14 #i73249#
641         case FN_TITLE_DESCRIPTION_SHAPE:
642         {
643             bUpdateMgr = sal_False;
644             SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
645             if ( pSdrView &&
646                  pSdrView->GetMarkedObjectCount() == 1 )
647             {
648                 String aDescription(rSh.GetObjDescription());
649                 String aTitle(rSh.GetObjTitle());
650 
651                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
652                 OSL_ENSURE(pFact, "Dialogdiet fail!");
653                 AbstractSvxObjectTitleDescDialog* pDlg =
654                     pFact->CreateSvxObjectTitleDescDialog( NULL,
655                                                            aTitle,
656                                                            aDescription );
657                 OSL_ENSURE(pDlg, "Dialogdiet fail!");
658 
659                 if ( pDlg->Execute() == RET_OK )
660                 {
661                     pDlg->GetDescription(aDescription);
662                     pDlg->GetTitle(aTitle);
663 
664                     rSh.SetObjDescription(aDescription);
665                     rSh.SetObjTitle(aTitle);
666                 }
667 
668                 delete pDlg;
669             }
670         }
671         break;
672         // <--
673         default:
674             ASSERT( !this, "falscher Dispatcher" );
675             return;
676     }
677     if ( bUpdateMgr )
678     {
679         SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
680         if ( bCopyToFmt && pFmt && pFmt->IsAutoUpdateFmt() )
681         {
682             rSh.AutoUpdateFrame(pFmt, aMgr.GetAttrSet());
683         }
684         else
685         {
686             aMgr.UpdateFlyFrm();
687         }
688     }
689 
690 }
691 
692 /*--------------------------------------------------------------------
693 	Beschreibung:
694  --------------------------------------------------------------------*/
695 
696 
GetState(SfxItemSet & rSet)697 void SwFrameShell::GetState(SfxItemSet& rSet)
698 {
699 	SwWrtShell &rSh = GetShell();
700 	sal_Bool bHtmlMode = 0 != ::GetHtmlMode(rSh.GetView().GetDocShell());
701 	if (rSh.IsFrmSelected())
702 	{
703 		SfxItemSet aSet( rSh.GetAttrPool(),
704 							RES_LR_SPACE, RES_UL_SPACE,
705 							RES_PROTECT, RES_HORI_ORIENT,
706 							RES_OPAQUE, RES_OPAQUE,
707 							RES_PRINT, RES_OPAQUE,
708 							0 );
709 		rSh.GetFlyFrmAttr( aSet );
710 
711 		sal_Bool bProtect = rSh.IsSelObjProtected(FLYPROTECT_POS);
712 		sal_Bool bParentCntProt = rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
713 
714 		bProtect |= bParentCntProt;
715 
716 		const sal_uInt16 eFrmType = rSh.GetFrmType(0,sal_True);
717 		SwFlyFrmAttrMgr aMgr( sal_False, &rSh, FRMMGR_TYPE_NONE );
718 
719 		SfxWhichIter aIter( rSet );
720 		sal_uInt16 nWhich = aIter.FirstWhich();
721 		while ( nWhich )
722 		{
723 			switch ( nWhich )
724 			{
725 				case RES_FRM_SIZE:
726 				{
727 					SwFmtFrmSize aSz(aMgr.GetFrmSize());
728 					rSet.Put(aSz);
729 				}
730 				break;
731 				case RES_VERT_ORIENT:
732 				case RES_HORI_ORIENT:
733 				case SID_ATTR_ULSPACE:
734 				case SID_ATTR_LRSPACE:
735 				case RES_LR_SPACE:
736 				case RES_UL_SPACE:
737 				case RES_PROTECT:
738 				case RES_OPAQUE:
739 				case RES_PRINT:
740 				case RES_SURROUND:
741 				{
742 					rSet.Put(aSet.Get(GetPool().GetWhich(nWhich), sal_True ));
743 				}
744 				break;
745                 case SID_OBJECT_ALIGN_LEFT   :
746                 case SID_OBJECT_ALIGN_CENTER :
747                 case SID_OBJECT_ALIGN_RIGHT  :
748 				case FN_FRAME_ALIGN_HORZ_CENTER:
749 				case FN_FRAME_ALIGN_HORZ_RIGHT:
750 				case FN_FRAME_ALIGN_HORZ_LEFT:
751 					if ( (eFrmType & FRMTYPE_FLY_INCNT) ||
752 							bProtect ||
753                             ((nWhich == FN_FRAME_ALIGN_HORZ_CENTER  || nWhich == SID_OBJECT_ALIGN_CENTER)&& bHtmlMode) )
754 						rSet.DisableItem( nWhich );
755 				break;
756 				case FN_FRAME_ALIGN_VERT_ROW_TOP:
757 				case FN_FRAME_ALIGN_VERT_ROW_CENTER:
758 				case FN_FRAME_ALIGN_VERT_ROW_BOTTOM:
759 				case FN_FRAME_ALIGN_VERT_CHAR_TOP:
760 				case FN_FRAME_ALIGN_VERT_CHAR_CENTER:
761 				case FN_FRAME_ALIGN_VERT_CHAR_BOTTOM:
762 					if ( !(eFrmType & FRMTYPE_FLY_INCNT) || bProtect
763 							|| (bHtmlMode && FN_FRAME_ALIGN_VERT_CHAR_BOTTOM == nWhich) )
764 						rSet.DisableItem( nWhich );
765 				break;
766 
767                 case SID_OBJECT_ALIGN_UP     :
768                 case SID_OBJECT_ALIGN_MIDDLE :
769                 case SID_OBJECT_ALIGN_DOWN :
770 
771                 case FN_FRAME_ALIGN_VERT_TOP:
772 				case FN_FRAME_ALIGN_VERT_CENTER:
773 				case FN_FRAME_ALIGN_VERT_BOTTOM:
774 					if ( bProtect || (bHtmlMode && eFrmType & FRMTYPE_FLY_ATCNT) )
775 						rSet.DisableItem( nWhich );
776 					else
777 					{
778 						sal_uInt16 nId = 0;
779 						if (eFrmType & FRMTYPE_FLY_INCNT)
780 						{
781 							switch (nWhich)
782 							{
783                                 case SID_OBJECT_ALIGN_UP     :
784                                 case FN_FRAME_ALIGN_VERT_TOP:
785 									nId = STR_TOP_BASE;	break;
786                                 case SID_OBJECT_ALIGN_MIDDLE :
787                                 case FN_FRAME_ALIGN_VERT_CENTER:
788 									nId = STR_CENTER_BASE;	break;
789                                 case SID_OBJECT_ALIGN_DOWN :
790                                 case FN_FRAME_ALIGN_VERT_BOTTOM:
791 									if(!bHtmlMode)
792 										nId = STR_BOTTOM_BASE;
793 									else
794 										rSet.DisableItem( nWhich );
795 								break;
796 							}
797 						}
798 						else
799 						{
800                             if (nWhich != FN_FRAME_ALIGN_VERT_TOP &&
801                                     nWhich != SID_OBJECT_ALIGN_UP )
802 							{
803 								if (aMgr.GetAnchor() == FLY_AT_FLY)
804 								{
805 									const SwFrmFmt* pFmt = rSh.IsFlyInFly();
806 									if (pFmt)
807 									{
808 										const SwFmtFrmSize& rFrmSz = pFmt->GetFrmSize();
809                                         if (rFrmSz.GetHeightSizeType() != ATT_FIX_SIZE)
810 										{
811 											rSet.DisableItem( nWhich );
812 											break;
813 										}
814 									}
815 								}
816 							}
817 							switch (nWhich)
818 							{
819                                 case SID_OBJECT_ALIGN_UP :
820                                 case FN_FRAME_ALIGN_VERT_TOP:
821 									nId = STR_TOP; break;
822                                 case SID_OBJECT_ALIGN_MIDDLE:
823                                 case FN_FRAME_ALIGN_VERT_CENTER:
824 									nId = STR_CENTER_VERT; break;
825                                 case SID_OBJECT_ALIGN_DOWN:
826                                 case FN_FRAME_ALIGN_VERT_BOTTOM:
827 									nId = STR_BOTTOM; break;
828 							}
829 						}
830 						if ( nId )
831 							rSet.Put( SfxStringItem( nWhich, SW_RES(nId) ));
832 					}
833 				break;
834 				case SID_HYPERLINK_GETLINK:
835 				{
836 					String sURL;
837 					SvxHyperlinkItem aHLinkItem;
838 					const SfxPoolItem* pItem;
839 
840                     SfxItemSet aURLSet(GetPool(), RES_URL, RES_URL);
841                     rSh.GetFlyFrmAttr( aURLSet );
842 
843                     if(SFX_ITEM_SET == aURLSet.GetItemState(RES_URL, sal_True, &pItem))
844 					{
845 						const SwFmtURL* pFmtURL = (const SwFmtURL*)pItem;
846 						aHLinkItem.SetURL(pFmtURL->GetURL());
847 						aHLinkItem.SetTargetFrame(pFmtURL->GetTargetFrameName());
848 						aHLinkItem.SetName(rSh.GetFlyName());
849 					}
850 
851 					aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
852 						(bHtmlMode ? HLINK_HTMLMODE : 0)));
853 
854 					rSet.Put(aHLinkItem);
855 				}
856 				break;
857 
858 				case FN_FRAME_CHAIN:
859 				{
860 					const int nSel = rSh.GetSelectionType();
861 					if (nSel & nsSelectionType::SEL_GRF || nSel & nsSelectionType::SEL_OLE)
862 						rSet.DisableItem( FN_FRAME_CHAIN );
863 					else
864 					{
865 						const SwFrmFmt *pFmt = rSh.GetFlyFrmFmt();
866 						if ( bParentCntProt || rSh.GetView().GetEditWin().GetApplyTemplate() ||
867 						 	!pFmt || pFmt->GetChain().GetNext() )
868 						{
869 							rSet.DisableItem( FN_FRAME_CHAIN );
870 						}
871 						else
872 						{
873 							sal_Bool bChainMode = rSh.GetView().GetEditWin().IsChainMode();
874 							rSet.Put( SfxBoolItem( FN_FRAME_CHAIN, bChainMode ) );
875 						}
876 					}
877 				}
878 				break;
879 				case FN_FRAME_UNCHAIN:
880 				{
881 					const int nSel = rSh.GetSelectionType();
882 					if (nSel & nsSelectionType::SEL_GRF || nSel & nsSelectionType::SEL_OLE)
883 						rSet.DisableItem( FN_FRAME_UNCHAIN );
884 					else
885 					{
886 						const SwFrmFmt *pFmt = rSh.GetFlyFrmFmt();
887 						if ( bParentCntProt || rSh.GetView().GetEditWin().GetApplyTemplate() ||
888 						 	!pFmt || !pFmt->GetChain().GetNext() )
889 						{
890 							rSet.DisableItem( FN_FRAME_UNCHAIN );
891 						}
892 					}
893 				}
894 				break;
895 				case SID_FRAME_TO_TOP:
896 				case SID_FRAME_TO_BOTTOM:
897 				case FN_FRAME_UP:
898 				case FN_FRAME_DOWN:
899                     if ( bParentCntProt )
900                         rSet.DisableItem( nWhich );
901                 break;
902 
903                 case SID_ATTR_TRANSFORM:
904                 {
905                     rSet.DisableItem( nWhich );
906                 }
907                 break;
908 
909                 case SID_ATTR_TRANSFORM_PROTECT_SIZE:
910                 {
911                     const sal_uInt8 eProtection = rSh.IsSelObjProtected( FLYPROTECT_SIZE );
912                     if ( ( eProtection & FLYPROTECT_CONTENT ) ||
913                          ( eProtection & FLYPROTECT_SIZE ) )
914                     {
915                         rSet.Put( SfxBoolItem( SID_ATTR_TRANSFORM_PROTECT_SIZE, sal_True ) );
916                     }
917                     else
918                     {
919                         rSet.Put( SfxBoolItem( SID_ATTR_TRANSFORM_PROTECT_SIZE, sal_False ) );
920                     }
921                 }
922                 break;
923 
924                 case SID_ATTR_TRANSFORM_WIDTH:
925                 {
926                     rSet.Put( SfxUInt32Item( SID_ATTR_TRANSFORM_WIDTH, aMgr.GetSize().getWidth() ) );
927                 }
928                 break;
929 
930                 case SID_ATTR_TRANSFORM_HEIGHT:
931                 {
932                     rSet.Put( SfxUInt32Item( SID_ATTR_TRANSFORM_HEIGHT, aMgr.GetSize().getHeight() ) );
933                 }
934                 break;
935 
936                 case FN_FORMAT_FRAME_DLG:
937                 {
938                     const int nSel = rSh.GetSelectionType();
939                     if ( bParentCntProt || nSel & nsSelectionType::SEL_GRF)
940                         rSet.DisableItem( nWhich );
941                 }
942                 break;
943 
944                 case FN_TITLE_DESCRIPTION_SHAPE:
945                 {
946                     SwWrtShell &rWrtSh = GetShell();
947                     SdrView* pSdrView = rWrtSh.GetDrawViewWithValidMarkList();
948                     if ( !pSdrView ||
949                          pSdrView->GetMarkedObjectCount() != 1 )
950                     {
951                         rSet.DisableItem( nWhich );
952                     }
953 
954                 }
955                 break;
956 
957                 default:
958                     /* do nothing */;
959                     break;
960             }
961             nWhich = aIter.NextWhich();
962         }
963     }
964 }
965 
966 /*--------------------------------------------------------------------
967 	Beschreibung:	Ctor fuer FrameShell
968  --------------------------------------------------------------------*/
969 
970 
SwFrameShell(SwView & _rView)971 SwFrameShell::SwFrameShell(SwView &_rView) :
972     SwBaseShell( _rView )
973 {
974 	SetName(String::CreateFromAscii("Frame"));
975 	SetHelpId(SW_FRAMESHELL);
976 
977 	/* #96392# Use this to announce it is the frame shell who creates the
978        selection. */
979     SwTransferable::CreateSelection( _rView.GetWrtShell(), (ViewShell *) this );
980 
981     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Frame));
982 }
983 
~SwFrameShell()984 SwFrameShell::~SwFrameShell()
985 {
986 	/* #96392# Only clear the selection if it was this frame shell who created
987        it. */
988 	SwTransferable::ClearSelection( GetShell(), (ViewShell *) this );
989 }
990 
991 /*--------------------------------------------------------------------
992 	Beschreibung:
993  --------------------------------------------------------------------*/
994 
995 
996 
ExecFrameStyle(SfxRequest & rReq)997 void SwFrameShell::ExecFrameStyle(SfxRequest& rReq)
998 {
999 	SwWrtShell &rSh = GetShell();
1000 	sal_Bool bDefault = sal_False;
1001 	if (!rSh.IsFrmSelected())
1002 		return;
1003 
1004 	// Erst Default-BoxItem aus Pool holen. Wenn ungleich normalem Boxitem,
1005 	// dann ist es bereits geaendert worden (neues ist kein Default).
1006 	const SvxBoxItem* pPoolBoxItem = (const SvxBoxItem*)::GetDfltAttr(RES_BOX);
1007 
1008 	const SfxItemSet *pArgs = rReq.GetArgs();
1009 	SfxItemSet aFrameSet(rSh.GetAttrPool(), RES_BOX, RES_BOX);
1010 
1011 	rSh.GetFlyFrmAttr( aFrameSet );
1012 	const SvxBoxItem& rBoxItem = (const SvxBoxItem&)aFrameSet.Get(RES_BOX);
1013 
1014 	if (pPoolBoxItem == &rBoxItem)
1015 		bDefault = sal_True;
1016 
1017 	SvxBoxItem aBoxItem(rBoxItem);
1018 
1019 	SvxBorderLine aBorderLine;
1020 	const SfxPoolItem *pItem = 0;
1021 
1022 	if(pArgs)    //irgendein Controller kann auch mal nichts liefern #48169#
1023 	{
1024 		switch (rReq.GetSlot())
1025 		{
1026 			case SID_ATTR_BORDER:
1027 			{
1028 				if (pArgs->GetItemState(RES_BOX, sal_True, &pItem) == SFX_ITEM_SET)
1029 				{
1030 					SvxBoxItem aNewBox(*((SvxBoxItem *)pItem));
1031 					const SvxBorderLine* pBorderLine;
1032 
1033 					if ((pBorderLine = aBoxItem.GetTop()) != NULL)
1034 						lcl_FrmGetMaxLineWidth(pBorderLine, aBorderLine);
1035 					if ((pBorderLine = aBoxItem.GetBottom()) != NULL)
1036 						lcl_FrmGetMaxLineWidth(pBorderLine, aBorderLine);
1037 					if ((pBorderLine = aBoxItem.GetLeft()) != NULL)
1038 						lcl_FrmGetMaxLineWidth(pBorderLine, aBorderLine);
1039 					if ((pBorderLine = aBoxItem.GetRight()) != NULL)
1040 						lcl_FrmGetMaxLineWidth(pBorderLine, aBorderLine);
1041 
1042 					if(aBorderLine.GetOutWidth() == 0)
1043 					{
1044 						aBorderLine.SetInWidth(0);
1045 						aBorderLine.SetOutWidth(DEF_LINE_WIDTH_0);
1046 						aBorderLine.SetDistance(0);
1047 					}
1048 					//Distance nur setzen, wenn der Request vom Controller kommt
1049 
1050 					if(!StarBASIC::IsRunning())
1051 					{
1052 						aNewBox.SetDistance( rBoxItem.GetDistance() );
1053 					}
1054 
1055 					aBoxItem = aNewBox;
1056 					SvxBorderLine aDestBorderLine;
1057 
1058 					if ((pBorderLine = aBoxItem.GetTop()) != NULL)
1059 						aBoxItem.SetLine(&aBorderLine, BOX_LINE_TOP);
1060 					if ((pBorderLine = aBoxItem.GetBottom()) != NULL)
1061 						aBoxItem.SetLine(&aBorderLine, BOX_LINE_BOTTOM);
1062 					if ((pBorderLine = aBoxItem.GetLeft()) != NULL)
1063 						aBoxItem.SetLine(&aBorderLine, BOX_LINE_LEFT);
1064 					if ((pBorderLine = aBoxItem.GetRight()) != NULL)
1065 						aBoxItem.SetLine(&aBorderLine, BOX_LINE_RIGHT);
1066 				}
1067 			}
1068 			break;
1069 
1070 			case SID_FRAME_LINESTYLE:
1071 			{
1072 				if (pArgs->GetItemState(SID_FRAME_LINESTYLE, sal_False, &pItem) == SFX_ITEM_SET)
1073 				{
1074 					const SvxLineItem* pLineItem =
1075 							(const SvxLineItem*)pItem;
1076 
1077 					if ( pLineItem->GetLine() )
1078 					{
1079 						aBorderLine = *(pLineItem->GetLine());
1080 
1081 						if (!aBoxItem.GetTop() && !aBoxItem.GetBottom() &&
1082 							!aBoxItem.GetLeft() && !aBoxItem.GetRight())
1083 						{
1084 							aBoxItem.SetLine(&aBorderLine, BOX_LINE_TOP);
1085 							aBoxItem.SetLine(&aBorderLine, BOX_LINE_BOTTOM);
1086 							aBoxItem.SetLine(&aBorderLine, BOX_LINE_LEFT);
1087 							aBoxItem.SetLine(&aBorderLine, BOX_LINE_RIGHT);
1088 						}
1089 						else
1090 						{
1091 							if( aBoxItem.GetTop() )
1092 							{
1093 								aBorderLine.SetColor( aBoxItem.GetTop()->GetColor() );
1094 								aBoxItem.SetLine(&aBorderLine, BOX_LINE_TOP);
1095 							}
1096 							if( aBoxItem.GetBottom() )
1097 							{
1098 								aBorderLine.SetColor( aBoxItem.GetBottom()->GetColor());
1099 								aBoxItem.SetLine(&aBorderLine, BOX_LINE_BOTTOM);
1100 							}
1101 							if( aBoxItem.GetLeft() )
1102 							{
1103 								aBorderLine.SetColor( aBoxItem.GetLeft()->GetColor());
1104 								aBoxItem.SetLine(&aBorderLine, BOX_LINE_LEFT);
1105 							}
1106 							if( aBoxItem.GetRight() )
1107 							{
1108 								aBorderLine.SetColor(aBoxItem.GetRight()->GetColor());
1109 								aBoxItem.SetLine(&aBorderLine, BOX_LINE_RIGHT);
1110 							}
1111 						}
1112 					}
1113 					else
1114 					{
1115 						aBoxItem.SetLine(0, BOX_LINE_TOP);
1116 						aBoxItem.SetLine(0, BOX_LINE_BOTTOM);
1117 						aBoxItem.SetLine(0, BOX_LINE_LEFT);
1118 						aBoxItem.SetLine(0, BOX_LINE_RIGHT);
1119 					}
1120 				}
1121 			}
1122 			break;
1123 
1124 			case SID_FRAME_LINECOLOR:
1125 			{
1126 				if (pArgs->GetItemState(SID_FRAME_LINECOLOR, sal_False, &pItem) == SFX_ITEM_SET)
1127 				{
1128 					const Color& rNewColor = ((const SvxColorItem*)pItem)->GetValue();
1129 
1130 					if (!aBoxItem.GetTop() && !aBoxItem.GetBottom() &&
1131 						!aBoxItem.GetLeft() && !aBoxItem.GetRight())
1132 					{
1133 						aBorderLine.SetColor( rNewColor );
1134 						aBoxItem.SetLine(&aBorderLine, BOX_LINE_TOP);
1135 						aBoxItem.SetLine(&aBorderLine, BOX_LINE_BOTTOM);
1136 						aBoxItem.SetLine(&aBorderLine, BOX_LINE_LEFT);
1137 						aBoxItem.SetLine(&aBorderLine, BOX_LINE_RIGHT);
1138 					}
1139 					else
1140 					{
1141 						if ( aBoxItem.GetTop() )
1142 							((SvxBorderLine*)aBoxItem.GetTop())->SetColor( rNewColor );
1143 						if ( aBoxItem.GetBottom() )
1144 							((SvxBorderLine*)aBoxItem.GetBottom())->SetColor( rNewColor );
1145 						if ( aBoxItem.GetLeft() )
1146 							((SvxBorderLine*)aBoxItem.GetLeft())->SetColor( rNewColor );
1147 						if ( aBoxItem.GetRight() )
1148 							((SvxBorderLine*)aBoxItem.GetRight())->SetColor( rNewColor );
1149 					}
1150 				}
1151 			}
1152 			break;
1153 		}
1154 	}
1155 	if (bDefault && (aBoxItem.GetTop() || aBoxItem.GetBottom() ||
1156 		aBoxItem.GetLeft() || aBoxItem.GetRight()))
1157 	{
1158 		aBoxItem.SetDistance(MIN_BORDER_DIST);
1159 	}
1160 	aFrameSet.Put( aBoxItem );
1161 	// Vorlagen-AutoUpdate
1162 	SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
1163 	if(pFmt && pFmt->IsAutoUpdateFmt())
1164 	{
1165 		rSh.AutoUpdateFrame(pFmt, aFrameSet);
1166 	}
1167 	else
1168 		rSh.SetFlyFrmAttr( aFrameSet );
1169 
1170 }
1171 
1172 
1173 
lcl_FrmGetMaxLineWidth(const SvxBorderLine * pBorderLine,SvxBorderLine & rBorderLine)1174 void lcl_FrmGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine)
1175 {
1176 	if(pBorderLine->GetInWidth() > rBorderLine.GetInWidth())
1177 		rBorderLine.SetInWidth(pBorderLine->GetInWidth());
1178 
1179 	if(pBorderLine->GetOutWidth() > rBorderLine.GetOutWidth())
1180 		rBorderLine.SetOutWidth(pBorderLine->GetOutWidth());
1181 
1182 	if(pBorderLine->GetDistance() > rBorderLine.GetDistance())
1183 		rBorderLine.SetDistance(pBorderLine->GetDistance());
1184 
1185 	rBorderLine.SetColor(pBorderLine->GetColor());
1186 }
1187 
1188 
1189 
GetLineStyleState(SfxItemSet & rSet)1190 void SwFrameShell::GetLineStyleState(SfxItemSet &rSet)
1191 {
1192 	SwWrtShell &rSh = GetShell();
1193 	sal_Bool bParentCntProt = rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
1194 
1195 	if (bParentCntProt)
1196 	{
1197 		if (rSh.IsFrmSelected())
1198 			rSet.DisableItem( SID_FRAME_LINECOLOR );
1199 
1200 		rSet.DisableItem( SID_ATTR_BORDER );
1201 		rSet.DisableItem( SID_FRAME_LINESTYLE );
1202 	}
1203 	else
1204 	{
1205 		if (rSh.IsFrmSelected())
1206 		{
1207 			SfxItemSet aFrameSet( rSh.GetAttrPool(), RES_BOX, RES_BOX );
1208 
1209 			rSh.GetFlyFrmAttr(aFrameSet);
1210 
1211 			const SvxBorderLine* pLine = ((const SvxBoxItem&)aFrameSet.Get(RES_BOX)).GetTop();
1212 			rSet.Put(SvxColorItem(pLine ? pLine->GetColor() : Color(), SID_FRAME_LINECOLOR));
1213 		}
1214 	}
1215 }
1216 
StateInsert(SfxItemSet & rSet)1217 void  SwFrameShell::StateInsert(SfxItemSet &rSet)
1218 {
1219     const int nSel = GetShell().GetSelectionType();
1220     if ( (nSel & nsSelectionType::SEL_GRF)
1221         || (nSel & nsSelectionType::SEL_OLE) )
1222     {
1223         rSet.DisableItem(FN_INSERT_FRAME);
1224     }
1225     else if ( GetShell().CrsrInsideInputFld() )
1226     {
1227         rSet.DisableItem(FN_INSERT_FRAME);
1228     }
1229 }
1230