Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / ui / chrdlg / break.cxx
blob34048c2564591ba39269c9b802796667fd2e302b
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>
23 #include <uitool.hxx>
24 #include <swtypes.hxx>
25 #include <wrtsh.hxx>
26 #include <view.hxx>
27 #include <viewopt.hxx>
28 #include <break.hxx>
29 #include <pagedesc.hxx>
30 #include <poolfmt.hxx>
32 #include <strings.hrc>
33 #include <SwStyleNameMapper.hxx>
35 void SwBreakDlg::rememberResult()
37 m_nKind = 0;
38 if (m_xLineBtn->get_active())
40 m_nKind = 1;
41 m_eClear = static_cast<SwLineBreakClear>(m_xLineClearBox->get_active());
43 else if(m_xColumnBtn->get_active())
44 m_nKind = 2;
45 else if(m_xPageBtn->get_active())
47 m_nKind = 3;
48 const int nPos = m_xPageCollBox->get_active();
49 if (nPos != 0 && nPos != -1)
51 m_aTemplate = m_xPageCollBox->get_active_text();
52 m_oPgNum.reset();
53 if (m_xPageNumBox->get_active())
55 m_oPgNum = o3tl::narrowing<sal_uInt16>(m_xPageNumEdit->get_value());
61 IMPL_LINK_NOARG(SwBreakDlg, ToggleHdl, weld::Toggleable&, void)
63 CheckEnable();
66 IMPL_LINK_NOARG(SwBreakDlg, ChangeHdl, weld::ComboBox&, void)
68 CheckEnable();
71 // Handler for Change Page Number
72 IMPL_LINK(SwBreakDlg, PageNumHdl, weld::Toggleable&, rBox, void)
74 if (rBox.get_active())
75 m_xPageNumEdit->set_value(1);
76 else
77 m_xPageNumEdit->set_text(OUString());
80 // By changing the Page number the checkbox is checked.
81 IMPL_LINK_NOARG(SwBreakDlg, PageNumModifyHdl, weld::SpinButton&, void)
83 m_xPageNumBox->set_active(true);
87 * Ok-Handler;
88 * checks whether pagenumber nPage is a legal pagenumber (left pages with even
89 * numbers etc. for a page template with alternating pages)
91 IMPL_LINK_NOARG(SwBreakDlg, OkHdl, weld::Button&, void)
93 if (m_xPageNumBox->get_active())
95 // In case of differing page descriptions, test validity
96 const int nPos = m_xPageCollBox->get_active();
97 // position 0 says 'Without'.
98 const SwPageDesc *pPageDesc;
99 if (nPos != 0 && nPos != -1)
100 pPageDesc = m_rSh.FindPageDescByName(m_xPageCollBox->get_active_text(), true);
101 else
102 pPageDesc = &m_rSh.GetPageDesc(m_rSh.GetCurPageDesc());
104 OSL_ENSURE(pPageDesc, "Page description not found.");
105 const sal_uInt16 nUserPage = sal_uInt16(m_xPageNumEdit->get_value());
106 bool bOk = true;
107 switch(pPageDesc->GetUseOn())
109 case UseOnPage::Mirror:
110 case UseOnPage::All: break;
111 case UseOnPage::Left: bOk = 0 == nUserPage % 2; break;
112 case UseOnPage::Right: bOk = 1 == nUserPage % 2; break;
113 default:; //prevent warning
115 if(!bOk)
117 std::unique_ptr<weld::Dialog> xDialog(Application::CreateMessageDialog(m_xPageNumEdit.get(), VclMessageType::Info,
118 VclButtonsType::Ok, SwResId(STR_ILLEGAL_PAGENUM)));
119 xDialog->run();
120 m_xPageNumEdit->grab_focus();
121 return;
124 rememberResult();
125 m_xDialog->response(RET_OK);
128 SwBreakDlg::SwBreakDlg(weld::Window *pParent, SwWrtShell &rS)
129 : GenericDialogController(pParent, "modules/swriter/ui/insertbreak.ui", "BreakDialog")
130 , m_xLineBtn(m_xBuilder->weld_radio_button("linerb"))
131 , m_xLineClearText(m_xBuilder->weld_label("clearft"))
132 , m_xLineClearBox(m_xBuilder->weld_combo_box("clearlb"))
133 , m_xColumnBtn(m_xBuilder->weld_radio_button("columnrb"))
134 , m_xPageBtn(m_xBuilder->weld_radio_button("pagerb"))
135 , m_xPageCollText(m_xBuilder->weld_label("styleft"))
136 , m_xPageCollBox(m_xBuilder->weld_combo_box("stylelb"))
137 , m_xPageNumBox(m_xBuilder->weld_check_button("pagenumcb"))
138 , m_xPageNumEdit(m_xBuilder->weld_spin_button("pagenumsb"))
139 , m_xOkBtn(m_xBuilder->weld_button("ok"))
140 , m_rSh(rS)
141 , m_nKind(0)
142 , m_bHtmlMode(0 != ::GetHtmlMode(rS.GetView().GetDocShell()))
144 Link<weld::Toggleable&,void> aLk = LINK(this, SwBreakDlg, ToggleHdl);
145 m_xPageBtn->connect_toggled(aLk);
146 m_xLineBtn->connect_toggled(aLk);
147 m_xColumnBtn->connect_toggled(aLk);
148 m_xPageCollBox->connect_changed(LINK(this, SwBreakDlg, ChangeHdl));
150 m_xOkBtn->connect_clicked(LINK(this, SwBreakDlg, OkHdl));
151 m_xPageNumBox->connect_toggled(LINK(this, SwBreakDlg, PageNumHdl));
152 m_xPageNumEdit->connect_value_changed(LINK(this, SwBreakDlg, PageNumModifyHdl));
154 // Insert page description to Listbox
155 const size_t nCount = m_rSh.GetPageDescCnt();
156 for (size_t i = 0; i < nCount; ++i)
158 const SwPageDesc &rPageDesc = m_rSh.GetPageDesc(i);
159 ::InsertStringSorted("", rPageDesc.GetName(), *m_xPageCollBox, 1 );
162 OUString aFormatName;
163 for (sal_uInt16 i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
165 aFormatName = SwStyleNameMapper::GetUIName( i, aFormatName );
166 if (m_xPageCollBox->find_text(aFormatName) == -1)
167 ::InsertStringSorted("", aFormatName, *m_xPageCollBox, 1 );
169 //add landscape page
170 aFormatName = SwStyleNameMapper::GetUIName( RES_POOLPAGE_LANDSCAPE, aFormatName );
171 if (m_xPageCollBox->find_text(aFormatName) == -1)
172 ::InsertStringSorted("", aFormatName, *m_xPageCollBox, 1);
173 CheckEnable();
174 m_xPageNumEdit->set_text(OUString());
177 void SwBreakDlg::CheckEnable()
179 bool bEnable = true;
180 if ( m_bHtmlMode )
182 m_xColumnBtn->set_sensitive(false);
183 m_xPageCollBox->set_sensitive(false);
184 bEnable = false;
186 else if(m_rSh.GetFrameType(nullptr,true)
187 & (FrameTypeFlags::FLY_ANY | FrameTypeFlags::HEADER | FrameTypeFlags::FOOTER | FrameTypeFlags::FOOTNOTE))
189 m_xPageBtn->set_sensitive(false);
190 if (m_xPageBtn->get_active())
191 m_xLineBtn->set_active(true);
192 bEnable = false;
194 const bool bPage = m_xPageBtn->get_active();
195 m_xPageCollText->set_sensitive(bPage);
196 m_xPageCollBox->set_sensitive(bPage);
197 bool bLine = m_xLineBtn->get_active();
198 m_xLineClearText->set_sensitive(bLine);
199 m_xLineClearBox->set_sensitive(bLine);
201 bEnable &= bPage;
202 if ( bEnable )
204 // position 0 says 'Without' page template.
205 const int nPos = m_xPageCollBox->get_active();
206 if (nPos == 0 || nPos == -1)
207 bEnable = false;
209 m_xPageNumBox->set_sensitive(bEnable);
210 m_xPageNumEdit->set_sensitive(bEnable);
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */