20#undef SC_DLLIMPLEMENTATION
26#include <osl/diagnose.h>
29#include <document.hxx>
51 :
SfxTabPage(pPage, pController,
"modules/scalc/ui/optsortlists.ui",
"OptSortLists",
53 , mxFtLists(m_xBuilder->weld_label(
"listslabel"))
54 , mxLbLists(m_xBuilder->weld_tree_view(
"lists"))
55 , mxFtEntries(m_xBuilder->weld_label(
"entrieslabel"))
56 , mxEdEntries(m_xBuilder->weld_text_view(
"entries"))
57 , mxFtCopyFrom(m_xBuilder->weld_label(
"copyfromlabel"))
58 , mxEdCopyFrom(m_xBuilder->weld_entry(
"copyfrom"))
59 , mxBtnNew(m_xBuilder->weld_button(
"new"))
60 , mxBtnDiscard(m_xBuilder->weld_button(
"discard"))
61 , mxBtnAdd(m_xBuilder->weld_button(
"add"))
62 , mxBtnModify(m_xBuilder->weld_button(
"modify"))
63 , mxBtnRemove(m_xBuilder->weld_button(
"delete"))
64 , mxBtnCopy(m_xBuilder->weld_button(
"copy"))
65 , aStrQueryRemove (
ScResId( STR_QUERYREMOVE ) )
66 , aStrCopyList (
ScResId( STR_COPYLIST ) )
67 , aStrCopyFrom (
ScResId( STR_COPYFROM ) )
68 , aStrCopyErr (
ScResId( STR_COPYERR ) )
69 , nWhichUserLists (
GetWhich( SID_SCUSERLISTS ) )
71 , pViewData ( nullptr )
72 , bModifyMode ( false )
73 , bCancelMode ( false )
112 nEndCol, nEndRow, nEndTab );
135 return std::make_unique<ScTpUserLists>(pPage, pController, *rAttrSet);
144 OSL_ENSURE( pCoreList,
"UserList not found :-/" );
200 bool bDataModified =
false;
202 if ( (
pUserLists ==
nullptr) && (pCoreList ==
nullptr) )
204 bDataModified =
false;
208 if ( pCoreList !=
nullptr )
211 bDataModified =
true;
221 rCoreAttrs->
Put( aULItem );
224 return bDataModified;
232 return DeactivateRC::LeavePage;
246 aEntry = (*pUserLists)[
i].GetString();
247 OSL_ENSURE( !aEntry.isEmpty(),
"Empty UserList-entry :-/" );
258 if ( nList < pUserLists->
size() )
262 OUStringBuffer aEntryListStr;
264 for (
size_t i=0;
i<nSubCount;
i++ )
267 aEntryListStr.append(
CR);
275 OSL_FAIL(
"Invalid ListIndex :-/" );
281 if (rListStr.isEmpty())
286 for(sal_Int32 nIdx=0; nIdx>=0;)
293 sal_Int32 nLen =
aStr.getLength();
301 rListStr += OUStringChar(
aStr[c]);
306 rListStr += OUStringChar(
aStr[c]);
317 OUString theEntriesStr( rEntriesStr );
339 if ( (nStartCol != nEndCol) && (nStartRow != nEndRow) )
342 nCellDir = aDialog.
run();
344 else if ( nStartCol != nEndCol )
351 bool bValueIgnored =
false;
357 OUStringBuffer aStrList;
358 for (
SCROW row=nStartRow; row<=nEndRow; row++ )
364 if ( !aStrField.isEmpty() )
366 aStrList.append(aStrField +
"\n");
370 bValueIgnored =
true;
372 if ( !aStrList.isEmpty() )
378 for (
SCROW row=nStartRow; row<=nEndRow; row++ )
380 OUStringBuffer aStrList;
387 if ( !aStrField.isEmpty() )
389 aStrList.append(aStrField +
"\n");
393 bValueIgnored =
true;
395 if ( !aStrList.isEmpty() )
403 VclMessageType::Info, VclButtonsType::Ok,
414 const OUString& rEntriesStr )
418 OUString theEntriesStr( rEntriesStr );
422 (*pUserLists)[nSelList].SetString( theEntriesStr );
435 if ( &rLb != mxLbLists.get() )
438 sal_Int32 nSelPos = mxLbLists->get_selected_index();
442 if ( !mxFtEntries->get_sensitive() ) mxFtEntries->set_sensitive(
true);
443 if ( !mxEdEntries->get_sensitive() ) mxEdEntries->set_sensitive(
true);
444 if ( !mxBtnRemove->get_sensitive() ) mxBtnRemove->set_sensitive(
true);
445 if ( mxBtnAdd->get_sensitive() )
447 mxBtnAdd->set_sensitive(
false);
448 mxBtnModify->set_sensitive(
false);
451 UpdateEntries( nSelPos );
456 if (&rBtn == mxBtnNew.get() || &rBtn == mxBtnDiscard.get())
460 nCancelPos = ( mxLbLists->n_children() > 0 )
461 ? mxLbLists->get_selected_index()
463 mxLbLists->unselect_all();
464 mxFtLists->set_sensitive(
false);
465 mxLbLists->set_sensitive(
false);
466 mxFtEntries->set_sensitive(
true);
467 mxEdEntries->set_sensitive(
true);
468 mxEdEntries->set_text( OUString() );
469 mxEdEntries->grab_focus();
470 mxBtnAdd->set_sensitive(
false);
471 mxBtnModify->set_sensitive(
false);
472 mxBtnRemove->set_sensitive(
false);
474 if ( mxBtnCopy->get_sensitive() )
476 mxBtnCopy->set_sensitive(
false);
477 mxFtCopyFrom->set_sensitive(
false);
478 mxEdCopyFrom->set_sensitive(
false);
481 mxBtnDiscard->show();
486 if ( mxLbLists->n_children() > 0 )
488 mxLbLists->select( nCancelPos );
489 LbSelectHdl( *mxLbLists );
490 mxFtLists->set_sensitive(
true);
491 mxLbLists->set_sensitive(
true);
495 mxFtEntries->set_sensitive(
false);
496 mxEdEntries->set_sensitive(
false);
497 mxEdEntries->set_text( OUString() );
498 mxBtnRemove->set_sensitive(
false);
500 mxBtnAdd->set_sensitive(
false);
501 mxBtnModify->set_sensitive(
false);
503 if ( pViewData && !bCopyDone )
505 mxBtnCopy->set_sensitive(
true);
506 mxFtCopyFrom->set_sensitive(
true);
507 mxEdCopyFrom->set_sensitive(
true);
510 mxBtnDiscard->hide();
515 else if (&rBtn == mxBtnAdd.get() || &rBtn == mxBtnModify.get())
517 OUString theEntriesStr( mxEdEntries->get_text() );
521 if ( !theEntriesStr.isEmpty() )
523 AddNewList( theEntriesStr );
525 mxLbLists->select( mxLbLists->n_children()-1 );
526 LbSelectHdl( *mxLbLists );
527 mxFtLists->set_sensitive(
true);
528 mxLbLists->set_sensitive(
true);
532 if ( mxLbLists->n_children() > 0 )
534 mxLbLists->select( nCancelPos );
535 LbSelectHdl( *mxLbLists );
536 mxLbLists->set_sensitive(
true);
537 mxLbLists->set_sensitive(
true);
541 mxBtnAdd->set_sensitive(
false);
542 mxBtnModify->set_sensitive(
false);
543 mxBtnRemove->set_sensitive(
true);
545 mxBtnDiscard->hide();
550 sal_Int32 nSelList = mxLbLists->get_selected_index();
552 OSL_ENSURE( nSelList != -1 ,
"Modify without List :-/" );
554 if ( !theEntriesStr.isEmpty() )
556 ModifyList( nSelList, theEntriesStr );
558 mxLbLists->select( nSelList );
562 mxLbLists->select( 0 );
563 LbSelectHdl( *mxLbLists );
567 mxBtnDiscard->hide();
571 mxBtnAdd->set_sensitive(
false);
572 mxBtnModify->set_sensitive(
false);
574 mxBtnRemove->set_sensitive(
true);
575 mxFtLists->set_sensitive(
true);
576 mxLbLists->set_sensitive(
true);
579 if ( pViewData && !bCopyDone )
581 mxBtnCopy->set_sensitive(
true);
582 mxFtCopyFrom->set_sensitive(
true);
583 mxEdCopyFrom->set_sensitive(
true);
586 else if ( &rBtn == mxBtnRemove.get() )
588 if ( mxLbLists->n_children() > 0 )
590 sal_Int32 nRemovePos = mxLbLists->get_selected_index();
592 + mxLbLists->get_text( nRemovePos )
596 VclMessageType::Question, VclButtonsType::YesNo,
598 xQueryBox->set_default_response(
RET_YES);
600 if (
RET_YES == xQueryBox->run())
602 RemoveList( nRemovePos );
605 if ( mxLbLists->n_children() > 0 )
608 ( nRemovePos >= mxLbLists->n_children() )
609 ? mxLbLists->n_children()-1
611 LbSelectHdl( *mxLbLists );
615 mxFtLists->set_sensitive(
false);
616 mxLbLists->set_sensitive(
false);
617 mxFtEntries->set_sensitive(
false);
618 mxEdEntries->set_sensitive(
false);
619 mxEdEntries->set_text( OUString() );
620 mxBtnRemove->set_sensitive(
false);
624 if ( pViewData && !bCopyDone && !mxBtnCopy->get_sensitive() )
626 mxBtnCopy->set_sensitive(
true);
627 mxFtCopyFrom->set_sensitive(
true);
628 mxEdCopyFrom->set_sensitive(
true);
632 else if ( pViewData && (&rBtn == mxBtnCopy.get()) )
639 OUString theAreaStr( mxEdCopyFrom->get_text() );
640 bool bAreaOk =
false;
642 if ( !theAreaStr.isEmpty() )
646 pViewData->GetTabNo(),
650 pDoc->GetAddressConvention() );
655 pViewData->GetTabNo(),
658 pDoc->GetAddressConvention() );
659 theEndPos = theStartPos;
665 CopyListFromArea( theStartPos, theEndPos );
667 mxLbLists->select( mxLbLists->n_children()-1 );
668 LbSelectHdl( *mxLbLists );
669 mxEdCopyFrom->set_text( theAreaStr );
670 mxEdCopyFrom->set_sensitive(
false);
671 mxBtnCopy->set_sensitive(
false);
672 mxFtCopyFrom->set_sensitive(
false);
677 VclMessageType::Warning, VclButtonsType::Ok,
681 mxEdCopyFrom->grab_focus();
682 mxEdCopyFrom->select_region(0, -1);
689 if ( &rEd != mxEdEntries.get() )
692 if ( mxBtnCopy->get_sensitive() )
694 mxBtnCopy->set_sensitive(
false);
695 mxFtCopyFrom->set_sensitive(
false);
696 mxEdCopyFrom->set_sensitive(
false);
699 if ( !mxEdEntries->get_text().isEmpty() )
701 if ( !bCancelMode && !bModifyMode )
704 mxBtnDiscard->show();
707 mxBtnAdd->set_sensitive(
true);
709 mxBtnModify->set_sensitive(
true);
711 mxBtnRemove->set_sensitive(
false);
712 mxFtLists->set_sensitive(
false);
713 mxLbLists->set_sensitive(
false);
717 if ( !mxBtnAdd->get_sensitive() )
719 mxBtnAdd->set_sensitive(
true);
720 mxBtnModify->set_sensitive(
true);
726 if ( mxBtnAdd->get_sensitive() )
728 mxBtnAdd->set_sensitive(
false);
729 mxBtnModify->set_sensitive(
false);
void PutInOrder(T &nStart, T &nEnd)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
SC_DLLPUBLIC bool HasStringData(SCCOL nCol, SCROW nRow, SCTAB nTab) const
SC_DLLPUBLIC OUString GetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const ScInterpreterContext *pContext=nullptr) const
static bool IsAbsArea(const OUString &rAreaStr, const ScDocument &rDoc, SCTAB nTab, OUString *pCompleteStr, ScRefAddress *pStartPos=nullptr, ScRefAddress *pEndPos=nullptr, ScAddress::Details const &rDetails=ScAddress::detailsOOOa1)
static bool IsAbsPos(const OUString &rPosStr, const ScDocument &rDoc, SCTAB nTab, OUString *pCompleteStr, ScRefAddress *pPosTripel=nullptr, ScAddress::Details const &rDetails=ScAddress::detailsOOOa1)
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...
ScViewData & GetViewData()
virtual ~ScTpUserLists() override
ScTpUserLists(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rArgSet)
std::unique_ptr< weld::TextView > mxEdEntries
virtual bool FillItemSet(SfxItemSet *rCoreAttrs) override
const sal_uInt16 nWhichUserLists
std::unique_ptr< weld::Button > mxBtnDiscard
std::unique_ptr< ScUserList > pUserLists
const OUString aStrCopyErr
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
std::unique_ptr< weld::Label > mxFtCopyFrom
void UpdateEntries(size_t nList)
std::unique_ptr< weld::Label > mxFtLists
const OUString aStrCopyFrom
OUString aStrSelectedArea
std::unique_ptr< weld::Button > mxBtnModify
const OUString aStrCopyList
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
std::unique_ptr< weld::Button > mxBtnNew
std::unique_ptr< weld::Button > mxBtnAdd
virtual void Reset(const SfxItemSet *rCoreAttrs) override
void AddNewList(const OUString &rEntriesStr)
std::unique_ptr< weld::Label > mxFtEntries
void CopyListFromArea(const ScRefAddress &rStartPos, const ScRefAddress &rEndPos)
void RemoveList(size_t nList)
std::unique_ptr< weld::Button > mxBtnCopy
std::unique_ptr< weld::Entry > mxEdCopyFrom
static void MakeListStr(OUString &rListStr)
std::unique_ptr< weld::Button > mxBtnRemove
void ModifyList(size_t nSelList, const OUString &rEntriesStr)
std::unique_ptr< weld::TreeView > mxLbLists
size_t UpdateUserListBox()
Stores individual user-defined sort list.
OUString GetSubStr(sal_uInt16 nIndex) const
size_t GetSubCount() const
ScUserList * GetUserList() const
void SetUserList(const ScUserList &rUserList)
Collection of user-defined sort lists.
ScDocument & GetDocument() const
ScMarkType GetSimpleArea(SCCOL &rStartCol, SCROW &rStartRow, SCTAB &rStartTab, SCCOL &rEndCol, SCROW &rEndRow, SCTAB &rEndTab) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const SfxItemSet & GetItemSet() const
void SetExchangeSupport()
weld::Window * GetFrameWeld() const
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
LineEnd GetSystemLineEnd()
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
#define LINK(Instance, Class, Member)
RttiCompleteObjectLocator col
OString strip(const OString &rIn, char c)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OUString ScResId(TranslateId aId)
const sal_Unicode cDelimiter
IMPL_LINK(ScTpUserLists, LbSelectHdl, weld::TreeView &, rLb, void)