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 <vcl/customweld.hxx>
25 #include <svl/style.hxx>
26 #include <com/sun/star/frame/XDispatchProvider.hpp>
27 #include <sfx2/sfxstatuslistener.hxx>
29 class StylesPreviewWindow_Base
;
31 class StyleStatusListener
: public SfxStatusListener
33 StylesPreviewWindow_Base
* m_pPreviewControl
;
36 StyleStatusListener(StylesPreviewWindow_Base
* pPreviewControl
,
37 css::uno::Reference
<css::frame::XDispatchProvider
>& xDispatchProvider
);
39 void StateChanged(SfxItemState eState
, const SfxPoolItem
* pState
) override
;
42 class StyleItemController
: public weld::CustomWidgetController
44 static constexpr unsigned LEFT_MARGIN
= 8;
46 SfxStyleFamily m_eStyleFamily
;
47 std::pair
<OUString
, OUString
> m_aStyleName
;
49 css::uno::Reference
<css::frame::XDispatchProvider
> m_xDispatchProvider
;
52 StyleItemController(const std::pair
<OUString
, OUString
>& aStyleName
,
53 css::uno::Reference
<css::frame::XDispatchProvider
>& xDispatchProvider
);
55 void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
57 bool MouseButtonDown(const MouseEvent
&) override
;
59 void SetStyle(const std::pair
<OUString
, OUString
>& sStyleName
);
61 void Select(bool bSelect
);
64 void DrawEntry(vcl::RenderContext
& rRenderContext
);
65 void DrawText(vcl::RenderContext
& rRenderContext
);
66 void DrawHighlight(vcl::RenderContext
& rRenderContext
, Color aFontBack
);
67 static void DrawSelection(vcl::RenderContext
& rRenderContext
);
68 static void DrawContentBackground(vcl::RenderContext
& rRenderContext
,
69 tools::Rectangle
& aContentRect
, Color
& aColor
);
72 class StylesPreviewWindow_Base
75 static constexpr unsigned STYLES_COUNT
= 4;
77 std::unique_ptr
<StyleItemController
> m_xStyleControllers
[STYLES_COUNT
];
78 std::unique_ptr
<weld::CustomWeld
> m_xStyleControllersWeld
[STYLES_COUNT
];
80 StyleStatusListener
* m_pStatusListener
;
81 css::uno::Reference
<css::lang::XComponent
> m_xStatusListener
;
83 std::unique_ptr
<weld::Toolbar
> m_xUp
;
84 std::unique_ptr
<weld::Toolbar
> m_xDown
;
86 std::vector
<std::pair
<OUString
, OUString
>> m_aDefaultStyles
;
87 std::vector
<std::pair
<OUString
, OUString
>> m_aAllStyles
;
89 unsigned m_nStyleIterator
;
90 OUString m_sSelectedStyle
;
92 DECL_LINK(GoUp
, const OString
&, void);
93 DECL_LINK(GoDown
, const OString
&, void);
96 StylesPreviewWindow_Base(weld::Builder
& xBuilder
,
97 std::vector
<std::pair
<OUString
, OUString
>>& aDefaultStyles
,
98 css::uno::Reference
<css::frame::XDispatchProvider
>& xDispatchProvider
);
99 ~StylesPreviewWindow_Base();
101 void Select(const OUString
& rStyleName
);
105 void UpdateStylesList();
106 void MakeCurrentStyleVisible();
107 std::pair
<OUString
, OUString
> GetVisibleStyle(unsigned nPosition
);
110 class StylesPreviewWindow_Impl
: public InterimItemWindow
, public StylesPreviewWindow_Base
113 StylesPreviewWindow_Impl(vcl::Window
* pParent
,
114 std::vector
<std::pair
<OUString
, OUString
>>& aDefaultStyles
,
115 css::uno::Reference
<css::frame::XDispatchProvider
>& xDispatchProvider
);
116 ~StylesPreviewWindow_Impl();
120 void SetOptimalSize();
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */