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 : #include <string>
21 :
22 : #include <vcl/toolbox.hxx>
23 : #include <vcl/field.hxx>
24 : #include <vcl/fixed.hxx>
25 : #include <vcl/msgbox.hxx>
26 : #include <svl/intitem.hxx>
27 : #include <svl/eitem.hxx>
28 : #include <svl/whiter.hxx>
29 : #include <sfx2/app.hxx>
30 : #include <sfx2/dispatch.hxx>
31 : #include <sfx2/objsh.hxx>
32 : #include <sfx2/viewsh.hxx>
33 : #include <sfx2/request.hxx>
34 : #include <sfx2/basedlgs.hxx>
35 : #include <tools/urlobj.hxx>
36 : #include <comphelper/processfactory.hxx>
37 :
38 : #include <svx/svxids.hrc>
39 : #include "grafctrl.hrc"
40 : #include <svx/dialogs.hrc>
41 : #include <editeng/brushitem.hxx>
42 : #include <editeng/sizeitem.hxx>
43 : #include <svx/sdgcpitm.hxx>
44 :
45 : #include <svx/itemwin.hxx>
46 : #include <svx/dialmgr.hxx>
47 : #include <svx/svdview.hxx>
48 : #include <svx/svdmodel.hxx>
49 : #include <svx/svdograf.hxx>
50 : #include <svx/svdundo.hxx>
51 : #include <svx/svdtrans.hxx>
52 : #include "svx/grafctrl.hxx"
53 : #include "svx/tbxcolor.hxx"
54 :
55 : using namespace ::com::sun::star::uno;
56 : using namespace ::com::sun::star::frame;
57 : using namespace ::com::sun::star::util;
58 : using namespace ::com::sun::star::beans;
59 : using namespace ::com::sun::star::lang;
60 :
61 : #include <svx/svxdlg.hxx>
62 :
63 : #define SYMBOL_TO_FIELD_OFFSET 4
64 : #define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()
65 : #define TOOLBOX_NAME OUString( "colorbar" )
66 :
67 13722 : TYPEINIT1_AUTOFACTORY( TbxImageItem, SfxUInt16Item );
68 :
69 79512 : TbxImageItem::TbxImageItem( sal_uInt16 _nWhich, sal_uInt16 nImage ) :
70 79512 : SfxUInt16Item( _nWhich, nImage )
71 : {
72 79512 : }
73 :
74 :
75 2632 : SfxPoolItem* TbxImageItem::Clone( SfxItemPool* ) const
76 : {
77 2632 : return new TbxImageItem( *this );
78 : }
79 :
80 1190 : int TbxImageItem::operator==( const SfxPoolItem& rItem ) const
81 : {
82 1190 : return( ( (TbxImageItem&) rItem ).GetValue() == GetValue() );
83 : }
84 :
85 : class ImplGrafMetricField : public MetricField
86 : {
87 : using Window::Update;
88 :
89 : private:
90 : Timer maTimer;
91 : OUString maCommand;
92 : Reference< XFrame > mxFrame;
93 :
94 : DECL_LINK(ImplModifyHdl, void *);
95 :
96 : protected:
97 :
98 : virtual void Modify();
99 :
100 : public:
101 :
102 : ImplGrafMetricField( Window* pParent, const OUString& aCmd, const Reference< XFrame >& rFrame );
103 : ~ImplGrafMetricField();
104 :
105 : void Update( const SfxPoolItem* pItem );
106 : const OUString& GetCommand() const { return maCommand; }
107 : };
108 :
109 0 : ImplGrafMetricField::ImplGrafMetricField( Window* pParent, const OUString& rCmd, const Reference< XFrame >& rFrame ) :
110 : MetricField( pParent, WB_BORDER | WB_SPIN | WB_REPEAT | WB_3DLOOK ),
111 : maCommand( rCmd ),
112 0 : mxFrame( rFrame )
113 : {
114 0 : Size aSize( GetTextWidth( OUString("-100 %") ), GetTextHeight() );
115 :
116 0 : aSize.Width() += 20, aSize.Height() += 6;
117 0 : SetSizePixel( aSize );
118 :
119 0 : if ( maCommand == ".uno:GrafGamma" )
120 : {
121 0 : SetDecimalDigits( 2 );
122 :
123 0 : SetMin( 10 );
124 0 : SetFirst( 10 );
125 0 : SetMax( 1000 );
126 0 : SetLast( 1000 );
127 0 : SetSpinSize( 10 );
128 : }
129 : else
130 : {
131 0 : const long nMinVal = ( maCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafTransparence" ) )) ? 0 : -100;
132 :
133 0 : SetUnit( FUNIT_CUSTOM );
134 0 : SetCustomUnitText( OUString(" %") );
135 0 : SetDecimalDigits( 0 );
136 :
137 0 : SetMin( nMinVal );
138 0 : SetFirst( nMinVal );
139 0 : SetMax( 100 );
140 0 : SetLast( 100 );
141 0 : SetSpinSize( 1 );
142 : }
143 :
144 0 : maTimer.SetTimeout( 100 );
145 0 : maTimer.SetTimeoutHdl( LINK( this, ImplGrafMetricField, ImplModifyHdl ) );
146 0 : }
147 :
148 0 : ImplGrafMetricField::~ImplGrafMetricField()
149 : {
150 0 : }
151 :
152 0 : void ImplGrafMetricField::Modify()
153 : {
154 0 : maTimer.Start();
155 0 : }
156 :
157 0 : IMPL_LINK_NOARG(ImplGrafMetricField, ImplModifyHdl)
158 : {
159 0 : const sal_Int64 nVal = GetValue();
160 :
161 : // Convert value to an any to be usable with dispatch API
162 0 : Any a;
163 0 : if ( maCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafRed" ) ) ||
164 0 : maCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafGreen" ) ) ||
165 0 : maCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafBlue" ) ) ||
166 0 : maCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafLuminance" ) ) ||
167 0 : maCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafContrast" ) ))
168 0 : a = makeAny( sal_Int16( nVal ));
169 0 : else if ( maCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafGamma" ) ) ||
170 0 : maCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafTransparence" ) ))
171 0 : a = makeAny( sal_Int32( nVal ));
172 :
173 0 : if ( a.hasValue() )
174 : {
175 0 : INetURLObject aObj( maCommand );
176 :
177 0 : Sequence< PropertyValue > aArgs( 1 );
178 0 : aArgs[0].Name = aObj.GetURLPath();
179 0 : aArgs[0].Value = a;
180 :
181 : SfxToolBoxControl::Dispatch(
182 0 : Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
183 : maCommand,
184 0 : aArgs );
185 : }
186 0 : return 0L;
187 : }
188 :
189 0 : void ImplGrafMetricField::Update( const SfxPoolItem* pItem )
190 : {
191 0 : if( pItem )
192 : {
193 : long nValue;
194 :
195 0 : if ( maCommand == ".uno:GrafTransparence" )
196 0 : nValue = ( (SfxUInt16Item*) pItem )->GetValue();
197 0 : else if ( maCommand == ".uno:GrafGamma" )
198 0 : nValue = ( (SfxUInt32Item*) pItem )->GetValue();
199 : else
200 0 : nValue = ( (SfxInt16Item*) pItem )->GetValue();
201 :
202 0 : SetValue( nValue );
203 : }
204 : else
205 0 : SetText( OUString() );
206 0 : }
207 :
208 : struct CommandToRID
209 : {
210 : const char* pCommand;
211 : sal_uInt16 nResId;
212 : };
213 :
214 0 : static sal_uInt16 ImplGetRID( const OUString& aCommand )
215 : {
216 : static const CommandToRID aImplCommandToResMap[] =
217 : {
218 : { ".uno:GrafRed", RID_SVXIMG_GRAF_RED },
219 : { ".uno:GrafGreen", RID_SVXIMG_GRAF_GREEN },
220 : { ".uno:GrafBlue", RID_SVXIMG_GRAF_BLUE },
221 : { ".uno:GrafLuminance", RID_SVXIMG_GRAF_LUMINANCE },
222 : { ".uno:GrafContrast", RID_SVXIMG_GRAF_CONTRAST },
223 : { ".uno:GrafGamma", RID_SVXIMG_GRAF_GAMMA },
224 : { ".uno:GrafTransparence", RID_SVXIMG_GRAF_TRANSPARENCE },
225 : { 0, 0 }
226 : };
227 :
228 0 : sal_uInt16 nRID = 0;
229 :
230 0 : sal_Int32 i( 0 );
231 0 : while ( aImplCommandToResMap[ i ].pCommand )
232 : {
233 0 : if ( aCommand.equalsAscii( aImplCommandToResMap[ i ].pCommand ))
234 : {
235 0 : nRID = aImplCommandToResMap[ i ].nResId;
236 0 : break;
237 : }
238 0 : ++i;
239 : }
240 :
241 0 : return nRID;
242 : }
243 :
244 : class ImplGrafControl : public Control
245 : {
246 : using Window::Update;
247 : private:
248 : FixedImage maImage;
249 : ImplGrafMetricField maField;
250 :
251 : protected:
252 :
253 : virtual void GetFocus();
254 :
255 : public:
256 :
257 : ImplGrafControl( Window* pParent, const OUString& rCmd, const Reference< XFrame >& rFrame );
258 : ~ImplGrafControl();
259 :
260 0 : void Update( const SfxPoolItem* pItem ) { maField.Update( pItem ); }
261 0 : void SetText( const OUString& rStr ) { maField.SetText( rStr ); }
262 : };
263 :
264 0 : ImplGrafControl::ImplGrafControl(
265 : Window* pParent,
266 : const OUString& rCmd,
267 : const Reference< XFrame >& rFrame
268 : ) : Control( pParent, WB_TABSTOP )
269 : , maImage( this )
270 0 : , maField( this, rCmd, rFrame )
271 : {
272 0 : ResId aResId( ImplGetRID( rCmd ), DIALOG_MGR() ) ;
273 0 : Image aImage( aResId );
274 :
275 0 : Size aImgSize( aImage.GetSizePixel() );
276 0 : Size aFldSize( maField.GetSizePixel() );
277 : long nFldY, nImgY;
278 :
279 0 : maImage.SetImage( aImage );
280 0 : maImage.SetSizePixel( aImgSize );
281 : // we want to see the backbround of the toolbox, not of the FixedImage or Control
282 0 : maImage.SetBackground( Wallpaper( COL_TRANSPARENT ) );
283 0 : SetBackground( Wallpaper( COL_TRANSPARENT ) );
284 :
285 0 : if( aImgSize.Height() > aFldSize.Height() )
286 0 : nImgY = 0, nFldY = ( aImgSize.Height() - aFldSize.Height() ) >> 1;
287 : else
288 0 : nFldY = 0, nImgY = ( aFldSize.Height() - aImgSize.Height() ) >> 1;
289 :
290 0 : long nOffset = SYMBOL_TO_FIELD_OFFSET / 2;
291 0 : maImage.SetPosPixel( Point( nOffset, nImgY ) );
292 0 : maField.SetPosPixel( Point( aImgSize.Width() + SYMBOL_TO_FIELD_OFFSET, nFldY ) );
293 0 : SetSizePixel( Size( aImgSize.Width() + aFldSize.Width() + SYMBOL_TO_FIELD_OFFSET + nOffset,
294 0 : std::max( aImgSize.Height(), aFldSize.Height() ) ) );
295 :
296 0 : SetBackground( Wallpaper() ); // transparent background
297 :
298 0 : maImage.Show();
299 :
300 0 : maField.SetHelpId( OUStringToOString( rCmd, RTL_TEXTENCODING_UTF8 ) );
301 0 : maField.Show();
302 0 : }
303 :
304 0 : ImplGrafControl::~ImplGrafControl()
305 : {
306 0 : }
307 :
308 0 : void ImplGrafControl::GetFocus()
309 : {
310 0 : maField.GrabFocus();
311 0 : }
312 :
313 : class ImplGrafModeControl : public ListBox
314 : {
315 : using Window::Update;
316 : private:
317 : sal_uInt16 mnCurPos;
318 : Reference< XFrame > mxFrame;
319 :
320 : virtual void Select();
321 : virtual long PreNotify( NotifyEvent& rNEvt );
322 : virtual long Notify( NotifyEvent& rNEvt );
323 : void ImplReleaseFocus();
324 :
325 : public:
326 :
327 : ImplGrafModeControl( Window* pParent, const Reference< XFrame >& rFrame );
328 : ~ImplGrafModeControl();
329 :
330 : void Update( const SfxPoolItem* pItem );
331 : };
332 :
333 0 : ImplGrafModeControl::ImplGrafModeControl( Window* pParent, const Reference< XFrame >& rFrame ) :
334 : ListBox( pParent, WB_BORDER | WB_DROPDOWN | WB_AUTOHSCROLL ),
335 : mnCurPos( 0 ),
336 0 : mxFrame( rFrame )
337 : {
338 0 : SetSizePixel( Size( 100, 260 ) );
339 :
340 0 : InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_STANDARD ) );
341 0 : InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_GREYS ) );
342 0 : InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_MONO ) );
343 0 : InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_WATERMARK ) );
344 :
345 0 : Show();
346 0 : }
347 :
348 0 : ImplGrafModeControl::~ImplGrafModeControl()
349 : {
350 0 : }
351 :
352 0 : void ImplGrafModeControl::Select()
353 : {
354 0 : if ( !IsTravelSelect() )
355 : {
356 0 : Sequence< PropertyValue > aArgs( 1 );
357 0 : aArgs[0].Name = OUString( "GrafMode" );
358 0 : aArgs[0].Value = makeAny( sal_Int16( GetSelectEntryPos() ));
359 :
360 : /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
361 : This instance may be deleted in the meantime (i.e. when a dialog is opened
362 : while in Dispatch()), accessing members will crash in this case. */
363 0 : ImplReleaseFocus();
364 :
365 : SfxToolBoxControl::Dispatch(
366 0 : Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
367 : OUString( ".uno:GrafMode" ),
368 0 : aArgs );
369 : }
370 0 : }
371 :
372 0 : long ImplGrafModeControl::PreNotify( NotifyEvent& rNEvt )
373 : {
374 0 : sal_uInt16 nType = rNEvt.GetType();
375 :
376 0 : if( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
377 0 : mnCurPos = GetSelectEntryPos();
378 :
379 0 : return ListBox::PreNotify( rNEvt );
380 : }
381 :
382 0 : long ImplGrafModeControl::Notify( NotifyEvent& rNEvt )
383 : {
384 0 : long nHandled = ListBox::Notify( rNEvt );
385 :
386 0 : if( rNEvt.GetType() == EVENT_KEYINPUT )
387 : {
388 0 : const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
389 :
390 0 : switch( pKEvt->GetKeyCode().GetCode() )
391 : {
392 : case KEY_RETURN:
393 : {
394 0 : Select();
395 0 : nHandled = 1;
396 : }
397 0 : break;
398 :
399 : case KEY_ESCAPE:
400 : {
401 0 : SelectEntryPos( mnCurPos );
402 0 : ImplReleaseFocus();
403 0 : nHandled = 1;
404 : }
405 0 : break;
406 : }
407 : }
408 :
409 0 : return nHandled;
410 : }
411 :
412 0 : void ImplGrafModeControl::ImplReleaseFocus()
413 : {
414 0 : if( SfxViewShell::Current() )
415 : {
416 0 : Window* pShellWnd = SfxViewShell::Current()->GetWindow();
417 :
418 0 : if( pShellWnd )
419 0 : pShellWnd->GrabFocus();
420 : }
421 0 : }
422 :
423 0 : void ImplGrafModeControl::Update( const SfxPoolItem* pItem )
424 : {
425 0 : if( pItem )
426 0 : SelectEntryPos( ((SfxUInt16Item*)pItem)->GetValue() );
427 : else
428 0 : SetNoSelection();
429 0 : }
430 :
431 75 : SFX_IMPL_TOOLBOX_CONTROL( SvxGrafFilterToolBoxControl, TbxImageItem );
432 :
433 0 : SvxGrafFilterToolBoxControl::SvxGrafFilterToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
434 0 : SfxToolBoxControl( nSlotId, nId, rTbx )
435 : {
436 0 : rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
437 0 : rTbx.Invalidate();
438 0 : }
439 :
440 0 : SvxGrafFilterToolBoxControl::~SvxGrafFilterToolBoxControl()
441 : {
442 0 : }
443 :
444 0 : void SvxGrafFilterToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* )
445 : {
446 0 : GetToolBox().EnableItem( GetId(), ( eState != SFX_ITEM_DISABLED ) );
447 0 : }
448 :
449 0 : SfxPopupWindowType SvxGrafFilterToolBoxControl::GetPopupWindowType() const
450 : {
451 0 : return SFX_POPUPWINDOW_ONCLICK;
452 : }
453 :
454 0 : SfxPopupWindow* SvxGrafFilterToolBoxControl::CreatePopupWindow()
455 : {
456 0 : OUString aSubTbxResName( "private:resource/toolbar/graffilterbar" );
457 0 : createAndPositionSubToolBar( aSubTbxResName );
458 :
459 0 : return NULL;
460 : }
461 :
462 0 : SvxGrafToolBoxControl::SvxGrafToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx) :
463 0 : SfxToolBoxControl( nSlotId, nId, rTbx )
464 : {
465 0 : rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
466 0 : rTbx.Invalidate();
467 0 : }
468 :
469 0 : SvxGrafToolBoxControl::~SvxGrafToolBoxControl()
470 : {
471 0 : }
472 :
473 0 : void SvxGrafToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
474 :
475 : {
476 0 : ImplGrafControl* pCtrl = (ImplGrafControl*) GetToolBox().GetItemWindow( GetId() );
477 : DBG_ASSERT( pCtrl, "Control not found" );
478 :
479 0 : if( eState == SFX_ITEM_DISABLED )
480 : {
481 0 : pCtrl->Disable();
482 0 : pCtrl->SetText( OUString() );
483 : }
484 : else
485 : {
486 0 : pCtrl->Enable();
487 :
488 0 : if( eState == SFX_ITEM_AVAILABLE )
489 0 : pCtrl->Update( pState );
490 : else
491 0 : pCtrl->Update( NULL );
492 : }
493 0 : }
494 :
495 0 : Window* SvxGrafToolBoxControl::CreateItemWindow( Window *pParent )
496 : {
497 0 : return( new ImplGrafControl( pParent, m_aCommandURL, m_xFrame ) );
498 : }
499 :
500 75 : SFX_IMPL_TOOLBOX_CONTROL( SvxGrafRedToolBoxControl, SfxInt16Item );
501 :
502 0 : SvxGrafRedToolBoxControl::SvxGrafRedToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
503 0 : SvxGrafToolBoxControl( nSlotId, nId, rTbx )
504 : {
505 0 : }
506 :
507 75 : SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGreenToolBoxControl, SfxInt16Item );
508 :
509 0 : SvxGrafGreenToolBoxControl::SvxGrafGreenToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
510 0 : SvxGrafToolBoxControl( nSlotId, nId, rTbx )
511 : {
512 0 : }
513 :
514 75 : SFX_IMPL_TOOLBOX_CONTROL( SvxGrafBlueToolBoxControl, SfxInt16Item );
515 :
516 0 : SvxGrafBlueToolBoxControl::SvxGrafBlueToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
517 0 : SvxGrafToolBoxControl( nSlotId, nId, rTbx )
518 : {
519 0 : }
520 :
521 75 : SFX_IMPL_TOOLBOX_CONTROL( SvxGrafLuminanceToolBoxControl, SfxInt16Item );
522 :
523 0 : SvxGrafLuminanceToolBoxControl::SvxGrafLuminanceToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
524 0 : SvxGrafToolBoxControl( nSlotId, nId, rTbx )
525 : {
526 0 : }
527 :
528 75 : SFX_IMPL_TOOLBOX_CONTROL( SvxGrafContrastToolBoxControl, SfxInt16Item );
529 :
530 0 : SvxGrafContrastToolBoxControl::SvxGrafContrastToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
531 0 : SvxGrafToolBoxControl( nSlotId, nId, rTbx )
532 : {
533 0 : }
534 :
535 75 : SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGammaToolBoxControl, SfxUInt32Item );
536 :
537 0 : SvxGrafGammaToolBoxControl::SvxGrafGammaToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
538 0 : SvxGrafToolBoxControl( nSlotId, nId, rTbx )
539 : {
540 0 : }
541 :
542 75 : SFX_IMPL_TOOLBOX_CONTROL( SvxGrafTransparenceToolBoxControl, SfxUInt16Item );
543 :
544 0 : SvxGrafTransparenceToolBoxControl::SvxGrafTransparenceToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
545 0 : SvxGrafToolBoxControl( nSlotId, nId, rTbx )
546 : {
547 0 : }
548 :
549 75 : SFX_IMPL_TOOLBOX_CONTROL( SvxGrafModeToolBoxControl, SfxUInt16Item );
550 :
551 0 : SvxGrafModeToolBoxControl::SvxGrafModeToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
552 0 : SfxToolBoxControl( nSlotId, nId, rTbx )
553 : {
554 0 : }
555 :
556 0 : SvxGrafModeToolBoxControl::~SvxGrafModeToolBoxControl()
557 : {
558 0 : }
559 :
560 0 : void SvxGrafModeToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
561 :
562 : {
563 0 : ImplGrafModeControl* pCtrl = (ImplGrafModeControl*) GetToolBox().GetItemWindow( GetId() );
564 : DBG_ASSERT( pCtrl, "Control not found" );
565 :
566 0 : if( eState == SFX_ITEM_DISABLED )
567 : {
568 0 : pCtrl->Disable();
569 0 : pCtrl->SetText( OUString() );
570 : }
571 : else
572 : {
573 0 : pCtrl->Enable();
574 :
575 0 : if( eState == SFX_ITEM_AVAILABLE )
576 0 : pCtrl->Update( pState );
577 : else
578 0 : pCtrl->Update( NULL );
579 : }
580 0 : }
581 :
582 0 : Window* SvxGrafModeToolBoxControl::CreateItemWindow( Window *pParent )
583 : {
584 0 : return( new ImplGrafModeControl( pParent, m_xFrame ) );
585 : }
586 :
587 0 : void SvxGrafAttrHelper::ExecuteGrafAttr( SfxRequest& rReq, SdrView& rView )
588 : {
589 0 : SfxItemPool& rPool = rView.GetModel()->GetItemPool();
590 0 : SfxItemSet aSet( rPool, SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST );
591 0 : String aUndoStr;
592 0 : const bool bUndo = rView.IsUndoEnabled();
593 :
594 0 : if( bUndo )
595 : {
596 0 : aUndoStr = rView.GetDescriptionOfMarkedObjects();
597 0 : aUndoStr.Append( sal_Unicode(' ') );
598 : }
599 :
600 0 : const SfxItemSet* pArgs = rReq.GetArgs();
601 : const SfxPoolItem* pItem;
602 0 : sal_uInt16 nSlot = rReq.GetSlot();
603 :
604 0 : if( !pArgs || SFX_ITEM_SET != pArgs->GetItemState( nSlot, sal_False, &pItem ))
605 0 : pItem = 0;
606 :
607 0 : switch( nSlot )
608 : {
609 : case SID_ATTR_GRAF_RED:
610 : {
611 0 : if( pItem )
612 : {
613 0 : aSet.Put( SdrGrafRedItem( ((SfxInt16Item*)pItem)->GetValue() ));
614 0 : if( bUndo )
615 0 : aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFRED ) ) );
616 : }
617 : }
618 0 : break;
619 :
620 : case SID_ATTR_GRAF_GREEN:
621 : {
622 0 : if( pItem )
623 : {
624 0 : aSet.Put( SdrGrafGreenItem( ((SfxInt16Item*)pItem)->GetValue() ));
625 0 : if( bUndo )
626 0 : aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGREEN ) ) );
627 : }
628 : }
629 0 : break;
630 :
631 : case SID_ATTR_GRAF_BLUE:
632 : {
633 0 : if( pItem )
634 : {
635 0 : aSet.Put( SdrGrafBlueItem( ((SfxInt16Item*)pItem)->GetValue() ));
636 0 : if( bUndo )
637 0 : aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFBLUE ) ) );
638 : }
639 : }
640 0 : break;
641 :
642 : case SID_ATTR_GRAF_LUMINANCE:
643 : {
644 0 : if( pItem )
645 : {
646 0 : aSet.Put( SdrGrafLuminanceItem( ((SfxInt16Item*)pItem)->GetValue() ));
647 0 : if( bUndo )
648 0 : aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFLUMINANCE ) ) );
649 : }
650 : }
651 0 : break;
652 :
653 : case SID_ATTR_GRAF_CONTRAST:
654 : {
655 0 : if( pItem )
656 : {
657 0 : aSet.Put( SdrGrafContrastItem( ((SfxInt16Item*)pItem)->GetValue() ));
658 0 : if( bUndo )
659 0 : aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCONTRAST ) ) );
660 : }
661 : }
662 0 : break;
663 :
664 : case SID_ATTR_GRAF_GAMMA:
665 : {
666 0 : if( pItem )
667 : {
668 0 : aSet.Put( SdrGrafGamma100Item( ((SfxUInt32Item*)pItem)->GetValue() ));
669 0 : if( bUndo )
670 0 : aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGAMMA ) ) );
671 : }
672 : }
673 0 : break;
674 :
675 : case SID_ATTR_GRAF_TRANSPARENCE:
676 : {
677 0 : if( pItem )
678 : {
679 0 : aSet.Put( SdrGrafTransparenceItem( ((SfxUInt16Item*)pItem)->GetValue() ));
680 0 : if( bUndo )
681 0 : aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFTRANSPARENCY ) ) );
682 : }
683 : }
684 0 : break;
685 :
686 : case SID_ATTR_GRAF_MODE:
687 : {
688 0 : if( pItem )
689 : {
690 0 : aSet.Put( SdrGrafModeItem( (GraphicDrawMode) ((SfxUInt16Item*)pItem)->GetValue() ));
691 0 : if( bUndo )
692 0 : aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFMODE ) ) );
693 : }
694 : }
695 0 : break;
696 :
697 : case( SID_ATTR_GRAF_CROP ):
698 : {
699 0 : const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
700 :
701 0 : if( 0 < rMarkList.GetMarkCount() )
702 : {
703 0 : SdrGrafObj* pObj = (SdrGrafObj*) rMarkList.GetMark( 0 )->GetMarkedSdrObj();
704 :
705 0 : if( pObj && pObj->ISA( SdrGrafObj ) &&
706 0 : ( pObj->GetGraphicType() != GRAPHIC_NONE ) &&
707 0 : ( pObj->GetGraphicType() != GRAPHIC_DEFAULT ) )
708 : {
709 0 : SfxItemSet aGrfAttr( rPool, SDRATTR_GRAFCROP, SDRATTR_GRAFCROP, 0 );
710 0 : const SfxMapUnit eOldMetric = rPool.GetMetric( 0 );
711 0 : const MapMode aMap100( MAP_100TH_MM );
712 0 : const MapMode aMapTwip( MAP_TWIP );
713 :
714 0 : aGrfAttr.Put(pObj->GetMergedItemSet());
715 0 : rPool.SetDefaultMetric( SFX_MAPUNIT_TWIP );
716 :
717 : SfxItemSet aCropDlgAttr( rPool,
718 : SDRATTR_GRAFCROP, SDRATTR_GRAFCROP,
719 : SID_ATTR_GRAF_GRAPHIC, SID_ATTR_GRAF_GRAPHIC,
720 : SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
721 : SID_ATTR_GRAF_FRMSIZE, SID_ATTR_GRAF_FRMSIZE,
722 0 : SID_ATTR_GRAF_CROP, SID_ATTR_GRAF_CROP, 0 );
723 :
724 0 : aCropDlgAttr.Put( SvxBrushItem( pObj->GetGraphic(), GPOS_MM, SID_ATTR_GRAF_GRAPHIC ) );
725 : aCropDlgAttr.Put( SvxSizeItem( SID_ATTR_PAGE_SIZE,
726 : Size( OutputDevice::LogicToLogic(
727 0 : Size( 200000, 200000 ), aMap100, aMapTwip ) ) ) );
728 : aCropDlgAttr.Put( SvxSizeItem( SID_ATTR_GRAF_FRMSIZE, OutputDevice::LogicToLogic(
729 0 : pObj->GetLogicRect().GetSize(), aMap100, aMapTwip ) ) );
730 :
731 0 : const SdrGrafCropItem& rCrop = (const SdrGrafCropItem&) aGrfAttr.Get( SDRATTR_GRAFCROP );
732 : Size aLTSize( OutputDevice::LogicToLogic(
733 0 : Size( rCrop.GetLeft(), rCrop.GetTop() ), aMap100, aMapTwip ) );
734 : Size aRBSize( OutputDevice::LogicToLogic(
735 0 : Size( rCrop.GetRight(), rCrop.GetBottom() ), aMap100, aMapTwip ) );
736 :
737 0 : aCropDlgAttr.Put( SdrGrafCropItem( aLTSize.Width(), aLTSize.Height(),
738 0 : aRBSize.Width(), aRBSize.Height() ) );
739 :
740 0 : SfxNoLayoutSingleTabDialog aCropDialog( SfxViewShell::Current() ? SfxViewShell::Current()->GetWindow() : NULL,
741 0 : aCropDlgAttr, 950 );
742 0 : const String aCropStr = SVX_RESSTR( RID_SVXSTR_GRAFCROP );
743 :
744 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
745 : DBG_ASSERT(pFact, "Dialogdiet error!");
746 0 : ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( RID_SVXPAGE_GRFCROP );
747 : DBG_ASSERT(fnCreatePage, "Dialogdiet error!");
748 0 : SfxTabPage* pTabPage = (*fnCreatePage)( &aCropDialog, aCropDlgAttr );
749 :
750 0 : pTabPage->SetText( aCropStr );
751 0 : aCropDialog.SetTabPage( pTabPage );
752 :
753 0 : if( aCropDialog.Execute() == RET_OK )
754 : {
755 0 : const SfxItemSet* pOutAttr = aCropDialog.GetOutputItemSet();
756 :
757 0 : if( pOutAttr )
758 : {
759 0 : aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCROP ) ) );
760 :
761 : // set crop attributes
762 0 : if( SFX_ITEM_SET <= pOutAttr->GetItemState( SDRATTR_GRAFCROP ) )
763 : {
764 0 : const SdrGrafCropItem& rNewCrop = (const SdrGrafCropItem&) pOutAttr->Get( SDRATTR_GRAFCROP );
765 :
766 0 : aLTSize = OutputDevice::LogicToLogic( Size( rNewCrop.GetLeft(), rNewCrop.GetTop() ), aMapTwip, aMap100 );
767 0 : aRBSize = OutputDevice::LogicToLogic( Size( rNewCrop.GetRight(), rNewCrop.GetBottom() ), aMapTwip, aMap100 );
768 0 : aSet.Put( SdrGrafCropItem( aLTSize.Width(), aLTSize.Height(), aRBSize.Width(), aRBSize.Height() ) );
769 : }
770 :
771 : // set new logic rect
772 0 : if( SFX_ITEM_SET <= pOutAttr->GetItemState( SID_ATTR_GRAF_FRMSIZE ) )
773 : {
774 0 : Point aNewOrigin( pObj->GetLogicRect().TopLeft() );
775 0 : const Size& rGrfSize = ( (const SvxSizeItem&) pOutAttr->Get( SID_ATTR_GRAF_FRMSIZE ) ).GetSize();
776 0 : Size aNewGrfSize( OutputDevice::LogicToLogic( rGrfSize, aMapTwip, aMap100 ) );
777 0 : Size aOldGrfSize( pObj->GetLogicRect().GetSize() );
778 :
779 0 : Rectangle aNewRect( aNewOrigin, aNewGrfSize );
780 0 : Point aOffset( (aNewGrfSize.Width() - aOldGrfSize.Width()) >> 1,
781 0 : (aNewGrfSize.Height() - aOldGrfSize.Height()) >> 1 );
782 :
783 : // #106181# rotate snap rect before setting it
784 0 : const GeoStat& aGeo = pObj->GetGeoStat();
785 :
786 0 : if (aGeo.nDrehWink!=0 || aGeo.nShearWink!=0)
787 : {
788 0 : Polygon aPol(aNewRect);
789 :
790 : // also transform origin offset
791 0 : if (aGeo.nShearWink!=0)
792 : {
793 : ShearPoly(aPol,
794 : aNewRect.TopLeft(),
795 0 : aGeo.nTan);
796 0 : ShearPoint(aOffset, Point(0,0), aGeo.nTan);
797 : }
798 0 : if (aGeo.nDrehWink!=0)
799 : {
800 : RotatePoly(aPol,
801 : aNewRect.TopLeft(),
802 0 : aGeo.nSin,aGeo.nCos);
803 0 : RotatePoint(aOffset, Point(0,0), aGeo.nSin,aGeo.nCos);
804 : }
805 :
806 : // apply offset
807 0 : aPol.Move( -aOffset.X(), -aOffset.Y() );
808 0 : aNewRect=aPol.GetBoundRect();
809 : }
810 : else
811 : {
812 0 : aNewRect.Move( -aOffset.X(), -aOffset.Y() );
813 : }
814 :
815 0 : if( !aSet.Count() )
816 0 : rView.SetMarkedObjRect( aNewRect );
817 : else
818 : {
819 0 : if( bUndo )
820 : {
821 0 : rView.BegUndo( aUndoStr );
822 0 : rView.AddUndo( rView.GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
823 : }
824 0 : pObj->SetSnapRect( aNewRect );
825 0 : rView.SetAttributes( aSet );
826 :
827 0 : if( bUndo )
828 0 : rView.EndUndo();
829 0 : aSet.ClearItem();
830 : }
831 : }
832 : }
833 : }
834 :
835 0 : rPool.SetDefaultMetric( eOldMetric );
836 : }
837 : }
838 : }
839 0 : break;
840 :
841 : case SID_COLOR_SETTINGS:
842 : {
843 0 : svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
844 0 : aToolboxAccess.toggleToolbox();
845 0 : rReq.Done();
846 0 : break;
847 : }
848 :
849 : default:
850 0 : break;
851 : }
852 :
853 0 : if( aSet.Count() )
854 : {
855 0 : if( bUndo )
856 0 : rView.BegUndo( aUndoStr );
857 :
858 0 : rView.SetAttributes( aSet );
859 :
860 0 : if( bUndo )
861 0 : rView.EndUndo();
862 0 : }
863 0 : }
864 :
865 0 : void SvxGrafAttrHelper::GetGrafAttrState( SfxItemSet& rSet, SdrView& rView )
866 : {
867 0 : SfxItemPool& rPool = rView.GetModel()->GetItemPool();
868 0 : SfxItemSet aAttrSet( rPool );
869 0 : SfxWhichIter aIter( rSet );
870 0 : sal_uInt16 nWhich = aIter.FirstWhich();
871 0 : const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
872 0 : bool bEnableColors = true;
873 0 : bool bEnableTransparency = true;
874 0 : bool bEnableCrop = ( 1 == rMarkList.GetMarkCount() );
875 :
876 0 : for( int i = 0, nCount = rMarkList.GetMarkCount(); i < nCount; ++i )
877 : {
878 0 : SdrGrafObj* pGrafObj = dynamic_cast< SdrGrafObj* >( rMarkList.GetMark( i )->GetMarkedSdrObj() );
879 :
880 0 : if( !pGrafObj ||
881 0 : ( pGrafObj->GetGraphicType() == GRAPHIC_NONE ) ||
882 0 : ( pGrafObj->GetGraphicType() == GRAPHIC_DEFAULT ))
883 : {
884 0 : bEnableColors = bEnableTransparency = bEnableCrop = false;
885 0 : break;
886 : }
887 0 : else if( bEnableTransparency && ( pGrafObj->HasGDIMetaFile() || pGrafObj->IsAnimated() ) )
888 : {
889 0 : bEnableTransparency = false;
890 : }
891 : }
892 :
893 0 : rView.GetAttributes( aAttrSet );
894 :
895 0 : while( nWhich )
896 : {
897 0 : sal_uInt16 nSlotId = SfxItemPool::IsWhich( nWhich ) ? rPool.GetSlotId( nWhich ) : nWhich;
898 :
899 0 : switch( nSlotId )
900 : {
901 : case( SID_ATTR_GRAF_MODE ):
902 : {
903 0 : if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFMODE ) )
904 : {
905 0 : if( bEnableColors )
906 : {
907 : rSet.Put( SfxUInt16Item( nSlotId,
908 0 : sal::static_int_cast< sal_uInt16 >( ITEMVALUE( aAttrSet, SDRATTR_GRAFMODE, SdrGrafModeItem ) ) ) );
909 : }
910 : else
911 : {
912 0 : rSet.DisableItem( SID_ATTR_GRAF_MODE );
913 : }
914 : }
915 : }
916 0 : break;
917 :
918 : case( SID_ATTR_GRAF_RED ):
919 : {
920 0 : if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFRED ) )
921 : {
922 0 : if( bEnableColors )
923 : {
924 : rSet.Put( SfxInt16Item( nSlotId,
925 0 : ITEMVALUE( aAttrSet, SDRATTR_GRAFRED, SdrGrafRedItem ) ) );
926 : }
927 : else
928 : {
929 0 : rSet.DisableItem( SID_ATTR_GRAF_RED );
930 : }
931 : }
932 : }
933 0 : break;
934 :
935 : case( SID_ATTR_GRAF_GREEN ):
936 : {
937 0 : if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFGREEN ) )
938 : {
939 0 : if( bEnableColors )
940 : {
941 : rSet.Put( SfxInt16Item( nSlotId,
942 0 : ITEMVALUE( aAttrSet, SDRATTR_GRAFGREEN, SdrGrafGreenItem ) ) );
943 : }
944 : else
945 : {
946 0 : rSet.DisableItem( SID_ATTR_GRAF_GREEN );
947 : }
948 : }
949 : }
950 0 : break;
951 :
952 : case( SID_ATTR_GRAF_BLUE ):
953 : {
954 0 : if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFBLUE ) )
955 : {
956 0 : if( bEnableColors )
957 : {
958 : rSet.Put( SfxInt16Item( nSlotId,
959 0 : ITEMVALUE( aAttrSet, SDRATTR_GRAFBLUE, SdrGrafBlueItem ) ) );
960 : }
961 : else
962 : {
963 0 : rSet.DisableItem( SID_ATTR_GRAF_BLUE );
964 : }
965 : }
966 : }
967 0 : break;
968 :
969 : case( SID_ATTR_GRAF_LUMINANCE ):
970 : {
971 0 : if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFLUMINANCE ) )
972 : {
973 0 : if( bEnableColors )
974 : {
975 : rSet.Put( SfxInt16Item( nSlotId,
976 0 : ITEMVALUE( aAttrSet, SDRATTR_GRAFLUMINANCE, SdrGrafLuminanceItem ) ) );
977 : }
978 : else
979 : {
980 0 : rSet.DisableItem( SID_ATTR_GRAF_LUMINANCE );
981 : }
982 : }
983 : }
984 0 : break;
985 :
986 : case( SID_ATTR_GRAF_CONTRAST ):
987 : {
988 0 : if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFCONTRAST ) )
989 : {
990 0 : if( bEnableColors )
991 : {
992 : rSet.Put( SfxInt16Item( nSlotId,
993 0 : ITEMVALUE( aAttrSet, SDRATTR_GRAFCONTRAST, SdrGrafContrastItem ) ) );
994 : }
995 : else
996 : {
997 0 : rSet.DisableItem( SID_ATTR_GRAF_CONTRAST );
998 : }
999 : }
1000 : }
1001 0 : break;
1002 :
1003 : case( SID_ATTR_GRAF_GAMMA ):
1004 : {
1005 0 : if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFGAMMA ) )
1006 : {
1007 0 : if( bEnableColors )
1008 : {
1009 : rSet.Put( SfxUInt32Item( nSlotId,
1010 0 : ITEMVALUE( aAttrSet, SDRATTR_GRAFGAMMA, SdrGrafGamma100Item ) ) );
1011 : }
1012 : else
1013 : {
1014 0 : rSet.DisableItem( SID_ATTR_GRAF_GAMMA );
1015 : }
1016 : }
1017 : }
1018 0 : break;
1019 :
1020 : case( SID_ATTR_GRAF_TRANSPARENCE ):
1021 : {
1022 0 : if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFTRANSPARENCE ) )
1023 : {
1024 0 : if( bEnableTransparency )
1025 : {
1026 : rSet.Put( SfxUInt16Item( nSlotId,
1027 0 : ITEMVALUE( aAttrSet, SDRATTR_GRAFTRANSPARENCE, SdrGrafTransparenceItem ) ) );
1028 : }
1029 : else
1030 : {
1031 0 : rSet.DisableItem( SID_ATTR_GRAF_TRANSPARENCE );
1032 : }
1033 : }
1034 : }
1035 0 : break;
1036 :
1037 : case( SID_ATTR_GRAF_CROP ):
1038 : {
1039 0 : if( !bEnableCrop )
1040 0 : rSet.DisableItem( nSlotId );
1041 : }
1042 0 : break;
1043 :
1044 : case SID_COLOR_SETTINGS :
1045 : {
1046 0 : svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
1047 0 : rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
1048 0 : break;
1049 : }
1050 :
1051 : default:
1052 0 : break;
1053 : }
1054 :
1055 0 : nWhich = aIter.NextWhich();
1056 0 : }
1057 216 : }
1058 :
1059 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|