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