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