bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / svtools / ctrlbox.hxx
blobb11dc4cbff6047af4a13cb50ae5fd40feb902298
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 #ifndef INCLUDED_SVTOOLS_CTRLBOX_HXX
21 #define INCLUDED_SVTOOLS_CTRLBOX_HXX
23 #include <svtools/svtdllapi.h>
25 #include <editeng/borderline.hxx>
27 #include <vcl/lstbox.hxx>
28 #include <vcl/combobox.hxx>
29 #include <vcl/metric.hxx>
30 #include <vcl/field.hxx>
31 #include <vcl/weld.hxx>
33 #include <memory>
35 namespace weld { class CustomWeld; }
37 class VirtualDevice;
38 class BorderWidthImpl;
39 class FontList;
41 /** Utility class storing the border line width, style and colors. The widths
42 are defined in Twips.
44 class ImpLineListData
46 private:
47 BorderWidthImpl const m_aWidthImpl;
49 Color ( * const m_pColor1Fn )( Color );
50 Color ( * const m_pColor2Fn )( Color );
51 Color ( * const m_pColorDistFn )( Color, Color );
53 long const m_nMinWidth;
54 SvxBorderLineStyle const m_nStyle;
56 public:
57 ImpLineListData( BorderWidthImpl aWidthImpl,
58 SvxBorderLineStyle nStyle, long nMinWidth, Color ( *pColor1Fn )( Color ),
59 Color ( *pColor2Fn )( Color ), Color ( *pColorDistFn )( Color, Color ) ) :
60 m_aWidthImpl( aWidthImpl ),
61 m_pColor1Fn( pColor1Fn ),
62 m_pColor2Fn( pColor2Fn ),
63 m_pColorDistFn( pColorDistFn ),
64 m_nMinWidth( nMinWidth ),
65 m_nStyle( nStyle )
69 /** Returns the computed width of the line 1 in twips. */
70 long GetLine1ForWidth( long nWidth ) { return m_aWidthImpl.GetLine1( nWidth ); }
72 /** Returns the computed width of the line 2 in twips. */
73 long GetLine2ForWidth( long nWidth ) { return m_aWidthImpl.GetLine2( nWidth ); }
75 /** Returns the computed width of the gap in twips. */
76 long GetDistForWidth( long nWidth ) { return m_aWidthImpl.GetGap( nWidth ); }
78 Color GetColorLine1( const Color& rMain )
80 return ( *m_pColor1Fn )( rMain );
83 Color GetColorLine2( const Color& rMain )
85 return ( *m_pColor2Fn )( rMain );
88 Color GetColorDist( const Color& rMain, const Color& rDefault )
90 return ( *m_pColorDistFn )( rMain, rDefault );
93 /** Returns the minimum width in twips */
94 long GetMinWidth( ) { return m_nMinWidth;}
95 SvxBorderLineStyle GetStyle( ) { return m_nStyle;}
98 enum class SvxBorderLineStyle : sal_Int16;
100 typedef ::std::vector< FontMetric > ImplFontList;
102 /*************************************************************************
104 class LineListBox
106 Description
108 Allows selection of line styles and sizes. Note that before first insert,
109 units and window size need to be set. Supported units are typographic point
110 (pt) and millimeters (mm). For SourceUnit, pt, mm and twips are supported.
111 All scalar numbers in 1/100 of the corresponding unit.
113 Line1 is the outer, Line2 the inner line, Distance is the distance between
114 these two lines. If Line2 == 0, only Line1 will be shown. Defaults for
115 source and target unit are FieldUnit::POINT.
117 SetColor() sets the line color.
119 Remarks
121 Contrary to a simple ListBox, user-specific data are not supported.
122 If UpdateMode is disabled, no data should be read, no selections
123 should be set, and the return code shall be ignore, as in these are
124 not defined in this mode. Also the bit WinBit WB_SORT may not be set.
126 --------------------------------------------------------------------------
128 class FontNameBox
130 Description
132 Allows selection of fonts. The ListBox will be filled using Fill parameter,
133 which is pointer to an FontList object.
135 Calling EnableWYSIWYG() enables rendering the font name in the currently
136 selected font.
138 See also
140 FontList; FontStyleBox; FontSizeBox; FontNameMenu
142 --------------------------------------------------------------------------
144 class FontStyleBox
146 Description
148 Allows select of FontStyle's. The parameter Fill points to a list
149 of available font styles for the font.
151 Reproduced styles are always added - this could change in future, as
152 potentially not all applications [Draw,Equation,FontWork] can properly
153 handle synthetic fonts. On filling, the previous name will be retained
154 if possible.
156 For DontKnow, the FontStyleBox should be filled with OUString(),
157 so it will contain a list with the default attributes. The currently
158 shown style probably needs to be reset by the application.
160 See also
162 FontList; FontNameBox; FontSizeBox;
164 --------------------------------------------------------------------------
166 class FontSizeBox
168 Description
170 Allows selection of font sizes. The values are retrieved via GetValue()
171 and set via SetValue(). The Fill parameter fills the ListBox with the
172 available sizes for the passed font.
174 All sizes are in 1/10 typographic point (pt).
176 The passed FontList must be retained until the next fill call.
178 Additionally it supports an relative mod, which allows entering
179 percentage values. This, eg., can be useful for template dialogs.
180 This mode can only be enabled, but not disabled again.
182 For DontKnow the FontSizeBox should be filled FontMetric(), so it will
183 contain an list with the standard sizes. Th currently shown size
184 probably needs to be reset by the application.
186 See also
188 FontList; FontNameBox; FontStyleBox; FontSizeMenu
190 *************************************************************************/
192 inline Color sameColor( Color rMain )
194 return rMain;
197 inline Color sameDistColor( Color /*rMain*/, Color rDefault )
199 return rDefault;
202 class SvtValueSet;
204 class SVT_DLLPUBLIC SvtLineListBox
206 public:
207 typedef Color (*ColorFunc)(Color);
208 typedef Color (*ColorDistFunc)(Color, Color);
210 SvtLineListBox(std::unique_ptr<weld::MenuButton> pControl);
211 ~SvtLineListBox();
213 /** Set the width in Twips */
214 void SetWidth(long nWidth)
216 m_nWidth = nWidth;
217 UpdateEntries();
218 UpdatePreview();
221 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, 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 private:
250 SVT_DLLPRIVATE void ImpGetLine( long nLine1, long nLine2, long nDistance,
251 Color nColor1, Color nColor2, Color nColorDist,
252 SvxBorderLineStyle nStyle, BitmapEx& rBmp );
254 void UpdatePaintLineColor(); // returns sal_True if maPaintCol has changed
255 DECL_LINK(StyleUpdated, weld::Widget&, void);
256 DECL_LINK(ValueSelectHdl, SvtValueSet*, void);
257 DECL_LINK(FocusHdl, weld::Widget&, void);
258 DECL_LINK(NoneHdl, weld::Button&, void);
260 void UpdateEntries();
261 sal_Int32 GetStylePos(sal_Int32 nListPos);
263 const Color& GetPaintColor() const
265 return maPaintCol;
267 Color GetColorLine1( sal_Int32 nPos );
268 Color GetColorLine2( sal_Int32 nPos );
269 Color GetColorDist( sal_Int32 nPos );
271 void UpdatePreview();
273 SvtLineListBox( const SvtLineListBox& ) = delete;
274 SvtLineListBox& operator =( const SvtLineListBox& ) = delete;
276 std::unique_ptr<weld::MenuButton> m_xControl;
277 std::unique_ptr<weld::Builder> m_xBuilder;
278 std::unique_ptr<weld::Widget> m_xTopLevel;
279 std::unique_ptr<weld::Button> m_xNoneButton;
280 std::unique_ptr<SvtValueSet> m_xLineSet;
281 std::unique_ptr<weld::CustomWeld> m_xLineSetWin;
283 std::vector<std::unique_ptr<ImpLineListData>> m_vLineList;
284 long m_nWidth;
285 ScopedVclPtr<VirtualDevice> aVirDev;
286 Color aColor;
287 Color maPaintCol;
288 FieldUnit eSourceUnit;
289 Link<SvtLineListBox&,void> maSelectHdl;
292 class SVT_DLLPUBLIC SvtCalendarBox
294 public:
295 SvtCalendarBox(std::unique_ptr<weld::MenuButton> pControl);
296 ~SvtCalendarBox();
298 weld::MenuButton& get_button() { return *m_xControl; }
300 void set_date(const Date& rDate);
301 Date get_date() const { return m_xCalendar->get_date(); }
303 void set_label(const OUString& rLabel) { m_xControl->set_label(rLabel); }
304 OUString get_label() const { return m_xControl->get_label(); }
306 void set_sensitive(bool bSensitive) { m_xControl->set_sensitive(bSensitive); }
307 bool get_sensitive() const { return m_xControl->get_sensitive(); }
308 void set_visible(bool bSensitive) { m_xControl->set_visible(bSensitive); }
309 void show() { set_visible(true); }
310 void grab_focus() { m_xControl->grab_focus(); }
312 void connect_activated(const Link<SvtCalendarBox&, void>& rActivatedHdl) { m_aActivatedHdl = rActivatedHdl; }
313 private:
314 DECL_LINK(SelectHdl, weld::Calendar&, void);
315 DECL_LINK(ActivateHdl, weld::Calendar&, void);
317 std::unique_ptr<weld::MenuButton> m_xControl;
318 std::unique_ptr<weld::Builder> m_xBuilder;
319 std::unique_ptr<weld::Widget> m_xTopLevel;
320 std::unique_ptr<weld::Calendar> m_xCalendar;
322 Link<SvtCalendarBox&, void> m_aActivatedHdl;
324 void set_label_from_date();
327 class SVT_DLLPUBLIC FontNameBox : public ComboBox
329 private:
330 std::unique_ptr<ImplFontList> mpFontList;
331 bool mbWYSIWYG;
332 OUString maFontMRUEntriesFile;
334 SVT_DLLPRIVATE void ImplCalcUserItemSize();
335 SVT_DLLPRIVATE void ImplDestroyFontList();
337 protected:
338 void LoadMRUEntries( const OUString& aFontMRUEntriesFile );
339 void SaveMRUEntries( const OUString& aFontMRUEntriesFile ) const;
340 public:
341 FontNameBox( vcl::Window* pParent,
342 WinBits nWinStyle );
343 virtual ~FontNameBox() override;
344 virtual void dispose() override;
346 virtual void UserDraw( const UserDrawEvent& rUDEvt ) override;
348 void Fill( const FontList* pList );
350 void EnableWYSIWYG( bool bEnable );
352 private:
353 void InitFontMRUEntriesFile();
355 FontNameBox( const FontNameBox& ) = delete;
356 FontNameBox& operator =( const FontNameBox& ) = delete;
359 class SVT_DLLPUBLIC FontStyleBox : public ComboBox
361 Size aOptimalSize;
363 public:
364 FontStyleBox( vcl::Window* pParent, WinBits nBits );
366 virtual void Modify() override;
367 virtual Size GetOptimalSize() const override;
369 private:
370 FontStyleBox( const FontStyleBox& ) = delete;
371 FontStyleBox& operator =( const FontStyleBox& ) = delete;
374 class SVT_DLLPUBLIC SvtFontStyleBox
376 std::unique_ptr<weld::ComboBox> m_xComboBox;
377 public:
378 SvtFontStyleBox(std::unique_ptr<weld::ComboBox> p);
380 void Fill(const OUString& rName, const FontList* pList);
382 void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_xComboBox->connect_changed(rLink); }
383 OUString get_active_text() const { return m_xComboBox->get_active_text(); }
384 void set_active_text(const OUString& rText) { m_xComboBox->set_active_text(rText); }
385 void append_text(const OUString& rStr) { m_xComboBox->append_text(rStr); }
386 void set_sensitive(bool bSensitive) { m_xComboBox->set_sensitive(bSensitive); }
387 void save_value() { m_xComboBox->save_value(); }
388 OUString const& get_saved_value() const { return m_xComboBox->get_saved_value(); }
389 int get_count() const { return m_xComboBox->get_count(); }
390 int find_text(const OUString& rStr) const { return m_xComboBox->find_text(rStr); }
391 private:
392 SvtFontStyleBox(const SvtFontStyleBox& ) = delete;
393 SvtFontStyleBox& operator=(const SvtFontStyleBox&) = delete;
396 class SVT_DLLPUBLIC FontSizeBox : public MetricBox
398 bool bStdSize:1;
400 using Window::ImplInit;
401 SVT_DLLPRIVATE void ImplInit();
403 protected:
404 virtual sal_Int64 GetValueFromStringUnit(const OUString& rStr, FieldUnit eOutUnit) const override;
406 public:
407 FontSizeBox( vcl::Window* pParent, WinBits nWinStyle );
409 void Reformat() override;
411 void Fill( const FontMetric* pFontMetric, const FontList* pList );
413 virtual void SetValue( sal_Int64 nNewValue, FieldUnit eInUnit ) override;
414 virtual void SetValue( sal_Int64 nNewValue ) override;
416 private:
417 FontSizeBox( const FontSizeBox& ) = delete;
418 FontSizeBox& operator =( const FontSizeBox& ) = delete;
421 class SVT_DLLPUBLIC SvtFontSizeBox
423 FontMetric aFontMetric;
424 const FontList* pFontList;
425 int nSavedValue;
426 int nMin;
427 int nMax;
428 FieldUnit eUnit;
429 sal_uInt16 nDecimalDigits;
430 sal_uInt16 nRelMin;
431 sal_uInt16 nRelMax;
432 sal_uInt16 nRelStep;
433 short nPtRelMin;
434 short nPtRelMax;
435 short nPtRelStep;
436 bool bRelativeMode:1,
437 bRelative:1,
438 bPtRelative:1,
439 bStdSize:1;
440 Link<weld::ComboBox&, void> m_aChangeHdl;
441 std::unique_ptr<weld::ComboBox> m_xComboBox;
443 sal_uInt16 GetDecimalDigits() const { return nDecimalDigits; }
444 void SetDecimalDigits(sal_uInt16 nDigits) { nDecimalDigits = nDigits; }
445 FieldUnit GetUnit() const { return eUnit; }
446 void SetUnit(FieldUnit _eUnit) { eUnit = _eUnit; }
447 void SetRange(int nNewMin, int nNewMax) { nMin = nNewMin; nMax = nNewMax; }
448 void SetValue(int nNewValue, FieldUnit eInUnit);
450 void InsertValue(int i);
452 OUString format_number(int nValue) const;
454 DECL_LINK(ModifyHdl, weld::ComboBox&, void);
455 DECL_LINK(ReformatHdl, weld::Widget&, void);
456 public:
457 SvtFontSizeBox(std::unique_ptr<weld::ComboBox> p);
459 void Fill(const FontMetric* pFontMetric, const FontList* pList);
461 void EnableRelativeMode(sal_uInt16 nMin, sal_uInt16 nMax, sal_uInt16 nStep = 5);
462 void EnablePtRelativeMode(short nMin, short nMax, short nStep = 10);
463 bool IsRelativeMode() const { return bRelativeMode; }
464 void SetRelative( bool bRelative );
465 bool IsRelative() const { return bRelative; }
466 void SetPtRelative( bool bPtRel )
468 bPtRelative = bPtRel;
469 SetRelative(true);
471 bool IsPtRelative() const { return bPtRelative; }
473 void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_aChangeHdl = rLink; }
474 OUString get_active_text() const { return m_xComboBox->get_active_text(); }
475 void set_active_text(const OUString& rText) { m_xComboBox->set_active_text(rText); }
476 void set_sensitive(bool bSensitive) { m_xComboBox->set_sensitive(bSensitive); }
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; }
482 private:
483 SvtFontSizeBox(const SvtFontSizeBox&) = delete;
484 SvtFontSizeBox& operator=(const SvtFontSizeBox&) = delete;
488 #endif // INCLUDED_SVTOOLS_CTRLBOX_HXX
490 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */