1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #ifdef SW_DLLIMPLEMENTATION
27 #undef SW_DLLIMPLEMENTATION
28 #endif
29 
30 
31 #include <swtypes.hxx>
32 #include <globals.hrc>
33 #include <misc.hrc>
34 
35 #include <utlui.hrc>
36 #include <unotools.hrc>
37 #include <unoprnms.hxx>
38 #include <tools/debug.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
41 #include <com/sun/star/view/XScreenCursor.hpp>
42 #include <com/sun/star/view/DocumentZoomType.hpp>
43 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
44 #include <com/sun/star/style/XStyle.hpp>
45 #include <com/sun/star/frame/XFrame.hpp>
46 #include <com/sun/star/text/XText.hpp>
47 #include <com/sun/star/text/XTextDocument.hpp>
48 #include <com/sun/star/awt/PosSize.hpp>
49 #include <com/sun/star/view/XViewSettingsSupplier.hpp>
50 #include <com/sun/star/container/XNameContainer.hpp>
51 #include <comphelper/processfactory.hxx>
52 #include <sfx2/dispatch.hxx>
53 #include <svl/stritem.hxx>
54 #include <shellio.hxx>
55 #include <docsh.hxx>
56 #include <view.hxx>
57 #include <wrtsh.hxx>
58 #include <swmodule.hxx>
59 #include <unocrsr.hxx>
60 
61 #include "swrenamexnameddlg.hxx"
62 
63 
64 using namespace ::com::sun::star;
65 using ::rtl::OUString;
66 
SwRenameXNamedDlg(Window * pWin,uno::Reference<container::XNamed> & xN,uno::Reference<container::XNameAccess> & xNA)67 SwRenameXNamedDlg::SwRenameXNamedDlg( Window* pWin,
68 			uno::Reference< container::XNamed > & xN,
69 			uno::Reference< container::XNameAccess > & xNA ) :
70 	ModalDialog(pWin, SW_RES(DLG_RENAME_XNAMED)),
71    aNameFL(this, SW_RES(FL_NAME)),
72     aNewNameFT(this, SW_RES(FT_NEW_NAME)),
73    aNewNameED(this, SW_RES(ED_NEW_NAME)),
74    aOk(this, SW_RES(PB_OK)),
75    aCancel(this, SW_RES(PB_CANCEL)),
76    aHelp(this, SW_RES(PB_HELP)),
77    xNamed(xN),
78    xNameAccess(xNA)
79 {
80 	FreeResource();
81 	sRemoveWarning = String(SW_RES(STR_REMOVE_WARNING));
82 
83 	String sTmp(GetText());
84 	aNewNameED.SetText(xNamed->getName());
85     aNewNameED.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
86 	sTmp += String(xNamed->getName());
87 	SetText(sTmp);
88 
89 	aOk.SetClickHdl(LINK(this, SwRenameXNamedDlg, OkHdl));
90 	aNewNameED.SetModifyHdl(LINK(this, SwRenameXNamedDlg, ModifyHdl));
91 	aOk.Enable(sal_False);
92 }
93 /* -----------------09.06.99 15:34-------------------
94  *
95  * --------------------------------------------------*/
IMPL_LINK(SwRenameXNamedDlg,OkHdl,OKButton *,EMPTYARG)96 IMPL_LINK(SwRenameXNamedDlg, OkHdl, OKButton*, EMPTYARG)
97 {
98 	try
99 	{
100 		xNamed->setName(aNewNameED.GetText());
101 	}
102 	catch(uno::RuntimeException&)
103 	{
104 		DBG_ERROR("Name wurde nicht geaendert");
105 	}
106 	EndDialog(RET_OK);
107 	return 0;
108 }
109 /* -----------------09.06.99 15:48-------------------
110  *
111  * --------------------------------------------------*/
IMPL_LINK(SwRenameXNamedDlg,ModifyHdl,NoSpaceEdit *,pEdit)112 IMPL_LINK(SwRenameXNamedDlg, ModifyHdl, NoSpaceEdit*, pEdit)
113 {
114 	String sTmp(pEdit->GetText());
115 
116 	// prevent from pasting illegal characters
117 	sal_uInt16 nLen = sTmp.Len();
118 	String sMsg;
119 	for(sal_uInt16 i = 0; i < pEdit->GetForbiddenChars().Len(); i++)
120 	{
121 		sal_uInt16 nTmpLen = sTmp.Len();
122 		sTmp.EraseAllChars(pEdit->GetForbiddenChars().GetChar(i));
123 		if(sTmp.Len() != nTmpLen)
124 			sMsg += pEdit->GetForbiddenChars().GetChar(i);
125 	}
126 	if(sTmp.Len() != nLen)
127 	{
128 		pEdit->SetText(sTmp);
129 		String sWarning(sRemoveWarning);
130 		sWarning += sMsg;
131 		InfoBox(this, sWarning).Execute();
132 	}
133 
134 	aOk.Enable(sTmp.Len() && !xNameAccess->hasByName(sTmp)
135 	&& (!xSecondAccess.is() || !xSecondAccess->hasByName(sTmp))
136 	&& (!xThirdAccess.is() || !xThirdAccess->hasByName(sTmp))
137 	);
138 	return 0;
139 }
140