bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fulinend.cxx
blobb963b06e5cf89f15f2b06848865c50a9bb304fe3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "fulinend.hxx"
21 #include <svx/xtable.hxx>
22 #include <svx/svxdlg.hxx>
23 #include <svx/dialogs.hrc>
24 #include <svx/svdobj.hxx>
25 #include <svx/svdopath.hxx>
26 #include <vcl/msgbox.hxx>
28 #include "strings.hrc"
29 #include "ViewShell.hxx"
30 #include "helpids.h"
31 #include "sdresid.hxx"
32 #include "drawdoc.hxx"
33 #include "View.hxx"
34 #include "Window.hxx"
35 #include <boost/scoped_ptr.hpp>
37 namespace sd {
39 TYPEINIT1( FuLineEnd, FuPoor );
41 FuLineEnd::FuLineEnd(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
42 SdDrawDocument* pDoc, SfxRequest& rReq)
43 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
47 rtl::Reference<FuPoor> FuLineEnd::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
49 rtl::Reference<FuPoor> xFunc( new FuLineEnd( pViewSh, pWin, pView, pDoc, rReq ) );
50 xFunc->DoExecute(rReq);
51 return xFunc;
54 void FuLineEnd::DoExecute( SfxRequest& )
56 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
58 if( rMarkList.GetMarkCount() == 1 )
60 const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
61 const SdrObject* pNewObj;
62 SdrObject* pConvPolyObj = NULL;
64 if( pObj->ISA( SdrPathObj ) )
66 pNewObj = pObj;
68 else
70 SdrObjTransformInfoRec aInfoRec;
71 pObj->TakeObjInfo( aInfoRec );
73 if( aInfoRec.bCanConvToPath &&
74 pObj->GetObjInventor() == SdrInventor &&
75 pObj->GetObjIdentifier() != OBJ_GRUP )
76 // bCanConvToPath is sal_True for group objects,
77 // but it crashes on ConvertToPathObj()!
79 pNewObj = pConvPolyObj = pObj->ConvertToPolyObj( true, false );
81 if( !pNewObj || !pNewObj->ISA( SdrPathObj ) )
82 return; // Cancel, additional security, but it does not help
83 // for group objects
85 else return; // Cancel
88 const ::basegfx::B2DPolyPolygon aPolyPolygon = static_cast<const SdrPathObj*>(pNewObj)->GetPathPoly();
90 // Delete the created poly-object
91 SdrObject::Free( pConvPolyObj );
93 XLineEndListRef pLineEndList = mpDoc->GetLineEndList();
95 OUString aNewName( SD_RESSTR( STR_LINEEND ) );
96 OUString aDesc( SD_RESSTR( STR_DESC_LINEEND ) );
97 OUString aName;
99 long nCount = pLineEndList->Count();
100 long j = 1;
101 bool bDifferent = false;
103 while( !bDifferent )
105 aName = aNewName;
106 aName += " ";
107 aName += OUString::number(j++);
108 bDifferent = true;
109 for( long i = 0; i < nCount && bDifferent; i++ )
111 if( aName == pLineEndList->GetLineEnd( i )->GetName() )
112 bDifferent = false;
116 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
117 boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact ? pFact->CreateSvxNameDialog( NULL, aName, aDesc ) : 0);
119 if( pDlg )
121 pDlg->SetEditHelpId( HID_SD_NAMEDIALOG_LINEEND );
123 if( pDlg->Execute() == RET_OK )
125 pDlg->GetName( aName );
126 bDifferent = true;
128 for( long i = 0; i < nCount && bDifferent; i++ )
130 if( aName == pLineEndList->GetLineEnd( i )->GetName() )
131 bDifferent = false;
134 if( bDifferent )
136 XLineEndEntry* pEntry = new XLineEndEntry( aPolyPolygon, aName );
137 pLineEndList->Insert( pEntry);
139 else
141 ScopedVclPtrInstance<WarningBox> aWarningBox( mpWindow, WinBits( WB_OK ),
142 SD_RESSTR( STR_WARN_NAME_DUPLICATE ) );
143 aWarningBox->Execute();
150 void FuLineEnd::Activate()
154 void FuLineEnd::Deactivate()
158 } // end of namespace sd
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */