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 sal_uInt16 SwCondCollPage::m_aPageRg[] = {
37  0
38 };
39 
41  : SfxTabPage(pPage, pController, "modules/swriter/ui/conditionpage.ui", "ConditionPage", &rSet)
42  , m_rSh(::GetActiveView()->GetWrtShell())
43  , m_pCmds(SwCondCollItem::GetCmds())
44  , m_pFormat(nullptr)
45  , m_xTbLinks(m_xBuilder->weld_tree_view("links"))
46  , m_xStyleLB(m_xBuilder->weld_tree_view("styles"))
47  , m_xFilterLB(m_xBuilder->weld_combo_box("filter"))
48  , m_xRemovePB(m_xBuilder->weld_button("remove"))
49  , m_xAssignPB(m_xBuilder->weld_button("apply"))
50 {
51  m_xStyleLB->make_sorted();
52  const auto nHeightRequest = m_xStyleLB->get_height_rows(12);
53  m_xStyleLB->set_size_request(-1, nHeightRequest);
54  m_xTbLinks->set_size_request(-1, nHeightRequest);
55  std::vector<int> aWidths;
56  aWidths.push_back(m_xTbLinks->get_approximate_digit_width() * 40);
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::unique_ptr<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(1);
90  m_xTbLinks->show();
91 }
92 
94 {
95 }
96 
98 {
99  if( _pSet )
100  FillItemSet(_pSet);
101 
102  return DeactivateRC::LeavePage;
103 }
104 
105 std::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 
158 IMPL_LINK(SwCondCollPage, AssignRemoveClickHdl, weld::Button&, rBtn, void)
159 {
160  AssignRemove(&rBtn);
161 }
162 
163 IMPL_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 
186 IMPL_LINK(SwCondCollPage, SelectTreeListBoxHdl, weld::TreeView&, rBox, void)
187 {
188  SelectHdl(&rBox);
189 }
190 
191 IMPL_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: */
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: swuiccoll.cxx:97
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: swuiccoll.cxx:105
SfxStyleSheetBase * First(SfxStyleFamily eFamily, SfxStyleSearchBits eMask=SfxStyleSearchBits::All)
virtual ~SwCondCollPage() override
Definition: swuiccoll.cxx:93
SwView * GetActiveView()
Definition: swmodul1.cxx:116
sal_Int64 n
SwFormat * m_pFormat
Definition: swuiccoll.hxx:35
#define FN_COND_COLL
Definition: cmdid.h:797
SwCondCollPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: swuiccoll.cxx:40
constexpr TypedWhichId< SwConditionTextFormatColl > RES_CONDTXTFMTCOLL(160)
SwWrtShell & m_rSh
Definition: swuiccoll.hxx:33
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: swuiccoll.cxx:110
SwTextFormatColl * GetTextFormatColl() const
Definition: fmtcol.hxx:225
const SfxStyleFilter & GetFilterList() const
const SwView & GetView() const
Definition: wrtsh.hxx:429
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:169
IMPL_LINK(SwCondCollPage, AssignRemoveClickHdl, weld::Button &, rBtn, void)
Definition: swuiccoll.cxx:158
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:196
#define SW_MOD()
Definition: swmodule.hxx:255
int i
virtual void Reset(const SfxItemSet *rSet) override
Definition: swuiccoll.cxx:122
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1140
std::unique_ptr< weld::ComboBox > m_xFilterLB
Definition: swuiccoll.hxx:39
void SetCollection(SwFormat *pFormat)
Definition: swuiccoll.cxx:234
std::unique_ptr< weld::Button > m_xAssignPB
Definition: swuiccoll.hxx:41
SwDocShell * GetDocShell()
Definition: view.cxx:1126
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()
static const sal_uInt16 m_aPageRg[]
Definition: swuiccoll.hxx:52
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
std::vector< OUString > m_aStrArr
Definition: swuiccoll.hxx:31
SfxStyleSearchBits
sal_uInt16 nPos