LibreOffice Module svx (master)  1
tbcontrl.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 <typeinfo>
21 #include <utility>
22 
25 #include <tools/color.hxx>
26 #include <svl/poolitem.hxx>
27 #include <svl/itemset.hxx>
29 #include <vcl/event.hxx>
30 #include <vcl/toolbox.hxx>
31 #include <vcl/customweld.hxx>
32 #include <vcl/vclptr.hxx>
33 #include <vcl/weldutils.hxx>
34 #include <svtools/valueset.hxx>
35 #include <svtools/ctrlbox.hxx>
36 #include <svl/style.hxx>
37 #include <svtools/ctrltool.hxx>
38 #include <svtools/borderhelper.hxx>
40 #include <sfx2/tplpitem.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vcl/settings.hxx>
46 #include <vcl/virdev.hxx>
47 #include <com/sun/star/awt/FontDescriptor.hpp>
48 #include <com/sun/star/table/BorderLine2.hpp>
49 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
50 #include <com/sun/star/lang/XServiceInfo.hpp>
51 #include <com/sun/star/beans/XPropertySet.hpp>
52 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
53 #include <com/sun/star/frame/XDispatchProvider.hpp>
54 #include <com/sun/star/frame/XFrame.hpp>
55 #include <svx/strings.hrc>
56 #include <svx/svxids.hrc>
57 #include <helpids.h>
58 #include <sfx2/sidebar/Sidebar.hxx>
60 #include <svx/xtable.hxx>
61 #include <editeng/editids.hrc>
62 #include <editeng/fontitem.hxx>
63 #include <editeng/fhgtitem.hxx>
64 #include <editeng/boxitem.hxx>
66 #include <editeng/contouritem.hxx>
67 #include <editeng/colritem.hxx>
70 #include <editeng/flstitem.hxx>
71 #include <editeng/lineitem.hxx>
72 #include <editeng/postitem.hxx>
73 #include <editeng/shdditem.hxx>
74 #include <editeng/udlnitem.hxx>
75 #include <editeng/wghtitem.hxx>
76 #include <editeng/svxfont.hxx>
77 #include <editeng/cmapitem.hxx>
78 #include <svx/colorwindow.hxx>
79 #include <svx/colorbox.hxx>
80 #include <svx/tbcontrl.hxx>
81 #include <svx/dialmgr.hxx>
82 #include <svx/PaletteManager.hxx>
83 #include <memory>
84 
85 #include <tbxcolorupdate.hxx>
86 #include <editeng/eerdll.hxx>
87 #include <editeng/editrids.hrc>
88 #include <svx/xdef.hxx>
89 #include <svx/xfillit0.hxx>
90 #include <svx/xflclit.hxx>
91 #include <svl/currencytable.hxx>
92 #include <svtools/langtab.hxx>
93 #include <cppu/unotype.hxx>
95 #include <officecfg/Office/Common.hxx>
96 #include <o3tl/safeint.hxx>
97 #include <o3tl/typed_flags_set.hxx>
98 #include <bitmaps.hlst>
99 #include <sal/log.hxx>
101 
102 #include <comphelper/lok.hxx>
103 #include <tools/json_writer.hxx>
104 
105 #define MAX_MRU_FONTNAME_ENTRIES 5
106 
107 #define COMBO_WIDTH_IN_CHARS 18
108 
109 // namespaces
110 using namespace ::editeng;
111 using namespace ::com::sun::star;
112 using namespace ::com::sun::star::uno;
113 using namespace ::com::sun::star::frame;
114 using namespace ::com::sun::star::beans;
115 using namespace ::com::sun::star::lang;
116 
117 namespace
118 {
119 class SvxStyleBox_Base
120 {
121 public:
122  SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget, const OUString& rCommand, SfxStyleFamily eFamily,
123  const Reference<XDispatchProvider>& rDispatchProvider,
124  const Reference<XFrame>& _xFrame,const OUString& rClearFormatKey,
125  const OUString& rMoreKey, bool bInSpecialMode, SvxStyleToolBoxControl& rCtrl);
126 
127  virtual ~SvxStyleBox_Base()
128  {
129  }
130 
131  void SetFamily( SfxStyleFamily eNewFamily );
132 
133  void SetDefaultStyle( const OUString& rDefault ) { sDefaultStyle = rDefault; }
134 
135  int get_count() const { return m_xWidget->get_count(); }
136  OUString get_text(int nIndex) const { return m_xWidget->get_text(nIndex); }
137  OUString get_active_text() const { return m_xWidget->get_active_text(); }
138 
139  void append_text(const OUString& rStr)
140  {
141  OUString sId(OUString::number(m_xWidget->get_count()));
142  m_xWidget->append(sId, rStr);
143  }
144 
145  void insert_separator(int pos, const OUString& rId)
146  {
147  m_xWidget->insert_separator(pos, rId);
148  }
149 
150  virtual void set_sensitive(bool bSensitive)
151  {
152  m_xWidget->set_sensitive(bSensitive);
153  }
154 
155  void set_active_or_entry_text(const OUString& rText)
156  {
157  const int nFound = m_xWidget->find_text(rText);
158  if (nFound != -1)
159  m_xWidget->set_active(nFound);
160  else
161  m_xWidget->set_entry_text(rText);
162  }
163 
164  void set_active(int nActive)
165  {
166  m_xWidget->set_active(nActive);
167  }
168 
169  void freeze()
170  {
171  m_xWidget->freeze();
172  }
173 
174  void save_value()
175  {
176  m_xWidget->save_value();
177  }
178 
179  void clear()
180  {
181  m_xWidget->clear();
182  m_nMaxUserDrawFontWidth = 0;
183  }
184 
185  void thaw()
186  {
187  m_xWidget->thaw();
188  }
189 
190  virtual bool DoKeyInput(const KeyEvent& rKEvt);
191 
192 private:
193  DECL_LINK(SelectHdl, weld::ComboBox&, void);
194  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
195  DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
196  DECL_LINK(FocusOutHdl, weld::Widget&, void);
197  DECL_LINK(DumpAsPropertyTreeHdl, tools::JsonWriter&, void);
198  DECL_LINK(CustomRenderHdl, weld::ComboBox::render_args, void);
199  DECL_LINK(CustomGetSizeHdl, OutputDevice&, Size);
200 
202  void CalcOptimalExtraUserWidth(vcl::RenderContext& rRenderContext);
203 
204  void Select(bool bNonTravelSelect);
205 
206 protected:
207  SvxStyleToolBoxControl& m_rCtrl;
208 
209  std::unique_ptr<weld::Builder> m_xMenuBuilder;
210  std::unique_ptr<weld::Menu> m_xMenu;
211  std::unique_ptr<weld::ComboBox> m_xWidget;
212 
213  SfxStyleFamily eStyleFamily;
214  int m_nMaxUserDrawFontWidth;
215  bool bRelease;
216  Reference< XDispatchProvider > m_xDispatchProvider;
217  Reference< XFrame > m_xFrame;
218  OUString m_aCommand;
219  OUString aClearFormatKey;
220  OUString aMoreKey;
221  OUString sDefaultStyle;
222  bool bInSpecialMode;
223 
224  void ReleaseFocus();
225  static Color TestColorsVisible(const Color &FontCol, const Color &BackCol);
226  static void UserDrawEntry(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const OUString &rStyleName);
227  void SetupEntry(vcl::RenderContext& rRenderContext, sal_Int32 nItem, const tools::Rectangle& rRect, const OUString& rStyleName, bool bIsNotSelected);
228  static bool AdjustFontForItemHeight(OutputDevice& rDevice, tools::Rectangle const & rTextRect, long nHeight);
229  DECL_LINK(MenuSelectHdl, const OString&, void);
230  DECL_STATIC_LINK(SvxStyleBox_Base, ShowMoreHdl, void*, void);
231 };
232 
233 class SvxStyleBox_Impl final : public InterimItemWindow
234  , public SvxStyleBox_Base
235 {
236 public:
237  SvxStyleBox_Impl(vcl::Window* pParent, const OUString& rCommand, SfxStyleFamily eFamily, const Reference< XDispatchProvider >& rDispatchProvider,
238  const Reference< XFrame >& _xFrame,const OUString& rClearFormatKey, const OUString& rMoreKey, bool bInSpecialMode, SvxStyleToolBoxControl& rCtrl);
239 
240  virtual ~SvxStyleBox_Impl() override
241  {
242  disposeOnce();
243  }
244 
245  virtual void dispose() override
246  {
247  m_xWidget.reset();
248  m_xMenu.reset();
249  m_xMenuBuilder.reset();
251  }
252 
253  virtual bool DoKeyInput(const KeyEvent& rKEvt) override;
254 
255 private:
256 
257  virtual void set_sensitive(bool bSensitive) override
258  {
259  m_xWidget->set_sensitive(bSensitive);
260  if (bSensitive)
262  else
264  }
265 
266  virtual void DataChanged(const DataChangedEvent& rDCEvt) override;
267  void SetOptimalSize();
268 };
269 
270 class SvxFontNameBox_Impl;
271 class SvxFontNameBox_Base;
272 
273 class SvxFontNameToolBoxControl final : public cppu::ImplInheritanceHelper<svt::ToolboxController,
274  css::lang::XServiceInfo>
275 {
276 public:
277  SvxFontNameToolBoxControl();
278 
279  // XStatusListener
280  virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
281 
282  // XToolbarController
283  virtual css::uno::Reference<css::awt::XWindow> SAL_CALL createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent) override;
284 
285  // XComponent
286  virtual void SAL_CALL dispose() override;
287 
288  // XServiceInfo
289  virtual OUString SAL_CALL getImplementationName() override;
290  virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override;
291  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
292 
293 private:
294  VclPtr<SvxFontNameBox_Impl> m_xVclBox;
295  std::unique_ptr<SvxFontNameBox_Base> m_xWeldBox;
296  SvxFontNameBox_Base* m_pBox;
297 };
298 
299 class FontOptionsListener final : public comphelper::ConfigurationListenerProperty<bool>
300 {
301 private:
302  SvxFontNameBox_Base& m_rBox;
303 
304  virtual void setProperty(const css::uno::Any &rProperty) override;
305 public:
306  FontOptionsListener(const rtl::Reference<comphelper::ConfigurationListener>& rListener, const OUString& rProp, SvxFontNameBox_Base& rBox)
308  , m_rBox(rBox)
309  {
310  }
311 };
312 
313 class SvxFontNameBox_Base
314 {
315 private:
317  FontOptionsListener m_aWYSIWYG;
318  FontOptionsListener m_aHistory;
319 
320 protected:
321  SvxFontNameToolBoxControl& m_rCtrl;
322 
323  std::unique_ptr<FontNameBox> m_xWidget;
324  const FontList* pFontList;
325  ::std::unique_ptr<FontList> m_aOwnFontList;
326  vcl::Font aCurFont;
327  sal_uInt16 nFtCount;
328  bool bRelease;
329  Reference< XDispatchProvider > m_xDispatchProvider;
330  Reference< XFrame > m_xFrame;
331  bool mbCheckingUnknownFont;
332 
333  void ReleaseFocus_Impl();
334 
335  void Select(bool bNonTravelSelect);
336 
337  void EndPreview()
338  {
339  Sequence< PropertyValue > aArgs;
340  SfxToolBoxControl::Dispatch( m_xDispatchProvider,
341  ".uno:CharEndPreviewFontName",
342  aArgs );
343  }
344  void CheckAndMarkUnknownFont();
345 
346 public:
347  SvxFontNameBox_Base(std::unique_ptr<weld::ComboBox> xWidget, const Reference<XDispatchProvider>& rDispatchProvider,
348  const Reference<XFrame>& rFrame, SvxFontNameToolBoxControl& rCtrl);
349  virtual ~SvxFontNameBox_Base()
350  {
351  m_xListener->dispose();
352  }
353 
354  void FillList();
355  void Update( const css::awt::FontDescriptor* pFontDesc );
356  sal_uInt16 GetListCount() const { return nFtCount; }
357  void Clear() { m_xWidget->clear(); nFtCount = 0; }
358  void Fill( const FontList* pList )
359  {
360  m_xWidget->Fill(pList);
361  nFtCount = pList->GetFontNameCount();
362  }
363 
364  void SetOwnFontList(::std::unique_ptr<FontList> && _aOwnFontList) { m_aOwnFontList = std::move(_aOwnFontList); }
365 
366  virtual void set_sensitive(bool bSensitive)
367  {
368  m_xWidget->set_sensitive(bSensitive);
369  }
370 
371  void set_active_or_entry_text(const OUString& rText);
372 
373  void statusChanged_Impl(const css::frame::FeatureStateEvent& rEvent);
374 
375  virtual bool DoKeyInput(const KeyEvent& rKEvt);
376 
377  void EnableControls();
378 
379  DECL_LINK(SelectHdl, weld::ComboBox&, void);
380  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
381  DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
382  DECL_LINK(FocusInHdl, weld::Widget&, void);
383  DECL_LINK(FocusOutHdl, weld::Widget&, void);
384  DECL_LINK(DumpAsPropertyTreeHdl, tools::JsonWriter&, void);
385 };
386 
387 void FontOptionsListener::setProperty(const css::uno::Any &rProperty)
388 {
390  m_rBox.EnableControls();
391 }
392 
393 class SvxFontNameBox_Impl final : public InterimItemWindow
394  , public SvxFontNameBox_Base
395 {
396 private:
397  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
398  virtual void GetFocus() override
399  {
400  if (m_xWidget)
401  m_xWidget->grab_focus();
403  }
404 
405  void SetOptimalSize();
406 
407  virtual bool DoKeyInput(const KeyEvent& rKEvt) override;
408 
409 public:
410  SvxFontNameBox_Impl(vcl::Window* pParent, const Reference<XDispatchProvider>& rDispatchProvider,
411  const Reference<XFrame>& rFrame, SvxFontNameToolBoxControl& rCtrl);
412 
413  virtual void dispose() override
414  {
415  m_xWidget.reset();
417  }
418 
419  virtual ~SvxFontNameBox_Impl() override
420  {
421  disposeOnce();
422  }
423 
424  virtual Reference< css::accessibility::XAccessible > CreateAccessible() override;
425 
426  virtual void set_sensitive(bool bSensitive) override
427  {
428  m_xWidget->set_sensitive(bSensitive);
429  if (bSensitive)
431  else
433  }
434 };
435 
436 
437 // SelectHdl needs the Modifiers, get them in MouseButtonUp
438 class SvxFrmValueSet_Impl final : public ValueSet
439 {
440 private:
441  sal_uInt16 nModifier;
442 
443  virtual bool MouseButtonUp(const MouseEvent& rMEvt) override
444  {
445  nModifier = rMEvt.GetModifier();
446  return ValueSet::MouseButtonUp(rMEvt);
447  }
448 
449 public:
450  SvxFrmValueSet_Impl()
451  : ValueSet(nullptr)
452  , nModifier(0)
453  {
454  }
455  sal_uInt16 GetModifier() const {return nModifier;}
456 };
457 
458 }
459 
460 namespace {
461 
462 class SvxFrameToolBoxControl;
463 
464 class SvxFrameWindow_Impl final : public WeldToolbarPopup
465 {
466 private:
468  std::unique_ptr<SvxFrmValueSet_Impl> mxFrameSet;
469  std::unique_ptr<weld::CustomWeld> mxFrameSetWin;
470  std::vector<BitmapEx> aImgVec;
471  bool bParagraphMode;
472 
473  void InitImageList();
474  void CalcSizeValueSet();
475  DECL_LINK( SelectHdl, ValueSet*, void );
476 
477 public:
478  SvxFrameWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent);
479  virtual void GrabFocus() override
480  {
481  mxFrameSet->GrabFocus();
482  }
483 
484  virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
485 };
486 
487 class SvxFrameToolBoxControl : public svt::PopupWindowController
488 {
489 public:
490  explicit SvxFrameToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rContext );
491 
492  // XInitialization
493  virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) override;
494 
495  // XServiceInfo
496  virtual OUString SAL_CALL getImplementationName() override;
497  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
498 
499  virtual void SAL_CALL execute(sal_Int16 nKeyModifier) override;
500 private:
501  virtual std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override;
502  virtual VclPtr<vcl::Window> createVclPopupWindow( vcl::Window* pParent ) override;
503 };
504 
505  class LineListBox final : public ValueSet
506  {
507  public:
508  typedef Color (*ColorFunc)(Color);
509  typedef Color (*ColorDistFunc)(Color, Color);
510 
511  LineListBox();
512 
514  Size SetWidth( long nWidth )
515  {
516  long nOldWidth = m_nWidth;
517  m_nWidth = nWidth;
518  return UpdateEntries( nOldWidth );
519  }
520 
521  void SetNone( const OUString& sNone )
522  {
523  m_sNone = sNone;
524  }
525 
527  void InsertEntry(const BorderWidthImpl& rWidthImpl,
528  SvxBorderLineStyle nStyle, long nMinWidth = 0,
529  ColorFunc pColor1Fn = &sameColor,
530  ColorFunc pColor2Fn = &sameColor,
531  ColorDistFunc pColorDistFn = &sameDistColor);
532 
533  SvxBorderLineStyle GetEntryStyle( sal_Int32 nPos ) const;
534 
535  SvxBorderLineStyle GetSelectEntryStyle() const;
536 
537  void SetSourceUnit( FieldUnit eNewUnit ) { eSourceUnit = eNewUnit; }
538 
539  const Color& GetColor() const { return aColor; }
540 
541  virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
542  private:
543 
544  void ImpGetLine(long nLine1, long nLine2, long nDistance,
545  Color nColor1, Color nColor2, Color nColorDist,
546  SvxBorderLineStyle nStyle, BitmapEx& rBmp);
547 
548  void UpdatePaintLineColor(); // returns sal_True if maPaintCol has changed
549 
550  Size UpdateEntries( long nOldWidth );
551  sal_Int32 GetStylePos( sal_Int32 nListPos, long nWidth );
552 
553  const Color& GetPaintColor() const
554  {
555  return maPaintCol;
556  }
557 
558  Color GetColorLine1( sal_Int32 nPos );
559  Color GetColorLine2( sal_Int32 nPos );
560  Color GetColorDist( sal_Int32 nPos );
561 
562  LineListBox( const LineListBox& ) = delete;
563  LineListBox& operator =( const LineListBox& ) = delete;
564 
565  std::vector<std::unique_ptr<ImpLineListData>> m_vLineList;
566  long m_nWidth;
567  OUString m_sNone;
569  Size aTxtSize;
570  Color const aColor;
571  Color maPaintCol;
572  FieldUnit eSourceUnit;
573  };
574 
575  SvxBorderLineStyle LineListBox::GetSelectEntryStyle() const
576  {
577  SvxBorderLineStyle nStyle = SvxBorderLineStyle::SOLID;
578  size_t nPos = GetSelectItemPos();
579  if (nPos != VALUESET_ITEM_NOTFOUND)
580  {
581  if (!m_sNone.isEmpty())
582  --nPos;
583  nStyle = GetEntryStyle( nPos );
584  }
585 
586  return nStyle;
587  }
588 
589  void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
590  Color aColor1, Color aColor2, Color aColorDist,
591  SvxBorderLineStyle nStyle, BitmapEx& rBmp )
592  {
593  auto nMinWidth = GetDrawingArea()->get_ref_device().approximate_digit_width() * COMBO_WIDTH_IN_CHARS;
594  Size aSize(nMinWidth, aTxtSize.Height());
595  aSize.AdjustWidth( -(aTxtSize.Width()) );
596  aSize.AdjustWidth( -6 );
597 
598  // SourceUnit to Twips
599  if ( eSourceUnit == FieldUnit::POINT )
600  {
601  nLine1 /= 5;
602  nLine2 /= 5;
603  nDistance /= 5;
604  }
605 
606  // Paint the lines
607  aSize = aVirDev->PixelToLogic( aSize );
608  long nPix = aVirDev->PixelToLogic( Size( 0, 1 ) ).Height();
609  sal_uInt32 n1 = nLine1;
610  sal_uInt32 n2 = nLine2;
611  long nDist = nDistance;
612  n1 += nPix-1;
613  n1 -= n1%nPix;
614  if ( n2 )
615  {
616  nDist += nPix-1;
617  nDist -= nDist%nPix;
618  n2 += nPix-1;
619  n2 -= n2%nPix;
620  }
621  long nVirHeight = n1+nDist+n2;
622  if ( nVirHeight > aSize.Height() )
623  aSize.setHeight( nVirHeight );
624  // negative width should not be drawn
625  if ( aSize.Width() <= 0 )
626  return;
627 
628  Size aVirSize = aVirDev->LogicToPixel( aSize );
629  if ( aVirDev->GetOutputSizePixel() != aVirSize )
630  aVirDev->SetOutputSizePixel( aVirSize );
631  aVirDev->SetFillColor( aColorDist );
632  aVirDev->DrawRect( tools::Rectangle( Point(), aSize ) );
633 
634  aVirDev->SetFillColor( aColor1 );
635 
636  double y1 = double( n1 ) / 2;
637  svtools::DrawLine( *aVirDev, basegfx::B2DPoint( 0, y1 ), basegfx::B2DPoint( aSize.Width( ), y1 ), n1, nStyle );
638 
639  if ( n2 )
640  {
641  double y2 = n1 + nDist + double( n2 ) / 2;
642  aVirDev->SetFillColor( aColor2 );
643  svtools::DrawLine( *aVirDev, basegfx::B2DPoint( 0, y2 ), basegfx::B2DPoint( aSize.Width(), y2 ), n2, SvxBorderLineStyle::SOLID );
644  }
645  rBmp = aVirDev->GetBitmapEx( Point(), Size( aSize.Width(), n1+nDist+n2 ) );
646  }
647 
648  LineListBox::LineListBox()
649  : ValueSet(nullptr)
650  , m_nWidth( 5 )
651  , m_sNone()
652  , aVirDev(VclPtr<VirtualDevice>::Create())
653  , aColor(COL_BLACK)
654  , maPaintCol(COL_BLACK)
655  , eSourceUnit(FieldUnit::POINT)
656  {
657  aVirDev->SetLineColor();
658  aVirDev->SetMapMode( MapMode( MapUnit::MapTwip ) );
659  }
660 
661  void LineListBox::SetDrawingArea(weld::DrawingArea* pDrawingArea)
662  {
663  ValueSet::SetDrawingArea(pDrawingArea);
664 
665  OutputDevice& rDevice = pDrawingArea->get_ref_device();
666 
667  aTxtSize.setWidth( rDevice.approximate_digit_width() );
668  aTxtSize.setHeight( rDevice.GetTextHeight() );
669 
670  UpdatePaintLineColor();
671  }
672 
673  sal_Int32 LineListBox::GetStylePos( sal_Int32 nListPos, long nWidth )
674  {
675  sal_Int32 nPos = -1;
676  if (!m_sNone.isEmpty())
677  nListPos--;
678 
679  sal_Int32 n = 0;
680  size_t i = 0;
681  size_t nCount = m_vLineList.size();
682  while ( nPos == -1 && i < nCount )
683  {
684  auto& pData = m_vLineList[ i ];
685  if ( pData->GetMinWidth() <= nWidth )
686  {
687  if ( nListPos == n )
688  nPos = static_cast<sal_Int32>(i);
689  n++;
690  }
691  i++;
692  }
693 
694  return nPos;
695  }
696 
697  void LineListBox::InsertEntry(
698  const BorderWidthImpl& rWidthImpl, SvxBorderLineStyle nStyle, long nMinWidth,
699  ColorFunc pColor1Fn, ColorFunc pColor2Fn, ColorDistFunc pColorDistFn )
700  {
701  m_vLineList.emplace_back(new ImpLineListData(
702  rWidthImpl, nStyle, nMinWidth, pColor1Fn, pColor2Fn, pColorDistFn));
703  }
704 
705  SvxBorderLineStyle LineListBox::GetEntryStyle( sal_Int32 nPos ) const
706  {
707  ImpLineListData* pData = (0 <= nPos && o3tl::make_unsigned(nPos) < m_vLineList.size()) ? m_vLineList[ nPos ].get() : nullptr;
708  return pData ? pData->GetStyle() : SvxBorderLineStyle::NONE;
709  }
710 
711  void LineListBox::UpdatePaintLineColor()
712  {
714  Color aNewCol( rSettings.GetWindowColor().IsDark()? rSettings.GetLabelTextColor() : aColor );
715 
716  bool bRet = aNewCol != maPaintCol;
717 
718  if( bRet )
719  maPaintCol = aNewCol;
720  }
721 
722  Size LineListBox::UpdateEntries( long nOldWidth )
723  {
724  Size aSize;
725 
726  UpdatePaintLineColor( );
727 
728  sal_Int32 nSelEntry = GetSelectItemPos();
729  sal_Int32 nTypePos = GetStylePos( nSelEntry, nOldWidth );
730 
731  // Remove the old entries
732  Clear();
733 
734  sal_uInt16 nId(1);
735 
736  // Add the new entries based on the defined width
737  if (!m_sNone.isEmpty())
738  InsertItem(nId++, Image(), m_sNone);
739 
740  sal_uInt16 n = 0;
741  sal_uInt16 nCount = m_vLineList.size( );
742  while ( n < nCount )
743  {
744  auto& pData = m_vLineList[ n ];
745  if ( pData->GetMinWidth() <= m_nWidth )
746  {
747  BitmapEx aBmp;
748  ImpGetLine( pData->GetLine1ForWidth( m_nWidth ),
749  pData->GetLine2ForWidth( m_nWidth ),
750  pData->GetDistForWidth( m_nWidth ),
751  GetColorLine1( GetItemCount( ) ),
752  GetColorLine2( GetItemCount( ) ),
753  GetColorDist( GetItemCount( ) ),
754  pData->GetStyle(), aBmp );
755  InsertItem(nId, Image(aBmp));
756  Size aBmpSize = aBmp.GetSizePixel();
757  if (aBmpSize.Width() > aSize.Width())
758  aSize.setWidth(aBmpSize.getWidth());
759  if (aBmpSize.Height() > aSize.Height())
760  aSize.setHeight(aBmpSize.getHeight());
761  if ( n == nTypePos )
762  SelectItem(nId);
763  }
764  else if ( n == nTypePos )
765  SetNoSelection();
766  n++;
767  ++nId;
768  }
769 
770  Invalidate();
771 
772  return aSize;
773  }
774 
775  Color LineListBox::GetColorLine1( sal_Int32 nPos )
776  {
777  sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
778  if (nStyle == -1)
779  return GetPaintColor( );
780  auto& pData = m_vLineList[ nStyle ];
781  return pData->GetColorLine1( GetColor( ) );
782  }
783 
784  Color LineListBox::GetColorLine2( sal_Int32 nPos )
785  {
786  sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
787  if (nStyle == -1)
788  return GetPaintColor( );
789  auto& pData = m_vLineList[ nStyle ];
790  return pData->GetColorLine2( GetColor( ) );
791  }
792 
793  Color LineListBox::GetColorDist( sal_Int32 nPos )
794  {
796 
797  sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
798  if (nStyle == -1)
799  return rResult;
800  auto& pData = m_vLineList[ nStyle ];
801  return pData->GetColorDist( GetColor( ), rResult );
802  }
803 }
804 
805 namespace {
806 
807 class SvxLineWindow_Impl final : public WeldToolbarPopup
808 {
809 private:
811  std::unique_ptr<LineListBox> m_xLineStyleLb;
812  std::unique_ptr<weld::CustomWeld> m_xLineStyleLbWin;
813  bool m_bIsWriter;
814 
815  DECL_LINK( SelectHdl, ValueSet*, void );
816 
817 public:
818  SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent);
819  virtual void GrabFocus() override
820  {
821  m_xLineStyleLb->GrabFocus();
822  }
823 };
824 
825 }
826 
828 
829 class SfxStyleControllerItem_Impl : public SfxStatusListener
830 {
831  public:
832  SfxStyleControllerItem_Impl( const Reference< XDispatchProvider >& rDispatchProvider,
833  sal_uInt16 nSlotId,
834  const OUString& rCommand,
835  SvxStyleToolBoxControl& rTbxCtl );
836 
837  protected:
838  virtual void StateChanged( SfxItemState eState, const SfxPoolItem* pState ) override;
839 
840  private:
842 };
843 
844 #define BUTTON_PADDING 10
845 #define ITEM_HEIGHT 30
846 
847 SvxStyleBox_Base::SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
848  const OUString& rCommand,
849  SfxStyleFamily eFamily,
850  const Reference< XDispatchProvider >& rDispatchProvider,
851  const Reference< XFrame >& _xFrame,
852  const OUString& rClearFormatKey,
853  const OUString& rMoreKey,
854  bool bInSpec, SvxStyleToolBoxControl& rCtrl)
855  : m_rCtrl(rCtrl)
856  , m_xMenuBuilder(Application::CreateBuilder(nullptr, "svx/ui/stylemenu.ui"))
857  , m_xMenu(m_xMenuBuilder->weld_menu("menu"))
858  , m_xWidget(std::move(xWidget))
859  , eStyleFamily( eFamily )
860  , m_nMaxUserDrawFontWidth(0)
861  , bRelease( true )
862  , m_xDispatchProvider( rDispatchProvider )
863  , m_xFrame(_xFrame)
864  , m_aCommand( rCommand )
865  , aClearFormatKey( rClearFormatKey )
866  , aMoreKey( rMoreKey )
867  , bInSpecialMode( bInSpec )
868 {
869  m_xWidget->connect_changed(LINK(this, SvxStyleBox_Base, SelectHdl));
870  m_xWidget->connect_key_press(LINK(this, SvxStyleBox_Base, KeyInputHdl));
871  m_xWidget->connect_entry_activate(LINK(this, SvxStyleBox_Base, ActivateHdl));
872  m_xWidget->connect_focus_out(LINK(this, SvxStyleBox_Base, FocusOutHdl));
873  m_xWidget->connect_get_property_tree(LINK(this, SvxStyleBox_Base, DumpAsPropertyTreeHdl));
874  m_xWidget->set_help_id(HID_STYLE_LISTBOX);
875  m_xWidget->set_entry_completion(true);
876  m_xMenu->connect_activate(LINK(this, SvxStyleBox_Base, MenuSelectHdl));
877 
878  m_xWidget->connect_custom_get_size(LINK(this, SvxStyleBox_Base, CustomGetSizeHdl));
879  m_xWidget->connect_custom_render(LINK(this, SvxStyleBox_Base, CustomRenderHdl));
880  m_xWidget->set_custom_renderer(true);
881 
882  m_xWidget->set_entry_width_chars(COMBO_WIDTH_IN_CHARS);
883 }
884 
885 IMPL_LINK(SvxStyleBox_Base, CustomGetSizeHdl, OutputDevice&, rArg, Size)
886 {
887  CalcOptimalExtraUserWidth(rArg);
888  return Size(m_nMaxUserDrawFontWidth, ITEM_HEIGHT);
889 }
890 
891 SvxStyleBox_Impl::SvxStyleBox_Impl(vcl::Window* pParent,
892  const OUString& rCommand,
893  SfxStyleFamily eFamily,
894  const Reference< XDispatchProvider >& rDispatchProvider,
895  const Reference< XFrame >& _xFrame,
896  const OUString& rClearFormatKey,
897  const OUString& rMoreKey,
898  bool bInSpec, SvxStyleToolBoxControl& rCtrl)
899  : InterimItemWindow(pParent, "svx/ui/applystylebox.ui", "ApplyStyleBox")
900  , SvxStyleBox_Base(m_xBuilder->weld_combo_box("applystyle"), rCommand, eFamily,
901  rDispatchProvider, _xFrame, rClearFormatKey, rMoreKey, bInSpec, rCtrl)
902 {
903  InitControlBase(m_xWidget.get());
904 
905  set_id("applystyle");
906  SetOptimalSize();
907 }
908 
909 void SvxStyleBox_Base::ReleaseFocus()
910 {
911  if ( !bRelease )
912  {
913  bRelease = true;
914  return;
915  }
916  if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
917  m_xFrame->getContainerWindow()->setFocus();
918 }
919 
920 IMPL_LINK(SvxStyleBox_Base, MenuSelectHdl, const OString&, rMenuIdent, void)
921 {
922  OUString sEntry = m_xWidget->get_active_text();
923 
924  ReleaseFocus(); // It must be after getting entry pos!
925  Sequence<PropertyValue> aArgs(2);
926  aArgs[0].Name = "Param";
927  aArgs[0].Value <<= sEntry;
928  aArgs[1].Name = "Family";
929  aArgs[1].Value <<= sal_Int16( eStyleFamily );
930 
931  if (rMenuIdent == "update")
932  {
933  SfxToolBoxControl::Dispatch( m_xDispatchProvider,
934  ".uno:StyleUpdateByExample", aArgs );
935  }
936  else if (rMenuIdent == "edit")
937  {
938  SfxToolBoxControl::Dispatch( m_xDispatchProvider,
939  ".uno:EditStyle", aArgs );
940  }
941 }
942 
943 IMPL_STATIC_LINK_NOARG(SvxStyleBox_Base, ShowMoreHdl, void*, void)
944 {
945  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
946  DBG_ASSERT( pViewFrm, "SvxStyleBox_Base::Select(): no viewframe" );
947  if (!pViewFrm)
948  return;
949  pViewFrm->ShowChildWindow(SID_SIDEBAR);
950  ::sfx2::sidebar::Sidebar::ShowPanel("StyleListPanel", pViewFrm->GetFrame().GetFrameInterface(), true);
951 }
952 
953 IMPL_LINK(SvxStyleBox_Base, SelectHdl, weld::ComboBox&, rCombo, void)
954 {
955  Select(rCombo.changed_by_direct_pick()); // only when picked from the list
956 }
957 
958 IMPL_LINK_NOARG(SvxStyleBox_Base, ActivateHdl, weld::ComboBox&, bool)
959 {
960  Select(true);
961  return true;
962 }
963 
964 void SvxStyleBox_Base::Select(bool bNonTravelSelect)
965 {
966  if (!bNonTravelSelect)
967  return;
968 
969  OUString aSearchEntry(m_xWidget->get_active_text());
970  bool bDoIt = true, bClear = false;
971  if( bInSpecialMode )
972  {
973  if( aSearchEntry == aClearFormatKey && m_xWidget->get_active() == 0 )
974  {
975  aSearchEntry = sDefaultStyle;
976  bClear = true;
977  //not only apply default style but also call 'ClearFormatting'
978  Sequence< PropertyValue > aEmptyVals;
979  SfxToolBoxControl::Dispatch( m_xDispatchProvider, ".uno:ResetAttributes",
980  aEmptyVals);
981  }
982  else if (aSearchEntry == aMoreKey && m_xWidget->get_active() == (m_xWidget->get_count() - 1))
983  {
984  Application::PostUserEvent(LINK(nullptr, SvxStyleBox_Base, ShowMoreHdl));
985  //tdf#113214 change text back to previous entry
986  set_active_or_entry_text(m_xWidget->get_saved_value());
987  bDoIt = false;
988  }
989  }
990 
991  //Do we need to create a new style?
993  SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool();
994  SfxStyleSheetBase* pStyle = nullptr;
995 
996  bool bCreateNew = false;
997 
998  if ( pPool )
999  {
1000  pStyle = pPool->First(eStyleFamily);
1001  while ( pStyle && pStyle->GetName() != aSearchEntry )
1002  pStyle = pPool->Next();
1003  }
1004 
1005  if ( !pStyle )
1006  {
1007  // cannot find the style for whatever reason
1008  // therefore create a new style
1009  bCreateNew = true;
1010  }
1011 
1012  /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
1013  This instance may be deleted in the meantime (i.e. when a dialog is opened
1014  while in Dispatch()), accessing members will crash in this case. */
1015  ReleaseFocus();
1016 
1017  if( bDoIt )
1018  {
1019  if ( bClear )
1020  set_active_or_entry_text(aSearchEntry);
1021  m_xWidget->save_value();
1022 
1023  Sequence< PropertyValue > aArgs( 2 );
1024  aArgs[0].Value <<= aSearchEntry;
1025  aArgs[1].Name = "Family";
1026  aArgs[1].Value <<= sal_Int16( eStyleFamily );
1027  if( bCreateNew )
1028  {
1029  aArgs[0].Name = "Param";
1030  SfxToolBoxControl::Dispatch( m_xDispatchProvider, ".uno:StyleNewByExample", aArgs);
1031  }
1032  else
1033  {
1034  aArgs[0].Name = "Template";
1035  SfxToolBoxControl::Dispatch( m_xDispatchProvider, m_aCommand, aArgs );
1036  }
1037  }
1038 }
1039 
1040 void SvxStyleBox_Base::SetFamily( SfxStyleFamily eNewFamily )
1041 {
1042  eStyleFamily = eNewFamily;
1043 }
1044 
1045 IMPL_LINK_NOARG(SvxStyleBox_Base, FocusOutHdl, weld::Widget&, void)
1046 {
1047  if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus
1048  set_active_or_entry_text(m_xWidget->get_saved_value());
1049 }
1050 
1051 IMPL_LINK(SvxStyleBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
1052 {
1053  return DoKeyInput(rKEvt);
1054 }
1055 
1056 bool SvxStyleBox_Base::DoKeyInput(const KeyEvent& rKEvt)
1057 {
1058  bool bHandled = false;
1059 
1060  sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
1061 
1062  switch (nCode)
1063  {
1064  case KEY_TAB:
1065  bRelease = false;
1066  Select(true);
1067  break;
1068  case KEY_ESCAPE:
1069  set_active_or_entry_text(m_xWidget->get_saved_value());
1070  if (!m_rCtrl.IsInSidebar())
1071  {
1072  ReleaseFocus();
1073  bHandled = true;
1074  }
1075  break;
1076  }
1077 
1078  return bHandled;
1079 }
1080 
1081 bool SvxStyleBox_Impl::DoKeyInput(const KeyEvent& rKEvt)
1082 {
1083  return SvxStyleBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
1084 }
1085 
1086 void SvxStyleBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
1087 {
1088  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
1089  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
1090  {
1091  SetOptimalSize();
1092  }
1093 
1095 }
1096 
1097 bool SvxStyleBox_Base::AdjustFontForItemHeight(OutputDevice& rDevice, tools::Rectangle const & rTextRect, long nHeight)
1098 {
1099  if (rTextRect.Bottom() > nHeight)
1100  {
1101  // the text does not fit, adjust the font size
1102  double ratio = static_cast< double >( nHeight ) / rTextRect.Bottom();
1103  vcl::Font aFont(rDevice.GetFont());
1104  Size aPixelSize(aFont.GetFontSize());
1105  aPixelSize.setWidth( aPixelSize.Width() * ratio );
1106  aPixelSize.setHeight( aPixelSize.Height() * ratio );
1107  aFont.SetFontSize(aPixelSize);
1108  rDevice.SetFont(aFont);
1109  return true;
1110  }
1111  return false;
1112 }
1113 
1114 void SvxStyleBox_Impl::SetOptimalSize()
1115 {
1116  // set width in chars low so the size request will not be overridden
1117  m_xWidget->set_entry_width_chars(1);
1118  // tdf#132338 purely using this calculation to keep things their traditional width
1119  Size aSize(LogicToPixel(Size(COMBO_WIDTH_IN_CHARS * 4, 0), MapMode(MapUnit::MapAppFont)));
1120  m_xWidget->set_size_request(aSize.Width(), -1);
1121 
1122  SetSizePixel(get_preferred_size());
1123 }
1124 
1125 void SvxStyleBox_Base::UserDrawEntry(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const OUString &rStyleName)
1126 {
1127  // IMG_TXT_DISTANCE in ilstbox.hxx is 6, then 1 is added as
1128  // nBorder, and we are adding 1 in order to look better when
1129  // italics is present
1130  const int nLeftDistance = 8;
1131 
1132  tools::Rectangle aTextRect;
1133  rRenderContext.GetTextBoundRect(aTextRect, rStyleName);
1134 
1135  Point aPos(rRect.TopLeft());
1136  aPos.AdjustX(nLeftDistance );
1137 
1138  if (!AdjustFontForItemHeight(rRenderContext, aTextRect, rRect.GetHeight()))
1139  aPos.AdjustY((rRect.GetHeight() - aTextRect.Bottom() ) / 2);
1140 
1141  rRenderContext.DrawText(aPos, rStyleName);
1142 }
1143 
1144 void SvxStyleBox_Base::SetupEntry(vcl::RenderContext& rRenderContext, sal_Int32 nItem, const tools::Rectangle& rRect, const OUString& rStyleName, bool bIsNotSelected)
1145 {
1146  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1147  if (!bIsNotSelected)
1148  rRenderContext.SetTextColor(rStyleSettings.GetHighlightTextColor());
1149  else
1150  rRenderContext.SetTextColor(rStyleSettings.GetDialogTextColor());
1151 
1152  // handle the push-button
1153  if (!bIsNotSelected)
1154  {
1155  if (nItem == 0 || nItem == m_xWidget->get_count() - 1)
1156  m_xWidget->set_item_menu(OString::number(nItem), nullptr);
1157  else
1158  m_xWidget->set_item_menu(OString::number(nItem), m_xMenu.get());
1159  }
1160 
1161  if (nItem > 0 && nItem < m_xWidget->get_count() - 1)
1162  {
1164  SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool();
1165  SfxStyleSheetBase* pStyle = nullptr;
1166 
1167  if ( pPool )
1168  {
1169  pStyle = pPool->First(eStyleFamily);
1170  while (pStyle && pStyle->GetName() != rStyleName)
1171  pStyle = pPool->Next();
1172  }
1173 
1174  if (pStyle )
1175  {
1176  std::unique_ptr<const SfxItemSet> const pItemSet(pStyle->GetItemSetForPreview());
1177  if (!pItemSet) return;
1178 
1179  const SvxFontItem * const pFontItem =
1180  pItemSet->GetItem<SvxFontItem>(SID_ATTR_CHAR_FONT);
1181  const SvxFontHeightItem * const pFontHeightItem =
1182  pItemSet->GetItem<SvxFontHeightItem>(SID_ATTR_CHAR_FONTHEIGHT);
1183 
1184  if ( pFontItem && pFontHeightItem )
1185  {
1186  Size aFontSize( 0, pFontHeightItem->GetHeight() );
1187  Size aPixelSize(rRenderContext.LogicToPixel(aFontSize, MapMode(pShell->GetMapUnit())));
1188 
1189  // setup the font properties
1190  SvxFont aFont;
1191  aFont.SetFamilyName(pFontItem->GetFamilyName());
1192  aFont.SetStyleName(pFontItem->GetStyleName());
1193  aFont.SetFontSize(aPixelSize);
1194 
1195  const SfxPoolItem *pItem = pItemSet->GetItem( SID_ATTR_CHAR_WEIGHT );
1196  if ( pItem )
1197  aFont.SetWeight( static_cast< const SvxWeightItem* >( pItem )->GetWeight() );
1198 
1199  pItem = pItemSet->GetItem( SID_ATTR_CHAR_POSTURE );
1200  if ( pItem )
1201  aFont.SetItalic( static_cast< const SvxPostureItem* >( pItem )->GetPosture() );
1202 
1203  pItem = pItemSet->GetItem( SID_ATTR_CHAR_CONTOUR );
1204  if ( pItem )
1205  aFont.SetOutline( static_cast< const SvxContourItem* >( pItem )->GetValue() );
1206 
1207  pItem = pItemSet->GetItem( SID_ATTR_CHAR_SHADOWED );
1208  if ( pItem )
1209  aFont.SetShadow( static_cast< const SvxShadowedItem* >( pItem )->GetValue() );
1210 
1211  pItem = pItemSet->GetItem( SID_ATTR_CHAR_RELIEF );
1212  if ( pItem )
1213  aFont.SetRelief( static_cast< const SvxCharReliefItem* >( pItem )->GetValue() );
1214 
1215  pItem = pItemSet->GetItem( SID_ATTR_CHAR_UNDERLINE );
1216  if ( pItem )
1217  aFont.SetUnderline( static_cast< const SvxUnderlineItem* >( pItem )->GetLineStyle() );
1218 
1219  pItem = pItemSet->GetItem( SID_ATTR_CHAR_OVERLINE );
1220  if ( pItem )
1221  aFont.SetOverline( static_cast< const SvxOverlineItem* >( pItem )->GetValue() );
1222 
1223  pItem = pItemSet->GetItem( SID_ATTR_CHAR_STRIKEOUT );
1224  if ( pItem )
1225  aFont.SetStrikeout( static_cast< const SvxCrossedOutItem* >( pItem )->GetStrikeout() );
1226 
1227  pItem = pItemSet->GetItem( SID_ATTR_CHAR_CASEMAP );
1228  if ( pItem )
1229  aFont.SetCaseMap(static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap());
1230 
1231  pItem = pItemSet->GetItem( SID_ATTR_CHAR_EMPHASISMARK );
1232  if ( pItem )
1233  aFont.SetEmphasisMark( static_cast< const SvxEmphasisMarkItem* >( pItem )->GetEmphasisMark() );
1234 
1235  // setup the device & draw
1236  Color aFontCol = COL_AUTO, aBackCol = COL_AUTO;
1237 
1238  rRenderContext.SetFont(aFont);
1239 
1240  pItem = pItemSet->GetItem( SID_ATTR_CHAR_COLOR );
1241  // text color, when nothing is selected
1242  if ( (nullptr != pItem) && bIsNotSelected)
1243  aFontCol = static_cast< const SvxColorItem* >( pItem )->GetValue();
1244 
1245  drawing::FillStyle style = drawing::FillStyle_NONE;
1246  // which kind of Fill style is selected
1247  pItem = pItemSet->GetItem( XATTR_FILLSTYLE );
1248  // only when ok and not selected
1249  if ( (nullptr != pItem) && bIsNotSelected)
1250  style = static_cast< const XFillStyleItem* >( pItem )->GetValue();
1251 
1252  switch(style)
1253  {
1254  case drawing::FillStyle_SOLID:
1255  {
1256  // set background color
1257  pItem = pItemSet->GetItem( XATTR_FILLCOLOR );
1258  if ( nullptr != pItem )
1259  aBackCol = static_cast< const XFillColorItem* >( pItem )->GetColorValue();
1260 
1261  if ( aBackCol != COL_AUTO )
1262  {
1263  rRenderContext.SetFillColor(aBackCol);
1264  rRenderContext.DrawRect(rRect);
1265  }
1266  }
1267  break;
1268 
1269  default: break;
1270  //TODO Draw the other background styles: gradient, hatching and bitmap
1271  }
1272 
1273  // when the font and background color are too similar, adjust the Font-Color
1274  if( (aFontCol != COL_AUTO) || (aBackCol != COL_AUTO) )
1275  aFontCol = TestColorsVisible(aFontCol, (aBackCol != COL_AUTO) ? aBackCol : rRenderContext.GetBackground().GetColor());
1276 
1277  // set text color
1278  if ( aFontCol != COL_AUTO )
1279  rRenderContext.SetTextColor(aFontCol);
1280  }
1281  }
1282  }
1283 }
1284 
1285 IMPL_LINK(SvxStyleBox_Base, CustomRenderHdl, weld::ComboBox::render_args, aPayload, void)
1286 {
1287  vcl::RenderContext& rRenderContext = std::get<0>(aPayload);
1288  const ::tools::Rectangle& rRect = std::get<1>(aPayload);
1289  bool bSelected = std::get<2>(aPayload);
1290  const OUString& rId = std::get<3>(aPayload);
1291 
1292  sal_uInt32 nIndex = rId.toUInt32();
1293 
1294  OUString aStyleName(m_xWidget->get_text(nIndex));
1295 
1296  rRenderContext.Push(PushFlags::FILLCOLOR | PushFlags::FONT | PushFlags::TEXTCOLOR);
1297 
1298  SetupEntry(rRenderContext, nIndex, rRect, aStyleName, !bSelected);
1299 
1300  UserDrawEntry(rRenderContext, rRect, aStyleName);
1301 
1302  rRenderContext.Pop();
1303 }
1304 
1305 void SvxStyleBox_Base::CalcOptimalExtraUserWidth(vcl::RenderContext& rRenderContext)
1306 {
1307  if (m_nMaxUserDrawFontWidth)
1308  return;
1309 
1310  long nMaxNormalFontWidth = 0;
1311  sal_Int32 nEntryCount = m_xWidget->get_count();
1312  for (sal_Int32 i = 0; i < nEntryCount; ++i)
1313  {
1314  OUString sStyleName(get_text(i));
1315  tools::Rectangle aTextRectForDefaultFont;
1316  rRenderContext.GetTextBoundRect(aTextRectForDefaultFont, sStyleName);
1317 
1318  const long nWidth = aTextRectForDefaultFont.GetWidth();
1319 
1320  nMaxNormalFontWidth = std::max(nWidth, nMaxNormalFontWidth);
1321  }
1322 
1323  m_nMaxUserDrawFontWidth = nMaxNormalFontWidth;
1324  for (sal_Int32 i = 1; i < nEntryCount-1; ++i)
1325  {
1326  OUString sStyleName(get_text(i));
1327 
1328  rRenderContext.Push(PushFlags::FILLCOLOR | PushFlags::FONT | PushFlags::TEXTCOLOR);
1329  SetupEntry(rRenderContext, i, tools::Rectangle(0, 0, RECT_MAX, ITEM_HEIGHT), sStyleName, true);
1330  tools::Rectangle aTextRectForActualFont;
1331  rRenderContext.GetTextBoundRect(aTextRectForActualFont, sStyleName);
1332  if (AdjustFontForItemHeight(rRenderContext, aTextRectForActualFont, ITEM_HEIGHT))
1333  {
1334  //Font didn't fit, so it was changed, refetch with final font size
1335  rRenderContext.GetTextBoundRect(aTextRectForActualFont, sStyleName);
1336  }
1337  rRenderContext.Pop();
1338 
1339  const int nWidth = aTextRectForActualFont.GetWidth() + m_xWidget->get_menu_button_width() + BUTTON_PADDING;
1340 
1341  m_nMaxUserDrawFontWidth = std::max(nWidth, m_nMaxUserDrawFontWidth);
1342  }
1343 }
1344 
1345 // test is the color between Font- and background-color to be identify
1346 // return is always the Font-Color
1347 // when both light or dark, change the Contrast
1348 // in other case do not change the origin color
1349 // when the color is R=G=B=128 the DecreaseContrast make 128 the need an exception
1350 Color SvxStyleBox_Base::TestColorsVisible(const Color &FontCol, const Color &BackCol)
1351 {
1352  const sal_uInt8 ChgVal = 60; // increase/decrease the Contrast
1353 
1354  Color retCol = FontCol;
1355  if ((FontCol.IsDark() == BackCol.IsDark()) && (FontCol.IsBright() == BackCol.IsBright()))
1356  {
1357  sal_uInt8 lumi = retCol.GetLuminance();
1358 
1359  if((lumi > 120) && (lumi < 140))
1360  retCol.DecreaseLuminance(ChgVal / 2);
1361  else
1362  retCol.DecreaseContrast(ChgVal);
1363  }
1364 
1365  return retCol;
1366 }
1367 
1368 IMPL_LINK(SvxStyleBox_Base, DumpAsPropertyTreeHdl, tools::JsonWriter&, rJsonWriter, void)
1369 {
1370  {
1371  auto entriesNode = rJsonWriter.startNode("entries");
1372  for (int i = 0, nEntryCount = m_xWidget->get_count(); i < nEntryCount; ++i)
1373  {
1374  auto entryNode = rJsonWriter.startNode("");
1375  rJsonWriter.put("", m_xWidget->get_text(i));
1376  }
1377  }
1378 
1379  int nActive = m_xWidget->get_active();
1380  rJsonWriter.put("selectedCount", static_cast<sal_Int32>(nActive == -1 ? 0 : 1));
1381 
1382  {
1383  auto selectedNode = rJsonWriter.startNode("selectedEntries");
1384  if (nActive != -1)
1385  {
1386  auto node = rJsonWriter.startNode("");
1387  rJsonWriter.put("", static_cast<sal_Int32>(nActive));
1388  }
1389  }
1390 
1391  rJsonWriter.put("command", ".uno:StyleApply");
1392 }
1393 
1394 static bool lcl_GetDocFontList(const FontList** ppFontList, SvxFontNameBox_Base* pBox)
1395 {
1396  bool bChanged = false;
1397  const SfxObjectShell* pDocSh = SfxObjectShell::Current();
1398  const SvxFontListItem* pFontListItem = nullptr;
1399 
1400  if ( pDocSh )
1401  pFontListItem =
1402  static_cast<const SvxFontListItem*>(pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST ));
1403  else
1404  {
1405  ::std::unique_ptr<FontList> aFontList(new FontList(Application::GetDefaultDevice()));
1406  *ppFontList = aFontList.get();
1407  pBox->SetOwnFontList(std::move(aFontList));
1408  bChanged = true;
1409  }
1410 
1411  if ( pFontListItem )
1412  {
1413  const FontList* pNewFontList = pFontListItem->GetFontList();
1414  DBG_ASSERT( pNewFontList, "Doc-FontList not available!" );
1415 
1416  // No old list, but a new list
1417  if ( !*ppFontList && pNewFontList )
1418  {
1419  // => take over
1420  *ppFontList = pNewFontList;
1421  bChanged = true;
1422  }
1423  else
1424  {
1425  // Comparing the font lists is not perfect.
1426  // When you change the font list in the Doc, you can track
1427  // changes here only on the Listbox, because ppFontList
1428  // has already been updated.
1429  bChanged =
1430  ( ( *ppFontList != pNewFontList ) ||
1431  pBox->GetListCount() != pNewFontList->GetFontNameCount() );
1432  // HACK: Comparing is incomplete
1433 
1434  if ( bChanged )
1435  *ppFontList = pNewFontList;
1436  }
1437 
1438  if ( pBox )
1439  pBox->set_sensitive(true);
1440  }
1441  else if ( pBox && ( pDocSh || !ppFontList ))
1442  {
1443  // Disable box only when we have a SfxObjectShell and didn't get a font list OR
1444  // we don't have a SfxObjectShell and no current font list.
1445  // It's possible that we currently have no SfxObjectShell, but a current font list.
1446  // See #i58471: When a user set the focus into the font name combo box and opens
1447  // the help window with F1. After closing the help window, we disable the font name
1448  // combo box. The SfxObjectShell::Current() method returns in that case zero. But the
1449  // font list hasn't changed and therefore the combo box shouldn't be disabled!
1450  pBox->set_sensitive(false);
1451  }
1452 
1453  // Fill the FontBox, also the new list if necessary
1454  if ( pBox && bChanged )
1455  {
1456  if ( *ppFontList )
1457  pBox->Fill( *ppFontList );
1458  else
1459  pBox->Clear();
1460  }
1461  return bChanged;
1462 }
1463 
1464 SvxFontNameBox_Base::SvxFontNameBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
1465  const Reference<XDispatchProvider>& rDispatchProvider,
1466  const Reference<XFrame>& rFrame,
1467  SvxFontNameToolBoxControl& rCtrl)
1468  : m_xListener(new comphelper::ConfigurationListener("/org.openoffice.Office.Common/Font/View"))
1469  , m_aWYSIWYG(m_xListener, "ShowFontBoxWYSIWYG", *this)
1470  , m_aHistory(m_xListener, "History", *this)
1471  , m_rCtrl(rCtrl)
1472  , m_xWidget(new FontNameBox(std::move(xWidget)))
1473  , pFontList(nullptr)
1474  , nFtCount(0)
1475  , bRelease(true)
1476  , m_xDispatchProvider(rDispatchProvider)
1477  , m_xFrame(rFrame)
1478  , mbCheckingUnknownFont(false)
1479 {
1480  EnableControls();
1481 
1482  m_xWidget->connect_changed(LINK(this, SvxFontNameBox_Base, SelectHdl));
1483  m_xWidget->connect_key_press(LINK(this, SvxFontNameBox_Base, KeyInputHdl));
1484  m_xWidget->connect_entry_activate(LINK(this, SvxFontNameBox_Base, ActivateHdl));
1485  m_xWidget->connect_focus_in(LINK(this, SvxFontNameBox_Base, FocusInHdl));
1486  m_xWidget->connect_focus_out(LINK(this, SvxFontNameBox_Base, FocusOutHdl));
1487  m_xWidget->connect_get_property_tree(LINK(this, SvxFontNameBox_Base, DumpAsPropertyTreeHdl));
1488 
1489  m_xWidget->set_entry_width_chars(COMBO_WIDTH_IN_CHARS);
1490 }
1491 
1492 SvxFontNameBox_Impl::SvxFontNameBox_Impl(vcl::Window* pParent, const Reference<XDispatchProvider>& rDispatchProvider,
1493  const Reference<XFrame>& rFrame, SvxFontNameToolBoxControl& rCtrl)
1494  : InterimItemWindow(pParent, "svx/ui/fontnamebox.ui", "FontNameBox")
1495  , SvxFontNameBox_Base(m_xBuilder->weld_combo_box("fontnamecombobox"), rDispatchProvider, rFrame, rCtrl)
1496 {
1497  set_id("fontnamecombobox");
1498  SetOptimalSize();
1499 }
1500 
1501 void SvxFontNameBox_Base::FillList()
1502 {
1503  if (!m_xWidget) // e.g. disposed
1504  return;
1505  // Save old Selection, set back in the end
1506  int nStartPos, nEndPos;
1507  m_xWidget->get_entry_selection_bounds(nStartPos, nEndPos);
1508 
1509  // Did Doc-Fontlist change?
1510  lcl_GetDocFontList(&pFontList, this);
1511 
1512  m_xWidget->select_entry_region(nStartPos, nEndPos);
1513 }
1514 
1515 void SvxFontNameBox_Base::CheckAndMarkUnknownFont()
1516 {
1517  if (mbCheckingUnknownFont) //tdf#117537 block rentry
1518  return;
1519  mbCheckingUnknownFont = true;
1520  OUString fontname = m_xWidget->get_active_text();
1521  lcl_GetDocFontList( &pFontList, this );
1522  // If the font is unknown, show it in italic.
1523  vcl::Font font = m_xWidget->get_entry_font();
1524  if( pFontList != nullptr && pFontList->IsAvailable( fontname ))
1525  {
1526  if( font.GetItalic() != ITALIC_NONE )
1527  {
1528  font.SetItalic( ITALIC_NONE );
1529  m_xWidget->set_entry_font(font);
1530  m_xWidget->set_tooltip_text(SvxResId(RID_SVXSTR_CHARFONTNAME));
1531  }
1532  }
1533  else
1534  {
1535  if( font.GetItalic() != ITALIC_NORMAL )
1536  {
1537  font.SetItalic( ITALIC_NORMAL );
1538  m_xWidget->set_entry_font(font);
1539  m_xWidget->set_tooltip_text(SvxResId(RID_SVXSTR_CHARFONTNAME_NOTAVAILABLE));
1540  }
1541  }
1542  mbCheckingUnknownFont = false;
1543 }
1544 
1545 void SvxFontNameBox_Base::Update( const css::awt::FontDescriptor* pFontDesc )
1546 {
1547  if ( pFontDesc )
1548  {
1549  aCurFont.SetFamilyName ( pFontDesc->Name );
1550  aCurFont.SetFamily ( FontFamily( pFontDesc->Family ) );
1551  aCurFont.SetStyleName ( pFontDesc->StyleName );
1552  aCurFont.SetPitch ( FontPitch( pFontDesc->Pitch ) );
1553  aCurFont.SetCharSet ( rtl_TextEncoding( pFontDesc->CharSet ) );
1554  }
1555  OUString aCurName = aCurFont.GetFamilyName();
1556  OUString aText = m_xWidget->get_active_text();
1557  if (aText != aCurName)
1558  set_active_or_entry_text(aCurName);
1559 }
1560 
1561 void SvxFontNameBox_Base::set_active_or_entry_text(const OUString& rText)
1562 {
1563  m_xWidget->set_active_or_entry_text(rText);
1564  CheckAndMarkUnknownFont();
1565 }
1566 
1567 IMPL_LINK_NOARG(SvxFontNameBox_Base, FocusInHdl, weld::Widget&, void)
1568 {
1569  FillList();
1570 }
1571 
1572 IMPL_LINK(SvxFontNameBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
1573 {
1574  return DoKeyInput(rKEvt);
1575 }
1576 
1577 bool SvxFontNameBox_Base::DoKeyInput(const KeyEvent& rKEvt)
1578 {
1579  bool bHandled = false;
1580 
1581  sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
1582 
1583  switch (nCode)
1584  {
1585  case KEY_TAB:
1586  bRelease = false;
1587  Select(true);
1588  break;
1589 
1590  case KEY_ESCAPE:
1591  set_active_or_entry_text(m_xWidget->get_saved_value());
1592  if (!m_rCtrl.IsInSidebar())
1593  {
1594  ReleaseFocus_Impl();
1595  bHandled = true;
1596  }
1597  EndPreview();
1598  break;
1599  }
1600 
1601  return bHandled;
1602 }
1603 
1604 bool SvxFontNameBox_Impl::DoKeyInput(const KeyEvent& rKEvt)
1605 {
1606  return SvxFontNameBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
1607 }
1608 
1609 IMPL_LINK_NOARG(SvxFontNameBox_Base, FocusOutHdl, weld::Widget&, void)
1610 {
1611  if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus
1612  {
1613  set_active_or_entry_text(m_xWidget->get_saved_value());
1614  // send EndPreview
1615  EndPreview();
1616  }
1617 }
1618 
1619 void SvxFontNameBox_Impl::SetOptimalSize()
1620 {
1621  // set width in chars low so the size request will not be overridden
1622  m_xWidget->set_entry_width_chars(1);
1623  // tdf#132338 purely using this calculation to keep things their traditional width
1624  Size aSize(LogicToPixel(Size(COMBO_WIDTH_IN_CHARS * 4, 0), MapMode(MapUnit::MapAppFont)));
1625  m_xWidget->set_size_request(aSize.Width(), -1);
1626 
1627  SetSizePixel(get_preferred_size());
1628 }
1629 
1630 void SvxFontNameBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
1631 {
1632  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
1633  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
1634  {
1635  SetOptimalSize();
1636  }
1637  else if ( ( rDCEvt.GetType() == DataChangedEventType::FONTS ) ||
1638  ( rDCEvt.GetType() == DataChangedEventType::DISPLAY ) )
1639  {
1640  // The old font list in shell has likely been destroyed at this point, so we need to get
1641  // the new one before doing anything further.
1642  lcl_GetDocFontList( &pFontList, this );
1643  }
1644 }
1645 
1646 void SvxFontNameBox_Base::ReleaseFocus_Impl()
1647 {
1648  if ( !bRelease )
1649  {
1650  bRelease = true;
1651  return;
1652  }
1653  if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
1654  m_xFrame->getContainerWindow()->setFocus();
1655 }
1656 
1657 void SvxFontNameBox_Base::EnableControls()
1658 {
1659  bool bEnableMRU = m_aHistory.get();
1660  sal_uInt16 nEntries = bEnableMRU ? MAX_MRU_FONTNAME_ENTRIES : 0;
1661 
1662  bool bNewWYSIWYG = m_aWYSIWYG.get();
1663  bool bOldWYSIWYG = m_xWidget->IsWYSIWYGEnabled();
1664 
1665  if (m_xWidget->get_max_mru_count() != nEntries || bNewWYSIWYG != bOldWYSIWYG)
1666  {
1667  // refill in the next GetFocus-Handler
1668  pFontList = nullptr;
1669  Clear();
1670  m_xWidget->set_max_mru_count(nEntries);
1671  }
1672 
1673  if (bNewWYSIWYG != bOldWYSIWYG)
1674  m_xWidget->EnableWYSIWYG(bNewWYSIWYG);
1675 }
1676 
1677 IMPL_LINK(SvxFontNameBox_Base, SelectHdl, weld::ComboBox&, rCombo, void)
1678 {
1679  Select(rCombo.changed_by_direct_pick()); // only when picked from the list
1680 }
1681 
1682 IMPL_LINK_NOARG(SvxFontNameBox_Base, ActivateHdl, weld::ComboBox&, bool)
1683 {
1684  Select(true);
1685  return true;
1686 }
1687 
1688 void SvxFontNameBox_Base::Select(bool bNonTravelSelect)
1689 {
1690  Sequence< PropertyValue > aArgs( 1 );
1691  std::unique_ptr<SvxFontItem> pFontItem;
1692  if ( pFontList )
1693  {
1694  FontMetric aFontMetric( pFontList->Get(m_xWidget->get_active_text(),
1695  aCurFont.GetWeight(),
1696  aCurFont.GetItalic() ) );
1697  aCurFont = aFontMetric;
1698 
1699  pFontItem.reset( new SvxFontItem( aFontMetric.GetFamilyType(),
1700  aFontMetric.GetFamilyName(),
1701  aFontMetric.GetStyleName(),
1702  aFontMetric.GetPitch(),
1703  aFontMetric.GetCharSet(),
1704  SID_ATTR_CHAR_FONT ) );
1705 
1706  Any a;
1707  pFontItem->QueryValue( a );
1708  aArgs[0].Value = a;
1709  }
1710 
1711  if (bNonTravelSelect)
1712  {
1713  CheckAndMarkUnknownFont();
1714  // #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
1715  // This instance may be deleted in the meantime (i.e. when a dialog is opened
1716  // while in Dispatch()), accessing members will crash in this case.
1717  ReleaseFocus_Impl();
1718  EndPreview();
1719  if (pFontItem)
1720  {
1721  aArgs[0].Name = "CharFontName";
1722  SfxToolBoxControl::Dispatch( m_xDispatchProvider,
1723  ".uno:CharFontName",
1724  aArgs );
1725  }
1726  }
1727  else
1728  {
1729  if (pFontItem)
1730  {
1731  aArgs[0].Name = "CharPreviewFontName";
1732  SfxToolBoxControl::Dispatch( m_xDispatchProvider,
1733  ".uno:CharPreviewFontName",
1734  aArgs );
1735  }
1736  }
1737 }
1738 
1739 IMPL_LINK(SvxFontNameBox_Base, DumpAsPropertyTreeHdl, tools::JsonWriter&, rJsonWriter, void)
1740 {
1741  {
1742  auto entriesNode = rJsonWriter.startNode("entries");
1743  for (int i = 0, nEntryCount = m_xWidget->get_count(); i < nEntryCount; ++i)
1744  {
1745  auto entryNode = rJsonWriter.startNode("");
1746  rJsonWriter.put("", m_xWidget->get_text(i));
1747  }
1748  }
1749 
1750  int nSelectedEntry = m_xWidget->get_active();
1751  rJsonWriter.put("selectedCount", static_cast<sal_Int32>(nSelectedEntry == -1 ? 0 : 1));
1752 
1753  {
1754  auto selectedNode = rJsonWriter.startNode("selectedEntries");
1755  if (nSelectedEntry != -1)
1756  {
1757  auto entryNode = rJsonWriter.startNode("");
1758  rJsonWriter.put("", m_xWidget->get_text(nSelectedEntry));
1759  }
1760  }
1761 
1762  rJsonWriter.put("command", ".uno:CharFontName");
1763 }
1764 
1765 ColorWindow::ColorWindow(const OUString& rCommand,
1766  std::shared_ptr<PaletteManager> const & rPaletteManager,
1767  ColorStatus& rColorStatus,
1768  sal_uInt16 nSlotId,
1769  const Reference< XFrame >& rFrame,
1770  weld::Window* pParentWindow,
1771  const MenuOrToolMenuButton& rMenuButton,
1772  ColorSelectFunction const & aFunction)
1773  : WeldToolbarPopup(rFrame, rMenuButton.get_widget(), "svx/ui/colorwindow.ui", "palette_popup_window")
1774  , theSlotId(nSlotId)
1775  , maCommand(rCommand)
1776  , mpParentWindow(pParentWindow)
1777  , maMenuButton(rMenuButton)
1778  , mxPaletteManager(rPaletteManager)
1779  , mrColorStatus(rColorStatus)
1780  , maColorSelectFunction(aFunction)
1781  , mxColorSet(new SvxColorValueSet(m_xBuilder->weld_scrolled_window("colorsetwin")))
1782  , mxRecentColorSet(new SvxColorValueSet(nullptr))
1783  , mxPaletteListBox(m_xBuilder->weld_combo_box("palette_listbox"))
1784  , mxButtonAutoColor(m_xBuilder->weld_button("auto_color_button"))
1785  , mxButtonNoneColor(m_xBuilder->weld_button("none_color_button"))
1786  , mxButtonPicker(m_xBuilder->weld_button("color_picker_button"))
1787  , mxAutomaticSeparator(m_xBuilder->weld_widget("separator4"))
1788  , mxColorSetWin(new weld::CustomWeld(*m_xBuilder, "colorset", *mxColorSet))
1789  , mxRecentColorSetWin(new weld::CustomWeld(*m_xBuilder, "recent_colorset", *mxRecentColorSet))
1790  , mpDefaultButton(nullptr)
1791 {
1794 
1795  switch ( theSlotId )
1796  {
1797  case SID_ATTR_CHAR_COLOR_BACKGROUND:
1798  case SID_BACKGROUND_COLOR:
1799  case SID_ATTR_CHAR_BACK_COLOR:
1800  case SID_TABLE_CELL_BACKGROUND_COLOR:
1801  {
1802  mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_NOFILL ) );
1803  break;
1804  }
1805  case SID_AUTHOR_COLOR:
1806  {
1807  mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_BY_AUTHOR ) );
1808  break;
1809  }
1810  case SID_BMPMASK_COLOR:
1811  {
1812  mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_TRANSPARENT ) );
1813  break;
1814  }
1815  case SID_ATTR_CHAR_COLOR:
1816  case SID_ATTR_CHAR_COLOR2:
1817  case SID_EXTRUSION_3D_COLOR:
1818  {
1819  mxButtonAutoColor->set_label(EditResId(RID_SVXSTR_AUTOMATIC));
1820  break;
1821  }
1822  case SID_FM_CTL_PROPERTIES:
1823  {
1824  mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_DEFAULT ) );
1825  break;
1826  }
1827  default:
1828  {
1829  mxButtonAutoColor->hide();
1830  mxAutomaticSeparator->hide();
1831  break;
1832  }
1833  }
1834 
1835  mxPaletteListBox->connect_changed(LINK(this, ColorWindow, SelectPaletteHdl));
1836  std::vector<OUString> aPaletteList = mxPaletteManager->GetPaletteList();
1837  mxPaletteListBox->freeze();
1838  for (const auto& rPalette : aPaletteList)
1839  mxPaletteListBox->append_text(rPalette);
1840  mxPaletteListBox->thaw();
1841  OUString aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() );
1842  mxPaletteListBox->set_active_text(aPaletteName);
1843  const int nSelectedEntry(mxPaletteListBox->get_active());
1844  if (nSelectedEntry != -1)
1845  mxPaletteManager->SetPalette(nSelectedEntry);
1846 
1847  mxButtonAutoColor->connect_clicked(LINK(this, ColorWindow, AutoColorClickHdl));
1848  mxButtonNoneColor->connect_clicked(LINK(this, ColorWindow, AutoColorClickHdl));
1849  mxButtonPicker->connect_clicked(LINK(this, ColorWindow, OpenPickerClickHdl));
1850 
1851  mxColorSet->SetSelectHdl(LINK( this, ColorWindow, SelectHdl));
1852  mxRecentColorSet->SetSelectHdl(LINK( this, ColorWindow, SelectHdl));
1853  m_xTopLevel->set_help_id(HID_POPUP_COLOR);
1854  mxColorSet->SetHelpId(HID_POPUP_COLOR_CTRL);
1855 
1856  mxPaletteManager->ReloadColorSet(*mxColorSet);
1857  const sal_uInt32 nMaxItems(SvxColorValueSet::getMaxRowCount() * SvxColorValueSet::getColumnCount());
1858  Size aSize = mxColorSet->layoutAllVisible(nMaxItems);
1859  mxColorSet->set_size_request(aSize.Width(), aSize.Height());
1860 
1861  mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
1862  aSize = mxRecentColorSet->layoutAllVisible(mxPaletteManager->GetRecentColorCount());
1863  mxRecentColorSet->set_size_request(aSize.Width(), aSize.Height());
1864 
1865  AddStatusListener( ".uno:ColorTableState" );
1867  if ( maCommand == ".uno:FrameLineColor" )
1868  {
1869  AddStatusListener( ".uno:BorderTLBR" );
1870  AddStatusListener( ".uno:BorderBLTR" );
1871  }
1872 }
1873 
1875 {
1876  if (mxColorSet->IsNoSelection() && mpDefaultButton)
1878  else
1879  mxColorSet->GrabFocus();
1880 }
1881 
1883 {
1884  mxButtonNoneColor->show();
1885 }
1886 
1888 {
1889 }
1890 
1892 {
1893  Color aColor = pColorSet->GetItemColor(pColorSet->GetSelectedItemId());
1894  OUString sColorName = pColorSet->GetItemText(pColorSet->GetSelectedItemId());
1895  return std::make_pair(aColor, sColorName);
1896 }
1897 
1898 namespace
1899 {
1900  NamedColor GetAutoColor(sal_uInt16 nSlotId)
1901  {
1902  Color aColor;
1903  OUString sColorName;
1904  switch (nSlotId)
1905  {
1906  case SID_ATTR_CHAR_COLOR_BACKGROUND:
1907  case SID_BACKGROUND_COLOR:
1908  case SID_ATTR_CHAR_BACK_COLOR:
1909  case SID_TABLE_CELL_BACKGROUND_COLOR:
1910  aColor = COL_TRANSPARENT;
1911  sColorName = SvxResId(RID_SVXSTR_NOFILL);
1912  break;
1913  case SID_AUTHOR_COLOR:
1914  aColor = COL_TRANSPARENT;
1915  sColorName = SvxResId(RID_SVXSTR_BY_AUTHOR);
1916  break;
1917  case SID_BMPMASK_COLOR:
1918  aColor = COL_TRANSPARENT;
1919  sColorName = SvxResId(RID_SVXSTR_TRANSPARENT);
1920  break;
1921  case SID_FM_CTL_PROPERTIES:
1922  aColor = COL_TRANSPARENT;
1923  sColorName = SvxResId(RID_SVXSTR_DEFAULT);
1924  break;
1925  case SID_ATTR_CHAR_COLOR:
1926  case SID_ATTR_CHAR_COLOR2:
1927  case SID_EXTRUSION_3D_COLOR:
1928  default:
1929  aColor = COL_AUTO;
1930  sColorName = EditResId(RID_SVXSTR_AUTOMATIC);
1931  break;
1932  }
1933 
1934  return std::make_pair(aColor, sColorName);
1935  }
1936 
1937  NamedColor GetNoneColor()
1938  {
1939  return std::make_pair(COL_NONE_COLOR, comphelper::LibreOfficeKit::isActive() ? SvxResId(RID_SVXSTR_INVISIBLE)
1940  : SvxResId(RID_SVXSTR_NONE));
1941  }
1942 }
1943 
1945 {
1946  if (!mxColorSet->IsNoSelection())
1947  return GetSelectEntryColor(mxColorSet.get());
1948  if (!mxRecentColorSet->IsNoSelection())
1949  return GetSelectEntryColor(mxRecentColorSet.get());
1950  if (mxButtonNoneColor.get() == mpDefaultButton)
1951  return GetNoneColor();
1952  return GetAutoColor();
1953 }
1954 
1955 IMPL_LINK(ColorWindow, SelectHdl, ValueSet*, pColorSet, void)
1956 {
1957  NamedColor aNamedColor = GetSelectEntryColor(pColorSet);
1958 
1959  if (pColorSet != mxRecentColorSet.get())
1960  {
1961  mxPaletteManager->AddRecentColor(aNamedColor.first, aNamedColor.second);
1962  if (!maMenuButton.get_active())
1963  mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
1964  }
1965 
1966  maSelectedLink.Call(aNamedColor);
1967 
1968  // deliberate take a copy here in case maMenuButton.set_inactive
1969  // triggers a callback that destroys ourself
1970  ColorSelectFunction aColorSelectFunction(maColorSelectFunction);
1971  OUString sCommand(maCommand);
1972 
1973  maMenuButton.set_inactive();
1974 
1975  aColorSelectFunction(sCommand, aNamedColor);
1976 }
1977 
1978 IMPL_LINK_NOARG(ColorWindow, SelectPaletteHdl, weld::ComboBox&, void)
1979 {
1980  int nPos = mxPaletteListBox->get_active();
1981  mxPaletteManager->SetPalette( nPos );
1982  mxPaletteManager->ReloadColorSet(*mxColorSet);
1983  mxColorSet->layoutToGivenHeight(mxColorSet->GetOutputSizePixel().Height(), mxPaletteManager->GetColorCount());
1984 }
1985 
1987 {
1988  return ::GetAutoColor(theSlotId);
1989 }
1990 
1991 IMPL_LINK(ColorWindow, AutoColorClickHdl, weld::Button&, rButton, void)
1992 {
1993  NamedColor aNamedColor = &rButton == mxButtonAutoColor.get() ? GetAutoColor() : GetNoneColor();
1994 
1995  mxColorSet->SetNoSelection();
1996  mxRecentColorSet->SetNoSelection();
1997  mpDefaultButton = &rButton;
1998 
1999  maSelectedLink.Call(aNamedColor);
2000 
2001  // deliberate take a copy here in case maMenuButton.set_inactive
2002  // triggers a callback that destroys ourself
2003  ColorSelectFunction aColorSelectFunction(maColorSelectFunction);
2004  OUString sCommand(maCommand);
2005 
2006  maMenuButton.set_inactive();
2007 
2008  aColorSelectFunction(sCommand, aNamedColor);
2009 }
2010 
2011 IMPL_LINK_NOARG(ColorWindow, OpenPickerClickHdl, weld::Button&, void)
2012 {
2013  // copy before set_inactive
2014  auto nColor = GetSelectEntryColor().first;
2015  auto pParentWindow = mpParentWindow;
2016  OUString sCommand = maCommand;
2017  std::shared_ptr<PaletteManager> xPaletteManager(mxPaletteManager);
2018 
2019  maMenuButton.set_inactive();
2020 
2021  xPaletteManager->PopupColorPicker(pParentWindow, sCommand, nColor);
2022 }
2023 
2025 {
2026  mxColorSet->SetNoSelection();
2027  mxRecentColorSet->SetNoSelection();
2028  mpDefaultButton = nullptr;
2029 }
2030 
2032 {
2033  if (!mxColorSet->IsNoSelection())
2034  return false;
2035  if (!mxRecentColorSet->IsNoSelection())
2036  return false;
2037  return !mxButtonAutoColor->get_visible() && !mxButtonNoneColor->get_visible();
2038 }
2039 
2040 void ColorWindow::statusChanged( const css::frame::FeatureStateEvent& rEvent )
2041 {
2042  if (rEvent.FeatureURL.Complete == ".uno:ColorTableState")
2043  {
2044  if (rEvent.IsEnabled && mxPaletteManager->GetPalette() == 0)
2045  {
2046  mxPaletteManager->ReloadColorSet(*mxColorSet);
2047  mxColorSet->layoutToGivenHeight(mxColorSet->GetOutputSizePixel().Height(), mxPaletteManager->GetColorCount());
2048  }
2049  }
2050  else
2051  {
2052  mrColorStatus.statusChanged(rEvent);
2054  }
2055 }
2056 
2058 {
2059  for (size_t i = 1; i <= pColorSet->GetItemCount(); ++i)
2060  {
2061  if (rColor == pColorSet->GetItemColor(i))
2062  {
2063  pColorSet->SelectItem(i);
2064  return true;
2065  }
2066  }
2067  return false;
2068 }
2069 
2070 void ColorWindow::SelectEntry(const NamedColor& rNamedColor)
2071 {
2072  SetNoSelection();
2073 
2074  const Color &rColor = rNamedColor.first;
2075 
2076  if (mxButtonAutoColor->get_visible() && (rColor == COL_TRANSPARENT || rColor == COL_AUTO))
2077  {
2079  return;
2080  }
2081 
2082  if (mxButtonNoneColor->get_visible() && rColor == COL_NONE_COLOR)
2083  {
2085  return;
2086  }
2087 
2088  // try current palette
2089  bool bFoundColor = SelectValueSetEntry(mxColorSet.get(), rColor);
2090  // try recently used
2091  if (!bFoundColor)
2092  bFoundColor = SelectValueSetEntry(mxRecentColorSet.get(), rColor);
2093  // if it's not there, add it there now to the end of the recently used
2094  // so its available somewhere handy, but not without trashing the
2095  // whole recently used
2096  if (!bFoundColor)
2097  {
2098  const OUString& rColorName = rNamedColor.second;
2099  mxPaletteManager->AddRecentColor(rColor, rColorName, false);
2100  mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
2101  SelectValueSetEntry(mxRecentColorSet.get(), rColor);
2102  }
2103 }
2104 
2105 void ColorWindow::SelectEntry(const Color& rColor)
2106 {
2107  OUString sColorName = "#" + rColor.AsRGBHexString().toAsciiUpperCase();
2108  ColorWindow::SelectEntry(std::make_pair(rColor, sColorName));
2109 }
2110 
2113  maTLBRColor( COL_TRANSPARENT ),
2114  maBLTRColor( COL_TRANSPARENT )
2115 {
2116 }
2117 
2119 {
2120 }
2121 
2122 void ColorStatus::statusChanged( const css::frame::FeatureStateEvent& rEvent )
2123 {
2124  Color aColor( COL_TRANSPARENT );
2125  css::table::BorderLine2 aTable;
2126 
2127  if ( rEvent.State >>= aTable )
2128  {
2129  SvxBorderLine aLine;
2130  SvxBoxItem::LineToSvxLine( aTable, aLine, false );
2131  if ( !aLine.isEmpty() )
2132  aColor = aLine.GetColor();
2133  }
2134  else
2135  rEvent.State >>= aColor;
2136 
2137  if ( rEvent.FeatureURL.Path == "BorderTLBR" )
2138  maTLBRColor = aColor;
2139  else if ( rEvent.FeatureURL.Path == "BorderBLTR" )
2140  maBLTRColor = aColor;
2141  else
2142  maColor = aColor;
2143 }
2144 
2146 {
2147  Color aColor( maColor );
2148 
2149  if ( maTLBRColor != COL_TRANSPARENT )
2150  {
2151  if ( aColor != maTLBRColor && aColor != COL_TRANSPARENT )
2152  return COL_TRANSPARENT;
2153  aColor = maTLBRColor;
2154  }
2155 
2156  if ( maBLTRColor != COL_TRANSPARENT )
2157  {
2158  if ( aColor != maBLTRColor && aColor != COL_TRANSPARENT )
2159  return COL_TRANSPARENT;
2160  return maBLTRColor;
2161  }
2162 
2163  return aColor;
2164 }
2165 
2166 
2167 SvxFrameWindow_Impl::SvxFrameWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent)
2168  : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/floatingframeborder.ui", "FloatingFrameBorder")
2169  , mxControl(pControl)
2170  , mxFrameSet(new SvxFrmValueSet_Impl)
2171  , mxFrameSetWin(new weld::CustomWeld(*m_xBuilder, "valueset", *mxFrameSet))
2172  , bParagraphMode(false)
2173 {
2174  mxFrameSet->SetStyle(WB_ITEMBORDER | WB_DOUBLEBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT);
2175  AddStatusListener(".uno:BorderReducedMode");
2176  InitImageList();
2177 
2178  /*
2179  * 1 2 3 4
2180  * -------------------------------------
2181  * NONE LEFT RIGHT LEFTRIGHT
2182  * TOP BOTTOM TOPBOTTOM OUTER
2183  * -------------------------------------
2184  * HOR HORINNER VERINNER ALL <- can be switched of via bParagraphMode
2185  */
2186 
2187  sal_uInt16 i = 0;
2188 
2189  for ( i=1; i<9; i++ )
2190  mxFrameSet->InsertItem(i, Image(aImgVec[i-1]));
2191 
2192  //bParagraphMode should have been set in StateChanged
2193  if ( !bParagraphMode )
2194  for ( i = 9; i < 13; i++ )
2195  mxFrameSet->InsertItem(i, Image(aImgVec[i-1]));
2196 
2197  mxFrameSet->SetColCount( 4 );
2198  mxFrameSet->SetSelectHdl( LINK( this, SvxFrameWindow_Impl, SelectHdl ) );
2199  CalcSizeValueSet();
2200 
2201  mxFrameSet->SetHelpId( HID_POPUP_FRAME );
2202  mxFrameSet->SetAccessibleName( SvxResId(RID_SVXSTR_FRAME) );
2203 }
2204 
2205 namespace {
2206 
2207 enum class FrmValidFlags {
2208  NONE = 0x00,
2209  Left = 0x01,
2210  Right = 0x02,
2211  Top = 0x04,
2212  Bottom = 0x08,
2213  HInner = 0x10,
2214  VInner = 0x20,
2215  AllMask = 0x3f,
2216 };
2217 
2218 }
2219 
2220 namespace o3tl {
2221  template<> struct typed_flags<FrmValidFlags> : is_typed_flags<FrmValidFlags, 0x3f> {};
2222 }
2223 
2224 // By default unset lines remain unchanged.
2225 // Via Shift unset lines are reset
2226 
2227 IMPL_LINK_NOARG(SvxFrameWindow_Impl, SelectHdl, ValueSet*, void)
2228 {
2229  SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
2230  SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
2231  SvxBorderLine theDefLine;
2232  SvxBorderLine *pLeft = nullptr,
2233  *pRight = nullptr,
2234  *pTop = nullptr,
2235  *pBottom = nullptr;
2236  sal_uInt16 nSel = mxFrameSet->GetSelectedItemId();
2237  sal_uInt16 nModifier = mxFrameSet->GetModifier();
2238  FrmValidFlags nValidFlags = FrmValidFlags::NONE;
2239 
2240  theDefLine.GuessLinesWidths(theDefLine.GetBorderLineStyle(),
2242  switch ( nSel )
2243  {
2244  case 1: nValidFlags |= FrmValidFlags::AllMask;
2245  break; // NONE
2246  case 2: pLeft = &theDefLine;
2247  nValidFlags |= FrmValidFlags::Left;
2248  break; // LEFT
2249  case 3: pRight = &theDefLine;
2250  nValidFlags |= FrmValidFlags::Right;
2251  break; // RIGHT
2252  case 4: pLeft = pRight = &theDefLine;
2253  nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left;
2254  break; // LEFTRIGHT
2255  case 5: pTop = &theDefLine;
2256  nValidFlags |= FrmValidFlags::Top;
2257  break; // TOP
2258  case 6: pBottom = &theDefLine;
2259  nValidFlags |= FrmValidFlags::Bottom;
2260  break; // BOTTOM
2261  case 7: pTop = pBottom = &theDefLine;
2262  nValidFlags |= FrmValidFlags::Bottom|FrmValidFlags::Top;
2263  break; // TOPBOTTOM
2264  case 8: pLeft = pRight = pTop = pBottom = &theDefLine;
2265  nValidFlags |= FrmValidFlags::Left | FrmValidFlags::Right | FrmValidFlags::Top | FrmValidFlags::Bottom;
2266  break; // OUTER
2267 
2268  // Inner Table:
2269  case 9: // HOR
2270  pTop = pBottom = &theDefLine;
2271  aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI );
2272  aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::VERT );
2273  nValidFlags |= FrmValidFlags::HInner|FrmValidFlags::Top|FrmValidFlags::Bottom;
2274  break;
2275 
2276  case 10: // HORINNER
2277  pLeft = pRight = pTop = pBottom = &theDefLine;
2278  aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI );
2279  aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::VERT );
2280  nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left|FrmValidFlags::HInner|FrmValidFlags::Top|FrmValidFlags::Bottom;
2281  break;
2282 
2283  case 11: // VERINNER
2284  pLeft = pRight = pTop = pBottom = &theDefLine;
2285  aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::HORI );
2286  aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::VERT );
2287  nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left|FrmValidFlags::VInner|FrmValidFlags::Top|FrmValidFlags::Bottom;
2288  break;
2289 
2290  case 12: // ALL
2291  pLeft = pRight = pTop = pBottom = &theDefLine;
2292  aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI );
2293  aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::VERT );
2294  nValidFlags |= FrmValidFlags::AllMask;
2295  break;
2296 
2297  default:
2298  break;
2299  }
2300  aBorderOuter.SetLine( pLeft, SvxBoxItemLine::LEFT );
2301  aBorderOuter.SetLine( pRight, SvxBoxItemLine::RIGHT );
2302  aBorderOuter.SetLine( pTop, SvxBoxItemLine::TOP );
2303  aBorderOuter.SetLine( pBottom, SvxBoxItemLine::BOTTOM );
2304 
2305  if(nModifier == KEY_SHIFT)
2306  nValidFlags |= FrmValidFlags::AllMask;
2307  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP, bool(nValidFlags&FrmValidFlags::Top ));
2308  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM, bool(nValidFlags&FrmValidFlags::Bottom ));
2309  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT, bool(nValidFlags&FrmValidFlags::Left));
2310  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT, bool(nValidFlags&FrmValidFlags::Right ));
2311  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI, bool(nValidFlags&FrmValidFlags::HInner ));
2312  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT, bool(nValidFlags&FrmValidFlags::VInner));
2313  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE );
2314  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false );
2315 
2316  Any a;
2317  Sequence< PropertyValue > aArgs( 2 );
2318  aArgs[0].Name = "OuterBorder";
2319  aBorderOuter.QueryValue( a );
2320  aArgs[0].Value = a;
2321  aArgs[1].Name = "InnerBorder";
2322  aBorderInner.QueryValue( a );
2323  aArgs[1].Value = a;
2324 
2325  if (mxFrameSet)
2326  {
2327  /* #i33380# Moved the following line above the Dispatch() call.
2328  This instance may be deleted in the meantime (i.e. when a dialog is opened
2329  while in Dispatch()), accessing members will crash in this case. */
2330  mxFrameSet->SetNoSelection();
2331  }
2332 
2333  mxControl->dispatchCommand( ".uno:SetBorderStyle", aArgs );
2334 
2335  mxControl->EndPopupMode();
2336 }
2337 
2338 void SvxFrameWindow_Impl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
2339 {
2340  if ( rEvent.FeatureURL.Complete == ".uno:BorderReducedMode" )
2341  {
2342  bool bValue;
2343  if ( rEvent.State >>= bValue )
2344  {
2345  bParagraphMode = bValue;
2346  //initial calls mustn't insert or remove elements
2347  if(mxFrameSet->GetItemCount())
2348  {
2349  bool bTableMode = ( mxFrameSet->GetItemCount() == 12 );
2350  bool bResize = false;
2351 
2352  if ( bTableMode && bParagraphMode )
2353  {
2354  for ( sal_uInt16 i = 9; i < 13; i++ )
2355  mxFrameSet->RemoveItem(i);
2356  bResize = true;
2357  }
2358  else if ( !bTableMode && !bParagraphMode )
2359  {
2360  for ( sal_uInt16 i = 9; i < 13; i++ )
2361  mxFrameSet->InsertItem(i, Image(aImgVec[i-1]));
2362  bResize = true;
2363  }
2364 
2365  if ( bResize )
2366  {
2367  CalcSizeValueSet();
2368  }
2369  }
2370  }
2371  }
2372 }
2373 
2374 void SvxFrameWindow_Impl::CalcSizeValueSet()
2375 {
2376  weld::DrawingArea* pDrawingArea = mxFrameSet->GetDrawingArea();
2377  const OutputDevice& rDevice = pDrawingArea->get_ref_device();
2378  Size aItemSize( 20 * rDevice.GetDPIScaleFactor(), 20 * rDevice.GetDPIScaleFactor() );
2379  Size aSize = mxFrameSet->CalcWindowSizePixel( aItemSize );
2380  pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
2381  mxFrameSet->SetOutputSizePixel(aSize);
2382 }
2383 
2384 void SvxFrameWindow_Impl::InitImageList()
2385 {
2386  aImgVec.clear();
2387  aImgVec.emplace_back(RID_SVXBMP_FRAME1);
2388  aImgVec.emplace_back(RID_SVXBMP_FRAME2);
2389  aImgVec.emplace_back(RID_SVXBMP_FRAME3);
2390  aImgVec.emplace_back(RID_SVXBMP_FRAME4);
2391  aImgVec.emplace_back(RID_SVXBMP_FRAME5);
2392  aImgVec.emplace_back(RID_SVXBMP_FRAME6);
2393  aImgVec.emplace_back(RID_SVXBMP_FRAME7);
2394  aImgVec.emplace_back(RID_SVXBMP_FRAME8);
2395  aImgVec.emplace_back(RID_SVXBMP_FRAME9);
2396  aImgVec.emplace_back(RID_SVXBMP_FRAME10);
2397  aImgVec.emplace_back(RID_SVXBMP_FRAME11);
2398  aImgVec.emplace_back(RID_SVXBMP_FRAME12);
2399 }
2400 
2401 static Color lcl_mediumColor( Color aMain, Color /*aDefault*/ )
2402 {
2403  return SvxBorderLine::threeDMediumColor( aMain );
2404 }
2405 
2406 SvxLineWindow_Impl::SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent)
2407  : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/floatingframeborder.ui", "FloatingFrameBorder")
2408  , m_xControl(pControl)
2409  , m_xLineStyleLb(new LineListBox)
2410  , m_xLineStyleLbWin(new weld::CustomWeld(*m_xBuilder, "valueset", *m_xLineStyleLb))
2411  , m_bIsWriter(false)
2412 {
2413  try
2414  {
2415  Reference< lang::XServiceInfo > xServices(mxFrame->getController()->getModel(), UNO_QUERY_THROW);
2416  m_bIsWriter = xServices->supportsService("com.sun.star.text.TextDocument");
2417  }
2418  catch(const uno::Exception& )
2419  {
2420  }
2421 
2422  m_xLineStyleLb->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) );
2423 
2424  m_xLineStyleLb->SetSourceUnit( FieldUnit::TWIP );
2425  m_xLineStyleLb->SetNone( comphelper::LibreOfficeKit::isActive() ? SvxResId(RID_SVXSTR_INVISIBLE)
2426  :SvxResId(RID_SVXSTR_NONE) );
2427 
2428  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::SOLID ), SvxBorderLineStyle::SOLID );
2429  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DOTTED ), SvxBorderLineStyle::DOTTED );
2430  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DASHED ), SvxBorderLineStyle::DASHED );
2431 
2432  // Double lines
2433  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DOUBLE ), SvxBorderLineStyle::DOUBLE );
2434  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_SMALLGAP ), SvxBorderLineStyle::THINTHICK_SMALLGAP, 20 );
2435  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_MEDIUMGAP ), SvxBorderLineStyle::THINTHICK_MEDIUMGAP );
2436  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_LARGEGAP ), SvxBorderLineStyle::THINTHICK_LARGEGAP );
2437  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_SMALLGAP ), SvxBorderLineStyle::THICKTHIN_SMALLGAP, 20 );
2438  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_MEDIUMGAP ), SvxBorderLineStyle::THICKTHIN_MEDIUMGAP );
2439  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_LARGEGAP ), SvxBorderLineStyle::THICKTHIN_LARGEGAP );
2440 
2441  // Engraved / Embossed
2442  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::EMBOSSED ), SvxBorderLineStyle::EMBOSSED, 15,
2443  &SvxBorderLine::threeDLightColor, &SvxBorderLine::threeDDarkColor,
2444  &lcl_mediumColor );
2445  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::ENGRAVED ), SvxBorderLineStyle::ENGRAVED, 15,
2446  &SvxBorderLine::threeDDarkColor, &SvxBorderLine::threeDLightColor,
2447  &lcl_mediumColor );
2448 
2449  // Inset / Outset
2450  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::OUTSET ), SvxBorderLineStyle::OUTSET, 10,
2451  &SvxBorderLine::lightColor, &SvxBorderLine::darkColor );
2452  m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::INSET ), SvxBorderLineStyle::INSET, 10,
2453  &SvxBorderLine::darkColor, &SvxBorderLine::lightColor );
2454  Size aSize = m_xLineStyleLb->SetWidth( 20 ); // 1pt by default
2455 
2456  m_xLineStyleLb->SetSelectHdl( LINK( this, SvxLineWindow_Impl, SelectHdl ) );
2457 
2458  m_xContainer->set_help_id(HID_POPUP_LINE);
2459 
2460  aSize.AdjustWidth(6);
2461  aSize.AdjustHeight(6);
2462  aSize = m_xLineStyleLb->CalcWindowSizePixel(aSize);
2463  m_xLineStyleLb->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
2464  m_xLineStyleLb->SetOutputSizePixel(aSize);
2465 }
2466 
2467 IMPL_LINK_NOARG(SvxLineWindow_Impl, SelectHdl, ValueSet*, void)
2468 {
2469  SvxLineItem aLineItem( SID_FRAME_LINESTYLE );
2470  SvxBorderLineStyle nStyle = m_xLineStyleLb->GetSelectEntryStyle();
2471 
2472  if ( m_xLineStyleLb->GetSelectItemPos( ) > 0 )
2473  {
2474  SvxBorderLine aTmp;
2475  aTmp.SetBorderLineStyle( nStyle );
2476  aTmp.SetWidth( 20 ); // TODO Make it depend on a width field
2477  aLineItem.SetLine( &aTmp );
2478  }
2479  else
2480  aLineItem.SetLine( nullptr );
2481 
2482  Any a;
2483  Sequence< PropertyValue > aArgs( 1 );
2484  aArgs[0].Name = "LineStyle";
2485  aLineItem.QueryValue( a, m_bIsWriter ? CONVERT_TWIPS : 0 );
2486  aArgs[0].Value = a;
2487 
2488  m_xControl->dispatchCommand( ".uno:LineStyle", aArgs );
2489 
2490  m_xControl->EndPopupMode();
2491 }
2492 
2494  const Reference< XDispatchProvider >& rDispatchProvider,
2495  sal_uInt16 nSlotId, // Family-ID
2496  const OUString& rCommand, // .uno: command bound to this item
2497  SvxStyleToolBoxControl& rTbxCtl ) // controller instance, which the item is assigned to.
2498  : SfxStatusListener( rDispatchProvider, nSlotId, rCommand ),
2499  rControl( rTbxCtl )
2500 {
2501 }
2502 
2504  SfxItemState eState, const SfxPoolItem* pState )
2505 {
2506  switch ( GetId() )
2507  {
2508  case SID_STYLE_FAMILY1:
2509  case SID_STYLE_FAMILY2:
2510  case SID_STYLE_FAMILY3:
2511  case SID_STYLE_FAMILY4:
2512  case SID_STYLE_FAMILY5:
2513  {
2514  const sal_uInt16 nIdx = GetId() - SID_STYLE_FAMILY_START;
2515 
2516  if ( SfxItemState::DEFAULT == eState )
2517  {
2518  const SfxTemplateItem* pStateItem =
2519  dynamic_cast<const SfxTemplateItem*>( pState );
2520  DBG_ASSERT( pStateItem != nullptr, "SfxTemplateItem expected" );
2521  rControl.SetFamilyState( nIdx, pStateItem );
2522  }
2523  else
2524  rControl.SetFamilyState( nIdx, nullptr );
2525  break;
2526  }
2527  }
2528 }
2529 
2531 {
2532  OUString aClearForm;
2533  OUString aMore;
2534  ::std::vector< OUString > aDefaultStyles;
2537 
2539  std::unique_ptr<SvxStyleBox_Base> m_xWeldBox;
2540  SvxStyleBox_Base* m_pBox;
2541 
2543  :aClearForm ( SvxResId( RID_SVXSTR_CLEARFORM ) )
2544  ,aMore ( SvxResId( RID_SVXSTR_MORE_STYLES ) )
2545  ,bSpecModeWriter ( false )
2546  ,bSpecModeCalc ( false )
2547  ,m_pBox ( nullptr )
2548  {
2549 
2550 
2551  }
2553  {
2554  aDefaultStyles.clear();
2555 
2556  //now convert the default style names to the localized names
2557  try
2558  {
2559  Reference< style::XStyleFamiliesSupplier > xStylesSupplier( xModel, UNO_QUERY_THROW );
2560  Reference< lang::XServiceInfo > xServices( xModel, UNO_QUERY_THROW );
2561  bSpecModeWriter = xServices->supportsService("com.sun.star.text.TextDocument");
2562  if(bSpecModeWriter)
2563  {
2565  xStylesSupplier->getStyleFamilies()->getByName("ParagraphStyles") >>=
2566  xParaStyles;
2567  static const std::vector<OUString> aWriterStyles =
2568  {
2569  "Standard",
2570  "Text body",
2571  "Title",
2572  "Subtitle",
2573  "Heading 1",
2574  "Heading 2",
2575  "Heading 3",
2576  "Quotations"
2577  };
2578  for( const OUString& aStyle: aWriterStyles )
2579  {
2580  try
2581  {
2583  xParaStyles->getByName( aStyle ) >>= xStyle;
2584  OUString sName;
2585  xStyle->getPropertyValue("DisplayName") >>= sName;
2586  if( !sName.isEmpty() )
2587  aDefaultStyles.push_back(sName);
2588  }
2589  catch( const uno::Exception& )
2590  {}
2591  }
2592 
2593  }
2594  else if( (
2595  bSpecModeCalc = xServices->supportsService(
2596  "com.sun.star.sheet.SpreadsheetDocument")))
2597  {
2598  static const char* aCalcStyles[] =
2599  {
2600  "Default",
2601  "Heading1",
2602  "Result",
2603  "Result2"
2604  };
2606  xStylesSupplier->getStyleFamilies()->getByName("CellStyles") >>= xCellStyles;
2607  for(const char* pCalcStyle : aCalcStyles)
2608  {
2609  try
2610  {
2611  const OUString sStyleName( OUString::createFromAscii( pCalcStyle ) );
2612  if( xCellStyles->hasByName( sStyleName ) )
2613  {
2614  Reference< beans::XPropertySet > xStyle( xCellStyles->getByName( sStyleName), UNO_QUERY_THROW );
2615  OUString sName;
2616  xStyle->getPropertyValue("DisplayName") >>= sName;
2617  if( !sName.isEmpty() )
2618  aDefaultStyles.push_back(sName);
2619  }
2620  }
2621  catch( const uno::Exception& )
2622  {}
2623  }
2624  }
2625  }
2626  catch(const uno::Exception& )
2627  {
2628  OSL_FAIL("error while initializing style names");
2629  }
2630  }
2631 };
2632 
2633 // mapping table from bound items. BE CAREFUL this table must be in the
2634 // same order as the uno commands bound to the slots SID_STYLE_FAMILY1..n
2635 // MAX_FAMILIES must also be correctly set!
2637 {
2638  ".uno:CharStyle",
2639  ".uno:ParaStyle",
2640  ".uno:FrameStyle",
2641  ".uno:PageStyle",
2642  ".uno:TemplateFamily5"
2643 };
2644 
2646  : pImpl(new Impl)
2647  , pStyleSheetPool(nullptr)
2648  , nActFamily(0xffff)
2649 {
2650  for (sal_uInt16 i = 0; i < MAX_FAMILIES; ++i)
2651  {
2652  pBoundItems[i] = nullptr;
2653  m_xBoundItems[i].clear();
2654  pFamilyState[i] = nullptr;
2655  }
2656 }
2657 
2659 {
2660 }
2661 
2662 void SAL_CALL SvxStyleToolBoxControl::initialize(const Sequence<Any>& rArguments)
2663 {
2665 
2666  // After initialize we should have a valid frame member where we can retrieve our
2667  // dispatch provider.
2668  if ( m_xFrame.is() )
2669  {
2670  pImpl->InitializeStyles(m_xFrame->getController()->getModel());
2671  Reference< XDispatchProvider > xDispatchProvider( m_xFrame->getController(), UNO_QUERY );
2672  for ( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
2673  {
2674  pBoundItems[i] = new SfxStyleControllerItem_Impl( xDispatchProvider,
2675  SID_STYLE_FAMILY_START + i,
2676  OUString::createFromAscii( StyleSlotToStyleCommand[i] ),
2677  *this );
2678  m_xBoundItems[i].set( static_cast< OWeakObject* >( pBoundItems[i] ), UNO_QUERY );
2679  pFamilyState[i] = nullptr;
2680  }
2681  }
2682 }
2683 
2684 // XComponent
2686 {
2688 
2689  SolarMutexGuard aSolarMutexGuard;
2690  pImpl->m_xVclBox.disposeAndClear();
2691  pImpl->m_xWeldBox.reset();
2692  pImpl->m_pBox = nullptr;
2693 
2694  for (SfxStyleControllerItem_Impl* pBoundItem : pBoundItems)
2695  {
2696  if (!pBoundItem)
2697  continue;
2698  pBoundItem->UnBind();
2699  }
2700  unbindListener();
2701 
2702  for( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
2703  {
2704  if ( m_xBoundItems[i].is() )
2705  {
2706  try
2707  {
2708  m_xBoundItems[i]->dispose();
2709  }
2710  catch ( Exception& )
2711  {
2712  }
2713 
2714  m_xBoundItems[i].clear();
2715  pBoundItems[i] = nullptr;
2716  }
2717  pFamilyState[i].reset();
2718  }
2719  pStyleSheetPool = nullptr;
2720  pImpl.reset();
2721 }
2722 
2724 {
2725  return "com.sun.star.comp.svx.StyleToolBoxControl";
2726 }
2727 
2728 sal_Bool SvxStyleToolBoxControl::supportsService( const OUString& rServiceName )
2729 {
2730  return cppu::supportsService( this, rServiceName );
2731 }
2732 
2734 {
2735  return { "com.sun.star.frame.ToolbarController" };
2736 }
2737 
2738 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
2740  css::uno::XComponentContext*,
2741  css::uno::Sequence<css::uno::Any> const & )
2742 {
2743  return cppu::acquire( new SvxStyleToolBoxControl() );
2744 }
2745 
2747 {
2748  for (SfxStyleControllerItem_Impl* pBoundItem : pBoundItems)
2749  pBoundItem->ReBind();
2750  bindListener();
2751 }
2752 
2754 {
2755  switch ( nActFamily-1 + SID_STYLE_FAMILY_START )
2756  {
2757  case SID_STYLE_FAMILY1: return SfxStyleFamily::Char;
2758  case SID_STYLE_FAMILY2: return SfxStyleFamily::Para;
2759  case SID_STYLE_FAMILY3: return SfxStyleFamily::Frame;
2760  case SID_STYLE_FAMILY4: return SfxStyleFamily::Page;
2761  case SID_STYLE_FAMILY5: return SfxStyleFamily::Pseudo;
2762  default:
2763  OSL_FAIL( "unknown style family" );
2764  break;
2765  }
2766  return SfxStyleFamily::Para;
2767 }
2768 
2770 {
2771  SvxStyleBox_Base* pBox = pImpl->m_pBox;
2772 
2773  DBG_ASSERT( pStyleSheetPool, "StyleSheetPool not found!" );
2774  DBG_ASSERT( pBox, "Control not found!" );
2775 
2776  if ( pStyleSheetPool && pBox && nActFamily!=0xffff )
2777  {
2778  const SfxStyleFamily eFamily = GetActFamily();
2779  SfxStyleSheetBase* pStyle = nullptr;
2780  bool bDoFill = false;
2781 
2782  auto xIter = pStyleSheetPool->CreateIterator(eFamily, SfxStyleSearchBits::Used);
2783  sal_uInt16 nCount = xIter->Count();
2784 
2785  // Check whether fill is necessary
2786  pStyle = xIter->First();
2789  if ( nCount != pBox->get_count() )
2790  {
2791  bDoFill = true;
2792  }
2793  else
2794  {
2795  sal_uInt16 i= 0;
2796  while ( pStyle && !bDoFill )
2797  {
2798  bDoFill = ( pBox->get_text(i) != pStyle->GetName() );
2799  pStyle = xIter->Next();
2800  i++;
2801  }
2802  }
2803 
2804  if ( bDoFill )
2805  {
2806  OUString aStrSel(pBox->get_active_text());
2807  pBox->freeze();
2808  pBox->clear();
2809 
2810  std::vector<OUString> aStyles;
2811 
2812  {
2813  pStyle = xIter->Next();
2814 
2815  if( pImpl->bSpecModeWriter || pImpl->bSpecModeCalc )
2816  {
2817  while ( pStyle )
2818  {
2819  // sort out default styles
2820  bool bInsert = true;
2821  OUString aName( pStyle->GetName() );
2822  for( auto const & _i: pImpl->aDefaultStyles )
2823  {
2824  if( _i == aName )
2825  {
2826  bInsert = false;
2827  break;
2828  }
2829  }
2830 
2831  if( bInsert )
2832  aStyles.push_back(aName);
2833  pStyle = xIter->Next();
2834  }
2835  }
2836  else
2837  {
2838  while ( pStyle )
2839  {
2840  aStyles.push_back(pStyle->GetName());
2841  pStyle = xIter->Next();
2842  }
2843  }
2844  }
2845 
2846  if (pImpl->bSpecModeWriter || pImpl->bSpecModeCalc)
2847  {
2848  pBox->append_text(pImpl->aClearForm);
2849  pBox->insert_separator(1, "separator");
2850 
2851  // insert default styles
2852  for (const auto &rStyle : pImpl->aDefaultStyles)
2853  pBox->append_text(rStyle);
2854  }
2855 
2856  std::sort(aStyles.begin(), aStyles.end());
2857 
2858  for (const auto& rStyle : aStyles)
2859  pBox->append_text(rStyle);
2860 
2861  if (pImpl->bSpecModeWriter || pImpl->bSpecModeCalc)
2862  pBox->append_text(pImpl->aMore);
2863 
2864  pBox->thaw();
2865  pBox->set_active_or_entry_text(aStrSel);
2866  pBox->SetFamily( eFamily );
2867  }
2868  }
2869 }
2870 
2871 void SvxStyleToolBoxControl::SelectStyle( const OUString& rStyleName )
2872 {
2873  SvxStyleBox_Base* pBox = pImpl->m_pBox;
2874  DBG_ASSERT( pBox, "Control not found!" );
2875 
2876  if ( pBox )
2877  {
2878  OUString aStrSel(pBox->get_active_text());
2879 
2880  if ( !rStyleName.isEmpty() )
2881  {
2882  if ( rStyleName != aStrSel )
2883  pBox->set_active_or_entry_text( rStyleName );
2884  }
2885  else
2886  pBox->set_active(-1);
2887  pBox->save_value();
2888  }
2889 }
2890 
2892 {
2893  SfxStyleSheetBasePool* pPool = nullptr;
2894  SfxObjectShell* pDocShell = SfxObjectShell::Current();
2895 
2896  if ( pDocShell )
2897  pPool = pDocShell->GetStyleSheetPool();
2898 
2899  sal_uInt16 i;
2900  for ( i=0; i<MAX_FAMILIES; i++ )
2901  if( pFamilyState[i] )
2902  break;
2903 
2904  if ( i==MAX_FAMILIES || !pPool )
2905  {
2906  pStyleSheetPool = pPool;
2907  return;
2908  }
2909 
2910 
2911  const SfxTemplateItem* pItem = nullptr;
2912 
2913  if ( nActFamily == 0xffff || nullptr == (pItem = pFamilyState[nActFamily-1].get()) )
2914  // Current range not within allowed ranges or default
2915  {
2916  pStyleSheetPool = pPool;
2917  nActFamily = 2;
2918 
2919  pItem = pFamilyState[nActFamily-1].get();
2920  if ( !pItem )
2921  {
2922  nActFamily++;
2923  pItem = pFamilyState[nActFamily-1].get();
2924  }
2925  }
2926  else if ( pPool != pStyleSheetPool )
2927  pStyleSheetPool = pPool;
2928 
2929  FillStyleBox(); // Decides by itself whether Fill is needed
2930 
2931  if ( pItem )
2932  SelectStyle( pItem->GetStyleName() );
2933 }
2934 
2936  const SfxTemplateItem* pItem )
2937 {
2938  pFamilyState[nIdx].reset( pItem == nullptr ? nullptr : new SfxTemplateItem( *pItem ) );
2939  Update();
2940 }
2941 
2942 void SvxStyleToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
2943 {
2944  SolarMutexGuard aGuard;
2945 
2946  if (m_pToolbar)
2947  m_pToolbar->set_item_sensitive(m_aCommandURL.toUtf8(), rEvent.IsEnabled);
2948  else
2949  {
2950  ToolBox* pToolBox = nullptr;
2951  sal_uInt16 nId = 0;
2952  if (!getToolboxId( nId, &pToolBox ) )
2953  return;
2954  pToolBox->EnableItem( nId, rEvent.IsEnabled );
2955  }
2956 
2957  if (rEvent.IsEnabled)
2958  Update();
2959 }
2960 
2961 css::uno::Reference<css::awt::XWindow> SvxStyleToolBoxControl::createItemWindow(const css::uno::Reference< css::awt::XWindow>& rParent)
2962 {
2963  uno::Reference< awt::XWindow > xItemWindow;
2964 
2965  if (m_pBuilder)
2966  {
2967  SolarMutexGuard aSolarMutexGuard;
2968 
2969  std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("applystyle"));
2970 
2971  xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
2972 
2973  pImpl->m_xWeldBox.reset(new SvxStyleBox_Base(std::move(xWidget),
2974  ".uno:StyleApply",
2975  SfxStyleFamily::Para,
2976  Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
2977  m_xFrame,
2978  pImpl->aClearForm,
2979  pImpl->aMore,
2980  pImpl->bSpecModeWriter || pImpl->bSpecModeCalc, *this));
2981  pImpl->m_pBox = pImpl->m_xWeldBox.get();
2982  }
2983  else
2984  {
2985  VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent);
2986  if ( pParent )
2987  {
2988  SolarMutexGuard aSolarMutexGuard;
2989 
2990  pImpl->m_xVclBox = VclPtr<SvxStyleBox_Impl>::Create(pParent,
2991  ".uno:StyleApply",
2992  SfxStyleFamily::Para,
2993  Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
2994  m_xFrame,
2995  pImpl->aClearForm,
2996  pImpl->aMore,
2997  pImpl->bSpecModeWriter || pImpl->bSpecModeCalc, *this);
2998  pImpl->m_pBox = pImpl->m_xVclBox.get();
2999  xItemWindow = VCLUnoHelper::GetInterface(pImpl->m_xVclBox);
3000  }
3001  }
3002 
3003  if (pImpl->m_pBox && !pImpl->aDefaultStyles.empty())
3004  pImpl->m_pBox->SetDefaultStyle(pImpl->aDefaultStyles[0]);
3005 
3006  return xItemWindow;
3007 }
3008 
3009 SvxFontNameToolBoxControl::SvxFontNameToolBoxControl()
3010  : m_pBox(nullptr)
3011 {
3012 }
3013 
3014 void SvxFontNameBox_Base::statusChanged_Impl( const css::frame::FeatureStateEvent& rEvent )
3015 {
3016  if ( !rEvent.IsEnabled )
3017  {
3018  set_sensitive(false);
3019  Update( nullptr );
3020  }
3021  else
3022  {
3023  set_sensitive(true);
3024 
3025  css::awt::FontDescriptor aFontDesc;
3026  if ( rEvent.State >>= aFontDesc )
3027  Update(&aFontDesc);
3028  else
3029  set_active_or_entry_text("");
3030  m_xWidget->save_value();
3031  }
3032 }
3033 
3034 void SvxFontNameToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
3035 {
3036  SolarMutexGuard aGuard;
3037  m_pBox->statusChanged_Impl(rEvent);
3038 
3039  if (m_pToolbar)
3040  m_pToolbar->set_item_sensitive(m_aCommandURL.toUtf8(), rEvent.IsEnabled);
3041  else
3042  {
3043  ToolBox* pToolBox = nullptr;
3044  sal_uInt16 nId = 0;
3045  if (!getToolboxId( nId, &pToolBox ) )
3046  return;
3047  pToolBox->EnableItem( nId, rEvent.IsEnabled );
3048  }
3049 }
3050 
3051 css::uno::Reference<css::awt::XWindow> SvxFontNameToolBoxControl::createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent)
3052 {
3053  uno::Reference< awt::XWindow > xItemWindow;
3054 
3055  if (m_pBuilder)
3056  {
3057  SolarMutexGuard aSolarMutexGuard;
3058 
3059  std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("fontnamecombobox"));
3060 
3061  xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
3062 
3063  m_xWeldBox.reset(new SvxFontNameBox_Base(std::move(xWidget),
3064  Reference<XDispatchProvider>(m_xFrame->getController(), UNO_QUERY),
3065  m_xFrame, *this));
3066  m_pBox = m_xWeldBox.get();
3067  }
3068  else
3069  {
3070  VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent);
3071  if ( pParent )
3072  {
3073  SolarMutexGuard aSolarMutexGuard;
3074  m_xVclBox = VclPtr<SvxFontNameBox_Impl>::Create(pParent,
3075  Reference<XDispatchProvider>(m_xFrame->getController(), UNO_QUERY),
3076  m_xFrame, *this);
3077  m_pBox = m_xVclBox.get();
3078  xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox);
3079  }
3080  }
3081 
3082  return xItemWindow;
3083 }
3084 
3085 void SvxFontNameToolBoxControl::dispose()
3086 {
3087  ToolboxController::dispose();
3088 
3089  SolarMutexGuard aSolarMutexGuard;
3090  m_xVclBox.disposeAndClear();
3091  m_xWeldBox.reset();
3092  m_pBox = nullptr;
3093 }
3094 
3095 OUString SvxFontNameToolBoxControl::getImplementationName()
3096 {
3097  return "com.sun.star.comp.svx.FontNameToolBoxControl";
3098 }
3099 
3100 sal_Bool SvxFontNameToolBoxControl::supportsService( const OUString& rServiceName )
3101 {
3102  return cppu::supportsService( this, rServiceName );
3103 }
3104 
3105 css::uno::Sequence< OUString > SvxFontNameToolBoxControl::getSupportedServiceNames()
3106 {
3107  return { "com.sun.star.frame.ToolbarController" };
3108 }
3109 
3110 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
3112  css::uno::XComponentContext*,
3113  css::uno::Sequence<css::uno::Any> const & )
3114 {
3115  return cppu::acquire( new SvxFontNameToolBoxControl() );
3116 }
3117 
3118 SvxColorToolBoxControl::SvxColorToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext ) :
3119  ImplInheritanceHelper( rContext, nullptr, OUString() ),
3120  m_bSplitButton(true),
3121  m_nSlotId(0),
3122  m_aColorSelectFunction(PaletteManager::DispatchColorCommand)
3123 {
3124 }
3125 
3126 namespace {
3127 
3128 sal_uInt16 MapCommandToSlotId(const OUString& rCommand)
3129 {
3130  if (rCommand == ".uno:Color")
3131  return SID_ATTR_CHAR_COLOR;
3132  else if (rCommand == ".uno:FontColor")
3133  return SID_ATTR_CHAR_COLOR2;
3134  else if (rCommand == ".uno:BackColor")
3135  return SID_ATTR_CHAR_COLOR_BACKGROUND;
3136  else if (rCommand == ".uno:CharBackColor")
3137  return SID_ATTR_CHAR_BACK_COLOR;
3138  else if (rCommand == ".uno:BackgroundColor")
3139  return SID_BACKGROUND_COLOR;
3140  else if (rCommand == ".uno:TableCellBackgroundColor")
3141  return SID_TABLE_CELL_BACKGROUND_COLOR;
3142  else if (rCommand == ".uno:Extrusion3DColor")
3143  return SID_EXTRUSION_3D_COLOR;
3144  else if (rCommand == ".uno:XLineColor")
3145  return SID_ATTR_LINE_COLOR;
3146  else if (rCommand == ".uno:FillColor")
3147  return SID_ATTR_FILL_COLOR;
3148  else if (rCommand == ".uno:FrameLineColor")
3149  return SID_FRAME_LINECOLOR;
3150 
3151  SAL_WARN("svx.tbxcrtls", "Unknown color command: " << rCommand);
3152  return 0;
3153 }
3154 
3155 }
3156 
3157 void SvxColorToolBoxControl::initialize( const css::uno::Sequence<css::uno::Any>& rArguments )
3158 {
3159  PopupWindowController::initialize( rArguments );
3160 
3161  m_nSlotId = MapCommandToSlotId( m_aCommandURL );
3162 
3163  if ( m_nSlotId == SID_ATTR_LINE_COLOR || m_nSlotId == SID_ATTR_FILL_COLOR ||
3164  m_nSlotId == SID_FRAME_LINECOLOR || m_nSlotId == SID_BACKGROUND_COLOR )
3165  {
3166  // Sidebar uses wide buttons for those.
3167  m_bSplitButton = !m_bSidebar;
3168  }
3169 
3170  auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(getCommandURL(), getModuleName());
3172 
3173  OString aId(m_aCommandURL.toUtf8());
3174 
3175  if (m_pToolbar)
3176  {
3177  mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
3178  m_pToolbar->set_item_popover(aId, mxPopoverContainer->getTopLevel());
3179  m_xBtnUpdater.reset(new svx::ToolboxButtonColorUpdater(m_nSlotId, aId, m_pToolbar, !m_bSplitButton, aCommandLabel, m_xFrame));
3180  return;
3181  }
3182 
3183  ToolBox* pToolBox = nullptr;
3184  sal_uInt16 nId = 0;
3185  if (getToolboxId(nId, &pToolBox))
3186  {
3187  m_xBtnUpdater.reset( new svx::VclToolboxButtonColorUpdater( m_nSlotId, nId, pToolBox, !m_bSplitButton, aCommandLabel, m_aCommandURL, m_xFrame ) );
3188  pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ( m_bSplitButton ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY ) );
3189  }
3190 }
3191 
3193 {
3194  PopupWindowController::update();
3195 
3196  switch( m_nSlotId )
3197  {
3198  case SID_ATTR_CHAR_COLOR2:
3199  addStatusListener( ".uno:CharColorExt");
3200  break;
3201 
3202  case SID_ATTR_CHAR_COLOR_BACKGROUND:
3203  addStatusListener( ".uno:CharBackgroundExt");
3204  break;
3205 
3206  case SID_FRAME_LINECOLOR:
3207  addStatusListener( ".uno:BorderTLBR");
3208  addStatusListener( ".uno:BorderBLTR");
3209  break;
3210  }
3211 }
3212 
3214 {
3215  if (!m_xPaletteManager)
3216  {
3217  m_xPaletteManager = std::make_shared<PaletteManager>();
3218  m_xPaletteManager->SetBtnUpdater(m_xBtnUpdater.get());
3219  }
3220 }
3221 
3223 {
3224  if (m_xPaletteManager)
3225  m_xPaletteManager->SetBtnUpdater(nullptr);
3226 }
3227 
3229 {
3230  m_aColorSelectFunction = aColorSelectFunction;
3231  if (m_xPaletteManager)
3232  m_xPaletteManager->SetColorSelectFunction(aColorSelectFunction);
3233 }
3234 
3235 std::unique_ptr<WeldToolbarPopup> SvxColorToolBoxControl::weldPopupWindow()
3236 {
3238 
3239  const css::uno::Reference<css::awt::XWindow> xParent = m_xFrame->getContainerWindow();
3240  weld::Window* pParentFrame = Application::GetFrameWeld(xParent);
3241 
3242  const OString aId(m_aCommandURL.toUtf8());
3243 
3244  auto xPopover = std::make_unique<ColorWindow>(
3245  m_aCommandURL,
3248  m_nSlotId,
3249  m_xFrame,
3250  pParentFrame,
3251  MenuOrToolMenuButton(m_pToolbar, aId),
3253 
3254  if ( m_bSplitButton )
3255  xPopover->SetSelectedHdl( LINK( this, SvxColorToolBoxControl, SelectedHdl ) );
3256 
3257  return xPopover;
3258 }
3259 
3261 {
3262  ToolBox* pToolBox = nullptr;
3263  sal_uInt16 nId = 0;
3264  if (!getToolboxId(nId, &pToolBox))
3265  return nullptr;
3266 
3267  const css::uno::Reference<css::awt::XWindow> xParent = m_xFrame->getContainerWindow();
3268  weld::Window* pParentFrame = Application::GetFrameWeld(xParent);
3269 
3271 
3272  auto xPopover = std::make_unique<ColorWindow>(
3273  m_aCommandURL,
3276  m_nSlotId,
3277  m_xFrame,
3278  pParentFrame,
3279  MenuOrToolMenuButton(this, pToolBox, nId),
3281 
3282  if ( m_bSplitButton )
3283  xPopover->SetSelectedHdl( LINK( this, SvxColorToolBoxControl, SelectedHdl ) );
3284 
3285  mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
3286  std::move(xPopover));
3287 
3288  mxInterimPopover->Show();
3289 
3290  return mxInterimPopover;
3291 }
3292 
3293 IMPL_LINK(SvxColorToolBoxControl, SelectedHdl, const NamedColor&, rColor, void)
3294 {
3295  m_xBtnUpdater->Update(rColor);
3296 }
3297 
3298 void SvxColorToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
3299 {
3300  ToolBox* pToolBox = nullptr;
3301  sal_uInt16 nId = 0;
3302  if (!getToolboxId(nId, &pToolBox) && !m_pToolbar)
3303  return;
3304 
3305  if ( rEvent.FeatureURL.Complete == m_aCommandURL )
3306  {
3307  if (m_pToolbar)
3308  m_pToolbar->set_item_sensitive(m_aCommandURL.toUtf8(), rEvent.IsEnabled);
3309  else
3310  pToolBox->EnableItem( nId, rEvent.IsEnabled );
3311  }
3312 
3313  bool bValue;
3314  if ( !m_bSplitButton )
3315  {
3316  m_aColorStatus.statusChanged( rEvent );
3317  m_xBtnUpdater->Update( m_aColorStatus.GetColor() );
3318  }
3319  else if ( rEvent.State >>= bValue )
3320  {
3321  if (m_pToolbar)
3322  m_pToolbar->set_item_active(m_aCommandURL.toUtf8(), bValue);
3323  else if (pToolBox)
3324  pToolBox->CheckItem( nId, bValue );
3325  }
3326 }
3327 
3328 void SvxColorToolBoxControl::execute(sal_Int16 /*nSelectModifier*/)
3329 {
3330  if ( !m_bSplitButton )
3331  {
3332  if (m_pToolbar)
3333  {
3334  // Toggle the popup also when toolbutton is activated
3335  const OString aId(m_aCommandURL.toUtf8());
3336  m_pToolbar->set_menu_item_active(aId, !m_pToolbar->get_menu_item_active(aId));
3337  }
3338  else
3339  {
3340  // Open the popup also when Enter key is pressed.
3341  createPopupWindow();
3342  }
3343  return;
3344  }
3345 
3346  OUString aCommand = m_aCommandURL;
3347  Color aColor = m_xBtnUpdater->GetCurrentColor();
3348 
3349  switch( m_nSlotId )
3350  {
3351  case SID_ATTR_CHAR_COLOR2 :
3352  aCommand = ".uno:CharColorExt";
3353  break;
3354 
3355  case SID_ATTR_CHAR_COLOR_BACKGROUND :
3356  aCommand = ".uno:CharBackgroundExt";
3357  break;
3358  }
3359 
3360  auto aArgs( comphelper::InitPropertySequence( {
3361  { m_aCommandURL.copy(5), css::uno::makeAny(aColor) }
3362  } ) );
3363  dispatchCommand( aCommand, aArgs );
3364 
3366  OUString sColorName = m_xBtnUpdater->GetCurrentColorName();
3367  m_xPaletteManager->AddRecentColor(aColor, sColorName);
3368 }
3369 
3371 {
3372  // We mark this controller as a sub-toolbar controller, so we get notified
3373  // (through updateImage method) on button image changes, and could redraw
3374  // the last used color on top of it.
3375  return true;
3376 }
3377 
3379 {
3380  m_xBtnUpdater->Update(m_xBtnUpdater->GetCurrentColor(), true);
3381 }
3382 
3384 {
3385  return OUString();
3386 }
3387 
3388 void SvxColorToolBoxControl::functionSelected( const OUString& /*rCommand*/ )
3389 {
3390 }
3391 
3393 {
3394  return "com.sun.star.comp.svx.ColorToolBoxControl";
3395 }
3396 
3398 {
3399  return { "com.sun.star.frame.ToolbarController" };
3400 }
3401 
3402 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
3404  css::uno::XComponentContext* rContext,
3405  css::uno::Sequence<css::uno::Any> const & )
3406 {
3407  return cppu::acquire( new SvxColorToolBoxControl( rContext ) );
3408 }
3409 
3410 SvxFrameToolBoxControl::SvxFrameToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rContext )
3411  : svt::PopupWindowController( rContext, nullptr, OUString() )
3412 {
3413 }
3414 
3415 void SAL_CALL SvxFrameToolBoxControl::execute(sal_Int16 /*KeyModifier*/)
3416 {
3417  if (m_pToolbar)
3418  {
3419  // Toggle the popup also when toolbutton is activated
3420  const OString aId(m_aCommandURL.toUtf8());
3421  m_pToolbar->set_menu_item_active(aId, !m_pToolbar->get_menu_item_active(aId));
3422  }
3423  else
3424  {
3425  // Open the popup also when Enter key is pressed.
3426  createPopupWindow();
3427  }
3428 }
3429 
3430 void SvxFrameToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& rArguments )
3431 {
3432  svt::PopupWindowController::initialize( rArguments );
3433 
3434  if (m_pToolbar)
3435  {
3436  mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
3437  m_pToolbar->set_item_popover(m_aCommandURL.toUtf8(), mxPopoverContainer->getTopLevel());
3438  }
3439 
3440  ToolBox* pToolBox = nullptr;
3441  sal_uInt16 nId = 0;
3442  if (getToolboxId(nId, &pToolBox))
3443  pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
3444 }
3445 
3446 std::unique_ptr<WeldToolbarPopup> SvxFrameToolBoxControl::weldPopupWindow()
3447 {
3448  if ( m_aCommandURL == ".uno:LineStyle" )
3449  return std::make_unique<SvxLineWindow_Impl>(this, m_pToolbar);
3450  return std::make_unique<SvxFrameWindow_Impl>(this, m_pToolbar);
3451 }
3452 
3453 VclPtr<vcl::Window> SvxFrameToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
3454 {
3455  if ( m_aCommandURL == ".uno:LineStyle" )
3456  {
3457  mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
3458  std::make_unique<SvxLineWindow_Impl>(this, pParent->GetFrameWeld()));
3459 
3460  mxInterimPopover->Show();
3461 
3462  mxInterimPopover->SetText(SvxResId(RID_SVXSTR_FRAME_STYLE));
3463 
3464  return mxInterimPopover;
3465  }
3466 
3467  mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
3468  std::make_unique<SvxFrameWindow_Impl>(this, pParent->GetFrameWeld()));
3469 
3470  mxInterimPopover->Show();
3471 
3472  mxInterimPopover->SetText(SvxResId(RID_SVXSTR_FRAME));
3473 
3474  return mxInterimPopover;
3475 }
3476 
3477 OUString SvxFrameToolBoxControl::getImplementationName()
3478 {
3479  return "com.sun.star.comp.svx.FrameToolBoxControl";
3480 }
3481 
3482 css::uno::Sequence< OUString > SvxFrameToolBoxControl::getSupportedServiceNames()
3483 {
3484  return { "com.sun.star.frame.ToolbarController" };
3485 }
3486 
3487 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
3489  css::uno::XComponentContext* rContext,
3490  css::uno::Sequence<css::uno::Any> const & )
3491 {
3492  return cppu::acquire( new SvxFrameToolBoxControl( rContext ) );
3493 }
3494 
3495 SvxCurrencyToolBoxControl::SvxCurrencyToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext ) :
3496  PopupWindowController( rContext, nullptr, OUString() ),
3497  m_eLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() ),
3498  m_nFormatKey( NUMBERFORMAT_ENTRY_NOT_FOUND )
3499 {
3500 }
3501 
3502 SvxCurrencyToolBoxControl::~SvxCurrencyToolBoxControl() {}
3503 
3504 namespace
3505 {
3506  class SvxCurrencyList_Impl : public WeldToolbarPopup
3507  {
3508  private:
3510  std::unique_ptr<weld::Label> m_xLabel;
3511  std::unique_ptr<weld::TreeView> m_xCurrencyLb;
3512  std::unique_ptr<weld::Button> m_xOkBtn;
3513  OUString& m_rSelectedFormat;
3514  LanguageType& m_eSelectedLanguage;
3515 
3516  std::vector<OUString> m_aFormatEntries;
3517  LanguageType m_eFormatLanguage;
3518  DECL_LINK(RowActivatedHdl, weld::TreeView&, bool);
3519  DECL_LINK(OKHdl, weld::Button&, void);
3520 
3521  virtual void GrabFocus() override;
3522 
3523  public:
3524  SvxCurrencyList_Impl(SvxCurrencyToolBoxControl* pControl, weld::Widget* pParent, OUString& rSelectedFormat, LanguageType& eSelectedLanguage)
3525  : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/currencywindow.ui", "CurrencyWindow")
3526  , m_xControl(pControl)
3527  , m_xLabel(m_xBuilder->weld_label("label"))
3528  , m_xCurrencyLb(m_xBuilder->weld_tree_view("currency"))
3529  , m_xOkBtn(m_xBuilder->weld_button("ok"))
3530  , m_rSelectedFormat(rSelectedFormat)
3531  , m_eSelectedLanguage(eSelectedLanguage)
3532  {
3533  std::vector< OUString > aList;
3534  std::vector< sal_uInt16 > aCurrencyList;
3535  const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
3536  sal_uInt16 nLen = rCurrencyTable.size();
3537 
3538  SvNumberFormatter aFormatter( m_xControl->getContext(), LANGUAGE_SYSTEM );
3539  m_eFormatLanguage = aFormatter.GetLanguage();
3540 
3541  SvxCurrencyToolBoxControl::GetCurrencySymbols( aList, true, aCurrencyList );
3542 
3543  sal_uInt16 nPos = 0, nCount = 0;
3544  sal_Int32 nSelectedPos = -1;
3545  bool bIsSymbol;
3546  NfWSStringsDtor aStringsDtor;
3547 
3548  OUString sLongestString;
3549 
3550  m_xCurrencyLb->freeze();
3551  for( const auto& rItem : aList )
3552  {
3553  sal_uInt16& rCurrencyIndex = aCurrencyList[ nCount ];
3554  if ( rCurrencyIndex < nLen )
3555  {
3556  m_xCurrencyLb->append_text(rItem);
3557 
3558  if (rItem.getLength() > sLongestString.getLength())
3559  sLongestString = rItem;
3560 
3561  const NfCurrencyEntry& aCurrencyEntry = rCurrencyTable[ rCurrencyIndex ];
3562 
3563  bIsSymbol = nPos >= nLen;
3564 
3565  sal_uInt16 nDefaultFormat = aFormatter.GetCurrencyFormatStrings( aStringsDtor, aCurrencyEntry, bIsSymbol );
3566  const OUString& rFormatStr = aStringsDtor[ nDefaultFormat ];
3567  m_aFormatEntries.push_back( rFormatStr );
3568  if( rFormatStr == m_rSelectedFormat )
3569  nSelectedPos = nPos;
3570  ++nPos;
3571  }
3572  ++nCount;
3573  }
3574  m_xCurrencyLb->thaw();
3575  // enable multiple selection enabled so we can start with nothing selected
3576  m_xCurrencyLb->set_selection_mode(SelectionMode::Multiple);
3577  m_xCurrencyLb->connect_row_activated( LINK( this, SvxCurrencyList_Impl, RowActivatedHdl ) );
3578  m_xLabel->set_label(SvxResId(RID_SVXSTR_TBLAFMT_CURRENCY));
3579  m_xCurrencyLb->select( nSelectedPos );
3580  m_xOkBtn->connect_clicked(LINK(this, SvxCurrencyList_Impl, OKHdl));
3581 
3582  // gtk will initially make a best guess depending on the first few entries, so copy the probable
3583  // longest entry to the start temporarily and force in the width at this point
3584  m_xCurrencyLb->insert_text(0, sLongestString);
3585  m_xCurrencyLb->set_size_request(m_xCurrencyLb->get_preferred_size().Width(), m_xCurrencyLb->get_height_rows(12));
3586  m_xCurrencyLb->remove(0);
3587  }
3588  };
3589 
3590  void SvxCurrencyList_Impl::GrabFocus()
3591  {
3592  m_xCurrencyLb->grab_focus();
3593  }
3594 
3595  IMPL_LINK_NOARG(SvxCurrencyList_Impl, OKHdl, weld::Button&, void)
3596  {
3597  RowActivatedHdl(*m_xCurrencyLb);
3598  }
3599 
3600  IMPL_LINK_NOARG(SvxCurrencyList_Impl, RowActivatedHdl, weld::TreeView&, bool)
3601  {
3602  if (!m_xControl.is())
3603  return true;
3604 
3605  // multiple selection enabled so we can start with nothing selected,
3606  // so force single selection after something is picked
3607  int nSelected = m_xCurrencyLb->get_selected_index();
3608  if (nSelected == -1)
3609  return true;
3610 
3611  m_xCurrencyLb->set_selection_mode(SelectionMode::Single);
3612 
3613  m_rSelectedFormat = m_aFormatEntries[nSelected];
3614  m_eSelectedLanguage = m_eFormatLanguage;
3615 
3616  m_xControl->execute(nSelected + 1);
3617 
3618  m_xControl->EndPopupMode();
3619 
3620  return true;
3621  }
3622 }
3623 
3624 void SvxCurrencyToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& rArguments )
3625 {
3626  PopupWindowController::initialize(rArguments);
3627 
3628  if (m_pToolbar)
3629  {
3630  mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
3631  m_pToolbar->set_item_popover(m_aCommandURL.toUtf8(), mxPopoverContainer->getTopLevel());
3632  return;
3633  }
3634 
3635  ToolBox* pToolBox = nullptr;
3636  sal_uInt16 nId = 0;
3637  if (getToolboxId(nId, &pToolBox) && pToolBox->GetItemCommand(nId) == m_aCommandURL)
3638  pToolBox->SetItemBits(nId, ToolBoxItemBits::DROPDOWN | pToolBox->GetItemBits(nId));
3639 }
3640 
3641 std::unique_ptr<WeldToolbarPopup> SvxCurrencyToolBoxControl::weldPopupWindow()
3642 {
3643  return std::make_unique<SvxCurrencyList_Impl>(this, m_pToolbar, m_aFormatString, m_eLanguage);
3644 }
3645 
3646 VclPtr<vcl::Window> SvxCurrencyToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
3647 {
3648  mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
3649  std::make_unique<SvxCurrencyList_Impl>(this, pParent->GetFrameWeld(), m_aFormatString, m_eLanguage));
3650 
3651  mxInterimPopover->Show();
3652 
3653  return mxInterimPopover;
3654 }
3655 
3656 void SvxCurrencyToolBoxControl::execute( sal_Int16 nSelectModifier )
3657 {
3658  sal_uInt32 nFormatKey;
3659  if (m_aFormatString.isEmpty())
3660  nFormatKey = NUMBERFORMAT_ENTRY_NOT_FOUND;
3661  else
3662  {
3663  if ( nSelectModifier > 0 )
3664  {
3665  try
3666  {
3667  uno::Reference< util::XNumberFormatsSupplier > xRef( m_xFrame->getController()->getModel(), uno::UNO_QUERY );
3668  uno::Reference< util::XNumberFormats > rxNumberFormats( xRef->getNumberFormats(), uno::UNO_SET_THROW );
3669  css::lang::Locale aLocale = LanguageTag::convertToLocale( m_eLanguage );
3670  nFormatKey = rxNumberFormats->queryKey( m_aFormatString, aLocale, false );
3671  if ( nFormatKey == NUMBERFORMAT_ENTRY_NOT_FOUND )
3672  nFormatKey = rxNumberFormats->addNew( m_aFormatString, aLocale );
3673  }
3674  catch( const uno::Exception& )
3675  {
3676  nFormatKey = m_nFormatKey;
3677  }
3678  }
3679  else
3680  nFormatKey = m_nFormatKey;
3681  }
3682 
3683  if( nFormatKey != NUMBERFORMAT_ENTRY_NOT_FOUND )
3684  {
3685  Sequence< PropertyValue > aArgs( 1 );
3686  aArgs[0].Name = "NumberFormatCurrency";
3687  aArgs[0].Value <<= nFormatKey;
3688  dispatchCommand( m_aCommandURL, aArgs );
3689  m_nFormatKey = nFormatKey;
3690  }
3691  else
3692  PopupWindowController::execute( nSelectModifier );
3693 }
3694 
3695 OUString SvxCurrencyToolBoxControl::getImplementationName()
3696 {
3697  return "com.sun.star.comp.svx.CurrencyToolBoxControl";
3698 }
3699 
3700 css::uno::Sequence<OUString> SvxCurrencyToolBoxControl::getSupportedServiceNames()
3701 {
3702  return { "com.sun.star.frame.ToolbarController" };
3703 }
3704 
3705 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
3707  css::uno::XComponentContext* rContext,
3708  css::uno::Sequence<css::uno::Any> const & )
3709 {
3710  return cppu::acquire( new SvxCurrencyToolBoxControl( rContext ) );
3711 }
3712 
3713 Reference< css::accessibility::XAccessible > SvxFontNameBox_Impl::CreateAccessible()
3714 {
3715  FillList();
3717 }
3718 
3719 //static
3720 void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector<OUString>& rList, bool bFlag,
3721  std::vector<sal_uInt16>& rCurrencyList )
3722 {
3723  rCurrencyList.clear();
3724 
3725  const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
3726  sal_uInt16 nCount = rCurrencyTable.size();
3727 
3728  sal_uInt16 nStart = 1;
3729 
3730  OUString aString( ApplyLreOrRleEmbedding( rCurrencyTable[0].GetSymbol() ) + " " );
3732  rCurrencyTable[0].GetLanguage() ) );
3733 
3734  rList.push_back( aString );
3735  rCurrencyList.push_back( sal_uInt16(-1) ); // nAuto
3736 
3737  if( bFlag )
3738  {
3739  rList.push_back( aString );
3740  rCurrencyList.push_back( 0 );
3741  ++nStart;
3742  }
3743 
3745  aCollator.loadDefaultCollator( Application::GetSettings().GetLanguageTag().getLocale(), 0 );
3746 
3747  const OUString aTwoSpace(" ");
3748 
3749  for( sal_uInt16 i = 1; i < nCount; ++i )
3750  {
3751  OUString aStr( ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol() ) );
3752  aStr += aTwoSpace;
3753  aStr += ApplyLreOrRleEmbedding( rCurrencyTable[i].GetSymbol() );
3754  aStr += aTwoSpace;
3756  rCurrencyTable[i].GetLanguage() ) );
3757 
3758  std::vector<OUString>::size_type j = nStart;
3759  for( ; j < rList.size(); ++j )
3760  if ( aCollator.compareString( aStr, rList[j] ) < 0 )
3761  break; // insert before first greater than
3762 
3763  rList.insert( rList.begin() + j, aStr );
3764  rCurrencyList.insert( rCurrencyList.begin() + j, i );
3765  }
3766 
3767  // Append ISO codes to symbol list.
3768  // XXX If this is to be changed, various other places would had to be
3769  // adapted that assume this order!
3770  std::vector<OUString>::size_type nCont = rList.size();
3771 
3772  for ( sal_uInt16 i = 1; i < nCount; ++i )
3773  {
3774  bool bInsert = true;
3775  OUString aStr( ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol() ) );
3776 
3777  std::vector<OUString>::size_type j = nCont;
3778  for ( ; j < rList.size() && bInsert; ++j )
3779  {
3780  if( rList[j] == aStr )
3781  bInsert = false;
3782  else if ( aCollator.compareString( aStr, rList[j] ) < 0 )
3783  break; // insert before first greater than
3784  }
3785  if ( bInsert )
3786  {
3787  rList.insert( rList.begin() + j, aStr );
3788  rCurrencyList.insert( rCurrencyList.begin() + j, i );
3789  }
3790  }
3791 }
3792 
3794  : mpControl(pControl)
3795 {
3796 }
3797 
3798 void ListBoxColorWrapper::operator()(const OUString& /*rCommand*/, const NamedColor& rColor)
3799 {
3800  mpControl->Selected(rColor);
3801 }
3802 
3804 {
3805  if (!m_xPaletteManager)
3806  {
3807  m_xPaletteManager = std::make_shared<PaletteManager>();
3808  m_xPaletteManager->SetColorSelectFunction(std::ref(m_aColorWrapper));
3809  }
3810 }
3811 
3812 void ColorListBox::SetSlotId(sal_uInt16 nSlotId, bool bShowNoneButton)
3813 {
3814  m_nSlotId = nSlotId;
3815  m_bShowNoneButton = bShowNoneButton;
3816  m_xButton->set_popover(nullptr);
3817  m_xColorWindow.reset();
3818  m_aSelectedColor = bShowNoneButton ? GetNoneColor() : GetAutoColor(m_nSlotId);
3821 }
3822 
3823 ColorListBox::ColorListBox(std::unique_ptr<weld::MenuButton> pControl, weld::Window* pTopLevel)
3824  : m_xButton(std::move(pControl))
3825  , m_pTopLevel(pTopLevel)
3826  , m_aColorWrapper(this)
3827  , m_aAutoDisplayColor(Application::GetSettings().GetStyleSettings().GetDialogColor())
3828  , m_nSlotId(0)
3829  , m_bShowNoneButton(false)
3830 {
3831  m_xButton->connect_toggled(LINK(this, ColorListBox, ToggleHdl));
3832  m_aSelectedColor = GetAutoColor(m_nSlotId);
3833  LockWidthRequest();
3835 }
3836 
3837 IMPL_LINK(ColorListBox, ToggleHdl, weld::ToggleButton&, rButton, void)
3838 {
3839  if (rButton.get_active())
3840  getColorWindow()->GrabFocus();
3841 }
3842 
3844 {
3845 }
3846 
3848 {
3849  if (!m_xColorWindow)
3850  const_cast<ColorListBox*>(this)->createColorWindow();
3851  return m_xColorWindow.get();
3852 }
3853 
3855 {
3856  const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
3857  const SfxFrame* pFrame = pViewFrame ? &pViewFrame->GetFrame() : nullptr;
3858  css::uno::Reference<css::frame::XFrame> xFrame(pFrame ? pFrame->GetFrameInterface() : uno::Reference<css::frame::XFrame>());
3859 
3861 
3862  m_xColorWindow.reset(new ColorWindow(
3863  OUString() /*m_aCommandURL*/,
3866  m_nSlotId,
3867  xFrame,
3868  m_pTopLevel,
3869  m_xButton.get(),
3870  m_aColorWrapper));
3871 
3872  SetNoSelection();
3873  m_xButton->set_popover(m_xColorWindow->getTopLevel());
3874  if (m_bShowNoneButton)
3875  m_xColorWindow->ShowNoneButton();
3876  m_xColorWindow->SelectEntry(m_aSelectedColor);
3877 }
3878 
3880 {
3881  if (rColor.second.trim().isEmpty())
3882  {
3883  SelectEntry(rColor.first);
3884  return;
3885  }
3886  ColorWindow* pColorWindow = getColorWindow();
3887  pColorWindow->SelectEntry(rColor);
3888  m_aSelectedColor = pColorWindow->GetSelectEntryColor();
3890 }
3891 
3893 {
3894  ColorWindow* pColorWindow = getColorWindow();
3895  pColorWindow->SelectEntry(rColor);
3896  m_aSelectedColor = pColorWindow->GetSelectEntryColor();
3898 }
3899 
3901 {
3902  ShowPreview(rColor);
3903  m_aSelectedColor = rColor;
3904  if (m_aSelectedLink.IsSet())
3905  m_aSelectedLink.Call(*this);
3906 }
3907 
3908 //to avoid the box resizing every time the color is changed to
3909 //the optimal size of the individual color, get the longest
3910 //standard color and stick with that as the size for all
3912 {
3913  NamedColor aLongestColor;
3914  long nMaxStandardColorTextWidth = 0;
3915  XColorListRef const xColorTable = XColorList::CreateStdColorList();
3916  for (long i = 0; i != xColorTable->Count(); ++i)
3917  {
3918  XColorEntry& rEntry = *xColorTable->GetColor(i);
3919  auto nColorTextWidth = m_xButton->get_pixel_size(rEntry.GetName()).Width();
3920  if (nColorTextWidth > nMaxStandardColorTextWidth)
3921  {
3922  nMaxStandardColorTextWidth = nColorTextWidth;
3923  aLongestColor.second = rEntry.GetName();
3924  }
3925  }
3926  ShowPreview(aLongestColor);
3927  m_xButton->set_size_request(m_xButton->get_preferred_size().Width(), -1);
3928 }
3929 
3931 {
3932  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
3933  Size aImageSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
3934 
3936  xDevice->SetOutputSize(aImageSize);
3937  const tools::Rectangle aRect(Point(0, 0), aImageSize);
3938  if (m_bShowNoneButton && rColor.first == COL_NONE_COLOR)
3939  {
3940  const Color aW(COL_WHITE);
3941  const Color aG(0xef, 0xef, 0xef);
3942  xDevice->DrawCheckered(aRect.TopLeft(), aRect.GetSize(), 8, aW, aG);
3943  xDevice->SetFillColor();
3944  }
3945  else
3946  {
3947  if (rColor.first == COL_AUTO)
3948  xDevice->SetFillColor(m_aAutoDisplayColor);
3949  else
3950  xDevice->SetFillColor(rColor.first);
3951  }
3952 
3953  xDevice->SetLineColor(rStyleSettings.GetDisableColor());
3954  xDevice->DrawRect(aRect);
3955 
3956  m_xButton->set_image(xDevice.get());
3957  m_xButton->set_label(rColor.second);
3958 }
3959 
3961  : m_pMenuButton(pMenuButton)
3962  , m_pToolbar(nullptr)
3963  , m_pControl(nullptr)
3964  , m_nId(0)
3965 {
3966 }
3967 
3969  : m_pMenuButton(nullptr)
3970  , m_pToolbar(pToolbar)
3971  , m_aIdent(rIdent)
3972  , m_pControl(nullptr)
3973  , m_nId(0)
3974 {
3975 }
3976 
3978  : m_pMenuButton(nullptr)
3979  , m_pToolbar(nullptr)
3980  , m_pControl(pControl)
3981  , m_xToolBox(pToolbar)
3982  , m_nId(nId)
3983 {
3984 }
3985 
3987 {
3988 }
3989 
3991 {
3992  if (m_pMenuButton)
3993  return m_pMenuButton->get_active();
3994  if (m_pToolbar)
3996  return m_xToolBox->GetDownItemId() == m_nId;
3997 }
3998 
4000 {
4001  if (m_pMenuButton)
4002  {
4003  if (m_pMenuButton->get_active())
4004  m_pMenuButton->set_active(false);
4005  return;
4006  }
4007  if (m_pToolbar)
4008  {
4011  return;
4012  }
4013  m_pControl->EndPopupMode();
4014 }
4015 
4017 {
4018  if (m_pMenuButton)
4019  return m_pMenuButton;
4020  if (m_pToolbar)
4021  return m_pToolbar;
4022  return m_xToolBox->GetFrameWeld();
4023 }
4024 
4025 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString AsRGBHexString() const
Point TopLeft() const
long Width() const
virtual std::unique_ptr< SfxStyleSheetIterator > CreateIterator(SfxStyleFamily, SfxStyleSearchBits nMask=SfxStyleSearchBits::All)
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
static NamedColor GetSelectEntryColor(ValueSet const *pColorSet)
Definition: tbcontrl.cxx:1891
long GetDistForWidth(long nWidth)
SfxStyleSheetBase * First(SfxStyleFamily eFamily, SfxStyleSearchBits eMask=SfxStyleSearchBits::All)
std::pair< Color, OUString > NamedColor
Definition: Palette.hxx:26
long GetWidth() const
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
const Wallpaper & GetBackground() const
FieldUnit
FrmValidFlags
Definition: tbcontrl.cxx:2207
sal_Int32 nIndex
std::tuple< vcl::RenderContext &, const tools::Rectangle &, bool, const OUString & > render_args
long GetHeight() const
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
SvxColorToolBoxControl * m_pControl
Definition: colorwindow.hxx:63
virtual void set_menu_item_active(const OString &rIdent, bool bActive)=0
std::unique_ptr< SvxStyleBox_Base > m_xWeldBox
Definition: tbcontrl.cxx:2539
virtual void SAL_CALL dispose() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &rArguments) override
Definition: tbcontrl.cxx:3157
void set_inactive() const
Definition: tbcontrl.cxx:3999
#define COMBO_WIDTH_IN_CHARS
Definition: tbcontrl.cxx:107
long AdjustWidth(long n)
long GetLine2ForWidth(long nWidth)
ColorListBox * mpControl
Definition: colorbox.hxx:25
weld::Toolbar * m_pToolbar
Definition: colorwindow.hxx:60
const Color & GetHighlightTextColor() const
std::unique_ptr< ContentProperties > pData
std::string GetValue
Reference< XControl > m_xControl
long Height() const
static XColorListRef CreateStdColorList()
Definition: xtabcolr.cxx:31
virtual OUString SAL_CALL getImplementationName() override=0
int n1
void AddStatusListener(const OUString &rCommandURL)
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
OUString maCommand
Definition: colorwindow.hxx:86
ToolBoxItemBits GetItemBits(sal_uInt16 nItemId) const
ValueSet(std::unique_ptr< weld::ScrolledWindow > pScrolledWindow)
Reference< XFrame > xFrame
void SetSlotId(sal_uInt16 nSlotId, bool bShowNoneButton=false)
Definition: tbcontrl.cxx:3812
void LockWidthRequest()
Definition: tbcontrl.cxx:3911
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
static VclPtr< vcl::Window > GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
sal_uInt8 GetLuminance() const
OUString GetLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
Color GetColorLine1(const Color &rMain)
Color GetColorLine2(const Color &rMain)
sal_Int64 n
std::unique_ptr< SfxTemplateItem > pFamilyState[MAX_FAMILIES]
Definition: tbcontrl.hxx:192
css::uno::Reference< css::lang::XComponent > m_xFrame
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override=0
VclPtr< ToolBox > m_xToolBox
Definition: colorwindow.hxx:64
VclPtr< SvxStyleBox_Impl > m_xVclBox
Definition: tbcontrl.cxx:2538
sal_Int16 nId
Color GetColorDist(const Color &rMain, const Color &rDefault)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
sal_uInt16 GetCode() const
OUString aId
void SetFamilyState(sal_uInt16 nIdx, const SfxTemplateItem *pItem)
Definition: tbcontrl.cxx:2935
DataChangedEventType GetType() const
virtual void SAL_CALL update() override
Definition: tbcontrl.cxx:2746
basegfx::BColor maColor
virtual void statusChanged(const css::frame::FeatureStateEvent &Event)
const Color & GetLabelTextColor() const
sal_uInt16 GetSelectedItemId() const
static SfxObjectShell * Current()
void InitializeStyles(const Reference< frame::XModel > &xModel)
Definition: tbcontrl.cxx:2552
void SetLine(const editeng::SvxBorderLine *pNew)
SfxStyleControllerItem_Impl * pBoundItems[MAX_FAMILIES]
Definition: tbcontrl.hxx:190
std::unique_ptr< Impl > pImpl
Definition: tbcontrl.hxx:159
virtual OUString SAL_CALL getImplementationName() override
Definition: tbcontrl.cxx:2723
static const NfCurrencyTable & GetTheCurrencyTable()
#define MAX_FAMILIES
Definition: tbcontrl.hxx:187
const Size & GetListBoxPreviewDefaultPixelSize() const
SvxColorToolBoxControl(const css::uno::Reference< css::uno::XComponentContext > &rContext)
Definition: tbcontrl.cxx:3118
long AdjustHeight(long n)
virtual bool get_active() const =0
std::shared_ptr< PaletteManager > m_xPaletteManager
Definition: tbcontrl.hxx:211
virtual OUString SAL_CALL getSubToolbarName() override
Definition: tbcontrl.cxx:3383
std::unique_ptr< weld::Label > m_xLabel
virtual void GrabFocus() override
Definition: tbcontrl.cxx:1874
weld::MenuButton * m_pMenuButton
Definition: colorwindow.hxx:58
bool GetTextBoundRect(tools::Rectangle &rRect, const OUString &rStr, sal_Int32 nBase=0, sal_Int32 nIndex=0, sal_Int32 nLen=-1, sal_uLong nLayoutWidth=0, const long *pDXArray=nullptr, const SalLayoutGlyphs *pGlyphs=nullptr) const
virtual void SAL_CALL dispose() override
Definition: tbcontrl.cxx:2685
NONE
virtual SfxStyleSheetBasePool * GetStyleSheetPool()
static OutputDevice * GetDefaultDevice()
SvxBorderLineStyle
friend class SfxStyleControllerItem_Impl
Definition: tbcontrl.hxx:199
constexpr::Color COL_AUTO(0xFF, 0xFF, 0xFF, 0xFF)
static bool SelectValueSetEntry(SvxColorValueSet *pColorSet, const Color &rColor)
Definition: tbcontrl.cxx:2057
weld::Window * GetFrameWeld() const
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
Definition: tbcontrl.cxx:2728
static sal_uInt32 getColumnCount()
virtual void SAL_CALL updateImage() override
Definition: tbcontrl.cxx:3378
sal_Int64 WinBits
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible()
FontItalic GetItalic()
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
Reference< XNameAccess > m_xContainer
IMPL_LINK(SvxStyleBox_Base, CustomGetSizeHdl, OutputDevice &, rArg, Size)
Definition: tbcontrl.cxx:885
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
void SetNoSelection()
Definition: colorbox.hxx:70
int n2
void Enable(bool bEnable=true, bool bChild=true)
ColorWindow(const OUString &rCommand, std::shared_ptr< PaletteManager > const &rPaletteManager, ColorStatus &rColorStatus, sal_uInt16 nSlotId, const css::uno::Reference< css::frame::XFrame > &rFrame, weld::Window *pParentWindow, const MenuOrToolMenuButton &rMenuButton, ColorSelectFunction const &rColorSelectFunction)
Definition: tbcontrl.cxx:1765
const OUString & GetName() const
PropertiesInfo aProperties
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
void DecreaseContrast(sal_uInt8 cContDec)
size_t pos
const vcl::Font & GetFont() const
#define WB_ITEMBORDER
ColorStatus & mrColorStatus
Definition: colorwindow.hxx:90
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow(const css::uno::Reference< css::awt::XWindow > &rParent) override
Definition: tbcontrl.cxx:2961
constexpr sal_uInt32 NUMBERFORMAT_ENTRY_NOT_FOUND
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svx_CurrencyToolBoxControl_get_implementation(css::uno::XComponentContext *rContext, css::uno::Sequence< css::uno::Any > const &)
Definition: tbcontrl.cxx:3706
SfxFrame & GetFrame() const
int nCount
void Selected(const NamedColor &rNamedColor)
Definition: tbcontrl.cxx:3900
virtual void GetFocus() override
AllSettingsFlags GetFlags() const
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
static bool lcl_GetDocFontList(const FontList **ppFontList, SvxFontNameBox_Base *pBox)
Definition: tbcontrl.cxx:1394
#define HID_POPUP_LINE
Definition: helpids.h:36
void DrawLine(OutputDevice &rDev, const Point &rP1, const Point &rP2, sal_uInt32 nWidth, SvxBorderLineStyle nDashing)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: tbcontrl.cxx:3397
SfxStyleFamily
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
virtual OutputDevice & get_ref_device()=0
IMPL_LINK_NOARG(SvxStyleBox_Base, ActivateHdl, weld::ComboBox &, bool)
Definition: tbcontrl.cxx:958
void operator()(const OUString &rCommand, const NamedColor &rColor)
Definition: tbcontrl.cxx:3798
std::unique_ptr< weld::ComboBox > mxPaletteListBox
Definition: colorwindow.hxx:95
virtual void StateChanged(SfxItemState eState, const SfxPoolItem *pState) override
Definition: tbcontrl.cxx:2503
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
sal_uInt16 nCode
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: tbcontrl.cxx:2733
bool IsNoSelection() const
Definition: tbcontrl.cxx:2031
virtual void set_active(bool active)=0
void DrawRect(const tools::Rectangle &rRect)
const OUString & GetStyleName() const
std::unique_ptr< weld::Container > m_xTopLevel
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
virtual void SAL_CALL functionSelected(const OUString &rCommand) override
Definition: tbcontrl.cxx:3388
const OUString & GetName() const
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
void SelectEntry(const NamedColor &rColor)
Definition: tbcontrl.cxx:3879
virtual std::unique_ptr< WeldToolbarPopup > weldPopupWindow()
const Color & GetDisableColor() const
Right
std::unique_ptr< weld::Button > mxButtonPicker
Definition: colorwindow.hxx:98
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svx_StyleToolBoxControl_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: tbcontrl.cxx:2739
#define COL_NONE_COLOR
Definition: colorwindow.hxx:50
#define DBG_ASSERT(sCon, aError)
void DecreaseLuminance(sal_uInt8 cLumDec)
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: tbcontrl.cxx:2662
int i
uno_Any a
Reference< XTextListener > m_xListener
bool IsDark() const
virtual VclPtr< vcl::Window > createVclPopupWindow(vcl::Window *pParent) override
Definition: tbcontrl.cxx:3260
std::unique_ptr< weld::Button > mxButtonNoneColor
Definition: colorwindow.hxx:97
std::unique_ptr< SvxColorValueSet > mxRecentColorSet
Definition: colorwindow.hxx:94
OUString sName
sal_uInt16 GetDownItemId() const
float approximate_digit_width() const
#define LANGUAGE_SYSTEM
LanguageType GetLanguage(SwWrtShell &rSh, sal_uInt16 nLangWhichId)
#define HID_POPUP_COLOR_CTRL
Definition: helpids.h:34
ColorStatus m_aColorStatus
Definition: tbcontrl.hxx:212
long GetLine1ForWidth(long nWidth)
bool IsBright() const
const Color & GetColor() const
weld::Button * mpDefaultButton
void SetItemBits(sal_uInt16 nItemId, ToolBoxItemBits nBits)
void Create(SvxOrientationItem &rItem, SvStream &rStrm, sal_uInt16)
Definition: legacyitem.cxx:34
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
virtual std::unique_ptr< WeldToolbarPopup > weldPopupWindow() override
Definition: tbcontrl.cxx:3235
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxInfoItemLine nLine)
std::unique_ptr< weld::Widget > mxAutomaticSeparator
Definition: colorwindow.hxx:99
void SetFillColor()
virtual VclPtr< vcl::Window > createVclPopupWindow(vcl::Window *pParent)=0
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
const Color & GetFieldColor() const
OUString ApplyLreOrRleEmbedding(const OUString &rText)
DECL_LINK(FocusHdl, weld::Widget &, void)
virtual OUString SAL_CALL getImplementationName() override
Definition: tbcontrl.cxx:3392
void CheckItem(sal_uInt16 nItemId, bool bCheck=true)
unsigned char sal_Bool
void SetTextColor(const Color &rColor)
long Bottom() const
static void ShowPanel(const OUString &rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
std::shared_ptr< PaletteManager > mxPaletteManager
Definition: colorwindow.hxx:89
OUString GetItemText(sal_uInt16 nItemId) const
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &rEvent) override
Definition: tbcontrl.cxx:3298
void ShowNoneButton()
Definition: tbcontrl.cxx:1882
ITALIC_NONE
sal_uInt16 GetModifier() const
const OUString & GetStyleName() const
FontPitch
std::unique_ptr< weld::Button > mxButtonAutoColor
Definition: colorwindow.hxx:96
SfxStyleFamily GetActFamily() const
Definition: tbcontrl.cxx:2753
#define ITEM_HEIGHT
Definition: tbcontrl.cxx:845
long GetTextHeight() const
SvxBorderLineStyle GetStyle() const
exports com.sun.star. style
Size GetSize() const
ColorStatus m_aColorStatus
Definition: colorbox.hxx:43
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
void Disable(bool bChild=true)
static const char * StyleSlotToStyleCommand[MAX_FAMILIES]
Definition: tbcontrl.cxx:2636
const sal_uInt16 theSlotId
Definition: colorwindow.hxx:85
float GetDPIScaleFactor() const
void createColorWindow()
Definition: tbcontrl.cxx:3854
long GetMinWidth() const
virtual ~ColorWindow() override
Definition: tbcontrl.cxx:1887
ColorSelectFunction m_aColorSelectFunction
Definition: tbcontrl.hxx:215
virtual void SAL_CALL execute(sal_Int16 nSelectModifier) override
Definition: tbcontrl.cxx:3328
MenuOrToolMenuButton(weld::MenuButton *pMenuButton)
Definition: tbcontrl.cxx:3960
#define HID_POPUP_COLOR
Definition: helpids.h:33
size_t GetFontNameCount() const
NamedColor m_aSelectedColor
Definition: colorbox.hxx:39
void SelectItem(sal_uInt16 nItemId)
Point LogicToPixel(const Point &rLogicPt) const
SfxStyleControllerItem_Impl(const Reference< XDispatchProvider > &rDispatchProvider, sal_uInt16 nSlotId, const OUString &rCommand, SvxStyleToolBoxControl &rTbxCtl)
Definition: tbcontrl.cxx:2493
void SetNone(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
const LanguageTag & getLocale()
ValueSet & operator=(const ValueSet &)=delete
WinBits const WB_3DLOOK
Sequence< beans::PropertyValue > GetCommandProperties(const OUString &rsCommandName, const OUString &rsModuleName)
FontFamily
std::unique_ptr< svx::ToolboxButtonColorUpdaterBase > m_xBtnUpdater
Definition: tbcontrl.hxx:210
Fill
const OUString & GetFamilyName() const
constexpr TypedWhichId< XFillColorItem > XATTR_FILLCOLOR(XATTR_FILL_FIRST+1)
const vcl::KeyCode & GetKeyCode() const
virtual ~SvxColorToolBoxControl() override
Definition: tbcontrl.cxx:3222
static Color lcl_mediumColor(Color aMain, Color)
Definition: tbcontrl.cxx:2401
void EnsurePaletteManager()
Definition: tbcontrl.cxx:3803
OUString GetItemCommand(sal_uInt16 nItemId) const
static SfxViewFrame * Current()
SfxItemState
#define WB_NO_DIRECTSELECT
ListBoxColorWrapper(ColorListBox *pControl)
Definition: tbcontrl.cxx:3793
void SelectStyle(const OUString &rStyleName)
Definition: tbcontrl.cxx:2871
bool get_active() const
Definition: tbcontrl.cxx:3990
size_t GetItemCount() const
ITALIC_NORMAL
unsigned char sal_uInt8
std::unique_ptr< ColorWindow > m_xColorWindow
Definition: colorbox.hxx:32
OUString EditResId(const char *pId)
constexpr sal_uInt16 KEY_ESCAPE
void SetFont(const vcl::Font &rNewFont)
virtual void grab_focus()=0
SfxStyleSheetBase * Next()
virtual void dispose() override
MapUnit GetMapUnit() const
OUString aName
Color m_aAutoDisplayColor
Definition: colorbox.hxx:37
ColorWindow * getColorWindow() const
Definition: tbcontrl.cxx:3847
virtual ~SvxStyleToolBoxControl() override
Definition: tbcontrl.cxx:2658
virtual sal_Bool SAL_CALL opensSubToolbar() override
Definition: tbcontrl.cxx:3370
#define HID_STYLE_LISTBOX
Definition: helpids.h:39
Color GetColor()
Definition: tbcontrl.cxx:2145
static VclPtr< reference_type > Create(Arg &&...arg)
std::shared_ptr< PaletteManager > m_xPaletteManager
Definition: colorbox.hxx:42
ColorListBox(std::unique_ptr< weld::MenuButton > pControl, weld::Window *pTopLevelWindow)
Definition: tbcontrl.cxx:3823
void SelectEntry(const NamedColor &rColor)
Definition: tbcontrl.cxx:2070
Link< ColorListBox &, void > m_aSelectedLink
Definition: colorbox.hxx:35
virtual void SAL_CALL update() override
Definition: tbcontrl.cxx:3192
void setColorSelectFunction(const ColorSelectFunction &aColorSelectFunction)
Definition: tbcontrl.cxx:3228
Reference< XComponentContext > getProcessComponentContext()
virtual void setProperty(const css::uno::Any &aProperty) override
SfxStyleSheetBasePool * pStyleSheetPool
Definition: tbcontrl.hxx:189
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
virtual void statusChanged(const css::frame::FeatureStateEvent &rEvent) override
Definition: tbcontrl.cxx:2040
const Color & GetWindowColor() const
std::function< void(const OUString &, const NamedColor &)> ColorSelectFunction
Definition: colorwindow.hxx:47
bool m_bShowNoneButton
Definition: colorbox.hxx:41
sal_uInt16 m_nSlotId
Definition: colorbox.hxx:40
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svx_FrameToolBoxControl_get_implementation(css::uno::XComponentContext *rContext, css::uno::Sequence< css::uno::Any > const &)
Definition: tbcontrl.cxx:3488
constexpr::Color COL_WHITE(0xFF, 0xFF, 0xFF)
virtual bool get_menu_item_active(const OString &rIdent) const =0
void ShowChildWindow(sal_uInt16, bool bVisible=true)
WinBits const WB_TABSTOP
static OUString GetLanguageString(const LanguageType eType)
void SetItalic(FontItalic)
OUString sId
css::uno::Reference< css::lang::XComponent > m_xBoundItems[MAX_FAMILIES]
Definition: tbcontrl.hxx:191
void SetValid(SvxBoxInfoItemValidFlags nValid, bool bValid=true)
ListBoxColorWrapper m_aColorWrapper
Definition: colorbox.hxx:36
#define SAL_WARN(area, stream)
std::vector< OUString > NfWSStringsDtor
OUString aCommand
Color maTLBRColor
Definition: colorwindow.hxx:38
virtual std::unique_ptr< SfxItemSet > GetItemSetForPreview()
IMPL_STATIC_LINK_NOARG(SvxStyleBox_Base, ShowMoreHdl, void *, void)
Definition: tbcontrl.cxx:943
#define DEF_LINE_WIDTH_0
Left
static sal_uInt32 getMaxRowCount()
std::unique_ptr< SvxColorValueSet > mxColorSet
Definition: colorwindow.hxx:93
long getHeight() const
#define HID_POPUP_FRAME
Definition: helpids.h:35
const FontList * GetFontList() const
size_t size() const
void dispose()
#define MAX_MRU_FONTNAME_ENTRIES
Definition: tbcontrl.cxx:105
#define WB_FLATVALUESET
SvxStyleBox_Base * m_pBox
Definition: tbcontrl.cxx:2540
constexpr sal_uInt16 KEY_SHIFT
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
const Size & GetSizePixel() const
const Color & GetDialogTextColor() const
virtual void set_size_request(int nWidth, int nHeight)=0
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svx_ColorToolBoxControl_get_implementation(css::uno::XComponentContext *rContext, css::uno::Sequence< css::uno::Any > const &)
Definition: tbcontrl.cxx:3403
void Push(PushFlags nFlags=PushFlags::ALL)
long getWidth() const
NamedColor GetSelectEntryColor() const
Definition: tbcontrl.cxx:1944
void statusChanged(const css::frame::FeatureStateEvent &rEvent)
Definition: tbcontrl.cxx:2122
void setWidth(long nWidth)
virtual void GrabFocus()=0
weld::Window * m_pTopLevel
Definition: colorbox.hxx:34
sal_uInt32 m_nId
Color maBLTRColor
Definition: colorwindow.hxx:39
std::unique_ptr< weld::MenuButton > m_xButton
Definition: colorbox.hxx:33
NamedColor GetAutoColor() const
Definition: tbcontrl.cxx:1986
aStr
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)
#define BUTTON_PADDING
Definition: tbcontrl.cxx:844
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &rEvent) override
Definition: tbcontrl.cxx:2942
::std::vector< OUString > aDefaultStyles
Definition: tbcontrl.cxx:2534
sal_Int16 GetCaseMap(sal_Int32 nToken)
Color GetItemColor(sal_uInt16 nItemId) const
static bool LineToSvxLine(const css::table::BorderLine &rLine, editeng::SvxBorderLine &rSvxLine, bool bConvert)
sal_uInt16 nPos
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svx_FontNameToolBoxControl_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: tbcontrl.cxx:3111
SvxStyleToolBoxControl & rControl
Definition: tbcontrl.cxx:841
constexpr sal_uInt16 KEY_TAB
void ShowPreview(const NamedColor &rColor)
Definition: tbcontrl.cxx:3930
virtual void DataChanged(const DataChangedEvent &rDCEvt)
void SetNoSelection()
Definition: tbcontrl.cxx:2024
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
#define CONVERT_TWIPS
weld::Widget * get_widget() const
Definition: tbcontrl.cxx:4016
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxItemLine nLine)
void setHeight(long nHeight)