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_rSh(::GetActiveView()->GetWrtShell())
41 , m_pCmds(SwCondCollItem::GetCmds())
42 , m_pFormat(nullptr)
43 , m_xTbLinks(m_xBuilder->weld_tree_view("links"))
44 , m_xStyleLB(m_xBuilder->weld_tree_view("styles"))
45 , m_xFilterLB(m_xBuilder->weld_combo_box("filter"))
46 , m_xRemovePB(m_xBuilder->weld_button("remove"))
47 , m_xAssignPB(m_xBuilder->weld_button("apply"))
48{
49 m_xStyleLB->make_sorted();
50 const auto nHeightRequest = m_xStyleLB->get_height_rows(12);
51 m_xStyleLB->set_size_request(-1, nHeightRequest);
52 m_xTbLinks->set_size_request(-1, nHeightRequest);
53 std::vector<int> aWidths
54 {
55 o3tl::narrowing<int>(m_xTbLinks->get_approximate_digit_width() * 40)
56 };
57 m_xTbLinks->set_column_fixed_widths(aWidths);
58
59 const sal_Int32 nStrCount = m_xFilterLB->get_count();
60 for (sal_Int32 i = 0; i < nStrCount; ++i)
61 m_aStrArr.push_back(m_xFilterLB->get_text(i));
62 m_xFilterLB->clear();
63
65
66 // Install handlers
67 m_xTbLinks->connect_row_activated(LINK(this, SwCondCollPage, AssignRemoveTreeListBoxHdl));
68 m_xStyleLB->connect_row_activated(LINK(this, SwCondCollPage, AssignRemoveTreeListBoxHdl));
69 m_xRemovePB->connect_clicked(LINK(this, SwCondCollPage, AssignRemoveClickHdl));
70 m_xAssignPB->connect_clicked(LINK(this, SwCondCollPage, AssignRemoveClickHdl));
71 m_xTbLinks->connect_changed(LINK(this, SwCondCollPage, SelectTreeListBoxHdl));
72 m_xStyleLB->connect_changed(LINK(this, SwCondCollPage, SelectTreeListBoxHdl));
73 m_xFilterLB->connect_changed(LINK(this, SwCondCollPage, SelectListBoxHdl));
74
75 std::optional<SfxStyleFamilies> xFamilies(SW_MOD()->CreateStyleFamilies());
76 size_t nCount = xFamilies->size();
77 for (size_t j = 0; j < nCount; ++j)
78 {
79 const SfxStyleFamilyItem &rFamilyItem = xFamilies->at(j);
80 if (SfxStyleFamily::Para == rFamilyItem.GetFamily())
81 {
82 const SfxStyleFilter& rFilterList = rFamilyItem.GetFilterList();
83 for (size_t i = 0; i < rFilterList.size(); ++i)
84 m_xFilterLB->append(OUString::number(int(rFilterList[i].nFlags)), rFilterList[i].aName);
85 break;
86 }
87 }
88
89 m_xFilterLB->set_active(0);
90 m_xTbLinks->show();
91}
92
94{
95}
96
98{
99 if( _pSet )
100 FillItemSet(_pSet);
101
102 return DeactivateRC::LeavePage;
103}
104
105std::unique_ptr<SfxTabPage> SwCondCollPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
106{
107 return std::make_unique<SwCondCollPage>(pPage, pController, *rSet);
108}
109
111{
112 SwCondCollItem aCondItem;
113 for (size_t i = 0; i < m_aStrArr.size(); ++i)
114 {
115 const OUString sEntry = m_xTbLinks->get_text(i, 1);
116 aCondItem.SetStyle( &sEntry, i);
117 }
118 rSet->Put(aCondItem);
119 return true;
120}
121
123{
124 m_xTbLinks->clear();
125
127 m_xStyleLB->clear();
128 const SfxStyleSheetBase* pBase = pPool->First(SfxStyleFamily::Para);
129 while (pBase)
130 {
131 if (!m_pFormat || pBase->GetName() != m_pFormat->GetName())
132 m_xStyleLB->append_text(pBase->GetName());
133 pBase = pPool->Next();
134 }
135 m_xStyleLB->select(0);
136
137 for (size_t n = 0; n < m_aStrArr.size(); ++n)
138 {
139 m_xTbLinks->append_text(m_aStrArr[n]);
140
141 const SwCollCondition* pCond = nullptr;
143 nullptr != ( pCond = static_cast<SwConditionTextFormatColl*>(m_pFormat)->
144 HasCondition( SwCollCondition( nullptr, m_pCmds[n].nCnd, m_pCmds[n].nSubCond ) ) )
145 && pCond->GetTextFormatColl() )
146 {
147 m_xTbLinks->set_text(n, pCond->GetTextFormatColl()->GetName(), 1);
148 }
149
150 if (0 == n)
151 {
152 m_xTbLinks->select(0);
153 SelectTreeListBoxHdl(*m_xTbLinks);
154 }
155 }
156}
157
158IMPL_LINK(SwCondCollPage, AssignRemoveClickHdl, weld::Button&, rBtn, void)
159{
160 AssignRemove(&rBtn);
161}
162
163IMPL_LINK(SwCondCollPage, AssignRemoveTreeListBoxHdl, weld::TreeView&, rBtn, bool)
164{
165 AssignRemove(&rBtn);
166 return true;
167}
168
170{
171 int nPos = m_xTbLinks->get_selected_index();
172 if (nPos == -1)
173 {
174 return;
175 }
176
177 const bool bAssEnabled = pBtn != m_xRemovePB.get() && m_xAssignPB->get_sensitive();
178 m_xAssignPB->set_sensitive(!bAssEnabled);
179 m_xRemovePB->set_sensitive(bAssEnabled);
180 if (bAssEnabled)
181 m_xTbLinks->set_text(nPos, m_xStyleLB->get_selected_text(), 1);
182 else
183 m_xTbLinks->set_text(nPos, "", 1);
184}
185
186IMPL_LINK(SwCondCollPage, SelectTreeListBoxHdl, weld::TreeView&, rBox, void)
187{
188 SelectHdl(&rBox);
189}
190
191IMPL_LINK(SwCondCollPage, SelectListBoxHdl, weld::ComboBox&, rBox, void)
192{
193 SelectHdl(&rBox);
194}
195
197{
198 if (pBox == m_xFilterLB.get())
199 {
200 m_xStyleLB->clear();
201 const sal_Int32 nSelPos = m_xFilterLB->get_active();
202 const SfxStyleSearchBits nSearchFlags = static_cast<SfxStyleSearchBits>(m_xFilterLB->get_id(nSelPos).toInt32());
204 const SfxStyleSheetBase* pBase = pPool->First(SfxStyleFamily::Para, nSearchFlags);
205
206 bool bEmpty = true;
207 while (pBase)
208 {
209 if (!m_pFormat || pBase->GetName() != m_pFormat->GetName())
210 {
211 m_xStyleLB->append_text(pBase->GetName());
212 bEmpty = false;
213 }
214 pBase = pPool->Next();
215 }
216 m_xStyleLB->select(bEmpty ? -1 : 0);
217 SelectHdl(m_xStyleLB.get());
218 }
219 else
220 {
221 int nSelected = m_xTbLinks->get_selected_index();
222 const OUString sTbEntry = nSelected != -1
223 ? m_xTbLinks->get_text(nSelected, 1)
224 : OUString();
225 const OUString sStyle = m_xStyleLB->get_selected_text();
226
227 m_xAssignPB->set_sensitive(sStyle != sTbEntry);
228
229 if (pBox != m_xStyleLB.get())
230 m_xRemovePB->set_sensitive(!sTbEntry.isEmpty());
231 }
232}
233
235{
236 m_pFormat = pFormat;
237}
238
239/* 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:231
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:110
std::vector< OUString > m_aStrArr
Definition: swuiccoll.hxx:32
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: swuiccoll.cxx:97
virtual ~SwCondCollPage() override
Definition: swuiccoll.cxx:93
std::unique_ptr< weld::Button > m_xAssignPB
Definition: swuiccoll.hxx:42
void AssignRemove(const weld::Widget *)
Definition: swuiccoll.cxx:169
std::unique_ptr< weld::Button > m_xRemovePB
Definition: swuiccoll.hxx:41
SwCondCollPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: swuiccoll.cxx:38
void SetCollection(SwFormat *pFormat)
Definition: swuiccoll.cxx:234
SwFormat * m_pFormat
Definition: swuiccoll.hxx:36
SwWrtShell & m_rSh
Definition: swuiccoll.hxx:34
const CommandStruct * m_pCmds
Definition: swuiccoll.hxx:35
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: swuiccoll.cxx:105
std::unique_ptr< weld::TreeView > m_xStyleLB
Definition: swuiccoll.hxx:39
std::unique_ptr< weld::ComboBox > m_xFilterLB
Definition: swuiccoll.hxx:40
virtual void Reset(const SfxItemSet *rSet) override
Definition: swuiccoll.cxx:122
std::unique_ptr< weld::TreeView > m_xTbLinks
Definition: swuiccoll.hxx:38
static const WhichRangesContainer s_aPageRg
Definition: swuiccoll.hxx:53
void SelectHdl(const weld::Widget *)
Definition: swuiccoll.cxx:196
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1154
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
SwDocShell * GetDocShell()
Definition: view.cxx:1160
const SwView & GetView() const
Definition: wrtsh.hxx:443
int nCount
constexpr TypedWhichId< SwConditionTextFormatColl > RES_CONDTXTFMTCOLL(160)
sal_Int64 n
sal_uInt16 nPos
int i
static SfxItemSet & rSet
std::vector< SfxFilterTuple > SfxStyleFilter
SfxStyleSearchBits
SwView * GetActiveView()
Definition: swmodul1.cxx:116
#define SW_MOD()
Definition: swmodule.hxx:256
IMPL_LINK(SwCondCollPage, AssignRemoveClickHdl, weld::Button &, rBtn, void)
Definition: swuiccoll.cxx:158
DeactivateRC