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