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 #include <tools/resmgr.hxx>
36cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
37cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <svtools/svtools.hrc>
40cdf0e10cSrcweir #include <svtools/filedlg2.hrc>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //------------------------------------------------------------
43cdf0e10cSrcweir // namespace directives
44cdf0e10cSrcweir //------------------------------------------------------------
45cdf0e10cSrcweir 
46cdf0e10cSrcweir using rtl::OUString;
47cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
48cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //------------------------------------------------------------
51cdf0e10cSrcweir //
52cdf0e10cSrcweir //------------------------------------------------------------
53cdf0e10cSrcweir 
54cdf0e10cSrcweir static const char* RES_NAME = "fps_office";
55cdf0e10cSrcweir static const char* OTHER_RES_NAME = "svt";
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //------------------------------------------------------------
58cdf0e10cSrcweir // we have to translate control ids to resource ids
59cdf0e10cSrcweir //------------------------------------------------------------
60cdf0e10cSrcweir 
61cdf0e10cSrcweir struct _Entry
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     sal_Int32 ctrlId;
64cdf0e10cSrcweir     sal_Int16 resId;
65cdf0e10cSrcweir };
66cdf0e10cSrcweir 
67cdf0e10cSrcweir _Entry CtrlIdToResIdTable[] = {
68cdf0e10cSrcweir     { CHECKBOX_AUTOEXTENSION,                   STR_SVT_FILEPICKER_AUTO_EXTENSION },
69cdf0e10cSrcweir     { CHECKBOX_PASSWORD,                        STR_SVT_FILEPICKER_PASSWORD },
70cdf0e10cSrcweir     { CHECKBOX_FILTEROPTIONS,                   STR_SVT_FILEPICKER_FILTER_OPTIONS },
71cdf0e10cSrcweir     { CHECKBOX_READONLY,                        STR_SVT_FILEPICKER_READONLY },
72cdf0e10cSrcweir     { CHECKBOX_LINK,                            STR_SVT_FILEPICKER_INSERT_AS_LINK },
73cdf0e10cSrcweir     { CHECKBOX_PREVIEW,                         STR_SVT_FILEPICKER_SHOW_PREVIEW },
74cdf0e10cSrcweir     { PUSHBUTTON_PLAY,                          STR_SVT_FILEPICKER_PLAY },
75cdf0e10cSrcweir     { LISTBOX_VERSION_LABEL,                    STR_SVT_FILEPICKER_VERSION },
76cdf0e10cSrcweir     { LISTBOX_TEMPLATE_LABEL,                   STR_SVT_FILEPICKER_TEMPLATES },
77cdf0e10cSrcweir     { LISTBOX_IMAGE_TEMPLATE_LABEL,             STR_SVT_FILEPICKER_IMAGE_TEMPLATE },
78cdf0e10cSrcweir     { CHECKBOX_SELECTION,                       STR_SVT_FILEPICKER_SELECTION },
79cdf0e10cSrcweir     { FOLDERPICKER_TITLE,                       STR_SVT_FOLDERPICKER_DEFAULT_TITLE },
80cdf0e10cSrcweir     { FOLDER_PICKER_DEF_DESCRIPTION,            STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION },
81e5d951fcSPedro Giffuni     { FILE_PICKER_OVERWRITE,                    STR_SVT_ALREADYEXISTOVERWRITE },
82e5d951fcSPedro Giffuni     { FILE_PICKER_ALLFORMATS,                   STR_SVT_ALLFORMATS }
83cdf0e10cSrcweir };
84cdf0e10cSrcweir 
85cdf0e10cSrcweir _Entry OtherCtrlIdToResIdTable[] = {
86cdf0e10cSrcweir     { FILE_PICKER_TITLE_OPEN,                   STR_FILEDLG_OPEN },
87cdf0e10cSrcweir     { FILE_PICKER_TITLE_SAVE,                   STR_FILEDLG_SAVE },
88cdf0e10cSrcweir     { FILE_PICKER_FILE_TYPE,                    STR_FILEDLG_TYPE },
89cdf0e10cSrcweir };
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir const sal_Int32 SIZE_TABLE = sizeof( CtrlIdToResIdTable ) / sizeof( _Entry );
93cdf0e10cSrcweir const sal_Int32 OTHER_SIZE_TABLE = sizeof( OtherCtrlIdToResIdTable ) / sizeof( _Entry );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //------------------------------------------------------------
96cdf0e10cSrcweir //
97cdf0e10cSrcweir //------------------------------------------------------------
98cdf0e10cSrcweir 
CtrlIdToResId(sal_Int32 aControlId)99cdf0e10cSrcweir sal_Int16 CtrlIdToResId( sal_Int32 aControlId )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     sal_Int16 aResId = -1;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < SIZE_TABLE; i++ )
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         if ( CtrlIdToResIdTable[i].ctrlId == aControlId )
106cdf0e10cSrcweir         {
107cdf0e10cSrcweir             aResId = CtrlIdToResIdTable[i].resId;
108cdf0e10cSrcweir             break;
109cdf0e10cSrcweir         }
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     return aResId;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
OtherCtrlIdToResId(sal_Int32 aControlId)115cdf0e10cSrcweir sal_Int16 OtherCtrlIdToResId( sal_Int32 aControlId )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     sal_Int16 aResId = -1;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < OTHER_SIZE_TABLE; i++ )
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir         if ( OtherCtrlIdToResIdTable[i].ctrlId == aControlId )
122cdf0e10cSrcweir         {
123cdf0e10cSrcweir             aResId = OtherCtrlIdToResIdTable[i].resId;
124cdf0e10cSrcweir             break;
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     return aResId;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir //------------------------------------------------------------
132cdf0e10cSrcweir //
133cdf0e10cSrcweir //------------------------------------------------------------
134cdf0e10cSrcweir 
135cdf0e10cSrcweir class CResourceProvider_Impl
136cdf0e10cSrcweir {
137cdf0e10cSrcweir public:
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     //-------------------------------------
140cdf0e10cSrcweir     //
141cdf0e10cSrcweir     //-------------------------------------
142cdf0e10cSrcweir 
CResourceProvider_Impl()143cdf0e10cSrcweir     CResourceProvider_Impl( )
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         m_ResMgr = ResMgr::CreateResMgr( RES_NAME );
146cdf0e10cSrcweir         m_OtherResMgr = ResMgr::CreateResMgr( OTHER_RES_NAME );
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     //-------------------------------------
150cdf0e10cSrcweir     //
151cdf0e10cSrcweir     //-------------------------------------
152cdf0e10cSrcweir 
~CResourceProvider_Impl()153cdf0e10cSrcweir     ~CResourceProvider_Impl( )
154cdf0e10cSrcweir     {
155cdf0e10cSrcweir         delete m_ResMgr;
156cdf0e10cSrcweir         delete m_OtherResMgr;
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     //-------------------------------------
160cdf0e10cSrcweir     //
161cdf0e10cSrcweir     //-------------------------------------
162cdf0e10cSrcweir 
getResString(sal_Int16 aId)163cdf0e10cSrcweir     OUString getResString( sal_Int16 aId )
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         String   aResString;
166cdf0e10cSrcweir         OUString aResOUString;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         try
169cdf0e10cSrcweir         {
170cdf0e10cSrcweir             OSL_ASSERT( m_ResMgr && m_OtherResMgr );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir             // translate the control id to a resource id
173cdf0e10cSrcweir             sal_Int16 aResId = CtrlIdToResId( aId );
174cdf0e10cSrcweir             if ( aResId > -1 )
175cdf0e10cSrcweir                 aResString = String( ResId( aResId, *m_ResMgr ) );
176cdf0e10cSrcweir 	    else
177cdf0e10cSrcweir 	    {
178cdf0e10cSrcweir                 aResId = OtherCtrlIdToResId( aId );
179cdf0e10cSrcweir                 if ( aResId > -1 )
180cdf0e10cSrcweir                     aResString = String( ResId( aResId, *m_OtherResMgr ) );
181cdf0e10cSrcweir 	    }
182cdf0e10cSrcweir 	    if ( aResId > -1 )
183cdf0e10cSrcweir                 aResOUString = OUString( aResString );
184cdf0e10cSrcweir         }
185cdf0e10cSrcweir         catch(...)
186cdf0e10cSrcweir         {
187cdf0e10cSrcweir         }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         return aResOUString;
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir public:
193cdf0e10cSrcweir     ResMgr* m_ResMgr;
194cdf0e10cSrcweir     ResMgr* m_OtherResMgr;
195cdf0e10cSrcweir };
196cdf0e10cSrcweir 
197cdf0e10cSrcweir //------------------------------------------------------------
198cdf0e10cSrcweir //
199cdf0e10cSrcweir //------------------------------------------------------------
200cdf0e10cSrcweir 
CResourceProvider()201cdf0e10cSrcweir CResourceProvider::CResourceProvider( ) :
202cdf0e10cSrcweir     m_pImpl( new CResourceProvider_Impl() )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir //------------------------------------------------------------
207cdf0e10cSrcweir //
208cdf0e10cSrcweir //------------------------------------------------------------
209cdf0e10cSrcweir 
~CResourceProvider()210cdf0e10cSrcweir CResourceProvider::~CResourceProvider( )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     delete m_pImpl;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir //------------------------------------------------------------
216cdf0e10cSrcweir //
217cdf0e10cSrcweir //------------------------------------------------------------
218cdf0e10cSrcweir 
getResString(sal_Int32 aId)219cdf0e10cSrcweir OUString CResourceProvider::getResString( sal_Int32 aId )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir    return m_pImpl->getResString( aId ).replace('~', '_');
222cdf0e10cSrcweir }
223