$PBExportHeader$u_dw.sru
forward
global type u_dw from datawindow
end type
end forward

global type u_dw from datawindow
int Width=2176
int Height=1096
int TabOrder=1
event refresh pbm_custom01
event newrow pbm_custom02
event deleterow pbm_custom03
event savedata pbm_custom04
event retrievedata pbm_custom05
event accepttext pbm_custom06
event newfirstrow pbm_custom07
event newlastrow pbm_custom08
event postaccepttext pbm_custom09
event documentation pbm_custom75
event parentresize pbm_custom10
end type
global u_dw u_dw

type variables
Public:

Boolean		bFailedAccept = FALSE, i_bFailedSave = FALSE


Boolean		i_bAutoResizeHorizontal = FALSE, i_bAutoResizeVertical = FALSE
Integer		i_nBottomGap, i_nRightGap, i_nMinWidth, i_nMaxWidth = -1, i_nMinHeight, i_nMaxHeight = -1
Window		i_wParent

Private:

Boolean		i_bInAcceptText = FALSE
end variables

forward prototypes
public subroutine uf_ChangeDataObject (string szdataobject, rowfocusind rfipointertype, picture ptrpointer, integer nxlocation, integer nylocation, transaction trtransaction)
protected function long uf_retrievedata ()
end prototypes

on newrow;Long lRow

lRow = this.GetRow()

If lRow = -1 Then
	error.object = this.ClassName()
	error.ObjectEvent = "NewRow"
	error.line = 3
	error.number = -1
	error.text = "Error get row information from the datawindow."

Else
	lRow = this.InsertRow( lRow + 1)

	If lRow = -1 Then
		error.object = this.ClassName()
		error.ObjectEvent = "NewRow"
		error.line = 12
		error.number = -1
		error.text = "Unable to insert a new row into the datawindow."
	Else
		this.SetColumn( 1)
		this.ScrollToRow( lRow)
		this.SetFocus()
	End If
End If
end on

on deleterow;Long lRow

lRow = this.GetRow()

If lRow = -1 Then
	error.object = this.ClassName()
	error.ObjectEvent = "DeleteRow"
	error.line = 3
	error.number = -1
	error.text = "Error get row information from the datawindow."
Else
	If this.DeleteRow( lRow) <> 1 Then
		error.object = this.ClassName()
		error.ObjectEvent = "DeleteRow"
		error.line = 12
		error.number = -1
		error.text = "Unable to Delete a new row into the datawindow."
	Else
		this.ScrollToRow( lRow - 1)
		this.SetFocus()
	End If
End If
end on

on accepttext;If Not i_bInAcceptText Then
	i_bInAcceptText = TRUE
	If this.AcceptText() = -1 Then
		bFailedAccept = TRUE
		this.SetFocus()
		this.PostEvent( "PostAcceptText")
		Return
	Else
		bFailedAccept = FALSE
	End If
End If

i_bInAcceptText = FALSE
end on

on newfirstrow;Long lRow

lRow = this.InsertRow( 1)

If lRow = -1 Then
	error.object = this.ClassName()
	error.ObjectEvent = "NewFirstRow"
	error.line = 3
	error.number = -1
	error.text = "Unable to insert a new row into the datawindow."
Else
	this.SetColumn( 1)
	this.ScrollToRow( lRow)
	this.SetFocus()
End If
end on

on newlastrow;Long lRow

lRow = this.InsertRow( 0)

If lRow = -1 Then
	error.object = this.ClassName()
	error.ObjectEvent = "NewLastRow"
	error.line = 3
	error.number = -1
	error.text = "Unable to insert a new row into the datawindow."

Else
	this.SetColumn( 1)
	this.ScrollToRow( lRow)
	this.SetFocus()
End If
end on

on postaccepttext;i_bInAcceptText = FALSE
end on

on documentation;// Copyright Simon Gallagher 1993-1995
//
// This DataWindow object contains the following functionality:
// 
// Events:
// 	DeleteRow 		- Handles deleting the current row
// 	SaveData  		- Handles saving the data
//		RetrieveData 	- Handles retrieving data for the dw, no parameters
//		NewRow			- Inserts a new row after the current
//		NewFirstRow		- Inserts a new row at the beginning of the dw
//		NewLastRow		- Inserts a new row at the end of the dw
//		AcceptText		- Handles the acceptance of data before focus leaves the window
//		ParentResize	- On direction of a parent window, the datawindow will resize itself
end on

on parentresize;Integer nNewWidth, nNewHeight

this.SetRedraw( FALSE)

If i_bAutoResizeHorizontal Then
    nNewWidth = i_wParent.Width - this.X - i_nRightGap
    If nNewWidth >= i_nMinWidth And (nNewWidth <= i_nMaxWidth Or i_nMaxWidth = -1) Then
         this.Width = nNewWidth
         this.HScrollBar = TRUE
	ElseIf nNewWidth < i_nMinWidth Then
		this.Width = i_nMinWidth
    End If
End If

If i_bAutoResizeVertical Then
    nNewHeight = i_wParent.Height - this.Y - i_nBottomGap
    If nNewHeight >=i_nMinHeight And (nNewHeight <= i_nMaxHeight Or i_nMaxHeight=-1) Then
         this.Height = nNewHeight
         this.VScrollBar = TRUE
	ElseIf nNewHeight < i_nMinHeight Then
		this.Height = i_nMinHeight
    End If 
End If

this.SetRedraw( TRUE)
end on

public subroutine uf_ChangeDataObject (string szdataobject, rowfocusind rfipointertype, picture ptrpointer, integer nxlocation, integer nylocation, transaction trtransaction);this.dataobject = szDataObject

If IsValid( ptrPointer) Then
		this.SetRowFocusIndicator( ptrPointer, nXLocation, nYLocation)
Else
		this.SetRowFocusIndicator( rfiPointerType, nXLocation, nYLocation)
End If

this.SetTransObject( trTransaction)
end subroutine

protected function long uf_retrievedata ();Return this.Retrieve()
end function

event constructor;If this.SetTransObject( SQLCA) <> 1 Then
	error.object = this.ClassName()
	error.objectevent = "Constructor"
	error.line = 1
	error.number = SQLCA.SQLDBCode
	error.text = SQLCA.SQLErrText
End If
end event

on itemerror;i_bInAcceptText = TRUE
end on

on losefocus;this.PostEvent( "accepttext")
end on

event dberror;// Open the standard error window, no values can be passed from this level
// any information displayed apart from error text will have to be defined
// at the child level

error.text = sqlerrtext
error.number = sqldbcode

//
// Scroll to the row causing the error, if it is in the visible, PRIMARY!, buffer
//
If buffer = PRIMARY! Then
	this.ScrollToRow( row)
	this.SetFocus()
End If

// Do Not process message any further
Return 1
end event

