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/dialogs.hrc>
24 #include <svx/svdobj.hxx>
25 #include <svx/svdopath.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/weld.hxx>
29 #include <strings.hrc>
30 #include <ViewShell.hxx>
32 #include <sdresid.hxx>
33 #include <drawdoc.hxx>
37 #include <o3tl/make_unique.hxx>
42 FuLineEnd::FuLineEnd(ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
,
43 SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
44 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
48 rtl::Reference
<FuPoor
> FuLineEnd::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
50 rtl::Reference
<FuPoor
> xFunc( new FuLineEnd( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
51 xFunc
->DoExecute(rReq
);
55 void FuLineEnd::DoExecute( SfxRequest
& )
57 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
59 if( rMarkList
.GetMarkCount() == 1 )
61 const SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
62 const SdrObject
* pNewObj
;
63 SdrObject
* pConvPolyObj
= nullptr;
65 if( dynamic_cast< const SdrPathObj
*>( pObj
) != nullptr )
71 SdrObjTransformInfoRec aInfoRec
;
72 pObj
->TakeObjInfo( aInfoRec
);
74 if( aInfoRec
.bCanConvToPath
&&
75 pObj
->GetObjInventor() == SdrInventor::Default
&&
76 pObj
->GetObjIdentifier() != OBJ_GRUP
)
77 // bCanConvToPath is sal_True for group objects,
78 // but it crashes on ConvertToPathObj()!
80 pNewObj
= pConvPolyObj
= pObj
->ConvertToPolyObj( true, false );
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
92 SdrObject::Free( pConvPolyObj
);
94 XLineEndListRef pLineEndList
= mpDoc
->GetLineEndList();
96 OUString
aNewName( SdResId( STR_LINEEND
) );
97 OUString
aDesc( SdResId( STR_DESC_LINEEND
) );
100 long nCount
= pLineEndList
->Count();
102 bool bDifferent
= false;
108 aName
+= OUString::number(j
++);
110 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
112 if( aName
== pLineEndList
->GetLineEnd( i
)->GetName() )
117 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
118 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg(pFact
? pFact
->CreateSvxNameDialog( nullptr, aName
, aDesc
) : nullptr);
122 pDlg
->SetEditHelpId( HID_SD_NAMEDIALOG_LINEEND
);
124 if( pDlg
->Execute() == RET_OK
)
126 pDlg
->GetName( aName
);
129 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
131 if( aName
== pLineEndList
->GetLineEnd( i
)->GetName() )
137 pLineEndList
->Insert(o3tl::make_unique
<XLineEndEntry
>(aPolyPolygon
, aName
));
141 std::unique_ptr
<weld::MessageDialog
> xWarn(Application::CreateMessageDialog(mpWindow
? mpWindow
->GetFrameWeld() : nullptr,
142 VclMessageType::Warning
, VclButtonsType::Ok
,
143 SdResId(STR_WARN_NAME_DUPLICATE
)));
151 void FuLineEnd::Activate()
155 void FuLineEnd::Deactivate()
159 } // end of namespace sd
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */