xref: /aoo42x/main/sw/source/ui/chrdlg/break.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION
28cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <sfx2/request.hxx>
33cdf0e10cSrcweir #include <svl/stritem.hxx>
34cdf0e10cSrcweir #ifndef _MSGBOX_HXX //autogen
35cdf0e10cSrcweir #include <vcl/msgbox.hxx>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #ifndef _CMDID_H
39cdf0e10cSrcweir #include <cmdid.h>
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #include <uitool.hxx>
42cdf0e10cSrcweir #include <swtypes.hxx>
43cdf0e10cSrcweir #include <wrtsh.hxx>
44cdf0e10cSrcweir #ifndef _BASESH_HXX
45cdf0e10cSrcweir #include <basesh.hxx>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #ifndef _VIEW_HXX
48cdf0e10cSrcweir #include <view.hxx>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #include <viewopt.hxx>
51cdf0e10cSrcweir #include <break.hxx>
52cdf0e10cSrcweir #include <pagedesc.hxx>
53cdf0e10cSrcweir #include <poolfmt.hxx>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #ifndef _BREAK_HRC
56cdf0e10cSrcweir #include <break.hrc>
57cdf0e10cSrcweir #endif
58cdf0e10cSrcweir #ifndef _CHRDLG_HRC
59cdf0e10cSrcweir #include <chrdlg.hrc>
60cdf0e10cSrcweir #endif
61cdf0e10cSrcweir #include <SwStyleNameMapper.hxx>
62cdf0e10cSrcweir 
Apply()63cdf0e10cSrcweir void SwBreakDlg::Apply()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     nKind = 0;
66cdf0e10cSrcweir 	if(aLineBtn.IsChecked())
67cdf0e10cSrcweir         nKind = 1;
68cdf0e10cSrcweir 	else if(aColumnBtn.IsChecked())
69cdf0e10cSrcweir         nKind = 2;
70cdf0e10cSrcweir 	else if(aPageBtn.IsChecked())
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir         nKind = 3;
73cdf0e10cSrcweir 		const sal_uInt16 nPos = aPageCollBox.GetSelectEntryPos();
74cdf0e10cSrcweir 		if(0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos)
75cdf0e10cSrcweir 		{
76cdf0e10cSrcweir 			aTemplate = aPageCollBox.GetSelectEntry();
77cdf0e10cSrcweir             nPgNum = aPageNumBox.IsChecked() ? (sal_uInt16)aPageNumEdit.GetValue() : 0;
78cdf0e10cSrcweir 		}
79cdf0e10cSrcweir 	}
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
IMPL_LINK_INLINE_START(SwBreakDlg,ClickHdl,void *,EMPTYARG)83cdf0e10cSrcweir IMPL_LINK_INLINE_START( SwBreakDlg, ClickHdl, void *, EMPTYARG )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	CheckEnable();
86cdf0e10cSrcweir 	return 0;
87cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(SwBreakDlg,ClickHdl,void *,EMPTYARG)88cdf0e10cSrcweir IMPL_LINK_INLINE_END( SwBreakDlg, ClickHdl, void *, EMPTYARG )
89cdf0e10cSrcweir 
90cdf0e10cSrcweir /*------------------------------------------------------------------------
91cdf0e10cSrcweir  Beschreibung:	Handler fuer Aendern Seitenummer
92cdf0e10cSrcweir ------------------------------------------------------------------------*/
93cdf0e10cSrcweir 
94cdf0e10cSrcweir IMPL_LINK_INLINE_START( SwBreakDlg, PageNumHdl, CheckBox *, pBox )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	if(pBox->IsChecked()) aPageNumEdit.SetValue(1);
97cdf0e10cSrcweir 	else aPageNumEdit.SetText(aEmptyStr);
98cdf0e10cSrcweir 	return 0;
99cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(SwBreakDlg,PageNumHdl,CheckBox *,pBox)100cdf0e10cSrcweir IMPL_LINK_INLINE_END( SwBreakDlg, PageNumHdl, CheckBox *, pBox )
101cdf0e10cSrcweir 
102cdf0e10cSrcweir /*------------------------------------------------------------------------
103cdf0e10cSrcweir  Beschreibung:	Durch Aendern der Seitennummer wird die Checkbox gecheckt.
104cdf0e10cSrcweir ------------------------------------------------------------------------*/
105cdf0e10cSrcweir 
106cdf0e10cSrcweir IMPL_LINK_INLINE_START( SwBreakDlg, PageNumModifyHdl, Edit *, EMPTYARG )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	aPageNumBox.Check();
109cdf0e10cSrcweir 	return 0;
110cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(SwBreakDlg,PageNumModifyHdl,Edit *,EMPTYARG)111cdf0e10cSrcweir IMPL_LINK_INLINE_END( SwBreakDlg, PageNumModifyHdl, Edit *, EMPTYARG )
112cdf0e10cSrcweir 
113cdf0e10cSrcweir /*------------------------------------------------------------------------
114cdf0e10cSrcweir  Beschreibung:	Ok-Handler;
115cdf0e10cSrcweir 				prueft, ob die Seitenummer nPage eine legale Seitennummer
116cdf0e10cSrcweir 				ist (linke Seiten mit geraden Nummern etc. bei einer Seitenvorlage
117cdf0e10cSrcweir 				mit wechselnden Seiten)
118cdf0e10cSrcweir ------------------------------------------------------------------------*/
119cdf0e10cSrcweir 
120cdf0e10cSrcweir IMPL_LINK( SwBreakDlg, OkHdl, Button *, EMPTYARG )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 	if(aPageNumBox.IsChecked()) {
123cdf0e10cSrcweir 			// wenn unterschiedliche Seitenvorlagen, testen auf Gueltigkeit
124cdf0e10cSrcweir 		const sal_uInt16 nPos = aPageCollBox.GetSelectEntryPos();
125cdf0e10cSrcweir 			// auf Position 0 steht 'Ohne'.
126cdf0e10cSrcweir 		const SwPageDesc *pPageDesc;
127cdf0e10cSrcweir 		if ( 0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos )
128cdf0e10cSrcweir 			pPageDesc = rSh.FindPageDescByName( aPageCollBox.GetSelectEntry(),
129cdf0e10cSrcweir 												sal_True );
130cdf0e10cSrcweir 		else
131cdf0e10cSrcweir 			pPageDesc = &rSh.GetPageDesc(rSh.GetCurPageDesc());
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 		ASSERT(pPageDesc, Seitenvorlage nicht gefunden.);
134cdf0e10cSrcweir 		const sal_uInt16 nUserPage = sal_uInt16(aPageNumEdit.GetValue());
135cdf0e10cSrcweir 		sal_Bool bOk = sal_True;
136cdf0e10cSrcweir         switch(pPageDesc->GetUseOn())
137cdf0e10cSrcweir         {
138cdf0e10cSrcweir 			case nsUseOnPage::PD_MIRROR:
139cdf0e10cSrcweir 			case nsUseOnPage::PD_ALL: break;
140cdf0e10cSrcweir 			case nsUseOnPage::PD_LEFT: bOk = 0 == nUserPage % 2; break;
141cdf0e10cSrcweir             case nsUseOnPage::PD_RIGHT: bOk = static_cast< sal_Bool >(nUserPage % 2); break;
142cdf0e10cSrcweir             default:; //prevent warning
143cdf0e10cSrcweir 		}
144cdf0e10cSrcweir 		if(!bOk) {
145cdf0e10cSrcweir 			InfoBox(this, SW_RES(MSG_ILLEGAL_PAGENUM)).Execute();
146cdf0e10cSrcweir 			aPageNumEdit.GrabFocus();
147cdf0e10cSrcweir 			return 0;
148cdf0e10cSrcweir 		}
149cdf0e10cSrcweir 	}
150cdf0e10cSrcweir 	EndDialog(RET_OK);
151cdf0e10cSrcweir 	return 0;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
SwBreakDlg(Window * pParent,SwWrtShell & rS)154cdf0e10cSrcweir SwBreakDlg::SwBreakDlg( Window *pParent, SwWrtShell &rS ) :
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	SvxStandardDialog( pParent,SW_RES(DLG_BREAK) ),
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	rSh(rS),
159cdf0e10cSrcweir 	aBreakFL(this,SW_RES(FL_BREAK)),
160cdf0e10cSrcweir     aLineBtn(this,SW_RES(RB_LINE)),
161cdf0e10cSrcweir 	aColumnBtn(this,SW_RES(RB_COL)),
162cdf0e10cSrcweir 	aPageBtn(this,SW_RES(RB_PAGE)),
163cdf0e10cSrcweir 	aPageCollText(this, SW_RES(FT_COLL)),
164cdf0e10cSrcweir 	aPageCollBox(this, SW_RES(LB_COLL)),
165cdf0e10cSrcweir 	aPageNumBox(this, SW_RES(CB_PAGENUM)),
166cdf0e10cSrcweir 	aPageNumEdit(this, SW_RES(ED_PAGENUM)),
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     aOkBtn(this,SW_RES(BT_OK)),
169cdf0e10cSrcweir 	aCancelBtn(this,SW_RES(BT_CANCEL)),
170cdf0e10cSrcweir 	aHelpBtn(this,SW_RES(BT_HELP)),
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     nKind(0),
173cdf0e10cSrcweir     nPgNum(0),
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     bHtmlMode(0 != ::GetHtmlMode(rS.GetView().GetDocShell()))
176cdf0e10cSrcweir {
177cdf0e10cSrcweir 	aPageNumEdit.SetAccessibleRelationLabeledBy(&aPageNumBox);
178cdf0e10cSrcweir 	aPageNumEdit.SetAccessibleName(aPageNumBox.GetText());
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	Link aLk = LINK(this,SwBreakDlg,ClickHdl);
181cdf0e10cSrcweir 	aPageBtn.SetClickHdl( aLk );
182cdf0e10cSrcweir 	aLineBtn.SetClickHdl( aLk );
183cdf0e10cSrcweir 	aColumnBtn.SetClickHdl( aLk );
184cdf0e10cSrcweir 	aPageCollBox.SetSelectHdl( aLk );
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 	aOkBtn.SetClickHdl(LINK(this,SwBreakDlg,OkHdl));
187cdf0e10cSrcweir 	aPageNumBox.SetClickHdl(LINK(this,SwBreakDlg,PageNumHdl));
188cdf0e10cSrcweir 	aPageNumEdit.SetModifyHdl(LINK(this,SwBreakDlg,PageNumModifyHdl));
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	// Einfuegen der vorhandenen Seitenvorlagen in die Listbox
192cdf0e10cSrcweir 	const sal_uInt16 nCount = rSh.GetPageDescCnt();
193cdf0e10cSrcweir 	sal_uInt16 i;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	for( i = 0; i < nCount; ++i)
196cdf0e10cSrcweir 	{
197cdf0e10cSrcweir 		const SwPageDesc &rPageDesc = rSh.GetPageDesc(i);
198cdf0e10cSrcweir         ::InsertStringSorted(rPageDesc.GetName(), aPageCollBox, 1 );
199cdf0e10cSrcweir 	}
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	String aFmtName;
202cdf0e10cSrcweir 	for(i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
203cdf0e10cSrcweir 		if(LISTBOX_ENTRY_NOTFOUND == aPageCollBox.GetEntryPos( aFmtName =
204cdf0e10cSrcweir 									SwStyleNameMapper::GetUIName( i, aFmtName )))
205cdf0e10cSrcweir             ::InsertStringSorted(aFmtName, aPageCollBox, 1 );
206cdf0e10cSrcweir     //add landscape page
207cdf0e10cSrcweir     if(LISTBOX_ENTRY_NOTFOUND == aPageCollBox.GetEntryPos( aFmtName =
208cdf0e10cSrcweir                                     SwStyleNameMapper::GetUIName( RES_POOLPAGE_LANDSCAPE, aFmtName )))
209cdf0e10cSrcweir             ::InsertStringSorted(aFmtName, aPageCollBox, 1 );
210cdf0e10cSrcweir 	CheckEnable();
211cdf0e10cSrcweir 	aPageNumEdit.SetText( aEmptyStr );
212cdf0e10cSrcweir 	FreeResource();
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 
CheckEnable()216cdf0e10cSrcweir void SwBreakDlg::CheckEnable()
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	sal_Bool bEnable = sal_True;
219cdf0e10cSrcweir 	if ( bHtmlMode )
220cdf0e10cSrcweir 	{
221cdf0e10cSrcweir 		aColumnBtn	.Enable(sal_False);
222cdf0e10cSrcweir 		aPageCollBox.Enable(sal_False);
223cdf0e10cSrcweir 		bEnable = sal_False;
224cdf0e10cSrcweir 	}
225cdf0e10cSrcweir 	else if(rSh.GetFrmType(0,sal_True)
226cdf0e10cSrcweir 		& (FRMTYPE_FLY_ANY | FRMTYPE_HEADER | FRMTYPE_FOOTER  | FRMTYPE_FOOTNOTE))
227cdf0e10cSrcweir 	{
228cdf0e10cSrcweir 		aPageBtn.Enable(sal_False);
229cdf0e10cSrcweir 		if(aPageBtn.IsChecked())
230cdf0e10cSrcweir 			aLineBtn.Check(sal_True);
231cdf0e10cSrcweir 		bEnable = sal_False;
232cdf0e10cSrcweir 	}
233cdf0e10cSrcweir 	const sal_Bool bPage = aPageBtn.IsChecked();
234cdf0e10cSrcweir 	aPageCollText.Enable( bPage );
235cdf0e10cSrcweir 	aPageCollBox.Enable ( bPage );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	bEnable &= bPage;
238cdf0e10cSrcweir 	if ( bEnable )
239cdf0e10cSrcweir 	{
240cdf0e10cSrcweir 		// auf Position 0 steht 'Ohne' Seitenvorlage.
241cdf0e10cSrcweir 		const sal_uInt16 nPos = aPageCollBox.GetSelectEntryPos();
242cdf0e10cSrcweir 		if ( 0 == nPos || LISTBOX_ENTRY_NOTFOUND == nPos )
243cdf0e10cSrcweir 			bEnable = sal_False;
244cdf0e10cSrcweir 	}
245cdf0e10cSrcweir 	aPageNumBox	.Enable(bEnable);
246cdf0e10cSrcweir 	aPageNumEdit.Enable(bEnable);
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
~SwBreakDlg()249cdf0e10cSrcweir SwBreakDlg::~SwBreakDlg()
250cdf0e10cSrcweir {
251cdf0e10cSrcweir }
252