Advertisement
AZJIO

ArrayDisplay_Beta

Nov 27th, 2013
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 19.13 KB | None | 0 0
  1. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
  2.  
  3. ; #include <Constants.au3> ; Only for _UserFunc
  4.  
  5. ; UDF example begins here ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6.  
  7. #include <GuiListView.au3>
  8.  
  9. Global $aArray[50][3]
  10. For $i = 0 To UBound($aArray) - 1
  11.     For $j = 0 To UBound($aArray, 2) - 1
  12.         $aArray[$i][$j] = StringReplace(StringFormat("%0" & Random(0, 9, 1) & "d", "0"), "0", Random(0, 9, 1), 0, 2)
  13.     Next
  14. Next
  15.  
  16. _ArrayDisplay_Beta($aArray, 'Sorts in "Col 1"', '22:44', Default, Default, Default, Default, 0xDDFFDD, "_UserFunc")
  17. Func _UserFunc($aArray , $aSelected, $cListView, $hGUI)
  18.     _GUICtrlListView_SimpleSort($cListView, True, 2)
  19. EndFunc
  20.  
  21. _ArrayDisplay_Beta($aArray, 'Selects the column 1', '22:44', Default, Default, Default, Default, Default, "_UserFunc2")
  22. Func _UserFunc2($aArray , $aSelected, $cListView, $hGUI)
  23.     _GUICtrlListView_SetSelectedColumn($cListView, 2)
  24. EndFunc
  25.  
  26. _ArrayDisplay_Beta($aArray, 'Marks the red selected items', Default, Default, Default, Default, Default, Default, "_UserFunc3")
  27. Func _UserFunc3($aArray , $aSelected, $cListView, $hGUI)
  28.     _GUICtrlListView_BeginUpdate($cListView)
  29.     Local $aID = _GUICtrlListView_GetSelectedIndices($cListView, True)
  30.     For $i = 1 To $aID[0]
  31.         $iID = _GUICtrlListView_GetItemParam($cListView, $aID[$i])
  32.         GUICtrlSetBkColor($iID, 0xFFCC99)
  33.     Next
  34.     _GUICtrlListView_EndUpdate($cListView)
  35. EndFunc
  36.  
  37. _ArrayDisplay_Beta($aArray, 'Changes the style', '22:44', Default, Default, Default, Default, 0xFFFFC4, "_UserFunc4")
  38. Func _UserFunc4($aArray , $aSelected, $cListView, $hGUI)
  39.     Static Local $a = 0
  40.     $a += 1
  41.     If $a = 1 Then
  42.         _GUICtrlListView_SetExtendedListViewStyle($cListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_BORDERSELECT, $LVS_EX_CHECKBOXES))
  43.         Local $iWidth = _GUICtrlListView_GetColumnWidth($cListView, 0)
  44.         _GUICtrlListView_SetColumnWidth($cListView, 0, $iWidth + 20)
  45.     Else
  46.         Local $sMsg
  47.         $iCount = _GUICtrlListView_GetItemCount($cListView)
  48.         For $i = 0 To $iCount - 1
  49.             If _GUICtrlListView_GetItemChecked($cListView, $i) Then
  50.                 $sMsg &= _GUICtrlListView_GetItemText($cListView, $i, 1) & @CRLF
  51.             EndIf
  52.         Next
  53.         MsgBox(0, ';)', $sMsg, 0, $hGUI)
  54.     EndIf
  55. EndFunc
  56.  
  57. _ArrayDisplay_Beta($aArray, 'Highlight the number 5', '22:44', Default, Default, Default, Default, Default, "_UserFunc5")
  58. Func _UserFunc5($aArray , $aSelected, $cListView, $hGUI)
  59.     Local $iID, $iCount = _GUICtrlListView_GetItemCount($cListView)
  60.     For $i = 0 To $iCount - 1
  61.         If StringInStr(_GUICtrlListView_GetItemText($cListView, $i, 1), '5') Then
  62.             $iID = _GUICtrlListView_GetItemParam($cListView, $i)
  63.             GUICtrlSetBkColor($iID, 0xFFDDDD)
  64.         EndIf
  65.     Next
  66. EndFunc
  67.  
  68. ; UDF code begins here ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  69.  
  70. Func _ArrayDisplay_Beta(Const ByRef $avArray, $sTitle = Default, $sArray_Range = Default, $iFlags = Default, $vUser_Separator = Default, $sHeader = Default, $iMax_ColWidth = Default, $iAlt_Color = Default, $sUser_Func = Default)
  71.  
  72.     Local Const $_ARRAYCONSTANT_MB_SYSTEMMODAL = 4096
  73.     Local Const $_ARRAYCONSTANT_MB_ICONINFORMATION = 64
  74.     Local Const $_ARRAYCONSTANT_MB_ICONERROR = 16
  75.     Local Const $_ARRAYCONSTANT_MB_YESNO = 4
  76.     Local Const $_ARRAYCONSTANT_IDYES = 6
  77.  
  78.     ; Default values
  79.     If $sTitle = Default Then $sTitle = "ArrayDisplay"
  80.     If $sArray_Range = Default Then $sArray_Range = ""
  81.     If $iFlags = Default Then $iFlags = 0
  82.     If $vUser_Separator = Default Then $vUser_Separator = ""
  83.     If $sHeader = Default Then $sHeader = ""
  84.     If $iMax_ColWidth = Default Then $iMax_ColWidth = 350
  85.     If $iAlt_Color = Default Then $iAlt_Color = 0
  86.     If $sUser_Func = Default Then $sUser_Func = ""
  87.  
  88.     ; Check valid array
  89.     Local $sMsg = "", $iRet
  90.     If IsArray($avArray) Then
  91.         ; Dimension checking
  92.         Local $iDimension = UBound($avArray, 0), $iRowCount = UBound($avArray, 1), $iColCount = UBound($avArray, 2)
  93.         If $iDimension > 2 Then
  94.             $sMsg = "Larger than 2D array passed to function"
  95.             $iRet = 2
  96.         EndIf
  97.     Else
  98.         $sMsg = "No array variable passed to function"
  99.         $iRet = 1
  100.     EndIf
  101.     If $sMsg Then
  102.         If BitAND($iFlags, 8) And MsgBox($_ARRAYCONSTANT_MB_SYSTEMMODAL + $_ARRAYCONSTANT_MB_ICONERROR + $_ARRAYCONSTANT_MB_YESNO, _
  103.                 "ArrayDisplay Error: " & $sTitle, $sMsg & @CRLF & @CRLF & "Exit the script?") = $_ARRAYCONSTANT_IDYES Then
  104.             Exit
  105.         Else
  106.             Return SetError($iRet, 0, "")
  107.         EndIf
  108.     EndIf
  109.  
  110.     ; Check for transpose and column align
  111.     Local $iTranspose = BitAND($iFlags, 1)
  112.     Local $iColAlign = BitAND($iFlags, 6) ; 0 = Left (default); 2 = Right; 4 = Center
  113.  
  114.     ; Determine copy separator
  115.     Local $iCW_ColWidth = Number($vUser_Separator)
  116.  
  117.     ; Add dimensions to title
  118.     Local $sDisplayTitle = "[" & $iRowCount & "]"
  119.     If $iDimension = 2 Then
  120.         $sDisplayTitle &= "[" & $iColCount & "]"
  121.     EndIf
  122.     If $iTranspose Then $sDisplayTitle &= " Transposed"
  123.     If $sTitle Then $sDisplayTitle &= " - " & $sTitle
  124.  
  125.     ; Separator handling
  126.     Local $sAD_Separator = ChrW(0xFAB1)
  127.     ; Set separator to use in this UDF and store existing one
  128.     Local $sCurr_Separator = Opt("GUIDataSeparatorChar", $sAD_Separator)
  129.     ; Set default user separator if required
  130.     If $vUser_Separator = "" Then $vUser_Separator = $sCurr_Separator
  131.  
  132.     ; Declare variables
  133.     Local $vTmp, $iRowLimit = 65526, $iColLimit = 250 ; Row = 64k control limit minus 4 buttons; Column - arbitrary limit
  134.  
  135.     ; Swap dimensions if transposing
  136.     If $iColCount < 0 Then $iColCount = 0
  137.     If $iTranspose Then
  138.         $vTmp = $iRowCount
  139.         $iRowCount = $iColCount
  140.         $iColCount = $vTmp
  141.     EndIf
  142.  
  143.     ; Set display limits for dimensions
  144.     Local $iItem_Start = 0, $iItem_End = $iRowCount - 1, $iSubItem_Start = 0, $iSubItem_End = $iColCount - 1, $avDimSplit, $avRangeSplit
  145.     ; Adjust for 1D array
  146.     If $iDimension = 1 Then
  147.         If $iTranspose Then
  148.             $iItem_End = 0
  149.         Else
  150.             $iSubItem_End = 0
  151.         EndIf
  152.     EndIf
  153.     ; Check for range set
  154.     If $sArray_Range Then
  155.         ; Force trailing | if required
  156.         If (Not StringInStr($sArray_Range, "|")) Then
  157.             $sArray_Range &= "|"
  158.         EndIf
  159.         ; Split into row|col
  160.         $avDimSplit = StringSplit($sArray_Range, "|")
  161.         ; Check valid ranges
  162.         If Not @error Then
  163.             $avRangeSplit = StringSplit($avDimSplit[1], ":")
  164.             If @error Then
  165.                 $iItem_Start = 0
  166.                 If Number($avRangeSplit[1]) Then
  167.                     $iItem_End = Number($avRangeSplit[1])
  168.                 EndIf
  169.             Else
  170.                 $iItem_Start = Number($avRangeSplit[1])
  171.                 If Number($avRangeSplit[2]) Then
  172.                     $iItem_End = Number($avRangeSplit[2])
  173.                 EndIf
  174.             EndIf
  175.             $avRangeSplit = StringSplit($avDimSplit[2], ":")
  176.             If @error Then
  177.                 $iSubItem_Start = 0
  178.                 If Number($avRangeSplit[1]) Then
  179.                     $iSubItem_End = Number($avRangeSplit[1])
  180.                 EndIf
  181.             Else
  182.                 $iSubItem_Start = Number($avRangeSplit[1])
  183.                 If Number($avRangeSplit[2]) Then
  184.                     $iSubItem_End = Number($avRangeSplit[2])
  185.                 EndIf
  186.             EndIf
  187.             ; Swap if tranposing
  188.             If $iTranspose Then
  189.                 $vTmp = $iItem_Start
  190.                 $iItem_Start = $iSubItem_Start
  191.                 $iSubItem_Start = $vTmp
  192.                 $vTmp = $iItem_End
  193.                 $iItem_End = $iSubItem_End
  194.                 $iSubItem_End = $vTmp
  195.             EndIf
  196.             ; Check limits
  197.             If $iItem_Start < 0 Then $iItem_Start = 0
  198.             If $iSubItem_Start < 0 Then $iSubItem_Start = 0
  199.             If $iItem_End > $iRowCount - 1 Then $iItem_End = $iRowCount - 1
  200.             If $iSubItem_End > $iColCount - 1 Then $iSubItem_End = $iColCount - 1
  201.         EndIf
  202.     EndIf
  203.  
  204.     ; Check if array will be truncated
  205.     $sMsg = ""
  206.     If $iItem_End - $iItem_Start > $iRowLimit Then
  207.         $sMsg = "Array truncated - maximum " & $iRowLimit & " rows will be displayed"
  208.         $iItem_End = $iItem_Start + $iRowLimit - 1
  209.     EndIf
  210.     If $iSubItem_End - $iSubItem_Start > $iColLimit Then
  211.         If $sMsg Then $sMsg &= @CRLF & @CRLF
  212.         $sMsg &= "Array truncated - maximum " & $iColLimit & " columns will be displayed"
  213.         $iSubItem_End = $iSubItem_Start + $iColLimit - 1
  214.     EndIf
  215.  
  216.     ; Split custom header on separator
  217.     Local $asHeader = StringSplit($sHeader, $sCurr_Separator, 2) ; No count element
  218.     $sHeader = "Row"
  219.     ; Create custom header with available items
  220.     If $asHeader[0] Then
  221.         ; Set as many as available
  222.         For $i = $iSubItem_Start To $iSubItem_End
  223.             ; Check custom header available
  224.             If $i >= UBound($asHeader) Then ExitLoop
  225.             $sHeader &= $sAD_Separator & $asHeader[$i]
  226.         Next
  227.     Else
  228.         ; Set default start
  229.         $i = $iSubItem_Start
  230.     EndIf
  231.     ; Add default headers to fill to end
  232.     For $j = $i To $iSubItem_End
  233.         $sHeader &= $sAD_Separator & "Col " & $j
  234.     Next
  235.  
  236.     ; Convert array into ListViewItem compatible lines
  237.     Local $avArrayText[$iItem_End - $iItem_Start + 1]
  238.     For $i = $iItem_Start To $iItem_End
  239.         $avArrayText[$i - $iItem_Start] = "[" & $i & "]"
  240.         For $j = $iSubItem_Start To $iSubItem_End
  241.             ; Get current item
  242.             If $iDimension = 1 Then
  243.                 If $iTranspose Then
  244.                     $vTmp = $avArray[$j]
  245.                 Else
  246.                     $vTmp = $avArray[$i]
  247.                 EndIf
  248.             Else
  249.                 If $iTranspose Then
  250.                     $vTmp = $avArray[$j][$i]
  251.                 Else
  252.                     $vTmp = $avArray[$i][$j]
  253.                 EndIf
  254.             EndIf
  255.             $avArrayText[$i - $iItem_Start] &= $sAD_Separator & $vTmp
  256.         Next
  257.     Next
  258.  
  259.     ; GUI Constants
  260.     Local Const $_ARRAYCONSTANT_GUI_DOCKBOTTOM = 64
  261.     Local Const $_ARRAYCONSTANT_GUI_DOCKBORDERS = 102
  262.     Local Const $_ARRAYCONSTANT_GUI_DOCKHEIGHT = 512
  263.     Local Const $_ARRAYCONSTANT_GUI_DOCKLEFT = 2
  264.     Local Const $_ARRAYCONSTANT_GUI_DOCKRIGHT = 4
  265.     Local Const $_ARRAYCONSTANT_GUI_EVENT_CLOSE = -3
  266.     Local Const $_ARRAYCONSTANT_GUI_DISABLE = 128
  267.     Local Const $_ARRAYCONSTANT_GUI_FOCUS = 256
  268.     ; Local Const $_ARRAYCONSTANT_GUI_BKCOLOR_LV_ALTERNATE = 0xFE000000
  269.     Local Const $_ARRAYCONSTANT_LVM_GETITEMCOUNT = (0x1000 + 4)
  270.     Local Const $_ARRAYCONSTANT_LVM_GETITEMRECT = (0x1000 + 14)
  271.     Local Const $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH = (0x1000 + 29)
  272.     Local Const $_ARRAYCONSTANT_LVM_SETCOLUMNWIDTH = (0x1000 + 30)
  273.     Local Const $_ARRAYCONSTANT_LVM_GETITEMSTATE = (0x1000 + 44)
  274.     Local Const $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE = (0x1000 + 54)
  275.     Local Const $_ARRAYCONSTANT_LVS_EX_GRIDLINES = 0x1
  276.     Local Const $_ARRAYCONSTANT_LVIS_SELECTED = 0x2
  277.     Local Const $_ARRAYCONSTANT_LVS_SHOWSELALWAYS = 0x8
  278.     Local Const $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT = 0x20
  279.     Local Const $_ARRAYCONSTANT_WS_EX_CLIENTEDGE = 0x0200
  280.     Local Const $_ARRAYCONSTANT_WS_MAXIMIZEBOX = 0x00010000
  281.     Local Const $_ARRAYCONSTANT_WS_MINIMIZEBOX = 0x00020000
  282.     Local Const $_ARRAYCONSTANT_WS_SIZEBOX = 0x00040000
  283.     Local Const $_ARRAYCONSTANT_WM_SETREDRAW = 11
  284.     Local Const $_ARRAYCONSTANT_LVSCW_AUTOSIZE = -1
  285.  
  286.     ; Create GUI
  287.     Local $iOrgWidth = 200, $iHeight = 200, $iMinSize = 250
  288.     Local $hGUI = GUICreate($sDisplayTitle, $iOrgWidth, $iHeight, Default, Default, BitOR($_ARRAYCONSTANT_WS_SIZEBOX, $_ARRAYCONSTANT_WS_MINIMIZEBOX, $_ARRAYCONSTANT_WS_MAXIMIZEBOX))
  289.     Local $aiGUISize = WinGetClientSize($hGUI)
  290.     Local $iButtonWidth = $aiGUISize[0] / 2
  291.     ; Create ListView
  292.     Local $cListView = GUICtrlCreateListView($sHeader, 0, 0, $aiGUISize[0], $aiGUISize[1] - 46, $_ARRAYCONSTANT_LVS_SHOWSELALWAYS)
  293.     ; GUICtrlSetBkColor($cListView, $_ARRAYCONSTANT_GUI_BKCOLOR_LV_ALTERNATE)
  294.     GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_GRIDLINES, $_ARRAYCONSTANT_LVS_EX_GRIDLINES)
  295.     GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT)
  296.     GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE)
  297.     ; Create buttons
  298.     Local $cCopy_ID = GUICtrlCreateButton("Copy Data && Hdr/Row", 0, $aiGUISize[1] - 43, $iButtonWidth, 20)
  299.     Local $cCopy_Data = GUICtrlCreateButton("Copy Data Only", $iButtonWidth, $aiGUISize[1] - 43, $iButtonWidth, 20)
  300.     Local $cUser_Func = GUICtrlCreateButton("Run User Function", 0, $aiGUISize[1] - 23, $iButtonWidth, 20)
  301.     If Not $sUser_Func Then GUICtrlSetState($cUser_Func, $_ARRAYCONSTANT_GUI_DISABLE)
  302.     Local $cExit_Script = GUICtrlCreateButton("Exit Script", $iButtonWidth, $aiGUISize[1] - 23, $iButtonWidth, 20)
  303.     ; Set resizing
  304.     GUICtrlSetResizing($cListView, $_ARRAYCONSTANT_GUI_DOCKBORDERS)
  305.     GUICtrlSetResizing($cCopy_ID, $_ARRAYCONSTANT_GUI_DOCKLEFT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT)
  306.     GUICtrlSetResizing($cCopy_Data, $_ARRAYCONSTANT_GUI_DOCKRIGHT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT)
  307.     GUICtrlSetResizing($cUser_Func, $_ARRAYCONSTANT_GUI_DOCKLEFT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT)
  308.     GUICtrlSetResizing($cExit_Script, $_ARRAYCONSTANT_GUI_DOCKRIGHT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT)
  309.  
  310.     ; Start ListView update
  311.     GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_WM_SETREDRAW, 0, 0)
  312.  
  313.     ; Fill listview
  314.     Local $odd = False
  315.     Local $cItem
  316.     For $i = 0 To UBound($avArrayText) - 1
  317.         $cItem = GUICtrlCreateListViewItem($avArrayText[$i], $cListView)
  318.         If $iAlt_Color Then
  319.             If $odd Then GUICtrlSetBkColor($cItem, $iAlt_Color)
  320.             $odd = Not $odd
  321.         EndIf
  322.     Next
  323.  
  324.     ; Align columns if required - $iColAlign = 2 for Right and 4 for Center
  325.     If $iColAlign Then
  326.         Local Const $_ARRAYCONSTANT_LVCF_FMT = 0x01
  327.         Local Const $_ARRAYCONSTANT_LVM_SETCOLUMNW = (0x1000 + 96)
  328.         Local $tColumn = DllStructCreate("uint Mask;int Fmt;int CX;ptr Text;int TextMax;int SubItem;int Image;int Order;int cxMin;int cxDefault;int cxIdeal")
  329.         DllStructSetData($tColumn, "Mask", $_ARRAYCONSTANT_LVCF_FMT)
  330.         DllStructSetData($tColumn, "Fmt", $iColAlign / 2) ; Left = 0; Right = 1; Center = 2
  331.         Local $pColumn = DllStructGetPtr($tColumn)
  332.         ; Loop through columns
  333.         For $i = 1 To $iSubItem_End - $iSubItem_Start + 1
  334.             GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_SETCOLUMNW, $i, $pColumn)
  335.         Next
  336.     EndIf
  337.  
  338.     ; End ListView update
  339.     GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_WM_SETREDRAW, 1, 0)
  340.  
  341.     ; Allow for borders with and without vertical scrollbar
  342.     Local $iBorder = 45
  343.     If UBound($avArrayText) > 20 Then
  344.         $iBorder += 20
  345.     EndIf
  346.     ; Adjust dialog width
  347.     Local $iWidth = $iBorder, $iColWidth = 0, $aiColWidth[$iColCount + 2], $iMin_ColWidth = 50
  348.     ; Get required column widths to fit items
  349.     For $i = 0 To $iSubItem_End - $iSubItem_Start + 1
  350.         GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_SETCOLUMNWIDTH, $i, $_ARRAYCONSTANT_LVSCW_AUTOSIZE)
  351.         $iColWidth = GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH, $i, 0)
  352.         ; Set minimum if required
  353.         If $iColWidth < $iMin_ColWidth Then
  354.             GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_SETCOLUMNWIDTH, $i, $iMin_ColWidth)
  355.             $iColWidth = $iMin_ColWidth
  356.         EndIf
  357.         ; Add to total width
  358.         $iWidth += $iColWidth
  359.         ; Store  value
  360.         $aiColWidth[$i] = $iColWidth
  361.     Next
  362.     ; Now check max size
  363.     If $iWidth > @DesktopWidth - 100 Then
  364.         ; Apply max col width limit to reduce width
  365.         $iWidth = $iBorder
  366.         For $i = 0 To $iSubItem_End - $iSubItem_Start + 1
  367.             If $aiColWidth[$i] > $iMax_ColWidth Then
  368.                 ; Reset width
  369.                 GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_SETCOLUMNWIDTH, $i, $iMax_ColWidth)
  370.                 $iWidth += $iMax_ColWidth
  371.             Else
  372.                 ; Retain width
  373.                 $iWidth += $aiColWidth[$i]
  374.             EndIf
  375.         Next
  376.     EndIf
  377.     ; Check max/min width
  378.     If $iWidth > @DesktopWidth - 100 Then
  379.         $iWidth = @DesktopWidth - 100
  380.     ElseIf $iWidth < $iMinSize Then
  381.         $iWidth = $iMinSize
  382.     EndIf
  383.  
  384.     ; Get row height
  385.     Local $tRect = DllStructCreate("struct; long Left;long Top;long Right;long Bottom; endstruct")
  386.     DllCall("user32.dll", "struct*", "SendMessageW", "hwnd", GUICtrlGetHandle($cListView), "uint", $_ARRAYCONSTANT_LVM_GETITEMRECT, "wparam", 0, "struct*", $tRect)
  387.     ; Set required GUI height
  388.     Local $aiWin_Pos = WinGetPos($hGUI)
  389.     Local $aiLV_Pos = ControlGetPos($hGUI, "", $cListView)
  390.     $iHeight = ((UBound($avArrayText) + 3) * (DllStructGetData($tRect, "Bottom") - DllStructGetData($tRect, "Top"))) + $aiWin_Pos[3] - $aiLV_Pos[3]
  391.     ; Check min/max height
  392.     If $iHeight > @DesktopHeight - 100 Then
  393.         $iHeight = @DesktopHeight - 100
  394.     ElseIf $iHeight < $iMinSize Then
  395.         $iHeight = $iMinSize
  396.     EndIf
  397.  
  398.     ; Display and resize dialog
  399.     GUISetState(@SW_HIDE, $hGUI)
  400.     WinMove($hGUI, "", (@DesktopWidth - $iWidth) / 2, (@DesktopHeight - $iHeight) / 2, $iWidth, $iHeight)
  401.     GUISetState(@SW_SHOW, $hGUI)
  402.  
  403.     ; Announce if array was truncated
  404.     If $sMsg Then
  405.         MsgBox($_ARRAYCONSTANT_MB_SYSTEMMODAL + $_ARRAYCONSTANT_MB_ICONINFORMATION, "Array truncated", $sMsg, 0, $hGUI)
  406.     EndIf
  407.  
  408.     ; Switch to GetMessage mode
  409.     Local $iOnEventMode = Opt("GUIOnEventMode", 0), $iMsg
  410.  
  411.     While 1
  412.  
  413.         $iMsg = GUIGetMsg() ; Variable needed to check which "Copy" button was pressed
  414.         Switch $iMsg
  415.             Case $_ARRAYCONSTANT_GUI_EVENT_CLOSE
  416.                 ExitLoop
  417.  
  418.             Case $cCopy_ID, $cCopy_Data
  419.                 ; Count selected rows
  420.                 Local $iSel_Count = GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_GETSELECTEDCOUNT, 0, 0)
  421.                 ; Display splash dialog if required
  422.                 If Not ($iSel_Count) And ($iItem_End - $iItem_Start) * ($iSubItem_End - $iSubItem_Start) > 10000 Then
  423.                     SplashTextOn("ArrayDisplay", "Copying data" & @CRLF & @CRLF & "Please be patient", 300, 100)
  424.                 EndIf
  425.                 ; Generate clipboard text
  426.                 Local $sClip = "", $sItem, $aSplit
  427.                 ; Add items
  428.                 For $i = 0 To $iItem_End - $iItem_Start
  429.                     ; Skip if copying selected rows and item not selected
  430.                     If $iSel_Count And Not (GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_GETITEMSTATE, $i, $_ARRAYCONSTANT_LVIS_SELECTED)) Then
  431.                         ContinueLoop
  432.                     EndIf
  433.                     $sItem = $avArrayText[$i]
  434.                     If $iMsg = $cCopy_Data Then
  435.                         ; Remove row ID if required
  436.                         $sItem = StringRegExpReplace($sItem, "^\[\d+\].(.*)$", "$1")
  437.                     EndIf
  438.                     If $iCW_ColWidth Then
  439.                         ; Expand columns
  440.                         $aSplit = StringSplit($sItem, $sAD_Separator)
  441.                         $sItem = ""
  442.                         For $j = 1 To $aSplit[0]
  443.                             $sItem &= StringFormat("%-" & $iCW_ColWidth + 1 & "s", StringLeft($aSplit[$j], $iCW_ColWidth))
  444.                         Next
  445.                     Else
  446.                         ; Use defined separator
  447.                         $sItem = StringReplace($sItem, $sAD_Separator, $vUser_Separator)
  448.                     EndIf
  449.                     $sClip &= $sItem & @CRLF
  450.                 Next
  451.                 ; Add header line if required
  452.                 If $iMsg = $cCopy_ID Then
  453.                     If $iCW_ColWidth Then
  454.                         $aSplit = StringSplit($sHeader, $sAD_Separator)
  455.                         $sItem = ""
  456.                         For $j = 1 To $aSplit[0]
  457.                             $sItem &= StringFormat("%-" & $iCW_ColWidth + 1 & "s", StringLeft($aSplit[$j], $iCW_ColWidth))
  458.                         Next
  459.                     Else
  460.                         $sItem = StringReplace($sHeader, $sAD_Separator, $vUser_Separator)
  461.                     EndIf
  462.                     $sClip = $sItem & @CRLF & $sClip
  463.                 EndIf
  464.                 ;Send to clipboard
  465.                 ClipPut($sClip)
  466.                 ; Remove splash if used
  467.                 SplashOff()
  468.                 ; Refocus ListView
  469.                 GUICtrlSetState($cListView, $_ARRAYCONSTANT_GUI_FOCUS)
  470.  
  471.             Case $cUser_Func
  472.                 ; Get selected indices
  473.                 Local $aiSelItems[$iRowLimit] = [0]
  474.                 For $i = 0 To GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_GETITEMCOUNT, 0, 0)
  475.                     If GUICtrlSendMsg($cListView, $_ARRAYCONSTANT_LVM_GETITEMSTATE, $i, $_ARRAYCONSTANT_LVIS_SELECTED) Then
  476.                         $aiSelItems[0] += 1
  477.                         $aiSelItems[$aiSelItems[0]] = $i + $iItem_Start
  478.                     EndIf
  479.                 Next
  480.                 ReDim $aiSelItems[$aiSelItems[0] + 1]
  481.                 ; Pass array and selection to user function
  482.                 Call($sUser_Func, $avArray, $aiSelItems, $cListView, $hGUI)
  483.                 GUICtrlSetState($cListView, $_ARRAYCONSTANT_GUI_FOCUS)
  484.  
  485.             Case $cExit_Script
  486.                 Exit
  487.         EndSwitch
  488.     WEnd
  489.  
  490.     ; Clear up
  491.     GUIDelete($hGUI)
  492.  
  493.     Opt("GUIOnEventMode", $iOnEventMode) ; Reset original GUI mode
  494.     Opt("GUIDataSeparatorChar", $sCurr_Separator) ; Reset original separator
  495.  
  496.     Return 1
  497.  
  498. EndFunc   ;==>_ArrayDisplay_Beta
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement