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 .
20 #ifndef INCLUDED_SVTOOLS_CTRLBOX_HXX
21 #define INCLUDED_SVTOOLS_CTRLBOX_HXX
23 #include <svtools/svtdllapi.h>
25 #include <vcl/lstbox.hxx>
26 #include <vcl/combobox.hxx>
27 #include <vcl/image.hxx>
28 #include <vcl/virdev.hxx>
29 #include <vcl/metric.hxx>
30 #include <vcl/field.hxx>
32 #include <com/sun/star/table/BorderLineStyle.hpp>
33 #include <o3tl/typed_flags_set.hxx>
36 class ImpLineListData
;
37 enum class SvxBorderLineStyle
: sal_Int16
;
39 typedef ::std::vector
< ImpLineListData
* > ImpLineList
;
40 typedef ::std::vector
< FontMetric
> ImplFontList
;
42 /*************************************************************************
48 Allows selection of line styles and sizes. Note that before first insert,
49 units and window size need to be set. Supported units are typographic point
50 (pt) and millimeters (mm). For SourceUnit, pt, mm and twips are supported.
51 All scalar numbers in 1/100 of the corresponding unit.
53 Line1 is the outer, Line2 the inner line, Distance is the distance between
54 these two lines. If Line2 == 0, only Line1 will be shown. Defaults for
55 source and target unit are FUNIT_POINT.
57 SetColor() sets the line color.
61 Contrary to a simple ListBox, user-specific data are not supported.
62 If UpdateMode is disabled, no data should be read, no selections
63 should be set, and the return code shall be ignore, as in these are
64 not defined in this mode. Also the bit WinBit WB_SORT may not be set.
66 --------------------------------------------------------------------------
72 Allows selection of fonts. The ListBox will be filled using Fill parameter,
73 which is pointer to an FontList object.
75 Calling EnableWYSIWYG() enables rendering the font name in the currently
80 FontList; FontStyleBox; FontSizeBox; FontNameMenu
82 --------------------------------------------------------------------------
88 Allows select of FontStyle's. The parameter Fill points to a list
89 of available font styles for the font.
91 Reproduced styles are always added - this could change in future, as
92 potentially not all applications [Draw,Equation,FontWork] can properly
93 handle synthetic fonts. On filling, the previous name will be retained
96 For DontKnow, the FontStyleBox should be filled with OUString(),
97 so it will contain a list with the default attributes. The currently
98 shown style probably needs to be reset by the application.
102 FontList; FontNameBox; FontSizeBox;
104 --------------------------------------------------------------------------
110 Allows selection of font sizes. The values are retrieved via GetValue()
111 and set via SetValue(). The Fill parameter fills the ListBox with the
112 available sizes for the passed font.
114 All sizes are in 1/10 typographic point (pt).
116 The passed FontList must be retained until the next fill call.
118 Additionally it supports an relative mod, which allows entering
119 percentage values. This, eg., can be useful for template dialogs.
120 This mode can only be enabled, but not disabled again.
122 For DontKnow the FontSizeBox should be filled FontMetric(), so it will
123 contain an list with the standard sizes. Th currently shown size
124 probably needs to be reset by the application.
128 FontList; FontNameBox; FontStyleBox; FontSizeMenu
130 *************************************************************************/
133 Class computing border widths shared between Line style listbox and the
134 SvxBorderLine implementation.
136 This class doesn't know anything about units: it all depends on the different
137 values set. A border is composed of 2 lines separated by a gap. The computed
138 widths are the ones of each line and the gap and they can either be fix or vary.
140 The #m_nflags member will define which widths will vary (value 0 means that all
141 widths are fixed). The available flags are:
146 For each line, the rate member is used as a multiplication factor is the width
147 isn't fixed. Otherwise it is the width in the unit expected by the client code.
149 enum class BorderWidthImplFlags
158 template<> struct typed_flags
<BorderWidthImplFlags
> : is_typed_flags
<BorderWidthImplFlags
, 0x07> {};
160 class SVT_DLLPUBLIC BorderWidthImpl
162 BorderWidthImplFlags m_nFlags
;
169 BorderWidthImpl( BorderWidthImplFlags nFlags
= BorderWidthImplFlags::CHANGE_LINE1
, double nRate1
= 0.0,
170 double nRate2
= 0.0, double nRateGap
= 0.0 );
172 BorderWidthImpl
& operator= ( const BorderWidthImpl
& r
);
173 bool operator== ( const BorderWidthImpl
& r
) const;
175 long GetLine1 ( long nWidth
) const;
176 long GetLine2( long nWidth
) const;
177 long GetGap( long nWidth
) const;
179 long GuessWidth( long nLine1
, long nLine2
, long nGap
);
181 bool IsEmpty( ) const { return (0 == m_nRate1
) && (0 == m_nRate2
); }
182 bool IsDouble( ) const { return (0 != m_nRate1
) && (0 != m_nRate2
); }
185 inline Color
sameColor( Color rMain
)
190 inline Color
sameDistColor( Color
/*rMain*/, Color rDefault
)
195 class SVT_DLLPUBLIC LineListBox
: public ListBox
197 ImpLineList
* pLineList
;
201 ScopedVclPtr
<VirtualDevice
> aVirDev
;
206 FieldUnit eSourceUnit
;
208 SVT_DLLPRIVATE
void ImpGetLine( long nLine1
, long nLine2
, long nDistance
,
209 Color nColor1
, Color nColor2
, Color nColorDist
,
210 SvxBorderLineStyle nStyle
, Bitmap
& rBmp
);
211 using Window::ImplInit
;
212 SVT_DLLPRIVATE
void ImplInit();
213 void UpdatePaintLineColor(); // returns sal_True if maPaintCol has changed
214 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
216 void UpdateEntries( long nOldWidth
);
217 sal_Int32
GetStylePos( sal_Int32 nListPos
, long nWidth
);
220 typedef Color (*ColorFunc
)(Color
);
221 typedef Color (*ColorDistFunc
)(Color
, Color
);
223 LineListBox( vcl::Window
* pParent
, WinBits nWinStyle
= WB_BORDER
);
224 virtual ~LineListBox() override
;
225 virtual void dispose() override
;
227 /** Set the width in Twips */
228 void SetWidth( long nWidth
);
229 long GetWidth() const { return m_nWidth
; }
230 void SetNone( const OUString
& sNone
);
232 using ListBox::InsertEntry
;
233 /** Insert a listbox entry with all widths in Twips. */
234 void InsertEntry(const BorderWidthImpl
& rWidthImpl
,
235 SvxBorderLineStyle nStyle
, long nMinWidth
= 0,
236 ColorFunc pColor1Fn
= &sameColor
,
237 ColorFunc pColor2Fn
= &sameColor
,
238 ColorDistFunc pColorDistFn
= &sameDistColor
);
240 using ListBox::GetEntryPos
;
241 sal_Int32
GetEntryPos( SvxBorderLineStyle nStyle
) const;
242 SvxBorderLineStyle
GetEntryStyle( sal_Int32 nPos
) const;
244 void SelectEntry( SvxBorderLineStyle nStyle
, bool bSelect
= true );
245 SvxBorderLineStyle
GetSelectEntryStyle() const;
247 void SetUnit( FieldUnit eNewUnit
) { eUnit
= eNewUnit
; }
249 void SetSourceUnit( FieldUnit eNewUnit
) { eSourceUnit
= eNewUnit
; }
251 void SetColor( const Color
& rColor
);
252 const Color
& GetColor() const { return aColor
; }
256 inline const Color
& GetPaintColor() const;
257 Color
GetColorLine1( sal_Int32 nPos
);
258 Color
GetColorLine2( sal_Int32 nPos
);
259 Color
GetColorDist( sal_Int32 nPos
);
262 LineListBox( const LineListBox
& ) = delete;
263 LineListBox
& operator =( const LineListBox
& ) = delete;
266 inline void LineListBox::SetColor( const Color
& rColor
)
270 UpdateEntries( m_nWidth
);
273 const Color
& LineListBox::GetPaintColor() const
278 inline void LineListBox::SetWidth( long nWidth
)
280 long nOldWidth
= m_nWidth
;
282 UpdateEntries( nOldWidth
);
285 inline void LineListBox::SetNone( const OUString
& sNone
)
290 class SVT_DLLPUBLIC FontNameBox
: public ComboBox
293 ImplFontList
* mpFontList
;
295 OUString maFontMRUEntriesFile
;
297 SVT_DLLPRIVATE
void ImplCalcUserItemSize();
298 SVT_DLLPRIVATE
void ImplDestroyFontList();
301 void LoadMRUEntries( const OUString
& aFontMRUEntriesFile
);
302 void SaveMRUEntries( const OUString
& aFontMRUEntriesFile
) const;
304 FontNameBox( vcl::Window
* pParent
,
306 virtual ~FontNameBox() override
;
307 virtual void dispose() override
;
309 virtual void UserDraw( const UserDrawEvent
& rUDEvt
) override
;
311 void Fill( const FontList
* pList
);
313 void EnableWYSIWYG( bool bEnable
);
316 void InitFontMRUEntriesFile();
318 FontNameBox( const FontNameBox
& ) = delete;
319 FontNameBox
& operator =( const FontNameBox
& ) = delete;
322 class SVT_DLLPUBLIC FontStyleBox
: public ComboBox
329 using ComboBox::SetText
;
331 FontStyleBox( vcl::Window
* pParent
, WinBits nBits
);
333 virtual void Select() override
;
334 virtual void LoseFocus() override
;
335 virtual void Modify() override
;
336 virtual Size
GetOptimalSize() const override
;
338 void SetText( const OUString
& rText
) override
;
339 void Fill( const OUString
& rName
, const FontList
* pList
);
342 FontStyleBox( const FontStyleBox
& ) = delete;
343 FontStyleBox
& operator =( const FontStyleBox
& ) = delete;
346 inline void FontStyleBox::SetText( const OUString
& rText
)
349 ComboBox::SetText( rText
);
352 class SVT_DLLPUBLIC FontSizeBox
: public MetricBox
354 FontMetric aFontMetric
;
355 const FontList
* pFontList
;
362 bool bRelativeMode
:1,
367 using Window::ImplInit
;
368 SVT_DLLPRIVATE
void ImplInit();
371 virtual OUString
CreateFieldText( sal_Int64 nValue
) const override
;
374 FontSizeBox( vcl::Window
* pParent
, WinBits nWinStyle
);
376 void Reformat() override
;
377 void Modify() override
;
379 void Fill( const FontMetric
* pFontMetric
, const FontList
* pList
);
381 void EnableRelativeMode( sal_uInt16 nMin
, sal_uInt16 nMax
,
382 sal_uInt16 nStep
= 5 );
383 void EnablePtRelativeMode( short nMin
, short nMax
,
385 bool IsRelativeMode() const { return bRelativeMode
; }
386 void SetRelative( bool bRelative
);
387 bool IsRelative() const { return bRelative
; }
388 void SetPtRelative( bool bPtRel
)
389 { bPtRelative
= bPtRel
; SetRelative( true ); }
390 bool IsPtRelative() const { return bPtRelative
; }
392 virtual void SetValue( sal_Int64 nNewValue
, FieldUnit eInUnit
) override
;
393 virtual void SetValue( sal_Int64 nNewValue
) override
;
394 virtual sal_Int64
GetValue( FieldUnit eOutUnit
) const override
;
395 virtual sal_Int64
GetValue() const override
;
398 FontSizeBox( const FontSizeBox
& ) = delete;
399 FontSizeBox
& operator =( const FontSizeBox
& ) = delete;
402 #endif // INCLUDED_SVTOOLS_CTRLBOX_HXX
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */