File: n_svc_powerbuilder.sru
Size: 7429
Date: Mon, 07 Apr 2008 21:31:24 +0200
$PBExportHeader$n_svc_powerbuilder.sru
$PBExportComments$Powerbuilder Helper Service
forward
global type n_svc_powerbuilder from n_svc_base
end type
end forward

global type n_svc_powerbuilder from n_svc_base
end type
global n_svc_powerbuilder n_svc_powerbuilder

forward prototypes
public function boolean of_isdescendant (readonly string ancestor, readonly string cls)
public subroutine of_pixelstounits (ref long al_x, ref long al_y)
public subroutine of_unitstopixels (ref long al_x, ref long al_y)
public function boolean of_isvalidclass (readonly string as_classname)
public function boolean of_isdescendant (string as_ancestor, readonly classdefinition acd)
public function boolean of_isfcobject (readonly powerobject apo)
public function long of_getwindowobjects (powerobject apo, ref windowobject awo[])
public function boolean of_hasevent (readonly powerobject apo, readonly string as_eventname, readonly string as_args[])
public function boolean of_hasevent (readonly powerobject apo, readonly string as_eventname)
public function boolean of_hasfunction (readonly powerobject apo, readonly string as_functionname, readonly string as_args[])
public function boolean of_hasfunction (readonly powerobject apo, readonly string as_functionname)
end prototypes

public function boolean of_isdescendant (readonly string ancestor, readonly string cls);ClassDefinition CD
Boolean lb_ancestor, lb_ret

TRY
   IF NOT of_isvalidclass(cls) THEN RETURN FALSE
   CD = FindClassDefinition(lower(cls))
   IF NOT ISVALID(CD) THEN RETURN FALSE
   lb_ret = of_isdescendant(ancestor, CD)
CATCH (runtimeerror err)
   lb_ret = FALSE
END TRY

RETURN lb_ret
end function

public subroutine of_pixelstounits (ref long al_x, ref long al_y);al_x = PixelsToUnits(al_x, XPixelsToUnits!)
al_y = PixelsToUnits(al_y, YPixelsToUnits!)
end subroutine

public subroutine of_unitstopixels (ref long al_x, ref long al_y);al_x = UnitsToPixels(al_x, XUnitsToPixels!)
al_y = UnitsToPixels(al_y, YUnitsToPixels!)
end subroutine

public function boolean of_isvalidclass (readonly string as_classname);ClassDefinition CD

CD = FindClassDefinition(lower(as_classname))

RETURN NOT ISNULL(CD)
end function

public function boolean of_isdescendant (string as_ancestor, readonly classdefinition acd);ClassDefinition CDa
Boolean lb_ancestor, lb_ret

IF NOT ISVALID(acd) THEN RETURN FALSE

as_ancestor = lower(as_ancestor)
IF as_ancestor = acd.name THEN RETURN TRUE

TRY
   CDa = acd.ancestor
   DO
      IF ISNULL(CDa) THEN RETURN FALSE
      IF CDa.name =  as_ancestor THEN
         lb_ret = TRUE
         EXIT
      ELSE
         CDa = CDa.ancestor
      END IF
   LOOP WHILE 1 = 1  
CATCH (runtimeerror err)
   lb_ret = FALSE
END TRY

RETURN lb_ret
end function

public function boolean of_isfcobject (readonly powerobject apo);boolean lb
string lsc

IF ISNULL(apo) THEN RETURN FALSE

CHOOSE CASE apo.TypeOf()
   CASE CheckBox!
      lsc = Cfbase.CheckBox
   CASE CommandButton!
      lsc = Cfbase.CommandButton
   CASE DropDownListBox!
      lsc = Cfbase.DropdownListBox
   CASE DropDownPictureListBox!
      lsc = Cfbase.DropdownPictureListBox
   CASE Datawindow!
      lsc = Cfbase.Datawindow
   CASE Datastore!
      lsc = Cfbase.Datastore
   CASE EditMask!
      lsc = Cfbase.EditMask
   CASE Graph!
      lsc = Cfbase.Graph
   CASE GroupBox!
      lsc = Cfbase.GroupBox
   CASE HProgressBar!
      lsc = Cfbase.HorizontalProgressBar
   CASE HScrollbar!
      lsc = Cfbase.HorizontalScrollBar
   CASE HTrackbar!
      lsc = Cfbase.HorizontalTrackBar
   CASE ListBox!
      lsc = Cfbase.ListBox
   CASE Listview!
      lsc = Cfbase.Listview
   CASE MultiLineEdit!
      lsc = Cfbase.MultiLineEdit
   CASE Picture!
      lsc = Cfbase.Picture
   CASE PictureListBox!
      lsc = Cfbase.PictureListbox
   CASE PictureHyperLink!
      lsc = Cfbase.PictureHyperlink
   CASE RadioButton!
      lsc = Cfbase.RadioButton
   CASE RichTextEdit!
      lsc = Cfbase.RichTextEdit
   CASE SingleLineEdit!
      lsc = Cfbase.SingleLineEdit
   CASE StaticHyperLink!
      lsc = Cfbase.StaticHyperLink
   CASE StaticText!
      lsc = Cfbase.StaticText
   CASE Tab!
      lsc = Cfbase.Tab
   CASE Treeview!
      lsc = Cfbase.Treeview
   CASE UserObject!
      lsc = Cfbase.Userobject
   CASE VScrollBar!
      lsc = Cfbase.VerticalScrollBar
   CASE VProgressBar!
      lsc = Cfbase.VerticalProgressBar
   CASE VTrackBar!
      lsc = Cfbase.VerticalTrackBar
   CASE Window!
      lsc = Cfbase.WindowBase
   CASE ELSE
      RETURN FALSE
END CHOOSE

TRY
   lb = of_isdescendant(lsc, apo.ClassDefinition)
CATCH (runtimeerror err)
   lb = FALSE
END TRY

RETURN lb
end function

public function long of_getwindowobjects (powerobject apo, ref windowobject awo[]);windowobject lwo[]
window lw_base
userobject lu_base

TRY
   //check if supported parent object
   IF of_isdescendant(CFbase.WindowMain, apo.ClassDefinition) THEN
      //cast
      lw_base = apo
      lwo = lw_base.Control
   ELSEIF of_isdescendant(CFbase.UOContainer, apo.ClassDefinition) THEN
      //cast
      lu_base = apo
      lwo = lu_base.Control
   END IF
CATCH (n_x_svc ex)
   // an exception occurred
END TRY

awo = lwo

RETURN UPPERBOUND(awo)
end function

public function boolean of_hasevent (readonly powerobject apo, readonly string as_eventname, readonly string as_args[]);ClassDefinition lcd
ScriptDefinition lsd
long ll_count, n, ll_argcount, m

IF NOT ISVALID(apo) THEN RETURN FALSE

lcd = apo.ClassDefinition
lsd = lcd.FindMatchingFunction(as_eventname, as_args)

IF ISNULL(lsd) THEN
   //search
   ll_count = UPPERBOUND(lcd.scriptlist)
   FOR n = 1 to ll_count
      IF lcd.scriptlist[n].Name = as_eventname THEN
         IF UPPERBOUND(as_args) = 0 &
            AND UPPERBOUND(lcd.scriptlist[n].ArgumentList) = 0 THEN 
            lsd = lcd.scriptlist[n]
            EXIT
         //does the arg count match?
         ELSEIF UPPERBOUND(as_args) <> UPPERBOUND(lcd.scriptlist[n].ArgumentList)THEN
            CONTINUE
         ELSE
            //check args one by one
            ll_argcount = UPPERBOUND(as_args)
            FOR m = 1 to ll_argcount
               IF as_args[m] <> lcd.scriptlist[n].ArgumentList[m].TypeInfo.DataTypeOf THEN
                  EXIT
               ELSE
                  IF m = ll_argcount THEN RETURN TRUE
               END IF
            NEXT
         END IF
      END IF
   NEXT
END IF

//still null
IF ISNULL(lsd) THEN RETURN FALSE

RETURN lsd.kind = ScriptEvent!
end function

public function boolean of_hasevent (readonly powerobject apo, readonly string as_eventname);string ls_args[]

RETURN of_hasevent(apo, as_eventname, ls_args)
end function

public function boolean of_hasfunction (readonly powerobject apo, readonly string as_functionname, readonly string as_args[]);ClassDefinition lcd
ScriptDefinition lsd
long ll_count, n

IF NOT ISVALID(apo) THEN RETURN FALSE

lcd = apo.ClassDefinition
lsd = lcd.FindMatchingFunction(as_functionname, as_args)

IF ISNULL(lsd) THEN
   //search
   ll_count = UPPERBOUND(lcd.scriptlist)
   FOR n = 1 to ll_count
      IF lcd.scriptlist[n].Name = as_functionname THEN
         IF UPPERBOUND(as_args) = 0 THEN 
            lsd = lcd.scriptlist[n]
            EXIT
         ELSE
            //check for args
         END IF
      END IF
   NEXT
END IF

//still null
IF ISNULL(lsd) THEN RETURN FALSE

RETURN lsd.kind = ScriptFunction!
end function

public function boolean of_hasfunction (readonly powerobject apo, readonly string as_functionname);string ls_args[]

RETURN of_hasfunction(apo, as_functionname, ls_args)
end function

on n_svc_powerbuilder.create
call super::create
end on

on n_svc_powerbuilder.destroy
call super::destroy
end on