Branch libreoffice-5-0-4
[LibreOffice.git] / include / svtools / ctrlbox.hxx
bloba38f00940fb28484a5aa43ccdc1c9b70e0309789
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 <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>
35 class FontList;
36 class ImplColorListData;
37 class ImpLineListData;
39 typedef ::std::vector< ImplColorListData* > ImpColorList;
40 typedef ::std::vector< ImpLineListData* > ImpLineList;
41 typedef ::std::vector< vcl::FontInfo > ImplFontList;
43 /*************************************************************************
45 Description
46 ============
48 class ColorListBox
50 Description
52 Allows color selection
54 --------------------------------------------------------------------------
56 class LineListBox
58 Description
60 Allows selection of line styles and sizes. Not that before first insert,
61 units and window size need to be set. Supported units are typographic point
62 (pt) and millimeters (mm). For SourceUnit, pt, mm and twips are supported.
63 All scalar numbers in 1/100 of the corresponding unit.
65 Line1 is the outer, Line2 the inner line, Distance is the distance between
66 these two lines. If Line2 == 0, only Line1 will be shown. Defaults for
67 source and target unit are FUNIT_POINT.
69 SetColor() sets the line color.
71 Remarks
73 Contrary to a simple ListBox, user-specific data are not supported.
74 If UpdateMode is disabled, no data should be read, no selections
75 should be set, and the return code shall be ignore, as in these are
76 not defined in this mode. Also the bit WinBit WB_SORT may not be set.
78 --------------------------------------------------------------------------
80 class FontNameBox
82 Description
84 Allows selection of fonts. The ListBox will be filled using Fill parameter,
85 which is pointer to an FontList object.
87 Calling EnableWYSIWYG() enables rendering the font name in the currently
88 selected font.
90 See also
92 FontList; FontStyleBox; FontSizeBox; FontNameMenu
94 --------------------------------------------------------------------------
96 class FontStyleBox
98 Description
100 Allows select of FontStyle's. The parameter Fill points to a list
101 of available font styles for the font.
103 Reproduced styles are always added - this could change in future, as
104 potentially not all applications [Draw,Equation,FontWork] can properly
105 handle synthetic fonts. On filling, the previous name will be retained
106 if possible.
108 For DontKnow, the FontStyleBox should be filled with OUString(),
109 so it will contain a list with the default attributes. The currently
110 shown style probably needs to be reset by the application.
112 See also
114 FontList; FontNameBox; FontSizeBox;
116 --------------------------------------------------------------------------
118 class FontSizeBox
120 Description
122 Allows selection of font sizes. The values are retrieved via GetValue()
123 and set via SetValue(). The Fill parameter fills the ListBox with the
124 available sizes for the passed font.
126 All sizes are in 1/10 typographic point (pt).
128 The passed FontList must be retained until the next fill call.
130 Additionally it supports an relative mod, which allows entering
131 percentage values. This, eg., can be useful for template dialogs.
132 This mode can only be enabled, but not disabled again.
134 For DontKnow the FontSizeBox should be filled FontInfo(), so it will
135 contain an list with the standard sizes. Th currently shown size
136 probably needs to be reset by the application.
138 See also
140 FontList; FontNameBox; FontStyleBox; FontSizeMenu
142 *************************************************************************/
144 class SVT_DLLPUBLIC ColorListBox : public ListBox
146 ImpColorList* pColorList; // separate liste, in case of user data are required from outside
147 Size aImageSize;
149 using Window::ImplInit;
150 SVT_DLLPRIVATE void ImplInit();
151 SVT_DLLPRIVATE void ImplDestroyColorEntries();
153 public:
154 ColorListBox( vcl::Window* pParent,
155 WinBits nWinStyle = WB_BORDER );
156 ColorListBox( vcl::Window* pParent, const ResId& rResId );
157 virtual ~ColorListBox();
158 virtual void dispose() SAL_OVERRIDE;
160 virtual void UserDraw( const UserDrawEvent& rUDEvt ) SAL_OVERRIDE;
162 using ListBox::InsertEntry;
163 sal_Int32 InsertEntry( const OUString& rStr,
164 sal_Int32 nPos = LISTBOX_APPEND );
165 sal_Int32 InsertEntry( const Color& rColor, const OUString& rStr,
166 sal_Int32 nPos = LISTBOX_APPEND );
167 void InsertAutomaticEntryColor(const Color &rAutoColorValue);
168 bool IsAutomaticSelected() { return !GetSelectEntryPos(); }
169 using ListBox::RemoveEntry;
170 void RemoveEntry( sal_Int32 nPos );
171 void Clear();
172 void CopyEntries( const ColorListBox& rBox );
174 using ListBox::GetEntryPos;
175 sal_Int32 GetEntryPos( const Color& rColor ) const;
176 Color GetEntryColor( sal_Int32 nPos ) const;
177 Size GetImageSize() const { return aImageSize; }
179 void SelectEntry( const OUString& rStr, bool bSelect = true )
180 { ListBox::SelectEntry( rStr, bSelect ); }
181 void SelectEntry( const Color& rColor, bool bSelect = true );
182 Color GetSelectEntryColor( sal_Int32 nSelIndex = 0 ) const;
183 bool IsEntrySelected(const OUString& rStr ) const
185 return ListBox::IsEntrySelected(rStr);
188 bool IsEntrySelected(const Color& rColor) const
190 sal_Int32 nPos = GetEntryPos( rColor );
191 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
192 return IsEntryPosSelected( nPos );
193 else
194 return false;
197 private:
198 ColorListBox( const ColorListBox& ) SAL_DELETED_FUNCTION;
199 ColorListBox& operator =( const ColorListBox& ) SAL_DELETED_FUNCTION;
201 void SetEntryData( sal_Int32 nPos, void* pNewData );
202 void* GetEntryData( sal_Int32 nPos ) const;
205 inline void ColorListBox::SelectEntry( const Color& rColor, bool bSelect )
207 sal_Int32 nPos = GetEntryPos( rColor );
208 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
209 ListBox::SelectEntryPos( nPos, bSelect );
212 inline Color ColorListBox::GetSelectEntryColor( sal_Int32 nSelIndex ) const
214 sal_Int32 nPos = GetSelectEntryPos( nSelIndex );
215 Color aColor;
216 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
217 aColor = GetEntryColor( nPos );
218 return aColor;
222 Class computing border widths shared between Line style listbox and the
223 SvxBorderLine implementation.
225 This class doesn't know anything about units: it all depends on the different
226 values set. A border is composed of 2 lines separated by a gap. The computed
227 widths are the ones of each line and the gap and they can either be fix or vary.
229 The #m_nflags member will define which widths will vary (value 0 means that all
230 widths are fixed). The available flags are:
231 - CHANGE_LINE1
232 - CHANGE_LINE2
233 - CHANGE_DIST
235 For each line, the rate member is used as a multiplication factor is the width
236 isn't fixed. Otherwise it is the width in the unit expected by the client code.
238 enum class BorderWidthImplFlags
240 FIXED = 0,
241 CHANGE_LINE1 = 1,
242 CHANGE_LINE2 = 2,
243 CHANGE_DIST = 4,
244 ADAPT_DIST = 8,
246 namespace o3tl
248 template<> struct typed_flags<BorderWidthImplFlags> : is_typed_flags<BorderWidthImplFlags, 0x0f> {};
250 class SVT_DLLPUBLIC BorderWidthImpl
252 BorderWidthImplFlags m_nFlags;
253 double m_nRate1;
254 double m_nRate2;
255 double m_nRateGap;
257 public:
259 BorderWidthImpl( BorderWidthImplFlags nFlags = BorderWidthImplFlags::CHANGE_LINE1, double nRate1 = 0.0,
260 double nRate2 = 0.0, double nRateGap = 0.0 );
262 BorderWidthImpl& operator= ( const BorderWidthImpl& r );
263 bool operator== ( const BorderWidthImpl& r ) const;
265 long GetLine1 ( long nWidth ) const;
266 long GetLine2( long nWidth ) const;
267 long GetGap( long nWidth ) const;
269 long GuessWidth( long nLine1, long nLine2, long nGap );
271 bool IsEmpty( ) const { return (0 == m_nRate1) && (0 == m_nRate2); }
272 bool IsDouble( ) const { return (0 != m_nRate1) && (0 != m_nRate2); }
275 inline Color sameColor( Color rMain )
277 return rMain;
280 inline Color sameDistColor( Color /*rMain*/, Color rDefault )
282 return rDefault;
285 class SVT_DLLPUBLIC LineListBox : public ListBox
287 ImpLineList* pLineList;
288 long m_nWidth;
289 OUString m_sNone;
291 ScopedVclPtr<VirtualDevice> aVirDev;
292 Size aTxtSize;
293 Color aColor;
294 Color maPaintCol;
295 FieldUnit eUnit;
296 FieldUnit eSourceUnit;
298 SVT_DLLPRIVATE void ImpGetLine( long nLine1, long nLine2, long nDistance,
299 Color nColor1, Color nColor2, Color nColorDist,
300 sal_uInt16 nStyle, Bitmap& rBmp );
301 using Window::ImplInit;
302 SVT_DLLPRIVATE void ImplInit();
303 bool UpdatePaintLineColor(); // returns sal_True if maPaintCol has changed
304 virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
306 void UpdateEntries( long nOldWidth );
307 sal_Int32 GetStylePos( sal_Int32 nListPos, long nWidth );
309 public:
310 typedef Color (*ColorFunc)(Color);
311 typedef Color (*ColorDistFunc)(Color, Color);
313 LineListBox( vcl::Window* pParent, WinBits nWinStyle = WB_BORDER );
314 virtual ~LineListBox();
315 virtual void dispose() SAL_OVERRIDE;
317 /** Set the width in Twips */
318 void SetWidth( long nWidth );
319 long GetWidth() const { return m_nWidth; }
320 void SetNone( const OUString& sNone );
322 using ListBox::InsertEntry;
323 /** Insert a listbox entry with all widths in Twips. */
324 void InsertEntry(const BorderWidthImpl& rWidthImpl,
325 sal_uInt16 nStyle, long nMinWidth = 0,
326 ColorFunc pColor1Fn = &sameColor,
327 ColorFunc pColor2Fn = &sameColor,
328 ColorDistFunc pColorDistFn = &sameDistColor);
330 using ListBox::GetEntryPos;
331 sal_Int32 GetEntryPos( sal_uInt16 nStyle = com::sun::star::table::BorderLineStyle::SOLID ) const;
332 sal_uInt16 GetEntryStyle( sal_Int32 nPos ) const;
334 void SelectEntry( const OUString& rStr, bool bSelect = true ) { ListBox::SelectEntry( rStr, bSelect ); }
335 void SelectEntry( sal_uInt16 nStyle = com::sun::star::table::BorderLineStyle::SOLID, bool bSelect = true );
336 sal_uInt16 GetSelectEntryStyle( sal_Int32 nSelIndex = 0 ) const;
337 bool IsEntrySelected(const OUString& rStr) const
339 return ListBox::IsEntrySelected(rStr);
341 bool IsEntrySelected( sal_uInt16 nStyle = com::sun::star::table::BorderLineStyle::SOLID ) const
343 sal_Int32 nPos = GetEntryPos( nStyle );
344 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
345 return IsEntryPosSelected( nPos );
346 else
347 return false;
350 inline void SetUnit( FieldUnit eNewUnit ) { eUnit = eNewUnit; }
351 inline FieldUnit GetUnit() const { return eUnit; }
352 inline void SetSourceUnit( FieldUnit eNewUnit ) { eSourceUnit = eNewUnit; }
353 inline FieldUnit GetSourceUnit() const { return eSourceUnit; }
355 void SetColor( const Color& rColor );
356 Color GetColor() const { return aColor; }
358 protected:
360 inline const Color& GetPaintColor() const;
361 Color GetColorLine1( sal_Int32 nPos = 0 );
362 Color GetColorLine2( sal_Int32 nPos = 0 );
363 Color GetColorDist( sal_Int32 nPos = 0 );
365 private:
366 LineListBox( const LineListBox& ) SAL_DELETED_FUNCTION;
367 LineListBox& operator =( const LineListBox& ) SAL_DELETED_FUNCTION;
368 void SetEntryData( sal_Int32 nPos, void* pNewData );
369 void* GetEntryData( sal_Int32 nPos ) const;
372 inline void LineListBox::SetColor( const Color& rColor )
374 aColor = rColor;
376 UpdateEntries( m_nWidth );
379 const Color& LineListBox::GetPaintColor() const
381 return maPaintCol;
384 inline void LineListBox::SetWidth( long nWidth )
386 long nOldWidth = m_nWidth;
387 m_nWidth = nWidth;
388 UpdateEntries( nOldWidth );
391 inline void LineListBox::SetNone( const OUString& sNone )
393 m_sNone = sNone;
396 class SVT_DLLPUBLIC FontNameBox : public ComboBox
398 private:
399 ImplFontList* mpFontList;
400 bool mbWYSIWYG;
401 OUString maFontMRUEntriesFile;
403 SVT_DLLPRIVATE void ImplCalcUserItemSize();
404 SVT_DLLPRIVATE void ImplDestroyFontList();
406 protected:
407 void LoadMRUEntries( const OUString& aFontMRUEntriesFile, sal_Unicode cSep = ';' );
408 void SaveMRUEntries( const OUString& aFontMRUEntriesFile, sal_Unicode cSep = ';' ) const;
409 public:
410 FontNameBox( vcl::Window* pParent,
411 WinBits nWinStyle = WB_SORT );
412 virtual ~FontNameBox();
413 virtual void dispose() SAL_OVERRIDE;
415 virtual void UserDraw( const UserDrawEvent& rUDEvt ) SAL_OVERRIDE;
417 void Fill( const FontList* pList );
419 void EnableWYSIWYG( bool bEnable = true );
420 bool IsWYSIWYGEnabled() const { return mbWYSIWYG; }
422 private:
423 void InitFontMRUEntriesFile();
425 FontNameBox( const FontNameBox& ) SAL_DELETED_FUNCTION;
426 FontNameBox& operator =( const FontNameBox& ) SAL_DELETED_FUNCTION;
429 class SVT_DLLPUBLIC FontStyleBox : public ComboBox
431 OUString aLastStyle;
433 Size aOptimalSize;
435 private:
436 using ComboBox::SetText;
437 public:
438 FontStyleBox( vcl::Window* pParent, WinBits nBits );
440 virtual void Select() SAL_OVERRIDE;
441 virtual void LoseFocus() SAL_OVERRIDE;
442 virtual void Modify() SAL_OVERRIDE;
443 virtual Size GetOptimalSize() const SAL_OVERRIDE;
445 void SetText( const OUString& rText ) SAL_OVERRIDE;
446 void Fill( const OUString& rName, const FontList* pList );
448 private:
449 FontStyleBox( const FontStyleBox& ) SAL_DELETED_FUNCTION;
450 FontStyleBox& operator =( const FontStyleBox& ) SAL_DELETED_FUNCTION;
453 inline void FontStyleBox::SetText( const OUString& rText )
455 aLastStyle = rText;
456 ComboBox::SetText( rText );
459 class SVT_DLLPUBLIC FontSizeBox : public MetricBox
461 vcl::FontInfo aFontInfo;
462 const FontList* pFontList;
463 sal_uInt16 nRelMin;
464 sal_uInt16 nRelMax;
465 sal_uInt16 nRelStep;
466 short nPtRelMin;
467 short nPtRelMax;
468 short nPtRelStep;
469 bool bRelativeMode:1,
470 bRelative:1,
471 bPtRelative:1,
472 bStdSize:1;
474 using Window::ImplInit;
475 SVT_DLLPRIVATE void ImplInit();
477 protected:
478 virtual OUString CreateFieldText( sal_Int64 nValue ) const SAL_OVERRIDE;
480 public:
481 FontSizeBox( vcl::Window* pParent, WinBits nWinStyle = 0 );
483 void Reformat() SAL_OVERRIDE;
484 void Modify() SAL_OVERRIDE;
486 void Fill( const vcl::FontInfo* pInfo, const FontList* pList );
488 void EnableRelativeMode( sal_uInt16 nMin = 50, sal_uInt16 nMax = 150,
489 sal_uInt16 nStep = 5 );
490 void EnablePtRelativeMode( short nMin = -200, short nMax = 200,
491 short nStep = 10 );
492 bool IsRelativeMode() const { return bRelativeMode; }
493 void SetRelative( bool bRelative = false );
494 bool IsRelative() const { return bRelative; }
495 void SetPtRelative( bool bPtRel = true )
496 { bPtRelative = bPtRel; SetRelative( true ); }
497 bool IsPtRelative() const { return bPtRelative; }
499 virtual void SetValue( sal_Int64 nNewValue, FieldUnit eInUnit ) SAL_OVERRIDE;
500 virtual void SetValue( sal_Int64 nNewValue ) SAL_OVERRIDE;
501 virtual sal_Int64 GetValue( FieldUnit eOutUnit ) const SAL_OVERRIDE;
502 virtual sal_Int64 GetValue() const SAL_OVERRIDE;
504 private:
505 FontSizeBox( const FontSizeBox& ) SAL_DELETED_FUNCTION;
506 FontSizeBox& operator =( const FontSizeBox& ) SAL_DELETED_FUNCTION;
509 #endif // INCLUDED_SVTOOLS_CTRLBOX_HXX
511 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */