Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / tbxctrls / tbcontrl.cxx
blob06cefd08062a2c1429c1d90ff0bbea96e142da3f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <utility>
22 #include <comphelper/configurationlistener.hxx>
23 #include <comphelper/propertysequence.hxx>
24 #include <comphelper/propertyvalue.hxx>
25 #include <tools/color.hxx>
26 #include <svl/numformat.hxx>
27 #include <svl/poolitem.hxx>
28 #include <svl/itemset.hxx>
29 #include <svl/itempool.hxx>
30 #include <vcl/commandinfoprovider.hxx>
31 #include <vcl/event.hxx>
32 #include <vcl/toolbox.hxx>
33 #include <vcl/customweld.hxx>
34 #include <vcl/vclptr.hxx>
35 #include <vcl/weldutils.hxx>
36 #include <svtools/valueset.hxx>
37 #include <svtools/ctrlbox.hxx>
38 #include <svl/style.hxx>
39 #include <svtools/ctrltool.hxx>
40 #include <svtools/borderhelper.hxx>
41 #include <vcl/InterimItemWindow.hxx>
42 #include <sfx2/tbxctrl.hxx>
43 #include <sfx2/tplpitem.hxx>
44 #include <sfx2/sfxstatuslistener.hxx>
45 #include <toolkit/helper/vclunohelper.hxx>
46 #include <sfx2/viewfrm.hxx>
47 #include <vcl/svapp.hxx>
48 #include <vcl/settings.hxx>
49 #include <vcl/virdev.hxx>
50 #include <com/sun/star/awt/FontDescriptor.hpp>
51 #include <com/sun/star/table/BorderLine2.hpp>
52 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
53 #include <com/sun/star/lang/XServiceInfo.hpp>
54 #include <com/sun/star/beans/XPropertySet.hpp>
55 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
56 #include <com/sun/star/frame/XDispatchProvider.hpp>
57 #include <com/sun/star/frame/XFrame.hpp>
58 #include <svx/strings.hrc>
59 #include <svx/svxids.hrc>
60 #include <helpids.h>
61 #include <sfx2/sidebar/Sidebar.hxx>
62 #include <svx/xtable.hxx>
63 #include <editeng/editids.hrc>
64 #include <editeng/fontitem.hxx>
65 #include <editeng/fhgtitem.hxx>
66 #include <editeng/boxitem.hxx>
67 #include <editeng/charreliefitem.hxx>
68 #include <editeng/contouritem.hxx>
69 #include <editeng/colritem.hxx>
70 #include <editeng/crossedoutitem.hxx>
71 #include <editeng/emphasismarkitem.hxx>
72 #include <editeng/flstitem.hxx>
73 #include <editeng/lineitem.hxx>
74 #include <editeng/postitem.hxx>
75 #include <editeng/shdditem.hxx>
76 #include <editeng/udlnitem.hxx>
77 #include <editeng/wghtitem.hxx>
78 #include <editeng/svxfont.hxx>
79 #include <editeng/cmapitem.hxx>
80 #include <svx/colorwindow.hxx>
81 #include <svx/colorbox.hxx>
82 #include <svx/tbcontrl.hxx>
83 #include <svx/dialmgr.hxx>
84 #include <svx/PaletteManager.hxx>
85 #include <memory>
87 #include <tbxcolorupdate.hxx>
88 #include <editeng/eerdll.hxx>
89 #include <editeng/editrids.hrc>
90 #include <svx/xdef.hxx>
91 #include <svx/xfillit0.hxx>
92 #include <svx/xflclit.hxx>
93 #include <svl/currencytable.hxx>
94 #include <svtools/langtab.hxx>
95 #include <cppu/unotype.hxx>
96 #include <cppuhelper/supportsservice.hxx>
97 #include <officecfg/Office/Common.hxx>
98 #include <o3tl/safeint.hxx>
99 #include <o3tl/string_view.hxx>
100 #include <o3tl/typed_flags_set.hxx>
101 #include <bitmaps.hlst>
102 #include <sal/log.hxx>
103 #include <unotools/collatorwrapper.hxx>
105 #include <comphelper/lok.hxx>
106 #include <tools/json_writer.hxx>
108 #include <editeng/editeng.hxx>
110 #define MAX_MRU_FONTNAME_ENTRIES 5
112 #define COMBO_WIDTH_IN_CHARS 18
114 #define MAX_MRU_CURRENCIES 5
116 #define INVALID_CURRENCY sal_uInt16(-2)
118 // namespaces
119 using namespace ::editeng;
120 using namespace ::com::sun::star;
121 using namespace ::com::sun::star::uno;
122 using namespace ::com::sun::star::frame;
123 using namespace ::com::sun::star::beans;
124 using namespace ::com::sun::star::lang;
126 namespace
128 struct ScriptInfo
130 tools::Long textWidth;
131 SvtScriptType scriptType;
132 sal_Int32 changePos;
133 ScriptInfo(SvtScriptType scrptType, sal_Int32 position)
134 : textWidth(0)
135 , scriptType(scrptType)
136 , changePos(position)
141 class SvxStyleBox_Base
143 public:
144 SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget, OUString rCommand, SfxStyleFamily eFamily,
145 const Reference<XDispatchProvider>& rDispatchProvider,
146 const Reference<XFrame>& _xFrame, OUString aClearFormatKey,
147 OUString aMoreKey, bool bInSpecialMode, SvxStyleToolBoxControl& rCtrl);
149 virtual ~SvxStyleBox_Base()
153 void SetFamily( SfxStyleFamily eNewFamily );
155 void SetDefaultStyle( const OUString& rDefault ) { sDefaultStyle = rDefault; }
157 int get_count() const { return m_xWidget->get_count(); }
158 OUString get_text(int nIndex) const { return m_xWidget->get_text(nIndex); }
159 OUString get_active_text() const { return m_xWidget->get_active_text(); }
161 void append_text(const OUString& rStr)
163 OUString sId(OUString::number(m_xWidget->get_count()));
164 m_xWidget->append(sId, rStr);
167 void insert_separator(int pos, const OUString& rId)
169 m_xWidget->insert_separator(pos, rId);
172 void set_active_or_entry_text(const OUString& rText)
174 const int nFound = m_xWidget->find_text(rText);
175 if (nFound != -1)
176 m_xWidget->set_active(nFound);
177 else
178 m_xWidget->set_entry_text(rText);
181 void set_active(int nActive)
183 m_xWidget->set_active(nActive);
186 void freeze()
188 m_xWidget->freeze();
191 void save_value()
193 m_xWidget->save_value();
196 void clear()
198 m_xWidget->clear();
199 m_nMaxUserDrawFontWidth = 0;
202 void thaw()
204 m_xWidget->thaw();
207 virtual bool DoKeyInput(const KeyEvent& rKEvt);
209 private:
210 std::optional<SvxFont> m_oFont;
211 std::optional<SvxFont> m_oCJKFont;
212 std::optional<SvxFont> m_oCTLFont;
214 DECL_LINK(SelectHdl, weld::ComboBox&, void);
215 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
216 DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
217 DECL_LINK(FocusOutHdl, weld::Widget&, void);
218 DECL_LINK(DumpAsPropertyTreeHdl, tools::JsonWriter&, void);
219 DECL_LINK(CustomRenderHdl, weld::ComboBox::render_args, void);
220 DECL_LINK(CustomGetSizeHdl, OutputDevice&, Size);
222 /// Calculate the optimal width of the dropdown. Very expensive operation, triggers lots of font measurement.
223 void CalcOptimalExtraUserWidth(vcl::RenderContext& rRenderContext);
225 void Select(bool bNonTravelSelect);
227 tools::Rectangle CalcBoundRect(vcl::RenderContext& rRenderContext, const OUString &rStyleName, std::vector<ScriptInfo>& rScriptChanges, double fRatio = 1);
229 protected:
230 SvxStyleToolBoxControl& m_rCtrl;
232 std::unique_ptr<weld::Builder> m_xMenuBuilder;
233 std::unique_ptr<weld::Menu> m_xMenu;
234 std::unique_ptr<weld::ComboBox> m_xWidget;
236 SfxStyleFamily eStyleFamily;
237 int m_nMaxUserDrawFontWidth;
238 int m_nLastItemWithMenu;
239 bool bRelease;
240 Reference< XDispatchProvider > m_xDispatchProvider;
241 Reference< XFrame > m_xFrame;
242 OUString m_aCommand;
243 OUString aClearFormatKey;
244 OUString aMoreKey;
245 OUString sDefaultStyle;
246 bool bInSpecialMode;
248 void ReleaseFocus();
249 static Color TestColorsVisible(const Color &FontCol, const Color &BackCol);
250 void UserDrawEntry(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const tools::Rectangle& rTextRect, const OUString &rStyleName, const std::vector<ScriptInfo>& rScriptChanges);
251 void SetupEntry(vcl::RenderContext& rRenderContext, sal_Int32 nItem, const tools::Rectangle& rRect, std::u16string_view rStyleName, bool bIsNotSelected);
252 DECL_LINK(MenuSelectHdl, const OUString&, void);
253 DECL_STATIC_LINK(SvxStyleBox_Base, ShowMoreHdl, void*, void);
256 class SvxStyleBox_Impl final : public InterimItemWindow
257 , public SvxStyleBox_Base
259 public:
260 SvxStyleBox_Impl(vcl::Window* pParent, const OUString& rCommand, SfxStyleFamily eFamily, const Reference< XDispatchProvider >& rDispatchProvider,
261 const Reference< XFrame >& _xFrame,const OUString& rClearFormatKey, const OUString& rMoreKey, bool bInSpecialMode, SvxStyleToolBoxControl& rCtrl);
263 virtual ~SvxStyleBox_Impl() override
265 disposeOnce();
268 virtual void dispose() override
270 m_xWidget.reset();
271 m_xMenu.reset();
272 m_xMenuBuilder.reset();
273 InterimItemWindow::dispose();
276 virtual bool DoKeyInput(const KeyEvent& rKEvt) override;
278 private:
280 virtual void DataChanged(const DataChangedEvent& rDCEvt) override;
281 void SetOptimalSize();
284 class SvxFontNameBox_Impl;
285 class SvxFontNameBox_Base;
287 class SvxFontNameToolBoxControl final : public cppu::ImplInheritanceHelper<svt::ToolboxController,
288 css::lang::XServiceInfo>
290 public:
291 SvxFontNameToolBoxControl();
293 // XStatusListener
294 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
296 // XToolbarController
297 virtual css::uno::Reference<css::awt::XWindow> SAL_CALL createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent) override;
299 // XComponent
300 virtual void SAL_CALL dispose() override;
302 // XServiceInfo
303 virtual OUString SAL_CALL getImplementationName() override;
304 virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override;
305 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
307 private:
308 VclPtr<SvxFontNameBox_Impl> m_xVclBox;
309 std::unique_ptr<SvxFontNameBox_Base> m_xWeldBox;
310 SvxFontNameBox_Base* m_pBox;
313 class FontOptionsListener final : public comphelper::ConfigurationListenerProperty<bool>
315 private:
316 SvxFontNameBox_Base& m_rBox;
318 virtual void setProperty(const css::uno::Any &rProperty) override;
319 public:
320 FontOptionsListener(const rtl::Reference<comphelper::ConfigurationListener>& rListener, const OUString& rProp, SvxFontNameBox_Base& rBox)
321 : comphelper::ConfigurationListenerProperty<bool>(rListener, rProp)
322 , m_rBox(rBox)
327 class SvxFontNameBox_Base
329 private:
330 rtl::Reference<comphelper::ConfigurationListener> m_xListener;
331 FontOptionsListener m_aWYSIWYG;
332 FontOptionsListener m_aHistory;
334 protected:
335 SvxFontNameToolBoxControl& m_rCtrl;
337 std::unique_ptr<FontNameBox> m_xWidget;
338 const FontList* pFontList;
339 ::std::unique_ptr<FontList> m_aOwnFontList;
340 vcl::Font aCurFont;
341 sal_uInt16 nFtCount;
342 bool bRelease;
343 Reference< XDispatchProvider > m_xDispatchProvider;
344 Reference< XFrame > m_xFrame;
345 bool mbCheckingUnknownFont;
347 void ReleaseFocus_Impl();
349 void Select(bool bNonTravelSelect);
351 void EndPreview()
353 Sequence< PropertyValue > aArgs;
354 SfxToolBoxControl::Dispatch( m_xDispatchProvider,
355 ".uno:CharEndPreviewFontName",
356 aArgs );
359 bool CheckFontIsAvailable(std::u16string_view fontname);
360 void CheckAndMarkUnknownFont();
362 public:
363 SvxFontNameBox_Base(std::unique_ptr<weld::ComboBox> xWidget, const Reference<XDispatchProvider>& rDispatchProvider,
364 const Reference<XFrame>& rFrame, SvxFontNameToolBoxControl& rCtrl);
365 virtual ~SvxFontNameBox_Base()
367 m_xListener->dispose();
370 void FillList();
371 void Update( const css::awt::FontDescriptor* pFontDesc );
372 sal_uInt16 GetListCount() const { return nFtCount; }
373 void Clear() { m_xWidget->clear(); nFtCount = 0; }
374 void Fill( const FontList* pList )
376 m_xWidget->Fill(pList);
377 nFtCount = pList->GetFontNameCount();
380 void SetOwnFontList(::std::unique_ptr<FontList> && _aOwnFontList) { m_aOwnFontList = std::move(_aOwnFontList); }
382 virtual void set_sensitive(bool bSensitive)
384 m_xWidget->set_sensitive(bSensitive);
387 void set_active_or_entry_text(const OUString& rText);
389 void statusChanged_Impl(const css::frame::FeatureStateEvent& rEvent);
391 virtual bool DoKeyInput(const KeyEvent& rKEvt);
393 void EnableControls();
395 DECL_LINK(SelectHdl, weld::ComboBox&, void);
396 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
397 DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
398 DECL_LINK(FocusInHdl, weld::Widget&, void);
399 DECL_LINK(FocusOutHdl, weld::Widget&, void);
400 DECL_LINK(DumpAsPropertyTreeHdl, tools::JsonWriter&, void);
403 void FontOptionsListener::setProperty(const css::uno::Any &rProperty)
405 comphelper::ConfigurationListenerProperty<bool>::setProperty(rProperty);
406 m_rBox.EnableControls();
409 class SvxFontNameBox_Impl final : public InterimItemWindow
410 , public SvxFontNameBox_Base
412 private:
413 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
414 virtual void GetFocus() override
416 if (m_xWidget)
417 m_xWidget->grab_focus();
418 InterimItemWindow::GetFocus();
421 void SetOptimalSize();
423 virtual bool DoKeyInput(const KeyEvent& rKEvt) override;
425 public:
426 SvxFontNameBox_Impl(vcl::Window* pParent, const Reference<XDispatchProvider>& rDispatchProvider,
427 const Reference<XFrame>& rFrame, SvxFontNameToolBoxControl& rCtrl);
429 virtual void dispose() override
431 m_xWidget.reset();
432 InterimItemWindow::dispose();
435 virtual ~SvxFontNameBox_Impl() override
437 disposeOnce();
440 virtual Reference< css::accessibility::XAccessible > CreateAccessible() override;
442 virtual void set_sensitive(bool bSensitive) override
444 m_xWidget->set_sensitive(bSensitive);
445 if (bSensitive)
446 InterimItemWindow::Enable();
447 else
448 InterimItemWindow::Disable();
453 // SelectHdl needs the Modifiers, get them in MouseButtonUp
454 class SvxFrmValueSet_Impl final : public ValueSet
456 private:
457 sal_uInt16 nModifier;
459 virtual bool MouseButtonUp(const MouseEvent& rMEvt) override
461 nModifier = rMEvt.GetModifier();
462 return ValueSet::MouseButtonUp(rMEvt);
465 public:
466 SvxFrmValueSet_Impl()
467 : ValueSet(nullptr)
468 , nModifier(0)
471 sal_uInt16 GetModifier() const {return nModifier;}
476 namespace {
478 class SvxFrameToolBoxControl;
480 class SvxFrameWindow_Impl final : public WeldToolbarPopup
482 private:
483 rtl::Reference<SvxFrameToolBoxControl> mxControl;
484 std::unique_ptr<SvxFrmValueSet_Impl> mxFrameSet;
485 std::unique_ptr<weld::CustomWeld> mxFrameSetWin;
486 std::vector<std::pair<BitmapEx, OUString>> aImgVec;
487 bool bParagraphMode;
488 bool m_bIsWriter;
490 void InitImageList();
491 void CalcSizeValueSet();
492 DECL_LINK( SelectHdl, ValueSet*, void );
494 void SetDiagonalDownBorder(const SvxLineItem& dDownLineItem);
495 void SetDiagonalUpBorder(const SvxLineItem& dUpLineItem);
497 public:
498 SvxFrameWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent);
499 virtual void GrabFocus() override
501 mxFrameSet->GrabFocus();
504 virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
507 class SvxFrameToolBoxControl : public svt::PopupWindowController
509 public:
510 explicit SvxFrameToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rContext );
512 // XInitialization
513 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) override;
515 // XServiceInfo
516 virtual OUString SAL_CALL getImplementationName() override;
517 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
519 virtual void SAL_CALL execute(sal_Int16 nKeyModifier) override;
520 private:
521 virtual std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override;
522 virtual VclPtr<vcl::Window> createVclPopupWindow( vcl::Window* pParent ) override;
525 class LineListBox final : public ValueSet
527 public:
528 typedef Color (*ColorFunc)(Color);
529 typedef Color (*ColorDistFunc)(Color, Color);
531 LineListBox();
533 /** Set the width in Twips */
534 Size SetWidth( tools::Long nWidth )
536 tools::Long nOldWidth = m_nWidth;
537 m_nWidth = nWidth;
538 return UpdateEntries( nOldWidth );
541 void SetNone( const OUString& sNone )
543 m_sNone = sNone;
546 /** Insert a listbox entry with all widths in Twips. */
547 void InsertEntry(const BorderWidthImpl& rWidthImpl,
548 SvxBorderLineStyle nStyle, tools::Long nMinWidth = 0,
549 ColorFunc pColor1Fn = &sameColor,
550 ColorFunc pColor2Fn = &sameColor,
551 ColorDistFunc pColorDistFn = &sameDistColor);
553 SvxBorderLineStyle GetEntryStyle( sal_Int32 nPos ) const;
555 SvxBorderLineStyle GetSelectEntryStyle() const;
557 void SetSourceUnit( FieldUnit eNewUnit ) { eSourceUnit = eNewUnit; }
559 const Color& GetColor() const { return aColor; }
561 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
562 private:
564 void ImpGetLine(tools::Long nLine1, tools::Long nLine2, tools::Long nDistance,
565 Color nColor1, Color nColor2, Color nColorDist,
566 SvxBorderLineStyle nStyle, BitmapEx& rBmp);
568 void UpdatePaintLineColor(); // returns sal_True if maPaintCol has changed
570 Size UpdateEntries( tools::Long nOldWidth );
571 sal_Int32 GetStylePos( sal_Int32 nListPos, tools::Long nWidth );
573 const Color& GetPaintColor() const
575 return maPaintCol;
578 Color GetColorLine1( sal_Int32 nPos );
579 Color GetColorLine2( sal_Int32 nPos );
580 Color GetColorDist( sal_Int32 nPos );
582 LineListBox( const LineListBox& ) = delete;
583 LineListBox& operator =( const LineListBox& ) = delete;
585 std::vector<std::unique_ptr<ImpLineListData>> m_vLineList;
586 tools::Long m_nWidth;
587 OUString m_sNone;
588 ScopedVclPtr<VirtualDevice> aVirDev;
589 Size aTxtSize;
590 Color const aColor;
591 Color maPaintCol;
592 FieldUnit eSourceUnit;
595 SvxBorderLineStyle LineListBox::GetSelectEntryStyle() const
597 SvxBorderLineStyle nStyle = SvxBorderLineStyle::SOLID;
598 size_t nPos = GetSelectItemPos();
599 if (nPos != VALUESET_ITEM_NOTFOUND)
601 if (!m_sNone.isEmpty())
602 --nPos;
603 nStyle = GetEntryStyle( nPos );
606 return nStyle;
609 void LineListBox::ImpGetLine( tools::Long nLine1, tools::Long nLine2, tools::Long nDistance,
610 Color aColor1, Color aColor2, Color aColorDist,
611 SvxBorderLineStyle nStyle, BitmapEx& rBmp )
613 auto nMinWidth = GetDrawingArea()->get_ref_device().approximate_digit_width() * COMBO_WIDTH_IN_CHARS;
614 Size aSize(nMinWidth, aTxtSize.Height());
615 aSize.AdjustWidth( -(aTxtSize.Width()) );
616 aSize.AdjustWidth( -6 );
618 // SourceUnit to Twips
619 if ( eSourceUnit == FieldUnit::POINT )
621 nLine1 /= 5;
622 nLine2 /= 5;
623 nDistance /= 5;
626 // Paint the lines
627 aSize = aVirDev->PixelToLogic( aSize );
628 tools::Long nPix = aVirDev->PixelToLogic( Size( 0, 1 ) ).Height();
629 sal_uInt32 n1 = nLine1;
630 sal_uInt32 n2 = nLine2;
631 tools::Long nDist = nDistance;
632 n1 += nPix-1;
633 n1 -= n1%nPix;
634 if ( n2 )
636 nDist += nPix-1;
637 nDist -= nDist%nPix;
638 n2 += nPix-1;
639 n2 -= n2%nPix;
641 tools::Long nVirHeight = n1+nDist+n2;
642 if ( nVirHeight > aSize.Height() )
643 aSize.setHeight( nVirHeight );
644 // negative width should not be drawn
645 if ( aSize.Width() <= 0 )
646 return;
648 Size aVirSize = aVirDev->LogicToPixel( aSize );
649 if ( aVirDev->GetOutputSizePixel() != aVirSize )
650 aVirDev->SetOutputSizePixel( aVirSize );
651 aVirDev->SetFillColor( aColorDist );
652 aVirDev->DrawRect( tools::Rectangle( Point(), aSize ) );
654 aVirDev->SetFillColor( aColor1 );
656 double y1 = double( n1 ) / 2;
657 svtools::DrawLine( *aVirDev, basegfx::B2DPoint( 0, y1 ), basegfx::B2DPoint( aSize.Width( ), y1 ), n1, nStyle );
659 if ( n2 )
661 double y2 = n1 + nDist + double( n2 ) / 2;
662 aVirDev->SetFillColor( aColor2 );
663 svtools::DrawLine( *aVirDev, basegfx::B2DPoint( 0, y2 ), basegfx::B2DPoint( aSize.Width(), y2 ), n2, SvxBorderLineStyle::SOLID );
665 rBmp = aVirDev->GetBitmapEx( Point(), Size( aSize.Width(), n1+nDist+n2 ) );
668 LineListBox::LineListBox()
669 : ValueSet(nullptr)
670 , m_nWidth( 5 )
671 , aVirDev(VclPtr<VirtualDevice>::Create())
672 , aColor(Application::GetSettings().GetStyleSettings().GetWindowTextColor())
673 , maPaintCol(COL_BLACK)
674 , eSourceUnit(FieldUnit::POINT)
676 aVirDev->SetLineColor();
677 aVirDev->SetMapMode( MapMode( MapUnit::MapTwip ) );
680 void LineListBox::SetDrawingArea(weld::DrawingArea* pDrawingArea)
682 ValueSet::SetDrawingArea(pDrawingArea);
684 OutputDevice& rDevice = pDrawingArea->get_ref_device();
686 aTxtSize.setWidth( rDevice.approximate_digit_width() );
687 aTxtSize.setHeight( rDevice.GetTextHeight() );
689 UpdatePaintLineColor();
692 sal_Int32 LineListBox::GetStylePos( sal_Int32 nListPos, tools::Long nWidth )
694 sal_Int32 nPos = -1;
695 if (!m_sNone.isEmpty())
696 nListPos--;
698 sal_Int32 n = 0;
699 size_t i = 0;
700 size_t nCount = m_vLineList.size();
701 while ( nPos == -1 && i < nCount )
703 auto& pData = m_vLineList[ i ];
704 if ( pData->GetMinWidth() <= nWidth )
706 if ( nListPos == n )
707 nPos = static_cast<sal_Int32>(i);
708 n++;
710 i++;
713 return nPos;
716 void LineListBox::InsertEntry(
717 const BorderWidthImpl& rWidthImpl, SvxBorderLineStyle nStyle, tools::Long nMinWidth,
718 ColorFunc pColor1Fn, ColorFunc pColor2Fn, ColorDistFunc pColorDistFn )
720 m_vLineList.emplace_back(new ImpLineListData(
721 rWidthImpl, nStyle, nMinWidth, pColor1Fn, pColor2Fn, pColorDistFn));
724 SvxBorderLineStyle LineListBox::GetEntryStyle( sal_Int32 nPos ) const
726 ImpLineListData* pData = (0 <= nPos && o3tl::make_unsigned(nPos) < m_vLineList.size()) ? m_vLineList[ nPos ].get() : nullptr;
727 return pData ? pData->GetStyle() : SvxBorderLineStyle::NONE;
730 void LineListBox::UpdatePaintLineColor()
732 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
733 Color aNewCol( rSettings.GetWindowColor().IsDark()? rSettings.GetLabelTextColor() : aColor );
735 bool bRet = aNewCol != maPaintCol;
737 if( bRet )
738 maPaintCol = aNewCol;
741 Size LineListBox::UpdateEntries( tools::Long nOldWidth )
743 Size aSize;
745 UpdatePaintLineColor( );
747 sal_Int32 nSelEntry = GetSelectItemPos();
748 sal_Int32 nTypePos = GetStylePos( nSelEntry, nOldWidth );
750 // Remove the old entries
751 Clear();
753 sal_uInt16 nId(1);
755 // Add the new entries based on the defined width
756 if (!m_sNone.isEmpty())
757 InsertItem(nId++, Image(), m_sNone);
759 sal_uInt16 n = 0;
760 sal_uInt16 nCount = m_vLineList.size( );
761 while ( n < nCount )
763 auto& pData = m_vLineList[ n ];
764 if ( pData->GetMinWidth() <= m_nWidth )
766 BitmapEx aBmp;
767 ImpGetLine( pData->GetLine1ForWidth( m_nWidth ),
768 pData->GetLine2ForWidth( m_nWidth ),
769 pData->GetDistForWidth( m_nWidth ),
770 GetColorLine1( GetItemCount( ) ),
771 GetColorLine2( GetItemCount( ) ),
772 GetColorDist( GetItemCount( ) ),
773 pData->GetStyle(), aBmp );
774 InsertItem(nId, Image(aBmp), SvtLineListBox::GetLineStyleName(pData->GetStyle()));
775 Size aBmpSize = aBmp.GetSizePixel();
776 if (aBmpSize.Width() > aSize.Width())
777 aSize.setWidth(aBmpSize.getWidth());
778 if (aBmpSize.Height() > aSize.Height())
779 aSize.setHeight(aBmpSize.getHeight());
780 if ( n == nTypePos )
781 SelectItem(nId);
783 else if ( n == nTypePos )
784 SetNoSelection();
785 n++;
786 ++nId;
789 Invalidate();
791 return aSize;
794 Color LineListBox::GetColorLine1( sal_Int32 nPos )
796 sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
797 if (nStyle == -1)
798 return GetPaintColor( );
799 auto& pData = m_vLineList[ nStyle ];
800 return pData->GetColorLine1( GetColor( ) );
803 Color LineListBox::GetColorLine2( sal_Int32 nPos )
805 sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
806 if (nStyle == -1)
807 return GetPaintColor( );
808 auto& pData = m_vLineList[ nStyle ];
809 return pData->GetColorLine2( GetColor( ) );
812 Color LineListBox::GetColorDist( sal_Int32 nPos )
814 Color rResult = Application::GetSettings().GetStyleSettings().GetFieldColor();
816 sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
817 if (nStyle == -1)
818 return rResult;
819 auto& pData = m_vLineList[ nStyle ];
820 return pData->GetColorDist( GetColor( ), rResult );
824 namespace {
826 class SvxLineWindow_Impl final : public WeldToolbarPopup
828 private:
829 rtl::Reference<SvxFrameToolBoxControl> m_xControl;
830 std::unique_ptr<LineListBox> m_xLineStyleLb;
831 std::unique_ptr<weld::CustomWeld> m_xLineStyleLbWin;
832 bool m_bIsWriter;
834 DECL_LINK( SelectHdl, ValueSet*, void );
836 public:
837 SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent);
838 virtual void GrabFocus() override
840 m_xLineStyleLb->GrabFocus();
846 class SvxStyleToolBoxControl;
848 class SfxStyleControllerItem_Impl : public SfxStatusListener
850 public:
851 SfxStyleControllerItem_Impl( const Reference< XDispatchProvider >& rDispatchProvider,
852 sal_uInt16 nSlotId,
853 const OUString& rCommand,
854 SvxStyleToolBoxControl& rTbxCtl );
856 protected:
857 virtual void StateChangedAtStatusListener( SfxItemState eState, const SfxPoolItem* pState ) override;
859 private:
860 SvxStyleToolBoxControl& rControl;
863 #define BUTTON_PADDING 10
864 #define ITEM_HEIGHT 30
866 SvxStyleBox_Base::SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
867 OUString aCommand,
868 SfxStyleFamily eFamily,
869 const Reference< XDispatchProvider >& rDispatchProvider,
870 const Reference< XFrame >& _xFrame,
871 OUString _aClearFormatKey,
872 OUString _aMoreKey,
873 bool bInSpec, SvxStyleToolBoxControl& rCtrl)
874 : m_rCtrl(rCtrl)
875 , m_xMenuBuilder(Application::CreateBuilder(nullptr, "svx/ui/stylemenu.ui"))
876 , m_xMenu(m_xMenuBuilder->weld_menu("menu"))
877 , m_xWidget(std::move(xWidget))
878 , eStyleFamily( eFamily )
879 , m_nMaxUserDrawFontWidth(0)
880 , m_nLastItemWithMenu(-1)
881 , bRelease( true )
882 , m_xDispatchProvider( rDispatchProvider )
883 , m_xFrame(_xFrame)
884 , m_aCommand(std::move( aCommand ))
885 , aClearFormatKey(std::move( _aClearFormatKey ))
886 , aMoreKey(std::move( _aMoreKey ))
887 , bInSpecialMode( bInSpec )
889 m_xWidget->connect_changed(LINK(this, SvxStyleBox_Base, SelectHdl));
890 m_xWidget->connect_key_press(LINK(this, SvxStyleBox_Base, KeyInputHdl));
891 m_xWidget->connect_entry_activate(LINK(this, SvxStyleBox_Base, ActivateHdl));
892 m_xWidget->connect_focus_out(LINK(this, SvxStyleBox_Base, FocusOutHdl));
893 m_xWidget->connect_get_property_tree(LINK(this, SvxStyleBox_Base, DumpAsPropertyTreeHdl));
894 m_xWidget->set_help_id(HID_STYLE_LISTBOX);
895 m_xWidget->set_entry_completion(true);
896 m_xMenu->connect_activate(LINK(this, SvxStyleBox_Base, MenuSelectHdl));
898 m_xWidget->connect_custom_get_size(LINK(this, SvxStyleBox_Base, CustomGetSizeHdl));
899 m_xWidget->connect_custom_render(LINK(this, SvxStyleBox_Base, CustomRenderHdl));
900 m_xWidget->set_custom_renderer(true);
902 m_xWidget->set_entry_width_chars(COMBO_WIDTH_IN_CHARS + 3);
905 IMPL_LINK(SvxStyleBox_Base, CustomGetSizeHdl, OutputDevice&, rArg, Size)
907 CalcOptimalExtraUserWidth(rArg);
908 return Size(m_nMaxUserDrawFontWidth, ITEM_HEIGHT);
911 SvxStyleBox_Impl::SvxStyleBox_Impl(vcl::Window* pParent,
912 const OUString& rCommand,
913 SfxStyleFamily eFamily,
914 const Reference< XDispatchProvider >& rDispatchProvider,
915 const Reference< XFrame >& _xFrame,
916 const OUString& rClearFormatKey,
917 const OUString& rMoreKey,
918 bool bInSpec, SvxStyleToolBoxControl& rCtrl)
919 : InterimItemWindow(pParent, "svx/ui/applystylebox.ui", "ApplyStyleBox")
920 , SvxStyleBox_Base(m_xBuilder->weld_combo_box("applystyle"), rCommand, eFamily,
921 rDispatchProvider, _xFrame, rClearFormatKey, rMoreKey, bInSpec, rCtrl)
923 InitControlBase(m_xWidget.get());
925 set_id("applystyle");
926 SetOptimalSize();
929 void SvxStyleBox_Base::ReleaseFocus()
931 if ( !bRelease )
933 bRelease = true;
934 return;
936 if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
937 m_xFrame->getContainerWindow()->setFocus();
940 IMPL_LINK(SvxStyleBox_Base, MenuSelectHdl, const OUString&, rMenuIdent, void)
942 if (m_nLastItemWithMenu < 0 || m_nLastItemWithMenu >= m_xWidget->get_count())
943 return;
945 OUString sEntry = m_xWidget->get_text(m_nLastItemWithMenu);
947 ReleaseFocus(); // It must be after getting entry pos!
948 Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue("Param", sEntry),
949 comphelper::makePropertyValue("Family",
950 sal_Int16( eStyleFamily )) };
952 if (rMenuIdent == "update")
954 SfxToolBoxControl::Dispatch( m_xDispatchProvider,
955 ".uno:StyleUpdateByExample", aArgs );
957 else if (rMenuIdent == "edit")
959 SfxToolBoxControl::Dispatch( m_xDispatchProvider,
960 ".uno:EditStyle", aArgs );
964 IMPL_STATIC_LINK_NOARG(SvxStyleBox_Base, ShowMoreHdl, void*, void)
966 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
967 DBG_ASSERT( pViewFrm, "SvxStyleBox_Base::Select(): no viewframe" );
968 if (!pViewFrm)
969 return;
970 pViewFrm->ShowChildWindow(SID_SIDEBAR);
971 ::sfx2::sidebar::Sidebar::ShowPanel(u"StyleListPanel", pViewFrm->GetFrame().GetFrameInterface(), true);
974 IMPL_LINK(SvxStyleBox_Base, SelectHdl, weld::ComboBox&, rCombo, void)
976 Select(rCombo.changed_by_direct_pick()); // only when picked from the list
979 IMPL_LINK_NOARG(SvxStyleBox_Base, ActivateHdl, weld::ComboBox&, bool)
981 Select(true);
982 return true;
985 void SvxStyleBox_Base::Select(bool bNonTravelSelect)
987 if (!bNonTravelSelect)
988 return;
990 OUString aSearchEntry(m_xWidget->get_active_text());
991 bool bDoIt = true, bClear = false;
992 if( bInSpecialMode )
994 if( aSearchEntry == aClearFormatKey && m_xWidget->get_active() == 0 )
996 aSearchEntry = sDefaultStyle;
997 bClear = true;
998 //not only apply default style but also call 'ClearFormatting'
999 Sequence< PropertyValue > aEmptyVals;
1000 SfxToolBoxControl::Dispatch( m_xDispatchProvider, ".uno:ResetAttributes",
1001 aEmptyVals);
1003 else if (aSearchEntry == aMoreKey && m_xWidget->get_active() == (m_xWidget->get_count() - 1))
1005 Application::PostUserEvent(LINK(nullptr, SvxStyleBox_Base, ShowMoreHdl));
1006 //tdf#113214 change text back to previous entry
1007 set_active_or_entry_text(m_xWidget->get_saved_value());
1008 bDoIt = false;
1012 //Do we need to create a new style?
1013 SfxObjectShell *pShell = SfxObjectShell::Current();
1014 if (!pShell)
1015 return;
1017 SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool();
1018 SfxStyleSheetBase* pStyle = nullptr;
1020 bool bCreateNew = false;
1022 if ( pPool )
1024 pStyle = pPool->First(eStyleFamily);
1025 while ( pStyle && pStyle->GetName() != aSearchEntry )
1026 pStyle = pPool->Next();
1029 if ( !pStyle )
1031 // cannot find the style for whatever reason
1032 // therefore create a new style
1033 bCreateNew = true;
1036 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
1037 This instance may be deleted in the meantime (i.e. when a dialog is opened
1038 while in Dispatch()), accessing members will crash in this case. */
1039 ReleaseFocus();
1041 if( !bDoIt )
1042 return;
1044 if ( bClear )
1045 set_active_or_entry_text(aSearchEntry);
1046 m_xWidget->save_value();
1048 Sequence< PropertyValue > aArgs( 2 );
1049 auto pArgs = aArgs.getArray();
1050 pArgs[0].Value <<= aSearchEntry;
1051 pArgs[1].Name = "Family";
1052 pArgs[1].Value <<= sal_Int16( eStyleFamily );
1053 if( bCreateNew )
1055 pArgs[0].Name = "Param";
1056 SfxToolBoxControl::Dispatch( m_xDispatchProvider, ".uno:StyleNewByExample", aArgs);
1058 else
1060 pArgs[0].Name = "Template";
1061 SfxToolBoxControl::Dispatch( m_xDispatchProvider, m_aCommand, aArgs );
1065 void SvxStyleBox_Base::SetFamily( SfxStyleFamily eNewFamily )
1067 eStyleFamily = eNewFamily;
1070 IMPL_LINK_NOARG(SvxStyleBox_Base, FocusOutHdl, weld::Widget&, void)
1072 if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus
1073 set_active_or_entry_text(m_xWidget->get_saved_value());
1076 IMPL_LINK(SvxStyleBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
1078 return DoKeyInput(rKEvt);
1081 bool SvxStyleBox_Base::DoKeyInput(const KeyEvent& rKEvt)
1083 bool bHandled = false;
1085 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
1087 switch (nCode)
1089 case KEY_TAB:
1090 bRelease = false;
1091 Select(true);
1092 break;
1093 case KEY_ESCAPE:
1094 set_active_or_entry_text(m_xWidget->get_saved_value());
1095 if (!m_rCtrl.IsInSidebar())
1097 ReleaseFocus();
1098 bHandled = true;
1100 break;
1103 return bHandled;
1106 bool SvxStyleBox_Impl::DoKeyInput(const KeyEvent& rKEvt)
1108 return SvxStyleBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
1111 void SvxStyleBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
1113 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
1114 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
1116 SetOptimalSize();
1119 InterimItemWindow::DataChanged( rDCEvt );
1122 void SvxStyleBox_Impl::SetOptimalSize()
1124 // set width in chars low so the size request will not be overridden
1125 m_xWidget->set_entry_width_chars(1);
1126 // tdf#132338 purely using this calculation to keep things their traditional width
1127 Size aSize(LogicToPixel(Size((COMBO_WIDTH_IN_CHARS + 3) * 4, 0), MapMode(MapUnit::MapAppFont)));
1128 m_xWidget->set_size_request(aSize.Width(), -1);
1130 SetSizePixel(get_preferred_size());
1133 namespace
1135 std::vector<ScriptInfo> CheckScript(const OUString &rStyleName)
1137 assert(!rStyleName.isEmpty()); // must have a preview text here!
1139 std::vector<ScriptInfo> aScriptChanges;
1141 auto aEditEngine = EditEngine(nullptr);
1142 aEditEngine.SetText(rStyleName);
1144 auto aScript = aEditEngine.GetScriptType({ 0, 0, 0, 0 });
1145 for (sal_Int32 i = 1; i <= rStyleName.getLength(); i++)
1147 auto aNextScript = aEditEngine.GetScriptType({ 0, i, 0, i });
1148 if (aNextScript != aScript || i == rStyleName.getLength())
1149 aScriptChanges.emplace_back(aScript, i);
1150 aScript = aNextScript;
1153 return aScriptChanges;
1157 tools::Rectangle SvxStyleBox_Base::CalcBoundRect(vcl::RenderContext& rRenderContext, const OUString &rStyleName, std::vector<ScriptInfo>& rScriptChanges, double fRatio)
1159 tools::Rectangle aTextRect;
1161 SvtScriptType aScript;
1162 sal_uInt16 nIdx = 0;
1163 sal_Int32 nStart = 0;
1164 sal_Int32 nEnd;
1165 size_t nCnt = rScriptChanges.size();
1167 if (nCnt)
1169 nEnd = rScriptChanges[nIdx].changePos;
1170 aScript = rScriptChanges[nIdx].scriptType;
1172 else
1174 nEnd = rStyleName.getLength();
1175 aScript = SvtScriptType::LATIN;
1180 auto oFont = (aScript == SvtScriptType::ASIAN) ?
1181 m_oCJKFont :
1182 ((aScript == SvtScriptType::COMPLEX) ?
1183 m_oCTLFont :
1184 m_oFont);
1186 rRenderContext.Push(vcl::PushFlags::FONT);
1188 if (oFont)
1189 rRenderContext.SetFont(*oFont);
1191 if (fRatio != 1)
1193 vcl::Font aFont(rRenderContext.GetFont());
1194 Size aPixelSize(aFont.GetFontSize());
1195 aPixelSize.setWidth(aPixelSize.Width() * fRatio);
1196 aPixelSize.setHeight(aPixelSize.Height() * fRatio);
1197 aFont.SetFontSize(aPixelSize);
1198 rRenderContext.SetFont(aFont);
1201 tools::Rectangle aRect;
1202 rRenderContext.GetTextBoundRect(aRect, rStyleName, nStart, nStart, nEnd - nStart);
1203 aTextRect = aTextRect.Union(aRect);
1205 tools::Long nWidth = rRenderContext.GetTextWidth(rStyleName, nStart, nEnd - nStart);
1207 rRenderContext.Pop();
1209 if (nIdx >= rScriptChanges.size())
1210 break;
1212 rScriptChanges[nIdx++].textWidth = nWidth;
1214 if (nEnd < rStyleName.getLength() && nIdx < nCnt)
1216 nStart = nEnd;
1217 nEnd = rScriptChanges[nIdx].changePos;
1218 aScript = rScriptChanges[nIdx].scriptType;
1220 else
1221 break;
1223 while(true);
1225 return aTextRect;
1228 void SvxStyleBox_Base::UserDrawEntry(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const tools::Rectangle& rTextRect, const OUString &rStyleName, const std::vector<ScriptInfo>& rScriptChanges)
1230 // IMG_TXT_DISTANCE in ilstbox.hxx is 6, then 1 is added as
1231 // nBorder, and we are adding 1 in order to look better when
1232 // italics is present
1233 const int nLeftDistance = 8;
1235 Point aPos(rRect.TopLeft());
1236 aPos.AdjustX(nLeftDistance );
1238 double fRatio = 1;
1239 if (rTextRect.Bottom() > rRect.GetHeight())
1240 fRatio = static_cast<double>(rRect.GetHeight()) / rTextRect.Bottom();
1241 else
1242 aPos.AdjustY((rRect.GetHeight() - rTextRect.Bottom()) / 2);
1244 SvtScriptType aScript;
1245 sal_uInt16 nIdx = 0;
1246 sal_Int32 nStart = 0;
1247 sal_Int32 nEnd;
1248 size_t nCnt = rScriptChanges.size();
1250 if (nCnt)
1252 nEnd = rScriptChanges[nIdx].changePos;
1253 aScript = rScriptChanges[nIdx].scriptType;
1255 else
1257 nEnd = rStyleName.getLength();
1258 aScript = SvtScriptType::LATIN;
1264 auto oFont = (aScript == SvtScriptType::ASIAN) ?
1265 m_oCJKFont :
1266 ((aScript == SvtScriptType::COMPLEX) ?
1267 m_oCTLFont :
1268 m_oFont);
1270 rRenderContext.Push(vcl::PushFlags::FONT);
1272 if (oFont)
1273 rRenderContext.SetFont(*oFont);
1275 if (fRatio != 1)
1277 vcl::Font aFont(rRenderContext.GetFont());
1278 Size aPixelSize(aFont.GetFontSize());
1279 aPixelSize.setWidth(aPixelSize.Width() * fRatio);
1280 aPixelSize.setHeight(aPixelSize.Height() * fRatio);
1281 aFont.SetFontSize(aPixelSize);
1282 rRenderContext.SetFont(aFont);
1285 rRenderContext.DrawText(aPos, rStyleName, nStart, nEnd - nStart);
1287 rRenderContext.Pop();
1289 aPos.AdjustX(rScriptChanges[nIdx++].textWidth * fRatio);
1290 if (nEnd < rStyleName.getLength() && nIdx < nCnt)
1292 nStart = nEnd;
1293 nEnd = rScriptChanges[nIdx].changePos;
1294 aScript = rScriptChanges[nIdx].scriptType;
1296 else
1297 break;
1299 while(true);
1302 static bool GetWhich(const SfxItemSet& rSet, sal_uInt16 nSlot, sal_uInt16& rWhich)
1304 rWhich = rSet.GetPool()->GetWhich(nSlot);
1305 return rSet.GetItemState(rWhich) >= SfxItemState::DEFAULT;
1308 static bool SetFont(const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont)
1310 sal_uInt16 nWhich;
1311 if (GetWhich(rSet, nSlot, nWhich))
1313 const auto& rFontItem = static_cast<const SvxFontItem&>(rSet.Get(nWhich));
1314 rFont.SetFamilyName(rFontItem.GetFamilyName());
1315 rFont.SetStyleName(rFontItem.GetStyleName());
1316 return true;
1318 return false;
1321 static bool SetFontSize(vcl::RenderContext& rRenderContext, const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont)
1323 sal_uInt16 nWhich;
1324 if (GetWhich(rSet, nSlot, nWhich))
1326 const auto& rFontHeightItem = static_cast<const SvxFontHeightItem&>(rSet.Get(nWhich));
1327 if (SfxObjectShell *pShell = SfxObjectShell::Current())
1329 Size aFontSize(0, rFontHeightItem.GetHeight());
1330 Size aPixelSize(rRenderContext.LogicToPixel(aFontSize, MapMode(pShell->GetMapUnit())));
1331 rFont.SetFontSize(aPixelSize);
1332 return true;
1335 return false;
1338 static void SetFontStyle(const SfxItemSet& rSet, sal_uInt16 nPosture, sal_uInt16 nWeight, SvxFont& rFont)
1340 sal_uInt16 nWhich;
1341 if (GetWhich(rSet, nPosture, nWhich))
1343 const auto& rItem = static_cast<const SvxPostureItem&>(rSet.Get(nWhich));
1344 rFont.SetItalic(rItem.GetPosture());
1347 if (GetWhich(rSet, nWeight, nWhich))
1349 const auto& rItem = static_cast<const SvxWeightItem&>(rSet.Get(nWhich));
1350 rFont.SetWeight(rItem.GetWeight());
1354 void SvxStyleBox_Base::SetupEntry(vcl::RenderContext& rRenderContext, sal_Int32 nItem, const tools::Rectangle& rRect, std::u16string_view rStyleName, bool bIsNotSelected)
1356 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1357 if (!bIsNotSelected)
1358 rRenderContext.SetTextColor(rStyleSettings.GetHighlightTextColor());
1359 else
1360 rRenderContext.SetTextColor(rStyleSettings.GetDialogTextColor());
1362 // handle the push-button
1363 if (!bIsNotSelected)
1365 if (nItem == 0 || nItem == m_xWidget->get_count() - 1)
1366 m_xWidget->set_item_menu(OUString::number(nItem), nullptr);
1367 else
1369 m_nLastItemWithMenu = nItem;
1370 m_xWidget->set_item_menu(OUString::number(nItem), m_xMenu.get());
1374 if (nItem <= 0 || nItem >= m_xWidget->get_count() - 1)
1375 return;
1377 SfxObjectShell *pShell = SfxObjectShell::Current();
1378 if (!pShell)
1379 return;
1381 SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool();
1382 if (!pPool)
1383 return;
1385 SfxStyleSheetBase* pStyle = pPool->First(eStyleFamily);
1386 while (pStyle && pStyle->GetName() != rStyleName)
1387 pStyle = pPool->Next();
1389 if (!pStyle )
1390 return;
1392 std::optional<SfxItemSet> const pItemSet(pStyle->GetItemSetForPreview());
1393 if (!pItemSet) return;
1395 SvxFont aFont;
1396 SvxFont aCJKFont;
1397 SvxFont aCTLFont;
1399 SetFontStyle(*pItemSet, SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_WEIGHT, aFont);
1400 SetFontStyle(*pItemSet, SID_ATTR_CHAR_CJK_POSTURE, SID_ATTR_CHAR_CJK_WEIGHT, aCJKFont);
1401 SetFontStyle(*pItemSet, SID_ATTR_CHAR_CTL_POSTURE, SID_ATTR_CHAR_CTL_WEIGHT, aCTLFont);
1403 const SfxPoolItem *pItem = pItemSet->GetItem( SID_ATTR_CHAR_CONTOUR );
1404 if ( pItem )
1406 auto aVal = static_cast< const SvxContourItem* >( pItem )->GetValue();
1407 aFont.SetOutline(aVal);
1408 aCJKFont.SetOutline(aVal);
1409 aCTLFont.SetOutline(aVal);
1412 pItem = pItemSet->GetItem( SID_ATTR_CHAR_SHADOWED );
1413 if ( pItem )
1415 auto aVal = static_cast< const SvxShadowedItem* >( pItem )->GetValue();
1416 aFont.SetShadow(aVal);
1417 aCJKFont.SetShadow(aVal);
1418 aCTLFont.SetShadow(aVal);
1421 pItem = pItemSet->GetItem( SID_ATTR_CHAR_RELIEF );
1422 if ( pItem )
1424 auto aVal = static_cast< const SvxCharReliefItem* >( pItem )->GetValue();
1425 aFont.SetRelief(aVal);
1426 aCJKFont.SetRelief(aVal);
1427 aCTLFont.SetRelief(aVal);
1430 pItem = pItemSet->GetItem( SID_ATTR_CHAR_UNDERLINE );
1431 if ( pItem )
1433 auto aVal = static_cast<const SvxUnderlineItem*>(pItem)->GetLineStyle();
1434 aFont.SetUnderline(aVal);
1435 aCJKFont.SetUnderline(aVal);
1436 aCTLFont.SetUnderline(aVal);
1439 pItem = pItemSet->GetItem( SID_ATTR_CHAR_OVERLINE );
1440 if ( pItem )
1442 auto aVal = static_cast< const SvxOverlineItem* >( pItem )->GetValue();
1443 aFont.SetOverline(aVal);
1444 aCJKFont.SetOverline(aVal);
1445 aCTLFont.SetOverline(aVal);
1448 pItem = pItemSet->GetItem( SID_ATTR_CHAR_STRIKEOUT );
1449 if ( pItem )
1451 auto aVal = static_cast< const SvxCrossedOutItem* >( pItem )->GetStrikeout();
1452 aFont.SetStrikeout(aVal);
1453 aCJKFont.SetStrikeout(aVal);
1454 aCTLFont.SetStrikeout(aVal);
1457 pItem = pItemSet->GetItem( SID_ATTR_CHAR_CASEMAP );
1458 if ( pItem )
1460 auto aVal = static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap();
1461 aFont.SetCaseMap(aVal);
1462 aCJKFont.SetCaseMap(aVal);
1463 aCTLFont.SetCaseMap(aVal);
1466 pItem = pItemSet->GetItem( SID_ATTR_CHAR_EMPHASISMARK );
1467 if ( pItem )
1469 auto aVal = static_cast< const SvxEmphasisMarkItem* >( pItem )->GetEmphasisMark();
1470 aFont.SetEmphasisMark(aVal);
1471 aCJKFont.SetEmphasisMark(aVal);
1472 aCTLFont.SetEmphasisMark(aVal);
1475 // setup the device & draw
1476 Color aFontCol = COL_AUTO, aBackCol = COL_AUTO;
1478 pItem = pItemSet->GetItem( SID_ATTR_CHAR_COLOR );
1479 // text color, when nothing is selected
1480 if ( (nullptr != pItem) && bIsNotSelected)
1481 aFontCol = static_cast< const SvxColorItem* >( pItem )->GetValue();
1483 drawing::FillStyle style = drawing::FillStyle_NONE;
1484 // which kind of Fill style is selected
1485 pItem = pItemSet->GetItem( XATTR_FILLSTYLE );
1486 // only when ok and not selected
1487 if ( (nullptr != pItem) && bIsNotSelected)
1488 style = static_cast< const XFillStyleItem* >( pItem )->GetValue();
1490 switch(style)
1492 case drawing::FillStyle_SOLID:
1494 // set background color
1495 pItem = pItemSet->GetItem( XATTR_FILLCOLOR );
1496 if ( nullptr != pItem )
1497 aBackCol = static_cast< const XFillColorItem* >( pItem )->GetColorValue();
1499 if ( aBackCol != COL_AUTO )
1501 rRenderContext.SetFillColor(aBackCol);
1502 rRenderContext.DrawRect(rRect);
1505 break;
1507 default: break;
1508 //TODO Draw the other background styles: gradient, hatching and bitmap
1511 // when the font and background color are too similar, adjust the Font-Color
1512 if( (aFontCol != COL_AUTO) || (aBackCol != COL_AUTO) )
1513 aFontCol = TestColorsVisible(aFontCol, (aBackCol != COL_AUTO) ? aBackCol : rRenderContext.GetBackground().GetColor());
1515 // set text color
1516 if ( aFontCol != COL_AUTO )
1517 rRenderContext.SetTextColor(aFontCol);
1519 if (SetFont(*pItemSet, SID_ATTR_CHAR_FONT, aFont) &&
1520 SetFontSize(rRenderContext, *pItemSet, SID_ATTR_CHAR_FONTHEIGHT, aFont))
1521 m_oFont = aFont;
1523 if (SetFont(*pItemSet, SID_ATTR_CHAR_CJK_FONT, aCJKFont) &&
1524 SetFontSize(rRenderContext, *pItemSet, SID_ATTR_CHAR_CJK_FONTHEIGHT, aCJKFont))
1525 m_oCJKFont = aCJKFont;
1527 if (SetFont(*pItemSet, SID_ATTR_CHAR_CTL_FONT, aCTLFont) &&
1528 SetFontSize(rRenderContext, *pItemSet, SID_ATTR_CHAR_CTL_FONTHEIGHT, aCTLFont))
1529 m_oCTLFont = aCTLFont;
1532 IMPL_LINK(SvxStyleBox_Base, CustomRenderHdl, weld::ComboBox::render_args, aPayload, void)
1534 vcl::RenderContext& rRenderContext = std::get<0>(aPayload);
1535 const ::tools::Rectangle& rRect = std::get<1>(aPayload);
1536 bool bSelected = std::get<2>(aPayload);
1537 const OUString& rId = std::get<3>(aPayload);
1539 sal_uInt32 nIndex = rId.toUInt32();
1541 OUString aStyleName(m_xWidget->get_text(nIndex));
1543 rRenderContext.Push(vcl::PushFlags::FILLCOLOR | vcl::PushFlags::FONT | vcl::PushFlags::TEXTCOLOR);
1545 SetupEntry(rRenderContext, nIndex, rRect, aStyleName, !bSelected);
1546 auto aScriptChanges = CheckScript(aStyleName);
1547 auto aTextRect = CalcBoundRect(rRenderContext, aStyleName, aScriptChanges);
1548 UserDrawEntry(rRenderContext, rRect, aTextRect, aStyleName, aScriptChanges);
1550 rRenderContext.Pop();
1553 void SvxStyleBox_Base::CalcOptimalExtraUserWidth(vcl::RenderContext& rRenderContext)
1555 if (m_nMaxUserDrawFontWidth)
1556 return;
1558 tools::Long nMaxNormalFontWidth = 0;
1559 sal_Int32 nEntryCount = m_xWidget->get_count();
1560 for (sal_Int32 i = 0; i < nEntryCount; ++i)
1562 OUString sStyleName(get_text(i));
1563 tools::Rectangle aTextRectForDefaultFont;
1564 rRenderContext.GetTextBoundRect(aTextRectForDefaultFont, sStyleName);
1566 const tools::Long nWidth = aTextRectForDefaultFont.GetWidth();
1568 nMaxNormalFontWidth = std::max(nWidth, nMaxNormalFontWidth);
1571 m_nMaxUserDrawFontWidth = nMaxNormalFontWidth;
1572 for (sal_Int32 i = 1; i < nEntryCount-1; ++i)
1574 OUString sStyleName(get_text(i));
1576 if (sStyleName.isEmpty())
1577 continue;
1579 rRenderContext.Push(vcl::PushFlags::FILLCOLOR | vcl::PushFlags::FONT | vcl::PushFlags::TEXTCOLOR);
1580 SetupEntry(rRenderContext, i, tools::Rectangle(0, 0, RECT_MAX, ITEM_HEIGHT), sStyleName, true);
1581 auto aScriptChanges = CheckScript(sStyleName);
1582 tools::Rectangle aTextRectForActualFont = CalcBoundRect(rRenderContext, sStyleName, aScriptChanges);
1583 if (aTextRectForActualFont.Bottom() > ITEM_HEIGHT)
1585 //Font didn't fit, re-calculate with adjustment ratio.
1586 double fRatio = static_cast<double>(ITEM_HEIGHT) / aTextRectForActualFont.Bottom();
1587 aTextRectForActualFont = CalcBoundRect(rRenderContext, sStyleName, aScriptChanges, fRatio);
1589 rRenderContext.Pop();
1591 const int nWidth = aTextRectForActualFont.GetWidth() + m_xWidget->get_menu_button_width() + BUTTON_PADDING;
1593 m_nMaxUserDrawFontWidth = std::max(nWidth, m_nMaxUserDrawFontWidth);
1597 // test is the color between Font- and background-color to be identify
1598 // return is always the Font-Color
1599 // when both light or dark, change the Contrast
1600 // in other case do not change the origin color
1601 // when the color is R=G=B=128 the DecreaseContrast make 128 the need an exception
1602 Color SvxStyleBox_Base::TestColorsVisible(const Color &FontCol, const Color &BackCol)
1604 constexpr sal_uInt8 ChgVal = 60; // increase/decrease the Contrast
1606 Color retCol = FontCol;
1607 if ((FontCol.IsDark() == BackCol.IsDark()) && (FontCol.IsBright() == BackCol.IsBright()))
1609 sal_uInt8 lumi = retCol.GetLuminance();
1611 if((lumi > 120) && (lumi < 140))
1612 retCol.DecreaseLuminance(ChgVal / 2);
1613 else
1614 retCol.DecreaseContrast(ChgVal);
1617 return retCol;
1620 IMPL_LINK(SvxStyleBox_Base, DumpAsPropertyTreeHdl, tools::JsonWriter&, rJsonWriter, void)
1622 if (!m_xWidget)
1623 return;
1626 auto entriesNode = rJsonWriter.startNode("entries");
1627 for (int i = 0, nEntryCount = m_xWidget->get_count(); i < nEntryCount; ++i)
1629 auto entryNode = rJsonWriter.startNode("");
1630 rJsonWriter.put("", m_xWidget->get_text(i));
1634 int nActive = m_xWidget->get_active();
1635 rJsonWriter.put("selectedCount", static_cast<sal_Int32>(nActive == -1 ? 0 : 1));
1638 auto selectedNode = rJsonWriter.startNode("selectedEntries");
1639 if (nActive != -1)
1641 auto node = rJsonWriter.startNode("");
1642 rJsonWriter.put("", static_cast<sal_Int32>(nActive));
1646 rJsonWriter.put("command", ".uno:StyleApply");
1649 static bool lcl_GetDocFontList(const FontList** ppFontList, SvxFontNameBox_Base* pBox)
1651 bool bChanged = false;
1652 const SfxObjectShell* pDocSh = SfxObjectShell::Current();
1653 const SvxFontListItem* pFontListItem = nullptr;
1655 if ( pDocSh )
1656 pFontListItem =
1657 static_cast<const SvxFontListItem*>(pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST ));
1658 else
1660 ::std::unique_ptr<FontList> aFontList(new FontList(Application::GetDefaultDevice()));
1661 *ppFontList = aFontList.get();
1662 pBox->SetOwnFontList(std::move(aFontList));
1663 bChanged = true;
1666 if ( pFontListItem )
1668 const FontList* pNewFontList = pFontListItem->GetFontList();
1669 DBG_ASSERT( pNewFontList, "Doc-FontList not available!" );
1671 // No old list, but a new list
1672 if ( !*ppFontList && pNewFontList )
1674 // => take over
1675 *ppFontList = pNewFontList;
1676 bChanged = true;
1678 else
1680 // Comparing the font lists is not perfect.
1681 // When you change the font list in the Doc, you can track
1682 // changes here only on the Listbox, because ppFontList
1683 // has already been updated.
1684 bChanged =
1685 ( ( *ppFontList != pNewFontList ) ||
1686 pBox->GetListCount() != pNewFontList->GetFontNameCount() );
1687 // HACK: Comparing is incomplete
1689 if ( bChanged )
1690 *ppFontList = pNewFontList;
1693 if ( pBox )
1694 pBox->set_sensitive(true);
1696 else if ( pBox && ( pDocSh || !ppFontList ))
1698 // Disable box only when we have a SfxObjectShell and didn't get a font list OR
1699 // we don't have a SfxObjectShell and no current font list.
1700 // It's possible that we currently have no SfxObjectShell, but a current font list.
1701 // See #i58471: When a user set the focus into the font name combo box and opens
1702 // the help window with F1. After closing the help window, we disable the font name
1703 // combo box. The SfxObjectShell::Current() method returns in that case zero. But the
1704 // font list hasn't changed and therefore the combo box shouldn't be disabled!
1705 pBox->set_sensitive(false);
1708 // Fill the FontBox, also the new list if necessary
1709 if ( pBox && bChanged )
1711 if ( *ppFontList )
1712 pBox->Fill( *ppFontList );
1713 else
1714 pBox->Clear();
1716 return bChanged;
1719 SvxFontNameBox_Base::SvxFontNameBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
1720 const Reference<XDispatchProvider>& rDispatchProvider,
1721 const Reference<XFrame>& rFrame,
1722 SvxFontNameToolBoxControl& rCtrl)
1723 : m_xListener(new comphelper::ConfigurationListener("/org.openoffice.Office.Common/Font/View"))
1724 , m_aWYSIWYG(m_xListener, "ShowFontBoxWYSIWYG", *this)
1725 , m_aHistory(m_xListener, "History", *this)
1726 , m_rCtrl(rCtrl)
1727 , m_xWidget(new FontNameBox(std::move(xWidget)))
1728 , pFontList(nullptr)
1729 , nFtCount(0)
1730 , bRelease(true)
1731 , m_xDispatchProvider(rDispatchProvider)
1732 , m_xFrame(rFrame)
1733 , mbCheckingUnknownFont(false)
1735 EnableControls();
1737 m_xWidget->connect_changed(LINK(this, SvxFontNameBox_Base, SelectHdl));
1738 m_xWidget->connect_key_press(LINK(this, SvxFontNameBox_Base, KeyInputHdl));
1739 m_xWidget->connect_entry_activate(LINK(this, SvxFontNameBox_Base, ActivateHdl));
1740 m_xWidget->connect_focus_in(LINK(this, SvxFontNameBox_Base, FocusInHdl));
1741 m_xWidget->connect_focus_out(LINK(this, SvxFontNameBox_Base, FocusOutHdl));
1742 m_xWidget->connect_get_property_tree(LINK(this, SvxFontNameBox_Base, DumpAsPropertyTreeHdl));
1744 m_xWidget->set_entry_width_chars(COMBO_WIDTH_IN_CHARS + 5);
1747 SvxFontNameBox_Impl::SvxFontNameBox_Impl(vcl::Window* pParent, const Reference<XDispatchProvider>& rDispatchProvider,
1748 const Reference<XFrame>& rFrame, SvxFontNameToolBoxControl& rCtrl)
1749 : InterimItemWindow(pParent, "svx/ui/fontnamebox.ui", "FontNameBox")
1750 , SvxFontNameBox_Base(m_xBuilder->weld_combo_box("fontnamecombobox"), rDispatchProvider, rFrame, rCtrl)
1752 set_id("fontnamecombobox");
1753 SetOptimalSize();
1756 void SvxFontNameBox_Base::FillList()
1758 if (!m_xWidget) // e.g. disposed
1759 return;
1760 // Save old Selection, set back in the end
1761 int nStartPos, nEndPos;
1762 m_xWidget->get_entry_selection_bounds(nStartPos, nEndPos);
1764 // Did Doc-Fontlist change?
1765 lcl_GetDocFontList(&pFontList, this);
1767 m_xWidget->select_entry_region(nStartPos, nEndPos);
1770 bool SvxFontNameBox_Base::CheckFontIsAvailable(std::u16string_view fontname)
1772 lcl_GetDocFontList(&pFontList, this);
1773 return pFontList && pFontList->IsAvailable(fontname);
1776 void SvxFontNameBox_Base::CheckAndMarkUnknownFont()
1778 if (mbCheckingUnknownFont) //tdf#117537 block rentry
1779 return;
1780 mbCheckingUnknownFont = true;
1781 OUString fontname = m_xWidget->get_active_text();
1782 // tdf#154680 If a font is set and that font is unknown, show it in italic.
1783 vcl::Font font = m_xWidget->get_entry_font();
1784 if (fontname.isEmpty() || CheckFontIsAvailable(fontname))
1786 if( font.GetItalic() != ITALIC_NONE )
1788 font.SetItalic( ITALIC_NONE );
1789 m_xWidget->set_entry_font(font);
1790 m_xWidget->set_tooltip_text(SvxResId(RID_SVXSTR_CHARFONTNAME));
1793 else
1795 if( font.GetItalic() != ITALIC_NORMAL )
1797 font.SetItalic( ITALIC_NORMAL );
1798 m_xWidget->set_entry_font(font);
1799 m_xWidget->set_tooltip_text(SvxResId(RID_SVXSTR_CHARFONTNAME_NOTAVAILABLE));
1802 mbCheckingUnknownFont = false;
1805 void SvxFontNameBox_Base::Update( const css::awt::FontDescriptor* pFontDesc )
1807 if ( pFontDesc )
1809 aCurFont.SetFamilyName ( pFontDesc->Name );
1810 aCurFont.SetFamily ( FontFamily( pFontDesc->Family ) );
1811 aCurFont.SetStyleName ( pFontDesc->StyleName );
1812 aCurFont.SetPitch ( FontPitch( pFontDesc->Pitch ) );
1813 aCurFont.SetCharSet ( rtl_TextEncoding( pFontDesc->CharSet ) );
1815 OUString aCurName = aCurFont.GetFamilyName();
1816 OUString aText = m_xWidget->get_active_text();
1817 if (aText != aCurName)
1818 set_active_or_entry_text(aCurName);
1821 void SvxFontNameBox_Base::set_active_or_entry_text(const OUString& rText)
1823 m_xWidget->set_active_or_entry_text(rText);
1824 CheckAndMarkUnknownFont();
1827 IMPL_LINK_NOARG(SvxFontNameBox_Base, FocusInHdl, weld::Widget&, void)
1829 FillList();
1832 IMPL_LINK(SvxFontNameBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
1834 return DoKeyInput(rKEvt);
1837 bool SvxFontNameBox_Base::DoKeyInput(const KeyEvent& rKEvt)
1839 bool bHandled = false;
1841 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
1843 switch (nCode)
1845 case KEY_TAB:
1846 bRelease = false;
1847 Select(true);
1848 break;
1850 case KEY_ESCAPE:
1851 set_active_or_entry_text(m_xWidget->get_saved_value());
1852 if (!m_rCtrl.IsInSidebar())
1854 ReleaseFocus_Impl();
1855 bHandled = true;
1857 EndPreview();
1858 break;
1861 return bHandled;
1864 bool SvxFontNameBox_Impl::DoKeyInput(const KeyEvent& rKEvt)
1866 return SvxFontNameBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
1869 IMPL_LINK_NOARG(SvxFontNameBox_Base, FocusOutHdl, weld::Widget&, void)
1871 if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus
1873 set_active_or_entry_text(m_xWidget->get_saved_value());
1874 // send EndPreview
1875 EndPreview();
1879 void SvxFontNameBox_Impl::SetOptimalSize()
1881 // set width in chars low so the size request will not be overridden
1882 m_xWidget->set_entry_width_chars(1);
1883 // tdf#132338 purely using this calculation to keep things their traditional width
1884 Size aSize(LogicToPixel(Size((COMBO_WIDTH_IN_CHARS +5) * 4, 0), MapMode(MapUnit::MapAppFont)));
1885 m_xWidget->set_size_request(aSize.Width(), -1);
1887 SetSizePixel(get_preferred_size());
1890 void SvxFontNameBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
1892 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
1893 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
1895 SetOptimalSize();
1897 else if ( ( rDCEvt.GetType() == DataChangedEventType::FONTS ) ||
1898 ( rDCEvt.GetType() == DataChangedEventType::DISPLAY ) )
1900 // The old font list in shell has likely been destroyed at this point, so we need to get
1901 // the new one before doing anything further.
1902 lcl_GetDocFontList( &pFontList, this );
1906 void SvxFontNameBox_Base::ReleaseFocus_Impl()
1908 if ( !bRelease )
1910 bRelease = true;
1911 return;
1913 if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
1914 m_xFrame->getContainerWindow()->setFocus();
1917 void SvxFontNameBox_Base::EnableControls()
1919 bool bEnableMRU = m_aHistory.get();
1920 sal_uInt16 nEntries = bEnableMRU ? MAX_MRU_FONTNAME_ENTRIES : 0;
1922 bool bNewWYSIWYG = m_aWYSIWYG.get();
1923 bool bOldWYSIWYG = m_xWidget->IsWYSIWYGEnabled();
1925 if (m_xWidget->get_max_mru_count() != nEntries || bNewWYSIWYG != bOldWYSIWYG)
1927 // refill in the next GetFocus-Handler
1928 pFontList = nullptr;
1929 Clear();
1930 m_xWidget->set_max_mru_count(nEntries);
1933 if (bNewWYSIWYG != bOldWYSIWYG)
1934 m_xWidget->EnableWYSIWYG(bNewWYSIWYG);
1937 IMPL_LINK(SvxFontNameBox_Base, SelectHdl, weld::ComboBox&, rCombo, void)
1939 Select(rCombo.changed_by_direct_pick()); // only when picked from the list
1942 IMPL_LINK_NOARG(SvxFontNameBox_Base, ActivateHdl, weld::ComboBox&, bool)
1944 Select(true);
1945 return true;
1948 void SvxFontNameBox_Base::Select(bool bNonTravelSelect)
1950 Sequence< PropertyValue > aArgs( 1 );
1951 auto pArgs = aArgs.getArray();
1952 std::unique_ptr<SvxFontItem> pFontItem;
1953 if ( pFontList )
1955 FontMetric aFontMetric( pFontList->Get(m_xWidget->get_active_text(),
1956 aCurFont.GetWeight(),
1957 aCurFont.GetItalic() ) );
1958 aCurFont = aFontMetric;
1960 pFontItem.reset( new SvxFontItem( aFontMetric.GetFamilyType(),
1961 aFontMetric.GetFamilyName(),
1962 aFontMetric.GetStyleName(),
1963 aFontMetric.GetPitch(),
1964 aFontMetric.GetCharSet(),
1965 SID_ATTR_CHAR_FONT ) );
1967 Any a;
1968 pFontItem->QueryValue( a );
1969 pArgs[0].Value = a;
1972 if (bNonTravelSelect)
1974 CheckAndMarkUnknownFont();
1975 // #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
1976 // This instance may be deleted in the meantime (i.e. when a dialog is opened
1977 // while in Dispatch()), accessing members will crash in this case.
1978 ReleaseFocus_Impl();
1979 EndPreview();
1980 if (pFontItem)
1982 pArgs[0].Name = "CharFontName";
1983 SfxToolBoxControl::Dispatch( m_xDispatchProvider,
1984 ".uno:CharFontName",
1985 aArgs );
1988 else
1990 if (pFontItem)
1992 pArgs[0].Name = "CharPreviewFontName";
1993 SfxToolBoxControl::Dispatch( m_xDispatchProvider,
1994 ".uno:CharPreviewFontName",
1995 aArgs );
2000 IMPL_LINK(SvxFontNameBox_Base, DumpAsPropertyTreeHdl, tools::JsonWriter&, rJsonWriter, void)
2003 auto entriesNode = rJsonWriter.startNode("entries");
2004 for (int i = 0, nEntryCount = m_xWidget->get_count(); i < nEntryCount; ++i)
2006 auto entryNode = rJsonWriter.startNode("");
2007 rJsonWriter.put("", m_xWidget->get_text(i));
2011 int nSelectedEntry = m_xWidget->get_active();
2012 rJsonWriter.put("selectedCount", static_cast<sal_Int32>(nSelectedEntry == -1 ? 0 : 1));
2015 auto selectedNode = rJsonWriter.startNode("selectedEntries");
2016 if (nSelectedEntry != -1)
2018 auto entryNode = rJsonWriter.startNode("");
2019 rJsonWriter.put("", m_xWidget->get_text(nSelectedEntry));
2023 rJsonWriter.put("command", ".uno:CharFontName");
2026 ColorWindow::ColorWindow(OUString rCommand,
2027 std::shared_ptr<PaletteManager> xPaletteManager,
2028 ColorStatus& rColorStatus,
2029 sal_uInt16 nSlotId,
2030 const Reference< XFrame >& rFrame,
2031 const MenuOrToolMenuButton& rMenuButton,
2032 TopLevelParentFunction aTopLevelParentFunction,
2033 ColorSelectFunction aColorSelectFunction)
2034 : WeldToolbarPopup(rFrame, rMenuButton.get_widget(), "svx/ui/colorwindow.ui", "palette_popup_window")
2035 , theSlotId(nSlotId)
2036 , maCommand(std::move(rCommand))
2037 , maMenuButton(rMenuButton)
2038 , mxPaletteManager(std::move(xPaletteManager))
2039 , mrColorStatus(rColorStatus)
2040 , maTopLevelParentFunction(std::move(aTopLevelParentFunction))
2041 , maColorSelectFunction(std::move(aColorSelectFunction))
2042 , mxColorSet(new SvxColorValueSet(m_xBuilder->weld_scrolled_window("colorsetwin", true)))
2043 , mxRecentColorSet(new SvxColorValueSet(nullptr))
2044 , mxPaletteListBox(m_xBuilder->weld_combo_box("palette_listbox"))
2045 , mxButtonAutoColor(m_xBuilder->weld_button("auto_color_button"))
2046 , mxButtonNoneColor(m_xBuilder->weld_button("none_color_button"))
2047 , mxButtonPicker(m_xBuilder->weld_button("color_picker_button"))
2048 , mxAutomaticSeparator(m_xBuilder->weld_widget("separator4"))
2049 , mxColorSetWin(new weld::CustomWeld(*m_xBuilder, "colorset", *mxColorSet))
2050 , mxRecentColorSetWin(new weld::CustomWeld(*m_xBuilder, "recent_colorset", *mxRecentColorSet))
2051 , mpDefaultButton(nullptr)
2053 mxColorSet->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) );
2054 mxRecentColorSet->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) );
2056 switch ( theSlotId )
2058 case SID_ATTR_CHAR_COLOR_BACKGROUND:
2059 case SID_BACKGROUND_COLOR:
2060 case SID_ATTR_CHAR_BACK_COLOR:
2061 case SID_TABLE_CELL_BACKGROUND_COLOR:
2063 mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_NOFILL ) );
2064 break;
2066 case SID_AUTHOR_COLOR:
2068 mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_BY_AUTHOR ) );
2069 break;
2071 case SID_BMPMASK_COLOR:
2073 mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_TRANSPARENT ) );
2074 break;
2076 case SID_ATTR_CHAR_COLOR:
2077 case SID_ATTR_CHAR_COLOR2:
2078 case SID_EXTRUSION_3D_COLOR:
2080 mxButtonAutoColor->set_label(EditResId(RID_SVXSTR_AUTOMATIC));
2081 break;
2083 case SID_FM_CTL_PROPERTIES:
2085 mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_DEFAULT ) );
2086 break;
2088 default:
2090 mxButtonAutoColor->hide();
2091 mxAutomaticSeparator->hide();
2092 break;
2096 mxPaletteListBox->connect_changed(LINK(this, ColorWindow, SelectPaletteHdl));
2097 std::vector<OUString> aPaletteList = mxPaletteManager->GetPaletteList();
2098 mxPaletteListBox->freeze();
2099 for (const auto& rPalette : aPaletteList)
2100 mxPaletteListBox->append_text(rPalette);
2101 mxPaletteListBox->thaw();
2102 OUString aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() );
2103 mxPaletteListBox->set_active_text(aPaletteName);
2104 const int nSelectedEntry(mxPaletteListBox->get_active());
2105 if (nSelectedEntry != -1)
2106 mxPaletteManager->SetPalette(nSelectedEntry);
2108 mxButtonAutoColor->connect_clicked(LINK(this, ColorWindow, AutoColorClickHdl));
2109 mxButtonNoneColor->connect_clicked(LINK(this, ColorWindow, AutoColorClickHdl));
2110 mxButtonPicker->connect_clicked(LINK(this, ColorWindow, OpenPickerClickHdl));
2112 mxColorSet->SetSelectHdl(LINK( this, ColorWindow, SelectHdl));
2113 mxRecentColorSet->SetSelectHdl(LINK( this, ColorWindow, SelectHdl));
2114 m_xTopLevel->set_help_id(HID_POPUP_COLOR);
2115 mxColorSet->SetHelpId(HID_POPUP_COLOR_CTRL);
2117 mxPaletteManager->ReloadColorSet(*mxColorSet);
2118 const sal_uInt32 nMaxItems(SvxColorValueSet::getMaxRowCount() * SvxColorValueSet::getColumnCount());
2119 Size aSize = mxColorSet->layoutAllVisible(nMaxItems);
2120 mxColorSet->set_size_request(aSize.Width(), aSize.Height());
2122 mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
2123 aSize = mxRecentColorSet->layoutAllVisible(mxPaletteManager->GetRecentColorCount());
2124 mxRecentColorSet->set_size_request(aSize.Width(), aSize.Height());
2126 AddStatusListener( ".uno:ColorTableState" );
2127 AddStatusListener( maCommand );
2128 if ( maCommand == ".uno:FrameLineColor" )
2130 AddStatusListener( ".uno:BorderTLBR" );
2131 AddStatusListener( ".uno:BorderBLTR" );
2135 void ColorWindow::GrabFocus()
2137 if (mxColorSet->IsNoSelection() && mpDefaultButton)
2138 mpDefaultButton->grab_focus();
2139 else
2140 mxColorSet->GrabFocus();
2143 void ColorWindow::ShowNoneButton()
2145 mxButtonNoneColor->show();
2148 ColorWindow::~ColorWindow()
2152 NamedColor ColorWindow::GetSelectEntryColor(ValueSet const * pColorSet)
2154 Color aColor = pColorSet->GetItemColor(pColorSet->GetSelectedItemId());
2155 OUString sColorName = pColorSet->GetItemText(pColorSet->GetSelectedItemId());
2156 return { aColor, sColorName };
2159 namespace
2161 NamedColor GetAutoColor(sal_uInt16 nSlotId)
2163 Color aColor;
2164 OUString sColorName;
2165 switch (nSlotId)
2167 case SID_ATTR_CHAR_COLOR_BACKGROUND:
2168 case SID_BACKGROUND_COLOR:
2169 case SID_ATTR_CHAR_BACK_COLOR:
2170 case SID_TABLE_CELL_BACKGROUND_COLOR:
2171 aColor = COL_TRANSPARENT;
2172 sColorName = SvxResId(RID_SVXSTR_NOFILL);
2173 break;
2174 case SID_AUTHOR_COLOR:
2175 aColor = COL_TRANSPARENT;
2176 sColorName = SvxResId(RID_SVXSTR_BY_AUTHOR);
2177 break;
2178 case SID_BMPMASK_COLOR:
2179 aColor = COL_TRANSPARENT;
2180 sColorName = SvxResId(RID_SVXSTR_TRANSPARENT);
2181 break;
2182 case SID_FM_CTL_PROPERTIES:
2183 aColor = COL_TRANSPARENT;
2184 sColorName = SvxResId(RID_SVXSTR_DEFAULT);
2185 break;
2186 case SID_ATTR_CHAR_COLOR:
2187 case SID_ATTR_CHAR_COLOR2:
2188 case SID_EXTRUSION_3D_COLOR:
2189 default:
2190 aColor = COL_AUTO;
2191 sColorName = EditResId(RID_SVXSTR_AUTOMATIC);
2192 break;
2195 return {aColor, sColorName};
2198 NamedColor GetNoneColor()
2200 OUString aName = comphelper::LibreOfficeKit::isActive()
2201 ? SvxResId(RID_SVXSTR_INVISIBLE)
2202 : SvxResId(RID_SVXSTR_NONE);
2203 return { COL_NONE_COLOR, aName };
2207 NamedColor ColorWindow::GetSelectEntryColor() const
2209 if (!mxColorSet->IsNoSelection())
2210 return GetSelectEntryColor(mxColorSet.get());
2211 if (!mxRecentColorSet->IsNoSelection())
2212 return GetSelectEntryColor(mxRecentColorSet.get());
2213 if (mxButtonNoneColor.get() == mpDefaultButton)
2214 return GetNoneColor();
2215 return GetAutoColor();
2218 IMPL_LINK(ColorWindow, SelectHdl, ValueSet*, pColorSet, void)
2220 NamedColor aNamedColor = GetSelectEntryColor(pColorSet);
2222 if (pColorSet != mxRecentColorSet.get())
2224 mxPaletteManager->AddRecentColor(aNamedColor.m_aColor, aNamedColor.m_aName);
2225 if (!maMenuButton.get_active())
2226 mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
2229 mxPaletteManager->SetSplitButtonColor(aNamedColor);
2231 // deliberate take a copy here in case maMenuButton.set_inactive
2232 // triggers a callback that destroys ourself
2233 ColorSelectFunction aColorSelectFunction(maColorSelectFunction);
2234 OUString sCommand(maCommand);
2235 // Same for querying IsTheme early.
2236 bool bThemePaletteSelected = mxPaletteManager->IsThemePaletteSelected();
2237 sal_uInt16 nSelectedItemId = pColorSet->GetSelectedItemId();
2239 if (bThemePaletteSelected)
2241 sal_uInt16 nThemeIndex;
2242 sal_uInt16 nEffectIndex;
2243 if (PaletteManager::GetThemeAndEffectIndex(nSelectedItemId, nThemeIndex, nEffectIndex))
2245 aNamedColor.m_nThemeIndex = nThemeIndex;
2246 mxPaletteManager->GetLumModOff(nThemeIndex, nEffectIndex, aNamedColor.m_nLumMod, aNamedColor.m_nLumOff);
2250 maMenuButton.set_inactive();
2251 aColorSelectFunction(sCommand, aNamedColor);
2254 IMPL_LINK_NOARG(ColorWindow, SelectPaletteHdl, weld::ComboBox&, void)
2256 int nPos = mxPaletteListBox->get_active();
2257 mxPaletteManager->SetPalette( nPos );
2258 mxPaletteManager->ReloadColorSet(*mxColorSet);
2259 mxColorSet->layoutToGivenHeight(mxColorSet->GetOutputSizePixel().Height(), mxPaletteManager->GetColorCount());
2262 NamedColor ColorWindow::GetAutoColor() const
2264 return ::GetAutoColor(theSlotId);
2267 IMPL_LINK(ColorWindow, AutoColorClickHdl, weld::Button&, rButton, void)
2269 NamedColor aNamedColor = &rButton == mxButtonAutoColor.get() ? GetAutoColor() : GetNoneColor();
2271 mxColorSet->SetNoSelection();
2272 mxRecentColorSet->SetNoSelection();
2273 mpDefaultButton = &rButton;
2275 mxPaletteManager->SetSplitButtonColor(aNamedColor);
2277 // deliberate take a copy here in case maMenuButton.set_inactive
2278 // triggers a callback that destroys ourself
2279 ColorSelectFunction aColorSelectFunction(maColorSelectFunction);
2280 OUString sCommand(maCommand);
2282 maMenuButton.set_inactive();
2284 aColorSelectFunction(sCommand, aNamedColor);
2287 IMPL_LINK_NOARG(ColorWindow, OpenPickerClickHdl, weld::Button&, void)
2289 // copy before set_inactive
2290 auto nColor = GetSelectEntryColor().m_aColor;
2291 auto pParentWindow = maTopLevelParentFunction();
2292 OUString sCommand = maCommand;
2293 std::shared_ptr<PaletteManager> xPaletteManager(mxPaletteManager);
2295 maMenuButton.set_inactive();
2297 xPaletteManager->PopupColorPicker(pParentWindow, sCommand, nColor);
2300 void ColorWindow::SetNoSelection()
2302 mxColorSet->SetNoSelection();
2303 mxRecentColorSet->SetNoSelection();
2304 mpDefaultButton = nullptr;
2307 bool ColorWindow::IsNoSelection() const
2309 if (!mxColorSet->IsNoSelection())
2310 return false;
2311 if (!mxRecentColorSet->IsNoSelection())
2312 return false;
2313 return !mxButtonAutoColor->get_visible() && !mxButtonNoneColor->get_visible();
2316 void ColorWindow::statusChanged( const css::frame::FeatureStateEvent& rEvent )
2318 if (rEvent.FeatureURL.Complete == ".uno:ColorTableState")
2320 if (rEvent.IsEnabled && mxPaletteManager->GetPalette() == 0)
2322 mxPaletteManager->ReloadColorSet(*mxColorSet);
2323 mxColorSet->layoutToGivenHeight(mxColorSet->GetOutputSizePixel().Height(), mxPaletteManager->GetColorCount());
2326 else
2328 mrColorStatus.statusChanged(rEvent);
2329 SelectEntry(mrColorStatus.GetColor());
2333 bool ColorWindow::SelectValueSetEntry(SvxColorValueSet* pColorSet, const Color& rColor)
2335 for (size_t i = 1; i <= pColorSet->GetItemCount(); ++i)
2337 if (rColor == pColorSet->GetItemColor(i))
2339 pColorSet->SelectItem(i);
2340 return true;
2343 return false;
2346 void ColorWindow::SelectEntry(const NamedColor& rNamedColor)
2348 SetNoSelection();
2350 const Color &rColor = rNamedColor.m_aColor;
2352 if (mxButtonAutoColor->get_visible() && (rColor == COL_TRANSPARENT || rColor == COL_AUTO))
2354 mpDefaultButton = mxButtonAutoColor.get();
2355 return;
2358 if (mxButtonNoneColor->get_visible() && rColor == COL_NONE_COLOR)
2360 mpDefaultButton = mxButtonNoneColor.get();
2361 return;
2364 // try current palette
2365 bool bFoundColor = SelectValueSetEntry(mxColorSet.get(), rColor);
2366 // try recently used
2367 if (!bFoundColor)
2368 bFoundColor = SelectValueSetEntry(mxRecentColorSet.get(), rColor);
2369 // if it's not there, add it there now to the end of the recently used
2370 // so its available somewhere handy, but not without trashing the
2371 // whole recently used
2372 if (!bFoundColor)
2374 const OUString& rColorName = rNamedColor.m_aName;
2375 mxPaletteManager->AddRecentColor(rColor, rColorName, false);
2376 mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
2377 SelectValueSetEntry(mxRecentColorSet.get(), rColor);
2381 void ColorWindow::SelectEntry(const Color& rColor)
2383 OUString sColorName = "#" + rColor.AsRGBHexString().toAsciiUpperCase();
2384 ColorWindow::SelectEntry({rColor, sColorName});
2387 ColorStatus::ColorStatus() :
2388 maColor( COL_TRANSPARENT ),
2389 maTLBRColor( COL_TRANSPARENT ),
2390 maBLTRColor( COL_TRANSPARENT )
2394 void ColorStatus::statusChanged( const css::frame::FeatureStateEvent& rEvent )
2396 Color aColor( COL_TRANSPARENT );
2397 css::table::BorderLine2 aTable;
2399 if ( rEvent.State >>= aTable )
2401 SvxBorderLine aLine;
2402 SvxBoxItem::LineToSvxLine( aTable, aLine, false );
2403 if ( !aLine.isEmpty() )
2404 aColor = aLine.GetColor();
2406 else
2407 rEvent.State >>= aColor;
2409 if ( rEvent.FeatureURL.Path == "BorderTLBR" )
2410 maTLBRColor = aColor;
2411 else if ( rEvent.FeatureURL.Path == "BorderBLTR" )
2412 maBLTRColor = aColor;
2413 else
2414 maColor = aColor;
2417 Color ColorStatus::GetColor()
2419 Color aColor( maColor );
2421 if ( maTLBRColor != COL_TRANSPARENT )
2423 if ( aColor != maTLBRColor && aColor != COL_TRANSPARENT )
2424 return COL_TRANSPARENT;
2425 aColor = maTLBRColor;
2428 if ( maBLTRColor != COL_TRANSPARENT )
2430 if ( aColor != maBLTRColor && aColor != COL_TRANSPARENT )
2431 return COL_TRANSPARENT;
2432 return maBLTRColor;
2435 return aColor;
2439 SvxFrameWindow_Impl::SvxFrameWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent)
2440 : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/floatingframeborder.ui", "FloatingFrameBorder")
2441 , mxControl(pControl)
2442 , mxFrameSet(new SvxFrmValueSet_Impl)
2443 , mxFrameSetWin(new weld::CustomWeld(*m_xBuilder, "valueset", *mxFrameSet))
2444 , bParagraphMode(false)
2445 , m_bIsWriter(false)
2448 // check whether the document is Writer or not
2449 if (Reference<lang::XServiceInfo> xSI{ m_xFrame->getController()->getModel(), UNO_QUERY })
2450 m_bIsWriter = xSI->supportsService("com.sun.star.text.TextDocument");
2452 mxFrameSet->SetStyle(WB_ITEMBORDER | WB_DOUBLEBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT);
2453 AddStatusListener(".uno:BorderReducedMode");
2454 InitImageList();
2457 * 1 2 3 4 5
2458 * ------------------------------------------------------
2459 * NONE LEFT RIGHT LEFTRIGHT DIAGONALDOWN
2460 * TOP BOTTOM TOPBOTTOM OUTER DIAGONALUP
2461 * ------------------------------------------------------
2462 * HOR HORINNER VERINNER ALL CRISSCROSS <- can be switched of via bParagraphMode
2465 sal_uInt16 i = 0;
2467 // diagonal borders available only for Calc.
2468 // Therefore, Calc uses 10 border types while
2469 // Writer uses 8 of them - for a single cell.
2470 for ( i=1; i < (m_bIsWriter ? 9 : 11); i++ )
2471 mxFrameSet->InsertItem(i, Image(aImgVec[i-1].first), aImgVec[i-1].second);
2473 //bParagraphMode should have been set in StateChanged
2474 if ( !bParagraphMode )
2475 // when multiple cell selected:
2476 // Writer has 12 border types and Calc has 15 of them.
2477 for ( i = (m_bIsWriter ? 9 : 11); i < (m_bIsWriter ? 13 : 16); i++ )
2478 mxFrameSet->InsertItem(i, Image(aImgVec[i-1].first), aImgVec[i-1].second);
2480 // adjust frame column for Writer
2481 sal_uInt16 colCount = m_bIsWriter ? 4 : 5;
2482 mxFrameSet->SetColCount( colCount );
2483 mxFrameSet->SetSelectHdl( LINK( this, SvxFrameWindow_Impl, SelectHdl ) );
2484 CalcSizeValueSet();
2486 mxFrameSet->SetHelpId( HID_POPUP_FRAME );
2487 mxFrameSet->SetAccessibleName( SvxResId(RID_SVXSTR_FRAME) );
2490 namespace {
2492 enum class FrmValidFlags {
2493 NONE = 0x00,
2494 Left = 0x01,
2495 Right = 0x02,
2496 Top = 0x04,
2497 Bottom = 0x08,
2498 HInner = 0x10,
2499 VInner = 0x20,
2500 AllMask = 0x3f,
2505 namespace o3tl {
2506 template<> struct typed_flags<FrmValidFlags> : is_typed_flags<FrmValidFlags, 0x3f> {};
2509 // By default unset lines remain unchanged.
2510 // Via Shift unset lines are reset
2512 IMPL_LINK_NOARG(SvxFrameWindow_Impl, SelectHdl, ValueSet*, void)
2514 SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
2515 SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
2516 SvxBorderLine theDefLine;
2518 // diagonal down border
2519 SvxBorderLine dDownBorderLine(nullptr, SvxBorderLineWidth::Hairline);
2520 SvxLineItem dDownLineItem(SID_ATTR_BORDER_DIAG_TLBR);
2522 // diagonal up border
2523 SvxBorderLine dUpBorderLine(nullptr, SvxBorderLineWidth::Hairline);
2524 SvxLineItem dUpLineItem(SID_ATTR_BORDER_DIAG_BLTR);
2526 bool bIsDiagonalBorder = false;
2528 SvxBorderLine *pLeft = nullptr,
2529 *pRight = nullptr,
2530 *pTop = nullptr,
2531 *pBottom = nullptr;
2532 sal_uInt16 nSel = mxFrameSet->GetSelectedItemId();
2533 sal_uInt16 nModifier = mxFrameSet->GetModifier();
2534 FrmValidFlags nValidFlags = FrmValidFlags::NONE;
2536 // tdf#48622, tdf#145828 use correct default to create intended 0.75pt
2537 // cell border using the border formatting tool in the standard toolbar
2538 theDefLine.GuessLinesWidths(theDefLine.GetBorderLineStyle(), SvxBorderLineWidth::Thin);
2540 // nSel has 15 cases which means 15 border
2541 // types for Calc. But Writer uses only 12
2542 // of them - when diagonal borders excluded.
2543 if (m_bIsWriter)
2545 // add appropriate increments
2546 // to match the correct borders.
2547 if (nSel > 8) { nSel += 2; }
2548 else if (nSel > 4) { nSel++; }
2551 switch ( nSel )
2553 case 1: nValidFlags |= FrmValidFlags::AllMask;
2554 // set nullptr to remove diagonal lines
2555 dDownLineItem.SetLine(nullptr);
2556 dUpLineItem.SetLine(nullptr);
2557 SetDiagonalDownBorder(dDownLineItem);
2558 SetDiagonalUpBorder(dUpLineItem);
2559 break; // NONE
2560 case 2: pLeft = &theDefLine;
2561 nValidFlags |= FrmValidFlags::Left;
2562 break; // LEFT
2563 case 3: pRight = &theDefLine;
2564 nValidFlags |= FrmValidFlags::Right;
2565 break; // RIGHT
2566 case 4: pLeft = pRight = &theDefLine;
2567 nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left;
2568 break; // LEFTRIGHT
2569 case 5: dDownLineItem.SetLine(&dDownBorderLine);
2570 SetDiagonalDownBorder(dDownLineItem);
2571 bIsDiagonalBorder = true;
2572 break; // DIAGONAL DOWN
2573 case 6: pTop = &theDefLine;
2574 nValidFlags |= FrmValidFlags::Top;
2575 break; // TOP
2576 case 7: pBottom = &theDefLine;
2577 nValidFlags |= FrmValidFlags::Bottom;
2578 break; // BOTTOM
2579 case 8: pTop = pBottom = &theDefLine;
2580 nValidFlags |= FrmValidFlags::Bottom|FrmValidFlags::Top;
2581 break; // TOPBOTTOM
2582 case 9: pLeft = pRight = pTop = pBottom = &theDefLine;
2583 nValidFlags |= FrmValidFlags::Left | FrmValidFlags::Right | FrmValidFlags::Top | FrmValidFlags::Bottom;
2584 break; // OUTER
2585 case 10:
2586 dUpLineItem.SetLine(&dUpBorderLine);
2587 SetDiagonalUpBorder(dUpLineItem);
2588 bIsDiagonalBorder = true;
2589 break; // DIAGONAL UP
2591 // Inner Table:
2592 case 11: // HOR
2593 pTop = pBottom = &theDefLine;
2594 aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI );
2595 aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::VERT );
2596 nValidFlags |= FrmValidFlags::HInner|FrmValidFlags::Top|FrmValidFlags::Bottom;
2597 break;
2599 case 12: // HORINNER
2600 pLeft = pRight = pTop = pBottom = &theDefLine;
2601 aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI );
2602 aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::VERT );
2603 nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left|FrmValidFlags::HInner|FrmValidFlags::Top|FrmValidFlags::Bottom;
2604 break;
2606 case 13: // VERINNER
2607 pLeft = pRight = pTop = pBottom = &theDefLine;
2608 aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::HORI );
2609 aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::VERT );
2610 nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left|FrmValidFlags::VInner|FrmValidFlags::Top|FrmValidFlags::Bottom;
2611 break;
2613 case 14: // ALL
2614 pLeft = pRight = pTop = pBottom = &theDefLine;
2615 aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI );
2616 aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::VERT );
2617 nValidFlags |= FrmValidFlags::AllMask;
2618 break;
2620 case 15:
2621 // set both diagonal lines to draw criss-cross line
2622 dDownLineItem.SetLine(&dDownBorderLine);
2623 dUpLineItem.SetLine(&dUpBorderLine);
2625 SetDiagonalDownBorder(dDownLineItem);
2626 SetDiagonalUpBorder(dUpLineItem);
2627 bIsDiagonalBorder = true;
2628 break; // CRISS-CROSS
2630 default:
2631 break;
2634 // if diagonal borders selected,
2635 // no need to execute this block
2636 if (!bIsDiagonalBorder)
2638 aBorderOuter.SetLine( pLeft, SvxBoxItemLine::LEFT );
2639 aBorderOuter.SetLine( pRight, SvxBoxItemLine::RIGHT );
2640 aBorderOuter.SetLine( pTop, SvxBoxItemLine::TOP );
2641 aBorderOuter.SetLine( pBottom, SvxBoxItemLine::BOTTOM );
2643 if(nModifier == KEY_SHIFT)
2644 nValidFlags |= FrmValidFlags::AllMask;
2645 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP, bool(nValidFlags&FrmValidFlags::Top ));
2646 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM, bool(nValidFlags&FrmValidFlags::Bottom ));
2647 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT, bool(nValidFlags&FrmValidFlags::Left));
2648 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT, bool(nValidFlags&FrmValidFlags::Right ));
2649 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI, bool(nValidFlags&FrmValidFlags::HInner ));
2650 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT, bool(nValidFlags&FrmValidFlags::VInner));
2651 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE );
2652 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false );
2654 Any a1, a2;
2655 aBorderOuter.QueryValue( a1 );
2656 aBorderInner.QueryValue( a2 );
2657 Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue("OuterBorder", a1),
2658 comphelper::makePropertyValue("InnerBorder", a2) };
2660 mxControl->dispatchCommand( ".uno:SetBorderStyle", aArgs );
2663 // coverity[ check_after_deref : FALSE]
2664 if (mxFrameSet)
2666 /* #i33380# Moved the following line above the Dispatch() call.
2667 This instance may be deleted in the meantime (i.e. when a dialog is opened
2668 while in Dispatch()), accessing members will crash in this case. */
2669 mxFrameSet->SetNoSelection();
2672 mxControl->EndPopupMode();
2675 void SvxFrameWindow_Impl::SetDiagonalDownBorder(const SvxLineItem& dDownLineItem)
2677 // apply diagonal down border
2678 Any a;
2679 dDownLineItem.QueryValue(a);
2680 Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue("BorderTLBR", a) };
2682 mxControl->dispatchCommand(".uno:BorderTLBR", aArgs);
2685 void SvxFrameWindow_Impl::SetDiagonalUpBorder(const SvxLineItem& dUpLineItem)
2687 // apply diagonal up border
2688 Any a;
2689 dUpLineItem.QueryValue(a);
2690 Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue("BorderBLTR", a) };
2692 mxControl->dispatchCommand(".uno:BorderBLTR", aArgs);
2695 void SvxFrameWindow_Impl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
2697 if ( rEvent.FeatureURL.Complete != ".uno:BorderReducedMode" )
2698 return;
2700 bool bValue;
2701 if ( !(rEvent.State >>= bValue) )
2702 return;
2704 bParagraphMode = bValue;
2705 //initial calls mustn't insert or remove elements
2706 if(!mxFrameSet->GetItemCount())
2707 return;
2709 // set 12 border types for Writer, otherwise 15 for Calc.
2710 bool bTableMode = ( mxFrameSet->GetItemCount() == static_cast<size_t>(m_bIsWriter ? 12 : 15) );
2711 bool bResize = false;
2713 if ( bTableMode && bParagraphMode )
2715 for ( sal_uInt16 i = (m_bIsWriter ? 9 : 11); i < (m_bIsWriter ? 13 : 16); i++ )
2716 mxFrameSet->RemoveItem(i);
2717 bResize = true;
2719 else if ( !bTableMode && !bParagraphMode )
2721 for ( sal_uInt16 i = (m_bIsWriter ? 9 : 11); i < (m_bIsWriter ? 13 : 16); i++ )
2722 mxFrameSet->InsertItem(i, Image(aImgVec[i-1].first), aImgVec[i-1].second);
2723 bResize = true;
2726 if ( bResize )
2728 CalcSizeValueSet();
2732 void SvxFrameWindow_Impl::CalcSizeValueSet()
2734 weld::DrawingArea* pDrawingArea = mxFrameSet->GetDrawingArea();
2735 const OutputDevice& rDevice = pDrawingArea->get_ref_device();
2736 Size aItemSize( 20 * rDevice.GetDPIScaleFactor(), 20 * rDevice.GetDPIScaleFactor() );
2737 Size aSize = mxFrameSet->CalcWindowSizePixel( aItemSize );
2738 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
2739 mxFrameSet->SetOutputSizePixel(aSize);
2742 void SvxFrameWindow_Impl::InitImageList()
2744 if (m_bIsWriter)
2746 // Writer-specific aImgVec.
2747 // Since Writer doesn't have diagonal borders,
2748 // we have to use 12 border types here.
2749 aImgVec = {
2750 {BitmapEx(RID_SVXBMP_FRAME1), SvxResId(RID_SVXSTR_TABLE_PRESET_NONE)},
2751 {BitmapEx(RID_SVXBMP_FRAME2), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYLEFT)},
2752 {BitmapEx(RID_SVXBMP_FRAME3), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYRIGHT)},
2753 {BitmapEx(RID_SVXBMP_FRAME4), SvxResId(RID_SVXSTR_PARA_PRESET_LEFTRIGHT)},
2755 {BitmapEx(RID_SVXBMP_FRAME5), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTOP)},
2756 {BitmapEx(RID_SVXBMP_FRAME6), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTBOTTOM)},
2757 {BitmapEx(RID_SVXBMP_FRAME7), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOM)},
2758 {BitmapEx(RID_SVXBMP_FRAME8), SvxResId(RID_SVXSTR_TABLE_PRESET_ONLYOUTER)},
2760 {BitmapEx(RID_SVXBMP_FRAME9), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOMHORI)},
2761 {BitmapEx(RID_SVXBMP_FRAME10), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERHORI)},
2762 {BitmapEx(RID_SVXBMP_FRAME11), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERVERI)},
2763 {BitmapEx(RID_SVXBMP_FRAME12), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERALL)}
2766 else
2768 // Calc has diagonal borders feature.
2769 // Therefore use additional 3 diagonal border types,
2770 // which make border types 15 in total.
2771 aImgVec = {
2772 {BitmapEx(RID_SVXBMP_FRAME1), SvxResId(RID_SVXSTR_TABLE_PRESET_NONE)},
2773 {BitmapEx(RID_SVXBMP_FRAME2), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYLEFT)},
2774 {BitmapEx(RID_SVXBMP_FRAME3), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYRIGHT)},
2775 {BitmapEx(RID_SVXBMP_FRAME4), SvxResId(RID_SVXSTR_PARA_PRESET_LEFTRIGHT)},
2776 {BitmapEx(RID_SVXBMP_FRAME14), SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALDOWN)}, // diagonal down border
2778 {BitmapEx(RID_SVXBMP_FRAME5), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTOP)},
2779 {BitmapEx(RID_SVXBMP_FRAME6), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTBOTTOM)},
2780 {BitmapEx(RID_SVXBMP_FRAME7), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOM)},
2781 {BitmapEx(RID_SVXBMP_FRAME8), SvxResId(RID_SVXSTR_TABLE_PRESET_ONLYOUTER)},
2782 {BitmapEx(RID_SVXBMP_FRAME13), SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALUP)}, // diagonal up border
2784 {BitmapEx(RID_SVXBMP_FRAME9), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOMHORI)},
2785 {BitmapEx(RID_SVXBMP_FRAME10), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERHORI)},
2786 {BitmapEx(RID_SVXBMP_FRAME11), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERVERI)},
2787 {BitmapEx(RID_SVXBMP_FRAME12), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERALL)},
2788 {BitmapEx(RID_SVXBMP_FRAME15), SvxResId(RID_SVXSTR_PARA_PRESET_CRISSCROSS)} // criss-cross border
2793 static Color lcl_mediumColor( Color aMain, Color /*aDefault*/ )
2795 return SvxBorderLine::threeDMediumColor( aMain );
2798 SvxLineWindow_Impl::SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent)
2799 : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/floatingframeborder.ui", "FloatingFrameBorder")
2800 , m_xControl(pControl)
2801 , m_xLineStyleLb(new LineListBox)
2802 , m_xLineStyleLbWin(new weld::CustomWeld(*m_xBuilder, "valueset", *m_xLineStyleLb))
2803 , m_bIsWriter(false)
2807 Reference< lang::XServiceInfo > xServices(m_xFrame->getController()->getModel(), UNO_QUERY_THROW);
2808 m_bIsWriter = xServices->supportsService("com.sun.star.text.TextDocument");
2810 catch(const uno::Exception& )
2814 m_xLineStyleLb->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) );
2816 m_xLineStyleLb->SetSourceUnit( FieldUnit::TWIP );
2817 m_xLineStyleLb->SetNone( comphelper::LibreOfficeKit::isActive() ? SvxResId(RID_SVXSTR_INVISIBLE)
2818 :SvxResId(RID_SVXSTR_NONE) );
2820 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::SOLID ), SvxBorderLineStyle::SOLID );
2821 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DOTTED ), SvxBorderLineStyle::DOTTED );
2822 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DASHED ), SvxBorderLineStyle::DASHED );
2824 // Double lines
2825 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DOUBLE ), SvxBorderLineStyle::DOUBLE );
2826 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_SMALLGAP ), SvxBorderLineStyle::THINTHICK_SMALLGAP, 20 );
2827 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_MEDIUMGAP ), SvxBorderLineStyle::THINTHICK_MEDIUMGAP );
2828 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_LARGEGAP ), SvxBorderLineStyle::THINTHICK_LARGEGAP );
2829 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_SMALLGAP ), SvxBorderLineStyle::THICKTHIN_SMALLGAP, 20 );
2830 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_MEDIUMGAP ), SvxBorderLineStyle::THICKTHIN_MEDIUMGAP );
2831 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_LARGEGAP ), SvxBorderLineStyle::THICKTHIN_LARGEGAP );
2833 // Engraved / Embossed
2834 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::EMBOSSED ), SvxBorderLineStyle::EMBOSSED, 15,
2835 &SvxBorderLine::threeDLightColor, &SvxBorderLine::threeDDarkColor,
2836 &lcl_mediumColor );
2837 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::ENGRAVED ), SvxBorderLineStyle::ENGRAVED, 15,
2838 &SvxBorderLine::threeDDarkColor, &SvxBorderLine::threeDLightColor,
2839 &lcl_mediumColor );
2841 // Inset / Outset
2842 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::OUTSET ), SvxBorderLineStyle::OUTSET, 10,
2843 &SvxBorderLine::lightColor, &SvxBorderLine::darkColor );
2844 m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::INSET ), SvxBorderLineStyle::INSET, 10,
2845 &SvxBorderLine::darkColor, &SvxBorderLine::lightColor );
2846 Size aSize = m_xLineStyleLb->SetWidth( 20 ); // 1pt by default
2848 m_xLineStyleLb->SetSelectHdl( LINK( this, SvxLineWindow_Impl, SelectHdl ) );
2850 m_xContainer->set_help_id(HID_POPUP_LINE);
2852 aSize.AdjustWidth(6);
2853 aSize.AdjustHeight(6);
2854 aSize = m_xLineStyleLb->CalcWindowSizePixel(aSize);
2855 m_xLineStyleLb->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
2856 m_xLineStyleLb->SetOutputSizePixel(aSize);
2859 IMPL_LINK_NOARG(SvxLineWindow_Impl, SelectHdl, ValueSet*, void)
2861 SvxLineItem aLineItem( SID_FRAME_LINESTYLE );
2862 SvxBorderLineStyle nStyle = m_xLineStyleLb->GetSelectEntryStyle();
2864 if ( m_xLineStyleLb->GetSelectItemPos( ) > 0 )
2866 SvxBorderLine aTmp;
2867 aTmp.SetBorderLineStyle( nStyle );
2868 aTmp.SetWidth( SvxBorderLineWidth::Thin ); // TODO Make it depend on a width field
2869 aLineItem.SetLine( &aTmp );
2871 else
2872 aLineItem.SetLine( nullptr );
2874 Any a;
2875 aLineItem.QueryValue( a, m_bIsWriter ? CONVERT_TWIPS : 0 );
2876 Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue("LineStyle", a) };
2878 m_xControl->dispatchCommand( ".uno:LineStyle", aArgs );
2880 m_xControl->EndPopupMode();
2883 SfxStyleControllerItem_Impl::SfxStyleControllerItem_Impl(
2884 const Reference< XDispatchProvider >& rDispatchProvider,
2885 sal_uInt16 nSlotId, // Family-ID
2886 const OUString& rCommand, // .uno: command bound to this item
2887 SvxStyleToolBoxControl& rTbxCtl ) // controller instance, which the item is assigned to.
2888 : SfxStatusListener( rDispatchProvider, nSlotId, rCommand ),
2889 rControl( rTbxCtl )
2893 void SfxStyleControllerItem_Impl::StateChangedAtStatusListener(
2894 SfxItemState eState, const SfxPoolItem* pState )
2896 switch ( GetId() )
2898 case SID_STYLE_FAMILY1:
2899 case SID_STYLE_FAMILY2:
2900 case SID_STYLE_FAMILY3:
2901 case SID_STYLE_FAMILY4:
2902 case SID_STYLE_FAMILY5:
2904 const sal_uInt16 nIdx = GetId() - SID_STYLE_FAMILY_START;
2906 if ( SfxItemState::DEFAULT == eState )
2908 const SfxTemplateItem* pStateItem =
2909 dynamic_cast<const SfxTemplateItem*>( pState );
2910 DBG_ASSERT( pStateItem != nullptr, "SfxTemplateItem expected" );
2911 rControl.SetFamilyState( nIdx, pStateItem );
2913 else
2914 rControl.SetFamilyState( nIdx, nullptr );
2915 break;
2920 struct SvxStyleToolBoxControl::Impl
2922 OUString aClearForm;
2923 OUString aMore;
2924 ::std::vector< std::pair< OUString, OUString > > aDefaultStyles;
2925 bool bSpecModeWriter;
2926 bool bSpecModeCalc;
2928 VclPtr<SvxStyleBox_Impl> m_xVclBox;
2929 std::unique_ptr<SvxStyleBox_Base> m_xWeldBox;
2930 SvxStyleBox_Base* m_pBox;
2932 Impl()
2933 :aClearForm ( SvxResId( RID_SVXSTR_CLEARFORM ) )
2934 ,aMore ( SvxResId( RID_SVXSTR_MORE_STYLES ) )
2935 ,bSpecModeWriter ( false )
2936 ,bSpecModeCalc ( false )
2937 ,m_pBox ( nullptr )
2942 void InitializeStyles(const Reference < frame::XModel >& xModel)
2944 aDefaultStyles.clear();
2946 //now convert the default style names to the localized names
2949 Reference< style::XStyleFamiliesSupplier > xStylesSupplier( xModel, UNO_QUERY_THROW );
2950 Reference< lang::XServiceInfo > xServices( xModel, UNO_QUERY_THROW );
2951 bSpecModeWriter = xServices->supportsService("com.sun.star.text.TextDocument");
2952 if(bSpecModeWriter)
2954 Reference<container::XNameAccess> xParaStyles;
2955 xStylesSupplier->getStyleFamilies()->getByName("ParagraphStyles") >>=
2956 xParaStyles;
2957 static const std::vector<OUString> aWriterStyles =
2959 "Standard",
2960 "Text body",
2961 "Title",
2962 "Subtitle",
2963 "Heading 1",
2964 "Heading 2",
2965 "Heading 3",
2966 "Heading 4",
2967 "Quotations",
2968 "Preformatted Text"
2970 for( const OUString& aStyle: aWriterStyles )
2974 Reference< beans::XPropertySet > xStyle;
2975 xParaStyles->getByName( aStyle ) >>= xStyle;
2976 OUString sName;
2977 xStyle->getPropertyValue("DisplayName") >>= sName;
2978 if( !sName.isEmpty() )
2979 aDefaultStyles.push_back(
2980 std::pair<OUString, OUString>(aStyle, sName) );
2982 catch( const uno::Exception& )
2987 else if( (
2988 bSpecModeCalc = xServices->supportsService(
2989 "com.sun.star.sheet.SpreadsheetDocument")))
2991 static const char* aCalcStyles[] =
2993 "Default",
2994 "Accent 1",
2995 "Accent 2",
2996 "Accent 3",
2997 "Heading 1",
2998 "Heading 2",
2999 "Result"
3001 Reference<container::XNameAccess> xCellStyles;
3002 xStylesSupplier->getStyleFamilies()->getByName("CellStyles") >>= xCellStyles;
3003 for(const char* pCalcStyle : aCalcStyles)
3007 const OUString sStyleName( OUString::createFromAscii( pCalcStyle ) );
3008 if( xCellStyles->hasByName( sStyleName ) )
3010 Reference< beans::XPropertySet > xStyle( xCellStyles->getByName( sStyleName), UNO_QUERY_THROW );
3011 OUString sName;
3012 xStyle->getPropertyValue("DisplayName") >>= sName;
3013 if( !sName.isEmpty() )
3014 aDefaultStyles.push_back(
3015 std::pair<OUString, OUString>(sStyleName, sName) );
3018 catch( const uno::Exception& )
3023 catch(const uno::Exception& )
3025 OSL_FAIL("error while initializing style names");
3030 // mapping table from bound items. BE CAREFUL this table must be in the
3031 // same order as the uno commands bound to the slots SID_STYLE_FAMILY1..n
3032 // MAX_FAMILIES must also be correctly set!
3033 static const char* StyleSlotToStyleCommand[MAX_FAMILIES] =
3035 ".uno:CharStyle",
3036 ".uno:ParaStyle",
3037 ".uno:FrameStyle",
3038 ".uno:PageStyle",
3039 ".uno:TemplateFamily5"
3042 SvxStyleToolBoxControl::SvxStyleToolBoxControl()
3043 : pImpl(new Impl)
3044 , pStyleSheetPool(nullptr)
3045 , nActFamily(0xffff)
3047 for (sal_uInt16 i = 0; i < MAX_FAMILIES; ++i)
3049 m_xBoundItems[i].clear();
3050 pFamilyState[i] = nullptr;
3054 SvxStyleToolBoxControl::~SvxStyleToolBoxControl()
3058 void SAL_CALL SvxStyleToolBoxControl::initialize(const Sequence<Any>& rArguments)
3060 svt::ToolboxController::initialize(rArguments);
3062 // After initialize we should have a valid frame member where we can retrieve our
3063 // dispatch provider.
3064 if ( !m_xFrame.is() )
3065 return;
3067 pImpl->InitializeStyles(m_xFrame->getController()->getModel());
3068 Reference< XDispatchProvider > xDispatchProvider( m_xFrame->getController(), UNO_QUERY );
3069 for ( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
3071 m_xBoundItems[i] = new SfxStyleControllerItem_Impl( xDispatchProvider,
3072 SID_STYLE_FAMILY_START + i,
3073 OUString::createFromAscii( StyleSlotToStyleCommand[i] ),
3074 *this );
3075 pFamilyState[i] = nullptr;
3079 // XComponent
3080 void SAL_CALL SvxStyleToolBoxControl::dispose()
3082 svt::ToolboxController::dispose();
3084 SolarMutexGuard aSolarMutexGuard;
3085 pImpl->m_xVclBox.disposeAndClear();
3086 pImpl->m_xWeldBox.reset();
3087 pImpl->m_pBox = nullptr;
3089 for (rtl::Reference<SfxStyleControllerItem_Impl>& pBoundItem : m_xBoundItems)
3091 if (!pBoundItem)
3092 continue;
3093 pBoundItem->UnBind();
3095 unbindListener();
3097 for( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
3099 if ( m_xBoundItems[i].is() )
3103 m_xBoundItems[i]->dispose();
3105 catch ( Exception& )
3109 m_xBoundItems[i].clear();
3111 pFamilyState[i].reset();
3113 pStyleSheetPool = nullptr;
3114 pImpl.reset();
3117 OUString SvxStyleToolBoxControl::getImplementationName()
3119 return "com.sun.star.comp.svx.StyleToolBoxControl";
3122 sal_Bool SvxStyleToolBoxControl::supportsService( const OUString& rServiceName )
3124 return cppu::supportsService( this, rServiceName );
3127 css::uno::Sequence< OUString > SvxStyleToolBoxControl::getSupportedServiceNames()
3129 return { "com.sun.star.frame.ToolbarController" };
3132 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
3133 com_sun_star_comp_svx_StyleToolBoxControl_get_implementation(
3134 css::uno::XComponentContext*,
3135 css::uno::Sequence<css::uno::Any> const & )
3137 return cppu::acquire( new SvxStyleToolBoxControl() );
3140 void SAL_CALL SvxStyleToolBoxControl::update()
3142 for (rtl::Reference<SfxStyleControllerItem_Impl>& pBoundItem : m_xBoundItems)
3143 pBoundItem->ReBind();
3144 bindListener();
3147 SfxStyleFamily SvxStyleToolBoxControl::GetActFamily() const
3149 switch ( nActFamily-1 + SID_STYLE_FAMILY_START )
3151 case SID_STYLE_FAMILY1: return SfxStyleFamily::Char;
3152 case SID_STYLE_FAMILY2: return SfxStyleFamily::Para;
3153 case SID_STYLE_FAMILY3: return SfxStyleFamily::Frame;
3154 case SID_STYLE_FAMILY4: return SfxStyleFamily::Page;
3155 case SID_STYLE_FAMILY5: return SfxStyleFamily::Pseudo;
3156 default:
3157 OSL_FAIL( "unknown style family" );
3158 break;
3160 return SfxStyleFamily::Para;
3163 void SvxStyleToolBoxControl::FillStyleBox()
3165 SvxStyleBox_Base* pBox = pImpl->m_pBox;
3167 DBG_ASSERT( pStyleSheetPool, "StyleSheetPool not found!" );
3168 DBG_ASSERT( pBox, "Control not found!" );
3170 if ( !(pStyleSheetPool && pBox && nActFamily!=0xffff) )
3171 return;
3173 const SfxStyleFamily eFamily = GetActFamily();
3174 SfxStyleSheetBase* pStyle = nullptr;
3175 bool bDoFill = false;
3177 auto xIter = pStyleSheetPool->CreateIterator(eFamily, SfxStyleSearchBits::Used);
3178 sal_uInt16 nCount = xIter->Count();
3180 // Check whether fill is necessary
3181 pStyle = xIter->First();
3182 //!!! TODO: This condition isn't right any longer, because we always show some default entries
3183 //!!! so the list doesn't show the count
3184 if ( nCount != pBox->get_count() )
3186 bDoFill = true;
3188 else
3190 sal_uInt16 i= 0;
3191 while ( pStyle && !bDoFill )
3193 bDoFill = ( pBox->get_text(i) != pStyle->GetName() );
3194 pStyle = xIter->Next();
3195 i++;
3199 if ( !bDoFill )
3200 return;
3202 OUString aStrSel(pBox->get_active_text());
3203 pBox->freeze();
3204 pBox->clear();
3206 std::vector<OUString> aStyles;
3208 // add used styles
3209 pStyle = xIter->Next();
3210 while ( pStyle )
3212 aStyles.push_back(pStyle->GetName());
3213 pStyle = xIter->Next();
3216 if (pImpl->bSpecModeWriter || pImpl->bSpecModeCalc)
3218 pBox->append_text(pImpl->aClearForm);
3219 pBox->insert_separator(1, "separator");
3221 // add default styles if less than 12 items
3222 for( const auto &rStyle : pImpl->aDefaultStyles )
3224 if ( aStyles.size() + pBox->get_count() > 12)
3225 break;
3226 // insert default style only if not used (and added to rStyle before)
3227 if (std::find(aStyles.begin(), aStyles.end(), rStyle.second) >= aStyles.end())
3228 pBox->append_text(rStyle.second);
3231 std::sort(aStyles.begin(), aStyles.end());
3233 for (const auto& rStyle : aStyles)
3234 pBox->append_text(rStyle);
3236 if ((pImpl->bSpecModeWriter || pImpl->bSpecModeCalc) && !comphelper::LibreOfficeKit::isActive())
3237 pBox->append_text(pImpl->aMore);
3239 pBox->thaw();
3240 pBox->set_active_or_entry_text(aStrSel);
3241 pBox->SetFamily( eFamily );
3244 void SvxStyleToolBoxControl::SelectStyle( const OUString& rStyleName )
3246 SvxStyleBox_Base* pBox = pImpl->m_pBox;
3247 DBG_ASSERT( pBox, "Control not found!" );
3249 if ( !pBox )
3250 return;
3252 OUString aStrSel(pBox->get_active_text());
3254 if ( !rStyleName.isEmpty() )
3256 OUString aNewStyle = rStyleName;
3258 auto aFound = std::find_if(pImpl->aDefaultStyles.begin(), pImpl->aDefaultStyles.end(),
3259 [rStyleName] (auto it) { return it.first == rStyleName || it.second == rStyleName; }
3262 if (aFound != pImpl->aDefaultStyles.end())
3263 aNewStyle = aFound->second;
3265 if ( aNewStyle != aStrSel )
3266 pBox->set_active_or_entry_text( aNewStyle );
3268 else
3269 pBox->set_active(-1);
3270 pBox->save_value();
3273 void SvxStyleToolBoxControl::Update()
3275 SfxStyleSheetBasePool* pPool = nullptr;
3276 SfxObjectShell* pDocShell = SfxObjectShell::Current();
3278 if ( pDocShell )
3279 pPool = pDocShell->GetStyleSheetPool();
3281 sal_uInt16 i;
3282 for ( i=0; i<MAX_FAMILIES; i++ )
3283 if( pFamilyState[i] )
3284 break;
3286 if ( i==MAX_FAMILIES || !pPool )
3288 pStyleSheetPool = pPool;
3289 return;
3293 const SfxTemplateItem* pItem = nullptr;
3295 if ( nActFamily == 0xffff || nullptr == (pItem = pFamilyState[nActFamily-1].get()) )
3296 // Current range not within allowed ranges or default
3298 pStyleSheetPool = pPool;
3299 nActFamily = 2;
3301 pItem = pFamilyState[nActFamily-1].get();
3302 if ( !pItem )
3304 nActFamily++;
3305 pItem = pFamilyState[nActFamily-1].get();
3308 else if ( pPool != pStyleSheetPool )
3309 pStyleSheetPool = pPool;
3311 FillStyleBox(); // Decides by itself whether Fill is needed
3313 if ( pItem )
3314 SelectStyle( pItem->GetStyleName() );
3317 void SvxStyleToolBoxControl::SetFamilyState( sal_uInt16 nIdx,
3318 const SfxTemplateItem* pItem )
3320 pFamilyState[nIdx].reset( pItem == nullptr ? nullptr : new SfxTemplateItem( *pItem ) );
3321 Update();
3324 void SvxStyleToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
3326 SolarMutexGuard aGuard;
3328 if (m_pToolbar)
3329 m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled);
3330 else
3332 ToolBox* pToolBox = nullptr;
3333 ToolBoxItemId nId;
3334 if (!getToolboxId( nId, &pToolBox ) )
3335 return;
3336 pToolBox->EnableItem( nId, rEvent.IsEnabled );
3339 if (rEvent.IsEnabled)
3340 Update();
3343 css::uno::Reference<css::awt::XWindow> SvxStyleToolBoxControl::createItemWindow(const css::uno::Reference< css::awt::XWindow>& rParent)
3345 uno::Reference< awt::XWindow > xItemWindow;
3347 if (m_pBuilder)
3349 SolarMutexGuard aSolarMutexGuard;
3351 std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("applystyle"));
3353 xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
3355 pImpl->m_xWeldBox.reset(new SvxStyleBox_Base(std::move(xWidget),
3356 ".uno:StyleApply",
3357 SfxStyleFamily::Para,
3358 Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
3359 m_xFrame,
3360 pImpl->aClearForm,
3361 pImpl->aMore,
3362 pImpl->bSpecModeWriter || pImpl->bSpecModeCalc, *this));
3363 pImpl->m_pBox = pImpl->m_xWeldBox.get();
3365 else
3367 VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent);
3368 if ( pParent )
3370 SolarMutexGuard aSolarMutexGuard;
3372 pImpl->m_xVclBox = VclPtr<SvxStyleBox_Impl>::Create(pParent,
3373 ".uno:StyleApply",
3374 SfxStyleFamily::Para,
3375 Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
3376 m_xFrame,
3377 pImpl->aClearForm,
3378 pImpl->aMore,
3379 pImpl->bSpecModeWriter || pImpl->bSpecModeCalc, *this);
3380 pImpl->m_pBox = pImpl->m_xVclBox.get();
3381 xItemWindow = VCLUnoHelper::GetInterface(pImpl->m_xVclBox);
3385 if (pImpl->m_pBox && !pImpl->aDefaultStyles.empty())
3386 pImpl->m_pBox->SetDefaultStyle(pImpl->aDefaultStyles[0].second);
3388 return xItemWindow;
3391 SvxFontNameToolBoxControl::SvxFontNameToolBoxControl()
3392 : m_pBox(nullptr)
3396 void SvxFontNameBox_Base::statusChanged_Impl( const css::frame::FeatureStateEvent& rEvent )
3398 if ( !rEvent.IsEnabled )
3400 set_sensitive(false);
3401 Update( nullptr );
3403 else
3405 set_sensitive(true);
3407 css::awt::FontDescriptor aFontDesc;
3408 if ( rEvent.State >>= aFontDesc )
3409 Update(&aFontDesc);
3410 else {
3411 // no active element; delete value in the display
3412 m_xWidget->set_active(-1);
3413 set_active_or_entry_text("");
3415 m_xWidget->save_value();
3419 void SvxFontNameToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
3421 SolarMutexGuard aGuard;
3422 m_pBox->statusChanged_Impl(rEvent);
3424 if (m_pToolbar)
3425 m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled);
3426 else
3428 ToolBox* pToolBox = nullptr;
3429 ToolBoxItemId nId;
3430 if (!getToolboxId( nId, &pToolBox ) )
3431 return;
3432 pToolBox->EnableItem( nId, rEvent.IsEnabled );
3436 css::uno::Reference<css::awt::XWindow> SvxFontNameToolBoxControl::createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent)
3438 uno::Reference< awt::XWindow > xItemWindow;
3440 if (m_pBuilder)
3442 SolarMutexGuard aSolarMutexGuard;
3444 std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("fontnamecombobox"));
3446 xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
3448 m_xWeldBox.reset(new SvxFontNameBox_Base(std::move(xWidget),
3449 Reference<XDispatchProvider>(m_xFrame->getController(), UNO_QUERY),
3450 m_xFrame, *this));
3451 m_pBox = m_xWeldBox.get();
3453 else
3455 VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent);
3456 if ( pParent )
3458 SolarMutexGuard aSolarMutexGuard;
3459 m_xVclBox = VclPtr<SvxFontNameBox_Impl>::Create(pParent,
3460 Reference<XDispatchProvider>(m_xFrame->getController(), UNO_QUERY),
3461 m_xFrame, *this);
3462 m_pBox = m_xVclBox.get();
3463 xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox);
3467 return xItemWindow;
3470 void SvxFontNameToolBoxControl::dispose()
3472 ToolboxController::dispose();
3474 SolarMutexGuard aSolarMutexGuard;
3475 m_xVclBox.disposeAndClear();
3476 m_xWeldBox.reset();
3477 m_pBox = nullptr;
3480 OUString SvxFontNameToolBoxControl::getImplementationName()
3482 return "com.sun.star.comp.svx.FontNameToolBoxControl";
3485 sal_Bool SvxFontNameToolBoxControl::supportsService( const OUString& rServiceName )
3487 return cppu::supportsService( this, rServiceName );
3490 css::uno::Sequence< OUString > SvxFontNameToolBoxControl::getSupportedServiceNames()
3492 return { "com.sun.star.frame.ToolbarController" };
3495 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
3496 com_sun_star_comp_svx_FontNameToolBoxControl_get_implementation(
3497 css::uno::XComponentContext*,
3498 css::uno::Sequence<css::uno::Any> const & )
3500 return cppu::acquire( new SvxFontNameToolBoxControl() );
3503 SvxColorToolBoxControl::SvxColorToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext ) :
3504 ImplInheritanceHelper( rContext, nullptr, OUString() ),
3505 m_bSplitButton(true),
3506 m_nSlotId(0),
3507 m_aColorSelectFunction(PaletteManager::DispatchColorCommand)
3511 namespace {
3513 sal_uInt16 MapCommandToSlotId(const OUString& rCommand)
3515 if (rCommand == ".uno:Color")
3516 return SID_ATTR_CHAR_COLOR;
3517 else if (rCommand == ".uno:FontColor")
3518 return SID_ATTR_CHAR_COLOR2;
3519 else if (rCommand == ".uno:BackColor") // deprecated - use CharBackColor
3520 return SID_ATTR_CHAR_COLOR_BACKGROUND;
3521 else if (rCommand == ".uno:CharBackColor")
3522 return SID_ATTR_CHAR_BACK_COLOR;
3523 else if (rCommand == ".uno:BackgroundColor")
3524 return SID_BACKGROUND_COLOR;
3525 else if (rCommand == ".uno:TableCellBackgroundColor")
3526 return SID_TABLE_CELL_BACKGROUND_COLOR;
3527 else if (rCommand == ".uno:Extrusion3DColor")
3528 return SID_EXTRUSION_3D_COLOR;
3529 else if (rCommand == ".uno:XLineColor")
3530 return SID_ATTR_LINE_COLOR;
3531 else if (rCommand == ".uno:FillColor")
3532 return SID_ATTR_FILL_COLOR;
3533 else if (rCommand == ".uno:FrameLineColor")
3534 return SID_FRAME_LINECOLOR;
3536 SAL_WARN("svx.tbxcrtls", "Unknown color command: " << rCommand);
3537 return 0;
3542 void SvxColorToolBoxControl::initialize( const css::uno::Sequence<css::uno::Any>& rArguments )
3544 PopupWindowController::initialize( rArguments );
3546 m_nSlotId = MapCommandToSlotId( m_aCommandURL );
3548 if ( m_nSlotId == SID_ATTR_LINE_COLOR || m_nSlotId == SID_ATTR_FILL_COLOR ||
3549 m_nSlotId == SID_FRAME_LINECOLOR || m_nSlotId == SID_BACKGROUND_COLOR )
3551 // Sidebar uses wide buttons for those.
3552 m_bSplitButton = !m_bSidebar;
3555 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(getCommandURL(), getModuleName());
3556 OUString aCommandLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
3558 if (m_pToolbar)
3560 mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
3561 m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel());
3562 m_xBtnUpdater.reset(new svx::ToolboxButtonColorUpdater(m_nSlotId, m_aCommandURL, m_pToolbar, !m_bSplitButton, aCommandLabel, m_xFrame));
3563 return;
3566 ToolBox* pToolBox = nullptr;
3567 ToolBoxItemId nId;
3568 if (getToolboxId(nId, &pToolBox))
3570 m_xBtnUpdater.reset( new svx::VclToolboxButtonColorUpdater( m_nSlotId, nId, pToolBox, !m_bSplitButton, aCommandLabel, m_aCommandURL, m_xFrame ) );
3571 pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ( m_bSplitButton ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY ) );
3575 void SvxColorToolBoxControl::update()
3577 PopupWindowController::update();
3579 switch( m_nSlotId )
3581 case SID_ATTR_CHAR_COLOR2:
3582 addStatusListener( ".uno:CharColorExt");
3583 break;
3585 case SID_ATTR_CHAR_BACK_COLOR:
3586 case SID_ATTR_CHAR_COLOR_BACKGROUND:
3587 addStatusListener( ".uno:CharBackgroundExt");
3588 break;
3590 case SID_FRAME_LINECOLOR:
3591 addStatusListener( ".uno:BorderTLBR");
3592 addStatusListener( ".uno:BorderBLTR");
3593 break;
3597 void SvxColorToolBoxControl::EnsurePaletteManager()
3599 if (!m_xPaletteManager)
3601 m_xPaletteManager = std::make_shared<PaletteManager>();
3602 m_xPaletteManager->SetBtnUpdater(m_xBtnUpdater.get());
3606 SvxColorToolBoxControl::~SvxColorToolBoxControl()
3608 if (m_xPaletteManager)
3609 m_xPaletteManager->SetBtnUpdater(nullptr);
3612 void SvxColorToolBoxControl::setColorSelectFunction(const ColorSelectFunction& aColorSelectFunction)
3614 m_aColorSelectFunction = aColorSelectFunction;
3615 if (m_xPaletteManager)
3616 m_xPaletteManager->SetColorSelectFunction(aColorSelectFunction);
3619 weld::Window* SvxColorToolBoxControl::GetParentFrame() const
3621 const css::uno::Reference<css::awt::XWindow> xParent = m_xFrame->getContainerWindow();
3622 return Application::GetFrameWeld(xParent);
3625 std::unique_ptr<WeldToolbarPopup> SvxColorToolBoxControl::weldPopupWindow()
3627 EnsurePaletteManager();
3629 auto xPopover = std::make_unique<ColorWindow>(
3630 m_aCommandURL,
3631 m_xPaletteManager,
3632 m_aColorStatus,
3633 m_nSlotId,
3634 m_xFrame,
3635 MenuOrToolMenuButton(m_pToolbar, m_aCommandURL),
3636 [this] { return GetParentFrame(); },
3637 m_aColorSelectFunction);
3639 return xPopover;
3642 VclPtr<vcl::Window> SvxColorToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
3644 ToolBox* pToolBox = nullptr;
3645 ToolBoxItemId nId;
3646 if (!getToolboxId(nId, &pToolBox))
3647 return nullptr;
3649 EnsurePaletteManager();
3651 auto xPopover = std::make_unique<ColorWindow>(
3652 m_aCommandURL,
3653 m_xPaletteManager,
3654 m_aColorStatus,
3655 m_nSlotId,
3656 m_xFrame,
3657 MenuOrToolMenuButton(this, pToolBox, nId),
3658 [this] { return GetParentFrame(); },
3659 m_aColorSelectFunction);
3661 mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
3662 std::move(xPopover), true);
3664 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(m_aCommandURL, m_sModuleName);
3665 OUString aWindowTitle = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
3666 mxInterimPopover->SetText(aWindowTitle);
3668 mxInterimPopover->Show();
3670 return mxInterimPopover;
3673 void SvxColorToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
3675 ToolBox* pToolBox = nullptr;
3676 ToolBoxItemId nId;
3677 if (!getToolboxId(nId, &pToolBox) && !m_pToolbar)
3678 return;
3680 if ( rEvent.FeatureURL.Complete == m_aCommandURL )
3682 if (m_pToolbar)
3683 m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled);
3684 else
3685 pToolBox->EnableItem( nId, rEvent.IsEnabled );
3688 bool bValue;
3689 if ( !m_bSplitButton )
3691 m_aColorStatus.statusChanged( rEvent );
3692 m_xBtnUpdater->Update( m_aColorStatus.GetColor() );
3694 else if ( rEvent.State >>= bValue )
3696 if (m_pToolbar)
3697 m_pToolbar->set_item_active(m_aCommandURL, bValue);
3698 else if (pToolBox)
3699 pToolBox->CheckItem( nId, bValue );
3703 void SvxColorToolBoxControl::execute(sal_Int16 /*nSelectModifier*/)
3705 if ( !m_bSplitButton )
3707 if (m_pToolbar)
3709 // Toggle the popup also when toolbutton is activated
3710 m_pToolbar->set_menu_item_active(m_aCommandURL, !m_pToolbar->get_menu_item_active(m_aCommandURL));
3712 else
3714 // Open the popup also when Enter key is pressed.
3715 createPopupWindow();
3717 return;
3720 OUString aCommand = m_aCommandURL;
3721 Color aColor = m_xBtnUpdater->GetCurrentColor();
3723 switch( m_nSlotId )
3725 case SID_ATTR_CHAR_COLOR2 :
3726 aCommand = ".uno:CharColorExt";
3727 break;
3730 auto aArgs( comphelper::InitPropertySequence( {
3731 { m_aCommandURL.copy(5), css::uno::Any(aColor) }
3732 } ) );
3733 dispatchCommand( aCommand, aArgs );
3735 EnsurePaletteManager();
3736 OUString sColorName = m_xBtnUpdater->GetCurrentColorName();
3737 m_xPaletteManager->AddRecentColor(aColor, sColorName);
3740 sal_Bool SvxColorToolBoxControl::opensSubToolbar()
3742 // We mark this controller as a sub-toolbar controller, so we get notified
3743 // (through updateImage method) on button image changes, and could redraw
3744 // the last used color on top of it.
3745 return true;
3748 void SvxColorToolBoxControl::updateImage()
3750 m_xBtnUpdater->Update(m_xBtnUpdater->GetCurrentColor(), true);
3753 OUString SvxColorToolBoxControl::getSubToolbarName()
3755 return OUString();
3758 void SvxColorToolBoxControl::functionSelected( const OUString& /*rCommand*/ )
3762 OUString SvxColorToolBoxControl::getImplementationName()
3764 return "com.sun.star.comp.svx.ColorToolBoxControl";
3767 css::uno::Sequence<OUString> SvxColorToolBoxControl::getSupportedServiceNames()
3769 return { "com.sun.star.frame.ToolbarController" };
3772 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
3773 com_sun_star_comp_svx_ColorToolBoxControl_get_implementation(
3774 css::uno::XComponentContext* rContext,
3775 css::uno::Sequence<css::uno::Any> const & )
3777 return cppu::acquire( new SvxColorToolBoxControl( rContext ) );
3780 SvxFrameToolBoxControl::SvxFrameToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rContext )
3781 : svt::PopupWindowController( rContext, nullptr, OUString() )
3785 void SAL_CALL SvxFrameToolBoxControl::execute(sal_Int16 /*KeyModifier*/)
3787 if (m_pToolbar)
3789 // Toggle the popup also when toolbutton is activated
3790 m_pToolbar->set_menu_item_active(m_aCommandURL, !m_pToolbar->get_menu_item_active(m_aCommandURL));
3792 else
3794 // Open the popup also when Enter key is pressed.
3795 createPopupWindow();
3799 void SvxFrameToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& rArguments )
3801 svt::PopupWindowController::initialize( rArguments );
3803 if (m_pToolbar)
3805 mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
3806 m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel());
3809 ToolBox* pToolBox = nullptr;
3810 ToolBoxItemId nId;
3811 if (getToolboxId(nId, &pToolBox))
3812 pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
3815 std::unique_ptr<WeldToolbarPopup> SvxFrameToolBoxControl::weldPopupWindow()
3817 if ( m_aCommandURL == ".uno:LineStyle" )
3818 return std::make_unique<SvxLineWindow_Impl>(this, m_pToolbar);
3819 return std::make_unique<SvxFrameWindow_Impl>(this, m_pToolbar);
3822 VclPtr<vcl::Window> SvxFrameToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
3824 if ( m_aCommandURL == ".uno:LineStyle" )
3826 mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
3827 std::make_unique<SvxLineWindow_Impl>(this, pParent->GetFrameWeld()), true);
3829 mxInterimPopover->Show();
3831 mxInterimPopover->SetText(SvxResId(RID_SVXSTR_FRAME_STYLE));
3833 return mxInterimPopover;
3836 mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
3837 std::make_unique<SvxFrameWindow_Impl>(this, pParent->GetFrameWeld()), true);
3839 mxInterimPopover->Show();
3841 mxInterimPopover->SetText(SvxResId(RID_SVXSTR_FRAME));
3843 return mxInterimPopover;
3846 OUString SvxFrameToolBoxControl::getImplementationName()
3848 return "com.sun.star.comp.svx.FrameToolBoxControl";
3851 css::uno::Sequence< OUString > SvxFrameToolBoxControl::getSupportedServiceNames()
3853 return { "com.sun.star.frame.ToolbarController" };
3856 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
3857 com_sun_star_comp_svx_FrameToolBoxControl_get_implementation(
3858 css::uno::XComponentContext* rContext,
3859 css::uno::Sequence<css::uno::Any> const & )
3861 return cppu::acquire( new SvxFrameToolBoxControl( rContext ) );
3864 SvxCurrencyToolBoxControl::SvxCurrencyToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext ) :
3865 PopupWindowController( rContext, nullptr, OUString() ),
3866 m_eLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() ),
3867 m_nFormatKey( NUMBERFORMAT_ENTRY_NOT_FOUND )
3871 SvxCurrencyToolBoxControl::~SvxCurrencyToolBoxControl() {}
3873 namespace
3875 /** Implementation of the currency combo widget **/
3876 class SvxCurrencyList_Impl : public WeldToolbarPopup
3878 private:
3879 rtl::Reference<SvxCurrencyToolBoxControl> m_xControl;
3880 std::unique_ptr<weld::Label> m_xLabel;
3881 std::unique_ptr<weld::TreeView> m_xCurrencyLb;
3882 std::unique_ptr<weld::Button> m_xOkBtn;
3883 OUString& m_rSelectedFormat;
3884 LanguageType& m_eSelectedLanguage;
3886 std::vector<OUString> m_aFormatEntries;
3887 LanguageType m_eFormatLanguage;
3888 DECL_LINK(RowActivatedHdl, weld::TreeView&, bool);
3889 DECL_LINK(OKHdl, weld::Button&, void);
3891 virtual void GrabFocus() override;
3893 public:
3894 SvxCurrencyList_Impl(SvxCurrencyToolBoxControl* pControl, weld::Widget* pParent, OUString& rSelectedFormat, LanguageType& eSelectedLanguage)
3895 : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/currencywindow.ui", "CurrencyWindow")
3896 , m_xControl(pControl)
3897 , m_xLabel(m_xBuilder->weld_label("label"))
3898 , m_xCurrencyLb(m_xBuilder->weld_tree_view("currency"))
3899 , m_xOkBtn(m_xBuilder->weld_button("ok"))
3900 , m_rSelectedFormat(rSelectedFormat)
3901 , m_eSelectedLanguage(eSelectedLanguage)
3903 const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
3904 sal_uInt16 nLen = rCurrencyTable.size();
3906 SvNumberFormatter aFormatter( m_xControl->getContext(), LANGUAGE_SYSTEM );
3907 m_eFormatLanguage = aFormatter.GetLanguage();
3909 const SvxCurrencyToolBoxControl::SvxCurrencyVect_t &rCurrencies = pControl->GetCurrencySymbols( );
3911 sal_uInt16 nPos = 0, nCount = 0;
3912 sal_Int32 nSelectedPos = -1;
3913 bool bIsSymbol;
3914 NfWSStringsDtor aStringsDtor;
3916 OUString sLongestString;
3918 m_xCurrencyLb->freeze();
3919 for( const SvxCurrencyToolBoxControl::SvxCurrencyData& curr : rCurrencies )
3921 const OUString& rItem = curr.m_label;
3922 sal_uInt16 rCurrencyIndex = rCurrencies[ nCount ].m_currencyIdx;
3924 if ( rCurrencyIndex < nLen )
3926 m_xCurrencyLb->append_text(rItem);
3928 if (rItem.getLength() > sLongestString.getLength())
3929 sLongestString = rItem;
3931 bIsSymbol = nPos >= nLen;
3933 sal_uInt16 nDefaultFormat;
3934 const NfCurrencyEntry& rCurrencyEntry = rCurrencyTable[ rCurrencyIndex ];
3935 if (rCurrencyIndex == 0)
3937 // Stored with system locale, but we want the resolved
3938 // full LCID format string. For example
3939 // "[$$-409]#,##0.00" instead of "[$$]#,##0.00".
3940 NfCurrencyEntry aCurrencyEntry( rCurrencyEntry);
3941 aCurrencyEntry.SetLanguage( LanguageTag( aCurrencyEntry.GetLanguage()).getLanguageType());
3942 nDefaultFormat = aFormatter.GetCurrencyFormatStrings( aStringsDtor, aCurrencyEntry, bIsSymbol);
3944 else
3946 nDefaultFormat = aFormatter.GetCurrencyFormatStrings( aStringsDtor, rCurrencyEntry, bIsSymbol);
3948 const OUString& rFormatStr = aStringsDtor[ nDefaultFormat ];
3949 m_aFormatEntries.push_back( rFormatStr );
3950 if( rFormatStr == m_rSelectedFormat )
3951 nSelectedPos = nPos;
3952 ++nPos;
3954 ++nCount;
3956 m_xCurrencyLb->thaw();
3957 // enable multiple selection enabled so we can start with nothing selected
3958 m_xCurrencyLb->set_selection_mode(SelectionMode::Multiple);
3959 m_xCurrencyLb->connect_row_activated( LINK( this, SvxCurrencyList_Impl, RowActivatedHdl ) );
3960 m_xLabel->set_label(SvxResId(RID_SVXSTR_TBLAFMT_CURRENCY));
3961 m_xCurrencyLb->select( nSelectedPos );
3962 m_xOkBtn->connect_clicked(LINK(this, SvxCurrencyList_Impl, OKHdl));
3964 // gtk will initially make a best guess depending on the first few entries, so copy the probable
3965 // longest entry to the start temporarily and force in the width at this point
3966 m_xCurrencyLb->insert_text(0, sLongestString);
3967 m_xCurrencyLb->set_size_request(m_xCurrencyLb->get_preferred_size().Width(), m_xCurrencyLb->get_height_rows(12));
3968 m_xCurrencyLb->remove(0);
3972 void SvxCurrencyList_Impl::GrabFocus()
3974 m_xCurrencyLb->grab_focus();
3977 IMPL_LINK_NOARG(SvxCurrencyList_Impl, OKHdl, weld::Button&, void)
3979 RowActivatedHdl(*m_xCurrencyLb);
3982 IMPL_LINK_NOARG(SvxCurrencyList_Impl, RowActivatedHdl, weld::TreeView&, bool)
3984 if (!m_xControl.is())
3985 return true;
3987 // multiple selection enabled so we can start with nothing selected,
3988 // so force single selection after something is picked
3989 int nSelected = m_xCurrencyLb->get_selected_index();
3990 if (nSelected == -1)
3991 return true;
3993 m_xCurrencyLb->set_selection_mode(SelectionMode::Single);
3995 m_rSelectedFormat = m_aFormatEntries[nSelected];
3996 m_eSelectedLanguage = m_eFormatLanguage;
3998 m_xControl->execute(nSelected + 1);
4000 m_xCurrencyLb->scroll_to_row(0);
4002 m_xControl->EndPopupMode();
4004 return true;
4008 void SvxCurrencyToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& rArguments )
4010 PopupWindowController::initialize(rArguments);
4012 if (m_pToolbar)
4014 mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
4015 m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel());
4016 return;
4019 ToolBox* pToolBox = nullptr;
4020 ToolBoxItemId nId;
4021 if (getToolboxId(nId, &pToolBox) && pToolBox->GetItemCommand(nId) == m_aCommandURL)
4022 pToolBox->SetItemBits(nId, ToolBoxItemBits::DROPDOWN | pToolBox->GetItemBits(nId));
4025 const SvxCurrencyToolBoxControl::SvxCurrencyVect_t &SvxCurrencyToolBoxControl::GetCurrencySymbols( ) {
4026 inner_GetCurrencySymbols( true, m_currencies, m_mru_currencies );
4027 return m_currencies;
4030 void SvxCurrencyToolBoxControl::addMruCurrency(sal_Int16 currencyPosition) {
4031 if (currencyPosition == 1)
4032 return;
4034 const SvxCurrencyData& curr = m_currencies[currencyPosition];
4035 auto currencyIter = std::find( m_mru_currencies.begin(), m_mru_currencies.end(), curr );
4037 if ( currencyIter != m_mru_currencies.end() )
4038 m_mru_currencies.erase( currencyIter );
4040 m_mru_currencies.insert( m_mru_currencies.begin(), curr );
4041 if (m_mru_currencies.size() > MAX_MRU_CURRENCIES)
4042 m_mru_currencies.resize( MAX_MRU_CURRENCIES );
4045 std::unique_ptr<WeldToolbarPopup> SvxCurrencyToolBoxControl::weldPopupWindow()
4047 return std::make_unique<SvxCurrencyList_Impl>(this, m_pToolbar, m_aFormatString, m_eLanguage);
4050 VclPtr<vcl::Window> SvxCurrencyToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
4052 mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
4053 std::make_unique<SvxCurrencyList_Impl>(this, pParent->GetFrameWeld(), m_aFormatString, m_eLanguage));
4055 mxInterimPopover->Show();
4057 return mxInterimPopover;
4060 void SvxCurrencyToolBoxControl::execute( sal_Int16 nSelectModifier )
4062 sal_uInt32 nFormatKey;
4063 if (m_aFormatString.isEmpty())
4064 nFormatKey = NUMBERFORMAT_ENTRY_NOT_FOUND;
4065 else
4067 if ( nSelectModifier > 0 )
4071 uno::Reference< util::XNumberFormatsSupplier > xRef( m_xFrame->getController()->getModel(), uno::UNO_QUERY );
4072 uno::Reference< util::XNumberFormats > rxNumberFormats( xRef->getNumberFormats(), uno::UNO_SET_THROW );
4073 css::lang::Locale aLocale = LanguageTag::convertToLocale( m_eLanguage );
4074 nFormatKey = rxNumberFormats->queryKey( m_aFormatString, aLocale, false );
4075 if ( nFormatKey == NUMBERFORMAT_ENTRY_NOT_FOUND )
4076 nFormatKey = rxNumberFormats->addNew( m_aFormatString, aLocale );
4077 addMruCurrency(nSelectModifier);
4079 catch( const uno::Exception& )
4081 nFormatKey = m_nFormatKey;
4084 else
4085 nFormatKey = m_nFormatKey;
4088 if( nFormatKey != NUMBERFORMAT_ENTRY_NOT_FOUND )
4090 Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue("NumberFormatCurrency",
4091 nFormatKey) };
4092 dispatchCommand( m_aCommandURL, aArgs );
4093 m_nFormatKey = nFormatKey;
4095 else
4096 PopupWindowController::execute( nSelectModifier );
4099 OUString SvxCurrencyToolBoxControl::getImplementationName()
4101 return "com.sun.star.comp.svx.CurrencyToolBoxControl";
4104 css::uno::Sequence<OUString> SvxCurrencyToolBoxControl::getSupportedServiceNames()
4106 return { "com.sun.star.frame.ToolbarController" };
4109 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
4110 com_sun_star_comp_svx_CurrencyToolBoxControl_get_implementation(
4111 css::uno::XComponentContext* rContext,
4112 css::uno::Sequence<css::uno::Any> const & )
4114 return cppu::acquire( new SvxCurrencyToolBoxControl( rContext ) );
4117 Reference< css::accessibility::XAccessible > SvxFontNameBox_Impl::CreateAccessible()
4119 FillList();
4120 return InterimItemWindow::CreateAccessible();
4123 //static
4124 sal_uInt16 const SvxCurrencyToolBoxControl::SvxCurrencyData::InvalidCurrency = INVALID_CURRENCY;
4126 SvxCurrencyToolBoxControl::SvxCurrencyData::SvxCurrencyData(
4127 sal_uInt16 currencyIdx,
4128 bool onlyIsoCode
4130 m_currencyIdx(currencyIdx),
4131 m_onlyIsoCode(onlyIsoCode)
4134 bool SvxCurrencyToolBoxControl::SvxCurrencyData::operator == (const SvxCurrencyData& other) const
4136 return
4137 (m_currencyIdx == other.m_currencyIdx) &&
4138 (m_onlyIsoCode == other.m_onlyIsoCode);
4141 //static
4142 void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector<OUString>& rList, bool bFlag,
4143 std::vector<sal_uInt16>& rCurrencyList )
4145 SvxCurrencyVect_t currencies, mru_currencies;
4147 inner_GetCurrencySymbols(bFlag, currencies, mru_currencies);
4149 rList.resize(currencies.size());
4150 rCurrencyList.resize(currencies.size());
4152 for (size_t j = 0; j < currencies.size(); j++) {
4153 rList[j] = std::move(currencies[j].m_label);
4154 rCurrencyList[j] = currencies[j].m_currencyIdx;
4158 //static
4159 void SvxCurrencyToolBoxControl::inner_GetCurrencySymbols(
4160 bool bFlag,
4161 SvxCurrencyVect_t &pCurrencies,
4162 SvxCurrencyVect_t &p_mru_currencies)
4164 const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
4165 sal_uInt16 nCount = rCurrencyTable.size();
4167 // reserving space for mru currencies on top of vector after -1 element
4168 pCurrencies.resize( p_mru_currencies.size() + 1);
4169 std::fill( pCurrencies.begin() + 1, pCurrencies.end(), SvxCurrencyData() );
4171 // lambda for vector insertion: mru currencies are on top
4172 auto addCurrency = [&pCurrencies, &p_mru_currencies]
4173 (SvxCurrencyData& curr, size_t position = SIZE_MAX)
4175 auto mruIter = std::find(p_mru_currencies.begin(), p_mru_currencies.end(), curr);
4177 if (mruIter == p_mru_currencies.end()) {
4178 if (position == SIZE_MAX)
4179 pCurrencies.push_back( std::move(curr) );
4180 else
4181 pCurrencies.insert( pCurrencies.begin() + position, std::move(curr) );
4183 else {
4184 size_t index = mruIter - p_mru_currencies.begin();
4185 pCurrencies[index] = std::move(curr);
4189 SvxCurrencyData aCurr( sal_uInt16(-1) );
4190 aCurr.m_label = ApplyLreOrRleEmbedding( rCurrencyTable[0].GetSymbol() ) + " ";
4191 aCurr.m_label += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString(
4192 rCurrencyTable[0].GetLanguage() ) );
4194 pCurrencies[0] = aCurr;
4195 if( bFlag ) {
4196 aCurr.m_currencyIdx = 0;
4197 addCurrency( aCurr );
4200 sal_uInt16 nStart = pCurrencies.size();
4202 CollatorWrapper aCollator( ::comphelper::getProcessComponentContext() );
4203 aCollator.loadDefaultCollator( Application::GetSettings().GetLanguageTag().getLocale(), 0 );
4205 static const OUStringLiteral aTwoSpace(u" ");
4207 // appending "long symbol" list
4208 for( sal_uInt16 i = 1; i < nCount; ++i )
4210 SvxCurrencyData curr( i );
4211 curr.m_label = ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol() );
4212 curr.m_label += aTwoSpace;
4213 curr.m_label += ApplyLreOrRleEmbedding( rCurrencyTable[i].GetSymbol() );
4214 curr.m_label += aTwoSpace;
4215 curr.m_label += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString(
4216 rCurrencyTable[i].GetLanguage() ) );
4218 SvxCurrencyVect_t::size_type j = nStart;
4219 for( ; j < pCurrencies.size(); ++j )
4220 if ( aCollator.compareString( curr.m_label, pCurrencies[j].m_label ) < 0 )
4221 break; // insert before first greater than
4223 addCurrency( curr, j );
4226 // Append ISO codes to symbol list.
4227 // XXX If this is to be changed, various other places would had to be
4228 // adapted that assume this order!
4229 size_t nCont = pCurrencies.size();
4231 for ( sal_uInt16 i = 1; i < nCount; ++i )
4233 bool bInsert = true;
4234 SvxCurrencyData curr( i, true );
4235 curr.m_label = ApplyLreOrRleEmbedding(rCurrencyTable[i].GetBankSymbol());
4237 size_t j = nCont;
4238 for ( ; j < pCurrencies.size() && bInsert; ++j )
4240 if( pCurrencies[j].m_label == curr.m_label )
4241 bInsert = false;
4242 else if ( aCollator.compareString( curr.m_label, pCurrencies[j].m_label ) < 0 )
4243 break; // insert before first greater than
4245 if ( bInsert )
4246 addCurrency( curr, j );
4249 for ( int j = p_mru_currencies.size() - 1; j > 0; j-- )
4250 if ( pCurrencies[j].m_currencyIdx == SvxCurrencyData::InvalidCurrency )
4251 pCurrencies.erase( pCurrencies.begin() + j );
4254 ListBoxColorWrapper::ListBoxColorWrapper(ColorListBox* pControl)
4255 : mpControl(pControl)
4259 void ListBoxColorWrapper::operator()(
4260 [[maybe_unused]] const OUString& /*rCommand*/, const NamedColor& rColor)
4262 mpControl->Selected(rColor);
4265 void ColorListBox::EnsurePaletteManager()
4267 if (!m_xPaletteManager)
4269 m_xPaletteManager = std::make_shared<PaletteManager>();
4270 m_xPaletteManager->SetColorSelectFunction(std::ref(m_aColorWrapper));
4274 void ColorListBox::SetSlotId(sal_uInt16 nSlotId, bool bShowNoneButton)
4276 m_nSlotId = nSlotId;
4277 m_bShowNoneButton = bShowNoneButton;
4278 m_xButton->set_popover(nullptr);
4279 m_xColorWindow.reset();
4280 m_aSelectedColor = bShowNoneButton ? GetNoneColor() : GetAutoColor(m_nSlotId);
4281 ShowPreview(m_aSelectedColor);
4282 createColorWindow();
4285 ColorListBox::ColorListBox(std::unique_ptr<weld::MenuButton> pControl,
4286 TopLevelParentFunction aTopLevelParentFunction,
4287 const ColorListBox* pCache)
4288 : m_xButton(std::move(pControl))
4289 , m_aColorWrapper(this)
4290 , m_aAutoDisplayColor(Application::GetSettings().GetStyleSettings().GetDialogColor())
4291 , m_nSlotId(0)
4292 , m_bShowNoneButton(false)
4293 , m_aTopLevelParentFunction(std::move(aTopLevelParentFunction))
4295 m_xButton->connect_toggled(LINK(this, ColorListBox, ToggleHdl));
4296 m_aSelectedColor = GetAutoColor(m_nSlotId);
4297 if (!pCache)
4298 LockWidthRequest(CalcBestWidthRequest());
4299 else
4301 LockWidthRequest(pCache->m_xButton->get_size_request().Width());
4302 m_xPaletteManager.reset(pCache->m_xPaletteManager->Clone());
4303 m_xPaletteManager->SetColorSelectFunction(std::ref(m_aColorWrapper));
4305 ShowPreview(m_aSelectedColor);
4308 IMPL_LINK(ColorListBox, ToggleHdl, weld::Toggleable&, rButton, void)
4310 if (rButton.get_active())
4312 ColorWindow* pColorWindow = getColorWindow();
4313 if (pColorWindow && !comphelper::LibreOfficeKit::isActive())
4314 pColorWindow->GrabFocus();
4318 ColorListBox::~ColorListBox()
4322 ColorWindow* ColorListBox::getColorWindow() const
4324 if (!m_xColorWindow)
4325 const_cast<ColorListBox*>(this)->createColorWindow();
4326 return m_xColorWindow.get();
4329 void ColorListBox::createColorWindow()
4331 const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
4332 const SfxFrame* pFrame = pViewFrame ? &pViewFrame->GetFrame() : nullptr;
4333 css::uno::Reference<css::frame::XFrame> xFrame(pFrame ? pFrame->GetFrameInterface() : uno::Reference<css::frame::XFrame>());
4335 EnsurePaletteManager();
4337 m_xColorWindow.reset(new ColorWindow(
4338 OUString() /*m_aCommandURL*/,
4339 m_xPaletteManager,
4340 m_aColorStatus,
4341 m_nSlotId,
4342 xFrame,
4343 m_xButton.get(),
4344 m_aTopLevelParentFunction,
4345 m_aColorWrapper));
4347 SetNoSelection();
4348 m_xButton->set_popover(m_xColorWindow->getTopLevel());
4349 if (m_bShowNoneButton)
4350 m_xColorWindow->ShowNoneButton();
4351 m_xColorWindow->SelectEntry(m_aSelectedColor);
4354 void ColorListBox::SelectEntry(const NamedColor& rColor)
4356 if (o3tl::trim(rColor.m_aName).empty())
4358 SelectEntry(rColor.m_aColor);
4359 return;
4361 ColorWindow* pColorWindow = getColorWindow();
4362 pColorWindow->SelectEntry(rColor);
4363 m_aSelectedColor = pColorWindow->GetSelectEntryColor();
4364 ShowPreview(m_aSelectedColor);
4367 void ColorListBox::SelectEntry(const Color& rColor)
4369 ColorWindow* pColorWindow = getColorWindow();
4370 pColorWindow->SelectEntry(rColor);
4371 m_aSelectedColor = pColorWindow->GetSelectEntryColor();
4372 ShowPreview(m_aSelectedColor);
4375 void ColorListBox::Selected(const NamedColor& rColor)
4377 ShowPreview(rColor);
4378 m_aSelectedColor = rColor;
4379 if (m_aSelectedLink.IsSet())
4380 m_aSelectedLink.Call(*this);
4383 //to avoid the box resizing every time the color is changed to
4384 //the optimal size of the individual color, get the longest
4385 //standard color and stick with that as the size for all
4386 int ColorListBox::CalcBestWidthRequest()
4388 NamedColor aLongestColor;
4389 tools::Long nMaxStandardColorTextWidth = 0;
4390 XColorListRef const xColorTable = XColorList::CreateStdColorList();
4391 for (tools::Long i = 0; i != xColorTable->Count(); ++i)
4393 XColorEntry& rEntry = *xColorTable->GetColor(i);
4394 auto nColorTextWidth = m_xButton->get_pixel_size(rEntry.GetName()).Width();
4395 if (nColorTextWidth > nMaxStandardColorTextWidth)
4397 nMaxStandardColorTextWidth = nColorTextWidth;
4398 aLongestColor.m_aName = rEntry.GetName();
4401 ShowPreview(aLongestColor);
4402 return m_xButton->get_preferred_size().Width();
4405 void ColorListBox::LockWidthRequest(int nWidth)
4407 m_xButton->set_size_request(nWidth, -1);
4410 void ColorListBox::ShowPreview(const NamedColor &rColor)
4412 // ScGridWindow::UpdateAutoFilterFromMenu is similar
4413 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
4414 Size aImageSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
4416 ScopedVclPtrInstance<VirtualDevice> xDevice;
4417 xDevice->SetOutputSize(aImageSize);
4418 const tools::Rectangle aRect(Point(0, 0), aImageSize);
4419 if (m_bShowNoneButton && rColor.m_aColor == COL_NONE_COLOR)
4421 const Color aW(COL_WHITE);
4422 const Color aG(0xef, 0xef, 0xef);
4423 int nMinDim = std::min(aImageSize.Width(), aImageSize.Height()) + 1;
4424 int nCheckSize = nMinDim / 3;
4425 xDevice->DrawCheckered(aRect.TopLeft(), aRect.GetSize(), std::min(nCheckSize, 8), aW, aG);
4426 xDevice->SetFillColor();
4428 else
4430 if (rColor.m_aColor == COL_AUTO)
4431 xDevice->SetFillColor(m_aAutoDisplayColor);
4432 else
4433 xDevice->SetFillColor(rColor.m_aColor);
4436 xDevice->SetLineColor(rStyleSettings.GetDisableColor());
4437 xDevice->DrawRect(aRect);
4439 m_xButton->set_image(xDevice.get());
4440 m_xButton->set_label(rColor.m_aName);
4443 MenuOrToolMenuButton::MenuOrToolMenuButton(weld::MenuButton* pMenuButton)
4444 : m_pMenuButton(pMenuButton)
4445 , m_pToolbar(nullptr)
4446 , m_pControl(nullptr)
4447 , m_nId(0)
4451 MenuOrToolMenuButton::MenuOrToolMenuButton(weld::Toolbar* pToolbar, OUString aIdent)
4452 : m_pMenuButton(nullptr)
4453 , m_pToolbar(pToolbar)
4454 , m_aIdent(std::move(aIdent))
4455 , m_pControl(nullptr)
4456 , m_nId(0)
4460 MenuOrToolMenuButton::MenuOrToolMenuButton(SvxColorToolBoxControl* pControl, ToolBox* pToolbar, ToolBoxItemId nId)
4461 : m_pMenuButton(nullptr)
4462 , m_pToolbar(nullptr)
4463 , m_pControl(pControl)
4464 , m_xToolBox(pToolbar)
4465 , m_nId(nId)
4469 MenuOrToolMenuButton::~MenuOrToolMenuButton()
4473 bool MenuOrToolMenuButton::get_active() const
4475 if (m_pMenuButton)
4476 return m_pMenuButton->get_active();
4477 if (m_pToolbar)
4478 return m_pToolbar->get_menu_item_active(m_aIdent);
4479 return m_xToolBox->GetDownItemId() == m_nId;
4482 void MenuOrToolMenuButton::set_inactive() const
4484 if (m_pMenuButton)
4486 if (m_pMenuButton->get_active())
4487 m_pMenuButton->set_active(false);
4488 return;
4490 if (m_pToolbar)
4492 if (m_pToolbar->get_menu_item_active(m_aIdent))
4493 m_pToolbar->set_menu_item_active(m_aIdent, false);
4494 return;
4496 m_pControl->EndPopupMode();
4499 weld::Widget* MenuOrToolMenuButton::get_widget() const
4501 if (m_pMenuButton)
4502 return m_pMenuButton;
4503 if (m_pToolbar)
4504 return m_pToolbar;
4505 return m_xToolBox->GetFrameWeld();
4508 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */