LibreOffice Module svx (master)  1
colorwindow.hxx
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 #ifndef INCLUDED_SVX_SOURCE_TBXCTRLS_COLORWINDOW_HXX
21 #define INCLUDED_SVX_SOURCE_TBXCTRLS_COLORWINDOW_HXX
22 
23 #include <svtools/toolbarmenu.hxx>
24 #include <rtl/ustring.hxx>
25 #include <svx/SvxColorValueSet.hxx>
26 #include <svx/Palette.hxx>
27 #include <vcl/lstbox.hxx>
28 #include <vcl/fixed.hxx>
29 
30 #include <functional>
31 
32 namespace com::sun::star::frame { class XFrame; }
33 
34 class PaletteManager;
35 
37 {
41 public:
42  ColorStatus();
43  ~ColorStatus();
44  void statusChanged( const css::frame::FeatureStateEvent& rEvent );
45  Color GetColor();
46 };
47 
48 class Button;
49 typedef std::function<void(const OUString&, const NamedColor&)> ColorSelectFunction;
50 
51 #define COL_NONE_COLOR ::Color(0x80, 0xFF, 0xFF, 0xFF)
52 
54 {
55 private:
56  const sal_uInt16 theSlotId;
59 
65  OUString const maCommand;
67 
69  std::shared_ptr<PaletteManager> mxPaletteManager;
71 
74 
75  DECL_LINK( SelectHdl, ValueSet*, void );
76  DECL_LINK( SelectPaletteHdl, ListBox&, void);
77  DECL_LINK( AutoColorClickHdl, Button*, void );
78  DECL_LINK( OpenPickerClickHdl, Button*, void );
79 
80  static bool SelectValueSetEntry(SvxColorValueSet* pColorSet, const Color& rColor);
81  static NamedColor GetSelectEntryColor(ValueSet const * pColorSet);
82  NamedColor GetAutoColor() const;
83 
84 public:
85  SvxColorWindow(const OUString& rCommand,
86  std::shared_ptr<PaletteManager> const & rPaletteManager,
87  ColorStatus& rColorStatus,
88  sal_uInt16 nSlotId,
89  const css::uno::Reference< css::frame::XFrame >& rFrame,
90  vcl::Window* pParentWindow,
91  // tdf#118251 When true, reuse pParentWindow as the parent of the color picker
92  // that appears from the 'custom color' button. When false use the window of
93  // rFrame. true is helpful when launched from a dialog, false for launched
94  // from a toolbar
95  bool bReuseParentForPicker,
96  ColorSelectFunction const& rColorSelectFunction);
97  virtual ~SvxColorWindow() override;
98  virtual void dispose() override;
99  void StartSelection();
100  void SetNoSelection();
101  bool IsNoSelection() const;
102  void SelectEntry(const NamedColor& rColor);
103  void SelectEntry(const Color& rColor);
104  NamedColor GetSelectEntryColor() const;
105 
106  virtual void KeyInput( const KeyEvent& rKEvt ) override;
107  virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
108 
109  void SetSelectedHdl( const Link<const NamedColor&, void>& rLink ) { maSelectedLink = rLink; }
110 };
111 
113 {
114 private:
115  // either
117  // or
119  OString m_aIdent;
120 public:
122  MenuOrToolMenuButton(weld::Toolbar* pToolbar, const OString& rIdent);
123 
124  bool get_active() const;
125  void set_active(bool bActive) const;
126  weld::Widget* get_widget() const;
127 };
128 
130 {
131 private:
132  std::unique_ptr<weld::Builder> m_xBuilder;
133 
134  const sal_uInt16 theSlotId;
137  std::shared_ptr<PaletteManager> mxPaletteManager;
140 
141  std::unique_ptr<ColorValueSet> mxColorSet;
142  std::unique_ptr<ColorValueSet> mxRecentColorSet;
143  std::unique_ptr<weld::Container> mxTopLevel;
144  std::unique_ptr<weld::ComboBox> mxPaletteListBox;
145  std::unique_ptr<weld::Button> mxButtonAutoColor;
146  std::unique_ptr<weld::Button> mxButtonNoneColor;
147  std::unique_ptr<weld::Button> mxButtonPicker;
148  std::unique_ptr<weld::Widget> mxAutomaticSeparator;
149  std::unique_ptr<weld::CustomWeld> mxColorSetWin;
150  std::unique_ptr<weld::CustomWeld> mxRecentColorSetWin;
152 
153  DECL_LINK(SelectHdl, SvtValueSet*, void);
154  DECL_LINK(SelectPaletteHdl, weld::ComboBox&, void);
155  DECL_LINK(AutoColorClickHdl, weld::Button&, void);
156  DECL_LINK(OpenPickerClickHdl, weld::Button&, void);
157 
158  static bool SelectValueSetEntry(ColorValueSet* pColorSet, const Color& rColor);
159  static NamedColor GetSelectEntryColor(SvtValueSet const * pColorSet);
160  NamedColor GetAutoColor() const;
161 
162 public:
163  ColorWindow(std::shared_ptr<PaletteManager> const & rPaletteManager,
164  ColorStatus& rColorStatus,
165  sal_uInt16 nSlotId,
166  const css::uno::Reference< css::frame::XFrame >& rFrame,
167  weld::Window* pParentWindow, const MenuOrToolMenuButton &rMenuButton,
168  ColorSelectFunction const& rColorSelectFunction);
169  weld::Container* GetWidget() { return mxTopLevel.get(); }
170  virtual ~ColorWindow() override;
171  void ShowNoneButton();
172  void SetNoSelection();
173  bool IsNoSelection() const;
174  void SelectEntry(const NamedColor& rColor);
175  void SelectEntry(const Color& rColor);
176  NamedColor GetSelectEntryColor() const;
177 
178  DECL_LINK(FocusHdl, weld::Widget&, void);
179 
180  virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
181 
182 };
183 
184 #endif
185 
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::pair< Color, OUString > NamedColor
Definition: Palette.hxx:27
Link< const NamedColor &, void > maSelectedLink
Definition: colorwindow.hxx:66
VclPtr< PushButton > mpButtonPicker
Definition: colorwindow.hxx:63
weld::Toolbar * m_pToolbar
ColorSelectFunction const maColorSelectFunction
Definition: colorwindow.hxx:72
weld::Container * GetWidget()
VclPtr< PushButton > mpButtonAutoColor
Definition: colorwindow.hxx:61
virtual void statusChanged(const css::frame::FeatureStateEvent &Event)
#define SVX_DLLPUBLIC
Definition: svxdllapi.h:28
MenuOrToolMenuButton maMenuButton
weld::MenuButton * m_pMenuButton
ColorStatus & mrColorStatus
VclPtr< vcl::Window > mxParentWindow
Definition: colorwindow.hxx:68
std::unique_ptr< weld::ComboBox > mxPaletteListBox
std::shared_ptr< PaletteManager > mxPaletteManager
Definition: colorwindow.hxx:69
std::unique_ptr< weld::Builder > m_xBuilder
ColorStatus & mrColorStatus
Definition: colorwindow.hxx:70
std::unique_ptr< weld::CustomWeld > mxRecentColorSetWin
std::unique_ptr< weld::Button > mxButtonPicker
VclPtr< ListBox > mpPaletteListBox
Definition: colorwindow.hxx:60
std::unique_ptr< ColorValueSet > mxRecentColorSet
const sal_uInt16 theSlotId
Definition: colorwindow.hxx:56
std::unique_ptr< ColorValueSet > mxColorSet
std::unique_ptr< weld::Button > mxButtonNoneColor
weld::Button * mpDefaultButton
std::unique_ptr< weld::Widget > mxAutomaticSeparator
std::unique_ptr< weld::CustomWeld > mxColorSetWin
ColorSelectFunction const maColorSelectFunction
std::shared_ptr< PaletteManager > mxPaletteManager
VclPtr< PushButton > mpButtonNoneColor
Definition: colorwindow.hxx:62
bool const mbReuseParentForPicker
Definition: colorwindow.hxx:73
std::unique_ptr< weld::Button > mxButtonAutoColor
virtual void dispose() override
VclPtr< SvxColorValueSet > mpColorSet
Definition: colorwindow.hxx:57
VclPtr< FixedLine > mpAutomaticSeparator
Definition: colorwindow.hxx:64
const sal_uInt16 theSlotId
VclPtr< SvxColorValueSet > mpRecentColorSet
Definition: colorwindow.hxx:58
void SetSelectedHdl(const Link< const NamedColor &, void > &rLink)
std::unique_ptr< weld::Container > mxTopLevel
std::function< void(const OUString &, const NamedColor &)> ColorSelectFunction
Definition: colorwindow.hxx:48
OUString const maCommand
Definition: colorwindow.hxx:65
Color maTLBRColor
Definition: colorwindow.hxx:39
Color maBLTRColor
Definition: colorwindow.hxx:40
weld::Window *const mpParentWindow