File: n_explorer_navigator.sru
Size: 6212
Date: Mon, 07 Apr 2008 21:32:48 +0200
$PBExportHeader$n_explorer_navigator.sru
$PBExportComments$Explorer Tree Navigator
forward
global type n_explorer_navigator from n_base
end type
end forward

global type n_explorer_navigator from n_base
event ke_back ( )
event ke_forward ( )
event ke_menutrigger ( )
end type
global n_explorer_navigator n_explorer_navigator

type variables
Public:

CONSTANT string NAV_BACK = "B"
CONSTANT string NAV_FORWARD = "F"
CONSTANT string NAV_JUMP = "J"

Protected:

u_tv itv

integer ii_back[], ii_forward[], ii_jumpindex
integer MAXLIST = 9
string NAV
Boolean JUMP_BACK
end variables

forward prototypes
public subroutine of_setmaxlist (integer ai_max)
public function integer of_getforwardcount ()
public subroutine of_popmenuback (integer px, integer py)
public subroutine of_popmenuforward (integer px, integer py)
public function integer of_getbackcount ()
protected subroutine of_popmenu (integer ai_items[], integer px, integer py)
public subroutine of_selectionchanged (long oldhandle, long newhandle)
public subroutine of_register (readonly treeview a_tv)
end prototypes

event ke_back();NAV = NAV_BACK
IF UPPERBOUND(ii_back) > 0 THEN itv.SelectItem(ii_back[1])
end event

event ke_forward();NAV = NAV_FORWARD
IF UPPERBOUND(ii_forward) > 0 THEN itv.SelectItem(ii_forward[1])
end event

event ke_menutrigger();integer li_tmp[]

NAV = NAV_JUMP

IF JUMP_BACK THEN
   li_tmp = ii_back
ELSE
   li_tmp = ii_forward
END IF

ii_jumpindex = INTEGER(STRING(Message.LongParm, "address"))

itv.SelectItem(li_tmp[ii_jumpindex])
end event

public subroutine of_setmaxlist (integer ai_max);MAXLIST = ai_max
end subroutine

public function integer of_getforwardcount ();RETURN UPPERBOUND(ii_forward)
end function

public subroutine of_popmenuback (integer px, integer py);JUMP_BACK = TRUE
this.of_popmenu(ii_back, px, py)
end subroutine

public subroutine of_popmenuforward (integer px, integer py);JUMP_BACK = FALSE
this.of_popmenu(ii_forward, px, py)
end subroutine

public function integer of_getbackcount ();RETURN UPPERBOUND(ii_back)
end function

protected subroutine of_popmenu (integer ai_items[], integer px, integer py);long ll_upper, n, ll_items
integer li_tmp[]
treeviewitem ltvi
n_svc_menu lnv_m
n_svc_mgr lnv_svc
str_menuitem lstr[]

li_tmp = ai_items

ll_upper = UPPERBOUND(li_tmp)

IF ll_upper > 0 THEN
   
   lnv_svc.of_LoadSvc(lnv_m, CSvc.MENU)
   
   FOR n = 1 to ll_upper
      itv.GetItem(li_tmp[n], ltvi)
      lstr[n].subscriber = this
      lstr[n].eventname = "ke_menutrigger"
      lstr[n].menutext = ltvi.Label
      lstr[n].data = STRING(n) //array index
   NEXT

   lnv_m.of_createmenu(lstr, px, py)
END IF
end subroutine

public subroutine of_selectionchanged (long oldhandle, long newhandle);treeviewitem ltvi_old, ltvi_new

IF NOT ISVALID(itv) THEN RETURN

itv.GetItem(oldhandle, ltvi_old)
itv.GetItem(newhandle, ltvi_new)

integer li_tmp[], li_empty[], c, li_jump, li_holder1[], li_holder2[]
long n, ll_upper

CHOOSE CASE NAV
   CASE NAV_BACK, NAV_FORWARD
      
      IF NAV = NAV_BACK THEN
         li_holder1 = ii_forward
         li_holder2 = ii_back       
      ELSE
         li_holder1 = ii_back
         li_holder2 = ii_forward
      END IF
      
      ll_upper = UPPERBOUND(li_holder1)
      //create new 
      //get previous item
      li_tmp[1] = ltvi_old.itemhandle
      FOR n = 1 to ll_upper
         li_tmp[n + 1] = li_holder1[n]
      NEXT
      li_holder1 = li_empty
      li_holder1 = li_tmp
      //remove top 
      li_tmp = li_empty
      ll_upper = UPPERBOUND(li_holder2)
      FOR n = 2 to ll_upper
         li_tmp[n - 1] = li_holder2[n]
      NEXT
      li_holder2 = li_empty
      li_holder2 = li_tmp     
      
      ii_back = li_empty
      ii_forward = li_empty
      
      IF NAV = NAV_BACK THEN
         ii_forward = li_holder1
         ii_back = li_holder2
      ELSE
         ii_back = li_holder1
         ii_forward = li_holder2
      END IF      
   CASE NAV_JUMP
      IF JUMP_BACK THEN
         //create new forward from back
         li_jump = ii_jumpindex - 1
         FOR n = li_jump to 0 STEP -1
            IF n = 0 THEN EXIT
            c++
            li_tmp[c] = ii_back[n]
         NEXT
         //now add prev forwards
         ll_upper = UPPERBOUND(ii_forward)
         FOR n = 1 to ll_upper
            c++
            li_tmp[c] = ii_forward[n]
         NEXT
         //add last selected
         ll_upper = UPPERBOUND(li_tmp)
         li_tmp[ll_upper + 1] = ltvi_old.itemhandle

         ii_forward = li_empty
         ii_forward = li_tmp

         li_tmp = li_empty
         c = 0
         //create new back
         ll_upper = UPPERBOUND(ii_back)
         li_jump = ii_jumpindex + 1
         FOR n = li_jump to ll_upper
            c++
            li_tmp[c] = ii_back[n]
         NEXT
         ii_back = li_empty
         ii_back = li_tmp
         
      ELSE
         //create new back from forward
         li_jump = ii_jumpindex - 1
         FOR n = li_jump to 0 STEP -1
            IF n = 0 THEN EXIT
            c++
            li_tmp[c] = ii_forward[n]
         NEXT
         c++
         //add last selected
         ll_upper = UPPERBOUND(li_tmp)
         li_tmp[c] = ltvi_old.itemhandle
         //now add prev back
         ll_upper = UPPERBOUND(ii_back)
         FOR n = 1 to ll_upper
            c++
            li_tmp[c] = ii_back[n]
         NEXT
         
         ii_back = li_empty
         ii_back = li_tmp

         li_tmp = li_empty
         c = 0
         //create new back
         ll_upper = UPPERBOUND(ii_forward)
         li_jump = ii_jumpindex + 1
         FOR n = li_jump to ll_upper
            c++
            li_tmp[c] = ii_forward[n]
         NEXT
         ii_forward = li_empty
         ii_forward = li_tmp
      END IF
   CASE ELSE
      //populate back array
      IF oldhandle > 0 THEN
         ll_upper = UPPERBOUND(ii_back)
         ll_upper ++
         FOR n = 1 to ll_upper
            IF n = 1 THEN 
               li_tmp[n] = ltvi_old.itemhandle
            ELSE
               li_tmp[n] = ii_back[n - 1]
            END IF
         NEXT
         ii_back = li_empty
         ii_back = li_tmp
         //reset forward array
         ii_forward = li_empty
         
         //trim array to max list
         ll_upper = UPPERBOUND(ii_back)
         IF ll_upper > MAXLIST THEN          
            li_tmp = li_empty
            FOR n = 1 to MAXLIST
               li_tmp[n] = ii_back[n]
            NEXT
            ii_back = li_empty
            ii_back = li_tmp           
         END IF
      END IF
END CHOOSE

//reset nav
NAV = ""
end subroutine

public subroutine of_register (readonly treeview a_tv);itv = a_tv
end subroutine

on n_explorer_navigator.create
call super::create
end on

on n_explorer_navigator.destroy
call super::destroy
end on