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 #include <tools/resmgr.hxx> 40 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> 41 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 42 43 #include <svtools/svtools.hrc> 44 #include <svtools/filedlg2.hrc> 45 46 //------------------------------------------------------------ 47 // namespace directives 48 //------------------------------------------------------------ 49 50 using rtl::OUString; 51 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds; 52 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds; 53 54 //------------------------------------------------------------ 55 // 56 //------------------------------------------------------------ 57 58 static const char* RES_NAME = "fps_office"; 59 static const char* OTHER_RES_NAME = "svt"; 60 61 //------------------------------------------------------------ 62 // we have to translate control ids to resource ids 63 //------------------------------------------------------------ 64 65 struct _Entry 66 { 67 sal_Int32 ctrlId; 68 sal_Int16 resId; 69 }; 70 71 _Entry CtrlIdToResIdTable[] = { 72 { CHECKBOX_AUTOEXTENSION, STR_SVT_FILEPICKER_AUTO_EXTENSION }, 73 { CHECKBOX_PASSWORD, STR_SVT_FILEPICKER_PASSWORD }, 74 { CHECKBOX_FILTEROPTIONS, STR_SVT_FILEPICKER_FILTER_OPTIONS }, 75 { CHECKBOX_READONLY, STR_SVT_FILEPICKER_READONLY }, 76 { CHECKBOX_LINK, STR_SVT_FILEPICKER_INSERT_AS_LINK }, 77 { CHECKBOX_PREVIEW, STR_SVT_FILEPICKER_SHOW_PREVIEW }, 78 { PUSHBUTTON_PLAY, STR_SVT_FILEPICKER_PLAY }, 79 { LISTBOX_VERSION_LABEL, STR_SVT_FILEPICKER_VERSION }, 80 { LISTBOX_TEMPLATE_LABEL, STR_SVT_FILEPICKER_TEMPLATES }, 81 { LISTBOX_IMAGE_TEMPLATE_LABEL, STR_SVT_FILEPICKER_IMAGE_TEMPLATE }, 82 { CHECKBOX_SELECTION, STR_SVT_FILEPICKER_SELECTION }, 83 { FOLDERPICKER_TITLE, STR_SVT_FOLDERPICKER_DEFAULT_TITLE }, 84 { FOLDER_PICKER_DEF_DESCRIPTION, STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION }, 85 { FILE_PICKER_OVERWRITE, STR_SVT_ALREADYEXISTOVERWRITE } 86 }; 87 88 _Entry OtherCtrlIdToResIdTable[] = { 89 { FILE_PICKER_TITLE_OPEN, STR_FILEDLG_OPEN }, 90 { FILE_PICKER_TITLE_SAVE, STR_FILEDLG_SAVE }, 91 { FILE_PICKER_FILE_TYPE, STR_FILEDLG_TYPE }, 92 }; 93 94 95 const sal_Int32 SIZE_TABLE = sizeof( CtrlIdToResIdTable ) / sizeof( _Entry ); 96 const sal_Int32 OTHER_SIZE_TABLE = sizeof( OtherCtrlIdToResIdTable ) / sizeof( _Entry ); 97 98 //------------------------------------------------------------ 99 // 100 //------------------------------------------------------------ 101 102 sal_Int16 CtrlIdToResId( sal_Int32 aControlId ) 103 { 104 sal_Int16 aResId = -1; 105 106 for ( sal_Int32 i = 0; i < SIZE_TABLE; i++ ) 107 { 108 if ( CtrlIdToResIdTable[i].ctrlId == aControlId ) 109 { 110 aResId = CtrlIdToResIdTable[i].resId; 111 break; 112 } 113 } 114 115 return aResId; 116 } 117 118 sal_Int16 OtherCtrlIdToResId( sal_Int32 aControlId ) 119 { 120 sal_Int16 aResId = -1; 121 122 for ( sal_Int32 i = 0; i < OTHER_SIZE_TABLE; i++ ) 123 { 124 if ( OtherCtrlIdToResIdTable[i].ctrlId == aControlId ) 125 { 126 aResId = OtherCtrlIdToResIdTable[i].resId; 127 break; 128 } 129 } 130 131 return aResId; 132 } 133 134 //------------------------------------------------------------ 135 // 136 //------------------------------------------------------------ 137 138 class CResourceProvider_Impl 139 { 140 public: 141 142 //------------------------------------- 143 // 144 //------------------------------------- 145 146 CResourceProvider_Impl( ) 147 { 148 m_ResMgr = ResMgr::CreateResMgr( RES_NAME ); 149 m_OtherResMgr = ResMgr::CreateResMgr( OTHER_RES_NAME ); 150 } 151 152 //------------------------------------- 153 // 154 //------------------------------------- 155 156 ~CResourceProvider_Impl( ) 157 { 158 delete m_ResMgr; 159 delete m_OtherResMgr; 160 } 161 162 //------------------------------------- 163 // 164 //------------------------------------- 165 166 OUString getResString( sal_Int16 aId ) 167 { 168 String aResString; 169 OUString aResOUString; 170 171 try 172 { 173 OSL_ASSERT( m_ResMgr && m_OtherResMgr ); 174 175 // translate the control id to a resource id 176 sal_Int16 aResId = CtrlIdToResId( aId ); 177 if ( aResId > -1 ) 178 aResString = String( ResId( aResId, *m_ResMgr ) ); 179 else 180 { 181 aResId = OtherCtrlIdToResId( aId ); 182 if ( aResId > -1 ) 183 aResString = String( ResId( aResId, *m_OtherResMgr ) ); 184 } 185 if ( aResId > -1 ) 186 aResOUString = OUString( aResString ); 187 } 188 catch(...) 189 { 190 } 191 192 return aResOUString; 193 } 194 195 public: 196 ResMgr* m_ResMgr; 197 ResMgr* m_OtherResMgr; 198 }; 199 200 //------------------------------------------------------------ 201 // 202 //------------------------------------------------------------ 203 204 CResourceProvider::CResourceProvider( ) : 205 m_pImpl( new CResourceProvider_Impl() ) 206 { 207 } 208 209 //------------------------------------------------------------ 210 // 211 //------------------------------------------------------------ 212 213 CResourceProvider::~CResourceProvider( ) 214 { 215 delete m_pImpl; 216 } 217 218 //------------------------------------------------------------ 219 // 220 //------------------------------------------------------------ 221 222 OUString CResourceProvider::getResString( sal_Int32 aId ) 223 { 224 return m_pImpl->getResString( aId ).replace('~', '_'); 225 } 226