#include #include #include #include #include-once OnAutoItExitRegister("__ListViewEditInput_onExit") ; #INDEX# ======================================================================================================================= ; Title .........: ListViewEditInput ; AutoIt Version : 3.3.12.0 ; Language ......: English ; Description ...: This UDF make it possible to edit ListviewSubitems ; Author(s) .....: Kanashius ; =============================================================================================================================== ; #VARIABLES# =================================================================================================================== Global $__ListViewEditInput_ListViews[0][7], $__ListViewEditInput_akt = -1, $__ListViewEditInput_Editing = False, $__ListViewEditInput_LastEdited[2] Global $__ListViewEditInput_EnterDummy, $__ListViewEditInput_ESCDummy, $__ListViewEditInput_TabDummy Global $__ListViewEditInput_EditInput Global $__ListViewEditInput_hGui, $__ListViewEditInput_hHook ; #CURRENT# ===================================================================================================================== ; __ListViewEditInput_StartUp ; __ListViewEditInput_AddListview ; __ListViewEditInput_DeleteListview ; __ListViewEditInput_ChangeListview ; __ListViewEditInput_InitializeKeys ; __ListViewEditInput_RegisterFunction ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ; __ListViewEditInput_onExit ; __ListViewEditInput__WinProc ; __ListViewEditInput_saveLVChange ; __ListViewEditInput_cancelLVChange ; __ListViewEditInput_WM_COMMAND ; __ListViewEditInput_WM_NOTIFY ; =============================================================================================================================== ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_StartUp ; Description ...: Saves the Changes from Input to Listview and delete the Listview ; Syntax.........: __ListViewEditInput_StartUp($hGui) ; Parameters ....: $hGui - Handle of the Gui where to create the Input and set the Message hooks ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_StartUp($hGui) $__ListViewEditInput_EditInput = GUICtrlCreateInput("", 10, 10, 10, 10) GUICtrlSetState($__ListViewEditInput_EditInput, $GUI_HIDE) $__ListViewEditInput_hGui = $hGui $hProc = DllCallbackRegister('__ListViewEditInput__WinProc', 'ptr', 'hwnd;uint;wparam;lparam') $__ListViewEditInput_hHook = _WinAPI_SetWindowLong($hGui, -4, DllCallbackGetPtr($hProc)) EndFunc ;==>__ListViewEditInput_StartUp ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_AddListview ; Description ...: Adds a Listview to make it Editable ; Syntax.........: __ListViewEditInput_AddListview($hGui,$hListView,$arColumn="All",$arRow="All",$click="D") ; Parameters ....: $hGui - Handle of the Gui, where the Listview is placed ; ...............: $hListView - CtrlID of the Listview ; ...............: $arColumn="All" - "All" to Edit all Columns ; ...............: Numbers delimated by a "," starting with 0 e.g.: 1,2,5 ; ...............: $arRow="All" - "All" to Edit all Rows ; ...............: Numbers delimated by a "," starting with 0 e.g.: 1,2,5 ; ...............: $click="D" - D needs a doubleClick ; ...............: E needs a singleClick ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_AddListview($hGui, $hListView, $arColumn = "All", $arRow = "All", $click = "D") ReDim $__ListViewEditInput_ListViews[UBound($__ListViewEditInput_ListViews) + 1][7] Local $__ListViewEditInput_akt = UBound($__ListViewEditInput_ListViews) - 1 $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][0] = $hListView $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][1] = $arColumn $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][2] = $hGui $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][3] = $arRow If $click = "D" Then $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][6] = $NM_DBLCLK Else $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][6] = $NM_CLICK EndIf EndFunc ;==>__ListViewEditInput_AddListview ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_DeleteListview ; Description ...: Deletes a Listview form the List of Editable Listviews ; Syntax.........: __ListViewEditInput_DeleteListview($hListView) ; Parameters ....: $hListView - Listview CtrlID ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_DeleteListview($hListView) Local $index = _ArraySearch($__ListViewEditInput_ListViews, $hListView) If $index <> -1 Then _ArrayDelete($__ListViewEditInput_ListViews, $index) EndIf EndFunc ;==>__ListViewEditInput_DeleteListview ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_ChangeListview ; Description ...: Changes the Colums and/or Rows of the given Listview ; Syntax.........: __ListViewEditInput_ChangeListview($hListView,$arColumn="All",$arRow="All") ; Parameters ....: $hListView ; ...............: $arColumn="All" - "All" to Edit all Columns ; ...............: Numbers delimated by a "," starting with 0 e.g.: 1,2,5 ; ...............: $arRow="All" - "All" to Edit all Rows ; ...............: Numbers delimated by a "," starting with 0 e.g.: 1,2,5 ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_ChangeListview($hListView, $arColumn = "All", $arRow = "All") Local $index = _ArraySearch($__ListViewEditInput_ListViews, $hListView) If $index <> -1 Then $__ListViewEditInput_ListViews[$index][1] = $arColumn $__ListViewEditInput_ListViews[$index][3] = $arRow EndIf EndFunc ;==>__ListViewEditInput_ChangeListview ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_GetEditedCell ; Description ...: Returns the index and Subindes of the last edited cell, or the actual editing cell ; Syntax.........: __ListViewEditInput_GetEditedCell() ; Return values .: Array: [0]=Listview Control ; [1]=Listview Index ; [2]=Listview SubItemIndex ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_GetEditedCell() Local $__ListViewEditInput_Edited[3] $__ListViewEditInput_Edited[0] = $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][0] $__ListViewEditInput_Edited[1] = $__ListViewEditInput_LastEdited[0] $__ListViewEditInput_Edited[2] = $__ListViewEditInput_LastEdited[1] Return $__ListViewEditInput_Edited EndFunc ;==>__ListViewEditInput_GetEditedCell ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_InitializeKeys ; Description ...: Saves the Changes from Input to Listview and delete the Listview ; Syntax.........: __ListViewEditInput_InitializeKeys($hGui) ; Parameters ....: $hGui - Guihandle, where the Accellerators should be used ; Error .........: Array has wrong Dimension (View GuiSetAccelerators in manual) ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_InitializeKeys($hGui, $arAccelerators = -1) If UBound($arAccelerators, 2) < 2 Then SetError(1) EndIf $__ListViewEditInput_EnterDummy = GUICtrlCreateDummy() $__ListViewEditInput_ESCDummy = GUICtrlCreateDummy() $__ListViewEditInput_TabDummy = GUICtrlCreateDummy() Global $__ListViewEditInput_AccelKeys[3][2] = [ _ ["{ENTER}", $__ListViewEditInput_EnterDummy], _ ["{ESC}", $__ListViewEditInput_ESCDummy], _ ["{TAB}", $__ListViewEditInput_TabDummy]] ;~ __ListViewEditInput_GoToNextCell($hGui) ; Initialize the GUI handle for the function If $arAccelerators <> -1 Then $oldSize = UBound($__ListViewEditInput_AccelKeys) ReDim $__ListViewEditInput_AccelKeys[UBound($__ListViewEditInput_AccelKeys) + UBound($arAccelerators)][2] For $i = 0 To UBound($arAccelerators) - 1 Step 1 $__ListViewEditInput_AccelKeys[$i + $oldSize][0] = $arAccelerators[$i][0] $__ListViewEditInput_AccelKeys[$i + $oldSize][1] = $arAccelerators[$i][1] Next EndIf GUISetAccelerators($__ListViewEditInput_AccelKeys, $hGui) EndFunc ;==>__ListViewEditInput_InitializeKeys ; #FUNCTION#============================================================================== ; Name...........: __ListViewEditInput_RegisterFunction ; Description ...: Saves the Changes from Input to Listview and delete the Listview ; Syntax.........: __ListViewEditInput_RegisterFunction($hListView,$sFunction,$sWhen="Changed") ; Parameters ....: $hListView - ListView CtrlID ; $sFunction - Name of the User Function ; $sWhen="Changed" - When the Function should be called "Changed"->When the ListView was changed ; "Canceled"-> When the Change was canceled (ESC) ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput_RegisterFunction($hListView, $sFunction, $sWhen = "Changed") Local $index = _ArraySearch($__ListViewEditInput_ListViews, $hListView) If $index <> -1 Then If $sWhen = "Changed" Then $__ListViewEditInput_ListViews[$index][4] = $sFunction EndIf If $sWhen = "Canceled" Then $__ListViewEditInput_ListViews[$index][5] = $sFunction EndIf EndIf EndFunc ;==>__ListViewEditInput_RegisterFunction ; #INTERNAL_USE_ONLY#=========================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput_onExit ; Description ...: Deletes the Hook at the Programm exit ; Syntax.........: __ListViewEditInput_onExit() ; Author ........: Kanashius ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput_onExit() _WinAPI_SetWindowLong($__ListViewEditInput_hGui, -4, $__ListViewEditInput_hHook) ; original WinProc wiederherstellen EndFunc ;==>__ListViewEditInput_onExit ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput__WinProc ; Description ...: Takes the Messages and give them to the WM_COMMAND and WM_NOTIFY 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) EndIf Return _WinAPI_CallWindowProc($__ListViewEditInput_hHook, $hWnd, $iMsg, $iwParam, $ilParam) EndFunc ;==>__ListViewEditInput__WinProc ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput_GoToNextCell ; Description ...: Saves input and switches to next cell to the right ; Syntax.........: __ListViewEditInput_GoToNextCell() ; Author ........: mistersquirrle ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput_GoToNextCell() __ListViewEditInput_saveLVChange() Local $aCurrentCell = __ListViewEditInput_GetEditedCell() For $i = 0 To UBound($__ListViewEditInput_ListViews) - 1 Step 1 If $aCurrentCell[0] = $__ListViewEditInput_ListViews[$i][0] Then Local $iMaxColumns = _GUICtrlListView_GetColumnCount($aCurrentCell[0]) Local $iMaxRows = _GUICtrlListView_GetItemCount($aCurrentCell[0]) ;~ ConsoleWrite('Column count: ' & $iMaxColumns & @CRLF) ;~ ConsoleWrite('Current column: ' & $aCurrentCell[2] & @CRLF) ;~ ConsoleWrite('Row count: ' & $iMaxRows & @CRLF) ;~ ConsoleWrite('Current row: ' & $aCurrentCell[1] & @CRLF) If $aCurrentCell[2] + 1 <= $iMaxColumns - 1 Then __ListViewEditInput__EditItem($i, $aCurrentCell[1], $aCurrentCell[2] + 1, True) ExitLoop ElseIf $aCurrentCell[1] + 1 <= $iMaxRows - 1 Then __ListViewEditInput__EditItem($i, $aCurrentCell[1] + 1, 0, True) ExitLoop EndIf EndIf Next EndFunc ;==>__ListViewEditInput_GoToNextCell ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput_saveLVChange ; Description ...: Saves the Changes from Input to Listview and hide the Input ; Syntax.........: __ListViewEditInput_saveLVChange() ; Author ........: Kanashius ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput_saveLVChange() If $__ListViewEditInput_Editing Then $__ListViewEditInput_Editing = False $data = GUICtrlRead($__ListViewEditInput_EditInput) _GUICtrlListView_SetItemText($__ListViewEditInput_ListViews[$__ListViewEditInput_akt][0], $__ListViewEditInput_LastEdited[0], StringReplace($data, ",", "."), $__ListViewEditInput_LastEdited[1]) GUICtrlSetState($__ListViewEditInput_EditInput, $GUI_HIDE) GUICtrlSetData($__ListViewEditInput_EditInput, "") If $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][4] <> "" Then Call($__ListViewEditInput_ListViews[$__ListViewEditInput_akt][4], $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][0], $__ListViewEditInput_LastEdited[0], $__ListViewEditInput_LastEdited[1]) EndIf EndIf EndFunc ;==>__ListViewEditInput_saveLVChange ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput_cancelLVChange ; Description ...: Hides the Input ; Syntax.........: __ListViewEditInput_cancelLVChange() ; Author ........: Kanashius ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ListViewEditInput_cancelLVChange() If $__ListViewEditInput_Editing Then $__ListViewEditInput_Editing = False GUICtrlSetState($__ListViewEditInput_EditInput, $GUI_HIDE) GUICtrlSetData($__ListViewEditInput_EditInput, "") If $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][5] <> "" Then Call($__ListViewEditInput_ListViews[$__ListViewEditInput_akt][5], $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][0], $__ListViewEditInput_LastEdited[0], $__ListViewEditInput_LastEdited[1]) EndIf EndIf EndFunc ;==>__ListViewEditInput_cancelLVChange ; #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 Switch $iIDFrom Case $__ListViewEditInput_EnterDummy __ListViewEditInput_saveLVChange() Case $__ListViewEditInput_ESCDummy __ListViewEditInput_cancelLVChange() Case $__ListViewEditInput_TabDummy __ListViewEditInput_GoToNextCell() Case Else EndSwitch ;~ If $iIDFrom = $__ListViewEditInput_EnterDummy Then ;~ __ListViewEditInput_saveLVChange() ;~ ElseIf $iIDFrom = $__ListViewEditInput_ESCDummy Then ;~ __ListViewEditInput_cancelLVChange() ;~ EndIf Switch $hWndFrom Case GUICtrlGetHandle($__ListViewEditInput_EditInput) Switch $iCode Case 512 __ListViewEditInput_saveLVChange() EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>__ListViewEditInput_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") For $i = 0 To UBound($__ListViewEditInput_ListViews) - 1 Step 1 If $hWndFrom = GUICtrlGetHandle($__ListViewEditInput_ListViews[$i][0]) Then If $iCode = $__ListViewEditInput_ListViews[$i][6] Then Local $tmp = AutoItSetOption("MouseCoordMode", 2) Local $pos = MouseGetPos() Local $cPos = ControlGetPos($__ListViewEditInput_ListViews[$i][2], "", $__ListViewEditInput_ListViews[$i][0]) $ar = _GUICtrlListView_SubItemHitTest($__ListViewEditInput_ListViews[$i][0], $pos[0] - $cPos[0], $pos[1] - $cPos[1]) __ListViewEditInput__EditItem($i, $ar[0], $ar[1], True) AutoItSetOption("MouseCoordMode", $tmp) EndIf EndIf Next Return $GUI_RUNDEFMSG EndFunc ;==>__ListViewEditInput_WM_NOTIFY ; #INTERNAL_USE_ONLY#============================================================================== ; Name...........: __ListViewEditInput__EditItem ; Description ...: Detect the click at a subitem to show the edit ; Syntax.........: __ListViewEditInput__EditItem($listview,$index,$subindex,$isIndex) ; Parameters ....: $listview - Listview Ctrl or Index of Control ; $index - Index to edit ; $subindex - Subindex to edit ; $isIndex - Set true if $listview is an index ; Error .........: 1=Listview not found in Editable Listview list ; Author ........: Kanashius ; =============================================================================================================================== Func __ListViewEditInput__EditItem($listview, $index, $subindex, $isIndex = False) If Not $isIndex Then For $i = 0 To UBound($__ListViewEditInput_ListViews) - 1 Step 1 If $listview = $__ListViewEditInput_ListViews[$i][0] Then $listview = $i ExitLoop EndIf If $i = UBound($__ListViewEditInput_ListViews) - 1 Then SetError(1) EndIf Next EndIf Local $subItem = False If $__ListViewEditInput_ListViews[$listview][1] = "All" Then $subItem = True Else Local $arTmp = StringSplit($__ListViewEditInput_ListViews[$listview][1], ",", 2) For $l = 0 To UBound($arTmp) - 1 Step 1 If $arTmp[$l] = $subindex Then $subItem = True ExitLoop EndIf Next EndIf Local $Item = False If $__ListViewEditInput_ListViews[$listview][3] = "All" Then $Item = True Else Local $arTmp = StringSplit($__ListViewEditInput_ListViews[$listview][3], ",", 2) For $l = 0 To UBound($arTmp) - 1 Step 1 If $arTmp[$l] = $index Then $Item = True ExitLoop EndIf Next EndIf If $Item And $subItem And $index <> -1 And $subindex <> -1 Then $__ListViewEditInput_akt = $listview $__ListViewEditInput_LastEdited[0] = $index $__ListViewEditInput_LastEdited[1] = $subindex $ar2 = _GUICtrlListView_GetSubItemRect($__ListViewEditInput_ListViews[$__ListViewEditInput_akt][0], $index, $subindex) If $subindex = 0 Then Local $ar3 = _GUICtrlListView_GetSubItemRect($__ListViewEditInput_ListViews[$__ListViewEditInput_akt][0], $index, $subindex + 1) $ar2[2] = $ar3[0] - $ar2[0] EndIf $pos = ControlGetPos($__ListViewEditInput_ListViews[$__ListViewEditInput_akt][2], "", $__ListViewEditInput_ListViews[$__ListViewEditInput_akt][0]) GUICtrlSetPos($__ListViewEditInput_EditInput, $pos[0] + $ar2[0] + 2, $pos[1] + $ar2[1] + 2, $ar2[2] - $ar2[0], $ar2[3] - $ar2[1]) GUICtrlSetData($__ListViewEditInput_EditInput, _GUICtrlListView_GetItemText($__ListViewEditInput_ListViews[$__ListViewEditInput_akt][0], $index, $subindex)) GUICtrlSetState($__ListViewEditInput_EditInput, $GUI_SHOW) GUICtrlSetState($__ListViewEditInput_EditInput, $GUI_ONTOP) GUICtrlSetState($__ListViewEditInput_EditInput, $GUI_FOCUS) $__ListViewEditInput_Editing = True EndIf EndFunc ;==>__ListViewEditInput__EditItem