Jump to content

New UDFs for GuiListView?


GaryFrost
 Share

Recommended Posts

Edit: Combined the Move and Copy to Copy with a Delete Flag

Edit: Combined the Copy Checked Items and the Copy Selected Items to

_GUICtrlListViewCopyItems

Originally this was posted in Idea Lab, maybe it wasn't the best place to post for user input.

I'll try here and see what happens.

Move or Copy items between list views, inspired by quick_silver007 submission to udf's

Need users input on if these should be added into the GuiListView UDFs

If wanted please post this needs to be added.

UDF function is at the Bottom of this post.

Example:

#include <GuiConstants.au3>
#include <GuiListView.au3>

Opt ("GUIOnEventMode", 1)
Opt ('MustDeclareVars', 1)

Dim $listview, $listview2, $Btn_MoveLeft, $Btn_MoveRight, $Btn_Exit1, $Btn_Exit2, $msg, $GUI1, $GUI2
Dim $Btn_CopyRight, $Btn_CopyLeft
Dim $OptionsMenu, $OptionsItem1, $OptionsItem2, $separator1, $OptionsItem3, $OptionsItem4
Dim $Dock = 1, $Dock_Location = 1, $x1, $x2, $y1, $y2

$GUI1 = GUICreate("GuiListView Copy Items", 300, 220, 10, 10)
$OptionsMenu = GUICtrlCreateMenu("Options")
$OptionsItem1 = GUICtrlCreateMenu("Docking", $OptionsMenu)

$OptionsItem2 = GUICtrlCreateMenuItem("Docked", $OptionsItem1)
$separator1 = GUICtrlCreateMenuItem("", $OptionsItem1)
$OptionsItem3 = GUICtrlCreateMenuItem("Side By Side", $OptionsItem1)
$OptionsItem4 = GUICtrlCreateMenuItem("Top And Bottom", $OptionsItem1)
GUICtrlSetState($OptionsItem2, $GUI_CHECKED)
GUICtrlSetState($OptionsItem3, $GUI_CHECKED)
GUICtrlSetOnEvent($OptionsItem2, "_SetDocking")
GUICtrlSetOnEvent($OptionsItem3, "_SetDockSideBySide")
GUICtrlSetOnEvent($OptionsItem4, "_SetDockTopAndBottom")

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

$listview = GUICtrlCreateListView("col1|col2|col3", 5, 5, 150, 185, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
_GUICtrlListViewSetColumnWidth($listview, 0, 60)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_CHECKBOXES, $LVS_EX_CHECKBOXES)

$Btn_MoveRight = GUICtrlCreateButton("Move", 175, 35, 90, 20)
GUICtrlSetOnEvent($Btn_MoveRight, "_MoveRight")

$Btn_CopyRight = GUICtrlCreateButton("Copy", 175, 60, 90, 20)
GUICtrlSetOnEvent($Btn_CopyRight, "_CopyRight")

$Btn_Exit1 = GUICtrlCreateButton("Exit", 175, 140, 90, 25)
GUICtrlSetOnEvent($Btn_Exit1, "_Exit")

$GUI2 = GUICreate("Right/Bottom Window", 300, 220, 315, 10)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

$Btn_MoveLeft = GUICtrlCreateButton("Move", 175, 55, 90, 20)
GUICtrlSetOnEvent($Btn_MoveLeft, "_MoveLeft")

$Btn_CopyLeft = GUICtrlCreateButton("Copy", 175, 80, 90, 20)
GUICtrlSetOnEvent($Btn_CopyLeft, "_CopyLeft")

$Btn_Exit2 = GUICtrlCreateButton("Exit", 175, 160, 90, 25)
GUICtrlSetOnEvent($Btn_Exit2, "_Exit")

$listview2 = GUICtrlCreateListView("col1|col2|col3", 5, 25, 150, 185, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
_GUICtrlListViewSetColumnWidth($listview2, 0, 60)
GUICtrlSendMsg($listview2, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($listview2, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlSendMsg($listview2, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_CHECKBOXES, $LVS_EX_CHECKBOXES)

GUICtrlCreateListViewItem("line1|data1|more1", $listview)
GUICtrlCreateListViewItem("line2|data2|more2", $listview)
GUICtrlCreateListViewItem("line3|data3|more3", $listview)
GUICtrlCreateListViewItem("line4|data4|more4", $listview)
GUICtrlCreateListViewItem("line5|data5|more5", $listview)

GUISetState(@SW_SHOW, $GUI2)
GUISetState(@SW_SHOW, $GUI1)

While 1
    If $Dock Then _KeepWindowsDocked()
    Sleep(10)
WEnd

Func _SetDocking()
    If BitAND(GUICtrlRead($OptionsItem2), $GUI_CHECKED) = $GUI_CHECKED Then
        GUICtrlSetState($OptionsItem2, $GUI_UNCHECKED)
        $Dock = 0
    Else
        GUICtrlSetState($OptionsItem2, $GUI_CHECKED)
        $Dock = 2
    EndIf
    If $Dock Then _KeepWindowsDocked()
EndFunc  ;==>_SetDocking

Func _SetDockSideBySide()
    If BitAND(GUICtrlRead($OptionsItem3), $GUI_CHECKED) = $GUI_CHECKED Then
        GUICtrlSetState($OptionsItem3, $GUI_UNCHECKED)
        GUICtrlSetState($OptionsItem4, $GUI_CHECKED)
        $Dock_Location = 2
    Else
        GUICtrlSetState($OptionsItem3, $GUI_CHECKED)
        GUICtrlSetState($OptionsItem4, $GUI_UNCHECKED)
        $Dock_Location = 1
        If $Dock Then $Dock = 2
    EndIf
    If $Dock Then _KeepWindowsDocked()
EndFunc  ;==>_SetDockSideBySide

Func _SetDockTopAndBottom()
    If BitAND(GUICtrlRead($OptionsItem4), $GUI_CHECKED) = $GUI_CHECKED Then
        GUICtrlSetState($OptionsItem4, $GUI_UNCHECKED)
        GUICtrlSetState($OptionsItem3, $GUI_CHECKED)
        $Dock_Location = 1
    Else
        GUICtrlSetState($OptionsItem4, $GUI_CHECKED)
        GUICtrlSetState($OptionsItem3, $GUI_UNCHECKED)
        $Dock_Location = 2
        If $Dock Then $Dock = 2
    EndIf
    If $Dock Then _KeepWindowsDocked()
EndFunc  ;==>_SetDockTopAndBottom

Func _KeepWindowsDocked()
    Local $p_win1 = WinGetPos($GUI1)
    Local $p_win2 = WinGetPos($GUI2)
    If $Dock_Location == 1 Then
        If (($p_win1[0] <> $x1 Or $p_win1[1] <> $y1) And BitAND(WinGetState($GUI1), 8) Or $Dock = 2) Then
            $x1 = $p_win1[0]
            $y1 = $p_win1[1]
            $x2 = $p_win1[2] + $x1
            $y2 = $y1
            WinMove($GUI2, "", $x2, $y2)
            $Dock = 1
        ElseIf (($p_win2[0] <> $x2 Or $p_win2[1] <> $y2) And BitAND(WinGetState($GUI2), 8)) Then
            $x2 = $p_win2[0]
            $y2 = $p_win2[1]
            $x1 = $p_win2[0] - $p_win1[2]
            $y1 = $y2
            WinMove($GUI1, "", $x1, $y1)
        EndIf
    Else
        If (($p_win1[0] <> $x1 Or $p_win1[1] <> $y1) And BitAND(WinGetState($GUI1), 8) Or $Dock = 2) Then
            $x1 = $p_win1[0]
            $y1 = $p_win1[1]
            $x2 = $x1
            $y2 = $p_win1[3] + $y1
            WinMove($GUI2, "", $x2, $y2)
            $Dock = 1
        ElseIf (($p_win2[0] <> $x2 Or $p_win2[1] <> $y2) And BitAND(WinGetState($GUI2), 8)) Then
            $x2 = $p_win2[0]
            $y2 = $p_win2[1]
            $x1 = $x2
            $y1 = $p_win2[1] - $p_win1[3]
            WinMove($GUI1, "", $x1, $y1)
        EndIf
    EndIf
EndFunc  ;==>_KeepWindowsDocked

Func _CopyRight()
    _GUICtrlListViewCopyItems($listview, $listview2)
EndFunc  ;==>_MoveRight

Func _MoveRight()
    _GUICtrlListViewCopyItems($listview, $listview2, 1)
EndFunc  ;==>_MoveRight

Func _CopyLeft()
    _GUICtrlListViewCopyItems($listview2, $listview)
EndFunc  ;==>_MoveLeft

Func _MoveLeft()
    _GUICtrlListViewCopyItems($listview2, $listview, 1)
EndFunc  ;==>_MoveLeft

Func _Exit()
    Exit
EndFunc  ;==>_Exit

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
    EndSelect
EndFunc  ;==>SpecialEvents

Proposed UDF function to add:

Func _GUICtrlListViewCopyItems($h_Source_listview, $h_Destination_listview, $i_DelFlag = 0, $s_WindowTitle = "", $s_WindowText = "")
    Local $a_indices, $i, $s_item, $control_ID, $items
    $items = _GUICtrlListViewGetItemCount ($h_Source_listview)

    If BitAND(_GUICtrlListViewGetExtendedListViewStyle($h_Source_listview),$LVS_EX_CHECKBOXES) == $LVS_EX_CHECKBOXES Then
        For $i = 0 To $items - 1
            If (_GUICtrlListViewGetCheckedState ($h_Source_listview, $i)) Then
                If IsArray($a_indices) Then
                    ReDim $a_indices[UBound($a_indices) + 1]
                Else
                    Dim $a_indices[2]
                EndIf
                $a_indices[0] = $a_indices[0] + 1
                $a_indices[UBound($a_indices) - 1] = $i
            EndIf
        Next
        
        If (IsArray($a_indices)) Then
            If (StringLen($s_WindowTitle) == 0) Then
                $s_WindowTitle = WinGetTitle("")
            EndIf
            For $i = 1 To $a_indices[0]
                $s_item = _GUICtrlListViewGetItemText ($h_Source_listview, $a_indices[$i], -1, $s_WindowTitle, $s_WindowText)
                _GUICtrlListViewSetCheckState($h_Source_listview, $a_indices[$i], 0)
                GUICtrlCreateListViewItem($s_item, $h_Destination_listview)
            Next
            If $i_DelFlag Then 
                For $i = $a_indices[0] To 1 Step - 1
                    _GUICtrlListViewSetItemSelState ($h_Source_listview, $a_indices[$i])
                    $control_ID = GUICtrlRead($h_Source_listview)
                    GUICtrlDelete($control_ID)
                Next
            EndIf
        EndIf
    EndIf
    If (_GUICtrlListViewGetSelectedCount ($h_Source_listview)) Then
        If (StringLen($s_WindowTitle) == 0) Then
            $s_WindowTitle = WinGetTitle("")
        EndIf
        $a_indices = _GUICtrlListViewGetSelectedIndices ($h_Source_listview, 1, $s_WindowTitle, $s_WindowText)
        For $i = 1 To $a_indices[0]
            $s_item = _GUICtrlListViewGetItemText ($h_Source_listview, $a_indices[$i], -1, $s_WindowTitle, $s_WindowText)
            GUICtrlCreateListViewItem($s_item, $h_Destination_listview)
        Next
        ControlListView($s_WindowTitle, $s_WindowText, $h_Source_listview, "SelectClear")
        If $i_DelFlag Then 
            For $i = $a_indices[0] To 1 Step - 1
                _GUICtrlListViewSetItemSelState ($h_Source_listview, $a_indices[$i])
                $control_ID = GUICtrlRead($h_Source_listview)
                GUICtrlDelete($control_ID)
            Next
        EndIf
    EndIf
EndFunc  ;==>_GUICtrlListViewCopyItems

Gary

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...