1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drawsh.cxx,v $
10 * $Revision: 1.15.128.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_sc.hxx"
34 #include <svx/svxdlg.hxx> //CHINA001
35 #include <svx/dialogs.hrc> //CHINA001
37 #include "scitems.hxx"
39 #include <svx/eeitem.hxx>
40 #include <svx/fontwork.hxx>
41 //#include <svx/labdlg.hxx> CHINA001
42 #include <svx/srchitem.hxx>
43 #include <svx/tabarea.hxx>
44 #include <svx/tabline.hxx>
45 //CHINA001 #include <svx/transfrm.hxx>
46 #include <sfx2/app.hxx>
47 #include <sfx2/objface.hxx>
48 #include <sfx2/objsh.hxx>
49 #include <sfx2/request.hxx>
50 #include <sfx2/dispatch.hxx>
51 #include <svtools/whiter.hxx>
52 #include <vcl/msgbox.hxx>
55 #include "drwlayer.hxx"
57 #include "viewdata.hxx"
58 #include "document.hxx"
59 #include "docpool.hxx"
60 #include "drawview.hxx"
61 #include "scresid.hxx"
62 #include <svx/svdobj.hxx>
63 //add header of cui CHINA001
64 #include <svx/svxdlg.hxx>
65 #include <svx/dialogs.hrc>
66 #include <svx/drawitem.hxx>
67 #include <svx/xtable.hxx>
70 #include "scslots.hxx"
72 #include "userdat.hxx"
73 #include <sfx2/objsh.hxx>
74 #include <svtools/macitem.hxx>
75 #include <sfx2/evntconf.hxx>
76 #include <sfx2/viewsh.hxx>
77 #include <com/sun/star/util/XModifiable.hpp>
78 #include <com/sun/star/frame/XFrame.hpp>
80 //------------------------------------------------------------------
82 TYPEINIT1( ScDrawShell
, SfxShell
);
84 SFX_IMPL_INTERFACE(ScDrawShell
, SfxShell
, ScResId(SCSTR_DRAWSHELL
) )
86 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT
|SFX_VISIBILITY_STANDARD
|SFX_VISIBILITY_SERVER
,
87 ScResId(RID_DRAW_OBJECTBAR
) );
88 SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_DRAW
) );
89 SFX_CHILDWINDOW_REGISTRATION( SvxFontWorkChildWindow::GetChildWindowId() );
93 // abschalten der nicht erwuenschten Acceleratoren:
95 void ScDrawShell::StateDisableItems( SfxItemSet
&rSet
)
97 SfxWhichIter
aIter(rSet
);
98 USHORT nWhich
= aIter
.FirstWhich();
102 rSet
.DisableItem( nWhich
);
103 nWhich
= aIter
.NextWhich();
107 void lcl_setModified( SfxObjectShell
* pShell
)
111 com::sun::star::uno::Reference
< com::sun::star::util::XModifiable
> xModif( pShell
->GetModel(), com::sun::star::uno::UNO_QUERY
);
113 xModif
->setModified( sal_True
);
117 void ScDrawShell::ExecDrawAttr( SfxRequest
& rReq
)
119 USHORT nSlot
= rReq
.GetSlot();
120 Window
* pWin
= pViewData
->GetActiveWin();
121 // SfxViewFrame* pViewFrame = SfxViewShell::Current()->GetViewFrame(); //!!! koennte knallen
122 ScDrawView
* pView
= pViewData
->GetScDrawView();
123 SdrModel
* pDoc
= pViewData
->GetDocument()->GetDrawLayer();
125 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
126 ULONG nMarkCount
= rMarkList
.GetMarkCount();
127 SdrObject
* pSingleSelectedObj
= NULL
;
128 if ( nMarkCount
> 0 )
129 pSingleSelectedObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
133 case SID_ASSIGNMACRO
:
135 if ( pSingleSelectedObj
)
136 ExecuteMacroAssign( pSingleSelectedObj
, pWin
);
140 case SID_TEXT_STANDARD
: // Harte Textattributierung loeschen
142 SfxItemSet
aEmptyAttr(GetPool(), EE_ITEMS_START
, EE_ITEMS_END
);
143 pView
->SetAttributes(aEmptyAttr
, TRUE
);
147 case SID_ATTR_LINE_STYLE
:
148 case SID_ATTR_LINEEND_STYLE
:
149 case SID_ATTR_LINE_DASH
:
150 case SID_ATTR_LINE_WIDTH
:
151 case SID_ATTR_LINE_COLOR
:
152 case SID_ATTR_FILL_STYLE
:
153 case SID_ATTR_FILL_COLOR
:
154 case SID_ATTR_FILL_GRADIENT
:
155 case SID_ATTR_FILL_HATCH
:
156 case SID_ATTR_FILL_BITMAP
:
159 case SID_ATTR_FILL_SHADOW
:
161 // Wenn ToolBar vertikal :
162 if ( !rReq
.GetArgs() )
166 case SID_ATTR_LINE_STYLE
:
167 case SID_ATTR_LINE_DASH
:
168 case SID_ATTR_LINE_WIDTH
:
169 case SID_ATTR_LINE_COLOR
:
170 ExecuteLineDlg( rReq
);
173 case SID_ATTR_FILL_STYLE
:
174 case SID_ATTR_FILL_COLOR
:
175 case SID_ATTR_FILL_GRADIENT
:
176 case SID_ATTR_FILL_HATCH
:
177 case SID_ATTR_FILL_BITMAP
:
180 case SID_ATTR_FILL_SHADOW
:
182 ExecuteAreaDlg( rReq
);
194 if( pView
->AreObjectsMarked() )
195 pView
->SetAttrToMarked( *rReq
.GetArgs(), FALSE
);
197 pView
->SetDefaultAttr( *rReq
.GetArgs(), FALSE
);
198 pView
->InvalidateAttribs();
202 case SID_ATTRIBUTES_LINE
:
203 ExecuteLineDlg( rReq
);
206 case SID_ATTRIBUTES_AREA
:
207 ExecuteAreaDlg( rReq
);
210 case SID_DRAWTEXT_ATTR_DLG
:
211 ExecuteTextAttrDlg( rReq
);
214 case SID_DRAW_HLINK_EDIT
:
215 if ( pSingleSelectedObj
)
216 pViewData
->GetDispatcher().Execute( SID_HYPERLINK_DIALOG
);
219 case SID_DRAW_HLINK_DELETE
:
220 if ( pSingleSelectedObj
)
221 SetHlinkForObject( pSingleSelectedObj
, rtl::OUString() );
224 case SID_OPEN_HYPERLINK
:
225 if ( nMarkCount
== 1 )
227 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
228 if ( pObj
->IsGroupObject() )
230 SdrPageView
* pPV
= 0;
232 if ( pView
->PickObj( pWin
->PixelToLogic( pViewData
->GetMousePosPixel() ), pView
->getHitTolLog(), pHit
, pPV
, SDRSEARCH_DEEP
) )
236 ScMacroInfo
* pInfo
= ScDrawLayer::GetMacroInfo( pObj
);
237 if ( pInfo
&& (pInfo
->GetHlink().getLength() > 0) )
238 ScGlobal::OpenURL( pInfo
->GetHlink(), String::EmptyString() );
242 case SID_ATTR_TRANSFORM
:
244 if ( pView
->AreObjectsMarked() )
246 const SfxItemSet
* pArgs
= rReq
.GetArgs();
250 // const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
251 if( rMarkList
.GetMark(0) != 0 )
253 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
254 if( pObj
->GetObjIdentifier() == OBJ_CAPTION
)
256 // --------- Itemset fuer Caption --------
257 SfxItemSet
aNewAttr(pDoc
->GetItemPool());
258 pView
->GetAttributes(aNewAttr
);
259 // --------- Itemset fuer Groesse und Position --------
260 SfxItemSet
aNewGeoAttr(pView
->GetGeoAttrFromMarked());
262 //SvxCaptionTabDialog* pDlg = new SvxCaptionTabDialog(pWin, pView);
263 //change for cui CHINA001
264 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
267 SfxAbstractTabDialog
*pDlg
= pFact
->CreateCaptionDialog( pWin
, pView
, RID_SVXDLG_CAPTION
);
269 const USHORT
* pRange
= pDlg
->GetInputRanges( *aNewAttr
.GetPool() );
270 SfxItemSet
aCombSet( *aNewAttr
.GetPool(), pRange
);
271 aCombSet
.Put( aNewAttr
);
272 aCombSet
.Put( aNewGeoAttr
);
273 pDlg
->SetInputSet( &aCombSet
);
275 if (pDlg
->Execute() == RET_OK
)
277 rReq
.Done(*(pDlg
->GetOutputItemSet()));
278 pView
->SetAttributes(*pDlg
->GetOutputItemSet());
279 pView
->SetGeoAttrToMarked(*pDlg
->GetOutputItemSet());
287 SfxItemSet
aNewAttr(pView
->GetGeoAttrFromMarked());
288 //CHINA001 SvxTransformTabDialog* pDlg = new SvxTransformTabDialog(pWin, &aNewAttr, pView);
289 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
292 SfxAbstractTabDialog
* pDlg
= pFact
->CreateSvxTransformTabDialog( pWin
, &aNewAttr
,pView
, RID_SVXDLG_TRANSFORM
);
293 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
294 if (pDlg
->Execute() == RET_OK
)
296 rReq
.Done(*(pDlg
->GetOutputItemSet()));
297 pView
->SetGeoAttrToMarked(*pDlg
->GetOutputItemSet());
307 pView
->SetGeoAttrToMarked( *pArgs
);
317 void ScDrawShell::ExecuteMacroAssign( SdrObject
* pObj
, Window
* pWin
)
319 SvxMacroItem
aItem ( SFX_APP()->GetPool().GetWhich( SID_ATTR_MACROITEM
) );
320 ScMacroInfo
* pInfo
= ScDrawLayer::GetMacroInfo( pObj
, TRUE
);
321 if ( pInfo
->GetMacro().getLength() > 0 )
323 SvxMacroTableDtor aTab
;
324 String
sMacro( pInfo
->GetMacro() );
325 aTab
.Insert( SFX_EVENT_MOUSECLICK_OBJECT
, new SvxMacro( sMacro
, String() ) );
326 aItem
.SetMacroTable( aTab
);
329 // create empty itemset for macro-dlg
330 SfxItemSet
* pItemSet
= new SfxItemSet(SFX_APP()->GetPool(), SID_ATTR_MACROITEM
, SID_ATTR_MACROITEM
, SID_EVENTCONFIG
, SID_EVENTCONFIG
, 0 );
331 pItemSet
->Put ( aItem
, SID_ATTR_MACROITEM
);
333 SfxEventNamesItem
aNamesItem(SID_EVENTCONFIG
);
334 aNamesItem
.AddEvent( ScResId(RID_SCSTR_ONCLICK
), String(), SFX_EVENT_MOUSECLICK_OBJECT
);
335 pItemSet
->Put( aNamesItem
, SID_EVENTCONFIG
);
337 com::sun::star::uno::Reference
< com::sun::star::frame::XFrame
> xFrame
;
339 xFrame
= GetViewShell()->GetViewFrame()->GetFrame()->GetFrameInterface();
341 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
342 SfxAbstractDialog
* pMacroDlg
= pFact
->CreateSfxDialog( pWin
, *pItemSet
, xFrame
, SID_EVENTCONFIG
);
343 if ( pMacroDlg
&& pMacroDlg
->Execute() == RET_OK
)
345 const SfxItemSet
* pOutSet
= pMacroDlg
->GetOutputItemSet();
346 const SfxPoolItem
* pItem
;
347 if( SFX_ITEM_SET
== pOutSet
->GetItemState( SID_ATTR_MACROITEM
, FALSE
, &pItem
))
349 rtl::OUString sMacro
;
350 SvxMacro
* pMacro
= ((SvxMacroItem
*)pItem
)->GetMacroTable().Get( SFX_EVENT_MOUSECLICK_OBJECT
);
352 sMacro
= pMacro
->GetMacName();
354 if ( pObj
->IsGroupObject() )
356 SdrObjList
* pOL
= pObj
->GetSubList();
357 ULONG nObj
= pOL
->GetObjCount();
358 for ( ULONG index
=0; index
<nObj
; ++index
)
360 pInfo
= ScDrawLayer::GetMacroInfo( pOL
->GetObj(index
), TRUE
);
361 pInfo
->SetMacro( sMacro
);
365 pInfo
->SetMacro( sMacro
);
366 lcl_setModified( GetObjectShell() );
374 void ScDrawShell::ExecuteLineDlg( SfxRequest
& rReq
, USHORT nTabPage
)
376 ScDrawView
* pView
= pViewData
->GetScDrawView();
377 BOOL bHasMarked
= pView
->AreObjectsMarked();
378 const SdrObject
* pObj
= NULL
;
379 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
381 if( rMarkList
.GetMarkCount() == 1 )
382 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
384 SfxItemSet
aNewAttr( pView
->GetDefaultAttr() );
386 pView
->MergeAttrFromMarked( aNewAttr
, FALSE
);
388 //CHINA001 SvxLineTabDialog* pDlg
389 //CHINA001 = new SvxLineTabDialog( pViewData->GetDialogParent(),
390 //CHINA001 &aNewAttr,
391 //CHINA001 pViewData->GetDocument()->GetDrawLayer(),
393 //CHINA001 bHasMarked );
394 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
395 DBG_ASSERT(pFact
, "Dialogdiet Factory fail!");//CHINA001
396 SfxAbstractTabDialog
* pDlg
= pFact
->CreateSvxLineTabDialog( pViewData
->GetDialogParent(),
398 pViewData
->GetDocument()->GetDrawLayer(),
402 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
403 if ( nTabPage
!= 0xffff )
404 pDlg
->SetCurPageId( nTabPage
);
406 if ( pDlg
->Execute() == RET_OK
)
409 pView
->SetAttrToMarked( *pDlg
->GetOutputItemSet(), FALSE
);
411 pView
->SetDefaultAttr( *pDlg
->GetOutputItemSet(), FALSE
);
413 pView
->InvalidateAttribs();
420 void ScDrawShell::ExecuteAreaDlg( SfxRequest
& rReq
, USHORT nTabPage
)
422 ScDrawView
* pView
= pViewData
->GetScDrawView();
423 BOOL bHasMarked
= pView
->AreObjectsMarked();
425 SfxItemSet
aNewAttr( pView
->GetDefaultAttr() );
427 pView
->MergeAttrFromMarked( aNewAttr
, FALSE
);
429 //CHINA001 SvxAreaTabDialog* pDlg
430 //CHINA001 = new SvxAreaTabDialog( pViewData->GetDialogParent(),
431 //CHINA001 &aNewAttr,
432 //CHINA001 pViewData->GetDocument()->GetDrawLayer(),
435 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
436 DBG_ASSERT(pFact
, "Dialogdiet Factory fail!");//CHINA001
437 AbstractSvxAreaTabDialog
* pDlg
= pFact
->CreateSvxAreaTabDialog( pViewData
->GetDialogParent(),
439 pViewData
->GetDocument()->GetDrawLayer(),
442 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
444 // #i74099# by default, the dialog deletes the current color table if a different one is loaded
445 // (see SwDrawShell::ExecDrawDlg)
446 const SvxColorTableItem
* pColorItem
=
447 static_cast<const SvxColorTableItem
*>( pViewData
->GetSfxDocShell()->GetItem(SID_COLOR_TABLE
) );
448 if (pColorItem
->GetColorTable() == XColorTable::GetStdColorTable())
449 pDlg
->DontDeleteColorTable();
451 if ( nTabPage
!= 0xffff )
452 pDlg
->SetCurPageId( nTabPage
);
454 if ( pDlg
->Execute() == RET_OK
)
457 pView
->SetAttrToMarked( *pDlg
->GetOutputItemSet(), FALSE
);
459 pView
->SetDefaultAttr( *pDlg
->GetOutputItemSet(), FALSE
);
461 pView
->InvalidateAttribs();
468 void ScDrawShell::ExecuteTextAttrDlg( SfxRequest
& rReq
, USHORT
/* nTabPage */ )
470 ScDrawView
* pView
= pViewData
->GetScDrawView();
471 BOOL bHasMarked
= pView
->AreObjectsMarked();
472 SfxItemSet
aNewAttr ( pView
->GetDefaultAttr() );
475 pView
->MergeAttrFromMarked( aNewAttr
, FALSE
);
477 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
478 SfxAbstractTabDialog
*pDlg
= pFact
->CreateTextTabDialog( pViewData
->GetDialogParent(), &aNewAttr
, RID_SVXDLG_TEXT
, pView
);
480 USHORT nResult
= pDlg
->Execute();
482 if ( RET_OK
== nResult
)
485 pView
->SetAttributes( *pDlg
->GetOutputItemSet() );
487 pView
->SetDefaultAttr( *pDlg
->GetOutputItemSet(), FALSE
);
489 pView
->InvalidateAttribs();
495 void ScDrawShell::SetHlinkForObject( SdrObject
* pObj
, const rtl::OUString
& rHlnk
)
499 ScMacroInfo
* pInfo
= ScDrawLayer::GetMacroInfo( pObj
, TRUE
);
500 pInfo
->SetHlink( rHlnk
);
501 lcl_setModified( GetObjectShell() );