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