merge the formfield patch from ooo-build
[ooovba.git] / fpicker / source / win32 / filepicker / controlaccess.cxx
blob76cd8e655a37e0dc748e6d9132009be8729ab5fb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: controlaccess.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_fpicker.hxx"
34 //------------------------------------------------------------------------
35 // includes
36 //------------------------------------------------------------------------
38 #include <tchar.h>
39 #include <osl/diagnose.h>
40 #include "controlaccess.hxx"
41 #include "..\misc\WinImplHelper.hxx"
43 //------------------------------------------------------------
44 // we are using a table based algorithm to dispatch control
45 // actions there is one table containing one action table for
46 // each control class and one action table per control class
47 // which contains function pointer to control action functions
48 //------------------------------------------------------------
50 //------------------------------------------------------------
51 // namespace directives
52 //------------------------------------------------------------
54 using rtl::OUString;
56 namespace // private
59 //------------------------------------------------------------
60 // table setup
61 //------------------------------------------------------------
63 CTRL_SETVALUE_FUNCTION_T CheckboxSetValueFunctionTable[] =
65 CheckboxSetState
67 const size_t SIZE_CHECKBOX_SETVALUE_FUNCTION_TABLE =
68 sizeof( CheckboxSetValueFunctionTable ) / sizeof( CTRL_SETVALUE_FUNCTION_T );
70 CTRL_GETVALUE_FUNCTION_T CheckboxGetValueFunctionTable[] =
72 CheckboxGetState
74 const size_t SIZE_CHECKBOX_GETVALUE_FUNCTION_TABLE =
75 sizeof( CheckboxGetValueFunctionTable ) / sizeof( CTRL_GETVALUE_FUNCTION_T );
77 CTRL_SETVALUE_FUNCTION_T ListboxSetValueFunctionTable[] =
79 NULL,
80 ListboxAddItem,
81 ListboxAddItems,
82 ListboxDeleteItem,
83 ListboxDeleteItems,
84 ListboxSetSelectedItem
86 const size_t SIZE_LISTBOX_SETVALUE_FUNCTION_TABLE =
87 sizeof( ListboxSetValueFunctionTable ) / sizeof( CTRL_SETVALUE_FUNCTION_T );
89 CTRL_GETVALUE_FUNCTION_T ListboxGetValueFunctionTable[] =
91 NULL,
92 NULL,
93 NULL,
94 NULL,
95 NULL,
96 NULL,
97 ListboxGetItems,
98 ListboxGetSelectedItem,
99 ListboxGetSelectedItemIndex
101 const size_t SIZE_LISTBOX_GETVALUE_ACTION_TABLE =
102 sizeof( ListboxGetValueFunctionTable ) / sizeof( CTRL_GETVALUE_FUNCTION_T );
104 struct _ENTRY
106 LPVOID lpFunctionTable;
107 size_t TableSize;
110 // an array of function tables, one for each control class
111 _ENTRY CtrlClassSetValueFunctionTable[] =
113 { NULL, 0 },
114 { CheckboxSetValueFunctionTable, SIZE_CHECKBOX_SETVALUE_FUNCTION_TABLE },
115 { ListboxSetValueFunctionTable, SIZE_LISTBOX_SETVALUE_FUNCTION_TABLE },
116 { NULL, 0 }
119 // an array of function tables, one for each control class
120 _ENTRY CtrlClassGetValueFunctionTable[] =
122 { NULL, 0 },
123 { CheckboxGetValueFunctionTable, SIZE_CHECKBOX_GETVALUE_FUNCTION_TABLE },
124 { ListboxGetValueFunctionTable, SIZE_LISTBOX_GETVALUE_ACTION_TABLE },
125 { NULL, 0 }
128 //------------------------------------------------------------
130 //------------------------------------------------------------
132 CTRL_SETVALUE_FUNCTION_T SAL_CALL GetCtrlSetValueFunction(
133 CTRL_SETVALUE_FUNCTION_T* aCtrlSetValueFunctionTable, size_t aTableSize, sal_Int16 aCtrlAction )
135 if ( !aCtrlSetValueFunctionTable ||
136 aCtrlAction < 0
137 || sal::static_int_cast< sal_uInt16 >(aCtrlAction) >= aTableSize )
138 return NULL;
140 return aCtrlSetValueFunctionTable[aCtrlAction];
143 //------------------------------------------------------------
145 //------------------------------------------------------------
147 CTRL_GETVALUE_FUNCTION_T SAL_CALL GetCtrlGetValueFunction(
148 CTRL_GETVALUE_FUNCTION_T* aCtrlGetValueFunctionTable, size_t aTableSize, sal_Int16 aCtrlAction )
150 if ( !aCtrlGetValueFunctionTable ||
151 aCtrlAction < 0 ||
152 sal::static_int_cast< sal_uInt16 >(aCtrlAction) >= aTableSize )
153 return NULL;
155 return aCtrlGetValueFunctionTable[aCtrlAction];
158 //------------------------------------------------------------
160 //------------------------------------------------------------
162 inline
163 _ENTRY SAL_CALL GetCtrlClassSetValueFunctionTable( CTRL_CLASS aCtrlClass )
165 return CtrlClassSetValueFunctionTable[aCtrlClass];
168 //------------------------------------------------------------
170 //------------------------------------------------------------
172 inline
173 _ENTRY SAL_CALL GetCtrlClassGetValueFunctionTable( CTRL_CLASS aCtrlClass )
175 return CtrlClassGetValueFunctionTable[aCtrlClass];
178 int WindowsFileOpenCtrlIds[] =
181 IDOK, // PUSHBUTTON_OK
182 IDCANCEL, // PUSHBUTTON_CANCEL
183 cmb1, // LISTBOX_FILTER
184 0, // CONTROL_FILEVIEW
185 0, // not available in system file picker
186 stc2, // LISTBOX_FILTER_LABEL
187 stc3 // LISTBOX_FILE_NAME_LABEL
189 const int SIZE_WINDOWS_FILEOPEN_CTRL_IDS =
190 sizeof(WindowsFileOpenCtrlIds)/sizeof(WindowsFileOpenCtrlIds[0]);
192 }; // end namespace
194 //------------------------------------------------------------
196 //------------------------------------------------------------
198 CTRL_SETVALUE_FUNCTION_T SAL_CALL GetCtrlSetValueFunction( CTRL_CLASS aCtrlClass, sal_Int16 aCtrlAction )
200 _ENTRY aEntry =
201 GetCtrlClassSetValueFunctionTable( aCtrlClass );
203 return GetCtrlSetValueFunction(
204 reinterpret_cast< CTRL_SETVALUE_FUNCTION_T* >( aEntry.lpFunctionTable ),
205 aEntry.TableSize,
206 aCtrlAction );
209 //------------------------------------------------------------
211 //------------------------------------------------------------
213 CTRL_GETVALUE_FUNCTION_T SAL_CALL GetCtrlGetValueFunction( CTRL_CLASS aCtrlClass, sal_Int16 aCtrlAction )
215 _ENTRY aEntry =
216 GetCtrlClassGetValueFunctionTable( aCtrlClass );
218 return GetCtrlGetValueFunction(
219 reinterpret_cast< CTRL_GETVALUE_FUNCTION_T* >( aEntry.lpFunctionTable ),
220 aEntry.TableSize,
221 aCtrlAction );
224 //------------------------------------------------------------
226 //------------------------------------------------------------
228 CTRL_CLASS SAL_CALL GetCtrlClass( HWND hwndCtrl )
230 CTRL_CLASS aCtrlClass = UNKNOWN;
231 TCHAR aClassName[256];
233 int nRet = GetClassName(hwndCtrl,aClassName,(sizeof(aClassName)/sizeof(TCHAR)));
234 if (nRet)
236 if (0 == _tcsicmp(aClassName,TEXT("button")))
238 // button means many things so we have
239 // to find out what button it is
240 LONG lBtnStyle = GetWindowLong(hwndCtrl,GWL_STYLE);
241 if (lBtnStyle & BS_CHECKBOX)
242 aCtrlClass = CHECKBOX;
243 else if (((lBtnStyle & BS_PUSHBUTTON) == 0) || (lBtnStyle & BS_DEFPUSHBUTTON))
244 aCtrlClass = PUSHBUTTON;
246 else if (0 == _tcsicmp(aClassName,TEXT("listbox")) ||
247 0 == _tcsicmp(aClassName,TEXT("combobox")))
248 aCtrlClass = LISTBOX;
251 return aCtrlClass;
254 //------------------------------------------------------------
256 //------------------------------------------------------------
258 int SAL_CALL CommonFilePickerCtrlIdToWinFileOpenCtrlId( sal_Int16 aControlId )
260 if ( aControlId < 0 || aControlId > SIZE_WINDOWS_FILEOPEN_CTRL_IDS )
261 return aControlId;
263 return WindowsFileOpenCtrlIds[aControlId];