LibreOffice Module svx (master)  1
fillctrl.cxx
Go to the documentation of this file.
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 <sfx2/dispatch.hxx>
21 #include <sfx2/objsh.hxx>
22 #include <sfx2/viewfrm.hxx>
23 #include <sfx2/viewsh.hxx>
24 #include <rtl/ustring.hxx>
25 #include <vcl/event.hxx>
26 #include <vcl/settings.hxx>
27 #include <vcl/toolbox.hxx>
28 #include <svx/svxids.hrc>
29 
30 #define TMP_STR_BEGIN "["
31 #define TMP_STR_END "]"
32 
33 #include <svx/drawitem.hxx>
34 #include <svx/xfillit0.hxx>
35 #include <svx/xtable.hxx>
36 #include <svx/fillctrl.hxx>
37 #include <svx/itemwin.hxx>
38 #include <svx/xflclit.hxx>
39 #include <svx/xflgrit.hxx>
40 #include <svx/xflhtit.hxx>
41 #include <svx/xbtmpit.hxx>
42 #include <boost/property_tree/ptree.hpp>
43 #include <memory>
44 
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::util;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::lang;
50 
52 
54  sal_uInt16 nSlotId,
55  sal_uInt16 nId,
56  ToolBox& rTbx )
57  : SfxToolBoxControl( nSlotId, nId, rTbx )
58  , mpStyleItem()
59  , mpColorItem()
60  , mpFillGradientItem()
61  , mpHatchItem()
62  , mpBitmapItem()
63  , mxFillControl(nullptr)
64  , mpLbFillType(nullptr)
65  , mpToolBoxColor(nullptr)
66  , mpLbFillAttr(nullptr)
67  , meLastXFS(static_cast<drawing::FillStyle>(-1))
68  , mnLastPosGradient(0)
69  , mnLastPosHatch(0)
70  , mnLastPosBitmap(0)
71 {
72  addStatusListener( ".uno:FillColor");
73  addStatusListener( ".uno:FillGradient");
74  addStatusListener( ".uno:FillHatch");
75  addStatusListener( ".uno:FillBitmap");
76  addStatusListener( ".uno:ColorTableState");
77  addStatusListener( ".uno:GradientListState");
78  addStatusListener( ".uno:HatchListState");
79  addStatusListener( ".uno:BitmapListState");
80 }
81 
83 {
84 }
85 
87  sal_uInt16 nSID,
88  SfxItemState eState,
89  const SfxPoolItem* pState)
90 {
91  const bool bDisabled(SfxItemState::DISABLED == eState);
92 
93  switch(nSID)
94  {
95  case SID_ATTR_FILL_STYLE:
96  {
97  if(bDisabled)
98  {
101  mpLbFillAttr->show();
102  mpLbFillAttr->set_sensitive(false);
104  mpToolBoxColor->hide();
105  meLastXFS = static_cast<drawing::FillStyle>(-1);
106  mpStyleItem.reset();
107  }
108 
109  if(eState >= SfxItemState::DEFAULT)
110  {
111  const XFillStyleItem* pItem = dynamic_cast< const XFillStyleItem* >(pState);
112 
113  if(pItem)
114  {
115  mpStyleItem.reset(pItem->Clone());
117  drawing::FillStyle eXFS = mpStyleItem->GetValue();
118  meLastXFS = eXFS;
119  mpLbFillType->set_active(sal::static_int_cast< sal_Int32 >(eXFS));
120 
121  if(drawing::FillStyle_NONE == eXFS)
122  {
124  mpLbFillAttr->set_sensitive(false);
125  }
126 
127  Update();
128  break;
129  }
130  }
131 
133  mpLbFillAttr->show();
134  mpLbFillAttr->set_sensitive(false);
136  mpToolBoxColor->hide();
137  meLastXFS = static_cast<drawing::FillStyle>(-1);
138  mpStyleItem.reset();
140  break;
141  }
142  case SID_ATTR_FILL_COLOR:
143  {
144  if(SfxItemState::DEFAULT == eState)
145  {
146  mpColorItem.reset(pState ? static_cast<XFillColorItem*>(pState->Clone()) : nullptr);
147  }
148 
149  if(mpStyleItem && drawing::FillStyle_SOLID == mpStyleItem->GetValue())
150  {
151  mpLbFillAttr->hide();
152  mpToolBoxColor->show();
154 
155  Update();
156  }
157  break;
158  }
159  case SID_ATTR_FILL_GRADIENT:
160  {
161  if(SfxItemState::DEFAULT == eState)
162  {
163  mpFillGradientItem.reset(pState ? static_cast<XFillGradientItem*>(pState->Clone()) : nullptr);
164  }
165 
166  if(mpStyleItem && drawing::FillStyle_GRADIENT == mpStyleItem->GetValue())
167  {
168  mpLbFillAttr->show();
169  mpToolBoxColor->hide();
171 
172  if(SfxItemState::DEFAULT == eState)
173  {
175  Update();
176  }
177  else if(SfxItemState::DISABLED == eState )
178  {
179  mpLbFillAttr->set_sensitive(false);
181  }
182  else
183  {
185  }
186  }
187  break;
188  }
189  case SID_ATTR_FILL_HATCH:
190  {
191  if(SfxItemState::DEFAULT == eState)
192  {
193  mpHatchItem.reset(pState ? static_cast<XFillHatchItem*>(pState->Clone()) : nullptr);
194  }
195 
196  if(mpStyleItem && drawing::FillStyle_HATCH == mpStyleItem->GetValue())
197  {
198  mpLbFillAttr->show();
199  mpToolBoxColor->hide();
201 
202  if(SfxItemState::DEFAULT == eState)
203  {
205  Update();
206  }
207  else if(SfxItemState::DISABLED == eState )
208  {
209  mpLbFillAttr->set_sensitive(false);
211  }
212  else
213  {
215  }
216  }
217  break;
218  }
219  case SID_ATTR_FILL_BITMAP:
220  {
221  if(SfxItemState::DEFAULT == eState)
222  {
223  mpBitmapItem.reset(pState ? static_cast<XFillBitmapItem*>(pState->Clone()) : nullptr);
224  }
225 
226  if(mpStyleItem && drawing::FillStyle_BITMAP == mpStyleItem->GetValue())
227  {
228  mpLbFillAttr->show();
229  mpToolBoxColor->hide();
231 
232  if(SfxItemState::DEFAULT == eState)
233  {
235  Update();
236  }
237  else if(SfxItemState::DISABLED == eState )
238  {
239  mpLbFillAttr->set_sensitive(false);
241  }
242  else
243  {
245  }
246  }
247  break;
248  }
249  case SID_GRADIENT_LIST:
250  {
251  if(SfxItemState::DEFAULT == eState)
252  {
253  if(mpStyleItem && drawing::FillStyle_GRADIENT == mpStyleItem->GetValue())
254  {
256  {
257  const OUString aString( mpFillGradientItem->GetName() );
259 
260  mpLbFillAttr->clear();
262  SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
263  mpLbFillAttr->set_active_text(aString);
264  }
265  else
266  {
268  }
269  }
270  }
271  break;
272  }
273  case SID_HATCH_LIST:
274  {
275  if(SfxItemState::DEFAULT == eState)
276  {
277  if(mpStyleItem && drawing::FillStyle_HATCH == mpStyleItem->GetValue())
278  {
279  if(mpHatchItem)
280  {
281  const OUString aString( mpHatchItem->GetName() );
283 
284  mpLbFillAttr->clear();
286  SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
287  mpLbFillAttr->set_active_text(aString);
288  }
289  else
290  {
292  }
293  }
294  }
295  break;
296  }
297  case SID_BITMAP_LIST:
298  {
299  if(SfxItemState::DEFAULT == eState)
300  {
301  if(mpStyleItem && drawing::FillStyle_BITMAP == mpStyleItem->GetValue())
302  {
303  if(mpBitmapItem)
304  {
305  const OUString aString( mpBitmapItem->GetName() );
307 
308  mpLbFillAttr->clear();
310  SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
311  mpLbFillAttr->set_active_text(aString);
312  }
313  else
314  {
316  }
317  }
318  }
319  break;
320  }
321  }
322 }
323 
325 {
326  if(mpStyleItem)
327  {
328  const drawing::FillStyle eXFS = mpStyleItem->GetValue();
330 
331  switch( eXFS )
332  {
333  case drawing::FillStyle_NONE:
334  {
335  mpLbFillAttr->show();
336  mpToolBoxColor->hide();
338  break;
339  }
340  case drawing::FillStyle_SOLID:
341  {
342  if(mpColorItem)
343  {
344  mpLbFillAttr->hide();
345  mpToolBoxColor->show();
347  }
348  break;
349  }
350  case drawing::FillStyle_GRADIENT:
351  {
352  mpLbFillAttr->show();
353  mpToolBoxColor->hide();
355 
356  if(pSh && pSh->GetItem(SID_GRADIENT_LIST))
357  {
359  mpLbFillAttr->clear();
360  SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
361 
363  {
364  const OUString aString(mpFillGradientItem->GetName());
365 
366  mpLbFillAttr->set_active_text(aString);
367 
368  // Check if the entry is not in the list
369  if (mpLbFillAttr->get_active_text() != aString)
370  {
371  sal_Int32 nCount = mpLbFillAttr->get_count();
372  OUString aTmpStr;
373  if( nCount > 0 )
374  {
375  // Last entry gets tested against temporary entry
376  aTmpStr = mpLbFillAttr->get_text( nCount - 1 );
377  if( aTmpStr.startsWith(TMP_STR_BEGIN) &&
378  aTmpStr.endsWith(TMP_STR_END) )
379  {
380  mpLbFillAttr->remove(nCount - 1);
381  }
382  }
383  aTmpStr = TMP_STR_BEGIN + aString + TMP_STR_END;
384 
385  XGradientList aGradientList( "", ""/*TODO?*/ );
386  aGradientList.Insert(std::make_unique<XGradientEntry>(mpFillGradientItem->GetGradientValue(), aTmpStr));
387  aGradientList.SetDirty( false );
388  const BitmapEx aBmp = aGradientList.GetUiBitmap( 0 );
389 
390  if (!aBmp.IsEmpty())
391  {
393  const Size aBmpSize(aBmp.GetSizePixel());
394  pVD->SetOutputSizePixel(aBmpSize, false);
395  pVD->DrawBitmapEx(Point(), aBmp);
396  mpLbFillAttr->append("", aGradientList.Get(0)->GetName(), *pVD);
398  }
399  }
400 
401  }
402  else
403  {
405  }
406  }
407  else
408  {
410  }
411  break;
412  }
413  case drawing::FillStyle_HATCH:
414  {
415  mpLbFillAttr->show();
416  mpToolBoxColor->hide();
418 
419  if(pSh && pSh->GetItem(SID_HATCH_LIST))
420  {
422  mpLbFillAttr->clear();
423  SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
424 
425  if(mpHatchItem)
426  {
427  const OUString aString(mpHatchItem->GetName());
428 
429  mpLbFillAttr->set_active_text( aString );
430 
431  // Check if the entry is not in the list
432  if( mpLbFillAttr->get_active_text() != aString )
433  {
434  const sal_Int32 nCount = mpLbFillAttr->get_count();
435  OUString aTmpStr;
436  if( nCount > 0 )
437  {
438  // Last entry gets tested against temporary entry
439  aTmpStr = mpLbFillAttr->get_text( nCount - 1 );
440  if( aTmpStr.startsWith(TMP_STR_BEGIN) &&
441  aTmpStr.endsWith(TMP_STR_END) )
442  {
443  mpLbFillAttr->remove( nCount - 1 );
444  }
445  }
446  aTmpStr = TMP_STR_BEGIN + aString + TMP_STR_END;
447 
448  XHatchList aHatchList( "", ""/*TODO?*/ );
449  aHatchList.Insert(std::make_unique<XHatchEntry>(mpHatchItem->GetHatchValue(), aTmpStr));
450  aHatchList.SetDirty( false );
451  const BitmapEx & aBmp = aHatchList.GetUiBitmap( 0 );
452 
453  if( !aBmp.IsEmpty() )
454  {
456  const Size aBmpSize(aBmp.GetSizePixel());
457  pVD->SetOutputSizePixel(aBmpSize, false);
458  pVD->DrawBitmapEx(Point(), aBmp);
459  mpLbFillAttr->append("", aHatchList.GetHatch(0)->GetName(), *pVD);
461  }
462  }
463  }
464  else
465  {
467  }
468  }
469  else
470  {
472  }
473  break;
474  }
475  case drawing::FillStyle_BITMAP:
476  {
477  mpLbFillAttr->show();
478  mpToolBoxColor->hide();
480 
481  if(pSh && pSh->GetItem(SID_BITMAP_LIST))
482  {
484  mpLbFillAttr->clear();
485  SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
486 
487  if(mpBitmapItem)
488  {
489  const OUString aString(mpBitmapItem->GetName());
490 
491  mpLbFillAttr->set_active_text(aString);
492 
493  // Check if the entry is not in the list
494  if (mpLbFillAttr->get_active_text() != aString)
495  {
496  sal_Int32 nCount = mpLbFillAttr->get_count();
497  OUString aTmpStr;
498  if( nCount > 0 )
499  {
500  // Last entry gets tested against temporary entry
501  aTmpStr = mpLbFillAttr->get_text(nCount - 1);
502  if( aTmpStr.startsWith(TMP_STR_BEGIN) &&
503  aTmpStr.endsWith(TMP_STR_END) )
504  {
505  mpLbFillAttr->remove(nCount - 1);
506  }
507  }
508  aTmpStr = TMP_STR_BEGIN + aString + TMP_STR_END;
509 
510  XBitmapListRef xBitmapList =
513  XPropertyListType::Bitmap, "TmpList", ""/*TODO?*/));
514  xBitmapList->Insert(std::make_unique<XBitmapEntry>(mpBitmapItem->GetGraphicObject(), aTmpStr));
515  xBitmapList->SetDirty( false );
516  SvxFillAttrBox::Fill(*mpLbFillAttr, xBitmapList);
518  }
519 
520  }
521  else
522  {
524  }
525  }
526  else
527  {
529  }
530  break;
531  }
532  default:
533  OSL_ENSURE(false, "Non supported FillType (!)");
534  break;
535  }
536  }
537 
538 }
539 
541 {
542  if(GetSlotId() == SID_ATTR_FILL_STYLE)
543  {
545 
549 
550  mpLbFillType->connect_changed(LINK(this,SvxFillToolBoxControl,SelectFillTypeHdl));
551  mpLbFillAttr->connect_changed(LINK(this,SvxFillToolBoxControl,SelectFillAttrHdl));
552 
553 
554  return mxFillControl;
555  }
556  return VclPtr<vcl::Window>();
557 }
558 
559 FillControl::FillControl(vcl::Window* pParent, const css::uno::Reference<css::frame::XFrame>& rFrame)
560  : InterimItemWindow(pParent, "svx/ui/fillctrlbox.ui", "FillCtrlBox")
561  , mxLbFillType(m_xBuilder->weld_combo_box("type"))
562  , mxToolBoxColor(m_xBuilder->weld_toolbar("color"))
563  , mxColorDispatch(new ToolbarUnoDispatcher(*mxToolBoxColor, *m_xBuilder, rFrame))
564  , mxLbFillAttr(m_xBuilder->weld_combo_box("attr"))
565  , mnTypeCurPos(0)
566  , mnAttrCurPos(0)
567 {
568  mxLbFillAttr->connect_key_press(LINK(this, FillControl, AttrKeyInputHdl));
569  mxLbFillType->connect_key_press(LINK(this, FillControl, TypeKeyInputHdl));
570  mxToolBoxColor->connect_key_press(LINK(this, FillControl, ColorKeyInputHdl));
571 
572  mxLbFillType->connect_get_property_tree(LINK(this, FillControl, DumpAsPropertyTreeHdl));
573 
574  mxLbFillType->connect_focus_in(LINK(this, FillControl, TypeFocusHdl));
575  mxLbFillAttr->connect_focus_in(LINK(this, FillControl, AttrFocusHdl));
576 
578 
579  SetOptimalSize();
580 }
581 
582 IMPL_STATIC_LINK(FillControl, DumpAsPropertyTreeHdl, boost::property_tree::ptree&, rTree, void)
583 {
584  rTree.put("command", ".uno:FillStyle");
585 }
586 
588 {
590  if (pCurSh)
591  {
592  vcl::Window* pShellWnd = pCurSh->GetWindow();
593  if (pShellWnd)
594  pShellWnd->GrabFocus();
595  }
596 }
597 
598 IMPL_LINK(FillControl, TypeKeyInputHdl, const KeyEvent&, rKEvt, bool)
599 {
600  const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
601  sal_uInt16 nCode = rKeyCode.GetCode();
602 
603  if (nCode == KEY_ESCAPE)
604  {
605  mxLbFillType->set_active(mnTypeCurPos);
606  ReleaseFocus_Impl();
607  return true;
608  }
609 
610  if (nCode != KEY_TAB)
611  return false;
612  if (rKeyCode.IsShift())
613  return ChildKeyInput(rKEvt);
614  if (mxLbFillAttr->get_visible() && !mxLbFillAttr->get_sensitive())
615  return ChildKeyInput(rKEvt);
616  return false;
617 }
618 
620 {
621  mnTypeCurPos = mxLbFillType->get_active();
622 }
623 
625 {
626  mnAttrCurPos = mxLbFillAttr->get_active();
627 }
628 
629 IMPL_LINK(FillControl, AttrKeyInputHdl, const KeyEvent&, rKEvt, bool)
630 {
631  const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
632  sal_uInt16 nCode = rKeyCode.GetCode();
633 
634  if (nCode == KEY_ESCAPE)
635  {
636  mxLbFillAttr->set_active(mnAttrCurPos);
637  ReleaseFocus_Impl();
638  return true;
639  }
640 
641  return ChildKeyInput(rKEvt);
642 }
643 
644 IMPL_LINK(FillControl, ColorKeyInputHdl, const KeyEvent&, rKEvt, bool)
645 {
646  return ChildKeyInput(rKEvt);
647 }
648 
650 {
651  if (mxLbFillType)
652  mxLbFillType->grab_focus();
654 }
655 
657 {
658  disposeOnce();
659 }
660 
662 {
663  mxLbFillAttr.reset();
664  mxColorDispatch.reset();
665  mxToolBoxColor.reset();
666  mxLbFillType.reset();
668 }
669 
671 {
672  const drawing::FillStyle eXFS = static_cast<drawing::FillStyle>(mpLbFillType->get_active());
673 
674  if(meLastXFS != eXFS)
675  {
676  mpLbFillAttr->clear();
678  const XFillStyleItem aXFillStyleItem(eXFS);
679 
680  // #i122676# Do no longer trigger two Execute calls, one for SID_ATTR_FILL_STYLE
681  // and one for setting the fill attribute itself, but add two SfxPoolItems to the
682  // call to get just one action at the SdrObject and to create only one Undo action, too.
683  // Checked that this works in all apps.
684  switch( eXFS )
685  {
686  default:
687  case drawing::FillStyle_NONE:
688  {
689  mpLbFillAttr->show();
690  mpToolBoxColor->hide();
691  mpLbFillAttr->set_sensitive(false);
692 
693  // #i122676# need to call a single SID_ATTR_FILL_STYLE change
695  SID_ATTR_FILL_STYLE, SfxCallMode::RECORD,
696  { &aXFillStyleItem });
697  break;
698  }
699  case drawing::FillStyle_SOLID:
700  {
701  mpLbFillAttr->hide();
702  mpToolBoxColor->show();
703  const OUString aTmpStr;
704  const ::Color aColor = mpColorItem->GetColorValue();
705  const XFillColorItem aXFillColorItem( aTmpStr, aColor );
706 
707  // #i122676# change FillStyle and Color in one call
709  SID_ATTR_FILL_COLOR, SfxCallMode::RECORD,
710  { &aXFillColorItem, &aXFillStyleItem });
711  break;
712  }
713  case drawing::FillStyle_GRADIENT:
714  {
715  mpLbFillAttr->show();
716  mpToolBoxColor->hide();
717 
718  if(pSh && pSh->GetItem(SID_GRADIENT_LIST))
719  {
720  if(!mpLbFillAttr->get_count())
721  {
722  mpLbFillAttr->set_sensitive(true);
723  mpLbFillAttr->clear();
724  SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
725  }
726 
727  if (mnLastPosGradient != -1)
728  {
729  const SvxGradientListItem * pItem = pSh->GetItem(SID_GRADIENT_LIST);
730 
731  if(mnLastPosGradient < pItem->GetGradientList()->Count())
732  {
733  const XGradient aGradient = pItem->GetGradientList()->GetGradient(mnLastPosGradient)->GetGradient();
734  const XFillGradientItem aXFillGradientItem(mpLbFillAttr->get_text(mnLastPosGradient), aGradient);
735 
736  // #i122676# change FillStyle and Gradient in one call
738  SID_ATTR_FILL_GRADIENT, SfxCallMode::RECORD,
739  { &aXFillGradientItem, &aXFillStyleItem });
740  mpLbFillAttr->set_active(mnLastPosGradient);
741  }
742  }
743  }
744  else
745  {
746  mpLbFillAttr->set_sensitive(false);
747  }
748  break;
749  }
750  case drawing::FillStyle_HATCH:
751  {
752  mpLbFillAttr->show();
753  mpToolBoxColor->hide();
754 
755  if(pSh && pSh->GetItem(SID_HATCH_LIST))
756  {
757  if(!mpLbFillAttr->get_count())
758  {
759  mpLbFillAttr->set_sensitive(true);
760  mpLbFillAttr->clear();
761  SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
762  }
763 
764  if (mnLastPosHatch != -1)
765  {
766  const SvxHatchListItem * pItem = pSh->GetItem(SID_HATCH_LIST);
767 
768  if(mnLastPosHatch < pItem->GetHatchList()->Count())
769  {
770  const XHatch aHatch = pItem->GetHatchList()->GetHatch(mnLastPosHatch)->GetHatch();
771  const XFillHatchItem aXFillHatchItem(mpLbFillAttr->get_active_text(), aHatch);
772 
773  // #i122676# change FillStyle and Hatch in one call
775  SID_ATTR_FILL_HATCH, SfxCallMode::RECORD,
776  { &aXFillHatchItem, &aXFillStyleItem });
777  mpLbFillAttr->set_active(mnLastPosHatch);
778  }
779  }
780  }
781  else
782  {
783  mpLbFillAttr->set_sensitive(false);
784  }
785  break;
786  }
787  case drawing::FillStyle_BITMAP:
788  {
789  mpLbFillAttr->show();
790  mpToolBoxColor->hide();
791 
792  if(pSh && pSh->GetItem(SID_BITMAP_LIST))
793  {
794  if(!mpLbFillAttr->get_count())
795  {
796  mpLbFillAttr->set_sensitive(true);
797  mpLbFillAttr->clear();
798  SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
799  }
800 
801  if (mnLastPosBitmap != -1)
802  {
803  const SvxBitmapListItem * pItem = pSh->GetItem(SID_BITMAP_LIST);
804 
805  if(mnLastPosBitmap < pItem->GetBitmapList()->Count())
806  {
807  const XBitmapEntry* pXBitmapEntry = pItem->GetBitmapList()->GetBitmap(mnLastPosBitmap);
808  const XFillBitmapItem aXFillBitmapItem(mpLbFillAttr->get_active_text(), pXBitmapEntry->GetGraphicObject());
809 
810  // #i122676# change FillStyle and Bitmap in one call
812  SID_ATTR_FILL_BITMAP, SfxCallMode::RECORD,
813  { &aXFillBitmapItem, &aXFillStyleItem });
814  mpLbFillAttr->set_active(mnLastPosBitmap);
815  }
816  }
817  }
818  else
819  {
820  mpLbFillAttr->set_sensitive(false);
821  }
822  break;
823  }
824  }
825 
826  meLastXFS = eXFS;
827 
828  mxFillControl->Resize();
829  }
830 }
831 
833 {
834  const drawing::FillStyle eXFS = static_cast<drawing::FillStyle>(mpLbFillType->get_active());
835  const XFillStyleItem aXFillStyleItem(eXFS);
837 
838  // #i122676# dependent from bFillStyleChange, do execute a single or two
839  // changes in one Execute call
840  const bool bFillStyleChange(meLastXFS != eXFS);
841 
842  switch(eXFS)
843  {
844  case drawing::FillStyle_SOLID:
845  {
846  if(bFillStyleChange)
847  {
848  // #i122676# Single FillStyle change call needed here
850  SID_ATTR_FILL_STYLE, SfxCallMode::RECORD,
851  { &aXFillStyleItem });
852  }
853  break;
854  }
855  case drawing::FillStyle_GRADIENT:
856  {
857  sal_Int32 nPos = mpLbFillAttr->get_active();
858 
859  if (nPos == -1)
860  {
861  nPos = mnLastPosGradient;
862  }
863 
864  if (nPos != -1 && pSh && pSh->GetItem(SID_GRADIENT_LIST))
865  {
866  const SvxGradientListItem * pItem = pSh->GetItem(SID_GRADIENT_LIST);
867 
868  if(nPos < pItem->GetGradientList()->Count())
869  {
870  const XGradient aGradient = pItem->GetGradientList()->GetGradient(nPos)->GetGradient();
871  const XFillGradientItem aXFillGradientItem(mpLbFillAttr->get_active_text(), aGradient);
872 
873  // #i122676# Change FillStyle and Gradient in one call
875  SID_ATTR_FILL_GRADIENT, SfxCallMode::RECORD,
876  bFillStyleChange
877  ? std::initializer_list<SfxPoolItem const*>{ &aXFillGradientItem, &aXFillStyleItem }
878  : std::initializer_list<SfxPoolItem const*>{ &aXFillGradientItem });
879  }
880  }
881 
882  if (nPos != -1)
883  {
884  mnLastPosGradient = nPos;
885  }
886  break;
887  }
888  case drawing::FillStyle_HATCH:
889  {
890  sal_Int32 nPos = mpLbFillAttr->get_active();
891 
892  if (nPos == -1)
893  {
894  nPos = mnLastPosHatch;
895  }
896 
897  if (nPos != -1 && pSh && pSh->GetItem(SID_HATCH_LIST))
898  {
899  const SvxHatchListItem * pItem = pSh->GetItem(SID_HATCH_LIST);
900 
901  if(nPos < pItem->GetHatchList()->Count())
902  {
903  const XHatch aHatch = pItem->GetHatchList()->GetHatch(nPos)->GetHatch();
904  const XFillHatchItem aXFillHatchItem( mpLbFillAttr->get_active_text(), aHatch);
905 
906  // #i122676# Change FillStyle and Hatch in one call
908  SID_ATTR_FILL_HATCH, SfxCallMode::RECORD,
909  bFillStyleChange
910  ? std::initializer_list<SfxPoolItem const*>{ &aXFillHatchItem, &aXFillStyleItem }
911  : std::initializer_list<SfxPoolItem const*>{ &aXFillHatchItem });
912  }
913  }
914 
915  if (nPos != -1)
916  {
917  mnLastPosHatch = nPos;
918  }
919  break;
920  }
921  case drawing::FillStyle_BITMAP:
922  {
923  sal_Int32 nPos = mpLbFillAttr->get_active();
924 
925  if (nPos == -1)
926  {
927  nPos = mnLastPosBitmap;
928  }
929 
930  if (nPos != -1 && pSh && pSh->GetItem(SID_BITMAP_LIST))
931  {
932  const SvxBitmapListItem * pItem = pSh->GetItem(SID_BITMAP_LIST);
933 
934  if(nPos < pItem->GetBitmapList()->Count())
935  {
936  const XBitmapEntry* pXBitmapEntry = pItem->GetBitmapList()->GetBitmap(nPos);
937  const XFillBitmapItem aXFillBitmapItem(mpLbFillAttr->get_active_text(), pXBitmapEntry->GetGraphicObject());
938 
939  // #i122676# Change FillStyle and Bitmap in one call
941  SID_ATTR_FILL_BITMAP, SfxCallMode::RECORD,
942  bFillStyleChange
943  ? std::initializer_list<SfxPoolItem const*>{ &aXFillBitmapItem, &aXFillStyleItem }
944  : std::initializer_list<SfxPoolItem const*>{ &aXFillBitmapItem });
945  }
946  }
947 
948  if (nPos != -1)
949  {
950  mnLastPosBitmap = nPos;
951  }
952  break;
953  }
954  default: break;
955  }
956 }
957 
959 {
960  Size aSize(mxLbFillType->get_preferred_size());
961  Size aFirstSize(mxToolBoxColor->get_preferred_size());
962  auto nWidth = std::max(aFirstSize.Width(), LogicToPixel(Size(55, 0), MapMode(MapUnit::MapAppFont)).Width());
963  auto nHeight = std::max(aSize.Height(), aFirstSize.Height());
964  mxToolBoxColor->set_size_request(nWidth, -1);
965  mxLbFillAttr->set_size_request(42, -1); //something narrow so the toolbar sets the overall size of this column
966  SetSizePixel(Size(m_xContainer->get_preferred_size().Width(), nHeight));
967 }
968 
970 {
971  if((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
972  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))
973  {
974  SetOptimalSize();
975  }
976  InterimItemWindow::DataChanged(rDCEvt);
977 }
978 
979 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~FillControl() override
Definition: fillctrl.cxx:656
virtual void dispose() override
Definition: fillctrl.cxx:661
XPropertyEntry * Get(long nIndex) const
Definition: xtable.cxx:131
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
std::unique_ptr< XFillBitmapItem > mpBitmapItem
Definition: fillctrl.hxx:50
virtual void hide()=0
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
IMPL_STATIC_LINK(FillControl, DumpAsPropertyTreeHdl, boost::property_tree::ptree &, rTree, void)
Definition: fillctrl.cxx:582
SVX_DLLPUBLIC void Fill(weld::ComboBox &, const XHatchListRef &pList)
Definition: itemwin.cxx:245
SfxDispatcher * GetDispatcher()
virtual OUString get_text(int pos) const =0
static XBitmapListRef AsBitmapList(rtl::Reference< XPropertyList > const &plist)
Definition: xtable.hxx:389
std::unique_ptr< XFillColorItem > mpColorItem
Definition: fillctrl.hxx:47
css::uno::Reference< css::lang::XComponent > m_xFrame
std::unique_ptr< XFillGradientItem > mpFillGradientItem
Definition: fillctrl.hxx:48
const XGradientListRef & GetGradientList() const
Definition: drawitem.hxx:73
sal_uInt16 GetCode() const
DataChangedEventType GetType() const
IMPL_LINK_NOARG(FillControl, TypeFocusHdl, weld::Widget &, void)
Definition: fillctrl.cxx:619
static SfxObjectShell * Current()
void append(const OUString &rId, const OUString &rStr)
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: fillctrl.cxx:86
css::drawing::FillStyle meLastXFS
Definition: fillctrl.hxx:57
virtual int get_count() const =0
void Insert(std::unique_ptr< XPropertyEntry > pEntry, long nIndex=std::numeric_limits< long >::max())
Definition: xtable.cxx:177
virtual void show()=0
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: fillctrl.cxx:969
FillControl(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rFrame)
Definition: fillctrl.cxx:559
int nCount
virtual void GetFocus() override
AllSettingsFlags GetFlags() const
static SfxViewShell * Current()
IMPL_LINK(FillControl, TypeKeyInputHdl, const KeyEvent &, rKEvt, bool)
Definition: fillctrl.cxx:598
virtual void Resize() override
sal_uInt16 nCode
const GraphicObject & GetGraphicObject() const
Definition: xtable.hxx:125
const OUString & GetName() const
const XHatchListRef & GetHatchList() const
Definition: drawitem.hxx:97
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
bool IsEmpty() const
std::unique_ptr< weld::ComboBox > mxLbFillAttr
Definition: fillctrl.hxx:84
virtual ~SvxFillToolBoxControl() override
Definition: fillctrl.cxx:82
void set_active_text(const OUString &rStr)
SVX_DLLPUBLIC void Fill(weld::ComboBox &rListBox)
Definition: itemwin.cxx:175
static void ReleaseFocus_Impl()
Definition: fillctrl.cxx:587
void SetOptimalSize()
Definition: fillctrl.cxx:958
void connect_changed(const Link< ComboBox &, void > &rLink)
#define TMP_STR_END
Definition: fillctrl.cxx:31
Count
SvxFillToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: fillctrl.cxx:53
XHatchEntry * GetHatch(long nIndex) const
Definition: xtabhtch.cxx:52
static XPropertyListRef CreatePropertyList(XPropertyListType t, const OUString &rPath, const OUString &rReferer)
Definition: xtable.cxx:315
std::unique_ptr< XFillHatchItem > mpHatchItem
Definition: fillctrl.hxx:49
virtual void set_active(int pos)=0
VclPtr< FillControl > mxFillControl
Definition: fillctrl.hxx:52
virtual void clear()=0
virtual void GetFocus() override
Definition: fillctrl.cxx:649
weld::ComboBox * mpLbFillType
Definition: fillctrl.hxx:53
void GrabFocus()
void SetDirty(bool bDirty)
Definition: xtable.hxx:192
const XBitmapListRef & GetBitmapList() const
Definition: drawitem.hxx:122
SFX_IMPL_TOOLBOX_CONTROL(SvxFillToolBoxControl, XFillStyleItem)
void reset(reference_type *pBody)
bool IsShift() const
static SfxViewFrame * Current()
SfxItemState
std::unique_ptr< weld::Container > m_xContainer
#define TMP_STR_BEGIN
Definition: fillctrl.cxx:30
weld::ComboBox * mpLbFillAttr
Definition: fillctrl.hxx:55
constexpr sal_uInt16 KEY_ESCAPE
virtual void dispose() override
unsigned short GetSlotId() const
vcl::Window * GetWindow() const
std::unique_ptr< XFillStyleItem > mpStyleItem
Definition: fillctrl.hxx:46
std::unique_ptr< ToolbarUnoDispatcher > mxColorDispatch
Definition: fillctrl.hxx:83
weld::Toolbar * mpToolBoxColor
Definition: fillctrl.hxx:54
virtual void remove(int pos)=0
std::unique_ptr< weld::Toolbar > mxToolBoxColor
Definition: fillctrl.hxx:82
BitmapEx GetUiBitmap(long nIndex) const
Definition: xtable.cxx:160
const Size & GetSizePixel() const
virtual VclPtr< vcl::Window > CreateItemWindow(vcl::Window *pParent) override
Definition: fillctrl.cxx:540
std::unique_ptr< weld::ComboBox > mxLbFillType
Definition: fillctrl.hxx:81
virtual XFillStyleItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: xattr.cxx:1743
sal_uInt16 nPos
virtual void set_sensitive(bool sensitive)=0
constexpr sal_uInt16 KEY_TAB
virtual OUString get_active_text() const =0