Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <swtypes.hxx>
21 : #include <globals.hrc>
22 :
23 : #include <utlui.hrc>
24 : #include <unotools.hrc>
25 : #include <unoprnms.hxx>
26 : #include <osl/diagnose.h>
27 : #include <vcl/msgbox.hxx>
28 : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
29 : #include <com/sun/star/view/XScreenCursor.hpp>
30 : #include <com/sun/star/view/DocumentZoomType.hpp>
31 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
32 : #include <com/sun/star/style/XStyle.hpp>
33 : #include <com/sun/star/frame/XFrame.hpp>
34 : #include <com/sun/star/text/XText.hpp>
35 : #include <com/sun/star/text/XTextDocument.hpp>
36 : #include <com/sun/star/awt/PosSize.hpp>
37 : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
38 : #include <com/sun/star/container/XNameContainer.hpp>
39 : #include <comphelper/processfactory.hxx>
40 : #include <comphelper/string.hxx>
41 : #include <sfx2/dispatch.hxx>
42 : #include <svl/stritem.hxx>
43 : #include <shellio.hxx>
44 : #include <docsh.hxx>
45 : #include <view.hxx>
46 : #include <wrtsh.hxx>
47 : #include <swmodule.hxx>
48 : #include <unocrsr.hxx>
49 :
50 : #include "swrenamexnameddlg.hxx"
51 :
52 :
53 : using namespace ::com::sun::star;
54 :
55 0 : SwRenameXNamedDlg::SwRenameXNamedDlg( Window* pWin,
56 : uno::Reference< container::XNamed > & xN,
57 : uno::Reference< container::XNameAccess > & xNA )
58 : : ModalDialog(pWin, "RenameObjectDialog",
59 : "modules/swriter/ui/renameobjectdialog.ui")
60 : , m_sRemoveWarning(SW_RESSTR(STR_REMOVE_WARNING))
61 : , xNamed(xN)
62 0 : , xNameAccess(xNA)
63 : {
64 0 : get(m_pNewNameED, "entry");
65 0 : get(m_pOk, "ok");
66 :
67 0 : String sTmp(GetText());
68 0 : m_pNewNameED->SetText(xNamed->getName());
69 0 : m_pNewNameED->SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
70 0 : sTmp += String(xNamed->getName());
71 0 : SetText(sTmp);
72 :
73 0 : m_pOk->SetClickHdl(LINK(this, SwRenameXNamedDlg, OkHdl));
74 0 : m_pNewNameED->SetModifyHdl(LINK(this, SwRenameXNamedDlg, ModifyHdl));
75 0 : m_pOk->Enable(sal_False);
76 0 : }
77 :
78 0 : IMPL_LINK_NOARG(SwRenameXNamedDlg, OkHdl)
79 : {
80 : try
81 : {
82 0 : xNamed->setName(m_pNewNameED->GetText());
83 : }
84 0 : catch (const uno::RuntimeException&)
85 : {
86 : OSL_FAIL("name wasn't changed");
87 : }
88 0 : EndDialog(RET_OK);
89 0 : return 0;
90 : }
91 :
92 0 : IMPL_LINK(SwRenameXNamedDlg, ModifyHdl, NoSpaceEdit*, pEdit)
93 : {
94 0 : String sTmp(pEdit->GetText());
95 :
96 : // prevent from pasting illegal characters
97 0 : sal_uInt16 nLen = sTmp.Len();
98 0 : String sMsg;
99 0 : for(sal_uInt16 i = 0; i < pEdit->GetForbiddenChars().Len(); i++)
100 : {
101 0 : sal_uInt16 nTmpLen = sTmp.Len();
102 0 : sTmp = comphelper::string::remove(sTmp, pEdit->GetForbiddenChars().GetChar(i));
103 0 : if(sTmp.Len() != nTmpLen)
104 0 : sMsg += pEdit->GetForbiddenChars().GetChar(i);
105 : }
106 0 : if(sTmp.Len() != nLen)
107 : {
108 0 : pEdit->SetText(sTmp);
109 0 : String sWarning(m_sRemoveWarning);
110 0 : sWarning += sMsg;
111 0 : InfoBox(this, sWarning).Execute();
112 : }
113 :
114 0 : m_pOk->Enable(sTmp.Len() && !xNameAccess->hasByName(sTmp)
115 0 : && (!xSecondAccess.is() || !xSecondAccess->hasByName(sTmp))
116 0 : && (!xThirdAccess.is() || !xThirdAccess->hasByName(sTmp))
117 0 : );
118 0 : return 0;
119 0 : }
120 :
121 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|