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