1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_fpicker.hxx"
26 
27 //------------------------------------------------------------------------
28 // includes
29 //------------------------------------------------------------------------
30 #include <osl/diagnose.h>
31 #include <rtl/ustrbuf.hxx>
32 #include "resourceprovider.hxx"
33 #include <vos/mutex.hxx>
34 #include <vcl/svapp.hxx>
35 
36 #ifndef _TOOLS_SIMPLERESMGR_HXX
37 #include <tools/simplerm.hxx>
38 #endif
39 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
40 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
41 
42 #include <svtools/svtools.hrc>
43 
44 //------------------------------------------------------------
45 // namespace directives
46 //------------------------------------------------------------
47 
48 using rtl::OUString;
49 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
50 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
51 
52 //------------------------------------------------------------
53 //
54 //------------------------------------------------------------
55 
56 #define FOLDERPICKER_TITLE            500
57 #define FOLDER_PICKER_DEF_DESCRIPTION 501
58 
59 //------------------------------------------------------------
60 // we have to translate control ids to resource ids
61 //------------------------------------------------------------
62 
63 struct _Entry
64 {
65     sal_Int32 ctrlId;
66     sal_Int16 resId;
67 };
68 
69 _Entry CtrlIdToResIdTable[] = {
70     { CHECKBOX_AUTOEXTENSION,                   STR_SVT_FILEPICKER_AUTO_EXTENSION },
71     { CHECKBOX_PASSWORD,                        STR_SVT_FILEPICKER_PASSWORD },
72     { CHECKBOX_FILTEROPTIONS,                   STR_SVT_FILEPICKER_FILTER_OPTIONS },
73     { CHECKBOX_READONLY,                        STR_SVT_FILEPICKER_READONLY },
74     { CHECKBOX_LINK,                            STR_SVT_FILEPICKER_INSERT_AS_LINK },
75     { CHECKBOX_PREVIEW,                         STR_SVT_FILEPICKER_SHOW_PREVIEW },
76     { PUSHBUTTON_PLAY,                          STR_SVT_FILEPICKER_PLAY },
77     { LISTBOX_VERSION_LABEL,                    STR_SVT_FILEPICKER_VERSION },
78     { LISTBOX_TEMPLATE_LABEL,                   STR_SVT_FILEPICKER_TEMPLATES },
79     { LISTBOX_IMAGE_TEMPLATE_LABEL,             STR_SVT_FILEPICKER_IMAGE_TEMPLATE },
80     { CHECKBOX_SELECTION,                       STR_SVT_FILEPICKER_SELECTION },
81     { FOLDERPICKER_TITLE,                       STR_SVT_FOLDERPICKER_DEFAULT_TITLE },
82     { FOLDER_PICKER_DEF_DESCRIPTION,            STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION }
83 };
84 
85 const sal_Int32 SIZE_TABLE = sizeof( CtrlIdToResIdTable ) / sizeof( _Entry );
86 
87 //------------------------------------------------------------
88 //
89 //------------------------------------------------------------
90 
CtrlIdToResId(sal_Int32 aControlId)91 sal_Int16 CtrlIdToResId( sal_Int32 aControlId )
92 {
93     sal_Int16 aResId = -1;
94 
95     for ( sal_Int32 i = 0; i < SIZE_TABLE; i++ )
96     {
97         if ( CtrlIdToResIdTable[i].ctrlId == aControlId )
98         {
99             aResId = CtrlIdToResIdTable[i].resId;
100             break;
101         }
102     }
103 
104     return aResId;
105 }
106 
107 //------------------------------------------------------------
108 //
109 //------------------------------------------------------------
110 
111 class CResourceProvider_Impl
112 {
113 public:
114 
115     //-------------------------------------
116     //
117     //-------------------------------------
118 
CResourceProvider_Impl()119     CResourceProvider_Impl( )
120     {
121         const ::vos::OGuard aGuard( Application::GetSolarMutex() );
122 
123 		com::sun::star::lang::Locale aLoc( Application::GetSettings().GetUILocale() );
124         m_ResMgr = new SimpleResMgr( CREATEVERSIONRESMGR_NAME( fps_office ), aLoc );
125     }
126 
127     //-------------------------------------
128     //
129     //-------------------------------------
130 
~CResourceProvider_Impl()131     ~CResourceProvider_Impl( )
132     {
133         delete m_ResMgr;
134     }
135 
136     //-------------------------------------
137     //
138     //-------------------------------------
139 
getResString(sal_Int16 aId)140     OUString getResString( sal_Int16 aId )
141     {
142         OUString aResOUString;
143 
144         try
145         {
146             OSL_ASSERT( m_ResMgr );
147 
148             // translate the control id to a resource id
149             sal_Int16 aResId = CtrlIdToResId( aId );
150 
151             if ( aResId > -1 )
152                 aResOUString = m_ResMgr->ReadString( aResId );
153         }
154         catch(...)
155         {
156         }
157 
158         return aResOUString;
159     }
160 
161 public:
162     SimpleResMgr* m_ResMgr;
163 };
164 
165 //------------------------------------------------------------
166 //
167 //------------------------------------------------------------
168 
CResourceProvider()169 CResourceProvider::CResourceProvider( ) :
170     m_pImpl( new CResourceProvider_Impl() )
171 {
172 }
173 
174 //------------------------------------------------------------
175 //
176 //------------------------------------------------------------
177 
~CResourceProvider()178 CResourceProvider::~CResourceProvider( )
179 {
180     delete m_pImpl;
181 }
182 
183 //------------------------------------------------------------
184 //
185 //------------------------------------------------------------
186 
getResString(sal_Int16 aId)187 OUString CResourceProvider::getResString( sal_Int16 aId )
188 {
189    return m_pImpl->getResString( aId );
190 }
191