Add a comment to clarify what kind of inputs the class handles
[LibreOffice.git] / sw / source / ui / chrdlg / break.cxx
blob1c5c7753bdb778353fe944f62f604088a58f87d4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include <uitool.hxx>
25 #include <swtypes.hxx>
26 #include <wrtsh.hxx>
27 #include <view.hxx>
28 #include <viewopt.hxx>
29 #include <break.hxx>
30 #include <pagedesc.hxx>
31 #include <poolfmt.hxx>
33 #include <strings.hrc>
34 #include <SwStyleNameMapper.hxx>
35 #include <names.hxx>
37 void SwBreakDlg::rememberResult()
39 m_nKind = 0;
40 if (m_xLineBtn->get_active())
42 m_nKind = 1;
43 m_eClear = static_cast<SwLineBreakClear>(m_xLineClearBox->get_active());
45 else if(m_xColumnBtn->get_active())
46 m_nKind = 2;
47 else if(m_xPageBtn->get_active())
49 m_nKind = 3;
50 const int nPos = m_xPageCollBox->get_active();
51 if (nPos != 0 && nPos != -1)
53 m_aTemplate = m_xPageCollBox->get_active_text();
54 m_oPgNum.reset();
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)
65 CheckEnable();
66 UpdateImage();
69 IMPL_LINK_NOARG(SwBreakDlg, ChangeHdl, weld::ComboBox&, void)
71 CheckEnable();
74 IMPL_LINK_NOARG(SwBreakDlg, LineClearHdl, weld::ComboBox&, void)
76 UpdateImage();
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);
84 else
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);
95 * Ok-Handler;
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);
109 else
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());
114 bool bOk = true;
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
123 if(!bOk)
125 std::unique_ptr<weld::Dialog> xDialog(Application::CreateMessageDialog(m_xPageNumEdit.get(), VclMessageType::Info,
126 VclButtonsType::Ok, SwResId(STR_ILLEGAL_PAGENUM)));
127 xDialog->run();
128 m_xPageNumEdit->grab_focus();
129 return;
132 rememberResult();
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))
149 , m_rSh(rS)
150 , m_nKind(0)
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 );
179 //add landscape page
180 aFormatName = SwStyleNameMapper::GetUIName( RES_POOLPAGE_LANDSCAPE, ProgName() );
181 if (m_xPageCollBox->find_text(aFormatName) == -1)
182 ::InsertStringSorted(u""_ustr, aFormatName, *m_xPageCollBox, 1);
183 CheckEnable();
184 m_xPageNumEdit->set_text(OUString());
185 UpdateImage();
188 void SwBreakDlg::CheckEnable()
190 bool bEnable = true;
191 if ( m_bHtmlMode )
193 m_xColumnBtn->set_sensitive(false);
194 m_xPageCollBox->set_sensitive(false);
195 bEnable = 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);
203 bEnable = false;
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);
212 bEnable &= bPage;
213 if ( bEnable )
215 // position 0 says 'Without' page template.
216 const int nPos = m_xPageCollBox->get_active();
217 if (nPos == 0 || nPos == -1)
218 bEnable = false;
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())
230 case 0:
231 m_xTypeImage->set_from_icon_name(RID_BMP_LINEBREAK_NONE);
232 break;
233 case 1:
234 m_xTypeImage->set_from_icon_name(RID_BMP_LINEBREAK_LEFT);
235 break;
236 case 2:
237 m_xTypeImage->set_from_icon_name(RID_BMP_LINEBREAK_RIGHT);
238 break;
239 case 3:
240 m_xTypeImage->set_from_icon_name(RID_BMP_LINEBREAK_FULL);
241 break;
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);
248 else
249 m_xTypeImage->set_from_icon_name(""); //clear
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */