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