1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/svdobj.hxx>
24 #include <svx/svdopath.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/weld.hxx>
28 #include <strings.hrc>
30 #include <sdresid.hxx>
31 #include <drawdoc.hxx>
39 FuLineEnd::FuLineEnd(ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
,
40 SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
41 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
45 rtl::Reference
<FuPoor
> FuLineEnd::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
47 rtl::Reference
<FuPoor
> xFunc( new FuLineEnd( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
48 xFunc
->DoExecute(rReq
);
52 void FuLineEnd::DoExecute( SfxRequest
& )
54 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
56 if( rMarkList
.GetMarkCount() != 1 )
59 const SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
61 const SdrObject
* pNewObj
;
62 rtl::Reference
<SdrObject
> pConvPolyObj
;
64 if( dynamic_cast< const SdrPathObj
*>( pObj
) != nullptr )
70 SdrObjTransformInfoRec aInfoRec
;
71 pObj
->TakeObjInfo( aInfoRec
);
73 if( aInfoRec
.bCanConvToPath
&&
74 pObj
->GetObjInventor() == SdrInventor::Default
&&
75 pObj
->GetObjIdentifier() != SdrObjKind::Group
)
76 // bCanConvToPath is sal_True for group objects,
77 // but it crashes on ConvertToPathObj()!
79 pConvPolyObj
= pObj
->ConvertToPolyObj( true, false );
80 pNewObj
= pConvPolyObj
.get();
82 if( !pNewObj
|| dynamic_cast< const SdrPathObj
*>( pNewObj
) == nullptr )
83 return; // Cancel, additional security, but it does not help
86 else return; // Cancel
89 const ::basegfx::B2DPolyPolygon aPolyPolygon
= static_cast<const SdrPathObj
*>(pNewObj
)->GetPathPoly();
91 // Delete the created poly-object
94 XLineEndListRef pLineEndList
= mpDoc
->GetLineEndList();
96 OUString
aNewName( SdResId( STR_LINEEND
) );
97 OUString
aDesc( SdResId( STR_DESC_LINEEND
) );
100 ::tools::Long nCount
= pLineEndList
->Count();
102 bool bDifferent
= false;
106 aName
= aNewName
+ " " + OUString::number(j
++);
108 for( ::tools::Long i
= 0; i
< nCount
&& bDifferent
; i
++ )
110 if( aName
== pLineEndList
->GetLineEnd( i
)->GetName() )
115 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
116 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg( pFact
->CreateSvxNameDialog( nullptr, aName
, aDesc
) );
118 pDlg
->SetEditHelpId( HID_SD_NAMEDIALOG_LINEEND
);
120 if( pDlg
->Execute() != RET_OK
)
123 aName
= pDlg
->GetName();
126 for( ::tools::Long i
= 0; i
< nCount
&& bDifferent
; i
++ )
128 if( aName
== pLineEndList
->GetLineEnd( i
)->GetName() )
134 pLineEndList
->Insert(std::make_unique
<XLineEndEntry
>(aPolyPolygon
, aName
));
138 std::unique_ptr
<weld::MessageDialog
> xWarn(Application::CreateMessageDialog(mpWindow
? mpWindow
->GetFrameWeld() : nullptr,
139 VclMessageType::Warning
, VclButtonsType::Ok
,
140 SdResId(STR_WARN_NAME_DUPLICATE
)));
145 void FuLineEnd::Activate()
149 void FuLineEnd::Deactivate()
153 } // end of namespace sd
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */