1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVX_SOURCE_INC_STYLES_PREVIEW_WINDOW_HXX
21 #define INCLUDED_SVX_SOURCE_INC_STYLES_PREVIEW_WINDOW_HXX
23 #include <vcl/InterimItemWindow.hxx>
24 #include <svl/style.hxx>
25 #include <com/sun/star/frame/XDispatchProvider.hpp>
26 #include <sfx2/sfxstatuslistener.hxx>
28 class StylesPreviewWindow_Base
;
30 /// Listener for style selection
31 class StyleStatusListener final
: public SfxStatusListener
33 StylesPreviewWindow_Base
* m_pPreviewControl
;
37 StylesPreviewWindow_Base
* pPreviewControl
,
38 const css::uno::Reference
<css::frame::XDispatchProvider
>& xDispatchProvider
);
40 void StateChangedAtStatusListener(SfxItemState eState
, const SfxPoolItem
* pState
) override
;
43 /// Listener for styles creation or modification
44 class StylePoolChangeListener final
: public SfxListener
46 StylesPreviewWindow_Base
* m_pPreviewControl
;
47 SfxStyleSheetBasePool
* m_pStyleSheetPool
;
50 StylePoolChangeListener(StylesPreviewWindow_Base
* pPreviewControl
);
51 ~StylePoolChangeListener();
53 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
56 class StyleItemController
58 static constexpr unsigned LEFT_MARGIN
= 8;
60 SfxStyleFamily m_eStyleFamily
;
61 std::pair
<OUString
, OUString
> m_aStyleName
;
64 StyleItemController(std::pair
<OUString
, OUString
> aStyleName
);
66 void Paint(vcl::RenderContext
& rRenderContext
);
69 void DrawEntry(vcl::RenderContext
& rRenderContext
);
70 void DrawText(vcl::RenderContext
& rRenderContext
);
71 void DrawHighlight(vcl::RenderContext
& rRenderContext
, Color aFontBack
);
72 static void DrawContentBackground(vcl::RenderContext
& rRenderContext
,
73 const tools::Rectangle
& aContentRect
, const Color
& aColor
);
76 class StylesListUpdateTask final
: public Idle
78 StylesPreviewWindow_Base
& m_rStylesList
;
81 StylesListUpdateTask(StylesPreviewWindow_Base
& rStylesList
)
82 : Idle("StylesListUpdateTask")
83 , m_rStylesList(rStylesList
)
85 SetPriority(TaskPriority::HIGH_IDLE
);
88 virtual void Invoke() override
;
91 class StylesPreviewWindow_Base
93 friend class StylesListUpdateTask
;
96 static constexpr unsigned STYLES_COUNT
= 6;
98 css::uno::Reference
<css::frame::XDispatchProvider
> m_xDispatchProvider
;
100 std::unique_ptr
<weld::IconView
> m_xStylesView
;
102 StylesListUpdateTask m_aUpdateTask
;
104 rtl::Reference
<StyleStatusListener
> m_xStatusListener
;
105 std::unique_ptr
<StylePoolChangeListener
> m_pStylePoolChangeListener
;
107 std::vector
<std::pair
<OUString
, OUString
>> m_aDefaultStyles
;
108 std::vector
<std::pair
<OUString
, OUString
>> m_aAllStyles
;
110 OUString m_sSelectedStyle
;
112 DECL_LINK(Selected
, weld::IconView
&, void);
113 DECL_LINK(DoubleClick
, weld::IconView
&, bool);
114 DECL_LINK(DoCommand
, const CommandEvent
&, bool);
115 DECL_LINK(DoJsonProperty
, const weld::json_prop_query
&, bool);
118 StylesPreviewWindow_Base(
119 weld::Builder
& xBuilder
, std::vector
<std::pair
<OUString
, OUString
>>&& aDefaultStyles
,
120 const css::uno::Reference
<css::frame::XDispatchProvider
>& xDispatchProvider
);
121 ~StylesPreviewWindow_Base();
123 void Select(const OUString
& rStyleName
);
124 void RequestStylesListUpdate();
125 static VclPtr
<VirtualDevice
> GetCachedPreview(const std::pair
<OUString
, OUString
>& rStyle
);
126 static OString
GetCachedPreviewJson(const std::pair
<OUString
, OUString
>& rStyle
);
129 void UpdateStylesList();
130 void UpdateSelection();
131 bool Command(const CommandEvent
& rEvent
);
134 class StylesPreviewWindow_Impl final
: public InterimItemWindow
, public StylesPreviewWindow_Base
137 StylesPreviewWindow_Impl(
138 vcl::Window
* pParent
, std::vector
<std::pair
<OUString
, OUString
>>&& aDefaultStyles
,
139 const css::uno::Reference
<css::frame::XDispatchProvider
>& xDispatchProvider
);
140 ~StylesPreviewWindow_Impl();
144 void SetOptimalSize();
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */