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: windowcommanddispatch.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_framework.hxx"
34 //_______________________________________________
37 #include <dispatch/windowcommanddispatch.hxx>
38 #include <threadhelp/readguard.hxx>
39 #include <threadhelp/writeguard.hxx>
43 //_______________________________________________
46 #include <com/sun/star/frame/XDispatchProvider.hpp>
47 #include <com/sun/star/frame/XDispatch.hpp>
48 #include <com/sun/star/util/XURLTransformer.hpp>
50 //_______________________________________________
51 // includes of other projects
53 #include <vcl/window.hxx>
54 #include <vcl/svapp.hxx>
55 #include <vcl/cmdevt.hxx>
56 #include <vos/mutex.hxx>
57 #include <toolkit/helper/vclunohelper.hxx>
58 #include <rtl/logfile.hxx>
60 //_______________________________________________
65 namespace css
= ::com::sun::star
;
67 //_______________________________________________
70 const ::rtl::OUString
WindowCommandDispatch::COMMAND_PREFERENCES
= ::rtl::OUString::createFromAscii(".uno:OptionsTreeDialog");
71 const ::rtl::OUString
WindowCommandDispatch::COMMAND_ABOUTBOX
= ::rtl::OUString::createFromAscii(".uno:About");
73 //-----------------------------------------------
74 WindowCommandDispatch::WindowCommandDispatch(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
75 const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
79 , m_xWindow (xFrame
->getContainerWindow())
81 impl_startListening();
84 //-----------------------------------------------
85 WindowCommandDispatch::~WindowCommandDispatch()
90 //-----------------------------------------------
91 void SAL_CALL
WindowCommandDispatch::disposing(const css::lang::EventObject
& /*aSource*/)
92 throw (css::uno::RuntimeException
)
94 // We hold our window weak ... so there is no need to clear it's reference here.
95 // The window and we will die by ref count automatically.
98 //-----------------------------------------------
99 void WindowCommandDispatch::impl_startListening()
102 ReadGuard
aReadLock(m_aLock
);
103 css::uno::Reference
< css::awt::XWindow
> xWindow( m_xWindow
.get(), css::uno::UNO_QUERY
);
111 ::vos::OClearableGuard
aSolarLock(Application::GetSolarMutex());
113 Window
* pWindow
= VCLUnoHelper::GetWindow(xWindow
);
117 pWindow
->AddEventListener( LINK(this, WindowCommandDispatch
, impl_notifyCommand
) );
123 //-----------------------------------------------
124 IMPL_LINK(WindowCommandDispatch
, impl_notifyCommand
, void*, pParam
)
129 const VclWindowEvent
* pEvent
= (VclWindowEvent
*)pParam
;
130 if (pEvent
->GetId() != VCLEVENT_WINDOW_COMMAND
)
133 const CommandEvent
* pCommand
= (CommandEvent
*)pEvent
->GetData();
134 if (pCommand
->GetCommand() != COMMAND_SHOWDIALOG
)
137 const CommandDialogData
* pData
= pCommand
->GetDialogData();
141 const int nCommand
= pData
->GetDialogId();
142 ::rtl::OUString sCommand
;
146 case SHOWDIALOG_ID_PREFERENCES
:
147 sCommand
= WindowCommandDispatch::COMMAND_PREFERENCES
;
150 case SHOWDIALOG_ID_ABOUT
:
151 sCommand
= WindowCommandDispatch::COMMAND_ABOUTBOX
;
158 impl_dispatchCommand(sCommand
);
163 //-----------------------------------------------
164 void WindowCommandDispatch::impl_dispatchCommand(const ::rtl::OUString
& sCommand
)
166 // ignore all errors here. It's clicking a menu entry only ...
167 // The user will try it again, in case nothing happens .-)
171 ReadGuard
aReadLock(m_aLock
);
172 css::uno::Reference
< css::frame::XDispatchProvider
> xProvider(m_xFrame
.get(), css::uno::UNO_QUERY_THROW
);
173 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
177 // check provider ... we know it's weak reference only
178 if ( ! xProvider
.is())
181 css::uno::Reference
< css::util::XURLTransformer
> xParser(xSMGR
->createInstance(SERVICENAME_URLTRANSFORMER
), css::uno::UNO_QUERY_THROW
);
182 css::util::URL aCommand
;
183 aCommand
.Complete
= sCommand
;
184 xParser
->parseStrict(aCommand
);
186 css::uno::Reference
< css::frame::XDispatch
> xDispatch
= xProvider
->queryDispatch(aCommand
, SPECIALTARGET_SELF
, 0);
188 xDispatch
->dispatch(aCommand
, css::uno::Sequence
< css::beans::PropertyValue
>());
190 catch(const css::uno::Exception
&)
194 } // namespace framework