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