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 <svx/dialmgr.hxx>
33 :
34 : #include "fmpgeimp.hxx"
35 :
36 : #include <sfx2/objsh.hxx>
37 : #include <svx/svditer.hxx>
38 : #include <svx/svdview.hxx>
39 : #include <tools/urlobj.hxx>
40 : #include <vcl/help.hxx>
41 :
42 :
43 : #include <svx/fmglob.hxx>
44 : #include "fmprop.hrc"
45 : #include "fmundo.hxx"
46 : #include "svx/fmtools.hxx"
47 : using namespace ::svxform;
48 : #include <comphelper/property.hxx>
49 :
50 : using com::sun::star::uno::Reference;
51 : using com::sun::star::uno::UNO_QUERY;
52 : using com::sun::star::container::XChild;
53 : using com::sun::star::container::XNameContainer;
54 :
55 391229 : TYPEINIT1(FmFormPage, SdrPage);
56 :
57 :
58 9564 : FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
59 : :SdrPage(rModel, bMasterPage)
60 9564 : ,m_pImpl( new FmFormPageImpl( *this ) )
61 : {
62 9564 : }
63 :
64 :
65 2 : FmFormPage::FmFormPage(const FmFormPage& rPage)
66 : :SdrPage(rPage)
67 2 : ,m_pImpl(new FmFormPageImpl( *this ) )
68 : {
69 2 : m_pImpl->initFrom( rPage.GetImpl() );
70 2 : m_sPageName = rPage.m_sPageName;
71 2 : }
72 :
73 :
74 19114 : FmFormPage::~FmFormPage()
75 : {
76 9557 : delete m_pImpl;
77 9557 : }
78 :
79 :
80 9568 : void FmFormPage::SetModel(SdrModel* pNewModel)
81 : {
82 : /* #35055# */
83 : // we want to call the super's "SetModel" method even if the model is the
84 : // same, in case code somewhere in the system depends on it. But our code
85 : // doesn't, so get the old model to do a check.
86 9568 : SdrModel *pOldModel = GetModel();
87 :
88 9568 : SdrPage::SetModel( pNewModel );
89 :
90 : /* #35055# */
91 9568 : if ( ( pOldModel != pNewModel ) && m_pImpl )
92 : {
93 : try
94 : {
95 0 : Reference< css::form::XForms > xForms( m_pImpl->getForms( false ) );
96 0 : if ( xForms.is() )
97 : {
98 : // we want to keep the current collection, just reset the model
99 : // with which it's associated.
100 0 : FmFormModel* pDrawModel = static_cast<FmFormModel*>( GetModel() );
101 0 : SfxObjectShell* pObjShell = pDrawModel->GetObjectShell();
102 0 : if ( pObjShell )
103 0 : xForms->setParent( pObjShell->GetModel() );
104 0 : }
105 : }
106 0 : catch( ::com::sun::star::uno::Exception const& )
107 : {
108 : OSL_FAIL( "UNO Exception caught resetting model for m_pImpl (FmFormPageImpl) in FmFormPage::SetModel" );
109 : }
110 : }
111 9568 : }
112 :
113 :
114 0 : SdrPage* FmFormPage::Clone() const
115 : {
116 0 : return new FmFormPage(*this);
117 : // hier fehlt noch ein kopieren der Objekte
118 : }
119 :
120 :
121 21450 : void FmFormPage::InsertObject(SdrObject* pObj, size_t nPos,
122 : const SdrInsertReason* pReason)
123 : {
124 21450 : SdrPage::InsertObject( pObj, nPos, pReason );
125 21450 : if (GetModel() && (!pReason || pReason->GetReason() != SDRREASON_STREAMING))
126 21450 : static_cast<FmFormModel*>(GetModel())->GetUndoEnv().Inserted(pObj);
127 21450 : }
128 :
129 :
130 39225 : const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
131 : {
132 39225 : const SdrPage& rMasterPage( *this );
133 39225 : const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
134 : OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
135 39225 : if ( !pFormPage )
136 0 : pFormPage = this;
137 :
138 39225 : return pFormPage->m_pImpl->getForms( _bForceCreate );
139 : }
140 :
141 :
142 0 : bool FmFormPage::RequestHelp( vcl::Window* pWindow, SdrView* pView,
143 : const HelpEvent& rEvt )
144 : {
145 0 : if( pView->IsAction() )
146 0 : return false;
147 :
148 0 : Point aPos = rEvt.GetMousePosPixel();
149 0 : aPos = pWindow->ScreenToOutputPixel( aPos );
150 0 : aPos = pWindow->PixelToLogic( aPos );
151 :
152 0 : SdrObject* pObj = NULL;
153 0 : SdrPageView* pPV = NULL;
154 0 : if ( !pView->PickObj( aPos, 0, pObj, pPV, SDRSEARCH_DEEP ) )
155 0 : return false;
156 :
157 0 : FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
158 0 : if ( !pFormObject )
159 0 : return false;
160 :
161 0 : OUString aHelpText;
162 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSet( pFormObject->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY );
163 0 : if (xSet.is())
164 : {
165 0 : if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
166 0 : aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT)).getStr();
167 :
168 0 : if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
169 : {
170 0 : OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
171 0 : INetURLObject aUrl(aText);
172 :
173 : // testen, ob es ein Protokoll-Typ ist, den ich anzeigen will
174 0 : INetProtocol aProtocol = aUrl.GetProtocol();
175 : static const INetProtocol s_aQuickHelpSupported[] =
176 : { INET_PROT_FTP, INET_PROT_HTTP, INET_PROT_FILE, INET_PROT_MAILTO, INET_PROT_NEWS,
177 : INET_PROT_HTTPS, INET_PROT_JAVASCRIPT, INET_PROT_IMAP, INET_PROT_POP3,
178 : INET_PROT_VIM, INET_PROT_LDAP
179 : };
180 0 : for (sal_uInt16 i=0; i<sizeof(s_aQuickHelpSupported)/sizeof(s_aQuickHelpSupported[0]); ++i)
181 0 : if (s_aQuickHelpSupported[i] == aProtocol)
182 : {
183 0 : aHelpText = INetURLObject::decode(aUrl.GetURLNoPass(), '%', INetURLObject::DECODE_UNAMBIGUOUS);
184 0 : break;
185 0 : }
186 : }
187 : }
188 0 : if ( !aHelpText.isEmpty() )
189 : {
190 : // Hilfe anzeigen
191 0 : Rectangle aItemRect = pObj->GetCurrentBoundRect();
192 0 : aItemRect = pWindow->LogicToPixel( aItemRect );
193 0 : Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
194 0 : aItemRect.Left() = aPt.X();
195 0 : aItemRect.Top() = aPt.Y();
196 0 : aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
197 0 : aItemRect.Right() = aPt.X();
198 0 : aItemRect.Bottom() = aPt.Y();
199 0 : if( rEvt.GetMode() == HELPMODE_BALLOON )
200 0 : Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
201 : else
202 0 : Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
203 : }
204 0 : return true;
205 : }
206 :
207 :
208 12860 : SdrObject* FmFormPage::RemoveObject(size_t nObjNum)
209 : {
210 12860 : SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
211 12860 : if (pObj && GetModel())
212 12860 : static_cast<FmFormModel*>(GetModel())->GetUndoEnv().Removed(pObj);
213 12860 : return pObj;
214 651 : }
215 :
216 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|