summaryrefslogtreecommitdiff
path: root/svx/source/dialog/selector.cxx
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2004-07-23 13:17:03 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2004-07-23 13:17:03 +0000
commit79d3e08dd30b6fd390977e31a0e663cfae9da980 (patch)
treebf9d25f0d1d8b130396aac09d6f6cab7d9292cc2 /svx/source/dialog/selector.cxx
parent11d2c70553a4dc0bb8ba908d3872ce0c56fe8793 (diff)
INTEGRATION: CWS scriptingf7 (1.2.24); FILE MERGED
2004/07/13 15:41:10 dfoster 1.2.24.3: #i30924# Fix problem with user/share when launched from customize dialog where slots are shown. 2004/07/12 18:43:19 toconnor 1.2.24.2: RESYNC: (1.2-1.3); FILE MERGED 2004/07/12 16:10:06 dfoster 1.2.24.1: #i30924#
Diffstat (limited to 'svx/source/dialog/selector.cxx')
-rw-r--r--svx/source/dialog/selector.cxx284
1 files changed, 276 insertions, 8 deletions
diff --git a/svx/source/dialog/selector.cxx b/svx/source/dialog/selector.cxx
index 022f6f9de1d0..1de0f8773166 100644
--- a/svx/source/dialog/selector.cxx
+++ b/svx/source/dialog/selector.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: selector.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: obo $ $Date: 2004-07-06 13:14:12 $
+ * last change: $Author: hr $ $Date: 2004-07-23 14:17:03 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -139,6 +139,11 @@
#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_BROWSE_BROWSENODEFACTORYVIEWTYPE_HPP_
#include <drafts/com/sun/star/script/browse/BrowseNodeFactoryViewType.hpp>
#endif
+#include <drafts/com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/container/XEnumerationAccess.hpp>
+#include <com/sun/star/container/XEnumeration.hpp>
+#include <com/sun/star/document/XDocumentInfoSupplier.hpp>
using ::rtl::OUString;
using namespace ::com::sun::star;
@@ -147,6 +152,8 @@ using namespace ::drafts::com::sun::star::script;
#define _SVSTDARR_STRINGSDTOR
#include <svtools/svstdarr.hxx>
+#include <svtools/imagemgr.hxx>
+#include <tools/urlobj.hxx>
SV_IMPL_PTRARR(SvxGroupInfoArr_Impl, SvxGroupInfoPtr);
@@ -313,9 +320,13 @@ void SvxConfigFunctionListBox_Impl::FunctionSelected()
SvxConfigGroupListBox_Impl::SvxConfigGroupListBox_Impl(
Window* pParent, const ResId& rResId, ULONG nConfigMode )
: SvTreeListBox( pParent, rResId )
- , nMode( nConfigMode ), bShowSF( FALSE ), bShowBasic( TRUE )
- , m_pImageProvider( NULL )
+ , nMode( nConfigMode ), bShowSF( FALSE ), bShowBasic( TRUE ),
+ m_sMyMacros(ResId(STR_MYMACROS)),
+ m_sProdMacros(ResId(STR_PRODMACROS)),
+ m_hdImage(ResId(IMG_HARDDISK)),
+ m_hdImage_hc(ResId(IMG_HARDDISK_HC))
{
+ FreeResource();
SetWindowBits( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_HASBUTTONS | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONSATROOT );
ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
@@ -330,6 +341,13 @@ SvxConfigGroupListBox_Impl::SvxConfigGroupListBox_Impl(
aNavigatorImages.GetImage( RID_SVXIMG_EXPANDEDNODE ),
BMP_COLOR_HIGHCONTRAST );
+ ::rtl::OUString aResName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "basctl" ));
+ aResName += rtl::OUString::valueOf( sal_Int32( SUPD ));
+ ResMgr* pBasResMgr = ResMgr::CreateResMgr( rtl::OUStringToOString( aResName, RTL_TEXTENCODING_ASCII_US ));
+ m_aImagesNormal = ImageList(ResId(RID_IMGLST_OBJECTS, pBasResMgr ));
+ m_aImagesHighContrast = ImageList(ResId(RID_IMGLST_OBJECTS_HC, pBasResMgr ));
+ //m_hdImage = Image(ResId(IMG_HARDDISK));
+ //m_hdImage_hc = Image(ResId(IMG_HARDDISK_HC));
// Check configuration to see whether only Basic macros,
// only Scripting Framework scripts, or both should be listed
Any value;
@@ -559,11 +577,12 @@ void SvxConfigGroupListBox_Impl::Init( SvStringsDtor *pArr, SfxSlotPool* pPool )
// Add Scripting Framework entries
Reference< browse::XBrowseNode > rootNode;
+ Reference< XComponentContext > xCtx;
try
{
Reference < beans::XPropertySet > xProps(
::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
- Reference< XComponentContext > xCtx( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), UNO_QUERY_THROW );
+ xCtx.set( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), UNO_QUERY_THROW );
Reference< browse::XBrowseNodeFactory > xFac( xCtx->getValueByName(
OUString::createFromAscii( "/singletons/drafts.com.sun.star.script.browse.theBrowseNodeFactory") ), UNO_QUERY_THROW );
rootNode.set( xFac->getView( browse::BrowseNodeFactoryViewType::SCRIPTSELECTOR ) );
@@ -629,6 +648,8 @@ void SvxConfigGroupListBox_Impl::Init( SvStringsDtor *pArr, SfxSlotPool* pPool )
{
currentDocTitle = SfxObjectShell::GetWorkingDocument()->GetTitle();
}
+ ::rtl::OUString uiName = theChild->getName();
+
if ( bIsRootNode )
{
if ( ! ((theChild->getName().equals( user ) || theChild->getName().equals( share ) ||
@@ -636,6 +657,14 @@ void SvxConfigGroupListBox_Impl::Init( SvStringsDtor *pArr, SfxSlotPool* pPool )
{
bDisplay=FALSE;
}
+ if ( uiName.equals( user ) )
+ {
+ uiName = m_sMyMacros;
+ }
+ else if ( uiName.equals( share ) )
+ {
+ uiName = m_sProdMacros;
+ }
}
if (children[n]->getType() != browse::BrowseNodeTypes::SCRIPT && bDisplay )
{
@@ -650,8 +679,15 @@ void SvxConfigGroupListBox_Impl::Init( SvStringsDtor *pArr, SfxSlotPool* pPool )
new SvxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER,
0, static_cast<void *>( theChild.get()));
+ OSL_TRACE("adding child node %s",::rtl::OUStringToOString( uiName, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+ Image aImage = GetImage( theChild, xCtx, bIsRootNode,BMP_COLOR_NORMAL );
SvLBoxEntry* pNewEntry =
- InsertEntry( theChild->getName(), NULL);
+ InsertEntry( uiName, NULL);
+ SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
+ SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
+ aImage = GetImage( theChild, xCtx, bIsRootNode,BMP_COLOR_HIGHCONTRAST );
+ SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
+ SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
pNewEntry->SetUserData( pInfo );
aArr.Insert( pInfo, aArr.Count() );
@@ -684,6 +720,209 @@ void SvxConfigGroupListBox_Impl::Init( SvStringsDtor *pArr, SfxSlotPool* pPool )
SetUpdateMode( TRUE );
}
+Image SvxConfigGroupListBox_Impl::GetImage( Reference< browse::XBrowseNode > node, Reference< XComponentContext > xCtx, bool bIsRootNode, bool bHighContrast )
+{
+ Image aImage;
+ if ( bIsRootNode )
+ {
+ ::rtl::OUString user = ::rtl::OUString::createFromAscii("user");
+ ::rtl::OUString share = ::rtl::OUString::createFromAscii("share");
+ if (node->getName().equals( user ) || node->getName().equals(share ) )
+ {
+ if( bHighContrast == BMP_COLOR_NORMAL )
+ aImage = m_hdImage;
+ else
+ aImage = m_hdImage_hc;
+ }
+ else
+ {
+ ::rtl::OUString factoryURL;
+ ::rtl::OUString nodeName = node->getName();
+ Reference<XInterface> xDocumentModel = getDocumentModel(xCtx, nodeName );
+ if ( xDocumentModel.is() )
+ {
+ Reference< ::drafts::com::sun::star::frame::XModuleManager >
+ xModuleManager(
+ xCtx->getServiceManager()
+ ->createInstanceWithContext(
+ ::rtl::OUString::createFromAscii("drafts." // xxx todo
+ "com.sun.star.frame.ModuleManager"),
+ xCtx ),
+ UNO_QUERY_THROW );
+ Reference<container::XNameAccess> xModuleConfig(
+ xModuleManager, UNO_QUERY_THROW );
+ // get the long name of the document:
+ ::rtl::OUString appModule( xModuleManager->identify(
+ xDocumentModel ) );
+ Sequence<beans::PropertyValue> moduleDescr;
+ Any aAny = xModuleConfig->getByName(appModule);
+ if( sal_True != ( aAny >>= moduleDescr ) )
+ {
+ throw RuntimeException(::rtl::OUString::createFromAscii("SFTreeListBox::Init: failed to get PropertyValue"), Reference< XInterface >());
+ }
+ beans::PropertyValue const * pmoduleDescr =
+ moduleDescr.getConstArray();
+ for ( sal_Int32 pos = moduleDescr.getLength(); pos--; )
+ {
+ if (pmoduleDescr[ pos ].Name.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM(
+ "ooSetupFactoryEmptyDocumentURL") ))
+ {
+ pmoduleDescr[ pos ].Value >>= factoryURL;
+ OSL_TRACE("factory url for doc images is %s",
+ ::rtl::OUStringToOString( factoryURL , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+ break;
+ }
+ }
+ }
+ if( factoryURL.getLength() > 0 )
+ {
+ if( bHighContrast == BMP_COLOR_NORMAL )
+ aImage = SvFileInformationManager::GetFileImage(
+ INetURLObject(factoryURL), false,
+ BMP_COLOR_NORMAL );
+ else
+ aImage = SvFileInformationManager::GetFileImage(
+ INetURLObject(factoryURL), false,
+ BMP_COLOR_HIGHCONTRAST );
+ }
+ else
+ {
+ if( bHighContrast == BMP_COLOR_NORMAL )
+ aImage = m_aImagesNormal.GetImage(IMGID_DOCUMENT);
+ else
+ aImage = m_aImagesHighContrast.GetImage(IMGID_DOCUMENT);
+ }
+ }
+ }
+ else
+ {
+ if( node->getType() == browse::BrowseNodeTypes::SCRIPT )
+ {
+ if( bHighContrast == BMP_COLOR_NORMAL )
+ aImage = m_aImagesNormal.GetImage(IMGID_MODULE);
+ else
+ aImage = m_aImagesHighContrast.GetImage(IMGID_MODULE);
+ }
+ else
+ {
+ if( bHighContrast == BMP_COLOR_NORMAL )
+ aImage = m_aImagesNormal.GetImage(IMGID_LIB);
+ else
+ aImage = m_aImagesHighContrast.GetImage(IMGID_LIB);
+ }
+ }
+ return aImage;
+}
+
+Reference< XInterface >
+SvxConfigGroupListBox_Impl::getDocumentModel( Reference< XComponentContext >& xCtx, ::rtl::OUString& docName )
+{
+ Reference< XInterface > xModel;
+ Reference< lang::XMultiComponentFactory > mcf =
+ xCtx->getServiceManager();
+ Reference< frame::XDesktop > desktop (
+ mcf->createInstanceWithContext(
+ ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"), xCtx ),
+ UNO_QUERY );
+
+ Reference< container::XEnumerationAccess > componentsAccess =
+ desktop->getComponents();
+ Reference< container::XEnumeration > components =
+ componentsAccess->createEnumeration();
+ sal_Int32 docIndex = 0;
+ while (components->hasMoreElements())
+ {
+ Reference< frame::XModel > model(
+ components->nextElement(), UNO_QUERY );
+ if ( model.is() )
+ {
+ ::rtl::OUString sTdocUrl = xModelToDocTitle( model );
+ if( sTdocUrl.equals( docName ) )
+ {
+ xModel = model;
+ break;
+ }
+ }
+ }
+ return xModel;
+}
+
+::rtl::OUString SvxConfigGroupListBox_Impl::xModelToDocTitle( const Reference< frame::XModel >& xModel )
+{
+ // Set a default name, this should never be seen.
+ ::rtl::OUString docNameOrURL =
+ ::rtl::OUString::createFromAscii("Unknown");
+ if ( xModel.is() )
+ {
+ ::rtl::OUString tempName;
+ try
+ {
+ Reference< beans::XPropertySet > propSet( xModel->getCurrentController()->getFrame(), UNO_QUERY );
+ if ( propSet.is() )
+ {
+ if ( sal_True == ( propSet->getPropertyValue(::rtl::OUString::createFromAscii( "Title" ) ) >>= tempName ) )
+ {
+ docNameOrURL = tempName;
+ if ( xModel->getURL().getLength() == 0 )
+ {
+ // process "UntitledX - YYYYYYYY"
+ // to get UntitledX
+ sal_Int32 pos = 0;
+ docNameOrURL = tempName.getToken(0,' ',pos);
+ OSL_TRACE("xModelToDocTitle() Title for document is %s.",
+ ::rtl::OUStringToOString( docNameOrURL,
+ RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+ }
+ else
+ {
+ Reference< document::XDocumentInfoSupplier > xDIS( xModel, UNO_QUERY_THROW );
+ Reference< beans::XPropertySet > xProp (xDIS->getDocumentInfo(), UNO_QUERY_THROW );
+ Any aTitle = xProp->getPropertyValue(::rtl::OUString::createFromAscii( "Title" ) );
+
+ aTitle >>= docNameOrURL;
+ if ( docNameOrURL.getLength() == 0 )
+ {
+ docNameOrURL = parseLocationName( xModel->getURL() );
+ }
+ }
+ }
+ }
+ }
+ catch ( Exception& e )
+ {
+ OSL_TRACE("MiscUtils::xModelToDocTitle() exception thrown: !!! %s",
+ ::rtl::OUStringToOString( e.Message,
+ RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+ }
+
+ }
+ else
+ {
+ OSL_TRACE("MiscUtils::xModelToDocTitle() doc model is null" );
+ }
+ return docNameOrURL;
+}
+
+::rtl::OUString SvxConfigGroupListBox_Impl::parseLocationName( const ::rtl::OUString& location )
+{
+ // strip out the last leaf of location name
+ // e.g. file://dir1/dir2/Blah.sxw - > Blah.sxw
+ ::rtl::OUString temp = location;
+ sal_Int32 lastSlashIndex = temp.lastIndexOf( ::rtl::OUString::createFromAscii( "/" ) );
+
+ if ( ( lastSlashIndex + 1 ) < temp.getLength() )
+ {
+ temp = temp.copy( lastSlashIndex + 1 );
+ }
+ // maybe we should throw here!!!
+ else
+ {
+ OSL_TRACE("Something wrong with name, perhaps we should throw an exception");
+ }
+ return temp;
+}
+
void SvxConfigGroupListBox_Impl::GroupSelected()
{
SvLBoxEntry *pEntry = FirstSelected();
@@ -854,8 +1093,14 @@ void SvxConfigGroupListBox_Impl::GroupSelected()
new SvxGroupInfo_Impl(SFX_CFGFUNCTION_SCRIPT,
aInfo->GetSlotId(), aInfo);
+ Image aImage = GetImage( children[n], Reference< XComponentContext >(), sal_False, BMP_COLOR_NORMAL );
SvLBoxEntry* pNewEntry =
pFunctionListBox->InsertEntry( children[n]->getName(), NULL );
+ pFunctionListBox->SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
+ pFunctionListBox->SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
+ aImage = GetImage( children[n], Reference< XComponentContext >(), sal_False, BMP_COLOR_HIGHCONTRAST );
+ pFunctionListBox->SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
+ pFunctionListBox->SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
pNewEntry->SetUserData( pInfo );
@@ -1053,8 +1298,31 @@ void SvxConfigGroupListBox_Impl::RequestingChilds( SvLBoxEntry *pEntry )
new SvxGroupInfo_Impl(SFX_CFGGROUP_SCRIPTCONTAINER,
0, static_cast<void *>( theChild.get()));
+ ::rtl::OUString uiName = theChild->getName();
+ sal_Bool isRootNode = sal_False;
+ //if we show slots (as in the customize dialog)
+ //then the user & share are added at depth=1
+ if(nMode && GetModel()->GetDepth(pEntry) == 0)
+ {
+ if ( uiName.equals( user ) )
+ {
+ uiName = m_sMyMacros;
+ isRootNode = sal_True;
+ }
+ else if ( uiName.equals( share ) )
+ {
+ uiName = m_sProdMacros;
+ isRootNode = sal_True;
+ }
+ }
+ Image aImage = GetImage( theChild, Reference< XComponentContext >(), isRootNode, BMP_COLOR_NORMAL );
SvLBoxEntry* pNewEntry =
- InsertEntry( theChild->getName(), pEntry );
+ InsertEntry( uiName, pEntry );
+ SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
+ SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL);
+ aImage = GetImage( theChild, Reference< XComponentContext >(), isRootNode, BMP_COLOR_HIGHCONTRAST );
+ SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
+ SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_HIGHCONTRAST);
pNewEntry->SetUserData( pInfo );
aArr.Insert( pInfo, aArr.Count() );
@@ -1182,7 +1450,6 @@ SvxScriptSelectorDialog::SvxScriptSelectorDialog(
aDescriptionText( this, ResId( TXT_SELECTOR_DESCRIPTION ) ),
m_bShowSlots( bShowSlots )
{
- FreeResource();
ResMgr* pMgr = DIALOG_MGR();
@@ -1216,6 +1483,7 @@ SvxScriptSelectorDialog::SvxScriptSelectorDialog(
aCancelButton.SetClickHdl( LINK( this, SvxScriptSelectorDialog, ClickHdl ) );
UpdateUI();
+ FreeResource();
}
void SvxScriptSelectorDialog::ResizeControls()