Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <svx/svxdlg.hxx>
22 : #include <svx/dialogs.hrc>
23 :
24 : #include "scitems.hxx"
25 :
26 : #include <editeng/eeitem.hxx>
27 : #include <svx/fontwork.hxx>
28 : #include <svl/srchitem.hxx>
29 : #include <svx/svdpage.hxx>
30 : #include <sfx2/app.hxx>
31 : #include <sfx2/objface.hxx>
32 : #include <sfx2/objsh.hxx>
33 : #include <sfx2/request.hxx>
34 : #include <sfx2/dispatch.hxx>
35 : #include <svl/whiter.hxx>
36 : #include <vcl/msgbox.hxx>
37 :
38 : #include "drawsh.hxx"
39 : #include "drwlayer.hxx"
40 : #include "sc.hrc"
41 : #include "viewdata.hxx"
42 : #include "document.hxx"
43 : #include "docpool.hxx"
44 : #include "drawview.hxx"
45 : #include "scresid.hxx"
46 : #include <svx/svdobj.hxx>
47 : #include <svx/drawitem.hxx>
48 : #include <svx/xtable.hxx>
49 : #include "tabvwsh.hxx"
50 : #include <sfx2/bindings.hxx>
51 :
52 : #define ScDrawShell
53 : #include "scslots.hxx"
54 :
55 : #include "userdat.hxx"
56 : #include <svl/macitem.hxx>
57 : #include <sfx2/evntconf.hxx>
58 : #include <sfx2/viewsh.hxx>
59 : #include <com/sun/star/util/XModifiable.hpp>
60 : #include <com/sun/star/frame/XFrame.hpp>
61 :
62 0 : TYPEINIT1( ScDrawShell, SfxShell );
63 :
64 0 : SFX_IMPL_INTERFACE(ScDrawShell, SfxShell, ScResId(SCSTR_DRAWSHELL) )
65 : {
66 0 : SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
67 0 : ScResId(RID_DRAW_OBJECTBAR) );
68 0 : SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_DRAW) );
69 0 : SFX_CHILDWINDOW_REGISTRATION( SvxFontWorkChildWindow::GetChildWindowId() );
70 0 : }
71 :
72 :
73 : // abschalten der nicht erwuenschten Acceleratoren:
74 :
75 0 : void ScDrawShell::StateDisableItems( SfxItemSet &rSet )
76 : {
77 0 : SfxWhichIter aIter(rSet);
78 0 : sal_uInt16 nWhich = aIter.FirstWhich();
79 :
80 0 : while (nWhich)
81 : {
82 0 : rSet.DisableItem( nWhich );
83 0 : nWhich = aIter.NextWhich();
84 0 : }
85 0 : }
86 :
87 0 : static void lcl_setModified( SfxObjectShell* pShell )
88 : {
89 0 : if ( pShell )
90 : {
91 0 : com::sun::star::uno::Reference< com::sun::star::util::XModifiable > xModif( pShell->GetModel(), com::sun::star::uno::UNO_QUERY );
92 0 : if ( xModif.is() )
93 0 : xModif->setModified( sal_True );
94 : }
95 0 : }
96 :
97 0 : void ScDrawShell::ExecDrawAttr( SfxRequest& rReq )
98 : {
99 0 : sal_uInt16 nSlot = rReq.GetSlot();
100 0 : Window* pWin = pViewData->GetActiveWin();
101 0 : ScDrawView* pView = pViewData->GetScDrawView();
102 0 : SdrModel* pDoc = pViewData->GetDocument()->GetDrawLayer();
103 :
104 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
105 0 : sal_uLong nMarkCount = rMarkList.GetMarkCount();
106 0 : SdrObject* pSingleSelectedObj = NULL;
107 0 : if ( nMarkCount > 0 )
108 0 : pSingleSelectedObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
109 :
110 0 : switch ( nSlot )
111 : {
112 : case SID_ASSIGNMACRO:
113 : {
114 0 : if ( pSingleSelectedObj )
115 0 : ExecuteMacroAssign( pSingleSelectedObj, pWin );
116 : }
117 0 : break;
118 :
119 : case SID_TEXT_STANDARD: // Harte Textattributierung loeschen
120 : {
121 0 : SfxItemSet aEmptyAttr(GetPool(), EE_ITEMS_START, EE_ITEMS_END);
122 0 : pView->SetAttributes(aEmptyAttr, true);
123 : }
124 0 : break;
125 :
126 : case SID_ATTR_LINE_STYLE:
127 : case SID_ATTR_LINEEND_STYLE:
128 : case SID_ATTR_LINE_START:
129 : case SID_ATTR_LINE_END:
130 : case SID_ATTR_LINE_DASH:
131 : case SID_ATTR_LINE_WIDTH:
132 : case SID_ATTR_LINE_COLOR:
133 : case SID_ATTR_LINE_TRANSPARENCE:
134 : case SID_ATTR_LINE_JOINT:
135 : case SID_ATTR_LINE_CAP:
136 : case SID_ATTR_FILL_STYLE:
137 : case SID_ATTR_FILL_COLOR:
138 : case SID_ATTR_FILL_GRADIENT:
139 : case SID_ATTR_FILL_HATCH:
140 : case SID_ATTR_FILL_BITMAP:
141 : case SID_ATTR_FILL_TRANSPARENCE:
142 : case SID_ATTR_FILL_FLOATTRANSPARENCE:
143 :
144 : // #i25616#
145 : case SID_ATTR_FILL_SHADOW:
146 : {
147 : // Wenn ToolBar vertikal :
148 0 : if ( !rReq.GetArgs() )
149 : {
150 0 : switch ( nSlot )
151 : {
152 : case SID_ATTR_LINE_STYLE:
153 : case SID_ATTR_LINE_DASH:
154 : case SID_ATTR_LINE_WIDTH:
155 : case SID_ATTR_LINE_COLOR:
156 : case SID_ATTR_LINE_TRANSPARENCE:
157 : case SID_ATTR_LINE_JOINT:
158 : case SID_ATTR_LINE_CAP:
159 0 : ExecuteLineDlg( rReq );
160 0 : break;
161 :
162 : case SID_ATTR_FILL_STYLE:
163 : case SID_ATTR_FILL_COLOR:
164 : case SID_ATTR_FILL_GRADIENT:
165 : case SID_ATTR_FILL_HATCH:
166 : case SID_ATTR_FILL_BITMAP:
167 : case SID_ATTR_FILL_TRANSPARENCE:
168 : case SID_ATTR_FILL_FLOATTRANSPARENCE:
169 :
170 : // #i25616#
171 : case SID_ATTR_FILL_SHADOW:
172 :
173 0 : ExecuteAreaDlg( rReq );
174 0 : break;
175 :
176 : default:
177 0 : break;
178 : }
179 :
180 :
181 0 : return;
182 :
183 : }
184 :
185 0 : if( pView->AreObjectsMarked() )
186 0 : pView->SetAttrToMarked( *rReq.GetArgs(), false );
187 : else
188 0 : pView->SetDefaultAttr( *rReq.GetArgs(), false);
189 0 : pView->InvalidateAttribs();
190 : }
191 0 : break;
192 :
193 : case SID_ATTRIBUTES_LINE:
194 0 : ExecuteLineDlg( rReq );
195 0 : break;
196 :
197 : case SID_ATTRIBUTES_AREA:
198 0 : ExecuteAreaDlg( rReq );
199 0 : break;
200 :
201 : case SID_DRAWTEXT_ATTR_DLG:
202 0 : ExecuteTextAttrDlg( rReq );
203 0 : break;
204 :
205 : case SID_DRAW_HLINK_EDIT:
206 0 : if ( pSingleSelectedObj )
207 0 : pViewData->GetDispatcher().Execute( SID_HYPERLINK_DIALOG );
208 0 : break;
209 :
210 : case SID_DRAW_HLINK_DELETE:
211 0 : if ( pSingleSelectedObj )
212 0 : SetHlinkForObject( pSingleSelectedObj, OUString() );
213 0 : break;
214 :
215 : case SID_OPEN_HYPERLINK:
216 0 : if ( nMarkCount == 1 )
217 : {
218 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
219 0 : if ( pObj->IsGroupObject() )
220 : {
221 0 : SdrPageView* pPV = 0;
222 0 : SdrObject* pHit = 0;
223 0 : if ( pView->PickObj( pWin->PixelToLogic( pViewData->GetMousePosPixel() ), pView->getHitTolLog(), pHit, pPV, SDRSEARCH_DEEP ) )
224 0 : pObj = pHit;
225 : }
226 :
227 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
228 0 : if ( pInfo && !pInfo->GetHlink().isEmpty() )
229 0 : ScGlobal::OpenURL( pInfo->GetHlink(), OUString() );
230 : }
231 0 : break;
232 :
233 : case SID_ATTR_TRANSFORM:
234 : {
235 : {
236 0 : if ( pView->AreObjectsMarked() )
237 : {
238 0 : const SfxItemSet* pArgs = rReq.GetArgs();
239 :
240 0 : if( !pArgs )
241 : {
242 0 : if( rMarkList.GetMark(0) != 0 )
243 : {
244 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
245 0 : if( pObj->GetObjIdentifier() == OBJ_CAPTION )
246 : {
247 : // --------- Itemset fuer Caption --------
248 0 : SfxItemSet aNewAttr(pDoc->GetItemPool());
249 0 : pView->GetAttributes(aNewAttr);
250 : // --------- Itemset fuer Groesse und Position --------
251 0 : SfxItemSet aNewGeoAttr(pView->GetGeoAttrFromMarked());
252 :
253 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
254 0 : if ( pFact )
255 : {
256 0 : SfxAbstractTabDialog *pDlg = pFact->CreateCaptionDialog( pWin, pView );
257 :
258 0 : const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
259 0 : SfxItemSet aCombSet( *aNewAttr.GetPool(), pRange );
260 0 : aCombSet.Put( aNewAttr );
261 0 : aCombSet.Put( aNewGeoAttr );
262 0 : pDlg->SetInputSet( &aCombSet );
263 :
264 0 : if (pDlg->Execute() == RET_OK)
265 : {
266 0 : rReq.Done(*(pDlg->GetOutputItemSet()));
267 0 : pView->SetAttributes(*pDlg->GetOutputItemSet());
268 0 : pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
269 : }
270 :
271 0 : delete pDlg;
272 0 : }
273 : }
274 : else
275 : {
276 0 : SfxItemSet aNewAttr(pView->GetGeoAttrFromMarked());
277 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
278 0 : if(pFact)
279 : {
280 0 : SfxAbstractTabDialog* pDlg = pFact->CreateSvxTransformTabDialog( pWin, &aNewAttr,pView );
281 : OSL_ENSURE(pDlg, "Dialog creation failed!");
282 0 : if (pDlg->Execute() == RET_OK)
283 : {
284 0 : rReq.Done(*(pDlg->GetOutputItemSet()));
285 0 : pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
286 : }
287 0 : delete pDlg;
288 0 : }
289 : }
290 : }
291 :
292 :
293 : }
294 : else
295 0 : pView->SetGeoAttrToMarked( *pArgs );
296 : }
297 : }
298 :
299 0 : ScTabViewShell* pViewShell = pViewData->GetViewShell();
300 0 : SfxBindings& rBindings=pViewShell->GetViewFrame()->GetBindings();
301 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_WIDTH);
302 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_HEIGHT);
303 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_POS_X);
304 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_POS_Y);
305 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_ANGLE);
306 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_ROT_X);
307 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_ROT_Y);
308 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_AUTOWIDTH);
309 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_AUTOHEIGHT);
310 0 : break;
311 : }
312 :
313 : default:
314 0 : break;
315 : }
316 : }
317 :
318 0 : void ScDrawShell::ExecuteMacroAssign( SdrObject* pObj, Window* pWin )
319 : {
320 0 : SvxMacroItem aItem ( SFX_APP()->GetPool().GetWhich( SID_ATTR_MACROITEM ) );
321 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, true );
322 0 : if ( !pInfo->GetMacro().isEmpty() )
323 : {
324 0 : SvxMacroTableDtor aTab;
325 0 : OUString sMacro = pInfo->GetMacro();
326 0 : aTab.Insert(SFX_EVENT_MOUSECLICK_OBJECT, SvxMacro(sMacro, OUString()));
327 0 : aItem.SetMacroTable( aTab );
328 : }
329 :
330 : // create empty itemset for macro-dlg
331 0 : SfxItemSet* pItemSet = new SfxItemSet(SFX_APP()->GetPool(), SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 );
332 0 : pItemSet->Put ( aItem, SID_ATTR_MACROITEM );
333 :
334 0 : SfxEventNamesItem aNamesItem(SID_EVENTCONFIG);
335 0 : aNamesItem.AddEvent( ScResId(RID_SCSTR_ONCLICK), OUString(), SFX_EVENT_MOUSECLICK_OBJECT );
336 0 : pItemSet->Put( aNamesItem, SID_EVENTCONFIG );
337 :
338 0 : com::sun::star::uno::Reference < com::sun::star::frame::XFrame > xFrame;
339 0 : if (GetViewShell())
340 0 : xFrame = GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
341 :
342 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
343 0 : SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( pWin, *pItemSet, xFrame, SID_EVENTCONFIG );
344 0 : if ( pMacroDlg && pMacroDlg->Execute() == RET_OK )
345 : {
346 0 : const SfxItemSet* pOutSet = pMacroDlg->GetOutputItemSet();
347 : const SfxPoolItem* pItem;
348 0 : if( SFX_ITEM_SET == pOutSet->GetItemState( SID_ATTR_MACROITEM, false, &pItem ))
349 : {
350 0 : OUString sMacro;
351 0 : const SvxMacro* pMacro = ((SvxMacroItem*)pItem)->GetMacroTable().Get( SFX_EVENT_MOUSECLICK_OBJECT );
352 0 : if ( pMacro )
353 0 : sMacro = pMacro->GetMacName();
354 :
355 0 : if ( pObj->IsGroupObject() )
356 : {
357 0 : SdrObjList* pOL = pObj->GetSubList();
358 0 : sal_uLong nObj = pOL->GetObjCount();
359 0 : for ( sal_uLong index=0; index<nObj; ++index )
360 : {
361 0 : pInfo = ScDrawLayer::GetMacroInfo( pOL->GetObj(index), true );
362 0 : pInfo->SetMacro( sMacro );
363 : }
364 : }
365 : else
366 0 : pInfo->SetMacro( sMacro );
367 0 : lcl_setModified( GetObjectShell() );
368 : }
369 : }
370 :
371 0 : delete pMacroDlg;
372 0 : delete pItemSet;
373 0 : }
374 :
375 0 : void ScDrawShell::ExecuteLineDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
376 : {
377 0 : ScDrawView* pView = pViewData->GetScDrawView();
378 0 : sal_Bool bHasMarked = pView->AreObjectsMarked();
379 0 : const SdrObject* pObj = NULL;
380 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
381 :
382 0 : if( rMarkList.GetMarkCount() == 1 )
383 0 : pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
384 :
385 0 : SfxItemSet aNewAttr( pView->GetDefaultAttr() );
386 0 : if( bHasMarked )
387 0 : pView->MergeAttrFromMarked( aNewAttr, false );
388 :
389 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
390 : OSL_ENSURE(pFact, "Dialogdiet Factory fail!");
391 : SfxAbstractTabDialog * pDlg = pFact->CreateSvxLineTabDialog( pViewData->GetDialogParent(),
392 : &aNewAttr,
393 0 : pViewData->GetDocument()->GetDrawLayer(),
394 : pObj,
395 0 : bHasMarked);
396 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
397 0 : if ( nTabPage != 0xffff )
398 0 : pDlg->SetCurPageId( nTabPage );
399 :
400 0 : if ( pDlg->Execute() == RET_OK )
401 : {
402 0 : if( bHasMarked )
403 0 : pView->SetAttrToMarked( *pDlg->GetOutputItemSet(), false );
404 : else
405 0 : pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
406 :
407 0 : pView->InvalidateAttribs();
408 0 : rReq.Done();
409 : }
410 :
411 0 : delete pDlg;
412 0 : }
413 :
414 0 : void ScDrawShell::ExecuteAreaDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
415 : {
416 0 : ScDrawView* pView = pViewData->GetScDrawView();
417 0 : sal_Bool bHasMarked = pView->AreObjectsMarked();
418 :
419 0 : SfxItemSet aNewAttr( pView->GetDefaultAttr() );
420 0 : if( bHasMarked )
421 0 : pView->MergeAttrFromMarked( aNewAttr, false );
422 :
423 :
424 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
425 : AbstractSvxAreaTabDialog * pDlg = pFact->CreateSvxAreaTabDialog(
426 : pViewData->GetDialogParent(), &aNewAttr,
427 0 : pViewData->GetDocument()->GetDrawLayer(), true);
428 :
429 0 : if ( nTabPage != 0xffff )
430 0 : pDlg->SetCurPageId( nTabPage );
431 :
432 0 : if ( pDlg->Execute() == RET_OK )
433 : {
434 0 : if( bHasMarked )
435 0 : pView->SetAttrToMarked( *pDlg->GetOutputItemSet(), false );
436 : else
437 0 : pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
438 :
439 0 : pView->InvalidateAttribs();
440 0 : rReq.Done();
441 : }
442 :
443 0 : delete pDlg;
444 0 : }
445 :
446 0 : void ScDrawShell::ExecuteTextAttrDlg( SfxRequest& rReq, sal_uInt16 /* nTabPage */ )
447 : {
448 0 : ScDrawView* pView = pViewData->GetScDrawView();
449 0 : sal_Bool bHasMarked = pView->AreObjectsMarked();
450 0 : SfxItemSet aNewAttr ( pView->GetDefaultAttr() );
451 :
452 0 : if( bHasMarked )
453 0 : pView->MergeAttrFromMarked( aNewAttr, false );
454 :
455 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
456 0 : SfxAbstractTabDialog *pDlg = pFact->CreateTextTabDialog( pViewData->GetDialogParent(), &aNewAttr, pView );
457 :
458 0 : sal_uInt16 nResult = pDlg->Execute();
459 :
460 0 : if ( RET_OK == nResult )
461 : {
462 0 : if ( bHasMarked )
463 0 : pView->SetAttributes( *pDlg->GetOutputItemSet() );
464 : else
465 0 : pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
466 :
467 0 : pView->InvalidateAttribs();
468 0 : rReq.Done();
469 : }
470 0 : delete( pDlg );
471 0 : }
472 :
473 0 : void ScDrawShell::SetHlinkForObject( SdrObject* pObj, const OUString& rHlnk )
474 : {
475 0 : if ( pObj )
476 : {
477 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, true );
478 0 : pInfo->SetHlink( rHlnk );
479 0 : lcl_setModified( GetObjectShell() );
480 : }
481 0 : }
482 :
483 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|