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 : #ifdef _CTRLBOX_CXX
168 : using Window::ImplInit;
169 : SVT_DLLPRIVATE void ImplInit();
170 : SVT_DLLPRIVATE void ImplDestroyColorEntries();
171 : #endif
172 : public:
173 : ColorListBox( Window* pParent,
174 : WinBits nWinStyle = WB_BORDER );
175 : ColorListBox( Window* pParent, const ResId& rResId );
176 : virtual ~ColorListBox();
177 :
178 : virtual void UserDraw( const UserDrawEvent& rUDEvt );
179 :
180 : using ListBox::InsertEntry;
181 : virtual sal_uInt16 InsertEntry( const XubString& rStr,
182 : sal_uInt16 nPos = LISTBOX_APPEND );
183 : virtual sal_uInt16 InsertEntry( const Color& rColor, const XubString& rStr,
184 : sal_uInt16 nPos = LISTBOX_APPEND );
185 : void InsertAutomaticEntryColor(const Color &rAutoColorValue);
186 0 : bool IsAutomaticSelected() { return !GetSelectEntryPos(); }
187 : using ListBox::RemoveEntry;
188 : virtual void RemoveEntry( sal_uInt16 nPos );
189 : virtual void Clear();
190 : void CopyEntries( const ColorListBox& rBox );
191 :
192 : using ListBox::GetEntryPos;
193 : virtual sal_uInt16 GetEntryPos( const Color& rColor ) const;
194 : virtual Color GetEntryColor( sal_uInt16 nPos ) const;
195 : Size GetImageSize() const { return aImageSize; }
196 :
197 0 : void SelectEntry( const XubString& rStr, sal_Bool bSelect = sal_True )
198 0 : { ListBox::SelectEntry( rStr, bSelect ); }
199 : void SelectEntry( const Color& rColor, sal_Bool bSelect = sal_True );
200 0 : XubString GetSelectEntry( sal_uInt16 nSelIndex = 0 ) const
201 0 : { return ListBox::GetSelectEntry( nSelIndex ); }
202 : Color GetSelectEntryColor( sal_uInt16 nSelIndex = 0 ) const;
203 0 : sal_Bool IsEntrySelected( const XubString& rStr ) const
204 0 : { return ListBox::IsEntrySelected( rStr ); }
205 :
206 : sal_Bool IsEntrySelected( const Color& rColor ) const;
207 :
208 : private:
209 : // declared as private because some compilers would generate the default functions
210 : ColorListBox( const ColorListBox& );
211 : ColorListBox& operator =( const ColorListBox& );
212 :
213 : void SetEntryData( sal_uInt16 nPos, void* pNewData );
214 : void* GetEntryData( sal_uInt16 nPos ) const;
215 : };
216 :
217 0 : inline void ColorListBox::SelectEntry( const Color& rColor, sal_Bool bSelect )
218 : {
219 0 : sal_uInt16 nPos = GetEntryPos( rColor );
220 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
221 0 : ListBox::SelectEntryPos( nPos, bSelect );
222 0 : }
223 :
224 0 : inline sal_Bool ColorListBox::IsEntrySelected( const Color& rColor ) const
225 : {
226 0 : sal_uInt16 nPos = GetEntryPos( rColor );
227 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
228 0 : return IsEntryPosSelected( nPos );
229 : else
230 0 : return sal_False;
231 : }
232 :
233 0 : inline Color ColorListBox::GetSelectEntryColor( sal_uInt16 nSelIndex ) const
234 : {
235 0 : sal_uInt16 nPos = GetSelectEntryPos( nSelIndex );
236 0 : Color aColor;
237 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
238 0 : aColor = GetEntryColor( nPos );
239 0 : return aColor;
240 : }
241 :
242 : // ---------------
243 : // - LineListBox -
244 : // ---------------
245 :
246 : /**
247 : Class computing border widths shared between Line style listbox and the
248 : SvxBorderLine implementation.
249 :
250 : This class doesn't know anything about units: it all depends on the different
251 : values set. A border is composed of 2 lines separated by a gap. The computed
252 : widths are the ones of each line and the gap and they can either be fix or vary.
253 :
254 : The #m_nflags member will define which widths will vary (value 0 means that all
255 : widths are fixed). The available flags are:
256 : - CHANGE_LINE1
257 : - CHANGE_LINE2
258 : - CHANGE_DIST
259 :
260 : For each line, the rate member is used as a multiplication factor is the width
261 : isn't fixed. Otherwise it is the width in the unit expected by the client code.
262 : */
263 : class SVT_DLLPUBLIC BorderWidthImpl
264 : {
265 : sal_uInt16 m_nFlags;
266 : double m_nRate1;
267 : double m_nRate2;
268 : double m_nRateGap;
269 :
270 : public:
271 :
272 : BorderWidthImpl( sal_uInt16 nFlags = CHANGE_LINE1, double nRate1 = 0.0,
273 : double nRate2 = 0.0, double nRateGap = 0.0 );
274 :
275 : BorderWidthImpl& operator= ( const BorderWidthImpl& r );
276 : bool operator== ( const BorderWidthImpl& r ) const;
277 :
278 : long GetLine1 ( long nWidth ) const;
279 : long GetLine2( long nWidth ) const;
280 : long GetGap( long nWidth ) const;
281 :
282 : long GuessWidth( long nLine1, long nLine2, long nGap );
283 :
284 3225 : bool IsEmpty( ) const { return (0 == m_nRate1) && (0 == m_nRate2); }
285 1052 : bool IsDouble( ) const { return (0 != m_nRate1) && (0 != m_nRate2); }
286 : };
287 :
288 0 : SVT_DLLPUBLIC inline Color sameColor( Color rMain )
289 : {
290 0 : return rMain;
291 : }
292 :
293 0 : SVT_DLLPUBLIC inline Color sameDistColor( Color /*rMain*/, Color rDefault )
294 : {
295 0 : return rDefault;
296 : }
297 :
298 :
299 : class SVT_DLLPUBLIC LineListBox : public ListBox
300 : {
301 : ImpLineList* pLineList;
302 : long m_nWidth;
303 : XubString m_sNone;
304 :
305 : VirtualDevice aVirDev;
306 : Size aTxtSize;
307 : Color aColor;
308 : Color maPaintCol;
309 : FieldUnit eUnit;
310 : FieldUnit eSourceUnit;
311 :
312 : SVT_DLLPRIVATE void ImpGetLine( long nLine1, long nLine2, long nDistance,
313 : Color nColor1, Color nColor2, Color nColorDist,
314 : sal_uInt16 nStyle, Bitmap& rBmp );
315 : using Window::ImplInit;
316 : SVT_DLLPRIVATE void ImplInit();
317 : sal_Bool UpdatePaintLineColor( void ); // returns sal_True if maPaintCol has changed
318 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
319 :
320 : void UpdateEntries( long nOldWidth );
321 : sal_uInt16 GetStylePos( sal_uInt16 nListPos, long nWidth );
322 :
323 : public:
324 : LineListBox( Window* pParent, WinBits nWinStyle = WB_BORDER );
325 : LineListBox( Window* pParent, const ResId& rResId );
326 : virtual ~LineListBox();
327 :
328 : /** Set the width in Twips */
329 : void SetWidth( long nWidth );
330 : void SetNone( const XubString& sNone );
331 :
332 : using ListBox::InsertEntry;
333 : virtual sal_uInt16 InsertEntry( const XubString& rStr, sal_uInt16 nPos = LISTBOX_APPEND );
334 : /** Insert a listbox entry with all widths in Twips. */
335 : void InsertEntry( BorderWidthImpl aWidthImpl,
336 : sal_uInt16 nStyle, long nMinWidth = 0,
337 : Color (*pColor1Fn)(Color) = &sameColor,
338 : Color (*pColor2Fn)( Color ) = &sameColor,
339 : Color (*pColorDistFn)( Color, Color ) = &sameDistColor );
340 :
341 : using ListBox::RemoveEntry;
342 : virtual void RemoveEntry( sal_uInt16 nPos );
343 : virtual void Clear();
344 :
345 : using ListBox::GetEntryPos;
346 : virtual sal_uInt16 GetEntryPos( sal_uInt16 nStyle = STYLE_SOLID ) const;
347 : sal_uInt16 GetEntryStyle( sal_uInt16 nPos ) const;
348 :
349 0 : void SelectEntry( const XubString& rStr, sal_Bool bSelect = sal_True ) { ListBox::SelectEntry( rStr, bSelect ); }
350 : void SelectEntry( sal_uInt16 nStyle = STYLE_SOLID, sal_Bool bSelect = sal_True );
351 : sal_uInt16 GetSelectEntryStyle( sal_uInt16 nSelIndex = 0 ) const;
352 0 : inline sal_Bool IsEntrySelected( const XubString& rStr ) const { return ListBox::IsEntrySelected( rStr ); }
353 : sal_Bool IsEntrySelected( sal_uInt16 nStyle1 = STYLE_SOLID ) const;
354 :
355 0 : inline void SetUnit( FieldUnit eNewUnit ) { eUnit = eNewUnit; }
356 : inline FieldUnit GetUnit() const { return eUnit; }
357 0 : inline void SetSourceUnit( FieldUnit eNewUnit ) { eSourceUnit = eNewUnit; }
358 : inline FieldUnit GetSourceUnit() const { return eSourceUnit; }
359 :
360 : void SetColor( const Color& rColor );
361 : inline Color GetColor( void ) const;
362 :
363 : protected:
364 :
365 : inline const Color& GetPaintColor( void ) const;
366 : Color GetColorLine1( sal_uInt16 nPos = 0 );
367 : Color GetColorLine2( sal_uInt16 nPos = 0 );
368 : Color GetColorDist( sal_uInt16 nPos = 0 );
369 :
370 : private:
371 : // declared as private because some compilers would generate the default methods
372 : LineListBox( const LineListBox& );
373 : LineListBox& operator =( const LineListBox& );
374 : void SetEntryData( sal_uInt16 nPos, void* pNewData );
375 : void* GetEntryData( sal_uInt16 nPos ) const;
376 : };
377 :
378 : inline sal_Bool LineListBox::IsEntrySelected( sal_uInt16 nStyle ) const
379 : {
380 : sal_uInt16 nPos = GetEntryPos( nStyle );
381 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
382 : return IsEntryPosSelected( nPos );
383 : else
384 : return sal_False;
385 : }
386 :
387 0 : inline void LineListBox::SetColor( const Color& rColor )
388 : {
389 0 : aColor = rColor;
390 :
391 0 : UpdateEntries( m_nWidth );
392 0 : }
393 :
394 0 : inline Color LineListBox::GetColor( void ) const
395 : {
396 0 : return aColor;
397 : }
398 :
399 0 : const Color& LineListBox::GetPaintColor( void ) const
400 : {
401 0 : return maPaintCol;
402 : }
403 :
404 0 : inline void LineListBox::SetWidth( long nWidth )
405 : {
406 0 : long nOldWidth = m_nWidth;
407 0 : m_nWidth = nWidth;
408 0 : UpdateEntries( nOldWidth );
409 0 : }
410 :
411 0 : inline void LineListBox::SetNone( const XubString& sNone )
412 : {
413 0 : m_sNone = sNone;
414 0 : }
415 :
416 : // ---------------
417 : // - FontNameBox -
418 : // ---------------
419 :
420 : class SVT_DLLPUBLIC FontNameBox : public ComboBox
421 : {
422 : private:
423 : ImplFontList* mpFontList;
424 : sal_Bool mbWYSIWYG;
425 : String maFontMRUEntriesFile;
426 :
427 : #ifdef _CTRLBOX_CXX
428 : SVT_DLLPRIVATE void ImplCalcUserItemSize();
429 : SVT_DLLPRIVATE void ImplDestroyFontList();
430 : #endif
431 :
432 : protected:
433 : void LoadMRUEntries( const String& aFontMRUEntriesFile, sal_Unicode cSep = ';' );
434 : void SaveMRUEntries( const String& aFontMRUEntriesFile, sal_Unicode cSep = ';' ) const;
435 : public:
436 : FontNameBox( Window* pParent,
437 : WinBits nWinStyle = WB_SORT );
438 : FontNameBox( Window* pParent, const ResId& rResId );
439 : virtual ~FontNameBox();
440 :
441 : virtual void UserDraw( const UserDrawEvent& rUDEvt );
442 :
443 : void Fill( const FontList* pList );
444 :
445 : void EnableWYSIWYG( sal_Bool bEnable = sal_True );
446 : sal_Bool IsWYSIWYGEnabled() const { return mbWYSIWYG; }
447 :
448 : private:
449 : void InitFontMRUEntriesFile();
450 :
451 : // declared as private because some compilers would generate the default functions
452 : FontNameBox( const FontNameBox& );
453 : FontNameBox& operator =( const FontNameBox& );
454 : };
455 :
456 : // ----------------
457 : // - FontStyleBox -
458 : // ----------------
459 :
460 : class SVT_DLLPUBLIC FontStyleBox : public ComboBox
461 : {
462 : XubString aLastStyle;
463 :
464 : private:
465 : using ComboBox::SetText;
466 : public:
467 : FontStyleBox( Window* pParent, const ResId& rResId );
468 : FontStyleBox( Window* pParent, WinBits nBits );
469 : virtual ~FontStyleBox();
470 :
471 : virtual void Select();
472 : virtual void LoseFocus();
473 : virtual void Modify();
474 :
475 : void SetText( const XubString& rText );
476 : void Fill( const XubString& rName, const FontList* pList );
477 :
478 : private:
479 : // declared as private because some compilers would generate the default functions
480 : FontStyleBox( const FontStyleBox& );
481 : FontStyleBox& operator =( const FontStyleBox& );
482 : };
483 :
484 0 : inline void FontStyleBox::SetText( const XubString& rText )
485 : {
486 0 : aLastStyle = rText;
487 0 : ComboBox::SetText( rText );
488 0 : }
489 :
490 : // ---------------
491 : // - FontSizeBox -
492 : // ---------------
493 :
494 : class SVT_DLLPUBLIC FontSizeBox : public MetricBox
495 : {
496 : FontInfo aFontInfo;
497 : const FontList* pFontList;
498 : sal_uInt16 nRelMin;
499 : sal_uInt16 nRelMax;
500 : sal_uInt16 nRelStep;
501 : short nPtRelMin;
502 : short nPtRelMax;
503 : short nPtRelStep;
504 : sal_Bool bRelativeMode:1,
505 : bRelative:1,
506 : bPtRelative:1,
507 : bStdSize:1;
508 :
509 : #ifdef _CTRLBOX_CXX
510 : using Window::ImplInit;
511 : SVT_DLLPRIVATE void ImplInit();
512 : #endif
513 :
514 : protected:
515 : virtual XubString CreateFieldText( sal_Int64 nValue ) const;
516 :
517 : public:
518 : FontSizeBox( Window* pParent, WinBits nWinStyle = 0 );
519 : FontSizeBox( Window* pParent, const ResId& rResId );
520 : virtual ~FontSizeBox();
521 :
522 : void Reformat();
523 : void Modify();
524 :
525 : void Fill( const FontInfo* pInfo, const FontList* pList );
526 :
527 : void EnableRelativeMode( sal_uInt16 nMin = 50, sal_uInt16 nMax = 150,
528 : sal_uInt16 nStep = 5 );
529 : void EnablePtRelativeMode( short nMin = -200, short nMax = 200,
530 : short nStep = 10 );
531 0 : sal_Bool IsRelativeMode() const { return bRelativeMode; }
532 : void SetRelative( sal_Bool bRelative = sal_False );
533 0 : sal_Bool IsRelative() const { return bRelative; }
534 0 : void SetPtRelative( sal_Bool bPtRel = sal_True )
535 0 : { bPtRelative = bPtRel; SetRelative( sal_True ); }
536 0 : sal_Bool IsPtRelative() const { return bPtRelative; }
537 :
538 : virtual void SetValue( sal_Int64 nNewValue, FieldUnit eInUnit );
539 : virtual void SetValue( sal_Int64 nNewValue );
540 : virtual sal_Int64 GetValue( FieldUnit eOutUnit ) const;
541 : virtual sal_Int64 GetValue() const;
542 :
543 : private:
544 : // declared as private because some compilers would generate the default functions
545 : FontSizeBox( const FontSizeBox& );
546 : FontSizeBox& operator =( const FontSizeBox& );
547 : };
548 :
549 : #endif // _CTRLBOX_HXX
550 :
551 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|