#include-once #include #include #include #include #include #include OnAutoItExitRegister("__ListViewEditInput_onExit") ; #INDEX# ======================================================================================================================= ; Title .........: ListViewEditInput ; AutoIt Version : 3.3.16.1 ; Language ......: English ; Description ...: This UDF makes it possible to edit ListviewSubitems ; Author(s) .....: Kanashius ; Version: 3.0.2 ; =============================================================================================================================== ; #VARIABLES# =================================================================================================================== Global $__ListViewEditInput_CHANGED = "changed" Global $__ListViewEditInput_CANCELED = "canceled" Global $__ListViewEditInput_Data[] __ListViewEditInput__StartUp() ; #CURRENT# ===================================================================================================================== ; __ListViewEditInput_ListViewAdd ; __ListViewEditInput_ListViewRemove ; __ListViewEditInput_SetEditable ; __ListViewEditInput_RegisterFunction ; __ListViewEditInput_onExit ; __ListViewEditInput_saveEdit ; __ListViewEditInput_cancelEdit ; __ListViewEditInput_editNextCell ; __ListViewEditInput_isCellEditable ; __ListViewEditInput_EditItem ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ; __ListViewEditInput__endEdit ; __ListViewEditInput__updateNextCellIndex ; __ListViewEditInput__WinProc ; __ListViewEditInput__WM_COMMAND ; __ListViewEditInput__WM_NOTIFY ; __ListViewEditInput__WM_HOTKEY ; =============================================================================================================================== ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_ListViewAdd ; Description ...: Add a ListView to make it editable ; Syntax.........: __ListViewEditInput_ListViewAdd($hGui, $hListView, $sColumns=Default, $sRows=Default, $bSingleClick=False) ; Parameters ....: $hGui - Handle of the Gui, where the Listview is placed ; ...............: $hListView - CtrlID/Handle of the Listview ; ...............: $sColumns=Default - Default to Edit all Columns or ; ...............: Numbers sperated by a "," starting with 0 e.g.: 1,2,5 ; ...............: $sRows=Default - Default to Edit all Rows or ; ...............: Numbers seperated by a "," starting with 0 e.g.: 1,2,5 ; ...............: $bSingleClick=False - True if a single click should be used for editing. Uses Double click by default ; Errors ........: 1 - If $hListView is not a valid Control ; 2 - If __ListViewEditInput_SetEditable fails, @extended contains the error from that function ; (The gui/listview will be initialized, but the columns, rows, and singleclick parameter are not set) ; Returns .......: True on success ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_ListViewAdd($hGui, $hListView, $sColumns=Default, $sRows=Default, $bSingleClick=False) If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView) If @error Then Return SetError(1, @error, False) ; Not a valid handle/listview If Not MapExists($__ListViewEditInput_data.mListViews, $hListView) Then If MapExists($__ListViewEditInput_data.mGuis, $hGui) Then $__ListViewEditInput_data["mGuis"][$hGui]["iListViewCount"] += 1 Else Local $mGuiData[] $mGuiData.hGui = $hGui $mGuiData.iListViewCount = 1 $mGuiData.hProc = DllCallbackRegister('__ListViewEditInput__WinProc', 'ptr', 'hwnd;uint;wparam;lparam') $mGuiData.hPrevProc = _WinAPI_SetWindowLong($hGui, -4, DllCallbackGetPtr($mGuiData.hProc)) Local $hPrevGui = GUISwitch($hGui) $mGuiData.editInput = GUICtrlCreateInput("",10,10,10,10) GUICtrlSetState($mGuiData.editInput, $GUI_HIDE) Local $mEditInfo[] $mEditInfo.hListView = -1 $mEditInfo.iIndex = -1 $mEditInfo.iSubIndex = -1 $mGuiData.mEditInfo = $mEditInfo GUISwitch($hPrevGui) $__ListViewEditInput_data["mGuis"][$hGui] = $mGuiData EndIf Local $mListViewData[] $mListViewData.hGui = $hGui $mListViewData.hListView = $hListView $mListViewData.changed = Default $mListViewData.canceled = Default $__ListViewEditInput_data["mListViews"][$hListView] = $mListViewData EndIf __ListViewEditInput_SetEditable($hListView, $sColumns, $sRows, $bSingleClick) If @error Then Return SetError(2, @error, False) ; Error 2 => is correctly initialized, but the $sColumns, $sRows, $bSingleClick may be ignored return True EndFunc ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_ListViewRemove ; Description ...: Remove the editable ListView ; Syntax.........: __ListViewEditInput_ListViewRemove($hListView) ; Parameters ....: $hListView - Listview CtrlID/Handle ; Errors ........: 1 - If $hListView is not a valid Control ; 2 - $hListView is not registered as editable ; Returns .......: True on success ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_ListViewRemove($hListView) If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView) If @error Then Return SetError(1, @error, False) ; Not a valid handle/listview If Not MapExists($__ListViewEditInput_data.mListViews, $hListView) Then Return SetError(2, 0, False) Local $hGui = $__ListViewEditInput_data.mListViews[$hListView].hGui MapRemove($__ListViewEditInput_data.mListViews, $hListView) __ListViewEditInput__RemoveGui($hGui) Return True EndFunc ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_SetEditable ; Description ...: Set the editable rows and columns and change the method to start editing ; Syntax.........: __ListViewEditInput_SetEditable($hListView, $sColumns=Default, $sRows=Default, $bSingleClick=False) ; Parameters ....: $hListView - CtrlID/Handle of the Listview ; ...............: $sColumns=Default - Default to Edit all Columns or ; ...............: Indices seperated by non number characters e.g. "," starting with 0 e.g.: 1,2,5 ; ...............: $sRows=Default - Default to Edit all Rows or ; ...............: Indices seperated by non number characters e.g. "," starting with 0 e.g.: 1,2,5 ; ...............: $bSingleClick=False - True if a single click should be used for editing. Uses Double click by default ; Errors ........: 1 - If $hListView is not a valid Control ; 2 - $hListView is not registered as editable ; 3 - $sColumns is not Default, but the string could not be parsed ; 4 - $sRows is not Default, but the string could not be parsed ; Returns .......: True on success ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_SetEditable($hListView, $sColumns=Default, $sRows=Default, $bSingleClick=False) If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView) If @error Then Return SetError(1, @error, False) ; Not a valid handle/listview If Not MapExists($__ListViewEditInput_data.mListViews, $hListView) Then Return SetError(2, 0, False) $__ListViewEditInput_data["mListViews"][$hListView]["mCols"] = Default If $sColumns<>Default Then Local $mCols[] Local $arCols = StringRegExp($sColumns, "(?m)(\d+)+(?:\D|$)+", 3) If Not IsArray($arCols) Then Return SetError(3, @error, False) For $iIndex In $arCols $mCols[Int($iIndex)] = True Next $__ListViewEditInput_data["mListViews"][$hListView]["mCols"] = $mCols EndIf $__ListViewEditInput_data["mListViews"][$hListView]["mRows"] = Default If $sRows<>Default Then Local $mRows[] Local $arRows = StringRegExp($sRows, "(?m)(\d+)+(?:\D|$)+", 3) If Not IsArray($arRows) Then Return SetError(4, @error, False) For $iIndex In $arRows $mRows[Int($iIndex)] = True Next $__ListViewEditInput_data["mListViews"][$hListView]["mRows"] = $mRows EndIf $__ListViewEditInput_data["mListViews"][$hListView]["bSingleClick"] = $bSingleClick Return True EndFunc ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_RegisterFunction ; Description ...: Register a function to receive events. Use an empty string "" to unregister. ; Syntax.........: __ListViewEditInput_RegisterFunction($hListView, $sFunction, $sEvent="changed") ; Parameters ....: $hListView - CtrlID/Handle of the Listview ; ...............: $function=Default - The Function name to register; Default removes the call; Variable can also be of type "function" ; ...............: $sEvent="changed" - The type of event to receive; Can be either "changed" or "canceled" ; ($__ListViewEditInput_CHANGED/$__ListViewEditInput_CANCELED) ; Errors ........: 1 - If $hListView is not a valid Control ; 2 - $hListView is not registered as editable ; 3 - If the provided $sEvent is unknown, must be "changed" or "canceled" ; ($__ListViewEditInput_CHANGED/$__ListViewEditInput_CANCELED) ; Returns .......: True on success ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_RegisterFunction($hListView, $function=Default, $sEvent=$__ListViewEditInput_CHANGED) ; Empty sFunction removes call If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView) If @error Then Return SetError(1, @error, False) ; Not a valid handle/listview If Not MapExists($__ListViewEditInput_data.mListViews, $hListView) Then Return SetError(2, 0, False) Switch $sEvent Case $__ListViewEditInput_CHANGED $__ListViewEditInput_data["mListViews"][$hListView]["changed"] = $function Case $__ListViewEditInput_CANCELED $__ListViewEditInput_data["mListViews"][$hListView]["canceled"] = $function Case Else Return SetError(3, 0, False) EndSwitch Return True EndFunc ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_onExit ; Description ...: Disabled all editing on all ListViews. Called automatically on exit; ; Syntax.........: __ListViewEditInput_onExit() ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_onExit() For $hGui In MapKeys($__ListViewEditInput_data.mGuis) __ListViewEditInput__RemoveGui($hGui, True) Next _WinAPI_UnhookWindowsHookEx($__ListViewEditInput_data.pPrevKeyHook) DllCallbackFree($__ListViewEditInput_data.tKeyProc) EndFunc ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_saveLVChange ; Description ...: Saves the Changes from Input to Listview and hide the Input ; Syntax.........: __ListViewEditInput_saveLVChange($hGui) ; Parameters ....: $hGui - Handle of the Gui with the listview; Default: All open edit inputs are saved ; Errors ........: 1 - If $hGui is not a registered gui handle ; Returns .......: True on success ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_saveEdit($hGui=Default) If $hGui=Default Then For $hGui In $__ListViewEditInput_data.mGuis __ListViewEditInput_saveEdit($hGui) Next ElseIf MapExists($__ListViewEditInput_data.mGuis, $hGui) Then Local $mEditInfo = $__ListViewEditInput_data.mGuis[$hGui].mEditInfo Local $iEditInput = $__ListViewEditInput_data.mGuis[$hGui].editInput If BitAND(GUICtrlGetState($iEditInput), $GUI_SHOW) Then Local $sData=GUICtrlRead($iEditInput) _GUICtrlListView_SetItemText($mEditInfo.hListView, $mEditInfo.iIndex, $sData, $mEditInfo.iSubIndex) if MapExists($__ListViewEditInput_data.mListViews, $mEditInfo.hListView) then Local $changed = $__ListViewEditInput_data.mListViews[$mEditInfo.hListView].changed If $changed<>Default Then If IsFunc($changed) Then $changed($mEditInfo.hListView, $mEditInfo.iIndex, $mEditInfo.iSubIndex) Else Call($changed, $mEditInfo.hListView, $mEditInfo.iIndex, $mEditInfo.iSubIndex) EndIf EndIf endif __ListViewEditInput__endEdit($hGui) endif Else Return SetError(1, 0, False) ; parameter is not a registered gui handle EndIf Return True EndFunc ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_cancelEdit ; Description ...: Canceles the current input edit ; Syntax.........: __ListViewEditInput_cancelEdit($hGui) ; Parameters ....: $hGui - Handle of the Gui with the listview; Default: All open edit inputs are cancelled ; Errors ........: 1 - If $hGui is not a registered gui handle ; Returns .......: True on success ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_cancelEdit($hGui=Default) If $hGui=Default Then For $hGui In $__ListViewEditInput_data.mGuis __ListViewEditInput_saveEdit($hGui) Next ElseIf MapExists($__ListViewEditInput_data.mGuis, $hGui) Then Local $mEditInfo = $__ListViewEditInput_data.mGuis[$hGui].mEditInfo Local $iEditInput = $__ListViewEditInput_data.mGuis[$hGui].editInput If BitAND(GUICtrlGetState($iEditInput), $GUI_SHOW) Then If MapExists($__ListViewEditInput_data.mListViews, $mEditInfo.hListView) Then Local $canceled = $__ListViewEditInput_data.mListViews[$mEditInfo.hListView].canceled If $canceled<>Default Then If IsFunc($canceled) Then $canceled($mEditInfo.hListView, $mEditInfo.iIndex, $mEditInfo.iSubIndex) Else Call($canceled, $mEditInfo.hListView, $mEditInfo.iIndex, $mEditInfo.iSubIndex) EndIf EndIf endif __ListViewEditInput__endEdit($hGui) endif Else Return SetError(1, 0, False) ; parameter is not a registered gui handle EndIf Return True EndFunc ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput__endEdit ; Description ...: Called to finish an edit ; Syntax.........: __ListViewEditInput__endEdit($hGui) ; Parameters ....: $hGui - Handle of the Gui ; Author ........: Kanashius ; Errors ........: 1 - If $hGui is not a registered gui handle ; Returns .......: True on success ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput__endEdit($hGui=Default) If $hGui=Default Then For $hGui In $__ListViewEditInput_data.mGuis __ListViewEditInput_saveEdit($hGui) Next ElseIf MapExists($__ListViewEditInput_data.mGuis, $hGui) Then GUICtrlSetState($__ListViewEditInput_data.mGuis[$hGui].editInput, $GUI_HIDE) GUICtrlSetData($__ListViewEditInput_data.mGuis[$hGui].editInput, "") GUICtrlSetState($__ListViewEditInput_data.mGuis[$hGui].editInput, $GUI_NOFOCUS) GUICtrlSetState($__ListViewEditInput_data.mGuis[$hGui].mEditInfo.hListView, $GUI_FOCUS) _GUICtrlListView_SetItemSelected($__ListViewEditInput_data.mGuis[$hGui].mEditInfo.hListView, $__ListViewEditInput_data.mGuis[$hGui].mEditInfo.iIndex, True, True) _GUICtrlListView_ClickItem($__ListViewEditInput_data.mGuis[$hGui].mEditInfo.hListView, $__ListViewEditInput_data.mGuis[$hGui].mEditInfo.iIndex) $__ListViewEditInput_data["mGuis"][$hGui]["mEditInfo"]["hListView"] = -1 $__ListViewEditInput_data["mGuis"][$hGui]["mEditInfo"]["iIndex"] = -1 $__ListViewEditInput_data["mGuis"][$hGui]["mEditInfo"]["iSubIndex"] = -1 Else Return SetError(1, 0, False) ; parameter is not a registered gui handle EndIf Return True EndFunc ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput__RemoveGui ; Description ...: Called to remove a gui and unregister hooks ; Syntax.........: __ListViewEditInput__RemoveGui($hGui) ; Parameters ....: $hGui - Handle of the Gui ; Errors ........: 1 - If $hGui is not a registered gui handle ; Returns .......: True on success ; Author ........: Kanashius ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput__RemoveGui($hGui, $bForceRemove = False) If Not MapExists($__ListViewEditInput_data.mGuis, $hGui) Then Return SetError(1, 0, False) $__ListViewEditInput_data["mGuis"][$hGui]["iListViewCount"] -= 1 If $bForceRemove Or $__ListViewEditInput_data.mGuis[$hGui].iListViewCount = 0 Then _WinAPI_SetWindowLong($hGui, -4, $__ListViewEditInput_data.mGuis[$hGui].hPrevProc) MapRemove($__ListViewEditInput_data.mGuis, $hGui) EndIf Return True EndFunc ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_editNextCell ; Description ...: Edit the next editable cell in the listview ; Syntax.........: __ListViewEditInput_editNextCell($hGui) ; Parameters ....: $hGui - Handle of the Gui ; Errors ........: 1 - If $hGui is not a registered gui handle ; Returns .......: True on success ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_editNextCell($hGui) If Not MapExists($__ListViewEditInput_data.mGuis, $hGui) Then Return SetError(1, 0, False) ; parameter is not a registered gui handle Local $mEditInfo = $__ListViewEditInput_data.mGuis[$hGui].mEditInfo If $mEditInfo.hListView<>-1 Then Local $hListView = $mEditInfo.hListView Local $iColAmount = _GUICtrlListView_GetColumnCount($hListView) Local $iRowAmount = _GUICtrlListView_GetItemCount($hListView) If $iColAmount=0 Then return If $iRowAmount=0 Then return Local $arIndices = [$mEditInfo.iIndex, $mEditInfo.iSubIndex] __ListViewEditInput__updateNextCellIndex($arIndices, $iColAmount, $iRowAmount) While Not __ListViewEditInput_isCellEditable($hListview, $arIndices[0], $arIndices[1]) If $arIndices[0]=$mEditInfo.iIndex And $arIndices[1]=$mEditInfo.iSubIndex Then ExitLoop ;no other editable cell found __ListViewEditInput__updateNextCellIndex($arIndices, $iColAmount, $iRowAmount) WEnd __ListViewEditInput_EditItem($hGui, $hListview, $arIndices[0], $arIndices[1], True) EndIf Return True EndFunc ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput__updateNextCellIndex ; Description ...: Calculate the next possible cell ; Syntax.........: __ListViewEditInput__updateNextCellIndex($arIndices, $iColAmount, $iRowAmount) ; Parameters ....: $hGui - Handle of the Gui ; Author ........: Kanashius ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput__updateNextCellIndex(ByRef $arIndices, $iColAmount, $iRowAmount) $arIndices[1]+=1 If $arIndices[1]>=$iColAmount Then $arIndices[1]=0 $arIndices[0]+=1 EndIf If $arIndices[0]>=$iRowAmount Then $arIndices[0]=0 EndFunc ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_isCellEditable ; Description ...: Check if a cell is editable ; Syntax.........: __ListViewEditInput_isCellEditable($hListview, $iIndex, $iSubIndex) ; Parameters ....: $hListview - Handle of the ListView ; ...............: $iIndex - Index to check ; ...............: $iSubIndex - SubIndex to check ; Errors ........: 1 - If $hListView is not a valid Control ; 2 - $hListView is not registered as editable ; Returns .......: True if the cell is editable ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_isCellEditable($hListview, $iIndex, $iSubIndex) If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView) If @error Then Return SetError(1, @error, False) ; Not a valid handle/listview If Not MapExists($__ListViewEditInput_data.mListViews, $hListView) Then Return SetError(2, 0, False) Local $mListViewData = $__ListViewEditInput_data.mListViews[$hListview] Local $bCol = ($mListViewData.mCols=Default)?(True):(MapExists($mListViewData.mCols, $iSubIndex)) Local $bRow = ($mListViewData.mRows=Default)?(True):(MapExists($mListViewData.mRows, $iIndex)) Return $bCol And $bRow EndFunc ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput__WinProc ; Description ...: Takes the Messages and give them to the WM_COMMAND, WM_NOTIFY and WM_HOTKEY function ; Syntax.........: __ListViewEditInput__WinProc($hWnd, $iMsg, $iwParam, $ilParam) ; Parameters ....: $hWnd - GuiHandle ; ...............: $iMsg - MessageCode ; ...............: $iwParam - wParam ; ...............: $ilParam - lParam ; Return values .: WindowProc ; Author ........: Kanashius ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput__WinProc($hWnd, $iMsg, $iwParam, $ilParam) If $iMsg=$WM_NOTIFY Then __ListViewEditInput__WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ElseIf $iMsg=$WM_COMMAND Then __ListViewEditInput__WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) ElseIf $iMsg=$WM_HOTKEY Then __ListViewEditInput__WM_HOTKEY($hWnd, $iMsg, $iwParam, $ilParam) endif If MapExists($__ListViewEditInput_data.mGuis, $hWnd) Then Return _WinAPI_CallWindowProc($__ListViewEditInput_data.mGuis[$hWnd].hPrevProc, $hWnd, $iMsg, $iwParam, $ilParam) EndIf EndFunc ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput__WM_COMMAND ; Description ...: Find out when the Input should be hidden (with or without saves) ; Syntax.........: __ListViewEditInput__WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) ; Parameters ....: $hWnd - GuiHandle ; ...............: $iMsg - MessageCode ; ...............: $iwParam - wParam ; ...............: $ilParam - lParam ; Return values .: $GUI_RUNDEFMSG ; Author ........: Kanashius ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput__WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode $hWndFrom = $ilParam $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word $iCode = BitShift($iwParam, 16) ; Hi Word If MapExists($__ListViewEditInput_data.mGuis, $hWnd) Then Switch $hWndFrom Case GUICtrlGetHandle($__ListViewEditInput_data.mGuis[$hWnd].editInput) Switch $iCode Case 512 __ListViewEditInput_saveEdit($hWnd) EndSwitch EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput__WM_NOTIFY ; Description ...: Detect the click at a subitem to show the edit ; Syntax.........: __ListViewEditInput__WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ; Parameters ....: $hWnd - GuiHandle ; ...............: $iMsg - MessageCode ; ...............: $iwParam - wParam ; ...............: $ilParam - lParam ; Return values .: $GUI_RUNDEFMSG ; Author ........: Kanashius ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput__WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") If MapExists($__ListViewEditInput_data.mListViews, $hWndFrom) Then Local $mListViewData = $__ListViewEditInput_data.mListViews[$hWndFrom] If (Not $mListViewData.bSingleClick And $iCode=$NM_DBLCLK) Or ($mListViewData.bSingleClick And $iCode=$NM_CLICK) Then Local $tmp = AutoItSetOption("MouseCoordMode", 2) Local $arPos = MouseGetPos() Local $arCtrlPos = ControlGetPos($mListViewData.hGui, "", $mListViewData.hListView) $arItem = _GUICtrlListView_SubItemHitTest($mListViewData.hListView, $arPos[0]-$arCtrlPos[0], $arPos[1]-$arCtrlPos[1]) __ListViewEditInput_EditItem($hWnd, $hWndFrom, $arItem[0], $arItem[1]) AutoItSetOption("MouseCoordMode", $tmp) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput__WM_HOTKEY ; Description ...: Detect the press of a registered key ; Syntax.........: __ListViewEditInput__WM_HOTKEY($hWnd, $iMsg, $iwParam, $ilParam) ; Parameters ....: $hWnd - GuiHandle ; ...............: $iMsg - MessageCode ; ...............: $iwParam - wParam ; ...............: $ilParam - lParam ; Return values .: $GUI_RUNDEFMSG ; Author ........: Kanashius ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput__WM_HOTKEY($hWnd, $iMsg, $iwParam, $ilParam) Switch _WinAPI_HiWord($ilParam) Case $VK_ESCAPE __ListViewEditInput_cancelEdit($hWnd) Case $VK_TAB __ListViewEditInput_editNextCell($hWnd) Case $VK_RETURN __ListViewEditInput_saveEdit($hWnd) EndSwitch EndFunc ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput__StartUp ; Description ...: Startup to initialize variables and hooks ; Syntax.........: __ListViewEditInput__StartUp() ; Author ........: Kanashius ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput__StartUp() Local $mListviews[] $__ListViewEditInput_data.mListViews = $mListviews Local $mGuis[] $__ListViewEditInput_data.mGuis = $mGuis $__ListViewEditInput_data.tKeyProc = DllCallbackRegister("__ListViewEditInput__KeyProc", "int", "int;ptr;ptr") $__ListViewEditInput_data.pPrevKeyHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($__ListViewEditInput_data.tKeyProc), _WinAPI_GetModuleHandle(0), 0) EndFunc ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput__KeyProc ; Description ...: Handle Keyboard events ; Parameters ....: $nCode - nCode ; ...............: $wParam - wParam ; ...............: $lParam - lParam ; Syntax.........: __ListViewEditInput__KeyProc() ; Author ........: Kanashius ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput__KeyProc($nCode, $wParam, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($__ListViewEditInput_data.pPrevKeyHook, $nCode, $wParam, $lParam) Local $pHookStruct = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo", $lParam) Local $vkCode = DllStructGetData($pHookStruct, "vkCode") Switch $wParam Case $WM_KEYDOWN, $WM_SYSKEYDOWN Local $hGui = WinGetHandle("[active]") If MapExists($__ListViewEditInput_data.mGuis, $hGui) Then If ControlGetHandle($hGui, "", ControlGetFocus($hGui))=GUICtrlGetHandle($__ListViewEditInput_data.mGuis[$hGui].editInput) Then Switch $vkCode Case $VK_ESCAPE __ListViewEditInput_cancelEdit($hGui) Return -1 Case $VK_TAB __ListViewEditInput_editNextCell($hGui) Return -1 Case $VK_RETURN __ListViewEditInput_saveEdit($hGui) Return -1 EndSwitch EndIf EndIf EndSwitch Return _WinAPI_CallNextHookEx($__ListViewEditInput_data.pPrevKeyHook, $nCode, $wParam, $lParam) EndFunc ;==>_KeyProc ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_EditItem ; Description ...: Detect the click at a subitem to show the edit ; Syntax.........: __ListViewEditInput_EditItem($hGui, $listview,$index,$subindex,$isIndex) ; Parameters ....: $hGui - Handle of the Gui ; ...............: $listview - Listview Ctrl or Index of Control ; ...............: $index - Index to edit ; ...............: $subindex - Subindex to edit ; ...............: $bSelectRow - If true the row with the item to edit is selected ; Errors ........: 1 - If $hListView is not a valid Control ; 2 - If $hGui is not a registered gui handle ; 3 - If the $hListView is not registered as editable ; Returns .......: True on success ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_EditItem($hGui, $hListview, $iIndex, $iSubIndex, $bSelectRow = False) If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView) If @error Then Return SetError(1, @error, False) ; Not a valid handle/listview If Not MapExists($__ListViewEditInput_data.mGuis, $hGui) Then Return SetError(2, 0, False) If Not MapExists($__ListViewEditInput_data.mListViews, $hListView) Then __ListViewEditInput__endEdit($hGui) Return SetError(3, 0, False) Else Local $mListViewData = $__ListViewEditInput_data.mListViews[$hListview] If $iIndex<>-1 And $iSubIndex<>-1 And __ListViewEditInput_isCellEditable($hListview, $iIndex, $iSubIndex) Then __ListViewEditInput_saveEdit($hGui) $__ListViewEditInput_data["mGuis"][$hGui]["mEditInfo"]["hListView"] = $hListView $__ListViewEditInput_data["mGuis"][$hGui]["mEditInfo"]["iIndex"] = $iIndex $__ListViewEditInput_data["mGuis"][$hGui]["mEditInfo"]["iSubIndex"] = $iSubIndex If $bSelectRow Then _GUICtrlListView_SetItemSelected($__ListViewEditInput_data.mGuis[$hGui].mEditInfo.hListView, $__ListViewEditInput_data.mGuis[$hGui].mEditInfo.iIndex, True, True) EndIf Local $arItemRect = _GUICtrlListView_GetSubItemRect($hListview, $iIndex, $iSubIndex) if $iSubIndex=0 Then ; because with subitem 0 the complete row is used for the rectangle :/ local $arNextSubItem=_GUICtrlListView_GetSubItemRect($hListview, $iIndex, $iSubIndex+1) $arItemRect[2]=$arNextSubItem[0]-$arItemRect[0] endif Local $arPosListView = ControlGetPos($mListViewData.hGui, "", $hListView) Local $iEditInput = $__ListViewEditInput_data.mGuis[$hGui].editInput GUICtrlSetPos($iEditInput, $arPosListView[0]+$arItemRect[0]+2, $arPosListView[1]+$arItemRect[1]+2, _ $arItemRect[2]-$arItemRect[0], $arItemRect[3]-$arItemRect[1]) GUICtrlSetData($iEditInput, _GUICtrlListView_GetItemText($hListview, $iIndex, $iSubIndex)) GUICtrlSetState($iEditInput, $GUI_SHOW) GUICtrlSetState($iEditInput, $GUI_ONTOP) GUICtrlSetState($iEditInput, $GUI_FOCUS) Local $rect = DllStructCreate($tagRECT) $rect.Left = $arPosListView[0]+$arItemRect[0]-10 $rect.Top = $arPosListView[1]+$arItemRect[1]-10 $rect.Right = $arItemRect[2]+10 $rect.Bottom = $arItemRect[3]+10 _WinAPI_RedrawWindow($hGui, $rect, 0, BitOR($RDW_ERASE, $RDW_FRAME, $RDW_INVALIDATE, $RDW_ALLCHILDREN, $RDW_ERASENOW, $RDW_UPDATENOW)) GUICtrlSetState($iEditInput, $GUI_FOCUS) Return True EndIf __ListViewEditInput__endEdit($hGui) EndIf Return False EndFunc