21#include <document.hxx>
36 VclMessageType::Warning, VclButtonsType::Ok,
44 VclMessageType::Question, VclButtonsType::YesNo,
46 xBox->set_default_response(RET_YES);
64 , m_rViewData(rViewData)
65 , rDoc(rViewData.GetDocument())
66 , bDlgLostFocus(false)
67 , m_pEdActive(nullptr)
68 , m_xLbRange(m_xBuilder->weld_tree_view(
"range"))
69 , m_xEdAssign(new
formula::RefEdit(m_xBuilder->weld_entry(
"edassign")))
70 , m_xRbAssign(new
formula::RefButton(m_xBuilder->weld_button(
"rbassign")))
71 , m_xBtnColHead(m_xBuilder->weld_radio_button(
"colhead"))
72 , m_xBtnRowHead(m_xBuilder->weld_radio_button(
"rowhead"))
73 , m_xEdAssign2(new
formula::RefEdit(m_xBuilder->weld_entry(
"edassign2")))
74 , m_xRbAssign2(new
formula::RefButton(m_xBuilder->weld_button(
"rbassign2")))
75 , m_xBtnOk(m_xBuilder->weld_button(
"ok"))
76 , m_xBtnCancel(m_xBuilder->weld_button(
"cancel"))
77 , m_xBtnAdd(m_xBuilder->weld_button(
"add"))
78 , m_xBtnRemove(m_xBuilder->weld_button(
"delete"))
79 , m_xRangeFrame(m_xBuilder->weld_frame(
"rangeframe"))
80 , m_xRangeFT(m_xRangeFrame->weld_label_widget())
81 , m_xDataFT(m_xBuilder->weld_label(
"datarange"))
136 nEndCol, nEndRow, nEndTab );
158 if ( (
static_cast<SCCOLROW>(nCol2 - nCol1) >= nRow2 - nRow1) || (nCol1 == 0 && nCol2 ==
rDoc.
MaxCol()) )
315 DoClose( ScColRowNameRangesDlgWrapper::GetChildWindowId() );
356 OUString strDelim(
" --- ");
357 OUString aString = strDelim +
ScResId( STR_COLUMN ) + strDelim;
361 std::vector<const ScRangePair*> aSortArray(
xColNameRanges->CreateNameSortedArray(
363 nCount = aSortArray.size();
364 for ( j=0; j <
nCount; j++ )
366 const ScRange aRange(aSortArray[j]->GetRange(0));
370 aSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
371 nCol2, nRow2, nTab2 );
375 OUStringBuffer strShow =
" [";
377 strShow.append(rString);
380 strShow.append(
", ");
382 strShow.append(rString);
386 strShow.append(
", ...");
391 OUString aInsStr = aString + strShow;
396 aString = strDelim +
ScResId( STR_ROW ) + strDelim;
400 std::vector<const ScRangePair*> aSortArray(
xRowNameRanges->CreateNameSortedArray(
402 nCount = aSortArray.size();
403 for ( j=0; j <
nCount; j++ )
405 const ScRange aRange(aSortArray[j]->GetRange(0));
409 aSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
410 nCol2, nRow2, nTab2 );
413 OUStringBuffer strShow =
" [";
415 strShow.append(rString);
418 strShow.append(
", ");
420 strShow.append(rString);
424 strShow.append(
", ...");
428 OUString aInsStr = aString + strShow;
441 if ( bColName && (pPair =
xColNameRanges->Find( rRange )) !=
nullptr )
443 else if ( !bColName && (pPair =
xRowNameRanges->Find( rRange )) !=
nullptr )
482 AddBtnHdl(*m_xBtnAdd);
485 rDoc.GetColNameRangesRef() = xColNameRanges;
486 rDoc.GetRowNameRangesRef() = xRowNameRanges;
488 rDoc.CompileColRowNameFormula();
489 ScDocShell* pDocShell = m_rViewData.GetDocShell();
504 OUString aNewArea( m_xEdAssign->GetText() );
505 OUString aNewData( m_xEdAssign2->GetText() );
507 if (aNewArea.isEmpty() || aNewData.isEmpty())
515 theCurArea = aRange1;
516 AdjustColRowData( aRange2 );
518 if ( ( pPair = xColNameRanges->Find( theCurArea ) ) !=
nullptr )
520 xColNameRanges->Remove( *pPair );
522 if ( ( pPair = xRowNameRanges->Find( theCurArea ) ) !=
nullptr )
524 xRowNameRanges->Remove( *pPair );
526 if ( m_xBtnColHead->get_active() )
527 xColNameRanges->Join(
ScRangePair( theCurArea, theCurData ) );
529 xRowNameRanges->Join(
ScRangePair( theCurArea, theCurData ) );
533 m_xEdAssign->GrabFocus();
534 m_xBtnAdd->set_sensitive(
false);
535 m_xBtnRemove->set_sensitive(
false);
536 m_xEdAssign->SetText( OUString() );
537 m_xBtnColHead->set_active(
true);
538 m_xBtnRowHead->set_active(
false);
539 m_xEdAssign2->SetText( OUString() );
541 theCurData = theCurArea;
542 Range1SelectHdl( *m_xLbRange );
548 m_xEdAssign->GrabFocus();
550 m_xEdAssign2->GrabFocus();
556 OUString aRangeStr = m_xLbRange->get_selected_text();
557 sal_Int32 nSelectPos = m_xLbRange->get_selected_index();
558 bool bColName = nSelectPos != -1 && m_xLbRange->get_id(nSelectPos).toInt32() ==
nEntryDataCol;
559 NameRangeMap::const_iterator itr = aRangeMap.find(aRangeStr);
560 if (itr == aRangeMap.end())
562 const ScRange& rRange = itr->second;
566 if ( bColName && (pPair = xColNameRanges->Find( rRange )) !=
nullptr )
568 else if ( !bColName && (pPair = xRowNameRanges->Find( rRange )) !=
nullptr )
573 OUString aStrDelMsg =
ScResId( STR_QUERY_DELENTRY );
582 xColNameRanges->Remove( *pPair );
584 xRowNameRanges->Remove( *pPair );
587 const sal_Int32 nCnt = m_xLbRange->n_children();
588 if ( nSelectPos >= nCnt )
591 nSelectPos = nCnt - 1;
595 m_xLbRange->select(nSelectPos);
596 if (nSelectPos && m_xLbRange->get_id(nSelectPos).toInt32() ==
nEntryDataDelim)
597 m_xLbRange->select( --nSelectPos );
599 m_xLbRange->grab_focus();
600 m_xBtnAdd->set_sensitive(
false);
601 m_xBtnRemove->set_sensitive(
false);
602 m_xEdAssign->SetText( OUString() );
603 theCurArea = theCurData =
ScRange();
604 m_xBtnColHead->set_active(
true);
605 m_xBtnRowHead->set_active(
false);
606 m_xEdAssign2->SetText( OUString() );
607 Range1SelectHdl( *m_xLbRange );
613 sal_Int32 nSelectPos = m_xLbRange->get_selected_index();
614 const sal_Int32 nCnt = m_xLbRange->n_children();
615 sal_uInt16 nMoves = 0;
616 while (nSelectPos != -1 && nSelectPos < nCnt && m_xLbRange->get_id(nSelectPos).
toInt32() ==
nEntryDataDelim)
621 OUString aRangeStr = m_xLbRange->get_selected_text();
624 if ( nSelectPos > 1 && nSelectPos >= nCnt )
627 nSelectPos = nCnt - 2;
628 m_xLbRange->select(nSelectPos);
629 aRangeStr = m_xLbRange->get_selected_text();
631 else if ( nSelectPos > 2 && nSelectPos < nCnt && !aRangeStr.isEmpty()
632 && aRangeStr == m_xEdAssign->GetText() )
635 m_xLbRange->select( nSelectPos );
636 aRangeStr = m_xLbRange->get_selected_text();
639 m_xLbRange->select(nSelectPos);
641 NameRangeMap::const_iterator itr = aRangeMap.find(aRangeStr);
642 if ( itr != aRangeMap.end() )
644 bool bColName = m_xLbRange->get_id(nSelectPos).toInt32() ==
nEntryDataCol;
645 UpdateRangeData( itr->second, bColName );
646 m_xBtnAdd->set_sensitive(
false);
647 m_xBtnRemove->set_sensitive(
true);
651 if ( !m_xEdAssign->GetText().isEmpty() )
653 if ( !m_xEdAssign2->GetText().isEmpty() )
654 m_xBtnAdd->set_sensitive(
true);
656 m_xBtnAdd->set_sensitive(
false);
657 m_xBtnColHead->set_sensitive(
true);
658 m_xBtnRowHead->set_sensitive(
true);
659 m_xEdAssign2->GetWidget()->set_sensitive(
true);
660 m_xRbAssign2->GetWidget()->set_sensitive(
true);
664 m_xBtnAdd->set_sensitive(
false);
665 m_xBtnColHead->set_sensitive(
false);
666 m_xBtnRowHead->set_sensitive(
false);
667 m_xEdAssign2->GetWidget()->set_sensitive(
false);
668 m_xRbAssign2->GetWidget()->set_sensitive(
false);
670 m_xBtnRemove->set_sensitive(
false);
671 m_xEdAssign->GrabFocus();
674 m_xEdAssign->GetWidget()->set_sensitive(
true);
675 m_xRbAssign->GetWidget()->set_sensitive(
true);
681 OUString aNewArea( m_xEdAssign->GetText() );
683 if (!aNewArea.isEmpty())
688 SetColRowData( aRange );
694 m_xBtnAdd->set_sensitive(
true);
695 m_xBtnColHead->set_sensitive(
true);
696 m_xBtnRowHead->set_sensitive(
true);
697 m_xEdAssign2->GetWidget()->set_sensitive(
true);
698 m_xRbAssign2->GetWidget()->set_sensitive(
true);
702 m_xBtnAdd->set_sensitive(
false);
703 m_xBtnColHead->set_sensitive(
false);
704 m_xBtnRowHead->set_sensitive(
false);
705 m_xEdAssign2->GetWidget()->set_sensitive(
false);
706 m_xRbAssign2->GetWidget()->set_sensitive(
false);
708 m_xBtnRemove->set_sensitive(
false);
714 OUString aNewData( m_xEdAssign2->GetText() );
715 if ( !aNewData.isEmpty() )
720 AdjustColRowData( aRange );
721 m_xBtnAdd->set_sensitive(
true);
724 m_xBtnAdd->set_sensitive(
false);
728 m_xBtnAdd->set_sensitive(
false);
734 if (m_xBtnColHead->get_active())
737 if ( theCurArea.aStart.Row() == 0 && theCurArea.aEnd.Row() == rDoc.MaxRow() )
739 theCurArea.aEnd.SetRow( rDoc.MaxRow() - 1 );
741 m_xEdAssign->SetText(
aStr );
746 AdjustColRowData( aRange );
748 else if (m_xBtnRowHead->get_active())
751 if ( theCurArea.aStart.Col() == 0 && theCurArea.aEnd.Col() == rDoc.MaxCol() )
753 theCurArea.aEnd.SetCol( rDoc.MaxCol() - 1 );
755 m_xEdAssign->SetText(
aStr );
760 AdjustColRowData( aRange );
766 if (&rCtrl == m_xEdAssign.get())
767 m_pEdActive = m_xEdAssign.get();
768 else if (&rCtrl == m_xEdAssign2.get())
769 m_pEdActive = m_xEdAssign2.get();
771 m_pEdActive =
nullptr;
774 m_pEdActive->SelectAll();
779 if (&rCtrl == m_xRbAssign.get())
780 m_pEdActive = m_xEdAssign.get();
781 else if (&rCtrl == m_xRbAssign2.get())
782 m_pEdActive = m_xEdAssign2.get();
784 m_pEdActive =
nullptr;
787 m_pEdActive->SelectAll();
792 bDlgLostFocus = !
m_xDialog->has_toplevel_focus();
797 bDlgLostFocus = !
m_xDialog->has_toplevel_focus();
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
ScRangePairListRef xColNameRanges
std::unique_ptr< weld::Button > m_xBtnCancel
std::unique_ptr< weld::Button > m_xBtnAdd
std::unique_ptr< weld::Label > m_xRangeFT
std::unique_ptr< weld::Button > m_xBtnRemove
std::unique_ptr< formula::RefButton > m_xRbAssign2
std::unique_ptr< formula::RefButton > m_xRbAssign
void UpdateRangeData(const ScRange &rRange, bool bColName)
virtual ~ScColRowNameRangesDlg() override
void SetColRowData(const ScRange &rLabelRange, bool bRef=false)
std::unique_ptr< weld::Label > m_xDataFT
std::unique_ptr< weld::RadioButton > m_xBtnRowHead
std::unique_ptr< formula::RefEdit > m_xEdAssign
virtual void SetActive() override
std::unique_ptr< weld::TreeView > m_xLbRange
virtual void SetReference(const ScRange &rRef, ScDocument &rDoc) override
std::unique_ptr< weld::RadioButton > m_xBtnColHead
formula::RefEdit * m_pEdActive
ScColRowNameRangesDlg(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScViewData &rViewData)
void AdjustColRowData(const ScRange &rDataRange, bool bRef=false)
ScRangePairListRef xRowNameRanges
virtual bool IsRefInputMode() const override
std::unique_ptr< weld::Button > m_xBtnOk
std::unique_ptr< formula::RefEdit > m_xEdAssign2
virtual void Close() override
void SetDocumentModified()
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
ScRangePairList * GetRowNameRanges()
SC_DLLPUBLIC SCCOL MaxCol() const
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
SC_DLLPUBLIC SCROW MaxRow() const
ScRangePairList * GetColNameRanges()
SC_DLLPUBLIC OUString GetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const ScInterpreterContext *pContext=nullptr) const
ScRangePairList * Clone() const
const ScRange & GetRange(sal_uInt16 n) const
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...
bool Intersects(const ScRange &rRange) const
ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
virtual void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton=nullptr) override
virtual void RefInputDone(bool bForced=false) override
bool DoClose(sal_uInt16 nId)
ScMarkType GetSimpleArea(SCCOL &rStartCol, SCROW &rStartRow, SCTAB &rStartTab, SCCOL &rEndCol, SCROW &rEndRow, SCTAB &rEndTab) const
IMPL_LINK_NOARG(ScColRowNameRangesDlg, OkBtnHdl, weld::Button &, void)
const sal_uLong nEntryDataRow
const sal_uLong nEntryDataCol
const sal_uLong nEntryDataDelim
IMPL_LINK(ScColRowNameRangesDlg, GetEditFocusHdl, formula::RefEdit &, rCtrl, void)
#define LINK(Instance, Class, Member)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
sal_Int32 toInt32(std::u16string_view rStr)
OUString ScResId(TranslateId aId)
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW