xref: /trunk/main/sd/source/ui/func/fulinend.cxx (revision 5b190011)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 
28 #include "fulinend.hxx"
29 #include <svx/xtable.hxx>
30 #include <svx/svxdlg.hxx>
31 #include <svx/dialogs.hrc>
32 #include <svx/svdobj.hxx>
33 #include <svx/svdopath.hxx>
34 #include <vcl/msgbox.hxx>
35 
36 #include "strings.hrc"
37 #include "ViewShell.hxx"
38 #include "helpids.h"
39 #include "sdresid.hxx"
40 #include "drawdoc.hxx"
41 #include "View.hxx"
42 #ifndef SD_WINDOW_SHELL_HXX
43 #include "Window.hxx"
44 #endif
45 
46 namespace sd {
47 
48 #define BITMAP_WIDTH  32
49 #define BITMAP_HEIGHT 12
50 
51 TYPEINIT1( FuLineEnd, FuPoor );
52 
53 /*************************************************************************
54 |*
55 |* Konstruktor
56 |*
57 \************************************************************************/
58 
59 FuLineEnd::FuLineEnd(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
60 					SdDrawDocument* pDoc, SfxRequest& rReq)
61 	: FuPoor(pViewSh, pWin, pView, pDoc, rReq)
62 {
63 }
64 
65 FunctionReference FuLineEnd::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
66 {
67 	FunctionReference xFunc( new FuLineEnd( pViewSh, pWin, pView, pDoc, rReq ) );
68 	xFunc->DoExecute(rReq);
69 	return xFunc;
70 }
71 
72 void FuLineEnd::DoExecute( SfxRequest& )
73 {
74 	const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
75 
76 	if( rMarkList.GetMarkCount() == 1 )
77 	{
78 		const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
79 		const SdrObject* pNewObj;
80 		SdrObject* pConvPolyObj = NULL;
81 
82 		if( pObj->ISA( SdrPathObj ) )
83 		{
84 			pNewObj = pObj;
85 		}
86 		else
87 		{
88 			SdrObjTransformInfoRec aInfoRec;
89 			pObj->TakeObjInfo( aInfoRec );
90 
91 			if( aInfoRec.bCanConvToPath &&
92 				pObj->GetObjInventor() == SdrInventor &&
93 				pObj->GetObjIdentifier() != OBJ_GRUP )
94 				// bCanConvToPath ist bei Gruppenobjekten sal_True,
95 				// stuerzt aber bei ConvertToPathObj() ab !
96 			{
97 				pNewObj = pConvPolyObj = pObj->ConvertToPolyObj( sal_True, sal_False );
98 
99 				if( !pNewObj || !pNewObj->ISA( SdrPathObj ) )
100 					return; // Abbruch, zusaetzliche Sicherheit, die bei
101 							// Gruppenobjekten aber nichts bringt.
102 			}
103 			else return; // Abbruch
104 		}
105 
106 		const ::basegfx::B2DPolyPolygon aPolyPolygon = ( (SdrPathObj*) pNewObj )->GetPathPoly();
107 
108 		// Loeschen des angelegten PolyObjektes
109 		SdrObject::Free( pConvPolyObj );
110 
111 		XLineEndList* pLineEndList = mpDoc->GetLineEndList();
112 		XLineEndEntry* pEntry;
113 
114 		String aNewName( SdResId( STR_LINEEND ) );
115 		String aDesc( SdResId( STR_DESC_LINEEND ) );
116 		String aName;
117 
118 		long nCount = pLineEndList->Count();
119 		long j = 1;
120 		sal_Bool bDifferent = sal_False;
121 
122 		while( !bDifferent )
123 		{
124 			aName = aNewName;
125 			aName.Append( sal_Unicode(' ') );
126 			aName.Append( UniString::CreateFromInt32( j++ ) );
127 			bDifferent = sal_True;
128 			for( long i = 0; i < nCount && bDifferent; i++ )
129 			{
130 				if( aName == pLineEndList->GetLineEnd( i )->GetName() )
131 					bDifferent = sal_False;
132 			}
133 		}
134 
135 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
136 		AbstractSvxNameDialog* pDlg = pFact ? pFact->CreateSvxNameDialog( NULL, aName, aDesc ) : 0;
137 
138 		if( pDlg )
139 		{
140 			pDlg->SetEditHelpId( HID_SD_NAMEDIALOG_LINEEND );
141 
142 			if( pDlg->Execute() == RET_OK )
143 			{
144 				pDlg->GetName( aName );
145 				bDifferent = sal_True;
146 
147 				for( long i = 0; i < nCount && bDifferent; i++ )
148 				{
149 					if( aName == pLineEndList->GetLineEnd( i )->GetName() )
150 						bDifferent = sal_False;
151 				}
152 
153 				if( bDifferent )
154 				{
155 					pEntry = new XLineEndEntry( aPolyPolygon, aName );
156 					pLineEndList->Insert( pEntry, LIST_APPEND);
157 				}
158 				else
159 				{
160 					String aStr(SdResId( STR_WARN_NAME_DUPLICATE ));
161 					WarningBox aWarningBox( mpWindow, WinBits( WB_OK ),
162 						 aStr );
163 					aWarningBox.Execute();
164 				}
165 			}
166 		}
167 		delete pDlg;
168 	}
169 }
170 
171 void FuLineEnd::Activate()
172 {
173 }
174 
175 void FuLineEnd::Deactivate()
176 {
177 }
178 
179 } // end of namespace sd
180