bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / shells / drawsh.cxx
blob36c758a0bf2d712db15848c067cd189d5ded1303
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/shl.hxx>
21 #include <svx/svdview.hxx>
22 #include <svx/svdotext.hxx>
23 #include <svl/whiter.hxx>
24 #include <svx/fontwork.hxx>
25 #include <sfx2/request.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/objface.hxx>
28 #include <svl/itemiter.hxx>
29 #include <svl/srchitem.hxx>
30 #include <svx/xftsfit.hxx>
31 #include <svx/extrusionbar.hxx>
32 #include <svx/fontworkbar.hxx>
33 #include <svx/tbxcustomshapes.hxx>
34 #include <uitool.hxx>
35 #include <wview.hxx>
36 #include <swmodule.hxx>
37 #include <swwait.hxx>
38 #include <docstat.hxx>
39 #include <IDocumentStatistics.hxx>
40 #include <tools/diagnose_ex.h>
42 #include <comphelper/processfactory.hxx>
43 #include <com/sun/star/ui/dialogs/XSLTFilterDialog.hpp>
45 #include <svx/xtable.hxx>
46 #include <sfx2/sidebar/EnumContext.hxx>
47 #include <svx/svdoashp.hxx>
49 #include "swundo.hxx"
50 #include "wrtsh.hxx"
51 #include "cmdid.h"
52 #include "globals.hrc"
53 #include "helpid.h"
54 #include "popup.hrc"
55 #include "shells.hrc"
56 #include "drwbassh.hxx"
57 #include "drawsh.hxx"
59 #define SwDrawShell
60 #include <sfx2/msg.hxx>
61 #include "swslots.hxx"
62 #include "swabstdlg.hxx"
63 #include <wordcountdialog.hxx>
64 #include "misc.hrc"
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star::uno;
69 SFX_IMPL_INTERFACE(SwDrawShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAW))
71 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAW_POPUPMENU));
72 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_DRAW_TOOLBOX));
73 SFX_CHILDWINDOW_REGISTRATION(SvxFontWorkChildWindow::GetChildWindowId());
76 TYPEINIT1(SwDrawShell,SwDrawBaseShell)
78 void SwDrawShell::Execute(SfxRequest &rReq)
80 SwWrtShell &rSh = GetShell();
81 SdrView *pSdrView = rSh.GetDrawView();
82 const SfxItemSet *pArgs = rReq.GetArgs();
83 SfxBindings &rBnd = GetView().GetViewFrame()->GetBindings();
84 sal_uInt16 nSlotId = rReq.GetSlot();
85 sal_Bool bChanged = pSdrView->GetModel()->IsChanged();
87 pSdrView->GetModel()->SetChanged(sal_False);
89 const SfxPoolItem* pItem;
90 if(pArgs)
91 pArgs->GetItemState(nSlotId, sal_False, &pItem);
93 bool bMirror = true;
95 switch (nSlotId)
97 case SID_OBJECT_ROTATE:
98 if (rSh.IsObjSelected() && pSdrView->IsRotateAllowed())
100 if (GetView().IsDrawRotate())
101 rSh.SetDragMode(SDRDRAG_MOVE);
102 else
103 rSh.SetDragMode(SDRDRAG_ROTATE);
105 GetView().FlipDrawRotate();
107 break;
109 case SID_BEZIER_EDIT:
110 if (GetView().IsDrawRotate())
112 rSh.SetDragMode(SDRDRAG_MOVE);
113 GetView().FlipDrawRotate();
115 GetView().FlipDrawSelMode();
116 pSdrView->SetFrameDragSingles(GetView().IsDrawSelMode());
117 GetView().AttrChangedNotify(&rSh); // Shell switch
118 break;
120 case SID_OBJECT_HELL:
121 if (rSh.IsObjSelected())
123 rSh.StartUndo( UNDO_START );
124 SetWrapMode(FN_FRAME_WRAPTHRU_TRANSP);
125 rSh.SelectionToHell();
126 rSh.EndUndo( UNDO_END );
127 rBnd.Invalidate(SID_OBJECT_HEAVEN);
129 break;
131 case SID_OBJECT_HEAVEN:
132 if (rSh.IsObjSelected())
134 rSh.StartUndo( UNDO_START );
135 SetWrapMode(FN_FRAME_WRAPTHRU);
136 rSh.SelectionToHeaven();
137 rSh.EndUndo( UNDO_END );
138 rBnd.Invalidate(SID_OBJECT_HELL);
140 break;
142 case FN_TOOL_HIERARCHIE:
143 if (rSh.IsObjSelected())
145 rSh.StartUndo( UNDO_START );
146 if (rSh.GetLayerId() == 0)
148 SetWrapMode(FN_FRAME_WRAPTHRU);
149 rSh.SelectionToHeaven();
151 else
153 SetWrapMode(FN_FRAME_WRAPTHRU_TRANSP);
154 rSh.SelectionToHell();
156 rSh.EndUndo( UNDO_END );
157 rBnd.Invalidate( SID_OBJECT_HELL );
158 rBnd.Invalidate( SID_OBJECT_HEAVEN );
160 break;
162 case SID_FLIP_VERTICAL:
163 bMirror = false;
164 /* no break */
165 case SID_FLIP_HORIZONTAL:
166 rSh.MirrorSelection( bMirror );
167 break;
169 case SID_FONTWORK:
171 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &rSh.GetView()));
172 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
173 SfxViewFrame* pVFrame = GetView().GetViewFrame();
174 if (pArgs)
176 pVFrame->SetChildWindow(SvxFontWorkChildWindow::GetChildWindowId(),
177 ((const SfxBoolItem&)(pArgs->Get(SID_FONTWORK))).GetValue());
179 else
180 pVFrame->ToggleChildWindow( SvxFontWorkChildWindow::GetChildWindowId() );
181 pVFrame->GetBindings().Invalidate(SID_FONTWORK);
183 break;
184 case FN_FORMAT_FOOTNOTE_DLG:
186 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
187 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
189 VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( GetView().GetWindow(), GetView().GetWrtShell(), DLG_DOC_FOOTNOTE );
190 OSL_ENSURE(pDlg, "Dialogdiet fail!");
191 pDlg->Execute();
192 delete pDlg;
193 break;
195 case FN_NUMBERING_OUTLINE_DLG:
197 SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
198 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
199 OSL_ENSURE(pFact, "Dialogdiet fail!");
200 SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
201 GetView().GetWindow(), &aTmp, GetView().GetWrtShell());
202 OSL_ENSURE(pDlg, "Dialogdiet fail!");
203 pDlg->Execute();
204 delete pDlg;
205 rReq.Done();
207 break;
208 case SID_OPEN_XML_FILTERSETTINGS:
212 uno::Reference < ui::dialogs::XExecutableDialog > xDialog = ui::dialogs::XSLTFilterDialog::create( ::comphelper::getProcessComponentContext() );
213 xDialog->execute();
215 catch (const uno::Exception&)
217 DBG_UNHANDLED_EXCEPTION();
219 rReq.Ignore ();
221 break;
222 case FN_WORDCOUNT_DIALOG:
224 SfxViewFrame* pVFrame = GetView().GetViewFrame();
225 if (pVFrame != NULL)
227 pVFrame->ToggleChildWindow(FN_WORDCOUNT_DIALOG);
228 Invalidate(rReq.GetSlot());
230 SwWordCountWrapper *pWrdCnt = (SwWordCountWrapper*)pVFrame->GetChildWindow(SwWordCountWrapper::GetChildWindowId());
231 if (pWrdCnt)
232 pWrdCnt->UpdateCounts();
235 break;
236 case SID_EXTRUSION_TOOGLE:
237 case SID_EXTRUSION_TILT_DOWN:
238 case SID_EXTRUSION_TILT_UP:
239 case SID_EXTRUSION_TILT_LEFT:
240 case SID_EXTRUSION_TILT_RIGHT:
241 case SID_EXTRUSION_3D_COLOR:
242 case SID_EXTRUSION_DEPTH:
243 case SID_EXTRUSION_DIRECTION:
244 case SID_EXTRUSION_PROJECTION:
245 case SID_EXTRUSION_LIGHTING_DIRECTION:
246 case SID_EXTRUSION_LIGHTING_INTENSITY:
247 case SID_EXTRUSION_SURFACE:
248 case SID_EXTRUSION_DEPTH_FLOATER:
249 case SID_EXTRUSION_DIRECTION_FLOATER:
250 case SID_EXTRUSION_LIGHTING_FLOATER:
251 case SID_EXTRUSION_SURFACE_FLOATER:
252 case SID_EXTRUSION_DEPTH_DIALOG:
253 svx::ExtrusionBar::execute( pSdrView, rReq, rBnd );
254 rReq.Ignore ();
255 break;
257 case SID_FONTWORK_SHAPE:
258 case SID_FONTWORK_SHAPE_TYPE:
259 case SID_FONTWORK_ALIGNMENT:
260 case SID_FONTWORK_SAME_LETTER_HEIGHTS:
261 case SID_FONTWORK_CHARACTER_SPACING:
262 case SID_FONTWORK_KERN_CHARACTER_PAIRS:
263 case SID_FONTWORK_CHARACTER_SPACING_FLOATER:
264 case SID_FONTWORK_ALIGNMENT_FLOATER:
265 case SID_FONTWORK_CHARACTER_SPACING_DIALOG:
266 svx::FontworkBar::execute( pSdrView, rReq, rBnd );
267 rReq.Ignore ();
268 break;
270 default:
271 OSL_ENSURE(!this, "wrong dispatcher");
272 return;
274 if (pSdrView->GetModel()->IsChanged())
275 rSh.SetModified();
276 else if (bChanged)
277 pSdrView->GetModel()->SetChanged(sal_True);
280 void SwDrawShell::GetState(SfxItemSet& rSet)
282 SwWrtShell &rSh = GetShell();
283 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
284 SfxWhichIter aIter( rSet );
285 sal_uInt16 nWhich = aIter.FirstWhich();
286 sal_Bool bProtected = rSh.IsSelObjProtected(FLYPROTECT_CONTENT);
288 if (!bProtected) // Check the parent
289 bProtected |= rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
291 while( nWhich )
293 switch( nWhich )
295 case SID_OBJECT_HELL:
296 if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 0 || bProtected )
297 rSet.DisableItem( nWhich );
298 break;
300 case SID_OBJECT_HEAVEN:
301 if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 1 || bProtected )
302 rSet.DisableItem( nWhich );
303 break;
305 case FN_TOOL_HIERARCHIE:
306 if ( !rSh.IsObjSelected() || bProtected )
307 rSet.DisableItem( nWhich );
308 break;
310 case SID_OBJECT_ROTATE:
312 const sal_Bool bIsRotate = GetView().IsDrawRotate();
313 if ( (!bIsRotate && !pSdrView->IsRotateAllowed()) || bProtected )
314 rSet.DisableItem( nWhich );
315 else
316 rSet.Put( SfxBoolItem( nWhich, bIsRotate ) );
318 break;
320 case SID_BEZIER_EDIT:
321 if (!Disable(rSet, nWhich))
322 rSet.Put( SfxBoolItem( nWhich, !GetView().IsDrawSelMode()));
323 break;
325 case SID_FLIP_VERTICAL:
326 if ( !pSdrView->IsMirrorAllowed() || bProtected )
328 rSet.DisableItem( nWhich );
330 else
332 // TTTT - needs to be adapted in aw080:
333 // state is not kept for drawing objects --> provide not flipped state
334 rSet.Put( SfxBoolItem( nWhich, sal_False ) );
336 break;
338 case SID_FLIP_HORIZONTAL:
339 if ( !pSdrView->IsMirrorAllowed() || bProtected )
341 rSet.DisableItem( nWhich );
343 else
345 // TTTT - needs to be adapted in aw080:
346 // state is not kept for drawing objects --> provide not flipped state
347 rSet.Put( SfxBoolItem( nWhich, sal_False ) );
349 break;
351 case SID_FONTWORK:
353 if (bProtected)
354 rSet.DisableItem( nWhich );
355 else
357 const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
358 rSet.Put(SfxBoolItem( nWhich , GetView().GetViewFrame()->HasChildWindow(nId)));
361 break;
363 nWhich = aIter.NextWhich();
365 svx::ExtrusionBar::getState( pSdrView, rSet );
366 svx::FontworkBar::getState( pSdrView, rSet );
369 SwDrawShell::SwDrawShell(SwView &_rView) :
370 SwDrawBaseShell(_rView)
372 SetHelpId(SW_DRAWSHELL);
373 SetName(OUString("Draw"));
375 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Draw));
378 // Edit SfxRequests for FontWork
380 void SwDrawShell::ExecFormText(SfxRequest& rReq)
382 SwWrtShell &rSh = GetShell();
383 SdrView* pDrView = rSh.GetDrawView();
384 sal_Bool bChanged = pDrView->GetModel()->IsChanged();
385 pDrView->GetModel()->SetChanged(sal_False);
387 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
389 if ( rMarkList.GetMarkCount() == 1 && rReq.GetArgs() )
391 const SfxItemSet& rSet = *rReq.GetArgs();
392 const SfxPoolItem* pItem;
394 if ( pDrView->IsTextEdit() )
396 pDrView->SdrEndTextEdit( sal_True );
397 GetView().AttrChangedNotify(&rSh);
400 if ( rSet.GetItemState(XATTR_FORMTXTSTDFORM, sal_True, &pItem) ==
401 SFX_ITEM_SET &&
402 ((const XFormTextStdFormItem*) pItem)->GetValue() != XFTFORM_NONE )
405 const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
407 SvxFontWorkDialog* pDlg = (SvxFontWorkDialog*)(GetView().GetViewFrame()->
408 GetChildWindow(nId)->GetWindow());
410 pDlg->CreateStdFormObj(*pDrView, *pDrView->GetSdrPageView(),
411 rSet, *rMarkList.GetMark(0)->GetMarkedSdrObj(),
412 ((const XFormTextStdFormItem*) pItem)->
413 GetValue());
416 else
417 pDrView->SetAttributes(rSet);
419 if (pDrView->GetModel()->IsChanged())
420 rSh.SetModified();
421 else
422 if (bChanged)
423 pDrView->GetModel()->SetChanged(sal_True);
426 //Return status values for FontWork
428 void SwDrawShell::GetFormTextState(SfxItemSet& rSet)
430 SwWrtShell &rSh = GetShell();
431 SdrView* pDrView = rSh.GetDrawView();
432 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
433 const SdrObject* pObj = NULL;
434 SvxFontWorkDialog* pDlg = NULL;
436 const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
438 SfxViewFrame* pVFrame = GetView().GetViewFrame();
439 if ( pVFrame->HasChildWindow(nId) )
440 pDlg = (SvxFontWorkDialog*)(pVFrame->GetChildWindow(nId)->GetWindow());
442 if ( rMarkList.GetMarkCount() == 1 )
443 pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
445 if ( pObj == NULL || !pObj->ISA(SdrTextObj) ||
446 !((SdrTextObj*) pObj)->HasText() )
448 #define XATTR_ANZ 12
449 static const sal_uInt16 nXAttr[ XATTR_ANZ ] =
451 XATTR_FORMTXTSTYLE, XATTR_FORMTXTADJUST, XATTR_FORMTXTDISTANCE,
452 XATTR_FORMTXTSTART, XATTR_FORMTXTMIRROR, XATTR_FORMTXTSTDFORM,
453 XATTR_FORMTXTHIDEFORM, XATTR_FORMTXTOUTLINE, XATTR_FORMTXTSHADOW,
454 XATTR_FORMTXTSHDWCOLOR, XATTR_FORMTXTSHDWXVAL, XATTR_FORMTXTSHDWYVAL
456 for( sal_uInt16 i = 0; i < XATTR_ANZ; )
457 rSet.DisableItem( nXAttr[ i++ ] );
459 else
461 if ( pDlg )
462 pDlg->SetColorList(XColorList::GetStdColorList());
464 pDrView->GetAttributes( rSet );
468 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */