1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
36 #include <swmodule.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>
52 #include "globals.hrc"
56 #include "drwbassh.hxx"
60 #include <sfx2/msg.hxx>
61 #include "swslots.hxx"
62 #include "swabstdlg.hxx"
63 #include <wordcountdialog.hxx>
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
;
91 pArgs
->GetItemState(nSlotId
, sal_False
, &pItem
);
97 case SID_OBJECT_ROTATE
:
98 if (rSh
.IsObjSelected() && pSdrView
->IsRotateAllowed())
100 if (GetView().IsDrawRotate())
101 rSh
.SetDragMode(SDRDRAG_MOVE
);
103 rSh
.SetDragMode(SDRDRAG_ROTATE
);
105 GetView().FlipDrawRotate();
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
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
);
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
);
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();
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
);
162 case SID_FLIP_VERTICAL
:
165 case SID_FLIP_HORIZONTAL
:
166 rSh
.MirrorSelection( bMirror
);
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();
176 pVFrame
->SetChildWindow(SvxFontWorkChildWindow::GetChildWindowId(),
177 ((const SfxBoolItem
&)(pArgs
->Get(SID_FONTWORK
))).GetValue());
180 pVFrame
->ToggleChildWindow( SvxFontWorkChildWindow::GetChildWindowId() );
181 pVFrame
->GetBindings().Invalidate(SID_FONTWORK
);
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!");
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!");
208 case SID_OPEN_XML_FILTERSETTINGS
:
212 uno::Reference
< ui::dialogs::XExecutableDialog
> xDialog
= ui::dialogs::XSLTFilterDialog::create( ::comphelper::getProcessComponentContext() );
215 catch (const uno::Exception
&)
217 DBG_UNHANDLED_EXCEPTION();
222 case FN_WORDCOUNT_DIALOG
:
224 SfxViewFrame
* pVFrame
= GetView().GetViewFrame();
227 pVFrame
->ToggleChildWindow(FN_WORDCOUNT_DIALOG
);
228 Invalidate(rReq
.GetSlot());
230 SwWordCountWrapper
*pWrdCnt
= (SwWordCountWrapper
*)pVFrame
->GetChildWindow(SwWordCountWrapper::GetChildWindowId());
232 pWrdCnt
->UpdateCounts();
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
);
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
);
271 OSL_ENSURE(!this, "wrong dispatcher");
274 if (pSdrView
->GetModel()->IsChanged())
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;
295 case SID_OBJECT_HELL
:
296 if ( !rSh
.IsObjSelected() || rSh
.GetLayerId() == 0 || bProtected
)
297 rSet
.DisableItem( nWhich
);
300 case SID_OBJECT_HEAVEN
:
301 if ( !rSh
.IsObjSelected() || rSh
.GetLayerId() == 1 || bProtected
)
302 rSet
.DisableItem( nWhich
);
305 case FN_TOOL_HIERARCHIE
:
306 if ( !rSh
.IsObjSelected() || bProtected
)
307 rSet
.DisableItem( nWhich
);
310 case SID_OBJECT_ROTATE
:
312 const sal_Bool bIsRotate
= GetView().IsDrawRotate();
313 if ( (!bIsRotate
&& !pSdrView
->IsRotateAllowed()) || bProtected
)
314 rSet
.DisableItem( nWhich
);
316 rSet
.Put( SfxBoolItem( nWhich
, bIsRotate
) );
320 case SID_BEZIER_EDIT
:
321 if (!Disable(rSet
, nWhich
))
322 rSet
.Put( SfxBoolItem( nWhich
, !GetView().IsDrawSelMode()));
325 case SID_FLIP_VERTICAL
:
326 if ( !pSdrView
->IsMirrorAllowed() || bProtected
)
328 rSet
.DisableItem( nWhich
);
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
) );
338 case SID_FLIP_HORIZONTAL
:
339 if ( !pSdrView
->IsMirrorAllowed() || bProtected
)
341 rSet
.DisableItem( nWhich
);
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
) );
354 rSet
.DisableItem( nWhich
);
357 const sal_uInt16 nId
= SvxFontWorkChildWindow::GetChildWindowId();
358 rSet
.Put(SfxBoolItem( nWhich
, GetView().GetViewFrame()->HasChildWindow(nId
)));
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
) ==
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
)->
417 pDrView
->SetAttributes(rSet
);
419 if (pDrView
->GetModel()->IsChanged())
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() )
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
++ ] );
462 pDlg
->SetColorList(XColorList::GetStdColorList());
464 pDrView
->GetAttributes( rSet
);
468 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */