tbxitem.cxx (d119d52d) tbxitem.cxx (595fd105)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 107 unchanged lines hidden (view full) ---

116using namespace ::com::sun::star::util;
117using namespace ::com::sun::star::container;
118using namespace ::com::sun::star::frame;
119using namespace ::com::sun::star::ui;
120
121//====================================================================
122
123SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, sal_True);
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 107 unchanged lines hidden (view full) ---

116using namespace ::com::sun::star::util;
117using namespace ::com::sun::star::container;
118using namespace ::com::sun::star::frame;
119using namespace ::com::sun::star::ui;
120
121//====================================================================
122
123SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, sal_True);
124SFX_IMPL_TOOLBOX_CONTROL(SfxAppToolBoxControl_Impl, SfxStringItem);
125
126static Window* GetTopMostParentSystemWindow( Window* pWindow )
127{
128 OSL_ASSERT( pWindow );
129 if ( pWindow )
130 {
131 // ->manually search topmost system window
132 // required because their might be another system window between this and the top window

--- 1372 unchanged lines hidden (view full) ---

1505 if ( m_aDeleteLink.IsSet() )
1506 m_aDeleteLink.Call( this );
1507 delete this;
1508 return 0;
1509}
1510
1511//--------------------------------------------------------------------
1512
124
125static Window* GetTopMostParentSystemWindow( Window* pWindow )
126{
127 OSL_ASSERT( pWindow );
128 if ( pWindow )
129 {
130 // ->manually search topmost system window
131 // required because their might be another system window between this and the top window

--- 1372 unchanged lines hidden (view full) ---

1504 if ( m_aDeleteLink.IsSet() )
1505 m_aDeleteLink.Call( this );
1506 delete this;
1507 return 0;
1508}
1509
1510//--------------------------------------------------------------------
1511
1513SfxAppToolBoxControl_Impl::SfxAppToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox )
1514 : SfxToolBoxControl( nSlotId, nId, rBox )
1515 , bBigImages( sal_False )
1516 , pMenu( 0 )
1517{
1518 rBox.SetHelpId( nId, HID_TBXCONTROL_FILENEW );
1519 rBox.SetItemBits( nId, rBox.GetItemBits( nId ) | TIB_DROPDOWN);
1520
1521 // Determine the current background color of the menus
1522 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
1523 m_nSymbolsStyle = rSettings.GetSymbolsStyle();
1524 m_bWasHiContrastMode = rSettings.GetHighContrastMode();
1525 m_bShowMenuImages = rSettings.GetUseImagesInMenus();
1526
1527 SetImage( String() );
1528}
1529
1530SfxAppToolBoxControl_Impl::~SfxAppToolBoxControl_Impl()
1531{
1532 delete pMenu;
1533}
1534
1535//_____________________________________________________
1536/*
1537 it return the existing state of the given URL in the popupmenu of this toolbox control.
1538
1539 If the given URL can be located as an action command of one menu item of the
1540 popup menu of this control, we return sal_True. Otherwhise we return sal_False.
1541 Further we return a fallback URL, in case we have to return sal_False. Because
1542 the outside code must select a valid item of the popup menu everytime ...
1543 and we define it here. By the way this m ethod was written to handle
1544 error situations gracefully. E.g. it can be called during creation time
1545 but then we have no valid menu. For this case we know another fallback URL.
1546 Then we return the private:factory/ URL of the default factory.
1547
1548 @param *pMenu
1549 pounts to the popup menu, on which item we try to locate the given URL
1550 Can be NULL! Search will be supressed then.
1551
1552 @param sURL
1553 the URL for searching
1554
1555 @param pFallback
1556 contains the fallback URL in case we return FALSE
1557 Must point to valid memory!
1558
1559 @param pImage
1560 contains the image of the menu for the URL.
1561
1562 @return sal_True - if URL could be located as an item of the popup menu.
1563 sal_False - otherwhise.
1564*/
1565sal_Bool Impl_ExistURLInMenu( const PopupMenu *pMenu ,
1566 String &sURL ,
1567 String *pFallback ,
1568 Image *pImage )
1569{
1570 sal_Bool bValidFallback = sal_False;
1571 if (pMenu && sURL.Len())
1572 {
1573 sal_uInt16 c = pMenu->GetItemCount();
1574 for (sal_uInt16 p=0; p<c; ++p)
1575 {
1576 sal_uInt16 nId = pMenu->GetItemId(p);
1577 String aCmd( pMenu->GetItemCommand(nId) );
1578
1579 if (!bValidFallback && aCmd.Len())
1580 {
1581 *pFallback = aCmd;
1582 bValidFallback = sal_True;
1583 }
1584
1585 if (aCmd.Search(sURL)==0)//match even if the menu command is more detailed (maybe an additional query) #i28667#
1586 {
1587 sURL = aCmd;
1588 *pImage = pMenu->GetItemImage( nId );
1589 return sal_True;
1590 }
1591 }
1592 }
1593
1594 if (!bValidFallback)
1595 {
1596 *pFallback = DEFINE_CONST_UNICODE("private:factory/");
1597 *pFallback += String(SvtModuleOptions().GetDefaultModuleName());
1598 }
1599
1600 return sal_False;
1601}
1602
1603long Select_Impl( void* pHdl, void* pVoid );
1604
1605SfxPopupWindow* SfxAppToolBoxControl_Impl::CreatePopupWindow()
1606{
1607 ToolBox& rBox = GetToolBox();
1608 ::Rectangle aRect( rBox.GetItemRect( GetId() ) );
1609
1610 if ( !pMenu )
1611 {
1612 ::framework::MenuConfiguration aConf( m_xServiceManager );
1613 if ( m_aCommandURL.equalsAscii( ".uno:AddDirect" ))
1614 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
1615 else
1616 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
1617 }
1618
1619 if ( pMenu )
1620 {
1621 pMenu->SetSelectHdl( Link( NULL, Select_Impl ) );
1622 pMenu->SetActivateHdl( LINK( this, SfxAppToolBoxControl_Impl, Activate ));
1623 rBox.SetItemDown( GetId(), sal_True );
1624 sal_uInt16 nSelected = pMenu->Execute( &rBox, aRect, POPUPMENU_EXECUTE_DOWN );
1625 if ( nSelected )
1626 {
1627 aLastURL = pMenu->GetItemCommand( nSelected );
1628 SetImage( pMenu->GetItemCommand( nSelected ) );
1629 }
1630
1631 rBox.SetItemDown( GetId(), sal_False );
1632 }
1633
1634 return 0;
1635}
1636
1637void SfxAppToolBoxControl_Impl::SetImage( const String &rURL )
1638{
1639 /* We accept URL's here only, which exist as items of our internal popup menu.
1640 All other ones will be ignored and a fallback is used ... */
1641 String aURL = rURL;
1642 String sFallback;
1643 Image aMenuImage;
1644 sal_Bool bValid = Impl_ExistURLInMenu(pMenu,aURL,&sFallback,&aMenuImage);
1645 if (!bValid)
1646 aURL = sFallback;
1647
1648 sal_Bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
1649 sal_Bool bHC = GetToolBox().GetSettings().GetStyleSettings().GetHighContrastMode();
1650 Image aImage = SvFileInformationManager::GetImageNoDefault( INetURLObject( aURL ), bBig, bHC );
1651 if ( !aImage )
1652 aImage = !!aMenuImage ? aMenuImage :
1653 SvFileInformationManager::GetImage( INetURLObject( aURL ), bBig, bHC );
1654 Size aBigSize( GetToolBox().GetDefaultImageSize() );
1655 if ( bBig && aImage.GetSizePixel() != aBigSize )
1656 {
1657 BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
1658 aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE );
1659 GetToolBox().SetItemImage( GetId(), Image( aScaleBmpEx ) );
1660 }
1661 else
1662 GetToolBox().SetItemImage( GetId(), aImage );
1663 aLastURL = aURL;
1664}
1665
1666void SfxAppToolBoxControl_Impl::StateChanged
1667(
1668 sal_uInt16 nSlotId,
1669 SfxItemState eState,
1670 const SfxPoolItem* pState
1671)
1672{
1673 if ( pState && pState->ISA(SfxStringItem) )
1674 {
1675 // Important step for following SetImage() call!
1676 // It needs the valid pMenu item to fullfill it's specification
1677 // to check for supported URLs ...
1678 if ( !pMenu )
1679 {
1680 ::framework::MenuConfiguration aConf( m_xServiceManager );
1681 // This toolbox controller is used for two popup menus (new documents and wizards!). Create the correct
1682 // popup menu according to the slot ID our controller has been initialized with.
1683 if ( nSlotId == SID_NEWDOCDIRECT )
1684 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
1685 else
1686 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
1687 }
1688
1689 GetToolBox().EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
1690 SetImage(((const SfxStringItem*)pState)->GetValue());
1691 }
1692 else
1693 SfxToolBoxControl::StateChanged( nSlotId, eState, pState );
1694}
1695
1696//--------------------------------------------------------------------
1697
1698void SfxAppToolBoxControl_Impl::Select( sal_Bool bMod1 )
1699{
1700 if( aLastURL.Len() )
1701 {
1702 URL aTargetURL;
1703 Reference< XDispatch > xDispatch;
1704 Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY );
1705
1706 if ( xDispatchProvider.is() )
1707 {
1708 aTargetURL.Complete = aLastURL;
1709 getURLTransformer()->parseStrict( aTargetURL );
1710
1711 ::rtl::OUString aTarget( ::rtl::OUString::createFromAscii( "_default" ));
1712 if ( pMenu )
1713 {
1714 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
1715 (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
1716
1717 if ( pMenuAttributes )
1718 aTarget = pMenuAttributes->aTargetFrame;
1719 }
1720
1721 xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTarget, 0 );
1722
1723 if ( xDispatch.is() )
1724 {
1725 Sequence< PropertyValue > aArgs( 1 );
1726
1727 aArgs[0].Name = ::rtl::OUString::createFromAscii( "Referer" );
1728 aArgs[0].Value = makeAny( ::rtl::OUString::createFromAscii( SFX_REFERER_USER ));
1729
1730 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
1731 pExecuteInfo->xDispatch = xDispatch;
1732 pExecuteInfo->aTargetURL = aTargetURL;
1733 pExecuteInfo->aArgs = aArgs;
1734 Application::PostUserEvent( STATIC_LINK(0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
1735 }
1736 }
1737 }
1738 else
1739 SfxToolBoxControl::Select( bMod1 );
1740}
1741
1742//--------------------------------------------------------------------
1743long Select_Impl( void* /*pHdl*/, void* pVoid )
1744{
1745 Menu* pMenu = (Menu*)pVoid;
1746 String aURL( pMenu->GetItemCommand( pMenu->GetCurItemId() ) );
1747
1748 if( !aURL.Len() )
1749 return 0;
1750
1751 Reference < ::com::sun::star::frame::XFramesSupplier > xDesktop =
1752 Reference < ::com::sun::star::frame::XFramesSupplier >( ::comphelper::getProcessServiceFactory()->createInstance(
1753 DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
1754 Reference < ::com::sun::star::frame::XFrame > xFrame( xDesktop, UNO_QUERY );
1755
1756 URL aTargetURL;
1757 aTargetURL.Complete = aURL;
1758 Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
1759 rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
1760 UNO_QUERY );
1761 xTrans->parseStrict( aTargetURL );
1762
1763 Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
1764 Reference < XDispatch > xDisp;
1765 if ( xProv.is() )
1766 {
1767 if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL )
1768 xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
1769 else
1770 {
1771 ::rtl::OUString aTargetFrame( ::rtl::OUString::createFromAscii( "_blank" ) );
1772 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
1773 (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
1774
1775 if ( pMenuAttributes )
1776 aTargetFrame = pMenuAttributes->aTargetFrame;
1777
1778 xDisp = xProv->queryDispatch( aTargetURL, aTargetFrame , 0 );
1779 }
1780 }
1781
1782 if ( xDisp.is() )
1783 {
1784 SfxAppToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxAppToolBoxControl_Impl::ExecuteInfo;
1785 pExecuteInfo->xDispatch = xDisp;
1786 pExecuteInfo->aTargetURL = aTargetURL;
1787 pExecuteInfo->aArgs = Sequence< PropertyValue >();
1788 Application::PostUserEvent( STATIC_LINK( 0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
1789 }
1790
1791 return sal_True;
1792}
1793
1794IMPL_LINK( SfxAppToolBoxControl_Impl, Activate, Menu *, pActMenu )
1795{
1796 if ( pActMenu )
1797 {
1798 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
1799 sal_uIntPtr nSymbolsStyle = rSettings.GetSymbolsStyle();
1800 sal_Bool bIsHiContrastMode = rSettings.GetHighContrastMode();
1801 sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus();
1802
1803 if (( nSymbolsStyle != m_nSymbolsStyle ) ||
1804 ( bIsHiContrastMode != m_bWasHiContrastMode ) ||
1805 ( bShowMenuImages != m_bShowMenuImages ))
1806 {
1807 m_nSymbolsStyle = nSymbolsStyle;
1808 m_bWasHiContrastMode = bIsHiContrastMode;
1809 m_bShowMenuImages = bShowMenuImages;
1810
1811 sal_uInt16 nCount = pActMenu->GetItemCount();
1812 for ( sal_uInt16 nSVPos = 0; nSVPos < nCount; nSVPos++ )
1813 {
1814 sal_uInt16 nId = pActMenu->GetItemId( nSVPos );
1815 if ( pActMenu->GetItemType( nSVPos ) != MENUITEM_SEPARATOR )
1816 {
1817 if ( bShowMenuImages )
1818 {
1819 sal_Bool bImageSet = sal_False;
1820 ::rtl::OUString aImageId;
1821 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
1822 (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nId );
1823
1824 if ( pMenuAttributes )
1825 aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
1826
1827 if ( aImageId.getLength() > 0 )
1828 {
1829 Reference< ::com::sun::star::frame::XFrame > xFrame;
1830 Image aImage = GetImage( xFrame, aImageId, sal_False, bIsHiContrastMode );
1831 if ( !!aImage )
1832 {
1833 bImageSet = sal_True;
1834 pActMenu->SetItemImage( nId, aImage );
1835 }
1836 }
1837
1838 String aCmd( pActMenu->GetItemCommand( nId ) );
1839 if ( !bImageSet && aCmd.Len() )
1840 {
1841 Image aImage = SvFileInformationManager::GetImage(
1842 INetURLObject(aCmd), sal_False, bIsHiContrastMode );
1843 if ( !!aImage )
1844 pActMenu->SetItemImage( nId, aImage );
1845 }
1846 }
1847 else
1848 pActMenu->SetItemImage( nId, Image() );
1849 }
1850 }
1851 }
1852
1853 return sal_True;
1854 }
1855
1856 return sal_False;
1857}
1858
1859//--------------------------------------------------------------------
1860
1861IMPL_STATIC_LINK_NOINSTANCE( SfxAppToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
1862{
1863/* i62706: Don't catch all exceptions. We hide all problems here and are not able
1864 to handle them on higher levels.
1865 try
1866 {
1867*/
1868 // Asynchronous execution as this can lead to our own destruction!
1869 // Framework can recycle our current frame and the layout manager disposes all user interface
1870 // elements if a component gets detached from its frame!
1871 pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
1872/*
1873}
1874 catch (const ::com::sun::star::document::CorruptedFilterConfigurationException& exFilters)
1875 {
1876 throw exFilters;
1877 }
1878 catch (const Exception& )
1879 {
1880 }
1881*/
1882 delete pExecuteInfo;
1883 return 0;
1884}
1885
1886//--------------------------------------------------------------------
1887
1888void SfxAppToolBoxControl_Impl::Click( )
1889{
1890}