openoffice-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arie...@apache.org
Subject svn commit: r1417873 [1/2] - in /openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController: ./ description/ images/ registry/ registry/data/ registry/data/org/ registry/data/org/openoffice/ registry/data/org/openoffice/Off...
Date Thu, 06 Dec 2012 13:33:47 GMT
Author: arielch
Date: Thu Dec  6 13:33:40 2012
New Revision: 1417873

URL: http://svn.apache.org/viewvc?rev=1417873&view=rev
Log:
#i121442# - Add a StatusbarController example displaying the Word Count in Writer

Added:
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/BaseDispatch.cxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/BaseDispatch.hxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/DispatchPool.cxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/DispatchPool.hxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/LICENSE   (with props)
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/Makefile   (with props)
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/ProtocolHandler.cxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/ProtocolHandler.hxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/StatusbarController.cxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/StatusbarController.hxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/WordCountDispatch.cxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/WordCountDispatch.hxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/WordCountStatusbarController.cxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/WordCountStatusbarController.hxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/compfactory.cxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/defines.hxx
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/description/
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/description/description_en-US.txt   (with props)
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/images/
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/images/icon.png   (with props)
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/images/icon_hc.png   (with props)
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/macros.hxx   (with props)
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/project.mk
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/registry/
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/registry/data/
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/registry/data/org/
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/registry/data/org/openoffice/
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/registry/data/org/openoffice/Office/
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/registry/data/org/openoffice/Office/Addons.xcu
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/registry/data/org/openoffice/Office/ProtocolHandler.xcu   (with props)
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/registry/data/org/openoffice/Office/UI/
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/registry/data/org/openoffice/Office/UI/Controller.xcu
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/xml/
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/xml/components.xml   (with props)
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/xml/description.xml   (with props)
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/xml/manifest.xml   (with props)
    openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/xml/update.xml   (with props)

Added: openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/BaseDispatch.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/BaseDispatch.cxx?rev=1417873&view=auto
==============================================================================
--- openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/BaseDispatch.cxx (added)
+++ openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/BaseDispatch.cxx Thu Dec  6 13:33:40 2012
@@ -0,0 +1,237 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#include "BaseDispatch.hxx"
+#include "defines.hxx"
+
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+#include <map>
+#include <algorithm>
+
+using namespace com::sun::star;
+using namespace framework::statusbar_controller_wordcount;
+
+using com::sun::star::beans::PropertyValue;
+using com::sun::star::frame::FeatureStateEvent;
+using com::sun::star::frame::XController;
+using com::sun::star::frame::XDispatch;
+using com::sun::star::frame::XFrame;
+using com::sun::star::frame::XStatusListener;
+using com::sun::star::lang::DisposedException;
+using com::sun::star::uno::Reference;
+using com::sun::star::uno::RuntimeException;
+using com::sun::star::uno::Sequence;
+using com::sun::star::uno::UNO_QUERY;
+using com::sun::star::uno::UNO_QUERY_THROW;
+using com::sun::star::uno::XComponentContext;
+using com::sun::star::uno::XInterface;
+using com::sun::star::util::URL;
+
+using rtl::OUString;
+
+namespace
+{
+    template< class Map >
+    struct lcl_DisposeAndClearAndDeleteMapElement :
+        public ::std::unary_function< typename Map::value_type, void >
+    {
+
+            lcl_DisposeAndClearAndDeleteMapElement( const Reference< uno::XInterface > &xEventSource ) :
+                m_aEvent( xEventSource ) { }
+
+            void operator( ) ( typename Map::value_type &rElement )
+            {
+                if ( rElement.second )
+                {
+                    rElement.second->disposeAndClear( m_aEvent );
+                    delete rElement.second;
+                }
+            }
+        private:
+            lang::EventObject m_aEvent;
+    };
+
+    template< class Map >
+    void
+    lcl_DisposeAndClearAndDeleteAllMapElements(
+        Map &rMap,
+        const Reference< uno::XInterface > &xEventSource )
+    {
+        ::std::for_each( rMap.begin( ), rMap.end( ),
+                         lcl_DisposeAndClearAndDeleteMapElement< Map > ( xEventSource ) );
+    }
+}
+
+BaseDispatch::BaseDispatch(
+    const Reference< XComponentContext > &xContext,
+    const Reference<XFrame> &xFrame,
+    const OUString &rModuleIdentifier )
+    : BaseDispatch_Base( m_aMutex )
+    , m_xContext( xContext )
+    , m_xFrame( xFrame )
+    , m_sModuleIdentifier( rModuleIdentifier )
+{
+    OSL_TRACE( "sbctlwc::BaseDispatch::BaseDispatch" );
+}
+
+BaseDispatch::~BaseDispatch()
+{
+    OSL_TRACE( "sbctlwc::BaseDispatch::~BaseDispatch" );
+}
+
+void SAL_CALL
+BaseDispatch::addStatusListener(
+    const Reference< XStatusListener > &xControl,
+    const URL &aURL )
+throw ( RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::BaseDispatch::addStatusListener" );
+    osl::MutexGuard aGuad( m_aMutex );
+
+    tListenerMap::iterator aIt( m_aListeners.find( aURL.Complete ) );
+    if ( aIt == m_aListeners.end( ) )
+    {
+        aIt = m_aListeners.insert(
+                  m_aListeners.begin( ),
+                  tListenerMap::value_type( aURL.Complete, new ::cppu::OInterfaceContainerHelper( m_aMutex ) ) );
+    }
+
+    OSL_ASSERT( aIt != m_aListeners.end( ) );
+
+    aIt->second->addInterface( xControl );
+    FireStatusEvent( aURL, xControl );
+}
+
+void SAL_CALL
+BaseDispatch::removeStatusListener(
+    const Reference< XStatusListener > &xControl,
+    const URL &aURL )
+throw ( RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::BaseDispatch::removeStatusListener" );
+    osl::MutexGuard aGuad( m_aMutex );
+
+    tListenerMap::iterator aIt( m_aListeners.find( aURL.Complete ) );
+    if ( aIt != m_aListeners.end( ) )
+        ( *aIt ).second->removeInterface( xControl );
+}
+
+void SAL_CALL
+BaseDispatch::disposing( )
+{
+    OSL_TRACE( "sbctlwc::BaseDispatch::disposing" );
+    osl::MutexGuard aGuard( m_aMutex );
+
+    lcl_DisposeAndClearAndDeleteAllMapElements( m_aListeners, static_cast < cppu::OWeakObject * > ( this ) );
+    m_aListeners.clear( );
+}
+
+void
+BaseDispatch::ThrowIfDisposed( ) throw ( RuntimeException )
+{
+    if ( rBHelper.bInDispose || rBHelper.bInDispose )
+        throw DisposedException( );
+}
+
+
+void
+BaseDispatch::FireStatusEvent()
+{
+    URL aURL;
+    if ( m_xURLTransformer.is() )
+    {
+        aURL.Complete = GetCommand();
+        m_xURLTransformer->parseStrict( aURL );
+    }
+
+    FireStatusEvent( aURL );
+}
+
+void
+BaseDispatch::FireStatusEvent( const URL &rURL, const Reference< XStatusListener > &xControl )
+{
+    FeatureStateEvent aEvent = GetState( rURL );
+    if ( xControl.is() )
+        xControl->statusChanged( aEvent );
+    else
+    {
+        tListenerMap::iterator aIt( m_aListeners.find( rURL.Complete ) );
+        if ( aIt != m_aListeners.end() )
+        {
+            if ( aIt->second )
+            {
+                ::cppu::OInterfaceIteratorHelper aIntfIt( *( ( *aIt ).second ) );
+
+                while ( aIntfIt.hasMoreElements() )
+                {
+                    Reference< XStatusListener > xListener( aIntfIt.next(), UNO_QUERY );
+                    try
+                    {
+                        if ( xListener.is() )
+                            xListener->statusChanged( aEvent );
+                    }
+                    catch ( ... )
+                    {
+                    }
+                }
+            }
+        }
+    }
+}
+
+void SAL_CALL BaseDispatch::dispatch(
+    const URL &aURL, const Sequence< PropertyValue > &lArguments )
+throw ( RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::BaseDispatch::dispatch" );
+    osl::MutexGuard aGuard( m_aMutex );
+    ThrowIfDisposed();
+
+    ExecuteCommand( aURL, lArguments );
+}
+
+
+void SAL_CALL BaseDispatch::modified(
+    const ::com::sun::star::lang::EventObject &aEvent )
+throw ( RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::BaseDispatch::modified" );
+    FireStatusEvent();
+}
+
+
+void SAL_CALL BaseDispatch::selectionChanged(
+    const ::com::sun::star::lang::EventObject &aEvent )
+throw ( ::com::sun::star::uno::RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::BaseDispatch::selectionChanged" );
+    FireStatusEvent();
+}
+
+
+void SAL_CALL BaseDispatch::disposing(
+    const ::com::sun::star::lang::EventObject &aEvent )
+throw ( ::com::sun::star::uno::RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::BaseDispatch::disposing(aEvent)" );
+}

Added: openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/BaseDispatch.hxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/BaseDispatch.hxx?rev=1417873&view=auto
==============================================================================
--- openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/BaseDispatch.hxx (added)
+++ openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/BaseDispatch.hxx Thu Dec  6 13:33:40 2012
@@ -0,0 +1,95 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#ifndef BASE_DISPATCH_HXX
+#define BASE_DISPATCH_HXX
+
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/util/XModifyListener.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/view/XSelectionChangeListener.hpp>
+
+#include <cppuhelper/basemutex.hxx>
+#include <cppuhelper/compbase3.hxx>
+#include <cppuhelper/interfacecontainer.h>
+
+#include <map>
+
+namespace framework
+{
+    namespace statusbar_controller_wordcount
+    {
+        typedef cppu::WeakComponentImplHelper3 <
+            com::sun::star::frame::XDispatch,
+            com::sun::star::util::XModifyListener,
+            com::sun::star::view::XSelectionChangeListener > BaseDispatch_Base;
+
+        class BaseDispatch :
+            protected ::cppu::BaseMutex,
+            public BaseDispatch_Base
+        {
+            public:
+                virtual void SAL_CALL disposing();
+
+                // ::com::sun::star::frame::XDispatch:
+                virtual void SAL_CALL dispatch( const com::sun::star::util::URL &aURL, const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > &lArguments ) throw ( com::sun::star::uno::RuntimeException );
+                virtual void SAL_CALL addStatusListener( const com::sun::star::uno::Reference< com::sun::star::frame::XStatusListener > &xControl, const com::sun::star::util::URL &aURL ) throw ( com::sun::star::uno::RuntimeException );
+                virtual void SAL_CALL removeStatusListener( const com::sun::star::uno::Reference< com::sun::star::frame::XStatusListener > &xControl, const com::sun::star::util::URL &aURL ) throw ( com::sun::star::uno::RuntimeException );
+
+                // com::sun::star::util::XModifyListener Methods
+                virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject &aEvent ) throw ( ::com::sun::star::uno::RuntimeException );
+
+                // com::sun::star::view::XSelectionChangeListener Methods
+                virtual void SAL_CALL selectionChanged( const ::com::sun::star::lang::EventObject &aEvent ) throw ( ::com::sun::star::uno::RuntimeException );
+
+                // com::sun::star::lang::XEventListener Methods
+                virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject &aEvent ) throw ( ::com::sun::star::uno::RuntimeException );
+
+            protected:
+                BaseDispatch( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > &rxContext,
+                              const com::sun::star::uno::Reference< com::sun::star::frame::XFrame > &rxFrame,
+                              const rtl::OUString &rModuleIdentifier );
+                virtual ~BaseDispatch();
+
+                virtual com::sun::star::frame::FeatureStateEvent GetState( const com::sun::star::util::URL &rURL ) = 0;
+                virtual rtl::OUString GetCommand() = 0;
+                virtual void ExecuteCommand( const com::sun::star::util::URL &aURL, const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > &lArguments ) = 0;
+
+                void ThrowIfDisposed() throw ( com::sun::star::uno::RuntimeException );
+                void FireStatusEvent( const com::sun::star::util::URL &aURL, const com::sun::star::uno::Reference< com::sun::star::frame::XStatusListener > &xControl = com::sun::star::uno::Reference< com::sun::star::frame::XStatusListener >() );
+                void FireStatusEvent();
+
+                com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
+                com::sun::star::uno::Reference< com::sun::star::frame::XFrame > m_xFrame;
+                com::sun::star::uno::Reference< com::sun::star::frame::XModel > m_xModel;
+                com::sun::star::uno::Reference< com::sun::star::util::XURLTransformer > m_xURLTransformer;
+                rtl::OUString m_sModuleIdentifier;
+
+            private:
+                typedef ::std::map< ::rtl::OUString, ::cppu::OInterfaceContainerHelper * > tListenerMap;
+                tListenerMap m_aListeners;
+        };
+    }
+}
+
+#endif

Added: openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/DispatchPool.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/DispatchPool.cxx?rev=1417873&view=auto
==============================================================================
--- openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/DispatchPool.cxx (added)
+++ openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/DispatchPool.cxx Thu Dec  6 13:33:40 2012
@@ -0,0 +1,290 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#include "DispatchPool.hxx"
+#include "WordCountDispatch.hxx"
+#include "defines.hxx"
+
+#include <com/sun/star/util/XCloseable.hpp>
+
+#include <rtl/instance.hxx>
+#include <rtl/ref.hxx>
+
+#include <map>
+#include <set>
+#include <algorithm>
+
+using namespace framework::statusbar_controller_wordcount;
+
+using namespace com::sun::star::lang;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::frame;
+using namespace com::sun::star::util;
+
+using rtl::OUString;
+
+namespace
+{
+    struct CommandDispatchInfo
+    {
+        Reference< XComponent > Component;
+        Reference< XDispatch > Dispatch;
+
+        explicit CommandDispatchInfo(
+            const Reference< XComponent > &xComponent,
+            const Reference< XDispatch > &xDispatch )
+            : Component( xComponent )
+            , Dispatch( xDispatch ) {}
+    };
+
+    typedef std::map< OUString, CommandDispatchInfo > CommandDispatchMap;
+    typedef std::map< Reference< XFrame >, CommandDispatchMap > FrameDispatchMap;
+
+    struct StaticFrameDispatchMap
+            : public rtl::Static< FrameDispatchMap, StaticFrameDispatchMap > {};
+
+    struct TheDispatchPool
+            : public rtl::StaticWithInit< rtl::Reference< DispatchPool >, TheDispatchPool >
+    {
+        rtl::Reference< DispatchPool >
+        operator()()
+        {
+            OSL_TRACE( "sbctlwc: Initializing static DispatchPool" );
+            return rtl::Reference< DispatchPool >( DispatchPool::Create() );
+        }
+    };
+
+    typedef Reference< XDispatch > ( *CreateFnPtr )(
+        const Reference<XComponentContext> &,
+        const Reference<XFrame> &,
+        const OUString & );
+    typedef bool ( *SupportsURLFnPtr )( const URL &, const OUString & );
+
+    struct DispatchQueryInfo
+    {
+        SupportsURLFnPtr Supports;
+        CreateFnPtr      Create;
+        DispatchQueryInfo( SupportsURLFnPtr supports, CreateFnPtr create )
+            : Supports( supports )
+            , Create( create ) {}
+
+        bool operator<( const DispatchQueryInfo &other ) const
+        {
+            return Supports < other.Supports;
+        }
+    };
+
+    typedef std::set< DispatchQueryInfo > DispatchInfoSet;
+    struct StaticDispatchInfoInit
+    {
+            DispatchInfoSet *operator()()
+            {
+                static DispatchInfoSet aSet;
+                lcl_InitSet( aSet );
+                return &aSet;
+            }
+        private:
+            void lcl_InitSet( DispatchInfoSet &aSet )
+            {
+                aSet.insert( DispatchInfoSet::value_type(
+                                 &WordCountDispatch::SupportsURL,
+                                 &WordCountDispatch::Create ) );
+            }
+    };
+
+    struct DispatchQuery :
+        public rtl::StaticAggregate< DispatchInfoSet, StaticDispatchInfoInit > {};
+
+    struct lcl_QueryDispatch
+            : public std::unary_function< const DispatchQueryInfo &, bool>
+    {
+        private:
+            URL aURL;
+            OUString sMoudleIdetnifier;
+
+        public:
+            lcl_QueryDispatch( const URL &_aURL, const OUString &_sModuleId )
+                : aURL( _aURL )
+                , sMoudleIdetnifier( _sModuleId ) {}
+
+            bool operator()( const DispatchQueryInfo &aDispatch )
+            {
+                return ( *aDispatch.Supports )( aURL, sMoudleIdetnifier );
+            }
+    };
+}
+
+DispatchPool *
+DispatchPool::Create()
+{
+    return new DispatchPool();
+}
+
+DispatchPool::DispatchPool()
+    :  DipatchPool_Base()
+{
+    OSL_TRACE( "sbctlwc::DispatchPool::DispatchPool" );
+}
+
+DispatchPool::~DispatchPool( )
+{
+    OSL_TRACE( "sbctlwc::DispatchPool::~DispatchPool" );
+}
+
+void SAL_CALL
+DispatchPool::disposing(
+    const EventObject &aEventObject )
+throw ( RuntimeException )
+{
+    Reference< XFrame > xFrame( aEventObject.Source, UNO_QUERY );
+    if ( xFrame.is( ) )
+    {
+        FrameDispatchMap &aMap = StaticFrameDispatchMap::get( );
+        FrameDispatchMap::iterator it = aMap.find( xFrame );
+        if ( it != aMap.end( ) )
+        {
+            OSL_TRACE( "sbctlwc::DispatchPool::disposing : disposing dispatches for this XFrame" );
+            CommandDispatchMap &aCmds = it->second;
+            for ( CommandDispatchMap::iterator aCmdIt = aCmds.begin( );
+                    aCmdIt != aCmds.end( );
+                    aCmdIt++ )
+            {
+                CommandDispatchInfo &aInfo = aCmdIt->second;
+                if ( aInfo.Dispatch.is( ) )
+                {
+                    Reference< XComponent > xComp( aInfo.Dispatch, UNO_QUERY );
+                    if ( xComp.is( ) )
+                        xComp->dispose( );
+                    aInfo.Dispatch.clear();
+                    aInfo.Component.clear();
+                }
+
+            }
+            aCmds.clear();
+            aMap.erase( it );
+        }
+
+        return;
+    }
+
+    Reference< XComponent > xComponent( aEventObject.Source, UNO_QUERY );
+    if ( xComponent.is() )
+    {
+        FrameDispatchMap &aFrames = StaticFrameDispatchMap::get( );
+        for ( FrameDispatchMap::iterator aFrameIt = aFrames.begin();
+                aFrameIt != aFrames.end();
+                aFrameIt++ )
+        {
+            CommandDispatchMap &aCommands = aFrameIt->second;
+            for ( CommandDispatchMap::iterator aCommandIt = aCommands.begin();
+                    aCommandIt != aCommands.end();
+                    aCommandIt++ )
+            {
+                CommandDispatchInfo &aInfo = aCommandIt->second;
+                if ( xComponent == aInfo.Component )
+                {
+                    Reference< XComponent> xComp( aInfo.Dispatch, UNO_QUERY );
+                    if ( xComp.is( ) )
+                        xComp->dispose( );
+                    aInfo.Component.clear();
+                    aInfo.Dispatch.clear();
+                    aCommands.erase( aCommandIt );
+                }
+            }
+        }
+    }
+}
+
+Reference< XDispatch >
+DispatchPool::GetDispatch(
+    const Reference<XComponentContext> &xContext,
+    const Reference< XFrame > &xFrame,
+    const URL &rCommandURL,
+    const rtl::OUString &rModuleIdentifier )
+{
+
+    OSL_ENSURE( xFrame.is(), "DispatchPool::GetDispatch - no XFrame!" );
+    Reference< XDispatch > xRet;
+
+    const DispatchInfoSet &aDispatchInfo = *DispatchQuery::get();
+    const DispatchInfoSet::const_iterator pDispatchInfo = std::find_if(
+                aDispatchInfo.begin(),
+                aDispatchInfo.end(),
+                lcl_QueryDispatch( rCommandURL, rModuleIdentifier ) );
+    if ( pDispatchInfo == aDispatchInfo.end() )
+        return xRet;
+
+    Reference< XComponent > xComponent;
+    bool bListen = false;
+    const OUString sCommandURLPath = rCommandURL.Path;
+    const rtl::Reference<DispatchPool> &aPool = TheDispatchPool::get();
+    FrameDispatchMap &aFrames = StaticFrameDispatchMap::get();
+
+    Reference< XController > xController( xFrame->getController() );
+    if ( xController.is() )
+    {
+        Reference< XModel > xModel( xController->getModel(), UNO_QUERY );
+        if ( xModel.is() )
+            xComponent.set( xModel, UNO_QUERY );
+        else
+            xComponent.set( xController, UNO_QUERY );
+    }
+
+    FrameDispatchMap::iterator aFramesIt = aFrames.find( xFrame );
+    if ( aFramesIt == aFrames.end() )
+    {
+        CommandDispatchMap aMap;
+        xRet.set(  ( * pDispatchInfo->Create )( xContext, xFrame, rModuleIdentifier ) );
+        aMap.insert( CommandDispatchMap::value_type( sCommandURLPath, CommandDispatchInfo( xComponent, xRet ) ) );
+        aFrames[xFrame] = aMap;
+
+        xFrame->addEventListener( aPool.get() );
+        bListen = true;
+    }
+    else
+    {
+        // found XFrame
+        CommandDispatchMap &aMap = aFramesIt->second;
+        // find Command
+        const CommandDispatchMap::iterator &aDispatchesIt = aMap.find( sCommandURLPath );
+        if ( aDispatchesIt == aMap.end() )
+        {
+            // Command not found, create dispatch
+            xRet.set(  ( * pDispatchInfo->Create )( xContext, xFrame, rModuleIdentifier ) );
+            aMap.insert( CommandDispatchMap::value_type( sCommandURLPath, CommandDispatchInfo( xComponent, xRet ) ) );
+            bListen = true;
+        }
+        else
+        {
+            // command found
+            CommandDispatchInfo &aInfo = aDispatchesIt->second;
+            OSL_ENSURE( aInfo.Component == xComponent, "Requesting a dispatch for a different component!" );
+            xRet.set( aInfo.Dispatch );
+        }
+    }
+
+    if ( bListen )
+    {
+        xComponent->addEventListener( aPool.get() );
+    }
+
+    return xRet;
+}

Added: openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/DispatchPool.hxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/DispatchPool.hxx?rev=1417873&view=auto
==============================================================================
--- openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/DispatchPool.hxx (added)
+++ openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/DispatchPool.hxx Thu Dec  6 13:33:40 2012
@@ -0,0 +1,57 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#ifndef DISPATCH_POOL_HXX
+#define DISPATCH_POOL_HXX
+
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/basemutex.hxx>
+
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/lang/XEventListener.hpp>
+
+namespace framework
+{
+    namespace statusbar_controller_wordcount
+    {
+        namespace
+        {
+            typedef ::cppu::WeakImplHelper1 <
+            com::sun::star::lang::XEventListener > DipatchPool_Base;
+        }
+
+        class DispatchPool : public DipatchPool_Base
+        {
+            private:
+                DispatchPool();
+                ~DispatchPool();
+            public:
+                virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject &Source ) throw ( ::com::sun::star::uno::RuntimeException );
+
+                static DispatchPool *Create();
+                static com::sun::star::uno::Reference< com::sun::star::frame::XDispatch > GetDispatch( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext> &xContext, const com::sun::star::uno::Reference< com::sun::star::frame::XFrame > &xFrame, const com::sun::star::util::URL &rCommandURL, const rtl::OUString &rModuleIdentifier );
+        };
+    }
+}
+
+#endif

Added: openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/LICENSE
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/LICENSE?rev=1417873&view=auto
==============================================================================
--- openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/LICENSE (added)
+++ openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/LICENSE Thu Dec  6 13:33:40 2012
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright 2011, 2012 Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

Propchange: openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/LICENSE
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/Makefile
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/Makefile?rev=1417873&view=auto
==============================================================================
--- openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/Makefile (added)
+++ openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/Makefile Thu Dec  6 13:33:40 2012
@@ -0,0 +1,242 @@
+#**************************************************************
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+#**************************************************************
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+include $(SETTINGS)/platform.mk
+
+include project.mk
+
+COMP_NAME=WordCountStatusbarController
+
+OUT_COMP_INC=$(OUT_INC)/$(COMP_NAME)
+OUT_COMP_GEN=$(OUT_MISC)/$(COMP_NAME)
+OUT_COMP_SLO=$(OUT_SLO)/$(COMP_NAME)
+OUT_COMP_LIB=$(SHAREDLIB_OUT)/$(COMP_NAME)
+OUT_COMP_BIN=$(OUT_BIN)/$(COMP_NAME)
+OUT_COMP_DEPLOY=$(OUT_DEPLOY)/$(COMP_NAME)
+
+COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT)
+COMP_PACKAGE_FILENAME=$(COMP_NAME)-$(EXTENSION_VERSION)-$(subst _,-,$(EXTENSION_PLATFORM)).$(UNOOXT_EXT)
+COMP_PACKAGE = $(OUT_COMP_BIN)/$(COMP_PACKAGE_FILENAME)
+COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE)")
+COMP_UNOPKG_MANIFEST    = $(OUT_COMP_GEN)/$(COMPONENT_NAME)/META-INF/manifest.xml
+COMP_UNOPKG_DESCRIPTION = $(OUT_COMP_GEN)/$(COMPONENT_NAME)/description.xml
+COMP_MAPFILE = $(OUT_COMP_GEN)/$(COMP_NAME).uno.map
+COMP_COMPONENTS = $(OUT_COMP_GEN)/$(COMP_NAME).components
+
+# xcu
+COMP_ADDONS_CFG=registry/data/org/openoffice/Office/Addons.xcu
+COMP_PROTOCOLHABDLER_CFG=registry/data/org/openoffice/Office/ProtocolHandler.xcu
+COMP_CONTROLLER_CFG=registry/data/org/openoffice/Office/UI/Controller.xcu
+
+DESCRIPTION_IDENTIFIER=$(EXTENSION_ID)
+DESCRIPTION_PLATFORM=$(TARGET_PLATFORM)
+DESCRIPTION_UPDATE_FILENAME=$(EXTENSION_PLATFORM)-update.xml
+
+# Allow deploying the extension when running it
+ENV_USER_INSTALL=-env:"UserInstallation=$(URLPREFIX)$(OUT_COMP_DEPLOY)"
+OFFICE_START_OPTIONS=-nologo -nofirststartwizard -norestore -quickstart=no -writer
+OXT_DEPLOYEDFLAG=$(OUT_COMP_GEN)/so_deployed_$(COMP_NAME).flag
+
+# Files
+COMP_CXXFILES = \
+	BaseDispatch.cxx \
+	DispatchPool.cxx \
+	ProtocolHandler.cxx \
+	StatusbarController.cxx \
+	WordCountDispatch.cxx \
+	WordCountStatusbarController.cxx \
+	compfactory.cxx
+
+COMP_SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(COMP_CXXFILES))
+
+CC_DEFINES+= \
+	-DPROTOCOL_HANDLER_IMPL_NAME=\"$(PROTOCOLHANDLER_IMPLNAME)\" \
+	-DPROTOCOL_HANDLER_SERVICE_NAME=\"$(PROTOCOLHANDLER_SERVICE_NAME)\" \
+	-DPROTOCOL_HANDLER_URL_PROTOCOL=\"$(PROTOCOLHANDLER_PROTOCOL)\" \
+	-DSTATUSBAR_CONTROLLER_IMPL_NAME=\"$(STATUSBARCONTROLLER_IMPLNAME)\" \
+	-DSTATUSBAR_CONTROLLER_SERVICE_NAME=\"$(STATUSBARCONTROLLER_SERVICE_NAME)\" \
+
+# Targets and rules
+.PHONY: ALL update-desc WordCountStatusbarController WordCountStatusbarController.run
+ALL : \
+	update-desc \
+ WordCountStatusbarController
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG)
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	$(CC) $(CC_FLAGS) $(STL_INCLUDES) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<
+
+
+ifeq "$(OS)" "WIN"
+$(OUT_COMP_LIB)/%.$(SHAREDLIB_EXT) : $(COMP_SLOFILES)
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	-$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN))
+	$(LINK) \
+		$(COMP_LINK_FLAGS) \
+		/OUT:$@ \
+		/MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) \
+		$(COMP_SLOFILES) \
+		$(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) \
+		msvcrt.lib kernel32.lib
+	$(LINK_MANIFEST)
+else
+$(OUT_COMP_LIB)/%.$(SHAREDLIB_EXT) : $(COMP_SLOFILES)
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	$(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(COMP_SLOFILES) \
+		$(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) \
+		$(STLPORTLIB) $(STC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALDYLIB)
+ifeq "$(OS)" "MACOSX"
+	$(INSTALL_NAME_URELIBS)  $@
+endif
+endif
+
+# rule for extension ProtocolHandler.xcu
+$(OUT_COMP_GEN)/$(COMP_PROTOCOLHABDLER_CFG) : $(COMP_PROTOCOLHABDLER_CFG)
+	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	$(SDK_CAT) $< | $(SDK_SED) \
+	-e "s/#PROTOCOLHANDLER_IMPLNAME#/$(PROTOCOLHANDLER_IMPLNAME)/" \
+	-e "s/#PROTOCOLHANDLER_PROTOCOL#/$(PROTOCOLHANDLER_PROTOCOL)/" > $@
+
+
+# rule for extension Addons.xcu
+$(OUT_COMP_GEN)/$(COMP_ADDONS_CFG) : $(COMP_ADDONS_CFG)
+	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	$(SDK_CAT) $< | $(SDK_SED) \
+	-e "s/#PROTOCOLHANDLER_PROTOCOL#/$(PROTOCOLHANDLER_PROTOCOL)/" > $@
+
+
+# rule for extension Addons.xcu
+$(OUT_COMP_GEN)/$(COMP_CONTROLLER_CFG) : $(COMP_CONTROLLER_CFG)
+	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	$(SDK_CAT) $< | $(SDK_SED) \
+	-e "s/#PROTOCOLHANDLER_PROTOCOL#/$(PROTOCOLHANDLER_PROTOCOL)/" \
+	-e "s/#STATUSBARCONTROLLER_IMPLNAME#/$(STATUSBARCONTROLLER_IMPLNAME)/" > $@
+
+# rule for extension description.xml
+$(COMP_UNOPKG_DESCRIPTION) :  xml/description.xml
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	$(SDK_CAT) $< | $(SDK_SED) \
+	-e "s/#EXTENSION_VERSION#/$(EXTENSION_VERSION)/" \
+	-e "s/#DESCRIPTION_IDENTIFIER#/$(DESCRIPTION_IDENTIFIER)/" \
+	-e "s/#EXTENSION_PLATFORM#/$(EXTENSION_PLATFORM)/" \
+	-e "s/#DESCRIPTION_OOO_MIN_VER#/$(DESCRIPTION_OOO_MIN_VER)/" \
+	-e "s/#DESCRIPTION_DEP_NAME#/$(DESCRIPTION_DEP_NAME)/" \
+	-e "s/#DESCRIPTION_PUBLISHER_URL#/$(subst /,\/,$(DESCRIPTION_PUBLISHER_URL))/" \
+	-e "s/#DESCRIPTION_PUBLISHER_NAME#/$(DESCRIPTION_PUBLISHER_NAME)/" \
+	-e "s/#DESCRIPTION_DISPLAY_NAME#/$(DESCRIPTION_DISPLAY_NAME)/" \
+	-e "s/#DESCRIPTION_UPDATE#/$(subst /,\/,$(DESCRIPTION_UPDATE_BASEURL)$(DESCRIPTION_UPDATE_FILENAME))/"  > $@
+
+
+# rule for update description
+$(OUT_COMP_BIN)/$(DESCRIPTION_UPDATE_FILENAME) : xml/update.xml
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	$(SDK_CAT) $< | $(SDK_SED) \
+		-e "s/#DESCRIPTION_IDENTIFIER#/$(DESCRIPTION_IDENTIFIER)/" \
+		-e "s/#EXTENSION_VERSION#/$(EXTENSION_VERSION)/" \
+		-e "s/#DESCRIPTION_PUBLISHER_URL#/$(subst /,\/,$(DESCRIPTION_PUBLISHER_URL))/" \
+		-e "s/#DESCRIPTION_PUBLISHER_NAME#/$(DESCRIPTION_PUBLISHER_NAME)/" \
+		-e "s/#UPDATE_DOWNLOAD#/$(subst /,\/,$(UPDATE_DOWNLOAD_BASE)$(COMP_PACKAGE_FILENAME))/" \
+		-e "s/#RELEASE_NOTES#/$(subst /,\/,$(RELEASE_NOTES))/" > $@
+
+# rule for component package manifest
+$(COMP_UNOPKG_MANIFEST) : xml/manifest.xml
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	$(SDK_CAT) $< | $(SDK_SED) \
+		-e "s/#COMP_NAME#/$(COMP_NAME)/" \
+		-e "s/#UNOPKG_PLATFORM#/$(UNOPKG_PLATFORM)/" > $@
+
+# rule for component pasive registration
+$(COMP_COMPONENTS) : xml/components.xml
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	$(SDK_CAT) $< | $(SDK_SED) \
+		-e "s/#PROTOCOLHANDLER_IMPLNAME#/$(PROTOCOLHANDLER_IMPLNAME)/" \
+		-e "s/#STATUSBARCONTROLLER_IMPLNAME#/$(STATUSBARCONTROLLER_IMPLNAME)/" \
+		-e "s/#UNOPKG_PLATFORM#/$(UNOPKG_PLATFORM)/" \
+		-e "s/#COMP_IMPL_NAME#/$(COMP_IMPL_NAME)/" > $@
+
+$(OUT_COMP_GEN)/images/%.png : images/%.png
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	$(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$@)
+
+$(OUT_COMP_GEN)/description/%.txt : description/%.txt
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	$(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$@)
+
+# rule for component package file
+$(COMP_PACKAGE) : $(OUT_COMP_LIB)/$(COMP_IMPL_NAME) \
+			$(OUT_COMP_GEN)/$(COMP_PROTOCOLHABDLER_CFG)  \
+			$(OUT_COMP_GEN)/$(COMP_ADDONS_CFG)  \
+			$(OUT_COMP_GEN)/$(COMP_CONTROLLER_CFG)  \
+			$(COMP_UNOPKG_MANIFEST) \
+			$(COMP_COMPONENTS)  \
+			$(COMP_UNOPKG_DESCRIPTION) \
+			LICENSE \
+			$(OUT_COMP_GEN)/images/icon.png \
+			$(OUT_COMP_GEN)/images/icon_hc.png \
+			$(OUT_COMP_GEN)/description/description_en-US.txt
+	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+	-$(MKDIR) $(subst /,$(PS),$(@D))
+	-$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM))
+	$(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM))
+	-$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)/LICENSE)
+	$(COPY) $(subst /,$(PS),LICENSE) $(subst /,$(PS),$(OUT_COMP_GEN)/LICENSE/)
+	cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u $(COMP_PACKAGE) $(COMP_NAME).components description.xml
+	cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -ur $(COMP_PACKAGE) $(UNOPKG_PLATFORM)/ LICENSE/ META-INF/  registry/ images/ description/
+
+
+update-desc : $(OUT_COMP_BIN)/$(DESCRIPTION_UPDATE_FILENAME)
+
+WordCountStatusbarController : $(COMP_PACKAGE)
+	@echo --------------------------------------------------------------------------------
+	@echo Please use the following command to deploy the example!
+	@echo -
+	@echo $(MAKE) WordCountStatusbarController.run
+	@echo -
+	@echo --------------------------------------------------------------------------------
+
+WordCountStatusbarController.run: $(OXT_DEPLOYEDFLAG)
+	"$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(OFFICE_START_OPTIONS)  $(ENV_USER_INSTALL)
+
+$(OXT_DEPLOYEDFLAG) : $(COMP_PACKAGE)
+	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+	-$(MKDIR) $(subst /,$(PS),$(OUT_COMP_DEPLOY))
+	$(DEPLOYTOOL) $(COMP_PACKAGE_URL) $(ENV_USER_INSTALL)
+	@echo flagged > $(subst /,$(PS),$@)
+
+.PHONY: clean
+clean :
+	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC))
+	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN))
+	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO))
+	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_LIB))
+	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_BIN))
+	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_DEPLOY))

Propchange: openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/Makefile
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/ProtocolHandler.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/ProtocolHandler.cxx?rev=1417873&view=auto
==============================================================================
--- openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/ProtocolHandler.cxx (added)
+++ openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/ProtocolHandler.cxx Thu Dec  6 13:33:40 2012
@@ -0,0 +1,207 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#include "defines.hxx"
+#include "ProtocolHandler.hxx"
+#include "DispatchPool.hxx"
+
+#include <com/sun/star/lang/XMultiComponentFactory.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+#include <cppuhelper/compbase4.hxx>
+#include <uno/current_context.hxx>
+
+using namespace framework::statusbar_controller_wordcount;
+
+using namespace com::sun::star;
+using namespace com::sun::star::frame;
+using namespace com::sun::star::beans;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::util;
+
+using rtl::OUString;
+
+namespace
+{
+    struct StaticSupportedServices
+            : public rtl::StaticWithInit< Sequence< OUString >, StaticSupportedServices >
+    {
+        Sequence< OUString >
+        operator( )( )
+        {
+            Sequence< OUString > aServices( 2 );
+            aServices[0] = C2U( PROTOCOL_HANDLER_SERVICE_NAME );
+            aServices[1] = OUSTR_SERVICENAME_PROTOCOLHANDLER;
+            return aServices;
+        }
+    };
+}
+
+ProtocolHandler::ProtocolHandler( Reference< XComponentContext > const &rxContext )
+    : ProtocolHandler_Base( m_aMutex ),
+      m_xContext( rxContext ),
+      m_xFrame( )
+{
+    OSL_TRACE( "sbctlwc::ProtocolHandler::ProtocolHandler" );
+}
+
+ProtocolHandler::~ProtocolHandler( )
+{
+    OSL_TRACE( "sbctlwc::ProtocolHandler::~ProtocolHandler" );
+}
+
+void
+ProtocolHandler::ThrowIfDisposed( ) throw ( RuntimeException )
+{
+    if ( rBHelper.bInDispose || rBHelper.bDisposed )
+        throw DisposedException( );
+}
+
+void SAL_CALL
+ProtocolHandler::disposing()
+{
+}
+
+void SAL_CALL
+ProtocolHandler::initialize( const Sequence< Any > &aArguments )
+throw ( Exception, RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::ProtocolHandler::initialize" );
+    Reference < XFrame > xFrame;
+    if ( aArguments.getLength( ) )
+    {
+        aArguments[0] >>= xFrame;
+        osl::MutexGuard aGuard( m_aMutex );
+        m_xFrame = xFrame;
+        try
+        {
+            Reference< XModuleManager > xModuleManager(
+                m_xContext->getServiceManager()->createInstanceWithContext(
+                    OUSTR_SERVICENAME_MODULEMANAGER, m_xContext ),
+                UNO_QUERY );
+            m_sModuleIdentifier = xModuleManager->identify( m_xFrame );
+        }
+        catch ( ... ) {}
+    }
+}
+
+Reference< XDispatch > SAL_CALL
+ProtocolHandler::queryDispatch(
+    const URL &aURL,
+    const OUString &sTargetFrameName,
+    sal_Int32 )
+throw ( RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::ProtocolHandler::queryDispatch" );
+    Reference< XDispatch > xRet;
+    OUString sModuleIdentifier;
+
+    osl::ClearableMutexGuard aGuard( m_aMutex );
+    Reference< XFrame > xFrame = m_xFrame;
+    Reference< XComponentContext > xContext = m_xContext;
+    sModuleIdentifier = m_sModuleIdentifier;
+    aGuard.clear( );
+
+    if ( !xFrame.is( ) )
+        return xRet;
+
+    if ( aURL.Protocol.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( PROTOCOL_HANDLER_URL_PROTOCOL":" ) )
+            && sTargetFrameName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "_self" ) ) )
+    {
+        return DispatchPool::GetDispatch( xContext, xFrame, aURL, sModuleIdentifier );
+    }
+
+    return xRet;
+}
+
+Sequence< Reference< XDispatch > >
+SAL_CALL
+ProtocolHandler::queryDispatches( const Sequence< DispatchDescriptor > &seqDescripts )
+throw ( RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::ProtocolHandler::queryDispatches" );
+    ::sal_Int32 nCount = seqDescripts.getLength( );
+    Sequence< Reference< XDispatch > > lDispatcher( nCount );
+
+    for ( ::sal_Int32 i = 0; i < nCount; ++i )
+    {
+        lDispatcher[i] = queryDispatch(
+                             seqDescripts[i].FeatureURL,
+                             seqDescripts[i].FrameName,
+                             seqDescripts[i].SearchFlags );
+    }
+
+    return lDispatcher;
+}
+
+OUString SAL_CALL
+ProtocolHandler::getImplementationName( ) throw ( RuntimeException )
+{
+    return getImplementationName_static( );
+}
+
+::sal_Bool SAL_CALL
+ProtocolHandler::supportsService( OUString const &ServiceName ) throw ( RuntimeException )
+{
+    const Sequence< OUString > &aServices = StaticSupportedServices::get( );
+
+    for ( const OUString *pService = aServices.getConstArray( ),
+            *pEnd = pService + aServices.getLength( );
+            pService != pEnd;
+            pService++ )
+    {
+        if ( pService->equals( ServiceName ) )
+            return sal_True;
+    }
+
+    return sal_False;
+}
+
+Sequence< OUString > SAL_CALL
+ProtocolHandler::getSupportedServiceNames( ) throw ( RuntimeException )
+{
+    return getSupportedServiceNames_static( );
+}
+
+Reference< XInterface > ProtocolHandler::Create( const Reference< XComponentContext > &rxContext )
+throw( Exception )
+{
+    return Reference< XInterface >(
+               static_cast < ::cppu::OWeakObject * > ( new ProtocolHandler( rxContext ) ),
+               UNO_QUERY );
+}
+
+OUString
+ProtocolHandler::getImplementationName_static( )
+{
+    static OUString st_ImplName = C2U( PROTOCOL_HANDLER_IMPL_NAME );
+    return st_ImplName;
+}
+
+Sequence< OUString >
+ProtocolHandler::getSupportedServiceNames_static( )
+{
+    return StaticSupportedServices::get( );
+}

Added: openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/ProtocolHandler.hxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/ProtocolHandler.hxx?rev=1417873&view=auto
==============================================================================
--- openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/ProtocolHandler.hxx (added)
+++ openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/ProtocolHandler.hxx Thu Dec  6 13:33:40 2012
@@ -0,0 +1,100 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#ifndef PROTOCOL_HANDLER_HXX
+#define PROTOCOL_HANDLER_HXX
+
+#include <cppuhelper/compbase3.hxx>
+#include <cppuhelper/basemutex.hxx>
+
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+namespace com
+{
+    namespace sun
+    {
+        namespace star
+        {
+            namespace frame
+            {
+                class XFrame;
+            }
+        }
+    }
+}
+
+namespace framework
+{
+    namespace statusbar_controller_wordcount
+    {
+
+        namespace
+        {
+            typedef cppu::WeakComponentImplHelper3 <
+            com::sun::star::frame::XDispatchProvider,
+                com::sun::star::lang::XInitialization,
+                com::sun::star::lang::XServiceInfo > ProtocolHandler_Base;
+        }
+
+        class ProtocolHandler :
+            protected ::cppu::BaseMutex,
+            public ProtocolHandler_Base
+        {
+            public:
+                explicit ProtocolHandler( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > &rxContext );
+                virtual ~ProtocolHandler();
+
+                static com::sun::star::uno::Reference< com::sun::star::uno::XInterface > Create( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > &rxContext ) throw( com::sun::star::uno::Exception );
+                static com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static();
+                static ::rtl::OUString getImplementationName_static();
+
+                // called from WeakComponentImplHelper when XComponent::dispose() was
+                // called from outside
+                virtual void SAL_CALL disposing();
+
+                // ::com::sun::star::lang::XInitialization:
+                virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > &aArguments ) throw ( com::sun::star::uno::RuntimeException, com::sun::star::uno::Exception );
+
+                // ::com::sun::star::frame::XDispatchProvider:
+                virtual com::sun::star::uno::Reference< com::sun::star::frame::XDispatch > SAL_CALL queryDispatch( const com::sun::star::util::URL &URL, const ::rtl::OUString &TargetFrameName, sal_Int32 SearchFlags ) throw ( com::sun::star::uno::RuntimeException );
+                virtual com::sun::star::uno::Sequence< com::sun::star::uno::Reference< com::sun::star::frame::XDispatch > > SAL_CALL queryDispatches( const com::sun::star::uno::Sequence< com::sun::star::frame::DispatchDescriptor > &Requests ) throw ( com::sun::star::uno::RuntimeException );
+
+                // ::com::sun::star::lang::XServiceInfo:
+                virtual ::rtl::OUString SAL_CALL getImplementationName() throw ( com::sun::star::uno::RuntimeException );
+                virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString &ServiceName ) throw ( com::sun::star::uno::RuntimeException );
+                virtual com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw ( com::sun::star::uno::RuntimeException );
+
+            private:
+                void ThrowIfDisposed() throw ( com::sun::star::uno::RuntimeException );
+
+                com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
+                com::sun::star::uno::Reference< com::sun::star::frame::XFrame > m_xFrame;
+                rtl::OUString m_sModuleIdentifier;
+        };
+
+    }
+}
+
+#endif

Added: openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/StatusbarController.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/StatusbarController.cxx?rev=1417873&view=auto
==============================================================================
--- openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/StatusbarController.cxx (added)
+++ openoffice/trunk/main/odk/examples/cpp/StatusbarController/WordCountStatusbarController/StatusbarController.cxx Thu Dec  6 13:33:40 2012
@@ -0,0 +1,539 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#include "StatusbarController.hxx"
+#include "defines.hxx"
+
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/ui/ItemStyle.hpp>
+#include <com/sun/star/ucb/AlreadyInitializedException.hpp>
+
+#include <functional>
+#include <algorithm>
+
+using namespace framework::statusbar_controller_wordcount;
+
+using namespace com::sun::star;
+using namespace com::sun::star::ui;
+using namespace com::sun::star::util;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::awt;
+using namespace com::sun::star::frame;
+using namespace com::sun::star::beans;
+
+using rtl::OUString;
+using com::sun::star::ucb::AlreadyInitializedException;
+
+namespace
+{
+    template< class MAP >
+    struct lcl_StatusListenerRemove
+            : public std::unary_function< typename MAP::value_type &, void >
+    {
+        private:
+            Reference< XStatusListener > xListener;
+            Reference< XURLTransformer > xURLTransformer;
+        public:
+            explicit lcl_StatusListenerRemove(
+                const Reference< XStatusListener > &rxListener,
+                const Reference< XURLTransformer > &rxTransformer )
+                : xListener( rxListener )
+                , xURLTransformer( rxTransformer ) {}
+
+            void operator()( typename MAP::value_type &rPair ) const
+            {
+                if ( !rPair.second.is() )
+                    return;
+                try
+                {
+                    URL aURL;
+                    aURL.Complete = rPair.first;
+                    xURLTransformer->parseStrict( aURL );
+                    rPair.second->removeStatusListener( xListener, aURL );
+                }
+                catch ( ... )
+                {
+                }
+
+                rPair.second.clear();
+            }
+    };
+}
+
+
+StatusbarController::StatusbarController()
+    : StatusbarController_Base( m_aMutex )
+    , m_bInitialized( false )
+    , m_bOwnerDraw( false )
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::StatusbarController" );
+}
+
+StatusbarController::~StatusbarController()
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::~StatusbarController" );
+}
+
+void SAL_CALL
+StatusbarController::dispose()
+throw ( RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::dispose" );
+    osl::ClearableMutexGuard aGuard( m_aMutex );
+    ThrowIfDisposed();
+
+    UnbindListeners();
+
+    m_xFrame.clear();
+    m_xStatusbarWindow.clear();
+    m_xStatusbarItem.clear();
+    m_xURLTransformer.clear();
+    m_aListenerMap.clear();
+    aGuard.clear();
+
+    StatusbarController_Base::dispose();
+}
+
+void SAL_CALL
+StatusbarController::initialize(
+    const Sequence< Any > &aArguments )
+throw ( Exception, RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::initialize" );
+    bool bInitialized( true );
+
+    osl::ResettableMutexGuard aGuard( m_aMutex );
+    bInitialized = m_bInitialized;
+    aGuard.clear();
+
+    if ( bInitialized )
+        throw AlreadyInitializedException();
+
+    Reference< XFrame > xFrame;
+    Reference< XWindow > xStatusbarWindow;
+    Reference< XStatusbarItem > xStatusbarItem;
+    OUString sCommand, sModuleId;
+    bool bOwnerDraw( false );
+
+    PropertyValue aPropVal;
+    const Any *pAny = aArguments.getConstArray();
+    const Any *pEnd = pAny + aArguments.getLength();
+    for ( ; pAny != pEnd; pAny++ )
+    {
+        if ( *pAny >>= aPropVal )
+        {
+            if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Frame" ) ) )
+                aPropVal.Value >>= xFrame;
+            else if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CommandURL" ) ) )
+                aPropVal.Value >>= sCommand;
+            else if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ParentWindow" ) ) )
+                aPropVal.Value >>= xStatusbarWindow;
+            else if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ModuleName" ) ) )
+                aPropVal.Value >>= sModuleId;
+            else if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StatusbarItem" ) ) )
+                aPropVal.Value >>= xStatusbarItem;
+        }
+    }
+
+    if ( ( xStatusbarItem->getStyle() & ItemStyle::OWNER_DRAW ) == ItemStyle::OWNER_DRAW )
+        bOwnerDraw = true;
+
+    aGuard.reset();
+    m_bInitialized = true;
+    m_xFrame = xFrame;
+    m_xStatusbarItem = xStatusbarItem;
+    m_xStatusbarWindow = xStatusbarWindow;
+    m_sModuleIdentifier = sModuleId;
+    m_sCommandURL = sCommand;
+    m_bOwnerDraw = bOwnerDraw;
+    if ( m_sCommandURL.getLength() )
+        m_aListenerMap.insert( URLToDispatchMap::value_type( m_sCommandURL, Reference< XDispatch >() ) );
+    aGuard.clear();
+}
+
+void StatusbarController::BindListeners()
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::BindListeners" );
+    std::vector< Listener > aListeners;
+    Reference< XStatusListener > xStatusListener;
+    OUString sOwnCommandURL;
+
+    osl::ClearableMutexGuard aGuard( m_aMutex );
+    if ( !m_bInitialized )
+        return;
+
+    sOwnCommandURL = m_sCommandURL;
+    xStatusListener.set( static_cast< cppu::OWeakObject *>( this ), UNO_QUERY );
+    Reference< XDispatchProvider > xProvider( m_xFrame, UNO_QUERY );
+    if ( xProvider.is() )
+    {
+        for ( URLToDispatchMap::iterator it = m_aListenerMap.begin();
+                it != m_aListenerMap.end(); it++ )
+        {
+            Reference< XURLTransformer > xURLTransformer = GetURLTransformer();
+            URL aURL;
+            aURL.Complete = it->first;
+            xURLTransformer->parseStrict( aURL );
+
+            // remove
+            if ( it->second.is() )
+            {
+                try
+                {
+                    it->second->removeStatusListener( xStatusListener, aURL );
+                }
+                catch ( ... ) {}
+
+                it->second.clear();
+            }
+
+            // requery
+            try
+            {
+                it->second = xProvider->queryDispatch( aURL, OUString(), 0 );
+            }
+            catch ( ... ) {}
+
+            aListeners.push_back( Listener( aURL, it->second ) );
+        }
+    }
+    aGuard.clear();
+
+    if ( !xStatusListener.is() || aListeners.empty() )
+        return;
+
+    for ( std::vector< Listener >::const_iterator it = aListeners.begin();
+            it != aListeners.end(); it++ )
+    {
+        try
+        {
+            if ( it->xDispatch.is() )
+                it->xDispatch->addStatusListener( xStatusListener, it->aURL );
+            else if ( it->aURL.Complete.equals( sOwnCommandURL ) )
+            {
+                // no dispatch for our own command,
+                // send an update with the Feature disabled
+                FeatureStateEvent aFeatureState;
+                aFeatureState.FeatureURL = it->aURL;
+                aFeatureState.IsEnabled = sal_False;
+                aFeatureState.Source = xStatusListener;
+
+                xStatusListener->statusChanged( aFeatureState );
+            }
+        }
+        catch ( ... )
+        {}
+    }
+
+}
+
+void StatusbarController::UnbindListeners()
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::UnbindListeners" );
+
+    Reference< XStatusListener > xStatusListener( static_cast< cppu::OWeakObject * >( this ), UNO_QUERY );
+    std::for_each( m_aListenerMap.begin(),
+                   m_aListenerMap.end(),
+                   lcl_StatusListenerRemove< URLToDispatchMap >( xStatusListener, GetURLTransformer() ) );
+}
+
+bool StatusbarController::IsBound() const
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::IsBound" );
+    osl::MutexGuard aGuard( m_aMutex );
+    if ( !m_bInitialized )
+        return false;
+
+    const URLToDispatchMap::const_iterator it = m_aListenerMap.find( m_sCommandURL );
+    return it != m_aListenerMap.end() && it->second.is();
+}
+
+Reference< XURLTransformer > StatusbarController::GetURLTransformer()
+{
+    osl::MutexGuard aGuard( m_aMutex );
+    if ( !m_xURLTransformer.is() && m_xContext.is() )
+    {
+        try
+        {
+            m_xURLTransformer.set(
+                m_xContext->getServiceManager()->createInstanceWithContext(
+                    OUSTR_SERVICENAME_URLTRANSFORMER, m_xContext ), UNO_QUERY_THROW );
+        }
+        catch ( ... )
+        {}
+    }
+
+    return m_xURLTransformer;
+}
+
+void
+StatusbarController::ThrowIfDisposed( ) throw ( RuntimeException )
+{
+    if ( rBHelper.bDisposed || rBHelper.bInDispose )
+        throw lang::DisposedException( );
+}
+
+void StatusbarController::Execute(
+    const Sequence< PropertyValue > &aArgs )
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::Execute" );
+    Reference< XDispatch > xDispatch;
+    Reference< XURLTransformer > xURLParser;
+    OUString sCommandURL;
+
+    osl::ClearableMutexGuard aGuard( m_aMutex );
+    ThrowIfDisposed();
+    if ( m_bInitialized && m_sCommandURL.getLength() )
+    {
+        sCommandURL = m_sCommandURL;
+        xURLParser = GetURLTransformer();
+        const URLToDispatchMap::const_iterator it = m_aListenerMap.find( m_sCommandURL );
+        if ( it != m_aListenerMap.end() )
+            xDispatch = it->second;
+    }
+    aGuard.clear();
+
+    if ( xDispatch.is() && xURLParser.is() )
+    {
+        try
+        {
+            URL aURL;
+            aURL.Complete = sCommandURL;
+            xURLParser->parseStrict( aURL );
+            xDispatch->dispatch( aURL, aArgs );
+        }
+        catch ( ... )
+        {}
+    }
+}
+
+void StatusbarController::Execute(
+    const OUString &rCommandURL,
+    const Sequence< PropertyValue > &aArgs )
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::Execute" );
+    Reference< XDispatch > xDispatch;
+    URL aURL;
+    aURL.Complete = rCommandURL;
+
+    osl::ClearableMutexGuard aGuard( m_aMutex );
+    ThrowIfDisposed();
+    if ( m_bInitialized && rCommandURL.getLength() )
+    {
+        Reference< XURLTransformer > xURLParser = GetURLTransformer();
+        xURLParser->parseStrict( aURL );
+
+        const URLToDispatchMap::const_iterator it = m_aListenerMap.find( rCommandURL );
+        if ( it != m_aListenerMap.end() )
+            xDispatch = it->second;
+
+        if ( !xDispatch.is() )
+        {
+            try
+            {
+                Reference< XDispatchProvider > xProvider( m_xFrame, UNO_QUERY_THROW );
+                xDispatch = xProvider->queryDispatch( aURL, OUString(), 0 );
+            }
+            catch ( ... )
+            {}
+        }
+    }
+    aGuard.clear();
+
+    if ( xDispatch.is() )
+    {
+        try
+        {
+            xDispatch->dispatch( aURL, aArgs );
+        }
+        catch ( ... )
+        {}
+    }
+}
+
+void StatusbarController::UpdateStatus()
+{
+    BindListeners();
+}
+
+void StatusbarController::UpdateStatus( const OUString &rCommand )
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::UpdateStatus" );
+    Reference< XStatusListener > xStatusListener;
+    Reference< XDispatch > xDispatch;
+    URL aURL;
+    aURL.Complete = rCommand;
+
+    osl::ClearableMutexGuard aGuard( m_aMutex );
+    Reference< XDispatchProvider > xProvider( m_xFrame, UNO_QUERY );
+    Reference< XURLTransformer > xURLParser = GetURLTransformer();
+    xStatusListener.set( static_cast< cppu::OWeakObject * >( this ), UNO_QUERY );
+    if ( !xProvider.is() || !xURLParser.is() )
+        return;
+    try
+    {
+        xURLParser->parseStrict( aURL );
+        xDispatch = xProvider->queryDispatch( aURL, OUString(), 0 );
+    }
+    catch ( ... )
+    {}
+    aGuard.clear();
+
+    if ( !xStatusListener.is() || !xDispatch.is() )
+        return;
+
+    try
+    {
+        xDispatch->addStatusListener( xStatusListener, aURL );
+        xDispatch->removeStatusListener( xStatusListener, aURL );
+    }
+    catch ( ... )
+    {}
+}
+
+void SAL_CALL
+StatusbarController::statusChanged(
+    const FeatureStateEvent &aFeatureState )
+throw ( RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::statusChanged" );
+    osl::ClearableMutexGuard aGuard( m_aMutex );
+
+    if ( rBHelper.bInDispose || rBHelper.bDisposed )
+        return;
+
+    if ( aFeatureState.FeatureURL.Complete.equals( m_sCommandURL ) )
+    {
+        OUString aStrVal;
+        if ( aFeatureState.State >>= aStrVal )
+        {
+            m_xStatusbarItem->setText( aStrVal );
+        }
+        else if ( !aFeatureState.State.hasValue() && !aFeatureState.IsEnabled )
+            m_xStatusbarItem->setText( OUString() );
+    }
+}
+
+void SAL_CALL
+StatusbarController::disposing(
+    const lang::EventObject &Source )
+throw ( RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::disposing" );
+    osl::MutexGuard aGuard( m_aMutex );
+
+    if ( rBHelper.bInDispose || rBHelper.bDisposed )
+        return;
+
+    Reference< XFrame > xFrame( Source.Source, UNO_QUERY );
+    if ( xFrame.is() )
+    {
+        if ( xFrame == m_xFrame )
+            m_xFrame.clear();
+        return;
+    }
+
+    Reference< XDispatch > xDispatch( Source.Source, UNO_QUERY );
+    if ( !xDispatch.is() )
+        return;
+
+    URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
+    while ( pIter != m_aListenerMap.end() )
+    {
+        // Compare references and release dispatch references if they are equal.
+        if ( xDispatch == pIter->second )
+            pIter->second.clear();
+        pIter++;
+    }
+}
+
+void SAL_CALL
+StatusbarController::update()
+throw ( RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::update" );
+    osl::ClearableMutexGuard aGuard( m_aMutex );
+    ThrowIfDisposed();
+    aGuard.clear();
+
+    BindListeners();
+}
+
+::sal_Bool SAL_CALL
+StatusbarController::mouseButtonDown( const MouseEvent &/*aMouseEvent*/ )
+throw ( RuntimeException )
+{
+    return sal_False;
+}
+
+::sal_Bool SAL_CALL
+StatusbarController::mouseMove( const MouseEvent &/*aMouseEvent*/ )
+throw ( RuntimeException )
+{
+    return sal_False;
+}
+
+::sal_Bool SAL_CALL
+StatusbarController::mouseButtonUp( const MouseEvent &/*aMouseEvent*/ )
+throw ( RuntimeException )
+{
+    return sal_False;
+}
+
+void SAL_CALL
+StatusbarController::command(
+    const Point &/*aPos*/,
+    ::sal_Int32 /*nCommand*/,
+    ::sal_Bool /*bMouseEvent*/,
+    const Any &/*aData*/ )
+throw ( RuntimeException )
+{
+}
+
+void SAL_CALL
+StatusbarController::paint(
+    const Reference< XGraphics > &/*xGraphics*/,
+    const Rectangle &/*rOutputRectangle*/,
+    ::sal_Int32 /*nStyle*/ )
+throw ( RuntimeException )
+{
+}
+
+void SAL_CALL
+StatusbarController::click( const ::com::sun::star::awt::Point &/*aPos*/ )
+throw ( RuntimeException )
+{
+}
+
+void SAL_CALL
+StatusbarController::doubleClick( const ::com::sun::star::awt::Point &/*aPos*/ )
+throw ( RuntimeException )
+{
+    OSL_TRACE( "sbctlwc::StatusbarController::doubleClick" );
+    osl::ClearableMutexGuard aGuard( m_aMutex );
+    if ( rBHelper.bDisposed || rBHelper.bInDispose )
+        return;
+    aGuard.clear();
+
+    Sequence< PropertyValue > aDummyArgs;
+    Execute( aDummyArgs );
+}



Mime
View raw message