I added the graphical side of the checkboxes to the prototype listview control.
.
Code: Select all
;****************************************************************************************************************************************************************************
#Include <My Altered GDIP lib> ;GDIP: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517
#Include <PopUpWindow_V2> ; Paste at the bottom of the script
#Include <HB Vectors v2> ; Paste at the bottom of the script
;****************************************************************************************************************************************************************************
#SingleInstance, Force
SetBatchLines, -1
Gdip_Startup()
Gui1 := {}
Gui1.W := 800
Gui1.H := 420
Gui1.X := A_ScreenWidth - Gui1.W - 40
Gui1.Y := 150
Gui1.Scale := 1
;***********************************
Gui, New, +AlwaysOnTop +hwndhwnd -DPIScale
Gui1.Hwnd := hwnd
;***********************************
;***********************************
cc := Gui1
Gui, Show, % "x" cc.X " y" cc.Y " w" cc.W * cc.Scale " h" cc.H * cc.Scale
;***********************************
x := 10 ;at x *margin
y := 10 ;at y *margin
w := 700
h := 400
cc := Gui1.Listview1 := New PopUpWindow( { AutoShow: 1 , X: x , Y: y , W: w * Gui1.Scale , H: h * Gui1.Scale , Options: " -DPIScale +Parent" Gui1.Hwnd } )
cc.Sections := []
x := 0
w := 200
cc.Sections[ 1 ] := { Header: "Section 1" , X: x , Y: 0 , W: w , H: 24 , MoveVector: New Vector( x + w + 1 , 0 ) }
x += w + 3
cc.Sections[ 2 ] := { Header: "Section 2" , X: x , Y: 0 , W: w , H: 24 , MoveVector: New Vector( x + w + 1 , 0 ) }
x += w + 3
cc.Sections[ 3 ] := { Header: "Section 3" , X: x , Y: 0 , W: w , H: 24 , MoveVector: New Vector( x + w + 1 , 0 ) }
x += w + 3
cc.Sections[ 4 ] := { Header: "Section 4" , X: x , Y: 0 , W: w , H: 24 , MoveVector: New Vector( x + w + 1 , 0 ) }
x += w + 3
cc.Sections[ 5 ] := { Header: "Section 5" , X: x , Y: 0 , W: w , H: 24 , MoveVector: New Vector( x + w + 1 , 0 ) }
cc.Rows := []
DrawListControl( Gui1 )
obj := {}
obj.Values := [ "Item 1" , "Item 1 Value 1" , "Item 1 Value 2" , "Item 1 Value 3" ]
obj.Children := []
obj.Children[ 1 ] := [ "Item 1" , "Item 1 Value 1" , "Item 1 Value 2" , "Item 1 Value 3" ]
obj.Children[ 2 ] := [ "Header" , "Blah" , "Blah Blah" , "Blah Blah, Blah" ]
obj.Children[ 3 ] := [ "Section 1" , "Section 2" , "Section 3" , "Section 4" ]
obj.State := 0
Gui1.bob := New ListViewPanels( obj , Gui1.Listview1 )
;***********************************
obj := {}
obj.Values := [ "Main Header" , "1223" , "ABCD" , "Boop" ]
obj.Children := []
obj.Children[ 1 ] := [ "Item 1" , "Item 1 Value 1" , "Item 1 Value 2" , "Item 1 Value 3" ]
obj.Children[ 2 ] := [ "Header" , "Blah" , "Blah Blah" , "Blah Blah, Blah" ]
obj.Children[ 3 ] := [ "Section 1" , "Section 2" , "Section 3" , "Section 4" ]
obj.Children[ 4 ] := [ "Section 1" , "Section 2" , "Section 3" , "Section 4" ]
obj.Children[ 5 ] := [ "The next cell is empty" , "" , "Section 3" , "Section 4" ]
obj.Children[ 6 ] := [ "" , "Section 2" , "Section 3" , "Section 4" ]
obj.Children[ 7 ] := [ "Section 1" , "Section 2" , "Section 3" , "Section 4" ]
obj.ChildStates := [ 1 , 1 , 0 , 1 , "" , 1 , 0 ]
obj.FontSize := 12
obj.ChildFontSize := 12
Gui1.sam := New ListViewPanels( obj , Gui1.Listview1 )
;***********************************
obj := {}
obj.Values := [ "Example 3" , "4467" , "ABCD" , "Beep" ]
obj.Children := []
obj.Children[ 1 ] := [ "Item 1" , "Item 1 Value 1" , "Item 1 Value 2" , "Item 1 Value 3" ]
obj.Children[ 2 ] := [ "Header" , "Blah" , "Blah Blah" , "Blah Blah, Blah" ]
obj.FontSize := 12
obj.ChildFontSize := 12
obj.State := ""
obj.ChildStates := [ 0 , 1 ]
Gui1.joe := New ListViewPanels( obj , Gui1.Listview1 )
;***********************************
;~ Gui1.Listview1.Sections[ 2 ].X := 66
;~ ToolTip, % "Tip:`n" bob.RowHeight "`n" bob.Rows "`n: " bob.Sections[ 2 ].x
OnMessage( 0x201 , Func( "ClickEvent" ).Bind( Gui1 ) )
DrawListControl( Gui1 )
return
GuiClose:
GuiContextMenu:
*ESC::ExitApp
class ListViewPanels {
static Index := 0 , Panels := []
__New( obj := "" , parent := "" ){
This._SetDefaults()
This._UpdateDefaults( obj , parent )
;~ ToolTip, % "Tip:`n" This.RowHeight "`n" This.Rows "`n: " This.Sections[ 2 ].x
}
_SetDefaults(){
This.Index := ++ListViewPanels.Index
This.FontType := "Arial"
This.FontSize := 12
This.FontOptions := "vCenter Bold NoWrap"
This.FontColor := "0xFF000000"
This.FontColorBottom := "0x00000000"
This.ChildFontType := "Arial"
This.ChildFontSize := 12
This.ChildFontOptions := "vCenter NoWrap"
This.ChildFontColor := "0xFF000000"
This.Values := []
This.Children := []
This.RowHeight := ""
This.ToggleState := 1
This.PaddingX := 2
This.PaddingY := 2
This.TabSpacing := 15
This.State := 1
}
_UpdateDefaults( obj := "" , parent := "" ){
if( isObject( obj ) ){
for k , v in obj {
if( k != "Values" && k != "Children" && k != "ChildStates" )
This[ k ] := obj[ k ]
}
if( obj.Haskey( "Values" ) ){
for k , v in obj.Values {
This.Values[ A_Index ] := v
}
if( obj.Haskey( "Children" ) ){
Loop, % Obj.Children.Length(){
This.Children[ Index := A_Index ] := []
Loop, % Obj.Children[ Index ].Length() {
This.Children[ Index ][ A_Index ] := Obj.Children[ Index ][ A_Index ]
}
}
if( obj.Haskey( "ChildStates" ) ){
This.ChildStates := []
This.HasChildStates := 1
loop, % obj.ChildStates.Length() {
if( obj.ChildStates[ A_Index ] = "" )
This.ChildStates[ A_Index ] := ""
else
This.ChildStates[ A_Index ] := obj.ChildStates[ A_Index ]
}
}
}
}
if( parent != "" ){
This.Parent := parent
This.Sections := parent.Sections
This.TotalWidth := 2
Loop, % This.Sections.Length() {
This.TotalWidth += This.Sections[ A_Index ].W + 2
}
}
}
This.RowHeight := This._GetRowHeight( "Height" )
This.Rows := 1 + This.Children.Length()
This.Height1 := This.RowHeight + 2 * This.PaddingY
This.Height2 := ( This.RowHeight * This.Rows ) + ( This.PaddingY * ( This.Rows + 1 ) )
;~ This.Width1 := This.TotalWidth
This.Width1 := This.TotalWidth
This.Bitmap := This._CreatePanelBitmap()
}
_GetRowHeight( InputType := "Width" , Text := "Sample" ){
local pBitmap := Gdip_CreateBitmap( 10 , 10 )
local Graphics := Gdip_GraphicsFromImage( pBitmap )
local Brush := Gdip_BrushCreateSolid( "0xFF000000")
local OutputArray := ""
local Output := 0
local cc := This
Gdip_SetSmoothingMode( Graphics , 2 )
outputArray := StrSplit( Gdip_TextToGraphics( Graphics , Text , " s" cc.Fontsize " c" Brush " " cc.FontOptions " x" 0 " y" 0 , cc.FontType , 10000 , 10000 ) , "|" , "|" )
if( InputType = "Width" ){
Output := outputArray[ 3 ]
}else if( InputType = "Height" ){
Output := outputArray[ 4 ]
}
Gdip_DeleteBrush( Brush )
Gdip_DeleteGraphics( Graphics )
Gdip_DisposeImage( pBitmap )
return ceil( Output )
}
_CreatePanelBitmap(){
ScaleFactor := 1
if( This.ToggleState )
;~ pBitmap := Gdip_CreateBitmap( This.Width1 , This.Height2 )
pBitmap := Gdip_CreateBitmap( This.Parent.W , This.Height2 )
else
;~ pBitmap := Gdip_CreateBitmap( This.Width1 , This.Height1 )
pBitmap := Gdip_CreateBitmap( This.Parent.W , This.Height1 )
G := Gdip_GraphicsFromImage( pBitmap )
Gdip_SetSmoothingMode( G , 2 )
;draw the background of the panel
x := -2
y := -2
w := This.Width1 + 4
if( This.ToggleState )
This.H := h := This.Height2
else
This.H := h := This.Height1
;~ Brush := Gdip_BrushCreateSolid( "0xFFD6DBE9" )
Brush := Gdip_BrushCreateSolid( "0xFFFFFFFF" )
, Gdip_FillRectangle( G , Brush , x * ScaleFactor , y * ScaleFactor , w * ScaleFactor , h * ScaleFactor )
, Gdip_DeleteBrush( Brush )
Loop, % This.Sections.Length() {
;~ x := This.Sections[ A_Index ].X
x := This.Sections[ A_Index ].X
y := 0
w := This.Sections[ A_Index ].W
h := This.Height1
;~ MsgBox, % x
Brush := Gdip_BrushCreateSolid( "0xFFE4F8F8" )
, Gdip_FillRectangle( G , Brush , x * ScaleFactor , y * ScaleFactor , w * ScaleFactor , h * ScaleFactor )
, Gdip_DeleteBrush( Brush )
if( A_Index = 1 ){
x += This.TabSpacing
w -= This.TabSpacing
if( This.Children.Length() >= 1 ){
Brush := Gdip_BrushCreateSolid( "0xFF000000" )
, Gdip_TextToGraphics( G , ( This.ToggleState ) ? ( "5" ) : ( "6" ) , "s" 16 * ScaleFactor " Center vCenter c" Brush " x" ( x + 2 ) * ScaleFactor " y"( y + 4 ) * ScaleFactor , "WebDings" , ( This.RowHeight - 2 ) * ScaleFactor , ( This.RowHeight - 2 ) * ScaleFactor )
, Gdip_DeleteBrush( Brush )
x += This.RowHeight + 2
w -= This.RowHeight + 2
}
if( This.State != "" ){
Gdip_SetSmoothingMode( G , 1 )
Brush := Gdip_BrushCreateSolid( "0xFF000000" )
, Gdip_FillRectangle( G , Brush , x * ScaleFactor , ( y + 2 ) * ScaleFactor , This.RowHeight * ScaleFactor , This.RowHeight * ScaleFactor )
, Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFFFFFFFF" )
, Gdip_FillRectangle( G , Brush , ( x + 1 ) * ScaleFactor , ( y + 3 ) * ScaleFactor , ( This.RowHeight - 2 ) * ScaleFactor , ( This.RowHeight - 2 ) * ScaleFactor )
, Gdip_DeleteBrush( Brush )
if( This.State ){
Brush := Gdip_BrushCreateSolid( "0xFF000000" )
, Gdip_TextToGraphics( G , "a" , "s" 20 * ScaleFactor " Center vCenter c" Brush " x" ( x + 2 ) * ScaleFactor " y"( y + 4 ) * ScaleFactor , "WebDings" , ( This.RowHeight - 2 ) * ScaleFactor , ( This.RowHeight - 2 ) * ScaleFactor )
, Gdip_DeleteBrush( Brush )
}
x += This.RowHeight + 2
w -= This.RowHeight + 2
}
}
Gdip_SetSmoothingMode( G , 2 )
Brush := Gdip_BrushCreateSolid( This.FontColor )
, Gdip_TextToGraphics( G , This.Values[ A_Index ] , "s" This.FontSize * ScaleFactor " " This.FontOptions " c" Brush " x" x * ScaleFactor " y" y * ScaleFactor , This.FontType , w * ScaleFactor , h * ScaleFactor )
, Gdip_DeleteBrush( Brush )
}
if( This.Children.Length() ){
;~ SoundBeep
;~ colors := [ "0xFFFF0000" , "0xFFFFFF00" , "0xFFFF8000" , "0xFF80FFFF" , "0xFF00FF80" , "0xFF00FF00" ]
;~ colors := [ "0xFFfcfcfc" , "0xFFdbdddf" , "0xFFc0c3c7" , "0xFFa8abb2" , "0xFF90949c" ]
;~ colors := [ "0xFFfefefe" , "0xFFf7f8f8" , "0xFFf0f0f1" , "0xFFe5e6e8" , "0xFFdadcde" ]
colors := [ "0xFFFFFFFF" , "0xFFFFFFFF" , "0xFFFFFFFF" , "0xFFFFFFFF" , "0xFFFFFFFF" ]
;~ x += This.TabSpacing
;~ w -= This.TabSpacing
Loop, % This.Children.Length() {
y += This.Height1 - This.PaddingY
;~ Brush := Gdip_BrushCreateSolid( "0xFFFF0000" )
Index := A_Index
Loop, % This.Sections.Length() {
if( A_Index = 1 ){
;~ x := This.Sections[ A_Index ].X + 2 * This.TabSpacing
x := This.Sections[ A_Index ].X + 2 * ( This.RowHeight + 2) + This.TabSpacing
w := This.Sections[ A_Index ].W - 2 * ( This.RowHeight + 2) - This.TabSpacing
if( This.HasChildStates ){
;~ SoundBeep
if( This.ChildStates[ Index ] != "" ){
Gdip_SetSmoothingMode( G , 1 )
Brush := Gdip_BrushCreateSolid( "0xFF000000" )
, Gdip_FillRectangle( G , Brush , x * ScaleFactor , ( y + 2 ) * ScaleFactor , This.RowHeight * ScaleFactor , This.RowHeight * ScaleFactor )
, Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFFFFFFFF" )
, Gdip_FillRectangle( G , Brush , ( x + 1 ) * ScaleFactor , ( y + 3 ) * ScaleFactor , ( This.RowHeight - 2 ) * ScaleFactor , ( This.RowHeight - 2 ) * ScaleFactor )
, Gdip_DeleteBrush( Brush )
if( This.ChildStates[ Index ] ){
Brush := Gdip_BrushCreateSolid( "0xFF000000" )
, Gdip_TextToGraphics( G , "a" , "s" 16 * ScaleFactor " Center vCenter c" Brush " x" ( x + 2 ) * ScaleFactor " y"( y + 4 ) * ScaleFactor , "WebDings" , ( This.RowHeight - 2 ) * ScaleFactor , ( This.RowHeight - 2 ) * ScaleFactor )
, Gdip_DeleteBrush( Brush )
}
}
x += This.RowHeight + 2
w -= This.RowHeight - 2
}
}else{
x := This.Sections[ A_Index ].X
w := This.Sections[ A_Index ].W
}
;~ y := 0
;~ w := This.Sections[ A_Index ].W
h := This.Height1
Brush := Gdip_BrushCreateSolid( colors[ A_Index ] )
, Gdip_FillRectangle( G , Brush , x * ScaleFactor , y * ScaleFactor , w * ScaleFactor , h * ScaleFactor )
, Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( This.ChildFontColor )
, Gdip_TextToGraphics( G , This.Children[ Index ][ A_Index ] , "s" This.ChildFontSize * ScaleFactor " " This.ChildFontOptions " c" Brush " x" ( x + 2 ) * ScaleFactor " y" y * ScaleFactor , This.ChildFontType , w * ScaleFactor , h * ScaleFactor )
, Gdip_DeleteBrush( Brush )
}
}
}
Gdip_DeleteGraphics( G )
return pBitmap
}
}
ClickEvent( Gui1 ){
CoordMode, Mouse, Client
MouseGetPos, x , y
MouseVector := New Vector( ( x / Gui1.Scale ) - Gui1.Listview1.X , ( y / Gui1.Scale ) - Gui1.Listview1.Y )
closest := 1000
cIndex := ""
Loop, % Gui1.Listview1.Sections.Length() {
cc := Gui1.Listview1.Sections[ A_Index ].MoveVector
if( ( nDist := MouseVector.Dist( cc ) ) <= 10 ){
if( nDist < closest ){
closest := nDist
cIndex := A_Index
}
}
}
if( cIndex ){
cc := Gui1.Listview1.Sections[ cIndex ]
lx := ""
ly := ""
While( GetKeyState( "LButton" , "P" ) ){
MouseGetPos, x , y
x /= Gui1.Scale
y /= Gui1.Scale
x -= Gui1.Listview1.X
y -= Gui1.Listview1.Y
if( cIndex = 1 ){
if( x < 1 && lx != x ){
vc := lx := cc.MoveVector.X := 1
cc.W := 1
ox := Gui1.Listview1.Sections[ cIndex + 1 ].X
nx := Gui1.Listview1.Sections[ cIndex + 1 ].X := cc.MoveVector.X + 1
Loop, % Gui1.Listview1.Sections.Length() - 1 {
ox := Gui1.Listview1.Sections[ cIndex + A_Index ].X
nx := Gui1.Listview1.Sections[ cIndex + A_Index ].X := vc + 1
vc := Gui1.Listview1.Sections[ cIndex + A_Index ].MoveVector.X := nx + Gui1.Listview1.Sections[ cIndex + A_Index ].W
}
}else if( lx != x ){
vc := lx := cc.MoveVector.X := x
cc.W := x
Loop, % Gui1.Listview1.Sections.Length() - 1 {
ox := Gui1.Listview1.Sections[ cIndex + A_Index ].X
nx := Gui1.Listview1.Sections[ cIndex + A_Index ].X := vc + 1
vc := Gui1.Listview1.Sections[ cIndex + A_Index ].MoveVector.X := nx + Gui1.Listview1.Sections[ cIndex + A_Index ].W
}
}
}else{
if( x <= Gui1.Listview1.Sections[ cIndex - 1 ].MoveVector.X && lx != x ){
vc := lx := cc.MoveVector.X := Gui1.Listview1.Sections[ cIndex - 1 ].MoveVector.X + 1
cc.W := lx - Gui1.Listview1.Sections[ cIndex - 1 ].MoveVector.X
Loop, % Gui1.Listview1.Sections.Length() - cIndex {
ox := Gui1.Listview1.Sections[ cIndex + A_Index ].X
nx := Gui1.Listview1.Sections[ cIndex + A_Index ].X := vc + 1
vc := Gui1.Listview1.Sections[ cIndex + A_Index ].MoveVector.X := nx + Gui1.Listview1.Sections[ cIndex + A_Index ].W
}
}else if( lx != x ){
vc := lx := cc.MoveVector.X := x
cc.W := x - Gui1.Listview1.Sections[ cIndex - 1 ].MoveVector.X
Loop, % Gui1.Listview1.Sections.Length() - cIndex {
ox := Gui1.Listview1.Sections[ cIndex + A_Index ].X
nx := Gui1.Listview1.Sections[ cIndex + A_Index ].X := vc + 1
vc := Gui1.Listview1.Sections[ cIndex + A_Index ].MoveVector.X := nx + Gui1.Listview1.Sections[ cIndex + A_Index ].W
}
}
ToolTip, % cIndex
}
DrawListControl( Gui1 )
}
ToolTip
}
}
DrawListControl( Gui1 ){
if( Gui1.Busy )
return
Gui1.Busy := 1
cc := Gui1.Listview1
cc.ClearWindow()
y := 26
;~ _UpdateDefaults()
;~ cc.DrawBitmap( Gui1.bob._CreatePanelBitmap() , { X: 0 , Y: y , W: Gui1.bob.Width1 , H: Gui1.bob.H } , dispose := 1 , AutoUpdate := 0 )
cc.DrawBitmap( Gui1.bob._CreatePanelBitmap() , { X: 0 , Y: y , W: Gui1.bob.Parent.W , H: Gui1.bob.H } , dispose := 1 , AutoUpdate := 0 )
y += Gui1.bob.H
cc.DrawBitmap( Gui1.sam._CreatePanelBitmap() , { X: 0 , Y: y , W: Gui1.sam.Parent.W , H: Gui1.sam.H } , dispose := 1 , AutoUpdate := 0 )
y += Gui1.sam.H
cc.DrawBitmap( Gui1.joe._CreatePanelBitmap() , { X: 0 , Y: y , W: Gui1.joe.Parent.W , H: Gui1.joe.H } , dispose := 1 , AutoUpdate := 0 )
cc.DrawBitmap( HB_BITMAP_MAKER( Gui1 , Gui1.Scale ) , { X: 0 , Y: 0 , W: cc.W , H: cc.H } , dispose := 1 , AutoUpdate := 1 )
sleep, 30
Gui1.Busy := 0
}
HB_BITMAP_MAKER( Gui1 , ScaleFactor := 1 ){
;Bitmap Created Using: HB Bitmap Maker
pBitmap := Gdip_CreateBitmap( Gui1.Listview1.W , Gui1.Listview1.H ) , G := Gdip_GraphicsFromImage( pBitmap ) , Gdip_SetSmoothingMode( G , 2 )
;background
;~ SoundBeep
;~ x := -2
;~ y := -2
;~ w := ( Gui1.Listview1.W / Gui1.Scale ) + 4
;~ h := ( Gui1.Listview1.H / Gui1.Scale ) + 4
;~ Brush := Gdip_BrushCreateSolid( "0xFFFFFFFF" )
;~ , Gdip_FillRectangle( G , Brush , x * ScaleFactor , y * ScaleFactor , w * ScaleFactor , h * ScaleFactor )
;~ , Gdip_DeleteBrush( Brush )
;header background
x := -2
y := -2
w := ( Gui1.Listview1.W / Gui1.Scale ) + 4
h := 26
Brush := Gdip_BrushCreateSolid( "0xFFD6DBE9" )
, Gdip_FillRectangle( G , Brush , x * ScaleFactor , y * ScaleFactor , w * ScaleFactor , h * ScaleFactor )
, Gdip_DeleteBrush( Brush )
;section headers
Loop, % Gui1.Listview1.Sections.Length() {
cc := Gui1.Listview1.Sections[ A_Index ]
if( cc.W > 5 ){
Brush := Gdip_BrushCreateSolid( "0xFF000000" )
, Gdip_TextToGraphics( G , cc.Header , "s" 12 * ScaleFactor " vCenter NoWrap Bold c" Brush " x" ( cc.X + 2 ) * ScaleFactor " y" cc.Y * ScaleFactor , "Segoe ui" , cc.W * ScaleFactor , cc.H * ScaleFactor )
, Gdip_DeleteBrush( Brush )
}
x := cc.MoveVector.X
y := cc.MoveVector.Y
w := 3
h := Gui1.H
Gdip_SetSmoothingMode( G , 1 )
Brush := Gdip_BrushCreateSolid( "0xFF22262a" )
, Gdip_FillRectangle( G , Brush , x * ScaleFactor , y * ScaleFactor , w * ScaleFactor , h * ScaleFactor )
, Gdip_DeleteBrush( Brush )
w := 2
Brush := Gdip_BrushCreateSolid( "0xFFD6DBE9" )
, Gdip_FillRectangle( G , Brush , x * ScaleFactor , y * ScaleFactor , w * ScaleFactor , h * ScaleFactor )
, Gdip_DeleteBrush( Brush )
Gdip_SetSmoothingMode( G , 2 )
}
Gdip_DeleteGraphics( G )
return pBitmap
}