xref: /AOO41X/main/sc/source/ui/dbgui/validate.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifdef SC_DLLIMPLEMENTATION
32*cdf0e10cSrcweir #undef SC_DLLIMPLEMENTATION
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <vcl/svapp.hxx>
36*cdf0e10cSrcweir #include <svl/aeitem.hxx>
37*cdf0e10cSrcweir #include <svl/stritem.hxx>
38*cdf0e10cSrcweir #include <svl/eitem.hxx>
39*cdf0e10cSrcweir #include <svl/intitem.hxx>
40*cdf0e10cSrcweir #include <basic/sbmeth.hxx>
41*cdf0e10cSrcweir #include <basic/sbstar.hxx>
42*cdf0e10cSrcweir #include <basic/sbmod.hxx>
43*cdf0e10cSrcweir #include <sfx2/app.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include "scresid.hxx"
46*cdf0e10cSrcweir #include "sc.hrc"       // -> Slot IDs
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #include "validat.hxx"
49*cdf0e10cSrcweir #include "validate.hrc"
50*cdf0e10cSrcweir #include "validate.hxx"
51*cdf0e10cSrcweir #include "compiler.hxx"
52*cdf0e10cSrcweir #include "formula/opcode.hxx" //CHINA001
53*cdf0e10cSrcweir //<!--Added by PengYunQuan for Validity Cell Range Picker
54*cdf0e10cSrcweir #include "tabvwsh.hxx"
55*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
56*cdf0e10cSrcweir #include <sfx2/childwin.hxx>
57*cdf0e10cSrcweir #include "reffact.hxx"
58*cdf0e10cSrcweir //-->Added by PengYunQuan for Validity Cell Range Picker
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir // ============================================================================
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir static sal_uInt16 pValueRanges[] =
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir 	FID_VALID_MODE,	FID_VALID_ERRTEXT,
65*cdf0e10cSrcweir     FID_VALID_LISTTYPE, FID_VALID_LISTTYPE,
66*cdf0e10cSrcweir 	0
67*cdf0e10cSrcweir };
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir // ============================================================================
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir //<!--Modified by PengYunQuan for Validity Cell Range Picker
73*cdf0e10cSrcweir //ScValidationDlg::ScValidationDlg( Window* pParent, const SfxItemSet* pArgSet ) :
74*cdf0e10cSrcweir //    SfxTabDialog( pParent, ScResId( TAB_DLG_VALIDATION ), pArgSet )
75*cdf0e10cSrcweir ScValidationDlg::ScValidationDlg( Window*			pParent,
76*cdf0e10cSrcweir 								 const SfxItemSet* pArgSet,
77*cdf0e10cSrcweir 								 ScTabViewShell *pTabViewSh,
78*cdf0e10cSrcweir 								 SfxBindings *pB /*= NULL*/
79*cdf0e10cSrcweir 					  ) :
80*cdf0e10cSrcweir 		ScValidationDlgBase( pParent ? pParent : SFX_APP()->GetTopWindow(), TAB_DLG_VALIDATION, pArgSet, pB ),
81*cdf0e10cSrcweir 			m_bOwnRefHdlr( false ),
82*cdf0e10cSrcweir 			m_pTabVwSh( pTabViewSh ),
83*cdf0e10cSrcweir 			m_bRefInputting( false )
84*cdf0e10cSrcweir //-->Modified by PengYunQuan for Validity Cell Range Picker
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     AddTabPage( TP_VALIDATION_VALUES,    ScTPValidationValue::Create, 0 );
87*cdf0e10cSrcweir 	AddTabPage( TP_VALIDATION_INPUTHELP, ScTPValidationHelp::Create,  0 );
88*cdf0e10cSrcweir     AddTabPage( TP_VALIDATION_ERROR,     ScTPValidationError::Create, 0 );
89*cdf0e10cSrcweir 	FreeResource();
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir //<!--Added by PengYunQuan for Validity Cell Range Picker
93*cdf0e10cSrcweir void ScTPValidationValue::SetReferenceHdl( const ScRange&rRange , ScDocument* pDoc )
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir 	if ( rRange.aStart != rRange.aEnd )
96*cdf0e10cSrcweir 		if ( ScValidationDlg *pValidationDlg = GetValidationDlg() )
97*cdf0e10cSrcweir 			if( m_pRefEdit )
98*cdf0e10cSrcweir 				pValidationDlg/*->GetRefHandler()*/->RefInputStart( m_pRefEdit );
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	if ( m_pRefEdit )
101*cdf0e10cSrcweir 	{
102*cdf0e10cSrcweir 		String	aStr;
103*cdf0e10cSrcweir 		rRange.Format( aStr, SCR_ABS_3D, pDoc );
104*cdf0e10cSrcweir 		m_pRefEdit->SetRefString( aStr );
105*cdf0e10cSrcweir 		//m_pRefEdit->SetRefString( rRange.aStart != rRange.aEnd ? aStr : String::CreateFromAscii("=").Append( aStr ) );
106*cdf0e10cSrcweir 	}
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir void ScTPValidationValue:: SetActiveHdl()
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir 	if ( m_pRefEdit ) m_pRefEdit->GrabFocus();
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	if ( ScValidationDlg *pValidationDlg = GetValidationDlg() )
114*cdf0e10cSrcweir 		if( m_pRefEdit )
115*cdf0e10cSrcweir 		{
116*cdf0e10cSrcweir 			pValidationDlg/*->GetRefHandler()*/->RefInputDone();
117*cdf0e10cSrcweir 		}
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir void			ScTPValidationValue::RefInputStartPreHdl( ScRefEdit* pEdit, ScRefButton* pButton )
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir 	if ( ScValidationDlg *pValidationDlg = GetValidationDlg() )
123*cdf0e10cSrcweir 	{
124*cdf0e10cSrcweir 		if( pEdit == m_pRefEdit )
125*cdf0e10cSrcweir 		{
126*cdf0e10cSrcweir 			if( Window *pPreWnd = pEdit==&maEdMax?&maFtMax:(pEdit==&maEdMin?&maFtMin:NULL) )
127*cdf0e10cSrcweir 			{
128*cdf0e10cSrcweir 				pPreWnd->SetParent( pValidationDlg );
129*cdf0e10cSrcweir 				pPreWnd->Hide();
130*cdf0e10cSrcweir 			}
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 			m_pRefEdit->SetParent( pValidationDlg );
133*cdf0e10cSrcweir 		}
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 		if( pButton == &m_btnRef )m_btnRef.SetParent( pValidationDlg );
136*cdf0e10cSrcweir 	}
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir void			ScTPValidationValue::RefInputDonePreHdl()
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	if( m_pRefEdit && m_pRefEdit->GetParent()!= this )
143*cdf0e10cSrcweir 	{
144*cdf0e10cSrcweir 		if( Window *pPreWnd = m_pRefEdit==&maEdMax?&maFtMax:(m_pRefEdit==&maEdMin?&maFtMin:NULL) )
145*cdf0e10cSrcweir 		{
146*cdf0e10cSrcweir 			pPreWnd->SetParent( this );
147*cdf0e10cSrcweir 			pPreWnd->Show();
148*cdf0e10cSrcweir 		}
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 		m_pRefEdit->SetParent( this );
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 		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
153*cdf0e10cSrcweir //		aExample1.SetParent( m_pRefEdit ); // the aExample1's child order will affect acc key
154*cdf0e10cSrcweir 	}
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	if( m_btnRef.GetParent()!=this ) m_btnRef.SetParent( this );
157*cdf0e10cSrcweir //	if( aExample1.GetParent()!=this ) aExample1.SetParent( this );
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir void			ScTPValidationValue::RefInputDonePostHdl()
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 	if( m_pRefEdit && !m_pRefEdit->HasFocus() )
165*cdf0e10cSrcweir 		m_pRefEdit->GrabFocus();
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir sal_Bool ScValidationDlg::Close()
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir 	if( m_bOwnRefHdlr )
173*cdf0e10cSrcweir 		if( SfxTabPage* pPage = GetTabPage( TP_VALIDATION_VALUES ) )
174*cdf0e10cSrcweir 			static_cast<ScTPValidationValue*>(pPage)->RemoveRefDlg();
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	return ScValidationDlgBase::Close();
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir //-->Added by PengYunQuan for Validity Cell Range Picker
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir ScValidationDlg::~ScValidationDlg()
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir 	//<!--Added by PengYunQuan for Validity Cell Range Picker
183*cdf0e10cSrcweir 	if( m_bOwnRefHdlr )
184*cdf0e10cSrcweir 		RemoveRefDlg( sal_False );
185*cdf0e10cSrcweir 	//-->Added by PengYunQuan for Validity Cell Range Picker
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir // ============================================================================
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir namespace {
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir /** Converts the passed ScValidationMode to the position in the list box. */
194*cdf0e10cSrcweir sal_uInt16 lclGetPosFromValMode( ScValidationMode eValMode )
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir     sal_uInt16 nLbPos = SC_VALIDDLG_ALLOW_ANY;
197*cdf0e10cSrcweir     switch( eValMode )
198*cdf0e10cSrcweir     {
199*cdf0e10cSrcweir         case SC_VALID_ANY:      nLbPos = SC_VALIDDLG_ALLOW_ANY;     break;
200*cdf0e10cSrcweir         case SC_VALID_WHOLE:    nLbPos = SC_VALIDDLG_ALLOW_WHOLE;   break;
201*cdf0e10cSrcweir         case SC_VALID_DECIMAL:  nLbPos = SC_VALIDDLG_ALLOW_DECIMAL; break;
202*cdf0e10cSrcweir         case SC_VALID_DATE:     nLbPos = SC_VALIDDLG_ALLOW_DATE;    break;
203*cdf0e10cSrcweir         case SC_VALID_TIME:     nLbPos = SC_VALIDDLG_ALLOW_TIME;    break;
204*cdf0e10cSrcweir         case SC_VALID_TEXTLEN:  nLbPos = SC_VALIDDLG_ALLOW_TEXTLEN; break;
205*cdf0e10cSrcweir         case SC_VALID_LIST:     nLbPos = SC_VALIDDLG_ALLOW_RANGE;   break;
206*cdf0e10cSrcweir         case SC_VALID_CUSTOM:   nLbPos = SC_VALIDDLG_ALLOW_ANY;     break;  // not supported
207*cdf0e10cSrcweir         default:    DBG_ERRORFILE( "lclGetPosFromValMode - unknown validity mode" );
208*cdf0e10cSrcweir     }
209*cdf0e10cSrcweir     return nLbPos;
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir /** Converts the passed list box position to an ScValidationMode. */
213*cdf0e10cSrcweir ScValidationMode lclGetValModeFromPos( sal_uInt16 nLbPos )
214*cdf0e10cSrcweir {
215*cdf0e10cSrcweir     ScValidationMode eValMode = SC_VALID_ANY;
216*cdf0e10cSrcweir     switch( nLbPos )
217*cdf0e10cSrcweir     {
218*cdf0e10cSrcweir         case SC_VALIDDLG_ALLOW_ANY:     eValMode = SC_VALID_ANY;        break;
219*cdf0e10cSrcweir         case SC_VALIDDLG_ALLOW_WHOLE:   eValMode = SC_VALID_WHOLE;      break;
220*cdf0e10cSrcweir         case SC_VALIDDLG_ALLOW_DECIMAL: eValMode = SC_VALID_DECIMAL;    break;
221*cdf0e10cSrcweir         case SC_VALIDDLG_ALLOW_DATE:    eValMode = SC_VALID_DATE;       break;
222*cdf0e10cSrcweir         case SC_VALIDDLG_ALLOW_TIME:    eValMode = SC_VALID_TIME;       break;
223*cdf0e10cSrcweir         case SC_VALIDDLG_ALLOW_RANGE:   eValMode = SC_VALID_LIST;       break;
224*cdf0e10cSrcweir         case SC_VALIDDLG_ALLOW_LIST:    eValMode = SC_VALID_LIST;       break;
225*cdf0e10cSrcweir         case SC_VALIDDLG_ALLOW_TEXTLEN: eValMode = SC_VALID_TEXTLEN;    break;
226*cdf0e10cSrcweir         default:    DBG_ERRORFILE( "lclGetValModeFromPos - invalid list box position" );
227*cdf0e10cSrcweir     }
228*cdf0e10cSrcweir     return eValMode;
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir /** Converts the passed ScConditionMode to the position in the list box. */
232*cdf0e10cSrcweir sal_uInt16 lclGetPosFromCondMode( ScConditionMode eCondMode )
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir     sal_uInt16 nLbPos = SC_VALIDDLG_DATA_EQUAL;
235*cdf0e10cSrcweir     switch( eCondMode )
236*cdf0e10cSrcweir     {
237*cdf0e10cSrcweir         case SC_COND_NONE:          // #111771# may occur in old XML files after Excel import
238*cdf0e10cSrcweir         case SC_COND_EQUAL:         nLbPos = SC_VALIDDLG_DATA_EQUAL;        break;
239*cdf0e10cSrcweir         case SC_COND_LESS:          nLbPos = SC_VALIDDLG_DATA_LESS;         break;
240*cdf0e10cSrcweir         case SC_COND_GREATER:       nLbPos = SC_VALIDDLG_DATA_GREATER;      break;
241*cdf0e10cSrcweir         case SC_COND_EQLESS:        nLbPos = SC_VALIDDLG_DATA_EQLESS;       break;
242*cdf0e10cSrcweir         case SC_COND_EQGREATER:     nLbPos = SC_VALIDDLG_DATA_EQGREATER;    break;
243*cdf0e10cSrcweir         case SC_COND_NOTEQUAL:      nLbPos = SC_VALIDDLG_DATA_NOTEQUAL;     break;
244*cdf0e10cSrcweir         case SC_COND_BETWEEN:       nLbPos = SC_VALIDDLG_DATA_BETWEEN;      break;
245*cdf0e10cSrcweir         case SC_COND_NOTBETWEEN:    nLbPos = SC_VALIDDLG_DATA_NOTBETWEEN;   break;
246*cdf0e10cSrcweir         default:    DBG_ERRORFILE( "lclGetPosFromCondMode - unknown condition mode" );
247*cdf0e10cSrcweir     }
248*cdf0e10cSrcweir     return nLbPos;
249*cdf0e10cSrcweir }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir /** Converts the passed list box position to an ScConditionMode. */
252*cdf0e10cSrcweir ScConditionMode lclGetCondModeFromPos( sal_uInt16 nLbPos )
253*cdf0e10cSrcweir {
254*cdf0e10cSrcweir     ScConditionMode eCondMode = SC_COND_EQUAL;
255*cdf0e10cSrcweir     switch( nLbPos )
256*cdf0e10cSrcweir     {
257*cdf0e10cSrcweir         case SC_VALIDDLG_DATA_EQUAL:        eCondMode = SC_COND_EQUAL;      break;
258*cdf0e10cSrcweir         case SC_VALIDDLG_DATA_LESS:         eCondMode = SC_COND_LESS;       break;
259*cdf0e10cSrcweir         case SC_VALIDDLG_DATA_GREATER:      eCondMode = SC_COND_GREATER;    break;
260*cdf0e10cSrcweir         case SC_VALIDDLG_DATA_EQLESS:       eCondMode = SC_COND_EQLESS;     break;
261*cdf0e10cSrcweir         case SC_VALIDDLG_DATA_EQGREATER:    eCondMode = SC_COND_EQGREATER;  break;
262*cdf0e10cSrcweir         case SC_VALIDDLG_DATA_NOTEQUAL:     eCondMode = SC_COND_NOTEQUAL;   break;
263*cdf0e10cSrcweir         case SC_VALIDDLG_DATA_BETWEEN:      eCondMode = SC_COND_BETWEEN;    break;
264*cdf0e10cSrcweir         case SC_VALIDDLG_DATA_NOTBETWEEN:   eCondMode = SC_COND_NOTBETWEEN; break;
265*cdf0e10cSrcweir         default:    DBG_ERRORFILE( "lclGetCondModeFromPos - invalid list box position" );
266*cdf0e10cSrcweir     }
267*cdf0e10cSrcweir     return eCondMode;
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir /** Converts line feed separated string to a formula with strings separated by semicolons.
271*cdf0e10cSrcweir     @descr  Keeps all empty strings.
272*cdf0e10cSrcweir     Example: abc\ndef\n\nghi -> "abc";"def";"";"ghi".
273*cdf0e10cSrcweir     @param rFmlaStr  (out-param) The converted formula string. */
274*cdf0e10cSrcweir void lclGetFormulaFromStringList( String& rFmlaStr, const String& rStringList, sal_Unicode cFmlaSep )
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     rFmlaStr.Erase();
277*cdf0e10cSrcweir     xub_StrLen nTokenCnt = rStringList.GetTokenCount( '\n' );
278*cdf0e10cSrcweir     for( xub_StrLen nToken = 0, nStringIx = 0; nToken < nTokenCnt; ++nToken )
279*cdf0e10cSrcweir     {
280*cdf0e10cSrcweir         String aToken( rStringList.GetToken( 0, '\n', nStringIx ) );
281*cdf0e10cSrcweir         ScGlobal::AddQuotes( aToken, '"' );
282*cdf0e10cSrcweir         ScGlobal::AddToken( rFmlaStr, aToken, cFmlaSep );
283*cdf0e10cSrcweir     }
284*cdf0e10cSrcweir     if( !rFmlaStr.Len() )
285*cdf0e10cSrcweir         rFmlaStr.AssignAscii( "\"\"" );
286*cdf0e10cSrcweir }
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir /** Converts formula with strings separated by semicolons to line feed separated string.
290*cdf0e10cSrcweir     @descr  Keeps all empty strings. Ignores all empty tokens (multiple semicolons).
291*cdf0e10cSrcweir     Example: "abc";;;"def";"";"ghi" -> abc\ndef\n\nghi.
292*cdf0e10cSrcweir     @param rStringList  (out-param) The converted line feed separated string list.
293*cdf0e10cSrcweir     @return  true = Conversion successful. */
294*cdf0e10cSrcweir bool lclGetStringListFromFormula( String& rStringList, const String& rFmlaStr, sal_Unicode cFmlaSep )
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir     String aQuotes( RTL_CONSTASCII_USTRINGPARAM( "\"\"" ) );
297*cdf0e10cSrcweir     xub_StrLen nTokenCnt = rFmlaStr.GetQuotedTokenCount( aQuotes, cFmlaSep );
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     rStringList.Erase();
300*cdf0e10cSrcweir     bool bIsStringList = (nTokenCnt > 0);
301*cdf0e10cSrcweir     bool bTokenAdded = false;
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir     for( xub_StrLen nToken = 0, nStringIx = 0; bIsStringList && (nToken < nTokenCnt); ++nToken )
304*cdf0e10cSrcweir     {
305*cdf0e10cSrcweir         String aToken( rFmlaStr.GetQuotedToken( 0, aQuotes, cFmlaSep, nStringIx ) );
306*cdf0e10cSrcweir         aToken.EraseLeadingAndTrailingChars();
307*cdf0e10cSrcweir         if( aToken.Len() )      // ignore empty tokens, i.e. "a";;"b"
308*cdf0e10cSrcweir         {
309*cdf0e10cSrcweir             bIsStringList = ScGlobal::IsQuoted( aToken, '"' );
310*cdf0e10cSrcweir             if( bIsStringList )
311*cdf0e10cSrcweir             {
312*cdf0e10cSrcweir                 ScGlobal::EraseQuotes( aToken, '"' );
313*cdf0e10cSrcweir                 ScGlobal::AddToken( rStringList, aToken, '\n', 1, bTokenAdded );
314*cdf0e10cSrcweir                 bTokenAdded = true;
315*cdf0e10cSrcweir             }
316*cdf0e10cSrcweir         }
317*cdf0e10cSrcweir     }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir     return bIsStringList;
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir } // namespace
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir // ----------------------------------------------------------------------------
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir ScTPValidationValue::ScTPValidationValue( Window* pParent, const SfxItemSet& rArgSet ) :
327*cdf0e10cSrcweir     SfxTabPage( pParent, ScResId( TP_VALIDATION_VALUES ), rArgSet ),
328*cdf0e10cSrcweir     maFtAllow ( this, ScResId( FT_ALLOW ) ),
329*cdf0e10cSrcweir     maLbAllow ( this, ScResId( LB_ALLOW ) ),
330*cdf0e10cSrcweir     maCbAllow ( this, ScResId( TSB_ALLOW_BLANKS ) ),
331*cdf0e10cSrcweir     maCbShow  ( this, ScResId( CB_SHOWLIST ) ),
332*cdf0e10cSrcweir     maCbSort  ( this, ScResId( CB_SORTLIST ) ),
333*cdf0e10cSrcweir     maFtValue ( this, ScResId( FT_VALUE ) ),
334*cdf0e10cSrcweir     maLbValue ( this, ScResId( LB_VALUE ) ),
335*cdf0e10cSrcweir     maFtMin   ( this, ScResId( FT_MIN ) ),
336*cdf0e10cSrcweir     maEdMin   ( this, ScResId( EDT_MIN ) ),
337*cdf0e10cSrcweir     maEdList  ( this, ScResId( EDT_LIST ) ),
338*cdf0e10cSrcweir     maFtMax   ( this, ScResId( FT_MAX ) ),
339*cdf0e10cSrcweir     maEdMax   ( this, ScResId( EDT_MAX ) ),
340*cdf0e10cSrcweir     maFtHint  ( this, ScResId( FT_SOURCEHINT ) ),
341*cdf0e10cSrcweir     maStrMin  ( ScResId( SCSTR_VALID_MINIMUM ) ),
342*cdf0e10cSrcweir     maStrMax  ( ScResId( SCSTR_VALID_MAXIMUM ) ),
343*cdf0e10cSrcweir     maStrValue( ScResId( SCSTR_VALID_VALUE ) ),
344*cdf0e10cSrcweir     maStrRange( ScResId( SCSTR_VALID_RANGE ) ),
345*cdf0e10cSrcweir     maStrList ( ScResId( SCSTR_VALID_LIST ) ),
346*cdf0e10cSrcweir //<!--Added by PengYunQuan for Validity Cell Range Picker
347*cdf0e10cSrcweir 		m_btnRef( this, ScResId( RB_VALIDITY_REF ) )
348*cdf0e10cSrcweir //-->Added by PengYunQuan for Validity Cell Range Picker
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir 	Init();
351*cdf0e10cSrcweir 	FreeResource();
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir     // list separator in formulas
354*cdf0e10cSrcweir     //CHINA001 const String& rListSep = ScCompiler::pSymbolTableNative[ ocSep ];
355*cdf0e10cSrcweir 	String aListSep = ::GetScCompilerNativeSymbol( ocSep ); //CHINA001
356*cdf0e10cSrcweir     DBG_ASSERT( aListSep.Len() == 1, "ScTPValidationValue::ScTPValidationValue - list separator error" );
357*cdf0e10cSrcweir     mcFmlaSep = aListSep.Len() ? aListSep.GetChar( 0 ) : ';';
358*cdf0e10cSrcweir 	//<!--Added by PengYunQuan for Validity Cell Range Picker
359*cdf0e10cSrcweir 	m_btnRef.Hide();
360*cdf0e10cSrcweir 	//-->Added by PengYunQuan for Validity Cell Range Picker
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir ScTPValidationValue::~ScTPValidationValue()
364*cdf0e10cSrcweir {
365*cdf0e10cSrcweir }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir void ScTPValidationValue::Init()
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir     maLbAllow.SetSelectHdl( LINK( this, ScTPValidationValue, SelectHdl ) );
370*cdf0e10cSrcweir     maLbValue.SetSelectHdl( LINK( this, ScTPValidationValue, SelectHdl ) );
371*cdf0e10cSrcweir     maCbShow.SetClickHdl( LINK( this, ScTPValidationValue, CheckHdl ) );
372*cdf0e10cSrcweir 	//<!--Added by PengYunQuan for Validity Cell Range Picker
373*cdf0e10cSrcweir 	maEdMin.SetGetFocusHdl( LINK( this, ScTPValidationValue, EditSetFocusHdl ) );
374*cdf0e10cSrcweir 	maEdMin.SetLoseFocusHdl( LINK( this, ScTPValidationValue, KillFocusHdl ) );
375*cdf0e10cSrcweir 	maEdMax.SetGetFocusHdl( LINK( this, ScTPValidationValue, EditSetFocusHdl ) );
376*cdf0e10cSrcweir 	m_btnRef.SetLoseFocusHdl( LINK( this, ScTPValidationValue, KillFocusHdl ) );
377*cdf0e10cSrcweir 	maEdMax.SetLoseFocusHdl( LINK( this, ScTPValidationValue, KillFocusHdl ) );
378*cdf0e10cSrcweir 	//-->Added by PengYunQuan for Validity Cell Range Picker
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir     maLbAllow.SelectEntryPos( SC_VALIDDLG_ALLOW_ANY );
381*cdf0e10cSrcweir     maLbValue.SelectEntryPos( SC_VALIDDLG_DATA_EQUAL );
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir     SelectHdl( NULL );
384*cdf0e10cSrcweir     CheckHdl( NULL );
385*cdf0e10cSrcweir }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir SfxTabPage* ScTPValidationValue::Create( Window* pParent, const SfxItemSet& rArgSet )
388*cdf0e10cSrcweir {
389*cdf0e10cSrcweir     return( new ScTPValidationValue( pParent, rArgSet ) );
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir sal_uInt16* ScTPValidationValue::GetRanges()
393*cdf0e10cSrcweir {
394*cdf0e10cSrcweir     return pValueRanges;
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir void ScTPValidationValue::Reset( const SfxItemSet& rArgSet )
398*cdf0e10cSrcweir {
399*cdf0e10cSrcweir 	const SfxPoolItem* pItem;
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir     sal_uInt16 nLbPos = SC_VALIDDLG_ALLOW_ANY;
402*cdf0e10cSrcweir     if( rArgSet.GetItemState( FID_VALID_MODE, sal_True, &pItem ) == SFX_ITEM_SET )
403*cdf0e10cSrcweir         nLbPos = lclGetPosFromValMode( static_cast< ScValidationMode >(
404*cdf0e10cSrcweir             static_cast< const SfxAllEnumItem* >( pItem )->GetValue() ) );
405*cdf0e10cSrcweir     maLbAllow.SelectEntryPos( nLbPos );
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir     nLbPos = SC_VALIDDLG_DATA_EQUAL;
408*cdf0e10cSrcweir     if( rArgSet.GetItemState( FID_VALID_CONDMODE, sal_True, &pItem ) == SFX_ITEM_SET )
409*cdf0e10cSrcweir         nLbPos = lclGetPosFromCondMode( static_cast< ScConditionMode >(
410*cdf0e10cSrcweir             static_cast< const SfxAllEnumItem* >( pItem )->GetValue() ) );
411*cdf0e10cSrcweir     maLbValue.SelectEntryPos( nLbPos );
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir     // *** check boxes ***
414*cdf0e10cSrcweir     sal_Bool bCheck = sal_True;
415*cdf0e10cSrcweir     if( rArgSet.GetItemState( FID_VALID_BLANK, sal_True, &pItem ) == SFX_ITEM_SET )
416*cdf0e10cSrcweir         bCheck = static_cast< const SfxBoolItem* >( pItem )->GetValue();
417*cdf0e10cSrcweir     maCbAllow.Check( bCheck );
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir     sal_Int32 nListType = ValidListType::UNSORTED;
420*cdf0e10cSrcweir     if( rArgSet.GetItemState( FID_VALID_LISTTYPE, sal_True, &pItem ) == SFX_ITEM_SET )
421*cdf0e10cSrcweir         nListType = static_cast< const SfxInt16Item* >( pItem )->GetValue();
422*cdf0e10cSrcweir     maCbShow.Check( nListType != ValidListType::INVISIBLE );
423*cdf0e10cSrcweir     maCbSort.Check( nListType == ValidListType::SORTEDASCENDING );
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir     // *** formulas ***
426*cdf0e10cSrcweir     String aFmlaStr;
427*cdf0e10cSrcweir 	if ( rArgSet.GetItemState( FID_VALID_VALUE1, sal_True, &pItem ) == SFX_ITEM_SET )
428*cdf0e10cSrcweir         aFmlaStr = static_cast< const SfxStringItem* >( pItem )->GetValue();
429*cdf0e10cSrcweir     SetFirstFormula( aFmlaStr );
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir     aFmlaStr.Erase();
432*cdf0e10cSrcweir 	if ( rArgSet.GetItemState( FID_VALID_VALUE2, sal_True, &pItem ) == SFX_ITEM_SET )
433*cdf0e10cSrcweir         aFmlaStr = static_cast< const SfxStringItem* >( pItem )->GetValue();
434*cdf0e10cSrcweir     SetSecondFormula( aFmlaStr );
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir     SelectHdl( NULL );
437*cdf0e10cSrcweir     CheckHdl( NULL );
438*cdf0e10cSrcweir }
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir sal_Bool ScTPValidationValue::FillItemSet( SfxItemSet& rArgSet )
441*cdf0e10cSrcweir {
442*cdf0e10cSrcweir     sal_Int16 nListType = maCbShow.IsChecked() ?
443*cdf0e10cSrcweir         (maCbSort.IsChecked() ? ValidListType::SORTEDASCENDING : ValidListType::UNSORTED) :
444*cdf0e10cSrcweir         ValidListType::INVISIBLE;
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir     rArgSet.Put( SfxAllEnumItem( FID_VALID_MODE, sal::static_int_cast<sal_uInt16>(
447*cdf0e10cSrcweir                     lclGetValModeFromPos( maLbAllow.GetSelectEntryPos() ) ) ) );
448*cdf0e10cSrcweir     rArgSet.Put( SfxAllEnumItem( FID_VALID_CONDMODE, sal::static_int_cast<sal_uInt16>(
449*cdf0e10cSrcweir                     lclGetCondModeFromPos( maLbValue.GetSelectEntryPos() ) ) ) );
450*cdf0e10cSrcweir     rArgSet.Put( SfxStringItem( FID_VALID_VALUE1, GetFirstFormula() ) );
451*cdf0e10cSrcweir     rArgSet.Put( SfxStringItem( FID_VALID_VALUE2, GetSecondFormula() ) );
452*cdf0e10cSrcweir     rArgSet.Put( SfxBoolItem( FID_VALID_BLANK, maCbAllow.IsChecked() ) );
453*cdf0e10cSrcweir     rArgSet.Put( SfxInt16Item( FID_VALID_LISTTYPE, nListType ) );
454*cdf0e10cSrcweir 	return sal_True;
455*cdf0e10cSrcweir }
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir String ScTPValidationValue::GetFirstFormula() const
458*cdf0e10cSrcweir {
459*cdf0e10cSrcweir     String aFmlaStr;
460*cdf0e10cSrcweir     if( maLbAllow.GetSelectEntryPos() == SC_VALIDDLG_ALLOW_LIST )
461*cdf0e10cSrcweir         lclGetFormulaFromStringList( aFmlaStr, maEdList.GetText(), mcFmlaSep );
462*cdf0e10cSrcweir     else
463*cdf0e10cSrcweir         aFmlaStr = maEdMin.GetText();
464*cdf0e10cSrcweir     return aFmlaStr;
465*cdf0e10cSrcweir }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir String ScTPValidationValue::GetSecondFormula() const
468*cdf0e10cSrcweir {
469*cdf0e10cSrcweir     return maEdMax.GetText();
470*cdf0e10cSrcweir }
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir void ScTPValidationValue::SetFirstFormula( const String& rFmlaStr )
473*cdf0e10cSrcweir {
474*cdf0e10cSrcweir     // try if formula is a string list, validation mode must already be set
475*cdf0e10cSrcweir     String aStringList;
476*cdf0e10cSrcweir     if( (maLbAllow.GetSelectEntryPos() == SC_VALIDDLG_ALLOW_RANGE) &&
477*cdf0e10cSrcweir         lclGetStringListFromFormula( aStringList, rFmlaStr, mcFmlaSep ) )
478*cdf0e10cSrcweir     {
479*cdf0e10cSrcweir         maEdList.SetText( aStringList );
480*cdf0e10cSrcweir         maEdMin.SetText( EMPTY_STRING );
481*cdf0e10cSrcweir         // change validation mode to string list
482*cdf0e10cSrcweir         maLbAllow.SelectEntryPos( SC_VALIDDLG_ALLOW_LIST );
483*cdf0e10cSrcweir     }
484*cdf0e10cSrcweir     else
485*cdf0e10cSrcweir     {
486*cdf0e10cSrcweir         maEdMin.SetText( rFmlaStr );
487*cdf0e10cSrcweir         maEdList.SetText( EMPTY_STRING );
488*cdf0e10cSrcweir     }
489*cdf0e10cSrcweir }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir void ScTPValidationValue::SetSecondFormula( const String& rFmlaStr )
492*cdf0e10cSrcweir {
493*cdf0e10cSrcweir     maEdMax.SetText( rFmlaStr );
494*cdf0e10cSrcweir }
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir //<!--Added by PengYunQuan for Validity Cell Range Picker
497*cdf0e10cSrcweir ScValidationDlg * ScTPValidationValue::GetValidationDlg()
498*cdf0e10cSrcweir {
499*cdf0e10cSrcweir 	if( Window *pParent = GetParent() )
500*cdf0e10cSrcweir 		do{
501*cdf0e10cSrcweir 			if ( dynamic_cast<ScValidationDlg*>( pParent ) )
502*cdf0e10cSrcweir 				return static_cast<	ScValidationDlg * >( pParent );
503*cdf0e10cSrcweir 		}while ( NULL != ( pParent = pParent->GetParent() ) );
504*cdf0e10cSrcweir 	return NULL;
505*cdf0e10cSrcweir }
506*cdf0e10cSrcweir void ScTPValidationValue::SetupRefDlg()
507*cdf0e10cSrcweir {
508*cdf0e10cSrcweir 	if( ScValidationDlg *pValidationDlg = GetValidationDlg() )
509*cdf0e10cSrcweir 		if( pValidationDlg->SetupRefDlg() )
510*cdf0e10cSrcweir 		{
511*cdf0e10cSrcweir 			pValidationDlg->SetHandler( this );
512*cdf0e10cSrcweir 			pValidationDlg->SetSetRefHdl( (ScRefHandlerHelper::PFUNCSETREFHDLTYPE)( &ScTPValidationValue::SetReferenceHdl ) );
513*cdf0e10cSrcweir 			pValidationDlg->SetSetActHdl( (ScRefHandlerHelper::PCOMMONHDLTYPE)( &ScTPValidationValue::SetActiveHdl ) );
514*cdf0e10cSrcweir 			pValidationDlg->SetRefInputStartPreHdl( (ScRefHandlerHelper::PINPUTSTARTDLTYPE)( &ScTPValidationValue::RefInputStartPreHdl ) );
515*cdf0e10cSrcweir 			pValidationDlg->SetRefInputDonePreHdl( (ScRefHandlerHelper::PCOMMONHDLTYPE)( &ScTPValidationValue::RefInputDonePreHdl ) );
516*cdf0e10cSrcweir 			pValidationDlg->SetRefInputDonePostHdl( (ScRefHandlerHelper::PCOMMONHDLTYPE)( &ScTPValidationValue::RefInputDonePostHdl ) );
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir 			if ( maEdMax.IsVisible() ) { m_pRefEdit = &maEdMax; }
519*cdf0e10cSrcweir 			else if ( maEdMin.IsVisible() ) {  m_pRefEdit = &maEdMin; }
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir 			if( m_pRefEdit && !m_pRefEdit->HasFocus() ) m_pRefEdit->GrabFocus();
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir 			if( m_pRefEdit ) m_pRefEdit->SetRefDialog( pValidationDlg );
524*cdf0e10cSrcweir 			m_btnRef.SetReferences( pValidationDlg, m_pRefEdit );
525*cdf0e10cSrcweir 		}
526*cdf0e10cSrcweir }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir void ScTPValidationValue::RemoveRefDlg()
529*cdf0e10cSrcweir {
530*cdf0e10cSrcweir 	if( ScValidationDlg *pValidationDlg = GetValidationDlg() )
531*cdf0e10cSrcweir 		if( pValidationDlg->RemoveRefDlg() )
532*cdf0e10cSrcweir 		{
533*cdf0e10cSrcweir 			pValidationDlg->SetHandler( NULL );
534*cdf0e10cSrcweir 			pValidationDlg->SetSetRefHdl( NULL );
535*cdf0e10cSrcweir 			pValidationDlg->SetSetActHdl( NULL );
536*cdf0e10cSrcweir 			pValidationDlg->SetRefInputStartPreHdl( NULL );
537*cdf0e10cSrcweir 			pValidationDlg->SetRefInputDonePreHdl( NULL );
538*cdf0e10cSrcweir 			pValidationDlg->SetRefInputDonePostHdl( NULL );
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir 			if( m_pRefEdit ) m_pRefEdit->SetRefDialog( NULL );
541*cdf0e10cSrcweir 			m_pRefEdit = NULL;
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir 			m_btnRef.SetReferences( NULL, NULL );
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir #if ! defined( WNT ) && !defined( _MSC_VER )
546*cdf0e10cSrcweir 			TidyListBoxes();
547*cdf0e10cSrcweir #endif
548*cdf0e10cSrcweir 		}
549*cdf0e10cSrcweir }
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir void ScTPValidationValue::TidyListBoxes()
552*cdf0e10cSrcweir {
553*cdf0e10cSrcweir 	if ( Window *pWnd = GetChild( 0 ) )
554*cdf0e10cSrcweir 	{
555*cdf0e10cSrcweir 		bool bFindLst = false;
556*cdf0e10cSrcweir 		std::list<Window*> alstOrder;
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir 		do{
559*cdf0e10cSrcweir 			if( pWnd->GetParent() == this )
560*cdf0e10cSrcweir 			{
561*cdf0e10cSrcweir 				if ( !bFindLst )
562*cdf0e10cSrcweir 				{
563*cdf0e10cSrcweir 					try{
564*cdf0e10cSrcweir 						if( dynamic_cast<ListBox*>(pWnd)||dynamic_cast<ListBox*>(pWnd->GetWindow(WINDOW_CLIENT) ) )
565*cdf0e10cSrcweir 							bFindLst = true;
566*cdf0e10cSrcweir 					}
567*cdf0e10cSrcweir 					catch( ... )
568*cdf0e10cSrcweir 					{
569*cdf0e10cSrcweir 						if ( *(void**)pWnd == *(void**)&maLbValue )
570*cdf0e10cSrcweir 							bFindLst = true;
571*cdf0e10cSrcweir 						else if ( Window *pClient = pWnd->GetWindow( WINDOW_CLIENT ) )
572*cdf0e10cSrcweir 							if ( *(void**)pClient == *(void**)&maLbValue )
573*cdf0e10cSrcweir 								bFindLst = true;
574*cdf0e10cSrcweir 					}
575*cdf0e10cSrcweir 				}
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir 				if ( bFindLst )
578*cdf0e10cSrcweir 					alstOrder.push_back( pWnd->GetWindow( WINDOW_CLIENT ) );
579*cdf0e10cSrcweir 			}
580*cdf0e10cSrcweir 		}while( NULL != ( pWnd = pWnd->GetWindow( WINDOW_NEXT  ) ) );
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir 		pWnd = GetChild(0);
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 		while( std::find( alstOrder.begin(), alstOrder.end(), pWnd ) != alstOrder.end() && NULL != ( pWnd = pWnd->GetWindow( WINDOW_NEXT) ) ) ;
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir 		if ( pWnd )
587*cdf0e10cSrcweir 		{
588*cdf0e10cSrcweir 			for ( std::list<Window*>::iterator i = alstOrder.begin(); i!=alstOrder.end(); i++ )
589*cdf0e10cSrcweir 			{
590*cdf0e10cSrcweir 				Window *pParent = (*i)->GetParent();
591*cdf0e10cSrcweir 				(*i)->SetParent( pWnd );
592*cdf0e10cSrcweir 				(*i)->SetParent( pParent );
593*cdf0e10cSrcweir 			}
594*cdf0e10cSrcweir 		}
595*cdf0e10cSrcweir 	}
596*cdf0e10cSrcweir }
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir IMPL_LINK( ScTPValidationValue, EditSetFocusHdl, Edit *, /*pEdit*/ )
599*cdf0e10cSrcweir {
600*cdf0e10cSrcweir 	sal_uInt16  nPos=maLbAllow.GetSelectEntryPos();
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir 	if ( nPos == SC_VALIDDLG_ALLOW_RANGE )
603*cdf0e10cSrcweir 	{
604*cdf0e10cSrcweir 		SetupRefDlg();
605*cdf0e10cSrcweir 	}
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir 	return 0;
608*cdf0e10cSrcweir }
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir IMPL_LINK( ScTPValidationValue, KillFocusHdl, Window *, pWnd )
611*cdf0e10cSrcweir {
612*cdf0e10cSrcweir 	if(	pWnd == m_pRefEdit || pWnd == &m_btnRef )
613*cdf0e10cSrcweir 		if( ScValidationDlg *pValidationDlg = GetValidationDlg() )
614*cdf0e10cSrcweir 			if ( (pValidationDlg->IsActive() || pValidationDlg->IsChildFocus() ) && !pValidationDlg->IsRefInputting() )
615*cdf0e10cSrcweir 				if( ( !m_pRefEdit || !m_pRefEdit->HasFocus()) && !m_btnRef.HasFocus() )
616*cdf0e10cSrcweir 				{
617*cdf0e10cSrcweir 					RemoveRefDlg();
618*cdf0e10cSrcweir 				}
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir 	return 0;
621*cdf0e10cSrcweir }
622*cdf0e10cSrcweir //-->Added by PengYunQuan for Validity Cell Range Picker
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir // ----------------------------------------------------------------------------
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir IMPL_LINK( ScTPValidationValue, SelectHdl, ListBox*, EMPTYARG )
627*cdf0e10cSrcweir {
628*cdf0e10cSrcweir     sal_uInt16 nLbPos = maLbAllow.GetSelectEntryPos();
629*cdf0e10cSrcweir     bool bEnable = (nLbPos != SC_VALIDDLG_ALLOW_ANY);
630*cdf0e10cSrcweir     bool bRange = (nLbPos == SC_VALIDDLG_ALLOW_RANGE);
631*cdf0e10cSrcweir     bool bList = (nLbPos == SC_VALIDDLG_ALLOW_LIST);
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir     maCbAllow.Enable( bEnable );   // Leerzellen
634*cdf0e10cSrcweir     maFtValue.Enable( bEnable );
635*cdf0e10cSrcweir     maLbValue.Enable( bEnable );
636*cdf0e10cSrcweir     maFtMin.Enable( bEnable );
637*cdf0e10cSrcweir     maEdMin.Enable( bEnable );
638*cdf0e10cSrcweir     maEdList.Enable( bEnable );
639*cdf0e10cSrcweir     maFtMax.Enable( bEnable );
640*cdf0e10cSrcweir     maEdMax.Enable( bEnable );
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir     bool bShowMax = false;
643*cdf0e10cSrcweir     if( bRange )
644*cdf0e10cSrcweir         maFtMin.SetText( maStrRange );
645*cdf0e10cSrcweir     else if( bList )
646*cdf0e10cSrcweir         maFtMin.SetText( maStrList );
647*cdf0e10cSrcweir     else
648*cdf0e10cSrcweir     {
649*cdf0e10cSrcweir         switch( maLbValue.GetSelectEntryPos() )
650*cdf0e10cSrcweir         {
651*cdf0e10cSrcweir             case SC_VALIDDLG_DATA_EQUAL:
652*cdf0e10cSrcweir             case SC_VALIDDLG_DATA_NOTEQUAL:     maFtMin.SetText( maStrValue );  break;
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir             case SC_VALIDDLG_DATA_LESS:
655*cdf0e10cSrcweir             case SC_VALIDDLG_DATA_EQLESS:       maFtMin.SetText( maStrMax );    break;
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir             case SC_VALIDDLG_DATA_BETWEEN:
658*cdf0e10cSrcweir             case SC_VALIDDLG_DATA_NOTBETWEEN:   bShowMax = true;    // fall through
659*cdf0e10cSrcweir             case SC_VALIDDLG_DATA_GREATER:
660*cdf0e10cSrcweir             case SC_VALIDDLG_DATA_EQGREATER:    maFtMin.SetText( maStrMin );    break;
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir             default:
663*cdf0e10cSrcweir                 DBG_ERRORFILE( "ScTPValidationValue::SelectHdl - unknown condition mode" );
664*cdf0e10cSrcweir         }
665*cdf0e10cSrcweir     }
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir     maCbShow.Show( bRange || bList );
668*cdf0e10cSrcweir     maCbSort.Show( bRange || bList );
669*cdf0e10cSrcweir     maFtValue.Show( !bRange && !bList );
670*cdf0e10cSrcweir     maLbValue.Show( !bRange && !bList );
671*cdf0e10cSrcweir     maEdMin.Show( !bList );
672*cdf0e10cSrcweir     maEdList.Show( bList );
673*cdf0e10cSrcweir     maFtMax.Show( bShowMax );
674*cdf0e10cSrcweir     maEdMax.Show( bShowMax );
675*cdf0e10cSrcweir     maFtHint.Show( bRange );
676*cdf0e10cSrcweir 	//<!--Added by PengYunQuan for Validity Cell Range Picker
677*cdf0e10cSrcweir 	m_btnRef.Show( bRange );
678*cdf0e10cSrcweir 	//-->Added by PengYunQuan for Validity Cell Range Picker
679*cdf0e10cSrcweir     return 0;
680*cdf0e10cSrcweir }
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir IMPL_LINK( ScTPValidationValue, CheckHdl, CheckBox*, EMPTYARG )
683*cdf0e10cSrcweir {
684*cdf0e10cSrcweir     maCbSort.Enable( maCbShow.IsChecked() );
685*cdf0e10cSrcweir     return 0;
686*cdf0e10cSrcweir }
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir //========================================================================
690*cdf0e10cSrcweir //========================================================================
691*cdf0e10cSrcweir // Input Help Page
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir ScTPValidationHelp::ScTPValidationHelp( Window*			pParent,
694*cdf0e10cSrcweir 										  const SfxItemSet& rArgSet )
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir 	:	SfxTabPage		( pParent,
697*cdf0e10cSrcweir 						  ScResId( TP_VALIDATION_INPUTHELP ),
698*cdf0e10cSrcweir 						  rArgSet ),
699*cdf0e10cSrcweir 		aTsbHelp		( this, ScResId( TSB_HELP ) ),
700*cdf0e10cSrcweir         aFlContent      ( this, ScResId( FL_CONTENT ) ),
701*cdf0e10cSrcweir 		aFtTitle		( this, ScResId( FT_TITLE ) ),
702*cdf0e10cSrcweir 		aEdtTitle		( this, ScResId( EDT_TITLE ) ),
703*cdf0e10cSrcweir 		aFtInputHelp	( this, ScResId( FT_INPUTHELP ) ),
704*cdf0e10cSrcweir 		aEdInputHelp	( this, ScResId( EDT_INPUTHELP ) ),
705*cdf0e10cSrcweir 
706*cdf0e10cSrcweir         mrArgSet            ( rArgSet )
707*cdf0e10cSrcweir {
708*cdf0e10cSrcweir 	Init();
709*cdf0e10cSrcweir 	FreeResource();
710*cdf0e10cSrcweir }
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir // -----------------------------------------------------------------------
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir __EXPORT ScTPValidationHelp::~ScTPValidationHelp()
715*cdf0e10cSrcweir {
716*cdf0e10cSrcweir }
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir // -----------------------------------------------------------------------
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir void ScTPValidationHelp::Init()
721*cdf0e10cSrcweir {
722*cdf0e10cSrcweir 	//aLb.SetSelectHdl( LINK( this, ScTPValidationHelp, SelectHdl ) );
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir 	aTsbHelp.EnableTriState( sal_False );
725*cdf0e10cSrcweir }
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir //------------------------------------------------------------------------
728*cdf0e10cSrcweir 
729*cdf0e10cSrcweir sal_uInt16* __EXPORT ScTPValidationHelp::GetRanges()
730*cdf0e10cSrcweir {
731*cdf0e10cSrcweir 	return pValueRanges;
732*cdf0e10cSrcweir }
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir // -----------------------------------------------------------------------
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir SfxTabPage* __EXPORT ScTPValidationHelp::Create( Window*	pParent,
737*cdf0e10cSrcweir 										 const SfxItemSet&	rArgSet )
738*cdf0e10cSrcweir {
739*cdf0e10cSrcweir 	return ( new ScTPValidationHelp( pParent, rArgSet ) );
740*cdf0e10cSrcweir }
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir // -----------------------------------------------------------------------
743*cdf0e10cSrcweir 
744*cdf0e10cSrcweir void __EXPORT ScTPValidationHelp::Reset( const SfxItemSet& rArgSet )
745*cdf0e10cSrcweir {
746*cdf0e10cSrcweir 	const SfxPoolItem* pItem;
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir 	if ( rArgSet.GetItemState( FID_VALID_SHOWHELP, sal_True, &pItem ) == SFX_ITEM_SET )
749*cdf0e10cSrcweir 		aTsbHelp.SetState( ((const SfxBoolItem*)pItem)->GetValue() ? STATE_CHECK : STATE_NOCHECK );
750*cdf0e10cSrcweir 	else
751*cdf0e10cSrcweir 		aTsbHelp.SetState( STATE_NOCHECK );
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir 	if ( rArgSet.GetItemState( FID_VALID_HELPTITLE, sal_True, &pItem ) == SFX_ITEM_SET )
754*cdf0e10cSrcweir 		aEdtTitle.SetText( ((const SfxStringItem*)pItem)->GetValue() );
755*cdf0e10cSrcweir 	else
756*cdf0e10cSrcweir 		aEdtTitle.SetText( EMPTY_STRING );
757*cdf0e10cSrcweir 
758*cdf0e10cSrcweir 	if ( rArgSet.GetItemState( FID_VALID_HELPTEXT, sal_True, &pItem ) == SFX_ITEM_SET )
759*cdf0e10cSrcweir 		aEdInputHelp.SetText( ((const SfxStringItem*)pItem)->GetValue() );
760*cdf0e10cSrcweir 	else
761*cdf0e10cSrcweir 		aEdInputHelp.SetText( EMPTY_STRING );
762*cdf0e10cSrcweir }
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir // -----------------------------------------------------------------------
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir sal_Bool __EXPORT ScTPValidationHelp::FillItemSet( SfxItemSet& rArgSet )
767*cdf0e10cSrcweir {
768*cdf0e10cSrcweir 	rArgSet.Put( SfxBoolItem( FID_VALID_SHOWHELP, aTsbHelp.GetState() == STATE_CHECK ) );
769*cdf0e10cSrcweir 	rArgSet.Put( SfxStringItem( FID_VALID_HELPTITLE, aEdtTitle.GetText() ) );
770*cdf0e10cSrcweir 	rArgSet.Put( SfxStringItem( FID_VALID_HELPTEXT, aEdInputHelp.GetText() ) );
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir 	return sal_True;
773*cdf0e10cSrcweir }
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir //========================================================================
776*cdf0e10cSrcweir //========================================================================
777*cdf0e10cSrcweir // Error Alert Page
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir ScTPValidationError::ScTPValidationError( Window*			pParent,
780*cdf0e10cSrcweir 										  const SfxItemSet& rArgSet )
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir 	:	SfxTabPage		( pParent,
783*cdf0e10cSrcweir 						  ScResId( TP_VALIDATION_ERROR ),
784*cdf0e10cSrcweir 						  rArgSet ),
785*cdf0e10cSrcweir 		aTsbShow		( this, ScResId( TSB_SHOW ) ),
786*cdf0e10cSrcweir         aFlContent      ( this, ScResId( FL_CONTENT ) ),
787*cdf0e10cSrcweir 		aFtAction		( this, ScResId( FT_ACTION ) ),
788*cdf0e10cSrcweir 		aLbAction		( this, ScResId( LB_ACTION ) ),
789*cdf0e10cSrcweir 		aBtnSearch		( this, ScResId( BTN_SEARCH ) ),
790*cdf0e10cSrcweir 		aFtTitle		( this, ScResId( FT_TITLE ) ),
791*cdf0e10cSrcweir 		aEdtTitle		( this, ScResId( EDT_TITLE ) ),
792*cdf0e10cSrcweir 		aFtError		( this, ScResId( FT_ERROR ) ),
793*cdf0e10cSrcweir 		aEdError		( this, ScResId( EDT_ERROR ) ),
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir         mrArgSet            ( rArgSet )
796*cdf0e10cSrcweir {
797*cdf0e10cSrcweir 	Init();
798*cdf0e10cSrcweir 	FreeResource();
799*cdf0e10cSrcweir }
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir // -----------------------------------------------------------------------
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir __EXPORT ScTPValidationError::~ScTPValidationError()
804*cdf0e10cSrcweir {
805*cdf0e10cSrcweir }
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir // -----------------------------------------------------------------------
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir void ScTPValidationError::Init()
810*cdf0e10cSrcweir {
811*cdf0e10cSrcweir 	aLbAction.SetSelectHdl( LINK( this, ScTPValidationError, SelectActionHdl ) );
812*cdf0e10cSrcweir 	aBtnSearch.SetClickHdl( LINK( this, ScTPValidationError, ClickSearchHdl ) );
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 	aLbAction.SelectEntryPos( 0 );
815*cdf0e10cSrcweir 	aTsbShow.EnableTriState( sal_False );
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir 	SelectActionHdl( NULL );
818*cdf0e10cSrcweir }
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir //------------------------------------------------------------------------
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir sal_uInt16* __EXPORT ScTPValidationError::GetRanges()
823*cdf0e10cSrcweir {
824*cdf0e10cSrcweir 	return pValueRanges;
825*cdf0e10cSrcweir }
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir // -----------------------------------------------------------------------
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir SfxTabPage* __EXPORT ScTPValidationError::Create( Window*	pParent,
830*cdf0e10cSrcweir 										 const SfxItemSet&	rArgSet )
831*cdf0e10cSrcweir {
832*cdf0e10cSrcweir 	return ( new ScTPValidationError( pParent, rArgSet ) );
833*cdf0e10cSrcweir }
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir // -----------------------------------------------------------------------
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir void __EXPORT ScTPValidationError::Reset( const SfxItemSet& rArgSet )
838*cdf0e10cSrcweir {
839*cdf0e10cSrcweir 	const SfxPoolItem* pItem;
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir 	if ( rArgSet.GetItemState( FID_VALID_SHOWERR, sal_True, &pItem ) == SFX_ITEM_SET )
842*cdf0e10cSrcweir 		aTsbShow.SetState( ((const SfxBoolItem*)pItem)->GetValue() ? STATE_CHECK : STATE_NOCHECK );
843*cdf0e10cSrcweir 	else
844*cdf0e10cSrcweir         aTsbShow.SetState( STATE_CHECK );   // #111720# check by default
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir 	if ( rArgSet.GetItemState( FID_VALID_ERRSTYLE, sal_True, &pItem ) == SFX_ITEM_SET )
847*cdf0e10cSrcweir 		aLbAction.SelectEntryPos( ((const SfxAllEnumItem*)pItem)->GetValue() );
848*cdf0e10cSrcweir 	else
849*cdf0e10cSrcweir 		aLbAction.SelectEntryPos( 0 );
850*cdf0e10cSrcweir 
851*cdf0e10cSrcweir 	if ( rArgSet.GetItemState( FID_VALID_ERRTITLE, sal_True, &pItem ) == SFX_ITEM_SET )
852*cdf0e10cSrcweir 		aEdtTitle.SetText( ((const SfxStringItem*)pItem)->GetValue() );
853*cdf0e10cSrcweir 	else
854*cdf0e10cSrcweir 		aEdtTitle.SetText( EMPTY_STRING );
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir 	if ( rArgSet.GetItemState( FID_VALID_ERRTEXT, sal_True, &pItem ) == SFX_ITEM_SET )
857*cdf0e10cSrcweir 		aEdError.SetText( ((const SfxStringItem*)pItem)->GetValue() );
858*cdf0e10cSrcweir 	else
859*cdf0e10cSrcweir 		aEdError.SetText( EMPTY_STRING );
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir 	SelectActionHdl( NULL );
862*cdf0e10cSrcweir }
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir // -----------------------------------------------------------------------
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir sal_Bool __EXPORT ScTPValidationError::FillItemSet( SfxItemSet& rArgSet )
867*cdf0e10cSrcweir {
868*cdf0e10cSrcweir 	rArgSet.Put( SfxBoolItem( FID_VALID_SHOWERR, aTsbShow.GetState() == STATE_CHECK ) );
869*cdf0e10cSrcweir 	rArgSet.Put( SfxAllEnumItem( FID_VALID_ERRSTYLE, aLbAction.GetSelectEntryPos() ) );
870*cdf0e10cSrcweir 	rArgSet.Put( SfxStringItem( FID_VALID_ERRTITLE, aEdtTitle.GetText() ) );
871*cdf0e10cSrcweir 	rArgSet.Put( SfxStringItem( FID_VALID_ERRTEXT, aEdError.GetText() ) );
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir 	return sal_True;
874*cdf0e10cSrcweir }
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir // -----------------------------------------------------------------------
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir IMPL_LINK( ScTPValidationError, SelectActionHdl, ListBox*, EMPTYARG )
879*cdf0e10cSrcweir {
880*cdf0e10cSrcweir 	ScValidErrorStyle eStyle = (ScValidErrorStyle) aLbAction.GetSelectEntryPos();
881*cdf0e10cSrcweir 	sal_Bool bMacro = ( eStyle == SC_VALERR_MACRO );
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir 	aBtnSearch.Enable( bMacro );
884*cdf0e10cSrcweir 	aFtError.Enable( !bMacro );
885*cdf0e10cSrcweir 	aEdError.Enable( !bMacro );
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir 	return( 0L );
888*cdf0e10cSrcweir }
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir // -----------------------------------------------------------------------
891*cdf0e10cSrcweir 
892*cdf0e10cSrcweir IMPL_LINK( ScTPValidationError, ClickSearchHdl, PushButton*, EMPTYARG )
893*cdf0e10cSrcweir {
894*cdf0e10cSrcweir 	Window* pOld = Application::GetDefDialogParent();
895*cdf0e10cSrcweir 	Application::SetDefDialogParent( this );
896*cdf0e10cSrcweir 
897*cdf0e10cSrcweir 	// Use static SfxApplication method to bring up selector dialog for
898*cdf0e10cSrcweir 	// choosing a script
899*cdf0e10cSrcweir 	::rtl::OUString aScriptURL = SfxApplication::ChooseScript();
900*cdf0e10cSrcweir 
901*cdf0e10cSrcweir 	Application::SetDefDialogParent( pOld );
902*cdf0e10cSrcweir 
903*cdf0e10cSrcweir 	if ( aScriptURL != NULL && aScriptURL.getLength() != 0 )
904*cdf0e10cSrcweir 	{
905*cdf0e10cSrcweir 		aEdtTitle.SetText( aScriptURL );
906*cdf0e10cSrcweir 	}
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir 	return( 0L );
909*cdf0e10cSrcweir }
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir //<!--Added by PengYunQuan for Validity Cell Range Picker
912*cdf0e10cSrcweir bool ScValidationDlg::EnterRefStatus()
913*cdf0e10cSrcweir {
914*cdf0e10cSrcweir 	ScTabViewShell *pTabViewShell = GetTabViewShell();
915*cdf0e10cSrcweir 
916*cdf0e10cSrcweir 	if( !pTabViewShell ) return false;
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir 	sal_uInt16 nId  = SLOTID;
919*cdf0e10cSrcweir 	SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
920*cdf0e10cSrcweir 	SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
921*cdf0e10cSrcweir 
922*cdf0e10cSrcweir 	if ( pWnd && pWnd->GetWindow()!= this ) pWnd = NULL;
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir 	SC_MOD()->SetRefDialog( nId, pWnd ? sal_False : sal_True );
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir 	return true;
927*cdf0e10cSrcweir }
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir bool ScValidationDlg::LeaveRefStatus()
930*cdf0e10cSrcweir {
931*cdf0e10cSrcweir 	ScTabViewShell *pTabViewShell = GetTabViewShell();
932*cdf0e10cSrcweir 
933*cdf0e10cSrcweir 	if( !pTabViewShell ) return false;
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir 	sal_uInt16 nId  = SLOTID;
936*cdf0e10cSrcweir 	SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
937*cdf0e10cSrcweir 	//SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
938*cdf0e10cSrcweir     if ( pViewFrm->GetChildWindow( nId ) )
939*cdf0e10cSrcweir 	{
940*cdf0e10cSrcweir 		DoClose( nId );
941*cdf0e10cSrcweir 	}
942*cdf0e10cSrcweir 	return true;
943*cdf0e10cSrcweir }
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir bool ScValidationDlg::SetupRefDlg()
946*cdf0e10cSrcweir {
947*cdf0e10cSrcweir 	if ( m_bOwnRefHdlr ) return false;
948*cdf0e10cSrcweir 	if( EnterRefMode() )
949*cdf0e10cSrcweir 	{
950*cdf0e10cSrcweir 		SetModal( sal_False );
951*cdf0e10cSrcweir 		return  /*SetChkShell( GetDocShell() ),*/ m_bOwnRefHdlr = true && EnterRefStatus();
952*cdf0e10cSrcweir 	}
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir 	return false;
955*cdf0e10cSrcweir }
956*cdf0e10cSrcweir 
957*cdf0e10cSrcweir bool ScValidationDlg::RemoveRefDlg( sal_Bool bRestoreModal /* = sal_True */ )
958*cdf0e10cSrcweir {
959*cdf0e10cSrcweir 	bool bVisLock = false;
960*cdf0e10cSrcweir 	bool bFreeWindowLock = false;
961*cdf0e10cSrcweir 
962*cdf0e10cSrcweir 	ScTabViewShell *pTabVwSh = GetTabViewShell();
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir 	if( !pTabVwSh ) return false;
965*cdf0e10cSrcweir 
966*cdf0e10cSrcweir 	if ( SfxChildWindow* pWnd = pTabVwSh->GetViewFrame()->GetChildWindow( SID_VALIDITY_REFERENCE ) )
967*cdf0e10cSrcweir 	{
968*cdf0e10cSrcweir 		bVisLock = static_cast<ScValidityRefChildWin*>(pWnd)->LockVisible( true );
969*cdf0e10cSrcweir 		bFreeWindowLock = static_cast<ScValidityRefChildWin*>(pWnd)->LockFreeWindow( true );
970*cdf0e10cSrcweir 	}
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir 	if ( !m_bOwnRefHdlr ) return false;
973*cdf0e10cSrcweir 	if( LeaveRefStatus() && LeaveRefMode() )
974*cdf0e10cSrcweir 	{
975*cdf0e10cSrcweir 		m_bOwnRefHdlr = false;
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir 		if( bRestoreModal )
978*cdf0e10cSrcweir 			SetModal( sal_True );
979*cdf0e10cSrcweir 	}
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir 	if ( SfxChildWindow* pWnd = pTabVwSh->GetViewFrame()->GetChildWindow( SID_VALIDITY_REFERENCE ) )
982*cdf0e10cSrcweir 	{
983*cdf0e10cSrcweir 		static_cast<ScValidityRefChildWin*>(pWnd)->LockVisible( bVisLock );
984*cdf0e10cSrcweir 		static_cast<ScValidityRefChildWin*>(pWnd)->LockFreeWindow( bFreeWindowLock );
985*cdf0e10cSrcweir 	}
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir 	return true;
988*cdf0e10cSrcweir }
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir //TYPEINIT1( ScTPValidationValue, SfxTabPage )
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir void ScTPValidationValue::ScRefButtonEx::Click()
993*cdf0e10cSrcweir {
994*cdf0e10cSrcweir 	if( ScTPValidationValue *pParent = dynamic_cast< ScTPValidationValue*>( GetParent() ) )
995*cdf0e10cSrcweir 		pParent->OnClick( this );
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir 	ScRefButton::Click();
998*cdf0e10cSrcweir }
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir void ScTPValidationValue::OnClick( Button *pBtn )
1001*cdf0e10cSrcweir {
1002*cdf0e10cSrcweir 	if( pBtn == &m_btnRef )
1003*cdf0e10cSrcweir 		SetupRefDlg();
1004*cdf0e10cSrcweir }
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir sal_Bool ScValidationDlg::IsChildFocus()
1007*cdf0e10cSrcweir {
1008*cdf0e10cSrcweir 	if ( const Window *pWin = Application::GetFocusWindow() )
1009*cdf0e10cSrcweir 		while( NULL != ( pWin = pWin->GetParent() ) )
1010*cdf0e10cSrcweir 			if( pWin == this )
1011*cdf0e10cSrcweir 				return sal_True;
1012*cdf0e10cSrcweir 
1013*cdf0e10cSrcweir 	return sal_False;
1014*cdf0e10cSrcweir }
1015*cdf0e10cSrcweir 
1016*cdf0e10cSrcweir 
1017*cdf0e10cSrcweir bool	ScValidationDlg::IsAlive()
1018*cdf0e10cSrcweir {
1019*cdf0e10cSrcweir 	return SC_MOD()->IsAliveRefDlg( SLOTID, this );
1020*cdf0e10cSrcweir }
1021*cdf0e10cSrcweir //-->Added by PengYunQuan for Validity Cell Range Picker
1022