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>
17
19 ScDocument& rDoc, ScConditionalFormatList* pFormatList)
20 : mrTreeView(rTreeView)
21 , mrDoc(rDoc)
22 , mpFormatList(pFormatList)
23{
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();
45 mrTreeView.append(OUString::number(rItem->GetKey()), sRangeStr);
47 ++nRow;
48 }
49 }
50
52
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();
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();
77}
78
80{
81 std::vector<int> aWidths
82 {
83 o3tl::narrowing<int>(mrTreeView.get_size_request().Width() / 2)
84 };
86}
87
89 : GenericDialogController(pParent, "modules/scalc/ui/condformatmanager.ui", "CondFormatManager")
90 , m_bModified(false)
91 , m_xFormatList( pFormatList ? new ScConditionalFormatList(*pFormatList) : nullptr)
92 , m_xBtnAdd(m_xBuilder->weld_button("add"))
93 , m_xBtnRemove(m_xBuilder->weld_button("remove"))
94 , m_xBtnEdit(m_xBuilder->weld_button("edit"))
95 , m_xTreeView(m_xBuilder->weld_tree_view("CONTAINER"))
96 , m_xCtrlManager(new ScCondFormatManagerWindow(*m_xTreeView, rDoc, m_xFormatList.get()))
97{
98 m_xBtnRemove->connect_clicked(LINK(this, ScCondFormatManagerDlg, RemoveBtnHdl));
99 m_xBtnEdit->connect_clicked(LINK(this, ScCondFormatManagerDlg, EditBtnClickHdl));
100 m_xBtnAdd->connect_clicked(LINK(this, ScCondFormatManagerDlg, AddBtnHdl));
101 m_xTreeView->connect_row_activated(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
102
103 SvtViewOptions aDlgOpt(EViewType::Dialog, "CondFormatDialog");
104 if (aDlgOpt.Exists())
105 m_xDialog->set_window_state(aDlgOpt.GetWindowState());
106
108}
109
111{
112 // tdf#101285 - Remember position of dialog
113 SvtViewOptions aDlgOpt(EViewType::Dialog, "CondFormatDialog");
114 aDlgOpt.SetWindowState(m_xDialog->get_window_state(vcl::WindowDataMask::Pos));
115}
116
117std::unique_ptr<ScConditionalFormatList> ScCondFormatManagerDlg::GetConditionalFormatList()
118{
119 return std::move(m_xFormatList);
120}
121
123{
124 bool bNewSensitivity = !m_xFormatList->empty();
125 m_xBtnRemove->set_sensitive(bNewSensitivity);
126 m_xBtnEdit->set_sensitive(bNewSensitivity);
127}
128
129// Get the current conditional format selected.
130//
132{
133 return m_xCtrlManager->GetSelection();
134}
135
137{
138 m_xCtrlManager->DeleteSelection();
139 m_bModified = true;
140 UpdateButtonSensitivity();
141}
142
144{
145 EditBtnHdl(*m_xTreeView);
146}
147
149{
150 ScConditionalFormat* pFormat = m_xCtrlManager->GetSelection();
151
152 if (!pFormat)
153 return true;
154
155 m_bModified = true;
156 m_xDialog->response( DLG_RET_EDIT );
157
158 return true;
159}
160
162{
163 m_bModified = true;
164 m_xDialog->response( DLG_RET_ADD );
165}
166
168{
169 m_bModified = true;
171}
172
174{
175 return m_bModified;
176}
177
178/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
static SC_DLLPUBLIC OUString GetExpression(const ScConditionalFormat &rFormat, const ScAddress &rPos)
ScConditionalFormat * GetCondFormatSelected()
std::unique_ptr< weld::TreeView > m_xTreeView
bool CondFormatsChanged() const
ScCondFormatManagerDlg(weld::Window *pParent, ScDocument &rDoc, const ScConditionalFormatList *pFormatList)
std::unique_ptr< weld::Button > m_xBtnEdit
std::unique_ptr< weld::Button > m_xBtnAdd
std::unique_ptr< ScConditionalFormatList > m_xFormatList
std::unique_ptr< ScCondFormatManagerWindow > m_xCtrlManager
virtual ~ScCondFormatManagerDlg() override
std::unique_ptr< weld::Button > m_xBtnRemove
std::unique_ptr< ScConditionalFormatList > GetConditionalFormatList()
weld::TreeView & mrTreeView
ScCondFormatManagerWindow(weld::TreeView &rTreeView, ScDocument &rDoc, ScConditionalFormatList *pFormatList)
ScConditionalFormatList * mpFormatList
ScConditionalFormat * GetSelection()
ScConditionalFormat * GetFormat(sal_uInt32 nKey)
Definition: conditio.cxx:2098
void erase(sal_uLong nIndex)
Definition: conditio.cxx:2292
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:492
ScAddress GetTopLeftCorner() const
Definition: rangelst.cxx:1150
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
constexpr tools::Long Width() const
void SetWindowState(const OUString &sState)
OUString GetWindowState() const
bool Exists() const
std::shared_ptr< weld::Dialog > m_xDialog
virtual void make_sorted()=0
virtual void set_text(int row, const OUString &rText, int col=-1)=0
virtual void set_selection_mode(SelectionMode eMode)=0
void append(TreeIter *pRet=nullptr)
virtual int get_height_rows(int nRows) const=0
virtual void remove(int pos)=0
virtual void select(int pos)=0
virtual void set_column_fixed_widths(const std::vector< int > &rWidths)=0
virtual std::vector< int > get_selected_rows() const=0
virtual int get_selected_index() const=0
virtual OUString get_id(int pos) const=0
virtual Size get_size_request() const=0
virtual void set_size_request(int nWidth, int nHeight)=0
virtual void freeze()=0
virtual void thaw()=0
virtual float get_approximate_digit_width() const=0
#define DLG_RET_EDIT
#define DLG_RET_ADD
IMPL_LINK_NOARG(ScCondFormatManagerDlg, RemoveBtnHdl, weld::Button &, void)
sal_Int32 nIndex
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)