Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SVTOOLS_CTRLBOX_HXX
21 : #define INCLUDED_SVTOOLS_CTRLBOX_HXX
22 :
23 : #include <svtools/svtdllapi.h>
24 :
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>
31 :
32 : #include <com/sun/star/table/BorderLineStyle.hpp>
33 :
34 : class FontList;
35 : class ImplColorListData;
36 : class ImpLineListData;
37 :
38 : typedef ::std::vector< ImplColorListData* > ImpColorList;
39 : typedef ::std::vector< ImpLineListData* > ImpLineList;
40 : typedef ::std::vector< vcl::FontInfo > ImplFontList;
41 :
42 : #define CHANGE_LINE1 ( ( sal_uInt16 ) 1 )
43 : #define CHANGE_LINE2 ( ( sal_uInt16 ) 2 )
44 : #define CHANGE_DIST ( ( sal_uInt16 ) 4 )
45 : #define ADAPT_DIST ( ( sal_uInt16 ) 8 )
46 :
47 : /*************************************************************************
48 :
49 : Description
50 : ============
51 :
52 : class ColorListBox
53 :
54 : Description
55 :
56 : Allows color selection
57 :
58 : --------------------------------------------------------------------------
59 :
60 : class LineListBox
61 :
62 : Description
63 :
64 : Allows selection of line styles and sizes. Not that before first insert,
65 : units and window size need to be set. Supported units are typographic point
66 : (pt) and millimeters (mm). For SourceUnit, pt, mm and twips are supported.
67 : All scalar numbers in 1/100 of the corresponding unit.
68 :
69 : Line1 is the outer, Line2 the inner line, Distance is the distance between
70 : these two lines. If Line2 == 0, only Line1 will be shown. Defaults for
71 : source and target unit are FUNIT_POINT.
72 :
73 : SetColor() sets the line color.
74 :
75 : Remarks
76 :
77 : Contrary to a simple ListBox, user-specific data are not supported.
78 : If UpdateMode is disabled, no data should be read, no selections
79 : should be set, and the return code shall be ignore, as in these are
80 : not defined in this mode. Also the bit WinBit WB_SORT may not be set.
81 :
82 : --------------------------------------------------------------------------
83 :
84 : class FontNameBox
85 :
86 : Description
87 :
88 : Allows selection of fonts. The ListBox will be filled using Fill parameter,
89 : which is pointer to an FontList object.
90 :
91 : Calling EnableWYSIWYG() enables rendering the font name in the currently
92 : selected font.
93 :
94 : See also
95 :
96 : FontList; FontStyleBox; FontSizeBox; FontNameMenu
97 :
98 : --------------------------------------------------------------------------
99 :
100 : class FontStyleBox
101 :
102 : Description
103 :
104 : Allows select of FontStyle's. The parameter Fill points to a list
105 : of available font styles for the font.
106 :
107 : Reproduced styles are always added - this could change in future, as
108 : potentially not all applications [Draw,Equation,FontWork] can properly
109 : handle synthetic fonts. On filling, the previous name will be retained
110 : if possible.
111 :
112 : For DontKnow, the FontStyleBox should be filled with OUString(),
113 : so it will contain a list with the default attributes. The currently
114 : shown style probably needs to be reset by the application.
115 :
116 : See also
117 :
118 : FontList; FontNameBox; FontSizeBox;
119 :
120 : --------------------------------------------------------------------------
121 :
122 : class FontSizeBox
123 :
124 : Description
125 :
126 : Allows selection of font sizes. The values are retrieved via GetValue()
127 : and set via SetValue(). The Fill parameter fills the ListBox with the
128 : available sizes for the passed font.
129 :
130 : All sizes are in 1/10 typographic point (pt).
131 :
132 : The passed FontList must be retained until the next fill call.
133 :
134 : Additionally it supports an relative mod, which allows entering
135 : percentage values. This, eg., can be useful for template dialogs.
136 : This mode can only be enabled, but not disabled again.
137 :
138 : For DontKnow the FontSizeBox should be filled FontInfo(), so it will
139 : contain an list with the standard sizes. Th currently shown size
140 : probably needs to be reset by the application.
141 :
142 : See also
143 :
144 : FontList; FontNameBox; FontStyleBox; FontSizeMenu
145 :
146 : *************************************************************************/
147 :
148 : class SVT_DLLPUBLIC ColorListBox : public ListBox
149 : {
150 : ImpColorList* pColorList; // separate liste, in case of user data are required from outside
151 : Size aImageSize;
152 :
153 : using Window::ImplInit;
154 : SVT_DLLPRIVATE void ImplInit();
155 : SVT_DLLPRIVATE void ImplDestroyColorEntries();
156 :
157 : public:
158 : ColorListBox( vcl::Window* pParent,
159 : WinBits nWinStyle = WB_BORDER );
160 : ColorListBox( vcl::Window* pParent, const ResId& rResId );
161 : virtual ~ColorListBox();
162 :
163 : virtual void UserDraw( const UserDrawEvent& rUDEvt ) SAL_OVERRIDE;
164 :
165 : using ListBox::InsertEntry;
166 : virtual sal_Int32 InsertEntry( const OUString& rStr,
167 : sal_Int32 nPos = LISTBOX_APPEND );
168 : virtual sal_Int32 InsertEntry( const Color& rColor, const OUString& rStr,
169 : sal_Int32 nPos = LISTBOX_APPEND );
170 : void InsertAutomaticEntryColor(const Color &rAutoColorValue);
171 0 : bool IsAutomaticSelected() { return !GetSelectEntryPos(); }
172 : using ListBox::RemoveEntry;
173 : virtual void RemoveEntry( sal_Int32 nPos );
174 : virtual void Clear();
175 : void CopyEntries( const ColorListBox& rBox );
176 :
177 : using ListBox::GetEntryPos;
178 : virtual sal_Int32 GetEntryPos( const Color& rColor ) const;
179 : virtual Color GetEntryColor( sal_Int32 nPos ) const;
180 : Size GetImageSize() const { return aImageSize; }
181 :
182 66 : void SelectEntry( const OUString& rStr, bool bSelect = true )
183 66 : { ListBox::SelectEntry( rStr, bSelect ); }
184 : void SelectEntry( const Color& rColor, bool bSelect = true );
185 : Color GetSelectEntryColor( sal_Int32 nSelIndex = 0 ) const;
186 0 : bool IsEntrySelected(const OUString& rStr ) const
187 : {
188 0 : return ListBox::IsEntrySelected(rStr);
189 : }
190 :
191 0 : bool IsEntrySelected(const Color& rColor) const
192 : {
193 0 : sal_Int32 nPos = GetEntryPos( rColor );
194 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
195 0 : return IsEntryPosSelected( nPos );
196 : else
197 0 : return false;
198 : }
199 :
200 : private:
201 : // declared as private because some compilers would generate the default functions
202 : ColorListBox( const ColorListBox& );
203 : ColorListBox& operator =( const ColorListBox& );
204 :
205 : void SetEntryData( sal_Int32 nPos, void* pNewData );
206 : void* GetEntryData( sal_Int32 nPos ) const;
207 : };
208 :
209 57 : inline void ColorListBox::SelectEntry( const Color& rColor, bool bSelect )
210 : {
211 57 : sal_Int32 nPos = GetEntryPos( rColor );
212 57 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
213 57 : ListBox::SelectEntryPos( nPos, bSelect );
214 57 : }
215 :
216 75 : inline Color ColorListBox::GetSelectEntryColor( sal_Int32 nSelIndex ) const
217 : {
218 75 : sal_Int32 nPos = GetSelectEntryPos( nSelIndex );
219 75 : Color aColor;
220 75 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
221 75 : aColor = GetEntryColor( nPos );
222 75 : return aColor;
223 : }
224 :
225 : /**
226 : Class computing border widths shared between Line style listbox and the
227 : SvxBorderLine implementation.
228 :
229 : This class doesn't know anything about units: it all depends on the different
230 : values set. A border is composed of 2 lines separated by a gap. The computed
231 : widths are the ones of each line and the gap and they can either be fix or vary.
232 :
233 : The #m_nflags member will define which widths will vary (value 0 means that all
234 : widths are fixed). The available flags are:
235 : - CHANGE_LINE1
236 : - CHANGE_LINE2
237 : - CHANGE_DIST
238 :
239 : For each line, the rate member is used as a multiplication factor is the width
240 : isn't fixed. Otherwise it is the width in the unit expected by the client code.
241 : */
242 : class SVT_DLLPUBLIC BorderWidthImpl
243 : {
244 : sal_uInt16 m_nFlags;
245 : double m_nRate1;
246 : double m_nRate2;
247 : double m_nRateGap;
248 :
249 : public:
250 :
251 : BorderWidthImpl( sal_uInt16 nFlags = CHANGE_LINE1, double nRate1 = 0.0,
252 : double nRate2 = 0.0, double nRateGap = 0.0 );
253 :
254 : BorderWidthImpl& operator= ( const BorderWidthImpl& r );
255 : bool operator== ( const BorderWidthImpl& r ) const;
256 :
257 : long GetLine1 ( long nWidth ) const;
258 : long GetLine2( long nWidth ) const;
259 : long GetGap( long nWidth ) const;
260 :
261 : long GuessWidth( long nLine1, long nLine2, long nGap );
262 :
263 111886 : bool IsEmpty( ) const { return (0 == m_nRate1) && (0 == m_nRate2); }
264 6201875 : bool IsDouble( ) const { return (0 != m_nRate1) && (0 != m_nRate2); }
265 : };
266 :
267 0 : inline Color sameColor( Color rMain )
268 : {
269 0 : return rMain;
270 : }
271 :
272 0 : inline Color sameDistColor( Color /*rMain*/, Color rDefault )
273 : {
274 0 : return rDefault;
275 : }
276 :
277 : class SVT_DLLPUBLIC LineListBox : public ListBox
278 : {
279 : ImpLineList* pLineList;
280 : long m_nWidth;
281 : OUString m_sNone;
282 :
283 : VirtualDevice aVirDev;
284 : Size aTxtSize;
285 : Color aColor;
286 : Color maPaintCol;
287 : FieldUnit eUnit;
288 : FieldUnit eSourceUnit;
289 :
290 : SVT_DLLPRIVATE void ImpGetLine( long nLine1, long nLine2, long nDistance,
291 : Color nColor1, Color nColor2, Color nColorDist,
292 : sal_uInt16 nStyle, Bitmap& rBmp );
293 : using Window::ImplInit;
294 : SVT_DLLPRIVATE void ImplInit();
295 : bool UpdatePaintLineColor( void ); // returns sal_True if maPaintCol has changed
296 : virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
297 :
298 : void UpdateEntries( long nOldWidth );
299 : sal_Int32 GetStylePos( sal_Int32 nListPos, long nWidth );
300 :
301 : public:
302 : typedef Color (*ColorFunc)(Color);
303 : typedef Color (*ColorDistFunc)(Color, Color);
304 :
305 : LineListBox( vcl::Window* pParent, WinBits nWinStyle = WB_BORDER );
306 : virtual ~LineListBox();
307 :
308 : /** Set the width in Twips */
309 : void SetWidth( long nWidth );
310 0 : long GetWidth() const { return m_nWidth; }
311 : void SetNone( const OUString& sNone );
312 :
313 : using ListBox::InsertEntry;
314 : virtual sal_Int32 InsertEntry( const OUString& rStr, sal_Int32 nPos = LISTBOX_APPEND );
315 : /** Insert a listbox entry with all widths in Twips. */
316 : void InsertEntry( BorderWidthImpl aWidthImpl,
317 : sal_uInt16 nStyle, long nMinWidth = 0,
318 : ColorFunc pColor1Fn = &sameColor,
319 : ColorFunc pColor2Fn = &sameColor,
320 : ColorDistFunc pColorDistFn = &sameDistColor );
321 :
322 : using ListBox::RemoveEntry;
323 : virtual void RemoveEntry( sal_Int32 nPos );
324 : virtual void Clear();
325 :
326 : using ListBox::GetEntryPos;
327 : virtual sal_Int32 GetEntryPos( sal_uInt16 nStyle = com::sun::star::table::BorderLineStyle::SOLID ) const;
328 : sal_uInt16 GetEntryStyle( sal_Int32 nPos ) const;
329 :
330 : void SelectEntry( const OUString& rStr, bool bSelect = true ) { ListBox::SelectEntry( rStr, bSelect ); }
331 : void SelectEntry( sal_uInt16 nStyle = com::sun::star::table::BorderLineStyle::SOLID, bool bSelect = true );
332 : sal_uInt16 GetSelectEntryStyle( sal_Int32 nSelIndex = 0 ) const;
333 : bool IsEntrySelected(const OUString& rStr) const
334 : {
335 : return ListBox::IsEntrySelected(rStr);
336 : }
337 : bool IsEntrySelected( sal_uInt16 nStyle = com::sun::star::table::BorderLineStyle::SOLID ) const
338 : {
339 : sal_Int32 nPos = GetEntryPos( nStyle );
340 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
341 : return IsEntryPosSelected( nPos );
342 : else
343 : return false;
344 : }
345 :
346 0 : inline void SetUnit( FieldUnit eNewUnit ) { eUnit = eNewUnit; }
347 : inline FieldUnit GetUnit() const { return eUnit; }
348 0 : inline void SetSourceUnit( FieldUnit eNewUnit ) { eSourceUnit = eNewUnit; }
349 : inline FieldUnit GetSourceUnit() const { return eSourceUnit; }
350 :
351 : void SetColor( const Color& rColor );
352 0 : Color GetColor() const { return aColor; }
353 :
354 : protected:
355 :
356 : inline const Color& GetPaintColor( void ) const;
357 : Color GetColorLine1( sal_Int32 nPos = 0 );
358 : Color GetColorLine2( sal_Int32 nPos = 0 );
359 : Color GetColorDist( sal_Int32 nPos = 0 );
360 :
361 : private:
362 : // declared as private because some compilers would generate the default methods
363 : LineListBox( const LineListBox& );
364 : LineListBox& operator =( const LineListBox& );
365 : void SetEntryData( sal_Int32 nPos, void* pNewData );
366 : void* GetEntryData( sal_Int32 nPos ) const;
367 : };
368 :
369 0 : inline void LineListBox::SetColor( const Color& rColor )
370 : {
371 0 : aColor = rColor;
372 :
373 0 : UpdateEntries( m_nWidth );
374 0 : }
375 :
376 0 : const Color& LineListBox::GetPaintColor( void ) const
377 : {
378 0 : return maPaintCol;
379 : }
380 :
381 0 : inline void LineListBox::SetWidth( long nWidth )
382 : {
383 0 : long nOldWidth = m_nWidth;
384 0 : m_nWidth = nWidth;
385 0 : UpdateEntries( nOldWidth );
386 0 : }
387 :
388 0 : inline void LineListBox::SetNone( const OUString& sNone )
389 : {
390 0 : m_sNone = sNone;
391 0 : }
392 :
393 : class SVT_DLLPUBLIC FontNameBox : public ComboBox
394 : {
395 : private:
396 : ImplFontList* mpFontList;
397 : bool mbWYSIWYG;
398 : OUString maFontMRUEntriesFile;
399 :
400 : SVT_DLLPRIVATE void ImplCalcUserItemSize();
401 : SVT_DLLPRIVATE void ImplDestroyFontList();
402 :
403 : protected:
404 : void LoadMRUEntries( const OUString& aFontMRUEntriesFile, sal_Unicode cSep = ';' );
405 : void SaveMRUEntries( const OUString& aFontMRUEntriesFile, sal_Unicode cSep = ';' ) const;
406 : public:
407 : FontNameBox( vcl::Window* pParent,
408 : WinBits nWinStyle = WB_SORT );
409 : virtual ~FontNameBox();
410 :
411 : virtual void UserDraw( const UserDrawEvent& rUDEvt ) SAL_OVERRIDE;
412 :
413 : void Fill( const FontList* pList );
414 :
415 : void EnableWYSIWYG( bool bEnable = true );
416 : bool IsWYSIWYGEnabled() const { return mbWYSIWYG; }
417 :
418 : private:
419 : void InitFontMRUEntriesFile();
420 :
421 : // declared as private because some compilers would generate the default functions
422 : FontNameBox( const FontNameBox& );
423 : FontNameBox& operator =( const FontNameBox& );
424 : };
425 :
426 : class SVT_DLLPUBLIC FontStyleBox : public ComboBox
427 : {
428 : OUString aLastStyle;
429 :
430 : Size aOptimalSize;
431 :
432 : private:
433 : using ComboBox::SetText;
434 : public:
435 : FontStyleBox( vcl::Window* pParent, WinBits nBits );
436 : virtual ~FontStyleBox();
437 :
438 : virtual void Select() SAL_OVERRIDE;
439 : virtual void LoseFocus() SAL_OVERRIDE;
440 : virtual void Modify() SAL_OVERRIDE;
441 : virtual Size GetOptimalSize() const SAL_OVERRIDE;
442 :
443 : void SetText( const OUString& rText ) SAL_OVERRIDE;
444 : void Fill( const OUString& rName, const FontList* pList );
445 :
446 : private:
447 : // declared as private because some compilers would generate the default functions
448 : FontStyleBox( const FontStyleBox& );
449 : FontStyleBox& operator =( const FontStyleBox& );
450 : };
451 :
452 0 : inline void FontStyleBox::SetText( const OUString& rText )
453 : {
454 0 : aLastStyle = rText;
455 0 : ComboBox::SetText( rText );
456 0 : }
457 :
458 : class SVT_DLLPUBLIC FontSizeBox : public MetricBox
459 : {
460 : vcl::FontInfo aFontInfo;
461 : const FontList* pFontList;
462 : sal_uInt16 nRelMin;
463 : sal_uInt16 nRelMax;
464 : sal_uInt16 nRelStep;
465 : short nPtRelMin;
466 : short nPtRelMax;
467 : short nPtRelStep;
468 : bool bRelativeMode:1,
469 : bRelative:1,
470 : bPtRelative:1,
471 : bStdSize:1;
472 :
473 : using Window::ImplInit;
474 : SVT_DLLPRIVATE void ImplInit();
475 :
476 : protected:
477 : virtual OUString CreateFieldText( sal_Int64 nValue ) const SAL_OVERRIDE;
478 :
479 : public:
480 : FontSizeBox( vcl::Window* pParent, WinBits nWinStyle = 0 );
481 : virtual ~FontSizeBox();
482 :
483 : void Reformat() SAL_OVERRIDE;
484 : void Modify() SAL_OVERRIDE;
485 :
486 : void Fill( const vcl::FontInfo* pInfo, const FontList* pList );
487 :
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 0 : bool IsRelativeMode() const { return bRelativeMode; }
493 : void SetRelative( bool bRelative = false );
494 0 : bool IsRelative() const { return bRelative; }
495 0 : void SetPtRelative( bool bPtRel = true )
496 0 : { bPtRelative = bPtRel; SetRelative( true ); }
497 0 : bool IsPtRelative() const { return bPtRelative; }
498 :
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;
503 :
504 : private:
505 : // declared as private because some compilers would generate the default functions
506 : FontSizeBox( const FontSizeBox& );
507 : FontSizeBox& operator =( const FontSizeBox& );
508 : };
509 :
510 : #endif // INCLUDED_SVTOOLS_CTRLBOX_HXX
511 :
512 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|