1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifdef SC_DLLIMPLEMENTATION
21 #undef SC_DLLIMPLEMENTATION
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"
39 #include "stringutil.hxx"
40 #include "validat.hxx"
41 #include "validate.hxx"
42 #include "compiler.hxx"
43 #include <formula/opcode.hxx>
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
)
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() )
104 pValidationDlg
->RefInputStart( 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() )
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
);
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()
177 void ScTPValidationValue::ScRefButtonEx::dispose()
180 ::formula::RefButton::dispose();
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
;
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" );
204 /** Converts the passed list box position to an ScValidationMode. */
205 ScValidationMode
lclGetValModeFromPos( sal_uInt16 nLbPos
)
207 ScValidationMode eValMode
= SC_VALID_ANY
;
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" );
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
;
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" );
243 /** Converts the passed list box position to an ScConditionMode. */
244 ScConditionMode
lclGetCondModeFromPos( sal_uInt16 nLbPos
)
246 ScConditionMode eCondMode
= SC_COND_EQUAL
;
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" );
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
)
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() )
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
);
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
, '"' );
303 ScGlobal::EraseQuotes( aToken
, '"' );
304 rStringList
= ScGlobal::addToken(rStringList
, aToken
, '\n', 1, bTokenAdded
);
310 return bIsStringList
;
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
))
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());
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()
366 void ScTPValidationValue::dispose()
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
) );
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
);
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 ***
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
);
443 if ( rArgSet
->GetItemState( FID_VALID_VALUE1
, true, &pItem
) == SfxItemState::SET
)
444 aFmlaStr
= static_cast< const SfxStringItem
* >( pItem
)->GetValue();
445 SetFirstFormula( aFmlaStr
);
448 if ( rArgSet
->GetItemState( FID_VALID_VALUE2
, true, &pItem
) == SfxItemState::SET
)
449 aFmlaStr
= static_cast< const SfxStringItem
* >( pItem
)->GetValue();
450 SetSecondFormula( aFmlaStr
);
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
) );
473 OUString
ScTPValidationValue::GetFirstFormula() const
476 if( m_pLbAllow
->GetSelectEntryPos() == SC_VALIDDLG_ALLOW_LIST
)
477 lclGetFormulaFromStringList( aFmlaStr
, m_pEdList
->GetText(), mcFmlaSep
);
479 aFmlaStr
= m_pEdMin
->GetText();
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
);
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() ) );
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
;
541 else if ( m_pEdMin
->IsVisible() )
543 m_pRefEdit
= m_pEdMin
;
547 if( m_pRefEdit
&& !m_pRefEdit
->HasFocus() )
548 m_pRefEdit
->GrabFocus();
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
);
571 m_pRefEdit
->SetReferences( NULL
, 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
)
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() )
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;
622 m_pFtMin
->SetText( maStrRange
);
624 m_pFtMin
->SetText( maStrList
);
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;
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
);
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
666 IMPL_LINK_NOARG(ScTPValidationValue
, CheckHdl
)
668 m_pCbSort
->Enable( m_pCbShow
->IsChecked() );
674 ScTPValidationHelp::ScTPValidationHelp( vcl::Window
* pParent
,
675 const SfxItemSet
& rArgSet
)
677 : SfxTabPage ( pParent
,
678 "ValidationHelpTabPage" , "modules/scalc/ui/validationhelptabpage.ui" ,
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);
689 ScTPValidationHelp::~ScTPValidationHelp()
694 void ScTPValidationHelp::dispose()
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
);
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() );
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() );
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() ) );
744 ScTPValidationError::ScTPValidationError( vcl::Window
* pParent
,
745 const SfxItemSet
& rArgSet
)
747 : SfxTabPage ( pParent
,
748 "ErrorAlertTabPage" , "modules/scalc/ui/erroralerttabpage.ui" ,
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);
762 ScTPValidationError::~ScTPValidationError()
767 void ScTPValidationError::dispose()
771 m_pBtnSearch
.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
);
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() );
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() );
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() );
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() ) );
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
);
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
851 OUString aScriptURL
= SfxApplication::ChooseScript();
853 Application::SetDefDialogParent( pOld
);
855 if ( aScriptURL
!= NULL
&& !aScriptURL
.isEmpty() )
857 m_pEdtTitle
->SetText( aScriptURL
);
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 );
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
) )
895 bool ScValidationDlg::SetupRefDlg()
897 if ( m_bOwnRefHdlr
) return false;
901 return m_bOwnRefHdlr
= true && EnterRefStatus();
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;
931 if ( SfxChildWindow
* pWnd
= pTabVwSh
->GetViewFrame()->GetChildWindow( SID_VALIDITY_REFERENCE
) )
933 static_cast<ScValidityRefChildWin
*>(pWnd
)->LockVisible( bVisLock
);
934 static_cast<ScValidityRefChildWin
*>(pWnd
)->LockFreeWindow( bFreeWindowLock
);
940 VCL_BUILDER_DECL_FACTORY(ScRefButtonEx
)
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
)
960 bool ScValidationDlg::IsChildFocus()
962 if ( const vcl::Window
*pWin
= Application::GetFocusWindow() )
963 while( NULL
!= ( pWin
= pWin
->GetParent() ) )
970 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */