xref: /trunk/main/sd/source/ui/func/fulinend.cxx (revision c7be74b1)
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 
FuLineEnd(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)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 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)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 
DoExecute(SfxRequest &)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 		String aNewName( SdResId( STR_LINEEND ) );
112 		String aDesc( SdResId( STR_DESC_LINEEND ) );
113 		String aName;
114 
115 		XLineEndListSharedPtr aLineEndList = mpDoc->GetLineEndListFromSdrModel();
116 		long nCount = aLineEndList.get() ? aLineEndList->Count() : 0;
117 		long j = 1;
118 		sal_Bool bDifferent = sal_False;
119 
120 		while( !bDifferent )
121 		{
122 			aName = aNewName;
123 			aName.Append( sal_Unicode(' ') );
124 			aName.Append( UniString::CreateFromInt32( j++ ) );
125 			bDifferent = sal_True;
126 			for( long i = 0; i < nCount && bDifferent; i++ )
127 			{
128 				if( aName == aLineEndList->GetLineEnd( i )->GetName() )
129 					bDifferent = sal_False;
130 			}
131 		}
132 
133 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
134 		AbstractSvxNameDialog* pDlg = pFact ? pFact->CreateSvxNameDialog( NULL, aName, aDesc ) : 0;
135 
136 		if( pDlg )
137 		{
138 			pDlg->SetEditHelpId( HID_SD_NAMEDIALOG_LINEEND );
139 
140 			if( pDlg->Execute() == RET_OK )
141 			{
142 				pDlg->GetName( aName );
143 				bDifferent = sal_True;
144 
145 				for( long i = 0; i < nCount && bDifferent; i++ )
146 				{
147 					if( aName == aLineEndList->GetLineEnd( i )->GetName() )
148 						bDifferent = sal_False;
149 				}
150 
151 				if( bDifferent )
152 				{
153 					XLineEndEntry* pEntry = new XLineEndEntry( aPolyPolygon, aName );
154 					aLineEndList->Insert( pEntry, LIST_APPEND);
155 				}
156 				else
157 				{
158 					String aStr(SdResId( STR_WARN_NAME_DUPLICATE ));
159 					WarningBox aWarningBox( mpWindow, WinBits( WB_OK ),
160 						 aStr );
161 					aWarningBox.Execute();
162 				}
163 			}
164 		}
165 		delete pDlg;
166 	}
167 }
168 
Activate()169 void FuLineEnd::Activate()
170 {
171 }
172 
Deactivate()173 void FuLineEnd::Deactivate()
174 {
175 }
176 
177 } // end of namespace sd
178