1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #ifndef INCLUDED_SVX_COLORBOX_HXX
11 #define INCLUDED_SVX_COLORBOX_HXX
14 #include <vcl/menubtn.hxx>
15 #include <vcl/weld.hxx>
16 #include <svx/colorwindow.hxx>
18 class SvxColorListBox
;
21 class SvxListBoxColorWrapper
24 SvxListBoxColorWrapper(SvxColorListBox
* pControl
);
25 void operator()(const OUString
& rCommand
, const NamedColor
& rColor
);
28 VclPtr
<SvxColorListBox
> mxControl
;
31 class SVX_DLLPUBLIC SvxColorListBox
: public MenuButton
34 friend class SvxListBoxColorWrapper
;
35 VclPtr
<SvxColorWindow
> m_xColorWindow
;
36 Link
<SvxColorListBox
&, void> m_aSelectedLink
;
37 SvxListBoxColorWrapper m_aColorWrapper
;
38 Color m_aAutoDisplayColor
;
40 NamedColor m_aSelectedColor
;
42 bool m_bShowNoneButton
;
43 std::shared_ptr
<PaletteManager
> m_xPaletteManager
;
44 ColorStatus m_aColorStatus
;
46 DECL_LINK(MenuActivateHdl
, MenuButton
*, void);
47 void Selected(const NamedColor
& rNamedColor
);
48 void createColorWindow();
49 void LockWidthRequest();
50 VclPtr
<SvxColorWindow
> const & getColorWindow() const;
52 SvxColorListBox(vcl::Window
* pParent
, WinBits nStyle
= 0);
53 virtual ~SvxColorListBox() override
;
54 virtual void dispose() override
;
56 void SetSelectHdl(const Link
<SvxColorListBox
&, void>& rLink
)
58 m_aSelectedLink
= rLink
;
61 void SetSlotId(sal_uInt16 nSlotId
, bool bShowNoneButton
= false);
63 Color
const & GetSelectEntryColor() const { return m_aSelectedColor
.first
; }
64 NamedColor
const & GetSelectedEntry() const { return m_aSelectedColor
; }
66 void SelectEntry(const NamedColor
& rColor
);
67 void SelectEntry(const Color
& rColor
);
69 void SetNoSelection() { getColorWindow()->SetNoSelection(); }
70 bool IsNoSelection() const { return getColorWindow()->IsNoSelection(); }
72 void SetAutoDisplayColor(const Color
&rColor
) { m_aAutoDisplayColor
= rColor
; }
73 void ShowPreview(const NamedColor
&rColor
);
74 void EnsurePaletteManager();
76 void SaveValue() { m_aSaveColor
= GetSelectEntryColor(); }
77 bool IsValueChangedFromSaved() const { return m_aSaveColor
!= GetSelectEntryColor(); }
79 DECL_LINK(WindowEventListener
, VclWindowEvent
&, void);
82 class ListBoxColorWrapper
85 ListBoxColorWrapper(ColorListBox
* pControl
);
86 void operator()(const OUString
& rCommand
, const NamedColor
& rColor
);
88 ColorListBox
* mpControl
;
91 class SVX_DLLPUBLIC ColorListBox
94 friend class ListBoxColorWrapper
;
95 std::unique_ptr
<ColorWindow
> m_xColorWindow
;
96 std::unique_ptr
<weld::MenuButton
> m_xButton
;
97 weld::Window
* const m_pTopLevel
;
98 Link
<ColorListBox
&, void> m_aSelectedLink
;
99 ListBoxColorWrapper m_aColorWrapper
;
100 Color
const m_aAutoDisplayColor
;
102 NamedColor m_aSelectedColor
;
103 sal_uInt16 m_nSlotId
;
104 bool m_bShowNoneButton
;
105 std::shared_ptr
<PaletteManager
> m_xPaletteManager
;
106 ColorStatus m_aColorStatus
;
108 void Selected(const NamedColor
& rNamedColor
);
109 void createColorWindow();
110 void LockWidthRequest();
111 ColorWindow
* getColorWindow() const;
113 ColorListBox(std::unique_ptr
<weld::MenuButton
> pControl
, weld::Window
* pWindow
);
116 void SetSelectHdl(const Link
<ColorListBox
&, void>& rLink
)
118 m_aSelectedLink
= rLink
;
121 void SetSlotId(sal_uInt16 nSlotId
, bool bShowNoneButton
= false);
123 Color
const & GetSelectEntryColor() const { return m_aSelectedColor
.first
; }
124 NamedColor
const & GetSelectedEntry() const { return m_aSelectedColor
; }
126 void SelectEntry(const Color
& rColor
);
128 void SetNoSelection() { getColorWindow()->SetNoSelection(); }
129 bool IsNoSelection() const { return getColorWindow()->IsNoSelection(); }
131 void ShowPreview(const NamedColor
&rColor
);
132 void EnsurePaletteManager();
134 void SaveValue() { m_aSaveColor
= GetSelectEntryColor(); }
135 bool IsValueChangedFromSaved() const { return m_aSaveColor
!= GetSelectEntryColor(); }
137 void set_sensitive(bool sensitive
) { m_xButton
->set_sensitive(sensitive
); }
138 bool get_sensitive() const { return m_xButton
->get_sensitive(); }
139 void show() { m_xButton
->show(); }
140 void hide() { m_xButton
->hide(); }
141 void set_visible(bool bShow
) { m_xButton
->set_visible(bShow
); }
142 void set_help_id(const OString
& rHelpId
) { m_xButton
->set_help_id(rHelpId
); }
143 weld::MenuButton
& get_widget() { return *m_xButton
; }
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */