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/extrusionbar.hxx>
39 #include <svx/fontworkbar.hxx>
40 #include <svx/tbxcustomshapes.hxx>
41 #include <uitool.hxx>
42 #include <wview.hxx>
43 #include <swmodule.hxx>
44 #include <swwait.hxx>
45 #include <docstat.hxx>
46 #include <IDocumentStatistics.hxx>
47
48 #include <comphelper/processfactory.hxx>
49 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
50
51 #include <svx/xtable.hxx>
52 #include <sfx2/sidebar/EnumContext.hxx>
53 #include <svx/svdoashp.hxx>
54 #include <svx/svdoole2.hxx>
55 #include <sfx2/opengrf.hxx>
56 #include <svx/svdograf.hxx>
57 #include <svx/svdundo.hxx>
58 #include <svx/xbtmpit.hxx>
59
60 #include "swundo.hxx"
61 #include "wrtsh.hxx"
62 #include "cmdid.h"
63 #include "globals.hrc"
64 #include "helpid.h"
65 #include "popup.hrc"
66 #include "shells.hrc"
67 #include "drwbassh.hxx"
68 #include "drawsh.hxx"
69
70 #define SwDrawShell
71 #include <sfx2/msg.hxx>
72 #include "swslots.hxx"
73 #include "swabstdlg.hxx" //CHINA001
74 #include "misc.hrc"
75
76 using namespace ::com::sun::star;
77 using namespace ::com::sun::star::uno;
78
SFX_IMPL_INTERFACE(SwDrawShell,SwDrawBaseShell,SW_RES (STR_SHELLNAME_DRAW))79 SFX_IMPL_INTERFACE(SwDrawShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAW))
80 {
81 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAW_POPUPMENU));
82 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_DRAW_TOOLBOX));
83 SFX_CHILDWINDOW_REGISTRATION(SvxFontWorkChildWindow::GetChildWindowId());
84 }
85
TYPEINIT1(SwDrawShell,SwDrawBaseShell)86 TYPEINIT1(SwDrawShell,SwDrawBaseShell)
87
88 /*--------------------------------------------------------------------
89 Beschreibung:
90 --------------------------------------------------------------------*/
91
92
93 // #123922# check as the name implies
94 SdrObject* SwDrawShell::IsSingleFillableNonOLESelected()
95 {
96 SwWrtShell &rSh = GetShell();
97 SdrView* pSdrView = rSh.GetDrawView();
98
99 if(!pSdrView)
100 {
101 return 0;
102 }
103
104 if(1 != pSdrView->GetMarkedObjectCount())
105 {
106 return 0;
107 }
108
109 SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0);
110
111 if(!pPickObj)
112 {
113 return 0;
114 }
115
116 if(!pPickObj->IsClosedObj())
117 {
118 return 0;
119 }
120
121 if(dynamic_cast< SdrOle2Obj* >(pPickObj))
122 {
123 return 0;
124 }
125
126 return pPickObj;
127 }
128
129 // #123922# insert given graphic data dependent of the object type in focus
InsertPictureFromFile(SdrObject & rObject)130 void SwDrawShell::InsertPictureFromFile(SdrObject& rObject)
131 {
132 SwWrtShell &rSh = GetShell();
133 SdrView* pSdrView = rSh.GetDrawView();
134
135 if(pSdrView)
136 {
137 SvxOpenGraphicDialog aDlg(SW_RESSTR(STR_INSERT_GRAPHIC));
138
139 if(GRFILTER_OK == aDlg.Execute())
140 {
141 Graphic aGraphic;
142 int nError(aDlg.GetGraphic(aGraphic));
143
144 if(GRFILTER_OK == nError)
145 {
146 const bool bAsLink(aDlg.IsAsLink());
147 SdrObject* pResult = &rObject;
148
149 rSh.StartUndo(UNDO_PASTE_CLIPBOARD);
150
151 if(dynamic_cast< SdrGrafObj* >(&rObject))
152 {
153 SdrGrafObj* pNewGrafObj = (SdrGrafObj*)rObject.Clone();
154
155 pNewGrafObj->SetGraphic(aGraphic);
156
157 // #123922# for handling MasterObject and virtual ones correctly, SW
158 // wants us to call ReplaceObject at the page, but that also
159 // triggers the same assertion (I tried it), so stay at the view method
160 pSdrView->ReplaceObjectAtView(&rObject, *pSdrView->GetSdrPageView(), pNewGrafObj);
161
162 // set in all cases - the Clone() will have copied an existing link (!)
163 pNewGrafObj->SetGraphicLink(
164 bAsLink ? aDlg.GetPath() : String(),
165 bAsLink ? aDlg.GetCurrentFilter() : String());
166
167 pResult = pNewGrafObj;
168 }
169 else // if(rObject.IsClosedObj() && !dynamic_cast< SdrOle2Obj* >(&rObject))
170 {
171 pSdrView->AddUndo(new SdrUndoAttrObj(rObject));
172
173 SfxItemSet aSet(pSdrView->GetModel()->GetItemPool(), XATTR_FILLSTYLE, XATTR_FILLBITMAP);
174
175 aSet.Put(XFillStyleItem(XFILL_BITMAP));
176 aSet.Put(XFillBitmapItem(String(), aGraphic));
177 rObject.SetMergedItemSetAndBroadcast(aSet);
178 }
179
180 rSh.EndUndo( UNDO_END );
181
182 if(pResult)
183 {
184 // we are done; mark the modified/new object
185 pSdrView->MarkObj(pResult, pSdrView->GetSdrPageView());
186 }
187 }
188 }
189 }
190 }
191
Execute(SfxRequest & rReq)192 void SwDrawShell::Execute(SfxRequest &rReq)
193 {
194 SwWrtShell &rSh = GetShell();
195 SdrView *pSdrView = rSh.GetDrawView();
196 const SfxItemSet *pArgs = rReq.GetArgs();
197 SfxBindings &rBnd = GetView().GetViewFrame()->GetBindings();
198 sal_uInt16 nSlotId = rReq.GetSlot();
199 sal_Bool bChanged = pSdrView->GetModel()->IsChanged();
200
201 pSdrView->GetModel()->SetChanged(sal_False);
202
203 const SfxPoolItem* pItem;
204 if(pArgs)
205 pArgs->GetItemState(nSlotId, sal_False, &pItem);
206
207 sal_Bool bMirror = sal_True;
208
209 switch (nSlotId)
210 {
211 case SID_OBJECT_ROTATE:
212 if (rSh.IsObjSelected() && pSdrView->IsRotateAllowed())
213 {
214 if (GetView().IsDrawRotate())
215 rSh.SetDragMode(SDRDRAG_MOVE);
216 else
217 rSh.SetDragMode(SDRDRAG_ROTATE);
218
219 GetView().FlipDrawRotate();
220 }
221 break;
222
223 case SID_BEZIER_EDIT:
224 if (GetView().IsDrawRotate())
225 {
226 rSh.SetDragMode(SDRDRAG_MOVE);
227 GetView().FlipDrawRotate();
228 }
229 GetView().FlipDrawSelMode();
230 pSdrView->SetFrameDragSingles(GetView().IsDrawSelMode());
231 GetView().AttrChangedNotify(&rSh); // Shellwechsel...
232 break;
233
234 case SID_OBJECT_HELL:
235 if (rSh.IsObjSelected())
236 {
237 rSh.StartUndo( UNDO_START );
238 SetWrapMode(FN_FRAME_WRAPTHRU_TRANSP);
239 rSh.SelectionToHell();
240 rSh.EndUndo( UNDO_END );
241 rBnd.Invalidate(SID_OBJECT_HEAVEN);
242 }
243 break;
244
245 case SID_OBJECT_HEAVEN:
246 if (rSh.IsObjSelected())
247 {
248 rSh.StartUndo( UNDO_START );
249 SetWrapMode(FN_FRAME_WRAPTHRU);
250 rSh.SelectionToHeaven();
251 rSh.EndUndo( UNDO_END );
252 rBnd.Invalidate(SID_OBJECT_HELL);
253 }
254 break;
255
256 case FN_TOOL_HIERARCHIE:
257 if (rSh.IsObjSelected())
258 {
259 rSh.StartUndo( UNDO_START );
260 if (rSh.GetLayerId() == 0)
261 {
262 SetWrapMode(FN_FRAME_WRAPTHRU);
263 rSh.SelectionToHeaven();
264 }
265 else
266 {
267 SetWrapMode(FN_FRAME_WRAPTHRU_TRANSP);
268 rSh.SelectionToHell();
269 }
270 rSh.EndUndo( UNDO_END );
271 rBnd.Invalidate( SID_OBJECT_HELL );
272 rBnd.Invalidate( SID_OBJECT_HEAVEN );
273 }
274 break;
275
276 case SID_FLIP_VERTICAL:
277 bMirror = sal_False;
278 /* no break */
279 case SID_FLIP_HORIZONTAL:
280 rSh.MirrorSelection( bMirror );
281 break;
282
283 case SID_FONTWORK:
284 {
285 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &rSh.GetView()));
286 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
287 SfxViewFrame* pVFrame = GetView().GetViewFrame();
288 if (pArgs)
289 {
290 pVFrame->SetChildWindow(SvxFontWorkChildWindow::GetChildWindowId(),
291 ((const SfxBoolItem&)(pArgs->Get(SID_FONTWORK))).GetValue());
292 }
293 else
294 pVFrame->ToggleChildWindow( SvxFontWorkChildWindow::GetChildWindowId() );
295 pVFrame->GetBindings().Invalidate(SID_FONTWORK);
296 }
297 break;
298 case FN_FORMAT_FOOTNOTE_DLG:
299 {
300 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
301 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
302
303 VclAbstractDialog* pDlg = pFact->CreateSwFootNoteOptionDlg( GetView().GetWindow(), GetView().GetWrtShell(), DLG_DOC_FOOTNOTE );
304 DBG_ASSERT(pDlg, "Dialogdiet fail!");
305 pDlg->Execute();
306 delete pDlg;
307 break;
308 }
309 case FN_NUMBERING_OUTLINE_DLG:
310 {
311 SfxItemSet aTmp(GetPool(), FN_PARAM_1, FN_PARAM_1);
312 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
313 DBG_ASSERT(pFact, "Dialogdiet fail!");
314 SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_TAB_OUTLINE,
315 GetView().GetWindow(), &aTmp, GetView().GetWrtShell());
316 DBG_ASSERT(pDlg, "Dialogdiet fail!");
317 pDlg->Execute();
318 delete pDlg;
319 rReq.Done();
320 }
321 break;
322 case SID_OPEN_XML_FILTERSETTINGS:
323 {
324 try
325 {
326 uno::Reference < ui::dialogs::XExecutableDialog > xDialog(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.comp.ui.XSLTFilterDialog")), uno::UNO_QUERY);
327 if( xDialog.is() )
328 {
329 xDialog->execute();
330 }
331 }
332 catch( uno::Exception& )
333 {
334 }
335 rReq.Ignore ();
336 }
337 break;
338 case FN_WORDCOUNT_DIALOG:
339 {
340 SwDocStat aCurr;
341 SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
342 {
343 SwWait aWait( *GetView().GetDocShell(), true );
344 rSh.StartAction();
345 rSh.CountWords( aCurr );
346 rSh.UpdateDocStat( aDocStat );
347 rSh.EndAction();
348 }
349
350 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
351 DBG_ASSERT(pFact, "Dialogdiet fail!");
352 AbstractSwWordCountDialog* pDialog = pFact->CreateSwWordCountDialog( GetView().GetWindow() );
353 pDialog->SetValues(aCurr, aDocStat );
354 pDialog->Execute();
355 delete pDialog;
356 }
357 break;
358 case SID_EXTRUSION_TOOGLE:
359 case SID_EXTRUSION_TILT_DOWN:
360 case SID_EXTRUSION_TILT_UP:
361 case SID_EXTRUSION_TILT_LEFT:
362 case SID_EXTRUSION_TILT_RIGHT:
363 case SID_EXTRUSION_3D_COLOR:
364 case SID_EXTRUSION_DEPTH:
365 case SID_EXTRUSION_DIRECTION:
366 case SID_EXTRUSION_PROJECTION:
367 case SID_EXTRUSION_LIGHTING_DIRECTION:
368 case SID_EXTRUSION_LIGHTING_INTENSITY:
369 case SID_EXTRUSION_SURFACE:
370 case SID_EXTRUSION_DEPTH_FLOATER:
371 case SID_EXTRUSION_DIRECTION_FLOATER:
372 case SID_EXTRUSION_LIGHTING_FLOATER:
373 case SID_EXTRUSION_SURFACE_FLOATER:
374 case SID_EXTRUSION_DEPTH_DIALOG:
375 svx::ExtrusionBar::execute( pSdrView, rReq, rBnd );
376 rReq.Ignore ();
377 break;
378
379 case SID_FONTWORK_SHAPE:
380 case SID_FONTWORK_SHAPE_TYPE:
381 case SID_FONTWORK_ALIGNMENT:
382 case SID_FONTWORK_SAME_LETTER_HEIGHTS:
383 case SID_FONTWORK_CHARACTER_SPACING:
384 case SID_FONTWORK_KERN_CHARACTER_PAIRS:
385 case SID_FONTWORK_CHARACTER_SPACING_FLOATER:
386 case SID_FONTWORK_ALIGNMENT_FLOATER:
387 case SID_FONTWORK_CHARACTER_SPACING_DIALOG:
388 svx::FontworkBar::execute( pSdrView, rReq, rBnd );
389 rReq.Ignore ();
390 break;
391
392 case SID_INSERT_GRAPHIC:
393 {
394 // #123922# check if we can do something
395 SdrObject* pObj = IsSingleFillableNonOLESelected();
396
397 if(pObj)
398 {
399 // ...and if yes, do something
400 InsertPictureFromFile(*pObj);
401 bool bBla = true;
402 }
403
404 break;
405 }
406
407 default:
408 DBG_ASSERT(sal_False, "wrong dispatcher");
409 return;
410 }
411 if (pSdrView->GetModel()->IsChanged())
412 rSh.SetModified();
413 else if (bChanged)
414 pSdrView->GetModel()->SetChanged(sal_True);
415 }
416
417 /*--------------------------------------------------------------------
418 Beschreibung:
419 --------------------------------------------------------------------*/
420
GetState(SfxItemSet & rSet)421 void SwDrawShell::GetState(SfxItemSet& rSet)
422 {
423 SwWrtShell &rSh = GetShell();
424 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
425 SfxWhichIter aIter( rSet );
426 sal_uInt16 nWhich = aIter.FirstWhich();
427 sal_Bool bProtected = rSh.IsSelObjProtected(FLYPROTECT_CONTENT);
428
429 if (!bProtected) // Im Parent nachsehen
430 bProtected |= rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) != 0;
431
432 while( nWhich )
433 {
434 switch( nWhich )
435 {
436 case SID_OBJECT_HELL:
437 if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 0 || bProtected )
438 rSet.DisableItem( nWhich );
439 break;
440
441 case SID_OBJECT_HEAVEN:
442 if ( !rSh.IsObjSelected() || rSh.GetLayerId() == 1 || bProtected )
443 rSet.DisableItem( nWhich );
444 break;
445
446 case FN_TOOL_HIERARCHIE:
447 if ( !rSh.IsObjSelected() || bProtected )
448 rSet.DisableItem( nWhich );
449 break;
450
451 case SID_OBJECT_ROTATE:
452 {
453 const sal_Bool bIsRotate = GetView().IsDrawRotate();
454 if ( (!bIsRotate && !pSdrView->IsRotateAllowed()) || bProtected )
455 rSet.DisableItem( nWhich );
456 else
457 rSet.Put( SfxBoolItem( nWhich, bIsRotate ) );
458 }
459 break;
460
461 case SID_BEZIER_EDIT:
462 if (!Disable(rSet, nWhich))
463 rSet.Put( SfxBoolItem( nWhich, !GetView().IsDrawSelMode()));
464 break;
465
466 case SID_FLIP_VERTICAL:
467 if ( !pSdrView->IsMirrorAllowed() || bProtected )
468 {
469 rSet.DisableItem( nWhich );
470 }
471 else
472 {
473 // TTTT - needs to be adapted in aw080:
474 // state is not kept for drawing objects --> provide not flipped state
475 rSet.Put( SfxBoolItem( nWhich, sal_False ) );
476 }
477 break;
478
479 case SID_FLIP_HORIZONTAL:
480 if ( !pSdrView->IsMirrorAllowed() || bProtected )
481 {
482 rSet.DisableItem( nWhich );
483 }
484 else
485 {
486 // TTTT - needs to be adapted in aw080:
487 // state is not kept for drawing objects --> provide not flipped state
488 rSet.Put( SfxBoolItem( nWhich, sal_False ) );
489 }
490 break;
491
492 case SID_FONTWORK:
493 {
494 if (bProtected)
495 rSet.DisableItem( nWhich );
496 else
497 {
498 const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
499 rSet.Put(SfxBoolItem( nWhich , GetView().GetViewFrame()->HasChildWindow(nId)));
500 }
501 }
502 break;
503
504 case SID_INSERT_GRAPHIC:
505 {
506 // #123922# check if we can do something
507 SdrObject* pObj = IsSingleFillableNonOLESelected();
508
509 if(!pObj)
510 {
511 rSet.DisableItem(nWhich);
512 }
513
514 break;
515 }
516 }
517 nWhich = aIter.NextWhich();
518 }
519 svx::ExtrusionBar::getState( pSdrView, rSet );
520 svx::FontworkBar::getState( pSdrView, rSet );
521 }
522
523 /*--------------------------------------------------------------------
524 Beschreibung:
525 --------------------------------------------------------------------*/
526
527
528
SwDrawShell(SwView & _rView)529 SwDrawShell::SwDrawShell(SwView &_rView) :
530 SwDrawBaseShell(_rView)
531 {
532 SetHelpId(SW_DRAWSHELL);
533 SetName(String::CreateFromAscii("Draw"));
534
535 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Draw));
536 }
537
538 /*************************************************************************
539 |*
540 |* SfxRequests fuer FontWork bearbeiten
541 |*
542 \************************************************************************/
543
544
545
ExecFormText(SfxRequest & rReq)546 void SwDrawShell::ExecFormText(SfxRequest& rReq)
547 {
548 SwWrtShell &rSh = GetShell();
549 SdrView* pDrView = rSh.GetDrawView();
550 sal_Bool bChanged = pDrView->GetModel()->IsChanged();
551 pDrView->GetModel()->SetChanged(sal_False);
552
553 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
554
555 if ( rMarkList.GetMarkCount() == 1 && rReq.GetArgs() )
556 {
557 const SfxItemSet& rSet = *rReq.GetArgs();
558
559 if ( pDrView->IsTextEdit() )
560 {
561 pDrView->SdrEndTextEdit( sal_True );
562 GetView().AttrChangedNotify(&rSh);
563 }
564
565 pDrView->SetAttributes(rSet);
566 }
567 if (pDrView->GetModel()->IsChanged())
568 rSh.SetModified();
569 else
570 if (bChanged)
571 pDrView->GetModel()->SetChanged(sal_True);
572 }
573
574 /*************************************************************************
575 |*
576 |* Statuswerte fuer FontWork zurueckgeben
577 |*
578 \************************************************************************/
579
580
581
GetFormTextState(SfxItemSet & rSet)582 void SwDrawShell::GetFormTextState(SfxItemSet& rSet)
583 {
584 SwWrtShell &rSh = GetShell();
585 SdrView* pDrView = rSh.GetDrawView();
586 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
587 const SdrObject* pObj = NULL;
588 SvxFontWorkDialog* pDlg = NULL;
589
590 const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
591
592 SfxViewFrame* pVFrame = GetView().GetViewFrame();
593 if ( pVFrame->HasChildWindow(nId) )
594 pDlg = (SvxFontWorkDialog*)(pVFrame->GetChildWindow(nId)->GetWindow());
595
596 if ( rMarkList.GetMarkCount() == 1 )
597 pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
598
599 const SdrTextObj* pTextObj = dynamic_cast< const SdrTextObj* >(pObj);
600 const bool bDeactivate(
601 !pObj ||
602 !pTextObj ||
603 !pTextObj->HasText() ||
604 dynamic_cast< const SdrObjCustomShape* >(pObj)); // #121538# no FontWork for CustomShapes
605
606 if(bDeactivate)
607 {
608 rSet.DisableItem(XATTR_FORMTXTSTYLE);
609 rSet.DisableItem(XATTR_FORMTXTADJUST);
610 rSet.DisableItem(XATTR_FORMTXTDISTANCE);
611 rSet.DisableItem(XATTR_FORMTXTSTART);
612 rSet.DisableItem(XATTR_FORMTXTMIRROR);
613 rSet.DisableItem(XATTR_FORMTXTHIDEFORM);
614 rSet.DisableItem(XATTR_FORMTXTOUTLINE);
615 rSet.DisableItem(XATTR_FORMTXTSHADOW);
616 rSet.DisableItem(XATTR_FORMTXTSHDWCOLOR);
617 rSet.DisableItem(XATTR_FORMTXTSHDWXVAL);
618 rSet.DisableItem(XATTR_FORMTXTSHDWYVAL);
619 }
620 else
621 {
622 if ( pDlg )
623 pDlg->SetColorTable(XColorList::GetStdColorList());
624
625 pDrView->GetAttributes( rSet );
626 }
627 }
628