Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svtools/svmedit.hxx>
30 : : #include <tools/diagnose_ex.h>
31 : : #include <com/sun/star/document/XEventsSupplier.hpp>
32 : : #include <com/sun/star/frame/XModuleManager.hpp>
33 : :
34 : : #include <comphelper/processfactory.hxx>
35 : : #include <comphelper/documentinfo.hxx>
36 : : #include <unotools/configmgr.hxx>
37 : : #include <rtl/ustring.hxx>
38 : :
39 : : #include "eventdlg.hxx"
40 : :
41 : : #include <sfx2/viewfrm.hxx>
42 : : #include <sfx2/evntconf.hxx>
43 : : #include <sfx2/minfitem.hxx>
44 : : #include <sfx2/app.hxx>
45 : : #include <sfx2/objsh.hxx>
46 : : #include <sfx2/docfac.hxx>
47 : : #include <sfx2/fcontnr.hxx>
48 : : #include <unotools/eventcfg.hxx>
49 : :
50 : : #include "headertablistbox.hxx"
51 : : #include "macropg_impl.hxx"
52 : :
53 : : #include <dialmgr.hxx>
54 : : #include <cuires.hrc>
55 : : #include "eventdlg.hrc"
56 : : #include "helpid.hrc"
57 : : #include "selector.hxx"
58 : : #include "cfg.hxx"
59 : :
60 : :
61 : : using ::rtl::OUString;
62 : : using namespace ::com::sun::star;
63 : : // -----------------------------------------------------------------------
64 : :
65 : 0 : SvxEventConfigPage::SvxEventConfigPage( Window *pParent, const SfxItemSet& rSet, SvxEventConfigPage::EarlyInit ) :
66 : :
67 : 0 : _SvxMacroTabPage( pParent, CUI_RES(RID_SVXPAGE_EVENTS), rSet ),
68 [ # # ]: 0 : aSaveInText( this, CUI_RES( TXT_SAVEIN ) ),
69 [ # # ]: 0 : aSaveInListBox( this, CUI_RES( LB_SAVEIN ) ),
70 [ # # ][ # # ]: 0 : bAppConfig ( sal_True )
[ # # ]
71 : : {
72 [ # # ][ # # ]: 0 : mpImpl->pStrEvent = new String( CUI_RES( STR_EVENT ));
[ # # ]
73 [ # # ][ # # ]: 0 : mpImpl->pAssignedMacro = new String( CUI_RES( STR_ASSMACRO ));
[ # # ]
74 [ # # ][ # # ]: 0 : mpImpl->pEventLB = new _HeaderTabListBox( this, CUI_RES( LB_EVENT ));
[ # # ]
75 [ # # ][ # # ]: 0 : mpImpl->pAssignFT = new FixedText( this, CUI_RES( FT_ASSIGN ));
[ # # ]
76 [ # # ][ # # ]: 0 : mpImpl->pAssignPB = new PushButton( this, CUI_RES( PB_ASSIGN ));
[ # # ]
77 [ # # ][ # # ]: 0 : mpImpl->pDeletePB = new PushButton( this, CUI_RES( PB_DELETE ));
[ # # ]
78 [ # # ][ # # ]: 0 : mpImpl->pMacroImg = new Image( CUI_RES( IMG_MACRO) );
[ # # ]
79 [ # # ][ # # ]: 0 : mpImpl->pComponentImg = new Image( CUI_RES( IMG_COMPONENT) );
[ # # ]
80 : :
81 [ # # ]: 0 : FreeResource();
82 : :
83 : : // must be done after FreeResource is called
84 [ # # ]: 0 : InitResources();
85 : :
86 [ # # ]: 0 : mpImpl->pEventLB->GetListBox().SetHelpId( HID_SVX_MACRO_LB_EVENT );
87 : :
88 : : aSaveInListBox.SetSelectHdl( LINK( this, SvxEventConfigPage,
89 [ # # ]: 0 : SelectHdl_Impl ) );
90 : :
91 : 0 : uno::Reference< document::XEventsSupplier > xSupplier;
92 : :
93 : : xSupplier = uno::Reference< document::XEventsSupplier > (
94 [ # # ][ # # ]: 0 : ::comphelper::getProcessServiceFactory()->createInstance(
95 : : OUString(RTL_CONSTASCII_USTRINGPARAM(
96 : 0 : "com.sun.star.frame.GlobalEventBroadcaster" )) ),
97 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ][ # # ]
98 : :
99 : 0 : sal_uInt16 nPos(0);
100 [ # # ]: 0 : if ( xSupplier.is() )
101 : : {
102 [ # # ][ # # ]: 0 : m_xAppEvents = xSupplier->getEvents();
[ # # ]
103 : : nPos = aSaveInListBox.InsertEntry(
104 [ # # ][ # # ]: 0 : utl::ConfigManager::getProductName() );
[ # # ][ # # ]
105 [ # # ][ # # ]: 0 : aSaveInListBox.SetEntryData( nPos, new bool(true) );
106 [ # # ]: 0 : aSaveInListBox.SelectEntryPos( nPos, sal_True );
107 : 0 : }
108 : 0 : }
109 : :
110 : : // -----------------------------------------------------------------------
111 : 0 : void SvxEventConfigPage::LateInit( const uno::Reference< frame::XFrame >& _rxFrame )
112 : : {
113 : 0 : SetFrame( _rxFrame );
114 : 0 : ImplInitDocument();
115 : :
116 [ # # ]: 0 : InitAndSetHandler( m_xAppEvents, m_xDocumentEvents, m_xDocumentModifiable );
117 : :
118 : 0 : SelectHdl_Impl( NULL );
119 : 0 : }
120 : :
121 : : // -----------------------------------------------------------------------
122 : :
123 [ # # ][ # # ]: 0 : SvxEventConfigPage::~SvxEventConfigPage()
124 : : {
125 : : //DF Do I need to delete bools?
126 [ # # ]: 0 : }
127 : :
128 : : // -----------------------------------------------------------------------
129 : :
130 : 0 : void SvxEventConfigPage::ImplInitDocument()
131 : : {
132 [ # # ]: 0 : uno::Reference< frame::XFrame > xFrame( GetFrame() );
133 [ # # ]: 0 : OUString aModuleId = SvxConfigPage::GetFrameWithDefaultAndIdentify( xFrame );
134 [ # # ]: 0 : if ( !xFrame.is() )
135 : : return;
136 : :
137 : : try
138 : : {
139 : 0 : uno::Reference< frame::XModel > xModel;
140 [ # # ][ # # ]: 0 : if ( !SvxConfigPage::CanConfig( aModuleId ) )
141 : : return;
142 : :
143 : : uno::Reference< frame::XController > xController =
144 [ # # ][ # # ]: 0 : xFrame->getController();
145 : :
146 [ # # ]: 0 : if ( xController.is() )
147 : : {
148 [ # # ][ # # ]: 0 : xModel = xController->getModel();
[ # # ]
149 : : }
150 : :
151 [ # # ]: 0 : if ( !xModel.is() )
152 : : return;
153 : :
154 [ # # ]: 0 : uno::Reference< document::XEventsSupplier > xSupplier( xModel, uno::UNO_QUERY );
155 : :
156 [ # # ]: 0 : if ( xSupplier.is() )
157 : : {
158 [ # # ][ # # ]: 0 : m_xDocumentEvents = xSupplier->getEvents();
[ # # ]
159 [ # # ][ # # ]: 0 : m_xDocumentModifiable = m_xDocumentModifiable.query( xModel );
160 : :
161 [ # # ]: 0 : OUString aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
162 [ # # ][ # # ]: 0 : sal_uInt16 nPos = aSaveInListBox.InsertEntry( aTitle );
[ # # ]
163 : :
164 [ # # ][ # # ]: 0 : aSaveInListBox.SetEntryData( nPos, new bool(false) );
165 [ # # ]: 0 : aSaveInListBox.SelectEntryPos( nPos, sal_True );
166 : :
167 : 0 : bAppConfig = false;
168 [ # # ][ # # ]: 0 : }
[ # # ]
169 : : }
170 [ # # ]: 0 : catch( const uno::Exception& )
171 : : {
172 : : DBG_UNHANDLED_EXCEPTION();
173 [ # # ][ # # ]: 0 : }
174 : : }
175 : :
176 : : // -----------------------------------------------------------------------
177 : :
178 : 0 : IMPL_LINK( SvxEventConfigPage, SelectHdl_Impl, ListBox *, pBox )
179 : : {
180 : : (void)pBox;
181 : :
182 : : bool* bApp = (bool*) aSaveInListBox.GetEntryData(
183 : 0 : aSaveInListBox.GetSelectEntryPos());
184 : :
185 : 0 : mpImpl->pEventLB->SetUpdateMode( sal_False );
186 : 0 : bAppConfig = *bApp;
187 [ # # ]: 0 : if ( *bApp )
188 : : {
189 : 0 : SetReadOnly( sal_False );
190 : 0 : _SvxMacroTabPage::DisplayAppEvents( true );
191 : : }
192 : : else
193 : : {
194 : 0 : bool isReadonly = sal_False;
195 : :
196 : : uno::Reference< frame::XFramesSupplier > xFramesSupplier(
197 [ # # ][ # # ]: 0 : ::comphelper::getProcessServiceFactory()->createInstance(
198 : 0 : OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" )) ),
199 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ]
200 : :
201 : : uno::Reference< frame::XFrame > xFrame =
202 [ # # ][ # # ]: 0 : xFramesSupplier->getActiveFrame();
203 : :
204 [ # # ]: 0 : if ( xFrame.is() )
205 : : {
206 : : uno::Reference< frame::XController > xController =
207 [ # # ][ # # ]: 0 : xFrame->getController();
208 : :
209 [ # # ]: 0 : if ( xController.is() )
210 : : {
211 : : uno::Reference< frame::XStorable > xStorable(
212 [ # # ][ # # ]: 0 : xController->getModel(), uno::UNO_QUERY );
[ # # ]
213 [ # # ][ # # ]: 0 : isReadonly = xStorable->isReadonly();
214 : 0 : }
215 : : }
216 : :
217 [ # # ]: 0 : SetReadOnly( isReadonly );
218 [ # # ]: 0 : _SvxMacroTabPage::DisplayAppEvents( false );
219 : : }
220 : :
221 : 0 : mpImpl->pEventLB->SetUpdateMode( sal_True );
222 : 0 : return sal_True;
223 : : }
224 : :
225 : : // -----------------------------------------------------------------------
226 : :
227 : 0 : sal_Bool SvxEventConfigPage::FillItemSet( SfxItemSet& rSet )
228 : : {
229 : 0 : return _SvxMacroTabPage::FillItemSet( rSet );
230 : : }
231 : :
232 : : // -----------------------------------------------------------------------
233 : :
234 : 0 : void SvxEventConfigPage::Reset( const SfxItemSet& )
235 : : {
236 : 0 : _SvxMacroTabPage::Reset();
237 : 0 : }
238 : :
239 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|