1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #ifdef SC_DLLIMPLEMENTATION
22 #undef SC_DLLIMPLEMENTATION
25 #include <comphelper/string.hxx>
26 #include <vcl/svapp.hxx>
27 #include <svl/aeitem.hxx>
28 #include <svl/stritem.hxx>
29 #include <svl/eitem.hxx>
30 #include <svl/intitem.hxx>
31 #include <basic/sbmeth.hxx>
32 #include <basic/sbstar.hxx>
33 #include <basic/sbmod.hxx>
34 #include <sfx2/app.hxx>
36 #include "scresid.hxx"
37 #include "sc.hrc" // -> Slot IDs
39 #include "stringutil.hxx"
40 #include "validat.hxx"
41 #include "validate.hrc"
42 #include "validate.hxx"
43 #include "compiler.hxx"
44 #include "formula/opcode.hxx"
47 #include "tabvwsh.hxx"
48 #include <sfx2/viewfrm.hxx>
49 #include <sfx2/childwin.hxx>
50 #include "reffact.hxx"
52 // ============================================================================
54 static sal_uInt16 pValueRanges
[] =
56 FID_VALID_MODE
, FID_VALID_ERRTEXT
,
57 FID_VALID_LISTTYPE
, FID_VALID_LISTTYPE
,
62 // ============================================================================
64 ScValidationDlg::ScValidationDlg( Window
* pParent
,
65 const SfxItemSet
* pArgSet
,
66 ScTabViewShell
*pTabViewSh
,
67 SfxBindings
*pB
/*= NULL*/
69 ScValidationDlgBase( pParent
? pParent
: SFX_APP()->GetTopWindow(), TAB_DLG_VALIDATION
, pArgSet
, pB
),
70 m_bOwnRefHdlr( false ),
71 m_pTabVwSh( pTabViewSh
),
72 m_bRefInputting( false )
74 AddTabPage( TP_VALIDATION_VALUES
, ScTPValidationValue::Create
, 0 );
75 AddTabPage( TP_VALIDATION_INPUTHELP
, ScTPValidationHelp::Create
, 0 );
76 AddTabPage( TP_VALIDATION_ERROR
, ScTPValidationError::Create
, 0 );
78 //temp hack until converted to .ui
79 mpHBox
= new VclHBox(get_content_area());
82 void ScTPValidationValue::SetReferenceHdl( const ScRange
&rRange
, ScDocument
* pDoc
)
84 if ( rRange
.aStart
!= rRange
.aEnd
)
85 if ( ScValidationDlg
*pValidationDlg
= GetValidationDlg() )
87 pValidationDlg
->RefInputStart( m_pRefEdit
);
92 rRange
.Format( aStr
, SCR_ABS_3D
, pDoc
);
93 m_pRefEdit
->SetRefString( aStr
);
97 void ScTPValidationValue:: SetActiveHdl()
99 if ( m_pRefEdit
) m_pRefEdit
->GrabFocus();
101 if ( ScValidationDlg
*pValidationDlg
= GetValidationDlg() )
104 pValidationDlg
->RefInputDone();
108 void ScTPValidationValue::RefInputStartPreHdl( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
)
110 if ( ScValidationDlg
*pValidationDlg
= GetValidationDlg() )
112 Window
*pNewParent
= pValidationDlg
->get_refinput_shrink_parent();
113 if( pEdit
== m_pRefEdit
&& m_pRefEdit
->GetParent() != pNewParent
)
115 maRefEditPos
= m_pRefEdit
->GetPosPixel();
116 maRefEditSize
= m_pRefEdit
->GetSizePixel();
117 m_pRefEdit
->SetParent(pNewParent
);
120 if( pButton
== &m_btnRef
&& m_btnRef
.GetParent() != pNewParent
)
122 maBtnRefPos
= m_btnRef
.GetPosPixel();
123 maBtnRefSize
= m_btnRef
.GetSizePixel();
124 m_btnRef
.SetParent(pNewParent
);
131 void ScTPValidationValue::RefInputDonePostHdl()
133 if( m_pRefEdit
&& m_pRefEdit
->GetParent()!= this )
135 m_pRefEdit
->SetParent( this );
136 m_pRefEdit
->SetPosSizePixel( maRefEditPos
, maRefEditSize
);
138 m_btnRef
.SetParent( m_pRefEdit
); //if Edit SetParent but button not, the tab order will be incorrect, need button to setparent to anthor window and restore parent later in order to restore the tab order
141 if( m_btnRef
.GetParent()!=this )
143 m_btnRef
.SetParent( this );
144 m_btnRef
.SetPosSizePixel( maBtnRefPos
, maBtnRefSize
);
147 if ( ScValidationDlg
*pValidationDlg
= GetValidationDlg() )
148 pValidationDlg
->get_refinput_shrink_parent()->Hide();
150 if( m_pRefEdit
&& !m_pRefEdit
->HasFocus() )
151 m_pRefEdit
->GrabFocus();
156 sal_Bool
ScValidationDlg::Close()
159 if( SfxTabPage
* pPage
= GetTabPage( TP_VALIDATION_VALUES
) )
160 static_cast<ScTPValidationValue
*>(pPage
)->RemoveRefDlg();
162 return ScValidationDlgBase::Close();
165 ScValidationDlg::~ScValidationDlg()
168 RemoveRefDlg( false );
173 // ============================================================================
177 /** Converts the passed ScValidationMode to the position in the list box. */
178 sal_uInt16
lclGetPosFromValMode( ScValidationMode eValMode
)
180 sal_uInt16 nLbPos
= SC_VALIDDLG_ALLOW_ANY
;
183 case SC_VALID_ANY
: nLbPos
= SC_VALIDDLG_ALLOW_ANY
; break;
184 case SC_VALID_WHOLE
: nLbPos
= SC_VALIDDLG_ALLOW_WHOLE
; break;
185 case SC_VALID_DECIMAL
: nLbPos
= SC_VALIDDLG_ALLOW_DECIMAL
; break;
186 case SC_VALID_DATE
: nLbPos
= SC_VALIDDLG_ALLOW_DATE
; break;
187 case SC_VALID_TIME
: nLbPos
= SC_VALIDDLG_ALLOW_TIME
; break;
188 case SC_VALID_TEXTLEN
: nLbPos
= SC_VALIDDLG_ALLOW_TEXTLEN
; break;
189 case SC_VALID_LIST
: nLbPos
= SC_VALIDDLG_ALLOW_RANGE
; break;
190 case SC_VALID_CUSTOM
: nLbPos
= SC_VALIDDLG_ALLOW_ANY
; break; // not supported
191 default: OSL_FAIL( "lclGetPosFromValMode - unknown validity mode" );
196 /** Converts the passed list box position to an ScValidationMode. */
197 ScValidationMode
lclGetValModeFromPos( sal_uInt16 nLbPos
)
199 ScValidationMode eValMode
= SC_VALID_ANY
;
202 case SC_VALIDDLG_ALLOW_ANY
: eValMode
= SC_VALID_ANY
; break;
203 case SC_VALIDDLG_ALLOW_WHOLE
: eValMode
= SC_VALID_WHOLE
; break;
204 case SC_VALIDDLG_ALLOW_DECIMAL
: eValMode
= SC_VALID_DECIMAL
; break;
205 case SC_VALIDDLG_ALLOW_DATE
: eValMode
= SC_VALID_DATE
; break;
206 case SC_VALIDDLG_ALLOW_TIME
: eValMode
= SC_VALID_TIME
; break;
207 case SC_VALIDDLG_ALLOW_RANGE
: eValMode
= SC_VALID_LIST
; break;
208 case SC_VALIDDLG_ALLOW_LIST
: eValMode
= SC_VALID_LIST
; break;
209 case SC_VALIDDLG_ALLOW_TEXTLEN
: eValMode
= SC_VALID_TEXTLEN
; break;
210 default: OSL_FAIL( "lclGetValModeFromPos - invalid list box position" );
215 /** Converts the passed ScConditionMode to the position in the list box. */
216 sal_uInt16
lclGetPosFromCondMode( ScConditionMode eCondMode
)
218 sal_uInt16 nLbPos
= SC_VALIDDLG_DATA_EQUAL
;
221 case SC_COND_NONE
: // may occur in old XML files after Excel import
222 case SC_COND_EQUAL
: nLbPos
= SC_VALIDDLG_DATA_EQUAL
; break;
223 case SC_COND_LESS
: nLbPos
= SC_VALIDDLG_DATA_LESS
; break;
224 case SC_COND_GREATER
: nLbPos
= SC_VALIDDLG_DATA_GREATER
; break;
225 case SC_COND_EQLESS
: nLbPos
= SC_VALIDDLG_DATA_EQLESS
; break;
226 case SC_COND_EQGREATER
: nLbPos
= SC_VALIDDLG_DATA_EQGREATER
; break;
227 case SC_COND_NOTEQUAL
: nLbPos
= SC_VALIDDLG_DATA_NOTEQUAL
; break;
228 case SC_COND_BETWEEN
: nLbPos
= SC_VALIDDLG_DATA_VALIDRANGE
; break;
229 case SC_COND_NOTBETWEEN
: nLbPos
= SC_VALIDDLG_DATA_INVALIDRANGE
; break;
230 default: OSL_FAIL( "lclGetPosFromCondMode - unknown condition mode" );
235 /** Converts the passed list box position to an ScConditionMode. */
236 ScConditionMode
lclGetCondModeFromPos( sal_uInt16 nLbPos
)
238 ScConditionMode eCondMode
= SC_COND_EQUAL
;
241 case SC_VALIDDLG_DATA_EQUAL
: eCondMode
= SC_COND_EQUAL
; break;
242 case SC_VALIDDLG_DATA_LESS
: eCondMode
= SC_COND_LESS
; break;
243 case SC_VALIDDLG_DATA_GREATER
: eCondMode
= SC_COND_GREATER
; break;
244 case SC_VALIDDLG_DATA_EQLESS
: eCondMode
= SC_COND_EQLESS
; break;
245 case SC_VALIDDLG_DATA_EQGREATER
: eCondMode
= SC_COND_EQGREATER
; break;
246 case SC_VALIDDLG_DATA_NOTEQUAL
: eCondMode
= SC_COND_NOTEQUAL
; break;
247 case SC_VALIDDLG_DATA_VALIDRANGE
: eCondMode
= SC_COND_BETWEEN
; break;
248 case SC_VALIDDLG_DATA_INVALIDRANGE
: eCondMode
= SC_COND_NOTBETWEEN
; break;
249 default: OSL_FAIL( "lclGetCondModeFromPos - invalid list box position" );
254 /** Converts line feed separated string to a formula with strings separated by semicolons.
255 @descr Keeps all empty strings.
256 Example: abc\ndef\n\nghi -> "abc";"def";"";"ghi".
257 @param rFmlaStr (out-param) The converted formula string. */
258 void lclGetFormulaFromStringList( OUString
& rFmlaStr
, const OUString
& rStringList
, sal_Unicode cFmlaSep
)
261 xub_StrLen nTokenCnt
= comphelper::string::getTokenCount(rStringList
, '\n');
262 for( sal_Int32 nToken
= 0, nStringIx
= 0; nToken
< (sal_Int32
) nTokenCnt
; ++nToken
)
264 OUString
aToken( rStringList
.getToken( 0, '\n', nStringIx
) );
265 ScGlobal::AddQuotes( aToken
, '"' );
266 rFmlaStr
= ScGlobal::addToken(rFmlaStr
, aToken
, cFmlaSep
);
268 if( rFmlaStr
.isEmpty() )
273 /** Converts formula with strings separated by semicolons to line feed separated string.
274 @descr Keeps all empty strings. Ignores all empty tokens (multiple semicolons).
275 Example: "abc";;;"def";"";"ghi" -> abc\ndef\n\nghi.
276 @param rStringList (out-param) The converted line feed separated string list.
277 @return true = Conversion successful. */
278 bool lclGetStringListFromFormula( OUString
& rStringList
, const OUString
& rFmlaStr
, sal_Unicode cFmlaSep
)
280 OUString
aQuotes( "\"\"" );
281 sal_Int32 nTokenCnt
= ScStringUtil::GetQuotedTokenCount(rFmlaStr
, aQuotes
, cFmlaSep
);
284 bool bIsStringList
= (nTokenCnt
> 0);
285 bool bTokenAdded
= false;
287 for( sal_Int32 nToken
= 0, nStringIx
= 0; bIsStringList
&& (nToken
< nTokenCnt
); ++nToken
)
289 OUString
aToken( ScStringUtil::GetQuotedToken(rFmlaStr
, 0, aQuotes
, cFmlaSep
, nStringIx
) );
290 aToken
= comphelper::string::strip(aToken
, ' ');
291 if( !aToken
.isEmpty() ) // ignore empty tokens, i.e. "a";;"b"
293 bIsStringList
= ScGlobal::IsQuoted( aToken
, '"' );
296 ScGlobal::EraseQuotes( aToken
, '"' );
297 rStringList
= ScGlobal::addToken(rStringList
, aToken
, '\n', 1, bTokenAdded
);
303 return bIsStringList
;
308 // ----------------------------------------------------------------------------
310 ScTPValidationValue::ScTPValidationValue( Window
* pParent
, const SfxItemSet
& rArgSet
) :
311 SfxTabPage( pParent
, ScResId( TP_VALIDATION_VALUES
), rArgSet
),
312 maFtAllow ( this, ScResId( FT_ALLOW
) ),
313 maLbAllow ( this, ScResId( LB_ALLOW
) ),
314 maCbAllow ( this, ScResId( TSB_ALLOW_BLANKS
) ),
315 maCbShow ( this, ScResId( CB_SHOWLIST
) ),
316 maCbSort ( this, ScResId( CB_SORTLIST
) ),
317 maFtValue ( this, ScResId( FT_VALUE
) ),
318 maLbValue ( this, ScResId( LB_VALUE
) ),
319 maFtMin ( this, ScResId( FT_MIN
) ),
320 maEdMin ( this, NULL
, &maFtMin
, ScResId( EDT_MIN
) ),
321 maEdList ( this, ScResId( EDT_LIST
) ),
322 maFtMax ( this, ScResId( FT_MAX
) ),
323 maEdMax ( this, NULL
, &maFtMax
, ScResId( EDT_MAX
) ),
324 maFtHint ( this, ScResId( FT_SOURCEHINT
) ),
325 maStrMin ( ScResId( SCSTR_VALID_MINIMUM
) ),
326 maStrMax ( ScResId( SCSTR_VALID_MAXIMUM
) ),
327 maStrValue( ScResId( SCSTR_VALID_VALUE
) ),
328 maStrRange( ScResId( SCSTR_VALID_RANGE
) ),
329 maStrList ( ScResId( SCSTR_VALID_LIST
) ),
330 m_btnRef( this, ScResId( RB_VALIDITY_REF
) )
335 // list separator in formulas
336 String aListSep
= ::ScCompiler::GetNativeSymbol( ocSep
);
337 OSL_ENSURE( aListSep
.Len() == 1, "ScTPValidationValue::ScTPValidationValue - list separator error" );
338 mcFmlaSep
= aListSep
.Len() ? aListSep
.GetChar( 0 ) : ';';
339 m_btnRef
.Hide(); // cell range picker
342 ScTPValidationValue::~ScTPValidationValue()
346 void ScTPValidationValue::Init()
348 maLbAllow
.SetSelectHdl( LINK( this, ScTPValidationValue
, SelectHdl
) );
349 maLbValue
.SetSelectHdl( LINK( this, ScTPValidationValue
, SelectHdl
) );
350 maCbShow
.SetClickHdl( LINK( this, ScTPValidationValue
, CheckHdl
) );
353 maEdMin
.SetGetFocusHdl( LINK( this, ScTPValidationValue
, EditSetFocusHdl
) );
354 maEdMin
.SetLoseFocusHdl( LINK( this, ScTPValidationValue
, KillFocusHdl
) );
355 maEdMax
.SetGetFocusHdl( LINK( this, ScTPValidationValue
, EditSetFocusHdl
) );
356 m_btnRef
.SetLoseFocusHdl( LINK( this, ScTPValidationValue
, KillFocusHdl
) );
357 maEdMax
.SetLoseFocusHdl( LINK( this, ScTPValidationValue
, KillFocusHdl
) );
359 maLbAllow
.SelectEntryPos( SC_VALIDDLG_ALLOW_ANY
);
360 maLbValue
.SelectEntryPos( SC_VALIDDLG_DATA_EQUAL
);
366 SfxTabPage
* ScTPValidationValue::Create( Window
* pParent
, const SfxItemSet
& rArgSet
)
368 return( new ScTPValidationValue( pParent
, rArgSet
) );
371 sal_uInt16
* ScTPValidationValue::GetRanges()
376 void ScTPValidationValue::Reset( const SfxItemSet
& rArgSet
)
378 const SfxPoolItem
* pItem
;
380 sal_uInt16 nLbPos
= SC_VALIDDLG_ALLOW_ANY
;
381 if( rArgSet
.GetItemState( FID_VALID_MODE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
382 nLbPos
= lclGetPosFromValMode( static_cast< ScValidationMode
>(
383 static_cast< const SfxAllEnumItem
* >( pItem
)->GetValue() ) );
384 maLbAllow
.SelectEntryPos( nLbPos
);
386 nLbPos
= SC_VALIDDLG_DATA_EQUAL
;
387 if( rArgSet
.GetItemState( FID_VALID_CONDMODE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
388 nLbPos
= lclGetPosFromCondMode( static_cast< ScConditionMode
>(
389 static_cast< const SfxAllEnumItem
* >( pItem
)->GetValue() ) );
390 maLbValue
.SelectEntryPos( nLbPos
);
392 // *** check boxes ***
393 sal_Bool bCheck
= sal_True
;
394 if( rArgSet
.GetItemState( FID_VALID_BLANK
, sal_True
, &pItem
) == SFX_ITEM_SET
)
395 bCheck
= static_cast< const SfxBoolItem
* >( pItem
)->GetValue();
396 maCbAllow
.Check( bCheck
);
398 sal_Int32 nListType
= ValidListType::UNSORTED
;
399 if( rArgSet
.GetItemState( FID_VALID_LISTTYPE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
400 nListType
= static_cast< const SfxInt16Item
* >( pItem
)->GetValue();
401 maCbShow
.Check( nListType
!= ValidListType::INVISIBLE
);
402 maCbSort
.Check( nListType
== ValidListType::SORTEDASCENDING
);
406 if ( rArgSet
.GetItemState( FID_VALID_VALUE1
, sal_True
, &pItem
) == SFX_ITEM_SET
)
407 aFmlaStr
= static_cast< const SfxStringItem
* >( pItem
)->GetValue();
408 SetFirstFormula( aFmlaStr
);
411 if ( rArgSet
.GetItemState( FID_VALID_VALUE2
, sal_True
, &pItem
) == SFX_ITEM_SET
)
412 aFmlaStr
= static_cast< const SfxStringItem
* >( pItem
)->GetValue();
413 SetSecondFormula( aFmlaStr
);
419 sal_Bool
ScTPValidationValue::FillItemSet( SfxItemSet
& rArgSet
)
421 sal_Int16 nListType
= maCbShow
.IsChecked() ?
422 (maCbSort
.IsChecked() ? ValidListType::SORTEDASCENDING
: ValidListType::UNSORTED
) :
423 ValidListType::INVISIBLE
;
425 rArgSet
.Put( SfxAllEnumItem( FID_VALID_MODE
, sal::static_int_cast
<sal_uInt16
>(
426 lclGetValModeFromPos( maLbAllow
.GetSelectEntryPos() ) ) ) );
427 rArgSet
.Put( SfxAllEnumItem( FID_VALID_CONDMODE
, sal::static_int_cast
<sal_uInt16
>(
428 lclGetCondModeFromPos( maLbValue
.GetSelectEntryPos() ) ) ) );
429 rArgSet
.Put( SfxStringItem( FID_VALID_VALUE1
, GetFirstFormula() ) );
430 rArgSet
.Put( SfxStringItem( FID_VALID_VALUE2
, GetSecondFormula() ) );
431 rArgSet
.Put( SfxBoolItem( FID_VALID_BLANK
, maCbAllow
.IsChecked() ) );
432 rArgSet
.Put( SfxInt16Item( FID_VALID_LISTTYPE
, nListType
) );
436 String
ScTPValidationValue::GetFirstFormula() const
439 if( maLbAllow
.GetSelectEntryPos() == SC_VALIDDLG_ALLOW_LIST
)
440 lclGetFormulaFromStringList( aFmlaStr
, maEdList
.GetText(), mcFmlaSep
);
442 aFmlaStr
= maEdMin
.GetText();
446 String
ScTPValidationValue::GetSecondFormula() const
448 return maEdMax
.GetText();
451 void ScTPValidationValue::SetFirstFormula( const OUString
& rFmlaStr
)
453 // try if formula is a string list, validation mode must already be set
454 OUString aStringList
;
455 if( (maLbAllow
.GetSelectEntryPos() == SC_VALIDDLG_ALLOW_RANGE
) &&
456 lclGetStringListFromFormula( aStringList
, rFmlaStr
, mcFmlaSep
) )
458 maEdList
.SetText( aStringList
);
459 maEdMin
.SetText( EMPTY_STRING
);
460 // change validation mode to string list
461 maLbAllow
.SelectEntryPos( SC_VALIDDLG_ALLOW_LIST
);
465 maEdMin
.SetText( rFmlaStr
);
466 maEdList
.SetText( EMPTY_STRING
);
470 void ScTPValidationValue::SetSecondFormula( const String
& rFmlaStr
)
472 maEdMax
.SetText( rFmlaStr
);
475 ScValidationDlg
* ScTPValidationValue::GetValidationDlg()
477 if( Window
*pParent
= GetParent() )
479 if ( dynamic_cast<ScValidationDlg
*>( pParent
) )
480 return static_cast< ScValidationDlg
* >( pParent
);
481 }while ( NULL
!= ( pParent
= pParent
->GetParent() ) );
485 void ScTPValidationValue::SetupRefDlg()
487 if( ScValidationDlg
*pValidationDlg
= GetValidationDlg() )
489 if( pValidationDlg
->SetupRefDlg() )
491 pValidationDlg
->SetHandler( this );
492 pValidationDlg
->SetSetRefHdl( (ScRefHandlerHelper::PFUNCSETREFHDLTYPE
)( &ScTPValidationValue::SetReferenceHdl
) );
493 pValidationDlg
->SetSetActHdl( (ScRefHandlerHelper::PCOMMONHDLTYPE
)( &ScTPValidationValue::SetActiveHdl
) );
494 pValidationDlg
->SetRefInputStartPreHdl( (ScRefHandlerHelper::PINPUTSTARTDLTYPE
)( &ScTPValidationValue::RefInputStartPreHdl
) );
495 pValidationDlg
->SetRefInputDonePostHdl( (ScRefHandlerHelper::PCOMMONHDLTYPE
)( &ScTPValidationValue::RefInputDonePostHdl
) );
497 Window
*pLabel
= NULL
;
499 if ( maEdMax
.IsVisible() )
501 m_pRefEdit
= &maEdMax
;
504 else if ( maEdMin
.IsVisible() )
506 m_pRefEdit
= &maEdMin
;
510 if( m_pRefEdit
&& !m_pRefEdit
->HasFocus() )
511 m_pRefEdit
->GrabFocus();
514 m_pRefEdit
->SetReferences( pValidationDlg
, pLabel
);
516 m_btnRef
.SetReferences( pValidationDlg
, m_pRefEdit
);
521 void ScTPValidationValue::RemoveRefDlg()
523 if( ScValidationDlg
*pValidationDlg
= GetValidationDlg() )
525 if( pValidationDlg
->RemoveRefDlg() )
527 pValidationDlg
->SetHandler( NULL
);
528 pValidationDlg
->SetSetRefHdl( NULL
);
529 pValidationDlg
->SetSetActHdl( NULL
);
530 pValidationDlg
->SetRefInputStartPreHdl( NULL
);
531 pValidationDlg
->SetRefInputDonePostHdl( NULL
);
534 m_pRefEdit
->SetReferences( NULL
, NULL
);
537 m_btnRef
.SetReferences( NULL
, NULL
);
539 #if ! defined( WNT ) && !defined( _MSC_VER )
546 void ScTPValidationValue::TidyListBoxes()
548 if ( Window
*pWnd
= GetChild( 0 ) )
550 bool bFindLst
= false;
551 std::list
<Window
*> alstOrder
;
554 if( pWnd
->GetParent() == this )
559 if( dynamic_cast<ListBox
*>(pWnd
)||dynamic_cast<ListBox
*>(pWnd
->GetWindow(WINDOW_CLIENT
) ) )
564 if ( *(void**)pWnd
== *(void**)&maLbValue
)
566 else if ( Window
*pClient
= pWnd
->GetWindow( WINDOW_CLIENT
) )
567 if ( *(void**)pClient
== *(void**)&maLbValue
)
573 alstOrder
.push_back( pWnd
->GetWindow( WINDOW_CLIENT
) );
575 }while( NULL
!= ( pWnd
= pWnd
->GetWindow( WINDOW_NEXT
) ) );
579 while( std::find( alstOrder
.begin(), alstOrder
.end(), pWnd
) != alstOrder
.end() && NULL
!= ( pWnd
= pWnd
->GetWindow( WINDOW_NEXT
) ) ) ;
583 for ( std::list
<Window
*>::iterator i
= alstOrder
.begin(); i
!=alstOrder
.end(); ++i
)
585 Window
*pParent
= (*i
)->GetParent();
586 (*i
)->SetParent( pWnd
);
587 (*i
)->SetParent( pParent
);
593 IMPL_LINK_NOARG(ScTPValidationValue
, EditSetFocusHdl
)
595 sal_uInt16 nPos
=maLbAllow
.GetSelectEntryPos();
597 if ( nPos
== SC_VALIDDLG_ALLOW_RANGE
)
605 IMPL_LINK( ScTPValidationValue
, KillFocusHdl
, Window
*, pWnd
)
607 if( pWnd
== m_pRefEdit
|| pWnd
== &m_btnRef
)
608 if( ScValidationDlg
*pValidationDlg
= GetValidationDlg() )
609 if ( (pValidationDlg
->IsActive() || pValidationDlg
->IsChildFocus() ) && !pValidationDlg
->IsRefInputting() )
610 if( ( !m_pRefEdit
|| !m_pRefEdit
->HasFocus()) && !m_btnRef
.HasFocus() )
618 // ----------------------------------------------------------------------------
620 IMPL_LINK_NOARG(ScTPValidationValue
, SelectHdl
)
622 sal_uInt16 nLbPos
= maLbAllow
.GetSelectEntryPos();
623 bool bEnable
= (nLbPos
!= SC_VALIDDLG_ALLOW_ANY
);
624 bool bRange
= (nLbPos
== SC_VALIDDLG_ALLOW_RANGE
);
625 bool bList
= (nLbPos
== SC_VALIDDLG_ALLOW_LIST
);
627 maCbAllow
.Enable( bEnable
); // Empty cell
628 maFtValue
.Enable( bEnable
);
629 maLbValue
.Enable( bEnable
);
630 maFtMin
.Enable( bEnable
);
631 maEdMin
.Enable( bEnable
);
632 maEdList
.Enable( bEnable
);
633 maFtMax
.Enable( bEnable
);
634 maEdMax
.Enable( bEnable
);
636 bool bShowMax
= false;
638 maFtMin
.SetText( maStrRange
);
640 maFtMin
.SetText( maStrList
);
643 switch( maLbValue
.GetSelectEntryPos() )
645 case SC_VALIDDLG_DATA_EQUAL
:
646 case SC_VALIDDLG_DATA_NOTEQUAL
: maFtMin
.SetText( maStrValue
); break;
648 case SC_VALIDDLG_DATA_LESS
:
649 case SC_VALIDDLG_DATA_EQLESS
: maFtMin
.SetText( maStrMax
); break;
651 case SC_VALIDDLG_DATA_VALIDRANGE
:
652 case SC_VALIDDLG_DATA_INVALIDRANGE
: bShowMax
= true; // fall through
653 case SC_VALIDDLG_DATA_GREATER
:
654 case SC_VALIDDLG_DATA_EQGREATER
: maFtMin
.SetText( maStrMin
); break;
657 OSL_FAIL( "ScTPValidationValue::SelectHdl - unknown condition mode" );
661 maCbShow
.Show( bRange
|| bList
);
662 maCbSort
.Show( bRange
|| bList
);
663 maFtValue
.Show( !bRange
&& !bList
);
664 maLbValue
.Show( !bRange
&& !bList
);
665 maEdMin
.Show( !bList
);
666 maEdList
.Show( bList
);
667 maFtMax
.Show( bShowMax
);
668 maEdMax
.Show( bShowMax
);
669 maFtHint
.Show( bRange
);
670 m_btnRef
.Show( bRange
); // cell range picker
674 IMPL_LINK_NOARG(ScTPValidationValue
, CheckHdl
)
676 maCbSort
.Enable( maCbShow
.IsChecked() );
681 //========================================================================
682 //========================================================================
685 ScTPValidationHelp::ScTPValidationHelp( Window
* pParent
,
686 const SfxItemSet
& rArgSet
)
688 : SfxTabPage ( pParent
,
689 ScResId( TP_VALIDATION_INPUTHELP
),
691 aTsbHelp ( this, ScResId( TSB_HELP
) ),
692 aFlContent ( this, ScResId( FL_CONTENT
) ),
693 aFtTitle ( this, ScResId( FT_TITLE
) ),
694 aEdtTitle ( this, ScResId( EDT_TITLE
) ),
695 aFtInputHelp ( this, ScResId( FT_INPUTHELP
) ),
696 aEdInputHelp ( this, ScResId( EDT_INPUTHELP
) )
702 // -----------------------------------------------------------------------
704 ScTPValidationHelp::~ScTPValidationHelp()
708 // -----------------------------------------------------------------------
710 void ScTPValidationHelp::Init()
712 aTsbHelp
.EnableTriState( false );
715 //------------------------------------------------------------------------
717 sal_uInt16
* ScTPValidationHelp::GetRanges()
722 // -----------------------------------------------------------------------
724 SfxTabPage
* ScTPValidationHelp::Create( Window
* pParent
,
725 const SfxItemSet
& rArgSet
)
727 return ( new ScTPValidationHelp( pParent
, rArgSet
) );
730 // -----------------------------------------------------------------------
732 void ScTPValidationHelp::Reset( const SfxItemSet
& rArgSet
)
734 const SfxPoolItem
* pItem
;
736 if ( rArgSet
.GetItemState( FID_VALID_SHOWHELP
, sal_True
, &pItem
) == SFX_ITEM_SET
)
737 aTsbHelp
.SetState( ((const SfxBoolItem
*)pItem
)->GetValue() ? STATE_CHECK
: STATE_NOCHECK
);
739 aTsbHelp
.SetState( STATE_NOCHECK
);
741 if ( rArgSet
.GetItemState( FID_VALID_HELPTITLE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
742 aEdtTitle
.SetText( ((const SfxStringItem
*)pItem
)->GetValue() );
744 aEdtTitle
.SetText( EMPTY_STRING
);
746 if ( rArgSet
.GetItemState( FID_VALID_HELPTEXT
, sal_True
, &pItem
) == SFX_ITEM_SET
)
747 aEdInputHelp
.SetText( ((const SfxStringItem
*)pItem
)->GetValue() );
749 aEdInputHelp
.SetText( EMPTY_STRING
);
752 // -----------------------------------------------------------------------
754 sal_Bool
ScTPValidationHelp::FillItemSet( SfxItemSet
& rArgSet
)
756 rArgSet
.Put( SfxBoolItem( FID_VALID_SHOWHELP
, aTsbHelp
.GetState() == STATE_CHECK
) );
757 rArgSet
.Put( SfxStringItem( FID_VALID_HELPTITLE
, aEdtTitle
.GetText() ) );
758 rArgSet
.Put( SfxStringItem( FID_VALID_HELPTEXT
, aEdInputHelp
.GetText() ) );
763 //========================================================================
764 //========================================================================
767 ScTPValidationError::ScTPValidationError( Window
* pParent
,
768 const SfxItemSet
& rArgSet
)
770 : SfxTabPage ( pParent
,
771 ScResId( TP_VALIDATION_ERROR
),
773 aTsbShow ( this, ScResId( TSB_SHOW
) ),
774 aFlContent ( this, ScResId( FL_CONTENT
) ),
775 aFtAction ( this, ScResId( FT_ACTION
) ),
776 aLbAction ( this, ScResId( LB_ACTION
) ),
777 aBtnSearch ( this, ScResId( BTN_SEARCH
) ),
778 aFtTitle ( this, ScResId( FT_TITLE
) ),
779 aEdtTitle ( this, ScResId( EDT_TITLE
) ),
780 aFtError ( this, ScResId( FT_ERROR
) ),
781 aEdError ( this, ScResId( EDT_ERROR
) )
787 // -----------------------------------------------------------------------
789 ScTPValidationError::~ScTPValidationError()
793 // -----------------------------------------------------------------------
795 void ScTPValidationError::Init()
797 aLbAction
.SetSelectHdl( LINK( this, ScTPValidationError
, SelectActionHdl
) );
798 aBtnSearch
.SetClickHdl( LINK( this, ScTPValidationError
, ClickSearchHdl
) );
800 aLbAction
.SelectEntryPos( 0 );
801 aTsbShow
.EnableTriState( false );
803 SelectActionHdl( NULL
);
806 //------------------------------------------------------------------------
808 sal_uInt16
* ScTPValidationError::GetRanges()
813 // -----------------------------------------------------------------------
815 SfxTabPage
* ScTPValidationError::Create( Window
* pParent
,
816 const SfxItemSet
& rArgSet
)
818 return ( new ScTPValidationError( pParent
, rArgSet
) );
821 // -----------------------------------------------------------------------
823 void ScTPValidationError::Reset( const SfxItemSet
& rArgSet
)
825 const SfxPoolItem
* pItem
;
827 if ( rArgSet
.GetItemState( FID_VALID_SHOWERR
, sal_True
, &pItem
) == SFX_ITEM_SET
)
828 aTsbShow
.SetState( ((const SfxBoolItem
*)pItem
)->GetValue() ? STATE_CHECK
: STATE_NOCHECK
);
830 aTsbShow
.SetState( STATE_CHECK
); // check by default
832 if ( rArgSet
.GetItemState( FID_VALID_ERRSTYLE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
833 aLbAction
.SelectEntryPos( ((const SfxAllEnumItem
*)pItem
)->GetValue() );
835 aLbAction
.SelectEntryPos( 0 );
837 if ( rArgSet
.GetItemState( FID_VALID_ERRTITLE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
838 aEdtTitle
.SetText( ((const SfxStringItem
*)pItem
)->GetValue() );
840 aEdtTitle
.SetText( EMPTY_STRING
);
842 if ( rArgSet
.GetItemState( FID_VALID_ERRTEXT
, sal_True
, &pItem
) == SFX_ITEM_SET
)
843 aEdError
.SetText( ((const SfxStringItem
*)pItem
)->GetValue() );
845 aEdError
.SetText( EMPTY_STRING
);
847 SelectActionHdl( NULL
);
850 // -----------------------------------------------------------------------
852 sal_Bool
ScTPValidationError::FillItemSet( SfxItemSet
& rArgSet
)
854 rArgSet
.Put( SfxBoolItem( FID_VALID_SHOWERR
, aTsbShow
.GetState() == STATE_CHECK
) );
855 rArgSet
.Put( SfxAllEnumItem( FID_VALID_ERRSTYLE
, aLbAction
.GetSelectEntryPos() ) );
856 rArgSet
.Put( SfxStringItem( FID_VALID_ERRTITLE
, aEdtTitle
.GetText() ) );
857 rArgSet
.Put( SfxStringItem( FID_VALID_ERRTEXT
, aEdError
.GetText() ) );
862 // -----------------------------------------------------------------------
864 IMPL_LINK_NOARG(ScTPValidationError
, SelectActionHdl
)
866 ScValidErrorStyle eStyle
= (ScValidErrorStyle
) aLbAction
.GetSelectEntryPos();
867 sal_Bool bMacro
= ( eStyle
== SC_VALERR_MACRO
);
869 aBtnSearch
.Enable( bMacro
);
870 aFtError
.Enable( !bMacro
);
871 aEdError
.Enable( !bMacro
);
876 // -----------------------------------------------------------------------
878 IMPL_LINK_NOARG(ScTPValidationError
, ClickSearchHdl
)
880 Window
* pOld
= Application::GetDefDialogParent();
881 Application::SetDefDialogParent( this );
883 // Use static SfxApplication method to bring up selector dialog for
885 OUString aScriptURL
= SfxApplication::ChooseScript();
887 Application::SetDefDialogParent( pOld
);
889 if ( aScriptURL
!= NULL
&& !aScriptURL
.isEmpty() )
891 aEdtTitle
.SetText( aScriptURL
);
897 bool ScValidationDlg::EnterRefStatus()
899 ScTabViewShell
*pTabViewShell
= GetTabViewShell();
901 if( !pTabViewShell
) return false;
903 sal_uInt16 nId
= SLOTID
;
904 SfxViewFrame
* pViewFrm
= pTabViewShell
->GetViewFrame();
905 SfxChildWindow
* pWnd
= pViewFrm
->GetChildWindow( nId
);
907 if ( pWnd
&& pWnd
->GetWindow()!= this ) pWnd
= NULL
;
909 SC_MOD()->SetRefDialog( nId
, pWnd
? false : sal_True
);
914 bool ScValidationDlg::LeaveRefStatus()
916 ScTabViewShell
*pTabViewShell
= GetTabViewShell();
918 if( !pTabViewShell
) return false;
920 sal_uInt16 nId
= SLOTID
;
921 SfxViewFrame
* pViewFrm
= pTabViewShell
->GetViewFrame();
922 if ( pViewFrm
->GetChildWindow( nId
) )
929 bool ScValidationDlg::SetupRefDlg()
931 if ( m_bOwnRefHdlr
) return false;
935 return m_bOwnRefHdlr
= true && EnterRefStatus();
941 bool ScValidationDlg::RemoveRefDlg( sal_Bool bRestoreModal
/* = sal_True */ )
943 bool bVisLock
= false;
944 bool bFreeWindowLock
= false;
946 ScTabViewShell
*pTabVwSh
= GetTabViewShell();
948 if( !pTabVwSh
) return false;
950 if ( SfxChildWindow
* pWnd
= pTabVwSh
->GetViewFrame()->GetChildWindow( SID_VALIDITY_REFERENCE
) )
952 bVisLock
= static_cast<ScValidityRefChildWin
*>(pWnd
)->LockVisible( true );
953 bFreeWindowLock
= static_cast<ScValidityRefChildWin
*>(pWnd
)->LockFreeWindow( true );
956 if ( !m_bOwnRefHdlr
) return false;
957 if( LeaveRefStatus() && LeaveRefMode() )
959 m_bOwnRefHdlr
= false;
962 SetModal( sal_True
);
965 if ( SfxChildWindow
* pWnd
= pTabVwSh
->GetViewFrame()->GetChildWindow( SID_VALIDITY_REFERENCE
) )
967 static_cast<ScValidityRefChildWin
*>(pWnd
)->LockVisible( bVisLock
);
968 static_cast<ScValidityRefChildWin
*>(pWnd
)->LockFreeWindow( bFreeWindowLock
);
974 void ScTPValidationValue::ScRefButtonEx::Click()
976 if( ScTPValidationValue
*pParent
= dynamic_cast< ScTPValidationValue
*>( GetParent() ) )
977 pParent
->OnClick( this );
979 formula::RefButton::Click();
982 void ScTPValidationValue::OnClick( Button
*pBtn
)
984 if( pBtn
== &m_btnRef
)
988 sal_Bool
ScValidationDlg::IsChildFocus()
990 if ( const Window
*pWin
= Application::GetFocusWindow() )
991 while( NULL
!= ( pWin
= pWin
->GetParent() ) )
999 bool ScValidationDlg::IsAlive()
1001 return SC_MOD()->IsAliveRefDlg( SLOTID
, this );
1004 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */