1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_fpicker.hxx" 30 31 //------------------------------------------------------------------------ 32 // includes 33 //------------------------------------------------------------------------ 34 #include <osl/diagnose.h> 35 #include <rtl/ustrbuf.hxx> 36 #include "resourceprovider.hxx" 37 #include <vos/mutex.hxx> 38 #include <vcl/svapp.hxx> 39 40 #ifndef _TOOLS_SIMPLERESMGR_HXX 41 #include <tools/simplerm.hxx> 42 #endif 43 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> 44 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 45 46 #include <svtools/svtools.hrc> 47 48 //------------------------------------------------------------ 49 // namespace directives 50 //------------------------------------------------------------ 51 52 using rtl::OUString; 53 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds; 54 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds; 55 56 //------------------------------------------------------------ 57 // 58 //------------------------------------------------------------ 59 60 #define FOLDERPICKER_TITLE 500 61 #define FOLDER_PICKER_DEF_DESCRIPTION 501 62 63 //------------------------------------------------------------ 64 // we have to translate control ids to resource ids 65 //------------------------------------------------------------ 66 67 struct _Entry 68 { 69 sal_Int32 ctrlId; 70 sal_Int16 resId; 71 }; 72 73 _Entry CtrlIdToResIdTable[] = { 74 { CHECKBOX_AUTOEXTENSION, STR_SVT_FILEPICKER_AUTO_EXTENSION }, 75 { CHECKBOX_PASSWORD, STR_SVT_FILEPICKER_PASSWORD }, 76 { CHECKBOX_FILTEROPTIONS, STR_SVT_FILEPICKER_FILTER_OPTIONS }, 77 { CHECKBOX_READONLY, STR_SVT_FILEPICKER_READONLY }, 78 { CHECKBOX_LINK, STR_SVT_FILEPICKER_INSERT_AS_LINK }, 79 { CHECKBOX_PREVIEW, STR_SVT_FILEPICKER_SHOW_PREVIEW }, 80 { PUSHBUTTON_PLAY, STR_SVT_FILEPICKER_PLAY }, 81 { LISTBOX_VERSION_LABEL, STR_SVT_FILEPICKER_VERSION }, 82 { LISTBOX_TEMPLATE_LABEL, STR_SVT_FILEPICKER_TEMPLATES }, 83 { LISTBOX_IMAGE_TEMPLATE_LABEL, STR_SVT_FILEPICKER_IMAGE_TEMPLATE }, 84 { CHECKBOX_SELECTION, STR_SVT_FILEPICKER_SELECTION }, 85 { FOLDERPICKER_TITLE, STR_SVT_FOLDERPICKER_DEFAULT_TITLE }, 86 { FOLDER_PICKER_DEF_DESCRIPTION, STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION } 87 }; 88 89 const sal_Int32 SIZE_TABLE = sizeof( CtrlIdToResIdTable ) / sizeof( _Entry ); 90 91 //------------------------------------------------------------ 92 // 93 //------------------------------------------------------------ 94 95 sal_Int16 CtrlIdToResId( sal_Int32 aControlId ) 96 { 97 sal_Int16 aResId = -1; 98 99 for ( sal_Int32 i = 0; i < SIZE_TABLE; i++ ) 100 { 101 if ( CtrlIdToResIdTable[i].ctrlId == aControlId ) 102 { 103 aResId = CtrlIdToResIdTable[i].resId; 104 break; 105 } 106 } 107 108 return aResId; 109 } 110 111 //------------------------------------------------------------ 112 // 113 //------------------------------------------------------------ 114 115 class CResourceProvider_Impl 116 { 117 public: 118 119 //------------------------------------- 120 // 121 //------------------------------------- 122 123 CResourceProvider_Impl( ) 124 { 125 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 126 127 com::sun::star::lang::Locale aLoc( Application::GetSettings().GetUILocale() ); 128 m_ResMgr = new SimpleResMgr( CREATEVERSIONRESMGR_NAME( fps_office ), aLoc ); 129 } 130 131 //------------------------------------- 132 // 133 //------------------------------------- 134 135 ~CResourceProvider_Impl( ) 136 { 137 delete m_ResMgr; 138 } 139 140 //------------------------------------- 141 // 142 //------------------------------------- 143 144 OUString getResString( sal_Int16 aId ) 145 { 146 OUString aResOUString; 147 148 try 149 { 150 OSL_ASSERT( m_ResMgr ); 151 152 // translate the control id to a resource id 153 sal_Int16 aResId = CtrlIdToResId( aId ); 154 155 if ( aResId > -1 ) 156 aResOUString = m_ResMgr->ReadString( aResId ); 157 } 158 catch(...) 159 { 160 } 161 162 return aResOUString; 163 } 164 165 public: 166 SimpleResMgr* m_ResMgr; 167 }; 168 169 //------------------------------------------------------------ 170 // 171 //------------------------------------------------------------ 172 173 CResourceProvider::CResourceProvider( ) : 174 m_pImpl( new CResourceProvider_Impl() ) 175 { 176 } 177 178 //------------------------------------------------------------ 179 // 180 //------------------------------------------------------------ 181 182 CResourceProvider::~CResourceProvider( ) 183 { 184 delete m_pImpl; 185 } 186 187 //------------------------------------------------------------ 188 // 189 //------------------------------------------------------------ 190 191 OUString CResourceProvider::getResString( sal_Int16 aId ) 192 { 193 return m_pImpl->getResString( aId ); 194 } 195