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 "DrawViewShell.hxx"
22 : #include <vcl/wrkwin.hxx>
23 : #include <svx/xgrad.hxx>
24 : #include <svx/svdpagv.hxx>
25 : #include <svx/xlnwtit.hxx>
26 : #include <svx/xlndsit.hxx>
27 : #include <svx/xflhtit.hxx>
28 : #include <svx/xflgrit.hxx>
29 : #include <svx/xlnclit.hxx>
30 : #include <svx/xflclit.hxx>
31 : #include <sfx2/bindings.hxx>
32 :
33 : #include <sfx2/dispatch.hxx>
34 : #include <svl/intitem.hxx>
35 : #include <sfx2/app.hxx>
36 : #include <sfx2/request.hxx>
37 : #include <svl/stritem.hxx>
38 : #include <svx/svxids.hrc>
39 : #include <svx/xtable.hxx>
40 : #include <svx/gallery.hxx>
41 : #include <vcl/graph.hxx>
42 : #include <svx/svdograf.hxx>
43 : #include <svx/svdoole2.hxx>
44 : #include <sot/storage.hxx>
45 : #include <svl/whiter.hxx>
46 : #include <basic/sbstar.hxx>
47 :
48 : #include <sfx2/viewfrm.hxx>
49 :
50 :
51 : #include "app.hrc"
52 : #include "strings.hrc"
53 : #include "Window.hxx"
54 : #include "drawdoc.hxx"
55 : #include "drawview.hxx"
56 : #include "DrawDocShell.hxx"
57 : #include "sdresid.hxx"
58 : #include "fupoor.hxx"
59 :
60 : #include <svx/galleryitem.hxx>
61 : #include <com/sun/star/gallery/GalleryItemType.hpp>
62 :
63 : namespace sd {
64 :
65 :
66 0 : void DrawViewShell::ExecGallery(SfxRequest& rReq)
67 : {
68 : // nothing is executed during a slide show!
69 0 : if(HasCurrentFunction(SID_PRESENTATION))
70 0 : return;
71 :
72 0 : const SfxItemSet* pArgs = rReq.GetArgs();
73 :
74 0 : SFX_ITEMSET_ARG( pArgs, pGalleryItem, SvxGalleryItem, SID_GALLERY_FORMATS, sal_False );
75 0 : if ( !pGalleryItem )
76 0 : return;
77 :
78 0 : GetDocSh()->SetWaitCursor( sal_True );
79 :
80 0 : sal_Int8 nType( pGalleryItem->GetType() );
81 : // insert graphic
82 0 : if (nType == com::sun::star::gallery::GalleryItemType::GRAPHIC)
83 : {
84 0 : Graphic aGraphic( pGalleryItem->GetGraphic() );
85 :
86 : // reduce size if necessary
87 0 : Window aWindow (GetActiveWindow());
88 0 : aWindow.SetMapMode(aGraphic.GetPrefMapMode());
89 0 : Size aSizePix = aWindow.LogicToPixel(aGraphic.GetPrefSize());
90 0 : aWindow.SetMapMode( MapMode(MAP_100TH_MM) );
91 0 : Size aSize = aWindow.PixelToLogic(aSizePix);
92 :
93 : // constrain size to page size if necessary
94 0 : SdrPage* pPage = mpDrawView->GetSdrPageView()->GetPage();
95 0 : Size aPageSize = pPage->GetSize();
96 0 : aPageSize.Width() -= pPage->GetLftBorder() + pPage->GetRgtBorder();
97 0 : aPageSize.Height() -= pPage->GetUppBorder() + pPage->GetLwrBorder();
98 :
99 :
100 : // Falls Grafik zu gross, wird die Grafik
101 : // in die Seite eingepasst
102 0 : if ( ( ( aSize.Height() > aPageSize.Height() ) || ( aSize.Width() > aPageSize.Width() ) ) &&
103 0 : aSize.Height() && aPageSize.Height() )
104 : {
105 0 : float fGrfWH = (float)aSize.Width() /
106 0 : (float)aSize.Height();
107 0 : float fWinWH = (float)aPageSize.Width() /
108 0 : (float)aPageSize.Height();
109 :
110 : // constrain size to page size if necessary
111 0 : if ((fGrfWH != 0.F) && (fGrfWH < fWinWH))
112 : {
113 0 : aSize.Width() = (long)(aPageSize.Height() * fGrfWH);
114 0 : aSize.Height()= aPageSize.Height();
115 : }
116 : else
117 : {
118 0 : aSize.Width() = aPageSize.Width();
119 0 : aSize.Height()= (long)(aPageSize.Width() / fGrfWH);
120 : }
121 : }
122 :
123 : // set output rectangle for graphic
124 0 : Point aPnt ((aPageSize.Width() - aSize.Width()) / 2,
125 0 : (aPageSize.Height() - aSize.Height()) / 2);
126 0 : aPnt += Point(pPage->GetLftBorder(), pPage->GetUppBorder());
127 0 : Rectangle aRect (aPnt, aSize);
128 :
129 0 : SdrGrafObj* pGrafObj = NULL;
130 :
131 0 : sal_Bool bInsertNewObject = sal_True;
132 :
133 0 : if ( mpDrawView->AreObjectsMarked() )
134 : {
135 : // is there a empty graphic object?
136 0 : const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
137 :
138 0 : if (rMarkList.GetMarkCount() == 1)
139 : {
140 0 : SdrMark* pMark = rMarkList.GetMark(0);
141 0 : SdrObject* pObj = pMark->GetMarkedSdrObj();
142 :
143 0 : if (pObj->GetObjInventor() == SdrInventor && pObj->GetObjIdentifier() == OBJ_GRAF)
144 : {
145 0 : pGrafObj = (SdrGrafObj*) pObj;
146 :
147 0 : if( pGrafObj->IsEmptyPresObj() )
148 : {
149 : // the empty graphic object gets a new graphic
150 0 : bInsertNewObject = sal_False;
151 :
152 0 : SdrGrafObj* pNewGrafObj = (SdrGrafObj*) pGrafObj->Clone();
153 0 : pNewGrafObj->SetEmptyPresObj(sal_False);
154 0 : pNewGrafObj->SetOutlinerParaObject(NULL);
155 0 : pNewGrafObj->SetGraphic(aGraphic);
156 :
157 0 : String aStr(mpDrawView->GetDescriptionOfMarkedObjects());
158 0 : aStr += sal_Unicode(' ');
159 0 : aStr += String(SdResId(STR_UNDO_REPLACE));
160 0 : mpDrawView->BegUndo(aStr);
161 0 : SdrPageView* pPV = mpDrawView->GetSdrPageView();
162 0 : mpDrawView->ReplaceObjectAtView(pGrafObj, *pPV, pNewGrafObj);
163 0 : mpDrawView->EndUndo();
164 : }
165 : }
166 : }
167 : }
168 :
169 :
170 0 : if( bInsertNewObject )
171 : {
172 0 : pGrafObj = new SdrGrafObj(aGraphic, aRect);
173 0 : SdrPageView* pPV = mpDrawView->GetSdrPageView();
174 0 : mpDrawView->InsertObjectAtView(pGrafObj, *pPV, SDRINSERT_SETDEFLAYER);
175 : }
176 :
177 : // Soll nur ein Link benutzt werden?
178 0 : if( pGrafObj && pGalleryItem->IsLink() )
179 0 : pGrafObj->SetGraphicLink( pGalleryItem->GetURL(), pGalleryItem->GetFilterName() );
180 : }
181 : // insert sound
182 0 : else if( nType == com::sun::star::gallery::GalleryItemType::MEDIA )
183 : {
184 0 : const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, pGalleryItem->GetURL() );
185 0 : GetViewFrame()->GetDispatcher()->Execute( SID_INSERT_AVMEDIA, SFX_CALLMODE_SYNCHRON, &aMediaURLItem, 0L );
186 : }
187 :
188 0 : GetDocSh()->SetWaitCursor( sal_False );
189 : }
190 :
191 :
192 :
193 0 : void DrawViewShell::GetGalleryState(SfxItemSet& )
194 : {
195 0 : }
196 :
197 : /**
198 : * Edit macros for attribute configuration
199 : */
200 :
201 : /* the work flow to adjust the attributes is nearly everywhere the same
202 : 1. read existing attributes
203 : 2. read parameter from the basic-set
204 : 3. delete selected item from the attribute-set
205 : 4. create new attribute-item
206 : 5. insert item into set */
207 0 : void DrawViewShell::AttrExec (SfxRequest &rReq)
208 : {
209 : // nothing is executed during a slide show!
210 0 : if(HasCurrentFunction(SID_PRESENTATION))
211 0 : return;
212 :
213 0 : CheckLineTo (rReq);
214 :
215 0 : SfxBindings& rBindings = GetViewFrame()->GetBindings();
216 0 : SfxItemSet* pAttr = new SfxItemSet ( GetDoc()->GetPool() );
217 :
218 0 : GetView()->GetAttributes( *pAttr );
219 0 : const SfxItemSet* pArgs = rReq.GetArgs();
220 :
221 0 : switch (rReq.GetSlot ())
222 : {
223 : // set new fill-style
224 : case SID_SETFILLSTYLE :
225 0 : if (pArgs)
226 0 : if (pArgs->Count () == 1)
227 : {
228 0 : SFX_REQUEST_ARG (rReq, pFillStyle, SfxUInt32Item, ID_VAL_STYLE, sal_False);
229 0 : if (CHECK_RANGE (XFILL_NONE, (sal_Int32)pFillStyle->GetValue (), XFILL_BITMAP))
230 : {
231 0 : pAttr->ClearItem (XATTR_FILLSTYLE);
232 0 : pAttr->Put (XFillStyleItem ((XFillStyle) pFillStyle->GetValue ()), XATTR_FILLSTYLE);
233 0 : rBindings.Invalidate (SID_ATTR_FILL_STYLE);
234 : }
235 : #ifndef DISABLE_SCRIPTING
236 0 : else StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
237 : #endif
238 0 : break;
239 : }
240 : #ifndef DISABLE_SCRIPTING
241 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
242 : #endif
243 0 : break;
244 :
245 : // determine new line style
246 : case SID_SETLINESTYLE :
247 0 : if (pArgs)
248 0 : if (pArgs->Count () == 1)
249 : {
250 0 : SFX_REQUEST_ARG (rReq, pLineStyle, SfxUInt32Item, ID_VAL_STYLE, sal_False);
251 0 : if (CHECK_RANGE (XLINE_NONE, (sal_Int32)pLineStyle->GetValue (), XLINE_DASH))
252 : {
253 0 : pAttr->ClearItem (XATTR_LINESTYLE);
254 0 : pAttr->Put (XLineStyleItem ((XLineStyle) pLineStyle->GetValue ()), XATTR_LINESTYLE);
255 0 : rBindings.Invalidate (SID_ATTR_LINE_STYLE);
256 : }
257 : #ifndef DISABLE_SCRIPTING
258 0 : else StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
259 : #endif
260 0 : break;
261 : }
262 : #ifndef DISABLE_SCRIPTING
263 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
264 : #endif
265 0 : break;
266 :
267 : // set line width
268 : case SID_SETLINEWIDTH :
269 0 : if (pArgs)
270 0 : if (pArgs->Count () == 1)
271 : {
272 0 : SFX_REQUEST_ARG (rReq, pLineWidth, SfxUInt32Item, ID_VAL_WIDTH, sal_False);
273 0 : pAttr->ClearItem (XATTR_LINEWIDTH);
274 0 : pAttr->Put (XLineWidthItem (pLineWidth->GetValue ()), XATTR_LINEWIDTH);
275 0 : rBindings.Invalidate (SID_ATTR_LINE_WIDTH);
276 0 : break;
277 : }
278 : #ifndef DISABLE_SCRIPTING
279 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
280 : #endif
281 0 : break;
282 :
283 : case SID_SETFILLCOLOR :
284 0 : if (pArgs)
285 0 : if (pArgs->Count () == 3)
286 : {
287 0 : SFX_REQUEST_ARG (rReq, pRed, SfxUInt32Item, ID_VAL_RED, sal_False);
288 0 : SFX_REQUEST_ARG (rReq, pGreen, SfxUInt32Item, ID_VAL_GREEN, sal_False);
289 0 : SFX_REQUEST_ARG (rReq, pBlue, SfxUInt32Item, ID_VAL_BLUE, sal_False);
290 :
291 0 : pAttr->ClearItem (XATTR_FILLCOLOR);
292 0 : pAttr->ClearItem (XATTR_FILLSTYLE);
293 0 : pAttr->Put (XFillColorItem (-1, Color ((sal_uInt8) pRed->GetValue (),
294 0 : (sal_uInt8) pGreen->GetValue (),
295 0 : (sal_uInt8) pBlue->GetValue ())),
296 0 : XATTR_FILLCOLOR);
297 0 : pAttr->Put (XFillStyleItem (XFILL_SOLID), XATTR_FILLSTYLE);
298 0 : rBindings.Invalidate (SID_ATTR_FILL_COLOR);
299 0 : rBindings.Invalidate (SID_ATTR_FILL_STYLE);
300 0 : break;
301 : }
302 : #ifndef DISABLE_SCRIPTING
303 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
304 : #endif
305 0 : break;
306 :
307 : case SID_SETLINECOLOR :
308 0 : if (pArgs)
309 0 : if (pArgs->Count () == 3)
310 : {
311 0 : SFX_REQUEST_ARG (rReq, pRed, SfxUInt32Item, ID_VAL_RED, sal_False);
312 0 : SFX_REQUEST_ARG (rReq, pGreen, SfxUInt32Item, ID_VAL_GREEN, sal_False);
313 0 : SFX_REQUEST_ARG (rReq, pBlue, SfxUInt32Item, ID_VAL_BLUE, sal_False);
314 :
315 0 : pAttr->ClearItem (XATTR_LINECOLOR);
316 0 : pAttr->Put (XLineColorItem (-1, Color ((sal_uInt8) pRed->GetValue (),
317 0 : (sal_uInt8) pGreen->GetValue (),
318 0 : (sal_uInt8) pBlue->GetValue ())),
319 0 : XATTR_LINECOLOR);
320 0 : rBindings.Invalidate (SID_ATTR_LINE_COLOR);
321 0 : break;
322 : }
323 : #ifndef DISABLE_SCRIPTING
324 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
325 : #endif
326 0 : break;
327 :
328 : case SID_SETGRADSTARTCOLOR :
329 : case SID_SETGRADENDCOLOR :
330 0 : if (pArgs)
331 0 : if (pArgs->Count () == 4)
332 : {
333 0 : SFX_REQUEST_ARG (rReq, pName, SfxStringItem, ID_VAL_INDEX, sal_False);
334 0 : SFX_REQUEST_ARG (rReq, pRed, SfxUInt32Item, ID_VAL_RED, sal_False);
335 0 : SFX_REQUEST_ARG (rReq, pGreen, SfxUInt32Item, ID_VAL_GREEN, sal_False);
336 0 : SFX_REQUEST_ARG (rReq, pBlue, SfxUInt32Item, ID_VAL_BLUE, sal_False);
337 :
338 0 : XGradientListRef pGradientList = GetDoc()->GetGradientList ();
339 0 : long nCounts = pGradientList->Count ();
340 0 : Color aColor ((sal_uInt8) pRed->GetValue (),
341 0 : (sal_uInt8) pGreen->GetValue (),
342 0 : (sal_uInt8) pBlue->GetValue ());
343 : long i;
344 :
345 0 : pAttr->ClearItem (XATTR_FILLGRADIENT);
346 0 : pAttr->ClearItem (XATTR_FILLSTYLE);
347 :
348 0 : for ( i = 0; i < nCounts; i ++)
349 : {
350 0 : XGradientEntry *pEntry = pGradientList->GetGradient (i);
351 :
352 0 : if (pEntry->GetName () == pName->GetValue ())
353 : {
354 0 : XGradient aGradient(pEntry->GetGradient());
355 :
356 0 : if (rReq.GetSlot () == SID_SETGRADSTARTCOLOR) aGradient.SetStartColor (aColor);
357 0 : else aGradient.SetEndColor (aColor);
358 :
359 0 : pAttr->Put (XFillStyleItem (XFILL_GRADIENT), XATTR_FILLSTYLE);
360 0 : pAttr->Put (XFillGradientItem (pName->GetValue (), aGradient), XATTR_FILLGRADIENT);
361 0 : break;
362 : }
363 : }
364 :
365 0 : if (i >= nCounts)
366 : {
367 0 : Color aBlack (0, 0, 0);
368 0 : XGradient aGradient ((rReq.GetSlot () == SID_SETGRADSTARTCOLOR)
369 : ? aColor
370 : : aBlack,
371 0 : (rReq.GetSlot () == SID_SETGRADENDCOLOR)
372 : ? aColor
373 0 : : aBlack);
374 :
375 0 : GetDoc()->GetGradientList ()->Insert (new XGradientEntry (aGradient, pName->GetValue ()));
376 :
377 0 : pAttr->Put (XFillStyleItem (XFILL_GRADIENT), XATTR_FILLSTYLE);
378 0 : pAttr->Put (XFillGradientItem (pName->GetValue (), aGradient), XATTR_FILLGRADIENT);
379 : }
380 :
381 0 : rBindings.Invalidate (SID_ATTR_FILL_STYLE);
382 0 : rBindings.Invalidate (SID_ATTR_FILL_GRADIENT);
383 0 : break;
384 : }
385 : #ifndef DISABLE_SCRIPTING
386 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
387 : #endif
388 0 : break;
389 :
390 : case SID_SETHATCHCOLOR :
391 0 : if (pArgs)
392 0 : if (pArgs->Count () == 4)
393 : {
394 0 : SFX_REQUEST_ARG (rReq, pName, SfxStringItem, ID_VAL_INDEX, sal_False);
395 0 : SFX_REQUEST_ARG (rReq, pRed, SfxUInt32Item, ID_VAL_RED, sal_False);
396 0 : SFX_REQUEST_ARG (rReq, pGreen, SfxUInt32Item, ID_VAL_GREEN, sal_False);
397 0 : SFX_REQUEST_ARG (rReq, pBlue, SfxUInt32Item, ID_VAL_BLUE, sal_False);
398 :
399 0 : XHatchListRef pHatchList = GetDoc()->GetHatchList ();
400 0 : long nCounts = pHatchList->Count ();
401 0 : Color aColor ((sal_uInt8) pRed->GetValue (),
402 0 : (sal_uInt8) pGreen->GetValue (),
403 0 : (sal_uInt8) pBlue->GetValue ());
404 : long i;
405 :
406 0 : pAttr->ClearItem (XATTR_FILLHATCH);
407 0 : pAttr->ClearItem (XATTR_FILLSTYLE);
408 :
409 0 : for ( i = 0; i < nCounts; i ++)
410 : {
411 0 : XHatchEntry *pEntry = pHatchList->GetHatch (i);
412 :
413 0 : if (pEntry->GetName () == pName->GetValue ())
414 : {
415 0 : XHatch aHatch(pEntry->GetHatch());
416 :
417 0 : aHatch.SetColor (aColor);
418 :
419 0 : pAttr->Put (XFillStyleItem (XFILL_HATCH), XATTR_FILLSTYLE);
420 0 : pAttr->Put (XFillHatchItem (pName->GetValue (), aHatch), XATTR_FILLHATCH);
421 0 : break;
422 : }
423 : }
424 :
425 0 : if (i >= nCounts)
426 : {
427 0 : XHatch aHatch (aColor);
428 :
429 0 : GetDoc()->GetHatchList ()->Insert (new XHatchEntry (aHatch, pName->GetValue ()));
430 :
431 0 : pAttr->Put (XFillStyleItem (XFILL_HATCH), XATTR_FILLSTYLE);
432 0 : pAttr->Put (XFillHatchItem (pName->GetValue (), aHatch), XATTR_FILLHATCH);
433 : }
434 :
435 0 : rBindings.Invalidate (SID_ATTR_FILL_HATCH);
436 0 : rBindings.Invalidate (SID_ATTR_FILL_STYLE);
437 0 : break;
438 : }
439 : #ifndef DISABLE_SCRIPTING
440 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
441 : #endif
442 0 : break;
443 :
444 : // einstellungen fuer liniendash
445 : case SID_DASH :
446 0 : if (pArgs)
447 0 : if (pArgs->Count () == 7)
448 : {
449 0 : SFX_REQUEST_ARG (rReq, pName, SfxStringItem, ID_VAL_INDEX, sal_False);
450 0 : SFX_REQUEST_ARG (rReq, pStyle, SfxUInt32Item, ID_VAL_STYLE, sal_False);
451 0 : SFX_REQUEST_ARG (rReq, pDots, SfxUInt32Item, ID_VAL_DOTS, sal_False);
452 0 : SFX_REQUEST_ARG (rReq, pDotLen, SfxUInt32Item, ID_VAL_DOTLEN, sal_False);
453 0 : SFX_REQUEST_ARG (rReq, pDashes, SfxUInt32Item, ID_VAL_DASHES, sal_False);
454 0 : SFX_REQUEST_ARG (rReq, pDashLen, SfxUInt32Item, ID_VAL_DASHLEN, sal_False);
455 0 : SFX_REQUEST_ARG (rReq, pDistance, SfxUInt32Item, ID_VAL_DISTANCE, sal_False);
456 :
457 0 : if (CHECK_RANGE (XDASH_RECT, (sal_Int32)pStyle->GetValue (), XDASH_ROUNDRELATIVE))
458 : {
459 0 : XDash aNewDash ((XDashStyle) pStyle->GetValue (), (short) pDots->GetValue (), pDotLen->GetValue (),
460 0 : (short) pDashes->GetValue (), pDashLen->GetValue (), pDistance->GetValue ());
461 :
462 0 : pAttr->ClearItem (XATTR_LINEDASH);
463 0 : pAttr->ClearItem (XATTR_LINESTYLE);
464 :
465 0 : XDashListRef pDashList = GetDoc()->GetDashList();
466 0 : long nCounts = pDashList->Count ();
467 0 : XDashEntry *pEntry = new XDashEntry (aNewDash, pName->GetValue ());
468 : long i;
469 :
470 0 : for ( i = 0; i < nCounts; i++ )
471 0 : if (pDashList->GetDash (i)->GetName () == pName->GetValue ())
472 0 : break;
473 :
474 0 : if (i < nCounts)
475 0 : pDashList->Replace (pEntry, i);
476 : else
477 0 : pDashList->Insert (pEntry);
478 :
479 0 : pAttr->Put (XLineDashItem (pName->GetValue (), aNewDash), XATTR_LINEDASH);
480 0 : pAttr->Put (XLineStyleItem (XLINE_DASH), XATTR_LINESTYLE);
481 0 : rBindings.Invalidate (SID_ATTR_LINE_DASH);
482 0 : rBindings.Invalidate (SID_ATTR_FILL_STYLE);
483 : }
484 : #ifndef DISABLE_SCRIPTING
485 0 : else StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
486 : #endif
487 0 : break;
488 : }
489 : #ifndef DISABLE_SCRIPTING
490 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
491 : #endif
492 0 : break;
493 :
494 : // configuration for gradients
495 : case SID_GRADIENT :
496 0 : if (pArgs)
497 0 : if (pArgs->Count () == 8)
498 : {
499 0 : SFX_REQUEST_ARG (rReq, pName, SfxStringItem, ID_VAL_INDEX, sal_False);
500 0 : SFX_REQUEST_ARG (rReq, pStyle, SfxUInt32Item, ID_VAL_STYLE, sal_False);
501 0 : SFX_REQUEST_ARG (rReq, pAngle, SfxUInt32Item, ID_VAL_ANGLE, sal_False);
502 0 : SFX_REQUEST_ARG (rReq, pBorder, SfxUInt32Item, ID_VAL_BORDER, sal_False);
503 0 : SFX_REQUEST_ARG (rReq, pCenterX, SfxUInt32Item, ID_VAL_CENTER_X, sal_False);
504 0 : SFX_REQUEST_ARG (rReq, pCenterY, SfxUInt32Item, ID_VAL_CENTER_Y, sal_False);
505 0 : SFX_REQUEST_ARG (rReq, pStart, SfxUInt32Item, ID_VAL_STARTINTENS, sal_False);
506 0 : SFX_REQUEST_ARG (rReq, pEnd, SfxUInt32Item, ID_VAL_ENDINTENS, sal_False);
507 :
508 0 : if (CHECK_RANGE (XGRAD_LINEAR, (sal_Int32)pStyle->GetValue (), XGRAD_RECT) &&
509 0 : CHECK_RANGE (0, (sal_Int32)pAngle->GetValue (), 360) &&
510 0 : CHECK_RANGE (0, (sal_Int32)pBorder->GetValue (), 100) &&
511 0 : CHECK_RANGE (0, (sal_Int32)pCenterX->GetValue (), 100) &&
512 0 : CHECK_RANGE (0, (sal_Int32)pCenterY->GetValue (), 100) &&
513 0 : CHECK_RANGE (0, (sal_Int32)pStart->GetValue (), 100) &&
514 0 : CHECK_RANGE (0, (sal_Int32)pEnd->GetValue (), 100))
515 : {
516 0 : pAttr->ClearItem (XATTR_FILLGRADIENT);
517 0 : pAttr->ClearItem (XATTR_FILLSTYLE);
518 :
519 0 : XGradientListRef pGradientList = GetDoc()->GetGradientList ();
520 0 : long nCounts = pGradientList->Count ();
521 : long i;
522 :
523 0 : for ( i = 0; i < nCounts; i++ )
524 : {
525 0 : XGradientEntry *pEntry = pGradientList->GetGradient (i);
526 :
527 0 : if (pEntry->GetName () == pName->GetValue ())
528 : {
529 0 : XGradient aGradient(pEntry->GetGradient());
530 :
531 0 : aGradient.SetGradientStyle ((XGradientStyle) pStyle->GetValue ());
532 0 : aGradient.SetAngle (pAngle->GetValue () * 10);
533 0 : aGradient.SetBorder ((short) pBorder->GetValue ());
534 0 : aGradient.SetXOffset ((short) pCenterX->GetValue ());
535 0 : aGradient.SetYOffset ((short) pCenterY->GetValue ());
536 0 : aGradient.SetStartIntens ((short) pStart->GetValue ());
537 0 : aGradient.SetEndIntens ((short) pEnd->GetValue ());
538 :
539 0 : pAttr->Put (XFillStyleItem (XFILL_GRADIENT), XATTR_FILLSTYLE);
540 0 : pAttr->Put (XFillGradientItem (pName->GetValue (), aGradient), XATTR_FILLGRADIENT);
541 0 : break;
542 : }
543 : }
544 :
545 0 : if (i >= nCounts)
546 : {
547 0 : Color aBlack (0, 0, 0);
548 0 : XGradient aGradient (aBlack, aBlack, (XGradientStyle) pStyle->GetValue (),
549 0 : pAngle->GetValue () * 10, (short) pCenterX->GetValue (),
550 0 : (short) pCenterY->GetValue (), (short) pBorder->GetValue (),
551 0 : (short) pStart->GetValue (), (short) pEnd->GetValue ());
552 :
553 0 : pGradientList->Insert (new XGradientEntry (aGradient, pName->GetValue ()));
554 0 : pAttr->Put (XFillStyleItem (XFILL_GRADIENT), XATTR_FILLSTYLE);
555 0 : pAttr->Put (XFillGradientItem (pName->GetValue (), aGradient), XATTR_FILLGRADIENT);
556 : }
557 :
558 0 : rBindings.Invalidate (SID_ATTR_FILL_GRADIENT);
559 0 : rBindings.Invalidate (SID_ATTR_FILL_STYLE);
560 : }
561 : #ifndef DISABLE_SCRIPTING
562 0 : else StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
563 : #endif
564 0 : break;
565 : }
566 : #ifndef DISABLE_SCRIPTING
567 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
568 : #endif
569 0 : break;
570 :
571 : // configuration for hatch
572 : case SID_HATCH :
573 0 : if (pArgs)
574 0 : if (pArgs->Count () == 4)
575 : {
576 0 : SFX_REQUEST_ARG (rReq, pName, SfxStringItem, ID_VAL_INDEX, sal_False);
577 0 : SFX_REQUEST_ARG (rReq, pStyle, SfxUInt32Item, ID_VAL_STYLE, sal_False);
578 0 : SFX_REQUEST_ARG (rReq, pDistance, SfxUInt32Item, ID_VAL_DISTANCE, sal_False);
579 0 : SFX_REQUEST_ARG (rReq, pAngle, SfxUInt32Item, ID_VAL_ANGLE, sal_False);
580 :
581 0 : if (CHECK_RANGE (XHATCH_SINGLE, (sal_Int32)pStyle->GetValue (), XHATCH_TRIPLE) &&
582 0 : CHECK_RANGE (0, (sal_Int32)pAngle->GetValue (), 360))
583 : {
584 0 : pAttr->ClearItem (XATTR_FILLHATCH);
585 0 : pAttr->ClearItem (XATTR_FILLSTYLE);
586 :
587 0 : XHatchListRef pHatchList = GetDoc()->GetHatchList ();
588 0 : long nCounts = pHatchList->Count ();
589 : long i;
590 :
591 0 : for ( i = 0; i < nCounts; i++ )
592 : {
593 0 : XHatchEntry *pEntry = pHatchList->GetHatch (i);
594 :
595 0 : if (pEntry->GetName () == pName->GetValue ())
596 : {
597 0 : XHatch aHatch(pEntry->GetHatch());
598 :
599 0 : aHatch.SetHatchStyle ((XHatchStyle) pStyle->GetValue ());
600 0 : aHatch.SetDistance (pDistance->GetValue ());
601 0 : aHatch.SetAngle (pAngle->GetValue () * 10);
602 :
603 0 : pAttr->Put (XFillStyleItem (XFILL_HATCH), XATTR_FILLSTYLE);
604 0 : pAttr->Put (XFillHatchItem (pName->GetValue (), aHatch), XATTR_FILLHATCH);
605 0 : break;
606 : }
607 : }
608 :
609 0 : if (i >= nCounts)
610 : {
611 0 : Color aBlack (0, 0, 0);
612 0 : XHatch aHatch (aBlack, (XHatchStyle) pStyle->GetValue (), pDistance->GetValue (),
613 0 : pAngle->GetValue () * 10);
614 :
615 0 : pHatchList->Insert (new XHatchEntry (aHatch, pName->GetValue ()));
616 0 : pAttr->Put (XFillStyleItem (XFILL_HATCH), XATTR_FILLSTYLE);
617 0 : pAttr->Put (XFillHatchItem (pName->GetValue (), aHatch), XATTR_FILLHATCH);
618 : }
619 :
620 0 : rBindings.Invalidate (SID_ATTR_FILL_HATCH);
621 0 : rBindings.Invalidate (SID_ATTR_FILL_STYLE);
622 : }
623 : #ifndef DISABLE_SCRIPTING
624 0 : else StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
625 : #endif
626 0 : break;
627 : }
628 : #ifndef DISABLE_SCRIPTING
629 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
630 : #endif
631 0 : break;
632 :
633 : case SID_SELECTGRADIENT :
634 0 : if (pArgs)
635 0 : if (pArgs->Count () == 1)
636 : {
637 0 : SFX_REQUEST_ARG (rReq, pName, SfxStringItem, ID_VAL_INDEX, sal_False);
638 :
639 0 : XGradientListRef pGradientList = GetDoc()->GetGradientList ();
640 0 : long nCounts = pGradientList->Count ();
641 :
642 0 : for (long i = 0;
643 : i < nCounts;
644 : i ++)
645 : {
646 0 : XGradientEntry *pEntry = pGradientList->GetGradient (i);
647 :
648 0 : if (pEntry->GetName () == pName->GetValue ())
649 : {
650 0 : pAttr->ClearItem (XATTR_FILLGRADIENT);
651 0 : pAttr->ClearItem (XATTR_FILLSTYLE);
652 0 : pAttr->Put (XFillStyleItem (XFILL_GRADIENT), XATTR_FILLSTYLE);
653 0 : pAttr->Put (XFillGradientItem (pName->GetValue (), pEntry->GetGradient ()), XATTR_FILLGRADIENT);
654 :
655 0 : rBindings.Invalidate (SID_ATTR_FILL_GRADIENT);
656 0 : rBindings.Invalidate (SID_ATTR_FILL_STYLE);
657 0 : break;
658 : }
659 : }
660 :
661 0 : break;
662 : }
663 : #ifndef DISABLE_SCRIPTING
664 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
665 : #endif
666 0 : break;
667 :
668 : case SID_SELECTHATCH :
669 0 : if (pArgs)
670 0 : if (pArgs->Count () == 1)
671 : {
672 0 : SFX_REQUEST_ARG (rReq, pName, SfxStringItem, ID_VAL_INDEX, sal_False);
673 :
674 0 : XHatchListRef pHatchList = GetDoc()->GetHatchList ();
675 0 : long nCounts = pHatchList->Count ();
676 :
677 0 : for (long i = 0;
678 : i < nCounts;
679 : i ++)
680 : {
681 0 : XHatchEntry *pEntry = pHatchList->GetHatch (i);
682 :
683 0 : if (pEntry->GetName () == pName->GetValue ())
684 : {
685 0 : pAttr->ClearItem (XATTR_FILLHATCH);
686 0 : pAttr->ClearItem (XATTR_FILLSTYLE);
687 0 : pAttr->Put (XFillStyleItem (XFILL_HATCH), XATTR_FILLSTYLE);
688 0 : pAttr->Put (XFillHatchItem (pName->GetValue (), pEntry->GetHatch ()), XATTR_FILLHATCH);
689 :
690 0 : rBindings.Invalidate (SID_ATTR_FILL_HATCH);
691 0 : rBindings.Invalidate (SID_ATTR_FILL_STYLE);
692 0 : break;
693 : }
694 : }
695 :
696 0 : break;
697 : }
698 : #ifndef DISABLE_SCRIPTING
699 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
700 : #endif
701 0 : break;
702 :
703 : case SID_UNSELECT :
704 0 : mpDrawView->UnmarkAll ();
705 0 : break;
706 :
707 : case SID_GETRED :
708 0 : if (pArgs)
709 0 : if (pArgs->Count () == 1)
710 : {
711 0 : break;
712 : }
713 : #ifndef DISABLE_SCRIPTING
714 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
715 : #endif
716 0 : break;
717 :
718 : /* case SID_SETFONTFAMILYNAME :
719 : case SID_SETFONTSTYLENAME :
720 : case SID_SETFONTFAMILY :
721 : case SID_SETFONTPITCH :
722 : case SID_SETFONTCHARSET :
723 : case SID_SETFONTPOSTURE :
724 : case SID_SETFONTWEIGHT :
725 : case SID_SETFONTUNDERLINE :
726 : case SID_SETFONTCROSSEDOUT :
727 : case SID_SETFONTSHADOWED :
728 : case SID_SETFONTCONTOUR :
729 : case SID_SETFONTCOLOR :
730 : case SID_SETFONTLANGUAGE :
731 : case SID_SETFONTWORDLINE :
732 : case SID_SETFONTCASEMAP :
733 : case SID_SETFONTESCAPE :
734 : case SID_SETFONTKERNING :
735 : break;*/
736 :
737 : default :
738 : ;
739 : }
740 :
741 0 : mpDrawView->SetAttributes (*(const SfxItemSet *) pAttr);
742 0 : rReq.Ignore ();
743 0 : delete pAttr;
744 : }
745 :
746 : /**
747 : * Edit macros for attribute configuration
748 : */
749 0 : void DrawViewShell::AttrState (SfxItemSet& rSet)
750 : {
751 0 : SfxWhichIter aIter (rSet);
752 0 : sal_uInt16 nWhich = aIter.FirstWhich ();
753 0 : SfxItemSet aAttr( GetDoc()->GetPool() );
754 0 : mpDrawView->GetAttributes( aAttr );
755 :
756 0 : while (nWhich)
757 : {
758 0 : switch (nWhich)
759 : {
760 : case SID_GETFILLSTYLE :
761 : {
762 0 : const XFillStyleItem &rFillStyleItem = (const XFillStyleItem &) aAttr.Get (XATTR_FILLSTYLE);
763 :
764 0 : rSet.Put (SfxUInt32Item (nWhich, (long) rFillStyleItem.GetValue ()));
765 0 : break;
766 : }
767 :
768 : case SID_GETLINESTYLE :
769 : {
770 0 : const XLineStyleItem &rLineStyleItem = (const XLineStyleItem &) aAttr.Get (XATTR_LINESTYLE);
771 :
772 0 : rSet.Put (SfxUInt32Item (nWhich, (long) rLineStyleItem.GetValue ()));
773 0 : break;
774 : }
775 :
776 : case SID_GETLINEWIDTH :
777 : {
778 0 : const XLineWidthItem &rLineWidthItem = (const XLineWidthItem &) aAttr.Get (XATTR_LINEWIDTH);
779 :
780 0 : rSet.Put (SfxUInt32Item (nWhich, (long) rLineWidthItem.GetValue ()));
781 0 : break;
782 : }
783 :
784 : case SID_GETGREEN :
785 : case SID_GETRED :
786 : case SID_GETBLUE :
787 : {
788 0 : const SfxUInt32Item &rWhatKind = (const SfxUInt32Item &) rSet.Get (ID_VAL_WHATKIND);
789 0 : Color aColor;
790 :
791 0 : switch (rWhatKind.GetValue ())
792 : {
793 : case 1 :
794 : {
795 0 : const XLineColorItem &rLineColorItem = (const XLineColorItem &) aAttr.Get (XATTR_LINECOLOR);
796 :
797 0 : aColor = rLineColorItem.GetColorValue ();
798 0 : break;
799 : }
800 :
801 : case 2 :
802 : {
803 0 : const XFillColorItem &rFillColorItem = (const XFillColorItem &) aAttr.Get (XATTR_FILLCOLOR);
804 :
805 0 : aColor = rFillColorItem.GetColorValue ();
806 0 : break;
807 : }
808 :
809 : case 3 :
810 : case 4 :
811 : {
812 0 : const XFillGradientItem &rFillGradientItem = (const XFillGradientItem &) aAttr.Get (XATTR_FILLGRADIENT);
813 0 : const XGradient &rGradient = rFillGradientItem.GetGradientValue ();
814 :
815 0 : aColor = (rWhatKind.GetValue () == 3)
816 : ? rGradient.GetStartColor ()
817 0 : : rGradient.GetEndColor ();
818 0 : break;
819 : }
820 :
821 : case 5:
822 : {
823 0 : const XFillHatchItem &rFillHatchItem = (const XFillHatchItem &) aAttr.Get (XATTR_FILLHATCH);
824 0 : const XHatch &rHatch = rFillHatchItem.GetHatchValue ();
825 :
826 0 : aColor = rHatch.GetColor ();
827 0 : break;
828 : }
829 :
830 : default :
831 : ;
832 : }
833 :
834 : rSet.Put (SfxUInt32Item (nWhich, (long) ((nWhich == SID_GETRED)
835 0 : ? aColor.GetRed ()
836 : : (nWhich == SID_GETGREEN)
837 0 : ? aColor.GetGreen ()
838 0 : : aColor.GetBlue ())));
839 0 : break;
840 : }
841 :
842 : default :
843 : ;
844 : }
845 :
846 0 : nWhich = aIter.NextWhich ();
847 0 : }
848 0 : }
849 :
850 33 : } // end of namespace sd
851 :
852 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|