bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / tbxctrls / fillctrl.cxx
blobd730a44c84a66afbdfcd3d5147c7d059ff36cb80
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <string>
21 #include <sfx2/app.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <sfx2/objsh.hxx>
24 #include <sfx2/viewsh.hxx>
25 #include <sfx2/sidebar/SidebarToolBox.hxx>
26 #include <rtl/ustring.hxx>
27 #include <vcl/settings.hxx>
28 #include <vcl/toolbox.hxx>
29 #include <svx/dialogs.hrc>
31 #define TMP_STR_BEGIN "["
32 #define TMP_STR_END "]"
34 #include "svx/drawitem.hxx"
35 #include "svx/xattr.hxx"
36 #include <svx/xtable.hxx>
37 #include <svx/fillctrl.hxx>
38 #include <svx/itemwin.hxx>
39 #include <svx/dialmgr.hxx>
40 #include "helpid.hrc"
41 #include <boost/scoped_ptr.hpp>
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::util;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::frame;
48 using namespace ::com::sun::star::lang;
50 SFX_IMPL_TOOLBOX_CONTROL( SvxFillToolBoxControl, XFillStyleItem );
52 SvxFillToolBoxControl::SvxFillToolBoxControl(
53 sal_uInt16 nSlotId,
54 sal_uInt16 nId,
55 ToolBox& rTbx )
56 : SfxToolBoxControl( nSlotId, nId, rTbx )
57 , mpStyleItem()
58 , mpColorItem()
59 , mpFillGradientItem()
60 , mpHatchItem()
61 , mpBitmapItem()
62 , mpFillControl(0)
63 , mpLbFillType(0)
64 , mpLbFillAttr(0)
65 , meLastXFS(static_cast<sal_uInt16>(-1))
66 , mnLastPosGradient(0)
67 , mnLastPosHatch(0)
68 , mnLastPosBitmap(0)
70 addStatusListener( OUString( ".uno:FillColor" ));
71 addStatusListener( OUString( ".uno:FillGradient" ));
72 addStatusListener( OUString( ".uno:FillHatch" ));
73 addStatusListener( OUString( ".uno:FillBitmap" ));
74 addStatusListener( OUString( ".uno:ColorTableState" ));
75 addStatusListener( OUString( ".uno:GradientListState" ));
76 addStatusListener( OUString( ".uno:HatchListState" ));
77 addStatusListener( OUString( ".uno:BitmapListState" ));
80 SvxFillToolBoxControl::~SvxFillToolBoxControl()
84 void SvxFillToolBoxControl::StateChanged(
85 sal_uInt16 nSID,
86 SfxItemState eState,
87 const SfxPoolItem* pState)
89 const bool bDisabled(SfxItemState::DISABLED == eState);
91 switch(nSID)
93 case SID_ATTR_FILL_STYLE:
95 if(bDisabled)
97 mpLbFillType->Disable();
98 mpLbFillType->SetNoSelection();
99 mpLbFillAttr->Show();
100 mpLbFillAttr->Disable();
101 mpLbFillAttr->SetNoSelection();
102 mpToolBoxColor->Hide();
103 meLastXFS = static_cast<sal_uInt16>(-1);
104 mpStyleItem.reset();
107 if(eState >= SfxItemState::DEFAULT)
109 const XFillStyleItem* pItem = dynamic_cast< const XFillStyleItem* >(pState);
111 if(pItem)
113 mpStyleItem.reset(dynamic_cast< XFillStyleItem* >(pItem->Clone()));
114 mpLbFillType->Enable();
115 drawing::FillStyle eXFS = (drawing::FillStyle)mpStyleItem->GetValue();
116 meLastXFS = eXFS;
117 mpLbFillType->SelectEntryPos(sal::static_int_cast< sal_Int32 >(eXFS));
119 if(drawing::FillStyle_NONE == eXFS)
121 mpLbFillAttr->SetNoSelection();
122 mpLbFillAttr->Disable();
125 Update();
126 break;
130 mpLbFillType->SetNoSelection();
131 mpLbFillAttr->Show();
132 mpLbFillAttr->Disable();
133 mpLbFillAttr->SetNoSelection();
134 mpToolBoxColor->Hide();
135 meLastXFS = static_cast<sal_uInt16>(-1);
136 mpStyleItem.reset();
137 break;
139 case SID_ATTR_FILL_COLOR:
141 if(SfxItemState::DEFAULT == eState)
143 mpColorItem.reset(pState ? static_cast<XFillColorItem*>(pState->Clone()) : 0);
146 if(mpStyleItem && drawing::FillStyle_SOLID == (drawing::FillStyle)mpStyleItem->GetValue())
148 mpLbFillAttr->Hide();
149 mpToolBoxColor->Show();
151 Update();
153 break;
155 case SID_ATTR_FILL_GRADIENT:
157 if(SfxItemState::DEFAULT == eState)
159 mpFillGradientItem.reset(pState ? static_cast<XFillGradientItem*>(pState->Clone()) : 0);
162 if(mpStyleItem && drawing::FillStyle_GRADIENT == (drawing::FillStyle)mpStyleItem->GetValue())
164 mpLbFillAttr->Show();
165 mpToolBoxColor->Hide();
167 if(SfxItemState::DEFAULT == eState)
169 mpLbFillAttr->Enable();
170 Update();
172 else if(SfxItemState::DISABLED == eState )
174 mpLbFillAttr->Disable();
175 mpLbFillAttr->SetNoSelection();
177 else
179 mpLbFillAttr->SetNoSelection();
182 break;
184 case SID_ATTR_FILL_HATCH:
186 if(SfxItemState::DEFAULT == eState)
188 mpHatchItem.reset(pState ? static_cast<XFillHatchItem*>(pState->Clone()) : 0);
191 if(mpStyleItem && drawing::FillStyle_HATCH == (drawing::FillStyle)mpStyleItem->GetValue())
193 mpLbFillAttr->Show();
194 mpToolBoxColor->Hide();
196 if(SfxItemState::DEFAULT == eState)
198 mpLbFillAttr->Enable();
199 Update();
201 else if(SfxItemState::DISABLED == eState )
203 mpLbFillAttr->Disable();
204 mpLbFillAttr->SetNoSelection();
206 else
208 mpLbFillAttr->SetNoSelection();
211 break;
213 case SID_ATTR_FILL_BITMAP:
215 if(SfxItemState::DEFAULT == eState)
217 mpBitmapItem.reset(pState ? static_cast<XFillBitmapItem*>(pState->Clone()) : 0);
220 if(mpStyleItem && drawing::FillStyle_BITMAP == (drawing::FillStyle)mpStyleItem->GetValue())
222 mpLbFillAttr->Show();
223 mpToolBoxColor->Hide();
225 if(SfxItemState::DEFAULT == eState)
227 mpLbFillAttr->Enable();
228 Update();
230 else if(SfxItemState::DISABLED == eState )
232 mpLbFillAttr->Disable();
233 mpLbFillAttr->SetNoSelection();
235 else
237 mpLbFillAttr->SetNoSelection();
240 break;
242 case SID_GRADIENT_LIST:
244 if(SfxItemState::DEFAULT == eState)
246 if(mpStyleItem && drawing::FillStyle_GRADIENT == (drawing::FillStyle)mpStyleItem->GetValue())
248 if(mpFillGradientItem)
250 const OUString aString( mpFillGradientItem->GetName() );
251 const SfxObjectShell* pSh = SfxObjectShell::Current();
252 const SvxGradientListItem aItem( *static_cast<const SvxGradientListItem*>(pSh->GetItem(SID_GRADIENT_LIST)));
254 mpLbFillAttr->Clear();
255 mpLbFillAttr->Enable();
256 mpLbFillAttr->Fill(aItem.GetGradientList());
257 mpLbFillAttr->SelectEntry(aString);
259 else
261 mpLbFillAttr->SetNoSelection();
265 break;
267 case SID_HATCH_LIST:
269 if(SfxItemState::DEFAULT == eState)
271 if(mpStyleItem && drawing::FillStyle_HATCH == (drawing::FillStyle)mpStyleItem->GetValue())
273 if(mpHatchItem)
275 const OUString aString( mpHatchItem->GetName() );
276 const SfxObjectShell* pSh = SfxObjectShell::Current();
277 const SvxHatchListItem aItem(*static_cast<const SvxHatchListItem*>(pSh->GetItem(SID_HATCH_LIST)));
279 mpLbFillAttr->Clear();
280 mpLbFillAttr->Enable();
281 mpLbFillAttr->Fill(aItem.GetHatchList());
282 mpLbFillAttr->SelectEntry(aString);
284 else
286 mpLbFillAttr->SetNoSelection();
290 break;
292 case SID_BITMAP_LIST:
294 if(SfxItemState::DEFAULT == eState)
296 if(mpStyleItem && drawing::FillStyle_BITMAP == (drawing::FillStyle)mpStyleItem->GetValue())
298 if(mpBitmapItem)
300 const OUString aString( mpBitmapItem->GetName() );
301 const SfxObjectShell* pSh = SfxObjectShell::Current();
302 const SvxBitmapListItem aItem(*static_cast<const SvxBitmapListItem*>(pSh->GetItem(SID_BITMAP_LIST)));
304 mpLbFillAttr->Clear();
305 mpLbFillAttr->Enable();
306 mpLbFillAttr->Fill(aItem.GetBitmapList());
307 mpLbFillAttr->SelectEntry(aString);
309 else
311 mpLbFillAttr->SetNoSelection();
315 break;
320 void SvxFillToolBoxControl::Update()
322 if(mpStyleItem)
324 const drawing::FillStyle eXFS = (drawing::FillStyle)mpStyleItem->GetValue();
325 SfxObjectShell* pSh = SfxObjectShell::Current();
327 switch( eXFS )
329 case drawing::FillStyle_NONE:
331 mpLbFillAttr->Show();
332 mpToolBoxColor->Hide();
333 break;
335 case drawing::FillStyle_SOLID:
337 if(mpColorItem)
339 mpLbFillAttr->Hide();
340 mpToolBoxColor->Show();
342 break;
344 case drawing::FillStyle_GRADIENT:
346 mpLbFillAttr->Show();
347 mpToolBoxColor->Hide();
349 if(pSh && pSh->GetItem(SID_GRADIENT_LIST))
351 const SvxGradientListItem aItem(*static_cast<const SvxGradientListItem*>(pSh->GetItem(SID_GRADIENT_LIST)));
352 mpLbFillAttr->Enable();
353 mpLbFillAttr->Clear();
354 mpLbFillAttr->Fill(aItem.GetGradientList());
356 if(mpFillGradientItem)
358 const OUString aString(mpFillGradientItem->GetName());
360 mpLbFillAttr->SelectEntry(aString);
362 // Check if the entry is not in the list
363 if (mpLbFillAttr->GetSelectEntry() != aString)
365 sal_Int32 nCount = mpLbFillAttr->GetEntryCount();
366 OUString aTmpStr;
367 if( nCount > 0 )
369 // Last entry gets tested against temporary entry
370 aTmpStr = mpLbFillAttr->GetEntry( nCount - 1 );
371 if( aTmpStr.startsWith(TMP_STR_BEGIN) &&
372 aTmpStr.endsWith(TMP_STR_END) )
374 mpLbFillAttr->RemoveEntry(nCount - 1);
377 aTmpStr = TMP_STR_BEGIN + aString + TMP_STR_END;
379 boost::scoped_ptr<XGradientEntry> pEntry(new XGradientEntry(mpFillGradientItem->GetGradientValue(), aTmpStr));
380 XGradientList aGradientList( "", ""/*TODO?*/ );
381 aGradientList.Insert( pEntry.get() );
382 aGradientList.SetDirty( false );
383 const Bitmap aBmp = aGradientList.GetUiBitmap( 0 );
385 if(!aBmp.IsEmpty())
387 mpLbFillAttr->InsertEntry(pEntry->GetName(), Image(aBmp));
388 mpLbFillAttr->SelectEntryPos(mpLbFillAttr->GetEntryCount() - 1);
391 aGradientList.Remove( 0 );
395 else
397 mpLbFillAttr->SetNoSelection();
400 else
402 mpLbFillAttr->SetNoSelection();
404 break;
406 case drawing::FillStyle_HATCH:
408 mpLbFillAttr->Show();
409 mpToolBoxColor->Hide();
411 if(pSh && pSh->GetItem(SID_HATCH_LIST))
413 const SvxHatchListItem aItem(*static_cast<const SvxHatchListItem*>(pSh->GetItem(SID_HATCH_LIST)));
414 mpLbFillAttr->Enable();
415 mpLbFillAttr->Clear();
416 mpLbFillAttr->Fill(aItem.GetHatchList());
418 if(mpHatchItem)
420 const OUString aString(mpHatchItem->GetName());
422 mpLbFillAttr->SelectEntry( aString );
424 // Check if the entry is not in the list
425 if( mpLbFillAttr->GetSelectEntry() != aString )
427 sal_uInt16 nCount = mpLbFillAttr->GetEntryCount();
428 OUString aTmpStr;
429 if( nCount > 0 )
431 // Last entry gets tested against temporary entry
432 aTmpStr = mpLbFillAttr->GetEntry( nCount - 1 );
433 if( aTmpStr.startsWith(TMP_STR_BEGIN) &&
434 aTmpStr.endsWith(TMP_STR_END) )
436 mpLbFillAttr->RemoveEntry( nCount - 1 );
439 aTmpStr = TMP_STR_BEGIN + aString + TMP_STR_END;
441 XHatchEntry* pEntry = new XHatchEntry(mpHatchItem->GetHatchValue(), aTmpStr);
442 XHatchList aHatchList( "", ""/*TODO?*/ );
443 aHatchList.Insert( pEntry );
444 aHatchList.SetDirty( false );
445 const Bitmap aBmp = aHatchList.GetUiBitmap( 0 );
447 if( !aBmp.IsEmpty() )
449 mpLbFillAttr->InsertEntry(pEntry->GetName(), Image(aBmp));
450 mpLbFillAttr->SelectEntryPos( mpLbFillAttr->GetEntryCount() - 1 );
451 //delete pBmp;
454 aHatchList.Remove( 0 );
455 delete pEntry;
458 else
460 mpLbFillAttr->SetNoSelection();
463 else
465 mpLbFillAttr->SetNoSelection();
467 break;
469 case drawing::FillStyle_BITMAP:
471 mpLbFillAttr->Show();
472 mpToolBoxColor->Hide();
474 if(pSh && pSh->GetItem(SID_BITMAP_LIST))
476 const SvxBitmapListItem aItem(*static_cast<const SvxBitmapListItem*>(pSh->GetItem(SID_BITMAP_LIST)));
477 mpLbFillAttr->Enable();
478 mpLbFillAttr->Clear();
479 mpLbFillAttr->Fill(aItem.GetBitmapList());
481 if(mpBitmapItem)
483 const OUString aString(mpBitmapItem->GetName());
485 mpLbFillAttr->SelectEntry(aString);
487 // Check if the entry is not in the list
488 if (mpLbFillAttr->GetSelectEntry() != aString)
490 sal_Int32 nCount = mpLbFillAttr->GetEntryCount();
491 OUString aTmpStr;
492 if( nCount > 0 )
494 // Last entry gets tested against temporary entry
495 aTmpStr = mpLbFillAttr->GetEntry(nCount - 1);
496 if( aTmpStr.startsWith(TMP_STR_BEGIN) &&
497 aTmpStr.endsWith(TMP_STR_END) )
499 mpLbFillAttr->RemoveEntry(nCount - 1);
502 aTmpStr = TMP_STR_BEGIN + aString + TMP_STR_END;
504 boost::scoped_ptr<XBitmapEntry> pEntry(new XBitmapEntry(mpBitmapItem->GetGraphicObject(), aTmpStr));
505 XBitmapListRef xBitmapList =
506 XPropertyList::AsBitmapList(
507 XPropertyList::CreatePropertyList(
508 XBITMAP_LIST, "TmpList", ""/*TODO?*/));
509 xBitmapList->Insert( pEntry.get() );
510 xBitmapList->SetDirty( false );
511 mpLbFillAttr->Fill( xBitmapList );
512 mpLbFillAttr->SelectEntryPos(mpLbFillAttr->GetEntryCount() - 1);
513 xBitmapList->Remove( 0 );
517 else
519 mpLbFillAttr->SetNoSelection();
522 else
524 mpLbFillAttr->SetNoSelection();
526 break;
528 default:
529 OSL_ENSURE(false, "Non supported FillType (!)");
530 break;
536 VclPtr<vcl::Window> SvxFillToolBoxControl::CreateItemWindow(vcl::Window *pParent)
538 if(GetSlotId() == SID_ATTR_FILL_STYLE)
540 mpFillControl.reset(VclPtr<FillControl>::Create(pParent));
541 // Thus the FillControl is known by SvxFillToolBoxControl
542 // (and in order to remain compatible)
543 mpFillControl->SetData(this);
545 mpLbFillType = mpFillControl->mpLbFillType;
546 mpLbFillAttr = mpFillControl->mpLbFillAttr;
547 mpToolBoxColor = mpFillControl->mpToolBoxColor;
548 mpFillControl->Resize();
549 mpToolBoxColor->InsertItem(".uno:FillColor", m_xFrame, ToolBoxItemBits::DROPDOWNONLY, Size(mpToolBoxColor->GetSizePixel().Width(), 0));
551 mpLbFillAttr->SetUniqueId(HID_FILL_ATTR_LISTBOX);
552 mpToolBoxColor->SetUniqueId(HID_FILL_ATTR_LISTBOX);
553 mpLbFillType->SetUniqueId(HID_FILL_TYPE_LISTBOX);
555 mpLbFillType->SetSelectHdl(LINK(this,SvxFillToolBoxControl,SelectFillTypeHdl));
556 mpLbFillAttr->SetSelectHdl(LINK(this,SvxFillToolBoxControl,SelectFillAttrHdl));
558 return mpFillControl.get();
560 return VclPtr<vcl::Window>();
563 FillControl::FillControl(vcl::Window* pParent,WinBits nStyle)
564 : Window(pParent,nStyle | WB_DIALOGCONTROL)
565 , mpLbFillType(VclPtr<SvxFillTypeBox>::Create(this))
566 , mpToolBoxColor(VclPtr<sfx2::sidebar::SidebarToolBox>::Create(this))
567 , mpLbFillAttr(VclPtr<SvxFillAttrBox>::Create(this))
569 SetOptimalSize();
572 FillControl::~FillControl()
574 disposeOnce();
577 void FillControl::dispose()
579 mpLbFillType.disposeAndClear();
580 mpToolBoxColor.disposeAndClear();
581 mpLbFillAttr.disposeAndClear();
582 vcl::Window::dispose();
585 IMPL_LINK(SvxFillToolBoxControl, SelectFillTypeHdl, ListBox *, pToolBox)
587 const drawing::FillStyle eXFS = (drawing::FillStyle)mpLbFillType->GetSelectEntryPos();
589 if((drawing::FillStyle)meLastXFS != eXFS)
591 mpLbFillAttr->Clear();
592 SfxObjectShell* pSh = SfxObjectShell::Current();
593 const XFillStyleItem aXFillStyleItem(eXFS);
595 // #i122676# Do no longer trigger two Execute calls, one for SID_ATTR_FILL_STYLE
596 // and one for setting the fill attribute itself, but add two SfxPoolItems to the
597 // call to get just one action at the SdrObject and to create only one Undo action, too.
598 // Checked that this works in all apps.
599 switch( eXFS )
601 default:
602 case drawing::FillStyle_NONE:
604 mpLbFillAttr->Show();
605 mpToolBoxColor->Hide();
606 mpLbFillType->Selected();
607 mpLbFillAttr->Disable();
609 // #i122676# need to call a single SID_ATTR_FILL_STYLE change
610 SfxViewFrame::Current()->GetDispatcher()->Execute(
611 SID_ATTR_FILL_STYLE, SfxCallMode::RECORD, &aXFillStyleItem, 0L);
612 break;
614 case drawing::FillStyle_SOLID:
616 mpLbFillAttr->Hide();
617 mpToolBoxColor->Show();
618 const OUString aTmpStr;
619 const ::Color aColor = mpColorItem->GetColorValue();
620 const XFillColorItem aXFillColorItem( aTmpStr, aColor );
622 // #i122676# change FillStyle and Color in one call
623 SfxViewFrame::Current()->GetDispatcher()->Execute(
624 SID_ATTR_FILL_COLOR, SfxCallMode::RECORD, &aXFillColorItem, &aXFillStyleItem, 0L);
625 break;
627 case drawing::FillStyle_GRADIENT:
629 mpLbFillAttr->Show();
630 mpToolBoxColor->Hide();
632 if(pSh && pSh->GetItem(SID_GRADIENT_LIST))
634 if(!mpLbFillAttr->GetEntryCount())
636 const SvxGradientListItem aItem(*static_cast<const SvxGradientListItem*>(pSh->GetItem(SID_GRADIENT_LIST)));
637 mpLbFillAttr->Enable();
638 mpLbFillAttr->Clear();
639 mpLbFillAttr->Fill(aItem.GetGradientList());
642 mpLbFillAttr->AdaptDropDownLineCountToMaximum();
644 if(LISTBOX_ENTRY_NOTFOUND != mnLastPosGradient)
646 const SvxGradientListItem aItem(*static_cast<const SvxGradientListItem*>(pSh->GetItem(SID_GRADIENT_LIST)));
648 if(mnLastPosGradient < aItem.GetGradientList()->Count())
650 const XGradient aGradient = aItem.GetGradientList()->GetGradient(mnLastPosGradient)->GetGradient();
651 const XFillGradientItem aXFillGradientItem(mpLbFillAttr->GetEntry(mnLastPosGradient), aGradient);
653 // #i122676# change FillStyle and Gradient in one call
654 SfxViewFrame::Current()->GetDispatcher()->Execute(
655 SID_ATTR_FILL_GRADIENT, SfxCallMode::RECORD, &aXFillGradientItem, &aXFillStyleItem, 0L);
656 mpLbFillAttr->SelectEntryPos(mnLastPosGradient);
660 else
662 mpLbFillAttr->Disable();
664 break;
666 case drawing::FillStyle_HATCH:
668 mpLbFillAttr->Show();
669 mpToolBoxColor->Hide();
671 if(pSh && pSh->GetItem(SID_HATCH_LIST))
673 if(!mpLbFillAttr->GetEntryCount())
675 const SvxHatchListItem aItem( *static_cast<const SvxHatchListItem*>(pSh->GetItem(SID_HATCH_LIST)));
676 mpLbFillAttr->Enable();
677 mpLbFillAttr->Clear();
678 mpLbFillAttr->Fill(aItem.GetHatchList());
681 mpLbFillAttr->AdaptDropDownLineCountToMaximum();
683 if(LISTBOX_ENTRY_NOTFOUND != mnLastPosHatch)
685 const SvxHatchListItem aItem(*static_cast<const SvxHatchListItem*>(pSh->GetItem(SID_HATCH_LIST)));
687 if(mnLastPosHatch < aItem.GetHatchList()->Count())
689 const XHatch aHatch = aItem.GetHatchList()->GetHatch(mnLastPosHatch)->GetHatch();
690 const XFillHatchItem aXFillHatchItem(mpLbFillAttr->GetSelectEntry(), aHatch);
692 // #i122676# change FillStyle and Hatch in one call
693 SfxViewFrame::Current()->GetDispatcher()->Execute(
694 SID_ATTR_FILL_HATCH, SfxCallMode::RECORD, &aXFillHatchItem, &aXFillStyleItem, 0L);
695 mpLbFillAttr->SelectEntryPos(mnLastPosHatch);
699 else
701 mpLbFillAttr->Disable();
703 break;
705 case drawing::FillStyle_BITMAP:
707 mpLbFillAttr->Show();
708 mpToolBoxColor->Hide();
710 if(pSh && pSh->GetItem(SID_BITMAP_LIST))
712 if(!mpLbFillAttr->GetEntryCount())
714 const SvxBitmapListItem aItem( *static_cast<const SvxBitmapListItem*>(pSh->GetItem(SID_BITMAP_LIST)));
715 mpLbFillAttr->Enable();
716 mpLbFillAttr->Clear();
717 mpLbFillAttr->Fill(aItem.GetBitmapList());
720 mpLbFillAttr->AdaptDropDownLineCountToMaximum();
722 if(LISTBOX_ENTRY_NOTFOUND != mnLastPosBitmap)
724 const SvxBitmapListItem aItem(*static_cast<const SvxBitmapListItem*>(pSh->GetItem(SID_BITMAP_LIST)));
726 if(mnLastPosBitmap < aItem.GetBitmapList()->Count())
728 const XBitmapEntry* pXBitmapEntry = aItem.GetBitmapList()->GetBitmap(mnLastPosBitmap);
729 const XFillBitmapItem aXFillBitmapItem(mpLbFillAttr->GetSelectEntry(), pXBitmapEntry->GetGraphicObject());
731 // #i122676# change FillStyle and Bitmap in one call
732 SfxViewFrame::Current()->GetDispatcher()->Execute(
733 SID_ATTR_FILL_BITMAP, SfxCallMode::RECORD, &aXFillBitmapItem, &aXFillStyleItem, 0L);
734 mpLbFillAttr->SelectEntryPos(mnLastPosBitmap);
738 else
740 mpLbFillAttr->Disable();
742 break;
746 meLastXFS = (sal_uInt16)eXFS;
748 if(drawing::FillStyle_NONE != eXFS)
750 if(pToolBox)
752 mpLbFillType->Selected();
757 return 0;
760 IMPL_LINK(SvxFillToolBoxControl, SelectFillAttrHdl, ListBox *, pToolBox)
762 const drawing::FillStyle eXFS = (drawing::FillStyle)mpLbFillType->GetSelectEntryPos();
763 const XFillStyleItem aXFillStyleItem(eXFS);
764 SfxObjectShell* pSh = SfxObjectShell::Current();
766 if(pToolBox)
768 // #i122676# dependent from bFillStyleChange, do execute a single or two
769 // changes in one Execute call
770 const bool bFillStyleChange((drawing::FillStyle) meLastXFS != eXFS);
772 switch(eXFS)
774 case drawing::FillStyle_SOLID:
776 if(bFillStyleChange)
778 // #i122676# Single FillStyle change call needed here
779 SfxViewFrame::Current()->GetDispatcher()->Execute(SID_ATTR_FILL_STYLE, SfxCallMode::RECORD, &aXFillStyleItem, 0L);
781 break;
783 case drawing::FillStyle_GRADIENT:
785 sal_Int32 nPos = mpLbFillAttr->GetSelectEntryPos();
787 if(LISTBOX_ENTRY_NOTFOUND == nPos)
789 nPos = mnLastPosGradient;
792 if(LISTBOX_ENTRY_NOTFOUND != nPos && pSh && pSh->GetItem(SID_GRADIENT_LIST))
794 const SvxGradientListItem aItem(*static_cast<const SvxGradientListItem*>(pSh->GetItem(SID_GRADIENT_LIST)));
796 if(nPos < aItem.GetGradientList()->Count())
798 const XGradient aGradient = aItem.GetGradientList()->GetGradient(nPos)->GetGradient();
799 const XFillGradientItem aXFillGradientItem(mpLbFillAttr->GetSelectEntry(), aGradient);
801 // #i122676# Change FillStale and Gradinet in one call
802 SfxViewFrame::Current()->GetDispatcher()->Execute(
803 SID_ATTR_FILL_GRADIENT, SfxCallMode::RECORD, &aXFillGradientItem,
804 bFillStyleChange ? &aXFillStyleItem : 0L, 0L);
808 if(LISTBOX_ENTRY_NOTFOUND != nPos)
810 mnLastPosGradient = nPos;
812 break;
814 case drawing::FillStyle_HATCH:
816 sal_Int32 nPos = mpLbFillAttr->GetSelectEntryPos();
818 if(LISTBOX_ENTRY_NOTFOUND == nPos)
820 nPos = mnLastPosHatch;
823 if(LISTBOX_ENTRY_NOTFOUND != nPos && pSh && pSh->GetItem(SID_HATCH_LIST))
825 const SvxHatchListItem aItem(*static_cast<const SvxHatchListItem*>(pSh->GetItem(SID_HATCH_LIST)));
827 if(nPos < aItem.GetHatchList()->Count())
829 const XHatch aHatch = aItem.GetHatchList()->GetHatch(nPos)->GetHatch();
830 const XFillHatchItem aXFillHatchItem( mpLbFillAttr->GetSelectEntry(), aHatch);
832 // #i122676# Change FillStale and Hatch in one call
833 SfxViewFrame::Current()->GetDispatcher()->Execute(
834 SID_ATTR_FILL_HATCH, SfxCallMode::RECORD, &aXFillHatchItem,
835 bFillStyleChange ? &aXFillStyleItem : 0L, 0L);
839 if(LISTBOX_ENTRY_NOTFOUND != nPos)
841 mnLastPosHatch = nPos;
843 break;
845 case drawing::FillStyle_BITMAP:
847 sal_Int32 nPos = mpLbFillAttr->GetSelectEntryPos();
849 if(LISTBOX_ENTRY_NOTFOUND == nPos)
851 nPos = mnLastPosBitmap;
854 if(LISTBOX_ENTRY_NOTFOUND != nPos && pSh && pSh->GetItem(SID_BITMAP_LIST))
856 const SvxBitmapListItem aItem(*static_cast<const SvxBitmapListItem*>(pSh->GetItem(SID_BITMAP_LIST)));
858 if(nPos < aItem.GetBitmapList()->Count())
860 const XBitmapEntry* pXBitmapEntry = aItem.GetBitmapList()->GetBitmap(nPos);
861 const XFillBitmapItem aXFillBitmapItem(mpLbFillAttr->GetSelectEntry(), pXBitmapEntry->GetGraphicObject());
863 // #i122676# Change FillStale and Bitmap in one call
864 SfxViewFrame::Current()->GetDispatcher()->Execute(
865 SID_ATTR_FILL_BITMAP, SfxCallMode::RECORD, &aXFillBitmapItem,
866 bFillStyleChange ? &aXFillStyleItem : 0L, 0L);
870 if(LISTBOX_ENTRY_NOTFOUND != nPos)
872 mnLastPosBitmap = nPos;
874 break;
876 default: break;
880 return 0;
883 void FillControl::Resize()
885 // Relative width of the two list boxes is 2/5 : 3/5
886 Size aSize(GetOutputSizePixel());
887 long nW = aSize.Width() / 5;
888 long nH = aSize.Height();
890 long nPrefHeight = mpLbFillType->get_preferred_size().Height();
891 long nOffset = (nH - nPrefHeight)/2;
892 mpLbFillType->SetPosSizePixel(Point(0, nOffset), Size(nW * 2, nPrefHeight));
893 nPrefHeight = mpToolBoxColor->get_preferred_size().Height();
894 nOffset = (nH - nPrefHeight)/2;
895 mpToolBoxColor->SetPosSizePixel(Point(nW * 2, nOffset),Size(nW * 3, nPrefHeight));
896 nPrefHeight = mpLbFillType->get_preferred_size().Height();
897 nOffset = (nH - nPrefHeight)/2;
898 mpLbFillAttr->SetPosSizePixel(Point(nW * 2, nOffset),Size(nW * 3, nPrefHeight));
901 void FillControl::SetOptimalSize()
903 const Size aLogicalAttrSize(50,0);
904 Size aSize(LogicToPixel(aLogicalAttrSize,MAP_APPFONT));
906 Point aAttrPnt = mpLbFillAttr->GetPosPixel();
908 aSize.Height() = std::max(aSize.Height(), mpLbFillType->get_preferred_size().Height());
909 aSize.Height() = std::max(aSize.Height(), mpToolBoxColor->get_preferred_size().Height());
910 aSize.Height() = std::max(aSize.Height(), mpLbFillAttr->get_preferred_size().Height());
912 aSize.Width() = aAttrPnt.X() + aSize.Width();
914 SetSizePixel(aSize);
917 void FillControl::DataChanged(const DataChangedEvent& rDCEvt)
919 if((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
920 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))
922 SetOptimalSize();
924 Window::DataChanged(rDCEvt);
927 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */