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 .
23 #include "svtools/svtdllapi.h"
25 #include <tools/string.hxx>
26 #include <vcl/lstbox.hxx>
27 #include <vcl/combobox.hxx>
28 #include <vcl/image.hxx>
29 #include <vcl/virdev.hxx>
30 #include <vcl/metric.hxx>
31 #include <vcl/field.hxx>
34 class ImplColorListData
;
35 class ImpLineListData
;
37 typedef ::std::vector
< ImplColorListData
* > ImpColorList
;
38 typedef ::std::vector
< ImpLineListData
* > ImpLineList
;
39 typedef ::std::vector
< FontInfo
> ImplFontList
;
41 // FIXME: STYLE_* duplicate values from editeng::SvxBorderStyle,
42 // which in turn duplicates values from com::sun::star::table::BorderLineStyle:
43 // this needs cleaning up on master
44 #define STYLE_SOLID ( ( sal_uInt16 ) 0 )
45 #define STYLE_DOTTED ( ( sal_uInt16 ) 1 )
46 #define STYLE_DASHED ( ( sal_uInt16 ) 2 )
47 #define STYLE_FINE_DASHED ( ( sal_uInt16 ) 14 )
48 #define STYLE_NONE ( ( sal_uInt16 ) -1)
50 #define CHANGE_LINE1 ( ( sal_uInt16 ) 1 )
51 #define CHANGE_LINE2 ( ( sal_uInt16 ) 2 )
52 #define CHANGE_DIST ( ( sal_uInt16 ) 4 )
53 #define ADAPT_DIST ( ( sal_uInt16 ) 8 )
57 /*************************************************************************
66 Allows color selection
68 --------------------------------------------------------------------------
74 Allows selection of line styles and sizes. Not that before first insert,
75 units and window size need to be set. Supported units are typographic point
76 (pt) and millimeters (mm). For SourceUnit, pt, mm and twips are supported.
77 All scalar numbers in 1/100 of the corresponding unit.
79 Line1 is the outer, Line2 the inner line, Distance is the distance between
80 these two lines. If Line2 == 0, only Line1 will be shown. Defaults for
81 source and target unit are FUNIT_POINT.
83 SetColor() sets the line color.
87 Contrary to a simple ListBox, user-specific data are not supported.
88 If UpdateMode is disabled, no data should be read, no selections
89 should be set, and the return code shall be ignore, as in these are
90 not defined in this mode. Also the bit WinBit WB_SORT may not be set.
92 --------------------------------------------------------------------------
98 Allows selection of fonts. The ListBox will be filled using Fill parameter,
99 which is pointer to an FontList object.
101 Calling EnableWYSIWYG() enables rendering the font name in the currently
106 FontList; FontStyleBox; FontSizeBox; FontNameMenu
108 --------------------------------------------------------------------------
114 Allows select of FontStyle's. The parameter Fill points to a list
115 of available font styles for the font.
117 Reproduced styles are always added - this could change in future, as
118 potentially not all applications [Draw,Equation,FontWork] can properly
119 handle synthetic fonts. On filling, the previous name will be retained
122 For DontKnow, the FontStyleBox should be filled with String(),
123 so it will contain a list with the default attributes. The currently
124 shown style probably needs to be reset by the application.
128 FontList; FontNameBox; FontSizeBox;
130 --------------------------------------------------------------------------
136 Allows selection of font sizes. The values are retrieved via GetValue()
137 and set via SetValue(). The Fill parameter fills the ListBox with the
138 available sizes for the passed font.
140 All sizes are in 1/10 typographic point (pt).
142 The passed FontList must be retained until the next fill call.
144 Additionally it supports an relative mod, which allows entering
145 percentage values. This, eg., can be useful for template dialogs.
146 This mode can only be enabled, but not disabled again.
148 For DontKnow the FontSizeBox should be filled FontInfo(), so it will
149 contain an list with the standard sizes. Th currently shown size
150 probably needs to be reset by the application.
154 FontList; FontNameBox; FontStyleBox; FontSizeMenu
156 *************************************************************************/
162 class SVT_DLLPUBLIC ColorListBox
: public ListBox
164 ImpColorList
* pColorList
; // separate liste, in case of user data are required from outside
167 using Window::ImplInit
;
168 SVT_DLLPRIVATE
void ImplInit();
169 SVT_DLLPRIVATE
void ImplDestroyColorEntries();
172 ColorListBox( Window
* pParent
,
173 WinBits nWinStyle
= WB_BORDER
);
174 ColorListBox( Window
* pParent
, const ResId
& rResId
);
175 virtual ~ColorListBox();
177 virtual void UserDraw( const UserDrawEvent
& rUDEvt
);
179 using ListBox::InsertEntry
;
180 virtual sal_uInt16
InsertEntry( const XubString
& rStr
,
181 sal_uInt16 nPos
= LISTBOX_APPEND
);
182 virtual sal_uInt16
InsertEntry( const Color
& rColor
, const XubString
& rStr
,
183 sal_uInt16 nPos
= LISTBOX_APPEND
);
184 void InsertAutomaticEntryColor(const Color
&rAutoColorValue
);
185 bool IsAutomaticSelected() { return !GetSelectEntryPos(); }
186 using ListBox::RemoveEntry
;
187 virtual void RemoveEntry( sal_uInt16 nPos
);
188 virtual void Clear();
189 void CopyEntries( const ColorListBox
& rBox
);
191 using ListBox::GetEntryPos
;
192 virtual sal_uInt16
GetEntryPos( const Color
& rColor
) const;
193 virtual Color
GetEntryColor( sal_uInt16 nPos
) const;
194 Size
GetImageSize() const { return aImageSize
; }
196 void SelectEntry( const XubString
& rStr
, sal_Bool bSelect
= sal_True
)
197 { ListBox::SelectEntry( rStr
, bSelect
); }
198 void SelectEntry( const Color
& rColor
, sal_Bool bSelect
= sal_True
);
199 XubString
GetSelectEntry( sal_uInt16 nSelIndex
= 0 ) const
200 { return ListBox::GetSelectEntry( nSelIndex
); }
201 Color
GetSelectEntryColor( sal_uInt16 nSelIndex
= 0 ) const;
202 sal_Bool
IsEntrySelected( const XubString
& rStr
) const
203 { return ListBox::IsEntrySelected( rStr
); }
205 sal_Bool
IsEntrySelected( const Color
& rColor
) const;
208 // declared as private because some compilers would generate the default functions
209 ColorListBox( const ColorListBox
& );
210 ColorListBox
& operator =( const ColorListBox
& );
212 void SetEntryData( sal_uInt16 nPos
, void* pNewData
);
213 void* GetEntryData( sal_uInt16 nPos
) const;
216 inline void ColorListBox::SelectEntry( const Color
& rColor
, sal_Bool bSelect
)
218 sal_uInt16 nPos
= GetEntryPos( rColor
);
219 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
220 ListBox::SelectEntryPos( nPos
, bSelect
);
223 inline sal_Bool
ColorListBox::IsEntrySelected( const Color
& rColor
) const
225 sal_uInt16 nPos
= GetEntryPos( rColor
);
226 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
227 return IsEntryPosSelected( nPos
);
232 inline Color
ColorListBox::GetSelectEntryColor( sal_uInt16 nSelIndex
) const
234 sal_uInt16 nPos
= GetSelectEntryPos( nSelIndex
);
236 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
237 aColor
= GetEntryColor( nPos
);
246 Class computing border widths shared between Line style listbox and the
247 SvxBorderLine implementation.
249 This class doesn't know anything about units: it all depends on the different
250 values set. A border is composed of 2 lines separated by a gap. The computed
251 widths are the ones of each line and the gap and they can either be fix or vary.
253 The #m_nflags member will define which widths will vary (value 0 means that all
254 widths are fixed). The available flags are:
259 For each line, the rate member is used as a multiplication factor is the width
260 isn't fixed. Otherwise it is the width in the unit expected by the client code.
262 class SVT_DLLPUBLIC BorderWidthImpl
271 BorderWidthImpl( sal_uInt16 nFlags
= CHANGE_LINE1
, double nRate1
= 0.0,
272 double nRate2
= 0.0, double nRateGap
= 0.0 );
274 BorderWidthImpl
& operator= ( const BorderWidthImpl
& r
);
275 bool operator== ( const BorderWidthImpl
& r
) const;
277 long GetLine1 ( long nWidth
) const;
278 long GetLine2( long nWidth
) const;
279 long GetGap( long nWidth
) const;
281 long GuessWidth( long nLine1
, long nLine2
, long nGap
);
283 bool IsEmpty( ) const { return (0 == m_nRate1
) && (0 == m_nRate2
); }
284 bool IsDouble( ) const { return (0 != m_nRate1
) && (0 != m_nRate2
); }
287 SVT_DLLPUBLIC
inline Color
sameColor( Color rMain
)
292 SVT_DLLPUBLIC
inline Color
sameDistColor( Color
/*rMain*/, Color rDefault
)
298 class SVT_DLLPUBLIC LineListBox
: public ListBox
300 ImpLineList
* pLineList
;
304 VirtualDevice aVirDev
;
309 FieldUnit eSourceUnit
;
311 SVT_DLLPRIVATE
void ImpGetLine( long nLine1
, long nLine2
, long nDistance
,
312 Color nColor1
, Color nColor2
, Color nColorDist
,
313 sal_uInt16 nStyle
, Bitmap
& rBmp
);
314 using Window::ImplInit
;
315 SVT_DLLPRIVATE
void ImplInit();
316 sal_Bool
UpdatePaintLineColor( void ); // returns sal_True if maPaintCol has changed
317 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
319 void UpdateEntries( long nOldWidth
);
320 sal_uInt16
GetStylePos( sal_uInt16 nListPos
, long nWidth
);
323 LineListBox( Window
* pParent
, WinBits nWinStyle
= WB_BORDER
);
324 LineListBox( Window
* pParent
, const ResId
& rResId
);
325 virtual ~LineListBox();
327 /** Set the width in Twips */
328 void SetWidth( long nWidth
);
329 void SetNone( const XubString
& sNone
);
331 using ListBox::InsertEntry
;
332 virtual sal_uInt16
InsertEntry( const XubString
& rStr
, sal_uInt16 nPos
= LISTBOX_APPEND
);
333 /** Insert a listbox entry with all widths in Twips. */
334 void InsertEntry( BorderWidthImpl aWidthImpl
,
335 sal_uInt16 nStyle
, long nMinWidth
= 0,
336 Color (*pColor1Fn
)(Color
) = &sameColor
,
337 Color (*pColor2Fn
)( Color
) = &sameColor
,
338 Color (*pColorDistFn
)( Color
, Color
) = &sameDistColor
);
340 using ListBox::RemoveEntry
;
341 virtual void RemoveEntry( sal_uInt16 nPos
);
342 virtual void Clear();
344 using ListBox::GetEntryPos
;
345 virtual sal_uInt16
GetEntryPos( sal_uInt16 nStyle
= STYLE_SOLID
) const;
346 sal_uInt16
GetEntryStyle( sal_uInt16 nPos
) const;
348 void SelectEntry( const XubString
& rStr
, sal_Bool bSelect
= sal_True
) { ListBox::SelectEntry( rStr
, bSelect
); }
349 void SelectEntry( sal_uInt16 nStyle
= STYLE_SOLID
, sal_Bool bSelect
= sal_True
);
350 sal_uInt16
GetSelectEntryStyle( sal_uInt16 nSelIndex
= 0 ) const;
351 inline sal_Bool
IsEntrySelected( const XubString
& rStr
) const { return ListBox::IsEntrySelected( rStr
); }
352 sal_Bool
IsEntrySelected( sal_uInt16 nStyle1
= STYLE_SOLID
) const;
354 inline void SetUnit( FieldUnit eNewUnit
) { eUnit
= eNewUnit
; }
355 inline FieldUnit
GetUnit() const { return eUnit
; }
356 inline void SetSourceUnit( FieldUnit eNewUnit
) { eSourceUnit
= eNewUnit
; }
357 inline FieldUnit
GetSourceUnit() const { return eSourceUnit
; }
359 void SetColor( const Color
& rColor
);
360 inline Color
GetColor( void ) const;
364 inline const Color
& GetPaintColor( void ) const;
365 Color
GetColorLine1( sal_uInt16 nPos
= 0 );
366 Color
GetColorLine2( sal_uInt16 nPos
= 0 );
367 Color
GetColorDist( sal_uInt16 nPos
= 0 );
370 // declared as private because some compilers would generate the default methods
371 LineListBox( const LineListBox
& );
372 LineListBox
& operator =( const LineListBox
& );
373 void SetEntryData( sal_uInt16 nPos
, void* pNewData
);
374 void* GetEntryData( sal_uInt16 nPos
) const;
377 inline sal_Bool
LineListBox::IsEntrySelected( sal_uInt16 nStyle
) const
379 sal_uInt16 nPos
= GetEntryPos( nStyle
);
380 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
381 return IsEntryPosSelected( nPos
);
386 inline void LineListBox::SetColor( const Color
& rColor
)
390 UpdateEntries( m_nWidth
);
393 inline Color
LineListBox::GetColor( void ) const
398 const Color
& LineListBox::GetPaintColor( void ) const
403 inline void LineListBox::SetWidth( long nWidth
)
405 long nOldWidth
= m_nWidth
;
407 UpdateEntries( nOldWidth
);
410 inline void LineListBox::SetNone( const XubString
& sNone
)
419 class SVT_DLLPUBLIC FontNameBox
: public ComboBox
422 ImplFontList
* mpFontList
;
424 String maFontMRUEntriesFile
;
426 SVT_DLLPRIVATE
void ImplCalcUserItemSize();
427 SVT_DLLPRIVATE
void ImplDestroyFontList();
430 void LoadMRUEntries( const String
& aFontMRUEntriesFile
, sal_Unicode cSep
= ';' );
431 void SaveMRUEntries( const String
& aFontMRUEntriesFile
, sal_Unicode cSep
= ';' ) const;
433 FontNameBox( Window
* pParent
,
434 WinBits nWinStyle
= WB_SORT
);
435 FontNameBox( Window
* pParent
, const ResId
& rResId
);
436 virtual ~FontNameBox();
438 virtual void UserDraw( const UserDrawEvent
& rUDEvt
);
440 void Fill( const FontList
* pList
);
442 void EnableWYSIWYG( sal_Bool bEnable
= sal_True
);
443 sal_Bool
IsWYSIWYGEnabled() const { return mbWYSIWYG
; }
446 void InitFontMRUEntriesFile();
448 // declared as private because some compilers would generate the default functions
449 FontNameBox( const FontNameBox
& );
450 FontNameBox
& operator =( const FontNameBox
& );
457 class SVT_DLLPUBLIC FontStyleBox
: public ComboBox
459 XubString aLastStyle
;
462 using ComboBox::SetText
;
464 FontStyleBox( Window
* pParent
, const ResId
& rResId
);
465 FontStyleBox( Window
* pParent
, WinBits nBits
);
466 virtual ~FontStyleBox();
468 virtual void Select();
469 virtual void LoseFocus();
470 virtual void Modify();
472 void SetText( const OUString
& rText
);
473 void Fill( const XubString
& rName
, const FontList
* pList
);
476 // declared as private because some compilers would generate the default functions
477 FontStyleBox( const FontStyleBox
& );
478 FontStyleBox
& operator =( const FontStyleBox
& );
481 inline void FontStyleBox::SetText( const OUString
& rText
)
484 ComboBox::SetText( rText
);
491 class SVT_DLLPUBLIC FontSizeBox
: public MetricBox
494 const FontList
* pFontList
;
501 sal_Bool bRelativeMode
:1,
506 using Window::ImplInit
;
507 SVT_DLLPRIVATE
void ImplInit();
510 virtual OUString
CreateFieldText( sal_Int64 nValue
) const;
513 FontSizeBox( Window
* pParent
, WinBits nWinStyle
= 0 );
514 FontSizeBox( Window
* pParent
, const ResId
& rResId
);
515 virtual ~FontSizeBox();
520 void Fill( const FontInfo
* pInfo
, const FontList
* pList
);
522 void EnableRelativeMode( sal_uInt16 nMin
= 50, sal_uInt16 nMax
= 150,
523 sal_uInt16 nStep
= 5 );
524 void EnablePtRelativeMode( short nMin
= -200, short nMax
= 200,
526 sal_Bool
IsRelativeMode() const { return bRelativeMode
; }
527 void SetRelative( sal_Bool bRelative
= sal_False
);
528 sal_Bool
IsRelative() const { return bRelative
; }
529 void SetPtRelative( sal_Bool bPtRel
= sal_True
)
530 { bPtRelative
= bPtRel
; SetRelative( sal_True
); }
531 sal_Bool
IsPtRelative() const { return bPtRelative
; }
533 virtual void SetValue( sal_Int64 nNewValue
, FieldUnit eInUnit
);
534 virtual void SetValue( sal_Int64 nNewValue
);
535 virtual sal_Int64
GetValue( FieldUnit eOutUnit
) const;
536 virtual sal_Int64
GetValue() const;
537 sal_Int64
GetValue( sal_uInt16 nPos
, FieldUnit eOutUnit
) const;
540 // declared as private because some compilers would generate the default functions
541 FontSizeBox( const FontSizeBox
& );
542 FontSizeBox
& operator =( const FontSizeBox
& );
545 #endif // _CTRLBOX_HXX
547 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */