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