1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: controlaccess.cxx,v $
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 //------------------------------------------------------------------------
36 //------------------------------------------------------------------------
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 //------------------------------------------------------------
59 //------------------------------------------------------------
61 //------------------------------------------------------------
63 CTRL_SETVALUE_FUNCTION_T CheckboxSetValueFunctionTable
[] =
67 const size_t SIZE_CHECKBOX_SETVALUE_FUNCTION_TABLE
=
68 sizeof( CheckboxSetValueFunctionTable
) / sizeof( CTRL_SETVALUE_FUNCTION_T
);
70 CTRL_GETVALUE_FUNCTION_T CheckboxGetValueFunctionTable
[] =
74 const size_t SIZE_CHECKBOX_GETVALUE_FUNCTION_TABLE
=
75 sizeof( CheckboxGetValueFunctionTable
) / sizeof( CTRL_GETVALUE_FUNCTION_T
);
77 CTRL_SETVALUE_FUNCTION_T ListboxSetValueFunctionTable
[] =
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
[] =
98 ListboxGetSelectedItem
,
99 ListboxGetSelectedItemIndex
101 const size_t SIZE_LISTBOX_GETVALUE_ACTION_TABLE
=
102 sizeof( ListboxGetValueFunctionTable
) / sizeof( CTRL_GETVALUE_FUNCTION_T
);
106 LPVOID lpFunctionTable
;
110 // an array of function tables, one for each control class
111 _ENTRY CtrlClassSetValueFunctionTable
[] =
114 { CheckboxSetValueFunctionTable
, SIZE_CHECKBOX_SETVALUE_FUNCTION_TABLE
},
115 { ListboxSetValueFunctionTable
, SIZE_LISTBOX_SETVALUE_FUNCTION_TABLE
},
119 // an array of function tables, one for each control class
120 _ENTRY CtrlClassGetValueFunctionTable
[] =
123 { CheckboxGetValueFunctionTable
, SIZE_CHECKBOX_GETVALUE_FUNCTION_TABLE
},
124 { ListboxGetValueFunctionTable
, SIZE_LISTBOX_GETVALUE_ACTION_TABLE
},
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
||
137 || sal::static_int_cast
< sal_uInt16
>(aCtrlAction
) >= aTableSize
)
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
||
152 sal::static_int_cast
< sal_uInt16
>(aCtrlAction
) >= aTableSize
)
155 return aCtrlGetValueFunctionTable
[aCtrlAction
];
158 //------------------------------------------------------------
160 //------------------------------------------------------------
163 _ENTRY SAL_CALL
GetCtrlClassSetValueFunctionTable( CTRL_CLASS aCtrlClass
)
165 return CtrlClassSetValueFunctionTable
[aCtrlClass
];
168 //------------------------------------------------------------
170 //------------------------------------------------------------
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]);
194 //------------------------------------------------------------
196 //------------------------------------------------------------
198 CTRL_SETVALUE_FUNCTION_T SAL_CALL
GetCtrlSetValueFunction( CTRL_CLASS aCtrlClass
, sal_Int16 aCtrlAction
)
201 GetCtrlClassSetValueFunctionTable( aCtrlClass
);
203 return GetCtrlSetValueFunction(
204 reinterpret_cast< CTRL_SETVALUE_FUNCTION_T
* >( aEntry
.lpFunctionTable
),
209 //------------------------------------------------------------
211 //------------------------------------------------------------
213 CTRL_GETVALUE_FUNCTION_T SAL_CALL
GetCtrlGetValueFunction( CTRL_CLASS aCtrlClass
, sal_Int16 aCtrlAction
)
216 GetCtrlClassGetValueFunctionTable( aCtrlClass
);
218 return GetCtrlGetValueFunction(
219 reinterpret_cast< CTRL_GETVALUE_FUNCTION_T
* >( aEntry
.lpFunctionTable
),
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
)));
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
;
254 //------------------------------------------------------------
256 //------------------------------------------------------------
258 int SAL_CALL
CommonFilePickerCtrlIdToWinFileOpenCtrlId( sal_Int16 aControlId
)
260 if ( aControlId
< 0 || aControlId
> SIZE_WINDOWS_FILEOPEN_CTRL_IDS
)
263 return WindowsFileOpenCtrlIds
[aControlId
];