REM > JLibraries:Wind.5
REM © James Bursa, 1997

REM JB  17 Nov 1997     created
REM JB  19 Nov 1997     windows referenced by name instead of handle
REM JB  26 Nov 1997     removed obsolete PROCWind_Open
REM JB  27 Nov 1997     corrected conversion of handles to names
REM JB  27 Nov 1997     added PROCWind_PutCaret
REM JB  29 Nov 1997     added PROCWind_SetFocus
REM JB  06 Dec 1997     added PROCWind_IconSele
REM JB  21 Dec 1997     corrected FNWind_Open to return bool
REM JB  03 Apr 1998     added PROCWind_SetTitle
REM JB  24 Apr 1998     added PROCWind_SetVal


DEF PROCWind_OpenPointer(Wind$)
LOCAL XPos%, YPos%, XOff%, YOff%

SYS"Wimp_GetPointerInfo",, B% + 400
XPos% = B%!400
YPos% = B%!404

B%!400 = FNObject_Hand(0, Wind$, 0)
SYS"Wimp_GetWindowState",, B% + 400

XOff% = B%!404 - B%!412
YOff% = B%!408 - B%!416
PROCWind_OpenUp(Wind$, XPos% + XOff% / 2, YPos% + YOff% / 2, -1)

ENDPROC

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

DEF PROCWind_PopOpen(Wind$)
B%!400 = FNObject_Hand(0, Wind$, 0)
SYS"Wimp_GetWindowState",, B% + 400
B%!428 = -1
SYS"WimpExt_OpenLinked",, B% + 400
ENDPROC

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

DEF PROCWind_Close(Wind$)
B%!400 = FNObject_Hand(0, Wind$, 0)
SYS"WimpExt_CloseLinked",, B% + 400
ENDPROC

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

DEF PROCWind_Origin(Wind$, RETURN XPos%, RETURN YPos%)
B%!400 = FNObject_Hand(0, Wind$, 0)
SYS"Wimp_GetWindowState",, B% + 400
XPos% = B%!404 - B%!420
YPos% = B%!416 - B%!424
ENDPROC

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

DEF FNWind_Open(Wind$)
LOCAL Open%

SYS"WimpExt_CheckWindowOpen", FNObject_Hand(0, Wind$, 0) TO Open%
=(Open% = 1)

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

DEF PROCWind_ForceRedraw(Wind$)
LOCAL Wind%

Wind% = FNObject_Hand(0, Wind$, 0)
B%!400 = Wind%
SYS"Wimp_GetWindowInfo",, (B% + 400) OR 1
SYS"Wimp_ForceRedraw", Wind%, B%!444, B%!448, B%!452, B%!456
ENDPROC

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

DEF PROCWind_OpenUp(Wind$, XPos%, YPos%, Open%)
LOCAL XOff%, YOff%

B%!400 = FNObject_Hand(0, Wind$, 0)
SYS"Wimp_GetWindowState",, B% + 400
XOff% = B%!412 - B%!404
YOff% = B%!416 - B%!408
B%!404 = XPos%
B%!408 = YPos%
B%!412 = XPos% + XOff%
B%!416 = YPos% + YOff%
B%!428 = Open%
SYS"WimpExt_OpenLinked",, B% + 400
ENDPROC

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

DEF PROCWind_Load(Name$, Sprt%)
LOCAL Size%, IndS%, Find%, Buff%, Indi%, Icon%, Wind%, Temp%, Icon$

SYS"Wimp_LoadTemplate",, 0,,,, Name$, 0 TO , Size%, IndS%,,,, Find%
IF Find% = 0 THEN ERROR 1, "Wind_Load:'"+Name$+"'NotFound"

Buff%    = FNHeap_Alloc(Size%)
IF Buff% = 0 THEN ERROR Erro_Memo%, "Mem"
BuffB%   = !Buff%
DIM Indi% IndS%

SYS"Wimp_LoadTemplate",, BuffB%, Indi%, Indi% + IndS%, -1, Name$, 0
BuffB%!64 = Sprt%
SYS"WimpExt_RedirectSprites", Sprt%, BuffB%
SYS"Wimp_CreateWindow",, BuffB% TO Wind%
PROCObject_Add(0, Wind%, 0, Name$)

@% = "+g20.255"

 IF BuffB%!84 > 0 THEN
   FOR Icon% = 1 TO BuffB%!84
    Icon$ = STR$(Icon% - 1)
     IF (BuffB%!(88 + (Icon% - 1) * 32 + 16) AND %100000001) = %100000001 THEN
       IF BuffB%!(88 + (Icon% - 1) * 32 + 24) = -1 THEN
        Vali$ = ""
       ELSE
        Vali$ = FNWimp_GetString(BuffB%!(88 + (Icon% - 1) * 32 + 24))
       ENDIF
      Temp% = INSTR(Vali$, ";=")
      IF Temp% <> 0 THEN Temp% += 2
      IF (Temp% = 0) AND (LEFT$(Vali$, 1) = "=") THEN Temp% = 2
       IF Temp% <> 0 THEN
        Icon$ = MID$(Vali$, Temp%)
        Temp% = INSTR(Icon$, ";")
         IF Temp% <> 0 THEN
          Icon$ = LEFT$(Icon$, Temp% - 1)
         ENDIF
       ENDIF
     ENDIF
    PROCObject_Add(1, Icon% - 1, Wind%, Icon$)
   NEXT
 ENDIF

PROCHeap_Free(Buff%)
ENDPROC

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

DEF PROCWind_UpdateIcon(Wind$, Icon$)
B%!400 = FNObject_Hand(0, Wind$, 0)
B%!404 = FNObject_Hand(1, Icon$, B%!400)
B%!408 = 0
B%!412 = 0
SYS"Wimp_SetIconState",, B% + 400
ENDPROC

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

DEF PROCWind_HideIcon(Wind$, Icon$)
B%!400 = FNObject_Hand(0, Wind$, 0)
B%!404 = FNObject_Hand(1, Icon$, B%!400)
B%!408 = &00800080
B%!412 = &00800080
SYS"Wimp_SetIconState",, B% + 400
ENDPROC

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

DEF PROCWind_ShowIcon(Wind$, Icon$)
B%!400 = FNObject_Hand(0, Wind$, 0)
B%!404 = FNObject_Hand(1, Icon$, B%!400)
B%!408 = &00000000
B%!412 = &00800080
SYS"Wimp_SetIconState",, B% + 400
ENDPROC

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

DEF FNWind_Title(Wind$)
B%!400 = FNObject_Hand(0, Wind$, 0)
SYS"Wimp_GetWindowInfo",, B% + 401
=FNWimp_GetString(B%!476)

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

DEF FNWind_GetIcon(Wind$, Icon$)
LOCAL Sele%, Wind%
Wind% = FNObject_Hand(0, Wind$, 0)
SYS"WimpExt_GetIcon",,, Wind%, FNObject_Hand(1, Icon$, Wind%) TO Sele%
=(Sele% = 1)

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

DEF PROCWind_OpenC(Wind$)
B%!400 = FNObject_Hand(0, Wind$, 0)
SYS"Wimp_GetWindowState",, B% + 400
B%!428 = -1
SYS"WimpExt_CentreWindow",, B% + 404
SYS"WimpExt_CentreWindowV",, B% + 404
SYS"WimpExt_OpenLinked",, B% + 400
ENDPROC

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

DEF FNWind_GetText(Wind$, Icon$)
B%!400 = FNObject_Hand(0, Wind$, 0)
B%!404 = FNObject_Hand(1, Icon$, B%!400)
SYS"Wimp_GetIconState",, B% + 400
IF B%!424 AND (1<<8) THEN =FNWimp_GetString(B%!428)
=FNWimp_GetString(B% + 428)

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

DEF PROCWind_SetText(Wind$, Icon$, Text$)
LOCAL Wind%
Wind% = FNObject_Hand(0, Wind$, 0)
SYS"WimpExt_SetIconString",,, Wind%, FNObject_Hand(1, Icon$, Wind%), Text$
ENDPROC

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

DEF PROCWind_IconGrey(Wind$, Icon$, Grey%)
LOCAL Wind%, Icon%
Wind% = FNObject_Hand(0, Wind$, 0)
Icon% = FNObject_Hand(1, Icon$, Wind%)
SYS"WimpExt_ShadeIcon",,, Wind%, Icon%, Grey%
ENDPROC

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

DEF PROCWind_PutCaret(Wind$, Icon$)
LOCAL Wind%
Wind% = FNObject_Hand(0, Wind$, 0)
SYS"WimpExt_PutCaretIcon",,, Wind%, FNObject_Hand(1, Icon$, Wind%)
ENDPROC

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

DEF PROCWind_SetFocus(Wind$)
SYS"Wimp_SetCaretPosition", FNObject_Hand(0, Wind$, 0), -1,,, 1 << 25, -1
ENDPROC

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

DEF PROCWind_IconSele(Wind$, Icon$, Sele%)
LOCAL Wind%
Wind% = FNObject_Hand(0, Wind$, 0)
SYS"WimpExt_SetIcon",,, Wind%, FNObject_Hand(1, Icon$, Wind%), Sele%
ENDPROC

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

DEF PROCWind_SetTitle(Wind$, Text$)
LOCAL Wind%
Wind% = FNObject_Hand(0, Wind$, 0)
SYS"WimpExt_SetWindowTitle",,, Wind%, Text$
ENDPROC

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

DEF PROCWind_SetVal(Wind$, Icon$, Text$)
LOCAL Wind%, Icon%
Wind% = FNObject_Hand(0, Wind$, 0)
Icon% = FNObject_Hand(1, Icon$, Wind%)
B%!400 = Wind%
B%!404 = Icon%
SYS"Wimp_GetIconState",, B% + 400
$(B%!432) = Text$
PROCWind_UpdateIcon(Wind$, Icon$)
ENDPROC