REM > JLibraries:Menu.6
REM © James Bursa, 1997, 1998

REM JB  17 Nov 1997     created
REM JB  06 Dec 1997     updates to Mess.2
REM JB  09 Oct 1998     altered PROCMenu_PopUp to use window handle not name


DEF PROCMenu_AttachSub(Menu$, Item$, Subm$)
LOCAL Menu%
Menu% = FNObject_Hand(2, Menu$, 0)
Menu%!(28 + FNObject_Hand(3, Item$, Menu%) * 24 + 4) = FNObject_Hand(2, Subm$, 0)
ENDPROC

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

DEF FNMenu_CountItems(Menu$)
LOCAL Size%, Menu%
Size% = 28
Menu% = FNObject_Hand(2, Menu$, 0)
IF (Menu%!Size%) AND (1 << 7) THEN =1
 REPEAT
  Size% += 24
 UNTIL (Menu%!Size%) AND (1 << 7)
=((Size% - 28) / 24) + 1

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

DEF PROCMenu_IconBar(Menu$)
LOCAL YPos%, Item%, Loop%, Menu%

Menu% = FNObject_Hand(2, Menu$, 0)
SYS"Wimp_GetPointerInfo",, B% + 400

Item% = FNMenu_CountItems(Menu$)
YPos% = Item% * 44
 FOR Loop% = 1 TO Item%
  IF Menu%!(4 + 24 * Loop%) AND 1<<1 THEN YPos% += 24
 NEXT

SYS"Wimp_CreateMenu",, Menu%, B%!400 - (Menu%!16 / 2), YPos% + 96
Menu_Current% = Menu%
Menu_Current$ = Menu$
ENDPROC

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

DEF PROCMenu_Show(Menu$, XPos%, YPos%)
LOCAL Menu%
Menu% = FNObject_Hand(2, Menu$, 0)
SYS"Wimp_CreateMenu",, Menu%, XPos%, YPos%
Menu_Current% = Menu%
Menu_Current$ = Menu$
ENDPROC

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

DEF PROCMenu_Adjust(Menu$)
LOCAL Adju%, Menu%

Menu% = FNObject_Hand(2, Menu$, 0)
SYS"Wimp_GetPointerInfo",, B% + 400
Adju% = (B%!408 AND 1) OR Menu_Open%
IF Adju% = 0 THEN ENDPROC

SYS"Wimp_CreateMenu",, Menu%
Menu_Open% = FALSE

ENDPROC

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

DEF PROCMenu_Window(Wind$)
LOCAL Buff%, BuffB%, XPos%, YPos%, Wind%

Wind% = FNObject_Hand(0, Wind$, 0)

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

B%!400 = Wind%
SYS"Wimp_GetWindowState",, B% + 400
XPos% = XPos% + (B%!404 - B%!412) / 2
YPos% = YPos% - (B%!408 - B%!416) / 2

SYS"Wimp_CreateMenu",, Wind%, XPos%, YPos%

ENDPROC

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

DEF PROCMenu_Make(Menu$, Name$)
LOCAL Itms%, Temp%, Menu%, Item%, Subn%, Item$, Subm$, P%, Flag%

Itms% = 1
Temp% = INSTR(Menu$, ",")
 WHILE Temp% <> 0
  Itms% += 1
  Temp% = INSTR(Menu$, ",", Temp% + 1)
 ENDWHILE

DIM Menu% 28 + 24 * Itms%
P% = Menu%
Temp% = FNMess_Adr(Name$ + "_Titl", File_Menu%)
[OPT 2
EQUD Temp%
EQUD -1
EQUD LEN($Temp%)
EQUD &00070207
EQUD 100
EQUD 44
EQUD 0
]

 FOR Item% = 1 TO Itms%

  Item$ = LEFT$(Menu$, INSTR(Menu$, ",") - 1)
  Flag% = 0
  Subn% = -1
  IF LEFT$(Item$, 1) = "€" THEN Item$ = MID$(Item$, 2): Flag% += (1<<0)
  IF LEFT$(Item$, 1) = "-" THEN Item$ = MID$(Item$, 2): Flag% += (1<<1)
  IF LEFT$(Item$, 1) = "@" THEN Item$ = MID$(Item$, 2): Flag% += (1<<2)
  IF LEFT$(Item$, 1) = "+" THEN Item$ = MID$(Item$, 2): Flag% += (1<<3)
  IF Item% = Itms% THEN Flag% += (1<<7)
  IF Item% = 1     THEN Flag% += (1<<8)
   IF LEFT$(Item$, 1) = ">" THEN
    Item$ = MID$(Item$, 2)
    Subm$ = LEFT$(Item$, INSTR(Item$, "<") - 1)
    Item$ = MID$(Item$, LENSubm$ + 2)
     CASE LEFT$(Subm$, 1) OF
      WHEN "W"
       Subn% = FNObject_Hand(0, MID$(Subm$, 2), 0)
      WHEN "I"
       Subn% = 1
      OTHERWISE
       PROCMenu_Make(FNMess_Lookup(Subm$, File_Menu%), Subm$)
       Subn% = FNObject_Hand(2, Subm$, 0)
     ENDCASE
   ENDIF
  Temp% = FNMess_Adr(Name$ + "_" + Item$, File_Menu%)
  [OPT 2
  EQUD Flag%
  EQUD Subn%
  EQUD &07000111
  EQUD Temp%
  EQUD -1
  EQUD LEN($Temp%)
  ]
  IF NOT Menu_Fast% THEN PROCObject_Add(3, Item% - 1, Menu%, Item$)
  Menu$ = MID$(Menu$, INSTR(Menu$, ",") + 1)
 NEXT

SYS"WimpExt_MenuWidth",, Menu%
IF Menu%!16 < 112 THEN Menu%!16 = 112
PROCObject_Add(2, Menu%, 0, Name$)
ENDPROC

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

DEF PROCMenu_PopUp(Menu$)
LOCAL XPos%, YPos%

B%!400 = W%
SYS"Wimp_GetWindowState",, B% + 400
XPos% = B%!404 - B%!420
YPos% = B%!416 - B%!424

B%!400 = W%
B%!404 = I%
SYS"Wimp_GetIconState",, B% + 400
XPos% += B%!416
YPos% += B%!420

PROCMenu_Show(Menu$, XPos%, YPos%)

ENDPROC