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().toUtf8());
106
108}
109
111{
112 // tdf#101285 - Remember position of dialog
113 SvtViewOptions aDlgOpt(EViewType::Dialog, "CondFormatDialog");
114 OString sWindowState
115 = m_xDialog->get_window_state(vcl::WindowDataMask::Pos);
116 aDlgOpt.SetWindowState(OUString::fromUtf8(sWindowState));
117}
118
119std::unique_ptr<ScConditionalFormatList> ScCondFormatManagerDlg::GetConditionalFormatList()
120{
121 return std::move(m_xFormatList);
122}
123
125{
126 bool bNewSensitivity = !m_xFormatList->empty();
127 m_xBtnRemove->set_sensitive(bNewSensitivity);
128 m_xBtnEdit->set_sensitive(bNewSensitivity);
129}
130
131// Get the current conditional format selected.
132//
134{
135 return m_xCtrlManager->GetSelection();
136}
137
139{
140 m_xCtrlManager->DeleteSelection();
141 m_bModified = true;
142 UpdateButtonSensitivity();
143}
144
146{
147 EditBtnHdl(*m_xTreeView);
148}
149
151{
152 ScConditionalFormat* pFormat = m_xCtrlManager->GetSelection();
153
154 if (!pFormat)
155 return true;
156
157 m_bModified = true;
158 m_xDialog->response( DLG_RET_EDIT );
159
160 return true;
161}
162
164{
165 m_bModified = true;
166 m_xDialog->response( DLG_RET_ADD );
167}
168
170{
171 m_bModified = true;
173}
174
176{
177 return m_bModified;
178}
179
180/* 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:2077
void erase(sal_uLong nIndex)
Definition: conditio.cxx:2271
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:500
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)