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