Update ooo320-m1
[ooovba.git] / sw / source / ui / chrdlg / drpcps.cxx
blob37913b4da4004a36e485c610a7e2b6ac38e7ebe1
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: drpcps.cxx,v $
10 * $Revision: 1.22 $
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_sw.hxx"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
35 #endif
39 #include <hintids.hxx>
40 #define _SVSTDARR_STRINGSDTOR
41 #define _SVSTDARR_STRINGSISORTDTOR
42 #include <svtools/svstdarr.hxx>
44 #include "cmdid.h"
45 #include "swmodule.hxx"
46 #include "view.hxx"
47 #include "wrtsh.hxx"
48 #include "globals.hrc"
51 #ifndef _METRIC_HXX //autogen
52 #include <vcl/metric.hxx>
53 #endif
54 #include <svtools/stritem.hxx>
55 #include <svx/fontitem.hxx>
56 #include <svx/htmlmode.hxx>
57 #include <sfx2/objsh.hxx>
58 #include <svx/svxfont.hxx>
59 #include <vcl/print.hxx>
60 #include <sfx2/printer.hxx>
61 #ifndef _COM_SUN_STAR_I18N_SCRIPTTYPE_HDL_
62 #include <com/sun/star/i18n/ScriptType.hdl>
63 #endif
64 #include <svx/scripttypeitem.hxx>
65 #include <com/sun/star/i18n/XBreakIterator.hpp>
66 #include <comphelper/processfactory.hxx>
68 #define _SVSTDARR_XUB_STRLEN
69 #define _SVSTDARR_USHORTS
70 #define _SVSTDARR_ULONGS
71 #include <svtools/svstdarr.hxx>
73 #include "charatr.hxx"
74 #include "viewopt.hxx"
75 #include "drpcps.hxx"
76 #include "paratr.hxx"
77 #include "uitool.hxx"
78 #include "charfmt.hxx"
80 #include "chrdlg.hrc"
81 #include "drpcps.hrc"
84 using namespace ::com::sun::star;
85 using namespace ::com::sun::star::uno;
86 using namespace ::com::sun::star::lang;
87 //using namespace i18n; !using this namespace leads to mysterious conflicts with ScriptType::...!
88 // so don't use this instead of the following defines!
90 #define I18N ::com::sun::star::i18n
91 #define I18N_SCRIPTTYPE ::com::sun::star::i18n::ScriptType
93 // Globals ******************************************************************
95 static USHORT __FAR_DATA aPageRg[] = {
96 RES_PARATR_DROP, RES_PARATR_DROP,
102 // class SwDropCapsPict *****************************************************
104 class SwDropCapsPict : public Control
106 String maText;
107 String maScriptText;
108 Color maBackColor;
109 Color maTextLineColor;
110 BYTE mnLines;
111 long mnTotLineH;
112 long mnLineH;
113 long mnTextH;
114 USHORT mnDistance;
115 sal_Int32 mnLeading;
116 Printer* mpPrinter;
117 BOOL mbDelPrinter;
118 SvULongs maTextWidth;
119 SvXub_StrLens maScriptChg;
120 SvUShorts maScriptType;
121 SvxFont maFont;
122 SvxFont maCJKFont;
123 SvxFont maCTLFont;
124 Size maTextSize;
125 Reference< I18N::XBreakIterator > xBreak;
127 virtual void Paint(const Rectangle &rRect);
128 void CheckScript( void );
129 Size CalcTextSize( void );
130 inline void InitPrinter( void );
131 void _InitPrinter( void );
132 void GetFontSettings( const SwDropCapsPage& _rPage, Font& _rFont, USHORT _nWhich );
133 public:
135 SwDropCapsPict(Window *pParent, const ResId &rResId) :
136 Control(pParent, rResId), mpPrinter( NULL ), mbDelPrinter( FALSE ) {}
137 ~SwDropCapsPict();
139 void UpdatePaintSettings( void ); // also invalidates control!
141 inline void SetText( const String& rT );
142 inline void SetLines( BYTE nL );
143 inline void SetDistance( USHORT nD );
144 inline void SetValues( const String& rText, BYTE nLines, USHORT nDistance );
146 void DrawPrev( const Point& rPt );
149 inline void SwDropCapsPict::SetText( const String& rT )
151 maText = rT;
152 UpdatePaintSettings();
155 inline void SwDropCapsPict::SetLines( BYTE nL )
157 mnLines = nL;
158 UpdatePaintSettings();
161 inline void SwDropCapsPict::SetDistance( USHORT nD )
163 mnDistance = nD;
164 UpdatePaintSettings();
167 inline void SwDropCapsPict::SetValues( const String& rText, BYTE nLines, USHORT nDistance )
169 maText = rText;
170 mnLines = nLines;
171 mnDistance = nDistance;
173 UpdatePaintSettings();
176 inline void SwDropCapsPict::InitPrinter( void )
178 if( !mpPrinter )
179 _InitPrinter();
182 /****************************************************************************
183 Default-String aus Zeichenanzahl erzeugen (A, AB, ABC, ...)
184 ****************************************************************************/
187 String GetDefaultString(USHORT nChars)
189 String aStr;
190 for (USHORT i = 0; i < nChars; i++)
191 aStr += String((char) (i + 65));
192 return aStr;
195 static void calcFontHeightAnyAscent( OutputDevice* _pWin, Font& _rFont, long& _nHeight, long& _nAscent )
197 if ( !_nHeight )
199 _pWin->SetFont( _rFont );
200 FontMetric aMetric( _pWin->GetFontMetric() );
201 _nHeight = aMetric.GetLineHeight();
202 _nAscent = aMetric.GetAscent();
206 /****************************************************************************
207 Pict: Dtor
208 ****************************************************************************/
211 SwDropCapsPict::~SwDropCapsPict()
213 if( mbDelPrinter )
214 delete mpPrinter;
217 /****************************************************************************
218 Pict: Update Font
219 ****************************************************************************/
221 #define LINES 10
222 #define BORDER 2
224 void SwDropCapsPict::GetFontSettings( const SwDropCapsPage& _rPage, Font& _rFont, USHORT _nWhich )
226 SfxItemSet aSet( _rPage.rSh.GetAttrPool(), _nWhich, _nWhich);
227 _rPage.rSh.GetCurAttr(aSet);
228 SvxFontItem aFmtFont((SvxFontItem &) aSet.Get(_nWhich));
230 _rFont.SetFamily (aFmtFont.GetFamily());
231 _rFont.SetName (aFmtFont.GetFamilyName());
232 _rFont.SetPitch (aFmtFont.GetPitch());
233 _rFont.SetCharSet(aFmtFont.GetCharSet());
236 void SwDropCapsPict::UpdatePaintSettings( void )
238 maBackColor = GetSettings().GetStyleSettings().GetWindowColor();
239 maTextLineColor = Color( COL_LIGHTGRAY );
241 // gray lines
242 mnTotLineH = (GetOutputSizePixel().Height() - 2 * BORDER) / LINES;
243 mnLineH = mnTotLineH - 2;
244 mnLeading = GetFontMetric().GetIntLeading();
246 Font aFont;
248 SwDropCapsPage* pPage = ( SwDropCapsPage* ) GetParent();
249 if (!pPage->aTemplateBox.GetSelectEntryPos())
251 // Font an Absatzanfang erfragen
252 pPage->rSh.SttCrsrMove();
253 pPage->rSh.Push();
254 pPage->rSh.ClearMark();
255 SwWhichPara pSwuifnParaCurr = GetfnParaCurr();
256 SwPosPara pSwuifnParaStart = GetfnParaStart();
257 pPage->rSh.MovePara(pSwuifnParaCurr,pSwuifnParaStart);
258 // normal
259 GetFontSettings( *pPage, aFont, RES_CHRATR_FONT );
261 // CJK
262 GetFontSettings( *pPage, maCJKFont, RES_CHRATR_CJK_FONT );
264 // CTL
265 GetFontSettings( *pPage, maCTLFont, RES_CHRATR_CTL_FONT );
267 pPage->rSh.Pop(FALSE);
268 pPage->rSh.EndCrsrMove();
270 else
272 // Font an Zeichenvorlage erfragen
273 SwCharFmt *pFmt = pPage->rSh.GetCharStyle(
274 pPage->aTemplateBox.GetSelectEntry(),
275 SwWrtShell::GETSTYLE_CREATEANY );
276 ASSERT(pFmt, "Zeichenvorlage existiert nicht!");
277 const SvxFontItem &rFmtFont = pFmt->GetFont();
279 aFont.SetFamily (rFmtFont.GetFamily());
280 aFont.SetName (rFmtFont.GetFamilyName());
281 aFont.SetPitch (rFmtFont.GetPitch());
282 aFont.SetCharSet(rFmtFont.GetCharSet());
286 mnTextH = mnLines * mnTotLineH;
287 aFont.SetSize(Size(0, mnTextH));
288 maCJKFont.SetSize(Size(0, mnTextH));
289 maCTLFont.SetSize(Size(0, mnTextH));
291 aFont.SetTransparent(TRUE);
292 maCJKFont.SetTransparent(TRUE);
293 maCTLFont.SetTransparent(TRUE);
295 aFont.SetColor( SwViewOption::GetFontColor() );
296 maCJKFont.SetColor( SwViewOption::GetFontColor() );
297 maCTLFont.SetColor( SwViewOption::GetFontColor() );
299 aFont.SetFillColor(GetSettings().GetStyleSettings().GetWindowColor());
300 maCJKFont.SetFillColor(GetSettings().GetStyleSettings().GetWindowColor());
301 maCTLFont.SetFillColor(GetSettings().GetStyleSettings().GetWindowColor());
303 maCJKFont.SetSize(Size(0, maCJKFont.GetSize().Height() + mnLeading));
304 maCTLFont.SetSize(Size(0, maCTLFont.GetSize().Height() + mnLeading));
306 SetFont(aFont);
307 aFont.SetSize(Size(0, aFont.GetSize().Height() + mnLeading));
308 SetFont(aFont);
309 maFont = aFont;
311 CheckScript();
313 maTextSize = CalcTextSize();
315 Invalidate();
318 /****************************************************************************
319 Pict: Paint-Overload
320 ****************************************************************************/
322 void SwDropCapsPict::Paint(const Rectangle &/*rRect*/)
324 if (!IsVisible())
325 return;
327 SetMapMode(MapMode(MAP_PIXEL));
328 SetLineColor();
330 SetFillColor( maBackColor );
332 Size aOutputSizePixel( GetOutputSizePixel() );
334 DrawRect(Rectangle(Point(0, 0), aOutputSizePixel ));
335 SetClipRegion(Region(Rectangle(
336 Point(BORDER, BORDER),
337 Size (aOutputSizePixel.Width () - 2 * BORDER,
338 aOutputSizePixel.Height() - 2 * BORDER))));
340 ASSERT(mnLineH > 0, "So klein lassen wir uns nicht machen");
341 long nY0 = (aOutputSizePixel.Height() - (LINES * mnTotLineH)) / 2;
342 SetFillColor( maTextLineColor );
343 for (USHORT i = 0; i < LINES; ++i)
344 DrawRect(Rectangle(Point(BORDER, nY0 + i * mnTotLineH), Size(aOutputSizePixel.Width() - 2 * BORDER, mnLineH)));
346 // Texthintergrund mit Abstand (240 twips ~ 1 Zeilenhoehe)
347 ULONG lDistance = mnDistance;
348 USHORT nDistW = (USHORT) (ULONG) (((lDistance * 100) / 240) * mnTotLineH) / 100;
349 SetFillColor( maBackColor );
350 if(((SwDropCapsPage*)GetParent())->aDropCapsBox.IsChecked())
352 Size aTextSize( maTextSize );
353 aTextSize.Width() += nDistW;
354 DrawRect( Rectangle( Point( BORDER, nY0 ), aTextSize ) );
356 // Text zeichnen
357 DrawPrev( Point( BORDER, nY0 - mnLeading ) );
360 SetClipRegion();
363 void SwDropCapsPict::DrawPrev( const Point& rPt )
365 Point aPt(rPt);
366 InitPrinter();
368 Font aOldFont = mpPrinter->GetFont();
369 USHORT nScript;
370 USHORT nIdx = 0;
371 xub_StrLen nStart = 0;
372 xub_StrLen nEnd;
373 USHORT nCnt = maScriptChg.Count();
375 if( nCnt )
377 nEnd = maScriptChg[ nIdx ];
378 nScript = maScriptType[ nIdx ];
380 else
382 nEnd = maText.Len();
383 nScript = I18N_SCRIPTTYPE::LATIN;
387 SvxFont& rFnt = (nScript==I18N_SCRIPTTYPE::ASIAN) ? maCJKFont : ((nScript==I18N_SCRIPTTYPE::COMPLEX) ? maCTLFont : maFont);
388 mpPrinter->SetFont( rFnt );
390 rFnt.DrawPrev( this, mpPrinter, aPt, maText, nStart, nEnd - nStart );
392 aPt.X() += maTextWidth[ nIdx++ ];
393 if( nEnd < maText.Len() && nIdx < nCnt )
395 nStart = nEnd;
396 nEnd = maScriptChg[ nIdx ];
397 nScript = maScriptType[ nIdx ];
399 else
400 break;
402 while( TRUE );
403 mpPrinter->SetFont( aOldFont );
406 void SwDropCapsPict::CheckScript( void )
408 if( maScriptText == maText )
409 return;
411 maScriptText = maText;
412 USHORT nCnt = maScriptChg.Count();
413 if( nCnt )
415 maScriptChg.Remove( 0, nCnt );
416 maScriptType.Remove( 0, nCnt );
417 maTextWidth.Remove( 0, nCnt );
418 nCnt = 0;
420 if( !xBreak.is() )
422 Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
423 xBreak = Reference< I18N::XBreakIterator >(xMSF->createInstance(
424 ::rtl::OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) ),UNO_QUERY);
426 if( xBreak.is() )
428 USHORT nScript = xBreak->getScriptType( maText, 0 );
429 USHORT nChg = 0;
430 if( I18N_SCRIPTTYPE::WEAK == nScript )
432 nChg = (xub_StrLen)xBreak->endOfScript( maText, nChg, nScript );
433 if( nChg < maText.Len() )
434 nScript = xBreak->getScriptType( maText, nChg );
435 else
436 nScript = I18N_SCRIPTTYPE::LATIN;
441 nChg = (xub_StrLen)xBreak->endOfScript( maText, nChg, nScript );
442 maScriptChg.Insert( nChg, nCnt );
443 maScriptType.Insert( nScript, nCnt );
444 maTextWidth.Insert( ULONG(0), nCnt++ );
446 if( nChg < maText.Len() )
447 nScript = xBreak->getScriptType( maText, nChg );
448 else
449 break;
450 } while( TRUE );
454 Size SwDropCapsPict::CalcTextSize( void )
456 InitPrinter();
458 USHORT nScript;
459 USHORT nIdx = 0;
460 xub_StrLen nStart = 0;
461 xub_StrLen nEnd;
462 USHORT nCnt = maScriptChg.Count();
463 if( nCnt )
465 nEnd = maScriptChg[ nIdx ];
466 nScript = maScriptType[ nIdx ];
468 else
470 nEnd = maText.Len();
471 nScript = I18N_SCRIPTTYPE::LATIN;
473 long nTxtWidth = 0;
474 long nCJKHeight = 0;
475 long nCTLHeight = 0;
476 long nHeight = 0;
477 long nAscent = 0;
478 long nCJKAscent = 0;
479 long nCTLAscent = 0;
482 SvxFont& rFnt = ( nScript == I18N_SCRIPTTYPE::ASIAN )? maCJKFont :
483 ( ( nScript == I18N_SCRIPTTYPE::COMPLEX )? maCTLFont : maFont );
484 ULONG nWidth = rFnt.GetTxtSize( mpPrinter, maText, nStart, nEnd-nStart ).Width();
486 if( nIdx < maTextWidth.Count() )
487 maTextWidth[ nIdx++ ] = nWidth;
488 nTxtWidth += nWidth;
489 switch(nScript)
491 case I18N_SCRIPTTYPE::ASIAN:
492 calcFontHeightAnyAscent( this, maCJKFont, nCJKHeight, nCJKAscent );
493 break;
494 case I18N_SCRIPTTYPE::COMPLEX:
495 calcFontHeightAnyAscent( this, maCTLFont, nCTLHeight, nCTLAscent );
496 break;
497 default:
498 calcFontHeightAnyAscent( this, maFont, nHeight, nAscent );
501 if( nEnd < maText.Len() && nIdx < nCnt )
503 nStart = nEnd;
504 nEnd = maScriptChg[ nIdx ];
505 nScript = maScriptType[ nIdx ];
507 else
508 break;
510 while( TRUE );
511 nHeight -= nAscent;
512 nCJKHeight -= nCJKAscent;
513 nCTLHeight -= nCTLAscent;
514 if( nHeight < nCJKHeight )
515 nHeight = nCJKHeight;
516 if( nAscent < nCJKAscent )
517 nAscent = nCJKAscent;
518 if( nHeight < nCTLHeight )
519 nHeight = nCTLHeight;
520 if( nAscent < nCTLAscent )
521 nAscent = nCTLAscent;
522 nHeight += nAscent;
524 Size aTxtSize( nTxtWidth, nHeight );
525 return aTxtSize;
528 void SwDropCapsPict::_InitPrinter()
530 SfxViewShell* pSh = SfxViewShell::Current();
532 if ( pSh )
533 mpPrinter = pSh->GetPrinter();
535 if ( !mpPrinter )
537 mpPrinter = new Printer;
538 mbDelPrinter = TRUE;
542 /****************************************************************************
543 Dlg: Ctor
544 ****************************************************************************/
547 SwDropCapsDlg::SwDropCapsDlg(Window *pParent, const SfxItemSet &rSet ) :
549 SfxSingleTabDialog(pParent, rSet, 0)
552 SwDropCapsPage* pNewPage = (SwDropCapsPage*) SwDropCapsPage::Create(this, rSet);
553 pNewPage->SetFormat(FALSE);
554 SetTabPage(pNewPage);
557 /****************************************************************************
558 Dlg: Dtor
559 ****************************************************************************/
562 SwDropCapsDlg::~SwDropCapsDlg()
566 /****************************************************************************
567 Page: Ctor
568 ****************************************************************************/
571 SwDropCapsPage::SwDropCapsPage(Window *pParent, const SfxItemSet &rSet) :
573 SfxTabPage(pParent, SW_RES(TP_DROPCAPS), rSet),
575 aDropCapsBox (this, SW_RES(CB_SWITCH )),
576 aWholeWordCB (this, SW_RES(CB_WORD )),
577 aSwitchText (this, SW_RES(FT_DROPCAPS )),
578 aDropCapsField(this, SW_RES(FLD_DROPCAPS)),
579 aLinesText (this, SW_RES(TXT_LINES )),
580 aLinesField (this, SW_RES(FLD_LINES )),
581 aDistanceText (this, SW_RES(TXT_DISTANCE)),
582 aDistanceField(this, SW_RES(FLD_DISTANCE)),
583 aSettingsFL (this, SW_RES(FL_SETTINGS)),
585 aTextText (this, SW_RES(TXT_TEXT )),
586 aTextEdit (this, SW_RES(EDT_TEXT )),
587 aTemplateText (this, SW_RES(TXT_TEMPLATE)),
588 aTemplateBox (this, SW_RES(BOX_TEMPLATE)),
589 aContentFL (this, SW_RES(FL_CONTENT )),
591 pPict (new SwDropCapsPict(this, SW_RES(CNT_PICT))),
593 bModified(FALSE),
594 bFormat(TRUE),
595 rSh(::GetActiveView()->GetWrtShell())
597 FreeResource();
598 SetExchangeSupport();
600 USHORT nHtmlMode = ::GetHtmlMode((const SwDocShell*)SfxObjectShell::Current());
601 bHtmlMode = nHtmlMode & HTMLMODE_ON ? TRUE : FALSE;
603 //Im Vorlagendialog kann der Text nicht beeinflusst werden
604 aTextText.Enable( !bFormat );
605 aTextEdit.Enable( !bFormat );
607 // Metriken
608 SetMetric( aDistanceField, GetDfltMetric(bHtmlMode) );
610 pPict->SetBorderStyle( WINDOW_BORDER_MONO );
612 // Handler installieren
613 Link aLk = LINK(this, SwDropCapsPage, ModifyHdl);
614 aDropCapsField.SetModifyHdl( aLk );
615 aLinesField .SetModifyHdl( aLk );
616 aDistanceField.SetModifyHdl( aLk );
617 aTextEdit .SetModifyHdl( aLk );
618 aDropCapsBox .SetClickHdl (LINK(this, SwDropCapsPage, ClickHdl ));
619 aTemplateBox .SetSelectHdl(LINK(this, SwDropCapsPage, SelectHdl));
620 aWholeWordCB .SetClickHdl (LINK(this, SwDropCapsPage, WholeWordHdl ));
623 /****************************************************************************
624 Page: Dtor
625 ****************************************************************************/
628 SwDropCapsPage::~SwDropCapsPage()
630 delete pPict;
634 int SwDropCapsPage::DeactivatePage(SfxItemSet * _pSet)
636 if ( _pSet )
637 FillSet( *_pSet );
639 return LEAVE_PAGE;
642 /****************************************************************************
643 Page: Factory
644 ****************************************************************************/
647 SfxTabPage* SwDropCapsPage::Create(Window *pParent,
648 const SfxItemSet &rSet)
650 return new SwDropCapsPage(pParent, rSet);
653 /****************************************************************************
654 Page: FillItemSet-Overload
655 ****************************************************************************/
658 BOOL SwDropCapsPage::FillItemSet(SfxItemSet &rSet)
660 if(bModified)
661 FillSet(rSet);
662 return bModified;
665 /****************************************************************************
666 Page: Reset-Overload
667 ****************************************************************************/
670 void SwDropCapsPage::Reset(const SfxItemSet &rSet)
672 // Zeichen, Zeilen, Abstand und Text
673 SwFmtDrop aFmtDrop((SwFmtDrop &) rSet.Get(RES_PARATR_DROP));
674 if (aFmtDrop.GetLines() > 1)
676 aDropCapsField.SetValue(aFmtDrop.GetChars());
677 aLinesField .SetValue(aFmtDrop.GetLines());
678 aDistanceField.SetValue(aDistanceField.Normalize(aFmtDrop.GetDistance()), FUNIT_TWIP);
679 aWholeWordCB .Check (aFmtDrop.GetWholeWord());
681 else
683 aDropCapsField.SetValue(1);
684 aLinesField .SetValue(3);
685 aDistanceField.SetValue(0);
688 ::FillCharStyleListBox(aTemplateBox, rSh.GetView().GetDocShell(), TRUE);
690 aTemplateBox.InsertEntry(SW_RESSTR(SW_STR_NONE), 0);
691 // Vorlage defaulten
692 aTemplateBox.SelectEntryPos(0);
693 if (aFmtDrop.GetCharFmt())
694 aTemplateBox.SelectEntry(aFmtDrop.GetCharFmt()->GetName());
696 // Controls enablen
697 aDropCapsBox.Check(aFmtDrop.GetLines() > 1);
698 const USHORT nVal = USHORT(aDropCapsField.GetValue());
699 if (bFormat)
700 aTextEdit.SetText(GetDefaultString(nVal));
701 else
703 aTextEdit.SetText(rSh.GetDropTxt(nVal));
704 aTextEdit.Enable();
705 aTextText.Enable();
708 // Preview
709 pPict->SetValues( aTextEdit.GetText(),
710 BYTE( aLinesField.GetValue() ),
711 USHORT( aDistanceField.Denormalize( aDistanceField.GetValue( FUNIT_TWIP ) ) ) );
713 ClickHdl(&aDropCapsBox);
714 bModified = FALSE;
717 /****************************************************************************
718 Page: Click-Handler der CheckBox
719 ****************************************************************************/
722 IMPL_LINK( SwDropCapsPage, ClickHdl, Button *, EMPTYARG )
724 BOOL bChecked = aDropCapsBox.IsChecked();
726 aWholeWordCB .Enable( bChecked && !bHtmlMode );
728 aSwitchText.Enable( bChecked && !aWholeWordCB.IsChecked() );
729 aDropCapsField.Enable( bChecked && !aWholeWordCB.IsChecked() );
730 aLinesText .Enable( bChecked );
731 aLinesField .Enable( bChecked );
732 aDistanceText.Enable( bChecked );
733 aDistanceField.Enable( bChecked );
734 aTemplateText .Enable( bChecked );
735 aTemplateBox .Enable( bChecked );
736 aTextEdit .Enable( bChecked && !bFormat );
737 aTextText .Enable( bChecked && !bFormat );
739 if ( bChecked )
741 ModifyHdl(&aDropCapsField);
742 aDropCapsField.GrabFocus();
744 else
745 pPict->SetText(aEmptyStr);
747 bModified = TRUE;
749 return 0;
752 /****************************************************************************
753 Page: Click-Handler der CheckBox
754 ****************************************************************************/
757 IMPL_LINK( SwDropCapsPage, WholeWordHdl, CheckBox *, EMPTYARG )
759 aDropCapsField.Enable( !aWholeWordCB.IsChecked() );
761 ModifyHdl(&aDropCapsField);
763 bModified = TRUE;
765 return 0;
768 /****************************************************************************
769 Page: Modify-Handler der SpinFields
770 ****************************************************************************/
773 IMPL_LINK( SwDropCapsPage, ModifyHdl, Edit *, pEdit )
775 String sPreview;
777 // Ggf. Text setzen
778 if (pEdit == &aDropCapsField)
780 USHORT nVal;
781 BOOL bSetText = FALSE;
783 if (!aWholeWordCB.IsChecked())
784 nVal = (USHORT)aDropCapsField.GetValue();
785 else
786 nVal = 0;
788 if (bFormat || !rSh.GetDropTxt(1).Len())
789 sPreview = GetDefaultString(nVal);
790 else
792 bSetText = TRUE;
793 sPreview = rSh.GetDropTxt(nVal);
796 String sEdit(aTextEdit.GetText());
798 if (sEdit.Len() && sPreview.CompareTo(sEdit, sEdit.Len()) != COMPARE_EQUAL)
800 sPreview = sEdit.Copy(0, sPreview.Len());
801 bSetText = FALSE;
804 if (bSetText)
805 aTextEdit.SetText(sPreview);
807 else if (pEdit == &aTextEdit) // Ggf. Anzahl setzen
809 USHORT nTmp = aTextEdit.GetText().Len();
810 aDropCapsField.SetValue(Max((USHORT)1, nTmp));
812 sPreview = aTextEdit.GetText().Copy(0, nTmp);
815 // Bild anpassen
816 if (pEdit == &aDropCapsField || pEdit == &aTextEdit)
817 pPict->SetText (sPreview);
818 else if (pEdit == &aLinesField)
819 pPict->SetLines((BYTE)aLinesField.GetValue());
820 else
821 pPict->SetDistance((USHORT)aDistanceField.Denormalize(aDistanceField.GetValue(FUNIT_TWIP)));
823 bModified = TRUE;
825 return 0;
828 /****************************************************************************
829 Page: Select-Handler der Template-Box.
830 *****************************************************************************/
833 IMPL_LINK_INLINE_START( SwDropCapsPage, SelectHdl, ListBox *, EMPTYARG )
835 pPict->UpdatePaintSettings();
836 bModified = TRUE;
837 return 0;
839 IMPL_LINK_INLINE_END( SwDropCapsPage, SelectHdl, ListBox *, EMPTYARG )
842 USHORT* SwDropCapsPage::GetRanges()
844 return aPageRg;
848 void SwDropCapsPage::FillSet( SfxItemSet &rSet )
850 if(bModified)
852 SwFmtDrop aFmt;
854 BOOL bOn = aDropCapsBox.IsChecked();
855 if(bOn)
857 // Anzahl, Zeilen, Abstand
858 aFmt.GetChars() = (BYTE) aDropCapsField.GetValue();
859 aFmt.GetLines() = (BYTE) aLinesField.GetValue();
860 aFmt.GetDistance() = (USHORT) aDistanceField.Denormalize(aDistanceField.GetValue(FUNIT_TWIP));
861 aFmt.GetWholeWord() = aWholeWordCB.IsChecked();
863 // Vorlage
864 if (aTemplateBox.GetSelectEntryPos())
865 aFmt.SetCharFmt(rSh.GetCharStyle(aTemplateBox.GetSelectEntry()));
867 else
869 aFmt.GetChars() = 1;
870 aFmt.GetLines() = 1;
871 aFmt.GetDistance() = 0;
874 // Attribute setzen
875 const SfxPoolItem* pOldItem;
876 if(0 == (pOldItem = GetOldItem( rSet, FN_FORMAT_DROPCAPS )) ||
877 aFmt != *pOldItem )
878 rSet.Put(aFmt);
880 // Harte Textformatierung
881 // Bug 24974: In Gestalter/Vorlagenkatoplog macht das keinen Sinn!!
882 if( !bFormat && aDropCapsBox.IsChecked() )
884 String sText(aTextEdit.GetText());
886 if (!aWholeWordCB.IsChecked())
887 sText.Erase( static_cast< xub_StrLen >(aDropCapsField.GetValue()));
889 SfxStringItem aStr(FN_PARAM_1, sText);
890 rSet.Put( aStr );