File: u_dw.sru
Size: 11303
Date: Mon, 07 Apr 2008 21:30:50 +0200
$PBExportHeader$u_dw.sru
$PBExportComments$Base Datawindow Object
forward
global type u_dw from datawindow
end type
end forward

global type u_dw from datawindow
integer width = 686
integer height = 400
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
event ke_preopen ( )
event ke_postopen ( )
event ke_resize ( readonly integer newwidth,  readonly integer newheight )
event ke_constructor ( )
event ke_dwmousemove pbm_dwnmousemove
event ke_mousemove pbm_mousemove
event type transaction ke_requesttransaction ( )
event type long ke_insertrow ( )
event type long ke_deleterow ( )
event type long ke_preinsertrow ( )
event type long ke_predeleterow ( )
event type long ke_addrow ( )
event type integer ke_updatespending ( )
event type integer ke_accepttext ( readonly boolean ab_focusonerror )
event type integer ke_linkagevalidate ( )
event type integer ke_update ( readonly boolean ab_accepttext,  readonly boolean ab_resetflags )
event ke_rowchanged ( )
end type
global u_dw u_dw

type variables
Public:
Boolean #AutoCreate = TRUE
boolean #Updateable = TRUE
Boolean #Link
string #LinkMaster
string #MasterColumns
string #DetailColumns
//Size Order
Long #SizeOrder
//Anchoring
Boolean #AnchorTop
Boolean #AnchorLeft
Boolean #AnchorRight
Boolean #AnchorBottom
//Docking
Boolean #Dock
//Dock Padding
Long #DockType, #DockPadTop, #DockPadLeft, #DockPadRight, #DockPadBottom
//Dock control reference
String #Dock_Control_Top, #Dock_Control_Left, #Dock_Control_Right, #Dock_Control_Bottom
Boolean #ResizeObjects

Private:
str_resize istr_resize, istr_attribs[]
long OldWidth, OldHeight
str_dw_linkage istr_link
CONSTANT string LINK_SVC = "n_svc_dw_linkage"
boolean ibIgnoreError
end variables

forward prototypes
public function str_resize of_getresizeattrib ()
public function integer of_setdataobject (readonly string as_dataobjectname)
public subroutine of_resizeobjects (readonly boolean ab_init)
public function long of_retrieve ()
public function long of_retrieve (readonly any aa[20])
public function integer of_settransobject (readonly transaction atr)
public subroutine of_setlink (readonly boolean ab)
public function integer of_linkdetail (ref n_svc_mgr anv_svc, readonly u_dw adw_detail)
public function str_dw_linkage of_getlinkdefinition ()
public function boolean of_islinkmaster ()
public function boolean of_islinkroot ()
public subroutine of_setlinkdefinition (readonly str_dw_linkage astr)
public subroutine of_ignoreerror ()
end prototypes

event ke_preopen();of_SetDataObject(DataObject)
of_ResizeObjects(#ResizeObjects)
of_SetLink(#Link)
end event

event ke_postopen();//post-open
end event

event ke_resize(readonly integer newwidth, readonly integer newheight);n_svc_mgr lnv_svc
n_svc_resize lnv_size

lnv_svc.of_LoadSvc(lnv_size, CSvc.RESIZE)

IF oldwidth = 0 THEN oldwidth = newwidth
IF oldheight = 0 THEN oldheight = newheight

lnv_size.of_resize(this, istr_attribs, oldwidth, oldheight, newwidth, newheight)    
   
oldwidth = newwidth
oldheight = newheight   

IF oldwidth = 0 THEN oldwidth = newwidth
IF oldheight = 0 THEN oldheight = newheight
end event

event ke_constructor();IF #AutoCreate THEN
   EVENT ke_preopen()
   EVENT POST ke_postopen()
END IF
end event

event type transaction ke_requesttransaction();RETURN SQLCA
end event

event type long ke_insertrow();IF EVENT ke_PreInsertRow() <> CRet.SUCCESS THEN RETURN CRet.FAILURE

IF #Link THEN
   n_svc_mgr lnv_svc
   n_svc_dw_linkage lnv_dw
   long ll_row, ll_ret

   ll_row = GetRow()
   
   IF ll_row <= 0 OR ISNULL(ll_row) THEN ll_row = 0
   
   ll_row = InsertRow(ll_row)
   
   lnv_svc.of_LoadSvc(lnv_dw, LINK_SVC)
   ll_ret = lnv_dw.of_InsertRow(lnv_svc, istr_link, ll_row)
   IF ll_ret  <> CRet.SUCCESS THEN
      RETURN ll_ret
   ELSE
      RETURN ll_row
   END IF
ELSE
   RETURN CRet.SUCCESS
END IF
end event

event type long ke_deleterow();IF EVENT ke_PreDeleteRow() <> CRet.SUCCESS THEN RETURN CRet.FAILURE

RETURN DeleteRow(GetRow())
end event

event type long ke_preinsertrow();IF #Link THEN
   n_svc_mgr lnv_svc
   n_svc_dw_linkage lnv_dw
   integer li_ret
   
   lnv_svc.of_LoadSvc(lnv_dw, LINK_SVC)
   li_ret = lnv_dw.of_PreInsertRow(lnv_svc, istr_link)
   
   IF li_ret <> CRet.CONTINUE_ACTION THEN RETURN li_ret
END IF

RETURN CRet.SUCCESS
end event

event type long ke_predeleterow();RETURN CRet.SUCCESS
end event

event type long ke_addrow();IF EVENT ke_PreInsertRow() <> CRet.SUCCESS THEN RETURN CRet.FAILURE

IF #Link THEN
   n_svc_mgr lnv_svc
   n_svc_dw_linkage lnv_dw
   long ll_row, ll_ret

   ll_row = InsertRow(0)
   
   lnv_svc.of_LoadSvc(lnv_dw, LINK_SVC)
   ll_ret = lnv_dw.of_InsertRow(lnv_svc, istr_link, ll_row)
   IF ll_ret  <> CRet.SUCCESS THEN
      RETURN ll_ret
   ELSE
      RETURN ll_row
   END IF
ELSE
   RETURN CRet.SUCCESS
END IF
end event

event type integer ke_updatespending();IF NOT #Updateable THEN RETURN 0

IF (ModifiedCount() + DeletedCount()) > 0 THEN
   RETURN 1
ELSE
   RETURN 0
END IF
end event

event type integer ke_accepttext(readonly boolean ab_focusonerror);integer li_rc

// Do not perform AcceptText on Datawidows found on uncreated tab pages.
IF this.RowCount() + this.FilteredCount() + &
   this.ModifiedCount() + this.DeletedCount() <= 0 THEN
   RETURN CRet.SUCCESS
END IF
   
// Perform AcceptText, check rc
li_rc = this.AcceptText()
IF li_rc < 0 THEN 
   IF ab_FocusOnError THEN this.SetFocus()
   RETURN CRet.FAILURE
END IF

RETURN CRet.SUCCESS
end event

event ke_linkagevalidate;RETURN CRet.SUCCESS
end event

event type integer ke_update(readonly boolean ab_accepttext, readonly boolean ab_resetflags);RETURN CRet.SUCCESS
end event

event ke_rowchanged();//fire when rowdata moves
//TODO 
end event

public function str_resize of_getresizeattrib ();istr_resize.Control = this
istr_resize.ControlName = ClassName(this)
istr_resize.SizeOrder = #SizeOrder
istr_resize.SizeOrder = #SizeOrder
istr_resize.Dock = #Dock
istr_resize.DockType = #DockType
istr_resize.DockPadTop = #DockPadTop
istr_resize.DockPadLeft = #DockPadLeft
istr_resize.DockPadRight = #DockPadRight
istr_resize.DockPadBottom = #DockPadBottom
istr_resize.AnchorTop = #AnchorTop
istr_resize.AnchorLeft = #AnchorLeft
istr_resize.AnchorRight = #Anchorright
istr_resize.AnchorBottom = #Anchorbottom
istr_resize.reftop = #Dock_Control_top
istr_resize.refleft = #Dock_Control_left
istr_resize.refright = #Dock_Control_right
istr_resize.refbottom = #Dock_Control_bottom
istr_resize.bounds.left = X
istr_resize.bounds.top = Y
istr_resize.bounds.right = width
istr_resize.bounds.bottom = height

RETURN istr_resize
end function

public function integer of_setdataobject (readonly string as_dataobjectname);n_svc_mgr lnv_svc
n_svc_isempty lnv_check

lnv_Svc.of_LoadSvc(lnv_check, CSvc.ISEMPTY)

IF lnv_check.of_IsEmpty(as_dataobjectname) THEN RETURN CRet.FAILURE

n_svc_dw_in_database lnv_db

//load from database
lnv_svc.of_LoadSvc(lnv_db, "n_svc_dw_in_database")
IF NOT lnv_db.of_createfromdatabase(this, as_dataobjectname, EVENT ke_requesttransaction()) THEN
   //assign from library
   this.DataObject = as_dataobjectname
END IF

TRY
   //try accessing a property to 
   //see if Dataobject is valid
   this.object.Datawindow.Syntax
CATCH (RuntimeError ex)
   MessageBox(ClassName(this) + " - of_SetDataobject", "The dataobject '" + &
            as_dataobjectname + "' is invalid or does not exist.", &
            Exclamation!)
   RETURN CRet.FAILURE
END TRY

RETURN CRet.SUCCESS
end function

public subroutine of_resizeobjects (readonly boolean ab_init);n_svc_mgr lnv_svc
n_svc_resize lnv_size

#ResizeObjects = ab_init

IF ab_init THEN
   lnv_svc.of_LoadSvc(lnv_size, CSvc.RESIZE)
   lnv_size.of_initresize(lnv_svc, this, istr_attribs)
END IF

this.TriggerEvent("resize")
end subroutine

public function long of_retrieve ();RETURN Retrieve()
end function

public function long of_retrieve (readonly any aa[20]);RETURN Retrieve(aa[1], aa[2], aa[3], aa[4], aa[5], aa[6], aa[7], aa[8], aa[9], aa[10]&
                  , aa[11], aa[12], aa[13], aa[14], aa[15], aa[16], aa[17], aa[18], aa[19], aa[20])
end function

public function integer of_settransobject (readonly transaction atr);RETURN SetTransObject(atr)
end function

public subroutine of_setlink (readonly boolean ab);IF ab AND NOT ISVALID(istr_link.dw_requestor) THEN
   n_svc_mgr lnv_svc
   n_svc_dw_linkage lnv_link
   
   lnv_svc.of_LoadSvc(lnv_link, LINK_SVC)
   lnv_link.of_setlink(lnv_svc, this, istr_link)
END IF

#Link = ab
end subroutine

public function integer of_linkdetail (ref n_svc_mgr anv_svc, readonly u_dw adw_detail);IF NOT #Link THEN RETURN CRet.FAILURE

n_svc_dw_linkage lnv_link

anv_svc.of_LoadSvc(lnv_link, LINK_SVC)
RETURN lnv_link.of_LinkDetail(anv_svc, adw_detail, istr_link)
end function

public function str_dw_linkage of_getlinkdefinition ();RETURN istr_link
end function

public function boolean of_islinkmaster ();IF NOT #Link THEN RETURN FALSE
RETURN UPPERBOUND(istr_link.dw_detail) > 0
end function

public function boolean of_islinkroot ();IF NOT of_IsLinkMaster() THEN RETURN FALSE
RETURN (NOT ISVALID(istr_link.dw_master)) OR ISNULL(istr_link.dw_master)
end function

public subroutine of_setlinkdefinition (readonly str_dw_linkage astr);istr_link = astr
end subroutine

public subroutine of_ignoreerror ();ibIgnoreError = TRUE
end subroutine

on u_dw.create
end on

on u_dw.destroy
end on

event resize;IF #ResizeObjects THEN
   //ignore minimize
   IF sizetype = 1 THEN RETURN

   //ensure values
   newwidth = this.Width
   newheight = this.Height

   EVENT ke_resize(newwidth, newheight)
END IF
end event

event itemfocuschanged;IF #Link THEN
   string ls_col
   
   IF NOT ISVALID(dwo) OR ISNULL(dwo) THEN RETURN
   
   ls_col = STRING(dwo.Name)
   
   n_svc_mgr lnv_svc
   n_svc_dw_linkage lnv_dw
   
   lnv_svc.of_LoadSvc(lnv_dw, LINK_SVC)
   lnv_dw.of_ItemFocusChanged(lnv_svc, istr_link, row, ls_col)
   
   DoPosts()
END IF
end event

event itemchanged;IF #Link THEN
   n_svc_mgr lnv_svc
   n_svc_dw_linkage lnv_dw
   
   IF NOT ISVALID(dwo) OR ISNULL(dwo) THEN RETURN
   
   lnv_svc.of_LoadSvc(lnv_dw, LINK_SVC)
   lnv_dw.of_ItemChanged(lnv_svc, istr_link, row, STRING(dwo.Name), data)
END IF
end event

event retrievestart;IF #Link THEN
   n_svc_mgr lnv_svc
   n_svc_dw_linkage lnv_dw

   lnv_svc.of_LoadSvc(lnv_dw, LINK_SVC)
   lnv_dw.of_RetrieveStart(istr_link)
END IF
end event

event retrieveend;IF #Link THEN
   n_svc_mgr lnv_svc
   n_svc_dw_linkage lnv_dw

   lnv_svc.of_LoadSvc(lnv_dw, LINK_SVC)
   lnv_dw.of_RetrieveEnd(lnv_svc, istr_link, rowcount)
END IF
end event

event rowfocuschanged;IF #Link THEN
   n_svc_mgr lnv_svc
   n_svc_dw_linkage lnv_dw

   lnv_svc.of_LoadSvc(lnv_dw, LINK_SVC)
   lnv_dw.of_RowFocusChanged(lnv_svc, istr_link, currentrow)
END IF
end event

event rowfocuschanging;IF #Link THEN
   n_svc_mgr lnv_svc
   n_svc_dw_linkage lnv_dw

   lnv_svc.of_LoadSvc(lnv_dw, LINK_SVC)
   IF lnv_dw.of_RowFocusChanging(lnv_svc, istr_link, currentrow, newrow) <> CRet.CONTINUE_ACTION THEN
      //prevent rowfocuschange
      RETURN 1
   END IF
END IF
end event

event itemerror;IF ibIgnoreError THEN 
   ibIgnoreError = FALSE
   RETURN 1
END IF
end event