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>
23 #include <swtypes.hxx>
26 #include <viewopt.hxx>
28 #include <pagedesc.hxx>
29 #include <poolfmt.hxx>
31 #include <strings.hrc>
32 #include <SwStyleNameMapper.hxx>
34 void SwBreakDlg::rememberResult()
37 if (m_xLineBtn
->get_active())
39 else if(m_xColumnBtn
->get_active())
41 else if(m_xPageBtn
->get_active())
44 const int nPos
= m_xPageCollBox
->get_active();
45 if (nPos
!= 0 && nPos
!= -1)
47 m_aTemplate
= m_xPageCollBox
->get_active_text();
49 if (m_xPageNumBox
->get_active())
51 oPgNum
= static_cast<sal_uInt16
>(m_xPageNumEdit
->get_value());
57 IMPL_LINK_NOARG(SwBreakDlg
, ToggleHdl
, weld::ToggleButton
&, void)
62 IMPL_LINK_NOARG(SwBreakDlg
, ChangeHdl
, weld::ComboBox
&, void)
67 // Handler for Change Page Number
68 IMPL_LINK(SwBreakDlg
, PageNumHdl
, weld::ToggleButton
&, rBox
, void)
70 if (rBox
.get_active())
71 m_xPageNumEdit
->set_value(1);
73 m_xPageNumEdit
->set_text(OUString());
76 // By changing the Page number the checkbox is checked.
77 IMPL_LINK_NOARG(SwBreakDlg
, PageNumModifyHdl
, weld::SpinButton
&, void)
79 m_xPageNumBox
->set_active(true);
84 * checks whether pagenumber nPage is a legal pagenumber (left pages with even
85 * numbers etc. for a page template with alternating pages)
87 IMPL_LINK_NOARG(SwBreakDlg
, OkHdl
, weld::Button
&, void)
89 if (m_xPageNumBox
->get_active())
91 // In case of differing page descriptions, test validity
92 const int nPos
= m_xPageCollBox
->get_active();
93 // position 0 says 'Without'.
94 const SwPageDesc
*pPageDesc
;
95 if (nPos
!= 0 && nPos
!= -1)
96 pPageDesc
= rSh
.FindPageDescByName(m_xPageCollBox
->get_active_text(), true);
98 pPageDesc
= &rSh
.GetPageDesc(rSh
.GetCurPageDesc());
100 OSL_ENSURE(pPageDesc
, "Page description not found.");
101 const sal_uInt16 nUserPage
= sal_uInt16(m_xPageNumEdit
->get_value());
103 switch(pPageDesc
->GetUseOn())
105 case UseOnPage::Mirror
:
106 case UseOnPage::All
: break;
107 case UseOnPage::Left
: bOk
= 0 == nUserPage
% 2; break;
108 case UseOnPage::Right
: bOk
= 1 == nUserPage
% 2; break;
109 default:; //prevent warning
113 std::unique_ptr
<weld::Dialog
> xDialog(Application::CreateMessageDialog(m_xPageNumEdit
.get(), VclMessageType::Info
,
114 VclButtonsType::Ok
, SwResId(STR_ILLEGAL_PAGENUM
)));
116 m_xPageNumEdit
->grab_focus();
121 m_xDialog
->response(RET_OK
);
124 SwBreakDlg::SwBreakDlg(weld::Window
*pParent
, SwWrtShell
&rS
)
125 : GenericDialogController(pParent
, "modules/swriter/ui/insertbreak.ui", "BreakDialog")
126 , m_xLineBtn(m_xBuilder
->weld_radio_button("linerb"))
127 , m_xColumnBtn(m_xBuilder
->weld_radio_button("columnrb"))
128 , m_xPageBtn(m_xBuilder
->weld_radio_button("pagerb"))
129 , m_xPageCollText(m_xBuilder
->weld_label("styleft"))
130 , m_xPageCollBox(m_xBuilder
->weld_combo_box("stylelb"))
131 , m_xPageNumBox(m_xBuilder
->weld_check_button("pagenumcb"))
132 , m_xPageNumEdit(m_xBuilder
->weld_spin_button("pagenumsb"))
133 , m_xOkBtn(m_xBuilder
->weld_button("ok"))
136 , bHtmlMode(0 != ::GetHtmlMode(rS
.GetView().GetDocShell()))
138 Link
<weld::ToggleButton
&,void> aLk
= LINK(this, SwBreakDlg
, ToggleHdl
);
139 m_xPageBtn
->connect_toggled(aLk
);
140 m_xLineBtn
->connect_toggled(aLk
);
141 m_xColumnBtn
->connect_toggled(aLk
);
142 m_xPageCollBox
->connect_changed(LINK(this, SwBreakDlg
, ChangeHdl
));
144 m_xOkBtn
->connect_clicked(LINK(this, SwBreakDlg
, OkHdl
));
145 m_xPageNumBox
->connect_toggled(LINK(this, SwBreakDlg
, PageNumHdl
));
146 m_xPageNumEdit
->connect_value_changed(LINK(this, SwBreakDlg
, PageNumModifyHdl
));
148 // Insert page description to Listbox
149 const size_t nCount
= rSh
.GetPageDescCnt();
150 for (size_t i
= 0; i
< nCount
; ++i
)
152 const SwPageDesc
&rPageDesc
= rSh
.GetPageDesc(i
);
153 ::InsertStringSorted("", rPageDesc
.GetName(), *m_xPageCollBox
, 1 );
156 OUString aFormatName
;
157 for (sal_uInt16 i
= RES_POOLPAGE_BEGIN
; i
< RES_POOLPAGE_END
; ++i
)
159 aFormatName
= SwStyleNameMapper::GetUIName( i
, aFormatName
);
160 if (m_xPageCollBox
->find_text(aFormatName
) == -1)
161 ::InsertStringSorted("", aFormatName
, *m_xPageCollBox
, 1 );
164 aFormatName
= SwStyleNameMapper::GetUIName( RES_POOLPAGE_LANDSCAPE
, aFormatName
);
165 if (m_xPageCollBox
->find_text(aFormatName
) == -1)
166 ::InsertStringSorted("", aFormatName
, *m_xPageCollBox
, 1);
168 m_xPageNumEdit
->set_text(OUString());
171 void SwBreakDlg::CheckEnable()
176 m_xColumnBtn
->set_sensitive(false);
177 m_xPageCollBox
->set_sensitive(false);
180 else if(rSh
.GetFrameType(nullptr,true)
181 & (FrameTypeFlags::FLY_ANY
| FrameTypeFlags::HEADER
| FrameTypeFlags::FOOTER
| FrameTypeFlags::FOOTNOTE
))
183 m_xPageBtn
->set_sensitive(false);
184 if (m_xPageBtn
->get_active())
185 m_xLineBtn
->set_active(true);
188 const bool bPage
= m_xPageBtn
->get_active();
189 m_xPageCollText
->set_sensitive(bPage
);
190 m_xPageCollBox
->set_sensitive(bPage
);
195 // position 0 says 'Without' page template.
196 const int nPos
= m_xPageCollBox
->get_active();
197 if (nPos
== 0 || nPos
== -1)
200 m_xPageNumBox
->set_sensitive(bEnable
);
201 m_xPageNumEdit
->set_sensitive(bEnable
);
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */