xref: /trunk/main/sw/source/ui/shells/drawsh.cxx (revision ef076a15)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <tools/shl.hxx>
29 #include <svx/svdview.hxx>
30 #include <svx/svdotext.hxx>
31 #include <svl/whiter.hxx>
32 #include <svx/fontwork.hxx>
33 #include <sfx2/request.hxx>
34 #include <sfx2/bindings.hxx>
35 #include <sfx2/objface.hxx>
36 #include <svl/itemiter.hxx>
37 #include <svl/srchitem.hxx>
38 #include <svx/xftsfit.hxx>
39 #include <svx/extrusionbar.hxx>
40 #include <svx/fontworkbar.hxx>
41 #include <svx/tbxcustomshapes.hxx>
42 #include <uitool.hxx>
43 #include <wview.hxx>
44 #include <swmodule.hxx>
45 #include <swwait.hxx>
46 #include <docstat.hxx>
47 #include <IDocumentStatistics.hxx>
48 
49 #include <comphelper/processfactory.hxx>
50 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
51 
52 #include <svx/xtable.hxx>
53 #include <svx/svdoashp.hxx>
54 
55 #include "swundo.hxx"
56 #include "wrtsh.hxx"
57 #include "cmdid.h"
58 #include "globals.hrc"
59 #include "helpid.h"
60 #include "popup.hrc"
61 #include "shells.hrc"
62 #include "drwbassh.hxx"
63 #include "drawsh.hxx"
64 
65 #define SwDrawShell
66 #include <sfx2/msg.hxx>
67 #include "swslots.hxx"
68 #include "swabstdlg.hxx" //CHINA001
69 #include "misc.hrc"
70 
71 using namespace ::com::sun::star;
72 using namespace ::com::sun::star::uno;
73 
74 SFX_IMPL_INTERFACE(SwDrawShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAW))
75 {
76 	SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAW_POPUPMENU));
77 	SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_DRAW_TOOLBOX));
78 	SFX_CHILDWINDOW_REGISTRATION(SvxFontWorkChildWindow::GetChildWindowId());
79 }
80 
81 TYPEINIT1(SwDrawShell,SwDrawBaseShell)
82 
83 /*--------------------------------------------------------------------
84 	Beschreibung:
85  --------------------------------------------------------------------*/
86 
87 
88 void SwDrawShell::Execute(SfxRequest &rReq)
89 {
90 	SwWrtShell			&rSh = GetShell();
91 	SdrView				*pSdrView = rSh.GetDrawView();
92 	const SfxItemSet	*pArgs = rReq.GetArgs();
93 	SfxBindings			&rBnd  = GetView().GetViewFrame()->GetBindings();
94 	sal_uInt16				 nSlotId = rReq.GetSlot();
95 	sal_Bool				 bChanged = pSdrView->GetModel()->IsChanged();
96 
97 	pSdrView->GetModel()->SetChanged(sal_False);
98 
99 	const SfxPoolItem* pItem;
100 	if(pArgs)
101 		pArgs->GetItemState(nSlotId, sal_False, &pItem);
102 
103     sal_Bool bMirror = sal_True;
104 
105 	switch (nSlotId)
106 	{
107 		case SID_OBJECT_ROTATE:
108 			if (rSh.IsObjSelected() && pSdrView->IsRotateAllowed())
109 			{
110 				if (GetView().IsDrawRotate())
111 					rSh.SetDragMode(SDRDRAG_MOVE);
112 				else
113 					rSh.SetDragMode(SDRDRAG_ROTATE);
114 
115 				GetView().FlipDrawRotate();
116 			}
117 			break;
118 
119 		case SID_BEZIER_EDIT:
120 			if (GetView().IsDrawRotate())
121 			{
122 				rSh.SetDragMode(SDRDRAG_MOVE);
123 				GetView().FlipDrawRotate();
124 			}
125 			GetView().FlipDrawSelMode();
126 			pSdrView->SetFrameDragSingles(GetView().IsDrawSelMode());
127 			GetView().AttrChangedNotify(&rSh); // Shellwechsel...
128 			break;
129 
130 		case SID_OBJECT_HELL:
131 			if (rSh.IsObjSelected())
132 			{
133 				rSh.StartUndo( UNDO_START );
134 				SetWrapMode(FN_FRAME_WRAPTHRU_TRANSP);
135 				rSh.SelectionToHell();
136 				rSh.EndUndo( UNDO_END );
137 				rBnd.Invalidate(SID_OBJECT_HEAVEN);
138 			}
139 			break;
140 
141 		case SID_OBJECT_HEAVEN:
142 			if (rSh.IsObjSelected())
143 			{
144 				rSh.StartUndo( UNDO_START );
145 				SetWrapMode(FN_FRAME_WRAPTHRU);
146 				rSh.SelectionToHeaven();
147 				rSh.EndUndo( UNDO_END );
148 				rBnd.Invalidate(SID_OBJECT_HELL);
149 			}
150 			break;
151 
152 		case FN_TOOL_HIERARCHIE:
153 			if (rSh.IsObjSelected())
154 			{
155 				rSh.StartUndo( UNDO_START );
156 				if (rSh.GetLayerId() == 0)
157 				{
158 					SetWrapMode(FN_FRAME_WRAPTHRU);
159 					rSh.SelectionToHeaven();
160 				}
161 				else
162 				{
163 					SetWrapMode(FN_FRAME_WRAPTHRU_TRANSP);
164 					rSh.SelectionToHell();
165 				}
166 				rSh.EndUndo( UNDO_END );
167                 rBnd.Invalidate( SID_OBJECT_HELL );
168                 rBnd.Invalidate( SID_OBJECT_HEAVEN );
169 			}
170 			break;
171 
172         case FN_FLIP_HORZ_GRAFIC:
173 			bMirror = sal_False;
174 			/* no break */
175         case FN_FLIP_VERT_GRAFIC:
176 			rSh.MirrorSelection( bMirror );
177 			break;
178 
179 		case SID_FONTWORK:
180 		{
181             FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &rSh.GetView()));
182             SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
183             SfxViewFrame* pVFrame = GetView().GetViewFrame();
184 			if (pArgs)
185 			{
186 				pVFrame->SetChildWindow(SvxFontWorkChildWindow::GetChildWindowId(),
187 					((const SfxBoolItem&)(pArgs->Get(SID_FONTWORK))).GetValue());
188 			}
189 			else
190 				pVFrame->ToggleChildWindow( SvxFontWorkChildWindow::GetChildWindowId() );
191 			pVFrame->GetBindings().Invalidate(SID_FONTWORK);
192 		}
193 		break;
194 		case FN_FORMAT_FOOTNOTE_DLG:
195 		{
196             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
197             DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
198 
199             VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( GetView().GetWindow(), GetView().GetWrtShell(), DLG_DOC_FOOTNOTE );
200             DBG_ASSERT(pDlg, "Dialogdiet fail!");
201 			pDlg->Execute();
202 			delete pDlg;
203 			break;
204 		}
205 		case FN_NUMBERING_OUTLINE_DLG:
206 		{
207 			SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
208 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
209             DBG_ASSERT(pFact, "Dialogdiet fail!");
210             SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
211 														GetView().GetWindow(), &aTmp, GetView().GetWrtShell());
212             DBG_ASSERT(pDlg, "Dialogdiet fail!");
213 			pDlg->Execute();
214 			delete pDlg;
215 			rReq.Done();
216 		}
217 		break;
218 		case SID_OPEN_XML_FILTERSETTINGS:
219 		{
220 			try
221 			{
222 				uno::Reference < ui::dialogs::XExecutableDialog > xDialog(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.comp.ui.XSLTFilterDialog")), uno::UNO_QUERY);
223 				if( xDialog.is() )
224 				{
225 					xDialog->execute();
226 				}
227 			}
228 			catch( uno::Exception& )
229 			{
230 			}
231 			rReq.Ignore ();
232 		}
233 		break;
234 		case FN_WORDCOUNT_DIALOG:
235 		{
236 			SwDocStat aCurr;
237 			SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
238 			{
239 				SwWait aWait( *GetView().GetDocShell(), sal_True );
240 				rSh.StartAction();
241 				rSh.CountWords( aCurr );
242 				rSh.UpdateDocStat( aDocStat );
243 				rSh.EndAction();
244 			}
245 
246 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
247 			DBG_ASSERT(pFact, "Dialogdiet fail!");
248 			AbstractSwWordCountDialog* pDialog = pFact->CreateSwWordCountDialog( GetView().GetWindow() );
249 			pDialog->SetValues(aCurr, aDocStat );
250 			pDialog->Execute();
251 			delete pDialog;
252 		}
253 		break;
254 		case SID_EXTRUSION_TOOGLE:
255 		case SID_EXTRUSION_TILT_DOWN:
256 		case SID_EXTRUSION_TILT_UP:
257 		case SID_EXTRUSION_TILT_LEFT:
258 		case SID_EXTRUSION_TILT_RIGHT:
259 		case SID_EXTRUSION_3D_COLOR:
260 		case SID_EXTRUSION_DEPTH:
261 		case SID_EXTRUSION_DIRECTION:
262 		case SID_EXTRUSION_PROJECTION:
263 		case SID_EXTRUSION_LIGHTING_DIRECTION:
264 		case SID_EXTRUSION_LIGHTING_INTENSITY:
265 		case SID_EXTRUSION_SURFACE:
266 		case SID_EXTRUSION_DEPTH_FLOATER:
267 		case SID_EXTRUSION_DIRECTION_FLOATER:
268 		case SID_EXTRUSION_LIGHTING_FLOATER:
269 		case SID_EXTRUSION_SURFACE_FLOATER:
270 		case SID_EXTRUSION_DEPTH_DIALOG:
271 			svx::ExtrusionBar::execute( pSdrView, rReq, rBnd );
272 			rReq.Ignore ();
273 			break;
274 
275 		case SID_FONTWORK_SHAPE:
276 		case SID_FONTWORK_SHAPE_TYPE:
277 		case SID_FONTWORK_ALIGNMENT:
278 		case SID_FONTWORK_SAME_LETTER_HEIGHTS:
279 		case SID_FONTWORK_CHARACTER_SPACING:
280 		case SID_FONTWORK_KERN_CHARACTER_PAIRS:
281 		case SID_FONTWORK_CHARACTER_SPACING_FLOATER:
282 		case SID_FONTWORK_ALIGNMENT_FLOATER:
283 		case SID_FONTWORK_CHARACTER_SPACING_DIALOG:
284 			svx::FontworkBar::execute( pSdrView, rReq, rBnd );
285 			rReq.Ignore ();
286 			break;
287 
288 		default:
289 			DBG_ASSERT(!this, "falscher Dispatcher");
290 			return;
291 	}
292 	if (pSdrView->GetModel()->IsChanged())
293 		rSh.SetModified();
294 	else if (bChanged)
295 		pSdrView->GetModel()->SetChanged(sal_True);
296 }
297 
298 /*--------------------------------------------------------------------
299 	Beschreibung:
300  --------------------------------------------------------------------*/
301 
302 
303 
304 void SwDrawShell::GetState(SfxItemSet& rSet)
305 {
306 	SwWrtShell &rSh = GetShell();
307 	SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
308 	SfxWhichIter aIter( rSet );
309 	sal_uInt16 nWhich = aIter.FirstWhich();
310 	sal_Bool bProtected = rSh.IsSelObjProtected(FLYPROTECT_CONTENT);
311 
312 	if (!bProtected)	// Im Parent nachsehen
313 		bProtected |= rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
314 
315 	while( nWhich )
316 	{
317 		switch( nWhich )
318 		{
319 			case SID_OBJECT_HELL:
320 				if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 0 || bProtected )
321 					rSet.DisableItem( nWhich );
322 				break;
323 
324 			case SID_OBJECT_HEAVEN:
325 				if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 1 || bProtected )
326 					rSet.DisableItem( nWhich );
327 				break;
328 
329 			case FN_TOOL_HIERARCHIE:
330 				if ( !rSh.IsObjSelected() || bProtected )
331 					rSet.DisableItem( nWhich );
332 				break;
333 
334 			case SID_OBJECT_ROTATE:
335 			{
336 				const sal_Bool bIsRotate = GetView().IsDrawRotate();
337 				if ( (!bIsRotate && !pSdrView->IsRotateAllowed()) || bProtected )
338 					rSet.DisableItem( nWhich );
339 				else
340 					rSet.Put( SfxBoolItem( nWhich, bIsRotate ) );
341 			}
342 			break;
343 
344 			case SID_BEZIER_EDIT:
345 				if (!Disable(rSet, nWhich))
346 					rSet.Put( SfxBoolItem( nWhich, !GetView().IsDrawSelMode()));
347 			break;
348 
349 			case FN_FLIP_HORZ_GRAFIC:
350 				if ( !pSdrView->IsMirrorAllowed() || bProtected )
351 					rSet.DisableItem( nWhich );
352 				break;
353 
354 			case FN_FLIP_VERT_GRAFIC:
355 				if ( !pSdrView->IsMirrorAllowed() || bProtected )
356 					rSet.DisableItem( nWhich );
357 				break;
358 
359 			case SID_FONTWORK:
360 			{
361 				if (bProtected)
362 					rSet.DisableItem( nWhich );
363 				else
364 				{
365 					const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
366 					rSet.Put(SfxBoolItem( nWhich , GetView().GetViewFrame()->HasChildWindow(nId)));
367 				}
368 			}
369 			break;
370 		}
371 		nWhich = aIter.NextWhich();
372 	}
373 	svx::ExtrusionBar::getState( pSdrView, rSet );
374 	svx::FontworkBar::getState( pSdrView, rSet );
375 }
376 
377 /*--------------------------------------------------------------------
378 	Beschreibung:
379  --------------------------------------------------------------------*/
380 
381 
382 
383 SwDrawShell::SwDrawShell(SwView &_rView) :
384     SwDrawBaseShell(_rView)
385 {
386 	SetHelpId(SW_DRAWSHELL);
387 	SetName(String::CreateFromAscii("Draw"));
388 }
389 
390 /*************************************************************************
391 |*
392 |* SfxRequests fuer FontWork bearbeiten
393 |*
394 \************************************************************************/
395 
396 
397 
398 void SwDrawShell::ExecFormText(SfxRequest& rReq)
399 {
400 	SwWrtShell &rSh = GetShell();
401 	SdrView*	pDrView = rSh.GetDrawView();
402 	sal_Bool		bChanged = pDrView->GetModel()->IsChanged();
403 	pDrView->GetModel()->SetChanged(sal_False);
404 
405 	const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
406 
407 	if ( rMarkList.GetMarkCount() == 1 && rReq.GetArgs() )
408 	{
409 		const SfxItemSet& rSet = *rReq.GetArgs();
410 		const SfxPoolItem* pItem;
411 
412 		if ( pDrView->IsTextEdit() )
413 		{
414 			pDrView->SdrEndTextEdit( sal_True );
415 			GetView().AttrChangedNotify(&rSh);
416 		}
417 
418 		if ( rSet.GetItemState(XATTR_FORMTXTSTDFORM, sal_True, &pItem) ==
419 			 SFX_ITEM_SET &&
420 			((const XFormTextStdFormItem*) pItem)->GetValue() != XFTFORM_NONE )
421 		{
422 
423 			const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
424 
425 			SvxFontWorkDialog* pDlg = (SvxFontWorkDialog*)(GetView().GetViewFrame()->
426 										GetChildWindow(nId)->GetWindow());
427 
428 			pDlg->CreateStdFormObj(*pDrView, *pDrView->GetSdrPageView(),
429 									rSet, *rMarkList.GetMark(0)->GetMarkedSdrObj(),
430 								   ((const XFormTextStdFormItem*) pItem)->
431 								   GetValue());
432 
433 		}
434 		else
435 			pDrView->SetAttributes(rSet);
436 	}
437 	if (pDrView->GetModel()->IsChanged())
438 		rSh.SetModified();
439 	else
440 		if (bChanged)
441 			pDrView->GetModel()->SetChanged(sal_True);
442 }
443 
444 /*************************************************************************
445 |*
446 |* Statuswerte fuer FontWork zurueckgeben
447 |*
448 \************************************************************************/
449 
450 
451 
452 void SwDrawShell::GetFormTextState(SfxItemSet& rSet)
453 {
454 	SwWrtShell &rSh = GetShell();
455 	SdrView* pDrView = rSh.GetDrawView();
456 	const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
457 	const SdrObject* pObj = NULL;
458 	SvxFontWorkDialog* pDlg = NULL;
459 
460 	const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
461 
462 	SfxViewFrame* pVFrame = GetView().GetViewFrame();
463 	if ( pVFrame->HasChildWindow(nId) )
464 		pDlg = (SvxFontWorkDialog*)(pVFrame->GetChildWindow(nId)->GetWindow());
465 
466 	if ( rMarkList.GetMarkCount() == 1 )
467 		pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
468 
469     const SdrTextObj* pTextObj = dynamic_cast< const SdrTextObj* >(pObj);
470     const bool bDeactivate(
471         !pObj ||
472         !pTextObj ||
473         !pTextObj->HasText() ||
474         dynamic_cast< const SdrObjCustomShape* >(pObj)); // #121538# no FontWork for CustomShapes
475 
476     if(bDeactivate)
477 	{
478         rSet.DisableItem(XATTR_FORMTXTSTYLE);
479         rSet.DisableItem(XATTR_FORMTXTADJUST);
480         rSet.DisableItem(XATTR_FORMTXTDISTANCE);
481         rSet.DisableItem(XATTR_FORMTXTSTART);
482         rSet.DisableItem(XATTR_FORMTXTMIRROR);
483         rSet.DisableItem(XATTR_FORMTXTSTDFORM);
484         rSet.DisableItem(XATTR_FORMTXTHIDEFORM);
485         rSet.DisableItem(XATTR_FORMTXTOUTLINE);
486         rSet.DisableItem(XATTR_FORMTXTSHADOW);
487         rSet.DisableItem(XATTR_FORMTXTSHDWCOLOR);
488         rSet.DisableItem(XATTR_FORMTXTSHDWXVAL);
489         rSet.DisableItem(XATTR_FORMTXTSHDWYVAL);
490 	}
491 	else
492 	{
493 		if ( pDlg )
494 			pDlg->SetColorTable(XColorTable::GetStdColorTable());
495 
496 		pDrView->GetAttributes( rSet );
497 	}
498 }
499 
500 
501 
502 
503