bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fulinend.cxx
blob531ecda3225fd5f41c2df122dc9a78ff933df083
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"
36 namespace sd {
38 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 FunctionReference FuLineEnd::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
49 FunctionReference 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( sal_True, sal_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 = ( (SdrPathObj*) pNewObj )->GetPathPoly();
90 // Delete the created poly-object
91 SdrObject::Free( pConvPolyObj );
93 XLineEndListRef pLineEndList = mpDoc->GetLineEndList();
95 String aNewName( SdResId( STR_LINEEND ) );
96 String aDesc( SdResId( STR_DESC_LINEEND ) );
97 String aName;
99 long nCount = pLineEndList->Count();
100 long j = 1;
101 sal_Bool bDifferent = sal_False;
103 while( !bDifferent )
105 aName = aNewName;
106 aName.Append( sal_Unicode(' ') );
107 aName.Append( OUString::valueOf( j++ ) );
108 bDifferent = sal_True;
109 for( long i = 0; i < nCount && bDifferent; i++ )
111 if( aName == pLineEndList->GetLineEnd( i )->GetName() )
112 bDifferent = sal_False;
116 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
117 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 = sal_True;
128 for( long i = 0; i < nCount && bDifferent; i++ )
130 if( aName == pLineEndList->GetLineEnd( i )->GetName() )
131 bDifferent = sal_False;
134 if( bDifferent )
136 XLineEndEntry* pEntry = new XLineEndEntry( aPolyPolygon, aName );
137 pLineEndList->Insert( pEntry, LIST_APPEND);
139 else
141 String aStr(SdResId( STR_WARN_NAME_DUPLICATE ));
142 WarningBox aWarningBox( mpWindow, WinBits( WB_OK ),
143 aStr );
144 aWarningBox.Execute();
148 delete pDlg;
152 void FuLineEnd::Activate()
156 void FuLineEnd::Deactivate()
160 } // end of namespace sd
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */