Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / svtools / ctrlbox.hxx
blob0d7293fc77ebdd4a4c00fbecf41ad88c9ae0a2f3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <svtools/svtdllapi.h>
23 #include <svtools/toolbarmenu.hxx>
24 #include <editeng/borderline.hxx>
25 #include <vcl/idle.hxx>
26 #include <vcl/metric.hxx>
27 #include <vcl/weld.hxx>
29 #include <memory>
31 namespace weld { class CustomWeld; }
33 class BitmapEx;
34 class BorderWidthImpl;
35 class FontList;
36 class VclSimpleEvent;
37 class VirtualDevice;
39 /** Utility class storing the border line width, style and colors. The widths
40 are defined in Twips.
42 class ImpLineListData
44 private:
45 BorderWidthImpl const m_aWidthImpl;
47 Color ( * m_pColor1Fn )( Color );
48 Color ( * m_pColor2Fn )( Color );
49 Color ( * m_pColorDistFn )( Color, Color );
51 tools::Long m_nMinWidth;
52 SvxBorderLineStyle m_nStyle;
54 public:
55 ImpLineListData( BorderWidthImpl aWidthImpl,
56 SvxBorderLineStyle nStyle, tools::Long nMinWidth, Color ( *pColor1Fn )( Color ),
57 Color ( *pColor2Fn )( Color ), Color ( *pColorDistFn )( Color, Color ) ) :
58 m_aWidthImpl( aWidthImpl ),
59 m_pColor1Fn( pColor1Fn ),
60 m_pColor2Fn( pColor2Fn ),
61 m_pColorDistFn( pColorDistFn ),
62 m_nMinWidth( nMinWidth ),
63 m_nStyle( nStyle )
67 /** Returns the computed width of the line 1 in twips. */
68 tools::Long GetLine1ForWidth( tools::Long nWidth ) const { return m_aWidthImpl.GetLine1( nWidth ); }
70 /** Returns the computed width of the line 2 in twips. */
71 tools::Long GetLine2ForWidth( tools::Long nWidth ) const { return m_aWidthImpl.GetLine2( nWidth ); }
73 /** Returns the computed width of the gap in twips. */
74 tools::Long GetDistForWidth( tools::Long nWidth ) const { return m_aWidthImpl.GetGap( nWidth ); }
76 Color GetColorLine1( const Color& rMain ) const
78 return ( *m_pColor1Fn )( rMain );
81 Color GetColorLine2( const Color& rMain ) const
83 return ( *m_pColor2Fn )( rMain );
86 Color GetColorDist( const Color& rMain, const Color& rDefault ) const
88 return ( *m_pColorDistFn )( rMain, rDefault );
91 /** Returns the minimum width in twips */
92 tools::Long GetMinWidth( ) const { return m_nMinWidth;}
93 SvxBorderLineStyle GetStyle( ) const { return m_nStyle;}
96 enum class SvxBorderLineStyle : sal_Int16;
98 typedef ::std::vector< FontMetric > ImplFontList;
100 /*************************************************************************
102 class LineListBox
104 Description
106 Allows selection of line styles and sizes. Note that before first insert,
107 units and window size need to be set. Supported units are typographic point
108 (pt) and millimeters (mm). For SourceUnit, pt, mm and twips are supported.
109 All scalar numbers in 1/100 of the corresponding unit.
111 Line1 is the outer, Line2 the inner line, Distance is the distance between
112 these two lines. If Line2 == 0, only Line1 will be shown. Defaults for
113 source and target unit are FieldUnit::POINT.
115 SetColor() sets the line color.
117 Remarks
119 Contrary to a simple ListBox, user-specific data are not supported.
120 If UpdateMode is disabled, no data should be read, no selections
121 should be set, and the return code shall be ignore, as in these are
122 not defined in this mode. Also the bit WinBit WB_SORT may not be set.
124 --------------------------------------------------------------------------
126 class FontNameBox
128 Description
130 Allows selection of fonts. The ListBox will be filled using Fill parameter,
131 which is pointer to an FontList object.
133 Calling EnableWYSIWYG() enables rendering the font name in the currently
134 selected font.
136 See also
138 FontList; FontStyleBox; FontSizeBox; FontNameMenu
140 --------------------------------------------------------------------------
142 class FontStyleBox
144 Description
146 Allows select of FontStyle's. The parameter Fill points to a list
147 of available font styles for the font.
149 Reproduced styles are always added - this could change in future, as
150 potentially not all applications [Draw,Equation,FontWork] can properly
151 handle synthetic fonts. On filling, the previous name will be retained
152 if possible.
154 For DontKnow, the FontStyleBox should be filled with OUString(),
155 so it will contain a list with the default attributes. The currently
156 shown style probably needs to be reset by the application.
158 See also
160 FontList; FontNameBox; FontSizeBox;
162 --------------------------------------------------------------------------
164 class FontSizeBox
166 Description
168 Allows selection of font sizes. The values are retrieved via GetValue()
169 and set via SetValue(). The Fill parameter fills the ListBox with the
170 available sizes for the passed font.
172 All sizes are in 1/10 typographic point (pt).
174 The passed FontList must be retained until the next fill call.
176 Additionally it supports a relative mod, which allows entering
177 percentage values. This, eg., can be useful for template dialogs.
178 This mode can only be enabled, but not disabled again.
180 For DontKnow the FontSizeBox should be filled FontMetric(), so it will
181 contain a list with the standard sizes. Th currently shown size
182 probably needs to be reset by the application.
184 See also
186 FontList; FontNameBox; FontStyleBox; FontSizeMenu
188 *************************************************************************/
190 inline Color sameColor( Color rMain )
192 return rMain;
195 inline Color sameDistColor( Color /*rMain*/, Color rDefault )
197 return rDefault;
200 class ValueSet;
202 class SVT_DLLPUBLIC SvtLineListBox final : public WeldToolbarPopup
204 public:
205 typedef Color (*ColorFunc)(Color);
206 typedef Color (*ColorDistFunc)(Color, Color);
208 SvtLineListBox(std::unique_ptr<weld::MenuButton> pControl);
209 ~SvtLineListBox();
211 static OUString GetLineStyleName(SvxBorderLineStyle eStyle);
213 /** Set the width in Twips */
214 void SetWidth(tools::Long nWidth)
216 m_nWidth = nWidth;
217 UpdateEntries();
218 UpdatePreview();
221 tools::Long GetWidth() const { return m_nWidth; }
223 /** Insert a listbox entry with all widths in Twips. */
224 void InsertEntry(const BorderWidthImpl& rWidthImpl,
225 SvxBorderLineStyle nStyle, tools::Long nMinWidth = 0,
226 ColorFunc pColor1Fn = &sameColor,
227 ColorFunc pColor2Fn = &sameColor,
228 ColorDistFunc pColorDistFn = &sameDistColor);
230 void SelectEntry( SvxBorderLineStyle nStyle );
231 SvxBorderLineStyle GetSelectEntryStyle() const;
233 void SetSourceUnit( FieldUnit eNewUnit ) { eSourceUnit = eNewUnit; }
235 void SetColor( const Color& rColor )
237 aColor = rColor;
238 UpdateEntries();
239 UpdatePreview();
242 const Color& GetColor() const { return aColor; }
244 void SetSelectHdl(const Link<SvtLineListBox&,void>& rLink) { maSelectHdl = rLink; }
246 void set_sensitive(bool bSensitive) { m_xControl->set_sensitive(bSensitive); }
248 virtual void GrabFocus() override;
250 private:
252 SVT_DLLPRIVATE void ImpGetLine( tools::Long nLine1, tools::Long nLine2, tools::Long nDistance,
253 Color nColor1, Color nColor2, Color nColorDist,
254 SvxBorderLineStyle nStyle, BitmapEx& rBmp );
256 DECL_DLLPRIVATE_LINK(ValueSelectHdl, ValueSet*, void);
257 DECL_DLLPRIVATE_LINK(ToggleHdl, weld::Toggleable&, void);
258 DECL_DLLPRIVATE_LINK(NoneHdl, weld::Button&, void);
259 DECL_DLLPRIVATE_LINK(StyleUpdatedHdl, weld::Widget&, void);
261 void UpdateEntries();
263 void UpdatePreview();
265 SvtLineListBox( const SvtLineListBox& ) = delete;
266 SvtLineListBox& operator =( const SvtLineListBox& ) = delete;
268 std::unique_ptr<weld::MenuButton> m_xControl;
269 std::unique_ptr<weld::Button> m_xNoneButton;
270 std::unique_ptr<ValueSet> m_xLineSet;
271 std::unique_ptr<weld::CustomWeld> m_xLineSetWin;
273 std::vector<std::unique_ptr<ImpLineListData>> m_vLineList;
274 tools::Long m_nWidth;
275 ScopedVclPtr<VirtualDevice> aVirDev;
276 Color aColor;
277 FieldUnit eSourceUnit;
278 Link<SvtLineListBox&,void> maSelectHdl;
281 class SVT_DLLPUBLIC SvtCalendarBox
283 public:
284 SvtCalendarBox(std::unique_ptr<weld::MenuButton> pControl, bool bUseLabel = true);
285 ~SvtCalendarBox();
287 weld::MenuButton& get_button() { return *m_xControl; }
289 void set_date(const Date& rDate);
290 Date get_date() const { return m_xCalendar->get_date(); }
292 void set_label(const OUString& rLabel) { m_xControl->set_label(rLabel); }
293 OUString get_label() const { return m_xControl->get_label(); }
295 void set_sensitive(bool bSensitive) { m_xControl->set_sensitive(bSensitive); }
296 bool get_sensitive() const { return m_xControl->get_sensitive(); }
297 void set_visible(bool bSensitive) { m_xControl->set_visible(bSensitive); }
298 void show() { set_visible(true); }
299 void grab_focus() { m_xControl->grab_focus(); }
301 void connect_activated(const Link<SvtCalendarBox&, void>& rActivatedHdl) { m_aActivatedHdl = rActivatedHdl; }
302 void connect_selected(const Link<SvtCalendarBox&, void>& rSelectHdl) { m_aSelectHdl = rSelectHdl; }
304 void connect_focus_in(const Link<weld::Widget&, void>& rLink) { m_xControl->connect_focus_in(rLink); }
305 void connect_focus_out(const Link<weld::Widget&, void>& rLink) { m_xControl->connect_focus_out(rLink); }
306 private:
307 DECL_DLLPRIVATE_LINK(SelectHdl, weld::Calendar&, void);
308 DECL_DLLPRIVATE_LINK(ActivateHdl, weld::Calendar&, void);
310 bool m_bUseLabel;
312 std::unique_ptr<weld::MenuButton> m_xControl;
313 std::unique_ptr<weld::Builder> m_xBuilder;
314 std::unique_ptr<weld::Widget> m_xTopLevel;
315 std::unique_ptr<weld::Calendar> m_xCalendar;
317 Link<SvtCalendarBox&, void> m_aActivatedHdl;
318 Link<SvtCalendarBox&, void> m_aSelectHdl;
320 void set_label_from_date();
323 class SVT_DLLPUBLIC FontNameBox
325 private:
326 std::unique_ptr<weld::ComboBox> m_xComboBox;
327 std::unique_ptr<ImplFontList> mpFontList;
328 size_t mnPreviewProgress;
329 bool mbWYSIWYG;
330 OUString maFontMRUEntriesFile;
331 Idle maUpdateIdle;
333 SVT_DLLPRIVATE void ImplDestroyFontList();
335 DECL_DLLPRIVATE_LINK(CustomRenderHdl, weld::ComboBox::render_args, void);
336 DECL_DLLPRIVATE_LINK(CustomGetSizeHdl, OutputDevice&, Size);
337 DECL_DLLPRIVATE_LINK(SettingsChangedHdl, VclSimpleEvent&, void);
338 DECL_DLLPRIVATE_LINK(UpdateHdl, Timer*, void);
340 void LoadMRUEntries( const OUString& aFontMRUEntriesFile );
341 void SaveMRUEntries( const OUString& aFontMRUEntriesFile ) const;
343 OutputDevice& CachePreview(size_t nIndex, Point* pTopLeft);
345 public:
346 FontNameBox(std::unique_ptr<weld::ComboBox> p);
347 ~FontNameBox();
349 void Fill( const FontList* pList );
351 void EnableWYSIWYG(bool bEnable);
352 bool IsWYSIWYGEnabled() const { return mbWYSIWYG; }
354 void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_xComboBox->connect_changed(rLink); }
355 void connect_focus_in(const Link<weld::Widget&, void>& rLink) { m_xComboBox->connect_focus_in(rLink); }
356 void connect_focus_out(const Link<weld::Widget&, void>& rLink) { m_xComboBox->connect_focus_out(rLink); }
357 void connect_key_press(const Link<const KeyEvent&, bool>& rLink) { m_xComboBox->connect_key_press(rLink); }
358 int get_active() const { return m_xComboBox->get_active(); }
359 OUString get_active_text() const { return m_xComboBox->get_active_text(); }
360 void set_active_or_entry_text(const OUString& rText);
361 void set_active(int nPos) { m_xComboBox->set_active(nPos); }
362 int get_count() const { return m_xComboBox->get_count(); }
363 OUString get_text(int nIndex) const { return m_xComboBox->get_text(nIndex); }
364 void set_sensitive(bool bSensitive) { m_xComboBox->set_sensitive(bSensitive); }
365 void save_value() { m_xComboBox->save_value(); }
366 OUString const& get_saved_value() const { return m_xComboBox->get_saved_value(); }
367 void select_entry_region(int nStartPos, int nEndPos) { m_xComboBox->select_entry_region(nStartPos, nEndPos); }
368 bool get_entry_selection_bounds(int& rStartPos, int& rEndPos) { return m_xComboBox->get_entry_selection_bounds(rStartPos, rEndPos); }
369 void clear() { m_xComboBox->clear(); }
370 void grab_focus() { m_xComboBox->grab_focus(); }
371 bool has_focus() const { return m_xComboBox->has_focus(); }
372 void connect_entry_activate(const Link<weld::ComboBox&, bool>& rLink) { m_xComboBox->connect_entry_activate(rLink); }
373 void connect_get_property_tree(const Link<tools::JsonWriter&, void>& rLink) { m_xComboBox->connect_get_property_tree(rLink); }
374 void set_entry_width_chars(int nWidth) { m_xComboBox->set_entry_width_chars(nWidth); }
375 void set_size_request(int nWidth, int nHeight) { m_xComboBox->set_size_request(nWidth, nHeight); }
376 int get_max_mru_count() const { return m_xComboBox->get_max_mru_count(); }
377 void set_max_mru_count(int nCount) { m_xComboBox->set_max_mru_count(nCount); }
379 // font size is in points, not pixels, e.g. see Window::[G]etPointFont
380 void set_entry_font(const vcl::Font& rFont) { m_xComboBox->set_entry_font(rFont); }
381 vcl::Font get_entry_font() { return m_xComboBox->get_entry_font(); }
383 void set_tooltip_text(const OUString& rTip) { m_xComboBox->set_tooltip_text(rTip); }
385 private:
386 void InitFontMRUEntriesFile();
388 FontNameBox( const FontNameBox& ) = delete;
389 FontNameBox& operator =( const FontNameBox& ) = delete;
392 class SVT_DLLPUBLIC FontStyleBox
394 std::unique_ptr<weld::ComboBox> m_xComboBox;
395 public:
396 FontStyleBox(std::unique_ptr<weld::ComboBox> p);
398 void Fill(std::u16string_view rName, const FontList* pList);
400 void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_xComboBox->connect_changed(rLink); }
401 OUString get_active_text() const { return m_xComboBox->get_active_text(); }
402 void set_active_text(const OUString& rText) { m_xComboBox->set_active_text(rText); }
403 void set_size_request(int nWidth, int nHeight) { m_xComboBox->set_size_request(nWidth, nHeight); }
405 void append_text(const OUString& rStr) { m_xComboBox->append_text(rStr); }
406 void set_sensitive(bool bSensitive) { m_xComboBox->set_sensitive(bSensitive); }
407 void save_value() { m_xComboBox->save_value(); }
408 OUString const& get_saved_value() const { return m_xComboBox->get_saved_value(); }
409 int get_count() const { return m_xComboBox->get_count(); }
410 int find_text(const OUString& rStr) const { return m_xComboBox->find_text(rStr); }
411 private:
412 FontStyleBox(const FontStyleBox& ) = delete;
413 FontStyleBox& operator=(const FontStyleBox&) = delete;
416 class SVT_DLLPUBLIC FontSizeBox
418 const FontList* pFontList;
419 int nSavedValue;
420 int nMin;
421 int nMax;
422 FieldUnit eUnit;
423 sal_uInt16 nDecimalDigits;
424 sal_uInt16 nRelMin;
425 sal_uInt16 nRelMax;
426 sal_uInt16 nRelStep;
427 short nPtRelMin;
428 short nPtRelMax;
429 short nPtRelStep;
430 bool bRelativeMode:1,
431 bRelative:1,
432 bPtRelative:1,
433 bStdSize:1;
434 Link<weld::ComboBox&, void> m_aChangeHdl;
435 Link<weld::Widget&, void> m_aFocusOutHdl;
436 std::unique_ptr<weld::ComboBox> m_xComboBox;
438 sal_uInt16 GetDecimalDigits() const { return nDecimalDigits; }
439 void SetDecimalDigits(sal_uInt16 nDigits) { nDecimalDigits = nDigits; }
440 FieldUnit GetUnit() const { return eUnit; }
441 void SetUnit(FieldUnit _eUnit) { eUnit = _eUnit; }
442 void SetRange(int nNewMin, int nNewMax) { nMin = nNewMin; nMax = nNewMax; }
443 void SetValue(int nNewValue, FieldUnit eInUnit);
445 void InsertValue(int i);
447 OUString format_number(int nValue) const;
449 DECL_DLLPRIVATE_LINK(ModifyHdl, weld::ComboBox&, void);
450 DECL_DLLPRIVATE_LINK(ReformatHdl, weld::Widget&, void);
451 public:
452 FontSizeBox(std::unique_ptr<weld::ComboBox> p);
454 void Fill(const FontList* pList);
456 void EnableRelativeMode(sal_uInt16 nMin, sal_uInt16 nMax, sal_uInt16 nStep = 5);
457 void EnablePtRelativeMode(short nMin, short nMax, short nStep = 10);
458 bool IsRelativeMode() const { return bRelativeMode; }
459 void SetRelative( bool bRelative );
460 bool IsRelative() const { return bRelative; }
461 void SetPtRelative( bool bPtRel )
463 bPtRelative = bPtRel;
464 SetRelative(true);
466 bool IsPtRelative() const { return bPtRelative; }
468 void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_aChangeHdl = rLink; }
469 void connect_focus_out(const Link<weld::Widget&, void>& rLink) { m_aFocusOutHdl = rLink; }
470 void connect_key_press(const Link<const KeyEvent&, bool>& rLink) { m_xComboBox->connect_key_press(rLink); }
471 OUString get_active_text() const { return m_xComboBox->get_active_text(); }
472 void set_active_or_entry_text(const OUString& rText);
473 void set_sensitive(bool bSensitive) { m_xComboBox->set_sensitive(bSensitive); }
474 void set_size_request(int nWidth, int nHeight) { m_xComboBox->set_size_request(nWidth, nHeight); }
476 int get_active() const { return m_xComboBox->get_active(); }
477 int get_value() const;
478 void set_value(int nValue);
479 void save_value() { nSavedValue = get_value(); }
480 int get_saved_value() const { return nSavedValue; }
481 bool get_value_changed_from_saved() const { return get_value() != get_saved_value(); }
482 int get_count() const { return m_xComboBox->get_count(); }
483 OUString get_text(int i) const { return m_xComboBox->get_text(i); }
484 void grab_focus() { m_xComboBox->grab_focus(); }
485 bool has_focus() const { return m_xComboBox->has_focus(); }
486 void connect_entry_activate(const Link<weld::ComboBox&, bool>& rLink) { m_xComboBox->connect_entry_activate(rLink); }
487 void disable_entry_completion() { m_xComboBox->set_entry_completion(false, false); }
488 void connect_get_property_tree(const Link<tools::JsonWriter&, void>& rLink) { m_xComboBox->connect_get_property_tree(rLink); }
490 private:
491 FontSizeBox(const FontSizeBox&) = delete;
492 FontSizeBox& operator=(const FontSizeBox&) = delete;
495 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */