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/.
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 .
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>
31 namespace weld
{ class CustomWeld
; }
34 class BorderWidthImpl
;
39 /** Utility class storing the border line width, style and colors. The widths
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
;
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
),
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 /*************************************************************************
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.
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 --------------------------------------------------------------------------
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
138 FontList; FontStyleBox; FontSizeBox; FontNameMenu
140 --------------------------------------------------------------------------
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
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.
160 FontList; FontNameBox; FontSizeBox;
162 --------------------------------------------------------------------------
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.
186 FontList; FontNameBox; FontStyleBox; FontSizeMenu
188 *************************************************************************/
190 inline Color
sameColor( Color rMain
)
195 inline Color
sameDistColor( Color
/*rMain*/, Color rDefault
)
202 class SVT_DLLPUBLIC SvtLineListBox final
: public WeldToolbarPopup
205 typedef Color (*ColorFunc
)(Color
);
206 typedef Color (*ColorDistFunc
)(Color
, Color
);
208 SvtLineListBox(std::unique_ptr
<weld::MenuButton
> pControl
);
211 static OUString
GetLineStyleName(SvxBorderLineStyle eStyle
);
213 /** Set the width in Twips */
214 void SetWidth(tools::Long nWidth
)
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
)
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
;
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
;
277 FieldUnit eSourceUnit
;
278 Link
<SvtLineListBox
&,void> maSelectHdl
;
281 class SVT_DLLPUBLIC SvtCalendarBox
284 SvtCalendarBox(std::unique_ptr
<weld::MenuButton
> pControl
, bool bUseLabel
= true);
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
); }
307 DECL_DLLPRIVATE_LINK(SelectHdl
, weld::Calendar
&, void);
308 DECL_DLLPRIVATE_LINK(ActivateHdl
, weld::Calendar
&, void);
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
326 std::unique_ptr
<weld::ComboBox
> m_xComboBox
;
327 std::unique_ptr
<ImplFontList
> mpFontList
;
328 size_t mnPreviewProgress
;
330 OUString maFontMRUEntriesFile
;
332 Link
<const FontMetric
&, void> m_aLivePreviewHdl
;
334 SVT_DLLPRIVATE
void ImplDestroyFontList();
336 DECL_DLLPRIVATE_LINK(CustomRenderHdl
, weld::ComboBox::render_args
, void);
337 DECL_DLLPRIVATE_LINK(CustomGetSizeHdl
, OutputDevice
&, Size
);
338 DECL_DLLPRIVATE_LINK(SettingsChangedHdl
, VclSimpleEvent
&, void);
339 DECL_DLLPRIVATE_LINK(UpdateHdl
, Timer
*, void);
341 void LoadMRUEntries( const OUString
& aFontMRUEntriesFile
);
342 void SaveMRUEntries( const OUString
& aFontMRUEntriesFile
) const;
344 OutputDevice
& CachePreview(size_t nIndex
, Point
* pTopLeft
,
345 sal_Int32 nDPIX
= 96, sal_Int32 nDPIY
= 96);
348 FontNameBox(std::unique_ptr
<weld::ComboBox
> p
);
351 void Fill( const FontList
* pList
);
353 void EnableWYSIWYG(bool bEnable
);
354 bool IsWYSIWYGEnabled() const { return mbWYSIWYG
; }
356 void connect_changed(const Link
<weld::ComboBox
&, void>& rLink
) { m_xComboBox
->connect_changed(rLink
); }
357 void connect_focus_in(const Link
<weld::Widget
&, void>& rLink
) { m_xComboBox
->connect_focus_in(rLink
); }
358 void connect_focus_out(const Link
<weld::Widget
&, void>& rLink
) { m_xComboBox
->connect_focus_out(rLink
); }
359 void connect_key_press(const Link
<const KeyEvent
&, bool>& rLink
) { m_xComboBox
->connect_key_press(rLink
); }
360 void connect_popup_toggled(const Link
<weld::ComboBox
&, void>& rLink
){ m_xComboBox
->connect_popup_toggled(rLink
); }
361 void connect_live_preview(const Link
<const FontMetric
&, void>& rLink
) { m_aLivePreviewHdl
= rLink
; }
362 int get_active() const { return m_xComboBox
->get_active(); }
363 OUString
get_active_text() const { return m_xComboBox
->get_active_text(); }
364 void set_active_or_entry_text(const OUString
& rText
);
365 void set_active(int nPos
) { m_xComboBox
->set_active(nPos
); }
366 int get_count() const { return m_xComboBox
->get_count(); }
367 OUString
get_text(int nIndex
) const { return m_xComboBox
->get_text(nIndex
); }
368 void set_sensitive(bool bSensitive
) { m_xComboBox
->set_sensitive(bSensitive
); }
369 void save_value() { m_xComboBox
->save_value(); }
370 OUString
const& get_saved_value() const { return m_xComboBox
->get_saved_value(); }
371 void select_entry_region(int nStartPos
, int nEndPos
) { m_xComboBox
->select_entry_region(nStartPos
, nEndPos
); }
372 bool get_entry_selection_bounds(int& rStartPos
, int& rEndPos
) { return m_xComboBox
->get_entry_selection_bounds(rStartPos
, rEndPos
); }
373 void clear() { m_xComboBox
->clear(); }
374 void grab_focus() { m_xComboBox
->grab_focus(); }
375 bool has_focus() const { return m_xComboBox
->has_focus(); }
376 void connect_entry_activate(const Link
<weld::ComboBox
&, bool>& rLink
) { m_xComboBox
->connect_entry_activate(rLink
); }
377 void connect_get_property_tree(const Link
<tools::JsonWriter
&, void>& rLink
) { m_xComboBox
->connect_get_property_tree(rLink
); }
378 void set_entry_width_chars(int nWidth
) { m_xComboBox
->set_entry_width_chars(nWidth
); }
379 void set_size_request(int nWidth
, int nHeight
) { m_xComboBox
->set_size_request(nWidth
, nHeight
); }
380 int get_max_mru_count() const { return m_xComboBox
->get_max_mru_count(); }
381 void set_max_mru_count(int nCount
) { m_xComboBox
->set_max_mru_count(nCount
); }
383 // font size is in points, not pixels, e.g. see Window::[G]etPointFont
384 void set_entry_font(const vcl::Font
& rFont
) { m_xComboBox
->set_entry_font(rFont
); }
385 vcl::Font
get_entry_font() { return m_xComboBox
->get_entry_font(); }
387 void set_tooltip_text(const OUString
& rTip
) { m_xComboBox
->set_tooltip_text(rTip
); }
390 void InitFontMRUEntriesFile();
392 FontNameBox( const FontNameBox
& ) = delete;
393 FontNameBox
& operator =( const FontNameBox
& ) = delete;
396 class SVT_DLLPUBLIC FontStyleBox
398 std::unique_ptr
<weld::ComboBox
> m_xComboBox
;
400 FontStyleBox(std::unique_ptr
<weld::ComboBox
> p
);
402 void Fill(std::u16string_view rName
, const FontList
* pList
);
404 void connect_changed(const Link
<weld::ComboBox
&, void>& rLink
) { m_xComboBox
->connect_changed(rLink
); }
405 OUString
get_active_text() const { return m_xComboBox
->get_active_text(); }
406 void set_active_text(const OUString
& rText
) { m_xComboBox
->set_active_text(rText
); }
407 void set_size_request(int nWidth
, int nHeight
) { m_xComboBox
->set_size_request(nWidth
, nHeight
); }
409 void append_text(const OUString
& rStr
) { m_xComboBox
->append_text(rStr
); }
410 void set_sensitive(bool bSensitive
) { m_xComboBox
->set_sensitive(bSensitive
); }
411 void save_value() { m_xComboBox
->save_value(); }
412 OUString
const& get_saved_value() const { return m_xComboBox
->get_saved_value(); }
413 int get_count() const { return m_xComboBox
->get_count(); }
414 int find_text(const OUString
& rStr
) const { return m_xComboBox
->find_text(rStr
); }
416 FontStyleBox(const FontStyleBox
& ) = delete;
417 FontStyleBox
& operator=(const FontStyleBox
&) = delete;
420 class SVT_DLLPUBLIC FontSizeBox
422 const FontList
* pFontList
;
427 sal_uInt16 nDecimalDigits
;
434 bool bRelativeMode
:1,
438 Link
<weld::ComboBox
&, void> m_aChangeHdl
;
439 Link
<weld::Widget
&, void> m_aFocusOutHdl
;
440 std::unique_ptr
<weld::ComboBox
> m_xComboBox
;
442 sal_uInt16
GetDecimalDigits() const { return nDecimalDigits
; }
443 void SetDecimalDigits(sal_uInt16 nDigits
) { nDecimalDigits
= nDigits
; }
444 FieldUnit
GetUnit() const { return eUnit
; }
445 void SetUnit(FieldUnit _eUnit
) { eUnit
= _eUnit
; }
446 void SetRange(int nNewMin
, int nNewMax
) { nMin
= nNewMin
; nMax
= nNewMax
; }
447 void SetValue(int nNewValue
, FieldUnit eInUnit
);
449 void InsertValue(int i
);
451 OUString
format_number(int nValue
) const;
453 DECL_DLLPRIVATE_LINK(ModifyHdl
, weld::ComboBox
&, void);
454 DECL_DLLPRIVATE_LINK(ReformatHdl
, weld::Widget
&, void);
456 FontSizeBox(std::unique_ptr
<weld::ComboBox
> p
);
458 void Fill(const FontList
* pList
);
460 void EnableRelativeMode(sal_uInt16 nMin
, sal_uInt16 nMax
, sal_uInt16 nStep
= 5);
461 void EnablePtRelativeMode(short nMin
, short nMax
, short nStep
= 10);
462 bool IsRelativeMode() const { return bRelativeMode
; }
463 void SetRelative( bool bRelative
);
464 bool IsRelative() const { return bRelative
; }
465 void SetPtRelative( bool bPtRel
)
467 bPtRelative
= bPtRel
;
470 bool IsPtRelative() const { return bPtRelative
; }
472 void connect_changed(const Link
<weld::ComboBox
&, void>& rLink
) { m_aChangeHdl
= rLink
; }
473 void connect_focus_out(const Link
<weld::Widget
&, void>& rLink
) { m_aFocusOutHdl
= rLink
; }
474 void connect_key_press(const Link
<const KeyEvent
&, bool>& rLink
) { m_xComboBox
->connect_key_press(rLink
); }
475 OUString
get_active_text() const { return m_xComboBox
->get_active_text(); }
476 void set_active_or_entry_text(const OUString
& rText
);
477 void set_sensitive(bool bSensitive
) { m_xComboBox
->set_sensitive(bSensitive
); }
478 void set_size_request(int nWidth
, int nHeight
) { m_xComboBox
->set_size_request(nWidth
, nHeight
); }
480 int get_active() const { return m_xComboBox
->get_active(); }
481 int get_value() const;
482 void set_value(int nValue
);
483 void save_value() { nSavedValue
= get_value(); }
484 int get_saved_value() const { return nSavedValue
; }
485 bool get_value_changed_from_saved() const { return get_value() != get_saved_value(); }
486 int get_count() const { return m_xComboBox
->get_count(); }
487 OUString
get_text(int i
) const { return m_xComboBox
->get_text(i
); }
488 void grab_focus() { m_xComboBox
->grab_focus(); }
489 bool has_focus() const { return m_xComboBox
->has_focus(); }
490 void connect_entry_activate(const Link
<weld::ComboBox
&, bool>& rLink
) { m_xComboBox
->connect_entry_activate(rLink
); }
491 void disable_entry_completion() { m_xComboBox
->set_entry_completion(false, false); }
492 void connect_get_property_tree(const Link
<tools::JsonWriter
&, void>& rLink
) { m_xComboBox
->connect_get_property_tree(rLink
); }
495 FontSizeBox(const FontSizeBox
&) = delete;
496 FontSizeBox
& operator=(const FontSizeBox
&) = delete;
499 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */