1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: resourceprovider.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 //------------------------------------------------------------------------
33 //------------------------------------------------------------------------
35 #include <osl/diagnose.h>
36 #include <rtl/ustrbuf.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>
43 #ifndef _SVTOOLS_SVTOOLS_HRC_
44 #include <svtools/svtools.hrc>
47 #ifndef _SVTOOLS_FILEDLG2_HRC_
48 #include <svtools/filedlg2.hrc>
50 #include "NSString_OOoAdditions.hxx"
52 #include "resourceprovider.hxx"
54 //------------------------------------------------------------
55 // namespace directives
56 //------------------------------------------------------------
59 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds
;
60 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds
;
62 //------------------------------------------------------------
64 //------------------------------------------------------------
66 static const char* RES_NAME
= "fps_office";
67 static const char* OTHER_RES_NAME
= "svt";
69 //------------------------------------------------------------
70 // we have to translate control ids to resource ids
71 //------------------------------------------------------------
79 _Entry CtrlIdToResIdTable
[] = {
80 { CHECKBOX_AUTOEXTENSION
, STR_SVT_FILEPICKER_AUTO_EXTENSION
},
81 { CHECKBOX_PASSWORD
, STR_SVT_FILEPICKER_PASSWORD
},
82 { CHECKBOX_FILTEROPTIONS
, STR_SVT_FILEPICKER_FILTER_OPTIONS
},
83 { CHECKBOX_READONLY
, STR_SVT_FILEPICKER_READONLY
},
84 { CHECKBOX_LINK
, STR_SVT_FILEPICKER_INSERT_AS_LINK
},
85 { CHECKBOX_PREVIEW
, STR_SVT_FILEPICKER_SHOW_PREVIEW
},
86 { PUSHBUTTON_PLAY
, STR_SVT_FILEPICKER_PLAY
},
87 { LISTBOX_VERSION_LABEL
, STR_SVT_FILEPICKER_VERSION
},
88 { LISTBOX_TEMPLATE_LABEL
, STR_SVT_FILEPICKER_TEMPLATES
},
89 { LISTBOX_IMAGE_TEMPLATE_LABEL
, STR_SVT_FILEPICKER_IMAGE_TEMPLATE
},
90 { CHECKBOX_SELECTION
, STR_SVT_FILEPICKER_SELECTION
},
91 { FOLDERPICKER_TITLE
, STR_SVT_FOLDERPICKER_DEFAULT_TITLE
},
92 { FOLDER_PICKER_DEF_DESCRIPTION
, STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION
},
93 { FILE_PICKER_OVERWRITE
, STR_SVT_ALREADYEXISTOVERWRITE
},
94 { LISTBOX_FILTER_LABEL
, STR_SVT_FILEPICKER_FILTER_TITLE
}
97 _Entry OtherCtrlIdToResIdTable
[] = {
98 { FILE_PICKER_TITLE_OPEN
, STR_FILEDLG_OPEN
},
99 { FILE_PICKER_TITLE_SAVE
, STR_FILEDLG_SAVE
},
100 { FILE_PICKER_FILE_TYPE
, STR_FILEDLG_TYPE
}
104 const sal_Int32 SIZE_TABLE
= sizeof( CtrlIdToResIdTable
) / sizeof( _Entry
);
105 const sal_Int32 OTHER_SIZE_TABLE
= sizeof( OtherCtrlIdToResIdTable
) / sizeof( _Entry
);
107 //------------------------------------------------------------
109 //------------------------------------------------------------
111 sal_Int16
CtrlIdToResId( sal_Int32 aControlId
)
113 sal_Int16 aResId
= -1;
115 for ( sal_Int32 i
= 0; i
< SIZE_TABLE
; i
++ )
117 if ( CtrlIdToResIdTable
[i
].ctrlId
== aControlId
)
119 aResId
= CtrlIdToResIdTable
[i
].resId
;
127 sal_Int16
OtherCtrlIdToResId( sal_Int32 aControlId
)
129 sal_Int16 aResId
= -1;
131 for ( sal_Int32 i
= 0; i
< OTHER_SIZE_TABLE
; i
++ )
133 if ( OtherCtrlIdToResIdTable
[i
].ctrlId
== aControlId
)
135 aResId
= OtherCtrlIdToResIdTable
[i
].resId
;
143 //------------------------------------------------------------
145 //------------------------------------------------------------
147 class CResourceProvider_Impl
151 //-------------------------------------
153 //-------------------------------------
155 CResourceProvider_Impl( )
157 m_ResMgr
= ResMgr::CreateResMgr( RES_NAME
);
158 m_OtherResMgr
= ResMgr::CreateResMgr( OTHER_RES_NAME
);
161 //-------------------------------------
163 //-------------------------------------
165 ~CResourceProvider_Impl( )
168 delete m_OtherResMgr
;
171 //-------------------------------------
173 //-------------------------------------
175 NSString
* getResString( sal_Int16 aId
)
178 OUString aResOUString
;
180 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
184 OSL_ASSERT( m_ResMgr
&& m_OtherResMgr
);
186 // translate the control id to a resource id
187 sal_Int16 aResId
= CtrlIdToResId( aId
);
189 aResString
= String( ResId( aResId
, *m_ResMgr
) );
192 aResId
= OtherCtrlIdToResId( aId
);
194 aResString
= String( ResId( aResId
, *m_OtherResMgr
) );
198 aResOUString
= OUString( aResString
);
204 return [NSString stringWithOUString
:aResOUString
];
209 ResMgr
* m_OtherResMgr
;
212 //------------------------------------------------------------
214 //------------------------------------------------------------
216 CResourceProvider::CResourceProvider( ) :
217 m_pImpl( new CResourceProvider_Impl() )
221 //------------------------------------------------------------
223 //------------------------------------------------------------
225 CResourceProvider::~CResourceProvider( )
230 //------------------------------------------------------------
232 //------------------------------------------------------------
234 NSString
* CResourceProvider::getResString( sal_Int32 aId
)
236 NSString
* sImmutable
= m_pImpl
->getResString( aId
);
237 NSMutableString
*sMutableString
= [NSMutableString stringWithString
:sImmutable
];
238 [sMutableString replaceOccurrencesOfString
:@
"~" withString
:@
"" options
:0 range
:NSMakeRange(0, [sMutableString length
])];
240 NSString
*result
= [NSString stringWithString
:sMutableString
];