Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/edit.hxx>
30 : : #include <vcl/msgbox.hxx>
31 : : #include <vcl/svapp.hxx>
32 : : #include <svl/zforlist.hxx>
33 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 : : #include <com/sun/star/i18n/XBreakIterator.hpp>
35 : : #include <comphelper/processfactory.hxx>
36 : : #include <svtools/scriptedtext.hxx>
37 : : #include <svtools/accessibilityoptions.hxx>
38 : : #include <svx/framelinkarray.hxx>
39 : : #include "swmodule.hxx"
40 : : #include "swtypes.hxx"
41 : : #include "view.hxx"
42 : : #include "wrtsh.hxx"
43 : : #include "tblafmt.hxx"
44 : : #include "tautofmt.hxx"
45 : : #include "shellres.hxx"
46 : : #include "tautofmt.hrc"
47 : :
48 : : using namespace com::sun::star;
49 : :
50 : : #define FRAME_OFFSET 4
51 : :
52 : : //========================================================================
53 : :
54 : : class AutoFmtPreview : public Window
55 : : {
56 : : public:
57 : : AutoFmtPreview( Window* pParent, const ResId& rRes, SwWrtShell* pWrtShell );
58 : : ~AutoFmtPreview();
59 : :
60 : : void NotifyChange( const SwTableAutoFmt& rNewData );
61 : :
62 : : protected:
63 : : virtual void Paint( const Rectangle& rRect );
64 : :
65 : : private:
66 : : SwTableAutoFmt aCurData;
67 : : VirtualDevice aVD;
68 : : SvtScriptedTextHelper aScriptedText;
69 : : svx::frame::Array maArray; /// Implementation to draw the frame borders.
70 : : sal_Bool bFitWidth;
71 : : bool mbRTL;
72 : : Size aPrvSize;
73 : : long nLabelColWidth;
74 : : long nDataColWidth1;
75 : : long nDataColWidth2;
76 : : long nRowHeight;
77 : : const String aStrJan;
78 : : const String aStrFeb;
79 : : const String aStrMar;
80 : : const String aStrNorth;
81 : : const String aStrMid;
82 : : const String aStrSouth;
83 : : const String aStrSum;
84 : : SvNumberFormatter* pNumFmt;
85 : :
86 : : uno::Reference< lang::XMultiServiceFactory > m_xMSF;
87 : : uno::Reference< i18n::XBreakIterator > m_xBreak;
88 : :
89 : : //-------------------------------------------
90 : : void Init ();
91 : : void DoPaint ( const Rectangle& rRect );
92 : : void CalcCellArray ( sal_Bool bFitWidth );
93 : : void CalcLineMap ();
94 : : void PaintCells ();
95 : :
96 : : sal_uInt8 GetFormatIndex( size_t nCol, size_t nRow ) const;
97 : : const SvxBoxItem& GetBoxItem( size_t nCol, size_t nRow ) const;
98 : :
99 : : void DrawString( size_t nCol, size_t nRow );
100 : : void DrawStrings();
101 : : void DrawBackground();
102 : :
103 : : void MakeFonts ( sal_uInt8 nIndex, Font& rFont, Font& rCJKFont, Font& rCTLFont );
104 : : String MakeNumberString( String cellString, sal_Bool bAddDec );
105 : : };
106 : :
107 : : //========================================================================
108 : :
109 : : class SwStringInputDlg : public ModalDialog
110 : : {
111 : : public:
112 : : SwStringInputDlg( Window* pParent,
113 : : const String& rTitle,
114 : : const String& rEditTitle,
115 : : const String& rDefault );
116 : : ~SwStringInputDlg();
117 : :
118 : : void GetInputString( String& rString ) const;
119 : :
120 : : private:
121 : : Edit aEdInput; // Edit erhaelt so den Focus
122 : : FixedText aFtEditTitle;
123 : : OKButton aBtnOk;
124 : : CancelButton aBtnCancel;
125 : : };
126 : :
127 : :
128 : 0 : SwStringInputDlg::SwStringInputDlg( Window* pParent,
129 : : const String& rTitle,
130 : : const String& rEditTitle,
131 : : const String& rDefault ) :
132 : : ModalDialog ( pParent, SW_RES( DLG_SWDLG_STRINPUT ) ),
133 : : //
134 : : aEdInput ( this, SW_RES( ED_INPUT ) ),
135 : : aFtEditTitle ( this, SW_RES( FT_LABEL ) ),
136 : : aBtnOk ( this, SW_RES( BTN_OK ) ),
137 : 0 : aBtnCancel ( this, SW_RES( BTN_CANCEL ) )
138 : : {
139 : 0 : SetText( rTitle );
140 : 0 : aFtEditTitle.SetText( rEditTitle );
141 : 0 : aEdInput.SetText( rDefault );
142 : : //-------------
143 : 0 : FreeResource();
144 : 0 : }
145 : :
146 : : //------------------------------------------------------------------------
147 : :
148 : 0 : void SwStringInputDlg::GetInputString( String& rString ) const
149 : : {
150 : 0 : rString = aEdInput.GetText();
151 : 0 : }
152 : :
153 : :
154 : 0 : SwStringInputDlg::~SwStringInputDlg()
155 : : {
156 : 0 : }
157 : :
158 : : //========================================================================
159 : : // AutoFormat-Dialog:
160 : :
161 : :
162 : 0 : SwAutoFormatDlg::SwAutoFormatDlg( Window* pParent, SwWrtShell* pWrtShell,
163 : : sal_Bool bSetAutoFormat, const SwTableAutoFmt* pSelFmt )
164 : : : SfxModalDialog( pParent, SW_RES( DLG_AUTOFMT_TABLE ) ),
165 : : //
166 : : aFlFormat ( this, SW_RES( FL_FORMAT ) ),
167 : : aLbFormat ( this, SW_RES( LB_FORMAT ) ),
168 : : aFlFormats ( this, SW_RES( FL_FORMATS ) ),
169 : :
170 : : aBtnNumFormat ( this, SW_RES( BTN_NUMFORMAT ) ),
171 : : aBtnBorder ( this, SW_RES( BTN_BORDER ) ),
172 : : aBtnFont ( this, SW_RES( BTN_FONT ) ),
173 : : aBtnPattern ( this, SW_RES( BTN_PATTERN ) ),
174 : : aBtnAlignment ( this, SW_RES( BTN_ALIGNMENT ) ),
175 : : aBtnOk ( this, SW_RES( BTN_OK ) ),
176 : : aBtnCancel ( this, SW_RES( BTN_CANCEL ) ),
177 : : aBtnHelp ( this, SW_RES( BTN_HELP ) ),
178 : : aBtnAdd ( this, SW_RES( BTN_ADD ) ),
179 : : aBtnRemove ( this, SW_RES( BTN_REMOVE ) ),
180 : : aBtnRename ( this, SW_RES( BTN_RENAME ) ),
181 : : aBtnMore ( this, SW_RES( BTN_MORE ) ),
182 : : aStrTitle ( SW_RES( STR_ADD_TITLE ) ),
183 : : aStrLabel ( SW_RES( STR_ADD_LABEL ) ),
184 : : aStrClose ( SW_RES( STR_BTN_CLOSE ) ),
185 : : aStrDelTitle ( SW_RES( STR_DEL_TITLE ) ),
186 : : aStrDelMsg ( SW_RES( STR_DEL_MSG ) ),
187 : : aStrRenameTitle ( SW_RES( STR_RENAME_TITLE ) ),
188 : : aStrInvalidFmt ( SW_RES( STR_INVALID_AFNAME )),
189 : 0 : pWndPreview ( new AutoFmtPreview( this, SW_RES( WND_PREVIEW ), pWrtShell )),
190 : : //
191 : : pShell ( pWrtShell ),
192 : : nIndex ( 0 ),
193 : : nDfltStylePos ( 0 ),
194 : : bCoreDataChanged( sal_False ),
195 : 0 : bSetAutoFmt ( bSetAutoFormat )
196 : : {
197 : 0 : pTableTbl = new SwTableAutoFmtTbl;
198 : 0 : pTableTbl->Load();
199 : :
200 : 0 : Init( pSelFmt );
201 : : //------------- >
202 : 0 : FreeResource();
203 : 0 : }
204 : :
205 : : //------------------------------------------------------------------------
206 : :
207 : :
208 : 0 : SwAutoFormatDlg::~SwAutoFormatDlg()
209 : : {
210 : 0 : delete pWndPreview;
211 : :
212 : 0 : if( bCoreDataChanged )
213 : 0 : pTableTbl->Save();
214 : 0 : delete pTableTbl;
215 : 0 : }
216 : :
217 : : //------------------------------------------------------------------------
218 : :
219 : :
220 : 0 : void SwAutoFormatDlg::Init( const SwTableAutoFmt* pSelFmt )
221 : : {
222 : 0 : Link aLk( LINK( this, SwAutoFormatDlg, CheckHdl ) );
223 : 0 : aBtnBorder.SetClickHdl( aLk );
224 : 0 : aBtnFont.SetClickHdl( aLk );
225 : 0 : aBtnPattern.SetClickHdl( aLk );
226 : 0 : aBtnAlignment.SetClickHdl( aLk );
227 : 0 : aBtnNumFormat.SetClickHdl( aLk );
228 : :
229 : 0 : aBtnAdd.SetClickHdl ( LINK( this, SwAutoFormatDlg, AddHdl ) );
230 : 0 : aBtnRemove.SetClickHdl ( LINK( this, SwAutoFormatDlg, RemoveHdl ) );
231 : 0 : aBtnRename.SetClickHdl ( LINK( this, SwAutoFormatDlg, RenameHdl ) );
232 : 0 : aBtnOk.SetClickHdl ( LINK( this, SwAutoFormatDlg, OkHdl ) );
233 : 0 : aLbFormat.SetSelectHdl( LINK( this, SwAutoFormatDlg, SelFmtHdl ) );
234 : :
235 : 0 : aBtnMore.AddWindow( &aBtnNumFormat );
236 : 0 : aBtnMore.AddWindow( &aBtnBorder );
237 : 0 : aBtnMore.AddWindow( &aBtnFont );
238 : 0 : aBtnMore.AddWindow( &aBtnPattern );
239 : 0 : aBtnMore.AddWindow( &aBtnAlignment );
240 : 0 : aBtnMore.AddWindow( &aFlFormats );
241 : 0 : aBtnMore.AddWindow( &aBtnRename );
242 : :
243 : 0 : aBtnAdd.Enable( bSetAutoFmt );
244 : :
245 : 0 : nIndex = 0;
246 : 0 : if( !bSetAutoFmt )
247 : : {
248 : : // dann muss die Liste um den Eintrag <Keins> erweitert werden.
249 : 0 : aLbFormat.InsertEntry( ViewShell::GetShellRes()->aStrNone );
250 : 0 : nDfltStylePos = 1;
251 : 0 : nIndex = 255;
252 : : }
253 : :
254 : 0 : for (sal_uInt8 i = 0, nCount = static_cast<sal_uInt8>(pTableTbl->size());
255 : : i < nCount; i++)
256 : : {
257 : 0 : SwTableAutoFmt const& rFmt = (*pTableTbl)[ i ];
258 : 0 : aLbFormat.InsertEntry(rFmt.GetName());
259 : 0 : if (pSelFmt && rFmt.GetName() == pSelFmt->GetName())
260 : 0 : nIndex = i;
261 : : }
262 : :
263 : 0 : aLbFormat.SelectEntryPos( 255 != nIndex ? (nDfltStylePos + nIndex) : 0 );
264 : 0 : SelFmtHdl( 0 );
265 : 0 : }
266 : :
267 : : //------------------------------------------------------------------------
268 : :
269 : :
270 : 0 : void SwAutoFormatDlg::UpdateChecks( const SwTableAutoFmt& rFmt, sal_Bool bEnable )
271 : : {
272 : 0 : aBtnNumFormat.Enable( bEnable );
273 : 0 : aBtnNumFormat.Check( rFmt.IsValueFormat() );
274 : :
275 : 0 : aBtnBorder.Enable( bEnable );
276 : 0 : aBtnBorder.Check( rFmt.IsFrame() );
277 : :
278 : 0 : aBtnFont.Enable( bEnable );
279 : 0 : aBtnFont.Check( rFmt.IsFont() );
280 : :
281 : 0 : aBtnPattern.Enable( bEnable );
282 : 0 : aBtnPattern.Check( rFmt.IsBackground() );
283 : :
284 : 0 : aBtnAlignment.Enable( bEnable );
285 : 0 : aBtnAlignment.Check( rFmt.IsJustify() );
286 : 0 : }
287 : :
288 : 0 : void SwAutoFormatDlg::FillAutoFmtOfIndex( SwTableAutoFmt*& rToFill ) const
289 : : {
290 : 0 : if( 255 != nIndex )
291 : : {
292 : 0 : if( rToFill )
293 : 0 : *rToFill = (*pTableTbl)[ nIndex ];
294 : : else
295 : 0 : rToFill = new SwTableAutoFmt( (*pTableTbl)[ nIndex ] );
296 : : }
297 : : else
298 : 0 : delete rToFill, rToFill = 0;
299 : 0 : }
300 : :
301 : :
302 : : /*------------------------------------------------------------------------
303 : : Handler:
304 : : ---------*/
305 : :
306 : :
307 : 0 : IMPL_LINK( SwAutoFormatDlg, CheckHdl, Button *, pBtn )
308 : : {
309 : 0 : SwTableAutoFmt* pData = &(*pTableTbl)[nIndex];
310 : 0 : sal_Bool bCheck = ((CheckBox*)pBtn)->IsChecked(), bDataChgd = sal_True;
311 : :
312 : 0 : if( pBtn == &aBtnNumFormat )
313 : 0 : pData->SetValueFormat( bCheck );
314 : 0 : else if ( pBtn == &aBtnBorder )
315 : 0 : pData->SetFrame( bCheck );
316 : 0 : else if ( pBtn == &aBtnFont )
317 : 0 : pData->SetFont( bCheck );
318 : 0 : else if ( pBtn == &aBtnPattern )
319 : 0 : pData->SetBackground( bCheck );
320 : 0 : else if ( pBtn == &aBtnAlignment )
321 : 0 : pData->SetJustify( bCheck );
322 : : else
323 : 0 : bDataChgd = sal_False;
324 : :
325 : 0 : if( bDataChgd )
326 : : {
327 : 0 : if( !bCoreDataChanged )
328 : : {
329 : 0 : aBtnCancel.SetText( aStrClose );
330 : 0 : bCoreDataChanged = sal_True;
331 : : }
332 : :
333 : 0 : pWndPreview->NotifyChange( *pData );
334 : : }
335 : 0 : return 0;
336 : : }
337 : :
338 : : /*------------------------------------------------------------------------*/
339 : :
340 : :
341 : 0 : IMPL_LINK_NOARG(SwAutoFormatDlg, AddHdl)
342 : : {
343 : 0 : sal_Bool bOk = sal_False, bFmtInserted = sal_False;
344 : 0 : while( !bOk )
345 : : {
346 : : SwStringInputDlg* pDlg = new SwStringInputDlg( this,
347 : : aStrTitle,
348 : : aStrLabel,
349 : 0 : aEmptyStr );
350 : 0 : if( RET_OK == pDlg->Execute() )
351 : : {
352 : 0 : String aFormatName;
353 : 0 : pDlg->GetInputString( aFormatName );
354 : :
355 : 0 : if( aFormatName.Len() > 0 )
356 : : {
357 : : sal_uInt16 n;
358 : 0 : for( n = 0; n < pTableTbl->size(); ++n )
359 : 0 : if( (*pTableTbl)[n].GetName() == aFormatName )
360 : 0 : break;
361 : :
362 : 0 : if( n >= pTableTbl->size() )
363 : : {
364 : : // Format mit dem Namen noch nicht vorhanden, also
365 : : // aufnehmen
366 : : SwTableAutoFmt* pNewData = new
367 : 0 : SwTableAutoFmt( aFormatName );
368 : 0 : pShell->GetTableAutoFmt( *pNewData );
369 : :
370 : : // Sortiert einfuegen!!
371 : 0 : for( n = 1; n < pTableTbl->size(); ++n )
372 : 0 : if( (*pTableTbl)[ n ].GetName() > aFormatName )
373 : 0 : break;
374 : :
375 : 0 : pTableTbl->InsertAutoFmt(n, pNewData);
376 : 0 : aLbFormat.InsertEntry( aFormatName, nDfltStylePos + n );
377 : 0 : aLbFormat.SelectEntryPos( nDfltStylePos + n );
378 : 0 : bFmtInserted = sal_True;
379 : 0 : aBtnAdd.Enable( sal_False );
380 : 0 : if ( !bCoreDataChanged )
381 : : {
382 : 0 : aBtnCancel.SetText( aStrClose );
383 : 0 : bCoreDataChanged = sal_True;
384 : : }
385 : :
386 : 0 : SelFmtHdl( 0 );
387 : 0 : bOk = sal_True;
388 : : }
389 : : }
390 : :
391 : 0 : if( !bFmtInserted )
392 : : {
393 : : bOk = RET_CANCEL == ErrorBox( this,
394 : : WinBits( WB_OK_CANCEL | WB_DEF_OK),
395 : : aStrInvalidFmt
396 : 0 : ).Execute();
397 : 0 : }
398 : : }
399 : : else
400 : 0 : bOk = sal_True;
401 : 0 : delete pDlg;
402 : : }
403 : 0 : return 0;
404 : : }
405 : :
406 : : //------------------------------------------------------------------------
407 : :
408 : 0 : IMPL_LINK_NOARG(SwAutoFormatDlg, RemoveHdl)
409 : : {
410 : 0 : String aMessage = aStrDelMsg ;
411 : 0 : aMessage.AppendAscii("\n\n");
412 : 0 : aMessage += aLbFormat.GetSelectEntry() ;
413 : 0 : aMessage += '\n';
414 : :
415 : : MessBox* pBox = new MessBox( this, WinBits( WB_OK_CANCEL ),
416 : 0 : aStrDelTitle, aMessage);
417 : :
418 : 0 : if ( pBox->Execute() == RET_OK )
419 : : {
420 : 0 : aLbFormat.RemoveEntry( nDfltStylePos + nIndex );
421 : 0 : aLbFormat.SelectEntryPos( nDfltStylePos + nIndex-1 );
422 : :
423 : 0 : pTableTbl->EraseAutoFmt(nIndex);
424 : 0 : nIndex--;
425 : :
426 : 0 : if( !nIndex )
427 : : {
428 : 0 : aBtnRemove.Enable(sal_False);
429 : 0 : aBtnRename.Enable(sal_False);
430 : : }
431 : :
432 : 0 : if( !bCoreDataChanged )
433 : : {
434 : 0 : aBtnCancel.SetText( aStrClose );
435 : 0 : bCoreDataChanged = sal_True;
436 : : }
437 : : }
438 : 0 : delete pBox;
439 : :
440 : 0 : SelFmtHdl( 0 );
441 : :
442 : 0 : return 0;
443 : : }
444 : :
445 : 0 : IMPL_LINK_NOARG(SwAutoFormatDlg, RenameHdl)
446 : : {
447 : 0 : sal_Bool bOk = sal_False;
448 : 0 : while( !bOk )
449 : : {
450 : : SwStringInputDlg* pDlg = new SwStringInputDlg( this,
451 : : aStrRenameTitle, aLbFormat.GetSelectEntry(),
452 : 0 : aEmptyStr );
453 : 0 : if( pDlg->Execute() == RET_OK )
454 : : {
455 : 0 : sal_Bool bFmtRenamed = sal_False;
456 : 0 : String aFormatName;
457 : 0 : pDlg->GetInputString( aFormatName );
458 : :
459 : 0 : if ( aFormatName.Len() > 0 )
460 : : {
461 : : sal_uInt16 n;
462 : 0 : for( n = 0; n < pTableTbl->size(); ++n )
463 : 0 : if ((*pTableTbl)[n].GetName() == aFormatName)
464 : 0 : break;
465 : :
466 : 0 : if( n >= pTableTbl->size() )
467 : : {
468 : : // no format with this name exists, so rename it
469 : 0 : aLbFormat.RemoveEntry( nDfltStylePos + nIndex );
470 : 0 : SwTableAutoFmt* p = &(*pTableTbl)[ nIndex ];
471 : :
472 : 0 : p->SetName( aFormatName );
473 : :
474 : : // keep all arrays sorted!
475 : 0 : for( n = 1; n < pTableTbl->size(); ++n )
476 : 0 : if ((n != nIndex) &&
477 : 0 : ((*pTableTbl)[n].GetName() > aFormatName))
478 : : {
479 : 0 : break;
480 : : }
481 : :
482 : 0 : pTableTbl->MoveAutoFmt(n, nIndex);
483 : 0 : aLbFormat.InsertEntry( aFormatName, nDfltStylePos + n );
484 : 0 : aLbFormat.SelectEntryPos( nDfltStylePos + n );
485 : :
486 : 0 : if ( !bCoreDataChanged )
487 : : {
488 : 0 : aBtnCancel.SetText( aStrClose );
489 : 0 : bCoreDataChanged = sal_True;
490 : : }
491 : :
492 : 0 : SelFmtHdl( 0 );
493 : 0 : bOk = sal_True;
494 : 0 : bFmtRenamed = sal_True;
495 : : }
496 : : }
497 : :
498 : 0 : if( !bFmtRenamed )
499 : : {
500 : : bOk = RET_CANCEL == ErrorBox( this,
501 : : WinBits( WB_OK_CANCEL | WB_DEF_OK),
502 : : aStrInvalidFmt
503 : 0 : ).Execute();
504 : 0 : }
505 : : }
506 : : else
507 : 0 : bOk = sal_True;
508 : 0 : delete pDlg;
509 : : }
510 : 0 : return 0;
511 : : }
512 : :
513 : : //------------------------------------------------------------------------
514 : :
515 : 0 : IMPL_LINK_NOARG(SwAutoFormatDlg, SelFmtHdl)
516 : : {
517 : 0 : sal_Bool bBtnEnable = sal_False;
518 : 0 : sal_uInt8 nSelPos = (sal_uInt8) aLbFormat.GetSelectEntryPos(), nOldIdx = nIndex;
519 : 0 : if( nSelPos >= nDfltStylePos )
520 : : {
521 : 0 : nIndex = nSelPos - nDfltStylePos;
522 : 0 : pWndPreview->NotifyChange( (*pTableTbl)[nIndex] );
523 : 0 : bBtnEnable = 0 != nIndex;
524 : 0 : UpdateChecks( (*pTableTbl)[nIndex], sal_True );
525 : : }
526 : : else
527 : : {
528 : 0 : nIndex = 255;
529 : :
530 : 0 : SwTableAutoFmt aTmp( ViewShell::GetShellRes()->aStrNone );
531 : 0 : aTmp.SetFont( sal_False );
532 : 0 : aTmp.SetJustify( sal_False );
533 : 0 : aTmp.SetFrame( sal_False );
534 : 0 : aTmp.SetBackground( sal_False );
535 : 0 : aTmp.SetValueFormat( sal_False );
536 : 0 : aTmp.SetWidthHeight( sal_False );
537 : :
538 : 0 : if( nOldIdx != nIndex )
539 : 0 : pWndPreview->NotifyChange( aTmp );
540 : 0 : UpdateChecks( aTmp, sal_False );
541 : : }
542 : :
543 : 0 : aBtnRemove.Enable( bBtnEnable );
544 : 0 : aBtnRename.Enable( bBtnEnable );
545 : :
546 : 0 : return 0;
547 : : }
548 : : //------------------------------------------------------------------------
549 : :
550 : 0 : IMPL_LINK_NOARG_INLINE_START(SwAutoFormatDlg, OkHdl)
551 : : {
552 : 0 : if( bSetAutoFmt )
553 : 0 : pShell->SetTableAutoFmt( (*pTableTbl)[ nIndex ] );
554 : 0 : EndDialog( RET_OK );
555 : 0 : return sal_True;
556 : : }
557 : 0 : IMPL_LINK_NOARG_INLINE_END(SwAutoFormatDlg, OkHdl)
558 : :
559 : : //========================================================================
560 : : // AutoFmtPreview
561 : :
562 : : //------------------------------------------------------------------------
563 : :
564 : 0 : AutoFmtPreview::AutoFmtPreview( Window* pParent, const ResId& rRes, SwWrtShell* pWrtShell ) :
565 : : Window ( pParent, rRes ),
566 : :
567 : : aCurData ( aEmptyStr ),
568 : : aVD ( *this ),
569 : : aScriptedText ( aVD ),
570 : : bFitWidth ( sal_False ),
571 : : mbRTL ( false ),
572 : 0 : aPrvSize ( GetSizePixel().Width() - 6, GetSizePixel().Height() - 30 ),
573 : 0 : nLabelColWidth ( (aPrvSize.Width() - 4) / 4 - 12 ),
574 : 0 : nDataColWidth1 ( (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 3 ),
575 : 0 : nDataColWidth2 ( (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 4 ),
576 : 0 : nRowHeight ( (aPrvSize.Height() - 4) / 5 ),
577 : : aStrJan ( SW_RES( STR_JAN ) ),
578 : : aStrFeb ( SW_RES( STR_FEB ) ),
579 : : aStrMar ( SW_RES( STR_MAR ) ),
580 : : aStrNorth ( SW_RES( STR_NORTH ) ),
581 : : aStrMid ( SW_RES( STR_MID ) ),
582 : : aStrSouth ( SW_RES( STR_SOUTH ) ),
583 : : aStrSum ( SW_RES( STR_SUM ) ),
584 : 0 : m_xMSF ( comphelper::getProcessServiceFactory() )
585 : : {
586 : 0 : if (!pWrtShell->IsCrsrInTbl()) // We haven't created the table yet
587 : 0 : mbRTL = Application::GetSettings().GetLayoutRTL();
588 : : else
589 : 0 : mbRTL = pWrtShell->IsTableRightToLeft();
590 : :
591 : : OSL_ENSURE( m_xMSF.is(), "AutoFmtPreview: no MultiServiceFactory");
592 : 0 : if ( m_xMSF.is() )
593 : : {
594 : : m_xBreak = uno::Reference< i18n::XBreakIterator >(
595 : 0 : m_xMSF->createInstance (
596 : 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.BreakIterator")) ),
597 : 0 : uno::UNO_QUERY);
598 : : }
599 : 0 : pNumFmt = new SvNumberFormatter( m_xMSF, LANGUAGE_SYSTEM );
600 : :
601 : 0 : Init();
602 : 0 : }
603 : :
604 : : //------------------------------------------------------------------------
605 : :
606 : 0 : AutoFmtPreview::~AutoFmtPreview()
607 : : {
608 : 0 : delete pNumFmt;
609 : 0 : }
610 : :
611 : : //------------------------------------------------------------------------
612 : :
613 : 0 : static void lcl_SetFontProperties(
614 : : Font& rFont,
615 : : const SvxFontItem& rFontItem,
616 : : const SvxWeightItem& rWeightItem,
617 : : const SvxPostureItem& rPostureItem )
618 : : {
619 : 0 : rFont.SetFamily ( rFontItem.GetFamily() );
620 : 0 : rFont.SetName ( rFontItem.GetFamilyName() );
621 : 0 : rFont.SetStyleName ( rFontItem.GetStyleName() );
622 : 0 : rFont.SetCharSet ( rFontItem.GetCharSet() );
623 : 0 : rFont.SetPitch ( rFontItem.GetPitch() );
624 : 0 : rFont.SetWeight ( (FontWeight)rWeightItem.GetValue() );
625 : 0 : rFont.SetItalic ( (FontItalic)rPostureItem.GetValue() );
626 : 0 : }
627 : :
628 : : #define SETONALLFONTS( MethodName, Value ) \
629 : : rFont.MethodName( Value ); \
630 : : rCJKFont.MethodName( Value ); \
631 : : rCTLFont.MethodName( Value );
632 : :
633 : 0 : void AutoFmtPreview::MakeFonts( sal_uInt8 nIndex, Font& rFont, Font& rCJKFont, Font& rCTLFont )
634 : : {
635 : 0 : const SwBoxAutoFmt& rBoxFmt = aCurData.GetBoxFmt( nIndex );
636 : :
637 : 0 : rFont = rCJKFont = rCTLFont = GetFont();
638 : 0 : Size aFontSize( rFont.GetSize().Width(), 10 );
639 : :
640 : 0 : lcl_SetFontProperties( rFont, rBoxFmt.GetFont(), rBoxFmt.GetWeight(), rBoxFmt.GetPosture() );
641 : 0 : lcl_SetFontProperties( rCJKFont, rBoxFmt.GetCJKFont(), rBoxFmt.GetCJKWeight(), rBoxFmt.GetCJKPosture() );
642 : 0 : lcl_SetFontProperties( rCTLFont, rBoxFmt.GetCTLFont(), rBoxFmt.GetCTLWeight(), rBoxFmt.GetCTLPosture() );
643 : :
644 : 0 : SETONALLFONTS( SetUnderline, (FontUnderline)rBoxFmt.GetUnderline().GetValue() );
645 : 0 : SETONALLFONTS( SetOverline, (FontUnderline)rBoxFmt.GetOverline().GetValue() );
646 : 0 : SETONALLFONTS( SetStrikeout, (FontStrikeout)rBoxFmt.GetCrossedOut().GetValue() );
647 : 0 : SETONALLFONTS( SetOutline, rBoxFmt.GetContour().GetValue() );
648 : 0 : SETONALLFONTS( SetShadow, rBoxFmt.GetShadowed().GetValue() );
649 : 0 : SETONALLFONTS( SetColor, rBoxFmt.GetColor().GetValue() );
650 : 0 : SETONALLFONTS( SetSize, aFontSize );
651 : 0 : SETONALLFONTS( SetTransparent, sal_True );
652 : 0 : }
653 : :
654 : : //------------------------------------------------------------------------
655 : :
656 : 0 : sal_uInt8 AutoFmtPreview::GetFormatIndex( size_t nCol, size_t nRow ) const
657 : : {
658 : : static const sal_uInt8 pnFmtMap[] =
659 : : {
660 : : 0, 1, 2, 1, 3,
661 : : 4, 5, 6, 5, 7,
662 : : 8, 9, 10, 9, 11,
663 : : 4, 5, 6, 5, 7,
664 : : 12, 13, 14, 13, 15
665 : : };
666 : 0 : return pnFmtMap[ maArray.GetCellIndex( nCol, nRow, mbRTL ) ];
667 : : }
668 : :
669 : 0 : const SvxBoxItem& AutoFmtPreview::GetBoxItem( size_t nCol, size_t nRow ) const
670 : : {
671 : 0 : return aCurData.GetBoxFmt( GetFormatIndex( nCol, nRow ) ).GetBox();
672 : : }
673 : :
674 : : //------------------------------------------------------------------------
675 : :
676 : 0 : void AutoFmtPreview::DrawString( size_t nCol, size_t nRow )
677 : : {
678 : : //------------------------
679 : : // Ausgabe des Zelltextes:
680 : : //------------------------
681 : : sal_uLong nNum;
682 : : double nVal;
683 : 0 : String cellString;
684 : 0 : sal_uInt8 nIndex = static_cast< sal_uInt8 >( maArray.GetCellIndex( nCol, nRow, mbRTL ) );
685 : :
686 : 0 : switch( nIndex )
687 : : {
688 : 0 : case 1: cellString = aStrJan; break;
689 : 0 : case 2: cellString = aStrFeb; break;
690 : 0 : case 3: cellString = aStrMar; break;
691 : 0 : case 5: cellString = aStrNorth; break;
692 : 0 : case 10: cellString = aStrMid; break;
693 : 0 : case 15: cellString = aStrSouth; break;
694 : : case 4:
695 : 0 : case 20: cellString = aStrSum; break;
696 : :
697 : : case 6:
698 : : case 8:
699 : : case 16:
700 : 0 : case 18: nVal = nIndex;
701 : 0 : nNum = 5;
702 : 0 : goto MAKENUMSTR;
703 : : case 17:
704 : 0 : case 7: nVal = nIndex;
705 : 0 : nNum = 6;
706 : 0 : goto MAKENUMSTR;
707 : : case 11:
708 : : case 12:
709 : 0 : case 13: nVal = nIndex;
710 : 0 : nNum = 12 == nIndex ? 10 : 9;
711 : 0 : goto MAKENUMSTR;
712 : :
713 : 0 : case 9: nVal = 21; nNum = 7; goto MAKENUMSTR;
714 : 0 : case 14: nVal = 36; nNum = 11; goto MAKENUMSTR;
715 : 0 : case 19: nVal = 51; nNum = 7; goto MAKENUMSTR;
716 : 0 : case 21: nVal = 33; nNum = 13; goto MAKENUMSTR;
717 : 0 : case 22: nVal = 36; nNum = 14; goto MAKENUMSTR;
718 : 0 : case 23: nVal = 39; nNum = 13; goto MAKENUMSTR;
719 : 0 : case 24: nVal = 108; nNum = 15; goto MAKENUMSTR;
720 : : MAKENUMSTR:
721 : 0 : if( aCurData.IsValueFormat() )
722 : : {
723 : 0 : String sFmt; LanguageType eLng, eSys;
724 : 0 : aCurData.GetBoxFmt( (sal_uInt8)nNum ).GetValueFormat( sFmt, eLng, eSys );
725 : :
726 : : short nType;
727 : : bool bNew;
728 : : xub_StrLen nCheckPos;
729 : : sal_uInt32 nKey = pNumFmt->GetIndexPuttingAndConverting( sFmt, eLng,
730 : 0 : eSys, nType, bNew, nCheckPos);
731 : : Color* pDummy;
732 : 0 : pNumFmt->GetOutputString( nVal, nKey, cellString, &pDummy );
733 : : }
734 : : else
735 : 0 : cellString = String::CreateFromInt32((sal_Int32)nVal);
736 : 0 : break;
737 : :
738 : : }
739 : :
740 : 0 : if( cellString.Len() )
741 : : {
742 : 0 : Size aStrSize;
743 : 0 : sal_uInt8 nFmtIndex = GetFormatIndex( nCol, nRow );
744 : 0 : Rectangle cellRect = maArray.GetCellRect( nCol, nRow );
745 : 0 : Point aPos = cellRect.TopLeft();
746 : 0 : sal_uInt16 nRightX = 0;
747 : :
748 : 0 : Size theMaxStrSize( cellRect.GetWidth() - FRAME_OFFSET,
749 : 0 : cellRect.GetHeight() - FRAME_OFFSET );
750 : 0 : if( aCurData.IsFont() )
751 : : {
752 : 0 : Font aFont, aCJKFont, aCTLFont;
753 : 0 : MakeFonts( nFmtIndex, aFont, aCJKFont, aCTLFont );
754 : 0 : aScriptedText.SetFonts( &aFont, &aCJKFont, &aCTLFont );
755 : : }
756 : : else
757 : 0 : aScriptedText.SetDefaultFont();
758 : :
759 : 0 : aScriptedText.SetText( cellString, m_xBreak );
760 : 0 : aStrSize = aScriptedText.GetTextSize();
761 : :
762 : 0 : if( aCurData.IsFont() &&
763 : 0 : theMaxStrSize.Height() < aStrSize.Height() )
764 : : {
765 : : // wenn der String in diesem Font nicht
766 : : // in die Zelle passt, wird wieder der
767 : : // Standard-Font genommen:
768 : 0 : aScriptedText.SetDefaultFont();
769 : 0 : aStrSize = aScriptedText.GetTextSize();
770 : : }
771 : :
772 : 0 : while( theMaxStrSize.Width() <= aStrSize.Width() &&
773 : 0 : cellString.Len() > 1 )
774 : : {
775 : 0 : cellString.Erase( cellString.Len() - 1 );
776 : 0 : aScriptedText.SetText( cellString, m_xBreak );
777 : 0 : aStrSize = aScriptedText.GetTextSize();
778 : : }
779 : :
780 : 0 : nRightX = (sal_uInt16)( cellRect.GetWidth()
781 : 0 : - aStrSize.Width()
782 : 0 : - FRAME_OFFSET );
783 : :
784 : : //-----------------------------
785 : : // vertikal (immer zentrieren):
786 : : //-----------------------------
787 : 0 : aPos.Y() += (nRowHeight - (sal_uInt16)aStrSize.Height()) / 2;
788 : :
789 : : //-----------
790 : : // horizontal
791 : : //-----------
792 : 0 : if( mbRTL )
793 : 0 : aPos.X() += nRightX;
794 : 0 : else if (aCurData.IsJustify())
795 : : {
796 : : sal_uInt16 nHorPos = (sal_uInt16)
797 : 0 : ((cellRect.GetWidth()-aStrSize.Width())/2);
798 : 0 : const SvxAdjustItem& rAdj = aCurData.GetBoxFmt(nFmtIndex).GetAdjust();
799 : 0 : switch ( rAdj.GetAdjust() )
800 : : {
801 : : case SVX_ADJUST_LEFT:
802 : 0 : aPos.X() += FRAME_OFFSET;
803 : 0 : break;
804 : : case SVX_ADJUST_RIGHT:
805 : 0 : aPos.X() += nRightX;
806 : 0 : break;
807 : : default:
808 : 0 : aPos.X() += nHorPos;
809 : 0 : break;
810 : : }
811 : : }
812 : : else
813 : : {
814 : : //---------------------
815 : : // Standardausrichtung:
816 : : //---------------------
817 : 0 : if ( (nCol == 0) || (nIndex == 4) )
818 : : {
819 : : // Text-Label links oder Summe linksbuendig
820 : 0 : aPos.X() += FRAME_OFFSET;
821 : : }
822 : : else
823 : : {
824 : : // Zahlen/Datum rechtsbuendig
825 : 0 : aPos.X() += nRightX;
826 : : }
827 : : }
828 : :
829 : : //-------------------------------
830 : 0 : aScriptedText.DrawText( aPos );
831 : : //-------------------------------
832 : 0 : }
833 : 0 : }
834 : :
835 : : #undef FRAME_OFFSET
836 : :
837 : : //------------------------------------------------------------------------
838 : :
839 : 0 : void AutoFmtPreview::DrawStrings()
840 : : {
841 : 0 : for( size_t nRow = 0; nRow < 5; ++nRow )
842 : 0 : for( size_t nCol = 0; nCol < 5; ++nCol )
843 : 0 : DrawString( nCol, nRow );
844 : 0 : }
845 : :
846 : : //------------------------------------------------------------------------
847 : :
848 : :
849 : 0 : void AutoFmtPreview::DrawBackground()
850 : : {
851 : 0 : for( size_t nRow = 0; nRow < 5; ++nRow )
852 : : {
853 : 0 : for( size_t nCol = 0; nCol < 5; ++nCol )
854 : : {
855 : 0 : SvxBrushItem aBrushItem( aCurData.GetBoxFmt( GetFormatIndex( nCol, nRow ) ).GetBackground() );
856 : :
857 : 0 : aVD.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
858 : 0 : aVD.SetLineColor();
859 : 0 : aVD.SetFillColor( aBrushItem.GetColor() );
860 : 0 : aVD.DrawRect( maArray.GetCellRect( nCol, nRow ) );
861 : 0 : aVD.Pop();
862 : 0 : }
863 : : }
864 : 0 : }
865 : :
866 : : //------------------------------------------------------------------------
867 : :
868 : :
869 : 0 : void AutoFmtPreview::PaintCells()
870 : : {
871 : : // 1) background
872 : 0 : if ( aCurData.IsBackground() )
873 : 0 : DrawBackground();
874 : :
875 : : // 2) values
876 : 0 : DrawStrings();
877 : :
878 : : // 3) border
879 : 0 : if ( aCurData.IsFrame() )
880 : 0 : maArray.DrawArray( aVD );
881 : 0 : }
882 : :
883 : : //------------------------------------------------------------------------
884 : :
885 : :
886 : 0 : void AutoFmtPreview::Init()
887 : : {
888 : 0 : SetBorderStyle( GetBorderStyle() | WINDOW_BORDER_MONO );
889 : 0 : maArray.Initialize( 5, 5 );
890 : 0 : maArray.SetUseDiagDoubleClipping( false );
891 : 0 : CalcCellArray( sal_False );
892 : 0 : CalcLineMap();
893 : 0 : }
894 : :
895 : : //------------------------------------------------------------------------
896 : :
897 : :
898 : 0 : void AutoFmtPreview::CalcCellArray( sal_Bool _bFitWidth )
899 : : {
900 : 0 : maArray.SetXOffset( 2 );
901 : 0 : maArray.SetAllColWidths( _bFitWidth ? nDataColWidth2 : nDataColWidth1 );
902 : 0 : maArray.SetColWidth( 0, nLabelColWidth );
903 : 0 : maArray.SetColWidth( 4, nLabelColWidth );
904 : :
905 : 0 : maArray.SetYOffset( 2 );
906 : 0 : maArray.SetAllRowHeights( nRowHeight );
907 : :
908 : 0 : aPrvSize.Width() = maArray.GetWidth() + 4;
909 : 0 : aPrvSize.Height() = maArray.GetHeight() + 4;
910 : 0 : }
911 : :
912 : : //------------------------------------------------------------------------
913 : :
914 : 0 : inline void lclSetStyleFromBorder( svx::frame::Style& rStyle, const ::editeng::SvxBorderLine* pBorder )
915 : : {
916 : 0 : rStyle.Set( pBorder, 0.05, 5 );
917 : 0 : }
918 : :
919 : 0 : void AutoFmtPreview::CalcLineMap()
920 : : {
921 : 0 : for( size_t nRow = 0; nRow < 5; ++nRow )
922 : : {
923 : 0 : for( size_t nCol = 0; nCol < 5; ++nCol )
924 : : {
925 : 0 : svx::frame::Style aStyle;
926 : :
927 : 0 : const SvxBoxItem& rItem = GetBoxItem( nCol, nRow );
928 : 0 : lclSetStyleFromBorder( aStyle, rItem.GetLeft() );
929 : 0 : maArray.SetCellStyleLeft( nCol, nRow, aStyle );
930 : 0 : lclSetStyleFromBorder( aStyle, rItem.GetRight() );
931 : 0 : maArray.SetCellStyleRight( nCol, nRow, aStyle );
932 : 0 : lclSetStyleFromBorder( aStyle, rItem.GetTop() );
933 : 0 : maArray.SetCellStyleTop( nCol, nRow, aStyle );
934 : 0 : lclSetStyleFromBorder( aStyle, rItem.GetBottom() );
935 : 0 : maArray.SetCellStyleBottom( nCol, nRow, aStyle );
936 : :
937 : : // FIXME - uncomment to draw diagonal borders
938 : : // lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, true ).GetLine() );
939 : : // maArray.SetCellStyleTLBR( nCol, nRow, aStyle );
940 : : // lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, false ).GetLine() );
941 : : // maArray.SetCellStyleBLTR( nCol, nRow, aStyle );
942 : : }
943 : : }
944 : 0 : }
945 : :
946 : : //------------------------------------------------------------------------
947 : :
948 : :
949 : 0 : void AutoFmtPreview::NotifyChange( const SwTableAutoFmt& rNewData )
950 : : {
951 : 0 : aCurData = rNewData;
952 : 0 : bFitWidth = aCurData.IsJustify();//sal_True; //???
953 : 0 : CalcCellArray( bFitWidth );
954 : 0 : CalcLineMap();
955 : 0 : DoPaint( Rectangle( Point(0,0), GetSizePixel() ) );
956 : 0 : }
957 : :
958 : : //------------------------------------------------------------------------
959 : :
960 : :
961 : 0 : void AutoFmtPreview::DoPaint( const Rectangle& /*rRect*/ )
962 : : {
963 : 0 : sal_uInt32 nOldDrawMode = aVD.GetDrawMode();
964 : 0 : if( GetSettings().GetStyleSettings().GetHighContrastMode() )
965 : 0 : aVD.SetDrawMode( DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
966 : :
967 : 0 : Bitmap thePreview;
968 : 0 : Point aCenterPos;
969 : 0 : Size theWndSize = GetSizePixel();
970 : 0 : Size thePrevSize;
971 : 0 : Color oldColor;
972 : 0 : Font aFont;
973 : :
974 : 0 : aFont = aVD.GetFont();
975 : 0 : aFont.SetTransparent( sal_True );
976 : :
977 : 0 : aVD.SetFont ( aFont );
978 : 0 : aVD.SetLineColor ();
979 : 0 : const Color& rWinColor = GetSettings().GetStyleSettings().GetWindowColor();
980 : 0 : aVD.SetBackground ( Wallpaper(rWinColor) );
981 : 0 : aVD.SetFillColor ( rWinColor );
982 : 0 : aVD.SetOutputSizePixel ( aPrvSize );
983 : :
984 : : //--------------------------------
985 : : // Zellen auf virtual Device malen
986 : : // und Ergebnis sichern
987 : : //--------------------------------
988 : 0 : PaintCells();
989 : 0 : thePreview = aVD.GetBitmap( Point(0,0), aPrvSize );
990 : :
991 : : //--------------------------------------
992 : : // Rahmen malen und Vorschau zentrieren:
993 : : // (virtual Device fuer Fensterausgabe)
994 : : //--------------------------------------
995 : 0 : aVD.SetOutputSizePixel( theWndSize );
996 : 0 : oldColor = aVD.GetLineColor();
997 : 0 : aVD.SetLineColor();
998 : 0 : aVD.DrawRect( Rectangle( Point(0,0), theWndSize ) );
999 : 0 : SetLineColor( oldColor );
1000 : 0 : aCenterPos = Point( (theWndSize.Width() - aPrvSize.Width() ) / 2,
1001 : 0 : (theWndSize.Height() - aPrvSize.Height()) / 2 );
1002 : 0 : aVD.DrawBitmap( aCenterPos, thePreview );
1003 : :
1004 : : //----------------------------
1005 : : // Ausgabe im Vorschaufenster:
1006 : : //----------------------------
1007 : 0 : DrawBitmap( Point(0,0), aVD.GetBitmap( Point(0,0), theWndSize ) );
1008 : :
1009 : 0 : aVD.SetDrawMode( nOldDrawMode );
1010 : 0 : }
1011 : :
1012 : : //------------------------------------------------------------------------
1013 : :
1014 : 0 : void AutoFmtPreview::Paint( const Rectangle& rRect )
1015 : : {
1016 : 0 : DoPaint( rRect );
1017 : 0 : }
1018 : :
1019 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|