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 
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>
30 
31 #include <strings.hrc>
32 #include <SwStyleNameMapper.hxx>
33 
35 {
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())
42  {
43  nKind = 3;
44  const int nPos = m_xPageCollBox->get_active();
45  if (nPos != 0 && nPos != -1)
46  {
47  m_aTemplate = m_xPageCollBox->get_active_text();
48  oPgNum.reset();
49  if (m_xPageNumBox->get_active())
50  {
51  oPgNum = static_cast<sal_uInt16>(m_xPageNumEdit->get_value());
52  }
53  }
54  }
55 }
56 
58 {
59  CheckEnable();
60 }
61 
63 {
64  CheckEnable();
65 }
66 
67 // Handler for Change Page Number
68 IMPL_LINK(SwBreakDlg, PageNumHdl, weld::ToggleButton&, rBox, void)
69 {
70  if (rBox.get_active())
71  m_xPageNumEdit->set_value(1);
72  else
73  m_xPageNumEdit->set_text(OUString());
74 }
75 
76 // By changing the Page number the checkbox is checked.
77 IMPL_LINK_NOARG(SwBreakDlg, PageNumModifyHdl, weld::SpinButton&, void)
78 {
79  m_xPageNumBox->set_active(true);
80 }
81 
82 /*
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)
86  */
88 {
89  if (m_xPageNumBox->get_active())
90  {
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());
99 
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())
104  {
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
110  }
111  if(!bOk)
112  {
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;
118  }
119  }
120  rememberResult();
121  m_xDialog->response(RET_OK);
122 }
123 
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()))
137 {
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));
143 
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));
147 
148  // Insert page description to Listbox
149  const size_t nCount = rSh.GetPageDescCnt();
150  for (size_t i = 0; i < nCount; ++i)
151  {
152  const SwPageDesc &rPageDesc = rSh.GetPageDesc(i);
153  ::InsertStringSorted("", rPageDesc.GetName(), *m_xPageCollBox, 1 );
154  }
155 
156  OUString aFormatName;
157  for (sal_uInt16 i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
158  {
159  aFormatName = SwStyleNameMapper::GetUIName( i, aFormatName );
160  if (m_xPageCollBox->find_text(aFormatName) == -1)
161  ::InsertStringSorted("", aFormatName, *m_xPageCollBox, 1 );
162  }
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());
169 }
170 
172 {
173  bool bEnable = true;
174  if ( bHtmlMode )
175  {
176  m_xColumnBtn->set_sensitive(false);
177  m_xPageCollBox->set_sensitive(false);
178  bEnable = false;
179  }
180  else if(rSh.GetFrameType(nullptr,true)
182  {
183  m_xPageBtn->set_sensitive(false);
184  if (m_xPageBtn->get_active())
185  m_xLineBtn->set_active(true);
186  bEnable = false;
187  }
188  const bool bPage = m_xPageBtn->get_active();
189  m_xPageCollText->set_sensitive(bPage);
190  m_xPageCollBox->set_sensitive(bPage);
191 
192  bEnable &= bPage;
193  if ( bEnable )
194  {
195  // position 0 says 'Without' page template.
196  const int nPos = m_xPageCollBox->get_active();
197  if (nPos == 0 || nPos == -1)
198  bEnable = false;
199  }
200  m_xPageNumBox->set_sensitive(bEnable);
201  m_xPageNumEdit->set_sensitive(bEnable);
202 }
203 
204 /* 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:37
sal_uInt16 nKind
Definition: break.hxx:41
SwBreakDlg(weld::Window *pParent, SwWrtShell &rSh)
Definition: break.cxx:124
UseOnPage GetUseOn() const
Definition: pagedesc.hxx:332
Landscape page style.
Definition: poolfmt.hxx:180
const OUString & GetName() const
Definition: pagedesc.hxx:187
void CheckEnable()
Definition: break.cxx:171
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
int nCount
std::unique_ptr< weld::RadioButton > m_xLineBtn
Definition: break.hxx:30
std::unique_ptr< weld::RadioButton > m_xColumnBtn
Definition: break.hxx:31
IMPL_LINK(SwBreakDlg, PageNumHdl, weld::ToggleButton &, rBox, void)
Definition: break.cxx:68
int i
IMPL_LINK_NOARG(SwBreakDlg, ToggleHdl, weld::ToggleButton &, void)
Definition: break.cxx:57
void rememberResult()
Definition: break.cxx:34
SW_DLLPUBLIC void InsertStringSorted(const OUString &rId, const OUString &rEntry, weld::ComboBox &rToFill, int nOffset)
Definition: uitool.cxx:698
OUString m_aTemplate
Definition: break.hxx:40
const SwPageDesc & GetPageDesc(size_t i) const
Definition: fedesc.cxx:125
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:337
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
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
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
FrameTypeFlags GetFrameType(const Point *pPt, bool bStopAtFly) const
For return values see above FrameType.
Definition: fews.cxx:236
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
sal_uInt16 nPos