fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / dbgui / validate.cxx
blob23fb0f8df0ee7b637f002590722cccc84bb51867
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifdef SC_DLLIMPLEMENTATION
21 #undef SC_DLLIMPLEMENTATION
22 #endif
24 #include <comphelper/string.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/builderfactory.hxx>
27 #include <svl/aeitem.hxx>
28 #include <svl/stritem.hxx>
29 #include <svl/eitem.hxx>
30 #include <svl/intitem.hxx>
31 #include <basic/sbmeth.hxx>
32 #include <basic/sbstar.hxx>
33 #include <basic/sbmod.hxx>
34 #include <sfx2/app.hxx>
36 #include "scresid.hxx"
37 #include "sc.hrc"
39 #include "stringutil.hxx"
40 #include "validat.hxx"
41 #include "validate.hxx"
42 #include "compiler.hxx"
43 #include <formula/opcode.hxx>
45 // cell range picker
46 #include "tabvwsh.hxx"
47 #include <sfx2/viewfrm.hxx>
48 #include <sfx2/childwin.hxx>
49 #include "reffact.hxx"
51 /* Position indexes for "Allow" list box.
52 They do not map directly to ScValidationMode and can safely be modified to
53 change the order of the list box entries. */
54 #define SC_VALIDDLG_ALLOW_ANY 0
55 #define SC_VALIDDLG_ALLOW_WHOLE 1
56 #define SC_VALIDDLG_ALLOW_DECIMAL 2
57 #define SC_VALIDDLG_ALLOW_DATE 3
58 #define SC_VALIDDLG_ALLOW_TIME 4
59 #define SC_VALIDDLG_ALLOW_RANGE 5
60 #define SC_VALIDDLG_ALLOW_LIST 6
61 #define SC_VALIDDLG_ALLOW_TEXTLEN 7
63 /* Position indexes for "Data" list box.
64 They do not map directly to ScConditionMode and can safely be modified to
65 change the order of the list box entries. */
66 #define SC_VALIDDLG_DATA_EQUAL 0
67 #define SC_VALIDDLG_DATA_LESS 1
68 #define SC_VALIDDLG_DATA_GREATER 2
69 #define SC_VALIDDLG_DATA_EQLESS 3
70 #define SC_VALIDDLG_DATA_EQGREATER 4
71 #define SC_VALIDDLG_DATA_NOTEQUAL 5
72 #define SC_VALIDDLG_DATA_VALIDRANGE 6
73 #define SC_VALIDDLG_DATA_INVALIDRANGE 7
75 namespace ValidListType = css::sheet::TableValidationVisibility;
77 const sal_uInt16 ScTPValidationValue::pValueRanges[] =
79 FID_VALID_MODE, FID_VALID_ERRTEXT,
80 FID_VALID_LISTTYPE, FID_VALID_LISTTYPE,
84 ScValidationDlg::ScValidationDlg(vcl::Window* pParent, const SfxItemSet* pArgSet,
85 ScTabViewShell *pTabViewSh, SfxBindings *pB /*= NULL*/)
86 : ScValidationDlgBase(pParent ? pParent : SfxGetpApp()->GetTopWindow(),
87 "ValidationDialog", "modules/scalc/ui/validationdialog.ui", pArgSet, pB)
88 , m_pTabVwSh(pTabViewSh)
89 , m_nValuePageId(0)
90 , m_bOwnRefHdlr(false)
91 , m_bRefInputting(false)
93 m_nValuePageId = AddTabPage("criteria", ScTPValidationValue::Create, 0);
94 AddTabPage("inputhelp", ScTPValidationHelp::Create, 0);
95 AddTabPage("erroralert", ScTPValidationError::Create, 0);
96 get(m_pHBox, "refinputbox");
99 void ScTPValidationValue::SetReferenceHdl( const ScRange&rRange , ScDocument* pDoc )
101 if ( rRange.aStart != rRange.aEnd )
102 if ( ScValidationDlg *pValidationDlg = GetValidationDlg() )
103 if( m_pRefEdit )
104 pValidationDlg->RefInputStart( m_pRefEdit );
106 if ( m_pRefEdit )
108 OUString aStr(rRange.Format(SCR_ABS_3D, pDoc, pDoc->GetAddressConvention()));
109 m_pRefEdit->SetRefString( aStr );
113 void ScTPValidationValue:: SetActiveHdl()
115 if ( m_pRefEdit ) m_pRefEdit->GrabFocus();
117 if ( ScValidationDlg *pValidationDlg = GetValidationDlg() )
118 if( m_pRefEdit )
120 pValidationDlg->RefInputDone();
124 void ScTPValidationValue::RefInputStartPreHdl( formula::RefEdit* pEdit, formula::RefButton* pButton )
126 if ( ScValidationDlg *pValidationDlg = GetValidationDlg() )
128 vcl::Window *pNewParent = pValidationDlg->get_refinput_shrink_parent();
129 if( pEdit == m_pRefEdit && m_pRefEdit->GetParent() != pNewParent )
131 m_pRefEdit->SetParent(pNewParent);
134 if( pButton == m_pBtnRef && m_pBtnRef->GetParent() != pNewParent )
136 m_pBtnRef->SetParent(pNewParent);
139 pNewParent->Show();
143 void ScTPValidationValue::RefInputDonePostHdl()
145 if( m_pRefEdit && m_pRefEdit->GetParent() != m_pRefGrid )
147 m_pRefEdit->SetParent( m_pRefGrid );
148 m_pBtnRef->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
151 if( m_pBtnRef->GetParent() != m_pRefGrid )
152 m_pBtnRef->SetParent( m_pRefGrid );
154 if ( ScValidationDlg *pValidationDlg = GetValidationDlg() )
156 pValidationDlg->get_refinput_shrink_parent()->Hide();
157 ScViewData& rViewData = pValidationDlg->GetTabViewShell()->GetViewData();
158 SCTAB nCurTab = rViewData.GetTabNo();
159 SCTAB nRefTab = rViewData.GetRefTabNo();
160 // If RefInput switched to a different sheet from the data sheet,
161 // switch back: fdo#53920
162 if ( nCurTab != nRefTab )
164 rViewData.GetViewShell()->SetTabNo( nRefTab );
168 if( m_pRefEdit && !m_pRefEdit->HasFocus() )
169 m_pRefEdit->GrabFocus();
172 ScTPValidationValue::ScRefButtonEx::~ScRefButtonEx()
174 disposeOnce();
177 void ScTPValidationValue::ScRefButtonEx::dispose()
179 m_pPage.clear();
180 ::formula::RefButton::dispose();
183 namespace {
185 /** Converts the passed ScValidationMode to the position in the list box. */
186 sal_uInt16 lclGetPosFromValMode( ScValidationMode eValMode )
188 sal_uInt16 nLbPos = SC_VALIDDLG_ALLOW_ANY;
189 switch( eValMode )
191 case SC_VALID_ANY: nLbPos = SC_VALIDDLG_ALLOW_ANY; break;
192 case SC_VALID_WHOLE: nLbPos = SC_VALIDDLG_ALLOW_WHOLE; break;
193 case SC_VALID_DECIMAL: nLbPos = SC_VALIDDLG_ALLOW_DECIMAL; break;
194 case SC_VALID_DATE: nLbPos = SC_VALIDDLG_ALLOW_DATE; break;
195 case SC_VALID_TIME: nLbPos = SC_VALIDDLG_ALLOW_TIME; break;
196 case SC_VALID_TEXTLEN: nLbPos = SC_VALIDDLG_ALLOW_TEXTLEN; break;
197 case SC_VALID_LIST: nLbPos = SC_VALIDDLG_ALLOW_RANGE; break;
198 case SC_VALID_CUSTOM: nLbPos = SC_VALIDDLG_ALLOW_ANY; break; // not supported
199 default: OSL_FAIL( "lclGetPosFromValMode - unknown validity mode" );
201 return nLbPos;
204 /** Converts the passed list box position to an ScValidationMode. */
205 ScValidationMode lclGetValModeFromPos( sal_uInt16 nLbPos )
207 ScValidationMode eValMode = SC_VALID_ANY;
208 switch( nLbPos )
210 case SC_VALIDDLG_ALLOW_ANY: eValMode = SC_VALID_ANY; break;
211 case SC_VALIDDLG_ALLOW_WHOLE: eValMode = SC_VALID_WHOLE; break;
212 case SC_VALIDDLG_ALLOW_DECIMAL: eValMode = SC_VALID_DECIMAL; break;
213 case SC_VALIDDLG_ALLOW_DATE: eValMode = SC_VALID_DATE; break;
214 case SC_VALIDDLG_ALLOW_TIME: eValMode = SC_VALID_TIME; break;
215 case SC_VALIDDLG_ALLOW_RANGE: eValMode = SC_VALID_LIST; break;
216 case SC_VALIDDLG_ALLOW_LIST: eValMode = SC_VALID_LIST; break;
217 case SC_VALIDDLG_ALLOW_TEXTLEN: eValMode = SC_VALID_TEXTLEN; break;
218 default: OSL_FAIL( "lclGetValModeFromPos - invalid list box position" );
220 return eValMode;
223 /** Converts the passed ScConditionMode to the position in the list box. */
224 sal_uInt16 lclGetPosFromCondMode( ScConditionMode eCondMode )
226 sal_uInt16 nLbPos = SC_VALIDDLG_DATA_EQUAL;
227 switch( eCondMode )
229 case SC_COND_NONE: // may occur in old XML files after Excel import
230 case SC_COND_EQUAL: nLbPos = SC_VALIDDLG_DATA_EQUAL; break;
231 case SC_COND_LESS: nLbPos = SC_VALIDDLG_DATA_LESS; break;
232 case SC_COND_GREATER: nLbPos = SC_VALIDDLG_DATA_GREATER; break;
233 case SC_COND_EQLESS: nLbPos = SC_VALIDDLG_DATA_EQLESS; break;
234 case SC_COND_EQGREATER: nLbPos = SC_VALIDDLG_DATA_EQGREATER; break;
235 case SC_COND_NOTEQUAL: nLbPos = SC_VALIDDLG_DATA_NOTEQUAL; break;
236 case SC_COND_BETWEEN: nLbPos = SC_VALIDDLG_DATA_VALIDRANGE; break;
237 case SC_COND_NOTBETWEEN: nLbPos = SC_VALIDDLG_DATA_INVALIDRANGE; break;
238 default: OSL_FAIL( "lclGetPosFromCondMode - unknown condition mode" );
240 return nLbPos;
243 /** Converts the passed list box position to an ScConditionMode. */
244 ScConditionMode lclGetCondModeFromPos( sal_uInt16 nLbPos )
246 ScConditionMode eCondMode = SC_COND_EQUAL;
247 switch( nLbPos )
249 case SC_VALIDDLG_DATA_EQUAL: eCondMode = SC_COND_EQUAL; break;
250 case SC_VALIDDLG_DATA_LESS: eCondMode = SC_COND_LESS; break;
251 case SC_VALIDDLG_DATA_GREATER: eCondMode = SC_COND_GREATER; break;
252 case SC_VALIDDLG_DATA_EQLESS: eCondMode = SC_COND_EQLESS; break;
253 case SC_VALIDDLG_DATA_EQGREATER: eCondMode = SC_COND_EQGREATER; break;
254 case SC_VALIDDLG_DATA_NOTEQUAL: eCondMode = SC_COND_NOTEQUAL; break;
255 case SC_VALIDDLG_DATA_VALIDRANGE: eCondMode = SC_COND_BETWEEN; break;
256 case SC_VALIDDLG_DATA_INVALIDRANGE: eCondMode = SC_COND_NOTBETWEEN; break;
257 default: OSL_FAIL( "lclGetCondModeFromPos - invalid list box position" );
259 return eCondMode;
262 /** Converts line feed separated string to a formula with strings separated by semicolons.
263 @descr Keeps all empty strings.
264 Example: abc\ndef\n\nghi -> "abc";"def";"";"ghi".
265 @param rFmlaStr (out-param) The converted formula string. */
266 void lclGetFormulaFromStringList( OUString& rFmlaStr, const OUString& rStringList, sal_Unicode cFmlaSep )
268 rFmlaStr.clear();
269 sal_Int32 nTokenCnt = comphelper::string::getTokenCount(rStringList, '\n');
270 for( sal_Int32 nToken = 0, nStringIx = 0; nToken < (sal_Int32) nTokenCnt; ++nToken )
272 OUString aToken( rStringList.getToken( 0, '\n', nStringIx ) );
273 ScGlobal::AddQuotes( aToken, '"' );
274 rFmlaStr = ScGlobal::addToken(rFmlaStr, aToken, cFmlaSep);
276 if( rFmlaStr.isEmpty() )
277 rFmlaStr = "\"\"";
280 /** Converts formula with strings separated by semicolons to line feed separated string.
281 @descr Keeps all empty strings. Ignores all empty tokens (multiple semicolons).
282 Example: "abc";;;"def";"";"ghi" -> abc\ndef\n\nghi.
283 @param rStringList (out-param) The converted line feed separated string list.
284 @return true = Conversion successful. */
285 bool lclGetStringListFromFormula( OUString& rStringList, const OUString& rFmlaStr, sal_Unicode cFmlaSep )
287 OUString aQuotes( "\"\"" );
288 sal_Int32 nTokenCnt = ScStringUtil::GetQuotedTokenCount(rFmlaStr, aQuotes, cFmlaSep );
290 rStringList.clear();
291 bool bIsStringList = (nTokenCnt > 0);
292 bool bTokenAdded = false;
294 for( sal_Int32 nToken = 0, nStringIx = 0; bIsStringList && (nToken < nTokenCnt); ++nToken )
296 OUString aToken( ScStringUtil::GetQuotedToken(rFmlaStr, 0, aQuotes, cFmlaSep, nStringIx ) );
297 aToken = comphelper::string::strip(aToken, ' ');
298 if( !aToken.isEmpty() ) // ignore empty tokens, i.e. "a";;"b"
300 bIsStringList = ScGlobal::IsQuoted( aToken, '"' );
301 if( bIsStringList )
303 ScGlobal::EraseQuotes( aToken, '"' );
304 rStringList = ScGlobal::addToken(rStringList, aToken, '\n', 1, bTokenAdded);
305 bTokenAdded = true;
310 return bIsStringList;
313 } // namespace
315 ScTPValidationValue::ScTPValidationValue( vcl::Window* pParent, const SfxItemSet& rArgSet )
316 : SfxTabPage( pParent, "ValidationCriteriaPage",
317 "modules/scalc/ui/validationcriteriapage.ui", &rArgSet)
318 , maStrMin(ScResId(SCSTR_VALID_MINIMUM))
319 , maStrMax(ScResId(SCSTR_VALID_MAXIMUM))
320 , maStrValue(ScResId(SCSTR_VALID_VALUE))
321 , maStrRange(ScResId(SCSTR_VALID_RANGE))
322 , maStrList(ScResId(SCSTR_VALID_LIST))
323 , m_pRefEdit(NULL)
325 get(m_pLbAllow, "allow");
326 get(m_pCbAllow, "allowempty");
327 get(m_pCbShow, "showlist");
328 get(m_pCbSort, "sortascend");
329 get(m_pFtValue, "valueft");
330 get(m_pLbValue, "data");
331 get(m_pFtMin, "minft");
332 get(m_pMinGrid, "mingrid");
333 get(m_pEdMin, "min");
334 m_pEdMin->SetReferences(NULL, m_pFtMin);
335 get(m_pEdList, "minlist");
336 Size aSize(LogicToPixel(Size(174, 105), MAP_APPFONT));
337 m_pEdList->set_width_request(aSize.Width());
338 m_pEdList->set_height_request(aSize.Height());
339 get(m_pFtMax, "maxft");
340 get(m_pEdMax, "max");
341 m_pEdMax->SetReferences(NULL, m_pFtMax);
342 get(m_pFtHint, "hintft");
343 get(m_pBtnRef, "validref");
344 m_pBtnRef->SetParentPage(this);
345 get(m_pRefGrid, "refgrid");
347 //lock in the max size initial config
348 aSize = get_preferred_size();
349 set_width_request(aSize.Width());
350 set_height_request(aSize.Height());
352 Init();
354 // list separator in formulas
355 OUString aListSep = ::ScCompiler::GetNativeSymbol( ocSep );
356 OSL_ENSURE( aListSep.getLength() == 1, "ScTPValidationValue::ScTPValidationValue - list separator error" );
357 mcFmlaSep = aListSep.getLength() ? aListSep[0] : ';';
358 m_pBtnRef->Hide(); // cell range picker
361 ScTPValidationValue::~ScTPValidationValue()
363 disposeOnce();
366 void ScTPValidationValue::dispose()
368 m_pLbAllow.clear();
369 m_pCbAllow.clear();
370 m_pCbShow.clear();
371 m_pCbSort.clear();
372 m_pFtValue.clear();
373 m_pLbValue.clear();
374 m_pFtMin.clear();
375 m_pMinGrid.clear();
376 m_pEdMin.clear();
377 m_pEdList.clear();
378 m_pFtMax.clear();
379 m_pEdMax.clear();
380 m_pFtHint.clear();
381 m_pRefEdit.clear();
382 m_pBtnRef.clear();
383 m_pRefGrid.clear();
384 SfxTabPage::dispose();
388 void ScTPValidationValue::Init()
390 m_pLbAllow->SetSelectHdl( LINK( this, ScTPValidationValue, SelectHdl ) );
391 m_pLbValue->SetSelectHdl( LINK( this, ScTPValidationValue, SelectHdl ) );
392 m_pCbShow->SetClickHdl( LINK( this, ScTPValidationValue, CheckHdl ) );
394 // cell range picker
395 m_pEdMin->SetGetFocusHdl( LINK( this, ScTPValidationValue, EditSetFocusHdl ) );
396 m_pEdMin->SetLoseFocusHdl( LINK( this, ScTPValidationValue, KillFocusHdl ) );
397 m_pEdMax->SetGetFocusHdl( LINK( this, ScTPValidationValue, EditSetFocusHdl ) );
398 m_pBtnRef->SetLoseFocusHdl( LINK( this, ScTPValidationValue, KillFocusHdl ) );
399 m_pEdMax->SetLoseFocusHdl( LINK( this, ScTPValidationValue, KillFocusHdl ) );
401 m_pLbAllow->SelectEntryPos( SC_VALIDDLG_ALLOW_ANY );
402 m_pLbValue->SelectEntryPos( SC_VALIDDLG_DATA_EQUAL );
404 SelectHdl( NULL );
405 CheckHdl( NULL );
408 VclPtr<SfxTabPage> ScTPValidationValue::Create( vcl::Window* pParent, const SfxItemSet* rArgSet )
410 return VclPtr<ScTPValidationValue>::Create( pParent, *rArgSet );
413 void ScTPValidationValue::Reset( const SfxItemSet* rArgSet )
415 const SfxPoolItem* pItem;
417 sal_uInt16 nLbPos = SC_VALIDDLG_ALLOW_ANY;
418 if( rArgSet->GetItemState( FID_VALID_MODE, true, &pItem ) == SfxItemState::SET )
419 nLbPos = lclGetPosFromValMode( static_cast< ScValidationMode >(
420 static_cast< const SfxAllEnumItem* >( pItem )->GetValue() ) );
421 m_pLbAllow->SelectEntryPos( nLbPos );
423 nLbPos = SC_VALIDDLG_DATA_EQUAL;
424 if( rArgSet->GetItemState( FID_VALID_CONDMODE, true, &pItem ) == SfxItemState::SET )
425 nLbPos = lclGetPosFromCondMode( static_cast< ScConditionMode >(
426 static_cast< const SfxAllEnumItem* >( pItem )->GetValue() ) );
427 m_pLbValue->SelectEntryPos( nLbPos );
429 // *** check boxes ***
430 bool bCheck = true;
431 if( rArgSet->GetItemState( FID_VALID_BLANK, true, &pItem ) == SfxItemState::SET )
432 bCheck = static_cast< const SfxBoolItem* >( pItem )->GetValue();
433 m_pCbAllow->Check( bCheck );
435 sal_Int32 nListType = ValidListType::UNSORTED;
436 if( rArgSet->GetItemState( FID_VALID_LISTTYPE, true, &pItem ) == SfxItemState::SET )
437 nListType = static_cast< const SfxInt16Item* >( pItem )->GetValue();
438 m_pCbShow->Check( nListType != ValidListType::INVISIBLE );
439 m_pCbSort->Check( nListType == ValidListType::SORTEDASCENDING );
441 // *** formulas ***
442 OUString aFmlaStr;
443 if ( rArgSet->GetItemState( FID_VALID_VALUE1, true, &pItem ) == SfxItemState::SET )
444 aFmlaStr = static_cast< const SfxStringItem* >( pItem )->GetValue();
445 SetFirstFormula( aFmlaStr );
447 aFmlaStr.clear();
448 if ( rArgSet->GetItemState( FID_VALID_VALUE2, true, &pItem ) == SfxItemState::SET )
449 aFmlaStr = static_cast< const SfxStringItem* >( pItem )->GetValue();
450 SetSecondFormula( aFmlaStr );
452 SelectHdl( NULL );
453 CheckHdl( NULL );
456 bool ScTPValidationValue::FillItemSet( SfxItemSet* rArgSet )
458 sal_Int16 nListType = m_pCbShow->IsChecked() ?
459 (m_pCbSort->IsChecked() ? ValidListType::SORTEDASCENDING : ValidListType::UNSORTED) :
460 ValidListType::INVISIBLE;
462 rArgSet->Put( SfxAllEnumItem( FID_VALID_MODE, sal::static_int_cast<sal_uInt16>(
463 lclGetValModeFromPos( m_pLbAllow->GetSelectEntryPos() ) ) ) );
464 rArgSet->Put( SfxAllEnumItem( FID_VALID_CONDMODE, sal::static_int_cast<sal_uInt16>(
465 lclGetCondModeFromPos( m_pLbValue->GetSelectEntryPos() ) ) ) );
466 rArgSet->Put( SfxStringItem( FID_VALID_VALUE1, GetFirstFormula() ) );
467 rArgSet->Put( SfxStringItem( FID_VALID_VALUE2, GetSecondFormula() ) );
468 rArgSet->Put( SfxBoolItem( FID_VALID_BLANK, m_pCbAllow->IsChecked() ) );
469 rArgSet->Put( SfxInt16Item( FID_VALID_LISTTYPE, nListType ) );
470 return true;
473 OUString ScTPValidationValue::GetFirstFormula() const
475 OUString aFmlaStr;
476 if( m_pLbAllow->GetSelectEntryPos() == SC_VALIDDLG_ALLOW_LIST )
477 lclGetFormulaFromStringList( aFmlaStr, m_pEdList->GetText(), mcFmlaSep );
478 else
479 aFmlaStr = m_pEdMin->GetText();
480 return aFmlaStr;
483 OUString ScTPValidationValue::GetSecondFormula() const
485 return m_pEdMax->GetText();
488 void ScTPValidationValue::SetFirstFormula( const OUString& rFmlaStr )
490 // try if formula is a string list, validation mode must already be set
491 OUString aStringList;
492 if( (m_pLbAllow->GetSelectEntryPos() == SC_VALIDDLG_ALLOW_RANGE) &&
493 lclGetStringListFromFormula( aStringList, rFmlaStr, mcFmlaSep ) )
495 m_pEdList->SetText( aStringList );
496 m_pEdMin->SetText( EMPTY_OUSTRING );
497 // change validation mode to string list
498 m_pLbAllow->SelectEntryPos( SC_VALIDDLG_ALLOW_LIST );
500 else
502 m_pEdMin->SetText( rFmlaStr );
503 m_pEdList->SetText( EMPTY_OUSTRING );
507 void ScTPValidationValue::SetSecondFormula( const OUString& rFmlaStr )
509 m_pEdMax->SetText( rFmlaStr );
512 ScValidationDlg * ScTPValidationValue::GetValidationDlg()
514 if( vcl::Window *pParent = GetParent() )
516 if ( dynamic_cast<ScValidationDlg*>( pParent ) )
517 return static_cast< ScValidationDlg * >( pParent );
518 }while ( NULL != ( pParent = pParent->GetParent() ) );
519 return NULL;
522 void ScTPValidationValue::SetupRefDlg()
524 if( ScValidationDlg *pValidationDlg = GetValidationDlg() )
526 if( pValidationDlg->SetupRefDlg() )
528 pValidationDlg->SetHandler( this );
529 pValidationDlg->SetSetRefHdl( static_cast<ScRefHandlerHelper::PFUNCSETREFHDLTYPE>( &ScTPValidationValue::SetReferenceHdl ) );
530 pValidationDlg->SetSetActHdl( static_cast<ScRefHandlerHelper::PCOMMONHDLTYPE>( &ScTPValidationValue::SetActiveHdl ) );
531 pValidationDlg->SetRefInputStartPreHdl( static_cast<ScRefHandlerHelper::PINPUTSTARTDLTYPE>( &ScTPValidationValue::RefInputStartPreHdl ) );
532 pValidationDlg->SetRefInputDonePostHdl( static_cast<ScRefHandlerHelper::PCOMMONHDLTYPE>( &ScTPValidationValue::RefInputDonePostHdl ) );
534 vcl::Window *pLabel = NULL;
536 if ( m_pEdMax->IsVisible() )
538 m_pRefEdit = m_pEdMax;
539 pLabel = m_pFtMax;
541 else if ( m_pEdMin->IsVisible() )
543 m_pRefEdit = m_pEdMin;
544 pLabel = m_pFtMin;
547 if( m_pRefEdit && !m_pRefEdit->HasFocus() )
548 m_pRefEdit->GrabFocus();
550 if( m_pRefEdit )
551 m_pRefEdit->SetReferences( pValidationDlg, pLabel );
553 m_pBtnRef->SetReferences( pValidationDlg, m_pRefEdit );
558 void ScTPValidationValue::RemoveRefDlg()
560 if( ScValidationDlg *pValidationDlg = GetValidationDlg() )
562 if( pValidationDlg->RemoveRefDlg() )
564 pValidationDlg->SetHandler( NULL );
565 pValidationDlg->SetSetRefHdl( NULL );
566 pValidationDlg->SetSetActHdl( NULL );
567 pValidationDlg->SetRefInputStartPreHdl( NULL );
568 pValidationDlg->SetRefInputDonePostHdl( NULL );
570 if( m_pRefEdit )
571 m_pRefEdit->SetReferences( NULL, NULL );
572 m_pRefEdit = NULL;
574 m_pBtnRef->SetReferences( NULL, NULL );
579 IMPL_LINK_NOARG(ScTPValidationValue, EditSetFocusHdl)
581 sal_uInt16 nPos=m_pLbAllow->GetSelectEntryPos();
583 if ( nPos == SC_VALIDDLG_ALLOW_RANGE )
585 SetupRefDlg();
588 return 0;
591 IMPL_LINK( ScTPValidationValue, KillFocusHdl, vcl::Window *, pWnd )
593 if( pWnd == m_pRefEdit || pWnd == m_pBtnRef )
594 if( ScValidationDlg *pValidationDlg = GetValidationDlg() )
595 if ( (pValidationDlg->IsActive() || pValidationDlg->IsChildFocus() ) && !pValidationDlg->IsRefInputting() )
596 if( ( !m_pRefEdit || !m_pRefEdit->HasFocus()) && !m_pBtnRef->HasFocus() )
598 RemoveRefDlg();
601 return 0;
604 IMPL_LINK_NOARG(ScTPValidationValue, SelectHdl)
606 sal_uInt16 nLbPos = m_pLbAllow->GetSelectEntryPos();
607 bool bEnable = (nLbPos != SC_VALIDDLG_ALLOW_ANY);
608 bool bRange = (nLbPos == SC_VALIDDLG_ALLOW_RANGE);
609 bool bList = (nLbPos == SC_VALIDDLG_ALLOW_LIST);
611 m_pCbAllow->Enable( bEnable ); // Empty cell
612 m_pFtValue->Enable( bEnable );
613 m_pLbValue->Enable( bEnable );
614 m_pFtMin->Enable( bEnable );
615 m_pEdMin->Enable( bEnable );
616 m_pEdList->Enable( bEnable );
617 m_pFtMax->Enable( bEnable );
618 m_pEdMax->Enable( bEnable );
620 bool bShowMax = false;
621 if( bRange )
622 m_pFtMin->SetText( maStrRange );
623 else if( bList )
624 m_pFtMin->SetText( maStrList );
625 else
627 switch( m_pLbValue->GetSelectEntryPos() )
629 case SC_VALIDDLG_DATA_EQUAL:
630 case SC_VALIDDLG_DATA_NOTEQUAL: m_pFtMin->SetText( maStrValue ); break;
632 case SC_VALIDDLG_DATA_LESS:
633 case SC_VALIDDLG_DATA_EQLESS: m_pFtMin->SetText( maStrMax ); break;
635 case SC_VALIDDLG_DATA_VALIDRANGE:
636 case SC_VALIDDLG_DATA_INVALIDRANGE: bShowMax = true; // fall through
637 case SC_VALIDDLG_DATA_GREATER:
638 case SC_VALIDDLG_DATA_EQGREATER: m_pFtMin->SetText( maStrMin ); break;
640 default:
641 OSL_FAIL( "ScTPValidationValue::SelectHdl - unknown condition mode" );
645 m_pCbShow->Show( bRange || bList );
646 m_pCbSort->Show( bRange || bList );
647 m_pFtValue->Show( !bRange && !bList );
648 m_pLbValue->Show( !bRange && !bList );
649 m_pEdMin->Show( !bList );
650 m_pEdList->Show( bList );
651 m_pMinGrid->set_vexpand( bList );
652 WinBits nBits = m_pFtMin->GetStyle();
653 nBits &= ~(WB_TOP | WB_VCENTER | WB_BOTTOM);
654 if (bList)
655 nBits |= WB_TOP;
656 else
657 nBits |= WB_VCENTER;
658 m_pFtMin->SetStyle( nBits );
659 m_pFtMax->Show( bShowMax );
660 m_pEdMax->Show( bShowMax );
661 m_pFtHint->Show( bRange );
662 m_pBtnRef->Show( bRange ); // cell range picker
663 return 0;
666 IMPL_LINK_NOARG(ScTPValidationValue, CheckHdl)
668 m_pCbSort->Enable( m_pCbShow->IsChecked() );
669 return 0;
672 // Input Help Page
674 ScTPValidationHelp::ScTPValidationHelp( vcl::Window* pParent,
675 const SfxItemSet& rArgSet )
677 : SfxTabPage ( pParent,
678 "ValidationHelpTabPage" , "modules/scalc/ui/validationhelptabpage.ui" ,
679 &rArgSet )
681 get(pTsbHelp,"tsbhelp");
682 get(pEdtTitle,"title");
683 get(pEdInputHelp,"inputhelp");
684 pEdInputHelp->set_height_request(pEdInputHelp->GetTextHeight() * 12);
685 pEdInputHelp->set_width_request(pEdInputHelp->approximate_char_width() * 50);
686 Init();
689 ScTPValidationHelp::~ScTPValidationHelp()
691 disposeOnce();
694 void ScTPValidationHelp::dispose()
696 pTsbHelp.clear();
697 pEdtTitle.clear();
698 pEdInputHelp.clear();
699 SfxTabPage::dispose();
702 void ScTPValidationHelp::Init()
704 pTsbHelp->EnableTriState( false );
707 VclPtr<SfxTabPage> ScTPValidationHelp::Create( vcl::Window* pParent,
708 const SfxItemSet* rArgSet )
710 return VclPtr<ScTPValidationHelp>::Create( pParent, *rArgSet );
713 void ScTPValidationHelp::Reset( const SfxItemSet* rArgSet )
715 const SfxPoolItem* pItem;
717 if ( rArgSet->GetItemState( FID_VALID_SHOWHELP, true, &pItem ) == SfxItemState::SET )
718 pTsbHelp->SetState( static_cast<const SfxBoolItem*>(pItem)->GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
719 else
720 pTsbHelp->SetState( TRISTATE_FALSE );
722 if ( rArgSet->GetItemState( FID_VALID_HELPTITLE, true, &pItem ) == SfxItemState::SET )
723 pEdtTitle->SetText( static_cast<const SfxStringItem*>(pItem)->GetValue() );
724 else
725 pEdtTitle->SetText( EMPTY_OUSTRING );
727 if ( rArgSet->GetItemState( FID_VALID_HELPTEXT, true, &pItem ) == SfxItemState::SET )
728 pEdInputHelp->SetText( static_cast<const SfxStringItem*>(pItem)->GetValue() );
729 else
730 pEdInputHelp->SetText( EMPTY_OUSTRING );
733 bool ScTPValidationHelp::FillItemSet( SfxItemSet* rArgSet )
735 rArgSet->Put( SfxBoolItem( FID_VALID_SHOWHELP, pTsbHelp->GetState() == TRISTATE_TRUE ) );
736 rArgSet->Put( SfxStringItem( FID_VALID_HELPTITLE, pEdtTitle->GetText() ) );
737 rArgSet->Put( SfxStringItem( FID_VALID_HELPTEXT, pEdInputHelp->GetText() ) );
739 return true;
742 // Error Alert Page
744 ScTPValidationError::ScTPValidationError( vcl::Window* pParent,
745 const SfxItemSet& rArgSet )
747 : SfxTabPage ( pParent,
748 "ErrorAlertTabPage" , "modules/scalc/ui/erroralerttabpage.ui" ,
749 &rArgSet )
751 get(m_pTsbShow,"tsbshow");
752 get(m_pLbAction,"actionCB");
753 get(m_pBtnSearch,"browseBtn");
754 get(m_pEdtTitle,"title");
755 get(m_pFtError,"errormsg_label");
756 get(m_pEdError,"errorMsg");
757 m_pEdError->set_height_request(m_pEdError->GetTextHeight() * 12);
758 m_pEdError->set_width_request(m_pEdError->approximate_char_width() * 50);
759 Init();
762 ScTPValidationError::~ScTPValidationError()
764 disposeOnce();
767 void ScTPValidationError::dispose()
769 m_pTsbShow.clear();
770 m_pLbAction.clear();
771 m_pBtnSearch.clear();
772 m_pEdtTitle.clear();
773 m_pFtError.clear();
774 m_pEdError.clear();
775 SfxTabPage::dispose();
778 void ScTPValidationError::Init()
780 m_pLbAction->SetSelectHdl( LINK( this, ScTPValidationError, SelectActionHdl ) );
781 m_pBtnSearch->SetClickHdl( LINK( this, ScTPValidationError, ClickSearchHdl ) );
783 m_pLbAction->SelectEntryPos( 0 );
784 m_pTsbShow->EnableTriState( false );
786 SelectActionHdl( NULL );
789 VclPtr<SfxTabPage> ScTPValidationError::Create( vcl::Window* pParent,
790 const SfxItemSet* rArgSet )
792 return VclPtr<ScTPValidationError>::Create( pParent, *rArgSet );
795 void ScTPValidationError::Reset( const SfxItemSet* rArgSet )
797 const SfxPoolItem* pItem;
799 if ( rArgSet->GetItemState( FID_VALID_SHOWERR, true, &pItem ) == SfxItemState::SET )
800 m_pTsbShow->SetState( static_cast<const SfxBoolItem*>(pItem)->GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
801 else
802 m_pTsbShow->SetState( TRISTATE_TRUE ); // check by default
804 if ( rArgSet->GetItemState( FID_VALID_ERRSTYLE, true, &pItem ) == SfxItemState::SET )
805 m_pLbAction->SelectEntryPos( static_cast<const SfxAllEnumItem*>(pItem)->GetValue() );
806 else
807 m_pLbAction->SelectEntryPos( 0 );
809 if ( rArgSet->GetItemState( FID_VALID_ERRTITLE, true, &pItem ) == SfxItemState::SET )
810 m_pEdtTitle->SetText( static_cast<const SfxStringItem*>(pItem)->GetValue() );
811 else
812 m_pEdtTitle->SetText( EMPTY_OUSTRING );
814 if ( rArgSet->GetItemState( FID_VALID_ERRTEXT, true, &pItem ) == SfxItemState::SET )
815 m_pEdError->SetText( static_cast<const SfxStringItem*>(pItem)->GetValue() );
816 else
817 m_pEdError->SetText( EMPTY_OUSTRING );
819 SelectActionHdl( NULL );
822 bool ScTPValidationError::FillItemSet( SfxItemSet* rArgSet )
824 rArgSet->Put( SfxBoolItem( FID_VALID_SHOWERR, m_pTsbShow->GetState() == TRISTATE_TRUE ) );
825 rArgSet->Put( SfxAllEnumItem( FID_VALID_ERRSTYLE, m_pLbAction->GetSelectEntryPos() ) );
826 rArgSet->Put( SfxStringItem( FID_VALID_ERRTITLE, m_pEdtTitle->GetText() ) );
827 rArgSet->Put( SfxStringItem( FID_VALID_ERRTEXT, m_pEdError->GetText() ) );
829 return true;
832 IMPL_LINK_NOARG(ScTPValidationError, SelectActionHdl)
834 ScValidErrorStyle eStyle = (ScValidErrorStyle) m_pLbAction->GetSelectEntryPos();
835 bool bMacro = ( eStyle == SC_VALERR_MACRO );
837 m_pBtnSearch->Enable( bMacro );
838 m_pFtError->Enable( !bMacro );
839 m_pEdError->Enable( !bMacro );
841 return 0L;
844 IMPL_LINK_NOARG(ScTPValidationError, ClickSearchHdl)
846 vcl::Window* pOld = Application::GetDefDialogParent();
847 Application::SetDefDialogParent( this );
849 // Use static SfxApplication method to bring up selector dialog for
850 // choosing a script
851 OUString aScriptURL = SfxApplication::ChooseScript();
853 Application::SetDefDialogParent( pOld );
855 if ( aScriptURL != NULL && !aScriptURL.isEmpty() )
857 m_pEdtTitle->SetText( aScriptURL );
860 return 0L;
863 bool ScValidationDlg::EnterRefStatus()
865 ScTabViewShell *pTabViewShell = GetTabViewShell();
867 if( !pTabViewShell ) return false;
869 sal_uInt16 nId = SLOTID;
870 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
871 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
873 if ( pWnd && pWnd->GetWindow()!= this ) pWnd = NULL;
875 SC_MOD()->SetRefDialog( nId, pWnd == nullptr );
877 return true;
880 bool ScValidationDlg::LeaveRefStatus()
882 ScTabViewShell *pTabViewShell = GetTabViewShell();
884 if( !pTabViewShell ) return false;
886 sal_uInt16 nId = SLOTID;
887 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
888 if ( pViewFrm->GetChildWindow( nId ) )
890 DoClose( nId );
892 return true;
895 bool ScValidationDlg::SetupRefDlg()
897 if ( m_bOwnRefHdlr ) return false;
898 if( EnterRefMode() )
900 SetModal( false );
901 return m_bOwnRefHdlr = true && EnterRefStatus();
904 return false;
907 bool ScValidationDlg::RemoveRefDlg( bool bRestoreModal /* = true */ )
909 bool bVisLock = false;
910 bool bFreeWindowLock = false;
912 ScTabViewShell *pTabVwSh = GetTabViewShell();
914 if( !pTabVwSh ) return false;
916 if ( SfxChildWindow* pWnd = pTabVwSh->GetViewFrame()->GetChildWindow( SID_VALIDITY_REFERENCE ) )
918 bVisLock = static_cast<ScValidityRefChildWin*>(pWnd)->LockVisible( true );
919 bFreeWindowLock = static_cast<ScValidityRefChildWin*>(pWnd)->LockFreeWindow( true );
922 if ( !m_bOwnRefHdlr ) return false;
923 if( LeaveRefStatus() && LeaveRefMode() )
925 m_bOwnRefHdlr = false;
927 if( bRestoreModal )
928 SetModal( true );
931 if ( SfxChildWindow* pWnd = pTabVwSh->GetViewFrame()->GetChildWindow( SID_VALIDITY_REFERENCE ) )
933 static_cast<ScValidityRefChildWin*>(pWnd)->LockVisible( bVisLock );
934 static_cast<ScValidityRefChildWin*>(pWnd)->LockFreeWindow( bFreeWindowLock );
937 return true;
940 VCL_BUILDER_DECL_FACTORY(ScRefButtonEx)
942 (void)rMap;
943 rRet = VclPtr<ScTPValidationValue::ScRefButtonEx>::Create(pParent, 0);
946 void ScTPValidationValue::ScRefButtonEx::Click()
948 if( ScTPValidationValue *pParent = GetParentPage() )
949 pParent->OnClick( this );
951 formula::RefButton::Click();
954 void ScTPValidationValue::OnClick( Button *pBtn )
956 if( pBtn == m_pBtnRef )
957 SetupRefDlg();
960 bool ScValidationDlg::IsChildFocus()
962 if ( const vcl::Window *pWin = Application::GetFocusWindow() )
963 while( NULL != ( pWin = pWin->GetParent() ) )
964 if( pWin == this )
965 return true;
967 return false;
970 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */