Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
27 :
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>
36 :
37 : namespace sd {
38 :
39 0 : TYPEINIT1( FuLineEnd, FuPoor );
40 :
41 0 : FuLineEnd::FuLineEnd(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
42 : SdDrawDocument* pDoc, SfxRequest& rReq)
43 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
44 : {
45 0 : }
46 :
47 0 : rtl::Reference<FuPoor> FuLineEnd::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
48 : {
49 0 : rtl::Reference<FuPoor> xFunc( new FuLineEnd( pViewSh, pWin, pView, pDoc, rReq ) );
50 0 : xFunc->DoExecute(rReq);
51 0 : return xFunc;
52 : }
53 :
54 0 : void FuLineEnd::DoExecute( SfxRequest& )
55 : {
56 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
57 :
58 0 : if( rMarkList.GetMarkCount() == 1 )
59 : {
60 0 : const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
61 : const SdrObject* pNewObj;
62 0 : SdrObject* pConvPolyObj = NULL;
63 :
64 0 : if( pObj->ISA( SdrPathObj ) )
65 : {
66 0 : pNewObj = pObj;
67 : }
68 : else
69 : {
70 0 : SdrObjTransformInfoRec aInfoRec;
71 0 : pObj->TakeObjInfo( aInfoRec );
72 :
73 0 : if( aInfoRec.bCanConvToPath &&
74 0 : pObj->GetObjInventor() == SdrInventor &&
75 0 : pObj->GetObjIdentifier() != OBJ_GRUP )
76 : // bCanConvToPath is sal_True for group objects,
77 : // but it crashes on ConvertToPathObj()!
78 : {
79 0 : pNewObj = pConvPolyObj = pObj->ConvertToPolyObj( true, false );
80 :
81 0 : if( !pNewObj || !pNewObj->ISA( SdrPathObj ) )
82 0 : return; // Cancel, additional security, but it does not help
83 : // for group objects
84 : }
85 0 : else return; // Cancel
86 : }
87 :
88 0 : const ::basegfx::B2DPolyPolygon aPolyPolygon = static_cast<const SdrPathObj*>(pNewObj)->GetPathPoly();
89 :
90 : // Delete the created poly-object
91 0 : SdrObject::Free( pConvPolyObj );
92 :
93 0 : XLineEndListRef pLineEndList = mpDoc->GetLineEndList();
94 :
95 0 : OUString aNewName( SD_RESSTR( STR_LINEEND ) );
96 0 : OUString aDesc( SD_RESSTR( STR_DESC_LINEEND ) );
97 0 : OUString aName;
98 :
99 0 : long nCount = pLineEndList->Count();
100 0 : long j = 1;
101 0 : bool bDifferent = false;
102 :
103 0 : while( !bDifferent )
104 : {
105 0 : aName = aNewName;
106 0 : aName += " ";
107 0 : aName += OUString::number(j++);
108 0 : bDifferent = true;
109 0 : for( long i = 0; i < nCount && bDifferent; i++ )
110 : {
111 0 : if( aName == pLineEndList->GetLineEnd( i )->GetName() )
112 0 : bDifferent = false;
113 : }
114 : }
115 :
116 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
117 0 : boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact ? pFact->CreateSvxNameDialog( NULL, aName, aDesc ) : 0);
118 :
119 0 : if( pDlg )
120 : {
121 0 : pDlg->SetEditHelpId( HID_SD_NAMEDIALOG_LINEEND );
122 :
123 0 : if( pDlg->Execute() == RET_OK )
124 : {
125 0 : pDlg->GetName( aName );
126 0 : bDifferent = true;
127 :
128 0 : for( long i = 0; i < nCount && bDifferent; i++ )
129 : {
130 0 : if( aName == pLineEndList->GetLineEnd( i )->GetName() )
131 0 : bDifferent = false;
132 : }
133 :
134 0 : if( bDifferent )
135 : {
136 0 : XLineEndEntry* pEntry = new XLineEndEntry( aPolyPolygon, aName );
137 0 : pLineEndList->Insert( pEntry);
138 : }
139 : else
140 : {
141 : ScopedVclPtrInstance<WarningBox> aWarningBox( mpWindow, WinBits( WB_OK ),
142 0 : SD_RESSTR( STR_WARN_NAME_DUPLICATE ) );
143 0 : aWarningBox->Execute();
144 : }
145 : }
146 0 : }
147 : }
148 : }
149 :
150 0 : void FuLineEnd::Activate()
151 : {
152 0 : }
153 :
154 0 : void FuLineEnd::Deactivate()
155 : {
156 0 : }
157 :
158 66 : } // end of namespace sd
159 :
160 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|