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