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 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_fpicker.hxx" 26 27 //------------------------------------------------------------------------ 28 // includes 29 //------------------------------------------------------------------------ 30 #include <osl/diagnose.h> 31 #include <rtl/ustrbuf.hxx> 32 #include "resourceprovider.hxx" 33 #include <vos/mutex.hxx> 34 #include <vcl/svapp.hxx> 35 #include <tools/resmgr.hxx> 36 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> 37 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 38 39 #include <svtools/svtools.hrc> 40 #include <svtools/filedlg2.hrc> 41 42 //------------------------------------------------------------ 43 // namespace directives 44 //------------------------------------------------------------ 45 46 using rtl::OUString; 47 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds; 48 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds; 49 50 //------------------------------------------------------------ 51 // 52 //------------------------------------------------------------ 53 54 static const char* RES_NAME = "fps_office"; 55 static const char* OTHER_RES_NAME = "svt"; 56 57 //------------------------------------------------------------ 58 // we have to translate control ids to resource ids 59 //------------------------------------------------------------ 60 61 struct _Entry 62 { 63 sal_Int32 ctrlId; 64 sal_Int16 resId; 65 }; 66 67 _Entry CtrlIdToResIdTable[] = { 68 { CHECKBOX_AUTOEXTENSION, STR_SVT_FILEPICKER_AUTO_EXTENSION }, 69 { CHECKBOX_PASSWORD, STR_SVT_FILEPICKER_PASSWORD }, 70 { CHECKBOX_FILTEROPTIONS, STR_SVT_FILEPICKER_FILTER_OPTIONS }, 71 { CHECKBOX_READONLY, STR_SVT_FILEPICKER_READONLY }, 72 { CHECKBOX_LINK, STR_SVT_FILEPICKER_INSERT_AS_LINK }, 73 { CHECKBOX_PREVIEW, STR_SVT_FILEPICKER_SHOW_PREVIEW }, 74 { PUSHBUTTON_PLAY, STR_SVT_FILEPICKER_PLAY }, 75 { LISTBOX_VERSION_LABEL, STR_SVT_FILEPICKER_VERSION }, 76 { LISTBOX_TEMPLATE_LABEL, STR_SVT_FILEPICKER_TEMPLATES }, 77 { LISTBOX_IMAGE_TEMPLATE_LABEL, STR_SVT_FILEPICKER_IMAGE_TEMPLATE }, 78 { CHECKBOX_SELECTION, STR_SVT_FILEPICKER_SELECTION }, 79 { FOLDERPICKER_TITLE, STR_SVT_FOLDERPICKER_DEFAULT_TITLE }, 80 { FOLDER_PICKER_DEF_DESCRIPTION, STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION }, 81 { FILE_PICKER_OVERWRITE, STR_SVT_ALREADYEXISTOVERWRITE }, 82 { FILE_PICKER_ALLFORMATS, STR_SVT_ALLFORMATS } 83 }; 84 85 _Entry OtherCtrlIdToResIdTable[] = { 86 { FILE_PICKER_TITLE_OPEN, STR_FILEDLG_OPEN }, 87 { FILE_PICKER_TITLE_SAVE, STR_FILEDLG_SAVE }, 88 { FILE_PICKER_FILE_TYPE, STR_FILEDLG_TYPE }, 89 }; 90 91 92 const sal_Int32 SIZE_TABLE = sizeof( CtrlIdToResIdTable ) / sizeof( _Entry ); 93 const sal_Int32 OTHER_SIZE_TABLE = sizeof( OtherCtrlIdToResIdTable ) / sizeof( _Entry ); 94 95 //------------------------------------------------------------ 96 // 97 //------------------------------------------------------------ 98 99 sal_Int16 CtrlIdToResId( sal_Int32 aControlId ) 100 { 101 sal_Int16 aResId = -1; 102 103 for ( sal_Int32 i = 0; i < SIZE_TABLE; i++ ) 104 { 105 if ( CtrlIdToResIdTable[i].ctrlId == aControlId ) 106 { 107 aResId = CtrlIdToResIdTable[i].resId; 108 break; 109 } 110 } 111 112 return aResId; 113 } 114 115 sal_Int16 OtherCtrlIdToResId( sal_Int32 aControlId ) 116 { 117 sal_Int16 aResId = -1; 118 119 for ( sal_Int32 i = 0; i < OTHER_SIZE_TABLE; i++ ) 120 { 121 if ( OtherCtrlIdToResIdTable[i].ctrlId == aControlId ) 122 { 123 aResId = OtherCtrlIdToResIdTable[i].resId; 124 break; 125 } 126 } 127 128 return aResId; 129 } 130 131 //------------------------------------------------------------ 132 // 133 //------------------------------------------------------------ 134 135 class CResourceProvider_Impl 136 { 137 public: 138 139 //------------------------------------- 140 // 141 //------------------------------------- 142 143 CResourceProvider_Impl( ) 144 { 145 m_ResMgr = ResMgr::CreateResMgr( RES_NAME ); 146 m_OtherResMgr = ResMgr::CreateResMgr( OTHER_RES_NAME ); 147 } 148 149 //------------------------------------- 150 // 151 //------------------------------------- 152 153 ~CResourceProvider_Impl( ) 154 { 155 delete m_ResMgr; 156 delete m_OtherResMgr; 157 } 158 159 //------------------------------------- 160 // 161 //------------------------------------- 162 163 OUString getResString( sal_Int16 aId ) 164 { 165 String aResString; 166 OUString aResOUString; 167 168 try 169 { 170 OSL_ASSERT( m_ResMgr && m_OtherResMgr ); 171 172 // translate the control id to a resource id 173 sal_Int16 aResId = CtrlIdToResId( aId ); 174 if ( aResId > -1 ) 175 aResString = String( ResId( aResId, *m_ResMgr ) ); 176 else 177 { 178 aResId = OtherCtrlIdToResId( aId ); 179 if ( aResId > -1 ) 180 aResString = String( ResId( aResId, *m_OtherResMgr ) ); 181 } 182 if ( aResId > -1 ) 183 aResOUString = OUString( aResString ); 184 } 185 catch(...) 186 { 187 } 188 189 return aResOUString; 190 } 191 192 public: 193 ResMgr* m_ResMgr; 194 ResMgr* m_OtherResMgr; 195 }; 196 197 //------------------------------------------------------------ 198 // 199 //------------------------------------------------------------ 200 201 CResourceProvider::CResourceProvider( ) : 202 m_pImpl( new CResourceProvider_Impl() ) 203 { 204 } 205 206 //------------------------------------------------------------ 207 // 208 //------------------------------------------------------------ 209 210 CResourceProvider::~CResourceProvider( ) 211 { 212 delete m_pImpl; 213 } 214 215 //------------------------------------------------------------ 216 // 217 //------------------------------------------------------------ 218 219 OUString CResourceProvider::getResString( sal_Int32 aId ) 220 { 221 return m_pImpl->getResString( aId ).replace('~', '_'); 222 } 223