1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: validate.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #ifdef SC_DLLIMPLEMENTATION
35 #undef SC_DLLIMPLEMENTATION
38 #include <vcl/svapp.hxx>
39 #include <svtools/aeitem.hxx>
40 #include <svtools/stritem.hxx>
41 #include <svtools/eitem.hxx>
42 #include <svtools/intitem.hxx>
43 #include <basic/sbmeth.hxx>
44 #include <basic/sbstar.hxx>
45 #include <basic/sbmod.hxx>
46 #include <sfx2/app.hxx>
48 #include "scresid.hxx"
49 #include "sc.hrc" // -> Slot IDs
51 #include "validat.hxx"
52 #include "validate.hrc"
53 #include "validate.hxx"
54 #include "compiler.hxx"
55 #include "formula/opcode.hxx" //CHINA001
57 // ============================================================================
59 static USHORT pValueRanges
[] =
61 FID_VALID_MODE
, FID_VALID_ERRTEXT
,
62 FID_VALID_LISTTYPE
, FID_VALID_LISTTYPE
,
67 // ============================================================================
69 ScValidationDlg::ScValidationDlg( Window
* pParent
, const SfxItemSet
* pArgSet
) :
70 SfxTabDialog( pParent
, ScResId( TAB_DLG_VALIDATION
), pArgSet
)
72 AddTabPage( TP_VALIDATION_VALUES
, ScTPValidationValue::Create
, 0 );
73 AddTabPage( TP_VALIDATION_INPUTHELP
, ScTPValidationHelp::Create
, 0 );
74 AddTabPage( TP_VALIDATION_ERROR
, ScTPValidationError::Create
, 0 );
78 ScValidationDlg::~ScValidationDlg()
83 // ============================================================================
87 /** Converts the passed ScValidationMode to the position in the list box. */
88 USHORT
lclGetPosFromValMode( ScValidationMode eValMode
)
90 USHORT nLbPos
= SC_VALIDDLG_ALLOW_ANY
;
93 case SC_VALID_ANY
: nLbPos
= SC_VALIDDLG_ALLOW_ANY
; break;
94 case SC_VALID_WHOLE
: nLbPos
= SC_VALIDDLG_ALLOW_WHOLE
; break;
95 case SC_VALID_DECIMAL
: nLbPos
= SC_VALIDDLG_ALLOW_DECIMAL
; break;
96 case SC_VALID_DATE
: nLbPos
= SC_VALIDDLG_ALLOW_DATE
; break;
97 case SC_VALID_TIME
: nLbPos
= SC_VALIDDLG_ALLOW_TIME
; break;
98 case SC_VALID_TEXTLEN
: nLbPos
= SC_VALIDDLG_ALLOW_TEXTLEN
; break;
99 case SC_VALID_LIST
: nLbPos
= SC_VALIDDLG_ALLOW_RANGE
; break;
100 case SC_VALID_CUSTOM
: nLbPos
= SC_VALIDDLG_ALLOW_ANY
; break; // not supported
101 default: DBG_ERRORFILE( "lclGetPosFromValMode - unknown validity mode" );
106 /** Converts the passed list box position to an ScValidationMode. */
107 ScValidationMode
lclGetValModeFromPos( USHORT nLbPos
)
109 ScValidationMode eValMode
= SC_VALID_ANY
;
112 case SC_VALIDDLG_ALLOW_ANY
: eValMode
= SC_VALID_ANY
; break;
113 case SC_VALIDDLG_ALLOW_WHOLE
: eValMode
= SC_VALID_WHOLE
; break;
114 case SC_VALIDDLG_ALLOW_DECIMAL
: eValMode
= SC_VALID_DECIMAL
; break;
115 case SC_VALIDDLG_ALLOW_DATE
: eValMode
= SC_VALID_DATE
; break;
116 case SC_VALIDDLG_ALLOW_TIME
: eValMode
= SC_VALID_TIME
; break;
117 case SC_VALIDDLG_ALLOW_RANGE
: eValMode
= SC_VALID_LIST
; break;
118 case SC_VALIDDLG_ALLOW_LIST
: eValMode
= SC_VALID_LIST
; break;
119 case SC_VALIDDLG_ALLOW_TEXTLEN
: eValMode
= SC_VALID_TEXTLEN
; break;
120 default: DBG_ERRORFILE( "lclGetValModeFromPos - invalid list box position" );
125 /** Converts the passed ScConditionMode to the position in the list box. */
126 USHORT
lclGetPosFromCondMode( ScConditionMode eCondMode
)
128 USHORT nLbPos
= SC_VALIDDLG_DATA_EQUAL
;
131 case SC_COND_NONE
: // #111771# may occur in old XML files after Excel import
132 case SC_COND_EQUAL
: nLbPos
= SC_VALIDDLG_DATA_EQUAL
; break;
133 case SC_COND_LESS
: nLbPos
= SC_VALIDDLG_DATA_LESS
; break;
134 case SC_COND_GREATER
: nLbPos
= SC_VALIDDLG_DATA_GREATER
; break;
135 case SC_COND_EQLESS
: nLbPos
= SC_VALIDDLG_DATA_EQLESS
; break;
136 case SC_COND_EQGREATER
: nLbPos
= SC_VALIDDLG_DATA_EQGREATER
; break;
137 case SC_COND_NOTEQUAL
: nLbPos
= SC_VALIDDLG_DATA_NOTEQUAL
; break;
138 case SC_COND_BETWEEN
: nLbPos
= SC_VALIDDLG_DATA_BETWEEN
; break;
139 case SC_COND_NOTBETWEEN
: nLbPos
= SC_VALIDDLG_DATA_NOTBETWEEN
; break;
140 default: DBG_ERRORFILE( "lclGetPosFromCondMode - unknown condition mode" );
145 /** Converts the passed list box position to an ScConditionMode. */
146 ScConditionMode
lclGetCondModeFromPos( USHORT nLbPos
)
148 ScConditionMode eCondMode
= SC_COND_EQUAL
;
151 case SC_VALIDDLG_DATA_EQUAL
: eCondMode
= SC_COND_EQUAL
; break;
152 case SC_VALIDDLG_DATA_LESS
: eCondMode
= SC_COND_LESS
; break;
153 case SC_VALIDDLG_DATA_GREATER
: eCondMode
= SC_COND_GREATER
; break;
154 case SC_VALIDDLG_DATA_EQLESS
: eCondMode
= SC_COND_EQLESS
; break;
155 case SC_VALIDDLG_DATA_EQGREATER
: eCondMode
= SC_COND_EQGREATER
; break;
156 case SC_VALIDDLG_DATA_NOTEQUAL
: eCondMode
= SC_COND_NOTEQUAL
; break;
157 case SC_VALIDDLG_DATA_BETWEEN
: eCondMode
= SC_COND_BETWEEN
; break;
158 case SC_VALIDDLG_DATA_NOTBETWEEN
: eCondMode
= SC_COND_NOTBETWEEN
; break;
159 default: DBG_ERRORFILE( "lclGetCondModeFromPos - invalid list box position" );
164 /** Converts line feed separated string to a formula with strings separated by semicolons.
165 @descr Keeps all empty strings.
166 Example: abc\ndef\n\nghi -> "abc";"def";"";"ghi".
167 @param rFmlaStr (out-param) The converted formula string. */
168 void lclGetFormulaFromStringList( String
& rFmlaStr
, const String
& rStringList
, sal_Unicode cFmlaSep
)
171 xub_StrLen nTokenCnt
= rStringList
.GetTokenCount( '\n' );
172 for( xub_StrLen nToken
= 0, nStringIx
= 0; nToken
< nTokenCnt
; ++nToken
)
174 String
aToken( rStringList
.GetToken( 0, '\n', nStringIx
) );
175 ScGlobal::AddQuotes( aToken
, '"' );
176 ScGlobal::AddToken( rFmlaStr
, aToken
, cFmlaSep
);
178 if( !rFmlaStr
.Len() )
179 rFmlaStr
.AssignAscii( "\"\"" );
183 /** Converts formula with strings separated by semicolons to line feed separated string.
184 @descr Keeps all empty strings. Ignores all empty tokens (multiple semicolons).
185 Example: "abc";;;"def";"";"ghi" -> abc\ndef\n\nghi.
186 @param rStringList (out-param) The converted line feed separated string list.
187 @return true = Conversion successful. */
188 bool lclGetStringListFromFormula( String
& rStringList
, const String
& rFmlaStr
, sal_Unicode cFmlaSep
)
190 String
aQuotes( RTL_CONSTASCII_USTRINGPARAM( "\"\"" ) );
191 xub_StrLen nTokenCnt
= rFmlaStr
.GetQuotedTokenCount( aQuotes
, cFmlaSep
);
194 bool bIsStringList
= (nTokenCnt
> 0);
195 bool bTokenAdded
= false;
197 for( xub_StrLen nToken
= 0, nStringIx
= 0; bIsStringList
&& (nToken
< nTokenCnt
); ++nToken
)
199 String
aToken( rFmlaStr
.GetQuotedToken( 0, aQuotes
, cFmlaSep
, nStringIx
) );
200 aToken
.EraseLeadingAndTrailingChars();
201 if( aToken
.Len() ) // ignore empty tokens, i.e. "a";;"b"
203 bIsStringList
= ScGlobal::IsQuoted( aToken
, '"' );
206 ScGlobal::EraseQuotes( aToken
, '"' );
207 ScGlobal::AddToken( rStringList
, aToken
, '\n', 1, bTokenAdded
);
213 return bIsStringList
;
218 // ----------------------------------------------------------------------------
220 ScTPValidationValue::ScTPValidationValue( Window
* pParent
, const SfxItemSet
& rArgSet
) :
221 SfxTabPage( pParent
, ScResId( TP_VALIDATION_VALUES
), rArgSet
),
222 maFtAllow ( this, ScResId( FT_ALLOW
) ),
223 maLbAllow ( this, ScResId( LB_ALLOW
) ),
224 maCbAllow ( this, ScResId( TSB_ALLOW_BLANKS
) ),
225 maCbShow ( this, ScResId( CB_SHOWLIST
) ),
226 maCbSort ( this, ScResId( CB_SORTLIST
) ),
227 maFtValue ( this, ScResId( FT_VALUE
) ),
228 maLbValue ( this, ScResId( LB_VALUE
) ),
229 maFtMin ( this, ScResId( FT_MIN
) ),
230 maEdMin ( this, ScResId( EDT_MIN
) ),
231 maEdList ( this, ScResId( EDT_LIST
) ),
232 maFtMax ( this, ScResId( FT_MAX
) ),
233 maEdMax ( this, ScResId( EDT_MAX
) ),
234 maFtHint ( this, ScResId( FT_SOURCEHINT
) ),
235 maStrMin ( ScResId( SCSTR_VALID_MINIMUM
) ),
236 maStrMax ( ScResId( SCSTR_VALID_MAXIMUM
) ),
237 maStrValue( ScResId( SCSTR_VALID_VALUE
) ),
238 maStrRange( ScResId( SCSTR_VALID_RANGE
) ),
239 maStrList ( ScResId( SCSTR_VALID_LIST
) )
244 // list separator in formulas
245 //CHINA001 const String& rListSep = ScCompiler::pSymbolTableNative[ ocSep ];
246 String aListSep
= ::GetScCompilerNativeSymbol( ocSep
); //CHINA001
247 DBG_ASSERT( aListSep
.Len() == 1, "ScTPValidationValue::ScTPValidationValue - list separator error" );
248 mcFmlaSep
= aListSep
.Len() ? aListSep
.GetChar( 0 ) : ';';
251 ScTPValidationValue::~ScTPValidationValue()
255 void ScTPValidationValue::Init()
257 maLbAllow
.SetSelectHdl( LINK( this, ScTPValidationValue
, SelectHdl
) );
258 maLbValue
.SetSelectHdl( LINK( this, ScTPValidationValue
, SelectHdl
) );
259 maCbShow
.SetClickHdl( LINK( this, ScTPValidationValue
, CheckHdl
) );
261 maLbAllow
.SelectEntryPos( SC_VALIDDLG_ALLOW_ANY
);
262 maLbValue
.SelectEntryPos( SC_VALIDDLG_DATA_EQUAL
);
268 SfxTabPage
* ScTPValidationValue::Create( Window
* pParent
, const SfxItemSet
& rArgSet
)
270 return( new ScTPValidationValue( pParent
, rArgSet
) );
273 USHORT
* ScTPValidationValue::GetRanges()
278 void ScTPValidationValue::Reset( const SfxItemSet
& rArgSet
)
280 const SfxPoolItem
* pItem
;
282 USHORT nLbPos
= SC_VALIDDLG_ALLOW_ANY
;
283 if( rArgSet
.GetItemState( FID_VALID_MODE
, TRUE
, &pItem
) == SFX_ITEM_SET
)
284 nLbPos
= lclGetPosFromValMode( static_cast< ScValidationMode
>(
285 static_cast< const SfxAllEnumItem
* >( pItem
)->GetValue() ) );
286 maLbAllow
.SelectEntryPos( nLbPos
);
288 nLbPos
= SC_VALIDDLG_DATA_EQUAL
;
289 if( rArgSet
.GetItemState( FID_VALID_CONDMODE
, TRUE
, &pItem
) == SFX_ITEM_SET
)
290 nLbPos
= lclGetPosFromCondMode( static_cast< ScConditionMode
>(
291 static_cast< const SfxAllEnumItem
* >( pItem
)->GetValue() ) );
292 maLbValue
.SelectEntryPos( nLbPos
);
294 // *** check boxes ***
296 if( rArgSet
.GetItemState( FID_VALID_BLANK
, TRUE
, &pItem
) == SFX_ITEM_SET
)
297 bCheck
= static_cast< const SfxBoolItem
* >( pItem
)->GetValue();
298 maCbAllow
.Check( bCheck
);
300 sal_Int32 nListType
= ValidListType::UNSORTED
;
301 if( rArgSet
.GetItemState( FID_VALID_LISTTYPE
, TRUE
, &pItem
) == SFX_ITEM_SET
)
302 nListType
= static_cast< const SfxInt16Item
* >( pItem
)->GetValue();
303 maCbShow
.Check( nListType
!= ValidListType::INVISIBLE
);
304 maCbSort
.Check( nListType
== ValidListType::SORTEDASCENDING
);
308 if ( rArgSet
.GetItemState( FID_VALID_VALUE1
, TRUE
, &pItem
) == SFX_ITEM_SET
)
309 aFmlaStr
= static_cast< const SfxStringItem
* >( pItem
)->GetValue();
310 SetFirstFormula( aFmlaStr
);
313 if ( rArgSet
.GetItemState( FID_VALID_VALUE2
, TRUE
, &pItem
) == SFX_ITEM_SET
)
314 aFmlaStr
= static_cast< const SfxStringItem
* >( pItem
)->GetValue();
315 SetSecondFormula( aFmlaStr
);
321 BOOL
ScTPValidationValue::FillItemSet( SfxItemSet
& rArgSet
)
323 sal_Int16 nListType
= maCbShow
.IsChecked() ?
324 (maCbSort
.IsChecked() ? ValidListType::SORTEDASCENDING
: ValidListType::UNSORTED
) :
325 ValidListType::INVISIBLE
;
327 rArgSet
.Put( SfxAllEnumItem( FID_VALID_MODE
, sal::static_int_cast
<USHORT
>(
328 lclGetValModeFromPos( maLbAllow
.GetSelectEntryPos() ) ) ) );
329 rArgSet
.Put( SfxAllEnumItem( FID_VALID_CONDMODE
, sal::static_int_cast
<USHORT
>(
330 lclGetCondModeFromPos( maLbValue
.GetSelectEntryPos() ) ) ) );
331 rArgSet
.Put( SfxStringItem( FID_VALID_VALUE1
, GetFirstFormula() ) );
332 rArgSet
.Put( SfxStringItem( FID_VALID_VALUE2
, GetSecondFormula() ) );
333 rArgSet
.Put( SfxBoolItem( FID_VALID_BLANK
, maCbAllow
.IsChecked() ) );
334 rArgSet
.Put( SfxInt16Item( FID_VALID_LISTTYPE
, nListType
) );
338 String
ScTPValidationValue::GetFirstFormula() const
341 if( maLbAllow
.GetSelectEntryPos() == SC_VALIDDLG_ALLOW_LIST
)
342 lclGetFormulaFromStringList( aFmlaStr
, maEdList
.GetText(), mcFmlaSep
);
344 aFmlaStr
= maEdMin
.GetText();
348 String
ScTPValidationValue::GetSecondFormula() const
350 return maEdMax
.GetText();
353 void ScTPValidationValue::SetFirstFormula( const String
& rFmlaStr
)
355 // try if formula is a string list, validation mode must already be set
357 if( (maLbAllow
.GetSelectEntryPos() == SC_VALIDDLG_ALLOW_RANGE
) &&
358 lclGetStringListFromFormula( aStringList
, rFmlaStr
, mcFmlaSep
) )
360 maEdList
.SetText( aStringList
);
361 maEdMin
.SetText( EMPTY_STRING
);
362 // change validation mode to string list
363 maLbAllow
.SelectEntryPos( SC_VALIDDLG_ALLOW_LIST
);
367 maEdMin
.SetText( rFmlaStr
);
368 maEdList
.SetText( EMPTY_STRING
);
372 void ScTPValidationValue::SetSecondFormula( const String
& rFmlaStr
)
374 maEdMax
.SetText( rFmlaStr
);
378 // ----------------------------------------------------------------------------
380 IMPL_LINK( ScTPValidationValue
, SelectHdl
, ListBox
*, EMPTYARG
)
382 USHORT nLbPos
= maLbAllow
.GetSelectEntryPos();
383 bool bEnable
= (nLbPos
!= SC_VALIDDLG_ALLOW_ANY
);
384 bool bRange
= (nLbPos
== SC_VALIDDLG_ALLOW_RANGE
);
385 bool bList
= (nLbPos
== SC_VALIDDLG_ALLOW_LIST
);
387 maCbAllow
.Enable( bEnable
); // Leerzellen
388 maFtValue
.Enable( bEnable
);
389 maLbValue
.Enable( bEnable
);
390 maFtMin
.Enable( bEnable
);
391 maEdMin
.Enable( bEnable
);
392 maEdList
.Enable( bEnable
);
393 maFtMax
.Enable( bEnable
);
394 maEdMax
.Enable( bEnable
);
396 bool bShowMax
= false;
398 maFtMin
.SetText( maStrRange
);
400 maFtMin
.SetText( maStrList
);
403 switch( maLbValue
.GetSelectEntryPos() )
405 case SC_VALIDDLG_DATA_EQUAL
:
406 case SC_VALIDDLG_DATA_NOTEQUAL
: maFtMin
.SetText( maStrValue
); break;
408 case SC_VALIDDLG_DATA_LESS
:
409 case SC_VALIDDLG_DATA_EQLESS
: maFtMin
.SetText( maStrMax
); break;
411 case SC_VALIDDLG_DATA_BETWEEN
:
412 case SC_VALIDDLG_DATA_NOTBETWEEN
: bShowMax
= true; // fall through
413 case SC_VALIDDLG_DATA_GREATER
:
414 case SC_VALIDDLG_DATA_EQGREATER
: maFtMin
.SetText( maStrMin
); break;
417 DBG_ERRORFILE( "ScTPValidationValue::SelectHdl - unknown condition mode" );
421 maCbShow
.Show( bRange
|| bList
);
422 maCbSort
.Show( bRange
|| bList
);
423 maFtValue
.Show( !bRange
&& !bList
);
424 maLbValue
.Show( !bRange
&& !bList
);
425 maEdMin
.Show( !bList
);
426 maEdList
.Show( bList
);
427 maFtMax
.Show( bShowMax
);
428 maEdMax
.Show( bShowMax
);
429 maFtHint
.Show( bRange
);
434 IMPL_LINK( ScTPValidationValue
, CheckHdl
, CheckBox
*, EMPTYARG
)
436 maCbSort
.Enable( maCbShow
.IsChecked() );
441 //========================================================================
442 //========================================================================
445 ScTPValidationHelp::ScTPValidationHelp( Window
* pParent
,
446 const SfxItemSet
& rArgSet
)
448 : SfxTabPage ( pParent
,
449 ScResId( TP_VALIDATION_INPUTHELP
),
451 aTsbHelp ( this, ScResId( TSB_HELP
) ),
452 aFlContent ( this, ScResId( FL_CONTENT
) ),
453 aFtTitle ( this, ScResId( FT_TITLE
) ),
454 aEdtTitle ( this, ScResId( EDT_TITLE
) ),
455 aFtInputHelp ( this, ScResId( FT_INPUTHELP
) ),
456 aEdInputHelp ( this, ScResId( EDT_INPUTHELP
) ),
464 // -----------------------------------------------------------------------
466 __EXPORT
ScTPValidationHelp::~ScTPValidationHelp()
470 // -----------------------------------------------------------------------
472 void ScTPValidationHelp::Init()
474 //aLb.SetSelectHdl( LINK( this, ScTPValidationHelp, SelectHdl ) );
476 aTsbHelp
.EnableTriState( FALSE
);
479 //------------------------------------------------------------------------
481 USHORT
* __EXPORT
ScTPValidationHelp::GetRanges()
486 // -----------------------------------------------------------------------
488 SfxTabPage
* __EXPORT
ScTPValidationHelp::Create( Window
* pParent
,
489 const SfxItemSet
& rArgSet
)
491 return ( new ScTPValidationHelp( pParent
, rArgSet
) );
494 // -----------------------------------------------------------------------
496 void __EXPORT
ScTPValidationHelp::Reset( const SfxItemSet
& rArgSet
)
498 const SfxPoolItem
* pItem
;
500 if ( rArgSet
.GetItemState( FID_VALID_SHOWHELP
, TRUE
, &pItem
) == SFX_ITEM_SET
)
501 aTsbHelp
.SetState( ((const SfxBoolItem
*)pItem
)->GetValue() ? STATE_CHECK
: STATE_NOCHECK
);
503 aTsbHelp
.SetState( STATE_NOCHECK
);
505 if ( rArgSet
.GetItemState( FID_VALID_HELPTITLE
, TRUE
, &pItem
) == SFX_ITEM_SET
)
506 aEdtTitle
.SetText( ((const SfxStringItem
*)pItem
)->GetValue() );
508 aEdtTitle
.SetText( EMPTY_STRING
);
510 if ( rArgSet
.GetItemState( FID_VALID_HELPTEXT
, TRUE
, &pItem
) == SFX_ITEM_SET
)
511 aEdInputHelp
.SetText( ((const SfxStringItem
*)pItem
)->GetValue() );
513 aEdInputHelp
.SetText( EMPTY_STRING
);
516 // -----------------------------------------------------------------------
518 BOOL __EXPORT
ScTPValidationHelp::FillItemSet( SfxItemSet
& rArgSet
)
520 rArgSet
.Put( SfxBoolItem( FID_VALID_SHOWHELP
, aTsbHelp
.GetState() == STATE_CHECK
) );
521 rArgSet
.Put( SfxStringItem( FID_VALID_HELPTITLE
, aEdtTitle
.GetText() ) );
522 rArgSet
.Put( SfxStringItem( FID_VALID_HELPTEXT
, aEdInputHelp
.GetText() ) );
527 //========================================================================
528 //========================================================================
531 ScTPValidationError::ScTPValidationError( Window
* pParent
,
532 const SfxItemSet
& rArgSet
)
534 : SfxTabPage ( pParent
,
535 ScResId( TP_VALIDATION_ERROR
),
537 aTsbShow ( this, ScResId( TSB_SHOW
) ),
538 aFlContent ( this, ScResId( FL_CONTENT
) ),
539 aFtAction ( this, ScResId( FT_ACTION
) ),
540 aLbAction ( this, ScResId( LB_ACTION
) ),
541 aBtnSearch ( this, ScResId( BTN_SEARCH
) ),
542 aFtTitle ( this, ScResId( FT_TITLE
) ),
543 aEdtTitle ( this, ScResId( EDT_TITLE
) ),
544 aFtError ( this, ScResId( FT_ERROR
) ),
545 aEdError ( this, ScResId( EDT_ERROR
) ),
553 // -----------------------------------------------------------------------
555 __EXPORT
ScTPValidationError::~ScTPValidationError()
559 // -----------------------------------------------------------------------
561 void ScTPValidationError::Init()
563 aLbAction
.SetSelectHdl( LINK( this, ScTPValidationError
, SelectActionHdl
) );
564 aBtnSearch
.SetClickHdl( LINK( this, ScTPValidationError
, ClickSearchHdl
) );
566 aLbAction
.SelectEntryPos( 0 );
567 aTsbShow
.EnableTriState( FALSE
);
569 SelectActionHdl( NULL
);
572 //------------------------------------------------------------------------
574 USHORT
* __EXPORT
ScTPValidationError::GetRanges()
579 // -----------------------------------------------------------------------
581 SfxTabPage
* __EXPORT
ScTPValidationError::Create( Window
* pParent
,
582 const SfxItemSet
& rArgSet
)
584 return ( new ScTPValidationError( pParent
, rArgSet
) );
587 // -----------------------------------------------------------------------
589 void __EXPORT
ScTPValidationError::Reset( const SfxItemSet
& rArgSet
)
591 const SfxPoolItem
* pItem
;
593 if ( rArgSet
.GetItemState( FID_VALID_SHOWERR
, TRUE
, &pItem
) == SFX_ITEM_SET
)
594 aTsbShow
.SetState( ((const SfxBoolItem
*)pItem
)->GetValue() ? STATE_CHECK
: STATE_NOCHECK
);
596 aTsbShow
.SetState( STATE_CHECK
); // #111720# check by default
598 if ( rArgSet
.GetItemState( FID_VALID_ERRSTYLE
, TRUE
, &pItem
) == SFX_ITEM_SET
)
599 aLbAction
.SelectEntryPos( ((const SfxAllEnumItem
*)pItem
)->GetValue() );
601 aLbAction
.SelectEntryPos( 0 );
603 if ( rArgSet
.GetItemState( FID_VALID_ERRTITLE
, TRUE
, &pItem
) == SFX_ITEM_SET
)
604 aEdtTitle
.SetText( ((const SfxStringItem
*)pItem
)->GetValue() );
606 aEdtTitle
.SetText( EMPTY_STRING
);
608 if ( rArgSet
.GetItemState( FID_VALID_ERRTEXT
, TRUE
, &pItem
) == SFX_ITEM_SET
)
609 aEdError
.SetText( ((const SfxStringItem
*)pItem
)->GetValue() );
611 aEdError
.SetText( EMPTY_STRING
);
613 SelectActionHdl( NULL
);
616 // -----------------------------------------------------------------------
618 BOOL __EXPORT
ScTPValidationError::FillItemSet( SfxItemSet
& rArgSet
)
620 rArgSet
.Put( SfxBoolItem( FID_VALID_SHOWERR
, aTsbShow
.GetState() == STATE_CHECK
) );
621 rArgSet
.Put( SfxAllEnumItem( FID_VALID_ERRSTYLE
, aLbAction
.GetSelectEntryPos() ) );
622 rArgSet
.Put( SfxStringItem( FID_VALID_ERRTITLE
, aEdtTitle
.GetText() ) );
623 rArgSet
.Put( SfxStringItem( FID_VALID_ERRTEXT
, aEdError
.GetText() ) );
628 // -----------------------------------------------------------------------
630 IMPL_LINK( ScTPValidationError
, SelectActionHdl
, ListBox
*, EMPTYARG
)
632 ScValidErrorStyle eStyle
= (ScValidErrorStyle
) aLbAction
.GetSelectEntryPos();
633 BOOL bMacro
= ( eStyle
== SC_VALERR_MACRO
);
635 aBtnSearch
.Enable( bMacro
);
636 aFtError
.Enable( !bMacro
);
637 aEdError
.Enable( !bMacro
);
642 // -----------------------------------------------------------------------
644 IMPL_LINK( ScTPValidationError
, ClickSearchHdl
, PushButton
*, EMPTYARG
)
646 Window
* pOld
= Application::GetDefDialogParent();
647 Application::SetDefDialogParent( this );
649 // Use static SfxApplication method to bring up selector dialog for
651 ::rtl::OUString aScriptURL
= SfxApplication::ChooseScript();
653 Application::SetDefDialogParent( pOld
);
655 if ( aScriptURL
!= NULL
&& aScriptURL
.getLength() != 0 )
657 aEdtTitle
.SetText( aScriptURL
);