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 <globstr.hrc>
13 #include <scresid.hxx>
14 #include <condformatdlg.hxx>
15 #include <document.hxx>
16 #include <conditio.hxx>
17 
19  ScDocument* pDoc, ScConditionalFormatList* pFormatList)
20  : mrTreeView(rTreeView)
21  , mpDoc(pDoc)
22  , mpFormatList(pFormatList)
23 {
26  setColSizes();
27 
28  Init();
29  mrTreeView.set_selection_mode(SelectionMode::Multiple);
31 }
32 
34 {
36 
37  if (mpFormatList)
38  {
39  int nRow = 0;
40  OUString sRangeStr;
41  for(const auto& rItem : *mpFormatList)
42  {
43  const ScRangeList& aRange = rItem->GetRange();
44  aRange.Format(sRangeStr, ScRefFlags::VALID, *mpDoc, mpDoc->GetAddressConvention());
45  mrTreeView.append(OUString::number(rItem->GetKey()), sRangeStr);
47  ++nRow;
48  }
49  }
50 
51  mrTreeView.thaw();
52 
53  if (mpFormatList && !mpFormatList->empty())
54  mrTreeView.select(0);
55 }
56 
58 {
59  auto aSelectedRows = mrTreeView.get_selected_rows();
60  std::sort(aSelectedRows.begin(), aSelectedRows.end());
61  for (auto it = aSelectedRows.rbegin(); it != aSelectedRows.rend(); ++it)
62  {
63  sal_Int32 nIndex = mrTreeView.get_id(*it).toInt32();
64  mpFormatList->erase(nIndex);
65  mrTreeView.remove(*it);
66  }
67 }
68 
70 {
71  int nEntry = mrTreeView.get_selected_index();
72  if (nEntry == -1)
73  return nullptr;
74 
75  sal_Int32 nIndex = mrTreeView.get_id(nEntry).toInt32();
76  return mpFormatList->GetFormat(nIndex);
77 }
78 
80 {
81  std::vector<int> aWidths;
82  aWidths.push_back(mrTreeView.get_size_request().Width() / 2);
84 }
85 
87  : GenericDialogController(pParent, "modules/scalc/ui/condformatmanager.ui", "CondFormatManager")
88  , m_bModified(false)
89  , m_xFormatList( pFormatList ? new ScConditionalFormatList(*pFormatList) : nullptr)
90  , m_xBtnAdd(m_xBuilder->weld_button("add"))
91  , m_xBtnRemove(m_xBuilder->weld_button("remove"))
92  , m_xBtnEdit(m_xBuilder->weld_button("edit"))
93  , m_xTreeView(m_xBuilder->weld_tree_view("CONTAINER"))
94  , m_xCtrlManager(new ScCondFormatManagerWindow(*m_xTreeView, pDoc, m_xFormatList.get()))
95 {
96  m_xBtnRemove->connect_clicked(LINK(this, ScCondFormatManagerDlg, RemoveBtnHdl));
97  m_xBtnEdit->connect_clicked(LINK(this, ScCondFormatManagerDlg, EditBtnClickHdl));
98  m_xBtnAdd->connect_clicked(LINK(this, ScCondFormatManagerDlg, AddBtnHdl));
99  m_xTreeView->connect_row_activated(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
100 
102 }
103 
105 {
106 }
107 
108 std::unique_ptr<ScConditionalFormatList> ScCondFormatManagerDlg::GetConditionalFormatList()
109 {
110  return std::move(m_xFormatList);
111 }
112 
114 {
115  bool bNewSensitivity = !m_xFormatList->empty();
116  m_xBtnRemove->set_sensitive(bNewSensitivity);
117  m_xBtnEdit->set_sensitive(bNewSensitivity);
118 }
119 
120 // Get the current conditional format selected.
121 //
123 {
124  return m_xCtrlManager->GetSelection();
125 }
126 
128 {
129  m_xCtrlManager->DeleteSelection();
130  m_bModified = true;
131  UpdateButtonSensitivity();
132 }
133 
135 {
136  EditBtnHdl(*m_xTreeView);
137 }
138 
140 {
141  ScConditionalFormat* pFormat = m_xCtrlManager->GetSelection();
142 
143  if (!pFormat)
144  return true;
145 
146  m_bModified = true;
147  m_xDialog->response( DLG_RET_EDIT );
148 
149  return true;
150 }
151 
153 {
154  m_bModified = true;
155  m_xDialog->response( DLG_RET_ADD );
156 }
157 
159 {
160  m_bModified = true;
162 }
163 
165 {
166  return m_bModified;
167 }
168 
169 /* 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
long Width() const
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:146
ScConditionalFormat * GetFormat(sal_uInt32 nKey)
Definition: conditio.cxx:2069
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:475
bool CondFormatsChanged() const
virtual void thaw()=0
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:1157
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
ScCondFormatManagerWindow(weld::TreeView &rTreeView, ScDocument *pDoc, ScConditionalFormatList *pFormatList)
#define DLG_RET_EDIT
virtual void remove(int pos)=0
virtual void select(int pos)=0
std::unique_ptr< weld::Button > m_xBtnRemove
ScCondFormatManagerDlg(weld::Window *pParent, ScDocument *pDoc, const ScConditionalFormatList *pFormatList)
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:2263
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