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 
10 #ifndef INCLUDED_SVX_COLORBOX_HXX
11 #define INCLUDED_SVX_COLORBOX_HXX
12 
13 #include <memory>
14 #include <vcl/menubtn.hxx>
15 #include <vcl/weld.hxx>
16 #include <svx/colorwindow.hxx>
17 
18 class SvxColorListBox;
19 class ColorListBox;
20 
21 class SvxListBoxColorWrapper
22 {
23 public:
24     SvxListBoxColorWrapper(SvxColorListBox* pControl);
25     void operator()(const OUString& rCommand, const NamedColor& rColor);
26     void dispose();
27 private:
28     VclPtr<SvxColorListBox> mxControl;
29 };
30 
31 class SVX_DLLPUBLIC SvxColorListBox : public MenuButton
32 {
33 private:
34     friend class SvxListBoxColorWrapper;
35     VclPtr<SvxColorWindow> m_xColorWindow;
36     Link<SvxColorListBox&, void> m_aSelectedLink;
37     SvxListBoxColorWrapper m_aColorWrapper;
38     Color m_aAutoDisplayColor;
39     NamedColor m_aSelectedColor;
40     sal_uInt16 m_nSlotId;
41     bool m_bShowNoneButton;
42     std::shared_ptr<PaletteManager> m_xPaletteManager;
43     ColorStatus m_aColorStatus;
44 
45     DECL_LINK(MenuActivateHdl, MenuButton *, void);
46     void Selected(const NamedColor& rNamedColor);
47     void createColorWindow();
48     void LockWidthRequest();
49     VclPtr<SvxColorWindow> const & getColorWindow() const;
50 public:
51     SvxColorListBox(vcl::Window* pParent, WinBits nStyle = 0);
52     virtual ~SvxColorListBox() override;
53     virtual void dispose() override;
54 
SetSelectHdl(const Link<SvxColorListBox &,void> & rLink)55     void SetSelectHdl(const Link<SvxColorListBox&, void>& rLink)
56     {
57         m_aSelectedLink = rLink;
58     }
59 
60     void SetSlotId(sal_uInt16 nSlotId);
61 
GetSelectEntryColor() const62     Color const & GetSelectEntryColor() const { return m_aSelectedColor.first; }
63 
64     void SelectEntry(const NamedColor& rColor);
65     void SelectEntry(const Color& rColor);
66 
SetNoSelection()67     void SetNoSelection() { getColorWindow()->SetNoSelection(); }
IsNoSelection() const68     bool IsNoSelection() const { return getColorWindow()->IsNoSelection(); }
69 
70     void ShowPreview(const NamedColor &rColor);
71     void EnsurePaletteManager();
72 
73     DECL_LINK(WindowEventListener, VclWindowEvent&, void);
74 };
75 
76 class ListBoxColorWrapper
77 {
78 public:
79     ListBoxColorWrapper(ColorListBox* pControl);
80     void operator()(const OUString& rCommand, const NamedColor& rColor);
81 private:
82     ColorListBox* mpControl;
83 };
84 
85 class SVX_DLLPUBLIC ColorListBox
86 {
87 private:
88     friend class ListBoxColorWrapper;
89     std::unique_ptr<ColorWindow> m_xColorWindow;
90     std::unique_ptr<weld::MenuButton> m_xButton;
91     weld::Window* const m_pTopLevel;
92     Link<ColorListBox&, void> m_aSelectedLink;
93     ListBoxColorWrapper m_aColorWrapper;
94     Color m_aAutoDisplayColor;
95     Color m_aSaveColor;
96     NamedColor m_aSelectedColor;
97     sal_uInt16 m_nSlotId;
98     bool m_bShowNoneButton;
99     std::shared_ptr<PaletteManager> m_xPaletteManager;
100     ColorStatus m_aColorStatus;
101 
102     void Selected(const NamedColor& rNamedColor);
103     void createColorWindow();
104     void LockWidthRequest();
105     ColorWindow* getColorWindow() const;
106 
107     DECL_LINK(ToggleHdl, weld::ToggleButton&, void);
108 
109 public:
110     ColorListBox(std::unique_ptr<weld::MenuButton> pControl, weld::Window* pWindow);
111     ~ColorListBox();
112 
SetSelectHdl(const Link<ColorListBox &,void> & rLink)113     void SetSelectHdl(const Link<ColorListBox&, void>& rLink)
114     {
115         m_aSelectedLink = rLink;
116     }
117 
118     void SetSlotId(sal_uInt16 nSlotId, bool bShowNoneButton = false);
119 
GetSelectEntryColor() const120     Color const & GetSelectEntryColor() const { return m_aSelectedColor.first; }
GetSelectedEntry() const121     NamedColor const & GetSelectedEntry() const { return m_aSelectedColor; }
122 
123     void SelectEntry(const NamedColor& rColor);
124     void SelectEntry(const Color& rColor);
125 
SetNoSelection()126     void SetNoSelection() { getColorWindow()->SetNoSelection(); }
IsNoSelection() const127     bool IsNoSelection() const { return getColorWindow()->IsNoSelection(); }
128 
SetAutoDisplayColor(const Color & rColor)129     void SetAutoDisplayColor(const Color &rColor) { m_aAutoDisplayColor = rColor; }
130 
131     void ShowPreview(const NamedColor &rColor);
132     void EnsurePaletteManager();
133 
SaveValue()134     void SaveValue() { m_aSaveColor = GetSelectEntryColor(); }
IsValueChangedFromSaved() const135     bool IsValueChangedFromSaved() const { return m_aSaveColor != GetSelectEntryColor(); }
136 
set_sensitive(bool sensitive)137     void set_sensitive(bool sensitive) { m_xButton->set_sensitive(sensitive); }
get_sensitive() const138     bool get_sensitive() const { return m_xButton->get_sensitive(); }
show()139     void show() { m_xButton->show(); }
hide()140     void hide() { m_xButton->hide(); }
set_visible(bool bShow)141     void set_visible(bool bShow) { m_xButton->set_visible(bShow); }
set_help_id(const OString & rHelpId)142     void set_help_id(const OString& rHelpId) { m_xButton->set_help_id(rHelpId); }
connect_focus_in(const Link<weld::Widget &,void> & rLink)143     void connect_focus_in(const Link<weld::Widget&, void>& rLink) { m_xButton->connect_focus_in(rLink); }
get_widget()144     weld::MenuButton& get_widget() { return *m_xButton; }
145 };
146 
147 #endif
148 
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
150