Update ooo320-m1
[ooovba.git] / fpicker / source / unx / gnome / resourceprovider.cxx
blob9197082b241b9a6e8fd9175a04ec577b777eb7cf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: resourceprovider.cxx,v $
10 * $Revision: 1.9 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_fpicker.hxx"
34 //------------------------------------------------------------------------
35 // includes
36 //------------------------------------------------------------------------
37 #include <osl/diagnose.h>
38 #include <rtl/ustrbuf.hxx>
39 #include "resourceprovider.hxx"
40 #include <vos/mutex.hxx>
41 #include <vcl/svapp.hxx>
42 #include <tools/resmgr.hxx>
43 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
44 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
46 #include <svtools/svtools.hrc>
47 #include <svtools/filedlg2.hrc>
49 //------------------------------------------------------------
50 // namespace directives
51 //------------------------------------------------------------
53 using rtl::OUString;
54 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
55 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
57 //------------------------------------------------------------
58 //
59 //------------------------------------------------------------
61 static const char* RES_NAME = "fps_office";
62 static const char* OTHER_RES_NAME = "svt";
64 //------------------------------------------------------------
65 // we have to translate control ids to resource ids
66 //------------------------------------------------------------
68 struct _Entry
70 sal_Int32 ctrlId;
71 sal_Int16 resId;
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_LABEL, STR_SVT_FILEPICKER_VERSION },
83 { LISTBOX_TEMPLATE_LABEL, STR_SVT_FILEPICKER_TEMPLATES },
84 { LISTBOX_IMAGE_TEMPLATE_LABEL, 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 { FILE_PICKER_OVERWRITE, STR_SVT_ALREADYEXISTOVERWRITE }
91 _Entry OtherCtrlIdToResIdTable[] = {
92 { FILE_PICKER_TITLE_OPEN, STR_FILEDLG_OPEN },
93 { FILE_PICKER_TITLE_SAVE, STR_FILEDLG_SAVE },
94 { FILE_PICKER_FILE_TYPE, STR_FILEDLG_TYPE },
98 const sal_Int32 SIZE_TABLE = sizeof( CtrlIdToResIdTable ) / sizeof( _Entry );
99 const sal_Int32 OTHER_SIZE_TABLE = sizeof( OtherCtrlIdToResIdTable ) / sizeof( _Entry );
101 //------------------------------------------------------------
103 //------------------------------------------------------------
105 sal_Int16 CtrlIdToResId( sal_Int32 aControlId )
107 sal_Int16 aResId = -1;
109 for ( sal_Int32 i = 0; i < SIZE_TABLE; i++ )
111 if ( CtrlIdToResIdTable[i].ctrlId == aControlId )
113 aResId = CtrlIdToResIdTable[i].resId;
114 break;
118 return aResId;
121 sal_Int16 OtherCtrlIdToResId( sal_Int32 aControlId )
123 sal_Int16 aResId = -1;
125 for ( sal_Int32 i = 0; i < OTHER_SIZE_TABLE; i++ )
127 if ( OtherCtrlIdToResIdTable[i].ctrlId == aControlId )
129 aResId = OtherCtrlIdToResIdTable[i].resId;
130 break;
134 return aResId;
137 //------------------------------------------------------------
139 //------------------------------------------------------------
141 class CResourceProvider_Impl
143 public:
145 //-------------------------------------
147 //-------------------------------------
149 CResourceProvider_Impl( )
151 m_ResMgr = ResMgr::CreateResMgr( RES_NAME );
152 m_OtherResMgr = ResMgr::CreateResMgr( OTHER_RES_NAME );
155 //-------------------------------------
157 //-------------------------------------
159 ~CResourceProvider_Impl( )
161 delete m_ResMgr;
162 delete m_OtherResMgr;
165 //-------------------------------------
167 //-------------------------------------
169 OUString getResString( sal_Int16 aId )
171 String aResString;
172 OUString aResOUString;
174 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
178 OSL_ASSERT( m_ResMgr && m_OtherResMgr );
180 // translate the control id to a resource id
181 sal_Int16 aResId = CtrlIdToResId( aId );
182 if ( aResId > -1 )
183 aResString = String( ResId( aResId, *m_ResMgr ) );
184 else
186 aResId = OtherCtrlIdToResId( aId );
187 if ( aResId > -1 )
188 aResString = String( ResId( aResId, *m_OtherResMgr ) );
190 if ( aResId > -1 )
191 aResOUString = OUString( aResString );
193 catch(...)
197 return aResOUString;
200 public:
201 ResMgr* m_ResMgr;
202 ResMgr* m_OtherResMgr;
205 //------------------------------------------------------------
207 //------------------------------------------------------------
209 CResourceProvider::CResourceProvider( ) :
210 m_pImpl( new CResourceProvider_Impl() )
214 //------------------------------------------------------------
216 //------------------------------------------------------------
218 CResourceProvider::~CResourceProvider( )
220 delete m_pImpl;
223 //------------------------------------------------------------
225 //------------------------------------------------------------
227 OUString CResourceProvider::getResString( sal_Int32 aId )
229 return m_pImpl->getResString( aId ).replace('~', '_');