Commits

Anonymous committed 2b17a13

contextmenu1: #i116173 Reflect the feature enabled-disbaled state

  • Participants
  • Parent commits eeb7892

Comments (0)

Files changed (1)

File framework/source/uielement/fontmenucontroller.cxx

 DEFINE_INIT_SERVICE                     (   FontMenuController, {} )
 
 FontMenuController::FontMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
-	svt::PopupMenuControllerBase( xServiceManager )
+	svt::PopupMenuControllerBase( xServiceManager ),
+	m_bFeatureEnabled( sal_False )
 {
 }
 
 // XStatusListener
 void SAL_CALL FontMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
 {
-    com::sun::star::awt::FontDescriptor aFontDescriptor;
-    Sequence< rtl::OUString >           aFontNameSeq;
+    osl::MutexGuard aLock( m_aMutex );
+    if ( Event.FeatureURL.Complete.equals( m_aCommandURL ) )
+    {
+        m_bFeatureEnabled = Event.IsEnabled;
+        if ( !m_bFeatureEnabled )
+        {
+            resetPopupMenu( m_xPopupMenu );
+            return;
+        }
 
-    if ( Event.State >>= aFontDescriptor )
+        com::sun::star::awt::FontDescriptor aFontDescriptor;
+        if ( Event.State >>= aFontDescriptor )
+        {
+            m_aFontFamilyName = aFontDescriptor.Name;
+        }
+    }
+    else
     {
-        osl::MutexGuard aLock( m_aMutex );
-        m_aFontFamilyName = aFontDescriptor.Name;
-    }
-    else if ( Event.State >>= aFontNameSeq )
-    {
-        osl::MutexGuard aLock( m_aMutex );
+        Sequence< rtl::OUString > aFontNameSeq;
+        if ( !( Event.State >>= aFontNameSeq ) )
+            return;
+
         if ( m_xPopupMenu.is() )
             fillPopupMenu( aFontNameSeq, m_xPopupMenu );
     }
 }
 
+// TODO this is UNUSED code. REMOVE.
 // XMenuListener
 void FontMenuController::impl_select(const Reference< XDispatch >& _xDispatch,const ::com::sun::star::util::URL& aTargetURL)
 {
 
 		    rtl::OUString aText = m_xPopupMenu->getItemText( nItemId );
 
-            // TODO: must be replaced by implementation of VCL, when available
-			sal_Int32 nIndex = aText.indexOf( (sal_Unicode)'~' );
-			if ( nIndex >= 0 )
-			    aText = aText.replaceAt( nIndex, 1, aEmpty );
-            // TODO: must be replaced by implementation of VCL, when available
-
 		    if ( aText == m_aFontFamilyName )
 		    {
 			    m_xPopupMenu->checkItem( nItemId, sal_True );
 	svt::PopupMenuControllerBase::updatePopupMenu();
 
     osl::ClearableMutexGuard aLock( m_aMutex );
+
+    // base class updates command state
+    if ( !m_bFeatureEnabled )
+        return;
+
     Reference< XDispatch > xDispatch( m_xFontListDispatch );
     com::sun::star::util::URL aTargetURL;
     aTargetURL.Complete = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FontNameList" ));