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 
17  ScDocument& rDoc, ScConditionalFormatList* pFormatList)
18  : mrTreeView(rTreeView)
19  , mrDoc(rDoc)
20  , mpFormatList(pFormatList)
21 {
24  setColSizes();
25 
26  Init();
27  mrTreeView.set_selection_mode(SelectionMode::Multiple);
29 }
30 
32 {
34 
35  if (mpFormatList)
36  {
37  int nRow = 0;
38  OUString sRangeStr;
39  for(const auto& rItem : *mpFormatList)
40  {
41  const ScRangeList& aRange = rItem->GetRange();
43  mrTreeView.append(OUString::number(rItem->GetKey()), sRangeStr);
45  ++nRow;
46  }
47  }
48 
49  mrTreeView.thaw();
50 
51  if (mpFormatList && !mpFormatList->empty())
52  mrTreeView.select(0);
53 }
54 
56 {
57  auto aSelectedRows = mrTreeView.get_selected_rows();
58  std::sort(aSelectedRows.begin(), aSelectedRows.end());
59  for (auto it = aSelectedRows.rbegin(); it != aSelectedRows.rend(); ++it)
60  {
61  sal_Int32 nIndex = mrTreeView.get_id(*it).toInt32();
62  mpFormatList->erase(nIndex);
63  mrTreeView.remove(*it);
64  }
65 }
66 
68 {
69  int nEntry = mrTreeView.get_selected_index();
70  if (nEntry == -1)
71  return nullptr;
72 
73  sal_Int32 nIndex = mrTreeView.get_id(nEntry).toInt32();
74  return mpFormatList->GetFormat(nIndex);
75 }
76 
78 {
79  std::vector<int> aWidths;
80  aWidths.push_back(mrTreeView.get_size_request().Width() / 2);
82 }
83 
85  : GenericDialogController(pParent, "modules/scalc/ui/condformatmanager.ui", "CondFormatManager")
86  , m_bModified(false)
87  , m_xFormatList( pFormatList ? new ScConditionalFormatList(*pFormatList) : nullptr)
88  , m_xBtnAdd(m_xBuilder->weld_button("add"))
89  , m_xBtnRemove(m_xBuilder->weld_button("remove"))
90  , m_xBtnEdit(m_xBuilder->weld_button("edit"))
91  , m_xTreeView(m_xBuilder->weld_tree_view("CONTAINER"))
92  , m_xCtrlManager(new ScCondFormatManagerWindow(*m_xTreeView, rDoc, m_xFormatList.get()))
93 {
94  m_xBtnRemove->connect_clicked(LINK(this, ScCondFormatManagerDlg, RemoveBtnHdl));
95  m_xBtnEdit->connect_clicked(LINK(this, ScCondFormatManagerDlg, EditBtnClickHdl));
96  m_xBtnAdd->connect_clicked(LINK(this, ScCondFormatManagerDlg, AddBtnHdl));
97  m_xTreeView->connect_row_activated(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
98 
100 }
101 
103 {
104 }
105 
106 std::unique_ptr<ScConditionalFormatList> ScCondFormatManagerDlg::GetConditionalFormatList()
107 {
108  return std::move(m_xFormatList);
109 }
110 
112 {
113  bool bNewSensitivity = !m_xFormatList->empty();
114  m_xBtnRemove->set_sensitive(bNewSensitivity);
115  m_xBtnEdit->set_sensitive(bNewSensitivity);
116 }
117 
118 // Get the current conditional format selected.
119 //
121 {
122  return m_xCtrlManager->GetSelection();
123 }
124 
126 {
127  m_xCtrlManager->DeleteSelection();
128  m_bModified = true;
129  UpdateButtonSensitivity();
130 }
131 
133 {
134  EditBtnHdl(*m_xTreeView);
135 }
136 
138 {
139  ScConditionalFormat* pFormat = m_xCtrlManager->GetSelection();
140 
141  if (!pFormat)
142  return true;
143 
144  m_bModified = true;
145  m_xDialog->response( DLG_RET_EDIT );
146 
147  return true;
148 }
149 
151 {
152  m_bModified = true;
153  m_xDialog->response( DLG_RET_ADD );
154 }
155 
157 {
158  m_bModified = true;
160 }
161 
163 {
164  return m_bModified;
165 }
166 
167 /* 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:144
ScConditionalFormat * GetFormat(sal_uInt32 nKey)
Definition: conditio.cxx:2070
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:1154
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:2264
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