xref: /AOO41X/main/fpicker/source/win32/filepicker/controlaccess.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_fpicker.hxx"
30 
31 //------------------------------------------------------------------------
32 // includes
33 //------------------------------------------------------------------------
34 
35 #include <tchar.h>
36 #include <osl/diagnose.h>
37 #include "controlaccess.hxx"
38 #include "..\misc\WinImplHelper.hxx"
39 
40 //------------------------------------------------------------
41 // we are using a table based algorithm to dispatch control
42 // actions there is one table containing one action table for
43 // each control class and one action table per control class
44 // which contains function pointer to control action functions
45 //------------------------------------------------------------
46 
47 //------------------------------------------------------------
48 // namespace directives
49 //------------------------------------------------------------
50 
51 using rtl::OUString;
52 
53 namespace // private
54 {
55 
56     //------------------------------------------------------------
57     // table setup
58     //------------------------------------------------------------
59 
60     CTRL_SETVALUE_FUNCTION_T CheckboxSetValueFunctionTable[] =
61     {
62         CheckboxSetState
63     };
64     const size_t SIZE_CHECKBOX_SETVALUE_FUNCTION_TABLE =
65         sizeof( CheckboxSetValueFunctionTable ) / sizeof( CTRL_SETVALUE_FUNCTION_T );
66 
67     CTRL_GETVALUE_FUNCTION_T CheckboxGetValueFunctionTable[] =
68     {
69         CheckboxGetState
70     };
71     const size_t SIZE_CHECKBOX_GETVALUE_FUNCTION_TABLE =
72         sizeof( CheckboxGetValueFunctionTable ) / sizeof( CTRL_GETVALUE_FUNCTION_T );
73 
74     CTRL_SETVALUE_FUNCTION_T ListboxSetValueFunctionTable[] =
75     {
76         NULL,
77         ListboxAddItem,
78         ListboxAddItems,
79         ListboxDeleteItem,
80         ListboxDeleteItems,
81         ListboxSetSelectedItem
82     };
83     const size_t SIZE_LISTBOX_SETVALUE_FUNCTION_TABLE =
84         sizeof( ListboxSetValueFunctionTable ) / sizeof( CTRL_SETVALUE_FUNCTION_T );
85 
86     CTRL_GETVALUE_FUNCTION_T ListboxGetValueFunctionTable[] =
87     {
88         NULL,
89         NULL,
90         NULL,
91         NULL,
92         NULL,
93         NULL,
94         ListboxGetItems,
95         ListboxGetSelectedItem,
96         ListboxGetSelectedItemIndex
97     };
98     const size_t SIZE_LISTBOX_GETVALUE_ACTION_TABLE =
99         sizeof( ListboxGetValueFunctionTable ) / sizeof( CTRL_GETVALUE_FUNCTION_T );
100 
101     struct _ENTRY
102     {
103         LPVOID lpFunctionTable;
104         size_t TableSize;
105     };
106 
107     // an array of function tables, one for each control class
108     _ENTRY CtrlClassSetValueFunctionTable[] =
109     {
110         { NULL, 0 },
111         { CheckboxSetValueFunctionTable, SIZE_CHECKBOX_SETVALUE_FUNCTION_TABLE },
112         { ListboxSetValueFunctionTable, SIZE_LISTBOX_SETVALUE_FUNCTION_TABLE },
113         { NULL, 0 }
114     };
115 
116     // an array of function tables, one for each control class
117     _ENTRY CtrlClassGetValueFunctionTable[] =
118     {
119         { NULL, 0 },
120         { CheckboxGetValueFunctionTable, SIZE_CHECKBOX_GETVALUE_FUNCTION_TABLE },
121         { ListboxGetValueFunctionTable, SIZE_LISTBOX_GETVALUE_ACTION_TABLE },
122         { NULL, 0 }
123     };
124 
125     //------------------------------------------------------------
126     //
127     //------------------------------------------------------------
128 
129     CTRL_SETVALUE_FUNCTION_T SAL_CALL GetCtrlSetValueFunction(
130         CTRL_SETVALUE_FUNCTION_T* aCtrlSetValueFunctionTable, size_t aTableSize, sal_Int16 aCtrlAction )
131     {
132         if ( !aCtrlSetValueFunctionTable ||
133              aCtrlAction < 0
134              || sal::static_int_cast< sal_uInt16 >(aCtrlAction) >= aTableSize )
135             return NULL;
136 
137         return aCtrlSetValueFunctionTable[aCtrlAction];
138     }
139 
140     //------------------------------------------------------------
141     //
142     //------------------------------------------------------------
143 
144     CTRL_GETVALUE_FUNCTION_T SAL_CALL GetCtrlGetValueFunction(
145         CTRL_GETVALUE_FUNCTION_T* aCtrlGetValueFunctionTable, size_t aTableSize, sal_Int16 aCtrlAction )
146     {
147         if ( !aCtrlGetValueFunctionTable ||
148              aCtrlAction < 0 ||
149              sal::static_int_cast< sal_uInt16 >(aCtrlAction) >= aTableSize )
150             return NULL;
151 
152         return aCtrlGetValueFunctionTable[aCtrlAction];
153     }
154 
155     //------------------------------------------------------------
156     //
157     //------------------------------------------------------------
158 
159     inline
160     _ENTRY SAL_CALL GetCtrlClassSetValueFunctionTable( CTRL_CLASS aCtrlClass )
161     {
162         return CtrlClassSetValueFunctionTable[aCtrlClass];
163     }
164 
165     //------------------------------------------------------------
166     //
167     //------------------------------------------------------------
168 
169     inline
170     _ENTRY SAL_CALL GetCtrlClassGetValueFunctionTable( CTRL_CLASS aCtrlClass )
171     {
172         return CtrlClassGetValueFunctionTable[aCtrlClass];
173     }
174 
175     int WindowsFileOpenCtrlIds[] =
176     {
177         0,
178         IDOK,       //  PUSHBUTTON_OK
179         IDCANCEL,   //  PUSHBUTTON_CANCEL
180         cmb1,       //  LISTBOX_FILTER
181         0,          //  CONTROL_FILEVIEW
182         0,          //  not available in system file picker
183         stc2,       //  LISTBOX_FILTER_LABEL
184         stc3        //  LISTBOX_FILE_NAME_LABEL
185     };
186     const int SIZE_WINDOWS_FILEOPEN_CTRL_IDS =
187         sizeof(WindowsFileOpenCtrlIds)/sizeof(WindowsFileOpenCtrlIds[0]);
188 
189 }; // end namespace
190 
191 //------------------------------------------------------------
192 //
193 //------------------------------------------------------------
194 
195 CTRL_SETVALUE_FUNCTION_T SAL_CALL GetCtrlSetValueFunction( CTRL_CLASS aCtrlClass, sal_Int16 aCtrlAction )
196 {
197     _ENTRY aEntry =
198         GetCtrlClassSetValueFunctionTable( aCtrlClass );
199 
200     return GetCtrlSetValueFunction(
201         reinterpret_cast< CTRL_SETVALUE_FUNCTION_T* >( aEntry.lpFunctionTable ),
202         aEntry.TableSize,
203         aCtrlAction );
204 }
205 
206 //------------------------------------------------------------
207 //
208 //------------------------------------------------------------
209 
210 CTRL_GETVALUE_FUNCTION_T SAL_CALL GetCtrlGetValueFunction( CTRL_CLASS aCtrlClass, sal_Int16 aCtrlAction )
211 {
212     _ENTRY aEntry =
213         GetCtrlClassGetValueFunctionTable( aCtrlClass );
214 
215     return GetCtrlGetValueFunction(
216         reinterpret_cast< CTRL_GETVALUE_FUNCTION_T* >( aEntry.lpFunctionTable ),
217         aEntry.TableSize,
218         aCtrlAction );
219 }
220 
221 //------------------------------------------------------------
222 //
223 //------------------------------------------------------------
224 
225 CTRL_CLASS SAL_CALL GetCtrlClass( HWND hwndCtrl )
226 {
227     CTRL_CLASS aCtrlClass = UNKNOWN;
228     TCHAR aClassName[256];
229 
230     int nRet = GetClassName(hwndCtrl,aClassName,(sizeof(aClassName)/sizeof(TCHAR)));
231     if (nRet)
232     {
233         if (0 == _tcsicmp(aClassName,TEXT("button")))
234         {
235             // button means many things so we have
236             // to find out what button it is
237             LONG lBtnStyle = GetWindowLong(hwndCtrl,GWL_STYLE);
238             if (lBtnStyle & BS_CHECKBOX)
239                 aCtrlClass = CHECKBOX;
240             else if (((lBtnStyle & BS_PUSHBUTTON) == 0) || (lBtnStyle & BS_DEFPUSHBUTTON))
241                 aCtrlClass = PUSHBUTTON;
242         }
243         else if (0 == _tcsicmp(aClassName,TEXT("listbox")) ||
244                   0 == _tcsicmp(aClassName,TEXT("combobox")))
245             aCtrlClass = LISTBOX;
246     }
247 
248     return aCtrlClass;
249 }
250 
251 //------------------------------------------------------------
252 //
253 //------------------------------------------------------------
254 
255 int SAL_CALL CommonFilePickerCtrlIdToWinFileOpenCtrlId( sal_Int16 aControlId )
256 {
257     if ( aControlId < 0 || aControlId > SIZE_WINDOWS_FILEOPEN_CTRL_IDS )
258         return aControlId;
259 
260     return WindowsFileOpenCtrlIds[aControlId];
261 }
262