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