merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / shells / drawsh.cxx
blob9dd27332aa80b908da791e08d09ccf6f64b37bff
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drawsh.cxx,v $
10 * $Revision: 1.20.190.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <tools/shl.hxx>
36 #include <svx/svdview.hxx>
37 #include <svx/svdotext.hxx>
38 #include <svtools/whiter.hxx>
39 #include <svx/fontwork.hxx>
40 #include <sfx2/request.hxx>
41 #include <sfx2/bindings.hxx>
42 #include <sfx2/objface.hxx>
43 #include <svtools/itemiter.hxx>
44 #include <svx/srchitem.hxx>
45 #include <svx/xftsfit.hxx>
46 #include <svx/extrusionbar.hxx>
47 #include <svx/fontworkbar.hxx>
48 #include <svx/tbxcustomshapes.hxx>
49 #include <uitool.hxx>
50 #include <wview.hxx>
51 #include <swmodule.hxx>
52 #include <swwait.hxx>
53 #include <docstat.hxx>
54 #include <IDocumentStatistics.hxx>
56 #include <comphelper/processfactory.hxx>
57 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
59 #include <svx/xtable.hxx>
61 #include "swundo.hxx"
62 #include "wrtsh.hxx"
63 #include "cmdid.h"
64 #include "globals.hrc"
65 #include "helpid.h"
66 #include "popup.hrc"
67 #include "shells.hrc"
68 #include "drwbassh.hxx"
69 #include "drawsh.hxx"
71 #define SwDrawShell
72 #include <sfx2/msg.hxx>
73 #include "swslots.hxx"
74 #include "swabstdlg.hxx" //CHINA001
75 #include "misc.hrc"
77 using namespace ::com::sun::star;
78 using namespace ::com::sun::star::uno;
80 SFX_IMPL_INTERFACE(SwDrawShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAW))
82 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAW_POPUPMENU));
83 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_DRAW_TOOLBOX));
84 SFX_CHILDWINDOW_REGISTRATION(SvxFontWorkChildWindow::GetChildWindowId());
87 TYPEINIT1(SwDrawShell,SwDrawBaseShell)
89 /*--------------------------------------------------------------------
90 Beschreibung:
91 --------------------------------------------------------------------*/
94 void SwDrawShell::Execute(SfxRequest &rReq)
96 SwWrtShell &rSh = GetShell();
97 SdrView *pSdrView = rSh.GetDrawView();
98 const SfxItemSet *pArgs = rReq.GetArgs();
99 SfxBindings &rBnd = GetView().GetViewFrame()->GetBindings();
100 USHORT nSlotId = rReq.GetSlot();
101 BOOL bChanged = pSdrView->GetModel()->IsChanged();
103 pSdrView->GetModel()->SetChanged(FALSE);
105 const SfxPoolItem* pItem;
106 if(pArgs)
107 pArgs->GetItemState(nSlotId, FALSE, &pItem);
109 BOOL bMirror = TRUE;
111 switch (nSlotId)
113 case SID_OBJECT_ROTATE:
114 if (rSh.IsObjSelected() && pSdrView->IsRotateAllowed())
116 if (GetView().IsDrawRotate())
117 rSh.SetDragMode(SDRDRAG_MOVE);
118 else
119 rSh.SetDragMode(SDRDRAG_ROTATE);
121 GetView().FlipDrawRotate();
123 break;
125 case SID_BEZIER_EDIT:
126 if (GetView().IsDrawRotate())
128 rSh.SetDragMode(SDRDRAG_MOVE);
129 GetView().FlipDrawRotate();
131 GetView().FlipDrawSelMode();
132 pSdrView->SetFrameDragSingles(GetView().IsDrawSelMode());
133 GetView().AttrChangedNotify(&rSh); // Shellwechsel...
134 break;
136 case SID_OBJECT_HELL:
137 if (rSh.IsObjSelected())
139 rSh.StartUndo( UNDO_START );
140 SetWrapMode(FN_FRAME_WRAPTHRU_TRANSP);
141 rSh.SelectionToHell();
142 rSh.EndUndo( UNDO_END );
143 rBnd.Invalidate(SID_OBJECT_HEAVEN);
145 break;
147 case SID_OBJECT_HEAVEN:
148 if (rSh.IsObjSelected())
150 rSh.StartUndo( UNDO_START );
151 SetWrapMode(FN_FRAME_WRAPTHRU);
152 rSh.SelectionToHeaven();
153 rSh.EndUndo( UNDO_END );
154 rBnd.Invalidate(SID_OBJECT_HELL);
156 break;
158 case FN_TOOL_HIERARCHIE:
159 if (rSh.IsObjSelected())
161 rSh.StartUndo( UNDO_START );
162 if (rSh.GetLayerId() == 0)
164 SetWrapMode(FN_FRAME_WRAPTHRU);
165 rSh.SelectionToHeaven();
167 else
169 SetWrapMode(FN_FRAME_WRAPTHRU_TRANSP);
170 rSh.SelectionToHell();
172 rSh.EndUndo( UNDO_END );
173 rBnd.Invalidate( SID_OBJECT_HELL );
174 rBnd.Invalidate( SID_OBJECT_HEAVEN );
176 break;
178 case FN_FLIP_HORZ_GRAFIC:
179 bMirror = FALSE;
180 /* no break */
181 case FN_FLIP_VERT_GRAFIC:
182 rSh.MirrorSelection( bMirror );
183 break;
185 case SID_FONTWORK:
187 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &rSh.GetView()));
188 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< UINT16 >(eMetric)) );
189 SfxViewFrame* pVFrame = GetView().GetViewFrame();
190 if (pArgs)
192 pVFrame->SetChildWindow(SvxFontWorkChildWindow::GetChildWindowId(),
193 ((const SfxBoolItem&)(pArgs->Get(SID_FONTWORK))).GetValue());
195 else
196 pVFrame->ToggleChildWindow( SvxFontWorkChildWindow::GetChildWindowId() );
197 pVFrame->GetBindings().Invalidate(SID_FONTWORK);
199 break;
200 case FN_FORMAT_FOOTNOTE_DLG:
202 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
203 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
205 VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( GetView().GetWindow(), GetView().GetWrtShell(), DLG_DOC_FOOTNOTE );
206 DBG_ASSERT(pDlg, "Dialogdiet fail!");
207 pDlg->Execute();
208 delete pDlg;
209 break;
211 case FN_NUMBERING_OUTLINE_DLG:
213 SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
214 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
215 DBG_ASSERT(pFact, "Dialogdiet fail!");
216 SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
217 GetView().GetWindow(), &aTmp, GetView().GetWrtShell());
218 DBG_ASSERT(pDlg, "Dialogdiet fail!");
219 pDlg->Execute();
220 delete pDlg;
221 rReq.Done();
223 break;
224 case SID_OPEN_XML_FILTERSETTINGS:
228 uno::Reference < ui::dialogs::XExecutableDialog > xDialog(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.comp.ui.XSLTFilterDialog")), uno::UNO_QUERY);
229 if( xDialog.is() )
231 xDialog->execute();
234 catch( uno::Exception& )
237 rReq.Ignore ();
239 break;
240 case FN_WORDCOUNT_DIALOG:
242 SwDocStat aCurr;
243 SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
245 SwWait aWait( *GetView().GetDocShell(), TRUE );
246 rSh.StartAction();
247 rSh.CountWords( aCurr );
248 rSh.UpdateDocStat( aDocStat );
249 rSh.EndAction();
252 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
253 DBG_ASSERT(pFact, "Dialogdiet fail!");
254 AbstractSwWordCountDialog* pDialog = pFact->CreateSwWordCountDialog( GetView().GetWindow() );
255 pDialog->SetValues(aCurr, aDocStat );
256 pDialog->Execute();
257 delete pDialog;
259 break;
260 case SID_EXTRUSION_TOOGLE:
261 case SID_EXTRUSION_TILT_DOWN:
262 case SID_EXTRUSION_TILT_UP:
263 case SID_EXTRUSION_TILT_LEFT:
264 case SID_EXTRUSION_TILT_RIGHT:
265 case SID_EXTRUSION_3D_COLOR:
266 case SID_EXTRUSION_DEPTH:
267 case SID_EXTRUSION_DIRECTION:
268 case SID_EXTRUSION_PROJECTION:
269 case SID_EXTRUSION_LIGHTING_DIRECTION:
270 case SID_EXTRUSION_LIGHTING_INTENSITY:
271 case SID_EXTRUSION_SURFACE:
272 case SID_EXTRUSION_DEPTH_FLOATER:
273 case SID_EXTRUSION_DIRECTION_FLOATER:
274 case SID_EXTRUSION_LIGHTING_FLOATER:
275 case SID_EXTRUSION_SURFACE_FLOATER:
276 case SID_EXTRUSION_DEPTH_DIALOG:
277 svx::ExtrusionBar::execute( pSdrView, rReq, rBnd );
278 rReq.Ignore ();
279 break;
281 case SID_FONTWORK_SHAPE:
282 case SID_FONTWORK_SHAPE_TYPE:
283 case SID_FONTWORK_ALIGNMENT:
284 case SID_FONTWORK_SAME_LETTER_HEIGHTS:
285 case SID_FONTWORK_CHARACTER_SPACING:
286 case SID_FONTWORK_KERN_CHARACTER_PAIRS:
287 case SID_FONTWORK_CHARACTER_SPACING_FLOATER:
288 case SID_FONTWORK_ALIGNMENT_FLOATER:
289 case SID_FONTWORK_CHARACTER_SPACING_DIALOG:
290 svx::FontworkBar::execute( pSdrView, rReq, rBnd );
291 rReq.Ignore ();
292 break;
294 default:
295 DBG_ASSERT(!this, "falscher Dispatcher");
296 return;
298 if (pSdrView->GetModel()->IsChanged())
299 rSh.SetModified();
300 else if (bChanged)
301 pSdrView->GetModel()->SetChanged(TRUE);
304 /*--------------------------------------------------------------------
305 Beschreibung:
306 --------------------------------------------------------------------*/
310 void SwDrawShell::GetState(SfxItemSet& rSet)
312 SwWrtShell &rSh = GetShell();
313 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
314 SfxWhichIter aIter( rSet );
315 USHORT nWhich = aIter.FirstWhich();
316 BOOL bProtected = rSh.IsSelObjProtected(FLYPROTECT_CONTENT);
318 if (!bProtected) // Im Parent nachsehen
319 bProtected |= rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
321 while( nWhich )
323 switch( nWhich )
325 case SID_OBJECT_HELL:
326 if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 0 || bProtected )
327 rSet.DisableItem( nWhich );
328 break;
330 case SID_OBJECT_HEAVEN:
331 if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 1 || bProtected )
332 rSet.DisableItem( nWhich );
333 break;
335 case FN_TOOL_HIERARCHIE:
336 if ( !rSh.IsObjSelected() || bProtected )
337 rSet.DisableItem( nWhich );
338 break;
340 case SID_OBJECT_ROTATE:
342 const BOOL bIsRotate = GetView().IsDrawRotate();
343 if ( (!bIsRotate && !pSdrView->IsRotateAllowed()) || bProtected )
344 rSet.DisableItem( nWhich );
345 else
346 rSet.Put( SfxBoolItem( nWhich, bIsRotate ) );
348 break;
350 case SID_BEZIER_EDIT:
351 if (!Disable(rSet, nWhich))
352 rSet.Put( SfxBoolItem( nWhich, !GetView().IsDrawSelMode()));
353 break;
355 case FN_FLIP_HORZ_GRAFIC:
356 if ( !pSdrView->IsMirrorAllowed() || bProtected )
357 rSet.DisableItem( nWhich );
358 break;
360 case FN_FLIP_VERT_GRAFIC:
361 if ( !pSdrView->IsMirrorAllowed() || bProtected )
362 rSet.DisableItem( nWhich );
363 break;
365 case SID_FONTWORK:
367 if (bProtected)
368 rSet.DisableItem( nWhich );
369 else
371 const USHORT nId = SvxFontWorkChildWindow::GetChildWindowId();
372 rSet.Put(SfxBoolItem( nWhich , GetView().GetViewFrame()->HasChildWindow(nId)));
375 break;
377 nWhich = aIter.NextWhich();
379 svx::ExtrusionBar::getState( pSdrView, rSet );
380 svx::FontworkBar::getState( pSdrView, rSet );
383 /*--------------------------------------------------------------------
384 Beschreibung:
385 --------------------------------------------------------------------*/
389 SwDrawShell::SwDrawShell(SwView &_rView) :
390 SwDrawBaseShell(_rView)
392 SetHelpId(SW_DRAWSHELL);
393 SetName(String::CreateFromAscii("Draw"));
396 /*************************************************************************
398 |* SfxRequests fuer FontWork bearbeiten
400 \************************************************************************/
404 void SwDrawShell::ExecFormText(SfxRequest& rReq)
406 SwWrtShell &rSh = GetShell();
407 SdrView* pDrView = rSh.GetDrawView();
408 BOOL bChanged = pDrView->GetModel()->IsChanged();
409 pDrView->GetModel()->SetChanged(FALSE);
411 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
413 if ( rMarkList.GetMarkCount() == 1 && rReq.GetArgs() )
415 const SfxItemSet& rSet = *rReq.GetArgs();
416 const SfxPoolItem* pItem;
418 if ( pDrView->IsTextEdit() )
420 pDrView->SdrEndTextEdit( TRUE );
421 GetView().AttrChangedNotify(&rSh);
424 if ( rSet.GetItemState(XATTR_FORMTXTSTDFORM, TRUE, &pItem) ==
425 SFX_ITEM_SET &&
426 ((const XFormTextStdFormItem*) pItem)->GetValue() != XFTFORM_NONE )
429 const USHORT nId = SvxFontWorkChildWindow::GetChildWindowId();
431 SvxFontWorkDialog* pDlg = (SvxFontWorkDialog*)(GetView().GetViewFrame()->
432 GetChildWindow(nId)->GetWindow());
434 pDlg->CreateStdFormObj(*pDrView, *pDrView->GetSdrPageView(),
435 rSet, *rMarkList.GetMark(0)->GetMarkedSdrObj(),
436 ((const XFormTextStdFormItem*) pItem)->
437 GetValue());
440 else
441 pDrView->SetAttributes(rSet);
443 if (pDrView->GetModel()->IsChanged())
444 rSh.SetModified();
445 else
446 if (bChanged)
447 pDrView->GetModel()->SetChanged(TRUE);
450 /*************************************************************************
452 |* Statuswerte fuer FontWork zurueckgeben
454 \************************************************************************/
458 void SwDrawShell::GetFormTextState(SfxItemSet& rSet)
460 SwWrtShell &rSh = GetShell();
461 SdrView* pDrView = rSh.GetDrawView();
462 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
463 const SdrObject* pObj = NULL;
464 SvxFontWorkDialog* pDlg = NULL;
466 const USHORT nId = SvxFontWorkChildWindow::GetChildWindowId();
468 SfxViewFrame* pVFrame = GetView().GetViewFrame();
469 if ( pVFrame->HasChildWindow(nId) )
470 pDlg = (SvxFontWorkDialog*)(pVFrame->GetChildWindow(nId)->GetWindow());
472 if ( rMarkList.GetMarkCount() == 1 )
473 pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
475 if ( pObj == NULL || !pObj->ISA(SdrTextObj) ||
476 !((SdrTextObj*) pObj)->HasText() )
478 #define XATTR_ANZ 12
479 static const USHORT nXAttr[ XATTR_ANZ ] =
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
486 for( USHORT i = 0; i < XATTR_ANZ; )
487 rSet.DisableItem( nXAttr[ i++ ] );
489 else
491 if ( pDlg )
492 pDlg->SetColorTable(XColorTable::GetStdColorTable());
494 pDrView->GetAttributes( rSet );