Update ooo320-m1
[ooovba.git] / sc / source / ui / miscdlgs / autofmt.cxx
blobbf23fc07df711d0444ec827756ffee54e839a68b
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: autofmt.cxx,v $
10 * $Revision: 1.19.122.1 $
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_sc.hxx"
36 //------------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <svx/algitem.hxx>
40 #include <svx/boxitem.hxx>
41 #include <svx/brshitem.hxx>
42 #include <svx/cntritem.hxx>
43 #include <svx/colritem.hxx>
44 #include <svx/crsditem.hxx>
45 #include <svx/fontitem.hxx>
46 #include <svx/postitem.hxx>
47 #include <svx/shdditem.hxx>
48 #include <svx/udlnitem.hxx>
49 #include <svx/wghtitem.hxx>
50 #include <sfx2/topfrm.hxx>
51 #include <vcl/svapp.hxx>
52 #include <svtools/zforlist.hxx>
53 #include <vcl/msgbox.hxx>
54 #include <comphelper/processfactory.hxx>
56 #include "sc.hrc"
57 #include "scmod.hxx"
58 #include "attrib.hxx"
59 #include "zforauto.hxx"
60 #include "scitems.hxx"
61 #include "global.hxx"
62 #include "globstr.hrc"
63 #include "autoform.hxx"
64 //CHINA001 #include "strindlg.hxx"
65 #include "miscdlgs.hrc"
66 #include "autofmt.hxx"
67 #include "scresid.hxx"
68 #include "document.hxx"
69 #include "docsh.hxx"
70 #include "tabvwsh.hxx"
72 #define FRAME_OFFSET 4
74 BOOL bIsOlk = FALSE;
77 //CHINA001 //========================================================================
78 //CHINA001 // AutoFormat-Dialog:
79 //CHINA001
80 //CHINA001 ScAutoFormatDlg::ScAutoFormatDlg( Window* pParent,
81 //CHINA001 ScAutoFormat* pAutoFormat,
82 //CHINA001 const ScAutoFormatData* pSelFormatData,
83 //CHINA001 ScDocument* pDoc ) :
84 //CHINA001
85 //CHINA001 ModalDialog ( pParent, ScResId( RID_SCDLG_AUTOFORMAT ) ),
86 //CHINA001 //
87 //CHINA001 aLbFormat ( this, ScResId( LB_FORMAT ) ),
88 //CHINA001 aFlFormat ( this, ScResId( FL_FORMAT ) ),
89 //CHINA001 pWndPreview ( new ScAutoFmtPreview( this, ScResId( WND_PREVIEW ), pDoc ) ),
90 //CHINA001 aBtnNumFormat ( this, ScResId( BTN_NUMFORMAT ) ),
91 //CHINA001 aBtnBorder ( this, ScResId( BTN_BORDER ) ),
92 //CHINA001 aBtnFont ( this, ScResId( BTN_FONT ) ),
93 //CHINA001 aBtnPattern ( this, ScResId( BTN_PATTERN ) ),
94 //CHINA001 aBtnAlignment ( this, ScResId( BTN_ALIGNMENT ) ),
95 //CHINA001 aBtnAdjust ( this, ScResId( BTN_ADJUST ) ),
96 //CHINA001 aFlFormatting ( this, ScResId( FL_FORMATTING ) ),
97 //CHINA001 aBtnOk ( this, ScResId( BTN_OK ) ),
98 //CHINA001 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
99 //CHINA001 aBtnHelp ( this, ScResId( BTN_HELP ) ),
100 //CHINA001 aBtnAdd ( this, ScResId( BTN_ADD ) ),
101 //CHINA001 aBtnRemove ( this, ScResId( BTN_REMOVE ) ),
102 //CHINA001 aBtnMore ( this, ScResId( BTN_MORE ) ),
103 //CHINA001 aBtnRename ( this, ScResId( BTN_RENAME ) ),
104 //CHINA001 aStrTitle ( ScResId( STR_ADD_TITLE ) ),
105 //CHINA001 aStrLabel ( ScResId( STR_ADD_LABEL ) ),
106 //CHINA001 aStrRename ( ScResId( STR_RENAME_TITLE ) ),
107 //CHINA001 aStrClose ( ScResId( STR_BTN_CLOSE ) ),
108 //CHINA001 aStrDelTitle ( ScResId( STR_DEL_TITLE ) ),
109 //CHINA001 aStrDelMsg ( ScResId( STR_DEL_MSG ) ) ,
110 //CHINA001 //
111 //CHINA001 nIndex ( 0 ),
112 //CHINA001 bFmtInserted ( FALSE ),
113 //CHINA001 bCoreDataChanged( FALSE ),
114 //CHINA001 pFormat ( pAutoFormat ),
115 //CHINA001 pSelFmtData ( pSelFormatData )
116 //CHINA001 {
117 //CHINA001 Init();
118 //CHINA001 pWndPreview->NotifyChange( (*pFormat)[0] );
119 //CHINA001 FreeResource();
120 //CHINA001 }
121 //CHINA001
122 //CHINA001 //------------------------------------------------------------------------
123 //CHINA001
124 //CHINA001 ScAutoFormatDlg::~ScAutoFormatDlg()
125 //CHINA001 {
126 //CHINA001 delete pWndPreview;
127 //CHINA001 }
128 //CHINA001
129 //CHINA001 //------------------------------------------------------------------------
130 //CHINA001
131 //CHINA001 void ScAutoFormatDlg::Init()
132 //CHINA001 {
133 //CHINA001 USHORT nCount;
134 //CHINA001 String aEntry;
135 //CHINA001
136 //CHINA001 aLbFormat .SetSelectHdl( LINK( this, ScAutoFormatDlg, SelFmtHdl ) );
137 //CHINA001 aBtnNumFormat.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
138 //CHINA001 aBtnBorder .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
139 //CHINA001 aBtnFont .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
140 //CHINA001 aBtnPattern .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
141 //CHINA001 aBtnAlignment.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
142 //CHINA001 aBtnAdjust .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
143 //CHINA001 aBtnAdd .SetClickHdl ( LINK( this, ScAutoFormatDlg, AddHdl ) );
144 //CHINA001 aBtnRemove .SetClickHdl ( LINK( this, ScAutoFormatDlg, RemoveHdl ) );
145 //CHINA001 aBtnOk .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
146 //CHINA001 aBtnCancel .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
147 //CHINA001 aBtnRename .SetClickHdl ( LINK( this, ScAutoFormatDlg, RenameHdl ) );
148 //CHINA001 aLbFormat .SetDoubleClickHdl( LINK( this, ScAutoFormatDlg, DblClkHdl ) );
149 //CHINA001
150 //CHINA001 aBtnMore.AddWindow( &aBtnRename );
151 //CHINA001 aBtnMore.AddWindow( &aBtnNumFormat );
152 //CHINA001 aBtnMore.AddWindow( &aBtnBorder );
153 //CHINA001 aBtnMore.AddWindow( &aBtnFont );
154 //CHINA001 aBtnMore.AddWindow( &aBtnPattern );
155 //CHINA001 aBtnMore.AddWindow( &aBtnAlignment );
156 //CHINA001 aBtnMore.AddWindow( &aBtnAdjust );
157 //CHINA001 aBtnMore.AddWindow( &aFlFormatting );
158 //CHINA001
159 //CHINA001 nCount = pFormat->GetCount();
160 //CHINA001
161 //CHINA001 for ( USHORT i = 0; i < nCount; i++ )
162 //CHINA001 {
163 //CHINA001 ((*pFormat)[i])->GetName( aEntry );
164 //CHINA001 aLbFormat.InsertEntry( aEntry );
165 //CHINA001 }
166 //CHINA001
167 //CHINA001 if ( nCount == 1 )
168 //CHINA001 aBtnRemove.Disable();
169 //CHINA001
170 //CHINA001 aLbFormat.SelectEntryPos( 0 );
171 //CHINA001 aBtnRename.Disable();
172 //CHINA001 aBtnRemove.Disable();
173 //CHINA001
174 //CHINA001 nIndex = 0;
175 //CHINA001 UpdateChecks();
176 //CHINA001
177 //CHINA001 if ( !pSelFmtData )
178 //CHINA001 {
179 //CHINA001 aBtnAdd.Disable();
180 //CHINA001 aBtnRemove.Disable();
181 //CHINA001 bFmtInserted = TRUE;
182 //CHINA001 }
183 //CHINA001 }
184 //CHINA001
185 //CHINA001 //------------------------------------------------------------------------
186 //CHINA001
187 //CHINA001 void ScAutoFormatDlg::UpdateChecks()
188 //CHINA001 {
189 //CHINA001 ScAutoFormatData* pData = (*pFormat)[nIndex];
190 //CHINA001
191 //CHINA001 aBtnNumFormat.Check( pData->GetIncludeValueFormat() );
192 //CHINA001 aBtnBorder .Check( pData->GetIncludeFrame() );
193 //CHINA001 aBtnFont .Check( pData->GetIncludeFont() );
194 //CHINA001 aBtnPattern .Check( pData->GetIncludeBackground() );
195 //CHINA001 aBtnAlignment.Check( pData->GetIncludeJustify() );
196 //CHINA001 aBtnAdjust .Check( pData->GetIncludeWidthHeight() );
197 //CHINA001 }
198 //CHINA001
199 //CHINA001 //------------------------------------------------------------------------
200 //CHINA001 // Handler:
201 //CHINA001 //---------
202 //CHINA001
203 //CHINA001 IMPL_LINK( ScAutoFormatDlg, CloseHdl, PushButton *, pBtn )
204 //CHINA001 {
205 //CHINA001 if ( pBtn == &aBtnOk || pBtn == &aBtnCancel )
206 //CHINA001 {
207 //CHINA001 if ( bCoreDataChanged )
208 //CHINA001 ScGlobal::GetAutoFormat()->Save();
209 //CHINA001
210 //CHINA001 EndDialog( (pBtn == &aBtnOk) ? RET_OK : RET_CANCEL );
211 //CHINA001 }
212 //CHINA001 return 0;
213 //CHINA001 }
214 //CHINA001
215 //CHINA001 //------------------------------------------------------------------------
216 //CHINA001
217 //CHINA001 IMPL_LINK_INLINE_START( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG )
218 //CHINA001 {
219 //CHINA001 if ( bCoreDataChanged )
220 //CHINA001 ScGlobal::GetAutoFormat()->Save();
221 //CHINA001
222 //CHINA001 EndDialog( RET_OK );
223 //CHINA001 return 0;
224 //CHINA001 }
225 //CHINA001 IMPL_LINK_INLINE_END( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG )
226 //CHINA001
227 //CHINA001 //------------------------------------------------------------------------
228 //CHINA001
229 //CHINA001 IMPL_LINK( ScAutoFormatDlg, CheckHdl, Button *, pBtn )
230 //CHINA001 {
231 //CHINA001 ScAutoFormatData* pData = (*pFormat)[nIndex];
232 //CHINA001 BOOL bCheck = ((CheckBox*)pBtn)->IsChecked();
233 //CHINA001
234 //CHINA001 if ( pBtn == &aBtnNumFormat )
235 //CHINA001 pData->SetIncludeValueFormat( bCheck );
236 //CHINA001 else if ( pBtn == &aBtnBorder )
237 //CHINA001 pData->SetIncludeFrame( bCheck );
238 //CHINA001 else if ( pBtn == &aBtnFont )
239 //CHINA001 pData->SetIncludeFont( bCheck );
240 //CHINA001 else if ( pBtn == &aBtnPattern )
241 //CHINA001 pData->SetIncludeBackground( bCheck );
242 //CHINA001 else if ( pBtn == &aBtnAlignment )
243 //CHINA001 pData->SetIncludeJustify( bCheck );
244 //CHINA001 else if ( pBtn == &aBtnAdjust )
245 //CHINA001 pData->SetIncludeWidthHeight( bCheck );
246 //CHINA001
247 //CHINA001 if ( !bCoreDataChanged )
248 //CHINA001 {
249 //CHINA001 aBtnCancel.SetText( aStrClose );
250 //CHINA001 bCoreDataChanged = TRUE;
251 //CHINA001 }
252 //CHINA001
253 //CHINA001 pWndPreview->NotifyChange( pData );
254 //CHINA001
255 //CHINA001 return 0;
256 //CHINA001 }
257 //CHINA001
258 //CHINA001 //------------------------------------------------------------------------
259 //CHINA001
260 //CHINA001 IMPL_LINK( ScAutoFormatDlg, AddHdl, void *, EMPTYARG )
261 //CHINA001 {
262 //CHINA001 if ( !bFmtInserted && pSelFmtData )
263 //CHINA001 {
264 //CHINA001 String aStrStandard( ScResId(STR_STANDARD) );
265 //CHINA001 String aFormatName;
266 //CHINA001 ScStringInputDlg* pDlg;
267 //CHINA001 BOOL bOk = FALSE;
268 //CHINA001
269 //CHINA001 while ( !bOk )
270 //CHINA001 {
271 //CHINA001 pDlg = new ScStringInputDlg( this,
272 //CHINA001 aStrTitle,
273 //CHINA001 aStrLabel,
274 //CHINA001 aFormatName,
275 //CHINA001 HID_SC_ADD_AUTOFMT );
276 //CHINA001
277 //CHINA001 if ( pDlg->Execute() == RET_OK )
278 //CHINA001 {
279 //CHINA001 pDlg->GetInputString( aFormatName );
280 //CHINA001
281 //CHINA001 if ( (aFormatName.Len() > 0) && (aFormatName != aStrStandard) )
282 //CHINA001 {
283 //CHINA001 ScAutoFormatData* pNewData
284 //CHINA001 = new ScAutoFormatData( *pSelFmtData );
285 //CHINA001
286 //CHINA001 pNewData->SetName( aFormatName );
287 //CHINA001 bFmtInserted = pFormat->Insert( pNewData );
288 //CHINA001
289 //CHINA001 if ( bFmtInserted )
290 //CHINA001 {
291 //CHINA001 USHORT nAt = pFormat->IndexOf( pNewData );
292 //CHINA001
293 //CHINA001 aLbFormat.InsertEntry( aFormatName, nAt );
294 //CHINA001 aLbFormat.SelectEntry( aFormatName );
295 //CHINA001 aBtnAdd.Disable();
296 //CHINA001
297 //CHINA001 if ( !bCoreDataChanged )
298 //CHINA001 {
299 //CHINA001 aBtnCancel.SetText( aStrClose );
300 //CHINA001 bCoreDataChanged = TRUE;
301 //CHINA001 }
302 //CHINA001
303 //CHINA001 SelFmtHdl( 0 );
304 //CHINA001 bOk = TRUE;
305 //CHINA001 }
306 //CHINA001 else
307 //CHINA001 delete pNewData;
308 //CHINA001
309 //CHINA001 }
310 //CHINA001
311 //CHINA001 if ( !bFmtInserted )
312 //CHINA001 {
313 //CHINA001 USHORT nRet = ErrorBox( this,
314 //CHINA001 WinBits( WB_OK_CANCEL | WB_DEF_OK),
315 //CHINA001 ScGlobal::GetRscString(STR_INVALID_AFNAME)
316 //CHINA001 ).Execute();
317 //CHINA001
318 //CHINA001 bOk = ( nRet == RET_CANCEL );
319 //CHINA001 }
320 //CHINA001 }
321 //CHINA001 else
322 //CHINA001 bOk = TRUE;
323 //CHINA001
324 //CHINA001 delete pDlg;
325 //CHINA001 }
326 //CHINA001 }
327 //CHINA001
328 //CHINA001 return 0;
329 //CHINA001 }
330 //CHINA001
331 //CHINA001 //------------------------------------------------------------------------
332 //CHINA001
333 //CHINA001 IMPL_LINK( ScAutoFormatDlg, RemoveHdl, void *, EMPTYARG )
334 //CHINA001 {
335 //CHINA001 if ( (nIndex > 0) && (aLbFormat.GetEntryCount() > 0) )
336 //CHINA001 {
337 //CHINA001 String aMsg( aStrDelMsg.GetToken( 0, '#' ) );
338 //CHINA001
339 //CHINA001 aMsg += aLbFormat.GetSelectEntry();
340 //CHINA001 aMsg += aStrDelMsg.GetToken( 1, '#' );
341 //CHINA001
342 //CHINA001 if ( RET_YES ==
343 //CHINA001 QueryBox( this, WinBits( WB_YES_NO | WB_DEF_YES ), aMsg ).Execute() )
344 //CHINA001 {
345 //CHINA001 aLbFormat.RemoveEntry( nIndex );
346 //CHINA001 aLbFormat.SelectEntryPos( nIndex-1 );
347 //CHINA001
348 //CHINA001 if ( nIndex-1 == 0 )
349 //CHINA001 aBtnRemove.Disable();
350 //CHINA001
351 //CHINA001 if ( !bCoreDataChanged )
352 //CHINA001 {
353 //CHINA001 aBtnCancel.SetText( aStrClose );
354 //CHINA001 bCoreDataChanged = TRUE;
355 //CHINA001 }
356 //CHINA001
357 //CHINA001 pFormat->AtFree( nIndex ); // in der Core loeschen
358 //CHINA001 nIndex--;
359 //CHINA001
360 //CHINA001 SelFmtHdl( 0 );
361 //CHINA001 }
362 //CHINA001 }
363 //CHINA001
364 //CHINA001 SelFmtHdl( 0 );
365 //CHINA001
366 //CHINA001 return 0;
367 //CHINA001 }
368 //CHINA001
369 //CHINA001 IMPL_LINK( ScAutoFormatDlg, RenameHdl, void *, pBtn)
370 //CHINA001 {
371 //CHINA001 BOOL bOk = FALSE;
372 //CHINA001 while( !bOk )
373 //CHINA001 {
374 //CHINA001
375 //CHINA001 String aFormatName=aLbFormat.GetSelectEntry();
376 //CHINA001 String aEntry;
377 //CHINA001
378 //CHINA001 ScStringInputDlg* pDlg = new ScStringInputDlg( this,
379 //CHINA001 aStrRename,
380 //CHINA001 aStrLabel,
381 //CHINA001 aFormatName,
382 //CHINA001 HID_SC_RENAME_AUTOFMT );
383 //CHINA001 if( pDlg->Execute() == RET_OK )
384 //CHINA001 {
385 //CHINA001 BOOL bFmtRenamed = FALSE;
386 //CHINA001 pDlg->GetInputString( aFormatName );
387 //CHINA001 USHORT n;
388 //CHINA001
389 //CHINA001 if ( aFormatName.Len() > 0 )
390 //CHINA001 {
391 //CHINA001 for( n = 0; n < pFormat->GetCount(); ++n )
392 //CHINA001 {
393 //CHINA001 (*pFormat)[n]->GetName(aEntry);
394 //CHINA001 if ( aEntry== aFormatName)
395 //CHINA001 break;
396 //CHINA001 }
397 //CHINA001 if( n >= pFormat->GetCount() )
398 //CHINA001 {
399 //CHINA001 // Format mit dem Namen noch nicht vorhanden, also
400 //CHINA001 // umbenennen
401 //CHINA001
402 //CHINA001 aLbFormat.RemoveEntry(nIndex );
403 //CHINA001 ScAutoFormatData* p=(*pFormat)[ nIndex ];
404 //CHINA001 ScAutoFormatData* pNewData
405 //CHINA001 = new ScAutoFormatData(*p);
406 //CHINA001
407 //CHINA001 pFormat->AtFree( nIndex );
408 //CHINA001
409 //CHINA001 pNewData->SetName( aFormatName );
410 //CHINA001
411 //CHINA001 pFormat->Insert( pNewData);
412 //CHINA001
413 //CHINA001 USHORT nCount = pFormat->GetCount();
414 //CHINA001
415 //CHINA001 aLbFormat.SetUpdateMode(FALSE);
416 //CHINA001 aLbFormat.Clear();
417 //CHINA001 for ( USHORT i = 0; i < nCount; i++ )
418 //CHINA001 {
419 //CHINA001 ((*pFormat)[i])->GetName( aEntry );
420 //CHINA001 aLbFormat.InsertEntry( aEntry );
421 //CHINA001 }
422 //CHINA001
423 //CHINA001 aLbFormat.SetUpdateMode( TRUE);
424 //CHINA001 aLbFormat.SelectEntry( aFormatName);
425 //CHINA001
426 //CHINA001 if ( !bCoreDataChanged )
427 //CHINA001 {
428 //CHINA001 aBtnCancel.SetText( aStrClose );
429 //CHINA001 bCoreDataChanged = TRUE;
430 //CHINA001 }
431 //CHINA001
432 //CHINA001
433 //CHINA001 SelFmtHdl( 0 );
434 //CHINA001 bOk = TRUE;
435 //CHINA001 bFmtRenamed = TRUE;
436 //CHINA001 }
437 //CHINA001 }
438 //CHINA001 if( !bFmtRenamed )
439 //CHINA001 {
440 //CHINA001 bOk = RET_CANCEL == ErrorBox( this,
441 //CHINA001 WinBits( WB_OK_CANCEL | WB_DEF_OK),
442 //CHINA001 ScGlobal::GetRscString(STR_INVALID_AFNAME)
443 //CHINA001 ).Execute();
444 //CHINA001 }
445 //CHINA001 }
446 //CHINA001 else
447 //CHINA001 bOk = TRUE;
448 //CHINA001 delete pDlg;
449 //CHINA001 }
450 //CHINA001
451 //CHINA001 return 0;
452 //CHINA001 }
453 //CHINA001
454 //CHINA001 //------------------------------------------------------------------------
455 //CHINA001
456 //CHINA001 IMPL_LINK( ScAutoFormatDlg, SelFmtHdl, void *, EMPTYARG )
457 //CHINA001 {
458 //CHINA001 nIndex = aLbFormat.GetSelectEntryPos();
459 //CHINA001 UpdateChecks();
460 //CHINA001
461 //CHINA001 if ( nIndex == 0 )
462 //CHINA001 {
463 //CHINA001 aBtnRename.Disable();
464 //CHINA001 aBtnRemove.Disable();
465 //CHINA001 }
466 //CHINA001 else
467 //CHINA001 {
468 //CHINA001 aBtnRename.Enable();
469 //CHINA001 aBtnRemove.Enable();
470 //CHINA001 }
471 //CHINA001
472 //CHINA001 pWndPreview->NotifyChange( (*pFormat)[nIndex] );
473 //CHINA001
474 //CHINA001 return 0;
475 //CHINA001 }
476 //CHINA001
477 //CHINA001 //------------------------------------------------------------------------
478 //CHINA001
479 //CHINA001 String ScAutoFormatDlg::GetCurrFormatName()
480 //CHINA001 {
481 //CHINA001 String aResult;
482 //CHINA001
483 //CHINA001 ((*pFormat)[nIndex])->GetName( aResult );
484 //CHINA001
485 //CHINA001 return aResult;
486 //CHINA001 }
487 //CHINA001
488 //========================================================================
489 // ScAutoFmtPreview
491 ScAutoFmtPreview::ScAutoFmtPreview( Window* pParent, const ResId& rRes, ScDocument* pDoc ) :
492 Window ( pParent, rRes ),
493 pCurData ( NULL ),
494 aVD ( *this ),
495 aScriptedText ( aVD ),
496 xBreakIter ( pDoc->GetBreakIterator() ),
497 bFitWidth ( FALSE ),
498 mbRTL ( false ),
499 aPrvSize ( GetSizePixel().Width() - 6, GetSizePixel().Height() - 30 ),
500 mnLabelColWidth ( (aPrvSize.Width() - 4) / 4 - 12 ),
501 mnDataColWidth1 ( (aPrvSize.Width() - 4 - 2 * mnLabelColWidth) / 3 ),
502 mnDataColWidth2 ( (aPrvSize.Width() - 4 - 2 * mnLabelColWidth) / 4 ),
503 mnRowHeight ( (aPrvSize.Height() - 4) / 5 ),
504 aStrJan ( ScResId( STR_JAN ) ),
505 aStrFeb ( ScResId( STR_FEB ) ),
506 aStrMar ( ScResId( STR_MAR ) ),
507 aStrNorth ( ScResId( STR_NORTH ) ),
508 aStrMid ( ScResId( STR_MID ) ),
509 aStrSouth ( ScResId( STR_SOUTH ) ),
510 aStrSum ( ScResId( STR_SUM ) ),
511 pNumFmt ( new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), ScGlobal::eLnge ) )
513 Init();
514 if( bIsOlk )
515 ((String&)aStrMar).AssignAscii(RTL_CONSTASCII_STRINGPARAM( "Olk" ));
518 //------------------------------------------------------------------------
520 ScAutoFmtPreview::~ScAutoFmtPreview()
522 delete pNumFmt;
525 //------------------------------------------------------------------------
527 void lcl_SetFontProperties(
528 Font& rFont,
529 const SvxFontItem& rFontItem,
530 const SvxWeightItem& rWeightItem,
531 const SvxPostureItem& rPostureItem )
533 rFont.SetFamily ( rFontItem.GetFamily() );
534 rFont.SetName ( rFontItem.GetFamilyName() );
535 rFont.SetStyleName ( rFontItem.GetStyleName() );
536 rFont.SetCharSet ( rFontItem.GetCharSet() );
537 rFont.SetPitch ( rFontItem.GetPitch() );
538 rFont.SetWeight ( (FontWeight)rWeightItem.GetValue() );
539 rFont.SetItalic ( (FontItalic)rPostureItem.GetValue() );
542 void ScAutoFmtPreview::MakeFonts( USHORT nIndex, Font& rFont, Font& rCJKFont, Font& rCTLFont )
544 if ( pCurData )
546 rFont = rCJKFont = rCTLFont = GetFont();
547 Size aFontSize( rFont.GetSize().Width(), 10 );
549 const SvxFontItem* pFontItem = (const SvxFontItem*) pCurData->GetItem( nIndex, ATTR_FONT );
550 const SvxWeightItem* pWeightItem = (const SvxWeightItem*) pCurData->GetItem( nIndex, ATTR_FONT_WEIGHT );
551 const SvxPostureItem* pPostureItem = (const SvxPostureItem*) pCurData->GetItem( nIndex, ATTR_FONT_POSTURE );
552 const SvxFontItem* pCJKFontItem = (const SvxFontItem*) pCurData->GetItem( nIndex, ATTR_CJK_FONT );
553 const SvxWeightItem* pCJKWeightItem = (const SvxWeightItem*) pCurData->GetItem( nIndex, ATTR_CJK_FONT_WEIGHT );
554 const SvxPostureItem* pCJKPostureItem = (const SvxPostureItem*) pCurData->GetItem( nIndex, ATTR_CJK_FONT_POSTURE );
555 const SvxFontItem* pCTLFontItem = (const SvxFontItem*) pCurData->GetItem( nIndex, ATTR_CTL_FONT );
556 const SvxWeightItem* pCTLWeightItem = (const SvxWeightItem*) pCurData->GetItem( nIndex, ATTR_CTL_FONT_WEIGHT );
557 const SvxPostureItem* pCTLPostureItem = (const SvxPostureItem*) pCurData->GetItem( nIndex, ATTR_CTL_FONT_POSTURE );
558 const SvxUnderlineItem* pUnderlineItem = (const SvxUnderlineItem*) pCurData->GetItem( nIndex, ATTR_FONT_UNDERLINE );
559 const SvxOverlineItem* pOverlineItem = (const SvxOverlineItem*) pCurData->GetItem( nIndex, ATTR_FONT_OVERLINE );
560 const SvxCrossedOutItem* pCrossedOutItem = (const SvxCrossedOutItem*)pCurData->GetItem( nIndex, ATTR_FONT_CROSSEDOUT );
561 const SvxContourItem* pContourItem = (const SvxContourItem*) pCurData->GetItem( nIndex, ATTR_FONT_CONTOUR );
562 const SvxShadowedItem* pShadowedItem = (const SvxShadowedItem*) pCurData->GetItem( nIndex, ATTR_FONT_SHADOWED );
563 const SvxColorItem* pColorItem = (const SvxColorItem*) pCurData->GetItem( nIndex, ATTR_FONT_COLOR );
565 lcl_SetFontProperties( rFont, *pFontItem, *pWeightItem, *pPostureItem );
566 lcl_SetFontProperties( rCJKFont, *pCJKFontItem, *pCJKWeightItem, *pCJKPostureItem );
567 lcl_SetFontProperties( rCTLFont, *pCTLFontItem, *pCTLWeightItem, *pCTLPostureItem );
569 Color aColor( pColorItem->GetValue() );
570 if( aColor.GetColor() == COL_TRANSPARENT )
571 aColor = GetSettings().GetStyleSettings().GetWindowTextColor();
573 #define SETONALLFONTS( MethodName, Value ) \
574 rFont.MethodName( Value ); rCJKFont.MethodName( Value ); rCTLFont.MethodName( Value );
576 SETONALLFONTS( SetUnderline, (FontUnderline)pUnderlineItem->GetValue() )
577 SETONALLFONTS( SetOverline, (FontUnderline)pOverlineItem->GetValue() )
578 SETONALLFONTS( SetStrikeout, (FontStrikeout)pCrossedOutItem->GetValue() )
579 SETONALLFONTS( SetOutline, pContourItem->GetValue() )
580 SETONALLFONTS( SetShadow, pShadowedItem->GetValue() )
581 SETONALLFONTS( SetColor, aColor )
582 SETONALLFONTS( SetSize, aFontSize )
583 SETONALLFONTS( SetTransparent, TRUE )
585 #undef SETONALLFONTS
589 //------------------------------------------------------------------------
591 USHORT ScAutoFmtPreview::GetFormatIndex( size_t nCol, size_t nRow ) const
593 static const USHORT pnFmtMap[] =
595 0, 1, 2, 1, 3,
596 4, 5, 6, 5, 7,
597 8, 9, 10, 9, 11,
598 4, 5, 6, 5, 7,
599 12, 13, 14, 13, 15
601 return pnFmtMap[ maArray.GetCellIndex( nCol, nRow, mbRTL ) ];
604 const SvxBoxItem& ScAutoFmtPreview::GetBoxItem( size_t nCol, size_t nRow ) const
606 DBG_ASSERT( pCurData, "ScAutoFmtPreview::GetBoxItem - no format data found" );
607 return *static_cast< const SvxBoxItem* >( pCurData->GetItem( GetFormatIndex( nCol, nRow ), ATTR_BORDER ) );
610 const SvxLineItem& ScAutoFmtPreview::GetDiagItem( size_t nCol, size_t nRow, bool bTLBR ) const
612 DBG_ASSERT( pCurData, "ScAutoFmtPreview::GetDiagItem - no format data found" );
613 return *static_cast< const SvxLineItem* >( pCurData->GetItem( GetFormatIndex( nCol, nRow ), bTLBR ? ATTR_BORDER_TLBR : ATTR_BORDER_BLTR ) );
616 //------------------------------------------------------------------------
618 void ScAutoFmtPreview::DrawString( size_t nCol, size_t nRow )
620 if ( pCurData )
622 //------------------------
623 // Ausgabe des Zelltextes:
624 //------------------------
626 String cellString;
627 BOOL bNumFormat = pCurData->GetIncludeValueFormat();
628 ULONG nNum;
629 double nVal;
630 Color* pDummy = NULL;
631 USHORT nIndex = static_cast< USHORT >( maArray.GetCellIndex( nCol, nRow, mbRTL ) );
633 switch( nIndex )
635 case 1: cellString = aStrJan; break;
636 case 2: cellString = aStrFeb; break;
637 case 3: cellString = aStrMar; break;
638 case 5: cellString = aStrNorth; break;
639 case 10: cellString = aStrMid; break;
640 case 15: cellString = aStrSouth; break;
641 case 4:
642 case 20: cellString = aStrSum; break;
644 case 6:
645 case 8:
646 case 16:
647 case 18: nVal = nIndex;
648 nNum = 5;
649 goto mknum;
650 case 17:
651 case 7: nVal = nIndex;
652 nNum = 6;
653 goto mknum;
654 case 11:
655 case 12:
656 case 13: nVal = nIndex;
657 nNum = 12 == nIndex ? 10 : 9;
658 goto mknum;
660 case 9: nVal = 21; nNum = 7; goto mknum;
661 case 14: nVal = 36; nNum = 11; goto mknum;
662 case 19: nVal = 51; nNum = 7; goto mknum;
663 case 21: nVal = 33; nNum = 13; goto mknum;
664 case 22: nVal = 36; nNum = 14; goto mknum;
665 case 23: nVal = 39; nNum = 13; goto mknum;
666 case 24: nVal = 108; nNum = 15;
667 mknum:
668 if( bNumFormat )
670 ScNumFormatAbbrev& rNumFormat = (ScNumFormatAbbrev&)pCurData->GetNumFormat( (USHORT) nNum );
671 nNum = rNumFormat.GetFormatIndex( *pNumFmt );
673 else
674 nNum = 0;
675 pNumFmt->GetOutputString( nVal, nNum, cellString, &pDummy );
676 break;
679 if ( cellString.Len() > 0 )
681 Size aStrSize;
682 USHORT nFmtIndex = GetFormatIndex( nCol, nRow );
683 Rectangle cellRect = maArray.GetCellRect( nCol, nRow );
684 Point aPos = cellRect.TopLeft();
685 USHORT nRightX = 0;
686 BOOL bJustify = pCurData->GetIncludeJustify();
687 SvxHorJustifyItem aHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY );
688 SvxCellHorJustify eJustification;
690 //-------------
691 // Ausrichtung:
692 //-------------
693 eJustification = mbRTL ? SVX_HOR_JUSTIFY_RIGHT : bJustify ?
694 (SvxCellHorJustify)(((const SvxHorJustifyItem*)pCurData->GetItem( nFmtIndex, ATTR_HOR_JUSTIFY ))->GetValue()) :
695 SVX_HOR_JUSTIFY_STANDARD;
697 if ( pCurData->GetIncludeFont() )
699 Font aFont, aCJKFont, aCTLFont;
700 Size theMaxStrSize;
702 MakeFonts( nFmtIndex, aFont, aCJKFont, aCTLFont );
704 theMaxStrSize = cellRect.GetSize();
705 theMaxStrSize.Width() -= FRAME_OFFSET;
706 theMaxStrSize.Height() -= FRAME_OFFSET;
708 aScriptedText.SetFonts( &aFont, &aCJKFont, &aCTLFont );
709 aScriptedText.SetText( cellString, xBreakIter );
710 aStrSize = aScriptedText.GetTextSize();
712 if ( theMaxStrSize.Height() < aStrSize.Height() )
714 // wenn der String in diesem Font nicht
715 // in die Zelle passt, wird wieder der
716 // Standard-Font genommen:
717 aScriptedText.SetDefaultFont();
718 aStrSize = aScriptedText.GetTextSize();
720 while ( ( theMaxStrSize.Width() <= aStrSize.Width() )
721 && ( cellString.Len() > 1 ) )
723 if( eJustification == SVX_HOR_JUSTIFY_RIGHT )
724 cellString.Erase( 0, 1 );
725 else
726 cellString.Erase( cellString.Len() - 1 );
728 aScriptedText.SetText( cellString, xBreakIter );
729 aStrSize = aScriptedText.GetTextSize();
732 else
734 aScriptedText.SetDefaultFont();
735 aScriptedText.SetText( cellString, xBreakIter );
736 aStrSize = aScriptedText.GetTextSize();
739 nRightX = (USHORT)( cellRect.GetWidth()
740 - aStrSize.Width()
741 - FRAME_OFFSET );
743 //-----------------------------
744 // vertikal (immer zentrieren):
745 //-----------------------------
746 aPos.Y() += (mnRowHeight - (USHORT)aStrSize.Height()) / 2;
748 //-----------
749 // horizontal
750 //-----------
751 if ( eJustification != SVX_HOR_JUSTIFY_STANDARD )
753 USHORT nHorPos = (USHORT)
754 ((cellRect.GetWidth()-aStrSize.Width())/2);
756 switch ( eJustification )
758 case SVX_HOR_JUSTIFY_LEFT:
759 aPos.X() += FRAME_OFFSET;
760 break;
761 case SVX_HOR_JUSTIFY_RIGHT:
762 aPos.X() += nRightX;
763 break;
764 case SVX_HOR_JUSTIFY_BLOCK:
765 case SVX_HOR_JUSTIFY_REPEAT:
766 case SVX_HOR_JUSTIFY_CENTER:
767 aPos.X() += nHorPos;
768 break;
769 case SVX_HOR_JUSTIFY_STANDARD:
770 default:
771 // Standard wird hier nicht behandelt
772 break;
775 else
777 //---------------------
778 // Standardausrichtung:
779 //---------------------
780 if ( (nCol == 0) || (nRow == 0) )
782 // Text-Label links oder Summe linksbuendig
783 aPos.X() += FRAME_OFFSET;
785 else
787 // Zahlen/Datum rechtsbuendig
788 aPos.X() += nRightX;
792 //-------------------------------
793 aScriptedText.DrawText( aPos );
794 //-------------------------------
799 #undef FRAME_OFFSET
801 //------------------------------------------------------------------------
803 void ScAutoFmtPreview::DrawStrings()
805 for( size_t nRow = 0; nRow < 5; ++nRow )
806 for( size_t nCol = 0; nCol < 5; ++nCol )
807 DrawString( nCol, nRow );
810 //------------------------------------------------------------------------
812 void ScAutoFmtPreview::DrawBackground()
814 if( pCurData )
816 for( size_t nRow = 0; nRow < 5; ++nRow )
818 for( size_t nCol = 0; nCol < 5; ++nCol )
820 const SvxBrushItem* pItem = static_cast< const SvxBrushItem* >(
821 pCurData->GetItem( GetFormatIndex( nCol, nRow ), ATTR_BACKGROUND ) );
823 aVD.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
824 aVD.SetLineColor();
825 aVD.SetFillColor( pItem->GetColor() );
826 aVD.DrawRect( maArray.GetCellRect( nCol, nRow ) );
827 aVD.Pop();
833 //------------------------------------------------------------------------
835 void ScAutoFmtPreview::PaintCells()
837 if ( pCurData )
839 // 1) background
840 if ( pCurData->GetIncludeBackground() )
841 DrawBackground();
843 // 2) values
844 DrawStrings();
846 // 3) border
847 if ( pCurData->GetIncludeFrame() )
848 maArray.DrawArray( aVD );
852 //------------------------------------------------------------------------
854 void ScAutoFmtPreview::Init()
856 SetBorderStyle( WINDOW_BORDER_MONO );
857 maArray.Initialize( 5, 5 );
858 maArray.SetUseDiagDoubleClipping( false );
859 CalcCellArray( FALSE );
860 CalcLineMap();
862 TypeId aType(TYPE(ScDocShell));
863 ScDocShell* pDocShell = (ScDocShell*)SfxObjectShell::GetFirst(&aType);
864 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
865 SfxViewShell* p = pFrame->GetViewShell();
866 ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell* >( p );
867 ScViewData* pViewData = pViewSh->GetViewData();
868 SCTAB nCurrentTab = pViewData->GetTabNo();
869 ScDocument* pDoc = pViewData->GetDocument();
870 mbRTL = pDoc->IsLayoutRTL( nCurrentTab );
873 //------------------------------------------------------------------------
875 void ScAutoFmtPreview::CalcCellArray( BOOL bFitWidthP )
877 maArray.SetXOffset( 2 );
878 maArray.SetAllColWidths( bFitWidthP ? mnDataColWidth2 : mnDataColWidth1 );
879 maArray.SetColWidth( 0, mnLabelColWidth );
880 maArray.SetColWidth( 4, mnLabelColWidth );
882 maArray.SetYOffset( 2 );
883 maArray.SetAllRowHeights( mnRowHeight );
885 aPrvSize.Width() = maArray.GetWidth() + 4;
886 aPrvSize.Height() = maArray.GetHeight() + 4;
889 //------------------------------------------------------------------------
891 inline void lclSetStyleFromBorder( svx::frame::Style& rStyle, const SvxBorderLine* pBorder )
893 rStyle.Set( pBorder, 1.0 / TWIPS_PER_POINT, 5 );
896 void ScAutoFmtPreview::CalcLineMap()
898 if ( pCurData )
900 for( size_t nRow = 0; nRow < 5; ++nRow )
902 for( size_t nCol = 0; nCol < 5; ++nCol )
904 svx::frame::Style aStyle;
906 const SvxBoxItem& rItem = GetBoxItem( nCol, nRow );
907 lclSetStyleFromBorder( aStyle, rItem.GetLeft() );
908 maArray.SetCellStyleLeft( nCol, nRow, aStyle );
909 lclSetStyleFromBorder( aStyle, rItem.GetRight() );
910 maArray.SetCellStyleRight( nCol, nRow, aStyle );
911 lclSetStyleFromBorder( aStyle, rItem.GetTop() );
912 maArray.SetCellStyleTop( nCol, nRow, aStyle );
913 lclSetStyleFromBorder( aStyle, rItem.GetBottom() );
914 maArray.SetCellStyleBottom( nCol, nRow, aStyle );
916 lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, true ).GetLine() );
917 maArray.SetCellStyleTLBR( nCol, nRow, aStyle );
918 lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, false ).GetLine() );
919 maArray.SetCellStyleBLTR( nCol, nRow, aStyle );
925 //------------------------------------------------------------------------
927 void ScAutoFmtPreview::NotifyChange( ScAutoFormatData* pNewData )
929 if ( pNewData != pCurData )
931 pCurData = pNewData;
932 bFitWidth = pNewData->GetIncludeWidthHeight();
933 CalcCellArray( bFitWidth );
934 CalcLineMap();
936 else if ( bFitWidth != pNewData->GetIncludeWidthHeight() )
938 bFitWidth = !bFitWidth;
939 CalcCellArray( bFitWidth );
942 DoPaint( Rectangle( Point(0,0), GetSizePixel() ) );
945 //------------------------------------------------------------------------
947 void ScAutoFmtPreview::DoPaint( const Rectangle& /* rRect */ )
949 sal_uInt32 nOldDrawMode = aVD.GetDrawMode();
950 // #105733# SvtAccessibilityOptions::GetIsForBorders is no longer used (always assumed TRUE)
951 if( GetSettings().GetStyleSettings().GetHighContrastMode() )
952 aVD.SetDrawMode( DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
954 Size aWndSize( GetSizePixel() );
955 Font aFont( aVD.GetFont() );
956 Color aBackCol( GetSettings().GetStyleSettings().GetWindowColor() );
957 Point aTmpPoint;
958 Rectangle aRect( aTmpPoint, aWndSize );
960 aFont.SetTransparent( TRUE );
961 aVD.SetFont( aFont );
962 aVD.SetLineColor();
963 aVD.SetFillColor( aBackCol );
964 aVD.SetOutputSize( aWndSize );
965 aVD.DrawRect( aRect );
967 PaintCells();
968 SetLineColor();
969 SetFillColor( aBackCol );
970 DrawRect( aRect );
972 Point aPos( (aWndSize.Width() - aPrvSize.Width()) / 2, (aWndSize.Height() - aPrvSize.Height()) / 2 );
973 if (Application::GetSettings().GetLayoutRTL())
974 aPos.X() = -aPos.X();
975 DrawOutDev( aPos, aWndSize, Point(), aWndSize, aVD );
977 aVD.SetDrawMode( nOldDrawMode );
980 //------------------------------------------------------------------------
982 void ScAutoFmtPreview::Paint( const Rectangle& rRect )
984 DoPaint( rRect );