update credits
[LibreOffice.git] / sw / source / ui / chrdlg / break.cxx
blob032bdd69eb0411b80198851b60f958aa123a722b
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 <sfx2/request.hxx>
21 #include <svl/stritem.hxx>
22 #include <vcl/msgbox.hxx>
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>
35 #include <chrdlg.hrc>
36 #include <SwStyleNameMapper.hxx>
38 void SwBreakDlg::Apply()
40 nKind = 0;
41 if(m_pLineBtn->IsChecked())
42 nKind = 1;
43 else if(m_pColumnBtn->IsChecked())
44 nKind = 2;
45 else if(m_pPageBtn->IsChecked())
47 nKind = 3;
48 const sal_uInt16 nPos = m_pPageCollBox->GetSelectEntryPos();
49 if(0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos)
51 aTemplate = m_pPageCollBox->GetSelectEntry();
52 nPgNum = m_pPageNumBox->IsChecked() ? (sal_uInt16)m_pPageNumEdit->GetValue() : 0;
57 IMPL_LINK_NOARG_INLINE_START(SwBreakDlg, ClickHdl)
59 CheckEnable();
60 return 0;
62 IMPL_LINK_NOARG_INLINE_END(SwBreakDlg, ClickHdl)
64 /*------------------------------------------------------------------------
65 Description: Handler for Change Page Number
66 ------------------------------------------------------------------------*/
68 IMPL_LINK_INLINE_START( SwBreakDlg, PageNumHdl, CheckBox *, pBox )
70 if(pBox->IsChecked()) m_pPageNumEdit->SetValue(1);
71 else m_pPageNumEdit->SetText(OUString());
72 return 0;
74 IMPL_LINK_INLINE_END( SwBreakDlg, PageNumHdl, CheckBox *, pBox )
76 /*------------------------------------------------------------------------
77 Description: By changing the Page number the checkbox is checked.
78 ------------------------------------------------------------------------*/
80 IMPL_LINK_NOARG_INLINE_START(SwBreakDlg, PageNumModifyHdl)
82 m_pPageNumBox->Check();
83 return 0;
85 IMPL_LINK_NOARG_INLINE_END(SwBreakDlg, PageNumModifyHdl)
87 /*------------------------------------------------------------------------
88 Description: Ok-Handler;
89 checks whether pagenumber nPage is a legal pagenumber
90 (left pages with even numbers etc. for a page template
91 with alternating pages)
92 ------------------------------------------------------------------------*/
94 IMPL_LINK_NOARG(SwBreakDlg, OkHdl)
96 if(m_pPageNumBox->IsChecked()) {
97 // In case of differing page descriptions, test validity
98 const sal_uInt16 nPos = m_pPageCollBox->GetSelectEntryPos();
99 // position 0 says 'Without'.
100 const SwPageDesc *pPageDesc;
101 if ( 0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos )
102 pPageDesc = rSh.FindPageDescByName( m_pPageCollBox->GetSelectEntry(),
103 sal_True );
104 else
105 pPageDesc = &rSh.GetPageDesc(rSh.GetCurPageDesc());
107 OSL_ENSURE(pPageDesc, "Page description not found.");
108 const sal_uInt16 nUserPage = sal_uInt16(m_pPageNumEdit->GetValue());
109 sal_Bool bOk = sal_True;
110 switch(pPageDesc->GetUseOn())
112 case nsUseOnPage::PD_MIRROR:
113 case nsUseOnPage::PD_ALL: break;
114 case nsUseOnPage::PD_LEFT: bOk = 0 == nUserPage % 2; break;
115 case nsUseOnPage::PD_RIGHT: bOk = static_cast< sal_Bool >(nUserPage % 2); break;
116 default:; //prevent warning
118 if(!bOk) {
119 InfoBox(this, SW_RES(MSG_ILLEGAL_PAGENUM)).Execute();
120 m_pPageNumEdit->GrabFocus();
121 return 0;
124 EndDialog(RET_OK);
125 return 0;
128 SwBreakDlg::SwBreakDlg( Window *pParent, SwWrtShell &rS )
129 : SvxStandardDialog(pParent, "BreakDialog", "modules/swriter/ui/insertbreak.ui")
130 , rSh(rS)
131 , nKind(0)
132 , nPgNum(0)
133 , bHtmlMode(0 != ::GetHtmlMode(rS.GetView().GetDocShell()))
135 get(m_pLineBtn, "linerb");
136 get(m_pColumnBtn, "columnrb");
137 get(m_pPageBtn, "pagerb");
138 get(m_pPageCollText, "styleft");
139 get(m_pPageCollBox, "stylelb");
140 get(m_pPageNumBox, "pagenumcb");
141 get(m_pPageNumEdit, "pagenumsb");
143 m_pPageNumEdit->SetAccessibleName(m_pPageNumBox->GetText());
145 Link aLk = LINK(this,SwBreakDlg,ClickHdl);
146 m_pPageBtn->SetClickHdl( aLk );
147 m_pLineBtn->SetClickHdl( aLk );
148 m_pColumnBtn->SetClickHdl( aLk );
149 m_pPageCollBox->SetSelectHdl( aLk );
151 get<OKButton>("ok")->SetClickHdl(LINK(this,SwBreakDlg,OkHdl));;
152 m_pPageNumBox->SetClickHdl(LINK(this,SwBreakDlg,PageNumHdl));
153 m_pPageNumEdit->SetModifyHdl(LINK(this,SwBreakDlg,PageNumModifyHdl));
156 // Insert page description to Listbox
157 const sal_uInt16 nCount = rSh.GetPageDescCnt();
158 sal_uInt16 i;
160 for( i = 0; i < nCount; ++i)
162 const SwPageDesc &rPageDesc = rSh.GetPageDesc(i);
163 ::InsertStringSorted(rPageDesc.GetName(), *m_pPageCollBox, 1 );
166 String aFmtName;
167 for(i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
168 if(LISTBOX_ENTRY_NOTFOUND == m_pPageCollBox->GetEntryPos( aFmtName =
169 SwStyleNameMapper::GetUIName( i, aFmtName )))
170 ::InsertStringSorted(aFmtName, *m_pPageCollBox, 1 );
171 //add landscape page
172 if(LISTBOX_ENTRY_NOTFOUND == m_pPageCollBox->GetEntryPos( aFmtName =
173 SwStyleNameMapper::GetUIName( RES_POOLPAGE_LANDSCAPE, aFmtName )))
174 ::InsertStringSorted(aFmtName, *m_pPageCollBox, 1 );
175 CheckEnable();
176 m_pPageNumEdit->SetText(OUString());
179 void SwBreakDlg::CheckEnable()
181 sal_Bool bEnable = sal_True;
182 if ( bHtmlMode )
184 m_pColumnBtn->Enable(sal_False);
185 m_pPageCollBox->Enable(sal_False);
186 bEnable = sal_False;
188 else if(rSh.GetFrmType(0,sal_True)
189 & (FRMTYPE_FLY_ANY | FRMTYPE_HEADER | FRMTYPE_FOOTER | FRMTYPE_FOOTNOTE))
191 m_pPageBtn->Enable(sal_False);
192 if(m_pPageBtn->IsChecked())
193 m_pLineBtn->Check(sal_True);
194 bEnable = sal_False;
196 const sal_Bool bPage = m_pPageBtn->IsChecked();
197 m_pPageCollText->Enable( bPage );
198 m_pPageCollBox->Enable ( bPage );
200 bEnable &= bPage;
201 if ( bEnable )
203 // position 0 says 'Without' page template.
204 const sal_uInt16 nPos = m_pPageCollBox->GetSelectEntryPos();
205 if ( 0 == nPos || LISTBOX_ENTRY_NOTFOUND == nPos )
206 bEnable = sal_False;
208 m_pPageNumBox->Enable(bEnable);
209 m_pPageNumEdit->Enable(bEnable);
212 SwBreakDlg::~SwBreakDlg()
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */