xref: /aoo42x/main/sw/source/ui/shells/drawsh.cxx (revision f120fe41)
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 <sfx2/sidebar/EnumContext.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         case SID_FLIP_HORIZONTAL:
174 			bMirror = sal_False;
175 			/* no break */
176         case FN_FLIP_VERT_GRAFIC:
177         case SID_FLIP_VERTICAL:
178 			rSh.MirrorSelection( bMirror );
179 			break;
180 
181 		case SID_FONTWORK:
182 		{
183             FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &rSh.GetView()));
184             SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
185             SfxViewFrame* pVFrame = GetView().GetViewFrame();
186 			if (pArgs)
187 			{
188 				pVFrame->SetChildWindow(SvxFontWorkChildWindow::GetChildWindowId(),
189 					((const SfxBoolItem&)(pArgs->Get(SID_FONTWORK))).GetValue());
190 			}
191 			else
192 				pVFrame->ToggleChildWindow( SvxFontWorkChildWindow::GetChildWindowId() );
193 			pVFrame->GetBindings().Invalidate(SID_FONTWORK);
194 		}
195 		break;
196 		case FN_FORMAT_FOOTNOTE_DLG:
197 		{
198             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
199             DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
200 
201             VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( GetView().GetWindow(), GetView().GetWrtShell(), DLG_DOC_FOOTNOTE );
202             DBG_ASSERT(pDlg, "Dialogdiet fail!");
203 			pDlg->Execute();
204 			delete pDlg;
205 			break;
206 		}
207 		case FN_NUMBERING_OUTLINE_DLG:
208 		{
209 			SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
210 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
211             DBG_ASSERT(pFact, "Dialogdiet fail!");
212             SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
213 														GetView().GetWindow(), &aTmp, GetView().GetWrtShell());
214             DBG_ASSERT(pDlg, "Dialogdiet fail!");
215 			pDlg->Execute();
216 			delete pDlg;
217 			rReq.Done();
218 		}
219 		break;
220 		case SID_OPEN_XML_FILTERSETTINGS:
221 		{
222 			try
223 			{
224 				uno::Reference < ui::dialogs::XExecutableDialog > xDialog(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.comp.ui.XSLTFilterDialog")), uno::UNO_QUERY);
225 				if( xDialog.is() )
226 				{
227 					xDialog->execute();
228 				}
229 			}
230 			catch( uno::Exception& )
231 			{
232 			}
233 			rReq.Ignore ();
234 		}
235 		break;
236 		case FN_WORDCOUNT_DIALOG:
237 		{
238 			SwDocStat aCurr;
239 			SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
240 			{
241 				SwWait aWait( *GetView().GetDocShell(), sal_True );
242 				rSh.StartAction();
243 				rSh.CountWords( aCurr );
244 				rSh.UpdateDocStat( aDocStat );
245 				rSh.EndAction();
246 			}
247 
248 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
249 			DBG_ASSERT(pFact, "Dialogdiet fail!");
250 			AbstractSwWordCountDialog* pDialog = pFact->CreateSwWordCountDialog( GetView().GetWindow() );
251 			pDialog->SetValues(aCurr, aDocStat );
252 			pDialog->Execute();
253 			delete pDialog;
254 		}
255 		break;
256 		case SID_EXTRUSION_TOOGLE:
257 		case SID_EXTRUSION_TILT_DOWN:
258 		case SID_EXTRUSION_TILT_UP:
259 		case SID_EXTRUSION_TILT_LEFT:
260 		case SID_EXTRUSION_TILT_RIGHT:
261 		case SID_EXTRUSION_3D_COLOR:
262 		case SID_EXTRUSION_DEPTH:
263 		case SID_EXTRUSION_DIRECTION:
264 		case SID_EXTRUSION_PROJECTION:
265 		case SID_EXTRUSION_LIGHTING_DIRECTION:
266 		case SID_EXTRUSION_LIGHTING_INTENSITY:
267 		case SID_EXTRUSION_SURFACE:
268 		case SID_EXTRUSION_DEPTH_FLOATER:
269 		case SID_EXTRUSION_DIRECTION_FLOATER:
270 		case SID_EXTRUSION_LIGHTING_FLOATER:
271 		case SID_EXTRUSION_SURFACE_FLOATER:
272 		case SID_EXTRUSION_DEPTH_DIALOG:
273 			svx::ExtrusionBar::execute( pSdrView, rReq, rBnd );
274 			rReq.Ignore ();
275 			break;
276 
277 		case SID_FONTWORK_SHAPE:
278 		case SID_FONTWORK_SHAPE_TYPE:
279 		case SID_FONTWORK_ALIGNMENT:
280 		case SID_FONTWORK_SAME_LETTER_HEIGHTS:
281 		case SID_FONTWORK_CHARACTER_SPACING:
282 		case SID_FONTWORK_KERN_CHARACTER_PAIRS:
283 		case SID_FONTWORK_CHARACTER_SPACING_FLOATER:
284 		case SID_FONTWORK_ALIGNMENT_FLOATER:
285 		case SID_FONTWORK_CHARACTER_SPACING_DIALOG:
286 			svx::FontworkBar::execute( pSdrView, rReq, rBnd );
287 			rReq.Ignore ();
288 			break;
289 
290 		default:
291 			DBG_ASSERT(!this, "falscher Dispatcher");
292 			return;
293 	}
294 	if (pSdrView->GetModel()->IsChanged())
295 		rSh.SetModified();
296 	else if (bChanged)
297 		pSdrView->GetModel()->SetChanged(sal_True);
298 }
299 
300 /*--------------------------------------------------------------------
301 	Beschreibung:
302  --------------------------------------------------------------------*/
303 
304 
305 
306 void SwDrawShell::GetState(SfxItemSet& rSet)
307 {
308 	SwWrtShell &rSh = GetShell();
309 	SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
310 	SfxWhichIter aIter( rSet );
311 	sal_uInt16 nWhich = aIter.FirstWhich();
312 	sal_Bool bProtected = rSh.IsSelObjProtected(FLYPROTECT_CONTENT);
313 
314 	if (!bProtected)	// Im Parent nachsehen
315 		bProtected |= rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
316 
317 	while( nWhich )
318 	{
319 		switch( nWhich )
320 		{
321 			case SID_OBJECT_HELL:
322 				if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 0 || bProtected )
323 					rSet.DisableItem( nWhich );
324 				break;
325 
326 			case SID_OBJECT_HEAVEN:
327 				if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 1 || bProtected )
328 					rSet.DisableItem( nWhich );
329 				break;
330 
331 			case FN_TOOL_HIERARCHIE:
332 				if ( !rSh.IsObjSelected() || bProtected )
333 					rSet.DisableItem( nWhich );
334 				break;
335 
336 			case SID_OBJECT_ROTATE:
337 			{
338 				const sal_Bool bIsRotate = GetView().IsDrawRotate();
339 				if ( (!bIsRotate && !pSdrView->IsRotateAllowed()) || bProtected )
340 					rSet.DisableItem( nWhich );
341 				else
342 					rSet.Put( SfxBoolItem( nWhich, bIsRotate ) );
343 			}
344 			break;
345 
346 			case SID_BEZIER_EDIT:
347 				if (!Disable(rSet, nWhich))
348 					rSet.Put( SfxBoolItem( nWhich, !GetView().IsDrawSelMode()));
349 			break;
350 
351 			case FN_FLIP_HORZ_GRAFIC:
352             case SID_FLIP_HORIZONTAL:
353 				if ( !pSdrView->IsMirrorAllowed() || bProtected )
354 					rSet.DisableItem( nWhich );
355 				break;
356 
357 			case FN_FLIP_VERT_GRAFIC:
358             case SID_FLIP_VERTICAL:
359 				if ( !pSdrView->IsMirrorAllowed() || bProtected )
360 					rSet.DisableItem( nWhich );
361 				break;
362 
363 			case SID_FONTWORK:
364 			{
365 				if (bProtected)
366 					rSet.DisableItem( nWhich );
367 				else
368 				{
369 					const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
370 					rSet.Put(SfxBoolItem( nWhich , GetView().GetViewFrame()->HasChildWindow(nId)));
371 				}
372 			}
373 			break;
374 		}
375 		nWhich = aIter.NextWhich();
376 	}
377 	svx::ExtrusionBar::getState( pSdrView, rSet );
378 	svx::FontworkBar::getState( pSdrView, rSet );
379 }
380 
381 /*--------------------------------------------------------------------
382 	Beschreibung:
383  --------------------------------------------------------------------*/
384 
385 
386 
387 SwDrawShell::SwDrawShell(SwView &_rView) :
388     SwDrawBaseShell(_rView)
389 {
390 	SetHelpId(SW_DRAWSHELL);
391 	SetName(String::CreateFromAscii("Draw"));
392 
393     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Draw));
394 }
395 
396 /*************************************************************************
397 |*
398 |* SfxRequests fuer FontWork bearbeiten
399 |*
400 \************************************************************************/
401 
402 
403 
404 void SwDrawShell::ExecFormText(SfxRequest& rReq)
405 {
406 	SwWrtShell &rSh = GetShell();
407 	SdrView*	pDrView = rSh.GetDrawView();
408 	sal_Bool		bChanged = pDrView->GetModel()->IsChanged();
409 	pDrView->GetModel()->SetChanged(sal_False);
410 
411 	const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
412 
413 	if ( rMarkList.GetMarkCount() == 1 && rReq.GetArgs() )
414 	{
415 		const SfxItemSet& rSet = *rReq.GetArgs();
416 		const SfxPoolItem* pItem;
417 
418 		if ( pDrView->IsTextEdit() )
419 		{
420 			pDrView->SdrEndTextEdit( sal_True );
421 			GetView().AttrChangedNotify(&rSh);
422 		}
423 
424 		if ( rSet.GetItemState(XATTR_FORMTXTSTDFORM, sal_True, &pItem) ==
425 			 SFX_ITEM_SET &&
426 			((const XFormTextStdFormItem*) pItem)->GetValue() != XFTFORM_NONE )
427 		{
428 
429 			const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
430 
431 			SvxFontWorkDialog* pDlg = (SvxFontWorkDialog*)(GetView().GetViewFrame()->
432 										GetChildWindow(nId)->GetWindow());
433 
434 			pDlg->CreateStdFormObj(*pDrView, *pDrView->GetSdrPageView(),
435 									rSet, *rMarkList.GetMark(0)->GetMarkedSdrObj(),
436 								   ((const XFormTextStdFormItem*) pItem)->
437 								   GetValue());
438 
439 		}
440 		else
441 			pDrView->SetAttributes(rSet);
442 	}
443 	if (pDrView->GetModel()->IsChanged())
444 		rSh.SetModified();
445 	else
446 		if (bChanged)
447 			pDrView->GetModel()->SetChanged(sal_True);
448 }
449 
450 /*************************************************************************
451 |*
452 |* Statuswerte fuer FontWork zurueckgeben
453 |*
454 \************************************************************************/
455 
456 
457 
458 void SwDrawShell::GetFormTextState(SfxItemSet& rSet)
459 {
460 	SwWrtShell &rSh = GetShell();
461 	SdrView* pDrView = rSh.GetDrawView();
462 	const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
463 	const SdrObject* pObj = NULL;
464 	SvxFontWorkDialog* pDlg = NULL;
465 
466 	const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
467 
468 	SfxViewFrame* pVFrame = GetView().GetViewFrame();
469 	if ( pVFrame->HasChildWindow(nId) )
470 		pDlg = (SvxFontWorkDialog*)(pVFrame->GetChildWindow(nId)->GetWindow());
471 
472 	if ( rMarkList.GetMarkCount() == 1 )
473 		pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
474 
475 	if ( pObj == NULL || !pObj->ISA(SdrTextObj) ||
476 		!((SdrTextObj*) pObj)->HasText() )
477 	{
478 #define	XATTR_ANZ 12
479 		static const sal_uInt16 nXAttr[ XATTR_ANZ ] =
480 		{
481 			XATTR_FORMTXTSTYLE, XATTR_FORMTXTADJUST, XATTR_FORMTXTDISTANCE,
482 			XATTR_FORMTXTSTART, XATTR_FORMTXTMIRROR, XATTR_FORMTXTSTDFORM,
483 			XATTR_FORMTXTHIDEFORM, XATTR_FORMTXTOUTLINE, XATTR_FORMTXTSHADOW,
484 			XATTR_FORMTXTSHDWCOLOR, XATTR_FORMTXTSHDWXVAL, XATTR_FORMTXTSHDWYVAL
485 		};
486 		for( sal_uInt16 i = 0; i < XATTR_ANZ; )
487 			rSet.DisableItem( nXAttr[ i++ ] );
488 	}
489 	else
490 	{
491 		if ( pDlg )
492 			pDlg->SetColorTable(XColorTable::GetStdColorTable());
493 
494 		pDrView->GetAttributes( rSet );
495 	}
496 }
497