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 :
50 : #define ScDrawShell
51 : #include "scslots.hxx"
52 :
53 : #include "userdat.hxx"
54 : #include <svl/macitem.hxx>
55 : #include <sfx2/evntconf.hxx>
56 : #include <sfx2/viewsh.hxx>
57 : #include <com/sun/star/util/XModifiable.hpp>
58 : #include <com/sun/star/frame/XFrame.hpp>
59 :
60 : //------------------------------------------------------------------
61 :
62 0 : TYPEINIT1( ScDrawShell, SfxShell );
63 :
64 55 : SFX_IMPL_INTERFACE(ScDrawShell, SfxShell, ScResId(SCSTR_DRAWSHELL) )
65 : {
66 10 : SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
67 5 : ScResId(RID_DRAW_OBJECTBAR) );
68 5 : SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_DRAW) );
69 5 : SFX_CHILDWINDOW_REGISTRATION( SvxFontWorkChildWindow::GetChildWindowId() );
70 5 : }
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, sal_True);
123 : }
124 0 : break;
125 :
126 : case SID_ATTR_LINE_STYLE:
127 : case SID_ATTR_LINEEND_STYLE:
128 : case SID_ATTR_LINE_DASH:
129 : case SID_ATTR_LINE_WIDTH:
130 : case SID_ATTR_LINE_COLOR:
131 : case SID_ATTR_FILL_STYLE:
132 : case SID_ATTR_FILL_COLOR:
133 : case SID_ATTR_FILL_GRADIENT:
134 : case SID_ATTR_FILL_HATCH:
135 : case SID_ATTR_FILL_BITMAP:
136 :
137 : // #i25616#
138 : case SID_ATTR_FILL_SHADOW:
139 : {
140 : // Wenn ToolBar vertikal :
141 0 : if ( !rReq.GetArgs() )
142 : {
143 0 : switch ( nSlot )
144 : {
145 : case SID_ATTR_LINE_STYLE:
146 : case SID_ATTR_LINE_DASH:
147 : case SID_ATTR_LINE_WIDTH:
148 : case SID_ATTR_LINE_COLOR:
149 0 : ExecuteLineDlg( rReq );
150 0 : break;
151 :
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:
157 :
158 : // #i25616#
159 : case SID_ATTR_FILL_SHADOW:
160 :
161 0 : ExecuteAreaDlg( rReq );
162 0 : break;
163 :
164 : default:
165 0 : break;
166 : }
167 :
168 : //=====
169 0 : return;
170 : //=====
171 : }
172 :
173 0 : if( pView->AreObjectsMarked() )
174 0 : pView->SetAttrToMarked( *rReq.GetArgs(), false );
175 : else
176 0 : pView->SetDefaultAttr( *rReq.GetArgs(), false);
177 0 : pView->InvalidateAttribs();
178 : }
179 0 : break;
180 :
181 : case SID_ATTRIBUTES_LINE:
182 0 : ExecuteLineDlg( rReq );
183 0 : break;
184 :
185 : case SID_ATTRIBUTES_AREA:
186 0 : ExecuteAreaDlg( rReq );
187 0 : break;
188 :
189 : case SID_DRAWTEXT_ATTR_DLG:
190 0 : ExecuteTextAttrDlg( rReq );
191 0 : break;
192 :
193 : case SID_DRAW_HLINK_EDIT:
194 0 : if ( pSingleSelectedObj )
195 0 : pViewData->GetDispatcher().Execute( SID_HYPERLINK_DIALOG );
196 0 : break;
197 :
198 : case SID_DRAW_HLINK_DELETE:
199 0 : if ( pSingleSelectedObj )
200 0 : SetHlinkForObject( pSingleSelectedObj, rtl::OUString() );
201 0 : break;
202 :
203 : case SID_OPEN_HYPERLINK:
204 0 : if ( nMarkCount == 1 )
205 : {
206 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
207 0 : if ( pObj->IsGroupObject() )
208 : {
209 0 : SdrPageView* pPV = 0;
210 0 : SdrObject* pHit = 0;
211 0 : if ( pView->PickObj( pWin->PixelToLogic( pViewData->GetMousePosPixel() ), pView->getHitTolLog(), pHit, pPV, SDRSEARCH_DEEP ) )
212 0 : pObj = pHit;
213 : }
214 :
215 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
216 0 : if ( pInfo && !pInfo->GetHlink().isEmpty() )
217 0 : ScGlobal::OpenURL( pInfo->GetHlink(), String::EmptyString() );
218 : }
219 0 : break;
220 :
221 : case SID_ATTR_TRANSFORM:
222 : {
223 0 : if ( pView->AreObjectsMarked() )
224 : {
225 0 : const SfxItemSet* pArgs = rReq.GetArgs();
226 :
227 0 : if( !pArgs )
228 : {
229 0 : if( rMarkList.GetMark(0) != 0 )
230 : {
231 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
232 0 : if( pObj->GetObjIdentifier() == OBJ_CAPTION )
233 : {
234 : // --------- Itemset fuer Caption --------
235 0 : SfxItemSet aNewAttr(pDoc->GetItemPool());
236 0 : pView->GetAttributes(aNewAttr);
237 : // --------- Itemset fuer Groesse und Position --------
238 0 : SfxItemSet aNewGeoAttr(pView->GetGeoAttrFromMarked());
239 :
240 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
241 0 : if ( pFact )
242 : {
243 0 : SfxAbstractTabDialog *pDlg = pFact->CreateCaptionDialog( pWin, pView );
244 :
245 0 : const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
246 0 : SfxItemSet aCombSet( *aNewAttr.GetPool(), pRange );
247 0 : aCombSet.Put( aNewAttr );
248 0 : aCombSet.Put( aNewGeoAttr );
249 0 : pDlg->SetInputSet( &aCombSet );
250 :
251 0 : if (pDlg->Execute() == RET_OK)
252 : {
253 0 : rReq.Done(*(pDlg->GetOutputItemSet()));
254 0 : pView->SetAttributes(*pDlg->GetOutputItemSet());
255 0 : pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
256 : }
257 :
258 0 : delete pDlg;
259 0 : }
260 : }
261 : else
262 : {
263 0 : SfxItemSet aNewAttr(pView->GetGeoAttrFromMarked());
264 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
265 0 : if(pFact)
266 : {
267 0 : SfxAbstractTabDialog* pDlg = pFact->CreateSvxTransformTabDialog( pWin, &aNewAttr,pView );
268 : OSL_ENSURE(pDlg, "Dialog creation failed!");
269 0 : if (pDlg->Execute() == RET_OK)
270 : {
271 0 : rReq.Done(*(pDlg->GetOutputItemSet()));
272 0 : pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
273 : }
274 0 : delete pDlg;
275 0 : }
276 : }
277 : }
278 :
279 :
280 : }
281 : else
282 0 : pView->SetGeoAttrToMarked( *pArgs );
283 : }
284 : }
285 0 : break;
286 :
287 : default:
288 0 : break;
289 : }
290 : }
291 :
292 0 : void ScDrawShell::ExecuteMacroAssign( SdrObject* pObj, Window* pWin )
293 : {
294 0 : SvxMacroItem aItem ( SFX_APP()->GetPool().GetWhich( SID_ATTR_MACROITEM ) );
295 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, sal_True );
296 0 : if ( !pInfo->GetMacro().isEmpty() )
297 : {
298 0 : SvxMacroTableDtor aTab;
299 0 : rtl::OUString sMacro = pInfo->GetMacro();
300 0 : aTab.Insert(SFX_EVENT_MOUSECLICK_OBJECT, SvxMacro(sMacro, rtl::OUString()));
301 0 : aItem.SetMacroTable( aTab );
302 : }
303 :
304 : // create empty itemset for macro-dlg
305 0 : SfxItemSet* pItemSet = new SfxItemSet(SFX_APP()->GetPool(), SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 );
306 0 : pItemSet->Put ( aItem, SID_ATTR_MACROITEM );
307 :
308 0 : SfxEventNamesItem aNamesItem(SID_EVENTCONFIG);
309 0 : aNamesItem.AddEvent( ScResId(RID_SCSTR_ONCLICK), String(), SFX_EVENT_MOUSECLICK_OBJECT );
310 0 : pItemSet->Put( aNamesItem, SID_EVENTCONFIG );
311 :
312 0 : com::sun::star::uno::Reference < com::sun::star::frame::XFrame > xFrame;
313 0 : if (GetViewShell())
314 0 : xFrame = GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
315 :
316 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
317 0 : SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( pWin, *pItemSet, xFrame, SID_EVENTCONFIG );
318 0 : if ( pMacroDlg && pMacroDlg->Execute() == RET_OK )
319 : {
320 0 : const SfxItemSet* pOutSet = pMacroDlg->GetOutputItemSet();
321 : const SfxPoolItem* pItem;
322 0 : if( SFX_ITEM_SET == pOutSet->GetItemState( SID_ATTR_MACROITEM, false, &pItem ))
323 : {
324 0 : rtl::OUString sMacro;
325 0 : const SvxMacro* pMacro = ((SvxMacroItem*)pItem)->GetMacroTable().Get( SFX_EVENT_MOUSECLICK_OBJECT );
326 0 : if ( pMacro )
327 0 : sMacro = pMacro->GetMacName();
328 :
329 0 : if ( pObj->IsGroupObject() )
330 : {
331 0 : SdrObjList* pOL = pObj->GetSubList();
332 0 : sal_uLong nObj = pOL->GetObjCount();
333 0 : for ( sal_uLong index=0; index<nObj; ++index )
334 : {
335 0 : pInfo = ScDrawLayer::GetMacroInfo( pOL->GetObj(index), sal_True );
336 0 : pInfo->SetMacro( sMacro );
337 : }
338 : }
339 : else
340 0 : pInfo->SetMacro( sMacro );
341 0 : lcl_setModified( GetObjectShell() );
342 : }
343 : }
344 :
345 0 : delete pMacroDlg;
346 0 : delete pItemSet;
347 0 : }
348 :
349 0 : void ScDrawShell::ExecuteLineDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
350 : {
351 0 : ScDrawView* pView = pViewData->GetScDrawView();
352 0 : sal_Bool bHasMarked = pView->AreObjectsMarked();
353 0 : const SdrObject* pObj = NULL;
354 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
355 :
356 0 : if( rMarkList.GetMarkCount() == 1 )
357 0 : pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
358 :
359 0 : SfxItemSet aNewAttr( pView->GetDefaultAttr() );
360 0 : if( bHasMarked )
361 0 : pView->MergeAttrFromMarked( aNewAttr, false );
362 :
363 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
364 : OSL_ENSURE(pFact, "Dialogdiet Factory fail!");
365 : SfxAbstractTabDialog * pDlg = pFact->CreateSvxLineTabDialog( pViewData->GetDialogParent(),
366 : &aNewAttr,
367 0 : pViewData->GetDocument()->GetDrawLayer(),
368 : pObj,
369 0 : bHasMarked);
370 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
371 0 : if ( nTabPage != 0xffff )
372 0 : pDlg->SetCurPageId( nTabPage );
373 :
374 0 : if ( pDlg->Execute() == RET_OK )
375 : {
376 0 : if( bHasMarked )
377 0 : pView->SetAttrToMarked( *pDlg->GetOutputItemSet(), false );
378 : else
379 0 : pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
380 :
381 0 : pView->InvalidateAttribs();
382 0 : rReq.Done();
383 : }
384 :
385 0 : delete pDlg;
386 0 : }
387 :
388 0 : void ScDrawShell::ExecuteAreaDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
389 : {
390 0 : ScDrawView* pView = pViewData->GetScDrawView();
391 0 : sal_Bool bHasMarked = pView->AreObjectsMarked();
392 :
393 0 : SfxItemSet aNewAttr( pView->GetDefaultAttr() );
394 0 : if( bHasMarked )
395 0 : pView->MergeAttrFromMarked( aNewAttr, false );
396 :
397 :
398 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
399 : AbstractSvxAreaTabDialog * pDlg = pFact->CreateSvxAreaTabDialog(
400 : pViewData->GetDialogParent(), &aNewAttr,
401 0 : pViewData->GetDocument()->GetDrawLayer(), pView);
402 :
403 0 : if ( nTabPage != 0xffff )
404 0 : pDlg->SetCurPageId( nTabPage );
405 :
406 0 : if ( pDlg->Execute() == RET_OK )
407 : {
408 0 : if( bHasMarked )
409 0 : pView->SetAttrToMarked( *pDlg->GetOutputItemSet(), false );
410 : else
411 0 : pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
412 :
413 0 : pView->InvalidateAttribs();
414 0 : rReq.Done();
415 : }
416 :
417 0 : delete pDlg;
418 0 : }
419 :
420 0 : void ScDrawShell::ExecuteTextAttrDlg( SfxRequest& rReq, sal_uInt16 /* nTabPage */ )
421 : {
422 0 : ScDrawView* pView = pViewData->GetScDrawView();
423 0 : sal_Bool bHasMarked = pView->AreObjectsMarked();
424 0 : SfxItemSet aNewAttr ( pView->GetDefaultAttr() );
425 :
426 0 : if( bHasMarked )
427 0 : pView->MergeAttrFromMarked( aNewAttr, false );
428 :
429 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
430 0 : SfxAbstractTabDialog *pDlg = pFact->CreateTextTabDialog( pViewData->GetDialogParent(), &aNewAttr, pView );
431 :
432 0 : sal_uInt16 nResult = pDlg->Execute();
433 :
434 0 : if ( RET_OK == nResult )
435 : {
436 0 : if ( bHasMarked )
437 0 : pView->SetAttributes( *pDlg->GetOutputItemSet() );
438 : else
439 0 : pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
440 :
441 0 : pView->InvalidateAttribs();
442 0 : rReq.Done();
443 : }
444 0 : delete( pDlg );
445 0 : }
446 :
447 0 : void ScDrawShell::SetHlinkForObject( SdrObject* pObj, const rtl::OUString& rHlnk )
448 : {
449 0 : if ( pObj )
450 : {
451 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, sal_True );
452 0 : pInfo->SetHlink( rHlnk );
453 0 : lcl_setModified( GetObjectShell() );
454 : }
455 15 : }
456 :
457 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|