Update ooo320-m1
[ooovba.git] / fpicker / source / win32 / misc / resourceprovider.cxx
blob803339892aa78bf02d97fa4ddab7f4bd7f396f17
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.13 $
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>
43 #ifndef _TOOLS_SIMPLERESMGR_HXX
44 #include <tools/simplerm.hxx>
45 #endif
46 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
47 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
49 #include <svtools/svtools.hrc>
51 //------------------------------------------------------------
52 // namespace directives
53 //------------------------------------------------------------
55 using rtl::OUString;
56 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
57 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
59 //------------------------------------------------------------
60 //
61 //------------------------------------------------------------
63 #define FOLDERPICKER_TITLE 500
64 #define FOLDER_PICKER_DEF_DESCRIPTION 501
66 //------------------------------------------------------------
67 // we have to translate control ids to resource ids
68 //------------------------------------------------------------
70 struct _Entry
72 sal_Int32 ctrlId;
73 sal_Int16 resId;
76 _Entry CtrlIdToResIdTable[] = {
77 { CHECKBOX_AUTOEXTENSION, STR_SVT_FILEPICKER_AUTO_EXTENSION },
78 { CHECKBOX_PASSWORD, STR_SVT_FILEPICKER_PASSWORD },
79 { CHECKBOX_FILTEROPTIONS, STR_SVT_FILEPICKER_FILTER_OPTIONS },
80 { CHECKBOX_READONLY, STR_SVT_FILEPICKER_READONLY },
81 { CHECKBOX_LINK, STR_SVT_FILEPICKER_INSERT_AS_LINK },
82 { CHECKBOX_PREVIEW, STR_SVT_FILEPICKER_SHOW_PREVIEW },
83 { PUSHBUTTON_PLAY, STR_SVT_FILEPICKER_PLAY },
84 { LISTBOX_VERSION_LABEL, STR_SVT_FILEPICKER_VERSION },
85 { LISTBOX_TEMPLATE_LABEL, STR_SVT_FILEPICKER_TEMPLATES },
86 { LISTBOX_IMAGE_TEMPLATE_LABEL, STR_SVT_FILEPICKER_IMAGE_TEMPLATE },
87 { CHECKBOX_SELECTION, STR_SVT_FILEPICKER_SELECTION },
88 { FOLDERPICKER_TITLE, STR_SVT_FOLDERPICKER_DEFAULT_TITLE },
89 { FOLDER_PICKER_DEF_DESCRIPTION, STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION }
92 const sal_Int32 SIZE_TABLE = sizeof( CtrlIdToResIdTable ) / sizeof( _Entry );
94 //------------------------------------------------------------
96 //------------------------------------------------------------
98 sal_Int16 CtrlIdToResId( sal_Int32 aControlId )
100 sal_Int16 aResId = -1;
102 for ( sal_Int32 i = 0; i < SIZE_TABLE; i++ )
104 if ( CtrlIdToResIdTable[i].ctrlId == aControlId )
106 aResId = CtrlIdToResIdTable[i].resId;
107 break;
111 return aResId;
114 //------------------------------------------------------------
116 //------------------------------------------------------------
118 class CResourceProvider_Impl
120 public:
122 //-------------------------------------
124 //-------------------------------------
126 CResourceProvider_Impl( )
128 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
130 com::sun::star::lang::Locale aLoc( Application::GetSettings().GetUILocale() );
131 m_ResMgr = new SimpleResMgr( CREATEVERSIONRESMGR_NAME( fps_office ), aLoc );
134 //-------------------------------------
136 //-------------------------------------
138 ~CResourceProvider_Impl( )
140 delete m_ResMgr;
143 //-------------------------------------
145 //-------------------------------------
147 OUString getResString( sal_Int16 aId )
149 OUString aResOUString;
153 OSL_ASSERT( m_ResMgr );
155 // translate the control id to a resource id
156 sal_Int16 aResId = CtrlIdToResId( aId );
158 if ( aResId > -1 )
159 aResOUString = m_ResMgr->ReadString( aResId );
161 catch(...)
165 return aResOUString;
168 public:
169 SimpleResMgr* m_ResMgr;
172 //------------------------------------------------------------
174 //------------------------------------------------------------
176 CResourceProvider::CResourceProvider( ) :
177 m_pImpl( new CResourceProvider_Impl() )
181 //------------------------------------------------------------
183 //------------------------------------------------------------
185 CResourceProvider::~CResourceProvider( )
187 delete m_pImpl;
190 //------------------------------------------------------------
192 //------------------------------------------------------------
194 OUString CResourceProvider::getResString( sal_Int16 aId )
196 return m_pImpl->getResString( aId );