Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sal/macros.h>
21 :
22 : #include <svx/fmpage.hxx>
23 : #include <com/sun/star/beans/XPropertySet.hpp>
24 : #include <com/sun/star/container/XNameContainer.hpp>
25 :
26 :
27 : #include <svx/fmmodel.hxx>
28 :
29 : #include "fmobj.hxx"
30 :
31 : #include <svx/fmresids.hrc>
32 : #include <tools/shl.hxx>
33 : #include <svx/dialmgr.hxx>
34 :
35 : #include "fmpgeimp.hxx"
36 :
37 : #include <sfx2/objsh.hxx>
38 : #include <svx/svditer.hxx>
39 : #include <svx/svdview.hxx>
40 : #include <tools/urlobj.hxx>
41 : #include <vcl/help.hxx>
42 :
43 :
44 : #include <svx/fmglob.hxx>
45 : #include "fmprop.hrc"
46 : #include "fmundo.hxx"
47 : #include "svx/fmtools.hxx"
48 : using namespace ::svxform;
49 : #include <comphelper/property.hxx>
50 : #include <rtl/logfile.hxx>
51 :
52 : using com::sun::star::uno::Reference;
53 : using com::sun::star::uno::UNO_QUERY;
54 : using com::sun::star::container::XChild;
55 : using com::sun::star::container::XNameContainer;
56 :
57 118975 : TYPEINIT1(FmFormPage, SdrPage);
58 :
59 : //------------------------------------------------------------------
60 1921 : FmFormPage::FmFormPage(FmFormModel& rModel, StarBASIC* _pBasic, bool bMasterPage)
61 : :SdrPage(rModel, bMasterPage)
62 1921 : ,m_pImpl( new FmFormPageImpl( *this ) )
63 3842 : ,m_pBasic(_pBasic)
64 : {
65 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::FmFormPage" );
66 1921 : }
67 :
68 : //------------------------------------------------------------------
69 1 : FmFormPage::FmFormPage(const FmFormPage& rPage)
70 : :SdrPage(rPage)
71 1 : ,m_pImpl(new FmFormPageImpl( *this ) )
72 2 : ,m_pBasic(0)
73 : {
74 1 : m_pImpl->initFrom( rPage.GetImpl() );
75 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::FmFormPage" );
76 1 : m_sPageName = rPage.m_sPageName;
77 1 : }
78 :
79 : //------------------------------------------------------------------
80 3768 : FmFormPage::~FmFormPage()
81 : {
82 1884 : delete m_pImpl;
83 1884 : }
84 :
85 : //------------------------------------------------------------------
86 1923 : void FmFormPage::SetModel(SdrModel* pNewModel)
87 : {
88 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::SetModel" );
89 : /* #35055# */
90 : // we want to call the super's "SetModel" method even if the model is the
91 : // same, in case code somewhere in the system depends on it. But our code
92 : // doesn't, so get the old model to do a check.
93 1923 : SdrModel *pOldModel = GetModel();
94 :
95 1923 : SdrPage::SetModel( pNewModel );
96 :
97 : /* #35055# */
98 1923 : if ( ( pOldModel != pNewModel ) && m_pImpl )
99 : {
100 : try
101 : {
102 0 : Reference< css::form::XForms > xForms( m_pImpl->getForms( false ) );
103 0 : if ( xForms.is() )
104 : {
105 : // we want to keep the current collection, just reset the model
106 : // with which it's associated.
107 0 : FmFormModel* pDrawModel = (FmFormModel*) GetModel();
108 0 : SfxObjectShell* pObjShell = pDrawModel->GetObjectShell();
109 0 : if ( pObjShell )
110 0 : xForms->setParent( pObjShell->GetModel() );
111 0 : }
112 : }
113 0 : catch( ::com::sun::star::uno::Exception const& )
114 : {
115 : OSL_FAIL( "UNO Exception caught resetting model for m_pImpl (FmFormPageImpl) in FmFormPage::SetModel" );
116 : }
117 : }
118 1923 : }
119 :
120 : //------------------------------------------------------------------
121 0 : SdrPage* FmFormPage::Clone() const
122 : {
123 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::Clone" );
124 0 : return new FmFormPage(*this);
125 : // hier fehlt noch ein kopieren der Objekte
126 : }
127 :
128 : //------------------------------------------------------------------
129 2235 : void FmFormPage::InsertObject(SdrObject* pObj, sal_uLong nPos,
130 : const SdrInsertReason* pReason)
131 : {
132 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::InsertObject" );
133 2235 : SdrPage::InsertObject( pObj, nPos, pReason );
134 2235 : if (GetModel() && (!pReason || pReason->GetReason() != SDRREASON_STREAMING))
135 2235 : ((FmFormModel*)GetModel())->GetUndoEnv().Inserted(pObj);
136 2235 : }
137 :
138 : //------------------------------------------------------------------
139 9047 : const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
140 : {
141 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::GetForms" );
142 9047 : const SdrPage& rMasterPage( *this );
143 9047 : const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
144 : OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
145 9047 : if ( !pFormPage )
146 0 : pFormPage = this;
147 :
148 9047 : return pFormPage->m_pImpl->getForms( _bForceCreate );
149 : }
150 :
151 : //------------------------------------------------------------------
152 0 : sal_Bool FmFormPage::RequestHelp( Window* pWindow, SdrView* pView,
153 : const HelpEvent& rEvt )
154 : {
155 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::RequestHelp" );
156 0 : if( pView->IsAction() )
157 0 : return sal_False;
158 :
159 0 : Point aPos = rEvt.GetMousePosPixel();
160 0 : aPos = pWindow->ScreenToOutputPixel( aPos );
161 0 : aPos = pWindow->PixelToLogic( aPos );
162 :
163 0 : SdrObject* pObj = NULL;
164 0 : SdrPageView* pPV = NULL;
165 0 : if ( !pView->PickObj( aPos, 0, pObj, pPV, SDRSEARCH_DEEP ) )
166 0 : return sal_False;
167 :
168 0 : FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
169 0 : if ( !pFormObject )
170 0 : return sal_False;
171 :
172 0 : OUString aHelpText;
173 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSet( pFormObject->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY );
174 0 : if (xSet.is())
175 : {
176 0 : if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
177 0 : aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT)).getStr();
178 :
179 0 : if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
180 : {
181 0 : OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
182 0 : INetURLObject aUrl(aText);
183 :
184 : // testen, ob es ein Protokoll-Typ ist, den ich anzeigen will
185 0 : INetProtocol aProtocol = aUrl.GetProtocol();
186 : static const INetProtocol s_aQuickHelpSupported[] =
187 : { INET_PROT_FTP, INET_PROT_HTTP, INET_PROT_FILE, INET_PROT_MAILTO, INET_PROT_NEWS,
188 : INET_PROT_HTTPS, INET_PROT_JAVASCRIPT, INET_PROT_IMAP, INET_PROT_POP3,
189 : INET_PROT_VIM, INET_PROT_LDAP
190 : };
191 0 : for (sal_uInt16 i=0; i<sizeof(s_aQuickHelpSupported)/sizeof(s_aQuickHelpSupported[0]); ++i)
192 0 : if (s_aQuickHelpSupported[i] == aProtocol)
193 : {
194 0 : aHelpText = INetURLObject::decode(aUrl.GetURLNoPass(), '%', INetURLObject::DECODE_UNAMBIGUOUS);
195 0 : break;
196 0 : }
197 : }
198 : }
199 0 : if ( !aHelpText.isEmpty() )
200 : {
201 : // Hilfe anzeigen
202 0 : Rectangle aItemRect = pObj->GetCurrentBoundRect();
203 0 : aItemRect = pWindow->LogicToPixel( aItemRect );
204 0 : Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
205 0 : aItemRect.Left() = aPt.X();
206 0 : aItemRect.Top() = aPt.Y();
207 0 : aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
208 0 : aItemRect.Right() = aPt.X();
209 0 : aItemRect.Bottom() = aPt.Y();
210 0 : if( rEvt.GetMode() == HELPMODE_BALLOON )
211 0 : Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
212 : else
213 0 : Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
214 : }
215 0 : return sal_True;
216 : }
217 :
218 : //------------------------------------------------------------------
219 1111 : SdrObject* FmFormPage::RemoveObject(sal_uLong nObjNum)
220 : {
221 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::RemoveObject" );
222 1111 : SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
223 1111 : if (pObj && GetModel())
224 1111 : ((FmFormModel*)GetModel())->GetUndoEnv().Removed(pObj);
225 1111 : return pObj;
226 258 : }
227 :
228 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|