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 #undef SC_DLLIMPLEMENTATION
28
29
30
31 //------------------------------------------------------------------
32
33 #include "scitems.hxx"
34 #include <svx/algitem.hxx>
35 #include <editeng/boxitem.hxx>
36 #include <editeng/brshitem.hxx>
37 #include <editeng/cntritem.hxx>
38 #include <editeng/colritem.hxx>
39 #include <editeng/crsditem.hxx>
40 #include <editeng/fontitem.hxx>
41 #include <editeng/postitem.hxx>
42 #include <editeng/shdditem.hxx>
43 #include <editeng/udlnitem.hxx>
44 #include <editeng/wghtitem.hxx>
45 #include <svl/zforlist.hxx>
46 #include <vcl/msgbox.hxx>
47 #include <comphelper/processfactory.hxx>
48 #include <sfx2/sfxresid.hxx>
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 #include "strindlg.hxx"
58 #include "miscdlgs.hrc"
59 #include "scuiautofmt.hxx"
60 #include "scresid.hxx"
61 #include "document.hxx"
62
63 //========================================================================
64 // AutoFormat-Dialog:
65
ScAutoFormatDlg(Window * pParent,ScAutoFormat * pAutoFormat,const ScAutoFormatData * pSelFormatData,ScDocument * pDoc)66 ScAutoFormatDlg::ScAutoFormatDlg( Window* pParent,
67 ScAutoFormat* pAutoFormat,
68 const ScAutoFormatData* pSelFormatData,
69 ScDocument* pDoc ) :
70
71 ModalDialog ( pParent, ScResId( RID_SCDLG_AUTOFORMAT ) ),
72 //
73 aFlFormat ( this, ScResId( FL_FORMAT ) ),
74 aLbFormat ( this, ScResId( LB_FORMAT ) ),
75 pWndPreview ( new ScAutoFmtPreview( this, ScResId( WND_PREVIEW ), pDoc ) ),
76 aBtnOk ( this, ScResId( BTN_OK ) ),
77 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
78 aBtnHelp ( this, ScResId( BTN_HELP ) ),
79 aBtnAdd ( this, ScResId( BTN_ADD ) ),
80 aBtnRemove ( this, ScResId( BTN_REMOVE ) ),
81 aBtnMore ( this, ScResId( BTN_MORE ) ),
82 aFlFormatting ( this, ScResId( FL_FORMATTING ) ),
83 aBtnNumFormat ( this, ScResId( BTN_NUMFORMAT ) ),
84 aBtnBorder ( this, ScResId( BTN_BORDER ) ),
85 aBtnFont ( this, ScResId( BTN_FONT ) ),
86 aBtnPattern ( this, ScResId( BTN_PATTERN ) ),
87 aBtnAlignment ( this, ScResId( BTN_ALIGNMENT ) ),
88 aBtnAdjust ( this, ScResId( BTN_ADJUST ) ),
89 aBtnRename ( this, ScResId( BTN_RENAME ) ),
90 aStrTitle ( ScResId( STR_ADD_TITLE ) ),
91 aStrLabel ( ScResId( STR_ADD_LABEL ) ),
92 aStrClose ( ScResId( STR_BTN_CLOSE ) ),
93 aStrDelTitle ( ScResId( STR_DEL_TITLE ) ),
94 aStrDelMsg ( ScResId( STR_DEL_MSG ) ) ,
95 aStrRename ( ScResId( STR_RENAME_TITLE ) ),
96 //
97 pFormat ( pAutoFormat ),
98 pSelFmtData ( pSelFormatData ),
99 nIndex ( 0 ),
100 bCoreDataChanged( sal_False ),
101 bFmtInserted ( sal_False )
102 {
103 Init();
104 pWndPreview->NotifyChange( (*pFormat)[0] );
105 FreeResource();
106 }
107
108 //------------------------------------------------------------------------
109
~ScAutoFormatDlg()110 __EXPORT ScAutoFormatDlg::~ScAutoFormatDlg()
111 {
112 delete pWndPreview;
113 }
114
115 //------------------------------------------------------------------------
116
Init()117 void ScAutoFormatDlg::Init()
118 {
119 sal_uInt16 nCount;
120 String aEntry;
121
122 aLbFormat .SetSelectHdl( LINK( this, ScAutoFormatDlg, SelFmtHdl ) );
123 aBtnNumFormat.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
124 aBtnBorder .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
125 aBtnFont .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
126 aBtnPattern .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
127 aBtnAlignment.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
128 aBtnAdjust .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
129 aBtnAdd .SetClickHdl ( LINK( this, ScAutoFormatDlg, AddHdl ) );
130 aBtnRemove .SetClickHdl ( LINK( this, ScAutoFormatDlg, RemoveHdl ) );
131 aBtnOk .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
132 aBtnCancel .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
133 aBtnRename .SetClickHdl ( LINK( this, ScAutoFormatDlg, RenameHdl ) );
134 aLbFormat .SetDoubleClickHdl( LINK( this, ScAutoFormatDlg, DblClkHdl ) );
135
136 aBtnMore.AddWindow( &aBtnRename );
137 aBtnMore.AddWindow( &aBtnNumFormat );
138 aBtnMore.AddWindow( &aBtnBorder );
139 aBtnMore.AddWindow( &aBtnFont );
140 aBtnMore.AddWindow( &aBtnPattern );
141 aBtnMore.AddWindow( &aBtnAlignment );
142 aBtnMore.AddWindow( &aBtnAdjust );
143 aBtnMore.AddWindow( &aFlFormatting );
144
145 nCount = pFormat->GetCount();
146
147 for ( sal_uInt16 i = 0; i < nCount; i++ )
148 {
149 ((*pFormat)[i])->GetName( aEntry );
150 aLbFormat.InsertEntry( aEntry );
151 }
152
153 if ( nCount == 1 )
154 aBtnRemove.Disable();
155
156 aLbFormat.SelectEntryPos( 0 );
157 aBtnRename.Disable();
158 aBtnRemove.Disable();
159
160 nIndex = 0;
161 UpdateChecks();
162
163 if ( !pSelFmtData )
164 {
165 aBtnAdd.Disable();
166 aBtnRemove.Disable();
167 bFmtInserted = sal_True;
168 }
169 }
170
171 //------------------------------------------------------------------------
172
UpdateChecks()173 void ScAutoFormatDlg::UpdateChecks()
174 {
175 ScAutoFormatData* pData = (*pFormat)[nIndex];
176
177 aBtnNumFormat.Check( pData->GetIncludeValueFormat() );
178 aBtnBorder .Check( pData->GetIncludeFrame() );
179 aBtnFont .Check( pData->GetIncludeFont() );
180 aBtnPattern .Check( pData->GetIncludeBackground() );
181 aBtnAlignment.Check( pData->GetIncludeJustify() );
182 aBtnAdjust .Check( pData->GetIncludeWidthHeight() );
183 }
184
185 //------------------------------------------------------------------------
186 // Handler:
187 //---------
188
IMPL_LINK(ScAutoFormatDlg,CloseHdl,PushButton *,pBtn)189 IMPL_LINK( ScAutoFormatDlg, CloseHdl, PushButton *, pBtn )
190 {
191 if ( pBtn == &aBtnOk || pBtn == &aBtnCancel )
192 {
193 if ( bCoreDataChanged )
194 ScGlobal::GetAutoFormat()->Save();
195
196 EndDialog( (pBtn == &aBtnOk) ? RET_OK : RET_CANCEL );
197 }
198 return 0;
199 }
200
201 //------------------------------------------------------------------------
202
IMPL_LINK_INLINE_START(ScAutoFormatDlg,DblClkHdl,void *,EMPTYARG)203 IMPL_LINK_INLINE_START( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG )
204 {
205 if ( bCoreDataChanged )
206 ScGlobal::GetAutoFormat()->Save();
207
208 EndDialog( RET_OK );
209 return 0;
210 }
IMPL_LINK_INLINE_END(ScAutoFormatDlg,DblClkHdl,void *,EMPTYARG)211 IMPL_LINK_INLINE_END( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG )
212
213 //------------------------------------------------------------------------
214
215 IMPL_LINK( ScAutoFormatDlg, CheckHdl, Button *, pBtn )
216 {
217 ScAutoFormatData* pData = (*pFormat)[nIndex];
218 sal_Bool bCheck = ((CheckBox*)pBtn)->IsChecked();
219
220 if ( pBtn == &aBtnNumFormat )
221 pData->SetIncludeValueFormat( bCheck );
222 else if ( pBtn == &aBtnBorder )
223 pData->SetIncludeFrame( bCheck );
224 else if ( pBtn == &aBtnFont )
225 pData->SetIncludeFont( bCheck );
226 else if ( pBtn == &aBtnPattern )
227 pData->SetIncludeBackground( bCheck );
228 else if ( pBtn == &aBtnAlignment )
229 pData->SetIncludeJustify( bCheck );
230 else if ( pBtn == &aBtnAdjust )
231 pData->SetIncludeWidthHeight( bCheck );
232
233 if ( !bCoreDataChanged )
234 {
235 aBtnCancel.SetText( aStrClose );
236 bCoreDataChanged = sal_True;
237 }
238
239 pWndPreview->NotifyChange( pData );
240
241 return 0;
242 }
243
244 //------------------------------------------------------------------------
245
IMPL_LINK(ScAutoFormatDlg,AddHdl,void *,EMPTYARG)246 IMPL_LINK( ScAutoFormatDlg, AddHdl, void *, EMPTYARG )
247 {
248 if ( !bFmtInserted && pSelFmtData )
249 {
250 String aStrStandard( SfxResId(STR_STANDARD) );
251 String aFormatName;
252 ScStringInputDlg* pDlg;
253 sal_Bool bOk = sal_False;
254
255 while ( !bOk )
256 {
257 pDlg = new ScStringInputDlg( this,
258 aStrTitle,
259 aStrLabel,
260 aFormatName,
261 HID_SC_ADD_AUTOFMT, HID_SC_AUTOFMT_NAME );
262
263 if ( pDlg->Execute() == RET_OK )
264 {
265 pDlg->GetInputString( aFormatName );
266
267 if ( (aFormatName.Len() > 0) && (aFormatName != aStrStandard) )
268 {
269 ScAutoFormatData* pNewData
270 = new ScAutoFormatData( *pSelFmtData );
271
272 pNewData->SetName( aFormatName );
273 bFmtInserted = pFormat->Insert( pNewData );
274
275 if ( bFmtInserted )
276 {
277 sal_uInt16 nAt = pFormat->IndexOf( pNewData );
278
279 aLbFormat.InsertEntry( aFormatName, nAt );
280 aLbFormat.SelectEntry( aFormatName );
281 aBtnAdd.Disable();
282
283 if ( !bCoreDataChanged )
284 {
285 aBtnCancel.SetText( aStrClose );
286 bCoreDataChanged = sal_True;
287 }
288
289 SelFmtHdl( 0 );
290 bOk = sal_True;
291 }
292 else
293 delete pNewData;
294
295 }
296
297 if ( !bFmtInserted )
298 {
299 sal_uInt16 nRet = ErrorBox( this,
300 WinBits( WB_OK_CANCEL | WB_DEF_OK),
301 ScGlobal::GetRscString(STR_INVALID_AFNAME)
302 ).Execute();
303
304 bOk = ( nRet == RET_CANCEL );
305 }
306 }
307 else
308 bOk = sal_True;
309
310 delete pDlg;
311 }
312 }
313
314 return 0;
315 }
316
317 //------------------------------------------------------------------------
318
IMPL_LINK(ScAutoFormatDlg,RemoveHdl,void *,EMPTYARG)319 IMPL_LINK( ScAutoFormatDlg, RemoveHdl, void *, EMPTYARG )
320 {
321 if ( (nIndex > 0) && (aLbFormat.GetEntryCount() > 0) )
322 {
323 String aMsg( aStrDelMsg.GetToken( 0, '#' ) );
324
325 aMsg += aLbFormat.GetSelectEntry();
326 aMsg += aStrDelMsg.GetToken( 1, '#' );
327
328 if ( RET_YES ==
329 QueryBox( this, WinBits( WB_YES_NO | WB_DEF_YES ), aMsg ).Execute() )
330 {
331 aLbFormat.RemoveEntry( nIndex );
332 aLbFormat.SelectEntryPos( nIndex-1 );
333
334 if ( nIndex-1 == 0 )
335 aBtnRemove.Disable();
336
337 if ( !bCoreDataChanged )
338 {
339 aBtnCancel.SetText( aStrClose );
340 bCoreDataChanged = sal_True;
341 }
342
343 pFormat->AtFree( nIndex ); // in der Core loeschen
344 nIndex--;
345
346 SelFmtHdl( 0 );
347 }
348 }
349
350 SelFmtHdl( 0 );
351
352 return 0;
353 }
354
IMPL_LINK(ScAutoFormatDlg,RenameHdl,void *,EMPTYARG)355 IMPL_LINK( ScAutoFormatDlg, RenameHdl, void *, EMPTYARG )
356 {
357 sal_Bool bOk = sal_False;
358 while( !bOk )
359 {
360
361 String aFormatName=aLbFormat.GetSelectEntry();
362 String aEntry;
363
364 ScStringInputDlg* pDlg = new ScStringInputDlg( this,
365 aStrRename,
366 aStrLabel,
367 aFormatName,
368 HID_SC_REN_AFMT_DLG, HID_SC_REN_AFMT_NAME );
369 if( pDlg->Execute() == RET_OK )
370 {
371 sal_Bool bFmtRenamed = sal_False;
372 pDlg->GetInputString( aFormatName );
373 sal_uInt16 n;
374
375 if ( aFormatName.Len() > 0 )
376 {
377 for( n = 0; n < pFormat->GetCount(); ++n )
378 {
379 (*pFormat)[n]->GetName(aEntry);
380 if ( aEntry== aFormatName)
381 break;
382 }
383 if( n >= pFormat->GetCount() )
384 {
385 // Format mit dem Namen noch nicht vorhanden, also
386 // umbenennen
387
388 aLbFormat.RemoveEntry(nIndex );
389 ScAutoFormatData* p=(*pFormat)[ nIndex ];
390 ScAutoFormatData* pNewData
391 = new ScAutoFormatData(*p);
392
393 pFormat->AtFree( nIndex );
394
395 pNewData->SetName( aFormatName );
396
397 pFormat->Insert( pNewData);
398
399 sal_uInt16 nCount = pFormat->GetCount();
400
401 aLbFormat.SetUpdateMode(sal_False);
402 aLbFormat.Clear();
403 for ( sal_uInt16 i = 0; i < nCount; i++ )
404 {
405 ((*pFormat)[i])->GetName( aEntry );
406 aLbFormat.InsertEntry( aEntry );
407 }
408
409 aLbFormat.SetUpdateMode( sal_True);
410 aLbFormat.SelectEntry( aFormatName);
411
412 if ( !bCoreDataChanged )
413 {
414 aBtnCancel.SetText( aStrClose );
415 bCoreDataChanged = sal_True;
416 }
417
418
419 SelFmtHdl( 0 );
420 bOk = sal_True;
421 bFmtRenamed = sal_True;
422 }
423 }
424 if( !bFmtRenamed )
425 {
426 bOk = RET_CANCEL == ErrorBox( this,
427 WinBits( WB_OK_CANCEL | WB_DEF_OK),
428 ScGlobal::GetRscString(STR_INVALID_AFNAME)
429 ).Execute();
430 }
431 }
432 else
433 bOk = sal_True;
434 delete pDlg;
435 }
436
437 return 0;
438 }
439
440 //------------------------------------------------------------------------
441
IMPL_LINK(ScAutoFormatDlg,SelFmtHdl,void *,EMPTYARG)442 IMPL_LINK( ScAutoFormatDlg, SelFmtHdl, void *, EMPTYARG )
443 {
444 nIndex = aLbFormat.GetSelectEntryPos();
445 UpdateChecks();
446
447 if ( nIndex == 0 )
448 {
449 aBtnRename.Disable();
450 aBtnRemove.Disable();
451 }
452 else
453 {
454 aBtnRename.Enable();
455 aBtnRemove.Enable();
456 }
457
458 pWndPreview->NotifyChange( (*pFormat)[nIndex] );
459
460 return 0;
461 }
462
463 //------------------------------------------------------------------------
464
GetCurrFormatName()465 String __EXPORT ScAutoFormatDlg::GetCurrFormatName()
466 {
467 String aResult;
468
469 ((*pFormat)[nIndex])->GetName( aResult );
470
471 return aResult;
472 }
473