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