My MyTable/MyGrid

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
Cyllceaux
Enthusiast
Enthusiast
Posts: 353
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

My MyTable/MyGrid

Post by Cyllceaux »

Since everyone post his own Version of a table, here is my version.
Image

All 5 Elements are tables. It's not "clean code" but it does what it should.


And the example to show how to use it.

Code: Select all

EnableExplicit

UsePNGImageDecoder()

XIncludeFile "mytable.pbi"

Define rowImage=LoadImage(#PB_Any,"C:\Users\silko\OneDrive\Dokumente\Icons\office\png-hot\48x48\Briefcase.png")
Define rowImageSub=LoadImage(#PB_Any,"C:\Users\silko\OneDrive\Dokumente\Icons\office\png-hot\48x48\Lock.png")
Define rowImageSub2=LoadImage(#PB_Any,"C:\Users\silko\OneDrive\Dokumente\Icons\office\png-hot\48x48\Attach.png")

Global mainWindow=OpenWindow(#PB_Any,0,0,800,600,"MyTable",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget)

Global canvasTable=CanvasGadget(#PB_Any,0,0,WindowWidth(mainWindow),WindowHeight(mainWindow),#PB_Canvas_Container|#PB_Canvas_Border|#PB_Canvas_DrawFocus)
Global hscrollTable=ScrollBarGadget(#PB_Any,0,GadgetHeight(canvasTable)-20,GadgetWidth(canvasTable)-20,20,0,0,100)
Global vscrollTable=ScrollBarGadget(#PB_Any,GadgetWidth(canvasTable)-20,0,20,GadgetHeight(canvasTable)-20,0,0,100,#PB_ScrollBar_Vertical)              
CloseGadgetList()

Global canvasTable2=CanvasGadget(#PB_Any,0,0,WindowWidth(mainWindow),WindowHeight(mainWindow),#PB_Canvas_Container|#PB_Canvas_Border|#PB_Canvas_DrawFocus)
Global hscrollTable2=ScrollBarGadget(#PB_Any,0,GadgetHeight(canvasTable2)-20,GadgetWidth(canvasTable2)-20,20,0,0,100)
Global vscrollTable2=ScrollBarGadget(#PB_Any,GadgetWidth(canvasTable2)-20,0,20,GadgetHeight(canvasTable2)-20,0,0,100,#PB_ScrollBar_Vertical)              
CloseGadgetList()

Global canvasTree=CanvasGadget(#PB_Any,0,0,WindowWidth(mainWindow),WindowHeight(mainWindow),#PB_Canvas_Container|#PB_Canvas_Border|#PB_Canvas_DrawFocus)
Global hscrollTree=ScrollBarGadget(#PB_Any,0,GadgetHeight(canvasTree)-20,GadgetWidth(canvasTree)-20,20,0,0,100)
Global vscrollTree=ScrollBarGadget(#PB_Any,GadgetWidth(canvasTree)-20,0,20,GadgetHeight(canvasTree)-20,0,0,100,#PB_ScrollBar_Vertical)              
CloseGadgetList()

Global canvasTree2=CanvasGadget(#PB_Any,0,0,WindowWidth(mainWindow),WindowHeight(mainWindow),#PB_Canvas_Container|#PB_Canvas_Border|#PB_Canvas_DrawFocus)
Global hscrollTree2=ScrollBarGadget(#PB_Any,0,GadgetHeight(canvasTree2)-20,GadgetWidth(canvasTree2)-20,20,0,0,100)
Global vscrollTree2=ScrollBarGadget(#PB_Any,GadgetWidth(canvasTree2)-20,0,20,GadgetHeight(canvasTree2)-20,0,0,100,#PB_ScrollBar_Vertical)              
CloseGadgetList()

Global canvasBild=CanvasGadget(#PB_Any,WindowWidth(mainWindow)-150,0,150,WindowHeight(mainWindow),#PB_Canvas_Container|#PB_Canvas_Border|#PB_Canvas_DrawFocus)
Global hscrollBild=ScrollBarGadget(#PB_Any,0,GadgetHeight(canvasBild)-20,GadgetWidth(canvasBild)-20,20,0,0,100)
Global vscrollBild=ScrollBarGadget(#PB_Any,GadgetWidth(canvasBild)-20,0,20,GadgetHeight(canvasBild)-20,0,0,100,#PB_ScrollBar_Vertical)              
CloseGadgetList()


Global splitter=SplitterGadget(#PB_Any,0,0,0,0,canvasTable,canvasTable2,#PB_Splitter_FirstFixed|#PB_Splitter_Separator)
Global splitter2=SplitterGadget(#PB_Any,0,0,0,0,canvasTree,canvasTree2,#PB_Splitter_FirstFixed|#PB_Splitter_Separator)
Global splitter3=SplitterGadget(#PB_Any,0,0,WindowWidth(mainWindow)-150,WindowHeight(mainWindow),splitter2,splitter,#PB_Splitter_FirstFixed|#PB_Splitter_Vertical|#PB_Splitter_Separator)

SetGadgetState(splitter,300)
SetGadgetState(splitter2,300)
SetGadgetState(splitter3,300)

Procedure evtResizeWindow()
	ResizeGadget(splitter3,
	             #PB_Ignore,
	             #PB_Ignore,
	             WindowWidth(EventWindow())-150,
	             WindowHeight(EventWindow()))
	ResizeGadget(canvasBild,
	             WindowWidth(EventWindow())-150,
	             #PB_Ignore,
	             #PB_Ignore,
	             WindowHeight(EventWindow()))
EndProcedure

BindEvent(#PB_Event_SizeWindow,@evtResizeWindow(),mainWindow)
BindEvent(#PB_Event_RestoreWindow,@evtResizeWindow(),mainWindow)
BindEvent(#PB_Event_MaximizeWindow,@evtResizeWindow(),mainWindow)

MyTableRegister(mainWindow,canvasTable,hscrollTable,vscrollTable)
MyTableRegister(mainWindow,canvasTable2,hscrollTable2,vscrollTable2,#MYTABLE_TABLE_FLAGS_FULL_ROW_SELECT|#MYTABLE_TABLE_FLAGS_LAST_STRETCH|#MYTABLE_TABLE_FLAGS_GRID)
MyTableRegister(mainWindow,canvasTree,hscrollTree,vscrollTree,#MYTABLE_TABLE_FLAGS_LAST_STRETCH|#MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW|#MYTABLE_TABLE_FLAGS_CHECKBOX)
MyTableRegister(mainWindow,canvasTree2,hscrollTree2,vscrollTree2,#MYTABLE_TABLE_FLAGS_LAST_STRETCH|#MYTABLE_TABLE_FLAGS_NO_HEADER|#MYTABLE_TABLE_FLAGS_MULTISELECT)
MyTableRegister(mainWindow,canvasBild,hscrollBild,vscrollBild,#MYTABLE_TABLE_FLAGS_LAST_STRETCH|#MYTABLE_TABLE_FLAGS_NO_HEADER|#MYTABLE_TABLE_FLAGS_GRID)

MyTableAddColumn(canvasTree,"Kategorien",0)
MyTableAddColumn(canvasTree2,"Orte",0)
MyTableSetTableRowHeight(canvasTree2,30)

MyTableAddColumn(canvasTable,"ID",50,#MYTABLE_COLUMN_FLAGS_RIGHT|#MYTABLE_COLUMN_FLAGS_INTEGER)
MyTableAddColumn(canvasTable,"Vorname",200,#MYTABLE_COLUMN_FLAGS_EDITABLE)
MyTableAddColumn(canvasTable,"Nachname",200,#MYTABLE_COLUMN_FLAGS_EDITABLE)
MyTableAddColumn(canvasTable,"Geburtsdatum",150,#MYTABLE_COLUMN_FLAGS_CENTER|#MYTABLE_COLUMN_FLAGS_DATE|#MYTABLE_COLUMN_FLAGS_EDITABLE)
MyTableAddColumn(canvasTable,"Uhrzeit",150,#MYTABLE_COLUMN_FLAGS_CENTER|#MYTABLE_COLUMN_FLAGS_TIME_LONG|#MYTABLE_COLUMN_FLAGS_EDITABLE)


MyTableAddColumn(canvasTable2,"ID",50,#MYTABLE_COLUMN_FLAGS_RIGHT|#MYTABLE_COLUMN_FLAGS_INTEGER|#MYTABLE_COLUMN_FLAGS_MIDDLE)
MyTableAddColumn(canvasTable2,"Firma",200,#MYTABLE_COLUMN_FLAGS_EDITABLE|#MYTABLE_COLUMN_FLAGS_BOTTOM)
MyTableAddColumn(canvasTable2,"Privat",50,#MYTABLE_COLUMN_FLAGS_BOOLEAN|#MYTABLE_COLUMN_FLAGS_CENTER|#MYTABLE_COLUMN_FLAGS_EDITABLE|#MYTABLE_COLUMN_FLAGS_MIDDLE)
MyTableAddColumn(canvasTable2,"Info",150,#MYTABLE_COLUMN_FLAGS_EDITABLE)
MyTableSetTableRowHeight(canvasTable2,40)

MyTableAddColumn(canvasBild,"",150,#MYTABLE_COLUMN_FLAGS_CENTER|#MYTABLE_COLUMN_FLAGS_IMAGE|#MYTABLE_COLUMN_FLAGS_MIDDLE)
MyTableSetTableRowHeight(canvasBild,128)


MyTableSetBackground(canvasTree2,RGBA(10,10,10,255))
MyTableSetForecolor(canvasTree2,RGBA(210,210,210,255))
MyTableSetSelectedforecolor(canvasTree2,RGBA(10,10,10,255))

MyTableSetBackground(canvasBild,RGBA(10,10,10,255))


Define i,g,h
i=0
MyTableRedraw(canvasBild,#False)
If ExamineDirectory(0,"C:\Users\silko\OneDrive\Dokumente\Icons\hardware\png-hot\48x48","*.png")
	While NextDirectoryEntry(0)
		MyTableAddRow(canvasBild,"")
		MyTableSetCellImage(canvasBild,i,0,LoadImage(#PB_Any,"C:\Users\silko\OneDrive\Dokumente\Icons\hardware\png-hot\48x48\"+DirectoryEntryName(0)))
		i+1
		If i=10
			Break
		EndIf
	Wend
	FinishDirectory(0)
EndIf
MyTableRedraw(canvasBild,#True)




MyTableRedraw(canvasTree,#False)
For i=1 To 10
	Define id=MyTableAddRow(canvasTree,"Kategorie "+Str(i),"",#PB_Ignore,rowImage,0,Random(1,0),Random(1,0))	
	For g=1 To Random(5,0)
		Define sub= MyTableAddRow(canvasTree,"SubKategorie "+Str(g),"",#PB_Ignore,rowImageSub,0,Random(1,0),Random(1,0),id)
		For h=1 To Random(3,0)
			MyTableAddRow(canvasTree,"SubKategorie "+Str(g)+" "+Str(h),"",#PB_Ignore,rowImageSub2,0,Random(1,0),Random(1,0),sub)
		Next
	Next
Next
MyTableRedraw(canvasTree,#True)

MyTableRedraw(canvasTable,#False)
For i=1 To 100
	MyTableAddRow(canvasTable,Str(i)+"|Vorname "+Str(i)+"|Nachname "+Str(i)+"|"+FormatDate("%dd.%mm.%yyyy",AddDate(Date(),#PB_Date_Day,i))+"|"+FormatDate("%hh:%ii:%ss",AddDate(Date(),#PB_Date_Second,i)),"|",#PB_Ignore,rowImageSub2)
Next
MyTableRedraw(canvasTable,#True)

MyTableRedraw(canvasTree2,#False)
For i=1 To 100
	MyTableAddRow(canvasTree2,"Ort "+Str(i))
Next
MyTableRedraw(canvasTree2,#True)

MyTableRedraw(canvasTable2,#False)
For i=1 To 10000
	MyTableAddRow(canvasTable2,Str(i)+"|firma "+Str(i)+"|"+Str(Random(1,0))+"|Info "+Str(i))
Next
MyTableRedraw(canvasTable2,#True)


MyTableAutosizeColumn(canvasTable,#PB_Ignore)
MyTableAutosizeColumn(canvasTable2,#PB_Ignore)

PostEvent(#PB_Event_SizeWindow,mainWindow,0)

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

MyTableUnRegister(canvasTable)
MyTableUnRegister(canvasTable2)
MyTableUnRegister(canvasBild)
MyTableUnRegister(canvasTree)
MyTableUnRegister(canvasTree2)
Last edited by Cyllceaux on Wed May 26, 2021 9:15 am, edited 1 time in total.
Cyllceaux
Enthusiast
Enthusiast
Posts: 353
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable

Post by Cyllceaux »

Code: Select all

Global MyTableW2=DesktopScaledX(2)
Global MyTableW4=DesktopScaledX(4)
Global MyTableW7=DesktopScaledX(7)
Global MyTableW8=DesktopScaledX(8)
Global MyTableW10=DesktopScaledX(10)
Global MyTableW12=DesktopScaledX(12)
Global MyTableW14=DesktopScaledX(14)
Global MyTableW16=DesktopScaledX(16)
Global MyTableW20=DesktopScaledX(20)
Global MyTableH2=DesktopScaledY(2)
Global MyTableH4=DesktopScaledY(4)
Global MyTableH6=DesktopScaledY(6)
Global MyTableH7=DesktopScaledY(7)
Global MyTableH8=DesktopScaledY(8)
Global MyTableH10=DesktopScaledY(10)
Global MyTableH12=DesktopScaledY(12)
Global MyTableH14=DesktopScaledY(14)
Global MyTableH16=DesktopScaledY(16)

Global MyTableSortImageAsc=CreateImage(#PB_Any,MyTableW16,MyTableH16,32,#PB_Image_Transparent)
Global MyTableSortImageDesc=CreateImage(#PB_Any,MyTableW16,MyTableH16,32,#PB_Image_Transparent)
Global MyTableImagePlus=CreateImage(#PB_Any,MyTableW16,MyTableH16,32,#PB_Image_Transparent)
Global MyTableImageMinus=CreateImage(#PB_Any,MyTableW16,MyTableH16,32,#PB_Image_Transparent)
Global MyTableImageCheckBox=CreateImage(#PB_Any,MyTableW16,MyTableH16,32,#PB_Image_Transparent)
Global MyTableImageCheckBoxChecked=CreateImage(#PB_Any,MyTableW16,MyTableH16,32,#PB_Image_Transparent)
Global MyTableImagePlusArrow=CreateImage(#PB_Any,MyTableW16,MyTableH16,32,#PB_Image_Transparent)
Global MyTableImageMinusArrow=CreateImage(#PB_Any,MyTableW16,MyTableH16,32,#PB_Image_Transparent)


StartDrawing(ImageOutput(MyTableSortImageAsc))
DrawingMode(#PB_2DDrawing_AlphaBlend)
LineXY(MyTableW2,MyTableH8,MyTableW8,MyTableH2,RGBA(0,0,0,255))
LineXY(MyTableW8,MyTableH2,MyTableW14,MyTableH8,RGBA(0,0,0,255))
LineXY(MyTableW2,MyTableH8,MyTableW14,MyTableH8,RGBA(0,0,0,255))
StopDrawing()

StartDrawing(ImageOutput(MyTableSortImageDesc))
DrawingMode(#PB_2DDrawing_AlphaBlend)
LineXY(MyTableW2,MyTableH8,MyTableW8,MyTableH14,RGBA(0,0,0,255))
LineXY(MyTableW8,MyTableH14,MyTableW14,MyTableH8,RGBA(0,0,0,255))
LineXY(MyTableW2,MyTableH8,MyTableW14,MyTableH8,RGBA(0,0,0,255))
StopDrawing()

StartDrawing(ImageOutput(MyTableImagePlus))
DrawingMode(#PB_2DDrawing_Outlined|#PB_2DDrawing_AlphaBlend)
Box(MyTableW2,MyTableH2,MyTableW12,MyTableH12,RGBA(0,0,0,255))
LineXY(MyTableW4,MyTableH7,MyTableW10,MyTableH7,RGBA(0,0,0,255))
LineXY(MyTableW7,MyTableH4,MyTableW7,MyTableH10,RGBA(0,0,0,255))
StopDrawing()

StartDrawing(ImageOutput(MyTableImageMinus))
DrawingMode(#PB_2DDrawing_Outlined|#PB_2DDrawing_AlphaBlend)
Box(MyTableW2,MyTableH2,MyTableW12,MyTableH12,RGBA(0,0,0,255))
LineXY(MyTableW4,MyTableH7,MyTableW10,MyTableH7,RGBA(0,0,0,255))
StopDrawing()

StartDrawing(ImageOutput(MyTableImageCheckBox))
DrawingMode(#PB_2DDrawing_Outlined|#PB_2DDrawing_AlphaBlend)
Box(MyTableW2,MyTableH2,MyTableW12,MyTableH12,RGBA(0,0,0,255))
StopDrawing()

StartDrawing(ImageOutput(MyTableImageCheckBoxChecked))
DrawingMode(#PB_2DDrawing_Outlined|#PB_2DDrawing_AlphaBlend)
Box(MyTableW2,MyTableH2,MyTableW12,MyTableH12,RGBA(0,0,0,255))
LineXY(MyTableW4,MyTableH4,MyTableW12,MyTableH12,RGBA(0,0,0,255))
LineXY(MyTableW4,MyTableH12,MyTableW12,MyTableH4,RGBA(0,0,0,255))
StopDrawing()

StartDrawing(ImageOutput(MyTableImagePlusArrow))
DrawingMode(#PB_2DDrawing_AlphaBlend)
LineXY(MyTableW8,MyTableH4,MyTableW12,MyTableH8,RGBA(0,0,0,255))
LineXY(MyTableW8,MyTableH12,MyTableW12,MyTableH8,RGBA(0,0,0,255))
StopDrawing()

StartDrawing(ImageOutput(MyTableImageMinusArrow))
DrawingMode(#PB_2DDrawing_AlphaBlend)
LineXY(MyTableW4,MyTableH6,MyTableW8,MyTableH10,RGBA(0,0,0,255))
LineXY(MyTableW8,MyTableH10,MyTableW12,MyTableH6,RGBA(0,0,0,255))
StopDrawing()

Enumeration _mytable_type
	#MYTABLE_TYPE_NONE
	#MYTABLE_TYPE_TABLE
	#MYTABLE_TYPE_ROW
	#MYTABLE_TYPE_COL
	#MYTABLE_TYPE_CELL
EndEnumeration

Structure _strMyTableAObject
	type.i
EndStructure

Structure strMyTableAObject Extends _strMyTableAObject
	brow.b
	*data
	image.i
	sclaedimage.i
	calcwidth.i
	calcheight.i
	dirty.b
	textwidth.i
	textheight.i
	*table.strMyTableTable
EndStructure

Structure strMyTableCell Extends strMyTableAObject
	text.s
	value.d
	checked.b
	*row.strMyTableRow
	*col.strMyTableCol	
	startx.i
	starty.i
	formula.s
EndStructure

Structure strMyTableRow Extends strMyTableAObject
	List cells.strMyTableCell()
	List rows.strMyTableRow()
	id.q	
	checked.b
	expanded.b
	sort.s	
	dsort.d
	level.i
EndStructure

Enumeration _menu_evt
	#MYTABLE_NONE
	#MYTABLE_RETURN
	#MYTABLE_ESC
EndEnumeration

EnumerationBinary _MyTableColumnFlags
	#MYTABLE_COLUMN_FLAGS_LEFT
	#MYTABLE_COLUMN_FLAGS_RIGHT
	#MYTABLE_COLUMN_FLAGS_CENTER
	#MYTABLE_COLUMN_FLAGS_TEXT
	#MYTABLE_COLUMN_FLAGS_INTEGER
	#MYTABLE_COLUMN_FLAGS_DATE
	#MYTABLE_COLUMN_FLAGS_DATE_TIME
	#MYTABLE_COLUMN_FLAGS_TIME
	#MYTABLE_COLUMN_FLAGS_TIME_LONG
	#MYTABLE_COLUMN_FLAGS_DOUBLE
	#MYTABLE_COLUMN_FLAGS_BOOLEAN
	#MYTABLE_COLUMN_FLAGS_EDITABLE
	#MYTABLE_COLUMN_FLAGS_IMAGE
	#MYTABLE_COLUMN_FLAGS_TOP
	#MYTABLE_COLUMN_FLAGS_MIDDLE
	#MYTABLE_COLUMN_FLAGS_BOTTOM
	#MYTABLE_COLUMN_FLAGS_RESIZEABLE
EndEnumeration

#MYTABLE_COLUMN_FLAGS_DEFAULT = #MYTABLE_COLUMN_FLAGS_LEFT|#MYTABLE_COLUMN_FLAGS_TEXT
#MYTABLE_COLUMN_FLAGS_DEFAULT_DATE = #MYTABLE_COLUMN_FLAGS_DATE|#MYTABLE_COLUMN_FLAGS_DATE_TIME
#MYTABLE_COLUMN_FLAGS_DEFAULT_TIME = #MYTABLE_COLUMN_FLAGS_TIME|#MYTABLE_COLUMN_FLAGS_TIME_LONG
#MYTABLE_COLUMN_FLAGS_DEFAULT_DATE_TIME = #MYTABLE_COLUMN_FLAGS_DEFAULT_DATE|#MYTABLE_COLUMN_FLAGS_DEFAULT_TIME

Structure strMyTableCol Extends strMyTableAObject
	id.q
	text.s	
	width.i
	sort.i	
	flags.i
	format.s
EndStructure

EnumerationBinary _MyTableTableFlags
	#MYTABLE_TABLE_FLAGS_GRID
	#MYTABLE_TABLE_FLAGS_HIERARCHICAL
	#MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW
	#MYTABLE_TABLE_FLAGS_LAST_STRETCH
	#MYTABLE_TABLE_FLAGS_NO_HEADER
	#MYTABLE_TABLE_FLAGS_FULL_ROW_SELECT	
	#MYTABLE_TABLE_FLAGS_CHECKBOX
	#MYTABLE_TABLE_FLAGS_STOP_DRAWING
	#MYTABLE_TABLE_FLAGS_MULTISELECT
	#MYTABLE_TABLE_FLAGS_CALLBACK
	#MYTABLE_TABLE_FLAGS_ROW_RESIZEABLE	
EndEnumeration

#MYTABLE_TABLE_FLAGS_DEFAULT=#MYTABLE_TABLE_FLAGS_GRID

Prototype MyTableProtoEventRowSelected(canvas,*row.strMyTableRow)
Prototype MyTableProtoEventCellSelected(canvas,*cell.strMyTableCell)
Prototype MyTableProtoEventRowChecked(canvas,*row.strMyTableRow)
Prototype MyTableProtoEventCellChecked(canvas,*cell.strMyTableCell)
Prototype MyTableProtoEventCellChangedText(canvas,*cell.strMyTableCell,old.s)
Prototype MyTableProtoEventCellChangedValue(canvas,*cell.strMyTableCell,old.d)
Prototype MyTableProtoEventCallback(canvas,*row.strMyTableRow)

Structure strMyTableTable Extends _strMyTableAObject
	window.i
	canvas.i
	vscroll.i
	hscroll.i
	List rows.strMyTableRow()
	Map rowsById.i()
	List cols.strMyTableCol()	
	Map colsById.i()
	flags.i
	redraw.b
	dirty.b
	lastw.i
	lasth.i
	lastRowid.q
	lastColid.q
	rowheight.i
	headerheight.i
	bvs.b
	bhs.b
	Map selected.b()
	List expRows.i()
	
	editorgadget.i
	editorwindow.i
	menu.i
	
	evtRowSelect.MyTableProtoEventRowSelected
	evtCellSelect.MyTableProtoEventCellSelected
	evtRowChecked.MyTableProtoEventRowChecked
	evtCellChecked.MyTableProtoEventCellChecked
	evtCellChangedText.MyTableProtoEventCellChangedText
	evtCellChangedValue.MyTableProtoEventCellChangedValue
	evtCallback.MyTableProtoEventCallback
	
	selectedbackground.q
	background.q
	backgroundfixed.q
	headerbackground1.q
	headerbackground2.q
	headerbackgroundfixed.q
	forecolor.q
	headerforecolor.q
	selectedforecolor.q
	font.i
	
	fixedcolumns.i
	resizecol.b
	oldx.i
	*colResize.strMyTableCol
	
	*data
EndStructure



Declare MyTableRegisterEvents(canvas,
                              evtRowSelect.MyTableProtoEventRowSelected,
                              evtCellSelect.MyTableProtoEventCellSelected,
                              evtRowChecked.MyTableProtoEventRowChecked,
                              evtCellChecked.MyTableProtoEventCellChecked,
                              evtCellChangedText.MyTableProtoEventCellChangedText,
                              evtCellChangedValue.MyTableProtoEventCellChangedValue,
                              evtCallback.MyTableProtoEventCallback)

Declare _MyTableRedraw(*this.strMyTableTable)
Declare _MyTableRecalc(*this.strMyTableTable)
Declare _MyTableClearMaps(*this.strMyTableTable)
Declare _MyTableSort(*this.strMyTableTable,col.i)
Declare _MyTableResize(*this.strMyTableTable)
Declare _MyTableRecalcExp(*this.strMyTableTable,*row.strMyTableRow,w)
Declare _MyTableRegister(window,canvas,hscroll,vscroll,flags.i=#MYTABLE_TABLE_FLAGS_DEFAULT,callback.MyTableProtoEventCallback=0)
Declare _MyTableRowExpand(*row.strMyTableRow,expanded.b)	
Declare _MyTableDrawText(x,y,text.s,color.q)
Declare _MyTableDrawHeader(*this.strMyTableTable,*col.strMyTableCol,bx.i,fixed.b)
Declare _MyTableDrawRow(*this.strMyTableTable,*row.strMyTableRow,w.i,bx.i,by.i,fixed.b,fullrowselect.b,grid.b,hierarchical.b,checkboxes.b)
Declare _MyTableEditCell(*cell.strMyTableCell)
Declare _MyTableStopEditCell(*this.strMyTableTable)
Declare _MyTableTextHeight(text.s)
Declare _MyTableTextWidth(text.s)

Declare MyTableEvtResize()
Declare MyTableEvtDialogResize()
Declare MyTableEvtScroll()
Declare MyTableEvtMouseDown()
Declare MyTableEvtMouseUp()
Declare MyTableEvtMouseMove()
Declare MyTableEvtDouble()
Declare MyTableEvtKeyDown()
Declare MyTableEvtReturn()
Declare MyTableEvtEsc()
Declare MyTableEvtLostFocus()

Declare MyTableRegister(window,canvas,hscroll,vscroll,flags.i=#MYTABLE_TABLE_FLAGS_DEFAULT,callback.MyTableProtoEventCallback=0)
Declare MyTableRegisterDialog(window,canvas,hscroll,vscroll,flags.i=#MYTABLE_TABLE_FLAGS_DEFAULT,callback.MyTableProtoEventCallback=0)
Declare MyTableUnRegister(canvas)
Declare MyTableSetTableFlags(canvas,flags.i)
Declare MyTableSetTableRowHeight(canvas,flags.i)
Declare MyTableSetTableSelectedRow(canvas,row.i)
Declare MyTableSetTableSelectedRowById(canvas,rowid.i)
Declare MyTableSetTableSelectedCell(canvas,row.i,col.i)
Declare MyTableSetTableData(canvas,*data)
Declare MyTableSetTableFixedColumns(canvas,columns.i)
Declare MyTableGetTableFlags(canvas)
Declare MyTableGetTableRowHeight(canvas)
Declare MyTableGetTableSelectedRow(canvas)
Declare MyTableGetTableSelectedCell(canvas)
Declare MyTableRedraw(canvas,redraw.b)
Declare MyTableGetTableData(canvas)
Declare MyTableGetTableFixedColumns(canvas)

Declare.q MyTableAddColumn(canvas,text.s,width.i,flags.i=#MYTABLE_COLUMN_FLAGS_DEFAULT,image.i=0,*data=0,sort.i=0)
Declare MyTableRemoveColumn(canvas,column.i)
Declare MyTableSetColumnText(canvas,column.i,text.s)
Declare MyTableSetColumnWidth(canvas,column.i,width.i)
Declare MyTableSetColumnFlags(canvas,column.i,flags.i)
Declare MyTableSetColumnImage(canvas,column.i,image.i)
Declare MyTableSetColumnData(canvas,column.i,*data)
Declare MyTableSetColumnSort(canvas,column.i,sort.i)
Declare.s MyTableGetColumnText(canvas,column.i)
Declare MyTableGetColumnWidth(canvas,column.i)
Declare MyTableGetColumnFlags(canvas,column.i)
Declare MyTableGetColumnImage(canvas,column.i)
Declare MyTableGetColumnData(canvas,column.i)
Declare MyTableGetColumnSort(canvas,column.i)
Declare MyTableAutosizeColumn(canvas,col.i)

Declare.q MyTableAddRow(canvas,text.s,sep.s="|",id.q=#PB_Ignore,image.i=0,*data=0,checked.b=#False,expanded.b=#False,parentid.q=0)
Declare MyTableRemoveRow(canvas,row.i)
Declare MyTableAddDirtyRow(canvas,rows.i,parentid.q=0)
Declare MyTableClearRows(canvas)
Declare MyTableSetRowImage(canvas,row.i,image.i)
Declare MyTableSetRowData(canvas,row.i,*data)
Declare MyTableSetRowChecked(canvas,row.i,checked.b)
Declare MyTableSetRowExpanded(canvas,row.i,expanded.b)
Declare MyTableGetRowImage(canvas,row.i)
Declare MyTableGetRowDirty(canvas,row.i)
Declare MyTableGetRowData(canvas,row.i)
Declare.b MyTableGetRowChecked(canvas,row.i)
Declare.b MyTableGetRowExpanded(canvas,row.i)
Declare MyTableGetRowCount(canvas)

Declare MyTableSetCellText(canvas,row.i,col.i,text.s)
Declare MyTableSetCellValue(canvas,row.i,col.i,value.d)
Declare MyTableSetCellChecked(canvas,row.i,col.i,checked.b)
Declare MyTableSetCellData(canvas,row.i,col.i,*data)
Declare MyTableSetCellImage(canvas,row.i,col.i,image.i)
Declare.s MyTableGetCellText(canvas,row.i,col.i)
Declare.d MyTableGetCellValue(canvas,row.i,col.i)
Declare MyTableGetCellChecked(canvas,row.i,col.i)
Declare MyTableGetCellData(canvas,row.i,col.i)
Declare MyTableGetCellImage(canvas,row.i,col.i)

Declare MyTableSetSelectedbackground(canvas,color.q)
Declare MyTableSetBackground(canvas,color.q)
Declare MyTableSetBackgroundFixedColumns(canvas,color.q)
Declare MyTableSetHeaderbackground1(canvas,color.q)
Declare MyTableSetHeaderbackground2(canvas,color.q)
Declare MyTableSetHeaderbackgroundFixedColumns(canvas,color.q)
Declare MyTableSetForecolor(canvas,color.q)
Declare MyTableSetHeaderforecolor(canvas,color.q)
Declare MyTableSetSelectedforecolor(canvas,color.q)
Declare.q MyTableGetSelectedbackground(canvas)
Declare.q MyTableGetBackground(canvas)
Declare.q MyTableGetBackgroundFixedColumns(canvas)
Declare.q MyTableGetHeaderbackground1(canvas)
Declare.q MyTableGetHeaderbackground2(canvas)
Declare.q MyTableGetHeaderbackgroundFixedColumns(canvas)
Declare.q MyTableGetForecolor(canvas)
Declare.q MyTableGetHeaderforecolor(canvas)
Declare.q MyTableGetSelectedforecolor(canvas)

Procedure _MyTableStopEditCell(*this.strMyTableTable)
	If *this
		If IsWindow(*this\editorwindow)
			Protected *cell.strMyTableCell=GetGadgetData(*this\editorgadget)
			If *cell
				Protected *col.strMyTableCol=0
				Protected *row.strMyTableRow=0
				If *cell
					*col=*cell\col
					*row=*cell\row
					
					Protected s.s=GetGadgetText(*this\editorgadget)
					Protected sold.s=*cell\text
					If s<>*cell\text				
						*cell\dirty=#True
						*cell\textwidth=0					
						*cell\textheight=0					
						*cell\text=s
						If *this\evtCellChangedText
							*this\evtCellChangedText(*this\canvas,*cell,sold)
						EndIf
						If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_DOUBLE)
							*cell\value=ValD(s)
						EndIf
						If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_INTEGER)
							*cell\value=ValD(s)
						EndIf
						If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_DEFAULT_DATE_TIME)
							*cell\value=ParseDate(*col\format,s)
						EndIf
						*this\dirty=#True
						_MyTableRedraw(*this)
					EndIf
					
					RemoveKeyboardShortcut(*this\editorwindow,#PB_Shortcut_Return)
					RemoveKeyboardShortcut(*this\editorwindow,#PB_Shortcut_Escape)
					CloseWindow(*this\editorwindow)
					*this\editorwindow=0
				EndIf
			EndIf
		EndIf
	EndIf
EndProcedure

Procedure _MyTableEditCell(*cell.strMyTableCell)
	If *cell
		Protected *col.strMyTableCol=*cell\col
		Protected *row.strMyTableRow=*cell\row
		Protected *this.strMyTableTable=*cell\table
		
		If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_EDITABLE)
			If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_BOOLEAN)
				*cell\checked=Bool(*cell\checked=#False)
				*cell\value=*cell\checked
				*cell\text=Str(*cell\checked)
				*cell\textwidth=0
				*cell\textheight=0
				*cell\dirty=#True
				*this\dirty=#True
				If *this\evtCellChecked
					*this\evtCellChecked(*this\canvas,*cell)
				EndIf
				_MyTableRedraw(*this)
			Else
				If IsWindow(*this\editorwindow)
					CloseWindow(*this\editorwindow)					
				EndIf
				*this\editorwindow=OpenWindow(#PB_Any,
				                              DesktopUnscaledX(*cell\startx+2)+WindowX(*this\window,#PB_Window_InnerCoordinate)+GadgetX(*this\canvas,#PB_Gadget_WindowCoordinate),
				                              DesktopUnscaledY(*cell\starty+2)+WindowY(*this\window,#PB_Window_InnerCoordinate)+GadgetY(*this\canvas,#PB_Gadget_WindowCoordinate),
				                              DesktopUnscaledX(*col\calcwidth),
				                              DesktopUnscaledY(*row\calcheight),
				                              "",
				                              #PB_Window_BorderLess,
				                              GadgetID(*this\canvas))
				*this\editorgadget=EditorGadget(#PB_Any,
				                                0,
				                                0,
				                                WindowWidth(*this\editorwindow),
				                                WindowHeight(*this\editorwindow),
				                                #PB_Editor_WordWrap)		
				
				SetGadgetText(*this\editorgadget,*cell\text)
				HideGadget(*this\editorgadget,#False)
				SetActiveGadget(*this\editorgadget)
				SetGadgetData(*this\editorgadget,*cell)
				SetWindowData(*this\editorwindow,*cell)
				
				AddKeyboardShortcut(*this\editorwindow,#PB_Shortcut_Return,#MYTABLE_RETURN)
				AddKeyboardShortcut(*this\editorwindow,#PB_Shortcut_Escape,#MYTABLE_ESC)
				
				BindMenuEvent(*this\menu,#MYTABLE_RETURN,@MyTableEvtReturn())
				BindMenuEvent(*this\menu,#MYTABLE_ESC,@MyTableEvtEsc())		
				
				BindGadgetEvent(*this\editorgadget,@MyTableEvtLostFocus(),#PB_EventType_LostFocus)
			EndIf
		EndIf
	EndIf
EndProcedure

Procedure _MyTableTextHeight(text.s)
	ProcedureReturn TextHeight(text) * (CountString(text,#CRLF$)+1)
EndProcedure

Procedure _MyTableTextWidth(text.s)
	Protected result.i=0
	If FindString(text,#CRLF$)
		Protected c=CountString(text,#CRLF$)+1		
		Protected idx=0
		For idx=1 To c
			Protected v=TextWidth(StringField(text,idx,#CRLF$))
			If v>result
				result=v
			EndIf
		Next
	Else
		result=TextWidth(text)
	EndIf
	ProcedureReturn result
EndProcedure

Procedure _MyTableDrawText(x,y,text.s,color.q)
	If FindString(text,#CRLF$)
		Protected c=CountString(text,#CRLF$)+1
		Protected i=0
		Protected yc=0
		For i=1 To c
			Protected line.s=StringField(text,i,#CRLF$)
			DrawText(x,y+yc,line,color)
			If line=""
				yc+_MyTableTextHeight("Q")
			Else
				yc+_MyTableTextHeight(line)
			EndIf
		Next
	Else
		DrawText(x,y,text,color)
	EndIf
EndProcedure

Procedure _MyTableRowExpand(*row.strMyTableRow,expanded.b)	
	*row\expanded=expanded
	ForEach *row\rows()
		_MyTableRowExpand(*row\rows(),expanded)
	Next
EndProcedure

Procedure _MyTableDrawRow(*this.strMyTableTable,*row.strMyTableRow,w,bx.i,by.i,fixed.b,fullrowselect.b,grid.b,hierarchical.b,checkboxes.b)
	
	If Bool(*this\flags & #MYTABLE_TABLE_FLAGS_CALLBACK) And *row\dirty And *this\evtCallback
		*this\evtCallback(*this\canvas,*row)
		*row\dirty=#False
	EndIf
	Protected idx=0
	Protected firstcol.b=#True
	ForEach *row\cells()
		Protected *cell.strMyTableCell=*row\cells()
		Protected *col.strMyTableCol=SelectElement(*this\cols(),idx):idx+1
		If idx>*this\fixedcolumns And fixed
			Break
		EndIf
		If *cell\textheight=0
			If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_BOOLEAN)
				*cell\textheight=MyTableW20
			Else
				*cell\textheight=_MyTableTextHeight(*cell\text)
			EndIf
		EndIf
		If *cell\textwidth=0
			If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_BOOLEAN)
				*cell\textwidth=MyTableW20
			Else
				*cell\textwidth=_MyTableTextWidth(*cell\text)
			EndIf
		EndIf
		
		Protected selected.b=#False
		If fixed
			Box(bx,by,*col\calcwidth,*row\calcheight,*this\backgroundfixed)	
		EndIf
		If (fullrowselect And *this\selected(Str(*row))=#True) Or *this\selected(Str(*cell))=#True
			Box(bx,by,*col\calcwidth,*row\calcheight,*this\selectedbackground)	
			selected=#True
		EndIf
		*cell\startx=bx
		*cell\starty=by
		
		DrawingMode(#PB_2DDrawing_Outlined)	
		If grid
			Box(bx,by,*col\calcwidth,*row\calcheight,*this\headerbackground2)
		EndIf
		
		Protected foi.i=0
		Protected coi.i=0
		Protected cob.i=0
		
		Protected valw=0
		If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_MIDDLE)
			valw=*row\calcheight/2-*cell\textheight/2
		ElseIf Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_BOTTOM)
			valw=*row\calcheight-*cell\textheight
		Else
			valw=MyTableH2
		EndIf
		
		If firstcol And hierarchical
			foi=MyTableW20 * (*row\level+1)
			If ListSize(*row\rows())>0
				If *row\expanded
					If Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW)
						DrawAlphaImage(ImageID(MyTableImageMinusArrow),bx+foi-MyTableW20,by+valw)
					Else
						DrawAlphaImage(ImageID(MyTableImageMinus),bx+foi-MyTableW20,by+valw)
					EndIf
				Else
					If Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW)
						DrawAlphaImage(ImageID(MyTableImagePlusArrow),bx+foi-MyTableW20,by+valw)
					Else
						DrawAlphaImage(ImageID(MyTableImagePlus),bx+foi-MyTableW20,by+valw)
					EndIf
				EndIf
			EndIf
		EndIf
		
		If firstcol And checkboxes
			coi=MyTableW20
			If *row\checked
				DrawAlphaImage(ImageID(MyTableImageCheckBoxChecked),bx+foi,by+valw)
			Else
				DrawAlphaImage(ImageID(MyTableImageCheckBox),bx+foi,by+valw)
			EndIf
		EndIf
		
		
		If firstcol And IsImage(*row\sclaedimage)
			cob+MyTableW20
			
			DrawAlphaImage(ImageID(*row\sclaedimage),bx+foi+coi,by+valw)
		EndIf
		
		
		ClipOutput(bx,by,*col\calcwidth,*row\calcheight)
		DrawingMode(#PB_2DDrawing_Transparent)			
		
		
		If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_IMAGE)
			If IsImage(*cell\image)
				If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_CENTER)
					DrawAlphaImage(ImageID(*cell\image),bx+MyTableW2+*col\calcwidth/2-*cell\textwidth/2,by+valw)
				ElseIf Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_RIGHT)
					DrawAlphaImage(ImageID(*cell\image),bx+*col\calcwidth-*cell\textwidth-MyTableW4,by+valw)
				Else
					DrawAlphaImage(ImageID(*cell\image),bx+MyTableW2+foi,by+valw)
				EndIf	
			EndIf
		ElseIf Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_BOOLEAN)
			Protected img=0
			If *cell\checked
				img=MyTableImageCheckBoxChecked
			Else
				img=MyTableImageCheckBox
			EndIf
			
			If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_CENTER)
				DrawAlphaImage(ImageID(img),bx+MyTableW2+*col\calcwidth/2-*cell\textwidth/2,by+valw)
			ElseIf Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_RIGHT)
				DrawAlphaImage(ImageID(img),bx+*col\calcwidth-*cell\textwidth-MyTableW4,by+valw)
			Else
				DrawAlphaImage(ImageID(img),bx+MyTableW2+foi,by+valw)
			EndIf					
		Else
			Protected color=*this\forecolor
			If selected
				color=*this\selectedforecolor
			EndIf
			If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_CENTER)
				_MyTableDrawText(bx+MyTableW2+*col\calcwidth/2-*cell\textwidth/2,by+valw,*cell\text,color)
			ElseIf Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_RIGHT)
				_MyTableDrawText(bx+*col\calcwidth-*cell\textwidth-MyTableW4,by+valw,*cell\text,color)
			Else
				_MyTableDrawText(bx+MyTableW2+foi+coi+cob,by+valw,*cell\text,color)
			EndIf					
		EndIf
		DrawingMode(#PB_2DDrawing_AlphaClip)
		UnclipOutput()					
		bx+*col\calcwidth
		If bx>=w
			Break
		EndIf
		firstcol=#False
	Next
	ProcedureReturn *row\calcheight
EndProcedure

Procedure _MyTableDrawHeader(*this.strMyTableTable,*col.strMyTableCol,bx.i,fixed.b)
	If *col\textwidth=0
		*col\textwidth=_MyTableTextWidth(*col\text)
	EndIf
	If *col\textheight=0
		*col\textheight=_MyTableTextHeight(*col\text)
	EndIf
	Protected soi.i=0
	
	If *col\sort
		soi=MyTableW20
	EndIf
	
	
	Box(bx,0,*col\calcwidth,*col\calcheight,*this\headerbackground1)
	If fixed
		Box(bx,0,*col\calcwidth-MyTableW2,*col\calcheight-MyTableH2,*this\headerbackgroundfixed)
	Else
		Box(bx,0,*col\calcwidth-MyTableW2,*col\calcheight-MyTableH2,*this\headerbackground2)
	EndIf
	ClipOutput(bx,0,*col\calcwidth,*col\calcheight)
	DrawingMode(#PB_2DDrawing_Transparent)					
	If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_CENTER)
		_MyTableDrawText(bx+MyTableW2+*col\calcwidth/2-*col\textwidth/2-soi,0,*col\text,*this\headerforecolor)
	ElseIf Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_RIGHT)
		_MyTableDrawText(bx+*col\calcwidth-*col\textwidth-MyTableW4-soi,0,*col\text,*this\headerforecolor)
	Else
		_MyTableDrawText(bx+MyTableW2,0,*col\text,*this\headerforecolor)
	EndIf					
	DrawingMode(#PB_2DDrawing_AlphaClip)
	UnclipOutput()		
	Select *col\sort
		Case -1
			DrawAlphaImage(ImageID(MyTableSortImageDesc),bx+*col\calcwidth-soi,0)
		Case 1
			DrawAlphaImage(ImageID(MyTableSortImageAsc),bx+*col\calcwidth-soi,0)
	EndSelect
	ProcedureReturn *col\calcwidth
EndProcedure

Procedure _MyTableRedraw(*this.strMyTableTable)
	If *this
		With *this
			If \redraw And \dirty
				_MyTableClearMaps(*this)
				
				Protected grid.b=Bool(\flags & #MYTABLE_TABLE_FLAGS_GRID)
				Protected hierarchical.b=Bool(Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL) Or Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW))
				Protected laststretch.b=Bool(\flags & #MYTABLE_TABLE_FLAGS_LAST_STRETCH)
				Protected noheader.b=Bool(\flags & #MYTABLE_TABLE_FLAGS_NO_HEADER)
				Protected fullrowselect.b=Bool(\flags & #MYTABLE_TABLE_FLAGS_FULL_ROW_SELECT Or ListSize(*this\cols())=1)
				Protected checkboxes.b=Bool(\flags & #MYTABLE_TABLE_FLAGS_CHECKBOX)
				Protected idx=0
				
				Protected w=GadgetWidth(\canvas)
				Protected h=GadgetHeight(\canvas)
				
				If \bhs
					h-GadgetHeight(\hscroll)
				EndIf
				
				If \bvs
					w-GadgetWidth(\vscroll)
				EndIf
				
				w=DesktopScaledX(w)
				h=DesktopScaledY(h)
				
				
				
				StartDrawing(CanvasOutput(\canvas))
				DrawingMode(#PB_2DDrawing_AlphaClip)
				DrawingFont(\font)
				
				Box(0,0,OutputWidth(),OutputHeight(),\background)
				
				Protected bx=-GetGadgetState(\hscroll)
				Protected by=0
				
				Protected firstcol.b=#True
				
				If Not noheader
					ForEach \cols()
						Protected *col.strMyTableCol=\cols()
						
						bx+_MyTableDrawHeader(*this,*col,bx,#False)
						firstcol=#False
						If bx>=w
							Break
						EndIf
					Next
					
					If *this\fixedcolumns>0
						bx=0
						firstcol=#True
						For idx=1 To *this\fixedcolumns
							*col=SelectElement(\cols(),idx-1)
							bx+_MyTableDrawHeader(*this,*col,bx,#True)
							firstcol=#False
						Next
					EndIf
					
					by=DesktopScaledY(\headerheight)
				EndIf
				
				
				Protected c=ListSize(\expRows())-1
				Protected i=0
				
				For i=GetGadgetState(\vscroll) To c
					SelectElement(\expRows(),i)				
					Protected *row.strMyTableRow=\expRows()
					bx=-GetGadgetState(\hscroll)
					by+_MyTableDrawRow(*this,*row,w,bx,by,#False,fullrowselect,grid,hierarchical,checkboxes)
					If by>=h
						Break
					EndIf
				Next
				If *this\fixedcolumns>0
					by=DesktopScaledY(\headerheight)
					For i=GetGadgetState(\vscroll) To c
						SelectElement(\expRows(),i)				
						*row=\expRows()
						by+_MyTableDrawRow(*this,*row,w,0,by,#True,fullrowselect,grid,hierarchical,checkboxes)
						If by>=h
							Break
						EndIf
					Next
				EndIf
				
				StopDrawing()
				
				
				\dirty=#False
			EndIf			
		EndWith
	EndIf
EndProcedure

Procedure _MyTableRecalcExp(*this.strMyTableTable,*parent.strMyTableRow,w)
	ForEach *parent\rows()
		Protected *row.strMyTableRow=*parent\rows()
		AddElement(*this\expRows()):*this\expRows()=*row
		If *row\dirty
			*row\calcheight=DesktopScaledY(*this\rowheight)
			*row\calcwidth=w
			*row\dirty=#False
		EndIf
		If *row\expanded
			_MyTableRecalcExp(*this,*row,w)
		EndIf
	Next
EndProcedure

Procedure _MyTableClearMaps(*this.strMyTableTable)
	If *this
		ForEach *this\selected()
			If Not *this\selected()
				DeleteMapElement(*this\selected())
			EndIf
		Next
	EndIf	
EndProcedure

Procedure _MyTableRecalc(*this.strMyTableTable)
	If *this
		If *this\dirty And *this\redraw
			_MyTableClearMaps(*this)
			With *this
				Protected laststretch.b=Bool(\flags & #MYTABLE_TABLE_FLAGS_LAST_STRETCH)
				Protected noheader.b=Bool(\flags & #MYTABLE_TABLE_FLAGS_NO_HEADER)
				Protected callback.b=Bool(\flags & #MYTABLE_TABLE_FLAGS_CALLBACK)
				Protected hierarchical.b=Bool(Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL) Or Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW))
				
				Protected *lastCol.strMyTableCol=0
				Protected w=0
				Protected idx=0
				ForEach \cols()
					Protected *col.strMyTableCol=\cols()
					*lastCol=*col
					If *col\dirty
						*col\calcheight=DesktopScaledY(\headerheight)
						*col\calcwidth=DesktopScaledX(*col\width)
						*col\dirty=#False						
					EndIf
					w+*col\calcwidth					
				Next			
				
				ClearList(*this\expRows())
				
				ForEach \rows()
					Protected *row.strMyTableRow=\rows()
					AddElement(*this\expRows()):*this\expRows()=*row		
					If *row\dirty
						*row\calcheight=DesktopScaledY(\rowheight)
						*row\calcwidth=w
						If Not callback
							*row\dirty=#False
						EndIf
					EndIf
					If *row\expanded And hierarchical
						_MyTableRecalcExp(*this,*row,w)
					EndIf
				Next
				
				If w>\lastw
					SetGadgetAttribute(\hscroll,#PB_ScrollBar_Maximum,w-\lastw)				
				EndIf
				\bhs=Bool(w>\lastw)
				HideGadget(\hscroll,Bool(w<=\lastw))	
				If Not \bhs
					SetGadgetState(\hscroll,0)
				EndIf
				
				
				Protected h=ListSize(\expRows())
				If \bhs
					h-(GadgetHeight(\canvas)-GadgetHeight(\hscroll))/\rowheight
				Else
					h-GadgetHeight(\canvas)/\rowheight
				EndIf
				If Not noheader
					h+1
				EndIf
				\bvs=Bool(h>0)
				HideGadget(\vscroll,Bool(h<=0))	
				SetGadgetAttribute(\vscroll,#PB_ScrollBar_Maximum,h)
				
				
				If laststretch And *col 
					*col\calcheight=DesktopScaledY(\headerheight)
					*col\calcwidth=DesktopScaledX(GadgetWidth(\canvas))
					If \bvs
						*col\calcwidth-DesktopScaledX(GadgetWidth(\vscroll))	
					EndIf
					*col\dirty=#True
				EndIf
				
				
			EndWith
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure _MyTableSort(*this.strMyTableTable,col.i)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),col)
		Protected bdsort.b=Bool(Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_BOOLEAN) Or 
		                        Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_DEFAULT_DATE_TIME) Or 
		                        Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_INTEGER) Or 
		                        Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_DOUBLE))
		ForEach *this\rows()
			Protected *row.strMyTableRow=*this\rows()
			SelectElement(*row\cells(),col)
			If bdsort
				*row\dsort=*row\cells()\value
			Else
				*row\sort=*row\cells()\text
			EndIf
		Next
		Select *this\cols()\sort
			Case -1
				*this\cols()\sort=0				
				SortStructuredList(*this\rows(),#PB_Sort_Ascending,OffsetOf(strMyTableRow\id),TypeOf(strMyTableRow\id))				
			Case 0
				*this\cols()\sort=1
				If bdsort
					SortStructuredList(*this\rows(),#PB_Sort_Ascending,OffsetOf(strMyTableRow\dsort),TypeOf(strMyTableRow\dsort))
				Else
					SortStructuredList(*this\rows(),#PB_Sort_Ascending,OffsetOf(strMyTableRow\sort),TypeOf(strMyTableRow\sort))
				EndIf
			Case 1
				*this\cols()\sort=-1
				If bdsort
					SortStructuredList(*this\rows(),#PB_Sort_Descending,OffsetOf(strMyTableRow\dsort),TypeOf(strMyTableRow\dsort))
				Else
					SortStructuredList(*this\rows(),#PB_Sort_Descending,OffsetOf(strMyTableRow\sort),TypeOf(strMyTableRow\sort))
				EndIf
		EndSelect
	EndIf
EndProcedure

Procedure _MyTableResize(*this.strMyTableTable)
	If *this
		With *this
			Protected w=GadgetWidth(\canvas)
			Protected h=GadgetHeight(\canvas)
			If w<>\lastw Or h<>\lasth Or \dirty
				
				\lasth=h
				\lastw=w
				ResizeGadget(\vscroll,
				             \lastw-GadgetWidth(\vscroll),
				             #PB_Ignore,
				             #PB_Ignore,
				             \lasth-GadgetHeight(\hscroll))
				
				ResizeGadget(\hscroll,
				             #PB_Ignore,
				             \lasth-GadgetHeight(\hscroll),
				             \lastw-GadgetWidth(\vscroll),
				             #PB_Ignore)
				\dirty=#True
				_MyTableRecalc(*this)
			EndIf
		EndWith
	EndIf
EndProcedure

Procedure _MyTableAddDirtyRow(*this.strMyTableTable,*row.strMyTableRow)
	*row\dirty=#True
	*row\table=*this
	*this\lastRowid+1
	*row\id=*this\lastRowid	
	*row\type=#MYTABLE_TYPE_ROW
	Protected i
	For i=1 To ListSize(*this\cols())		
		Protected *cell.strMyTableCell=AddElement(*row\cells())
		*cell\row=*row
		*cell\table=*this
		*cell\type=#MYTABLE_TYPE_CELL
		*cell\col=SelectElement(*this\cols(),i-1)
	Next
EndProcedure
Last edited by Cyllceaux on Sun May 02, 2021 10:33 pm, edited 7 times in total.
Cyllceaux
Enthusiast
Enthusiast
Posts: 353
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable

Post by Cyllceaux »

Code: Select all

Procedure MyTableEvtResize()
	Protected *this.strMyTableTable=GetGadgetData(EventGadget())
	If *this
		*this\dirty=#True
		_MyTableResize(*this)
	EndIf
EndProcedure

Procedure MyTableEvtDialogResize()
	Protected *this.strMyTableTable=GetGadgetData(EventGadget())
	If *this
		With *this
			Protected w=GadgetWidth(\canvas)
			Protected h=GadgetHeight(\canvas)
			If w<>\lastw Or h<>\lasth Or \dirty				
				\lasth=h
				\lastw=w
				\dirty=#True
				_MyTableRecalc(*this)
			EndIf
		EndWith
	EndIf
EndProcedure


Procedure MyTableEvtScroll()
	Protected *this.strMyTableTable=GetGadgetData(EventGadget())
	If *this
		*this\dirty=#True
		_MyTableRedraw(*this)
	EndIf
EndProcedure

Procedure MyTableEvtReturn()
	Protected *cell.strMyTableCell=GetGadgetData(GetActiveGadget())
	If *cell And *cell\type=#MYTABLE_TYPE_CELL
		_MyTableStopEditCell(*cell\table)
	EndIf
EndProcedure

Procedure MyTableEvtEsc()
	Protected *cell.strMyTableCell=GetGadgetData(GetActiveGadget())
	If *cell And *cell\type=#MYTABLE_TYPE_CELL
		_MyTableStopEditCell(*cell\table)
	EndIf
EndProcedure

Procedure MyTableEvtMouseUp()
	Protected *this.strMyTableTable=GetGadgetData(EventGadget())
	If *this
		*this\resizecol=#False
		*this\oldx=0
		*this\colResize=0
	EndIf
EndProcedure

Procedure MyTableEvtKeyDown()
	Protected *this.strMyTableTable=GetGadgetData(EventGadget())
	If *this
		Protected fullrowselect.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_FULL_ROW_SELECT Or ListSize(*this\cols())=1)
		Protected multiselect.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_MULTISELECT)
		Protected checkboxes.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_CHECKBOX)
		Protected hierarchical.b=Bool(Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL) Or Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW))		
		Protected control.b=Bool(GetGadgetAttribute(*this\canvas,#PB_Canvas_Modifiers) & #PB_Canvas_Control)
		Protected shift.b=Bool(GetGadgetAttribute(*this\canvas,#PB_Canvas_Modifiers) & #PB_Canvas_Shift)		
		Protected redraw.b=#False
		Protected recalc.b=#False
		Protected *row.strMyTableRow=0
		Protected *cell.strMyTableCell=0
		Protected *col.strMyTableCol=0
		Protected listidx=-1,colidx=-1
		Protected NewList selected.q()
		
		Select GetGadgetAttribute(*this\canvas,#PB_Canvas_Key)
			Case #PB_Shortcut_Return,#PB_Shortcut_F2
				_MyTableClearMaps(*this)
				If Not fullrowselect
					ForEach *this\selected()
						*cell=Val(MapKey(*this\selected()))
						_MyTableEditCell(*cell)
						
						Break
					Next
				EndIf
			Case #PB_Shortcut_Multiply
				If hierarchical And fullrowselect
					_MyTableClearMaps(*this)
					ForEach *this\selected()
						If *this\selected()
							*row=Val(MapKey(*this\selected()))
							_MyTableRowExpand(*row,#True)						
						EndIf
					Next
					recalc=#True
				EndIf
			Case #PB_Shortcut_Divide
				If hierarchical And fullrowselect
					_MyTableClearMaps(*this)
					ForEach *this\selected()
						If *this\selected()
							*row=Val(MapKey(*this\selected()))
							_MyTableRowExpand(*row,#False)						
						EndIf
					Next
					recalc=#True
				EndIf
			Case #PB_Shortcut_Add
				If hierarchical And fullrowselect
					_MyTableClearMaps(*this)
					ForEach *this\selected()
						If *this\selected()
							*row=Val(MapKey(*this\selected()))
							*row\expanded=#True							
						EndIf
					Next
					recalc=#True
				EndIf
			Case #PB_Shortcut_Subtract
				If hierarchical And fullrowselect
					_MyTableClearMaps(*this)
					ForEach *this\selected()
						If *this\selected()
							*row=Val(MapKey(*this\selected()))
							*row\expanded=#False
						EndIf
					Next
					recalc=#True
				EndIf
			Case #PB_Shortcut_Space
				If checkboxes And fullrowselect
					_MyTableClearMaps(*this)
					ForEach *this\selected()
						If *this\selected()
							*row=Val(MapKey(*this\selected()))
							*row\checked=Bool(*row\checked=#False)
						EndIf
					Next
					redraw=#True
				EndIf				
			Case #PB_Shortcut_Left
				_MyTableClearMaps(*this)
				If ListSize(*this\expRows())>0
					If MapSize(*this\selected())>0
						If Not fullrowselect
							ForEach *this\selected()
								listidx=-1
								*cell=Val(MapKey(*this\selected()))
								*row=*cell\row
								ForEach *row\cells()
									If *row\cells()=*cell
										listidx=ListIndex(*row\cells())
										Break
									EndIf
								Next
								listidx-1
								If listidx>-1				
									*cell=SelectElement(*row\cells(),listidx)
								EndIf
								AddElement(selected())
								selected()=*cell									
							Next
							ClearMap(*this\selected())
							ForEach selected()
								*cell=selected()
								*this\selected(Str(*cell))=#True
								If *this\evtCellSelect
									*this\evtCellSelect(*this\canvas,*cell)
								EndIf
							Next
							redraw=#True
						EndIf
					Else
						If Not fullrowselect						
							SelectElement(*this\expRows(),0)
							*row=*this\expRows()
							*cell=SelectElement(*row\cells(),ListSize(*row\cells())-1)
							*this\selected(Str(*cell))=#True
							If *this\evtCellSelect
								*this\evtCellSelect(*this\canvas,*cell)
							EndIf
							redraw=#True
						EndIf
					EndIf					
				EndIf
			Case #PB_Shortcut_Right
				_MyTableClearMaps(*this)
				If ListSize(*this\expRows())>0
					If MapSize(*this\selected())>0
						If Not fullrowselect
							ForEach *this\selected()
								listidx=-1
								*cell=Val(MapKey(*this\selected()))
								*row=*cell\row
								ForEach *row\cells()
									If *row\cells()=*cell
										listidx=ListIndex(*row\cells())
										Break
									EndIf
								Next
								listidx+1
								If listidx<ListSize(*row\cells())									
									*cell=SelectElement(*row\cells(),listidx)
								EndIf
								AddElement(selected())
								selected()=*cell
							Next
							ClearMap(*this\selected())
							ForEach selected()
								*cell=selected()
								*this\selected(Str(*cell))=#True
								If *this\evtCellSelect
									*this\evtCellSelect(*this\canvas,*cell)
								EndIf
							Next
							redraw=#True
						EndIf
					Else
						If Not fullrowselect
							SelectElement(*this\expRows(),0)
							*row=*this\expRows()
							*cell=SelectElement(*row\cells(),0)
							*this\selected(Str(*cell))=#True
							If *this\evtCellSelect
								*this\evtCellSelect(*this\canvas,*cell)
							EndIf
							redraw=#True
						EndIf
					EndIf
					
				EndIf
			Case #PB_Shortcut_Up
				_MyTableClearMaps(*this)
				If ListSize(*this\expRows())>0
					If MapSize(*this\selected())>0
						If fullrowselect
							ForEach *this\selected()
								*row=Val(MapKey(*this\selected()))
								listidx=-1
								ForEach *this\expRows()
									If *this\expRows()=*row
										listidx=ListIndex(*this\expRows())
										Break
									EndIf
								Next
								listidx-1
								If listidx>-1
									SelectElement(*this\expRows(),listidx)									
									*row=*this\expRows()
								EndIf
								AddElement(selected())								
								selected()=*row
							Next
							ClearMap(*this\selected())
							ForEach selected()
								*row=selected()
								*this\selected(Str(*row))=#True
								If *this\evtRowSelect
									*this\evtRowSelect(*this\canvas,*row)
								EndIf
							Next
							redraw=#True
						Else
							ForEach *this\selected()
								*cell=Val(MapKey(*this\selected()))
								*row=*cell\row
								listidx=-1
								colidx=-1
								ForEach *row\cells()
									If *row\cells()=*cell
										colidx=ListIndex(*row\cells())
										Break
									EndIf
								Next
								ForEach *this\expRows()
									If *this\expRows()=*row
										listidx=ListIndex(*this\expRows())
										Break
									EndIf
								Next
								listidx-1
								If listidx>-1
									SelectElement(*this\expRows(),listidx)
									*row=*this\expRows()
									*cell=SelectElement(*row\cells(),colidx)
								EndIf								
								AddElement(selected())
								selected()=*cell
							Next
							ClearMap(*this\selected())
							ForEach selected()
								*cell=selected()
								*this\selected(Str(*cell))=#True
								If *this\evtCellSelect
									*this\evtCellSelect(*this\canvas,*cell)
								EndIf
							Next
							redraw=#True
						EndIf
					Else
						If fullrowselect
							SelectElement(*this\expRows(),ListSize(*this\expRows())-1)
							*row=*this\expRows()
							*this\selected(Str(*row))=#True
							If *this\evtRowSelect
								*this\evtRowSelect(*this\canvas,*row)
							EndIf
							redraw=#True
						Else
							SelectElement(*this\expRows(),ListSize(*this\expRows())-1)
							*row=*this\expRows()
							*cell=SelectElement(*row\cells(),0)
							*this\selected(Str(*cell))=#True
							If *this\evtCellSelect
								*this\evtCellSelect(*this\canvas,*cell)
							EndIf
							redraw=#True
						EndIf
					EndIf
					
				EndIf
			Case #PB_Shortcut_Down
				_MyTableClearMaps(*this)
				If ListSize(*this\expRows())>0
					If MapSize(*this\selected())>0
						If fullrowselect
							ForEach *this\selected()
								*row=Val(MapKey(*this\selected()))
								listidx=-1
								ForEach *this\expRows()
									If *this\expRows()=*row
										listidx=ListIndex(*this\expRows())
										Break
									EndIf
								Next
								listidx+1
								If listidx<ListSize(*this\expRows())
									SelectElement(*this\expRows(),listidx)									
									*row=*this\expRows()
								EndIf
								AddElement(selected())
								selected()=*row
							Next
							ClearMap(*this\selected())
							ForEach selected()
								*row=selected()
								*this\selected(Str(*row))=#True
								If *this\evtRowSelect
									*this\evtRowSelect(*this\canvas,*row)
								EndIf
							Next
							redraw=#True
						Else
							ForEach *this\selected()
								*cell=Val(MapKey(*this\selected()))
								*row=*cell\row
								listidx=-1
								colidx=-1
								ForEach *row\cells()
									If *row\cells()=*cell
										colidx=ListIndex(*row\cells())
										Break
									EndIf
								Next
								ForEach *this\expRows()
									If *this\expRows()=*row
										listidx=ListIndex(*this\expRows())
										Break
									EndIf
								Next
								listidx+1
								If listidx<ListSize(*this\expRows())
									SelectElement(*this\expRows(),listidx)
									*row=*this\expRows()
									*cell=SelectElement(*row\cells(),colidx)
								EndIf								
								AddElement(selected())
								selected()=*cell
							Next
							ClearMap(*this\selected())
							ForEach selected()
								*cell=selected()
								*this\selected(Str(*cell))=#True
								If *this\evtCellSelect
									*this\evtCellSelect(*this\canvas,*cell)
								EndIf
							Next
							redraw=#True
						EndIf
					Else
						If fullrowselect
							SelectElement(*this\expRows(),0)
							*row=*this\expRows()
							*this\selected(Str(*row))=#True
							If *this\evtRowSelect
								*this\evtRowSelect(*this\canvas,*row)
							EndIf
							redraw=#True
						Else
							SelectElement(*this\expRows(),0)
							*row=*this\expRows()
							*cell=SelectElement(*row\cells(),0)
							*this\selected(Str(*cell))=#True
							If *this\evtCellSelect
								*this\evtCellSelect(*this\canvas,*cell)
							EndIf
							redraw=#True
						EndIf
					EndIf					
				EndIf
		EndSelect
		If recalc
			*this\dirty=#True
			_MyTableRecalc(*this)
		ElseIf redraw
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
	FreeList(selected())
EndProcedure

Procedure MyTableEvtMouseMove()
	Protected *this.strMyTableTable=GetGadgetData(EventGadget())
	If *this
		Protected mx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)+GetGadgetState(*this\hscroll)
		Protected my=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseY)
		Protected noheader.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_NO_HEADER)
		Protected resizerow.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_ROW_RESIZEABLE)
		my=DesktopUnscaledY(my)
		
		If *this\resizecol
			Protected newx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)-*this\oldx
			*this\colResize\width+newx
			*this\colResize\dirty=#True
			*this\oldx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)
			*this\dirty=#True
			_MyTableRecalc(*this)
		Else
			
			Protected col=0
			Protected fw.b=#False
			SetGadgetAttribute(*this\canvas,#PB_Canvas_Cursor,#PB_Cursor_Default)
			If *this\fixedcolumns>0
				mx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)
				ForEach *this\cols()
					If ListIndex(*this\cols())<*this\fixedcolumns
						mx-*this\cols()\calcwidth
						If mx>=-MyTableW4 And mx<=MyTableW4
							fw=#True
							If Bool(*this\cols()\flags & #MYTABLE_COLUMN_FLAGS_RESIZEABLE)
								SetGadgetAttribute(*this\canvas,#PB_Canvas_Cursor,#PB_Cursor_LeftRight)
								
							EndIf
							Break
						EndIf
					EndIf
				Next
			EndIf
			
			If Not fw
				mx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)+GetGadgetState(*this\hscroll)
				col=0
				ForEach *this\cols()
					mx-*this\cols()\calcwidth
					If mx>=-MyTableW4 And mx<=MyTableW4
						If Bool(*this\cols()\flags & #MYTABLE_COLUMN_FLAGS_RESIZEABLE)
							SetGadgetAttribute(*this\canvas,#PB_Canvas_Cursor,#PB_Cursor_LeftRight)
							
						EndIf
						Break
						
					EndIf
				Next			
				
			EndIf
		EndIf
		
		
	EndIf
EndProcedure

Procedure MyTableEvtMouseDown()
	Protected *this.strMyTableTable=GetGadgetData(EventGadget())
	If *this
		
		Protected noheader.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_NO_HEADER)
		Protected fullrow.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_FULL_ROW_SELECT Or ListSize(*this\cols())=1)
		Protected checkboxes.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_CHECKBOX)
		Protected hierarchical.b=Bool(Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL) Or Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW))
		Protected multiselect.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_MULTISELECT)
		
		Protected mx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)+GetGadgetState(*this\hscroll)
		Protected my=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseY)
		Protected ms=GetGadgetAttribute(*this\canvas,#PB_Canvas_WheelDelta)
		Protected control.b=Bool(GetGadgetAttribute(*this\canvas,#PB_Canvas_Modifiers) & #PB_Canvas_Control)
		Protected shift.b=Bool(GetGadgetAttribute(*this\canvas,#PB_Canvas_Modifiers) & #PB_Canvas_Shift)
		
		Protected *cell.strMyTableCell=0
		
		Protected recalc.b=#False
		
		my=DesktopUnscaledY(my)
		
		If ms
			SetGadgetState(*this\vscroll,GetGadgetState(*this\vscroll)-ms)
			*this\dirty=#True
		Else
			
			Protected row=0
			If Not noheader
				row=(my-*this\headerheight)/*this\rowheight+GetGadgetState(*this\vscroll)
				
				If my<*this\headerheight
					row-1
				EndIf
			Else
				row=my/*this\rowheight+GetGadgetState(*this\vscroll)
			EndIf
			Protected col=0
			Protected fw.b=#False
			
			If *this\fixedcolumns>0
				mx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)
				ForEach *this\cols()
					If ListIndex(*this\cols())<*this\fixedcolumns
						mx-*this\cols()\calcwidth
						If mx>=-MyTableW4 And mx<=MyTableW4
							fw=#True
							If Bool(*this\cols()\flags & #MYTABLE_COLUMN_FLAGS_RESIZEABLE)
								*this\resizecol=#True
								*this\oldx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)-mx
								*this\colResize=*this\cols()
								ProcedureReturn #False
							EndIf							
						ElseIf mx<=0
							fw=#True
							Break
						Else
							col+1
						EndIf
					EndIf
				Next
				
			EndIf
			
			If Not fw
				mx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)+GetGadgetState(*this\hscroll)
				col=0
				ForEach *this\cols()
					mx-*this\cols()\calcwidth
					If mx>=-MyTableW4 And mx<=MyTableW4
						
						If Bool(*this\cols()\flags & #MYTABLE_COLUMN_FLAGS_RESIZEABLE)
							*this\resizecol=#True
							*this\oldx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)-mx
							*this\colResize=*this\cols()
							ProcedureReturn #False
						EndIf
					ElseIf mx<=0
						
						Break
					Else
						col+1
					EndIf
				Next			
			EndIf
			
			If row<ListSize(*this\expRows()) And col<ListSize(*this\cols())
				If col=0 And (checkboxes Or hierarchical) And row>-1
					mx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)+GetGadgetState(*this\hscroll)
					
					SelectElement(*this\expRows(),row)
					Protected *row.strMyTableRow=*this\expRows()
					Protected lv=MyTablew20 * *row\level
					Select  mx
						Case MyTablew20+lv To (MyTablew20*2)+lv
							If hierarchical And checkboxes
								*row\checked=Bool(*row\checked=#False)
								*this\dirty=#True
								If *this\evtRowChecked
									*this\evtRowChecked(*this\canvas,*row)
								EndIf
							EndIf
						Case 0+lv To MyTablew20+lv
							If hierarchical And checkboxes
								*row\expanded=Bool(*row\expanded=#False)
								recalc=#True
								*this\dirty=#True
							ElseIf hierarchical
								*row\expanded=Bool(*row\expanded=#False)
								recalc=#True
								*this\dirty=#True
							ElseIf checkboxes
								*row\checked=Bool(*row\checked=#False)
								*this\dirty=#True
								If *this\evtRowChecked
									*this\evtRowChecked(*this\canvas,*row)
								EndIf
							EndIf
						Default
							If Not control Or Not multiselect
								ClearMap(*this\selected())
							EndIf
							If row=-1 And Not noheader
								_MyTableSort(*this,col)		
								recalc=#True
							ElseIf row>-1
								SelectElement(*this\expRows(),row)
								*row=*this\expRows()
								If fullrow
									*this\selected(Str(*row))=Bool(*this\selected(Str(*row))=#False)
									If *this\evtRowSelect
										*this\evtRowSelect(*this\canvas,row)
									EndIf
									
								Else
									*cell=SelectElement(*row\cells(),col)
									*this\selected(Str(*row\cells()))=Bool(*this\selected(Str(*row\cells()))=#False)
									If *this\evtCellSelect
										*this\evtCellSelect(*this\canvas,*cell)
									EndIf
									
								EndIf
							EndIf
							*this\dirty=#True
					EndSelect					
				Else
					If Not control Or Not multiselect
						ClearMap(*this\selected())
					EndIf
					If row=-1 And Not noheader
						_MyTableSort(*this,col)		
						recalc=#True
					ElseIf row>-1
						SelectElement(*this\expRows(),row)
						*row=*this\expRows()
						If fullrow
							*this\selected(Str(*row))=Bool(*this\selected(Str(*row))=#False)
							If *this\evtRowSelect
								*this\evtRowSelect(*this\canvas,row)
							EndIf
							
						Else
							*cell=SelectElement(*row\cells(),col)
							*this\selected(Str(*row\cells()))=Bool(*this\selected(Str(*row\cells()))=#False)
							If *this\evtCellSelect
								*this\evtCellSelect(*this\canvas,*cell)
							EndIf
							
						EndIf
					EndIf
					*this\dirty=#True
				EndIf
			Else
				If Not control Or Not multiselect
					ClearMap(*this\selected())
				EndIf
				*this\dirty=#True
			EndIf
		EndIf
		
		If recalc
			_MyTableRecalc(*this)
		Else
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableEvtLostFocus()
	Protected *this._strMyTableAObject=GetGadgetData(EventGadget())
	If *this
		Select *this\type
			Case #MYTABLE_TYPE_TABLE
				_MyTableStopEditCell(*this)
			Case #MYTABLE_TYPE_CELL
				Protected *cell.strMyTableCell=*this
				_MyTableStopEditCell(*cell\table)
		EndSelect
	EndIf
EndProcedure

Procedure MyTableEvtDouble()
	Protected *this.strMyTableTable=GetGadgetData(EventGadget())
	If *this
		Protected noheader.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_NO_HEADER)
		Protected fullrow.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_FULL_ROW_SELECT Or ListSize(*this\cols())=1)
		Protected checkboxes.b=Bool(*this\flags & #MYTABLE_TABLE_FLAGS_CHECKBOX)
		Protected hierarchical.b=Bool(Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL) Or Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW))
		
		Protected mx=GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseX)+GetGadgetState(*this\hscroll)
		Protected my=DesktopUnscaledY(GetGadgetAttribute(*this\canvas,#PB_Canvas_MouseY))
		
		
		Protected row=0
		If Not noheader
			row=(my-*this\headerheight)/*this\rowheight+GetGadgetState(*this\vscroll)
			
			If my<*this\headerheight
				row-1
			EndIf
		Else
			row=my/*this\rowheight+GetGadgetState(*this\vscroll)
		EndIf
		Protected col=0
		ForEach *this\cols()
			mx-*this\cols()\calcwidth
			If mx<=0
				Break
			Else
				col+1
			EndIf
		Next			
		
		If row<ListSize(*this\expRows()) And col<ListSize(*this\cols())
			If row>-1
				SelectElement(*this\expRows(),row)		
				Protected *row.strMyTableRow=*this\expRows()
				Protected *cell.strMyTableCell=SelectElement(*row\cells(),col)
				_MyTableEditCell(*cell)				
			EndIf
		EndIf					
		
	EndIf
EndProcedure

Procedure _MyTableRegister(window,canvas,hscroll,vscroll,flags.i=#MYTABLE_TABLE_FLAGS_DEFAULT,callback.MyTableProtoEventCallback=0)
	Protected *this.strMyTableTable=AllocateStructure(strMyTableTable)
	With *this
		\window=window
		\canvas=canvas
		\hscroll=hscroll
		\vscroll=vscroll
		\flags=flags
		\type=#MYTABLE_TYPE_TABLE
		If Bool(flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW)
			\flags|#MYTABLE_TABLE_FLAGS_HIERARCHICAL
		EndIf
		\lasth=GadgetHeight(canvas)
		\lastw=GadgetWidth(canvas)
		\dirty=#True
		\redraw=Bool(Not (flags & #MYTABLE_TABLE_FLAGS_STOP_DRAWING))
		\rowheight=20
		\headerheight=20
		
		\selectedbackground=RGBA(200,200,240,255)
		\background=RGBA(250,250,250,255)
		\backgroundfixed=RGBA(255,245,245,255)
		\headerbackground1=RGBA(200,200,200,255)
		\headerbackground2=RGBA(150,150,150,255)
		\headerbackgroundfixed=RGBA(200,150,150,255)
		\forecolor=RGBA(0,0,0,255)
		\headerforecolor=RGBA(240,240,240,255)
		\selectedforecolor=RGBA(240,240,240,255)
		
		\evtCallback=callback
		
		\font=GetGadgetFont(#PB_Default)
		
		\menu=CreatePopupMenu(#PB_Any)
		
		SetGadgetData(canvas,*this)
		SetGadgetData(hscroll,*this)
		SetGadgetData(vscroll,*this)
		
		BindGadgetEvent(\hscroll,@MyTableEvtScroll())
		BindGadgetEvent(\vscroll,@MyTableEvtScroll())
		BindGadgetEvent(\canvas,@MyTableEvtMouseDown(),#PB_EventType_MouseWheel)
		BindGadgetEvent(\canvas,@MyTableEvtMouseDown(),#PB_EventType_LeftButtonDown)
		BindGadgetEvent(\canvas,@MyTableEvtMouseUp(),#PB_EventType_LeftButtonUp)
		BindGadgetEvent(\canvas,@MyTableEvtMouseMove(),#PB_EventType_MouseMove)
		BindGadgetEvent(\canvas,@MyTableEvtDouble(),#PB_EventType_LeftDoubleClick)
		BindGadgetEvent(\canvas,@MyTableEvtKeyDown(),#PB_EventType_KeyDown)
		
		BindGadgetEvent(\canvas,@MyTableEvtLostFocus(),#PB_EventType_LostFocus)
	EndWith
	
	ProcedureReturn *this
EndProcedure

Procedure MyTableRegister(window,canvas,hscroll,vscroll,flags.i=#MYTABLE_TABLE_FLAGS_DEFAULT,callback.MyTableProtoEventCallback=0)
	Protected *this.strMyTableTable=_MyTableRegister(window,canvas,hscroll,vscroll,flags,callback)
	BindGadgetEvent(canvas,@MyTableEvtResize(),#PB_EventType_Resize)
	_MyTableResize(*this)
	ProcedureReturn *this
EndProcedure

Procedure MyTableRegisterDialog(window,canvas,hscroll,vscroll,flags.i=#MYTABLE_TABLE_FLAGS_DEFAULT,callback.MyTableProtoEventCallback=0)
	Protected *this.strMyTableTable=_MyTableRegister(window,canvas,hscroll,vscroll,flags,callback)	
	BindGadgetEvent(canvas,@MyTableEvtDialogResize(),#PB_EventType_Resize)
	_MyTableRecalc(*this)
	ProcedureReturn *this
EndProcedure

Procedure MyTableUnRegister(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		With *this
			UnbindGadgetEvent(\canvas,@MyTableEvtResize(),#PB_EventType_Resize)
			UnbindGadgetEvent(\hscroll,@MyTableEvtScroll())
			UnbindGadgetEvent(\vscroll,@MyTableEvtScroll())
			
			UnbindGadgetEvent(\canvas,@MyTableEvtMouseDown(),#PB_EventType_MouseWheel)
			UnbindGadgetEvent(\canvas,@MyTableEvtMouseDown(),#PB_EventType_LeftClick)
			UnbindGadgetEvent(\canvas,@MyTableEvtDouble(),#PB_EventType_LeftDoubleClick)
			UnbindGadgetEvent(\canvas,@MyTableEvtKeyDown(),#PB_EventType_KeyDown)
		EndWith
		If IsGadget(*this\editorgadget)
			FreeGadget(*this\editorgadget)
		EndIf
	EndIf
	FreeStructure(*this)
EndProcedure

Procedure MyTableSetTableFlags(canvas,flags.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		If *this\flags<>flags
			*this\flags=flags
			*this\dirty=#True
			_MyTableRecalc(*this)
		EndIf
	EndIf
EndProcedure


Procedure MyTableSetTableRowHeight(canvas,rowheight.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		If *this\rowheight<>rowheight
			*this\rowheight=rowheight
			*this\dirty=#True
			ForEach *this\rows()
				*this\rows()\dirty=#True
			Next
			_MyTableRecalc(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetTableData(canvas,*data)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		*this\data=*data
	EndIf
EndProcedure

Procedure MyTableSetTableFixedColumns(canvas,columns.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		*this\fixedcolumns=columns
	EndIf
EndProcedure

Procedure MyTableSetTableSelectedRow(canvas,row.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ClearMap(*this\selected())
		If row>-1
			SelectElement(*this\rows(),row)
			*this\selected(Str(*this\rows()))=#True
		EndIf
		*this\dirty=#True
		_MyTableRedraw(*this)
	EndIf
EndProcedure

Procedure MyTableSetTableSelectedRowById(canvas,rowid.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ClearMap(*this\selected())
		If rowid>0
			Protected *row.strMyTableRow=*this\rowsById(Str(rowid))			
			*this\selected(Str(*row))=#True
		EndIf
		*this\dirty=#True
		_MyTableRedraw(*this)
	EndIf
EndProcedure

Procedure MyTableSetTableSelectedCell(canvas,row.i,col.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ClearMap(*this\selected())
		If row>-1
			SelectElement(*this\rows(),row)
			SelectElement(*this\rows()\cells(),col)
			*this\selected(Str(*this\rows()\cells()))=#True
		EndIf
		*this\dirty=#True
		_MyTableRedraw(*this)
	EndIf
EndProcedure

Procedure MyTableGetTableSelectedRow(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ForEach *this\selected()
			Protected *o.strMyTableAObject=Val(MapKey(*this\selected()))
			If *o\brow
				Protected *row.strMyTableRow=*o
				ProcedureReturn *row\id
			EndIf
		Next
	EndIf
EndProcedure

Procedure MyTableGetTableSelectedCell(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ForEach *this\selected()
			Protected *o.strMyTableAObject=Val(MapKey(*this\selected()))
			If Not *o\brow
				ProcedureReturn *o
			EndIf
		Next
	EndIf
EndProcedure


Procedure MyTableGetTableFlags(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\flags
	EndIf
EndProcedure

Procedure MyTableGetTableRowHeight(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\rowheight
	EndIf
EndProcedure

Procedure MyTableGetTableData(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\data
	EndIf
EndProcedure

Procedure MyTableGetTableFixedColumns(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\fixedcolumns
	EndIf
EndProcedure

Procedure MyTableRedraw(canvas,redraw.b)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		*this\redraw=redraw
		*this\dirty=#True
		_MyTableRecalc(*this)
	EndIf
EndProcedure


Procedure.q MyTableAddColumn(canvas,text.s,width.i,flags.i=#MYTABLE_COLUMN_FLAGS_DEFAULT,image.i=0,*data=0,sort.i=0)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		LastElement(*this\cols())
		Protected *col.strMyTableCol=AddElement(*this\cols())
		With *col
			\text=text
			\width=width
			\flags=flags
			\image=image
			\data=*data
			\sort=sort
			\dirty=#True
			\type=#MYTABLE_TYPE_COL
			If Bool(flags & #MYTABLE_COLUMN_FLAGS_DATE)
				\format="%dd.%mm.%yyyy"
			EndIf
			If Bool(flags & #MYTABLE_COLUMN_FLAGS_DATE_TIME)
				\format="%dd.%mm.%yyyy %hh:%ii:%ss"
			EndIf
			If Bool(flags & #MYTABLE_COLUMN_FLAGS_TIME)
				\format="%hh:%ii"
			EndIf
			If Bool(flags & #MYTABLE_COLUMN_FLAGS_TIME_LONG)
				\format="%hh:%ii:%ss"
			EndIf
			\table=*this
			*this\lastColid+1
			\id=*this\lastColid
		EndWith
		*this\colsById(Str(*col\id))=*col
		*this\dirty=#True
		ForEach *this\rows()
			Protected *cell.strMyTableCell=AddElement(*this\rows()\cells())
			*cell\row=*this\rows()
			*cell\col=*col
			*cell\table=*this
		Next
		_MyTableRecalc(*this)
		ProcedureReturn *col\id
	EndIf
EndProcedure

Procedure MyTableRemoveColumn(canvas,column.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		DeleteMapElement(*this\colsById(),Str(*col\id))
		DeleteElement(*this\cols())
		ForEach *this\rows()
			SelectElement(*this\rows()\cells(),column)
			DeleteElement(*this\rows()\cells())
			*this\rows()\dirty=#True
		Next
		_MyTableRecalc(*this)
	EndIf
EndProcedure

Procedure MyTableSetColumnText(canvas,column.i,text.s)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		If *col\text<>text
			*col\text=text
			*col\dirty=#True
			*col\textwidth=0
			*col\textheight=0
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetColumnWidth(canvas,column.i,width.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		If *col\width<>width
			*col\width=width
			*col\dirty=#True
			*this\dirty=#True
			_MyTableRecalc(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetColumnFlags(canvas,column.i,flags.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		If *col\flags<>flags
			*col\flags=flags
			*col\dirty=#True
			*this\dirty=#True
			If Bool(flags & #MYTABLE_COLUMN_FLAGS_DATE)
				*col\format="%dd.%mm.%yyyy"
			EndIf
			If Bool(flags & #MYTABLE_COLUMN_FLAGS_DATE_TIME)
				*col\format="%dd.%mm.%yyyy %hh:%ii:%ss"
			EndIf
			If Bool(flags & #MYTABLE_COLUMN_FLAGS_TIME)
				*col\format="%hh:%ii"
			EndIf
			If Bool(flags & #MYTABLE_COLUMN_FLAGS_TIME_LONG)
				*col\format="%hh:%ii:%ss"
			EndIf
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetColumnImage(canvas,column.i,image.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		If *col\image<>image
			*col\image=image
			*col\dirty=#True
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetColumnData(canvas,column.i,*data)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)		
		*col\data=*data		
	EndIf
EndProcedure

Procedure MyTableSetColumnSort(canvas,column.i,sort.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		If *col\sort<>sort
			*col\sort=sort
			*col\dirty=#True
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure.s MyTableGetColumnText(canvas,column.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		ProcedureReturn *col\text
	EndIf
EndProcedure

Procedure MyTableGetColumnWidth(canvas,column.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		ProcedureReturn *col\width
	EndIf
EndProcedure

Procedure MyTableGetColumnFlags(canvas,column.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		ProcedureReturn *col\flags
	EndIf
EndProcedure

Procedure MyTableGetColumnImage(canvas,column.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		ProcedureReturn *col\image
	EndIf
EndProcedure

Procedure MyTableGetColumnData(canvas,column.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		ProcedureReturn *col\data
	EndIf
EndProcedure

Procedure MyTableGetColumnSort(canvas,column.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *col.strMyTableCol=SelectElement(*this\cols(),column)
		ProcedureReturn *col\sort
	EndIf
EndProcedure



Procedure MyTableAddDirtyRow(canvas,rows.i,parentid.q=0)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected i=0
		Protected *row.strMyTableRow=0
		If parentid>0
			Protected *parent.strMyTableRow=*this\rowsById(Str(parentid))
			LastElement(*parent\rows())
			For i=1 To rows
				*row=AddElement(*this\rows())					
				_MyTableAddDirtyRow(*this,*row)
				*row\level=*parent\level+1
			Next
		Else
			LastElement(*this\rows())
			For i=1 To rows
				*row=AddElement(*this\rows())
				_MyTableAddDirtyRow(*this,*row)				
			Next
		EndIf
		*this\dirty=#True
		_MyTableRecalc(*this)
	EndIf	
EndProcedure

Procedure.q MyTableAddRow(canvas,text.s,sep.s="|",id.q=#PB_Ignore,image.i=0,*data=0,checked.b=#False,expanded.b=#False,parentid.q=0)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=0
		If parentid>0
			Protected *parent.strMyTableRow=*this\rowsById(Str(parentid))
			LastElement(*parent\rows())
			*row=AddElement(*parent\rows())
			*row\level=*parent\level+1
		Else
			LastElement(*this\rows())
			*row=AddElement(*this\rows())
		EndIf
		
		With *row
			\brow=#True
			\checked=checked
			\expanded=expanded
			\data=*data
			\image=image
			\type=#MYTABLE_TYPE_ROW
			If IsImage(image)				
				\sclaedimage=CopyImage(image,#PB_Any)
				ResizeImage(\sclaedimage,MyTableW16,MyTableH16)
			EndIf
			If id=#PB_Ignore Or id=*this\lastRowid
				*this\lastRowid+1
				\id=*this\lastRowid
			Else
				\id=id
				*this\lastRowid=id
			EndIf
			\dirty=#True
			\table=*this
			Protected c=CountString(text,sep)+1
			Protected i=0
			For i=1 To c
				Protected *cell.strMyTableCell=AddElement(*row\cells())
				Protected *coll.strMyTableCol=SelectElement(*this\cols(),i-1)
				*cell\text=StringField(text,i,sep)
				*cell\row=*row
				*cell\col=*coll
				*cell\table=*this
				*cell\type=#MYTABLE_TYPE_CELL
				If Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_DEFAULT_DATE_TIME)
					*cell\value=ParseDate(*coll\format,*cell\text)
				ElseIf Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_INTEGER)
					*cell\value=Val(*cell\text)
				ElseIf Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_DOUBLE)
					*cell\value=ValD(*cell\text)
				ElseIf Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_BOOLEAN)
					*cell\value=Bool(*cell\text="1" Or 
					                 LCase(*cell\text)="x" Or 
					                 LCase(*cell\text)="true" Or
					                 LCase(*cell\text)="yes")
					*cell\checked=*cell\value
				EndIf
			Next
		EndWith
		*this\rowsById(Str(*row\id))=*row
		*this\dirty=#True
		_MyTableRecalc(*this)
		ProcedureReturn *row\id
	EndIf
EndProcedure

Procedure MyTableRemoveRow(canvas,row.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		SelectElement(*this\rows(),row)
		If IsImage(*this\rows()\sclaedimage)
			FreeImage(*this\rows()\sclaedimage)
		EndIf
		DeleteMapElement(*this\rowsById(),Str(*this\rows()\id))
		DeleteElement(*this\rows())
		*this\dirty=#True
		_MyTableRecalc(*this)
	EndIf
EndProcedure

Procedure MyTableClearRows(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ClearList(*this\rows())
		ClearMap(*this\rowsById())
		*this\dirty=#True
		*this\lastRowid=0
		_MyTableRecalc(*this)
	EndIf
EndProcedure


Procedure MyTableSetRowImage(canvas,row.i,image.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		If *row\image<>image
			*row\image=image
			*row\dirty=#True
			*this\dirty=#True
			If IsImage(*row\sclaedimage)
				FreeImage(*row\sclaedimage)				
			EndIf
			If IsImage(image)				
				*row\sclaedimage=CopyImage(image,#PB_Any)
				ResizeImage(*row\sclaedimage,MyTableW16,MyTableH16)
			EndIf
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetRowData(canvas,row.i,*data)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		*row\data=*data		
	EndIf
EndProcedure

Procedure MyTableSetRowDirty(canvas,row.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		*row\dirty=#True
		_MyTableRedraw(*this)
	EndIf
EndProcedure

Procedure MyTableSetRowChecked(canvas,row.i,checked.b)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		If *row\checked<>checked
			*row\checked=checked
			*row\dirty=#True
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetRowExpanded(canvas,row.i,expanded.b)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		If *row\expanded<>expanded
			*row\expanded=expanded
			*row\dirty=#True
			*this\dirty=#True
			_MyTableRecalc(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableGetRowImage(canvas,row.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		ProcedureReturn *row\image
	EndIf
EndProcedure

Procedure MyTableGetRowData(canvas,row.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		ProcedureReturn *row\data
	EndIf
EndProcedure

Procedure MyTableGetRowCount(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn ListSize(*this\expRows())
	EndIf
EndProcedure

Procedure.b MyTableGetRowChecked(canvas,row.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		ProcedureReturn *row\checked
	EndIf
EndProcedure

Procedure.b MyTableGetRowExpanded(canvas,row.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		ProcedureReturn *row\expanded
	EndIf
EndProcedure

Procedure MyTableSetCellText(canvas,row.i,col.i,text.s)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		Protected *cell.strMyTableCell=SelectElement(*this\rows()\cells(),col)
		Protected *coll.strMyTableCol=*cell\col
		If *cell\text<>text
			*cell\text=text
			*cell\textwidth=0
			*cell\textheight=0
			*cell\dirty=#True
			If Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_DEFAULT_DATE_TIME)
				*cell\value=ParseDate(*coll\format,*cell\text)
			ElseIf Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_INTEGER)
				*cell\value=Val(*cell\text)
			ElseIf Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_DOUBLE)
				*cell\value=ValD(*cell\text)
			ElseIf Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_BOOLEAN)
				*cell\value=Bool(*cell\text="1" Or 
				                 LCase(*cell\text)="x" Or 
				                 LCase(*cell\text)="true" Or
				                 LCase(*cell\text)="yes")
				*cell\checked=*cell\value
			EndIf
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetCellValue(canvas,row.i,col.i,value.d)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		Protected *cell.strMyTableCell=SelectElement(*this\rows()\cells(),col)
		Protected *coll.strMyTableCol=*cell\col
		If *cell\value<>value		
			*cell\value=value		
			*cell\textwidth=0
			*cell\textheight=0
			*cell\dirty=#True
			If Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_DEFAULT_DATE_TIME)
				If value
					*cell\text=""
				Else
					*cell\text=FormatDate(*coll\format,*cell\value)
				EndIf
			ElseIf Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_INTEGER)
				*cell\text=Str(value)
			ElseIf Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_DOUBLE)
				*cell\text=FormatNumber(value)
			ElseIf Bool(*coll\flags & #MYTABLE_COLUMN_FLAGS_BOOLEAN)
				*cell\checked=*cell\value
				*cell\text=Str(value)
			EndIf
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetCellChecked(canvas,row.i,col.i,checked.b)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		Protected *cell.strMyTableCell=SelectElement(*this\rows()\cells(),col)
		Protected *coll.strMyTableCol=*cell\col
		If *cell\checked<>checked
			*cell\value=checked		
			*cell\checked=checked		
			*cell\textwidth=0
			*cell\textheight=0
			*cell\dirty=#True				
			*cell\text=Str(checked)		
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetCellData(canvas,row.i,col.i,*data)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		Protected *cell.strMyTableCell=SelectElement(*this\rows()\cells(),col)
		Protected *coll.strMyTableCol=*cell\col
		*cell\data=*data
	EndIf
EndProcedure

Procedure MyTableSetCellImage(canvas,row.i,col.i,image.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		Protected *cell.strMyTableCell=SelectElement(*this\rows()\cells(),col)
		Protected *coll.strMyTableCol=*cell\col
		If *cell\image<>image
			*cell\image=image		
			If IsImage(image)
				*cell\textheight=ImageHeight(image)
				*cell\textwidth=ImageWidth(image)
			Else
				*cell\textheight=0
				*cell\textwidth=0
			EndIf
			*cell\dirty=#True							
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure.s MyTableGetCellText(canvas,row.i,col.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		Protected *cell.strMyTableCell=SelectElement(*this\rows()\cells(),col)		
		ProcedureReturn *cell\text
	EndIf
EndProcedure

Procedure.d MyTableGetCellValue(canvas,row.i,col.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		Protected *cell.strMyTableCell=SelectElement(*this\rows()\cells(),col)		
		ProcedureReturn *cell\value
	EndIf
EndProcedure

Procedure MyTableGetCellChecked(canvas,row.i,col.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		Protected *cell.strMyTableCell=SelectElement(*this\rows()\cells(),col)		
		ProcedureReturn *cell\checked
	EndIf
EndProcedure

Procedure MyTableGetCellData(canvas,row.i,col.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		Protected *cell.strMyTableCell=SelectElement(*this\rows()\cells(),col)		
		ProcedureReturn *cell\data
	EndIf
EndProcedure

Procedure MyTableGetCellImage(canvas,row.i,col.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		Protected *row.strMyTableRow=SelectElement(*this\rows(),row)
		Protected *cell.strMyTableCell=SelectElement(*this\rows()\cells(),col)		
		ProcedureReturn *cell\image
	EndIf
EndProcedure

Procedure MyTableRegisterEvents(canvas,
                                evtRowSelect.MyTableProtoEventRowSelected,
                                evtCellSelect.MyTableProtoEventCellSelected,
                                evtRowChecked.MyTableProtoEventRowChecked,
                                evtCellChecked.MyTableProtoEventCellChecked,
                                evtCellChangedText.MyTableProtoEventCellChangedText,
                                evtCellChangedValue.MyTableProtoEventCellChangedValue,
                                evtCallback.MyTableProtoEventCallback)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		With *this
			\evtRowSelect=evtRowSelect
			\evtCellSelect=evtCellSelect
			\evtRowChecked=evtRowChecked
			\evtCellChecked=evtCellChecked
			\evtCellChangedText=evtCellChangedText
			\evtCellChangedValue=evtCellChangedValue
			\evtCallback=evtCallback
		EndWith
	EndIf
EndProcedure


Procedure MyTableSetSelectedbackground(canvas,color.q)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		If *this\selectedbackground<>color
			*this\selectedbackground=color
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetBackground(canvas,color.q)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		If *this\background<>color
			*this\background=color
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetBackgroundFixedColumns(canvas,color.q)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		If *this\backgroundfixed<>color
			*this\backgroundfixed=color
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetHeaderbackground1(canvas,color.q)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		If *this\headerbackground1<>color
			*this\headerbackground1=color
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetHeaderbackground2(canvas,color.q)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		If *this\headerbackground2<>color
			*this\headerbackground2=color
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetHeaderbackgroundFixedColumns(canvas,color.q)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		If *this\headerbackgroundfixed<>color
			*this\headerbackgroundfixed=color
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetForecolor(canvas,color.q)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		If *this\forecolor<>color
			*this\forecolor=color
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetHeaderforecolor(canvas,color.q)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		If *this\headerforecolor<>color
			*this\headerforecolor=color
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure MyTableSetSelectedforecolor(canvas,color.q)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		If *this\selectedforecolor<>color
			*this\selectedforecolor=color
			*this\dirty=#True
			_MyTableRedraw(*this)
		EndIf
	EndIf
EndProcedure

Procedure.q MyTableGetSelectedbackground(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\selectedbackground
	EndIf
EndProcedure

Procedure.q MyTableGetBackground(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\background
	EndIf
EndProcedure

Procedure.q MyTableGetBackgroundFixedColumns(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\backgroundfixed
	EndIf
EndProcedure

Procedure.q MyTableGetHeaderbackground1(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\headerbackground1
	EndIf
EndProcedure

Procedure.q MyTableGetHeaderbackground2(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\headerbackground2
	EndIf
EndProcedure

Procedure.q MyTableGetHeaderbackgroundFixedColumns(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\headerbackgroundfixed
	EndIf
EndProcedure

Procedure.q MyTableGetForecolor(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\forecolor
	EndIf
EndProcedure

Procedure.q MyTableGetHeaderforecolor(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\headerforecolor
	EndIf
EndProcedure

Procedure.q MyTableGetSelectedforecolor(canvas)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	If *this
		ProcedureReturn *this\selectedforecolor
	EndIf
EndProcedure

Procedure MyTableAutosizeColumn(canvas,col.i)
	Protected *this.strMyTableTable=GetGadgetData(canvas)
	
	If *this
		Protected hierarchical.b=Bool(Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL) Or Bool(*this\flags & #MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW))
		
		If col=#PB_Ignore
			Protected c=ListSize(*this\cols())-1
			Protected i=0
			For i=0 To c
				MyTableAutosizeColumn(canvas,i)
			Next
		Else
			StartDrawing(CanvasOutput(*this\canvas))			
			DrawingFont(*this\font)
			
			ClearList(*this\expRows())
			
			ForEach *this\rows()
				Protected *row.strMyTableRow=*this\rows()
				AddElement(*this\expRows()):*this\expRows()=*row
				If *row\expanded And hierarchical
					_MyTableRecalcExp(*this,*row,0)
				EndIf
			Next
			
			Protected w=0
			Protected *col.strMyTableCol=SelectElement(*this\cols(),col)
			w=_MyTableTextWidth(*col\text)
			
			ForEach *this\expRows()
				*row=*this\expRows()
				Protected *cell.strMyTableCell=SelectElement(*row\cells(),col)
				If *cell
					If *cell\textwidth=0
						If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_BOOLEAN)
							*cell\textwidth=MyTableW20
						Else
							*cell\textwidth=_MyTableTextWidth(*cell\text)
						EndIf
					EndIf
					If *cell\textheight=0
						If Bool(*col\flags & #MYTABLE_COLUMN_FLAGS_BOOLEAN)
							*cell\textheight=MyTableW20
						Else
							*cell\textheight=_MyTableTextHeight(*cell\text)
						EndIf
					EndIf
					If *cell\textwidth>w
						w=*cell\textwidth
					EndIf
				EndIf
			Next
			*col\width=w+40
			*col\calcwidth=DesktopScaledX(*col\width)
			
			StopDrawing()
		EndIf
		*this\dirty=#True
		_MyTableRedraw(*this)
	EndIf
EndProcedure
Last edited by Cyllceaux on Sun May 02, 2021 10:34 pm, edited 4 times in total.
Cyllceaux
Enthusiast
Enthusiast
Posts: 353
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable

Post by Cyllceaux »

Another example

Image
User avatar
Tenaja
Addict
Addict
Posts: 1829
Joined: Tue Nov 09, 2010 10:15 pm

Re: My MyTable

Post by Tenaja »

That looks very nice! Thanks for sharing.
User avatar
Kwai chang caine
Addict
Addict
Posts: 4968
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: My MyTable

Post by Kwai chang caine »

Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Cyllceaux
Enthusiast
Enthusiast
Posts: 353
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable

Post by Cyllceaux »

One step closer to my outlook-clone :)
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 1877
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: My MyTable

Post by Andre »

Looks very promising, thanks for sharing! :D

Keyboard support for navigating through the tables would be nice ;-)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Cyllceaux
Enthusiast
Enthusiast
Posts: 353
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable

Post by Cyllceaux »

I know about the keyboard support.

I have Multiselect with Control, but not with Shift.
So, Keyboard is not the only thing I have to do :)
zikitrake
Enthusiast
Enthusiast
Posts: 758
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain
Contact:

Re: My MyTable

Post by zikitrake »

Just logging here to thank you for showing this to us.
Looking forward to you adding keyboard support :)

I'm currently using Thorsten1867's wonderful module, but it has some problems when resizing columns and you exceed the gadget width.

Thanks to you and everyone who publishes these fantastic add-ons :)
Cyllceaux
Enthusiast
Enthusiast
Posts: 353
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable

Post by Cyllceaux »

Image

Next Version... I update the source Posts.

Now with Keyboardsupport:
navigate: Up, Down, Left, Right
tree: Add, Sub, Multiply, Divide,
row checkbox: Space

Code: Select all

EnableExplicit

UsePNGImageDecoder()

XIncludeFile "mytable.pbi"

Define rowImage=LoadImage(#PB_Any,"C:\Users\silko\OneDrive\Dokumente\Icons\office\png-hot\48x48\Briefcase.png")
Define rowImageSub=LoadImage(#PB_Any,"C:\Users\silko\OneDrive\Dokumente\Icons\office\png-hot\48x48\Lock.png")
Define rowImageSub2=LoadImage(#PB_Any,"C:\Users\silko\OneDrive\Dokumente\Icons\office\png-hot\48x48\Attach.png")

Global mainWindow=OpenWindow(#PB_Any,0,0,1100,600,"MyTable",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget)

Global canvasTable=CanvasGadget(#PB_Any,0,0,WindowWidth(mainWindow),WindowHeight(mainWindow),#PB_Canvas_Container|#PB_Canvas_Border|#PB_Canvas_Keyboard)
Global hscrollTable=ScrollBarGadget(#PB_Any,0,GadgetHeight(canvasTable)-20,GadgetWidth(canvasTable)-20,20,0,0,100)
Global vscrollTable=ScrollBarGadget(#PB_Any,GadgetWidth(canvasTable)-20,0,20,GadgetHeight(canvasTable)-20,0,0,100,#PB_ScrollBar_Vertical)              
CloseGadgetList()

Global canvasTable2=CanvasGadget(#PB_Any,0,0,WindowWidth(mainWindow),WindowHeight(mainWindow),#PB_Canvas_Container|#PB_Canvas_Border|#PB_Canvas_Keyboard)
Global hscrollTable2=ScrollBarGadget(#PB_Any,0,GadgetHeight(canvasTable2)-20,GadgetWidth(canvasTable2)-20,20,0,0,100)
Global vscrollTable2=ScrollBarGadget(#PB_Any,GadgetWidth(canvasTable2)-20,0,20,GadgetHeight(canvasTable2)-20,0,0,100,#PB_ScrollBar_Vertical)              
CloseGadgetList()

Global canvasTree=CanvasGadget(#PB_Any,0,0,WindowWidth(mainWindow),WindowHeight(mainWindow),#PB_Canvas_Container|#PB_Canvas_Border|#PB_Canvas_Keyboard)
Global hscrollTree=ScrollBarGadget(#PB_Any,0,GadgetHeight(canvasTree)-20,GadgetWidth(canvasTree)-20,20,0,0,100)
Global vscrollTree=ScrollBarGadget(#PB_Any,GadgetWidth(canvasTree)-20,0,20,GadgetHeight(canvasTree)-20,0,0,100,#PB_ScrollBar_Vertical)              
CloseGadgetList()

Global canvasTree2=CanvasGadget(#PB_Any,0,0,WindowWidth(mainWindow),WindowHeight(mainWindow),#PB_Canvas_Container|#PB_Canvas_Border|#PB_Canvas_Keyboard)
Global hscrollTree2=ScrollBarGadget(#PB_Any,0,GadgetHeight(canvasTree2)-20,GadgetWidth(canvasTree2)-20,20,0,0,100)
Global vscrollTree2=ScrollBarGadget(#PB_Any,GadgetWidth(canvasTree2)-20,0,20,GadgetHeight(canvasTree2)-20,0,0,100,#PB_ScrollBar_Vertical)              
CloseGadgetList()

Global canvasBild=CanvasGadget(#PB_Any,WindowWidth(mainWindow)-150,0,150,WindowHeight(mainWindow),#PB_Canvas_Container|#PB_Canvas_Border|#PB_Canvas_Keyboard)
Global hscrollBild=ScrollBarGadget(#PB_Any,0,GadgetHeight(canvasBild)-20,GadgetWidth(canvasBild)-20,20,0,0,100)
Global vscrollBild=ScrollBarGadget(#PB_Any,GadgetWidth(canvasBild)-20,0,20,GadgetHeight(canvasBild)-20,0,0,100,#PB_ScrollBar_Vertical)              
CloseGadgetList()

Global canvasTable3=CanvasGadget(#PB_Any,WindowWidth(mainWindow)-150,0,150,WindowHeight(mainWindow),#PB_Canvas_Container|#PB_Canvas_Border|#PB_Canvas_Keyboard)
Global hscrollTable3=ScrollBarGadget(#PB_Any,0,GadgetHeight(canvasTable3)-20,GadgetWidth(canvasTable3)-20,20,0,0,100)
Global vscrollTable3=ScrollBarGadget(#PB_Any,GadgetWidth(canvasTable3)-20,0,20,GadgetHeight(canvasTable3)-20,0,0,100,#PB_ScrollBar_Vertical)              
CloseGadgetList()



Global splitter=SplitterGadget(#PB_Any,0,0,0,0,canvasTable,canvasTable2,#PB_Splitter_FirstFixed|#PB_Splitter_Separator)
Global splitter2=SplitterGadget(#PB_Any,0,0,0,0,canvasTree,canvasTree2,#PB_Splitter_FirstFixed|#PB_Splitter_Separator)
Global splitter3=SplitterGadget(#PB_Any,0,0,0,0,splitter2,splitter,#PB_Splitter_FirstFixed|#PB_Splitter_Vertical|#PB_Splitter_Separator)
Global splitter4=SplitterGadget(#PB_Any,0,0,0,0,splitter3,canvasBild,#PB_Splitter_SecondFixed|#PB_Splitter_Vertical|#PB_Splitter_Separator)
Global splitter5=SplitterGadget(#PB_Any,0,0,WindowWidth(mainWindow),WindowHeight(mainWindow),splitter4,canvasTable3,#PB_Splitter_SecondFixed|#PB_Splitter_Vertical|#PB_Splitter_Separator)

SetGadgetState(splitter,300)
SetGadgetState(splitter2,300)
SetGadgetState(splitter3,300)
SetGadgetState(splitter4,400)
SetGadgetState(splitter5,800)

Procedure CanvasTable3Callback(canvas,*row.strMyTableRow)
	Protected titelnr=*row\id
	Protected albumnr=1
	If titelnr>10
		albumnr=titelnr/10
		titelnr-(albumnr*10)
	EndIf
	Protected *cell.strMyTableCell=SelectElement(*row\cells(),0)
	*cell\text="Titel "+titelnr
	*cell=SelectElement(*row\cells(),1)
	*cell\text="Album "+albumnr
	*cell=SelectElement(*row\cells(),2)	
	*cell\text=FormatDate(*cell\col\format,AddDate(0,#PB_Date_Second,Random(10000,100)))	
EndProcedure

Procedure evtResizeWindow()
	ResizeGadget(splitter5,
	             #PB_Ignore,
	             #PB_Ignore,
	             WindowWidth(EventWindow()),
	             WindowHeight(EventWindow()))
EndProcedure

BindEvent(#PB_Event_SizeWindow,@evtResizeWindow(),mainWindow)
BindEvent(#PB_Event_RestoreWindow,@evtResizeWindow(),mainWindow)
BindEvent(#PB_Event_MaximizeWindow,@evtResizeWindow(),mainWindow)

MyTableRegister(mainWindow,canvasTable,hscrollTable,vscrollTable)
MyTableRegister(mainWindow,canvasTable2,hscrollTable2,vscrollTable2,#MYTABLE_TABLE_FLAGS_FULL_ROW_SELECT|#MYTABLE_TABLE_FLAGS_LAST_STRETCH|#MYTABLE_TABLE_FLAGS_GRID)
MyTableRegister(mainWindow,canvasTree,hscrollTree,vscrollTree,#MYTABLE_TABLE_FLAGS_LAST_STRETCH|#MYTABLE_TABLE_FLAGS_HIERARCHICAL_ARROW|#MYTABLE_TABLE_FLAGS_CHECKBOX)
MyTableRegister(mainWindow,canvasTree2,hscrollTree2,vscrollTree2,#MYTABLE_TABLE_FLAGS_LAST_STRETCH|#MYTABLE_TABLE_FLAGS_NO_HEADER|#MYTABLE_TABLE_FLAGS_MULTISELECT)
MyTableRegister(mainWindow,canvasBild,hscrollBild,vscrollBild,#MYTABLE_TABLE_FLAGS_LAST_STRETCH|#MYTABLE_TABLE_FLAGS_NO_HEADER|#MYTABLE_TABLE_FLAGS_GRID)
MyTableRegister(mainWindow,canvasTable3,hscrollTable3,vscrollTable3,#MYTABLE_TABLE_FLAGS_GRID|#MYTABLE_TABLE_FLAGS_MULTISELECT|#MYTABLE_TABLE_FLAGS_CALLBACK,@CanvasTable3Callback())

MyTableAddColumn(canvasTree,"Kategorien",0)
MyTableAddColumn(canvasTree2,"Orte",0)
MyTableSetTableRowHeight(canvasTree2,30)

MyTableAddColumn(canvasTable,"ID",50,#MYTABLE_COLUMN_FLAGS_RIGHT|#MYTABLE_COLUMN_FLAGS_INTEGER)
MyTableAddColumn(canvasTable,"Vorname",200,#MYTABLE_COLUMN_FLAGS_EDITABLE)
MyTableAddColumn(canvasTable,"Nachname",200,#MYTABLE_COLUMN_FLAGS_EDITABLE)
MyTableAddColumn(canvasTable,"Geburtsdatum",150,#MYTABLE_COLUMN_FLAGS_CENTER|#MYTABLE_COLUMN_FLAGS_DATE|#MYTABLE_COLUMN_FLAGS_EDITABLE)
MyTableAddColumn(canvasTable,"Uhrzeit",150,#MYTABLE_COLUMN_FLAGS_CENTER|#MYTABLE_COLUMN_FLAGS_TIME_LONG|#MYTABLE_COLUMN_FLAGS_EDITABLE)


MyTableAddColumn(canvasTable2,"ID",50,#MYTABLE_COLUMN_FLAGS_RIGHT|#MYTABLE_COLUMN_FLAGS_INTEGER|#MYTABLE_COLUMN_FLAGS_MIDDLE)
MyTableAddColumn(canvasTable2,"Firma",200,#MYTABLE_COLUMN_FLAGS_EDITABLE|#MYTABLE_COLUMN_FLAGS_BOTTOM)
MyTableAddColumn(canvasTable2,"Privat",50,#MYTABLE_COLUMN_FLAGS_BOOLEAN|#MYTABLE_COLUMN_FLAGS_CENTER|#MYTABLE_COLUMN_FLAGS_EDITABLE|#MYTABLE_COLUMN_FLAGS_MIDDLE)
MyTableAddColumn(canvasTable2,"Info",150,#MYTABLE_COLUMN_FLAGS_EDITABLE)
MyTableSetTableRowHeight(canvasTable2,40)

MyTableAddColumn(canvasBild,"",150,#MYTABLE_COLUMN_FLAGS_CENTER|#MYTABLE_COLUMN_FLAGS_IMAGE|#MYTABLE_COLUMN_FLAGS_MIDDLE)
MyTableSetTableRowHeight(canvasBild,128)


MyTableSetBackground(canvasTree2,RGBA(10,10,10,255))
MyTableSetForecolor(canvasTree2,RGBA(210,210,210,255))
MyTableSetSelectedforecolor(canvasTree2,RGBA(10,10,10,255))

MyTableSetBackground(canvasBild,RGBA(10,10,10,255))


MyTableAddColumn(canvasTable3,"Titel",0)
MyTableAddColumn(canvasTable3,"Album",0)
MyTableAddColumn(canvasTable3,"Länge",0,#MYTABLE_COLUMN_FLAGS_CENTER|#MYTABLE_COLUMN_FLAGS_TIME_LONG)
MyTableAddDirtyRow(canvasTable3,1000)


Define i,g,h
i=0
MyTableRedraw(canvasBild,#False)
If ExamineDirectory(0,"C:\Users\silko\OneDrive\Dokumente\Icons\hardware\png-hot\48x48","*.png")
	While NextDirectoryEntry(0)
		MyTableAddRow(canvasBild,"")
		MyTableSetCellImage(canvasBild,i,0,LoadImage(#PB_Any,"C:\Users\silko\OneDrive\Dokumente\Icons\hardware\png-hot\48x48\"+DirectoryEntryName(0)))
		i+1
		If i=10
			Break
		EndIf
	Wend
	FinishDirectory(0)
EndIf
MyTableRedraw(canvasBild,#True)




MyTableRedraw(canvasTree,#False)
For i=1 To 10
	Define id=MyTableAddRow(canvasTree,"Kategorie "+Str(i),"",#PB_Ignore,rowImage,0,Random(1,0),Random(1,0))	
	For g=1 To Random(5,0)
		Define sub= MyTableAddRow(canvasTree,"SubKategorie "+Str(g),"",#PB_Ignore,rowImageSub,0,Random(1,0),Random(1,0),id)
		For h=1 To Random(3,0)
			MyTableAddRow(canvasTree,"SubKategorie "+Str(g)+" "+Str(h),"",#PB_Ignore,rowImageSub2,0,Random(1,0),Random(1,0),sub)
		Next
	Next
Next
MyTableRedraw(canvasTree,#True)

MyTableRedraw(canvasTable,#False)
For i=1 To 100
	MyTableAddRow(canvasTable,Str(i)+"|Vorname "+Str(i)+"|Nachname "+Str(i)+"|"+FormatDate("%dd.%mm.%yyyy",AddDate(Date(),#PB_Date_Day,i))+"|"+FormatDate("%hh:%ii:%ss",AddDate(Date(),#PB_Date_Second,i)),"|",#PB_Ignore,rowImageSub2)
Next
MyTableRedraw(canvasTable,#True)

MyTableRedraw(canvasTree2,#False)
For i=1 To 100
	MyTableAddRow(canvasTree2,"Ort "+Str(i))
Next
MyTableRedraw(canvasTree2,#True)

MyTableRedraw(canvasTable2,#False)
For i=1 To 10000
	MyTableAddRow(canvasTable2,Str(i)+"|firma "+Str(i)+"|"+Str(Random(1,0))+"|Info "+Str(i)+#CRLF$+"UnterInfo "+Str(i))
Next
MyTableRedraw(canvasTable2,#True)


MyTableAutosizeColumn(canvasTable,#PB_Ignore)
MyTableAutosizeColumn(canvasTable2,#PB_Ignore)
MyTableAutosizeColumn(canvasTable3,#PB_Ignore)

PostEvent(#PB_Event_SizeWindow,mainWindow,0)

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

MyTableUnRegister(canvasTable)
MyTableUnRegister(canvasTable2)
MyTableUnRegister(canvasBild)
MyTableUnRegister(canvasTree)
MyTableUnRegister(canvasTree2)
MyTableUnRegister(canvasTable3)



some words to the "callback" feature.
I have some Databases with millions on rows. I want to show "all" but I don't want to load all. So the callback only asc for the row which is show and cach the result. (and yes, I really mean millions.)
Last edited by Cyllceaux on Sun May 02, 2021 2:45 pm, edited 1 time in total.
User avatar
HeX0R
Enthusiast
Enthusiast
Posts: 690
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: My MyTable

Post by HeX0R »

That's a pretty cool thing, I didn't touch it first, because I thought this is really just a table, but in fact it is more like a grid gadget.

There are some behaviors with editable cells, which doesn't feel well.

When I doubleclick on a cell, the stringgadget will show-up, that's o.k.
But usually I'm clicking another time into the cell to set the cursor position, but that third click will just jump out of the edit mode.

Second:
I think anyone would expect that pressing the return key would make the cell non-editable again (accepting the changes), here I have to click somewhere first, which feels... wrong.
Cyllceaux
Enthusiast
Enthusiast
Posts: 353
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable

Post by Cyllceaux »

Yes, you are right.
The Edit-Feature was a test for me. My first plan was to make functions like excel. So only a stringfield. But it felt wrong.
But you are right. I will change it. But I will follow my plan again to excel-like. The calendar is not stable enough to use. (multiplatform and dpi-safe)
(yes in my actual version I can things doing like '=Sum(A1:A5)' )

So, next version Enter or Double click for editing, focus change or return for cell change. Shift + Return = linebreak. Yes... I have to write the linebreak feature again. It's broken in that version
Cyllceaux
Enthusiast
Enthusiast
Posts: 353
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable

Post by Cyllceaux »

Soooo:

Return starts editing. Editing Return is a commit, Shift+Return is a linebreak.
linebreak works.


TODO: column and row resize


BTW: the CanvasGadget steal Shortcuts and fokus events even though it doesn't have the focus. so I made a workaround with a borderless window.
Mr.L
User
User
Posts: 58
Joined: Sun Oct 09, 2011 7:39 am

Re: My MyTable

Post by Mr.L »

I may be stupid, but I can't find a download link to test your table :oops:
Post Reply