LibreOffice Module sc (master)  1
condformatmgr.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  */
9 
10 #include <condformatmgr.hxx>
11 #include <condformathelper.hxx>
12 #include <condformatdlg.hxx>
13 #include <document.hxx>
14 #include <conditio.hxx>
15 #include <o3tl/safeint.hxx>
16 
18  ScDocument& rDoc, ScConditionalFormatList* pFormatList)
19  : mrTreeView(rTreeView)
20  , mrDoc(rDoc)
21  , mpFormatList(pFormatList)
22 {
25  setColSizes();
26 
27  Init();
28  mrTreeView.set_selection_mode(SelectionMode::Multiple);
30 }
31 
33 {
35 
36  if (mpFormatList)
37  {
38  int nRow = 0;
39  OUString sRangeStr;
40  for(const auto& rItem : *mpFormatList)
41  {
42  const ScRangeList& aRange = rItem->GetRange();
44  mrTreeView.append(OUString::number(rItem->GetKey()), sRangeStr);
46  ++nRow;
47  }
48  }
49 
50  mrTreeView.thaw();
51 
52  if (mpFormatList && !mpFormatList->empty())
53  mrTreeView.select(0);
54 }
55 
57 {
58  auto aSelectedRows = mrTreeView.get_selected_rows();
59  std::sort(aSelectedRows.begin(), aSelectedRows.end());
60  for (auto it = aSelectedRows.rbegin(); it != aSelectedRows.rend(); ++it)
61  {
62  sal_Int32 nIndex = mrTreeView.get_id(*it).toInt32();
63  mpFormatList->erase(nIndex);
64  mrTreeView.remove(*it);
65  }
66 }
67 
69 {
70  int nEntry = mrTreeView.get_selected_index();
71  if (nEntry == -1)
72  return nullptr;
73 
74  sal_Int32 nIndex = mrTreeView.get_id(nEntry).toInt32();
75  return mpFormatList->GetFormat(nIndex);
76 }
77 
79 {
80  std::vector<int> aWidths
81  {
82  o3tl::narrowing<int>(mrTreeView.get_size_request().Width() / 2)
83  };
85 }
86 
88  : GenericDialogController(pParent, "modules/scalc/ui/condformatmanager.ui", "CondFormatManager")
89  , m_bModified(false)
90  , m_xFormatList( pFormatList ? new ScConditionalFormatList(*pFormatList) : nullptr)
91  , m_xBtnAdd(m_xBuilder->weld_button("add"))
92  , m_xBtnRemove(m_xBuilder->weld_button("remove"))
93  , m_xBtnEdit(m_xBuilder->weld_button("edit"))
94  , m_xTreeView(m_xBuilder->weld_tree_view("CONTAINER"))
95  , m_xCtrlManager(new ScCondFormatManagerWindow(*m_xTreeView, rDoc, m_xFormatList.get()))
96 {
97  m_xBtnRemove->connect_clicked(LINK(this, ScCondFormatManagerDlg, RemoveBtnHdl));
98  m_xBtnEdit->connect_clicked(LINK(this, ScCondFormatManagerDlg, EditBtnClickHdl));
99  m_xBtnAdd->connect_clicked(LINK(this, ScCondFormatManagerDlg, AddBtnHdl));
100  m_xTreeView->connect_row_activated(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
101 
103 }
104 
106 {
107 }
108 
109 std::unique_ptr<ScConditionalFormatList> ScCondFormatManagerDlg::GetConditionalFormatList()
110 {
111  return std::move(m_xFormatList);
112 }
113 
115 {
116  bool bNewSensitivity = !m_xFormatList->empty();
117  m_xBtnRemove->set_sensitive(bNewSensitivity);
118  m_xBtnEdit->set_sensitive(bNewSensitivity);
119 }
120 
121 // Get the current conditional format selected.
122 //
124 {
125  return m_xCtrlManager->GetSelection();
126 }
127 
129 {
130  m_xCtrlManager->DeleteSelection();
131  m_bModified = true;
132  UpdateButtonSensitivity();
133 }
134 
136 {
137  EditBtnHdl(*m_xTreeView);
138 }
139 
141 {
142  ScConditionalFormat* pFormat = m_xCtrlManager->GetSelection();
143 
144  if (!pFormat)
145  return true;
146 
147  m_bModified = true;
148  m_xDialog->response( DLG_RET_EDIT );
149 
150  return true;
151 }
152 
154 {
155  m_bModified = true;
156  m_xDialog->response( DLG_RET_ADD );
157 }
158 
160 {
161  m_bModified = true;
163 }
164 
166 {
167  return m_bModified;
168 }
169 
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
virtual void set_text(int row, const OUString &rText, int col=-1)=0
ScConditionalFormatList * mpFormatList
ScConditionalFormat * GetSelection()
std::unique_ptr< ScCondFormatManagerWindow > m_xCtrlManager
sal_Int32 nIndex
std::unique_ptr< weld::TreeView > m_xTreeView
ScConditionalFormat * GetCondFormatSelected()
void Format(OUString &, ScRefFlags nFlags, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, sal_Unicode cDelimiter=0, bool bFullAddressNotation=false) const
Definition: rangelst.cxx:132
ScConditionalFormat * GetFormat(sal_uInt32 nKey)
Definition: conditio.cxx:2073
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
bool CondFormatsChanged() const
virtual void thaw()=0
constexpr tools::Long Width() const
std::unique_ptr< ScConditionalFormatList > m_xFormatList
virtual void set_column_fixed_widths(const std::vector< int > &rWidths)=0
IMPL_LINK_NOARG(ScCondFormatManagerDlg, RemoveBtnHdl, weld::Button &, void)
static SC_DLLPUBLIC OUString GetExpression(const ScConditionalFormat &rFormat, const ScAddress &rPos)
virtual OUString get_id(int pos) const =0
std::unique_ptr< ScConditionalFormatList > GetConditionalFormatList()
weld::TreeView & mrTreeView
ScAddress GetTopLeftCorner() const
Definition: rangelst.cxx:1150
ScCondFormatManagerWindow(weld::TreeView &rTreeView, ScDocument &rDoc, ScConditionalFormatList *pFormatList)
virtual Size get_size_request() const =0
virtual int get_selected_index() const =0
std::unique_ptr< weld::Button > m_xBtnAdd
virtual void freeze()=0
#define DLG_RET_EDIT
virtual void remove(int pos)=0
virtual void select(int pos)=0
ScCondFormatManagerDlg(weld::Window *pParent, ScDocument &rDoc, const ScConditionalFormatList *pFormatList)
std::unique_ptr< weld::Button > m_xBtnRemove
virtual std::vector< int > get_selected_rows() const =0
Reference< XExecutableDialog > m_xDialog
virtual int get_height_rows(int nRows) const =0
virtual void set_selection_mode(SelectionMode eMode)=0
void append(TreeIter *pRet=nullptr)
void erase(sal_uLong nIndex)
Definition: conditio.cxx:2267
std::unique_ptr< weld::Button > m_xBtnEdit
virtual ~ScCondFormatManagerDlg() override
#define DLG_RET_ADD
virtual void set_size_request(int nWidth, int nHeight)=0
virtual void make_sorted()=0
virtual float get_approximate_digit_width() const =0
bool m_bDetectedRangeSegmentation false