xref: /AOO41X/main/sw/source/ui/shells/drawsh.cxx (revision ff0525f24f03981d56b7579b645949f111420994)
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 
54 #include "swundo.hxx"
55 #include "wrtsh.hxx"
56 #include "cmdid.h"
57 #include "globals.hrc"
58 #include "helpid.h"
59 #include "popup.hrc"
60 #include "shells.hrc"
61 #include "drwbassh.hxx"
62 #include "drawsh.hxx"
63 
64 #define SwDrawShell
65 #include <sfx2/msg.hxx>
66 #include "swslots.hxx"
67 #include "swabstdlg.hxx" //CHINA001
68 #include "misc.hrc"
69 
70 using namespace ::com::sun::star;
71 using namespace ::com::sun::star::uno;
72 
73 SFX_IMPL_INTERFACE(SwDrawShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAW))
74 {
75     SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAW_POPUPMENU));
76     SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_DRAW_TOOLBOX));
77     SFX_CHILDWINDOW_REGISTRATION(SvxFontWorkChildWindow::GetChildWindowId());
78 }
79 
80 TYPEINIT1(SwDrawShell,SwDrawBaseShell)
81 
82 /*--------------------------------------------------------------------
83     Beschreibung:
84  --------------------------------------------------------------------*/
85 
86 
87 void SwDrawShell::Execute(SfxRequest &rReq)
88 {
89     SwWrtShell          &rSh = GetShell();
90     SdrView             *pSdrView = rSh.GetDrawView();
91     const SfxItemSet    *pArgs = rReq.GetArgs();
92     SfxBindings         &rBnd  = GetView().GetViewFrame()->GetBindings();
93     sal_uInt16               nSlotId = rReq.GetSlot();
94     sal_Bool                 bChanged = pSdrView->GetModel()->IsChanged();
95 
96     pSdrView->GetModel()->SetChanged(sal_False);
97 
98     const SfxPoolItem* pItem;
99     if(pArgs)
100         pArgs->GetItemState(nSlotId, sal_False, &pItem);
101 
102     sal_Bool bMirror = sal_True;
103 
104     switch (nSlotId)
105     {
106         case SID_OBJECT_ROTATE:
107             if (rSh.IsObjSelected() && pSdrView->IsRotateAllowed())
108             {
109                 if (GetView().IsDrawRotate())
110                     rSh.SetDragMode(SDRDRAG_MOVE);
111                 else
112                     rSh.SetDragMode(SDRDRAG_ROTATE);
113 
114                 GetView().FlipDrawRotate();
115             }
116             break;
117 
118         case SID_BEZIER_EDIT:
119             if (GetView().IsDrawRotate())
120             {
121                 rSh.SetDragMode(SDRDRAG_MOVE);
122                 GetView().FlipDrawRotate();
123             }
124             GetView().FlipDrawSelMode();
125             pSdrView->SetFrameDragSingles(GetView().IsDrawSelMode());
126             GetView().AttrChangedNotify(&rSh); // Shellwechsel...
127             break;
128 
129         case SID_OBJECT_HELL:
130             if (rSh.IsObjSelected())
131             {
132                 rSh.StartUndo( UNDO_START );
133                 SetWrapMode(FN_FRAME_WRAPTHRU_TRANSP);
134                 rSh.SelectionToHell();
135                 rSh.EndUndo( UNDO_END );
136                 rBnd.Invalidate(SID_OBJECT_HEAVEN);
137             }
138             break;
139 
140         case SID_OBJECT_HEAVEN:
141             if (rSh.IsObjSelected())
142             {
143                 rSh.StartUndo( UNDO_START );
144                 SetWrapMode(FN_FRAME_WRAPTHRU);
145                 rSh.SelectionToHeaven();
146                 rSh.EndUndo( UNDO_END );
147                 rBnd.Invalidate(SID_OBJECT_HELL);
148             }
149             break;
150 
151         case FN_TOOL_HIERARCHIE:
152             if (rSh.IsObjSelected())
153             {
154                 rSh.StartUndo( UNDO_START );
155                 if (rSh.GetLayerId() == 0)
156                 {
157                     SetWrapMode(FN_FRAME_WRAPTHRU);
158                     rSh.SelectionToHeaven();
159                 }
160                 else
161                 {
162                     SetWrapMode(FN_FRAME_WRAPTHRU_TRANSP);
163                     rSh.SelectionToHell();
164                 }
165                 rSh.EndUndo( UNDO_END );
166                 rBnd.Invalidate( SID_OBJECT_HELL );
167                 rBnd.Invalidate( SID_OBJECT_HEAVEN );
168             }
169             break;
170 
171         case FN_FLIP_HORZ_GRAFIC:
172         case SID_FLIP_HORIZONTAL:
173             bMirror = sal_False;
174             /* no break */
175         case FN_FLIP_VERT_GRAFIC:
176         case SID_FLIP_VERTICAL:
177             rSh.MirrorSelection( bMirror );
178             break;
179 
180         case SID_FONTWORK:
181         {
182             FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &rSh.GetView()));
183             SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
184             SfxViewFrame* pVFrame = GetView().GetViewFrame();
185             if (pArgs)
186             {
187                 pVFrame->SetChildWindow(SvxFontWorkChildWindow::GetChildWindowId(),
188                     ((const SfxBoolItem&)(pArgs->Get(SID_FONTWORK))).GetValue());
189             }
190             else
191                 pVFrame->ToggleChildWindow( SvxFontWorkChildWindow::GetChildWindowId() );
192             pVFrame->GetBindings().Invalidate(SID_FONTWORK);
193         }
194         break;
195         case FN_FORMAT_FOOTNOTE_DLG:
196         {
197             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
198             DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
199 
200             VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( GetView().GetWindow(), GetView().GetWrtShell(), DLG_DOC_FOOTNOTE );
201             DBG_ASSERT(pDlg, "Dialogdiet fail!");
202             pDlg->Execute();
203             delete pDlg;
204             break;
205         }
206         case FN_NUMBERING_OUTLINE_DLG:
207         {
208             SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
209             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
210             DBG_ASSERT(pFact, "Dialogdiet fail!");
211             SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
212                                                         GetView().GetWindow(), &aTmp, GetView().GetWrtShell());
213             DBG_ASSERT(pDlg, "Dialogdiet fail!");
214             pDlg->Execute();
215             delete pDlg;
216             rReq.Done();
217         }
218         break;
219         case SID_OPEN_XML_FILTERSETTINGS:
220         {
221             try
222             {
223                 uno::Reference < ui::dialogs::XExecutableDialog > xDialog(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.comp.ui.XSLTFilterDialog")), uno::UNO_QUERY);
224                 if( xDialog.is() )
225                 {
226                     xDialog->execute();
227                 }
228             }
229             catch( uno::Exception& )
230             {
231             }
232             rReq.Ignore ();
233         }
234         break;
235         case FN_WORDCOUNT_DIALOG:
236         {
237             SwDocStat aCurr;
238             SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
239             {
240                 SwWait aWait( *GetView().GetDocShell(), sal_True );
241                 rSh.StartAction();
242                 rSh.CountWords( aCurr );
243                 rSh.UpdateDocStat( aDocStat );
244                 rSh.EndAction();
245             }
246 
247             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
248             DBG_ASSERT(pFact, "Dialogdiet fail!");
249             AbstractSwWordCountDialog* pDialog = pFact->CreateSwWordCountDialog( GetView().GetWindow() );
250             pDialog->SetValues(aCurr, aDocStat );
251             pDialog->Execute();
252             delete pDialog;
253         }
254         break;
255         case SID_EXTRUSION_TOOGLE:
256         case SID_EXTRUSION_TILT_DOWN:
257         case SID_EXTRUSION_TILT_UP:
258         case SID_EXTRUSION_TILT_LEFT:
259         case SID_EXTRUSION_TILT_RIGHT:
260         case SID_EXTRUSION_3D_COLOR:
261         case SID_EXTRUSION_DEPTH:
262         case SID_EXTRUSION_DIRECTION:
263         case SID_EXTRUSION_PROJECTION:
264         case SID_EXTRUSION_LIGHTING_DIRECTION:
265         case SID_EXTRUSION_LIGHTING_INTENSITY:
266         case SID_EXTRUSION_SURFACE:
267         case SID_EXTRUSION_DEPTH_FLOATER:
268         case SID_EXTRUSION_DIRECTION_FLOATER:
269         case SID_EXTRUSION_LIGHTING_FLOATER:
270         case SID_EXTRUSION_SURFACE_FLOATER:
271         case SID_EXTRUSION_DEPTH_DIALOG:
272             svx::ExtrusionBar::execute( pSdrView, rReq, rBnd );
273             rReq.Ignore ();
274             break;
275 
276         case SID_FONTWORK_SHAPE:
277         case SID_FONTWORK_SHAPE_TYPE:
278         case SID_FONTWORK_ALIGNMENT:
279         case SID_FONTWORK_SAME_LETTER_HEIGHTS:
280         case SID_FONTWORK_CHARACTER_SPACING:
281         case SID_FONTWORK_KERN_CHARACTER_PAIRS:
282         case SID_FONTWORK_CHARACTER_SPACING_FLOATER:
283         case SID_FONTWORK_ALIGNMENT_FLOATER:
284         case SID_FONTWORK_CHARACTER_SPACING_DIALOG:
285             svx::FontworkBar::execute( pSdrView, rReq, rBnd );
286             rReq.Ignore ();
287             break;
288 
289         default:
290             DBG_ASSERT(!this, "falscher Dispatcher");
291             return;
292     }
293     if (pSdrView->GetModel()->IsChanged())
294         rSh.SetModified();
295     else if (bChanged)
296         pSdrView->GetModel()->SetChanged(sal_True);
297 }
298 
299 /*--------------------------------------------------------------------
300     Beschreibung:
301  --------------------------------------------------------------------*/
302 
303 
304 
305 void SwDrawShell::GetState(SfxItemSet& rSet)
306 {
307     SwWrtShell &rSh = GetShell();
308     SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
309     SfxWhichIter aIter( rSet );
310     sal_uInt16 nWhich = aIter.FirstWhich();
311     sal_Bool bProtected = rSh.IsSelObjProtected(FLYPROTECT_CONTENT);
312 
313     if (!bProtected)    // Im Parent nachsehen
314         bProtected |= rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
315 
316     while( nWhich )
317     {
318         switch( nWhich )
319         {
320             case SID_OBJECT_HELL:
321                 if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 0 || bProtected )
322                     rSet.DisableItem( nWhich );
323                 break;
324 
325             case SID_OBJECT_HEAVEN:
326                 if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 1 || bProtected )
327                     rSet.DisableItem( nWhich );
328                 break;
329 
330             case FN_TOOL_HIERARCHIE:
331                 if ( !rSh.IsObjSelected() || bProtected )
332                     rSet.DisableItem( nWhich );
333                 break;
334 
335             case SID_OBJECT_ROTATE:
336             {
337                 const sal_Bool bIsRotate = GetView().IsDrawRotate();
338                 if ( (!bIsRotate && !pSdrView->IsRotateAllowed()) || bProtected )
339                     rSet.DisableItem( nWhich );
340                 else
341                     rSet.Put( SfxBoolItem( nWhich, bIsRotate ) );
342             }
343             break;
344 
345             case SID_BEZIER_EDIT:
346                 if (!Disable(rSet, nWhich))
347                     rSet.Put( SfxBoolItem( nWhich, !GetView().IsDrawSelMode()));
348             break;
349 
350             case FN_FLIP_HORZ_GRAFIC:
351             case SID_FLIP_HORIZONTAL:
352                 if ( !pSdrView->IsMirrorAllowed() || bProtected )
353                     rSet.DisableItem( nWhich );
354                 break;
355 
356             case FN_FLIP_VERT_GRAFIC:
357             case SID_FLIP_VERTICAL:
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