LibreOffice Module sw (master) 1
break.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <vcl/svapp.hxx>
21#include <osl/diagnose.h>
22
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>
31
32#include <strings.hrc>
33#include <SwStyleNameMapper.hxx>
34
36{
37 m_nKind = 0;
38 if (m_xLineBtn->get_active())
39 {
40 m_nKind = 1;
41 m_eClear = static_cast<SwLineBreakClear>(m_xLineClearBox->get_active());
42 }
43 else if(m_xColumnBtn->get_active())
44 m_nKind = 2;
45 else if(m_xPageBtn->get_active())
46 {
47 m_nKind = 3;
48 const int nPos = m_xPageCollBox->get_active();
49 if (nPos != 0 && nPos != -1)
50 {
51 m_aTemplate = m_xPageCollBox->get_active_text();
52 m_oPgNum.reset();
53 if (m_xPageNumBox->get_active())
54 {
55 m_oPgNum = o3tl::narrowing<sal_uInt16>(m_xPageNumEdit->get_value());
56 }
57 }
58 }
59}
60
62{
63 CheckEnable();
64}
65
67{
68 CheckEnable();
69}
70
71// Handler for Change Page Number
72IMPL_LINK(SwBreakDlg, PageNumHdl, weld::Toggleable&, rBox, void)
73{
74 if (rBox.get_active())
75 m_xPageNumEdit->set_value(1);
76 else
77 m_xPageNumEdit->set_text(OUString());
78}
79
80// By changing the Page number the checkbox is checked.
82{
83 m_xPageNumBox->set_active(true);
84}
85
86/*
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)
90 */
92{
93 if (m_xPageNumBox->get_active())
94 {
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());
103
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())
108 {
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
114 }
115 if(!bOk)
116 {
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;
122 }
123 }
124 rememberResult();
125 m_xDialog->response(RET_OK);
126}
127
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()))
143{
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));
149
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));
153
154 // Insert page description to Listbox
155 const size_t nCount = m_rSh.GetPageDescCnt();
156 for (size_t i = 0; i < nCount; ++i)
157 {
158 const SwPageDesc &rPageDesc = m_rSh.GetPageDesc(i);
159 ::InsertStringSorted("", rPageDesc.GetName(), *m_xPageCollBox, 1 );
160 }
161
162 OUString aFormatName;
163 for (sal_uInt16 i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
164 {
165 aFormatName = SwStyleNameMapper::GetUIName( i, aFormatName );
166 if (m_xPageCollBox->find_text(aFormatName) == -1)
167 ::InsertStringSorted("", aFormatName, *m_xPageCollBox, 1 );
168 }
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());
175}
176
178{
179 bool bEnable = true;
180 if ( m_bHtmlMode )
181 {
182 m_xColumnBtn->set_sensitive(false);
183 m_xPageCollBox->set_sensitive(false);
184 bEnable = false;
185 }
186 else if(m_rSh.GetFrameType(nullptr,true)
188 {
189 m_xPageBtn->set_sensitive(false);
190 if (m_xPageBtn->get_active())
191 m_xLineBtn->set_active(true);
192 bEnable = false;
193 }
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);
200
201 bEnable &= bPage;
202 if ( bEnable )
203 {
204 // position 0 says 'Without' page template.
205 const int nPos = m_xPageCollBox->get_active();
206 if (nPos == 0 || nPos == -1)
207 bEnable = false;
208 }
209 m_xPageNumBox->set_sensitive(bEnable);
210 m_xPageNumEdit->set_sensitive(bEnable);
211}
212
213/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
IMPL_LINK_NOARG(SwBreakDlg, ToggleHdl, weld::Toggleable &, void)
Definition: break.cxx:61
IMPL_LINK(SwBreakDlg, PageNumHdl, weld::Toggleable &, rBox, void)
Definition: break.cxx:72
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
std::unique_ptr< weld::RadioButton > m_xLineBtn
Definition: break.hxx:31
std::unique_ptr< weld::ComboBox > m_xPageCollBox
Definition: break.hxx:37
std::unique_ptr< weld::RadioButton > m_xColumnBtn
Definition: break.hxx:34
SwBreakDlg(weld::Window *pParent, SwWrtShell &rSh)
Definition: break.cxx:128
bool m_bHtmlMode
Definition: break.hxx:48
::std::optional< sal_uInt16 > m_oPgNum
Definition: break.hxx:45
std::unique_ptr< weld::RadioButton > m_xPageBtn
Definition: break.hxx:35
std::optional< SwLineBreakClear > m_eClear
Definition: break.hxx:46
OUString m_aTemplate
Definition: break.hxx:43
std::unique_ptr< weld::Button > m_xOkBtn
Definition: break.hxx:40
std::unique_ptr< weld::CheckButton > m_xPageNumBox
Definition: break.hxx:38
void rememberResult()
Definition: break.cxx:35
std::unique_ptr< weld::Label > m_xPageCollText
Definition: break.hxx:36
void CheckEnable()
Definition: break.cxx:177
std::unique_ptr< weld::Label > m_xLineClearText
Definition: break.hxx:32
SwWrtShell & m_rSh
Definition: break.hxx:42
std::unique_ptr< weld::ComboBox > m_xLineClearBox
Definition: break.hxx:33
std::unique_ptr< weld::SpinButton > m_xPageNumEdit
Definition: break.hxx:39
sal_uInt16 m_nKind
Definition: break.hxx:44
FrameTypeFlags GetFrameType(const Point *pPt, bool bStopAtFly) const
For return values see above FrameType.
Definition: fews.cxx:237
size_t GetPageDescCnt() const
Definition: fedesc.cxx:38
const SwPageDesc & GetPageDesc(size_t i) const
Definition: fedesc.cxx:126
const OUString & GetName() const
Definition: pagedesc.hxx:196
UseOnPage GetUseOn() const
Definition: pagedesc.hxx:353
static const OUString & GetUIName(const OUString &rName, SwGetPoolIdFromName)
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
int nCount
SwLineBreakClear
Defines the location of a line break text wrapping restart.
sal_uInt16 nPos
int i
@ RES_POOLPAGE_END
Definition: poolfmt.hxx:181
@ RES_POOLPAGE_BEGIN
Definition: poolfmt.hxx:168
@ RES_POOLPAGE_LANDSCAPE
Landscape page style.
Definition: poolfmt.hxx:179
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
SW_DLLPUBLIC void InsertStringSorted(const OUString &rId, const OUString &rEntry, weld::ComboBox &rToFill, int nOffset)
Definition: uitool.cxx:768
RET_OK
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:415