1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 #ifdef SW_DLLIMPLEMENTATION 32 #undef SW_DLLIMPLEMENTATION 33 #endif 34 35 36 #include <sfx2/request.hxx> 37 #include <svl/stritem.hxx> 38 #ifndef _MSGBOX_HXX //autogen 39 #include <vcl/msgbox.hxx> 40 #endif 41 42 #ifndef _CMDID_H 43 #include <cmdid.h> 44 #endif 45 #include <uitool.hxx> 46 #include <swtypes.hxx> 47 #include <wrtsh.hxx> 48 #ifndef _BASESH_HXX 49 #include <basesh.hxx> 50 #endif 51 #ifndef _VIEW_HXX 52 #include <view.hxx> 53 #endif 54 #include <viewopt.hxx> 55 #include <break.hxx> 56 #include <pagedesc.hxx> 57 #include <poolfmt.hxx> 58 59 #ifndef _BREAK_HRC 60 #include <break.hrc> 61 #endif 62 #ifndef _CHRDLG_HRC 63 #include <chrdlg.hrc> 64 #endif 65 #include <SwStyleNameMapper.hxx> 66 67 void SwBreakDlg::Apply() 68 { 69 nKind = 0; 70 if(aLineBtn.IsChecked()) 71 nKind = 1; 72 else if(aColumnBtn.IsChecked()) 73 nKind = 2; 74 else if(aPageBtn.IsChecked()) 75 { 76 nKind = 3; 77 const sal_uInt16 nPos = aPageCollBox.GetSelectEntryPos(); 78 if(0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos) 79 { 80 aTemplate = aPageCollBox.GetSelectEntry(); 81 nPgNum = aPageNumBox.IsChecked() ? (sal_uInt16)aPageNumEdit.GetValue() : 0; 82 } 83 } 84 } 85 86 87 IMPL_LINK_INLINE_START( SwBreakDlg, ClickHdl, void *, EMPTYARG ) 88 { 89 CheckEnable(); 90 return 0; 91 } 92 IMPL_LINK_INLINE_END( SwBreakDlg, ClickHdl, void *, EMPTYARG ) 93 94 /*------------------------------------------------------------------------ 95 Beschreibung: Handler fuer Aendern Seitenummer 96 ------------------------------------------------------------------------*/ 97 98 IMPL_LINK_INLINE_START( SwBreakDlg, PageNumHdl, CheckBox *, pBox ) 99 { 100 if(pBox->IsChecked()) aPageNumEdit.SetValue(1); 101 else aPageNumEdit.SetText(aEmptyStr); 102 return 0; 103 } 104 IMPL_LINK_INLINE_END( SwBreakDlg, PageNumHdl, CheckBox *, pBox ) 105 106 /*------------------------------------------------------------------------ 107 Beschreibung: Durch Aendern der Seitennummer wird die Checkbox gecheckt. 108 ------------------------------------------------------------------------*/ 109 110 IMPL_LINK_INLINE_START( SwBreakDlg, PageNumModifyHdl, Edit *, EMPTYARG ) 111 { 112 aPageNumBox.Check(); 113 return 0; 114 } 115 IMPL_LINK_INLINE_END( SwBreakDlg, PageNumModifyHdl, Edit *, EMPTYARG ) 116 117 /*------------------------------------------------------------------------ 118 Beschreibung: Ok-Handler; 119 prueft, ob die Seitenummer nPage eine legale Seitennummer 120 ist (linke Seiten mit geraden Nummern etc. bei einer Seitenvorlage 121 mit wechselnden Seiten) 122 ------------------------------------------------------------------------*/ 123 124 IMPL_LINK( SwBreakDlg, OkHdl, Button *, EMPTYARG ) 125 { 126 if(aPageNumBox.IsChecked()) { 127 // wenn unterschiedliche Seitenvorlagen, testen auf Gueltigkeit 128 const sal_uInt16 nPos = aPageCollBox.GetSelectEntryPos(); 129 // auf Position 0 steht 'Ohne'. 130 const SwPageDesc *pPageDesc; 131 if ( 0 != nPos && LISTBOX_ENTRY_NOTFOUND != nPos ) 132 pPageDesc = rSh.FindPageDescByName( aPageCollBox.GetSelectEntry(), 133 sal_True ); 134 else 135 pPageDesc = &rSh.GetPageDesc(rSh.GetCurPageDesc()); 136 137 ASSERT(pPageDesc, Seitenvorlage nicht gefunden.); 138 const sal_uInt16 nUserPage = sal_uInt16(aPageNumEdit.GetValue()); 139 sal_Bool bOk = sal_True; 140 switch(pPageDesc->GetUseOn()) 141 { 142 case nsUseOnPage::PD_MIRROR: 143 case nsUseOnPage::PD_ALL: break; 144 case nsUseOnPage::PD_LEFT: bOk = 0 == nUserPage % 2; break; 145 case nsUseOnPage::PD_RIGHT: bOk = static_cast< sal_Bool >(nUserPage % 2); break; 146 default:; //prevent warning 147 } 148 if(!bOk) { 149 InfoBox(this, SW_RES(MSG_ILLEGAL_PAGENUM)).Execute(); 150 aPageNumEdit.GrabFocus(); 151 return 0; 152 } 153 } 154 EndDialog(RET_OK); 155 return 0; 156 } 157 158 SwBreakDlg::SwBreakDlg( Window *pParent, SwWrtShell &rS ) : 159 160 SvxStandardDialog( pParent,SW_RES(DLG_BREAK) ), 161 162 rSh(rS), 163 aBreakFL(this,SW_RES(FL_BREAK)), 164 aLineBtn(this,SW_RES(RB_LINE)), 165 aColumnBtn(this,SW_RES(RB_COL)), 166 aPageBtn(this,SW_RES(RB_PAGE)), 167 aPageCollText(this, SW_RES(FT_COLL)), 168 aPageCollBox(this, SW_RES(LB_COLL)), 169 aPageNumBox(this, SW_RES(CB_PAGENUM)), 170 aPageNumEdit(this, SW_RES(ED_PAGENUM)), 171 172 aOkBtn(this,SW_RES(BT_OK)), 173 aCancelBtn(this,SW_RES(BT_CANCEL)), 174 aHelpBtn(this,SW_RES(BT_HELP)), 175 176 nKind(0), 177 nPgNum(0), 178 179 bHtmlMode(0 != ::GetHtmlMode(rS.GetView().GetDocShell())) 180 { 181 aPageNumEdit.SetAccessibleRelationLabeledBy(&aPageNumBox); 182 aPageNumEdit.SetAccessibleName(aPageNumBox.GetText()); 183 184 Link aLk = LINK(this,SwBreakDlg,ClickHdl); 185 aPageBtn.SetClickHdl( aLk ); 186 aLineBtn.SetClickHdl( aLk ); 187 aColumnBtn.SetClickHdl( aLk ); 188 aPageCollBox.SetSelectHdl( aLk ); 189 190 aOkBtn.SetClickHdl(LINK(this,SwBreakDlg,OkHdl)); 191 aPageNumBox.SetClickHdl(LINK(this,SwBreakDlg,PageNumHdl)); 192 aPageNumEdit.SetModifyHdl(LINK(this,SwBreakDlg,PageNumModifyHdl)); 193 194 195 // Einfuegen der vorhandenen Seitenvorlagen in die Listbox 196 const sal_uInt16 nCount = rSh.GetPageDescCnt(); 197 sal_uInt16 i; 198 199 for( i = 0; i < nCount; ++i) 200 { 201 const SwPageDesc &rPageDesc = rSh.GetPageDesc(i); 202 ::InsertStringSorted(rPageDesc.GetName(), aPageCollBox, 1 ); 203 } 204 205 String aFmtName; 206 for(i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++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(); 217 } 218 219 220 void SwBreakDlg::CheckEnable() 221 { 222 sal_Bool bEnable = sal_True; 223 if ( bHtmlMode ) 224 { 225 aColumnBtn .Enable(sal_False); 226 aPageCollBox.Enable(sal_False); 227 bEnable = sal_False; 228 } 229 else if(rSh.GetFrmType(0,sal_True) 230 & (FRMTYPE_FLY_ANY | FRMTYPE_HEADER | FRMTYPE_FOOTER | FRMTYPE_FOOTNOTE)) 231 { 232 aPageBtn.Enable(sal_False); 233 if(aPageBtn.IsChecked()) 234 aLineBtn.Check(sal_True); 235 bEnable = sal_False; 236 } 237 const sal_Bool bPage = aPageBtn.IsChecked(); 238 aPageCollText.Enable( bPage ); 239 aPageCollBox.Enable ( bPage ); 240 241 bEnable &= bPage; 242 if ( bEnable ) 243 { 244 // auf Position 0 steht 'Ohne' Seitenvorlage. 245 const sal_uInt16 nPos = aPageCollBox.GetSelectEntryPos(); 246 if ( 0 == nPos || LISTBOX_ENTRY_NOTFOUND == nPos ) 247 bEnable = sal_False; 248 } 249 aPageNumBox .Enable(bEnable); 250 aPageNumEdit.Enable(bEnable); 251 } 252 253 SwBreakDlg::~SwBreakDlg() 254 { 255 } 256