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 //------------------------------------------------------------------------ 25 // includes 26 //------------------------------------------------------------------------ 27 28 #include <osl/diagnose.h> 29 #include <rtl/ustrbuf.hxx> 30 #include "resourceprovider.hxx" 31 #include <tools/resmgr.hxx> 32 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> 33 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 34 35 #include <svtools/svtools.hrc> 36 37 //------------------------------------------------------------ 38 // namespace directives 39 //------------------------------------------------------------ 40 41 using rtl::OUString; 42 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds; 43 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds; 44 45 //------------------------------------------------------------ 46 // 47 //------------------------------------------------------------ 48 49 #define RES_NAME svt 50 51 // because the label of a listbox is 52 // a control itself (static text) we 53 // have defined a control id for this 54 // label which is the listbox control 55 // id + 100 56 #define LB_LABEL_OFFSET 100 57 58 const rtl::OUString TILDE = OUString::createFromAscii( "~" ); 59 const sal_Unicode TILDE_SIGN = L'~'; 60 61 #define FOLDERPICKER_TITLE 500 62 #define FOLDER_PICKER_DEF_DESCRIPTION 501 63 64 //------------------------------------------------------------ 65 // we have to translate control ids to resource ids 66 //------------------------------------------------------------ 67 68 struct _Entry 69 { 70 sal_Int32 ctrlId; 71 sal_Int16 resId; 72 }; 73 74 _Entry CtrlIdToResIdTable[] = { 75 { CHECKBOX_AUTOEXTENSION, STR_SVT_FILEPICKER_AUTO_EXTENSION }, 76 { CHECKBOX_PASSWORD, STR_SVT_FILEPICKER_PASSWORD }, 77 { CHECKBOX_FILTEROPTIONS, STR_SVT_FILEPICKER_FILTER_OPTIONS }, 78 { CHECKBOX_READONLY, STR_SVT_FILEPICKER_READONLY }, 79 { CHECKBOX_LINK, STR_SVT_FILEPICKER_INSERT_AS_LINK }, 80 { CHECKBOX_PREVIEW, STR_SVT_FILEPICKER_SHOW_PREVIEW }, 81 { PUSHBUTTON_PLAY, STR_SVT_FILEPICKER_PLAY }, 82 { LISTBOX_VERSION + LB_LABEL_OFFSET, STR_SVT_FILEPICKER_VERSION }, 83 { LISTBOX_TEMPLATE + LB_LABEL_OFFSET, STR_SVT_FILEPICKER_TEMPLATES }, 84 { LISTBOX_IMAGE_TEMPLATE + LB_LABEL_OFFSET, STR_SVT_FILEPICKER_IMAGE_TEMPLATE }, 85 { CHECKBOX_SELECTION, STR_SVT_FILEPICKER_SELECTION }, 86 { FOLDERPICKER_TITLE, STR_SVT_FOLDERPICKER_DEFAULT_TITLE }, 87 { FOLDER_PICKER_DEF_DESCRIPTION, STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION } 88 }; 89 90 const sal_Int32 SIZE_TABLE = sizeof( CtrlIdToResIdTable ) / sizeof( _Entry ); 91 92 //------------------------------------------------------------ 93 // 94 //------------------------------------------------------------ 95 96 sal_Int16 CtrlIdToResId( sal_Int32 aControlId ) 97 { 98 sal_Int16 aResId = -1; 99 100 for ( sal_Int32 i = 0; i < SIZE_TABLE; i++ ) 101 { 102 if ( CtrlIdToResIdTable[i].ctrlId == aControlId ) 103 { 104 aResId = CtrlIdToResIdTable[i].resId; 105 break; 106 } 107 } 108 109 return aResId; 110 } 111 112 //------------------------------------------------------------ 113 // 114 //------------------------------------------------------------ 115 116 class CResourceProvider_Impl 117 { 118 public: 119 120 //------------------------------------- 121 // 122 //------------------------------------- 123 124 CResourceProvider_Impl( ) 125 { 126 m_ResMgr = CREATEVERSIONRESMGR( RES_NAME ); 127 } 128 129 //------------------------------------- 130 // 131 //------------------------------------- 132 133 ~CResourceProvider_Impl( ) 134 { 135 delete m_ResMgr; 136 } 137 138 //------------------------------------- 139 // 140 //------------------------------------- 141 142 OUString getResString( sal_Int16 aId ) 143 { 144 String aResString; 145 OUString aResOUString; 146 147 try 148 { 149 OSL_ASSERT( m_ResMgr ); 150 151 // translate the control id to a resource id 152 sal_Int16 aResId = CtrlIdToResId( aId ); 153 154 if ( aResId > -1 ) 155 { 156 aResString = String( ResId( aResId, m_ResMgr ) ); 157 aResOUString = OUString( aResString ); 158 159 // remove '~' signs, if there are two '~' signs 160 // in a row we remove only one of them 161 if ( aResOUString.indexOf( TILDE ) > -1 ) 162 { 163 sal_Int32 nStrLen = aResOUString.getLength( ); 164 rtl::OUStringBuffer aBuffer( nStrLen ); 165 sal_Int32 i = 0; 166 const sal_Unicode* pPos = aResOUString.getStr( ); 167 const sal_Unicode* pNext = aResOUString.getStr( ) + 1; 168 const sal_Unicode* pEnd = aResOUString.getStr( ) + nStrLen; 169 170 while( pPos < pEnd ) 171 { 172 // we insert the next character only if the current character 173 // in not a '~' or the following character is also a '~' 174 if ( (*pPos != TILDE_SIGN) || 175 ((*pPos == TILDE_SIGN) && (pNext < pEnd) && (*pNext == TILDE_SIGN)) ) 176 { 177 aBuffer.insert( i, *pPos ); 178 i++; 179 } 180 181 pPos++; 182 pNext++; 183 } 184 185 aResOUString = aBuffer.makeStringAndClear( ); 186 } 187 } 188 } 189 catch(...) 190 { 191 } 192 193 return aResOUString; 194 } 195 196 public: 197 ResMgr* m_ResMgr; 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 ); 225 } 226