Update ooo320-m1
[ooovba.git] / svx / source / dialog / svxbmpnumvalueset.cxx
blob5f89bbda4e7026249146e846913f7a8a80a35478
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svxbmpnumvalueset.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/dialmgr.hxx>
34 #ifndef _SVX_DIALOGS_HRC
35 #include <svx/dialogs.hrc>
36 #endif
37 #include <tools/shl.hxx>
38 #include <i18npool/mslangid.hxx>
39 #include <svtools/valueset.hxx>
40 #include <svtools/languageoptions.hxx>
41 #ifndef _SVX_HELPID_HRC
42 #include <helpid.hrc>
43 #endif
44 #include <svx/numitem.hxx>
45 #include <svtools/eitem.hxx>
46 #include <vcl/svapp.hxx>
47 #include <gallery.hxx>
48 #include <svtools/urihelper.hxx>
49 #include <svx/brshitem.hxx>
50 #include <svtools/intitem.hxx>
51 #include <sfx2/objsh.hxx>
52 #include <vcl/graph.hxx>
53 #include <vcl/msgbox.hxx>
54 #include <flstitem.hxx>
55 #include <dlgutil.hxx>
56 #ifndef _XTABLE_HXX //autogen
58 #include <svx/xtable.hxx>
59 #endif
60 #include <drawitem.hxx>
61 #include <numvset.hxx>
62 #include <htmlmode.hxx>
63 #include <svtools/pathoptions.hxx>
64 #include <svtools/ctrltool.hxx>
65 #include <unolingu.hxx>
66 #include <com/sun/star/style/NumberingType.hpp>
67 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
68 #include <com/sun/star/container/XIndexAccess.hpp>
69 #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
70 #include <com/sun/star/text/XNumberingFormatter.hpp>
71 #include <com/sun/star/beans/PropertyValue.hpp>
72 #include <comphelper/processfactory.hxx>
73 #include <com/sun/star/text/XNumberingTypeInfo.hpp>
75 #include <algorithm>
76 #include "opengrf.hxx"
78 using namespace com::sun::star::uno;
79 using namespace com::sun::star::beans;
80 using namespace com::sun::star::lang;
81 using namespace com::sun::star::i18n;
82 using namespace com::sun::star::text;
83 using namespace com::sun::star::container;
84 using namespace com::sun::star::style;
85 using rtl::OUString;
87 #define C2U(cChar) OUString::createFromAscii(cChar)
88 #define NUM_PAGETYPE_BULLET 0
89 #define NUM_PAGETYPE_SINGLENUM 1
90 #define NUM_PAGETYPE_NUM 2
91 #define NUM_PAGETYPE_BMP 3
92 #define PAGETYPE_USER_START 10
94 #define SHOW_NUMBERING 0
95 #define SHOW_BULLET 1
96 #define SHOW_BITMAP 2
98 #define MAX_BMP_WIDTH 16
99 #define MAX_BMP_HEIGHT 16
101 static const sal_Char cNumberingType[] = "NumberingType";
102 static const sal_Char cValue[] = "Value";
103 static const sal_Char cParentNumbering[] = "ParentNumbering";
104 static const sal_Char cPrefix[] = "Prefix";
105 static const sal_Char cSuffix[] = "Suffix";
106 static const sal_Char cBulletChar[] = "BulletChar";
107 static const sal_Char cBulletFontName[] = "BulletFontName";
109 /* -----------------28.10.98 08:32-------------------
111 * --------------------------------------------------*/
112 // Die Auswahl an Bullets aus den StarSymbol
113 static const sal_Unicode aBulletTypes[] =
115 0x2022,
116 0x25cf,
117 0xe00c,
118 0xe00a,
119 0x2794,
120 0x27a2,
121 0x2717,
122 0x2714
125 static Font& lcl_GetDefaultBulletFont()
127 static BOOL bInit = 0;
128 static Font aDefBulletFont( UniString::CreateFromAscii(
129 RTL_CONSTASCII_STRINGPARAM( "StarSymbol" ) ),
130 String(), Size( 0, 14 ) );
131 if(!bInit)
133 aDefBulletFont.SetCharSet( RTL_TEXTENCODING_SYMBOL );
134 aDefBulletFont.SetFamily( FAMILY_DONTKNOW );
135 aDefBulletFont.SetPitch( PITCH_DONTKNOW );
136 aDefBulletFont.SetWeight( WEIGHT_DONTKNOW );
137 aDefBulletFont.SetTransparent( TRUE );
138 bInit = TRUE;
140 return aDefBulletFont;
143 static void lcl_PaintLevel(OutputDevice* pVDev, sal_Int16 nNumberingType,
144 const OUString& rBulletChar, const OUString& rText, const OUString& rFontName,
145 Point& rLeft, Font& rRuleFont, const Font& rTextFont)
148 if(NumberingType::CHAR_SPECIAL == nNumberingType )
150 rRuleFont.SetStyleName(rFontName);
151 pVDev->SetFont(rRuleFont);
152 pVDev->DrawText(rLeft, rBulletChar);
153 rLeft.X() += pVDev->GetTextWidth(rBulletChar);
155 else
157 pVDev->SetFont(rTextFont);
158 pVDev->DrawText(rLeft, rText);
159 rLeft.X() += pVDev->GetTextWidth(rText);
162 void SvxNumValueSet::UserDraw( const UserDrawEvent& rUDEvt )
164 static USHORT __READONLY_DATA aLinesArr[] =
166 15, 10,
167 20, 30,
168 25, 50,
169 30, 70,
170 35, 90, // up to here line positions
171 05, 10, // character positions
172 10, 30,
173 15, 50,
174 20, 70,
175 25, 90,
178 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
179 const Color aBackColor = rStyleSettings.GetFieldColor();
180 const Color aTextColor = rStyleSettings.GetFieldTextColor();
182 OutputDevice* pDev = rUDEvt.GetDevice();
183 Rectangle aRect = rUDEvt.GetRect();
184 USHORT nItemId = rUDEvt.GetItemId();
185 long nRectWidth = aRect.GetWidth();
186 long nRectHeight = aRect.GetHeight();
187 Size aRectSize(nRectWidth, aRect.GetHeight());
188 Point aBLPos = aRect.TopLeft();
189 Font aOldFont = pDev->GetFont();
190 Color aOldColor = pDev->GetLineColor();
191 pDev->SetLineColor(aTextColor);
192 Font aFont(OutputDevice::GetDefaultFont(
193 DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE));
195 Size aSize = aFont.GetSize();
197 Font aRuleFont( lcl_GetDefaultBulletFont() );
198 aSize.Height() = nRectHeight/6;
199 aRuleFont.SetSize(aSize);
200 aRuleFont.SetColor(aTextColor);
201 aRuleFont.SetFillColor(aBackColor);
202 if(nPageType == NUM_PAGETYPE_BULLET)
203 aFont = aRuleFont;
204 else if(nPageType == NUM_PAGETYPE_NUM)
206 aSize.Height() = nRectHeight/8;
208 aFont.SetColor(aTextColor);
209 aFont.SetFillColor(aBackColor);
210 aFont.SetSize( aSize );
211 pDev->SetFont(aFont);
213 if(!pVDev)
215 // Die Linien werden nur einmalig in das VirtualDevice gepainted
216 // nur die Gliederungspage bekommt es aktuell
217 pVDev = new VirtualDevice(*pDev);
218 pVDev->SetMapMode(pDev->GetMapMode());
219 pVDev->EnableRTL( IsRTLEnabled() );
220 pVDev->SetOutputSize( aRectSize );
221 aOrgRect = aRect;
222 pVDev->SetFillColor( aBackColor );
223 pVDev->DrawRect(aOrgRect);
225 if(aBackColor == aLineColor)
226 aLineColor.Invert();
227 pVDev->SetLineColor(aLineColor);
228 // Linien nur einmalig Zeichnen
229 if(nPageType != NUM_PAGETYPE_NUM)
231 Point aStart(aBLPos.X() + nRectWidth *25 / 100,0);
232 Point aEnd(aBLPos.X() + nRectWidth * 9 / 10,0);
233 for( USHORT i = 11; i < 100; i += 33)
235 aStart.Y() = aEnd.Y() = aBLPos.Y() + nRectHeight * i / 100;
236 pVDev->DrawLine(aStart, aEnd);
237 aStart.Y() = aEnd.Y() = aBLPos.Y() + nRectHeight * (i + 11) / 100;
238 pVDev->DrawLine(aStart, aEnd);
242 pDev->DrawOutDev( aRect.TopLeft(), aRectSize,
243 aOrgRect.TopLeft(), aRectSize,
244 *pVDev );
245 // jetzt kommt der Text
246 const OUString sValue(C2U(cValue));
247 if( NUM_PAGETYPE_SINGLENUM == nPageType ||
248 NUM_PAGETYPE_BULLET == nPageType )
250 Point aStart(aBLPos.X() + nRectWidth / 9,0);
251 for( USHORT i = 0; i < 3; i++ )
253 USHORT nY = 11 + i * 33;
254 aStart.Y() = aBLPos.Y() + nRectHeight * nY / 100;
255 String sText;
256 if(nPageType == NUM_PAGETYPE_BULLET)
258 sText = aBulletTypes[nItemId - 1];
259 aStart.Y() -= pDev->GetTextHeight()/2;
260 aStart.X() = aBLPos.X() + 5;
262 else
264 if(xFormatter.is() && aNumSettings.getLength() > nItemId - 1)
266 Sequence<PropertyValue> aLevel = aNumSettings.getConstArray()[nItemId - 1];
269 aLevel.realloc(aLevel.getLength() + 1);
270 PropertyValue& rValue = aLevel.getArray()[aLevel.getLength() - 1];
271 rValue.Name = sValue;
272 rValue.Value <<= (sal_Int32)(i + 1);
273 sText = xFormatter->makeNumberingString( aLevel, aLocale );
275 catch(Exception&)
277 DBG_ERROR("Exception in DefaultNumberingProvider::makeNumberingString");
280 // knapp neben dem linken Rand beginnen
281 aStart.X() = aBLPos.X() + 2;
282 aStart.Y() -= pDev->GetTextHeight()/2;
284 pDev->DrawText(aStart, sText);
287 else if(NUM_PAGETYPE_NUM == nPageType )
289 // Outline numbering has to be painted into the virtual device
290 // to get correct lines
291 // has to be made again
292 pVDev->DrawRect(aOrgRect);
293 long nStartX = aOrgRect.TopLeft().X();
294 long nStartY = aOrgRect.TopLeft().Y();
296 if(xFormatter.is() && aOutlineSettings.getLength() > nItemId - 1)
298 Reference<XIndexAccess> xLevel = aOutlineSettings.getArray()[nItemId - 1];
301 OUString sLevelTexts[5];
302 OUString sFontNames[5];
303 OUString sBulletChars[5];
304 sal_Int16 aNumberingTypes[5];
305 OUString sPrefixes[5];
306 OUString sSuffixes[5];
307 sal_Int16 aParentNumberings[5];
309 sal_Int32 nLevelCount = xLevel->getCount();
310 if(nLevelCount > 5)
311 nLevelCount = 5;
312 for( sal_Int32 i = 0; i < nLevelCount && i < 5; i++)
314 long nTop = nStartY + nRectHeight * (aLinesArr[2 * i + 11])/100 ;
315 Point aLeft(nStartX + nRectWidth * (aLinesArr[2 * i + 10])/ 100, nTop );
317 Any aLevelAny = xLevel->getByIndex(i);
318 Sequence<PropertyValue> aLevel;
319 aLevelAny >>= aLevel;
320 const PropertyValue* pValues = aLevel.getConstArray();
321 aNumberingTypes[i] = 0;
322 for(sal_Int32 nProperty = 0; nProperty < aLevel.getLength() - 1; nProperty++)
324 if(pValues[nProperty].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cNumberingType)))
325 pValues[nProperty].Value >>= aNumberingTypes[i];
326 else if(pValues[nProperty].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cBulletFontName)))
327 pValues[nProperty].Value >>= sFontNames[i];
328 else if(pValues[nProperty].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cBulletChar)))
329 pValues[nProperty].Value >>= sBulletChars[i];
330 else if(pValues[nProperty].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cPrefix)))
331 pValues[nProperty].Value >>= sPrefixes[i];
332 else if(pValues[nProperty].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cSuffix)))
333 pValues[nProperty].Value >>= sSuffixes[i];
334 else if(pValues[nProperty].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cParentNumbering)))
335 pValues[nProperty].Value >>= aParentNumberings[i];
337 Sequence< PropertyValue > aProperties(2);
338 PropertyValue* pProperties = aProperties.getArray();
339 pProperties[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberingType"));
340 pProperties[0].Value <<= aNumberingTypes[i];
341 pProperties[1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Value"));
342 pProperties[1].Value <<= (sal_Int32)1;
345 sLevelTexts[i] = xFormatter->makeNumberingString( aProperties, aLocale );
347 catch(Exception&)
349 DBG_ERROR("Exception in DefaultNumberingProvider::makeNumberingString");
352 aLeft.Y() -= (pDev->GetTextHeight()/2);
353 if(sPrefixes[i].getLength() &&
354 !sPrefixes[i].equalsAsciiL(" ", 1) &&
355 sPrefixes[i].getStr()[0] != 0)
357 pVDev->SetFont(aFont);
358 pVDev->DrawText(aLeft, sPrefixes[i]);
359 aLeft.X() += pDev->GetTextWidth(sPrefixes[i]);
361 if(aParentNumberings[i])
363 //insert old numberings here
364 sal_Int32 nStartLevel = std::min((sal_Int32)aParentNumberings[i], i);
365 for(sal_Int32 nParentLevel = i - nStartLevel; nParentLevel < i; nParentLevel++)
367 OUString sTmp(sLevelTexts[nParentLevel]);
368 sTmp += C2U(".");
369 lcl_PaintLevel(pVDev,
370 aNumberingTypes[nParentLevel],
371 sBulletChars[nParentLevel],
372 sTmp,
373 sFontNames[nParentLevel],
374 aLeft,
375 aRuleFont,
376 aFont);
379 lcl_PaintLevel(pVDev,
380 aNumberingTypes[i],
381 sBulletChars[i],
382 sLevelTexts[i],
383 sFontNames[i],
384 aLeft,
385 aRuleFont,
386 aFont);
387 if(sSuffixes[i].getLength()&&
388 !sSuffixes[i].equalsAsciiL(" ", 1) &&
389 sSuffixes[i].getStr()[0] != 0)
391 pVDev->SetFont(aFont);
392 pVDev->DrawText(aLeft, sSuffixes[i]);
393 aLeft.X() += pDev->GetTextWidth(sSuffixes[i]);
396 long nLineTop = nStartY + nRectHeight * aLinesArr[2 * i + 1]/100 ;
397 Point aLineLeft(aLeft.X() /*+ nStartX + nRectWidth * aLinesArr[2 * i]/ 100*/, nLineTop );
398 Point aLineRight(nStartX + nRectWidth * 90 /100, nLineTop );
399 pVDev->DrawLine(aLineLeft, aLineRight);
403 #ifdef DBG_UTIL
404 catch(Exception&)
406 static sal_Bool bAssert = FALSE;
407 if(!bAssert)
409 DBG_ERROR("exception in ::UserDraw");
410 bAssert = sal_True;
413 #else
414 catch(Exception&)
417 #endif
419 pDev->DrawOutDev( aRect.TopLeft(), aRectSize,
420 aOrgRect.TopLeft(), aRectSize,
421 *pVDev );
424 pDev->SetFont(aOldFont);
425 pDev->SetLineColor(aOldColor);
428 /**************************************************************************/
429 /* */
430 /* */
431 /**************************************************************************/
433 SvxNumValueSet::SvxNumValueSet( Window* pParent, const ResId& rResId, USHORT nType ) :
435 ValueSet( pParent, rResId ),
437 aLineColor ( COL_LIGHTGRAY ),
438 nPageType ( nType ),
439 bHTMLMode ( FALSE ),
440 pVDev ( NULL )
442 SetColCount( 4 );
443 SetLineCount( 2 );
444 SetStyle( GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER );
445 if(NUM_PAGETYPE_BULLET == nType)
447 for ( USHORT i = 0; i < 8; i++ )
449 InsertItem( i + 1, i );
450 SetItemText( i + 1, SVX_RESSTR( RID_SVXSTR_BULLET_DESCRIPTIONS + i ) );
455 /*-----------------08.02.97 12.38-------------------
457 --------------------------------------------------*/
459 SvxNumValueSet::~SvxNumValueSet()
461 delete pVDev;
463 /* -----------------------------30.01.01 16:24--------------------------------
465 ---------------------------------------------------------------------------*/
466 void SvxNumValueSet::SetNumberingSettings(
467 const Sequence<Sequence<PropertyValue> >& aNum,
468 Reference<XNumberingFormatter>& xFormat,
469 const Locale& rLocale )
471 aNumSettings = aNum;
472 xFormatter = xFormat;
473 aLocale = rLocale;
474 if(aNum.getLength() > 8)
475 SetStyle( GetStyle()|WB_VSCROLL);
476 for ( USHORT i = 0; i < aNum.getLength(); i++ )
478 InsertItem( i + 1, i );
479 if( i < 8 )
480 SetItemText( i + 1, SVX_RESSTR( RID_SVXSTR_SINGLENUM_DESCRIPTIONS + i ));
483 /* -----------------------------31.01.01 09:50--------------------------------
485 ---------------------------------------------------------------------------*/
486 void SvxNumValueSet::SetOutlineNumberingSettings(
487 Sequence<Reference<XIndexAccess> >& rOutline,
488 Reference<XNumberingFormatter>& xFormat,
489 const Locale& rLocale)
491 aOutlineSettings = rOutline;
492 xFormatter = xFormat;
493 aLocale = rLocale;
494 if(aOutlineSettings.getLength() > 8)
495 SetStyle( GetStyle() | WB_VSCROLL );
496 for ( sal_uInt16 i = 0; i < aOutlineSettings.getLength(); i++ )
498 InsertItem( i + 1, i );
499 if( i < 8 )
500 SetItemText( i + 1, SVX_RESSTR( RID_SVXSTR_OUTLINENUM_DESCRIPTIONS + i ));
504 SvxBmpNumValueSet::SvxBmpNumValueSet( Window* pParent, const ResId& rResId/*, const List& rStrNames*/ ) :
506 SvxNumValueSet( pParent, rResId, NUM_PAGETYPE_BMP ),
507 // rStrList ( rStrNames ),
508 bGrfNotFound( FALSE )
511 GalleryExplorer::BeginLocking(GALLERY_THEME_BULLETS);
512 SetStyle( GetStyle() | WB_VSCROLL );
513 SetLineCount( 3 );
514 aFormatTimer.SetTimeout(300);
515 aFormatTimer.SetTimeoutHdl(LINK(this, SvxBmpNumValueSet, FormatHdl_Impl));
518 /*-----------------13.02.97 09.41-------------------
520 --------------------------------------------------*/
522 SvxBmpNumValueSet::~SvxBmpNumValueSet()
524 GalleryExplorer::EndLocking(GALLERY_THEME_BULLETS);
525 aFormatTimer.Stop();
527 /*-----------------13.02.97 09.41-------------------
529 --------------------------------------------------*/
531 void SvxBmpNumValueSet::UserDraw( const UserDrawEvent& rUDEvt )
533 SvxNumValueSet::UserDraw(rUDEvt);
535 Rectangle aRect = rUDEvt.GetRect();
536 OutputDevice* pDev = rUDEvt.GetDevice();
537 USHORT nItemId = rUDEvt.GetItemId();
538 Point aBLPos = aRect.TopLeft();
540 int nRectHeight = aRect.GetHeight();
541 Size aSize(nRectHeight/8, nRectHeight/8);
543 Graphic aGraphic;
544 if(!GalleryExplorer::GetGraphicObj( GALLERY_THEME_BULLETS, nItemId - 1,
545 &aGraphic, NULL))
547 bGrfNotFound = TRUE;
549 else
551 Point aPos(aBLPos.X() + 5, 0);
552 for( USHORT i = 0; i < 3; i++ )
554 USHORT nY = 11 + i * 33;
555 aPos.Y() = aBLPos.Y() + nRectHeight * nY / 100;
556 aGraphic.Draw( pDev, aPos, aSize );
561 /*-----------------14.02.97 07.34-------------------
563 --------------------------------------------------*/
565 IMPL_LINK(SvxBmpNumValueSet, FormatHdl_Impl, Timer*, EMPTYARG)
567 // nur, wenn eine Grafik nicht da war, muss formatiert werden
568 if(bGrfNotFound)
570 bGrfNotFound = FALSE;
571 Format();
573 Invalidate();
574 return 0;