1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <swmodule.hxx>
26 #include <sfx2/styfitem.hxx>
30 #include <hintids.hxx>
33 #include <swuiccoll.hxx>
35 const sal_uInt16
SwCondCollPage::m_aPageRg
[] = {
36 FN_COND_COLL
, FN_COND_COLL
,
40 SwCondCollPage::SwCondCollPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
&rSet
)
41 : SfxTabPage(pPage
, pController
, "modules/swriter/ui/conditionpage.ui", "ConditionPage", &rSet
)
42 , m_rSh(::GetActiveView()->GetWrtShell())
43 , m_pCmds(SwCondCollItem::GetCmds())
45 , m_bNewTemplate(false)
46 , m_xConditionCB(m_xBuilder
->weld_check_button("condstyle"))
47 , m_xTbLinks(m_xBuilder
->weld_tree_view("links"))
48 , m_xStyleLB(m_xBuilder
->weld_tree_view("styles"))
49 , m_xFilterLB(m_xBuilder
->weld_combo_box("filter"))
50 , m_xRemovePB(m_xBuilder
->weld_button("remove"))
51 , m_xAssignPB(m_xBuilder
->weld_button("apply"))
53 m_xStyleLB
->make_sorted();
54 const auto nHeightRequest
= m_xStyleLB
->get_height_rows(12);
55 m_xStyleLB
->set_size_request(-1, nHeightRequest
);
56 m_xTbLinks
->set_size_request(-1, nHeightRequest
);
57 std::vector
<int> aWidths
;
58 aWidths
.push_back(m_xTbLinks
->get_approximate_digit_width() * 40);
59 m_xTbLinks
->set_column_fixed_widths(aWidths
);
61 const sal_Int32 nStrCount
= m_xFilterLB
->get_count();
62 for (sal_Int32 i
= 0; i
< nStrCount
; ++i
)
63 m_aStrArr
.push_back(m_xFilterLB
->get_text(i
));
69 m_xConditionCB
->connect_toggled(LINK(this, SwCondCollPage
, OnOffHdl
));
70 m_xTbLinks
->connect_row_activated(LINK(this, SwCondCollPage
, AssignRemoveTreeListBoxHdl
));
71 m_xStyleLB
->connect_row_activated(LINK(this, SwCondCollPage
, AssignRemoveTreeListBoxHdl
));
72 m_xRemovePB
->connect_clicked(LINK(this, SwCondCollPage
, AssignRemoveClickHdl
));
73 m_xAssignPB
->connect_clicked(LINK(this, SwCondCollPage
, AssignRemoveClickHdl
));
74 m_xTbLinks
->connect_changed(LINK(this, SwCondCollPage
, SelectTreeListBoxHdl
));
75 m_xStyleLB
->connect_changed(LINK(this, SwCondCollPage
, SelectTreeListBoxHdl
));
76 m_xFilterLB
->connect_changed(LINK(this, SwCondCollPage
, SelectListBoxHdl
));
78 std::unique_ptr
<SfxStyleFamilies
> xFamilies(SW_MOD()->CreateStyleFamilies());
79 size_t nCount
= xFamilies
->size();
80 for (size_t j
= 0; j
< nCount
; ++j
)
82 const SfxStyleFamilyItem
&rFamilyItem
= xFamilies
->at(j
);
83 if (SfxStyleFamily::Para
== rFamilyItem
.GetFamily())
85 const SfxStyleFilter
& rFilterList
= rFamilyItem
.GetFilterList();
86 for (size_t i
= 0; i
< rFilterList
.size(); ++i
)
87 m_xFilterLB
->append(OUString::number(int(rFilterList
[i
].nFlags
)), rFilterList
[i
].aName
);
92 m_xFilterLB
->set_active(1);
96 SwCondCollPage::~SwCondCollPage()
100 DeactivateRC
SwCondCollPage::DeactivatePage(SfxItemSet
* _pSet
)
105 return DeactivateRC::LeavePage
;
108 std::unique_ptr
<SfxTabPage
> SwCondCollPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
*rSet
)
110 return std::make_unique
<SwCondCollPage
>(pPage
, pController
, *rSet
);
113 bool SwCondCollPage::FillItemSet(SfxItemSet
*rSet
)
115 SwCondCollItem aCondItem
;
116 for (size_t i
= 0; i
< m_aStrArr
.size(); ++i
)
118 const OUString sEntry
= m_xTbLinks
->get_text(i
, 1);
119 aCondItem
.SetStyle( &sEntry
, i
);
121 rSet
->Put(aCondItem
);
125 void SwCondCollPage::Reset(const SfxItemSet
*)
128 m_xConditionCB
->set_sensitive(true);
129 if (RES_CONDTXTFMTCOLL
== m_pFormat
->Which())
130 m_xConditionCB
->set_active(true);
131 OnOffHdl(*m_xConditionCB
);
135 SfxStyleSheetBasePool
* pPool
= m_rSh
.GetView().GetDocShell()->GetStyleSheetPool();
137 const SfxStyleSheetBase
* pBase
= pPool
->First(SfxStyleFamily::Para
);
140 if (!m_pFormat
|| pBase
->GetName() != m_pFormat
->GetName())
141 m_xStyleLB
->append_text(pBase
->GetName());
142 pBase
= pPool
->Next();
144 m_xStyleLB
->select(0);
146 for (size_t n
= 0; n
< m_aStrArr
.size(); ++n
)
148 m_xTbLinks
->append_text(m_aStrArr
[n
]);
150 const SwCollCondition
* pCond
= nullptr;
151 if( m_pFormat
&& RES_CONDTXTFMTCOLL
== m_pFormat
->Which() &&
152 nullptr != ( pCond
= static_cast<SwConditionTextFormatColl
*>(m_pFormat
)->
153 HasCondition( SwCollCondition( nullptr, m_pCmds
[n
].nCnd
, m_pCmds
[n
].nSubCond
) ) )
154 && pCond
->GetTextFormatColl() )
156 m_xTbLinks
->set_text(n
, pCond
->GetTextFormatColl()->GetName(), 1);
161 m_xTbLinks
->select(0);
162 SelectTreeListBoxHdl(*m_xTbLinks
);
167 IMPL_LINK(SwCondCollPage
, OnOffHdl
, weld::ToggleButton
&, rBox
, void)
169 const bool bEnable
= rBox
.get_active();
170 m_xTbLinks
->set_sensitive(bEnable
);
171 m_xStyleLB
->set_sensitive(bEnable
);
172 m_xFilterLB
->set_sensitive(bEnable
);
173 m_xRemovePB
->set_sensitive(bEnable
);
174 m_xAssignPB
->set_sensitive(bEnable
);
179 IMPL_LINK(SwCondCollPage
, AssignRemoveClickHdl
, weld::Button
&, rBtn
, void)
184 IMPL_LINK(SwCondCollPage
, AssignRemoveTreeListBoxHdl
, weld::TreeView
&, rBtn
, bool)
190 void SwCondCollPage::AssignRemove(const weld::Widget
* pBtn
)
192 int nPos
= m_xTbLinks
->get_selected_index();
198 const bool bAssEnabled
= pBtn
!= m_xRemovePB
.get() && m_xAssignPB
->get_sensitive();
199 m_xAssignPB
->set_sensitive(!bAssEnabled
);
200 m_xRemovePB
->set_sensitive(bAssEnabled
);
202 m_xTbLinks
->set_text(nPos
, m_xStyleLB
->get_selected_text(), 1);
204 m_xTbLinks
->set_text(nPos
, "", 1);
207 IMPL_LINK(SwCondCollPage
, SelectTreeListBoxHdl
, weld::TreeView
&, rBox
, void)
212 IMPL_LINK(SwCondCollPage
, SelectListBoxHdl
, weld::ComboBox
&, rBox
, void)
217 void SwCondCollPage::SelectHdl(const weld::Widget
* pBox
)
219 if (pBox
== m_xFilterLB
.get())
222 const sal_Int32 nSelPos
= m_xFilterLB
->get_active();
223 const SfxStyleSearchBits nSearchFlags
= static_cast<SfxStyleSearchBits
>(m_xFilterLB
->get_id(nSelPos
).toInt32());
224 SfxStyleSheetBasePool
* pPool
= m_rSh
.GetView().GetDocShell()->GetStyleSheetPool();
225 const SfxStyleSheetBase
* pBase
= pPool
->First(SfxStyleFamily::Para
, nSearchFlags
);
230 if (!m_pFormat
|| pBase
->GetName() != m_pFormat
->GetName())
232 m_xStyleLB
->append_text(pBase
->GetName());
235 pBase
= pPool
->Next();
237 m_xStyleLB
->select(bEmpty
? -1 : 0);
238 SelectHdl(m_xStyleLB
.get());
242 int nSelected
= m_xTbLinks
->get_selected_index();
243 const OUString sTbEntry
= nSelected
!= -1
244 ? m_xTbLinks
->get_text(nSelected
, 1)
246 const OUString sStyle
= m_xStyleLB
->get_selected_text();
248 m_xAssignPB
->set_sensitive(sStyle
!= sTbEntry
&& m_xConditionCB
->get_active());
250 if (pBox
!= m_xStyleLB
.get())
251 m_xRemovePB
->set_sensitive(m_xConditionCB
->get_active() && !sTbEntry
.isEmpty());
255 void SwCondCollPage::SetCollection(SwFormat
* pFormat
, bool bNew
)
258 m_bNewTemplate
= bNew
;
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */