nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / ui / chrdlg / break.cxx
blob03b316895b090ca22bf2ff2b960c74088707d486
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>
22 #include <uitool.hxx>
23 #include <swtypes.hxx>
24 #include <wrtsh.hxx>
25 #include <view.hxx>
26 #include <viewopt.hxx>
27 #include <break.hxx>
28 #include <pagedesc.hxx>
29 #include <poolfmt.hxx>
31 #include <strings.hrc>
32 #include <SwStyleNameMapper.hxx>
34 void SwBreakDlg::rememberResult()
36 nKind = 0;
37 if (m_xLineBtn->get_active())
38 nKind = 1;
39 else if(m_xColumnBtn->get_active())
40 nKind = 2;
41 else if(m_xPageBtn->get_active())
43 nKind = 3;
44 const int nPos = m_xPageCollBox->get_active();
45 if (nPos != 0 && nPos != -1)
47 m_aTemplate = m_xPageCollBox->get_active_text();
48 oPgNum.reset();
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)
59 CheckEnable();
62 IMPL_LINK_NOARG(SwBreakDlg, ChangeHdl, weld::ComboBox&, void)
64 CheckEnable();
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);
72 else
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);
83 * Ok-Handler;
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);
97 else
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());
102 bool bOk = true;
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
111 if(!bOk)
113 std::unique_ptr<weld::Dialog> xDialog(Application::CreateMessageDialog(m_xPageNumEdit.get(), VclMessageType::Info,
114 VclButtonsType::Ok, SwResId(STR_ILLEGAL_PAGENUM)));
115 xDialog->run();
116 m_xPageNumEdit->grab_focus();
117 return;
120 rememberResult();
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"))
134 , rSh(rS)
135 , nKind(0)
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 );
163 //add landscape page
164 aFormatName = SwStyleNameMapper::GetUIName( RES_POOLPAGE_LANDSCAPE, aFormatName );
165 if (m_xPageCollBox->find_text(aFormatName) == -1)
166 ::InsertStringSorted("", aFormatName, *m_xPageCollBox, 1);
167 CheckEnable();
168 m_xPageNumEdit->set_text(OUString());
171 void SwBreakDlg::CheckEnable()
173 bool bEnable = true;
174 if ( bHtmlMode )
176 m_xColumnBtn->set_sensitive(false);
177 m_xPageCollBox->set_sensitive(false);
178 bEnable = 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);
186 bEnable = false;
188 const bool bPage = m_xPageBtn->get_active();
189 m_xPageCollText->set_sensitive(bPage);
190 m_xPageCollBox->set_sensitive(bPage);
192 bEnable &= bPage;
193 if ( bEnable )
195 // position 0 says 'Without' page template.
196 const int nPos = m_xPageCollBox->get_active();
197 if (nPos == 0 || nPos == -1)
198 bEnable = false;
200 m_xPageNumBox->set_sensitive(bEnable);
201 m_xPageNumEdit->set_sensitive(bEnable);
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */