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 _CTRLBOX_HXX
21 : #define _CTRLBOX_HXX
22 :
23 : #include "svtools/svtdllapi.h"
24 :
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>
32 :
33 : class FontList;
34 : class ImplColorListData;
35 : class ImpLineListData;
36 :
37 : typedef ::std::vector< ImplColorListData* > ImpColorList;
38 : typedef ::std::vector< ImpLineListData* > ImpLineList;
39 : typedef ::std::vector< FontInfo > ImplFontList;
40 :
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)
49 :
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 )
54 :
55 :
56 :
57 : /*************************************************************************
58 :
59 : Description
60 : ============
61 :
62 : class ColorListBox
63 :
64 : Description
65 :
66 : Allows color selection
67 :
68 : --------------------------------------------------------------------------
69 :
70 : class LineListBox
71 :
72 : Description
73 :
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.
78 :
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.
82 :
83 : SetColor() sets the line color.
84 :
85 : Remarks
86 :
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.
91 :
92 : --------------------------------------------------------------------------
93 :
94 : class FontNameBox
95 :
96 : Description
97 :
98 : Allows selection of fonts. The ListBox will be filled using Fill parameter,
99 : which is pointer to an FontList object.
100 :
101 : Calling EnableWYSIWYG() enables rendering the font name in the currently
102 : selected font.
103 :
104 : See also
105 :
106 : FontList; FontStyleBox; FontSizeBox; FontNameMenu
107 :
108 : --------------------------------------------------------------------------
109 :
110 : class FontStyleBox
111 :
112 : Description
113 :
114 : Allows select of FontStyle's. The parameter Fill points to a list
115 : of available font styles for the font.
116 :
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
120 : if possible.
121 :
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.
125 :
126 : See also
127 :
128 : FontList; FontNameBox; FontSizeBox;
129 :
130 : --------------------------------------------------------------------------
131 :
132 : class FontSizeBox
133 :
134 : Description
135 :
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.
139 :
140 : All sizes are in 1/10 typographic point (pt).
141 :
142 : The passed FontList must be retained until the next fill call.
143 :
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.
147 :
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.
151 :
152 : See also
153 :
154 : FontList; FontNameBox; FontStyleBox; FontSizeMenu
155 :
156 : *************************************************************************/
157 :
158 : // ----------------
159 : // - ColorListBox -
160 : // ----------------
161 :
162 : class SVT_DLLPUBLIC ColorListBox : public ListBox
163 : {
164 : ImpColorList* pColorList; // separate liste, in case of user data are required from outside
165 : Size aImageSize;
166 :
167 : using Window::ImplInit;
168 : SVT_DLLPRIVATE void ImplInit();
169 : SVT_DLLPRIVATE void ImplDestroyColorEntries();
170 :
171 : public:
172 : ColorListBox( Window* pParent,
173 : WinBits nWinStyle = WB_BORDER );
174 : ColorListBox( Window* pParent, const ResId& rResId );
175 : virtual ~ColorListBox();
176 :
177 : virtual void UserDraw( const UserDrawEvent& rUDEvt );
178 :
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 0 : 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 );
190 :
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; }
195 :
196 82 : void SelectEntry( const XubString& rStr, sal_Bool bSelect = sal_True )
197 82 : { ListBox::SelectEntry( rStr, bSelect ); }
198 : void SelectEntry( const Color& rColor, sal_Bool bSelect = sal_True );
199 0 : XubString GetSelectEntry( sal_uInt16 nSelIndex = 0 ) const
200 0 : { return ListBox::GetSelectEntry( nSelIndex ); }
201 : Color GetSelectEntryColor( sal_uInt16 nSelIndex = 0 ) const;
202 0 : sal_Bool IsEntrySelected( const XubString& rStr ) const
203 0 : { return ListBox::IsEntrySelected( rStr ); }
204 :
205 : sal_Bool IsEntrySelected( const Color& rColor ) const;
206 :
207 : private:
208 : // declared as private because some compilers would generate the default functions
209 : ColorListBox( const ColorListBox& );
210 : ColorListBox& operator =( const ColorListBox& );
211 :
212 : void SetEntryData( sal_uInt16 nPos, void* pNewData );
213 : void* GetEntryData( sal_uInt16 nPos ) const;
214 : };
215 :
216 141 : inline void ColorListBox::SelectEntry( const Color& rColor, sal_Bool bSelect )
217 : {
218 141 : sal_uInt16 nPos = GetEntryPos( rColor );
219 141 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
220 0 : ListBox::SelectEntryPos( nPos, bSelect );
221 141 : }
222 :
223 0 : inline sal_Bool ColorListBox::IsEntrySelected( const Color& rColor ) const
224 : {
225 0 : sal_uInt16 nPos = GetEntryPos( rColor );
226 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
227 0 : return IsEntryPosSelected( nPos );
228 : else
229 0 : return sal_False;
230 : }
231 :
232 46 : inline Color ColorListBox::GetSelectEntryColor( sal_uInt16 nSelIndex ) const
233 : {
234 46 : sal_uInt16 nPos = GetSelectEntryPos( nSelIndex );
235 46 : Color aColor;
236 46 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
237 46 : aColor = GetEntryColor( nPos );
238 46 : return aColor;
239 : }
240 :
241 : // ---------------
242 : // - LineListBox -
243 : // ---------------
244 :
245 : /**
246 : Class computing border widths shared between Line style listbox and the
247 : SvxBorderLine implementation.
248 :
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.
252 :
253 : The #m_nflags member will define which widths will vary (value 0 means that all
254 : widths are fixed). The available flags are:
255 : - CHANGE_LINE1
256 : - CHANGE_LINE2
257 : - CHANGE_DIST
258 :
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.
261 : */
262 : class SVT_DLLPUBLIC BorderWidthImpl
263 : {
264 : sal_uInt16 m_nFlags;
265 : double m_nRate1;
266 : double m_nRate2;
267 : double m_nRateGap;
268 :
269 : public:
270 :
271 : BorderWidthImpl( sal_uInt16 nFlags = CHANGE_LINE1, double nRate1 = 0.0,
272 : double nRate2 = 0.0, double nRateGap = 0.0 );
273 :
274 : BorderWidthImpl& operator= ( const BorderWidthImpl& r );
275 : bool operator== ( const BorderWidthImpl& r ) const;
276 :
277 : long GetLine1 ( long nWidth ) const;
278 : long GetLine2( long nWidth ) const;
279 : long GetGap( long nWidth ) const;
280 :
281 : long GuessWidth( long nLine1, long nLine2, long nGap );
282 :
283 7983 : bool IsEmpty( ) const { return (0 == m_nRate1) && (0 == m_nRate2); }
284 3596790 : bool IsDouble( ) const { return (0 != m_nRate1) && (0 != m_nRate2); }
285 : };
286 :
287 0 : SVT_DLLPUBLIC inline Color sameColor( Color rMain )
288 : {
289 0 : return rMain;
290 : }
291 :
292 0 : SVT_DLLPUBLIC inline Color sameDistColor( Color /*rMain*/, Color rDefault )
293 : {
294 0 : return rDefault;
295 : }
296 :
297 :
298 : class SVT_DLLPUBLIC LineListBox : public ListBox
299 : {
300 : ImpLineList* pLineList;
301 : long m_nWidth;
302 : XubString m_sNone;
303 :
304 : VirtualDevice aVirDev;
305 : Size aTxtSize;
306 : Color aColor;
307 : Color maPaintCol;
308 : FieldUnit eUnit;
309 : FieldUnit eSourceUnit;
310 :
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 );
318 :
319 : void UpdateEntries( long nOldWidth );
320 : sal_uInt16 GetStylePos( sal_uInt16 nListPos, long nWidth );
321 :
322 : public:
323 : LineListBox( Window* pParent, WinBits nWinStyle = WB_BORDER );
324 : virtual ~LineListBox();
325 :
326 : /** Set the width in Twips */
327 : void SetWidth( long nWidth );
328 : void SetNone( const XubString& sNone );
329 :
330 : using ListBox::InsertEntry;
331 : virtual sal_uInt16 InsertEntry( const XubString& rStr, sal_uInt16 nPos = LISTBOX_APPEND );
332 : /** Insert a listbox entry with all widths in Twips. */
333 : void InsertEntry( BorderWidthImpl aWidthImpl,
334 : sal_uInt16 nStyle, long nMinWidth = 0,
335 : Color (*pColor1Fn)(Color) = &sameColor,
336 : Color (*pColor2Fn)( Color ) = &sameColor,
337 : Color (*pColorDistFn)( Color, Color ) = &sameDistColor );
338 :
339 : using ListBox::RemoveEntry;
340 : virtual void RemoveEntry( sal_uInt16 nPos );
341 : virtual void Clear();
342 :
343 : using ListBox::GetEntryPos;
344 : virtual sal_uInt16 GetEntryPos( sal_uInt16 nStyle = STYLE_SOLID ) const;
345 : sal_uInt16 GetEntryStyle( sal_uInt16 nPos ) const;
346 :
347 0 : void SelectEntry( const XubString& rStr, sal_Bool bSelect = sal_True ) { ListBox::SelectEntry( rStr, bSelect ); }
348 : void SelectEntry( sal_uInt16 nStyle = STYLE_SOLID, sal_Bool bSelect = sal_True );
349 : sal_uInt16 GetSelectEntryStyle( sal_uInt16 nSelIndex = 0 ) const;
350 0 : inline sal_Bool IsEntrySelected( const XubString& rStr ) const { return ListBox::IsEntrySelected( rStr ); }
351 : sal_Bool IsEntrySelected( sal_uInt16 nStyle1 = STYLE_SOLID ) const;
352 :
353 0 : inline void SetUnit( FieldUnit eNewUnit ) { eUnit = eNewUnit; }
354 : inline FieldUnit GetUnit() const { return eUnit; }
355 0 : inline void SetSourceUnit( FieldUnit eNewUnit ) { eSourceUnit = eNewUnit; }
356 : inline FieldUnit GetSourceUnit() const { return eSourceUnit; }
357 :
358 : void SetColor( const Color& rColor );
359 : inline Color GetColor( void ) const;
360 :
361 : protected:
362 :
363 : inline const Color& GetPaintColor( void ) const;
364 : Color GetColorLine1( sal_uInt16 nPos = 0 );
365 : Color GetColorLine2( sal_uInt16 nPos = 0 );
366 : Color GetColorDist( sal_uInt16 nPos = 0 );
367 :
368 : private:
369 : // declared as private because some compilers would generate the default methods
370 : LineListBox( const LineListBox& );
371 : LineListBox& operator =( const LineListBox& );
372 : void SetEntryData( sal_uInt16 nPos, void* pNewData );
373 : void* GetEntryData( sal_uInt16 nPos ) const;
374 : };
375 :
376 : inline sal_Bool LineListBox::IsEntrySelected( sal_uInt16 nStyle ) const
377 : {
378 : sal_uInt16 nPos = GetEntryPos( nStyle );
379 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
380 : return IsEntryPosSelected( nPos );
381 : else
382 : return sal_False;
383 : }
384 :
385 0 : inline void LineListBox::SetColor( const Color& rColor )
386 : {
387 0 : aColor = rColor;
388 :
389 0 : UpdateEntries( m_nWidth );
390 0 : }
391 :
392 0 : inline Color LineListBox::GetColor( void ) const
393 : {
394 0 : return aColor;
395 : }
396 :
397 0 : const Color& LineListBox::GetPaintColor( void ) const
398 : {
399 0 : return maPaintCol;
400 : }
401 :
402 0 : inline void LineListBox::SetWidth( long nWidth )
403 : {
404 0 : long nOldWidth = m_nWidth;
405 0 : m_nWidth = nWidth;
406 0 : UpdateEntries( nOldWidth );
407 0 : }
408 :
409 0 : inline void LineListBox::SetNone( const XubString& sNone )
410 : {
411 0 : m_sNone = sNone;
412 0 : }
413 :
414 : // ---------------
415 : // - FontNameBox -
416 : // ---------------
417 :
418 : class SVT_DLLPUBLIC FontNameBox : public ComboBox
419 : {
420 : private:
421 : ImplFontList* mpFontList;
422 : sal_Bool mbWYSIWYG;
423 : String maFontMRUEntriesFile;
424 :
425 : SVT_DLLPRIVATE void ImplCalcUserItemSize();
426 : SVT_DLLPRIVATE void ImplDestroyFontList();
427 :
428 : protected:
429 : void LoadMRUEntries( const String& aFontMRUEntriesFile, sal_Unicode cSep = ';' );
430 : void SaveMRUEntries( const String& aFontMRUEntriesFile, sal_Unicode cSep = ';' ) const;
431 : public:
432 : FontNameBox( Window* pParent,
433 : WinBits nWinStyle = WB_SORT );
434 : FontNameBox( Window* pParent, const ResId& rResId );
435 : virtual ~FontNameBox();
436 :
437 : virtual void UserDraw( const UserDrawEvent& rUDEvt );
438 :
439 : void Fill( const FontList* pList );
440 :
441 : void EnableWYSIWYG( sal_Bool bEnable = sal_True );
442 : sal_Bool IsWYSIWYGEnabled() const { return mbWYSIWYG; }
443 :
444 : private:
445 : void InitFontMRUEntriesFile();
446 :
447 : // declared as private because some compilers would generate the default functions
448 : FontNameBox( const FontNameBox& );
449 : FontNameBox& operator =( const FontNameBox& );
450 : };
451 :
452 : // ----------------
453 : // - FontStyleBox -
454 : // ----------------
455 :
456 : class SVT_DLLPUBLIC FontStyleBox : public ComboBox
457 : {
458 : XubString aLastStyle;
459 :
460 : private:
461 : using ComboBox::SetText;
462 : public:
463 : FontStyleBox( Window* pParent, const ResId& rResId );
464 : FontStyleBox( Window* pParent, WinBits nBits );
465 : virtual ~FontStyleBox();
466 :
467 : virtual void Select();
468 : virtual void LoseFocus();
469 : virtual void Modify();
470 :
471 : void SetText( const OUString& rText );
472 : void Fill( const XubString& rName, const FontList* pList );
473 :
474 : private:
475 : // declared as private because some compilers would generate the default functions
476 : FontStyleBox( const FontStyleBox& );
477 : FontStyleBox& operator =( const FontStyleBox& );
478 : };
479 :
480 0 : inline void FontStyleBox::SetText( const OUString& rText )
481 : {
482 0 : aLastStyle = rText;
483 0 : ComboBox::SetText( rText );
484 0 : }
485 :
486 : // ---------------
487 : // - FontSizeBox -
488 : // ---------------
489 :
490 : class SVT_DLLPUBLIC FontSizeBox : public MetricBox
491 : {
492 : FontInfo aFontInfo;
493 : const FontList* pFontList;
494 : sal_uInt16 nRelMin;
495 : sal_uInt16 nRelMax;
496 : sal_uInt16 nRelStep;
497 : short nPtRelMin;
498 : short nPtRelMax;
499 : short nPtRelStep;
500 : sal_Bool bRelativeMode:1,
501 : bRelative:1,
502 : bPtRelative:1,
503 : bStdSize:1;
504 :
505 : using Window::ImplInit;
506 : SVT_DLLPRIVATE void ImplInit();
507 :
508 : protected:
509 : virtual OUString CreateFieldText( sal_Int64 nValue ) const;
510 :
511 : public:
512 : FontSizeBox( Window* pParent, WinBits nWinStyle = 0 );
513 : FontSizeBox( Window* pParent, const ResId& rResId );
514 : virtual ~FontSizeBox();
515 :
516 : void Reformat();
517 : void Modify();
518 :
519 : void Fill( const FontInfo* pInfo, const FontList* pList );
520 :
521 : void EnableRelativeMode( sal_uInt16 nMin = 50, sal_uInt16 nMax = 150,
522 : sal_uInt16 nStep = 5 );
523 : void EnablePtRelativeMode( short nMin = -200, short nMax = 200,
524 : short nStep = 10 );
525 0 : sal_Bool IsRelativeMode() const { return bRelativeMode; }
526 : void SetRelative( sal_Bool bRelative = sal_False );
527 0 : sal_Bool IsRelative() const { return bRelative; }
528 0 : void SetPtRelative( sal_Bool bPtRel = sal_True )
529 0 : { bPtRelative = bPtRel; SetRelative( sal_True ); }
530 0 : sal_Bool IsPtRelative() const { return bPtRelative; }
531 :
532 : virtual void SetValue( sal_Int64 nNewValue, FieldUnit eInUnit );
533 : virtual void SetValue( sal_Int64 nNewValue );
534 : virtual sal_Int64 GetValue( FieldUnit eOutUnit ) const;
535 : virtual sal_Int64 GetValue() const;
536 : sal_Int64 GetValue( sal_uInt16 nPos, FieldUnit eOutUnit ) const;
537 :
538 : private:
539 : // declared as private because some compilers would generate the default functions
540 : FontSizeBox( const FontSizeBox& );
541 : FontSizeBox& operator =( const FontSizeBox& );
542 : };
543 :
544 : #endif // _CTRLBOX_HXX
545 :
546 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|