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