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