Line data Source code
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/msgbox.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 <chrdlg.hrc>
36 : #include <SwStyleNameMapper.hxx>
37 :
38 0 : void SwBreakDlg::Apply()
39 : {
40 0 : nKind = 0;
41 0 : if(m_pLineBtn->IsChecked())
42 0 : nKind = 1;
43 0 : else if(m_pColumnBtn->IsChecked())
44 0 : nKind = 2;
45 0 : else if(m_pPageBtn->IsChecked())
46 : {
47 0 : nKind = 3;
48 0 : const sal_uInt16 nPos = m_pPageCollBox->GetSelectEntryPos();
49 0 : if(0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos)
50 : {
51 0 : aTemplate = m_pPageCollBox->GetSelectEntry();
52 0 : nPgNum = m_pPageNumBox->IsChecked() ? (sal_uInt16)m_pPageNumEdit->GetValue() : 0;
53 : }
54 : }
55 0 : }
56 :
57 0 : IMPL_LINK_NOARG_INLINE_START(SwBreakDlg, ClickHdl)
58 : {
59 0 : CheckEnable();
60 0 : return 0;
61 : }
62 0 : IMPL_LINK_NOARG_INLINE_END(SwBreakDlg, ClickHdl)
63 :
64 : /*------------------------------------------------------------------------
65 : Description: Handler for Change Page Number
66 : ------------------------------------------------------------------------*/
67 :
68 0 : IMPL_LINK_INLINE_START( SwBreakDlg, PageNumHdl, CheckBox *, pBox )
69 : {
70 0 : if(pBox->IsChecked()) m_pPageNumEdit->SetValue(1);
71 0 : else m_pPageNumEdit->SetText(OUString());
72 0 : return 0;
73 : }
74 0 : IMPL_LINK_INLINE_END( SwBreakDlg, PageNumHdl, CheckBox *, pBox )
75 :
76 : /*------------------------------------------------------------------------
77 : Description: By changing the Page number the checkbox is checked.
78 : ------------------------------------------------------------------------*/
79 :
80 0 : IMPL_LINK_NOARG_INLINE_START(SwBreakDlg, PageNumModifyHdl)
81 : {
82 0 : m_pPageNumBox->Check();
83 0 : return 0;
84 : }
85 0 : IMPL_LINK_NOARG_INLINE_END(SwBreakDlg, PageNumModifyHdl)
86 :
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 : ------------------------------------------------------------------------*/
93 :
94 0 : IMPL_LINK_NOARG(SwBreakDlg, OkHdl)
95 : {
96 0 : if(m_pPageNumBox->IsChecked()) {
97 : // In case of differing page descriptions, test validity
98 0 : const sal_uInt16 nPos = m_pPageCollBox->GetSelectEntryPos();
99 : // position 0 says 'Without'.
100 : const SwPageDesc *pPageDesc;
101 0 : if ( 0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos )
102 0 : pPageDesc = rSh.FindPageDescByName( m_pPageCollBox->GetSelectEntry(),
103 0 : sal_True );
104 : else
105 0 : pPageDesc = &rSh.GetPageDesc(rSh.GetCurPageDesc());
106 :
107 : OSL_ENSURE(pPageDesc, "Page description not found.");
108 0 : const sal_uInt16 nUserPage = sal_uInt16(m_pPageNumEdit->GetValue());
109 0 : sal_Bool bOk = sal_True;
110 0 : switch(pPageDesc->GetUseOn())
111 : {
112 : case nsUseOnPage::PD_MIRROR:
113 0 : case nsUseOnPage::PD_ALL: break;
114 0 : case nsUseOnPage::PD_LEFT: bOk = 0 == nUserPage % 2; break;
115 0 : case nsUseOnPage::PD_RIGHT: bOk = static_cast< sal_Bool >(nUserPage % 2); break;
116 : default:; //prevent warning
117 : }
118 0 : if(!bOk) {
119 0 : InfoBox(this, SW_RES(MSG_ILLEGAL_PAGENUM)).Execute();
120 0 : m_pPageNumEdit->GrabFocus();
121 0 : return 0;
122 : }
123 : }
124 0 : EndDialog(RET_OK);
125 0 : return 0;
126 : }
127 :
128 0 : 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 0 : , bHtmlMode(0 != ::GetHtmlMode(rS.GetView().GetDocShell()))
134 : {
135 0 : get(m_pLineBtn, "linerb");
136 0 : get(m_pColumnBtn, "columnrb");
137 0 : get(m_pPageBtn, "pagerb");
138 0 : get(m_pPageCollText, "styleft");
139 0 : get(m_pPageCollBox, "stylelb");
140 0 : get(m_pPageNumBox, "pagenumcb");
141 0 : get(m_pPageNumEdit, "pagenumsb");
142 :
143 0 : m_pPageNumEdit->SetAccessibleRelationLabeledBy(m_pPageNumBox);
144 0 : m_pPageNumEdit->SetAccessibleName(m_pPageNumBox->GetText());
145 :
146 0 : Link aLk = LINK(this,SwBreakDlg,ClickHdl);
147 0 : m_pPageBtn->SetClickHdl( aLk );
148 0 : m_pLineBtn->SetClickHdl( aLk );
149 0 : m_pColumnBtn->SetClickHdl( aLk );
150 0 : m_pPageCollBox->SetSelectHdl( aLk );
151 :
152 0 : get<OKButton>("ok")->SetClickHdl(LINK(this,SwBreakDlg,OkHdl));;
153 0 : m_pPageNumBox->SetClickHdl(LINK(this,SwBreakDlg,PageNumHdl));
154 0 : m_pPageNumEdit->SetModifyHdl(LINK(this,SwBreakDlg,PageNumModifyHdl));
155 :
156 :
157 : // Insert page description to Listbox
158 0 : const sal_uInt16 nCount = rSh.GetPageDescCnt();
159 : sal_uInt16 i;
160 :
161 0 : for( i = 0; i < nCount; ++i)
162 : {
163 0 : const SwPageDesc &rPageDesc = rSh.GetPageDesc(i);
164 0 : ::InsertStringSorted(rPageDesc.GetName(), *m_pPageCollBox, 1 );
165 : }
166 :
167 0 : String aFmtName;
168 0 : for(i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
169 0 : if(LISTBOX_ENTRY_NOTFOUND == m_pPageCollBox->GetEntryPos( aFmtName =
170 0 : SwStyleNameMapper::GetUIName( i, aFmtName )))
171 0 : ::InsertStringSorted(aFmtName, *m_pPageCollBox, 1 );
172 : //add landscape page
173 0 : if(LISTBOX_ENTRY_NOTFOUND == m_pPageCollBox->GetEntryPos( aFmtName =
174 0 : SwStyleNameMapper::GetUIName( RES_POOLPAGE_LANDSCAPE, aFmtName )))
175 0 : ::InsertStringSorted(aFmtName, *m_pPageCollBox, 1 );
176 0 : CheckEnable();
177 0 : m_pPageNumEdit->SetText(OUString());
178 0 : }
179 :
180 0 : void SwBreakDlg::CheckEnable()
181 : {
182 0 : sal_Bool bEnable = sal_True;
183 0 : if ( bHtmlMode )
184 : {
185 0 : m_pColumnBtn->Enable(sal_False);
186 0 : m_pPageCollBox->Enable(sal_False);
187 0 : bEnable = sal_False;
188 : }
189 0 : else if(rSh.GetFrmType(0,sal_True)
190 : & (FRMTYPE_FLY_ANY | FRMTYPE_HEADER | FRMTYPE_FOOTER | FRMTYPE_FOOTNOTE))
191 : {
192 0 : m_pPageBtn->Enable(sal_False);
193 0 : if(m_pPageBtn->IsChecked())
194 0 : m_pLineBtn->Check(sal_True);
195 0 : bEnable = sal_False;
196 : }
197 0 : const sal_Bool bPage = m_pPageBtn->IsChecked();
198 0 : m_pPageCollText->Enable( bPage );
199 0 : m_pPageCollBox->Enable ( bPage );
200 :
201 0 : bEnable &= bPage;
202 0 : if ( bEnable )
203 : {
204 : // position 0 says 'Without' page template.
205 0 : const sal_uInt16 nPos = m_pPageCollBox->GetSelectEntryPos();
206 0 : if ( 0 == nPos || LISTBOX_ENTRY_NOTFOUND == nPos )
207 0 : bEnable = sal_False;
208 : }
209 0 : m_pPageNumBox->Enable(bEnable);
210 0 : m_pPageNumEdit->Enable(bEnable);
211 0 : }
212 :
213 0 : SwBreakDlg::~SwBreakDlg()
214 : {
215 0 : }
216 :
217 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|