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