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 
31cdf0e10cSrcweir #include <tchar.h>
32cdf0e10cSrcweir #include <osl/diagnose.h>
33cdf0e10cSrcweir #include "controlaccess.hxx"
34cdf0e10cSrcweir #include "..\misc\WinImplHelper.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //------------------------------------------------------------
37cdf0e10cSrcweir // we are using a table based algorithm to dispatch control
38cdf0e10cSrcweir // actions there is one table containing one action table for
39cdf0e10cSrcweir // each control class and one action table per control class
40cdf0e10cSrcweir // which contains function pointer to control action functions
41cdf0e10cSrcweir //------------------------------------------------------------
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //------------------------------------------------------------
44cdf0e10cSrcweir // namespace directives
45cdf0e10cSrcweir //------------------------------------------------------------
46cdf0e10cSrcweir 
47cdf0e10cSrcweir using rtl::OUString;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace // private
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     //------------------------------------------------------------
53cdf0e10cSrcweir     // table setup
54cdf0e10cSrcweir     //------------------------------------------------------------
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     CTRL_SETVALUE_FUNCTION_T CheckboxSetValueFunctionTable[] =
57cdf0e10cSrcweir     {
58cdf0e10cSrcweir         CheckboxSetState
59cdf0e10cSrcweir     };
60cdf0e10cSrcweir     const size_t SIZE_CHECKBOX_SETVALUE_FUNCTION_TABLE =
61cdf0e10cSrcweir         sizeof( CheckboxSetValueFunctionTable ) / sizeof( CTRL_SETVALUE_FUNCTION_T );
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     CTRL_GETVALUE_FUNCTION_T CheckboxGetValueFunctionTable[] =
64cdf0e10cSrcweir     {
65cdf0e10cSrcweir         CheckboxGetState
66cdf0e10cSrcweir     };
67cdf0e10cSrcweir     const size_t SIZE_CHECKBOX_GETVALUE_FUNCTION_TABLE =
68cdf0e10cSrcweir         sizeof( CheckboxGetValueFunctionTable ) / sizeof( CTRL_GETVALUE_FUNCTION_T );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     CTRL_SETVALUE_FUNCTION_T ListboxSetValueFunctionTable[] =
71cdf0e10cSrcweir     {
72cdf0e10cSrcweir         NULL,
73cdf0e10cSrcweir         ListboxAddItem,
74cdf0e10cSrcweir         ListboxAddItems,
75cdf0e10cSrcweir         ListboxDeleteItem,
76cdf0e10cSrcweir         ListboxDeleteItems,
77cdf0e10cSrcweir         ListboxSetSelectedItem
78cdf0e10cSrcweir     };
79cdf0e10cSrcweir     const size_t SIZE_LISTBOX_SETVALUE_FUNCTION_TABLE =
80cdf0e10cSrcweir         sizeof( ListboxSetValueFunctionTable ) / sizeof( CTRL_SETVALUE_FUNCTION_T );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     CTRL_GETVALUE_FUNCTION_T ListboxGetValueFunctionTable[] =
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir         NULL,
85cdf0e10cSrcweir         NULL,
86cdf0e10cSrcweir         NULL,
87cdf0e10cSrcweir         NULL,
88cdf0e10cSrcweir         NULL,
89cdf0e10cSrcweir         NULL,
90cdf0e10cSrcweir         ListboxGetItems,
91cdf0e10cSrcweir         ListboxGetSelectedItem,
92cdf0e10cSrcweir         ListboxGetSelectedItemIndex
93cdf0e10cSrcweir     };
94cdf0e10cSrcweir     const size_t SIZE_LISTBOX_GETVALUE_ACTION_TABLE =
95cdf0e10cSrcweir         sizeof( ListboxGetValueFunctionTable ) / sizeof( CTRL_GETVALUE_FUNCTION_T );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     struct _ENTRY
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir         LPVOID lpFunctionTable;
100cdf0e10cSrcweir         size_t TableSize;
101cdf0e10cSrcweir     };
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     // an array of function tables, one for each control class
104cdf0e10cSrcweir     _ENTRY CtrlClassSetValueFunctionTable[] =
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         { NULL, 0 },
107cdf0e10cSrcweir         { CheckboxSetValueFunctionTable, SIZE_CHECKBOX_SETVALUE_FUNCTION_TABLE },
108cdf0e10cSrcweir         { ListboxSetValueFunctionTable, SIZE_LISTBOX_SETVALUE_FUNCTION_TABLE },
109cdf0e10cSrcweir         { NULL, 0 }
110cdf0e10cSrcweir     };
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     // an array of function tables, one for each control class
113cdf0e10cSrcweir     _ENTRY CtrlClassGetValueFunctionTable[] =
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         { NULL, 0 },
116cdf0e10cSrcweir         { CheckboxGetValueFunctionTable, SIZE_CHECKBOX_GETVALUE_FUNCTION_TABLE },
117cdf0e10cSrcweir         { ListboxGetValueFunctionTable, SIZE_LISTBOX_GETVALUE_ACTION_TABLE },
118cdf0e10cSrcweir         { NULL, 0 }
119cdf0e10cSrcweir     };
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     //------------------------------------------------------------
122cdf0e10cSrcweir     //
123cdf0e10cSrcweir     //------------------------------------------------------------
124cdf0e10cSrcweir 
GetCtrlSetValueFunction(CTRL_SETVALUE_FUNCTION_T * aCtrlSetValueFunctionTable,size_t aTableSize,sal_Int16 aCtrlAction)125cdf0e10cSrcweir     CTRL_SETVALUE_FUNCTION_T SAL_CALL GetCtrlSetValueFunction(
126cdf0e10cSrcweir         CTRL_SETVALUE_FUNCTION_T* aCtrlSetValueFunctionTable, size_t aTableSize, sal_Int16 aCtrlAction )
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         if ( !aCtrlSetValueFunctionTable ||
129cdf0e10cSrcweir              aCtrlAction < 0
130cdf0e10cSrcweir              || sal::static_int_cast< sal_uInt16 >(aCtrlAction) >= aTableSize )
131cdf0e10cSrcweir             return NULL;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         return aCtrlSetValueFunctionTable[aCtrlAction];
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     //------------------------------------------------------------
137cdf0e10cSrcweir     //
138cdf0e10cSrcweir     //------------------------------------------------------------
139cdf0e10cSrcweir 
GetCtrlGetValueFunction(CTRL_GETVALUE_FUNCTION_T * aCtrlGetValueFunctionTable,size_t aTableSize,sal_Int16 aCtrlAction)140cdf0e10cSrcweir     CTRL_GETVALUE_FUNCTION_T SAL_CALL GetCtrlGetValueFunction(
141cdf0e10cSrcweir         CTRL_GETVALUE_FUNCTION_T* aCtrlGetValueFunctionTable, size_t aTableSize, sal_Int16 aCtrlAction )
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         if ( !aCtrlGetValueFunctionTable ||
144cdf0e10cSrcweir              aCtrlAction < 0 ||
145cdf0e10cSrcweir              sal::static_int_cast< sal_uInt16 >(aCtrlAction) >= aTableSize )
146cdf0e10cSrcweir             return NULL;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         return aCtrlGetValueFunctionTable[aCtrlAction];
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     //------------------------------------------------------------
152cdf0e10cSrcweir     //
153cdf0e10cSrcweir     //------------------------------------------------------------
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     inline
GetCtrlClassSetValueFunctionTable(CTRL_CLASS aCtrlClass)156cdf0e10cSrcweir     _ENTRY SAL_CALL GetCtrlClassSetValueFunctionTable( CTRL_CLASS aCtrlClass )
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir         return CtrlClassSetValueFunctionTable[aCtrlClass];
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     //------------------------------------------------------------
162cdf0e10cSrcweir     //
163cdf0e10cSrcweir     //------------------------------------------------------------
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     inline
GetCtrlClassGetValueFunctionTable(CTRL_CLASS aCtrlClass)166cdf0e10cSrcweir     _ENTRY SAL_CALL GetCtrlClassGetValueFunctionTable( CTRL_CLASS aCtrlClass )
167cdf0e10cSrcweir     {
168cdf0e10cSrcweir         return CtrlClassGetValueFunctionTable[aCtrlClass];
169cdf0e10cSrcweir     }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     int WindowsFileOpenCtrlIds[] =
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir         0,
174cdf0e10cSrcweir         IDOK,       //  PUSHBUTTON_OK
175cdf0e10cSrcweir         IDCANCEL,   //  PUSHBUTTON_CANCEL
176cdf0e10cSrcweir         cmb1,       //  LISTBOX_FILTER
177cdf0e10cSrcweir         0,          //  CONTROL_FILEVIEW
178cdf0e10cSrcweir         0,          //  not available in system file picker
179cdf0e10cSrcweir         stc2,       //  LISTBOX_FILTER_LABEL
180cdf0e10cSrcweir         stc3        //  LISTBOX_FILE_NAME_LABEL
181cdf0e10cSrcweir     };
182cdf0e10cSrcweir     const int SIZE_WINDOWS_FILEOPEN_CTRL_IDS =
183cdf0e10cSrcweir         sizeof(WindowsFileOpenCtrlIds)/sizeof(WindowsFileOpenCtrlIds[0]);
184cdf0e10cSrcweir 
185cdf0e10cSrcweir }; // end namespace
186cdf0e10cSrcweir 
187cdf0e10cSrcweir //------------------------------------------------------------
188cdf0e10cSrcweir //
189cdf0e10cSrcweir //------------------------------------------------------------
190cdf0e10cSrcweir 
GetCtrlSetValueFunction(CTRL_CLASS aCtrlClass,sal_Int16 aCtrlAction)191cdf0e10cSrcweir CTRL_SETVALUE_FUNCTION_T SAL_CALL GetCtrlSetValueFunction( CTRL_CLASS aCtrlClass, sal_Int16 aCtrlAction )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     _ENTRY aEntry =
194cdf0e10cSrcweir         GetCtrlClassSetValueFunctionTable( aCtrlClass );
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     return GetCtrlSetValueFunction(
197cdf0e10cSrcweir         reinterpret_cast< CTRL_SETVALUE_FUNCTION_T* >( aEntry.lpFunctionTable ),
198cdf0e10cSrcweir         aEntry.TableSize,
199cdf0e10cSrcweir         aCtrlAction );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir //------------------------------------------------------------
203cdf0e10cSrcweir //
204cdf0e10cSrcweir //------------------------------------------------------------
205cdf0e10cSrcweir 
GetCtrlGetValueFunction(CTRL_CLASS aCtrlClass,sal_Int16 aCtrlAction)206cdf0e10cSrcweir CTRL_GETVALUE_FUNCTION_T SAL_CALL GetCtrlGetValueFunction( CTRL_CLASS aCtrlClass, sal_Int16 aCtrlAction )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     _ENTRY aEntry =
209cdf0e10cSrcweir         GetCtrlClassGetValueFunctionTable( aCtrlClass );
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     return GetCtrlGetValueFunction(
212cdf0e10cSrcweir         reinterpret_cast< CTRL_GETVALUE_FUNCTION_T* >( aEntry.lpFunctionTable ),
213cdf0e10cSrcweir         aEntry.TableSize,
214cdf0e10cSrcweir         aCtrlAction );
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir //------------------------------------------------------------
218cdf0e10cSrcweir //
219cdf0e10cSrcweir //------------------------------------------------------------
220cdf0e10cSrcweir 
GetCtrlClass(HWND hwndCtrl)221cdf0e10cSrcweir CTRL_CLASS SAL_CALL GetCtrlClass( HWND hwndCtrl )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir     CTRL_CLASS aCtrlClass = UNKNOWN;
224cdf0e10cSrcweir     TCHAR aClassName[256];
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     int nRet = GetClassName(hwndCtrl,aClassName,(sizeof(aClassName)/sizeof(TCHAR)));
227cdf0e10cSrcweir     if (nRet)
228cdf0e10cSrcweir     {
229cdf0e10cSrcweir         if (0 == _tcsicmp(aClassName,TEXT("button")))
230cdf0e10cSrcweir         {
231cdf0e10cSrcweir             // button means many things so we have
232cdf0e10cSrcweir             // to find out what button it is
233cdf0e10cSrcweir             LONG lBtnStyle = GetWindowLong(hwndCtrl,GWL_STYLE);
234cdf0e10cSrcweir             if (lBtnStyle & BS_CHECKBOX)
235cdf0e10cSrcweir                 aCtrlClass = CHECKBOX;
236cdf0e10cSrcweir             else if (((lBtnStyle & BS_PUSHBUTTON) == 0) || (lBtnStyle & BS_DEFPUSHBUTTON))
237cdf0e10cSrcweir                 aCtrlClass = PUSHBUTTON;
238cdf0e10cSrcweir         }
239cdf0e10cSrcweir         else if (0 == _tcsicmp(aClassName,TEXT("listbox")) ||
240cdf0e10cSrcweir                   0 == _tcsicmp(aClassName,TEXT("combobox")))
241cdf0e10cSrcweir             aCtrlClass = LISTBOX;
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir     return aCtrlClass;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir //------------------------------------------------------------
248cdf0e10cSrcweir //
249cdf0e10cSrcweir //------------------------------------------------------------
250cdf0e10cSrcweir 
CommonFilePickerCtrlIdToWinFileOpenCtrlId(sal_Int16 aControlId)251cdf0e10cSrcweir int SAL_CALL CommonFilePickerCtrlIdToWinFileOpenCtrlId( sal_Int16 aControlId )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir     if ( aControlId < 0 || aControlId > SIZE_WINDOWS_FILEOPEN_CTRL_IDS )
254cdf0e10cSrcweir         return aControlId;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     return WindowsFileOpenCtrlIds[aControlId];
257cdf0e10cSrcweir }
258