xref: /aoo41x/main/sd/source/ui/func/fulinend.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 
32 #include "fulinend.hxx"
33 #include <svx/xtable.hxx>
34 #include <svx/svxdlg.hxx>
35 #include <svx/dialogs.hrc>
36 #include <svx/svdobj.hxx>
37 #include <svx/svdopath.hxx>
38 #include <vcl/msgbox.hxx>
39 
40 #include "strings.hrc"
41 #include "ViewShell.hxx"
42 #include "helpids.h"
43 #include "sdresid.hxx"
44 #include "drawdoc.hxx"
45 #include "View.hxx"
46 #ifndef SD_WINDOW_SHELL_HXX
47 #include "Window.hxx"
48 #endif
49 
50 namespace sd {
51 
52 #define BITMAP_WIDTH  32
53 #define BITMAP_HEIGHT 12
54 
55 TYPEINIT1( FuLineEnd, FuPoor );
56 
57 /*************************************************************************
58 |*
59 |* Konstruktor
60 |*
61 \************************************************************************/
62 
63 FuLineEnd::FuLineEnd(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
64 					SdDrawDocument* pDoc, SfxRequest& rReq)
65 	: FuPoor(pViewSh, pWin, pView, pDoc, rReq)
66 {
67 }
68 
69 FunctionReference FuLineEnd::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
70 {
71 	FunctionReference xFunc( new FuLineEnd( pViewSh, pWin, pView, pDoc, rReq ) );
72 	xFunc->DoExecute(rReq);
73 	return xFunc;
74 }
75 
76 void FuLineEnd::DoExecute( SfxRequest& )
77 {
78 	const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
79 
80 	if( rMarkList.GetMarkCount() == 1 )
81 	{
82 		const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
83 		const SdrObject* pNewObj;
84 		SdrObject* pConvPolyObj = NULL;
85 
86 		if( pObj->ISA( SdrPathObj ) )
87 		{
88 			pNewObj = pObj;
89 		}
90 		else
91 		{
92 			SdrObjTransformInfoRec aInfoRec;
93 			pObj->TakeObjInfo( aInfoRec );
94 
95 			if( aInfoRec.bCanConvToPath &&
96 				pObj->GetObjInventor() == SdrInventor &&
97 				pObj->GetObjIdentifier() != OBJ_GRUP )
98 				// bCanConvToPath ist bei Gruppenobjekten sal_True,
99 				// stuerzt aber bei ConvertToPathObj() ab !
100 			{
101 				pNewObj = pConvPolyObj = pObj->ConvertToPolyObj( sal_True, sal_False );
102 
103 				if( !pNewObj || !pNewObj->ISA( SdrPathObj ) )
104 					return; // Abbruch, zusaetzliche Sicherheit, die bei
105 							// Gruppenobjekten aber nichts bringt.
106 			}
107 			else return; // Abbruch
108 		}
109 
110 		const ::basegfx::B2DPolyPolygon aPolyPolygon = ( (SdrPathObj*) pNewObj )->GetPathPoly();
111 
112 		// Loeschen des angelegten PolyObjektes
113 		SdrObject::Free( pConvPolyObj );
114 
115 		XLineEndList* pLineEndList = mpDoc->GetLineEndList();
116 		XLineEndEntry* pEntry;
117 
118 		String aNewName( SdResId( STR_LINEEND ) );
119 		String aDesc( SdResId( STR_DESC_LINEEND ) );
120 		String aName;
121 
122 		long nCount = pLineEndList->Count();
123 		long j = 1;
124 		sal_Bool bDifferent = sal_False;
125 
126 		while( !bDifferent )
127 		{
128 			aName = aNewName;
129 			aName.Append( sal_Unicode(' ') );
130 			aName.Append( UniString::CreateFromInt32( j++ ) );
131 			bDifferent = sal_True;
132 			for( long i = 0; i < nCount && bDifferent; i++ )
133 			{
134 				if( aName == pLineEndList->GetLineEnd( i )->GetName() )
135 					bDifferent = sal_False;
136 			}
137 		}
138 
139 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
140 		AbstractSvxNameDialog* pDlg = pFact ? pFact->CreateSvxNameDialog( NULL, aName, aDesc ) : 0;
141 
142 		if( pDlg )
143 		{
144 			pDlg->SetEditHelpId( HID_SD_NAMEDIALOG_LINEEND );
145 
146 			if( pDlg->Execute() == RET_OK )
147 			{
148 				pDlg->GetName( aName );
149 				bDifferent = sal_True;
150 
151 				for( long i = 0; i < nCount && bDifferent; i++ )
152 				{
153 					if( aName == pLineEndList->GetLineEnd( i )->GetName() )
154 						bDifferent = sal_False;
155 				}
156 
157 				if( bDifferent )
158 				{
159 					pEntry = new XLineEndEntry( aPolyPolygon, aName );
160 					pLineEndList->Insert( pEntry, LIST_APPEND);
161 				}
162 				else
163 				{
164 					String aStr(SdResId( STR_WARN_NAME_DUPLICATE ));
165 					WarningBox aWarningBox( mpWindow, WinBits( WB_OK ),
166 						 aStr );
167 					aWarningBox.Execute();
168 				}
169 			}
170 		}
171 		delete pDlg;
172 	}
173 }
174 
175 void FuLineEnd::Activate()
176 {
177 }
178 
179 void FuLineEnd::Deactivate()
180 {
181 }
182 
183 } // end of namespace sd
184