merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / chrdlg / break.cxx
blobd21b3340a0b7fba6ba513495d684e70308a73b83
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: break.cxx,v $
10 * $Revision: 1.16.224.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
39 #include <sfx2/request.hxx>
40 #include <svtools/stritem.hxx>
41 #ifndef _MSGBOX_HXX //autogen
42 #include <vcl/msgbox.hxx>
43 #endif
45 #ifndef _CMDID_H
46 #include <cmdid.h>
47 #endif
48 #include <uitool.hxx>
49 #include <swtypes.hxx>
50 #include <wrtsh.hxx>
51 #ifndef _BASESH_HXX
52 #include <basesh.hxx>
53 #endif
54 #ifndef _VIEW_HXX
55 #include <view.hxx>
56 #endif
57 #include <viewopt.hxx>
58 #include <break.hxx>
59 #include <pagedesc.hxx>
60 #include <poolfmt.hxx>
62 #ifndef _BREAK_HRC
63 #include <break.hrc>
64 #endif
65 #ifndef _CHRDLG_HRC
66 #include <chrdlg.hrc>
67 #endif
68 #include <SwStyleNameMapper.hxx>
70 void SwBreakDlg::Apply()
72 nKind = 0;
73 if(aLineBtn.IsChecked())
74 nKind = 1;
75 else if(aColumnBtn.IsChecked())
76 nKind = 2;
77 else if(aPageBtn.IsChecked())
79 nKind = 3;
80 const USHORT nPos = aPageCollBox.GetSelectEntryPos();
81 if(0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos)
83 aTemplate = aPageCollBox.GetSelectEntry();
84 nPgNum = aPageNumBox.IsChecked() ? (USHORT)aPageNumEdit.GetValue() : 0;
90 IMPL_LINK_INLINE_START( SwBreakDlg, ClickHdl, void *, EMPTYARG )
92 CheckEnable();
93 return 0;
95 IMPL_LINK_INLINE_END( SwBreakDlg, ClickHdl, void *, EMPTYARG )
97 /*------------------------------------------------------------------------
98 Beschreibung: Handler fuer Aendern Seitenummer
99 ------------------------------------------------------------------------*/
101 IMPL_LINK_INLINE_START( SwBreakDlg, PageNumHdl, CheckBox *, pBox )
103 if(pBox->IsChecked()) aPageNumEdit.SetValue(1);
104 else aPageNumEdit.SetText(aEmptyStr);
105 return 0;
107 IMPL_LINK_INLINE_END( SwBreakDlg, PageNumHdl, CheckBox *, pBox )
109 /*------------------------------------------------------------------------
110 Beschreibung: Durch Aendern der Seitennummer wird die Checkbox gecheckt.
111 ------------------------------------------------------------------------*/
113 IMPL_LINK_INLINE_START( SwBreakDlg, PageNumModifyHdl, Edit *, EMPTYARG )
115 aPageNumBox.Check();
116 return 0;
118 IMPL_LINK_INLINE_END( SwBreakDlg, PageNumModifyHdl, Edit *, EMPTYARG )
120 /*------------------------------------------------------------------------
121 Beschreibung: Ok-Handler;
122 prueft, ob die Seitenummer nPage eine legale Seitennummer
123 ist (linke Seiten mit geraden Nummern etc. bei einer Seitenvorlage
124 mit wechselnden Seiten)
125 ------------------------------------------------------------------------*/
127 IMPL_LINK( SwBreakDlg, OkHdl, Button *, EMPTYARG )
129 if(aPageNumBox.IsChecked()) {
130 // wenn unterschiedliche Seitenvorlagen, testen auf Gueltigkeit
131 const USHORT nPos = aPageCollBox.GetSelectEntryPos();
132 // auf Position 0 steht 'Ohne'.
133 const SwPageDesc *pPageDesc;
134 if ( 0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos )
135 pPageDesc = rSh.FindPageDescByName( aPageCollBox.GetSelectEntry(),
136 TRUE );
137 else
138 pPageDesc = &rSh.GetPageDesc(rSh.GetCurPageDesc());
140 ASSERT(pPageDesc, Seitenvorlage nicht gefunden.);
141 const USHORT nUserPage = USHORT(aPageNumEdit.GetValue());
142 BOOL bOk = TRUE;
143 switch(pPageDesc->GetUseOn())
145 case nsUseOnPage::PD_MIRROR:
146 case nsUseOnPage::PD_ALL: break;
147 case nsUseOnPage::PD_LEFT: bOk = 0 == nUserPage % 2; break;
148 case nsUseOnPage::PD_RIGHT: bOk = static_cast< sal_Bool >(nUserPage % 2); break;
149 default:; //prevent warning
151 if(!bOk) {
152 InfoBox(this, SW_RES(MSG_ILLEGAL_PAGENUM)).Execute();
153 aPageNumEdit.GrabFocus();
154 return 0;
157 EndDialog(RET_OK);
158 return 0;
161 SwBreakDlg::SwBreakDlg( Window *pParent, SwWrtShell &rS ) :
163 SvxStandardDialog( pParent,SW_RES(DLG_BREAK) ),
165 rSh(rS),
166 aLineBtn(this,SW_RES(RB_LINE)),
167 aColumnBtn(this,SW_RES(RB_COL)),
168 aPageBtn(this,SW_RES(RB_PAGE)),
169 aPageCollText(this, SW_RES(FT_COLL)),
170 aPageCollBox(this, SW_RES(LB_COLL)),
171 aPageNumBox(this, SW_RES(CB_PAGENUM)),
172 aPageNumEdit(this, SW_RES(ED_PAGENUM)),
173 aBreakFL(this,SW_RES(FL_BREAK)),
175 aOkBtn(this,SW_RES(BT_OK)),
176 aCancelBtn(this,SW_RES(BT_CANCEL)),
177 aHelpBtn(this,SW_RES(BT_HELP)),
179 nKind(0),
180 nPgNum(0),
182 bHtmlMode(0 != ::GetHtmlMode(rS.GetView().GetDocShell()))
184 Link aLk = LINK(this,SwBreakDlg,ClickHdl);
185 aPageBtn.SetClickHdl( aLk );
186 aLineBtn.SetClickHdl( aLk );
187 aColumnBtn.SetClickHdl( aLk );
188 aPageCollBox.SetSelectHdl( aLk );
190 aOkBtn.SetClickHdl(LINK(this,SwBreakDlg,OkHdl));
191 aPageNumBox.SetClickHdl(LINK(this,SwBreakDlg,PageNumHdl));
192 aPageNumEdit.SetModifyHdl(LINK(this,SwBreakDlg,PageNumModifyHdl));
195 // Einfuegen der vorhandenen Seitenvorlagen in die Listbox
196 const USHORT nCount = rSh.GetPageDescCnt();
197 USHORT i;
199 for( i = 0; i < nCount; ++i)
201 const SwPageDesc &rPageDesc = rSh.GetPageDesc(i);
202 ::InsertStringSorted(rPageDesc.GetName(), aPageCollBox, 1 );
205 String aFmtName;
206 for(i = RES_POOLPAGE_BEGIN; i <= RES_POOLPAGE_REGISTER; ++i)
207 if(LISTBOX_ENTRY_NOTFOUND == aPageCollBox.GetEntryPos( aFmtName =
208 SwStyleNameMapper::GetUIName( i, aFmtName )))
209 ::InsertStringSorted(aFmtName, aPageCollBox, 1 );
210 //add landscape page
211 if(LISTBOX_ENTRY_NOTFOUND == aPageCollBox.GetEntryPos( aFmtName =
212 SwStyleNameMapper::GetUIName( RES_POOLPAGE_LANDSCAPE, aFmtName )))
213 ::InsertStringSorted(aFmtName, aPageCollBox, 1 );
214 CheckEnable();
215 aPageNumEdit.SetText( aEmptyStr );
216 FreeResource();
220 void SwBreakDlg::CheckEnable()
222 BOOL bEnable = TRUE;
223 if ( bHtmlMode )
225 aColumnBtn .Enable(FALSE);
226 aPageCollBox.Enable(FALSE);
227 bEnable = FALSE;
229 else if(rSh.GetFrmType(0,TRUE)
230 & (FRMTYPE_FLY_ANY | FRMTYPE_HEADER | FRMTYPE_FOOTER | FRMTYPE_FOOTNOTE))
232 aPageBtn.Enable(FALSE);
233 if(aPageBtn.IsChecked())
234 aLineBtn.Check(TRUE);
235 bEnable = FALSE;
237 const BOOL bPage = aPageBtn.IsChecked();
238 aPageCollText.Enable( bPage );
239 aPageCollBox.Enable ( bPage );
241 bEnable &= bPage;
242 if ( bEnable )
244 // auf Position 0 steht 'Ohne' Seitenvorlage.
245 const USHORT nPos = aPageCollBox.GetSelectEntryPos();
246 if ( 0 == nPos || LISTBOX_ENTRY_NOTFOUND == nPos )
247 bEnable = FALSE;
249 aPageNumBox .Enable(bEnable);
250 aPageNumEdit.Enable(bEnable);
253 SwBreakDlg::~SwBreakDlg()