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