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 #ifdef SW_DLLIMPLEMENTATION 31 #undef SW_DLLIMPLEMENTATION 32 #endif 33 34 35 #include <swtypes.hxx> 36 #include <globals.hrc> 37 #include <misc.hrc> 38 39 #include <utlui.hrc> 40 #include <unotools.hrc> 41 #include <unoprnms.hxx> 42 #include <tools/debug.hxx> 43 #include <vcl/msgbox.hxx> 44 #include <com/sun/star/text/XTextViewCursorSupplier.hpp> 45 #include <com/sun/star/view/XScreenCursor.hpp> 46 #include <com/sun/star/view/DocumentZoomType.hpp> 47 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 48 #include <com/sun/star/style/XStyle.hpp> 49 #include <com/sun/star/frame/XFrame.hpp> 50 #include <com/sun/star/text/XText.hpp> 51 #include <com/sun/star/text/XTextDocument.hpp> 52 #include <com/sun/star/awt/PosSize.hpp> 53 #include <com/sun/star/view/XViewSettingsSupplier.hpp> 54 #include <com/sun/star/container/XNameContainer.hpp> 55 #include <comphelper/processfactory.hxx> 56 #include <sfx2/dispatch.hxx> 57 #include <svl/stritem.hxx> 58 #include <shellio.hxx> 59 #include <docsh.hxx> 60 #include <view.hxx> 61 #include <wrtsh.hxx> 62 #include <swmodule.hxx> 63 #include <unocrsr.hxx> 64 65 #include "swrenamexnameddlg.hxx" 66 67 68 using namespace ::com::sun::star; 69 using ::rtl::OUString; 70 71 SwRenameXNamedDlg::SwRenameXNamedDlg( Window* pWin, 72 uno::Reference< container::XNamed > & xN, 73 uno::Reference< container::XNameAccess > & xNA ) : 74 ModalDialog(pWin, SW_RES(DLG_RENAME_XNAMED)), 75 aNameFL(this, SW_RES(FL_NAME)), 76 aNewNameFT(this, SW_RES(FT_NEW_NAME)), 77 aNewNameED(this, SW_RES(ED_NEW_NAME)), 78 aOk(this, SW_RES(PB_OK)), 79 aCancel(this, SW_RES(PB_CANCEL)), 80 aHelp(this, SW_RES(PB_HELP)), 81 xNamed(xN), 82 xNameAccess(xNA) 83 { 84 FreeResource(); 85 sRemoveWarning = String(SW_RES(STR_REMOVE_WARNING)); 86 87 String sTmp(GetText()); 88 aNewNameED.SetText(xNamed->getName()); 89 aNewNameED.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX)); 90 sTmp += String(xNamed->getName()); 91 SetText(sTmp); 92 93 aOk.SetClickHdl(LINK(this, SwRenameXNamedDlg, OkHdl)); 94 aNewNameED.SetModifyHdl(LINK(this, SwRenameXNamedDlg, ModifyHdl)); 95 aOk.Enable(sal_False); 96 } 97 /* -----------------09.06.99 15:34------------------- 98 * 99 * --------------------------------------------------*/ 100 IMPL_LINK(SwRenameXNamedDlg, OkHdl, OKButton*, EMPTYARG) 101 { 102 try 103 { 104 xNamed->setName(aNewNameED.GetText()); 105 } 106 catch(uno::RuntimeException&) 107 { 108 DBG_ERROR("Name wurde nicht geaendert"); 109 } 110 EndDialog(RET_OK); 111 return 0; 112 } 113 /* -----------------09.06.99 15:48------------------- 114 * 115 * --------------------------------------------------*/ 116 IMPL_LINK(SwRenameXNamedDlg, ModifyHdl, NoSpaceEdit*, pEdit) 117 { 118 String sTmp(pEdit->GetText()); 119 120 // prevent from pasting illegal characters 121 sal_uInt16 nLen = sTmp.Len(); 122 String sMsg; 123 for(sal_uInt16 i = 0; i < pEdit->GetForbiddenChars().Len(); i++) 124 { 125 sal_uInt16 nTmpLen = sTmp.Len(); 126 sTmp.EraseAllChars(pEdit->GetForbiddenChars().GetChar(i)); 127 if(sTmp.Len() != nTmpLen) 128 sMsg += pEdit->GetForbiddenChars().GetChar(i); 129 } 130 if(sTmp.Len() != nLen) 131 { 132 pEdit->SetText(sTmp); 133 String sWarning(sRemoveWarning); 134 sWarning += sMsg; 135 InfoBox(this, sWarning).Execute(); 136 } 137 138 aOk.Enable(sTmp.Len() && !xNameAccess->hasByName(sTmp) 139 && (!xSecondAccess.is() || !xSecondAccess->hasByName(sTmp)) 140 && (!xThirdAccess.is() || !xThirdAccess->hasByName(sTmp)) 141 ); 142 return 0; 143 } 144