LibreOffice Module sw (master) 1
swuiccoll.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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <memory>
21#include <cmdid.h>
22#include <o3tl/safeint.hxx>
23#include <swmodule.hxx>
24#include <view.hxx>
25#include <wrtsh.hxx>
26
27#include <sfx2/styfitem.hxx>
28
29#include <ccoll.hxx>
30#include <fmtcol.hxx>
31#include <hintids.hxx>
32#include <docsh.hxx>
33
34#include <swuiccoll.hxx>
35
36const WhichRangesContainer SwCondCollPage::s_aPageRg(svl::Items<FN_COND_COLL, FN_COND_COLL>);
37
39 : SfxTabPage(pPage, pController, "modules/swriter/ui/conditionpage.ui", "ConditionPage", &rSet)
40 , m_pCmds(SwCondCollItem::GetCmds())
41 , m_pFormat(nullptr)
42 , m_xTbLinks(m_xBuilder->weld_tree_view("links"))
43 , m_xStyleLB(m_xBuilder->weld_tree_view("styles"))
44 , m_xFilterLB(m_xBuilder->weld_combo_box("filter"))
45 , m_xRemovePB(m_xBuilder->weld_button("remove"))
46 , m_xAssignPB(m_xBuilder->weld_button("apply"))
47{
48 m_xStyleLB->make_sorted();
49 const auto nHeightRequest = m_xStyleLB->get_height_rows(12);
50 m_xStyleLB->set_size_request(-1, nHeightRequest);
51 m_xTbLinks->set_size_request(-1, nHeightRequest);
52 std::vector<int> aWidths
53 {
54 o3tl::narrowing<int>(m_xTbLinks->get_approximate_digit_width() * 40)
55 };
56 m_xTbLinks->set_column_fixed_widths(aWidths);
57
58 const sal_Int32 nStrCount = m_xFilterLB->get_count();
59 for (sal_Int32 i = 0; i < nStrCount; ++i)
60 m_aStrArr.push_back(m_xFilterLB->get_text(i));
61 m_xFilterLB->clear();
62
64
65 // Install handlers
66 m_xTbLinks->connect_row_activated(LINK(this, SwCondCollPage, AssignRemoveTreeListBoxHdl));
67 m_xStyleLB->connect_row_activated(LINK(this, SwCondCollPage, AssignRemoveTreeListBoxHdl));
68 m_xRemovePB->connect_clicked(LINK(this, SwCondCollPage, AssignRemoveClickHdl));
69 m_xAssignPB->connect_clicked(LINK(this, SwCondCollPage, AssignRemoveClickHdl));
70 m_xTbLinks->connect_changed(LINK(this, SwCondCollPage, SelectTreeListBoxHdl));
71 m_xStyleLB->connect_changed(LINK(this, SwCondCollPage, SelectTreeListBoxHdl));
72 m_xFilterLB->connect_changed(LINK(this, SwCondCollPage, SelectListBoxHdl));
73
74 std::optional<SfxStyleFamilies> xFamilies(SW_MOD()->CreateStyleFamilies());
75 size_t nCount = xFamilies->size();
76 for (size_t j = 0; j < nCount; ++j)
77 {
78 const SfxStyleFamilyItem &rFamilyItem = xFamilies->at(j);
79 if (SfxStyleFamily::Para == rFamilyItem.GetFamily())
80 {
81 const SfxStyleFilter& rFilterList = rFamilyItem.GetFilterList();
82 for (size_t i = 0; i < rFilterList.size(); ++i)
83 m_xFilterLB->append(OUString::number(int(rFilterList[i].nFlags)), rFilterList[i].aName);
84 break;
85 }
86 }
87
88 m_xFilterLB->set_active(0);
89 m_xTbLinks->show();
90}
91
93{
94}
95
97{
98 if( _pSet )
99 FillItemSet(_pSet);
100
101 return DeactivateRC::LeavePage;
102}
103
104std::unique_ptr<SfxTabPage> SwCondCollPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
105{
106 return std::make_unique<SwCondCollPage>(pPage, pController, *rSet);
107}
108
110{
111 SwCondCollItem aCondItem;
112 for (size_t i = 0; i < m_aStrArr.size(); ++i)
113 {
114 const OUString sEntry = m_xTbLinks->get_text(i, 1);
115 aCondItem.SetStyle( &sEntry, i);
116 }
117 rSet->Put(aCondItem);
118 return true;
119}
120
122{
123 m_xTbLinks->clear();
124 m_xStyleLB->clear();
125
126 SwView* pView = GetActiveView();
127 if (!pView)
128 return;
129
131 const SfxStyleSheetBase* pBase = pPool->First(SfxStyleFamily::Para);
132 while (pBase)
133 {
134 if (!m_pFormat || pBase->GetName() != m_pFormat->GetName())
135 m_xStyleLB->append_text(pBase->GetName());
136 pBase = pPool->Next();
137 }
138 m_xStyleLB->select(0);
139
140 for (size_t n = 0; n < m_aStrArr.size(); ++n)
141 {
142 m_xTbLinks->append_text(m_aStrArr[n]);
143
144 const SwCollCondition* pCond = nullptr;
146 nullptr != ( pCond = static_cast<SwConditionTextFormatColl*>(m_pFormat)->
147 HasCondition( SwCollCondition( nullptr, m_pCmds[n].nCnd, m_pCmds[n].nSubCond ) ) )
148 && pCond->GetTextFormatColl() )
149 {
150 m_xTbLinks->set_text(n, pCond->GetTextFormatColl()->GetName(), 1);
151 }
152
153 if (0 == n)
154 {
155 m_xTbLinks->select(0);
156 SelectTreeListBoxHdl(*m_xTbLinks);
157 }
158 }
159}
160
161IMPL_LINK(SwCondCollPage, AssignRemoveClickHdl, weld::Button&, rBtn, void)
162{
163 AssignRemove(&rBtn);
164}
165
166IMPL_LINK(SwCondCollPage, AssignRemoveTreeListBoxHdl, weld::TreeView&, rBtn, bool)
167{
168 AssignRemove(&rBtn);
169 return true;
170}
171
173{
174 int nPos = m_xTbLinks->get_selected_index();
175 if (nPos == -1)
176 {
177 return;
178 }
179
180 const bool bAssEnabled = pBtn != m_xRemovePB.get() && m_xAssignPB->get_sensitive();
181 m_xAssignPB->set_sensitive(!bAssEnabled);
182 m_xRemovePB->set_sensitive(bAssEnabled);
183 if (bAssEnabled)
184 m_xTbLinks->set_text(nPos, m_xStyleLB->get_selected_text(), 1);
185 else
186 m_xTbLinks->set_text(nPos, "", 1);
187}
188
189IMPL_LINK(SwCondCollPage, SelectTreeListBoxHdl, weld::TreeView&, rBox, void)
190{
191 SelectHdl(&rBox);
192}
193
194IMPL_LINK(SwCondCollPage, SelectListBoxHdl, weld::ComboBox&, rBox, void)
195{
196 SelectHdl(&rBox);
197}
198
200{
201 if (pBox == m_xFilterLB.get())
202 {
203 m_xStyleLB->clear();
204
205 SwView* pView = GetActiveView();
206 if (!pView)
207 return;
208
209 const sal_Int32 nSelPos = m_xFilterLB->get_active();
210 const SfxStyleSearchBits nSearchFlags = static_cast<SfxStyleSearchBits>(m_xFilterLB->get_id(nSelPos).toInt32());
212 const SfxStyleSheetBase* pBase = pPool->First(SfxStyleFamily::Para, nSearchFlags);
213
214 bool bEmpty = true;
215 while (pBase)
216 {
217 if (!m_pFormat || pBase->GetName() != m_pFormat->GetName())
218 {
219 m_xStyleLB->append_text(pBase->GetName());
220 bEmpty = false;
221 }
222 pBase = pPool->Next();
223 }
224 m_xStyleLB->select(bEmpty ? -1 : 0);
225 SelectHdl(m_xStyleLB.get());
226 }
227 else
228 {
229 int nSelected = m_xTbLinks->get_selected_index();
230 const OUString sTbEntry = nSelected != -1
231 ? m_xTbLinks->get_text(nSelected, 1)
232 : OUString();
233 const OUString sStyle = m_xStyleLB->get_selected_text();
234
235 m_xAssignPB->set_sensitive(sStyle != sTbEntry);
236
237 if (pBox != m_xStyleLB.get())
238 m_xRemovePB->set_sensitive(!sTbEntry.isEmpty());
239 }
240}
241
243{
244 m_pFormat = pFormat;
245}
246
247/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxStyleFamily GetFamily() const
const SfxStyleFilter & GetFilterList() const
SfxStyleSheetBase * First(SfxStyleFamily eFamily, SfxStyleSearchBits eMask=SfxStyleSearchBits::All)
SfxStyleSheetBase * Next()
const OUString & GetName() const
void SetExchangeSupport()
SwTextFormatColl * GetTextFormatColl() const
Definition: fmtcol.hxx:234
void SetStyle(const OUString *pStyle, sal_uInt16 nPos)
Definition: ccoll.cxx:155
The Condition tab on the paragraph style dialog for conditional styles, e.g. Text Body.
Definition: swuiccoll.hxx:31
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: swuiccoll.cxx:109
std::vector< OUString > m_aStrArr
Definition: swuiccoll.hxx:32
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: swuiccoll.cxx:96
virtual ~SwCondCollPage() override
Definition: swuiccoll.cxx:92
std::unique_ptr< weld::Button > m_xAssignPB
Definition: swuiccoll.hxx:41
void AssignRemove(const weld::Widget *)
Definition: swuiccoll.cxx:172
std::unique_ptr< weld::Button > m_xRemovePB
Definition: swuiccoll.hxx:40
SwCondCollPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: swuiccoll.cxx:38
void SetCollection(SwFormat *pFormat)
Definition: swuiccoll.cxx:242
SwFormat * m_pFormat
Definition: swuiccoll.hxx:35
const CommandStruct * m_pCmds
Definition: swuiccoll.hxx:34
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: swuiccoll.cxx:104
std::unique_ptr< weld::TreeView > m_xStyleLB
Definition: swuiccoll.hxx:38
std::unique_ptr< weld::ComboBox > m_xFilterLB
Definition: swuiccoll.hxx:39
virtual void Reset(const SfxItemSet *rSet) override
Definition: swuiccoll.cxx:121
std::unique_ptr< weld::TreeView > m_xTbLinks
Definition: swuiccoll.hxx:37
static const WhichRangesContainer s_aPageRg
Definition: swuiccoll.hxx:52
void SelectHdl(const weld::Widget *)
Definition: swuiccoll.cxx:199
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1152
Base class for various Writer styles.
Definition: format.hxx:47
sal_uInt16 Which() const
for Querying of Writer-functions.
Definition: format.hxx:82
const OUString & GetName() const
Definition: format.hxx:131
Definition: view.hxx:146
SwWrtShell & GetWrtShell() const
Definition: view.hxx:423
SwDocShell * GetDocShell()
Definition: view.cxx:1193
const SwView & GetView() const
Definition: wrtsh.hxx:443
int nCount
constexpr TypedWhichId< SwConditionTextFormatColl > RES_CONDTXTFMTCOLL(166)
sal_Int64 n
sal_uInt16 nPos
int i
static SfxItemSet & rSet
std::vector< SfxFilterTuple > SfxStyleFilter
SfxStyleSearchBits
SwView * GetActiveView()
Definition: swmodul1.cxx:115
#define SW_MOD()
Definition: swmodule.hxx:254
IMPL_LINK(SwCondCollPage, AssignRemoveClickHdl, weld::Button &, rBtn, void)
Definition: swuiccoll.cxx:161
DeactivateRC