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 .
20 #include <vcl/svapp.hxx>
21 #include <osl/diagnose.h>
22 #include <bitmaps.hlst>
25 #include <swtypes.hxx>
28 #include <viewopt.hxx>
30 #include <pagedesc.hxx>
31 #include <poolfmt.hxx>
33 #include <strings.hrc>
34 #include <SwStyleNameMapper.hxx>
37 void SwBreakDlg::rememberResult()
40 if (m_xLineBtn
->get_active())
43 m_eClear
= static_cast<SwLineBreakClear
>(m_xLineClearBox
->get_active());
45 else if(m_xColumnBtn
->get_active())
47 else if(m_xPageBtn
->get_active())
50 const int nPos
= m_xPageCollBox
->get_active();
51 if (nPos
!= 0 && nPos
!= -1)
53 m_aTemplate
= m_xPageCollBox
->get_active_text();
55 if (m_xPageNumBox
->get_active())
57 m_oPgNum
= o3tl::narrowing
<sal_uInt16
>(m_xPageNumEdit
->get_value());
63 IMPL_LINK_NOARG(SwBreakDlg
, ToggleHdl
, weld::Toggleable
&, void)
69 IMPL_LINK_NOARG(SwBreakDlg
, ChangeHdl
, weld::ComboBox
&, void)
74 IMPL_LINK_NOARG(SwBreakDlg
, LineClearHdl
, weld::ComboBox
&, void)
79 // Handler for Change Page Number
80 IMPL_LINK(SwBreakDlg
, PageNumHdl
, weld::Toggleable
&, rBox
, void)
82 if (rBox
.get_active())
83 m_xPageNumEdit
->set_value(1);
85 m_xPageNumEdit
->set_text(OUString());
88 // By changing the Page number the checkbox is checked.
89 IMPL_LINK_NOARG(SwBreakDlg
, PageNumModifyHdl
, weld::SpinButton
&, void)
91 m_xPageNumBox
->set_active(true);
96 * checks whether pagenumber nPage is a legal pagenumber (left pages with even
97 * numbers etc. for a page template with alternating pages)
99 IMPL_LINK_NOARG(SwBreakDlg
, OkHdl
, weld::Button
&, void)
101 if (m_xPageNumBox
->get_active())
103 // In case of differing page descriptions, test validity
104 const int nPos
= m_xPageCollBox
->get_active();
105 // position 0 says 'Without'.
106 const SwPageDesc
*pPageDesc
;
107 if (nPos
!= 0 && nPos
!= -1)
108 pPageDesc
= m_rSh
.FindPageDescByName(m_xPageCollBox
->get_active_text(), true);
110 pPageDesc
= &m_rSh
.GetPageDesc(m_rSh
.GetCurPageDesc());
112 assert(pPageDesc
&& "Page description not found.");
113 const sal_uInt16 nUserPage
= sal_uInt16(m_xPageNumEdit
->get_value());
115 switch(pPageDesc
->GetUseOn())
117 case UseOnPage::Mirror
:
118 case UseOnPage::All
: break;
119 case UseOnPage::Left
: bOk
= 0 == nUserPage
% 2; break;
120 case UseOnPage::Right
: bOk
= 1 == nUserPage
% 2; break;
121 default:; //prevent warning
125 std::unique_ptr
<weld::Dialog
> xDialog(Application::CreateMessageDialog(m_xPageNumEdit
.get(), VclMessageType::Info
,
126 VclButtonsType::Ok
, SwResId(STR_ILLEGAL_PAGENUM
)));
128 m_xPageNumEdit
->grab_focus();
133 m_xDialog
->response(RET_OK
);
136 SwBreakDlg::SwBreakDlg(weld::Window
*pParent
, SwWrtShell
&rS
)
137 : GenericDialogController(pParent
, u
"modules/swriter/ui/insertbreak.ui"_ustr
, u
"BreakDialog"_ustr
)
138 , m_xLineBtn(m_xBuilder
->weld_radio_button(u
"linerb"_ustr
))
139 , m_xLineClearText(m_xBuilder
->weld_label(u
"clearft"_ustr
))
140 , m_xLineClearBox(m_xBuilder
->weld_combo_box(u
"clearlb"_ustr
))
141 , m_xColumnBtn(m_xBuilder
->weld_radio_button(u
"columnrb"_ustr
))
142 , m_xPageBtn(m_xBuilder
->weld_radio_button(u
"pagerb"_ustr
))
143 , m_xPageCollText(m_xBuilder
->weld_label(u
"styleft"_ustr
))
144 , m_xPageCollBox(m_xBuilder
->weld_combo_box(u
"stylelb"_ustr
))
145 , m_xPageNumBox(m_xBuilder
->weld_check_button(u
"pagenumcb"_ustr
))
146 , m_xPageNumEdit(m_xBuilder
->weld_spin_button(u
"pagenumsb"_ustr
))
147 , m_xOkBtn(m_xBuilder
->weld_button(u
"ok"_ustr
))
148 , m_xTypeImage(m_xBuilder
->weld_image(u
"imType"_ustr
))
151 , m_bHtmlMode(0 != ::GetHtmlMode(rS
.GetView().GetDocShell()))
153 Link
<weld::Toggleable
&,void> aLk
= LINK(this, SwBreakDlg
, ToggleHdl
);
154 m_xPageBtn
->connect_toggled(aLk
);
155 m_xLineBtn
->connect_toggled(aLk
);
156 m_xColumnBtn
->connect_toggled(aLk
);
157 m_xPageCollBox
->connect_changed(LINK(this, SwBreakDlg
, ChangeHdl
));
158 m_xLineClearBox
->connect_changed(LINK(this, SwBreakDlg
, LineClearHdl
));
160 m_xOkBtn
->connect_clicked(LINK(this, SwBreakDlg
, OkHdl
));
161 m_xPageNumBox
->connect_toggled(LINK(this, SwBreakDlg
, PageNumHdl
));
162 m_xPageNumEdit
->connect_value_changed(LINK(this, SwBreakDlg
, PageNumModifyHdl
));
164 // Insert page description to Listbox
165 const size_t nCount
= m_rSh
.GetPageDescCnt();
166 for (size_t i
= 0; i
< nCount
; ++i
)
168 const SwPageDesc
&rPageDesc
= m_rSh
.GetPageDesc(i
);
169 ::InsertStringSorted(u
""_ustr
, rPageDesc
.GetName(), *m_xPageCollBox
, 1 );
172 OUString aFormatName
;
173 for (sal_uInt16 i
= RES_POOLPAGE_BEGIN
; i
< RES_POOLPAGE_END
; ++i
)
175 aFormatName
= SwStyleNameMapper::GetUIName( i
, ProgName() );
176 if (m_xPageCollBox
->find_text(aFormatName
) == -1)
177 ::InsertStringSorted(u
""_ustr
, aFormatName
, *m_xPageCollBox
, 1 );
180 aFormatName
= SwStyleNameMapper::GetUIName( RES_POOLPAGE_LANDSCAPE
, ProgName() );
181 if (m_xPageCollBox
->find_text(aFormatName
) == -1)
182 ::InsertStringSorted(u
""_ustr
, aFormatName
, *m_xPageCollBox
, 1);
184 m_xPageNumEdit
->set_text(OUString());
188 void SwBreakDlg::CheckEnable()
193 m_xColumnBtn
->set_sensitive(false);
194 m_xPageCollBox
->set_sensitive(false);
197 else if(m_rSh
.GetFrameType(nullptr,true)
198 & (FrameTypeFlags::FLY_ANY
| FrameTypeFlags::HEADER
| FrameTypeFlags::FOOTER
| FrameTypeFlags::FOOTNOTE
))
200 m_xPageBtn
->set_sensitive(false);
201 if (m_xPageBtn
->get_active())
202 m_xLineBtn
->set_active(true);
205 const bool bPage
= m_xPageBtn
->get_active();
206 m_xPageCollText
->set_sensitive(bPage
);
207 m_xPageCollBox
->set_sensitive(bPage
);
208 bool bLine
= m_xLineBtn
->get_active();
209 m_xLineClearText
->set_sensitive(bLine
);
210 m_xLineClearBox
->set_sensitive(bLine
);
215 // position 0 says 'Without' page template.
216 const int nPos
= m_xPageCollBox
->get_active();
217 if (nPos
== 0 || nPos
== -1)
220 m_xPageNumBox
->set_sensitive(bEnable
);
221 m_xPageNumEdit
->set_sensitive(bEnable
);
224 void SwBreakDlg::UpdateImage()
226 if (m_xLineBtn
->get_active())
228 switch (m_xLineClearBox
->get_active())
231 m_xTypeImage
->set_from_icon_name(RID_BMP_LINEBREAK_NONE
);
234 m_xTypeImage
->set_from_icon_name(RID_BMP_LINEBREAK_LEFT
);
237 m_xTypeImage
->set_from_icon_name(RID_BMP_LINEBREAK_RIGHT
);
240 m_xTypeImage
->set_from_icon_name(RID_BMP_LINEBREAK_FULL
);
244 else if (m_xColumnBtn
->get_active())
245 m_xTypeImage
->set_from_icon_name(RID_BMP_COLBREAK
);
246 else if (m_xPageBtn
->get_active())
247 m_xTypeImage
->set_from_icon_name(RID_BMP_PAGEBREAK
);
249 m_xTypeImage
->set_from_icon_name(""); //clear
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */