REM > JLibraries:Object.2
REM © James Bursa, 1997

REM JB  16 Nov 1997     created
REM JB  29 Nov 1997     sets <task$Objects>
REM JB  06 Dec 1997     optimised to grab memory in chunks of 16 objects
REM JB  07 Dec 1997     speeded up FNObject_Hand by reversing search

REM Object types
REM ~~~~~~~~~~~~
REM 0   windows
REM 1   icons
REM 2   menus
REM 3   menu items
REM 4   named heap blocks
REM 5   messages files
REM 6   sprite areas


DEF PROCObject_Init
LOCAL Task_ObjsB%

Task_Objs%    = FNHeap_Alloc(8 + 24 * 16)
IF Task_Objs% = 0 THEN ERROR Erro_Memo%, ""
Task_ObjsB%   = !Task_Objs%

Task_ObjsB%!00 = 0
Task_ObjsB%!04 = 16

 IF Task_ThrowBack% THEN
  @% = "+g20.20"
  OSCLI"SetEval " + Task_Name$ + "$Objects " + STR$Task_Objs%
  OSCLI"SetEval " + Task_Name$ + "$Handle " + STR$Task_Hand%
 ENDIF
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCObject_Add(Type%, Hand%, Word%, Name$)
LOCAL Objs%, Spac%

Task_ObjsB% = !Task_Objs%
Objs% = Task_ObjsB%!00
Spac% = Task_ObjsB%!04

 IF Objs% = Spac% THEN
  IF FNHeap_ReAlloc(Task_Objs%, 8 + 24 * (Spac% + 16)) = 0 THEN ERROR Erro_Memo%, ""
  Task_ObjsB% = !Task_Objs%
  Task_ObjsB%!04 += 16
 ENDIF

Task_ObjsB%!(8 + 24 * Objs% + 00) = Type%
Task_ObjsB%!(8 + 24 * Objs% + 04) = Hand%
Task_ObjsB%!(8 + 24 * Objs% + 08) = Word%
$(Task_ObjsB% + 8 + 24 * Objs% + 12) = LEFT$(Name$, 11)

Task_ObjsB%!00 = Objs% + 1

ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF FNObject_Name(Type%, Hand%, Word%)
LOCAL Objs%, Loop%

Task_ObjsB% = !Task_Objs%
Objs% = Task_ObjsB%!00

 IF Objs% THEN
   FOR Loop% = 0 TO (Objs% - 1)
     IF Task_ObjsB%!(8 + 24 * Loop% + 04) = Hand% THEN
       IF Task_ObjsB%!(8 + 24 * Loop% + 00) = Type% THEN
        IF Task_ObjsB%!(8 + 24 * Loop% + 08) = Word% THEN =$(Task_ObjsB% + 8 + 24 * Loop% + 12)
       ENDIF
     ENDIF
   NEXT
 ENDIF

="None"

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF FNObject_Hand(Type%, Name$, Word%)
LOCAL Objs%, Loop%, Obje%

Task_ObjsB% = !Task_Objs%
Objs% = Task_ObjsB%!00
IF Objs% = 0 THEN =&7FFFFFFF
Obje% = Task_ObjsB% + 8 + 24 * (Objs% - 1)

 FOR Loop% = 0 TO (Objs% - 1)
  IF !Obje% = Type% THEN IF Obje%!8 = Word% THEN IF $(Obje% + 12) = Name$ THEN =Obje%!4
  Obje% -= 24
 NEXT

=&7FFFFFFF

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF FNObject_Find(Type%, Word%)
LOCAL Objs%, Loop%

Task_ObjsB% = !Task_Objs%
Objs% = Task_ObjsB%!00

 IF Objs% THEN
   FOR Loop% = 0 TO (Objs% - 1)
     IF Task_ObjsB%!(8 + 24 * Loop% + 00) = Type% THEN
      IF Task_ObjsB%!(8 + 24 * Loop% + 08) = Word% THEN =Task_ObjsB%!(8 + 24 * Loop% + 04)
     ENDIF
   NEXT
 ENDIF

=&7FFFFFFF

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCObject_Remove(Type%, Hand%, Word%)
LOCAL Objs%, Loop%

Task_ObjsB% = !Task_Objs%
Objs% = Task_ObjsB%!00
Loop% = -1
 REPEAT
  Loop% += 1
  IF Loop% > Objs% THEN ERROR 1,"ObjectRemove:NotFound"
 UNTIL (Task_ObjsB%!(8 + 24 * Loop% + 00) = Type%) AND (Task_ObjsB%!(8 + 24 * Loop% + 04) = Hand%) AND (Task_ObjsB%!(8 + 24 * Loop% + 08) = Word%)

SYS"WimpExt_MemCopy", Task_ObjsB% + 8 + 24 * Loop% + 24, Task_ObjsB% + 8 + 24 * Loop%, ((Objs% - Loop%) - 1) * 24
Task_ObjsB%!00 -= 1
Task_ObjsB%!04 = Task_ObjsB%!00
IF FNHeap_ReAlloc(Task_Objs%, 8 + 24 * (Objs% - 1))
ENDPROC
