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
10*b557fc96SAndrew Rist  *
11*b557fc96SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b557fc96SAndrew Rist  *
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.
19*b557fc96SAndrew Rist  *
20*b557fc96SAndrew Rist  *************************************************************/
21*b557fc96SAndrew Rist 
22*b557fc96SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_fpicker.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //------------------------------------------------------------------------
28cdf0e10cSrcweir // includes
29cdf0e10cSrcweir //------------------------------------------------------------------------
30cdf0e10cSrcweir #include <osl/diagnose.h>
31cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
32cdf0e10cSrcweir #include "resourceprovider.hxx"
33cdf0e10cSrcweir #include <vos/mutex.hxx>
34cdf0e10cSrcweir #include <vcl/svapp.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifndef _TOOLS_SIMPLERESMGR_HXX
37cdf0e10cSrcweir #include <tools/simplerm.hxx>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
40cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <svtools/svtools.hrc>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //------------------------------------------------------------
45cdf0e10cSrcweir // namespace directives
46cdf0e10cSrcweir //------------------------------------------------------------
47cdf0e10cSrcweir 
48cdf0e10cSrcweir using rtl::OUString;
49cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
50cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir //------------------------------------------------------------
53cdf0e10cSrcweir //
54cdf0e10cSrcweir //------------------------------------------------------------
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #define FOLDERPICKER_TITLE            500
57cdf0e10cSrcweir #define FOLDER_PICKER_DEF_DESCRIPTION 501
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //------------------------------------------------------------
60cdf0e10cSrcweir // we have to translate control ids to resource ids
61cdf0e10cSrcweir //------------------------------------------------------------
62cdf0e10cSrcweir 
63cdf0e10cSrcweir struct _Entry
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     sal_Int32 ctrlId;
66cdf0e10cSrcweir     sal_Int16 resId;
67cdf0e10cSrcweir };
68cdf0e10cSrcweir 
69cdf0e10cSrcweir _Entry CtrlIdToResIdTable[] = {
70cdf0e10cSrcweir     { CHECKBOX_AUTOEXTENSION,                   STR_SVT_FILEPICKER_AUTO_EXTENSION },
71cdf0e10cSrcweir     { CHECKBOX_PASSWORD,                        STR_SVT_FILEPICKER_PASSWORD },
72cdf0e10cSrcweir     { CHECKBOX_FILTEROPTIONS,                   STR_SVT_FILEPICKER_FILTER_OPTIONS },
73cdf0e10cSrcweir     { CHECKBOX_READONLY,                        STR_SVT_FILEPICKER_READONLY },
74cdf0e10cSrcweir     { CHECKBOX_LINK,                            STR_SVT_FILEPICKER_INSERT_AS_LINK },
75cdf0e10cSrcweir     { CHECKBOX_PREVIEW,                         STR_SVT_FILEPICKER_SHOW_PREVIEW },
76cdf0e10cSrcweir     { PUSHBUTTON_PLAY,                          STR_SVT_FILEPICKER_PLAY },
77cdf0e10cSrcweir     { LISTBOX_VERSION_LABEL,                    STR_SVT_FILEPICKER_VERSION },
78cdf0e10cSrcweir     { LISTBOX_TEMPLATE_LABEL,                   STR_SVT_FILEPICKER_TEMPLATES },
79cdf0e10cSrcweir     { LISTBOX_IMAGE_TEMPLATE_LABEL,             STR_SVT_FILEPICKER_IMAGE_TEMPLATE },
80cdf0e10cSrcweir     { CHECKBOX_SELECTION,                       STR_SVT_FILEPICKER_SELECTION },
81cdf0e10cSrcweir     { FOLDERPICKER_TITLE,                       STR_SVT_FOLDERPICKER_DEFAULT_TITLE },
82cdf0e10cSrcweir     { FOLDER_PICKER_DEF_DESCRIPTION,            STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION }
83cdf0e10cSrcweir };
84cdf0e10cSrcweir 
85cdf0e10cSrcweir const sal_Int32 SIZE_TABLE = sizeof( CtrlIdToResIdTable ) / sizeof( _Entry );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir //------------------------------------------------------------
88cdf0e10cSrcweir //
89cdf0e10cSrcweir //------------------------------------------------------------
90cdf0e10cSrcweir 
CtrlIdToResId(sal_Int32 aControlId)91cdf0e10cSrcweir sal_Int16 CtrlIdToResId( sal_Int32 aControlId )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     sal_Int16 aResId = -1;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < SIZE_TABLE; i++ )
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         if ( CtrlIdToResIdTable[i].ctrlId == aControlId )
98cdf0e10cSrcweir         {
99cdf0e10cSrcweir             aResId = CtrlIdToResIdTable[i].resId;
100cdf0e10cSrcweir             break;
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     return aResId;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir //------------------------------------------------------------
108cdf0e10cSrcweir //
109cdf0e10cSrcweir //------------------------------------------------------------
110cdf0e10cSrcweir 
111cdf0e10cSrcweir class CResourceProvider_Impl
112cdf0e10cSrcweir {
113cdf0e10cSrcweir public:
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     //-------------------------------------
116cdf0e10cSrcweir     //
117cdf0e10cSrcweir     //-------------------------------------
118cdf0e10cSrcweir 
CResourceProvider_Impl()119cdf0e10cSrcweir     CResourceProvider_Impl( )
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir         const ::vos::OGuard aGuard( Application::GetSolarMutex() );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 		com::sun::star::lang::Locale aLoc( Application::GetSettings().GetUILocale() );
124cdf0e10cSrcweir         m_ResMgr = new SimpleResMgr( CREATEVERSIONRESMGR_NAME( fps_office ), aLoc );
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     //-------------------------------------
128cdf0e10cSrcweir     //
129cdf0e10cSrcweir     //-------------------------------------
130cdf0e10cSrcweir 
~CResourceProvider_Impl()131cdf0e10cSrcweir     ~CResourceProvider_Impl( )
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         delete m_ResMgr;
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     //-------------------------------------
137cdf0e10cSrcweir     //
138cdf0e10cSrcweir     //-------------------------------------
139cdf0e10cSrcweir 
getResString(sal_Int16 aId)140cdf0e10cSrcweir     OUString getResString( sal_Int16 aId )
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         OUString aResOUString;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         try
145cdf0e10cSrcweir         {
146cdf0e10cSrcweir             OSL_ASSERT( m_ResMgr );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir             // translate the control id to a resource id
149cdf0e10cSrcweir             sal_Int16 aResId = CtrlIdToResId( aId );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir             if ( aResId > -1 )
152cdf0e10cSrcweir                 aResOUString = m_ResMgr->ReadString( aResId );
153cdf0e10cSrcweir         }
154cdf0e10cSrcweir         catch(...)
155cdf0e10cSrcweir         {
156cdf0e10cSrcweir         }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         return aResOUString;
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir public:
162cdf0e10cSrcweir     SimpleResMgr* m_ResMgr;
163cdf0e10cSrcweir };
164cdf0e10cSrcweir 
165cdf0e10cSrcweir //------------------------------------------------------------
166cdf0e10cSrcweir //
167cdf0e10cSrcweir //------------------------------------------------------------
168cdf0e10cSrcweir 
CResourceProvider()169cdf0e10cSrcweir CResourceProvider::CResourceProvider( ) :
170cdf0e10cSrcweir     m_pImpl( new CResourceProvider_Impl() )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir //------------------------------------------------------------
175cdf0e10cSrcweir //
176cdf0e10cSrcweir //------------------------------------------------------------
177cdf0e10cSrcweir 
~CResourceProvider()178cdf0e10cSrcweir CResourceProvider::~CResourceProvider( )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir     delete m_pImpl;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir //------------------------------------------------------------
184cdf0e10cSrcweir //
185cdf0e10cSrcweir //------------------------------------------------------------
186cdf0e10cSrcweir 
getResString(sal_Int16 aId)187cdf0e10cSrcweir OUString CResourceProvider::getResString( sal_Int16 aId )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir    return m_pImpl->getResString( aId );
190cdf0e10cSrcweir }
191