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/msgbox.hxx>
28 #include "strings.hrc"
29 #include "ViewShell.hxx"
31 #include "sdresid.hxx"
32 #include "drawdoc.hxx"
35 #include <boost/scoped_ptr.hpp>
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
);
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
) )
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
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
) );
99 long nCount
= pLineEndList
->Count();
101 bool bDifferent
= false;
107 aName
+= OUString::number(j
++);
109 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
111 if( aName
== pLineEndList
->GetLineEnd( i
)->GetName() )
116 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
117 boost::scoped_ptr
<AbstractSvxNameDialog
> pDlg(pFact
? pFact
->CreateSvxNameDialog( NULL
, aName
, aDesc
) : 0);
121 pDlg
->SetEditHelpId( HID_SD_NAMEDIALOG_LINEEND
);
123 if( pDlg
->Execute() == RET_OK
)
125 pDlg
->GetName( aName
);
128 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
130 if( aName
== pLineEndList
->GetLineEnd( i
)->GetName() )
136 XLineEndEntry
* pEntry
= new XLineEndEntry( aPolyPolygon
, aName
);
137 pLineEndList
->Insert( pEntry
);
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: */