20 #ifdef SC_DLLIMPLEMENTATION
21 #undef SC_DLLIMPLEMENTATION
24 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
32 #include <strings.hrc>
37 #include <compiler.hxx>
48 #define IS_MOBILE (comphelper::LibreOfficeKit::isActive() && SfxViewShell::Current() && SfxViewShell::Current()->isLOKMobilePhone())
53 #define SC_VALIDDLG_ALLOW_ANY 0
54 #define SC_VALIDDLG_ALLOW_WHOLE 1
55 #define SC_VALIDDLG_ALLOW_DECIMAL 2
56 #define SC_VALIDDLG_ALLOW_DATE 3
57 #define SC_VALIDDLG_ALLOW_TIME 4
58 #define SC_VALIDDLG_ALLOW_RANGE 5
59 #define SC_VALIDDLG_ALLOW_LIST 6
60 #define SC_VALIDDLG_ALLOW_TEXTLEN 7
61 #define SC_VALIDDLG_ALLOW_CUSTOM 8
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
74 #define SC_VALIDDLG_DATA_DIRECT 8
76 namespace ValidListType = css::sheet::TableValidationVisibility;
80 FID_VALID_MODE, FID_VALID_ERRTEXT,
81 FID_VALID_LISTTYPE, FID_VALID_LISTTYPE,
88 "modules/scalc/ui/validationdialog.ui",
"ValidationDialog", pArgSet, nullptr)
89 , m_pTabVwSh(pTabViewSh)
90 , m_sValuePageId(
"criteria")
91 , m_bOwnRefHdlr(false)
92 , m_bRefInputting(false)
93 , m_xHBox(m_xBuilder->weld_container(
"refinputbox"))
101 m_xBuilder->weld_button(
"cancel")->hide();
102 m_xBuilder->weld_button(
"help")->hide();
141 pValidationDlg->RefInputDone();
176 weld::Container* pOldParent = pValidationDlg->get_refinput_shrink_parent();
192 ScViewData& rViewData = pValidationDlg->GetTabViewShell()->GetViewData();
197 if ( nCurTab != nRefTab )
223 default: OSL_FAIL(
"lclGetPosFromValMode - unknown validity mode" );
243 default: OSL_FAIL(
"lclGetValModeFromPos - invalid list box position" );
264 default: OSL_FAIL(
"lclGetPosFromCondMode - unknown condition mode" );
284 default: OSL_FAIL(
"lclGetCondModeFromPos - invalid list box position" );
293 void lclGetFormulaFromStringList( OUString& rFmlaStr,
const OUString& rStringList,
sal_Unicode cFmlaSep )
296 if (!rStringList.isEmpty())
301 OUString aToken {rStringList.getToken( 0,
'\n', nIdx )};
307 if( rFmlaStr.isEmpty() )
316 bool lclGetStringListFromFormula( OUString& rStringList,
const OUString& rFmlaStr,
sal_Unicode cFmlaSep )
318 const OUString aQuotes(
"\"\"" );
321 bool bIsStringList = !rFmlaStr.isEmpty();
322 bool bTokenAdded =
false;
324 for ( sal_Int32 nStringIx = 0; bIsStringList && nStringIx>=0; )
328 if( !aToken.isEmpty() )
340 return bIsStringList;
346 :
SfxTabPage(pPage, pController,
"modules/scalc/ui/validationcriteriapage.ui",
347 "ValidationCriteriaPage", &rArgSet)
348 , maStrMin(
ScResId(SCSTR_VALID_MINIMUM))
349 , maStrMax(
ScResId(SCSTR_VALID_MAXIMUM))
350 , maStrValue(
ScResId(SCSTR_VALID_VALUE))
351 , maStrFormula(
ScResId(SCSTR_VALID_FORMULA))
352 , maStrRange(
ScResId(SCSTR_VALID_RANGE))
353 , maStrList(
ScResId(SCSTR_VALID_LIST))
354 , m_pRefEdit(nullptr)
355 , m_xLbAllow(m_xBuilder->weld_combo_box(
"allow"))
356 , m_xCbAllow(m_xBuilder->weld_check_button(
"allowempty"))
357 , m_xCbShow(m_xBuilder->weld_check_button(
"showlist"))
358 , m_xCbSort(m_xBuilder->weld_check_button(
"sortascend"))
359 , m_xFtValue(m_xBuilder->weld_label(
"valueft"))
360 , m_xLbValue(m_xBuilder->weld_combo_box(
"data"))
361 , m_xFtMin(m_xBuilder->weld_label(
"minft"))
362 , m_xMinGrid(m_xBuilder->weld_widget(
"mingrid"))
363 , m_xEdMin(new
formula::RefEdit(m_xBuilder->weld_entry(
"min")))
364 , m_xEdList(m_xBuilder->weld_text_view(
"minlist"))
365 , m_xFtMax(m_xBuilder->weld_label(
"maxft"))
366 , m_xEdMax(new
formula::RefEdit(m_xBuilder->weld_entry(
"max")))
367 , m_xFtHint(m_xBuilder->weld_label(
"hintft"))
368 , m_xBtnRef(new
formula::RefButton(m_xBuilder->weld_button(
"validref")))
369 , m_xRefGrid(m_xBuilder->weld_container(
"refgrid"))
370 , m_pRefEditParent(m_xRefGrid.
get())
371 , m_pBtnRefParent(m_xRefGrid.
get())
377 m_xEdList->set_size_request(aSize.Width(), aSize.Height());
384 m_xContainer->set_size_request(aSize.Width(), aSize.Height());
390 OSL_ENSURE( aListSep.getLength() == 1,
"ScTPValidationValue::ScTPValidationValue - list separator error" );
391 mcFmlaSep = aListSep.getLength() ? aListSep[0] :
';';
424 return std::make_unique<ScTPValidationValue>(pPage, pController, *rArgSet);
432 if( rArgSet->
GetItemState( FID_VALID_MODE,
true, &pItem ) == SfxItemState::SET )
433 nLbPos = lclGetPosFromValMode( static_cast< ScValidationMode >(
434 static_cast< const SfxUInt16Item* >( pItem )->
GetValue() ) );
438 if( rArgSet->
GetItemState( FID_VALID_CONDMODE,
true, &pItem ) == SfxItemState::SET )
439 nLbPos = lclGetPosFromCondMode( static_cast< ScConditionMode >(
440 static_cast< const SfxUInt16Item* >( pItem )->
GetValue() ) );
445 if( rArgSet->
GetItemState( FID_VALID_BLANK,
true, &pItem ) == SfxItemState::SET )
446 bCheck = static_cast< const SfxBoolItem* >( pItem )->GetValue();
449 sal_Int32 nListType = ValidListType::UNSORTED;
450 if( rArgSet->
GetItemState( FID_VALID_LISTTYPE,
true, &pItem ) == SfxItemState::SET )
451 nListType = static_cast< const SfxInt16Item* >( pItem )->GetValue();
452 m_xCbShow->set_active( nListType != ValidListType::INVISIBLE );
453 m_xCbSort->set_active( nListType == ValidListType::SORTEDASCENDING );
457 if ( rArgSet->
GetItemState( FID_VALID_VALUE1,
true, &pItem ) == SfxItemState::SET )
458 aFmlaStr = static_cast< const SfxStringItem* >( pItem )->GetValue();
462 if ( rArgSet->
GetItemState( FID_VALID_VALUE2,
true, &pItem ) == SfxItemState::SET )
463 aFmlaStr = static_cast< const SfxStringItem* >( pItem )->GetValue();
472 sal_Int16 nListType =
m_xCbShow->get_active() ?
473 (
m_xCbSort->get_active() ? ValidListType::SORTEDASCENDING : ValidListType::UNSORTED) :
474 ValidListType::INVISIBLE;
476 const sal_Int32 nLbPos =
m_xLbAllow->get_active();
481 rArgSet->
Put(
SfxUInt16Item( FID_VALID_MODE, sal::static_int_cast<sal_uInt16>(
482 lclGetValModeFromPos( nLbPos ) ) ) );
483 rArgSet->
Put(
SfxUInt16Item( FID_VALID_CONDMODE, sal::static_int_cast<sal_uInt16>( eCondMode ) ) );
511 lclGetStringListFromFormula( aStringList, rFmlaStr,
mcFmlaSep ) )
538 if( !pValidationDlg )
552 if (
m_xEdMax->GetWidget()->get_visible())
557 else if (
m_xEdMin->GetWidget()->get_visible())
575 if( !pValidationDlg )
591 m_xBtnRef->SetReferences(
nullptr,
nullptr );
596 const sal_Int32
nPos = m_xLbAllow->get_active();
606 if (&rWnd != m_pRefEdit)
610 if (pValidationDlg->IsChildFocus() && !pValidationDlg->IsRefInputting())
612 if( ( !m_pRefEdit || !m_pRefEdit->GetWidget()->has_focus()) && !m_xBtnRef->GetWidget()->has_focus() )
622 if( &rWnd != m_xBtnRef.get())
625 if (pValidationDlg->IsChildFocus() && !pValidationDlg->IsRefInputting())
626 if( ( !m_pRefEdit || !m_pRefEdit->GetWidget()->has_focus()) && !m_xBtnRef->GetWidget()->has_focus() )
634 const sal_Int32 nLbPos = m_xLbAllow->get_active();
640 m_xCbAllow->set_sensitive( bEnable );
641 m_xFtValue->set_sensitive( bEnable );
642 m_xLbValue->set_sensitive( bEnable );
643 m_xFtMin->set_sensitive( bEnable );
644 m_xEdMin->GetWidget()->set_sensitive( bEnable );
645 m_xEdList->set_sensitive( bEnable );
646 m_xFtMax->set_sensitive( bEnable );
647 m_xEdMax->GetWidget()->set_sensitive( bEnable );
649 bool bShowMax =
false;
652 m_xFtMin->set_label( maStrRange );
654 m_xFtMin->set_label( maStrList );
656 m_xFtMin->set_label( maStrFormula );
659 switch( m_xLbValue->get_active() )
674 OSL_FAIL(
"ScTPValidationValue::SelectHdl - unknown condition mode" );
678 m_xCbShow->set_visible( bRange || bList );
679 m_xCbSort->set_visible( bRange || bList );
680 m_xFtValue->set_visible( !bRange && !bList && !bCustom);
681 m_xLbValue->set_visible( !bRange && !bList && !bCustom );
682 m_xEdMin->GetWidget()->set_visible( !bList );
683 m_xEdList->set_visible( bList );
684 m_xMinGrid->set_vexpand( bList );
685 m_xFtMax->set_visible( bShowMax );
686 m_xEdMax->GetWidget()->set_visible( bShowMax );
687 m_xFtHint->set_visible( bRange );
688 m_xBtnRef->GetWidget()->set_visible( bRange );
693 m_xCbSort->set_sensitive( m_xCbShow->get_active() );
699 :
SfxTabPage(pPage, pController,
IS_MOBILE ? OUString(
"modules/scalc/ui/validationhelptabpage-mobile.ui")
700 : OUString(
"modules/scalc/ui/validationhelptabpage.ui"),
"ValidationHelpTabPage", &rArgSet)
701 , m_xTsbHelp(m_xBuilder->weld_check_button(
"tsbhelp"))
702 , m_xEdtTitle(m_xBuilder->weld_entry(
"title"))
703 , m_xEdInputHelp(m_xBuilder->weld_text_view(
"inputhelp"))
715 return std::make_unique<ScTPValidationHelp>(pPage, pController, *rArgSet);
722 if ( rArgSet->
GetItemState( FID_VALID_SHOWHELP,
true, &pItem ) == SfxItemState::SET )
727 if ( rArgSet->
GetItemState( FID_VALID_HELPTITLE,
true, &pItem ) == SfxItemState::SET )
728 m_xEdtTitle->set_text( static_cast<const SfxStringItem*>(pItem)->GetValue() );
732 if ( rArgSet->
GetItemState( FID_VALID_HELPTEXT,
true, &pItem ) == SfxItemState::SET )
733 m_xEdInputHelp->set_text( static_cast<const SfxStringItem*>(pItem)->GetValue() );
753 IS_MOBILE ? OUString(
"modules/scalc/ui/erroralerttabpage-mobile.ui")
754 : OUString(
"modules/scalc/ui/erroralerttabpage.ui"),
"ErrorAlertTabPage",
756 , m_xTsbShow(m_xBuilder->weld_check_button(
"tsbshow"))
757 , m_xLbAction(m_xBuilder->weld_combo_box(
"actionCB"))
758 , m_xBtnSearch(m_xBuilder->weld_button(
"browseBtn"))
759 , m_xEdtTitle(m_xBuilder->weld_entry(
"erroralert_title"))
760 , m_xFtError(m_xBuilder->weld_label(
"errormsg_label"))
761 , m_xEdError(m_xBuilder->weld_text_view(
"errorMsg"))
784 return std::make_unique<ScTPValidationError>(pPage, pController, *rArgSet);
791 if ( rArgSet->
GetItemState( FID_VALID_SHOWERR,
true, &pItem ) == SfxItemState::SET )
796 if ( rArgSet->
GetItemState( FID_VALID_ERRSTYLE,
true, &pItem ) == SfxItemState::SET )
797 m_xLbAction->set_active( static_cast<const SfxUInt16Item*>(pItem)->GetValue() );
801 if ( rArgSet->
GetItemState( FID_VALID_ERRTITLE,
true, &pItem ) == SfxItemState::SET )
802 m_xEdtTitle->set_text( static_cast<const SfxStringItem*>(pItem)->GetValue() );
806 if ( rArgSet->
GetItemState( FID_VALID_ERRTEXT,
true, &pItem ) == SfxItemState::SET )
807 m_xEdError->set_text( static_cast<const SfxStringItem*>(pItem)->GetValue() );
829 m_xBtnSearch->set_sensitive( bMacro );
830 m_xFtError->set_sensitive( !bMacro );
831 m_xEdError->set_sensitive( !bMacro );
840 if ( !aScriptURL.isEmpty() )
842 m_xEdtTitle->set_text( aScriptURL );
850 if( !pTabViewShell )
return false;
856 if (pWnd && pWnd->
GetController().get() !=
this) pWnd =
nullptr;
858 SC_MOD()->SetRefDialog( nId, pWnd ==
nullptr );
867 if( !pTabViewShell )
return false;
893 bool bVisLock =
false;
894 bool bFreeWindowLock =
false;
898 if( !pTabVwSh )
return false;
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
std::shared_ptr< SfxDialogController > & GetController()
SfxViewFrame * GetViewFrame() const
#define LINK(Instance, Class, Member)
SfxChildWindow * GetChildWindow(sal_uInt16)
#define SC_VALIDDLG_DATA_LESS
std::unique_ptr< weld::CheckButton > m_xCbSort
Show selection list in cell.
ScTPValidationError(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rArgSet)
#define SC_VALIDDLG_ALLOW_ANY
std::unique_ptr< weld::TextView > m_xEdError
void SetRefInputDonePostHdl(void(ScRefHandlerCaller::*pNewHdl)())
virtual void EndDialog() override
OUString GetFirstFormula() const
IMPL_LINK_NOARG(ScTPValidationValue, EditSetFocusHdl, formula::RefEdit &, void)
ScValidationDlg * GetValidationDlg()
std::unique_ptr< weld::Label > m_xFtMin
void SetFirstFormula(const OUString &rFmlaStr)
void SetHandler(ScRefHandlerCaller *pNewHandler)
#define SC_VALIDDLG_DATA_NOTEQUAL
std::unique_ptr< weld::Container > m_xRefGrid
weld::Container * get_refinput_shrink_parent()
#define SC_VALIDDLG_ALLOW_DECIMAL
virtual bool FillItemSet(SfxItemSet *rArgSet) override
std::unique_ptr< weld::Entry > m_xEdtTitle
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
std::unique_ptr< weld::TextView > m_xEdList
#define SC_VALIDDLG_DATA_INVALIDRANGE
#define SC_VALIDDLG_ALLOW_TEXTLEN
#define SC_VALIDDLG_ALLOW_LIST
void SetSetActHdl(PCOMMONHDLTYPE pNewHdl)
#define SC_VALIDDLG_DATA_EQUAL
Reference< XNameAccess > m_xContainer
The tab page "Criteria" from the Validation dialog.
static SC_DLLPUBLIC void EraseQuotes(OUString &rString, sal_Unicode cQuote, bool bUnescapeEmbedded=true)
Erases the character cQuote from rString, if it exists at beginning AND end.
virtual void Reset(const SfxItemSet *rArgSet) override
#define SC_VALIDDLG_DATA_DIRECT
std::unique_ptr< weld::ComboBox > m_xLbValue
std::unique_ptr< weld::Entry > m_xEdtTitle
#define SC_VALIDDLG_ALLOW_TIME
#define SC_VALIDDLG_ALLOW_RANGE
#define SC_VALIDDLG_DATA_GREATER
#define SC_VALIDDLG_ALLOW_DATE
void RefInputStartPreHdl(formula::RefEdit *pEdit, const formula::RefButton *pButton)
ScTabViewShell * GetViewShell() const
static OUString ChooseScript(weld::Window *pParent)
std::unique_ptr< weld::ComboBox > m_xLbAllow
#define SC_VALIDDLG_ALLOW_CUSTOM
#define SC_VALIDDLG_DATA_EQLESS
std::unique_ptr< weld::TextView > m_xEdInputHelp
static const sal_uInt16 pValueRanges[]
void SetRefInputStartPreHdl(PINPUTSTARTDLTYPE pNewHdl)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
std::unique_ptr< weld::CheckButton > m_xTsbHelp
The "Validity" tab dialog.
formula::RefEdit * m_pRefEdit
void RefInputDonePostHdl()
#define SC_VALIDDLG_DATA_EQGREATER
SC_DLLPUBLIC OUString Format(const ScDocument &rDocument, ScRefFlags nFlags=ScRefFlags::ZERO, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, bool bFullAddressNotation=false) const
Returns string with formatted cell range from aStart to aEnd, according to provided address conventio...
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rArgSet)
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
ScTabViewShell * GetTabViewShell()
virtual ~ScTPValidationHelp() override
virtual ~ScValidationDlg() override
virtual ~ScTPValidationError() override
OUString ScResId(const char *pId)
virtual bool FillItemSet(SfxItemSet *rArgSet) override
virtual void move(weld::Widget *pWidget, weld::Container *pNewParent)=0
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rArgSet)
std::unique_ptr< weld::ComboBox > m_xLbAction
void SetModal(bool bModal)
bool RemoveRefDlg(bool bRestoreModal)
#define SC_VALIDDLG_ALLOW_WHOLE
std::unique_ptr< formula::RefEdit > m_xEdMin
OUString GetSecondFormula() const
std::unique_ptr< weld::CheckButton > m_xCbAllow
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
ScTPValidationValue(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rArgSet)
ScTPValidationHelp(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rArgSet)
#define SC_VALIDDLG_DATA_VALIDRANGE
void RemoveRefDlg(bool bRestoreModal)
static SC_DLLPUBLIC OUString addToken(const OUString &rTokenList, const OUString &rToken, sal_Unicode cSep, sal_Int32 nSepCount=1, bool bForceSep=false)
Adds the string rToken to rTokenList, using a list separator character.
weld::Container * m_pBtnRefParent
std::unique_ptr< weld::CheckButton > m_xTsbShow
OString strip(const OString &rIn, char c)
static OUString SC_DLLPUBLIC GetQuotedToken(const OUString &rIn, sal_Int32 nToken, const OUString &rQuotedPairs, sal_Unicode cTok, sal_Int32 &rIndex)
void SetSetRefHdl(PFUNCSETREFHDLTYPE pNewHdl)
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
Reference< XExecutableDialog > m_xDialog
SfxOkDialogController * GetDialogController() const
virtual ~ScTPValidationValue() override
std::unique_ptr< weld::Label > m_xFtMax
Entries for explicit list.
virtual bool FillItemSet(SfxItemSet *rArgSet) override
virtual void Reset(const SfxItemSet *rArgSet) override
virtual void Reset(const SfxItemSet *rArgSet) override
void SetReferenceHdl(const ScRange &, const ScDocument &)
ScValidationDlg(weld::Window *pParent, const SfxItemSet *pArgSet, ScTabViewShell *pTabViewSh)
const std::u16string_view aStringList[]
std::unique_ptr< weld::CheckButton > m_xCbShow
Allow blank cells.
SCTAB GetRefTabNo() const
bool IsChildFocus() const
std::unique_ptr< weld::Button > m_xBtnSearch
std::unique_ptr< formula::RefEdit > m_xEdMax
weld::Container * m_pRefEditParent
static SC_DLLPUBLIC bool IsQuoted(const OUString &rString, sal_Unicode cQuote)
Returns true, if the first and last character of the string is cQuote.
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rArgSet)
bool DoClose(sal_uInt16 nId)
std::unique_ptr< formula::RefButton > m_xBtnRef
Hint text for cell range validity.
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
static SC_DLLPUBLIC void AddQuotes(OUString &rString, sal_Unicode cQuote, bool bEscapeEmbedded=true)
Inserts the character cQuote at beginning and end of rString.
IMPL_LINK(ScTPValidationValue, KillEditFocusHdl, formula::RefEdit &, rWnd, void)
void SetSecondFormula(const OUString &rFmlaStr)