1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: eventdlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ***************************************************************
35 #include <svtools/svmedit.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <com/sun/star/document/XEventsSupplier.hpp>
38 #include <com/sun/star/frame/XModuleManager.hpp>
40 #include <comphelper/processfactory.hxx>
41 #include <comphelper/documentinfo.hxx>
42 #include <unotools/configmgr.hxx>
43 #include <rtl/ustring.hxx>
45 #include "eventdlg.hxx"
47 #include <sfx2/viewfrm.hxx>
48 #include <sfx2/evntconf.hxx>
49 #include <sfx2/macrconf.hxx>
50 #include <sfx2/minfitem.hxx>
51 #include <sfx2/app.hxx>
52 #include <sfx2/objsh.hxx>
53 #include <sfx2/docfac.hxx>
54 #include <sfx2/fcontnr.hxx>
55 #include <svtools/eventcfg.hxx>
57 #include "headertablistbox.hxx"
58 #include "macropg_impl.hxx"
60 #include <svx/dialmgr.hxx>
61 #include <svx/dialogs.hrc>
62 #include "eventdlg.hrc"
64 #include "selector.hxx"
68 using ::rtl::OUString
;
69 using namespace ::com::sun::star
;
70 // -----------------------------------------------------------------------
72 SvxEventConfigPage::SvxEventConfigPage( Window
*pParent
, const SfxItemSet
& rSet
, SvxEventConfigPage::EarlyInit
) :
74 _SvxMacroTabPage( pParent
, SVX_RES(RID_SVXPAGE_EVENTS
), rSet
),
75 aSaveInText( this, SVX_RES( TXT_SAVEIN
) ),
76 aSaveInListBox( this, SVX_RES( LB_SAVEIN
) ),
79 mpImpl
->pStrEvent
= new String( SVX_RES( STR_EVENT
));
80 mpImpl
->pAssignedMacro
= new String( SVX_RES( STR_ASSMACRO
));
81 mpImpl
->pEventLB
= new _HeaderTabListBox( this, SVX_RES( LB_EVENT
));
82 mpImpl
->pAssignFT
= new FixedText( this, SVX_RES( FT_ASSIGN
));
83 mpImpl
->pAssignPB
= new PushButton( this, SVX_RES( PB_ASSIGN
));
84 mpImpl
->pDeletePB
= new PushButton( this, SVX_RES( PB_DELETE
));
85 mpImpl
->pMacroImg
= new Image( SVX_RES( IMG_MACRO
) );
86 mpImpl
->pComponentImg
= new Image( SVX_RES( IMG_COMPONENT
) );
87 mpImpl
->pMacroImg_h
= new Image( SVX_RES( IMG_MACRO_H
) );
88 mpImpl
->pComponentImg_h
= new Image( SVX_RES( IMG_COMPONENT_H
) );
92 // must be done after FreeResource is called
95 mpImpl
->pEventLB
->GetListBox().SetHelpId( HID_SVX_MACRO_LB_EVENT
);
97 aSaveInListBox
.SetSelectHdl( LINK( this, SvxEventConfigPage
,
100 uno::Reference
< document::XEventsSupplier
> xSupplier
;
102 // xSupplier = uno::Reference< document::XEventsSupplier >( new GlobalEventConfig());
103 xSupplier
= uno::Reference
< document::XEventsSupplier
> (
104 ::comphelper::getProcessServiceFactory()->createInstance(
105 OUString::createFromAscii(
106 "com.sun.star.frame.GlobalEventBroadcaster" ) ),
110 if ( xSupplier
.is() )
112 m_xAppEvents
= xSupplier
->getEvents();
114 utl::ConfigManager::GetDirectConfigProperty(
115 utl::ConfigManager::PRODUCTNAME
) >>= label
;
116 nPos
= aSaveInListBox
.InsertEntry( label
);
117 aSaveInListBox
.SetEntryData( nPos
, new bool(true) );
118 aSaveInListBox
.SelectEntryPos( nPos
, TRUE
);
122 // -----------------------------------------------------------------------
123 void SvxEventConfigPage::LateInit( const uno::Reference
< frame::XFrame
>& _rxFrame
)
125 SetFrame( _rxFrame
);
128 InitAndSetHandler( m_xAppEvents
, m_xDocumentEvents
, m_xDocumentModifiable
);
130 SelectHdl_Impl( NULL
);
133 // -----------------------------------------------------------------------
135 SvxEventConfigPage::~SvxEventConfigPage()
137 //DF Do I need to delete bools?
140 // -----------------------------------------------------------------------
142 void SvxEventConfigPage::ImplInitDocument()
144 uno::Reference
< frame::XFrame
> xFrame( GetFrame() );
145 OUString aModuleId
= SvxConfigPage::GetFrameWithDefaultAndIdentify( xFrame
);
151 uno::Reference
< frame::XModel
> xModel
;
152 if ( !SvxConfigPage::CanConfig( aModuleId
) )
155 uno::Reference
< frame::XController
> xController
=
156 xFrame
->getController();
158 if ( xController
.is() )
160 xModel
= xController
->getModel();
166 uno::Reference
< document::XEventsSupplier
> xSupplier( xModel
, uno::UNO_QUERY
);
168 if ( xSupplier
.is() )
170 m_xDocumentEvents
= xSupplier
->getEvents();
171 m_xDocumentModifiable
= m_xDocumentModifiable
.query( xModel
);
173 OUString aTitle
= ::comphelper::DocumentInfo::getDocumentTitle( xModel
);
174 USHORT nPos
= aSaveInListBox
.InsertEntry( aTitle
);
176 aSaveInListBox
.SetEntryData( nPos
, new bool(false) );
177 aSaveInListBox
.SelectEntryPos( nPos
, TRUE
);
182 catch( const uno::Exception
& )
184 DBG_UNHANDLED_EXCEPTION();
188 // -----------------------------------------------------------------------
190 IMPL_LINK( SvxEventConfigPage
, SelectHdl_Impl
, ListBox
*, pBox
)
194 bool* bApp
= (bool*) aSaveInListBox
.GetEntryData(
195 aSaveInListBox
.GetSelectEntryPos());
197 mpImpl
->pEventLB
->SetUpdateMode( FALSE
);
201 SetReadOnly( FALSE
);
202 _SvxMacroTabPage::DisplayAppEvents( true );
206 bool isReadonly
= FALSE
;
208 uno::Reference
< frame::XFramesSupplier
> xFramesSupplier(
209 ::comphelper::getProcessServiceFactory()->createInstance(
210 OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ),
213 uno::Reference
< frame::XFrame
> xFrame
=
214 xFramesSupplier
->getActiveFrame();
218 uno::Reference
< frame::XController
> xController
=
219 xFrame
->getController();
221 if ( xController
.is() )
223 uno::Reference
< frame::XStorable
> xStorable(
224 xController
->getModel(), uno::UNO_QUERY
);
225 isReadonly
= xStorable
->isReadonly();
229 SetReadOnly( isReadonly
);
230 _SvxMacroTabPage::DisplayAppEvents( false );
233 mpImpl
->pEventLB
->SetUpdateMode( TRUE
);
237 // -----------------------------------------------------------------------
239 BOOL
SvxEventConfigPage::FillItemSet( SfxItemSet
& rSet
)
241 return _SvxMacroTabPage::FillItemSet( rSet
);
244 // -----------------------------------------------------------------------
246 void SvxEventConfigPage::Reset( const SfxItemSet
& )
248 _SvxMacroTabPage::Reset();