Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #undef SC_DLLIMPLEMENTATION
31 : :
32 : :
33 : :
34 : : //------------------------------------------------------------------
35 : :
36 : : #include "scitems.hxx"
37 : : #include <svx/algitem.hxx>
38 : : #include <editeng/boxitem.hxx>
39 : : #include <editeng/brshitem.hxx>
40 : : #include <editeng/cntritem.hxx>
41 : : #include <editeng/colritem.hxx>
42 : : #include <editeng/crsditem.hxx>
43 : : #include <editeng/fontitem.hxx>
44 : : #include <editeng/postitem.hxx>
45 : : #include <editeng/shdditem.hxx>
46 : : #include <editeng/udlnitem.hxx>
47 : : #include <editeng/wghtitem.hxx>
48 : : #include <svl/zforlist.hxx>
49 : : #include <vcl/msgbox.hxx>
50 : : #include <comphelper/processfactory.hxx>
51 : : #include <sfx2/sfxresid.hxx>
52 : : #include "sc.hrc"
53 : : #include "scmod.hxx"
54 : : #include "attrib.hxx"
55 : : #include "zforauto.hxx"
56 : : #include "global.hxx"
57 : : #include "globstr.hrc"
58 : : #include "autoform.hxx"
59 : : #include "strindlg.hxx"
60 : : #include "miscdlgs.hrc"
61 : : #include "scuiautofmt.hxx"
62 : : #include "scresid.hxx"
63 : : #include "document.hxx"
64 : :
65 : : //========================================================================
66 : : // AutoFormat-Dialog:
67 : :
68 : 0 : ScAutoFormatDlg::ScAutoFormatDlg( Window* pParent,
69 : : ScAutoFormat* pAutoFormat,
70 : : const ScAutoFormatData* pSelFormatData,
71 : : ScDocument* pDoc ) :
72 : :
73 : : ModalDialog ( pParent, ScResId( RID_SCDLG_AUTOFORMAT ) ),
74 : : //
75 : : aFlFormat ( this, ScResId( FL_FORMAT ) ),
76 : : aLbFormat ( this, ScResId( LB_FORMAT ) ),
77 : 0 : pWndPreview ( new ScAutoFmtPreview( this, ScResId( WND_PREVIEW ), pDoc ) ),
78 : : aBtnOk ( this, ScResId( BTN_OK ) ),
79 : : aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
80 : : aBtnHelp ( this, ScResId( BTN_HELP ) ),
81 : : aBtnAdd ( this, ScResId( BTN_ADD ) ),
82 : : aBtnRemove ( this, ScResId( BTN_REMOVE ) ),
83 : : aBtnMore ( this, ScResId( BTN_MORE ) ),
84 : : aFlFormatting ( this, ScResId( FL_FORMATTING ) ),
85 : : aBtnNumFormat ( this, ScResId( BTN_NUMFORMAT ) ),
86 : : aBtnBorder ( this, ScResId( BTN_BORDER ) ),
87 : : aBtnFont ( this, ScResId( BTN_FONT ) ),
88 : : aBtnPattern ( this, ScResId( BTN_PATTERN ) ),
89 : : aBtnAlignment ( this, ScResId( BTN_ALIGNMENT ) ),
90 : : aBtnAdjust ( this, ScResId( BTN_ADJUST ) ),
91 : : aBtnRename ( this, ScResId( BTN_RENAME ) ),
92 : : aStrTitle ( ScResId( STR_ADD_TITLE ) ),
93 : : aStrLabel ( ScResId( STR_ADD_LABEL ) ),
94 : : aStrClose ( ScResId( STR_BTN_CLOSE ) ),
95 : : aStrDelTitle ( ScResId( STR_DEL_TITLE ) ),
96 : : aStrDelMsg ( ScResId( STR_DEL_MSG ) ) ,
97 : : aStrRename ( ScResId( STR_RENAME_TITLE ) ),
98 : : //
99 : : pFormat ( pAutoFormat ),
100 : : pSelFmtData ( pSelFormatData ),
101 : : nIndex ( 0 ),
102 : : bCoreDataChanged( false ),
103 : 0 : bFmtInserted ( false )
104 : : {
105 : 0 : Init();
106 : 0 : ScAutoFormat::iterator it = pFormat->begin();
107 : 0 : pWndPreview->NotifyChange(it->second);
108 : 0 : FreeResource();
109 : 0 : }
110 : :
111 : : //------------------------------------------------------------------------
112 : :
113 : 0 : ScAutoFormatDlg::~ScAutoFormatDlg()
114 : : {
115 : 0 : delete pWndPreview;
116 : 0 : }
117 : :
118 : : //------------------------------------------------------------------------
119 : :
120 : 0 : void ScAutoFormatDlg::Init()
121 : : {
122 : 0 : aLbFormat .SetSelectHdl( LINK( this, ScAutoFormatDlg, SelFmtHdl ) );
123 : 0 : aBtnNumFormat.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
124 : 0 : aBtnBorder .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
125 : 0 : aBtnFont .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
126 : 0 : aBtnPattern .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
127 : 0 : aBtnAlignment.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
128 : 0 : aBtnAdjust .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
129 : 0 : aBtnAdd .SetClickHdl ( LINK( this, ScAutoFormatDlg, AddHdl ) );
130 : 0 : aBtnRemove .SetClickHdl ( LINK( this, ScAutoFormatDlg, RemoveHdl ) );
131 : 0 : aBtnOk .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
132 : 0 : aBtnCancel .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
133 : 0 : aBtnRename .SetClickHdl ( LINK( this, ScAutoFormatDlg, RenameHdl ) );
134 : 0 : aLbFormat .SetDoubleClickHdl( LINK( this, ScAutoFormatDlg, DblClkHdl ) );
135 : :
136 : 0 : aBtnMore.AddWindow( &aBtnRename );
137 : 0 : aBtnMore.AddWindow( &aBtnNumFormat );
138 : 0 : aBtnMore.AddWindow( &aBtnBorder );
139 : 0 : aBtnMore.AddWindow( &aBtnFont );
140 : 0 : aBtnMore.AddWindow( &aBtnPattern );
141 : 0 : aBtnMore.AddWindow( &aBtnAlignment );
142 : 0 : aBtnMore.AddWindow( &aBtnAdjust );
143 : 0 : aBtnMore.AddWindow( &aFlFormatting );
144 : :
145 : 0 : ScAutoFormat::const_iterator it = pFormat->begin(), itEnd = pFormat->end();
146 : 0 : for (; it != itEnd; ++it)
147 : 0 : aLbFormat.InsertEntry(it->second->GetName());
148 : :
149 : 0 : if (pFormat->size() == 1)
150 : 0 : aBtnRemove.Disable();
151 : :
152 : 0 : aLbFormat.SelectEntryPos( 0 );
153 : 0 : aBtnRename.Disable();
154 : 0 : aBtnRemove.Disable();
155 : :
156 : 0 : nIndex = 0;
157 : 0 : UpdateChecks();
158 : :
159 : 0 : if ( !pSelFmtData )
160 : : {
161 : 0 : aBtnAdd.Disable();
162 : 0 : aBtnRemove.Disable();
163 : 0 : bFmtInserted = true;
164 : : }
165 : 0 : }
166 : :
167 : : //------------------------------------------------------------------------
168 : :
169 : 0 : void ScAutoFormatDlg::UpdateChecks()
170 : : {
171 : 0 : const ScAutoFormatData* pData = pFormat->findByIndex(nIndex);
172 : :
173 : 0 : aBtnNumFormat.Check( pData->GetIncludeValueFormat() );
174 : 0 : aBtnBorder .Check( pData->GetIncludeFrame() );
175 : 0 : aBtnFont .Check( pData->GetIncludeFont() );
176 : 0 : aBtnPattern .Check( pData->GetIncludeBackground() );
177 : 0 : aBtnAlignment.Check( pData->GetIncludeJustify() );
178 : 0 : aBtnAdjust .Check( pData->GetIncludeWidthHeight() );
179 : 0 : }
180 : :
181 : : //------------------------------------------------------------------------
182 : : // Handler:
183 : : //---------
184 : :
185 : 0 : IMPL_LINK( ScAutoFormatDlg, CloseHdl, PushButton *, pBtn )
186 : : {
187 : 0 : if ( pBtn == &aBtnOk || pBtn == &aBtnCancel )
188 : : {
189 : 0 : if ( bCoreDataChanged )
190 : 0 : ScGlobal::GetOrCreateAutoFormat()->Save();
191 : :
192 : 0 : EndDialog( (pBtn == &aBtnOk) ? RET_OK : RET_CANCEL );
193 : : }
194 : 0 : return 0;
195 : : }
196 : :
197 : : //------------------------------------------------------------------------
198 : :
199 : 0 : IMPL_LINK_NOARG_INLINE_START(ScAutoFormatDlg, DblClkHdl)
200 : : {
201 : 0 : if ( bCoreDataChanged )
202 : 0 : ScGlobal::GetOrCreateAutoFormat()->Save();
203 : :
204 : 0 : EndDialog( RET_OK );
205 : 0 : return 0;
206 : : }
207 : 0 : IMPL_LINK_NOARG_INLINE_END(ScAutoFormatDlg, DblClkHdl)
208 : :
209 : : //------------------------------------------------------------------------
210 : :
211 : 0 : IMPL_LINK( ScAutoFormatDlg, CheckHdl, Button *, pBtn )
212 : : {
213 : 0 : ScAutoFormatData* pData = pFormat->findByIndex(nIndex);
214 : 0 : bool bCheck = ((CheckBox*)pBtn)->IsChecked();
215 : :
216 : 0 : if ( pBtn == &aBtnNumFormat )
217 : 0 : pData->SetIncludeValueFormat( bCheck );
218 : 0 : else if ( pBtn == &aBtnBorder )
219 : 0 : pData->SetIncludeFrame( bCheck );
220 : 0 : else if ( pBtn == &aBtnFont )
221 : 0 : pData->SetIncludeFont( bCheck );
222 : 0 : else if ( pBtn == &aBtnPattern )
223 : 0 : pData->SetIncludeBackground( bCheck );
224 : 0 : else if ( pBtn == &aBtnAlignment )
225 : 0 : pData->SetIncludeJustify( bCheck );
226 : 0 : else if ( pBtn == &aBtnAdjust )
227 : 0 : pData->SetIncludeWidthHeight( bCheck );
228 : :
229 : 0 : if ( !bCoreDataChanged )
230 : : {
231 : 0 : aBtnCancel.SetText( aStrClose );
232 : 0 : bCoreDataChanged = true;
233 : : }
234 : :
235 : 0 : pWndPreview->NotifyChange( pData );
236 : :
237 : 0 : return 0;
238 : : }
239 : :
240 : : //------------------------------------------------------------------------
241 : :
242 : 0 : IMPL_LINK_NOARG(ScAutoFormatDlg, AddHdl)
243 : : {
244 : 0 : if ( !bFmtInserted && pSelFmtData )
245 : : {
246 : 0 : String aStrStandard( SfxResId(STR_STANDARD) );
247 : 0 : rtl::OUString aFormatName;
248 : : ScStringInputDlg* pDlg;
249 : 0 : bool bOk = false;
250 : :
251 : 0 : while ( !bOk )
252 : : {
253 : : pDlg = new ScStringInputDlg( this,
254 : : aStrTitle,
255 : : aStrLabel,
256 : : aFormatName,
257 : 0 : HID_SC_ADD_AUTOFMT, HID_SC_AUTOFMT_NAME );
258 : :
259 : 0 : if ( pDlg->Execute() == RET_OK )
260 : : {
261 : 0 : pDlg->GetInputString( aFormatName );
262 : :
263 : 0 : if ( !aFormatName.isEmpty() && !aFormatName.equals(aStrStandard) )
264 : : {
265 : : ScAutoFormatData* pNewData
266 : 0 : = new ScAutoFormatData( *pSelFmtData );
267 : :
268 : 0 : pNewData->SetName( aFormatName );
269 : 0 : bFmtInserted = pFormat->insert(pNewData);
270 : :
271 : 0 : if ( bFmtInserted )
272 : : {
273 : 0 : ScAutoFormat::const_iterator it = pFormat->find(pNewData);
274 : 0 : ScAutoFormat::const_iterator itBeg = pFormat->begin();
275 : 0 : size_t nPos = std::distance(itBeg, it);
276 : 0 : aLbFormat.InsertEntry(aFormatName, nPos);
277 : 0 : aLbFormat.SelectEntry( aFormatName );
278 : 0 : aBtnAdd.Disable();
279 : :
280 : 0 : if ( !bCoreDataChanged )
281 : : {
282 : 0 : aBtnCancel.SetText( aStrClose );
283 : 0 : bCoreDataChanged = true;
284 : : }
285 : :
286 : 0 : SelFmtHdl( 0 );
287 : 0 : bOk = sal_True;
288 : : }
289 : : else
290 : 0 : delete pNewData;
291 : :
292 : : }
293 : :
294 : 0 : if ( !bFmtInserted )
295 : : {
296 : : sal_uInt16 nRet = ErrorBox( this,
297 : : WinBits( WB_OK_CANCEL | WB_DEF_OK),
298 : 0 : ScGlobal::GetRscString(STR_INVALID_AFNAME)
299 : 0 : ).Execute();
300 : :
301 : 0 : bOk = ( nRet == RET_CANCEL );
302 : : }
303 : : }
304 : : else
305 : 0 : bOk = sal_True;
306 : :
307 : 0 : delete pDlg;
308 : 0 : }
309 : : }
310 : :
311 : 0 : return 0;
312 : : }
313 : :
314 : : //------------------------------------------------------------------------
315 : :
316 : 0 : IMPL_LINK_NOARG(ScAutoFormatDlg, RemoveHdl)
317 : : {
318 : 0 : if ( (nIndex > 0) && (aLbFormat.GetEntryCount() > 0) )
319 : : {
320 : 0 : String aMsg( aStrDelMsg.GetToken( 0, '#' ) );
321 : :
322 : 0 : aMsg += aLbFormat.GetSelectEntry();
323 : 0 : aMsg += aStrDelMsg.GetToken( 1, '#' );
324 : :
325 : 0 : if ( RET_YES ==
326 : 0 : QueryBox( this, WinBits( WB_YES_NO | WB_DEF_YES ), aMsg ).Execute() )
327 : : {
328 : 0 : aLbFormat.RemoveEntry( nIndex );
329 : 0 : aLbFormat.SelectEntryPos( nIndex-1 );
330 : :
331 : 0 : if ( nIndex-1 == 0 )
332 : 0 : aBtnRemove.Disable();
333 : :
334 : 0 : if ( !bCoreDataChanged )
335 : : {
336 : 0 : aBtnCancel.SetText( aStrClose );
337 : 0 : bCoreDataChanged = true;
338 : : }
339 : :
340 : 0 : ScAutoFormat::iterator it = pFormat->begin();
341 : 0 : std::advance(it, nIndex);
342 : 0 : pFormat->erase(it);
343 : 0 : nIndex--;
344 : :
345 : 0 : SelFmtHdl( 0 );
346 : 0 : }
347 : : }
348 : :
349 : 0 : SelFmtHdl( 0 );
350 : :
351 : 0 : return 0;
352 : : }
353 : :
354 : 0 : IMPL_LINK_NOARG(ScAutoFormatDlg, RenameHdl)
355 : : {
356 : 0 : sal_Bool bOk = false;
357 : 0 : while( !bOk )
358 : : {
359 : :
360 : 0 : rtl::OUString aFormatName = aLbFormat.GetSelectEntry();
361 : 0 : String aEntry;
362 : :
363 : : ScStringInputDlg* pDlg = new ScStringInputDlg( this,
364 : : aStrRename,
365 : : aStrLabel,
366 : : aFormatName,
367 : 0 : HID_SC_REN_AFMT_DLG, HID_SC_REN_AFMT_NAME );
368 : 0 : if( pDlg->Execute() == RET_OK )
369 : : {
370 : 0 : bool bFmtRenamed = false;
371 : 0 : pDlg->GetInputString( aFormatName );
372 : :
373 : 0 : if (!aFormatName.isEmpty())
374 : : {
375 : 0 : ScAutoFormat::iterator it = pFormat->begin(), itEnd = pFormat->end();
376 : 0 : for (; it != itEnd; ++it)
377 : : {
378 : 0 : aEntry = it->second->GetName();
379 : 0 : if (aFormatName.equals(aEntry))
380 : 0 : break;
381 : : }
382 : 0 : if (it == itEnd)
383 : : {
384 : : // Format mit dem Namen noch nicht vorhanden, also
385 : : // umbenennen
386 : :
387 : 0 : aLbFormat.RemoveEntry(nIndex );
388 : 0 : const ScAutoFormatData* p = pFormat->findByIndex(nIndex);
389 : : ScAutoFormatData* pNewData
390 : 0 : = new ScAutoFormatData(*p);
391 : :
392 : 0 : it = pFormat->begin();
393 : 0 : std::advance(it, nIndex);
394 : 0 : pFormat->erase(it);
395 : :
396 : 0 : pNewData->SetName( aFormatName );
397 : :
398 : 0 : pFormat->insert(pNewData);
399 : :
400 : 0 : aLbFormat.SetUpdateMode(false);
401 : 0 : aLbFormat.Clear();
402 : 0 : for (it = pFormat->begin(); it != itEnd; ++it)
403 : : {
404 : 0 : aEntry = it->second->GetName();
405 : 0 : aLbFormat.InsertEntry( aEntry );
406 : : }
407 : :
408 : 0 : aLbFormat.SetUpdateMode(true);
409 : 0 : aLbFormat.SelectEntry( aFormatName);
410 : :
411 : 0 : if ( !bCoreDataChanged )
412 : : {
413 : 0 : aBtnCancel.SetText( aStrClose );
414 : 0 : bCoreDataChanged = true;
415 : : }
416 : :
417 : :
418 : 0 : SelFmtHdl( 0 );
419 : 0 : bOk = true;
420 : 0 : bFmtRenamed = true;
421 : : }
422 : : }
423 : 0 : if( !bFmtRenamed )
424 : : {
425 : : bOk = RET_CANCEL == ErrorBox( this,
426 : : WinBits( WB_OK_CANCEL | WB_DEF_OK),
427 : 0 : ScGlobal::GetRscString(STR_INVALID_AFNAME)
428 : 0 : ).Execute();
429 : : }
430 : : }
431 : : else
432 : 0 : bOk = true;
433 : 0 : delete pDlg;
434 : 0 : }
435 : :
436 : 0 : return 0;
437 : : }
438 : :
439 : : //------------------------------------------------------------------------
440 : :
441 : 0 : IMPL_LINK_NOARG(ScAutoFormatDlg, SelFmtHdl)
442 : : {
443 : 0 : nIndex = aLbFormat.GetSelectEntryPos();
444 : 0 : UpdateChecks();
445 : :
446 : 0 : if ( nIndex == 0 )
447 : : {
448 : 0 : aBtnRename.Disable();
449 : 0 : aBtnRemove.Disable();
450 : : }
451 : : else
452 : : {
453 : 0 : aBtnRename.Enable();
454 : 0 : aBtnRemove.Enable();
455 : : }
456 : :
457 : 0 : ScAutoFormatData* p = pFormat->findByIndex(nIndex);
458 : 0 : pWndPreview->NotifyChange(p);
459 : :
460 : 0 : return 0;
461 : : }
462 : :
463 : : //------------------------------------------------------------------------
464 : :
465 : 0 : rtl::OUString ScAutoFormatDlg::GetCurrFormatName()
466 : : {
467 : 0 : const ScAutoFormatData* p = pFormat->findByIndex(nIndex);
468 : 0 : return p ? p->GetName() : rtl::OUString();
469 : : }
470 : :
471 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|