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