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