xref: /aoo42x/main/svx/source/form/fmpage.cxx (revision f6e50924)
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_svx.hxx"
26 
27 #define ENABLE_BYTESTRING_STREAM_OPERATORS
28 #include <svx/fmpage.hxx>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/container/XNameContainer.hpp>
31 
32 
33 #include <svx/fmmodel.hxx>
34 
35 #ifndef SVX_LIGHT
36 #ifndef _SVX_FMOBJ_HXX
37 #include "fmobj.hxx"
38 #endif
39 #endif
40 
41 #ifndef SVX_LIGHT
42 #ifndef _SVX_FMRESIDS_HRC
43 #include "svx/fmresids.hrc"
44 #endif
45 #endif
46 #include <tools/shl.hxx>
47 #include <svx/dialmgr.hxx>
48 
49 #ifndef SVX_LIGHT
50 #ifndef _SVX_FMPGEIMP_HXX
51 #include "fmpgeimp.hxx"
52 #endif
53 #endif
54 
55 #ifndef SVX_LIGHT
56 #ifndef _SFX_OBJSH_HXX //autogen
57 #include <sfx2/objsh.hxx>
58 #endif
59 #endif
60 #include "svx/svditer.hxx"
61 #include <svx/svdview.hxx>
62 #include <tools/urlobj.hxx>
63 #include <vcl/help.hxx>
64 
65 
66 #ifndef SVX_LIGHT
67 #ifndef _SVX_FMGLOB_HXX
68 #include <svx/fmglob.hxx>
69 #endif
70 #ifndef _SVX_FMPROP_HRC
71 #include "fmprop.hrc"
72 #endif
73 #include "fmundo.hxx"
74 #include "svx/fmtools.hxx"
75 using namespace ::svxform;
76 #endif
77 #include <comphelper/property.hxx>
78 #include <rtl/logfile.hxx>
79 
80 using com::sun::star::uno::Reference;
81 using com::sun::star::uno::UNO_QUERY;
82 using com::sun::star::container::XChild;
83 using com::sun::star::container::XNameContainer;
84 
85 TYPEINIT1(FmFormPage, SdrPage);
86 
87 //------------------------------------------------------------------
FmFormPage(FmFormModel & rModel,StarBASIC * _pBasic,FASTBOOL bMasterPage)88 FmFormPage::FmFormPage(FmFormModel& rModel, StarBASIC* _pBasic, FASTBOOL bMasterPage)
89 		   :SdrPage(rModel, bMasterPage)
90 #ifndef SVX_LIGHT
91 		   ,m_pImpl( new FmFormPageImpl( *this ) )
92 #else
93 		   ,m_pImpl(NULL)
94 #endif
95 		   ,m_pBasic(_pBasic)
96 {
97     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::FmFormPage" );
98 }
99 
100 //------------------------------------------------------------------
FmFormPage(const FmFormPage & rPage)101 FmFormPage::FmFormPage(const FmFormPage& rPage)
102 		   :SdrPage(rPage)
103 #ifndef SVX_LIGHT
104 		   ,m_pImpl(new FmFormPageImpl( *this ) )
105 #else
106 		   ,m_pImpl(NULL)
107 #endif
108 		   ,m_pBasic(0)
109 {
110 #ifndef SVX_LIGHT
111     m_pImpl->initFrom( rPage.GetImpl() );
112 #endif
113     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::FmFormPage" );
114 	m_sPageName = rPage.m_sPageName;
115 }
116 
117 //------------------------------------------------------------------
~FmFormPage()118 FmFormPage::~FmFormPage()
119 {
120 #ifndef SVX_LIGHT
121 	delete m_pImpl;
122 #endif
123 }
124 
125 //------------------------------------------------------------------
SetModel(SdrModel * pNewModel)126 void FmFormPage::SetModel(SdrModel* pNewModel)
127 {
128     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::SetModel" );
129     /* #35055# */
130     // we want to call the super's "SetModel" method even if the model is the
131     // same, in case code somewhere in the system depends on it.  But our code
132     // doesn't, so get the old model to do a check.
133     SdrModel *pOldModel = GetModel();
134 
135 	SdrPage::SetModel( pNewModel );
136 
137     /* #35055# */
138     if ( ( pOldModel != pNewModel ) && m_pImpl )
139     {
140         try
141         {
142             Reference< XNameContainer > xForms( m_pImpl->getForms( false ) );
143             if ( xForms.is() )
144             {
145                 // we want to keep the current collection, just reset the model
146                 // with which it's associated.
147                 Reference< XChild > xAsChild( xForms, UNO_QUERY );
148                 if ( xAsChild.is() )
149                 {
150                     FmFormModel* pDrawModel = (FmFormModel*) GetModel();
151                     SfxObjectShell* pObjShell = pDrawModel->GetObjectShell();
152                     if ( pObjShell )
153                         xAsChild->setParent( pObjShell->GetModel() );
154                 }
155             }
156         }
157         catch( ::com::sun::star::uno::Exception ex )
158         {
159             OSL_ENSURE( sal_False, "UNO Exception caught resetting model for m_pImpl (FmFormPageImpl) in FmFormPage::SetModel" );
160         }
161     }
162 }
163 
164 //------------------------------------------------------------------
Clone() const165 SdrPage* FmFormPage::Clone() const
166 {
167     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::Clone" );
168 	return new FmFormPage(*this);
169 	// hier fehlt noch ein kopieren der Objekte
170 }
171 
172 //------------------------------------------------------------------
InsertObject(SdrObject * pObj,sal_uLong nPos,const SdrInsertReason * pReason)173 void FmFormPage::InsertObject(SdrObject* pObj, sal_uLong nPos,
174 							  const SdrInsertReason* pReason)
175 {
176     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::InsertObject" );
177 	SdrPage::InsertObject( pObj, nPos, pReason );
178 #ifndef SVX_LIGHT
179 	if (GetModel() && (!pReason || pReason->GetReason() != SDRREASON_STREAMING))
180 		((FmFormModel*)GetModel())->GetUndoEnv().Inserted(pObj);
181 #endif
182 }
183 
184 //------------------------------------------------------------------
GetForms(bool _bForceCreate) const185 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > & FmFormPage::GetForms( bool _bForceCreate ) const
186 {
187     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::GetForms" );
188 #ifndef SVX_LIGHT
189     const SdrPage& rMasterPage( *this );
190     const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
191     OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
192     if ( !pFormPage )
193         pFormPage = this;
194 
195     return pFormPage->m_pImpl->getForms( _bForceCreate );
196 #else
197 	static ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >  aRef;
198 	return aRef;
199 #endif
200 }
201 
202 //------------------------------------------------------------------
RequestHelp(Window * pWindow,SdrView * pView,const HelpEvent & rEvt)203 sal_Bool FmFormPage::RequestHelp( Window* pWindow, SdrView* pView,
204 							  const HelpEvent& rEvt )
205 {
206     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::RequestHelp" );
207 #ifndef SVX_LIGHT
208 	if( pView->IsAction() )
209         return sal_False;
210 
211     Point aPos = rEvt.GetMousePosPixel();
212 	aPos = pWindow->ScreenToOutputPixel( aPos );
213 	aPos = pWindow->PixelToLogic( aPos );
214 
215 	SdrObject* pObj = NULL;
216 	SdrPageView* pPV = NULL;
217 	if ( !pView->PickObj( aPos, 0, pObj, pPV, SDRSEARCH_DEEP ) )
218         return sal_False;
219 
220     FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
221     if ( !pFormObject )
222         return sal_False;
223 
224 	UniString aHelpText;
225 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  xSet( pFormObject->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY );
226 	if (xSet.is())
227 	{
228 		if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
229 			aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT)).getStr();
230 
231 		if (!aHelpText.Len() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
232 		{
233 			::rtl::OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
234 			INetURLObject aUrl(aText);
235 
236 			// testen, ob es ein Protokoll-Typ ist, den ich anzeigen will
237 			INetProtocol aProtocol = aUrl.GetProtocol();
238 			static const INetProtocol s_aQuickHelpSupported[] =
239 				{	INET_PROT_FTP, INET_PROT_HTTP, INET_PROT_FILE, INET_PROT_MAILTO, INET_PROT_NEWS,
240 					INET_PROT_HTTPS, INET_PROT_JAVASCRIPT, INET_PROT_IMAP, INET_PROT_POP3,
241 					INET_PROT_VIM, INET_PROT_LDAP
242 				};
243 			for (sal_uInt16 i=0; i<sizeof(s_aQuickHelpSupported)/sizeof(s_aQuickHelpSupported[0]); ++i)
244 				if (s_aQuickHelpSupported[i] == aProtocol)
245 				{
246 					aHelpText = INetURLObject::decode(aUrl.GetURLNoPass(), '%', INetURLObject::DECODE_UNAMBIGUOUS);
247 					break;
248 				}
249 		}
250 	}
251 	if ( aHelpText.Len() != 0 )
252 	{
253 		// Hilfe anzeigen
254 		Rectangle aItemRect = pObj->GetCurrentBoundRect();
255 		aItemRect = pWindow->LogicToPixel( aItemRect );
256 		Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
257 		aItemRect.Left()   = aPt.X();
258 		aItemRect.Top()    = aPt.Y();
259 		aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
260 		aItemRect.Right()  = aPt.X();
261 		aItemRect.Bottom() = aPt.Y();
262 		if( rEvt.GetMode() == HELPMODE_BALLOON )
263 			Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
264 		else
265 			Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
266 	}
267 #endif
268 	return sal_True;
269 }
270 
271 //------------------------------------------------------------------
RemoveObject(sal_uLong nObjNum)272 SdrObject* FmFormPage::RemoveObject(sal_uLong nObjNum)
273 {
274     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::RemoveObject" );
275 	SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
276 #ifndef SVX_LIGHT
277 	if (pObj && GetModel())
278 		((FmFormModel*)GetModel())->GetUndoEnv().Removed(pObj);
279 #endif
280 	return pObj;
281 }
282