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 : #include <hintids.hxx>
21 :
22 : #include "cmdid.h"
23 : #include "swmodule.hxx"
24 : #include "view.hxx"
25 : #include "wrtsh.hxx"
26 : #include "globals.hrc"
27 :
28 : #include <vcl/metric.hxx>
29 :
30 : #include <svl/stritem.hxx>
31 : #include <editeng/fontitem.hxx>
32 : #include <sfx2/dialoghelper.hxx>
33 : #include <sfx2/htmlmode.hxx>
34 : #include <sfx2/objsh.hxx>
35 : #include <editeng/svxfont.hxx>
36 : #include <vcl/print.hxx>
37 : #include <sfx2/printer.hxx>
38 : #include <com/sun/star/i18n/ScriptType.hpp>
39 : #include <editeng/scripttypeitem.hxx>
40 : #include <com/sun/star/i18n/BreakIterator.hpp>
41 : #include <comphelper/processfactory.hxx>
42 :
43 : #include "charatr.hxx"
44 : #include "viewopt.hxx"
45 : #include "drpcps.hxx"
46 : #include "paratr.hxx"
47 : #include "uitool.hxx"
48 : #include "charfmt.hxx"
49 :
50 : #include "chrdlg.hrc"
51 :
52 :
53 : using namespace css;
54 : using namespace css::uno;
55 : using namespace css::lang;
56 :
57 : // Globals ******************************************************************
58 :
59 : static sal_uInt16 aPageRg[] = {
60 : RES_PARATR_DROP, RES_PARATR_DROP,
61 : 0
62 : };
63 :
64 : class SwDropCapsPict : public Control
65 : {
66 : SwDropCapsPage* mpPage;
67 : String maText;
68 : String maScriptText;
69 : Color maBackColor;
70 : Color maTextLineColor;
71 : sal_uInt8 mnLines;
72 : long mnTotLineH;
73 : long mnLineH;
74 : long mnTextH;
75 : sal_uInt16 mnDistance;
76 : Printer* mpPrinter;
77 : bool mbDelPrinter;
78 : /// The _ScriptInfo structure holds information on where we change from one
79 : /// script to another.
80 : struct _ScriptInfo
81 : {
82 : sal_uLong textWidth; ///< Physical width of this segment.
83 : sal_uInt16 scriptType; ///< Script type (e.g. Latin, Asian, Complex)
84 : xub_StrLen changePos; ///< Character position where the script changes.
85 0 : _ScriptInfo(sal_uLong txtWidth, sal_uInt16 scrptType, xub_StrLen position)
86 0 : : textWidth(txtWidth), scriptType(scrptType), changePos(position) {}
87 : bool operator<(_ScriptInfo other) { return changePos < other.changePos; }
88 : };
89 : std::vector<_ScriptInfo> maScriptChanges;
90 : SvxFont maFont;
91 : SvxFont maCJKFont;
92 : SvxFont maCTLFont;
93 : Size maTextSize;
94 : Reference< css::i18n::XBreakIterator > xBreak;
95 :
96 : virtual void Paint(const Rectangle &rRect);
97 : void CheckScript( void );
98 : Size CalcTextSize( void );
99 : inline void InitPrinter( void );
100 : void _InitPrinter( void );
101 : void GetFontSettings( const SwDropCapsPage& _rPage, Font& _rFont, sal_uInt16 _nWhich );
102 : void GetFirstScriptSegment(xub_StrLen &start, xub_StrLen &end, sal_uInt16 &scriptType);
103 : bool GetNextScriptSegment(size_t &nIdx, xub_StrLen &start, xub_StrLen &end, sal_uInt16 &scriptType);
104 :
105 : public:
106 :
107 0 : SwDropCapsPict(Window *pParent, WinBits nBits)
108 : : Control(pParent, nBits)
109 : , mpPage(NULL)
110 : , mnTotLineH(0)
111 : , mnLineH(0)
112 : , mnTextH(0)
113 : , mpPrinter( NULL )
114 0 : , mbDelPrinter( false )
115 0 : {}
116 :
117 0 : void SetDropCapsPage(SwDropCapsPage* pPage) { mpPage = pPage; }
118 :
119 : ~SwDropCapsPict();
120 :
121 : void UpdatePaintSettings( void ); // also invalidates control!
122 :
123 : virtual void Resize();
124 : virtual Size GetOptimalSize() const;
125 :
126 : void SetText( const OUString& rT );
127 : void SetLines( sal_uInt8 nL );
128 : void SetDistance( sal_uInt16 nD );
129 : void SetValues( const String& rText, sal_uInt8 nLines, sal_uInt16 nDistance );
130 :
131 : void DrawPrev( const Point& rPt );
132 : };
133 :
134 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSwDropCapsPict(Window *pParent, VclBuilder::stringmap &)
135 : {
136 0 : return new SwDropCapsPict(pParent, WB_BORDER);
137 : }
138 :
139 0 : void SwDropCapsPict::SetText( const OUString& rT )
140 : {
141 0 : maText = rT;
142 0 : UpdatePaintSettings();
143 0 : }
144 :
145 0 : Size SwDropCapsPict::GetOptimalSize() const
146 : {
147 0 : return getParagraphPreviewOptimalSize(this);
148 : }
149 :
150 0 : void SwDropCapsPict::Resize()
151 : {
152 0 : Control::Resize();
153 0 : UpdatePaintSettings();
154 0 : }
155 :
156 0 : void SwDropCapsPict::SetLines( sal_uInt8 nL )
157 : {
158 0 : mnLines = nL;
159 0 : UpdatePaintSettings();
160 0 : }
161 :
162 0 : void SwDropCapsPict::SetDistance( sal_uInt16 nD )
163 : {
164 0 : mnDistance = nD;
165 0 : UpdatePaintSettings();
166 0 : }
167 :
168 0 : void SwDropCapsPict::SetValues( const String& rText, sal_uInt8 nLines, sal_uInt16 nDistance )
169 : {
170 0 : maText = rText;
171 0 : mnLines = nLines;
172 0 : mnDistance = nDistance;
173 :
174 0 : UpdatePaintSettings();
175 0 : }
176 :
177 0 : void SwDropCapsPict::InitPrinter( void )
178 : {
179 0 : if( !mpPrinter )
180 0 : _InitPrinter();
181 0 : }
182 :
183 : /****************************************************************************
184 : Create Default-String from character-count (A, AB, ABC, ...)
185 : ****************************************************************************/
186 :
187 :
188 0 : String GetDefaultString(sal_uInt16 nChars)
189 : {
190 0 : String aStr;
191 0 : for (sal_uInt16 i = 0; i < nChars; i++)
192 0 : aStr += OUString((char) (i + 65));
193 0 : return aStr;
194 : }
195 :
196 0 : static void calcFontHeightAnyAscent( OutputDevice* _pWin, Font& _rFont, long& _nHeight, long& _nAscent )
197 : {
198 0 : if ( !_nHeight )
199 : {
200 0 : _pWin->SetFont( _rFont );
201 0 : FontMetric aMetric( _pWin->GetFontMetric() );
202 0 : _nHeight = aMetric.GetLineHeight();
203 0 : _nAscent = aMetric.GetAscent();
204 : }
205 0 : }
206 :
207 0 : SwDropCapsPict::~SwDropCapsPict()
208 : {
209 0 : if( mbDelPrinter )
210 0 : delete mpPrinter;
211 0 : }
212 :
213 : /// Get the details of the first script change.
214 : /// @param[out] start The character position of the start of the segment.
215 : /// @param[out] end The character position of the end of the segment.
216 : /// @param[out] scriptType The script type (Latin, Asian, Complex etc.)
217 0 : void SwDropCapsPict::GetFirstScriptSegment(xub_StrLen &start, xub_StrLen &end, sal_uInt16 &scriptType)
218 : {
219 0 : start = 0;
220 0 : if( maScriptChanges.empty() )
221 : {
222 0 : end = maText.Len();
223 0 : scriptType = css::i18n::ScriptType::LATIN;
224 : }
225 : else
226 : {
227 0 : end = maScriptChanges[ 0 ].changePos;
228 0 : scriptType = maScriptChanges[ 0 ].scriptType;
229 : }
230 0 : }
231 :
232 : /// Get the details of the first script change.
233 : /// @param[in,out] nIdx Index of the current script change.
234 : /// @param[out] start The character position of the start of the segment.
235 : /// @param[in,out] end The character position of the end of the segment.
236 : /// @param[out] scriptType The script type (Latin, Asian, Complex etc.)
237 : /// @returns True if there was a next segment, false if not.
238 0 : bool SwDropCapsPict::GetNextScriptSegment(size_t &nIdx, xub_StrLen &start, xub_StrLen &end, sal_uInt16 &scriptType)
239 : {
240 0 : if (maScriptChanges.empty() || nIdx >= maScriptChanges.size() - 1 || end >= maText.Len())
241 0 : return false;
242 0 : start = maScriptChanges[nIdx++].changePos;
243 0 : end = maScriptChanges[ nIdx ].changePos;
244 0 : scriptType = maScriptChanges[ nIdx ].scriptType;
245 0 : return true;
246 : }
247 :
248 : #define LINES 10
249 : #define BORDER 2
250 :
251 0 : void SwDropCapsPict::GetFontSettings( const SwDropCapsPage& _rPage, Font& _rFont, sal_uInt16 _nWhich )
252 : {
253 0 : SfxItemSet aSet( _rPage.rSh.GetAttrPool(), _nWhich, _nWhich);
254 0 : _rPage.rSh.GetCurAttr(aSet);
255 0 : SvxFontItem aFmtFont((SvxFontItem &) aSet.Get(_nWhich));
256 :
257 0 : _rFont.SetFamily (aFmtFont.GetFamily());
258 0 : _rFont.SetName (aFmtFont.GetFamilyName());
259 0 : _rFont.SetPitch (aFmtFont.GetPitch());
260 0 : _rFont.SetCharSet(aFmtFont.GetCharSet());
261 0 : }
262 :
263 0 : void SwDropCapsPict::UpdatePaintSettings( void )
264 : {
265 0 : maBackColor = GetSettings().GetStyleSettings().GetWindowColor();
266 0 : maTextLineColor = Color( COL_LIGHTGRAY );
267 :
268 : // gray lines
269 0 : mnTotLineH = (GetOutputSizePixel().Height() - 2 * BORDER) / LINES;
270 0 : mnLineH = mnTotLineH - 2;
271 :
272 0 : Font aFont;
273 0 : if (mpPage)
274 : {
275 0 : if (!mpPage->m_pTemplateBox->GetSelectEntryPos())
276 : {
277 : // query the Font at paragraph's beginning
278 0 : mpPage->rSh.SttCrsrMove();
279 0 : mpPage->rSh.Push();
280 0 : mpPage->rSh.ClearMark();
281 0 : SwWhichPara pSwuifnParaCurr = GetfnParaCurr();
282 0 : SwPosPara pSwuifnParaStart = GetfnParaStart();
283 0 : mpPage->rSh.MovePara(pSwuifnParaCurr,pSwuifnParaStart);
284 : // normal
285 0 : GetFontSettings( *mpPage, aFont, RES_CHRATR_FONT );
286 :
287 : // CJK
288 0 : GetFontSettings( *mpPage, maCJKFont, RES_CHRATR_CJK_FONT );
289 :
290 : // CTL
291 0 : GetFontSettings( *mpPage, maCTLFont, RES_CHRATR_CTL_FONT );
292 :
293 0 : mpPage->rSh.Pop(sal_False);
294 0 : mpPage->rSh.EndCrsrMove();
295 : }
296 : else
297 : {
298 : // query Font at character template
299 : SwCharFmt *pFmt = mpPage->rSh.GetCharStyle(
300 0 : mpPage->m_pTemplateBox->GetSelectEntry(),
301 0 : SwWrtShell::GETSTYLE_CREATEANY );
302 : OSL_ENSURE(pFmt, "character style doesn't exist!");
303 0 : const SvxFontItem &rFmtFont = pFmt->GetFont();
304 :
305 0 : aFont.SetFamily (rFmtFont.GetFamily());
306 0 : aFont.SetName (rFmtFont.GetFamilyName());
307 0 : aFont.SetPitch (rFmtFont.GetPitch());
308 0 : aFont.SetCharSet(rFmtFont.GetCharSet());
309 : }
310 : }
311 :
312 0 : mnTextH = mnLines * mnTotLineH;
313 0 : aFont.SetSize(Size(0, mnTextH));
314 0 : maCJKFont.SetSize(Size(0, mnTextH));
315 0 : maCTLFont.SetSize(Size(0, mnTextH));
316 :
317 0 : aFont.SetTransparent(sal_True);
318 0 : maCJKFont.SetTransparent(sal_True);
319 0 : maCTLFont.SetTransparent(sal_True);
320 :
321 0 : aFont.SetColor( SwViewOption::GetFontColor() );
322 0 : maCJKFont.SetColor( SwViewOption::GetFontColor() );
323 0 : maCTLFont.SetColor( SwViewOption::GetFontColor() );
324 :
325 0 : aFont.SetFillColor(GetSettings().GetStyleSettings().GetWindowColor());
326 0 : maCJKFont.SetFillColor(GetSettings().GetStyleSettings().GetWindowColor());
327 0 : maCTLFont.SetFillColor(GetSettings().GetStyleSettings().GetWindowColor());
328 :
329 0 : maCJKFont.SetSize(Size(0, maCJKFont.GetSize().Height()));
330 0 : maCTLFont.SetSize(Size(0, maCTLFont.GetSize().Height()));
331 :
332 0 : SetFont(aFont);
333 0 : aFont.SetSize(Size(0, aFont.GetSize().Height()));
334 0 : SetFont(aFont);
335 0 : maFont = aFont;
336 :
337 0 : CheckScript();
338 :
339 0 : maTextSize = CalcTextSize();
340 :
341 0 : Invalidate();
342 0 : }
343 :
344 : /****************************************************************************
345 : Pict: Paint-Overload
346 : ****************************************************************************/
347 :
348 0 : void SwDropCapsPict::Paint(const Rectangle &/*rRect*/)
349 : {
350 0 : if (!IsVisible())
351 0 : return;
352 :
353 0 : SetMapMode(MapMode(MAP_PIXEL));
354 0 : SetLineColor();
355 :
356 0 : SetFillColor( maBackColor );
357 :
358 0 : Size aOutputSizePixel( GetOutputSizePixel() );
359 :
360 0 : DrawRect(Rectangle(Point(0, 0), aOutputSizePixel ));
361 : SetClipRegion(Region(Rectangle(
362 : Point(BORDER, BORDER),
363 0 : Size (aOutputSizePixel.Width () - 2 * BORDER,
364 0 : aOutputSizePixel.Height() - 2 * BORDER))));
365 :
366 : OSL_ENSURE(mnLineH > 0, "We cannot make it that small");
367 0 : long nY0 = (aOutputSizePixel.Height() - (LINES * mnTotLineH)) / 2;
368 0 : SetFillColor( maTextLineColor );
369 0 : for (sal_uInt16 i = 0; i < LINES; ++i)
370 0 : DrawRect(Rectangle(Point(BORDER, nY0 + i * mnTotLineH), Size(aOutputSizePixel.Width() - 2 * BORDER, mnLineH)));
371 :
372 : // Text background with gap (240 twips ~ 1 line height)
373 0 : sal_uLong lDistance = mnDistance;
374 0 : sal_uInt16 nDistW = (sal_uInt16) (sal_uLong) (((lDistance * 100) / 240) * mnTotLineH) / 100;
375 0 : SetFillColor( maBackColor );
376 0 : if (mpPage && mpPage->m_pDropCapsBox->IsChecked())
377 : {
378 0 : Size aTextSize( maTextSize );
379 0 : aTextSize.Width() += nDistW;
380 0 : DrawRect( Rectangle( Point( BORDER, nY0 ), aTextSize ) );
381 :
382 : // draw Text
383 0 : DrawPrev( Point( BORDER, nY0 ) );
384 : }
385 :
386 0 : SetClipRegion();
387 : }
388 :
389 0 : void SwDropCapsPict::DrawPrev( const Point& rPt )
390 : {
391 0 : Point aPt(rPt);
392 0 : InitPrinter();
393 :
394 0 : Font aOldFont = mpPrinter->GetFont();
395 : sal_uInt16 nScript;
396 0 : size_t nIdx = 0;
397 : xub_StrLen nStart;
398 : xub_StrLen nEnd;
399 0 : GetFirstScriptSegment(nStart, nEnd, nScript);
400 : do
401 : {
402 0 : SvxFont& rFnt = (nScript==css::i18n::ScriptType::ASIAN) ? maCJKFont : ((nScript==css::i18n::ScriptType::COMPLEX) ? maCTLFont : maFont);
403 0 : mpPrinter->SetFont( rFnt );
404 :
405 0 : rFnt.DrawPrev( this, mpPrinter, aPt, maText, nStart, nEnd - nStart );
406 :
407 0 : aPt.X() += maScriptChanges[ nIdx ].textWidth;
408 0 : if ( !GetNextScriptSegment(nIdx, nStart, nEnd, nScript) )
409 0 : break;
410 : }
411 : while( true );
412 0 : mpPrinter->SetFont( aOldFont );
413 0 : }
414 :
415 0 : void SwDropCapsPict::CheckScript( void )
416 : {
417 0 : if( maScriptText == maText )
418 0 : return;
419 :
420 0 : maScriptText = maText;
421 0 : maScriptChanges.clear();
422 0 : if( !xBreak.is() )
423 : {
424 0 : Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
425 0 : xBreak = css::i18n::BreakIterator::create(xContext);
426 : }
427 0 : sal_uInt16 nScript = xBreak->getScriptType( maText, 0 );
428 0 : sal_uInt16 nChg = 0;
429 0 : if( css::i18n::ScriptType::WEAK == nScript )
430 : {
431 0 : nChg = (xub_StrLen)xBreak->endOfScript( maText, nChg, nScript );
432 0 : if( nChg < maText.Len() )
433 0 : nScript = xBreak->getScriptType( maText, nChg );
434 : else
435 0 : nScript = css::i18n::ScriptType::LATIN;
436 : }
437 :
438 : do
439 : {
440 0 : nChg = (xub_StrLen)xBreak->endOfScript( maText, nChg, nScript );
441 0 : maScriptChanges.push_back( _ScriptInfo(0, nScript, nChg) );
442 :
443 0 : if( nChg < maText.Len() )
444 0 : nScript = xBreak->getScriptType( maText, nChg );
445 : else
446 0 : break;
447 0 : } while( true );
448 : }
449 :
450 0 : Size SwDropCapsPict::CalcTextSize( void )
451 : {
452 0 : InitPrinter();
453 :
454 : sal_uInt16 nScript;
455 0 : size_t nIdx = 0;
456 : xub_StrLen nStart;
457 : xub_StrLen nEnd;
458 0 : GetFirstScriptSegment(nStart, nEnd, nScript);
459 0 : long nTxtWidth = 0;
460 0 : long nCJKHeight = 0;
461 0 : long nCTLHeight = 0;
462 0 : long nHeight = 0;
463 0 : long nAscent = 0;
464 0 : long nCJKAscent = 0;
465 0 : long nCTLAscent = 0;
466 : do
467 : {
468 0 : SvxFont& rFnt = ( nScript == css::i18n::ScriptType::ASIAN )? maCJKFont :
469 0 : ( ( nScript == css::i18n::ScriptType::COMPLEX )? maCTLFont : maFont );
470 0 : sal_uLong nWidth = rFnt.GetTxtSize( mpPrinter, maText, nStart, nEnd-nStart ).Width();
471 :
472 0 : if( nIdx < maScriptChanges.size() )
473 0 : maScriptChanges[ nIdx ].textWidth = nWidth;
474 0 : nTxtWidth += nWidth;
475 0 : switch(nScript)
476 : {
477 : case css::i18n::ScriptType::ASIAN:
478 0 : calcFontHeightAnyAscent( this, maCJKFont, nCJKHeight, nCJKAscent );
479 0 : break;
480 : case css::i18n::ScriptType::COMPLEX:
481 0 : calcFontHeightAnyAscent( this, maCTLFont, nCTLHeight, nCTLAscent );
482 0 : break;
483 : default:
484 0 : calcFontHeightAnyAscent( this, maFont, nHeight, nAscent );
485 : }
486 :
487 0 : if ( !GetNextScriptSegment(nIdx, nStart, nEnd, nScript) )
488 0 : break;
489 : }
490 : while( true );
491 0 : nHeight -= nAscent;
492 0 : nCJKHeight -= nCJKAscent;
493 0 : nCTLHeight -= nCTLAscent;
494 0 : if( nHeight < nCJKHeight )
495 0 : nHeight = nCJKHeight;
496 0 : if( nAscent < nCJKAscent )
497 0 : nAscent = nCJKAscent;
498 0 : if( nHeight < nCTLHeight )
499 0 : nHeight = nCTLHeight;
500 0 : if( nAscent < nCTLAscent )
501 0 : nAscent = nCTLAscent;
502 0 : nHeight += nAscent;
503 :
504 0 : Size aTxtSize( nTxtWidth, nHeight );
505 0 : return aTxtSize;
506 : }
507 :
508 0 : void SwDropCapsPict::_InitPrinter()
509 : {
510 0 : SfxViewShell* pSh = SfxViewShell::Current();
511 :
512 0 : if ( pSh )
513 0 : mpPrinter = pSh->GetPrinter();
514 :
515 0 : if ( !mpPrinter )
516 : {
517 0 : mpPrinter = new Printer;
518 0 : mbDelPrinter = true;
519 : }
520 0 : }
521 :
522 0 : SwDropCapsDlg::SwDropCapsDlg(Window *pParent, const SfxItemSet &rSet ) :
523 :
524 0 : SfxNoLayoutSingleTabDialog(pParent, rSet, 0)
525 :
526 : {
527 0 : SwDropCapsPage* pNewPage = (SwDropCapsPage*) SwDropCapsPage::Create(this, rSet);
528 0 : pNewPage->SetFormat(sal_False);
529 0 : SetTabPage(pNewPage);
530 0 : }
531 :
532 0 : SwDropCapsDlg::~SwDropCapsDlg()
533 : {
534 0 : }
535 :
536 0 : SwDropCapsPage::SwDropCapsPage(Window *pParent, const SfxItemSet &rSet)
537 : : SfxTabPage(pParent, "DropCapPage","modules/swriter/ui/dropcapspage.ui", rSet)
538 : , bModified(false)
539 : , bFormat(true)
540 0 : , rSh(::GetActiveView()->GetWrtShell())
541 : {
542 0 : get(m_pDropCapsBox,"checkCB_SWITCH");
543 0 : get(m_pWholeWordCB,"checkCB_WORD");
544 0 : get(m_pDropCapsField,"spinFLD_DROPCAPS");
545 0 : get(m_pLinesField,"spinFLD_LINES");
546 0 : get(m_pDistanceField,"spinFLD_DISTANCE");
547 0 : get(m_pSwitchText,"labelFT_DROPCAPS");
548 0 : get(m_pLinesText,"labelTXT_LINES");
549 0 : get(m_pDistanceText,"labelTXT_DISTANCE");
550 0 : get(m_pTemplateText,"labelTXT_TEMPLATE");
551 0 : get(m_pTextText,"labelTXT_TEXT");
552 0 : get(m_pTextEdit,"entryEDT_TEXT");
553 0 : get(m_pTemplateBox,"comboBOX_TEMPLATE");
554 0 : get(m_pPict,"drawingareaWN_EXAMPLE");
555 :
556 0 : m_pPict->SetDropCapsPage(this);
557 :
558 0 : SetExchangeSupport();
559 :
560 0 : sal_uInt16 nHtmlMode = ::GetHtmlMode((const SwDocShell*)SfxObjectShell::Current());
561 0 : bHtmlMode = nHtmlMode & HTMLMODE_ON ? sal_True : sal_False;
562 :
563 : // In the template dialog the text is not influenceable
564 0 : m_pTextText->Enable( !bFormat );
565 0 : m_pTextEdit->Enable( !bFormat );
566 :
567 : // Metrics
568 0 : SetMetric( *m_pDistanceField, GetDfltMetric(bHtmlMode) );
569 :
570 0 : m_pPict->SetBorderStyle( WINDOW_BORDER_MONO );
571 :
572 : // Install handler
573 0 : Link aLk = LINK(this, SwDropCapsPage, ModifyHdl);
574 0 : m_pDropCapsField->SetModifyHdl( aLk );
575 0 : m_pLinesField->SetModifyHdl( aLk );
576 0 : m_pDistanceField->SetModifyHdl( aLk );
577 0 : m_pTextEdit->SetModifyHdl( aLk );
578 0 : m_pDropCapsBox->SetClickHdl (LINK(this, SwDropCapsPage, ClickHdl ));
579 0 : m_pTemplateBox->SetSelectHdl(LINK(this, SwDropCapsPage, SelectHdl));
580 0 : m_pWholeWordCB->SetClickHdl (LINK(this, SwDropCapsPage, WholeWordHdl ));
581 :
582 0 : setPreviewsToSamePlace(pParent, this);
583 0 : }
584 :
585 0 : SwDropCapsPage::~SwDropCapsPage()
586 : {
587 0 : }
588 :
589 0 : int SwDropCapsPage::DeactivatePage(SfxItemSet * _pSet)
590 : {
591 0 : if ( _pSet )
592 0 : FillSet( *_pSet );
593 :
594 0 : return LEAVE_PAGE;
595 : }
596 :
597 : /****************************************************************************
598 : Page: Factory
599 : ****************************************************************************/
600 :
601 0 : SfxTabPage* SwDropCapsPage::Create(Window *pParent,
602 : const SfxItemSet &rSet)
603 : {
604 0 : return new SwDropCapsPage(pParent, rSet);
605 : }
606 :
607 : /****************************************************************************
608 : Page: FillItemSet-Overload
609 : ****************************************************************************/
610 :
611 0 : sal_Bool SwDropCapsPage::FillItemSet(SfxItemSet &rSet)
612 : {
613 0 : if(bModified)
614 0 : FillSet(rSet);
615 0 : return bModified;
616 : }
617 :
618 : /****************************************************************************
619 : Page: Reset-Overload
620 : ****************************************************************************/
621 :
622 0 : void SwDropCapsPage::Reset(const SfxItemSet &rSet)
623 : {
624 : // Characters, lines, gap and text
625 0 : SwFmtDrop aFmtDrop((SwFmtDrop &) rSet.Get(RES_PARATR_DROP));
626 0 : if (aFmtDrop.GetLines() > 1)
627 : {
628 0 : m_pDropCapsField->SetValue(aFmtDrop.GetChars());
629 0 : m_pLinesField->SetValue(aFmtDrop.GetLines());
630 0 : m_pDistanceField->SetValue(m_pDistanceField->Normalize(aFmtDrop.GetDistance()), FUNIT_TWIP);
631 0 : m_pWholeWordCB->Check(aFmtDrop.GetWholeWord());
632 : }
633 : else
634 : {
635 0 : m_pDropCapsField->SetValue(1);
636 0 : m_pLinesField->SetValue(3);
637 0 : m_pDistanceField->SetValue(0);
638 : }
639 :
640 0 : ::FillCharStyleListBox(*m_pTemplateBox, rSh.GetView().GetDocShell(), true);
641 :
642 0 : m_pTemplateBox->InsertEntry(SW_RESSTR(SW_STR_NONE), 0);
643 :
644 : // Reset format
645 0 : m_pTemplateBox->SelectEntryPos(0);
646 0 : if (aFmtDrop.GetCharFmt())
647 0 : m_pTemplateBox->SelectEntry(aFmtDrop.GetCharFmt()->GetName());
648 :
649 : // Enable controls
650 0 : m_pDropCapsBox->Check(aFmtDrop.GetLines() > 1);
651 0 : const sal_uInt16 nVal = sal_uInt16(m_pDropCapsField->GetValue());
652 0 : if (bFormat)
653 0 : m_pTextEdit->SetText(GetDefaultString(nVal));
654 : else
655 : {
656 0 : m_pTextEdit->SetText(rSh.GetDropTxt(nVal));
657 0 : m_pTextEdit->Enable();
658 0 : m_pTextText->Enable();
659 : }
660 :
661 : // Preview
662 0 : m_pPict->SetValues( m_pTextEdit->GetText(),
663 0 : sal_uInt8( m_pLinesField->GetValue() ),
664 0 : sal_uInt16( m_pDistanceField->Denormalize( m_pDistanceField->GetValue( FUNIT_TWIP ) ) ) );
665 :
666 0 : ClickHdl(m_pDropCapsBox);
667 0 : bModified = sal_False;
668 0 : }
669 :
670 : /****************************************************************************
671 : Page: CheckBox's Click-Handler
672 : ****************************************************************************/
673 :
674 :
675 0 : IMPL_LINK_NOARG(SwDropCapsPage, ClickHdl)
676 : {
677 0 : sal_Bool bChecked = m_pDropCapsBox->IsChecked();
678 :
679 0 : m_pWholeWordCB->Enable( bChecked && !bHtmlMode );
680 :
681 0 : m_pSwitchText->Enable( bChecked && !m_pWholeWordCB->IsChecked() );
682 0 : m_pDropCapsField->Enable( bChecked && !m_pWholeWordCB->IsChecked() );
683 0 : m_pLinesText->Enable( bChecked );
684 0 : m_pLinesField->Enable( bChecked );
685 0 : m_pDistanceText->Enable( bChecked );
686 0 : m_pDistanceField->Enable( bChecked );
687 0 : m_pTemplateText->Enable( bChecked );
688 0 : m_pTemplateBox->Enable( bChecked );
689 0 : m_pTextEdit->Enable( bChecked && !bFormat );
690 0 : m_pTextText->Enable( bChecked && !bFormat );
691 :
692 0 : if ( bChecked )
693 : {
694 0 : ModifyHdl(m_pDropCapsField);
695 0 : m_pDropCapsField->GrabFocus();
696 : }
697 : else
698 0 : m_pPict->SetText("");
699 :
700 0 : bModified = sal_True;
701 :
702 0 : return 0;
703 : }
704 :
705 : /****************************************************************************
706 : Page: CheckBox's Click-Handler
707 : ****************************************************************************/
708 :
709 :
710 0 : IMPL_LINK_NOARG(SwDropCapsPage, WholeWordHdl)
711 : {
712 0 : m_pDropCapsField->Enable( !m_pWholeWordCB->IsChecked() );
713 0 : m_pSwitchText->Enable(!m_pWholeWordCB->IsChecked());
714 :
715 0 : ModifyHdl(m_pDropCapsField);
716 :
717 0 : bModified = sal_True;
718 :
719 0 : return 0;
720 : }
721 :
722 : /****************************************************************************
723 : Page: SpinFields' Modify-Handler
724 : ****************************************************************************/
725 :
726 :
727 0 : IMPL_LINK( SwDropCapsPage, ModifyHdl, Edit *, pEdit )
728 : {
729 0 : String sPreview;
730 :
731 : // set text if applicable
732 0 : if (pEdit == m_pDropCapsField)
733 : {
734 : sal_uInt16 nVal;
735 0 : bool bSetText = false;
736 :
737 0 : if (!m_pWholeWordCB->IsChecked())
738 0 : nVal = (sal_uInt16)m_pDropCapsField->GetValue();
739 : else
740 0 : nVal = 0;
741 :
742 0 : if (bFormat || !rSh.GetDropTxt(1).Len())
743 0 : sPreview = GetDefaultString(nVal);
744 : else
745 : {
746 0 : bSetText = true;
747 0 : sPreview = rSh.GetDropTxt(nVal);
748 : }
749 :
750 0 : String sEdit(m_pTextEdit->GetText());
751 :
752 0 : if (sEdit.Len() && sPreview.CompareTo(sEdit, sEdit.Len()) != COMPARE_EQUAL)
753 : {
754 0 : sPreview = sEdit.Copy(0, sPreview.Len());
755 0 : bSetText = false;
756 : }
757 :
758 0 : if (bSetText)
759 0 : m_pTextEdit->SetText(sPreview);
760 : }
761 0 : else if (pEdit == m_pTextEdit) // set quantity if applicable
762 : {
763 0 : sal_Int32 nTmp = m_pTextEdit->GetText().getLength();
764 0 : m_pDropCapsField->SetValue(std::max((sal_uInt16)1, (sal_uInt16)nTmp));
765 :
766 0 : sPreview = m_pTextEdit->GetText().copy(0, nTmp);
767 : }
768 :
769 : // adjust image
770 0 : if (pEdit == m_pDropCapsField || pEdit == m_pTextEdit)
771 0 : m_pPict->SetText (sPreview);
772 0 : else if (pEdit == m_pLinesField)
773 0 : m_pPict->SetLines((sal_uInt8)m_pLinesField->GetValue());
774 : else
775 0 : m_pPict->SetDistance((sal_uInt16)m_pDistanceField->Denormalize(m_pDistanceField->GetValue(FUNIT_TWIP)));
776 :
777 0 : bModified = sal_True;
778 :
779 0 : return 0;
780 : }
781 :
782 : /****************************************************************************
783 : Page: Template-Box' Select-Handler.
784 : *****************************************************************************/
785 :
786 :
787 0 : IMPL_LINK_NOARG_INLINE_START(SwDropCapsPage, SelectHdl)
788 : {
789 0 : m_pPict->UpdatePaintSettings();
790 0 : bModified = sal_True;
791 0 : return 0;
792 : }
793 0 : IMPL_LINK_NOARG_INLINE_END(SwDropCapsPage, SelectHdl)
794 :
795 0 : sal_uInt16* SwDropCapsPage::GetRanges()
796 : {
797 0 : return aPageRg;
798 : }
799 :
800 0 : void SwDropCapsPage::FillSet( SfxItemSet &rSet )
801 : {
802 0 : if(bModified)
803 : {
804 0 : SwFmtDrop aFmt;
805 :
806 0 : sal_Bool bOn = m_pDropCapsBox->IsChecked();
807 0 : if(bOn)
808 : {
809 : // quantity, lines, gap
810 0 : aFmt.GetChars() = (sal_uInt8) m_pDropCapsField->GetValue();
811 0 : aFmt.GetLines() = (sal_uInt8) m_pLinesField->GetValue();
812 0 : aFmt.GetDistance() = (sal_uInt16) m_pDistanceField->Denormalize(m_pDistanceField->GetValue(FUNIT_TWIP));
813 0 : aFmt.GetWholeWord() = m_pWholeWordCB->IsChecked();
814 :
815 : // template
816 0 : if (m_pTemplateBox->GetSelectEntryPos())
817 0 : aFmt.SetCharFmt(rSh.GetCharStyle(m_pTemplateBox->GetSelectEntry()));
818 : }
819 : else
820 : {
821 0 : aFmt.GetChars() = 1;
822 0 : aFmt.GetLines() = 1;
823 0 : aFmt.GetDistance() = 0;
824 : }
825 :
826 : // set attributes
827 : const SfxPoolItem* pOldItem;
828 0 : if(0 == (pOldItem = GetOldItem( rSet, FN_FORMAT_DROPCAPS )) ||
829 0 : aFmt != *pOldItem )
830 0 : rSet.Put(aFmt);
831 :
832 : // hard text formatting
833 : // Bug 24974: in designer/template catalog this doesn't make sense!!
834 0 : if( !bFormat && m_pDropCapsBox->IsChecked() )
835 : {
836 0 : String sText(m_pTextEdit->GetText());
837 :
838 0 : if (!m_pWholeWordCB->IsChecked())
839 0 : sText.Erase( static_cast< xub_StrLen >(m_pDropCapsField->GetValue()));
840 :
841 0 : SfxStringItem aStr(FN_PARAM_1, sText);
842 0 : rSet.Put( aStr );
843 0 : }
844 : }
845 0 : }
846 :
847 :
848 :
849 :
850 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|