Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <swtypes.hxx>
30 : : #include <globals.hrc>
31 : : #include <misc.hrc>
32 : :
33 : : #include <utlui.hrc>
34 : : #include <unotools.hrc>
35 : : #include <unoprnms.hxx>
36 : : #include <osl/diagnose.h>
37 : : #include <vcl/msgbox.hxx>
38 : : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
39 : : #include <com/sun/star/view/XScreenCursor.hpp>
40 : : #include <com/sun/star/view/DocumentZoomType.hpp>
41 : : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
42 : : #include <com/sun/star/style/XStyle.hpp>
43 : : #include <com/sun/star/frame/XFrame.hpp>
44 : : #include <com/sun/star/text/XText.hpp>
45 : : #include <com/sun/star/text/XTextDocument.hpp>
46 : : #include <com/sun/star/awt/PosSize.hpp>
47 : : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
48 : : #include <com/sun/star/container/XNameContainer.hpp>
49 : : #include <comphelper/processfactory.hxx>
50 : : #include <comphelper/string.hxx>
51 : : #include <sfx2/dispatch.hxx>
52 : : #include <svl/stritem.hxx>
53 : : #include <shellio.hxx>
54 : : #include <docsh.hxx>
55 : : #include <view.hxx>
56 : : #include <wrtsh.hxx>
57 : : #include <swmodule.hxx>
58 : : #include <unocrsr.hxx>
59 : :
60 : : #include "swrenamexnameddlg.hxx"
61 : :
62 : :
63 : : using namespace ::com::sun::star;
64 : : using ::rtl::OUString;
65 : :
66 : 0 : SwRenameXNamedDlg::SwRenameXNamedDlg( Window* pWin,
67 : : uno::Reference< container::XNamed > & xN,
68 : : uno::Reference< container::XNameAccess > & xNA ) :
69 : : ModalDialog(pWin, SW_RES(DLG_RENAME_XNAMED)),
70 : : aNameFL(this, SW_RES(FL_NAME)),
71 : : aNewNameFT(this, SW_RES(FT_NEW_NAME)),
72 : : aNewNameED(this, SW_RES(ED_NEW_NAME)),
73 : : aOk(this, SW_RES(PB_OK)),
74 : : aCancel(this, SW_RES(PB_CANCEL)),
75 : : aHelp(this, SW_RES(PB_HELP)),
76 : : xNamed(xN),
77 : 0 : xNameAccess(xNA)
78 : : {
79 : 0 : FreeResource();
80 : 0 : sRemoveWarning = String(SW_RES(STR_REMOVE_WARNING));
81 : :
82 : 0 : String sTmp(GetText());
83 : 0 : aNewNameED.SetText(xNamed->getName());
84 : 0 : aNewNameED.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
85 : 0 : sTmp += String(xNamed->getName());
86 : 0 : SetText(sTmp);
87 : :
88 : 0 : aOk.SetClickHdl(LINK(this, SwRenameXNamedDlg, OkHdl));
89 : 0 : aNewNameED.SetModifyHdl(LINK(this, SwRenameXNamedDlg, ModifyHdl));
90 : 0 : aOk.Enable(sal_False);
91 : 0 : }
92 : :
93 : 0 : IMPL_LINK_NOARG(SwRenameXNamedDlg, OkHdl)
94 : : {
95 : : try
96 : : {
97 : 0 : xNamed->setName(aNewNameED.GetText());
98 : : }
99 : 0 : catch (const uno::RuntimeException&)
100 : : {
101 : : OSL_FAIL("name wasn't changed");
102 : : }
103 : 0 : EndDialog(RET_OK);
104 : 0 : return 0;
105 : : }
106 : :
107 : 0 : IMPL_LINK(SwRenameXNamedDlg, ModifyHdl, NoSpaceEdit*, pEdit)
108 : : {
109 : 0 : String sTmp(pEdit->GetText());
110 : :
111 : : // prevent from pasting illegal characters
112 : 0 : sal_uInt16 nLen = sTmp.Len();
113 : 0 : String sMsg;
114 : 0 : for(sal_uInt16 i = 0; i < pEdit->GetForbiddenChars().Len(); i++)
115 : : {
116 : 0 : sal_uInt16 nTmpLen = sTmp.Len();
117 : 0 : sTmp = comphelper::string::remove(sTmp, pEdit->GetForbiddenChars().GetChar(i));
118 : 0 : if(sTmp.Len() != nTmpLen)
119 : 0 : sMsg += pEdit->GetForbiddenChars().GetChar(i);
120 : : }
121 : 0 : if(sTmp.Len() != nLen)
122 : : {
123 : 0 : pEdit->SetText(sTmp);
124 : 0 : String sWarning(sRemoveWarning);
125 : 0 : sWarning += sMsg;
126 : 0 : InfoBox(this, sWarning).Execute();
127 : : }
128 : :
129 : 0 : aOk.Enable(sTmp.Len() && !xNameAccess->hasByName(sTmp)
130 : 0 : && (!xSecondAccess.is() || !xSecondAccess->hasByName(sTmp))
131 : 0 : && (!xThirdAccess.is() || !xThirdAccess->hasByName(sTmp))
132 : 0 : );
133 : 0 : return 0;
134 : : }
135 : :
136 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|