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  nKind = 0;
38  if (m_xLineBtn->get_active())
39  nKind = 1;
40  else if(m_xColumnBtn->get_active())
41  nKind = 2;
42  else if(m_xPageBtn->get_active())
43  {
44  nKind = 3;
45  const int nPos = m_xPageCollBox->get_active();
46  if (nPos != 0 && nPos != -1)
47  {
48  m_aTemplate = m_xPageCollBox->get_active_text();
49  oPgNum.reset();
50  if (m_xPageNumBox->get_active())
51  {
52  oPgNum = o3tl::narrowing<sal_uInt16>(m_xPageNumEdit->get_value());
53  }
54  }
55  }
56 }
57 
59 {
60  CheckEnable();
61 }
62 
64 {
65  CheckEnable();
66 }
67 
68 // Handler for Change Page Number
69 IMPL_LINK(SwBreakDlg, PageNumHdl, weld::Toggleable&, rBox, void)
70 {
71  if (rBox.get_active())
72  m_xPageNumEdit->set_value(1);
73  else
74  m_xPageNumEdit->set_text(OUString());
75 }
76 
77 // By changing the Page number the checkbox is checked.
78 IMPL_LINK_NOARG(SwBreakDlg, PageNumModifyHdl, weld::SpinButton&, void)
79 {
80  m_xPageNumBox->set_active(true);
81 }
82 
83 /*
84  * Ok-Handler;
85  * checks whether pagenumber nPage is a legal pagenumber (left pages with even
86  * numbers etc. for a page template with alternating pages)
87  */
89 {
90  if (m_xPageNumBox->get_active())
91  {
92  // In case of differing page descriptions, test validity
93  const int nPos = m_xPageCollBox->get_active();
94  // position 0 says 'Without'.
95  const SwPageDesc *pPageDesc;
96  if (nPos != 0 && nPos != -1)
97  pPageDesc = rSh.FindPageDescByName(m_xPageCollBox->get_active_text(), true);
98  else
99  pPageDesc = &rSh.GetPageDesc(rSh.GetCurPageDesc());
100 
101  OSL_ENSURE(pPageDesc, "Page description not found.");
102  const sal_uInt16 nUserPage = sal_uInt16(m_xPageNumEdit->get_value());
103  bool bOk = true;
104  switch(pPageDesc->GetUseOn())
105  {
106  case UseOnPage::Mirror:
107  case UseOnPage::All: break;
108  case UseOnPage::Left: bOk = 0 == nUserPage % 2; break;
109  case UseOnPage::Right: bOk = 1 == nUserPage % 2; break;
110  default:; //prevent warning
111  }
112  if(!bOk)
113  {
114  std::unique_ptr<weld::Dialog> xDialog(Application::CreateMessageDialog(m_xPageNumEdit.get(), VclMessageType::Info,
115  VclButtonsType::Ok, SwResId(STR_ILLEGAL_PAGENUM)));
116  xDialog->run();
117  m_xPageNumEdit->grab_focus();
118  return;
119  }
120  }
121  rememberResult();
122  m_xDialog->response(RET_OK);
123 }
124 
126  : GenericDialogController(pParent, "modules/swriter/ui/insertbreak.ui", "BreakDialog")
127  , m_xLineBtn(m_xBuilder->weld_radio_button("linerb"))
128  , m_xColumnBtn(m_xBuilder->weld_radio_button("columnrb"))
129  , m_xPageBtn(m_xBuilder->weld_radio_button("pagerb"))
130  , m_xPageCollText(m_xBuilder->weld_label("styleft"))
131  , m_xPageCollBox(m_xBuilder->weld_combo_box("stylelb"))
132  , m_xPageNumBox(m_xBuilder->weld_check_button("pagenumcb"))
133  , m_xPageNumEdit(m_xBuilder->weld_spin_button("pagenumsb"))
134  , m_xOkBtn(m_xBuilder->weld_button("ok"))
135  , rSh(rS)
136  , nKind(0)
137  , bHtmlMode(0 != ::GetHtmlMode(rS.GetView().GetDocShell()))
138 {
139  Link<weld::Toggleable&,void> aLk = LINK(this, SwBreakDlg, ToggleHdl);
140  m_xPageBtn->connect_toggled(aLk);
141  m_xLineBtn->connect_toggled(aLk);
142  m_xColumnBtn->connect_toggled(aLk);
143  m_xPageCollBox->connect_changed(LINK(this, SwBreakDlg, ChangeHdl));
144 
145  m_xOkBtn->connect_clicked(LINK(this, SwBreakDlg, OkHdl));
146  m_xPageNumBox->connect_toggled(LINK(this, SwBreakDlg, PageNumHdl));
147  m_xPageNumEdit->connect_value_changed(LINK(this, SwBreakDlg, PageNumModifyHdl));
148 
149  // Insert page description to Listbox
150  const size_t nCount = rSh.GetPageDescCnt();
151  for (size_t i = 0; i < nCount; ++i)
152  {
153  const SwPageDesc &rPageDesc = rSh.GetPageDesc(i);
154  ::InsertStringSorted("", rPageDesc.GetName(), *m_xPageCollBox, 1 );
155  }
156 
157  OUString aFormatName;
158  for (sal_uInt16 i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
159  {
160  aFormatName = SwStyleNameMapper::GetUIName( i, aFormatName );
161  if (m_xPageCollBox->find_text(aFormatName) == -1)
162  ::InsertStringSorted("", aFormatName, *m_xPageCollBox, 1 );
163  }
164  //add landscape page
165  aFormatName = SwStyleNameMapper::GetUIName( RES_POOLPAGE_LANDSCAPE, aFormatName );
166  if (m_xPageCollBox->find_text(aFormatName) == -1)
167  ::InsertStringSorted("", aFormatName, *m_xPageCollBox, 1);
168  CheckEnable();
169  m_xPageNumEdit->set_text(OUString());
170 }
171 
173 {
174  bool bEnable = true;
175  if ( bHtmlMode )
176  {
177  m_xColumnBtn->set_sensitive(false);
178  m_xPageCollBox->set_sensitive(false);
179  bEnable = false;
180  }
181  else if(rSh.GetFrameType(nullptr,true)
183  {
184  m_xPageBtn->set_sensitive(false);
185  if (m_xPageBtn->get_active())
186  m_xLineBtn->set_active(true);
187  bEnable = false;
188  }
189  const bool bPage = m_xPageBtn->get_active();
190  m_xPageCollText->set_sensitive(bPage);
191  m_xPageCollBox->set_sensitive(bPage);
192 
193  bEnable &= bPage;
194  if ( bEnable )
195  {
196  // position 0 says 'Without' page template.
197  const int nPos = m_xPageCollBox->get_active();
198  if (nPos == 0 || nPos == -1)
199  bEnable = false;
200  }
201  m_xPageNumBox->set_sensitive(bEnable);
202  m_xPageNumEdit->set_sensitive(bEnable);
203 }
204 
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Label > m_xPageCollText
Definition: break.hxx:33
size_t GetPageDescCnt() const
Definition: fedesc.cxx:38
sal_uInt16 nKind
Definition: break.hxx:41
SwBreakDlg(weld::Window *pParent, SwWrtShell &rSh)
Definition: break.cxx:125
UseOnPage GetUseOn() const
Definition: pagedesc.hxx:353
Landscape page style.
Definition: poolfmt.hxx:179
const OUString & GetName() const
Definition: pagedesc.hxx:196
void CheckEnable()
Definition: break.cxx:172
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165
int nCount
std::unique_ptr< weld::RadioButton > m_xLineBtn
Definition: break.hxx:30
std::unique_ptr< weld::RadioButton > m_xColumnBtn
Definition: break.hxx:31
int i
void rememberResult()
Definition: break.cxx:35
SW_DLLPUBLIC void InsertStringSorted(const OUString &rId, const OUString &rEntry, weld::ComboBox &rToFill, int nOffset)
Definition: uitool.cxx:778
OUString m_aTemplate
Definition: break.hxx:40
const SwPageDesc & GetPageDesc(size_t i) const
Definition: fedesc.cxx:126
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:354
std::unique_ptr< weld::SpinButton > m_xPageNumEdit
Definition: break.hxx:36
SwWrtShell & rSh
Definition: break.hxx:39
std::unique_ptr< weld::CheckButton > m_xPageNumBox
Definition: break.hxx:35
bool bHtmlMode
Definition: break.hxx:44
IMPL_LINK_NOARG(SwBreakDlg, ToggleHdl, weld::Toggleable &, void)
Definition: break.cxx:58
RET_OK
std::unique_ptr< weld::Button > m_xOkBtn
Definition: break.hxx:37
Reference< XExecutableDialog > m_xDialog
static const OUString & GetUIName(const OUString &rName, SwGetPoolIdFromName)
std::unique_ptr< weld::RadioButton > m_xPageBtn
Definition: break.hxx:32
std::unique_ptr< weld::ComboBox > m_xPageCollBox
Definition: break.hxx:34
::std::optional< sal_uInt16 > oPgNum
Definition: break.hxx:42
IMPL_LINK(SwBreakDlg, PageNumHdl, weld::Toggleable &, rBox, void)
Definition: break.cxx:69
FrameTypeFlags GetFrameType(const Point *pPt, bool bStopAtFly) const
For return values see above FrameType.
Definition: fews.cxx:237
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
sal_uInt16 nPos