home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / proasm / routines / gtface.r < prev    next >
Text File  |  1995-10-16  |  48KB  |  2,631 lines

  1.  
  2. ;---;  gtface.r  ;-------------------------------------------------------------
  3. *
  4. *    ****    WINDOW HANDLING AND GADTOOLS INTERFACE ROUTINES    ****
  5. *
  6. *    Author        Stefan Walter
  7. *    Version        1.09
  8. *    Last Revision    16.10.95
  9. *    Identifier    gtf_defined
  10. *    Prefix        gtf_    (GadToolsFace)
  11. *                 ¯  ¯    ¯
  12. *    Functions    InitGTFace, ResetGTFace, SetZoomDimensionsLast
  13. *            SetZoomDimensions, OpenScaledWindowLast
  14. *            OpenScaledWindow, CloseScaledWindow
  15. *            CreateGList, FreeGList, AddGList, RemGList
  16. *            RefreshWindow, WaitForWindow, GetGTFMsg
  17. *            RefreshEventHandler, FindGadget, FindGadgetInKey
  18. *            SetZoomTitleBar, OpenUnScaledWindow
  19. *            PrintScaled, PrintScaledList
  20. *            AddMenu, RemMenu, GenMenu, FreeMenu, SetMenu, StripMenu
  21. *            CallGadget, CallMenu, CallKey, UnLockPubScreen
  22. *            WaitForWindowAndSignals, LockPubScreen
  23. *
  24. *    (PubScreen)    OpenScaledWindowPub,OpenScaledWindowLastPub
  25. *            SetZoomTitleBarPub
  26. *
  27. *    Flags        gtf_pubscreenfallback    (0: off, -:on)
  28. *
  29. ;------------------------------------------------------------------------------
  30.  
  31. ;------------------
  32.     ifnd    gtf_defined
  33. gtf_defined    =1
  34.  
  35. ;------------------
  36. gtf_oldbase    equ __base
  37.     base    gtf_base
  38. gtf_base:
  39.  
  40. ;------------------
  41. ; Some macros.
  42. ;
  43.     include    tasktricks.r
  44.     include    gtfdefs.r
  45.     include    basicmac.r
  46.  
  47. ;------------------
  48. ; Either let the startup do the library stuff or open it ourselves...
  49. ;
  50.     IFD    ely_defined
  51.  
  52.     IFND    GRAPHICS.LIB
  53.     FAIL    graphics.library needed for GTFace: GRAPHICS.LIB SET 1
  54.     ENDIF
  55.     IFND    INTUITION.LIB
  56.     FAIL    intuition.library needed for GTFace: INTUITION.LIB SET 1
  57.     ENDIF
  58.     IFND    GADTOOLS.LIB
  59.     FAIL    gadtools.library needed for GTFace: GADTOOLS.LIB SET 1
  60.     ENDIF
  61.  
  62. gtf_gfxbase        EQU    GfxBase
  63. gtf_intbase        EQU    IntBase
  64. gtf_gadtoolsbase    EQU    GadToolsBase
  65.  
  66.     ELSE
  67.  
  68. gtf_gfxbase    EQU    glb_gfxbase
  69. gtf_intbase    EQU    ilb_intbase
  70.     ENDIF    
  71.  
  72. ;------------------
  73.     IFND    USE_NEWROUTINES
  74.     WARN    You aren't using USE_NEWROUTINES, this is not efficient!
  75.     NEED_    InitGTFace        
  76.     NEED_    ResetGTFace        
  77.     NEED_    OpenScaledWindow    
  78.     NEED_    CloseScaledWindow    
  79.     NEED_    CreateGList        
  80.     NEED_    FreeGList        
  81.     NEED_    AddGList        
  82.     NEED_    RemGList        
  83.     NEED_    RefreshWindow    
  84.     NEED_    WaitForWindow    
  85.     NEED_    GetGTFMsg        
  86.     NEED_    RefreshEventHandler    
  87.     NEED_    FindGadget        
  88.     NEED_    AddMenu        
  89.     NEED_    RemMenu        
  90.     NEED_    CallGadget        
  91.     NEED_    CallKey        
  92.     NEED_    CallMenu        
  93.     NEED_    ClearWindow        
  94.     NEED_    PrintScaled        
  95.     NEED_    PaintObjects    
  96.     NEED_    LockWindow        
  97.     NEED_    UnLockWindow    
  98.     NEED_    gtf_doidcmp        
  99.     NEED_    gtf_rectfill    
  100.     NEED_    RemoveLVLabels    
  101.  
  102.     ENDIF
  103.  
  104. ;------------------
  105.  
  106.  
  107.  
  108.  
  109. ;------------------------------------------------------------------------------
  110. *
  111. * InitGTFace    Prepare for GTFace actions. Open libs, find and lock the
  112. *        system default font and get the pattern.
  113. *
  114. * RESULT:    d0    Default font or 0.
  115. *        ccr    On d0.
  116. *
  117. ;------------------------------------------------------------------------------
  118.  
  119. ;------------------
  120.     IFD    xxx_InitGTFace
  121. InitGTFace:
  122.     NEED_    ResetGTFace
  123.  
  124. ;------------------
  125. ; Open all needed libraries if no EasyLibraryHandler used.
  126. ;
  127. \start:    movem.l    d1-a6,-(sp)
  128.     lea    gtf_base(pc),a5
  129.  
  130.     IFND    ely_defined    
  131.     bsr    OpenIntuitionLib
  132.     beq    gtf_f1
  133.  
  134.     lea    gtf_gadtoolsname(pc),a1
  135.     move.l    4.w,a6
  136.     jsr    -408(a6)
  137.     move.l    d0,gtf_gadtoolsbase(a5)
  138.     beq    gtf_f2
  139.  
  140.     bsr    OpenGraphicsLib
  141.     beq    gtf_f3
  142.     ELSE
  143.     move.l    gtf_gfxbase(pc),a6
  144.     ENDIF
  145.  
  146. ;------------------
  147. ; Get topaz80 font. We need that one if the default font can't be used.
  148. ;
  149. \gettopaz:
  150.     lea    gtf_topazattr(pc),a0
  151.     lea    gtf_topazname(pc),a1
  152.     move.l    a1,(a0)
  153.     jsr    -72(a6)            ;OpenFont
  154.     move.l    d0,gtf_topazfont(a5)
  155.     beq    gtf_f4
  156.  
  157. ;------------------
  158. ; Get default font. Increase the accessor counter to ensure that noone
  159. ; takes that font from ous! Then init the TextAttr structure for it.
  160. ;
  161. \font:    move.l    gtf_gfxbase(pc),a6
  162.     Forbid_
  163.     move.l    154(a6),a4        ;gb_DefaultFont
  164.     addq.w    #1,30(a4)        ;tf_Accessors
  165.     Permit_
  166.     move.l    a4,gtf_defaultfont(a5)
  167.     move.l    10(a4),gtf_defaultattr(a5)
  168.     move.l    20(a4),gtf_defaultattr+4(a5)
  169.  
  170. ;------------------
  171. ; Allocate space for pattern.
  172. ;
  173. \alp:    moveq    #2,d0
  174.     moveq    #3,d1
  175.     move.l    4.w,a6
  176.     jsr    -198(a6)
  177.     move.l    d0,gtf_pattern(a5)
  178.     beq.s    gtf_f5
  179.     move.l    d0,a0
  180.     move.w    #$aaaa,(a0)
  181.  
  182.     st.b    gtf_status(a5)        ;set up!
  183.     move.l    a4,d0            ;return font
  184.     movem.l    (sp)+,d1-a6
  185.     rts
  186.  
  187.     ENDIF
  188. ;------------------
  189.  
  190.  
  191.  
  192.  
  193. ;------------------------------------------------------------------------------
  194. *
  195. * ResetGTFace    Free font and close libraries.
  196. *
  197. * RESULT:    d0    0
  198. *
  199. ;------------------------------------------------------------------------------
  200.  
  201. ;------------------
  202.     IFD    xxx_ResetGTFace
  203. ResetGTFace:
  204.  
  205. ;------------------
  206. ; Free all:
  207. ;
  208. \start:    movem.l    d1-a6,-(sp)
  209.     move.b    gtf_status(pc),d0    ;already reset?
  210.     beq.s    gtf_f1
  211.     move.l    4.w,a6
  212.     moveq    #2,d0
  213.     move.l    gtf_pattern(pc),a1
  214.     jsr    -210(a6)        ;FreeMem()
  215.  
  216. gtf_f5:    move.l    gtf_gfxbase(pc),a6
  217.     move.l    gtf_defaultfont(pc),a1
  218.     jsr    -78(a6)            ;CloseFont()
  219.     move.l    gtf_topazfont(pc),a1
  220.     jsr    -78(a6)            ;CloseFont()
  221.  
  222. gtf_f4:    IFND    ely_defined
  223.     bsr    CloseGraphicsLib
  224.  
  225. gtf_f3:    move.l    4.w,a6
  226.     move.l    gtf_gadtoolsbase(pc),a1
  227.     jsr    -414(a6)        ;CloseLibrary()
  228.  
  229. gtf_f2:    bsr    CloseIntuitionLib
  230.     ENDIF
  231.  
  232. gtf_f1:    lea    gtf_status(pc),a0
  233.     clr.b    (a0)            ;status!
  234.     moveq    #0,d0
  235.     movem.l    (sp)+,d1-a6
  236.     rts
  237.  
  238.     ENDIF
  239. ;------------------
  240.  
  241.  
  242.  
  243.  
  244. ;--------------------------------------------------------------------
  245. *
  246. * SetZoomDimensionsLast    Set the dimensions of the window when zoomed.
  247. *            Use the same dimensions as when the window was
  248. *            closed last time.
  249. *
  250. * INPUT:    a1    Tags for later OpenWindowScaled.
  251. *        a2    Empty WindowKey structure.
  252. *
  253. ;--------------------------------------------------------------------
  254.  
  255. ;------------------
  256.     IFD    xxx_SetZoomDimensionsLast
  257. SetZoomDimensionsLast:
  258.  
  259. ;------------------
  260. ; Do.
  261. ;
  262. \lock:     movem.l    d0-d3,-(sp)
  263.     movem.w    gfw_zoomxpos(a2),d0-d3
  264.     CALL_    SetZoomDimensions
  265.     movem.l    (sp)+,d0-d3
  266.     rts
  267.  
  268.     ENDIF
  269. ;------------------
  270.  
  271.  
  272.  
  273.  
  274. ;--------------------------------------------------------------------
  275. *
  276. * SetZoomTitleBarPub    (PubScreen only!)
  277. * SetZoomTitleBar    Set the zoom dimensions such that the window
  278. *            will be only a title bar and that the title
  279. *            string will fully fit.
  280. *
  281. * INPUT:    d0    XPos.
  282. *        d1    YPos.
  283. *        a0    NewWindowStruct for later OpenWindowScaled
  284. *        a1    Tags for later OpenWindowScaled.
  285. *        a2    Empty WindowKey structure.
  286. *        (a3     PubScreenName, only for *Pub variant)
  287. *
  288. ;--------------------------------------------------------------------
  289.  
  290. ;------------------
  291.     IFD    xxx_SetZoomTitleBar
  292. SetZoomTitleBarPub:
  293.     move.l    a3,gtf_pubscreenname
  294.     CALL_    SetZoomTitleBar
  295.     bne.s    1$
  296.     tst.b    gtf_pubscreenfallback
  297.     beq.s    1$
  298.     CALL_    SetZoomTitleBar
  299. 1$:    rts
  300.     ENDIF
  301.     
  302. ;------------------
  303.     IFD    xxx_SetZoomTitleBar
  304. SetZoomTitleBar:
  305.  
  306. ;------------------
  307. ; Do.
  308. ;
  309. \lock:     movem.l    d0-d3/a0-a3,-(sp)
  310.     lea    gfw_zoomxpos(a2),a3
  311.     move.l    a3,8*2+4(a1)
  312.     move.w    d0,(a3)
  313.     move.w    d1,gfw_zoomypos(a2)
  314.     CALL_    LockPubScreen
  315.     beq.s    \done
  316.     move.l    d0,a3
  317.     moveq    #0,d0
  318.     move.b    $1e(a3),d0        ;bar heigth...
  319.     add.b    $1f(a3),d0        ;plus bar border... ???
  320.     move.w    d0,gfw_zoomheigth(a2)
  321.     lea    $54(a3),a1        ;RP
  322.     move.l    $1a(a0),a0        ;string
  323.     move.l    a0,a3
  324.     moveq    #-1,d0
  325. \loop:    addq.l    #1,d0
  326.     tst.b    (a3)+
  327.     bne.s    \loop
  328.     move.l    gtf_gfxbase(pc),a6
  329.     jsr    -54(a6)            ;TextLength()
  330.     add.w    #46+18+2+(20),d0        ;magic number for gadgets!
  331.     move.w    d0,gfw_zoomwidth(a2)
  332. \done:    movem.l    (sp)+,d0-d3/a0-a3
  333.     rts
  334.  
  335.     ENDIF
  336. ;------------------
  337.  
  338.  
  339.  
  340.  
  341. ;--------------------------------------------------------------------
  342. *
  343. * SetZoomDimensions    Set the dimensions of the window when zoomed.
  344. *            The sizes given are *NOT* scaled. This function
  345. *            must be called *BEFORE* the window is opened.
  346. *
  347. * INPUT:    d0    XPos.
  348. *        d1    YPos.
  349. *        d2    Width (outer!).
  350. *        d3    Heigth (outer!).
  351. *        a1    Tags for later OpenWindowScaled.
  352. *        a2    Empty WindowKey structure.
  353. *
  354. ;--------------------------------------------------------------------
  355.  
  356. ;------------------
  357.     IFD    xxx_SetZoomDimensions
  358. SetZoomDimensions:
  359.  
  360. ;------------------
  361. ; Do.
  362. ;
  363. \lock:     pea    (a0)
  364.     lea    gfw_zoomheigth+2(a2),a0
  365.     movem.w    d0-d3,-(a0)
  366.     cmp.l    #WA_Zoom,2*8(a1)
  367.     bne.s    1$
  368.     move.l    a0,2*8+4(a1)        ;set WA_Zoom!
  369. 1$:    cmp.l    #WA_Zoom,3*8(a1)
  370.     bne.s    2$
  371.     move.l    a0,3*8+4(a1)        ;set WA_Zoom!
  372. 2$:    move.l    (sp)+,a0
  373.     rts
  374.  
  375.     ENDIF
  376. ;------------------
  377.  
  378.  
  379.  
  380.  
  381. ;--------------------------------------------------------------------
  382. *
  383. * OpenScaledWindowLastPub
  384. * OpenScaledWindowLast    Opens a window again at the same position and
  385. *            with the same size it was closed.
  386. *            the same zoomed size. The tag WA_Zoom must be on
  387. *            third position in the tag list.
  388. *
  389. * INPUT:    a0    NewWindow structure.
  390. *        a1    Tags, at least the three mentioned above.
  391. *        a2    Already used WindowKey structure.
  392. *        (a3     PubScreenName, only for *Pub variant)
  393. *
  394. * RESULT:    d0    Window or 0.
  395. *        a2    Filled WindowKey structure.
  396. *        ccr    On d0.
  397. *
  398. ;--------------------------------------------------------------------
  399.  
  400. ;------------------
  401.     IFD    xxx_OpenScaledWindowLast
  402. OpenScaledWindowLast:
  403.  
  404. ;------------------
  405. ; Remember old arguments from NewWindow structure and do...
  406. ;
  407. \do:    move.l    (a0),-(sp)        ;remember old x/y
  408.     move.l    4(a0),-(sp)        ;and w/h
  409.     move.l    gfw_winxpos(a2),(a0)
  410.     move.l    gfw_winiwidth(a2),4(a0)
  411.     st.b    gfw_noscale(a2)        ;inner size scaled!!!
  412.     CALL_    OpenScaledWindow
  413.     move.l    (sp)+,4(a0)
  414.     move.l    (sp)+,(a0)
  415.     tst.l    d0
  416.     bne.s    \fine
  417.     CALL_    OpenScaledWindow    ;try again!
  418. \fine:    rts
  419.  
  420.     ENDIF
  421. ;------------------
  422.  
  423.  
  424.  
  425. ;------------------
  426.     IFD    xxx_OpenScaledWindowLastPub
  427. OpenScaledWindowLastPub:
  428.  
  429. ;------------------
  430. ; Remember old arguments from NewWindow structure and do...
  431. ;
  432. \do:    move.l    (a0),-(sp)        ;remember old x/y
  433.     move.l    4(a0),-(sp)        ;and w/h
  434.     move.l    gfw_winxpos(a2),(a0)
  435.     move.l    gfw_winiwidth(a2),4(a0)
  436.     st.b    gfw_noscale(a2)        ;inner size scaled!!!
  437.     CALL_    OpenScaledWindowPub
  438.     move.l    (sp)+,4(a0)
  439.     move.l    (sp)+,(a0)
  440.     tst.l    d0
  441.     bne.s    \fine
  442.     CALL_    OpenScaledWindowPub    ;try again!
  443. \fine:    rts
  444.  
  445.     ENDIF
  446. ;------------------
  447.  
  448.  
  449.  
  450. ;--------------------------------------------------------------------
  451. *
  452. * OpenScaledWindowPub
  453. * OpenScaledWindow    Open a window. The window will be opened with
  454. *            an inner size that is scaled for use of the
  455. *            system default font. The size used for topaz80
  456. *            is stored in the NewWindow structure. The first
  457. *            two tags you provide must be WA_InnerWidth and
  458. *            WA_InnerHeigth. Min/Max values will also be
  459. *            scaled and must be given for the enterior size!
  460. *
  461. * OpenUnScaledWindow    Open a window without scaling, but still in
  462. *            GTFace manner. The first two tags must be WA_Width
  463. *            and WA_Height.
  464. *
  465. * INPUT:    a0    NewWindow structure.
  466. *        a1    Tags, at least the two mentioned above.
  467. *        a2    Empty WindowKey structure.
  468. *        (a3     PubScreenName, only for *Pub variant)
  469. *
  470. * RESULT:    d0    Window or 0.
  471. *        a2    Filled WindowKey structure.
  472. *        ccr    On d0.
  473. *
  474. ;--------------------------------------------------------------------
  475. * INTERNAL NOTE:
  476. *
  477. * This routine contains the neccessary hacks to best get around C='s problems
  478. * with opening a window. 3.0 always has a zoom gadget which zooms to the
  479. * minimal size specified when opening the window. At this point it is not
  480. * possible to calculate border sizes 100%, i.e. the width of size gadget
  481. * cannot be calculated. Therefore the maximal and minimal size is still
  482. * set with WindowLimits() after the window is opened, but the min/max sizes
  483. * are preset to some relatively good values before the window openes. 
  484. *
  485. * If C= tells about some bugfixes and official ways around these problems,
  486. * this routine may has to be changed.
  487. ;--------------------------------------------------------------------
  488.  
  489. ;------------------
  490.     IFD    xxx_OpenScaledWindowPub
  491. OpenScaledWindowPub:
  492.     move.l    a3,gtf_pubscreenname
  493.     CALL_    OpenScaledWindow
  494.     bne.s    1$
  495.     tst.b    gtf_pubscreenfallback
  496.     beq.s    1$
  497.     CALL_    OpenScaledWindow
  498. 1$:    rts
  499.     ENDIF
  500.  
  501.     
  502. ;------------------
  503.     IFD    xxx_OpenUnScaledWindow
  504.     NEED_    OpenScaledWindow    
  505. OpenUnScaledWindow:
  506.     st.b    gfw_noscale(a2)
  507.     st.b    gtf_nolimscale
  508.     ENDIF
  509.     IFD    xxx_OpenScaledWindow
  510. OpenScaledWindow:
  511.  
  512. ;------------------
  513. ; Lock screen while we get the window up.
  514. ;
  515. \start: movem.l    d1-a6,-(sp)
  516.     move.l    a0,d6
  517.     move.l    a1,d5
  518.     move.l    a2,a4
  519.     move.l    gtf_intbase(pc),a6
  520.  
  521.     lea    gtf_minmax(pc),a3
  522.     move.l    $26(a0),(a3)+        ;backup true min/max values!
  523.     move.l    $2a(a0),(a3)
  524.  
  525.     CALL_    LockPubScreen
  526.     beq    \fail
  527.  
  528.     move.l    gtf_screen(pc),d0
  529.     cmp.l    #WA_PubScreen,2*8(a1)
  530.     bne.s    ..1
  531.     move.l    d0,2*8+4(a1)
  532. ..1:    cmp.l    #WA_PubScreen,3*8(a1)
  533.     bne.s    ..2
  534.     move.l    d0,3*8+4(a1)
  535. ..2:
  536.  
  537.  
  538. ;------------------
  539. ; Calculate border sizes for future window.
  540. ;
  541. \calc:    move.l    gtf_screen(pc),a2
  542.     moveq    #0,d4
  543.     moveq    #0,d3
  544.     move.b    $24(a2),d4        ;left
  545.     add.b    $25(a2),d4
  546.  
  547.     move.b    $23(a2),d3        ;top
  548.     addq.w    #1,d3            ;+1    ????
  549.     move.l    $28(a2),a0
  550.     add.w    4(a0),d3        ;font heigth
  551.     add.b    $26(a2),d3        ;and bottom bar
  552.  
  553. ;------------------
  554. ; Test if window will fit screen when opened for default font.
  555. ;
  556. \try:    move.l    gtf_defaultfont(pc),a3
  557.     cmp.w    #7,24(a3)        ;width limited to 7
  558.     blt    \uset8
  559.     cmp.w    #8,20(a3)        ;heigth to 8
  560.     blt    \uset8
  561.  
  562.     bsr    \calib
  563.     move.w    $c(a2),d0        ;screen width...
  564.     sub.w    d4,d0            ;- borders 
  565.     cmp.w    6(a1),d0
  566.     blt    \uset8
  567.  
  568.     move.w    $e(a2),d0        ;screen heigth...
  569.     sub.w    d3,d0            ;- borders
  570.     cmp.w    6+8(a1),d0
  571.     blt    \uset8
  572.     bra    \open
  573.     
  574. ;------------------
  575. ; Calibrate window size. Set the WA_InnerWidth and WA_InnerHeigth
  576. ; Tags and the min/max sizes!
  577. ;
  578. \calib:    move.l    d6,a0
  579.     move.l    d5,a1
  580.     move.w    24(a3),gfw_fontx(a4)
  581.     move.w    20(a3),gfw_fonty(a4)
  582.  
  583.     moveq    #0,d0
  584.     move.w    4(a0),d0
  585.     move.b    gfw_noscale(a4),d2
  586.     bne.s    111$
  587.     mulu    24(a3),d0        ;multiply with font x size
  588.     addq.l    #7,d0
  589.     lsr.l    #3,d0
  590. 111$    move.l    d0,4(a1)        ;inner width
  591.     move.w    d0,gfw_winiwidth(a4)
  592.     move.w    6(a0),d0
  593.     tst.b    d2
  594.     bne.s    222$
  595.     mulu    20(a3),d0        ;multiply with font y size
  596.     addq.l    #7,d0
  597.     lsr.l    #3,d0
  598. 222$    move.l    d0,4+8(a1)        ;inner height
  599.     move.w    d0,gfw_winiheigth(a4)
  600.  
  601.     moveq    #-1,d2
  602.     move.b    gtf_nolimscale(pc),d0
  603.     bne.s    \nolsc
  604.  
  605. \maxy:    move.w    gtf_minmax+6(pc),d0
  606.     cmp.w    d0,d2
  607.     beq.s    \maxx
  608.     CALL_    gtf_scaled0y
  609.     add.w    d3,d0
  610.     move.w    d0,$2c(a0)
  611.     
  612. \maxx:    move.w    gtf_minmax+4(pc),d0
  613.     cmp.w    d0,d2
  614.     beq.s    \miny
  615.     CALL_    gtf_scaled0x
  616.     add.w    d4,d0
  617.     move.w    d0,$2a(a0)
  618.  
  619. \miny:    moveq    #1,d0
  620.     move.w    gtf_minmax+2(pc),d1
  621.     cmp.w    d1,d2
  622.     beq.s    \minx
  623.     move.w    d1,d0
  624.     CALL_    gtf_scaled0y
  625.     add.w    d3,d0
  626.  
  627. \minx:    move.w    d0,$28(a0)
  628.     moveq    #16,d0
  629.     move.w    gtf_minmax+2(pc),d1
  630.     cmp.w    d1,d2
  631.     beq.s    \setmm
  632.     move.w    d1,d0
  633.     CALL_    gtf_scaled0x
  634.     add.w    d4,d0
  635.  
  636. \setmm:    move.w    d0,$26(a0)
  637. \nolsc:    rts
  638.  
  639. ;------------------
  640. ; Open Window. First try default font, then topaz80.
  641. ;
  642. \open:    move.l    gtf_defaultfont(pc),a3
  643.     lea    gtf_defaultattr(pc),a5
  644.     bsr    \calib
  645.     jsr    -606(a6)        ;OpenWindowTagList()
  646.     move.l    d0,d7
  647.     bne.s    \set
  648.  
  649. \uset8:    move.l    gtf_topazfont(pc),a3
  650.     lea    gtf_topazattr(pc),a5
  651.     bsr    \calib
  652.     jsr    -606(a6)        ;OpenWindowTagList()
  653.     move.l    d0,d7
  654.     beq    \fail2
  655.         
  656. \set:    move.l    d7,a1
  657.     move.l    4(a1),gfw_winxpos(a4)
  658.     move.l    8(a1),gfw_winwidth(a4)
  659.     move.l    50(a1),a1        ;RasterPort
  660.     move.l    a3,a0
  661.     move.l    gtf_gfxbase(pc),a6
  662.     jsr    -66(a6)            ;SetFont()
  663.  
  664.     move.l    gtf_gadtoolsbase(pc),a6
  665.     move.l    d7,a2
  666.     move.l    $2e(a2),a0        ;screen
  667.     suba.l    a1,a1            ;no tags
  668.     jsr    -126(a6)        ;GetVisualInfoA()
  669.     move.l    d0,gfw_visualinfo(a4)
  670.     beq    \fail3
  671.  
  672.     
  673. ;------------------
  674. ; Init rest of WindowKey.
  675. ;
  676. \ikey:    move.l    d7,gfw_window(a4)
  677.     move.l    a3,gfw_font(a4)
  678.     move.l    a5,gfw_textattr(a4)
  679.     
  680.     lea    gfw_glists(a4),a0
  681.     move.l    a0,8(a0)        ;init 'gadget list' list!
  682.     addq.l    #4,a0
  683.     clr.l    (a0)
  684.     move.l    a0,-4(a0)
  685.  
  686. ;------------------
  687. ; Set new max and min size.
  688. ;
  689. \lim:    lea    gtf_minmax+8(pc),a1
  690.     move.l    d7,a0
  691.     lea    $36(a0),a2
  692.  
  693.     moveq    #0,d4
  694.     moveq    #0,d5
  695.     move.b    (a2)+,d4
  696.     move.w    d4,gfw_lefto(a4)
  697.     move.b    (a2)+,d5
  698.     move.w    d5,gfw_topo(a4)
  699.     add.b    (a2)+,d4
  700.     add.b    (a2)+,d5
  701.     move.w    d4,gfw_horbd(a4)
  702.     move.w    d5,gfw_vertbd(a4)
  703.  
  704.     move.l    d6,-(sp)
  705.     move.l    d6,a2
  706.     move.l    10(a2),gfw_idcmp(a4)    ;remember needed IDCMP
  707.     btst    #2,16(a2)        ;G00 window?
  708.     beq.s    \nog00
  709.     clr.l    gfw_lefto(a4)
  710.  
  711. \nog00:    moveq    #-1,d6
  712.  
  713. \maxy2:    move.w    -(a1),d0
  714.     move.w    d0,d3
  715.     cmp.w    d6,d0
  716.     beq.s    \maxx2
  717.     CALL_    gtf_scaled0y
  718.     move.w    d0,d3
  719.     add.w    d5,d3
  720.  
  721. \maxx2:    move.w    -(a1),d0
  722.     move.w    d0,d2
  723.     cmp.w    d6,d0
  724.     beq.s    \minx2
  725.     CALL_    gtf_scaled0x
  726.     move.w    d0,d2
  727.     add.w    d4,d2
  728.  
  729. \minx2:    moveq    #1,d0
  730.     cmp.w    -(a1),d6
  731.     beq.s    \miny2
  732.     move.w    (a1),d0
  733.     CALL_    gtf_scaled0y
  734.     add.w    d5,d0
  735.  
  736. \miny2:    move.w    d0,d1
  737.     moveq    #16,d0
  738.     cmp.w    -(a1),d6
  739.     beq.s    \setmm2
  740.     move.w    (a1),d0
  741.     CALL_    gtf_scaled0x
  742.     add.w    d4,d0
  743.  
  744. \setmm2:move.l    gtf_intbase(pc),a6
  745.     jsr    -318(a6)        ;WindowLimits()
  746.     move.l    (sp)+,d6
  747.  
  748. ;------------------
  749. ; Unlock screen.
  750. ;
  751. \un:    move.l    gtf_screen(pc),a1
  752.     suba.l    a0,a0
  753.     move.l    gtf_intbase(pc),a6
  754.     jsr    -516(a6)        ;UnLockPubScreen()
  755.     lea    gtf_locked(pc),a0
  756.     clr.b    (a0)
  757.  
  758. \exit:    move.l    d6,a2
  759.     move.l    gtf_minmax(pc),$26(a2)
  760.     move.l    gtf_minmax+4(pc),$26+4(a2)
  761.     clr.b    gfw_noscale(a4)        ;scaling allowed!
  762.     move.l    d7,d0
  763.     movem.l    (sp)+,d1-a6
  764.     rts
  765.  
  766. ;------------------
  767. ; Failures.
  768. ;
  769. \fail3:    move.l    gfw_window(a4),a0
  770.     move.l    gtf_intbase(pc),a6
  771.     jsr    -72(a6)            ;CloseWindow
  772.  
  773. \fail2:    move.l    gtf_screen(pc),a1
  774.     suba.l    a0,a0
  775.     jsr    -516(a6)        ;UnLockPubScreen()
  776.     lea    gtf_locked(pc),a0
  777.     clr.b    (a0)
  778.  
  779. \fail:    moveq    #0,d7
  780.     bra.s    \exit
  781.  
  782.     ENDIF
  783. ;------------------
  784.  
  785.  
  786.  
  787.  
  788. ;--------------------------------------------------------------------
  789. *
  790. * CloseScaledWindow    Close the window again.
  791. *
  792. * INPUT:    a2    WindowKey.
  793. *
  794. ;--------------------------------------------------------------------
  795.  
  796. ;------------------
  797.     IFD    xxx_CloseScaledWindow
  798. CloseScaledWindow
  799.  
  800. ;------------------
  801. ; Close.
  802. ;
  803. \start:    movem.l    d0-a6,-(sp)
  804.     move.l    gfw_window(a2),d0
  805.     beq.s    \done
  806.     move.l    d0,a0
  807.     clr.l    gfw_window(a2)        ;closed!
  808.     clr.b    gfw_domenu(a2)        ;for CallMenu()
  809.  
  810.     move.l    gfw_visualinfo(a2),d7
  811.  
  812.     move.l    gtf_intbase(pc),a6
  813.     jsr    -72(a6)            ;CloseWindow
  814.  
  815.     move.l    d7,a0
  816.     move.l    gtf_gadtoolsbase(pc),a6
  817.     jsr    -132(a6)        ;FreeVisualInfo()
  818.  
  819. \done:    movem.l    (sp)+,d0-a6
  820.     rts
  821.  
  822.     ENDIF
  823. ;------------------
  824.  
  825.  
  826.  
  827.  
  828. ;--------------------------------------------------------------------
  829. *
  830. * CreateGList    Create a gadget list from a GTFace info structure.
  831. *
  832. * INPUT:    a0    GTFace gadget structure.
  833. *        a1    Empty GadgetKey structure.
  834. *        a2    WindowKey of window these gadgets are rendered for.
  835. *
  836. * RESULT:    d0    Gadget list or 0.
  837. *        a1    GadgetKey.
  838. *        a2    WindowKey.
  839. *        d0    On d0.
  840. *
  841. ;--------------------------------------------------------------------
  842.  
  843. ;------------------
  844.     IFD    xxx_CreateGList
  845. CreateGList:
  846.     NEED_    gtf_newgadget
  847.     NEED_    gtf_tagspace
  848.  
  849. ;------------------
  850. ; Shuffle some registers.
  851. ;
  852. \init:    movem.l    d1-a6,-(a7)
  853.     move.l    a2,a4
  854.     move.l    a1,a5
  855.     move.l    a0,a3
  856.     moveq    #0,d5            ;default is error
  857.  
  858. ;------------------
  859. ; Create context.
  860. ;
  861. \dogts:    move.l    gtf_gadtoolsbase(pc),a6
  862.     lea    gfg_gadgets(a5),a0
  863.     clr.l    (a0)
  864.     jsr    -114(a6)        ;CreateContext()
  865.     lea    gtf_prev(pc),a0
  866.     move.l    d0,(a0)
  867.     beq    \done
  868.  
  869. ;------------------
  870. ; Allocate table.
  871. ;
  872. \atab:    move.l    (a3)+,d0
  873.     move.l    (a3)+,gfg_idcmp(a5)
  874.     clr.l    gfg_numof(a5)
  875.     clr.l    gfg_objects(a5)
  876.     clr.l    gfg_remkey(a5)
  877.     move.l    d0,gfg_gnumof(a5)
  878.     lsl.l    #2,d0
  879.     addq.l    #4,d0            ;to prevent 0 size allocs!
  880.     moveq    #1,d1
  881.     move.l    4.w,a6
  882.     jsr    -198(a6)        ;AllocMem()
  883.     move.l    d0,gfg_table(a5)
  884.     beq    \gerr
  885.     move.l    gtf_gadtoolsbase(pc),a6
  886.  
  887. ;------------------
  888. ; Now we can create the gadgets! Go through the structure and do the basic
  889. ; stuff that is the same for all kinds of gadgets.
  890. ;
  891. \cre:    move.w    (a3)+,d2            ;more?
  892.     beq    \fine
  893.     bmi    \special            ;BevelBoxes etc.
  894.  
  895.     lea    gtf_newgadget(pc),a1
  896.     bsr    \scalexypair2
  897.     bsr    \scalexypair
  898.     move.l    (a3)+,(a1)+            ;Text
  899.     move.l    gfw_textattr(a4),(a1)+        ;Font (TextAttr!!)
  900.     move.w    (a3)+,(a1)+            ;ID
  901.     moveq    #0,d0
  902.     move.w    (a3)+,d0
  903.     move.l    d0,(a1)+            ;Flags
  904.     move.l    gfw_visualinfo(a4),(a1)+
  905.     move.w    (a3)+,d4            ;Tag flags!
  906.  
  907. ;------------------
  908. ; Do the only basic tag, that is GT_Underscore and GA_Disabled.
  909. ;
  910. \bas:    lea    gtf_tagspace(pc),a2
  911.     moveq    #1,d1                ;for all subs the default flag
  912.     btst    #gtf_b_Disabled,d4        ;Disabled?
  913.     beq.s    \nod
  914.     move.l    #GA_Disabled,(a2)+
  915.     move.l    d1,(a2)+
  916.  
  917. \nod:    btst    #gtf_b_Underscore,d4        ;GT_Underscore wanted?
  918.     beq.s    \nou
  919.     move.l    #GT_Underscore,(a2)+
  920.     moveq    #"_",d0
  921.     move.l    d0,(a2)+
  922.  
  923. \nou:    lea    \jumplist(pc),a0
  924.     move.w    d2,d0
  925.     add.w    d0,d0
  926.     move.w    (a0,d0.w),d0
  927.     jsr    (a0,d0.w)
  928.     tst.w    d2
  929.     bmi    \cre
  930.  
  931. \dogad:    clr.l    (a2)                ;TAG_DONE
  932.     moveq    #0,d0
  933.     move.b    d2,d0
  934.     move.l    gtf_prev(pc),a0
  935.     lea    gtf_tagspace(pc),a2
  936.     lea    gtf_newgadget(pc),a1
  937.     jsr    -30(a6)            ;CreateGadgetA()
  938.     lea    gtf_prev(pc),a0
  939.     move.l    d0,(a0)
  940.     beq.s    \gerr
  941.  
  942.     move.l    gfg_numof(a5),d1
  943.     lsl.l    #2,d1
  944.     move.l    gfg_table(a5),a0
  945.     move.l    d0,(a0,d1.l)        ;remember in table
  946.  
  947.     addq.l    #1,gfg_numof(a5)    ;one more
  948.  
  949. ;------------------
  950. ; Do postcreation stuff, i.e. ToggleSelect.
  951. ;
  952. \post:    move.l    d0,a0
  953.     btst    #gtf_b_ToggleSelect,d4
  954.     beq.s    \npo1
  955.     or.w    #$100,14(a0)        ;GACD_TOGGLESELECT in gg_Activation
  956. \npo1:    btst    #gtf_b_Selected,d4
  957.     beq.s    \npo2
  958.     or.w    #$80,12(a0)        ;Selected! in Flags
  959. \npo2:    bra    \cre
  960.  
  961. ;------------------
  962. ; All went fine! Now count the gadgets!
  963. ;
  964. \fine:    move.l    gfg_gadgets(a5),d5
  965.     move.l    a4,gfg_window(a5)
  966.  
  967.     move.l    d5,a0
  968.     moveq    #1,d0
  969. \count:    move.l    (a0),d1
  970.     beq.s    \counted
  971.     addq.l    #1,d0
  972.     move.l    d1,a0
  973.     bra.s    \count
  974.  
  975. \counted:
  976.     move.l    d0,gfg_numof(a5)
  977.     bra.s    \done
  978.  
  979. ;------------------
  980. ; Init the GadgetKey structure.
  981. ;
  982. \igkey:    lea    gfg_numof(a5),a0
  983.     clr.l    (a0)+            ;no gadgets yet
  984.  
  985.     bra.s    \done
  986.  
  987. ;------------------
  988. ; Error occures, free all gadgets!
  989. ;
  990. \gerr:    move.l    gfg_gadgets(a5),a0
  991.     move.l    gtf_gadtoolsbase(pc),a6
  992.     jsr    -36(a6)            ;FreeGadgets()    
  993.     move.l    gtf_intbase(pc),a6
  994.     lea    gfg_remkey(a5),a0
  995.     moveq    #-1,d0
  996.     jsr    -408(a6)        ;FreeRemember()
  997.  
  998. ;------------------
  999. ; Okay!
  1000. ;
  1001. \done:    move.l    d5,d0
  1002.     movem.l    (sp)+,d1-a6
  1003.     rts
  1004.  
  1005. ;------------------
  1006. ; Scale value!
  1007. ;
  1008. \scalexypair:
  1009.     move.w    (a3)+,d0
  1010.     CALL_    gtf_scaled0x
  1011.     move.w    d0,(a1)+
  1012.     move.w    (a3)+,d0
  1013.     CALL_    gtf_scaled0y
  1014.     move.w    d0,(a1)+
  1015.     rts
  1016.  
  1017. \scalexypair2:
  1018.     bsr    \scalexypair
  1019.     move.l    gfw_lefto(a4),d0
  1020.     add.l    d0,-4(a1)            ;left&top border!
  1021.     rts
  1022.  
  1023. ;------------------
  1024. ; Jumplist for different handlings.
  1025. ;
  1026.     dc.w    \posinfo-\jumplist    ;for own 'generic' gadgets (MINUS!)
  1027. \jumplist:
  1028.     dc.w    0            ;Generic!
  1029.     dc.w    \button-\jumplist
  1030.     dc.w    \checkbox-\jumplist
  1031.     dc.w    \integer-\jumplist
  1032.     dc.w    \listview-\jumplist
  1033.     dc.w    \mx-\jumplist
  1034.     dc.w    0            ;No Number Gadgets!
  1035.     dc.w    \cycle-\jumplist
  1036.     dc.w    0            ;No Palette
  1037.     dc.w    0            ;No Scroller
  1038.     dc.w    0            ;RESERVED
  1039.     dc.w    \slider-\jumplist
  1040.     dc.w    \string-\jumplist
  1041.     dc.w    \text-\jumplist
  1042.  
  1043.  
  1044. ;--------------------------------------------------------------------
  1045. ; Each kind of gadget has a handler here.
  1046. ;
  1047.  
  1048. ;------------------
  1049. ; Button tags handling sub. Does nothing.
  1050. ;
  1051. \button:    rts
  1052.  
  1053. ;------------------
  1054. ; Checkbox tags handling sub.
  1055. ;
  1056. \checkbox:
  1057.     btst    #gtf_b_Checked,d4
  1058.     beq.s    \ck1
  1059.     move.l    #GTCB_Checked,(a2)+
  1060.     move.l    d1,(a2)+
  1061. \ck1:    rts
  1062.  
  1063. ;------------------
  1064. ; Integer tags handling sub.
  1065. ;
  1066. \integer:
  1067. ;    bsr.s    \calibborder
  1068.     btst    #gtf_b_Number,d4
  1069.     beq.s    \in1
  1070.     move.l    #GTIN_Number,(a2)+
  1071.     move.l    (a3)+,(a2)+
  1072. \in1:    btst    #gtf_b_MaxChars,d4
  1073.     beq.s    \in2
  1074.     move.l    #GTIN_MaxChars,(a2)+
  1075.     move.l    (a3)+,(a2)+
  1076. \in2:    btst    #gtf_b_RightJustified,d4
  1077.     beq.s    \in3
  1078.     move.l    #STRINGA_Justification,(a2)+
  1079.     move.l    #$400,(a2)+
  1080. \in3:    btst    #gtf_b_NoTabCycle,d4
  1081.     beq.s    \in4
  1082.     move.l    #GA_TabCycle,(a2)+
  1083.     clr.l    (a2)+
  1084. \in4:    rts
  1085.     
  1086. ;\calibborder:        ;Change big borders for String/Integer
  1087. ;    lea    gtf_newgadget(pc),a0
  1088. ;    add.l    #$00040002,(a0)+
  1089. ;    sub.l    #$00080004,(a0)
  1090. ;    rts
  1091.  
  1092. ;------------------
  1093. ; Listview tags handling.
  1094. ;
  1095. \listview:
  1096.     moveq    #16,d0
  1097.     CALL_    gtf_scaled0x
  1098.     move.l    #GTLV_ScrollWidth,(a2)+
  1099.     move.l    d0,(a2)+            ;scale the slider width too!
  1100.     btst    #gtf_b_Labels,d4
  1101.     beq.s    \lv1
  1102.     move.l    #GTLV_Labels,(a2)+
  1103.     move.l    (a3)+,(a2)+
  1104. \lv1:    btst    #gtf_b_ReadOnly,d4
  1105.     beq.s    \lv2
  1106.     move.l    #GTLV_ReadOnly,(a2)+
  1107.     move.l    d1,(a2)+
  1108. \lv2:    btst    #gtf_b_ShowSelected,d4
  1109.     beq.s    \lv3
  1110.     move.l    #GTLV_ShowSelected,(a2)+
  1111.     clr.l    (a2)+
  1112. \lv3:    btst    #gtf_b_LVSelected,d4
  1113.     beq.s    \lv4
  1114.     move.l    #GTLV_Selected,(a2)+
  1115.     move.l    (a3)+,(a2)+
  1116. \lv4:    rts
  1117.  
  1118. ;------------------
  1119. ; MX tags handling.
  1120. ;
  1121. \mx:    btst    #gtf_b_Labels,d4
  1122.     beq.s    \mx1
  1123.     move.l    #GTMX_Labels,(a2)+
  1124.     move.l    (a3)+,(a2)+
  1125. \mx1:    btst    #gtf_b_Active,d4
  1126.     beq.s    \mx2
  1127.     move.l    #GTMX_Active,(a2)+
  1128.     move.l    (a3)+,(a2)+
  1129. \mx2:    btst    #gtf_b_Spacing,d4
  1130.     beq.s    \mx3
  1131.     move.l    #GTMX_Spacing,(a2)+
  1132.     move.l    (a3)+,d0
  1133.     mulu    gfw_fonty(a4),d0
  1134.     lsr.l    #3,d0
  1135.     move.l    d0,(a2)+
  1136. \mx3:    rts
  1137.  
  1138. ;------------------
  1139. ; Slider gadget tags handling.
  1140. ;
  1141. \slider:
  1142.     move.l    #PGA_Freedom,(a2)+
  1143.     move.l    (a3)+,(a2)+
  1144.     btst    #gtf_b_RelVerify,d4
  1145.     beq.s    \sl1
  1146.     move.l    #GA_RelVerify,(a2)+
  1147.     move.l    d1,(a2)+
  1148. \sl1:    btst    #gtf_b_Min,d4
  1149.     beq.s    \sl2
  1150.     move.l    #GTSL_Min,(a2)+
  1151.     clr.w    (a2)+
  1152.     move.w    (a3)+,(a2)+
  1153. \sl2:    btst    #gtf_b_Max,d4
  1154.     beq.s    \sl3
  1155.     move.l    #GTSL_Max,(a2)+
  1156.     clr.w    (a2)+
  1157.     move.w    (a3)+,(a2)+
  1158. \sl3:    btst    #gtf_b_Level,d4
  1159.     beq.s    \sl4
  1160.     move.l    #GTSL_Level,(a2)+
  1161.     clr.w    (a2)+
  1162.     move.w    (a3)+,(a2)+
  1163. \sl4:    btst    #gtf_b_MaxLevelLen,d4
  1164.     beq.s    \sl5
  1165.     move.l    #GTSL_MaxLevelLen,(a2)+
  1166.     clr.w    (a2)+
  1167.     move.w    (a3)+,(a2)+
  1168. \sl5:    btst    #gtf_b_LevelFormat,d4
  1169.     beq.s    \sl6
  1170.     move.l    #GTSL_LevelFormat,(a2)+
  1171.     move.l    (a3)+,(a2)+
  1172. \sl6:    btst    #gtf_b_LevelPlace,d4
  1173.     beq.s    \sl7
  1174.     move.l    #GTSL_LevelPlace,(a2)+
  1175.     clr.w    (a2)+
  1176.     move.w    (a3)+,(a2)+
  1177. \sl7:    btst    #gtf_b_DispFunc,d4
  1178.     beq.s    \sl8
  1179.     move.l    #GTSL_DispFunc,(a2)+
  1180.     move.l    (a3)+,(a2)+
  1181. \sl8:    rts
  1182.  
  1183. ;------------------
  1184. ; Cycle gadget tags handling.
  1185. ;
  1186. \cycle:    btst    #gtf_b_Labels,d4
  1187.     beq.s    \cy1
  1188.     move.l    #GTCY_Labels,(a2)+
  1189.     move.l    (a3)+,(a2)+
  1190. \cy1:    btst    #gtf_b_Active,d4
  1191.     beq.s    \cy2
  1192.     move.l    #GTCY_Active,(a2)+
  1193.     move.l    (a3)+,(a2)+
  1194. \cy2:    rts
  1195.     
  1196. ;------------------
  1197. ; String tags handling.
  1198. ;
  1199. \string:
  1200. ;    bsr    \calibborder
  1201.     btst    #gtf_b_String,d4
  1202.     beq.s    \st1
  1203.     move.l    #GTST_String,(a2)+
  1204.     move.l    (a3)+,(a2)+
  1205. \st1:    btst    #gtf_b_MaxChars,d4
  1206.     beq.s    \st2
  1207.     move.l    #GTST_MaxChars,(a2)+
  1208.     move.l    (a3)+,(a2)+
  1209. \st2:    btst    #gtf_b_RightJustified,d4
  1210.     beq.s    \st3
  1211.     move.l    #STRINGA_Justification,(a2)+
  1212.     move.l    #$400,(a2)+
  1213. \st3:    btst    #gtf_b_TabCycle,d4
  1214.     beq.s    \st4
  1215.     move.l    #GA_TabCycle,(a2)+
  1216.     move.l    d1,(a2)+
  1217. \st4:    btst    #gtf_b_EditHook,d4
  1218.         beq.s   \st5
  1219.     move.l    #GTST_EditHook,(a2)+
  1220.     move.l    (a3)+,(a2)+
  1221. \st5:    rts
  1222.  
  1223.  
  1224. ;------------------
  1225. ; Text tags handling.
  1226. ;
  1227. \text:    btst    #gtf_b_Text,d4
  1228.     beq.s    \tx1
  1229.     move.l    #GTTX_Text,(a2)+
  1230.     move.l    (a3)+,(a2)+
  1231. \tx1:    btst    #gtf_b_CopyText,d4
  1232.     beq.s    \tx2
  1233.     move.l    #GTTX_CopyText,(a2)+
  1234.     move.l    d1,(a2)+
  1235. \tx2:    btst    #gtf_b_Border,d4
  1236.     beq.s    \tx3
  1237.     move.l    #GTTX_Border,(a2)+
  1238.     move.l    d1,(a2)+    
  1239. \tx3:    rts
  1240.  
  1241. ;------------------
  1242. ; PosInfo handling.
  1243. \posinfo:    
  1244.     move.l    (a3)+,a0
  1245.     move.l    gtf_newgadget(pc),(a0)+
  1246.     move.l    gtf_newgadget+4(pc),(a0)+
  1247.     rts
  1248.  
  1249. ;--------------------------------------------------------------------
  1250. ; Special handling of BevelBoxes and Texts.
  1251. ;
  1252. \special:
  1253.     move.l    gtf_intbase(pc),a6
  1254.     lea    gfg_remkey(a5),a0
  1255.     moveq    #gfb_SIZEOF,d0
  1256.     moveq    #1,d1
  1257.     jsr    -396(a6)        ;AllocRemember()
  1258.     move.l    gtf_gadtoolsbase(pc),a6
  1259.     tst.l    d0
  1260.     beq    \gerr
  1261.  
  1262.     move.l    d0,a1
  1263.     lea    gfg_objects(a5),a0
  1264. \spe1:    move.l    (a0),d0
  1265.     beq.s    \spe2
  1266.     move.l    d0,a0
  1267.     bra.s    \spe1
  1268. \spe2:    move.l    a1,(a0)
  1269.  
  1270.     clr.l    (a1)+
  1271.     move.l    (a3)+,(a1)+        ;type, flag, x
  1272.     move.l    (a3)+,(a1)+        ;y, x2/stype
  1273.     move.l    (a3)+,(a1)+        ;text/ fill,y2
  1274.     bra    \cre
  1275.  
  1276.     ENDIF
  1277. ;------------------
  1278.  
  1279.  
  1280.  
  1281.  
  1282. ;--------------------------------------------------------------------
  1283. *
  1284. * FreeGList    Free the gadgets in a list.
  1285. *
  1286. * INPUT:    a1    GadgetKey.
  1287. *
  1288. ;--------------------------------------------------------------------
  1289.  
  1290. ;------------------
  1291.     IFD    xxx_FreeGList
  1292. FreeGList:
  1293.  
  1294. ;------------------
  1295. ; Start:
  1296. ;
  1297. \do:    movem.l    d0-a6,-(sp)
  1298.     move.l    gtf_gadtoolsbase(pc),a6
  1299.     move.l    a1,a5
  1300.     move.l    gfg_gadgets(a1),d0
  1301.     beq.s    \done
  1302.     move.l    d0,a0
  1303.     clr.l    gfg_gadgets(a1)
  1304.     jsr    -36(a6)            ;FreeGadgets()
  1305.  
  1306.     move.l    gtf_intbase(pc),a6
  1307.     lea    gfg_remkey(a5),a0
  1308.     moveq    #-1,d0
  1309.     jsr    -408(a6)        ;FreeRemember()
  1310.  
  1311.     move.l    gfg_gnumof(a5),d0
  1312.     lsl.l    #2,d0
  1313.     addq.l    #4,d0            ;to prevent 0 size allocs!
  1314.     move.l    gfg_table(a5),a1
  1315.     move.l    4.w,a6
  1316.     jsr    -210(a6)        ;FreeMem()
  1317.  
  1318. \done:    movem.l    (sp)+,d0-a6
  1319.     rts
  1320.  
  1321.     ENDIF
  1322. ;------------------
  1323.  
  1324.  
  1325.  
  1326.  
  1327. ;--------------------------------------------------------------------
  1328. *
  1329. * AddGList    Add a gadget list to the window.
  1330. *
  1331. * INPUT:    a1    GadgetKey.
  1332. *
  1333. ;--------------------------------------------------------------------
  1334.  
  1335. ;------------------
  1336.     IFD    xxx_AddGList
  1337. AddGList:
  1338.  
  1339. ;------------------
  1340. ; Do.
  1341. ;
  1342. \do:    movem.l    d0-a6,-(sp)
  1343.     move.l    a1,a5
  1344.     CALL_    PaintObjects
  1345.     move.l    gfg_gadgets(a5),d7
  1346.     move.l    gfg_window(a5),a4
  1347.  
  1348.     move.l    gfw_window(a4),a0
  1349.     move.l    d7,a1
  1350.     moveq    #-1,d0
  1351.     moveq    #-1,d1
  1352.     move.l    gtf_intbase(pc),a6
  1353.     jsr    -438(a6)        ;AddGList()
  1354.  
  1355.     move.l    gfw_window(a4),a1
  1356.     move.l    d7,a0
  1357.     move.l    gfg_numof(a5),d0    ;only refresh the new ones..
  1358.     jsr    -432(a6)        ;RefreshGList()
  1359.  
  1360.     move.l    4.w,a6
  1361.     lea    gfw_glists(a4),a0
  1362.     move.l    a5,a1
  1363.     jsr    -246(a6)        ;AddTail()
  1364.  
  1365.     CALL_    gtf_doidcmp
  1366.  
  1367.     movem.l    (sp)+,d0-a6
  1368.     rts
  1369.  
  1370.     ENDIF
  1371.     IFD    xxx_gtf_doidcmp
  1372.  
  1373. ;------------------
  1374. ; Modify IDCMP for new lists.
  1375. ;
  1376. gtf_doidcmp:
  1377.     move.l    gfw_glists(a4),a0
  1378.     move.l    gfw_idcmp(a4),d0
  1379.     or.l    #gtf_MINIDCMP,d0
  1380.  
  1381. \l1:    move.l    (a0),d1
  1382.     beq.s    \done
  1383.     or.l    gfg_idcmp(a0),d0
  1384.     move.l    d1,a0
  1385.     bra.s    \l1
  1386.  
  1387. \done:    move.l    gtf_intbase(pc),a6
  1388.     move.l    gfw_window(a4),a0
  1389.     jsr    -150(a6)        ;ModifyIDCMP()
  1390.     rts
  1391.  
  1392.     ENDIF
  1393. ;------------------
  1394.  
  1395.  
  1396.  
  1397.  
  1398. ;--------------------------------------------------------------------
  1399. *
  1400. * RemGList    Remove a gadget list again.
  1401. *
  1402. * INPUT:    a1    GadgetKey.
  1403. *
  1404. ;--------------------------------------------------------------------
  1405.  
  1406. ;------------------
  1407.     IFD    xxx_RemGList
  1408. RemGList:
  1409.  
  1410. ;------------------
  1411. ; Do.
  1412. ;
  1413. \do:    movem.l    d0-a6,-(sp)
  1414.     move.l    a1,a5
  1415.     move.l    gfg_gadgets(a1),d0    ;key used?
  1416.     beq.s    \done
  1417.     move.l    4.w,a6
  1418.     jsr    -252(a6)
  1419.  
  1420.     move.l    gfg_window(a5),a4
  1421.     CALL_    gtf_doidcmp
  1422.  
  1423.     move.l    gfg_gadgets(a5),d7
  1424.     move.l    gfg_numof(a5),d0    ;there is always at least ONE!
  1425.         move.l  d0,d6
  1426.     move.l    d7,a1
  1427.     move.l    gfw_window(a4),a0
  1428.     move.l    gtf_intbase(pc),a6
  1429.     jsr    -444(a6)        ;RemoveGList()
  1430.  
  1431.         move.l  d7,a0
  1432. \loop:  subq.l  #1,d6
  1433.         beq.s   \yo
  1434.         move.l  (a0),a0
  1435.         bra.s   \loop
  1436. \yo:    clr.l    (a0)            ;clear last of list for FreeGList()
  1437.  
  1438. \done:    movem.l    (sp)+,d0-a6
  1439.     rts
  1440.  
  1441.     ENDIF
  1442. ;------------------
  1443.  
  1444.  
  1445.  
  1446.  
  1447. ;--------------------------------------------------------------------
  1448. *
  1449. * RefreshWindow        Refresh a window with all gadget lists etc.
  1450. *
  1451. * INPUT:    a2    WindowKey.
  1452. *
  1453. ;--------------------------------------------------------------------
  1454.  
  1455. ;------------------
  1456.     IFD    xxx_RefreshWindow
  1457. RefreshWindow:
  1458.  
  1459. ;------------------
  1460. ; Do.
  1461. ;
  1462. \do:    movem.l    d0-a6,-(a7)
  1463.  
  1464.     move.l    gtf_intbase(pc),a6
  1465.     move.l    gfw_window(a2),a0
  1466.     move.l    a0,d0
  1467.     beq.s    .out
  1468.     jsr    -456(a6)        ;RefreshWindowFrame()    
  1469.  
  1470.     move.l    gfw_window(a2),a0
  1471.     move.l    gtf_gadtoolsbase(pc),a6
  1472.     suba.l    a1,a1
  1473.     jsr    -84(a6)            ;GT_RefreshWindow()
  1474.  
  1475. .out:    movem.l    (sp)+,d0-a6
  1476.     rts
  1477.  
  1478.     ENDIF
  1479. ;------------------
  1480.  
  1481.  
  1482.  
  1483.  
  1484. ;--------------------------------------------------------------------
  1485. *
  1486. * RefreshEventHandler    Used when a REFRESH is required due to sizeing.
  1487. *
  1488. * INPUT:    a2    WindowKey.
  1489. *
  1490. ;--------------------------------------------------------------------
  1491.  
  1492. ;------------------
  1493.     IFD    xxx_RefreshEventHandler
  1494. RefreshEventHandler:
  1495.  
  1496. ;------------------
  1497. ; Do.
  1498. ;
  1499. \do:    movem.l    d0-a6,-(a7)
  1500.     move.l    gfw_window(a2),d7
  1501.     beq.s    .out
  1502.  
  1503.     move.l    gtf_gadtoolsbase(pc),a6
  1504.     move.l    d7,a0
  1505.     jsr    -90(a6)            ;GT_BeginRefresh()
  1506.  
  1507.     moveq    #-1,d0
  1508.     move.l    d7,a0
  1509.     move.l    gtf_gadtoolsbase(pc),a6
  1510.     jsr    -96(a6)            ;GT_EndRefresh()
  1511.  
  1512.     move.l    a2,a4
  1513.  
  1514.     move.w    gfw_clear(a4),d0
  1515.     beq.s    \nopattern1
  1516.  
  1517.     CALL_    ClearWindow
  1518.  
  1519. \nopattern1:
  1520.     movea.l    gfw_glists(a4),a3
  1521.     move.l    a3,d7
  1522.     beq.s    \done
  1523.  
  1524. \loop:    move.l    (a3),d7
  1525.     beq.s    \done
  1526.     move.l    a3,a1
  1527.     CALL_    PaintObjects
  1528.     move.l    d7,a3
  1529.     bra.s    \loop
  1530.  
  1531. \done:    move.w    gfw_clear(a4),d0
  1532.     beq.s    \nopattern
  1533.  
  1534.     move.l    gtf_intbase(pc),a6
  1535.     move.l    gfw_window(a4),a0
  1536.     jsr    -456(a6)        ;RefreshWindowFrame()    
  1537.  
  1538. \nopattern:
  1539.     move.l    gfw_window(a4),a0
  1540.     move.l    gtf_gadtoolsbase(pc),a6
  1541.     suba.l    a1,a1
  1542.     jsr    -84(a6)            ;GT_RefreshWindow()
  1543.  
  1544. .out:    movem.l    (sp)+,d0-a6
  1545.     rts
  1546.  
  1547.     ENDIF
  1548. ;------------------
  1549.  
  1550.  
  1551.  
  1552.  
  1553. ;--------------------------------------------------------------------
  1554. *
  1555. * WaitForWindow    Wait for a message to arrive at the window. Only returns
  1556. *        if there is one.
  1557. *
  1558. * INPUT:    a2    WindowKey.
  1559. *
  1560. ;--------------------------------------------------------------------
  1561.  
  1562. ;------------------
  1563.     IFD    xxx_WaitForWindow
  1564. WaitForWindow:
  1565.  
  1566. ;------------------
  1567. ; Do!
  1568. ;
  1569. \do:    movem.l    d0-a6,-(sp)
  1570.     move.l    gfw_window(a2),a0
  1571.     move.l    86(a0),d7
  1572.  
  1573. \wait:    move.l    d7,a0
  1574.     move.l    4.w,a6
  1575.     jsr    -384(a6)            ;WaitPort()
  1576.     tst.l    d0
  1577.     beq.s    \wait
  1578.     movem.l    (sp)+,d0-a6
  1579.     rts
  1580.  
  1581.     ENDIF
  1582. ;------------------
  1583.  
  1584.  
  1585.  
  1586.  
  1587. ;--------------------------------------------------------------------
  1588. *
  1589. * WaitForWindowAndSignals    Wait for a message to arrive at the window.
  1590. *                Also waits for a given signal set.
  1591. *
  1592. * INPUT:    a2    WindowKey.
  1593. *        d0    Signals.
  1594. *
  1595. * RESULT:    d0    Signals received.
  1596. *        d1.b    -1 if there is a message to get with GetGTFMsg
  1597. *
  1598. ;--------------------------------------------------------------------
  1599.  
  1600. ;------------------
  1601.     IFD    xxx_WaitForWindowAndSignals
  1602. WaitForWindowAndSignals:
  1603.  
  1604. ;------------------
  1605. ; Do!
  1606. ;
  1607. \do:    movem.l    d2-a6,-(sp)
  1608.     move.l    gfw_window(a2),a0
  1609.     move.l    86(a0),a0
  1610.     move.b    15(a0),d7
  1611.     bset    d7,d0
  1612.  
  1613.     move.l    4.w,a6
  1614.     jsr    -318(a6)        ;Wait()
  1615.     btst    d7,d0
  1616.     sne    d1
  1617.  
  1618.     movem.l    (sp)+,d2-a6
  1619.     rts
  1620.  
  1621.     ENDIF
  1622. ;------------------
  1623.  
  1624.  
  1625.  
  1626.  
  1627. ;--------------------------------------------------------------------
  1628. *
  1629. * GetGTFMsg    Get a message from GTFace. This does also track window
  1630. *        size changes!
  1631. *
  1632. * INPUT:    a2    WindowKey.
  1633. *
  1634. * RESULT:    d0    IDCMP that came in or 0.
  1635. *        a2    WindowKey. If there was a message, the information
  1636. *            contained is put in the gfw_msg* fields.
  1637. *        ccr    On d0.
  1638. *
  1639. ;--------------------------------------------------------------------
  1640.  
  1641. ;------------------
  1642.     IFD    xxx_GetGTFMsg
  1643. GetGTFMsg:
  1644.  
  1645. ;------------------
  1646. ; Do!
  1647. ;
  1648. \do:    movem.l    d1-a6,-(sp)
  1649.     move.l    a2,a5
  1650.     moveq    #0,d0
  1651.     move.l    gfw_window(a5),a0
  1652.     move.l    a0,d1
  1653.     beq.s    \done
  1654.     move.l    86(a0),a0
  1655.     move.l    gtf_gadtoolsbase(pc),a6
  1656.     jsr    -72(a6)            ;GT_GetIMsg
  1657.     tst.l    d0
  1658.     beq.s    \done
  1659.  
  1660. ;------------------
  1661. ; Read message fields!
  1662. ;
  1663. \read:    move.l    d0,a0
  1664.     move.l    $14(a0),gfw_msgidcmp(a5)    ;idcmp bits
  1665.     move.l    $18(a0),gfw_msgcode(a5)        ;code and qualifier
  1666.     move.l    $1c(a0),gfw_msgaddr(a5)        ;address of object
  1667.     move.l    $20(a0),gfw_msgmousex(a5)    ;mousex/y
  1668.     move.l    $24(a0),gfw_msgseconds(a5)    ;seconds
  1669.     move.l    $28(a0),gfw_msgmicros(a5)    ;micros
  1670.  
  1671.     move.l    d0,a1
  1672.     jsr    -78(a6)            ;GT_ReplyIMsg()
  1673.     move.l    gfw_msgidcmp(a5),d0
  1674.  
  1675. ;------------------
  1676. ; Check if we must track window size changes...
  1677. ;
  1678. \sized:    cmp.l    #$02000000,d0        ;IDCMP_CHANGEWINDOW??
  1679.     bne.s    \done
  1680.  
  1681.     move.l    gfw_window(a5),a0
  1682.     lea    gfw_zoomxpos(a5),a1
  1683.     btst    #4,24(a0)        ;WFLG_ZOOMED??
  1684.     bne.s    \copy
  1685.  
  1686.     move.w    10(a0),d1
  1687.     sub.w    gfw_vertbd(a5),d1
  1688.     move.w    d1,-(a1)        ;inner heigth...    
  1689.     move.w    8(a0),d1
  1690.     sub.w    gfw_horbd(a5),d1
  1691.     move.w    d1,-(a1)        ;inner width...
  1692.     subq.l    #8,a1
  1693.  
  1694. \copy:    move.l    4(a0),(a1)+
  1695.     move.l    8(a0),(a1)
  1696.  
  1697. \done:    movem.l    (sp)+,d1-a6
  1698.     rts
  1699.  
  1700.     ENDIF
  1701. ;------------------
  1702.  
  1703.  
  1704.  
  1705.  
  1706. ;--------------------------------------------------------------------
  1707. *
  1708. * ClearWindow    Fill the entier inside of the window with a line
  1709. *        pattern or with color 0.
  1710. *
  1711. * INPUT:    d0    Color.
  1712. *        a2    WindowKey.
  1713. *
  1714. ;--------------------------------------------------------------------
  1715.  
  1716. ;------------------
  1717.     IFD    xxx_ClearWindow
  1718. ClearWindow:
  1719.  
  1720. ;------------------
  1721. ; Do.
  1722. ;
  1723. \do:    movem.l    d0-a6,-(a7)
  1724.     tst.l    gfw_window(a2)
  1725.     beq.s    .out
  1726.     CALL_    LockWindow
  1727.  
  1728.     move.w    d0,d4
  1729.     move.w    d0,gfw_clear(a2)
  1730.  
  1731.     move.l    gfw_window(a2),a3
  1732.     move.w    8(a3),d2
  1733.     move.w    10(a3),d3
  1734.     moveq    #0,d0
  1735.     move.b    $38(a3),d0
  1736.     sub.w    d0,d2
  1737.     move.b    $39(a3),d0
  1738.     sub.w    d0,d3
  1739.  
  1740.     move.w    gfw_lefto(a2),d0
  1741.     move.w    gfw_topo(a2),d1
  1742.  
  1743.     CALL_    gtf_rectfill
  1744.  
  1745. \no:    CALL_    UnLockWindow
  1746. .out:    movem.l    (sp)+,d0-a6
  1747.     rts    
  1748.  
  1749.     ENDIF
  1750.     IFD    xxx_gtf_rectfill
  1751.  
  1752. ;------------------
  1753. ; RectFill() subroutine.
  1754. ;
  1755. ;    d0-d3    Coords & size.
  1756. ;    d4    Color.
  1757. ;    a3    Window.
  1758. ;
  1759. gtf_rectfill:
  1760.     movem.l    d0-d3,-(sp)
  1761.  
  1762.     move.l    gtf_gfxbase(pc),a6
  1763.  
  1764.     move.l    50(a3),a1
  1765.     move.l    d4,d0    
  1766.     jsr    -342(a6)        ;SetAPen()
  1767.     move.l    50(a3),a1
  1768.     moveq    #1,d0    
  1769.     jsr    -354(a6)        ;SetDrMd()
  1770.     movem.l    (sp)+,d0-d3
  1771.  
  1772.     subq.w    #1,d2
  1773.     subq.w    #1,d3
  1774.  
  1775.     cmp.w    d2,d0
  1776.     bge.s    \do
  1777.     cmp.w    d3,d1
  1778.     bge.s    \do
  1779.  
  1780.     move.l    50(a3),a1
  1781.     move.l    8(a1),-(sp)
  1782.     move.l    gtf_pattern(pc),8(a1)
  1783.     clr.b    $1d(a1)
  1784.     jsr    -306(a6)        ;RectFill()
  1785.     move.l    50(a3),a1
  1786.     move.l    (sp)+,8(a1)
  1787.     
  1788. \do:    rts
  1789.  
  1790.     ENDIF
  1791. ;------------------
  1792.  
  1793.  
  1794.  
  1795.  
  1796. ;--------------------------------------------------------------------
  1797. *
  1798. * PaintObjects    Refresh all objects of a gadget list.
  1799. *
  1800. * INPUT:    a1    GadgetKey.
  1801. *
  1802. ;--------------------------------------------------------------------
  1803.  
  1804. ;------------------
  1805.     IFD    xxx_PaintObjects
  1806. PaintObjects:
  1807.  
  1808. ;------------------
  1809. ; Do.
  1810. ;
  1811. \do:    movem.l    d0-a6,-(sp)
  1812.     lea    gfg_objects(a1),a3
  1813.     move.l    gfg_window(a1),a4
  1814.     move.l    gfw_window(a4),a5
  1815.     move.l    $32(a5),a5        ;RasterPort
  1816.  
  1817. \loop:    move.l    (a3),d7
  1818.     beq    \done
  1819.     move.l    d7,a3
  1820.     addq.l    #4,a3
  1821.     tst.b    (a3)+
  1822.     beq.s    \text
  1823.  
  1824. \bevel:    lea    gtf_beveltags(pc),a1
  1825.     move.l    gfw_visualinfo(a4),4(a1)
  1826.     tst.b    (a3)+
  1827.     beq.s    \norec
  1828.     subq.l    #8,a1
  1829. \norec:    move.l    a5,a0
  1830.     move.w    (a3)+,d0
  1831.     CALL_    gtf_scaled0x
  1832.     move.w    d0,d4
  1833.     move.w    (a3)+,d0
  1834.     CALL_    gtf_scaled0y
  1835.     move.w    d0,d1
  1836.     move.w    (a3)+,d0
  1837.     CALL_    gtf_scaled0x
  1838.     move.w    d0,d2
  1839.     move.w    (a3)+,d0
  1840.     CALL_    gtf_scaled0y
  1841.     move.w    d0,d3
  1842.     move.w    d4,d0
  1843.     add.w    gfw_lefto(a4),d0
  1844.     add.w    gfw_topo(a4),d1
  1845.     move.l    gtf_gadtoolsbase(pc),a6
  1846.     movem.l    d0-d3,-(sp)
  1847.     jsr    -120(a6)            ;DrawBevelBoxA()
  1848.     movem.l    (sp)+,d0-d3
  1849.  
  1850. \fill:    move.w    (a3)+,d4
  1851.     bmi.s    \next
  1852.  
  1853.     CALL_    LockWindow
  1854.  
  1855.     subq.w    #4,d2
  1856.     subq.w    #2,d3
  1857.     addq.w    #2,d0
  1858.     addq.w    #1,d1
  1859.     add.w    d0,d2
  1860.     add.w    d1,d3
  1861.     move.l    gfw_window(a4),a3
  1862.     CALL_    gtf_rectfill
  1863.  
  1864.     CALL_    UnLockWindow
  1865.  
  1866. \next:    move.l    d7,a3
  1867.     bra.s    \loop
  1868.  
  1869. \text:    move.b    (a3)+,d3
  1870.     move.w    (a3)+,d0
  1871.     move.w    (a3)+,d1
  1872.     move.w    (a3)+,d2
  1873.     move.l    (a3)+,a0
  1874.     tst.b    d3
  1875.     beq.s    \noptr
  1876.     move.l    (a0),a0
  1877. \noptr:    move.l    a4,a2
  1878.     CALL_    PrintScaled
  1879.     bra.s    \next
  1880.  
  1881. \done:    movem.l    (sp)+,d0-a6
  1882.     rts
  1883.  
  1884.     ENDIF
  1885. ;------------------
  1886.  
  1887.  
  1888.  
  1889.  
  1890. ;--------------------------------------------------------------------
  1891. *
  1892. * AddMenu    Generate and add a menu.
  1893. *
  1894. * INPUT:    a0    Menu structure.
  1895. *        a2    WindowKey.
  1896. *
  1897. * RESULT:    d0    0 if failure.
  1898. *        ccr    On d0.
  1899. *
  1900. ;--------------------------------------------------------------------
  1901.  
  1902. ;------------------
  1903.     IFD    xxx_AddMenu
  1904. AddMenu:
  1905.     NEED_    SetMenu
  1906.  
  1907. ;------------------
  1908. ; Do.
  1909. ;
  1910. \do:    CALL_    GenMenu
  1911.     bne.s    SetMenu
  1912.     rts
  1913.  
  1914.     ENDIF
  1915. ;------------------
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921. ;--------------------------------------------------------------------
  1922. *
  1923. * GenMenu    Generate a menu.
  1924. *
  1925. * INPUT:    a0    Menu structure.
  1926. *        a2    WindowKey.
  1927. *
  1928. * RESULT:    d0    Menu strip or 0 if failure.
  1929. *        ccr    On d0.
  1930. *
  1931. ;--------------------------------------------------------------------
  1932.  
  1933. ;------------------
  1934.     IFD    xxx_GenMenu
  1935. GenMenu:
  1936.  
  1937. ;------------------
  1938. ; Do.
  1939. ;
  1940. \do:    movem.l    d1-a6,-(sp)
  1941.     move.l    a2,a4
  1942.     lea    gtf_tagend(pc),a1
  1943.     move.l    gtf_gadtoolsbase(pc),a6
  1944.     jsr    -48(a6)            ;CreateMenus()
  1945.     move.l    d0,d7
  1946.     beq.s    \done
  1947.  
  1948.     move.l    gfw_visualinfo(a4),a1
  1949.     move.l    d7,a0
  1950.     lea    \newlooktag(pc),a2
  1951.     jsr    -66(a6)            ;LayoutMenus()
  1952.     tst.l    d0
  1953.     beq.s    \done
  1954.     move.l    d7,d0
  1955.  
  1956. \done:    movem.l    (sp)+,d1-a6
  1957.     rts
  1958.  
  1959. \newlooktag:
  1960.     IFD    GTMN_NewLookMenus
  1961.     dc.l    GTMN_NewLookMenus,1
  1962.     ENDC
  1963.     dc.l    TAG_DONE
  1964.  
  1965.     ENDIF
  1966. ;------------------
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972. ;--------------------------------------------------------------------
  1973. *
  1974. * SetMenu    Set a menu strip.
  1975. *
  1976. * INPUT:    d0    Menu strip.
  1977. *        a2    WindowKey.
  1978. *
  1979. ;--------------------------------------------------------------------
  1980.  
  1981. ;------------------
  1982.     IFD    xxx_SetMenu
  1983. SetMenu:
  1984.  
  1985. ;------------------
  1986. ; Do.
  1987. ;
  1988. \do:    movem.l    d0-a6,-(sp)
  1989.     move.l    a2,a4
  1990.     move.l    gtf_intbase(pc),a6
  1991.     move.l    gfw_window(a4),a0
  1992.     move.l    d0,a1
  1993.     move.l    d0,gfw_menu(a4)
  1994.     jsr    -264(a6)        ;SetMenuStrip()
  1995.     
  1996. \done:    movem.l    (sp)+,d0-a6
  1997.     rts
  1998.  
  1999.     ENDIF
  2000. ;------------------
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006. ;--------------------------------------------------------------------
  2007. *
  2008. * RemMenu    Remove and deallocate the menu.
  2009. *
  2010. * INPUT:    a2    WindowKey.
  2011. *
  2012. ;--------------------------------------------------------------------
  2013.  
  2014. ;------------------
  2015.     IFD    xxx_RemMenu
  2016. RemMenu:
  2017.  
  2018. ;------------------
  2019. ; Do.
  2020. ;
  2021. \do:    CALL_    StripMenu
  2022.     JUMP_    FreeMenu
  2023.  
  2024.     ENDIF
  2025. ;------------------
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031. ;--------------------------------------------------------------------
  2032. *
  2033. * StripMenu    Remove the menu.
  2034. *
  2035. * INPUT:    a2    WindowKey.
  2036. *
  2037. ;--------------------------------------------------------------------
  2038.  
  2039. ;------------------
  2040.     IFD    xxx_StripMenu
  2041. StripMenu:
  2042.  
  2043. ;------------------
  2044. ; Do.
  2045. ;
  2046. \do:    movem.l    d0-a6,-(sp)
  2047.     move.l    gtf_intbase(pc),a6
  2048.     move.l    gfw_window(a2),a0
  2049.     clr.b    gfw_domenu(a2)        ;for CallMenu()
  2050.     jsr    -54(a6)            ;ClearMenuStrip()
  2051.     movem.l    (sp)+,d0-a6
  2052.     rts
  2053.  
  2054.     ENDIF
  2055. ;------------------
  2056.  
  2057.  
  2058.  
  2059.  
  2060. ;--------------------------------------------------------------------
  2061. *
  2062. * FreeMenu    Free a menu.
  2063. *
  2064. * INPUT:    a2    WindowKey.
  2065. *
  2066. ;--------------------------------------------------------------------
  2067.  
  2068. ;------------------
  2069.     IFD    xxx_FreeMenu
  2070. FreeMenu:
  2071.  
  2072. ;------------------
  2073. ; Do.
  2074. ;
  2075. \do:    movem.l    d0-a6,-(sp)
  2076.     move.l    gtf_gadtoolsbase(pc),a6
  2077.     move.l    gfw_menu(a2),d0
  2078.     beq.s    \done
  2079.     move.l    d0,a0
  2080.     clr.l    gfw_menu(a2)
  2081.     jsr    -54(a6)            ;FreeMenu()
  2082.  
  2083. \done:    movem.l    (sp)+,d0-a6
  2084.     rts
  2085.  
  2086.     ENDIF
  2087. ;------------------
  2088.  
  2089.  
  2090.  
  2091.  
  2092. ;--------------------------------------------------------------------
  2093. *
  2094. * (Un)LockWindow    Lock or unlock the window for graphics.
  2095. * (Un)LockPubScreen    Lock or unlock the screen.
  2096. *
  2097. * INPUT:    a2    WindowKey.
  2098. *
  2099. ;--------------------------------------------------------------------
  2100.  
  2101. ;------------------
  2102.     IFD    xxx_LockWindow
  2103. LockWindow:
  2104.  
  2105. ;------------------
  2106. ; Do!
  2107. ;
  2108. \do:    movem.l    a5/a6,-(sp)
  2109.     move.l    gtf_gfxbase(pc),a6
  2110.     move.l    gfw_window(a2),a5
  2111.     move.l    $7c(a5),a5        ;Layer!
  2112.     jsr    -432(a6)        ;LockLayerRom()
  2113.     movem.l    (sp)+,a5/a6
  2114.     rts
  2115.  
  2116.     ENDIF
  2117. ;------------------
  2118.     IFD    xxx_UnLockWindow
  2119. UnLockWindow:
  2120.  
  2121. ;------------------
  2122. ; Do!
  2123. ;
  2124. \do:    movem.l    d0-a6,-(sp)
  2125.     move.l    gtf_gfxbase(pc),a6
  2126.     move.l    gfw_window(a2),a5
  2127.     move.l    $7c(a5),a5        ;Layer!
  2128.     jsr    -438(a6)        ;UnLockLayerRom()
  2129.     movem.l    (sp)+,d0-a6
  2130.     rts
  2131.  
  2132.     ENDIF
  2133. ;------------------
  2134.     IFD    xxx_LockPubScreen
  2135. LockPubScreen:
  2136.  
  2137. ;------------------
  2138. ; Do!
  2139. ;
  2140. \do:    movem.l    d1-a6,-(sp)
  2141.     move.b    gtf_locked(pc),d0
  2142.     bne.s    \okay
  2143.     move.l    gtf_intbase(pc),a6
  2144.     move.l    gtf_pubscreenname(pc),a0
  2145.     jsr    -510(a6)        ;LockPubScreen()
  2146.     clr.l    gtf_pubscreenname
  2147.     lea    gtf_screen(pc),a0
  2148.     move.l    d0,(a0)
  2149.     beq    \done
  2150.     lea    gtf_locked(pc),a0
  2151.     st.b    (a0)
  2152. \okay:    move.l    gtf_screen(pc),d0
  2153. \done:    movem.l    (sp)+,d1-a6
  2154.     rts
  2155.  
  2156.     ENDIF
  2157. ;------------------
  2158.     IFD    xxx_UnLockPubScreen
  2159. UnLockPubScreen:
  2160.  
  2161. ;------------------
  2162. ; Do!
  2163. ;
  2164. \do:    movem.l    d0-a6,-(sp)
  2165.     move.b    gtf_locked(pc),d0
  2166.     beq.s    \done
  2167.     move.l    gtf_screen(pc),a1
  2168.     suba.l    a0,a0
  2169.     move.l    gtf_intbase(pc),a6
  2170.     jsr    -516(a6)        ;UnLockPubScreen()
  2171.     lea    gtf_locked(pc),a0
  2172.     clr.b    (a0)
  2173. \done:    movem.l    (sp)+,d0-a6
  2174.     rts
  2175.  
  2176.     ENDIF
  2177. ;------------------
  2178.  
  2179.  
  2180.  
  2181.  
  2182. ;--------------------------------------------------------------------
  2183. *
  2184. * CallGadget    Call the gadget handler for a gadget.
  2185. *
  2186. * INPUT:    a2    WindowKey.
  2187. *        a0    Info list.
  2188. *
  2189. * Handler gets called with:
  2190. *
  2191. *        a1    Gadget address.
  2192. *        a2    WindowKey.
  2193. *
  2194. ;--------------------------------------------------------------------
  2195.  
  2196. ;------------------
  2197.     IFD    xxx_CallGadget
  2198. CallGadget:
  2199.  
  2200. ;------------------
  2201. ; Do!
  2202. ;
  2203. \do:    movem.l    d0-a6,-(sp)
  2204.     tst.l    (a2)
  2205.     beq.s    \done
  2206.     moveq    #$40,d0
  2207.     cmp.l    gfw_msgidcmp(a2),d0
  2208.     bne.s    \done
  2209.     move.l    gfw_msgaddr(a2),a1
  2210.     move.w    $26(a1),d0
  2211.     move.w    d0,d1
  2212.     CALL_    FindGadget        ;does that gadget exist?
  2213.     beq.s    \done
  2214.  
  2215. \loop:    tst.w    (a0)
  2216.     beq.s    \done
  2217.     cmp.w    (a0)+,d1
  2218.     bne.s    \next
  2219.     move.w    (a0),d0
  2220.  
  2221.     pea    \done(pc)
  2222.     lea    gtf_base(pc),a0
  2223.     jmp    (a0,d0)
  2224.  
  2225. \next:    addq.w    #2,a0
  2226.     bra.s    \loop
  2227.     
  2228. \done:    movem.l    (sp)+,d0-a6
  2229.     rts
  2230.  
  2231.     ENDIF
  2232. ;------------------
  2233.  
  2234.  
  2235.  
  2236. ;--------------------------------------------------------------------
  2237. *
  2238. * CallKey    Call the key handler for a key.
  2239. *
  2240. * INPUT:    a2    WindowKey.
  2241. *        a0    Info list.
  2242. *
  2243. ;--------------------------------------------------------------------
  2244.  
  2245. ;------------------
  2246.     IFD    xxx_CallKey
  2247. CallKey:
  2248.  
  2249. ;------------------
  2250. ; Do!
  2251. ;
  2252. \do:    movem.l    d0-a6,-(sp)
  2253.     tst.l    (a2)
  2254.     beq.s    \done
  2255.     move.w    gfw_msgcode(a2),d0
  2256.  
  2257. \loop:    tst.w    (a0)
  2258.     beq.s    \done
  2259.     cmp.w    (a0)+,d0
  2260.     bne.s    \next
  2261.     move.w    (a0),d0
  2262.  
  2263.     pea    \done(pc)
  2264.     lea    gtf_base(pc),a0
  2265.     jmp    (a0,d0)
  2266.  
  2267. \next:    addq.w    #2,a0
  2268.     bra.s    \loop
  2269.     
  2270. \done:    movem.l    (sp)+,d0-a6
  2271.     rts
  2272.  
  2273.     ENDIF
  2274. ;------------------
  2275.  
  2276.  
  2277.  
  2278. ;--------------------------------------------------------------------
  2279. *
  2280. * CallMenu    Call the menu handler for a menu selection.
  2281. *
  2282. * INPUT:    a2    WindowKey.
  2283. *        a0    Info list.
  2284. *
  2285. ;--------------------------------------------------------------------
  2286.  
  2287. ;------------------
  2288.     IFD    xxx_CallMenu
  2289. CallMenu:
  2290.  
  2291. ;------------------
  2292. ; Do!
  2293. ;
  2294. \do:    movem.l    d0-a6,-(sp)
  2295.     cmp.l    #$100,gfw_msgidcmp(a2)
  2296.     bne.s    \done
  2297.     move.w    gfw_msgcode(a2),d0
  2298.     st.b    gfw_domenu(a2)
  2299.     move.l    a0,a3
  2300.  
  2301. \loop:    tst.l    (a2)            ;maybe menu point removes window?
  2302.     beq.s    \done
  2303.     move.l    gfw_menu(a2),d1
  2304.     beq.s    \done
  2305.     move.l    d1,a0
  2306.     move.l    gtf_intbase(pc),a6
  2307.     jsr    -144(a6)        ;ItemAddress()
  2308.     tst.l    d0
  2309.     beq.s    \done
  2310.     move.l    d0,a1
  2311.     btst    #4,13(a1)        ;enabled?
  2312.     beq.s    \next
  2313.     move.l    a3,a0
  2314.     move.w    $22(a1),d0
  2315.  
  2316. \find:    tst.w    (a0)
  2317.     beq.s    \next
  2318.     cmp.w    (a0)+,d0
  2319.     bne.s    \no
  2320.     move.w    (a0),d0
  2321.     movem.l    a1/a2/a3,-(sp)
  2322.     lea    gtf_base(pc),a0
  2323.     jsr    (a0,d0.w)
  2324.     movem.l    (sp)+,a1/a2/a3
  2325.     bra.s    \next
  2326.  
  2327. \no:    addq.w    #2,a0
  2328.     bra.s    \find
  2329.  
  2330. \next:    tst.b    gfw_domenu(a2)
  2331.     beq.s    \done
  2332.     move.w    $20(a1),d0
  2333.     bra.s    \loop
  2334.     
  2335. \done:    movem.l    (sp)+,d0-a6
  2336.     rts
  2337.  
  2338.     ENDIF
  2339. ;------------------
  2340.  
  2341.  
  2342.  
  2343.  
  2344. ;--------------------------------------------------------------------
  2345. *
  2346. * PrintScaledList    Print a linked list of IntuiTexts.
  2347. *
  2348. * INPUT:    a2    WindowKey.
  2349. *        a0    IntuiText list. 0 allowed.
  2350. *
  2351. ;--------------------------------------------------------------------
  2352.  
  2353. ;------------------
  2354.     IFD    xxx_PrintScaledList
  2355. PrintScaledList:
  2356.  
  2357. ;------------------
  2358. ; Do!
  2359. ;
  2360. \do:    movem.l    d0-a6,-(sp)
  2361.     move.l    a0,d0
  2362.     beq.s    \end
  2363.  
  2364. \loop:    move.l    d0,a3
  2365.     move.b    (a3),d2
  2366.     lsl.w    #8,d2
  2367.     move.b    1(a3),d2
  2368.     move.w    6(a3),d1
  2369.     move.w    4(a3),d0
  2370.     move.l    12(a3),a0
  2371.     CALL_    PrintScaled
  2372.     move.l    16(a3),d0
  2373.     bne.s    \loop
  2374.  
  2375. \end:    movem.l    (sp)+,d0-a6
  2376.     rts
  2377.  
  2378.     ENDIF
  2379. ;------------------
  2380.  
  2381.  
  2382.  
  2383.  
  2384. ;--------------------------------------------------------------------
  2385. *
  2386. * PrintScaled    Print a one-line text, scaled.
  2387. *
  2388. * INPUT:    a0    Text.
  2389. *        d0    X position in inner window, for topaz80.
  2390. *        d1    Y position in inner window, for topaz80.
  2391. *        d2    (B Pen)*256+A Pen.
  2392. *        a2    WindowKey.
  2393. *
  2394. ;--------------------------------------------------------------------
  2395.  
  2396. ;------------------
  2397.     IFD    xxx_PrintScaled
  2398. PrintScaled:
  2399.  
  2400. ;------------------
  2401. ; Do!
  2402. ;
  2403. \do:    movem.l    d0-a6,-(sp)
  2404.     move.l    a2,a4
  2405.  
  2406.     lea    gtf_intuitext(pc),a1
  2407.     move.l    a1,a2
  2408.     move.b    d2,(a2)+
  2409.     lsr.w    #8,d2
  2410.     move.b    d2,(a2)+
  2411.     move.w    #$100,(a2)+
  2412.     CALL_    gtf_scaled0x
  2413.     move.w    d0,(a2)+
  2414.     move.w    d1,d0
  2415.     CALL_    gtf_scaled0y
  2416.     move.w    d0,(a2)+
  2417.     move.l    a0,4(a2)
  2418.  
  2419.     move.l    gfw_window(a4),a0
  2420.     move.l    a0,d0
  2421.     beq.s    .out
  2422.     move.l    50(a0),a0
  2423.     move.w    gfw_lefto(a4),d0
  2424.     move.w    gfw_topo(a4),d1
  2425.     move.l    gtf_intbase(pc),a6
  2426.     jsr    -216(a6)        ;PrintIText()
  2427. .out    movem.l    (sp)+,d0-a6
  2428.     rts
  2429.  
  2430.     ENDIF
  2431. ;------------------
  2432.  
  2433.  
  2434.  
  2435.  
  2436. ;--------------------------------------------------------------------
  2437. *
  2438. * FindGadget    Find a gadget in any of the gadget lists of a window.
  2439. *
  2440. * INPUT:    d0    ID
  2441. *        a2    WindowKey. DO NOT FORGET!
  2442. *
  2443. * RESULT:    d0    Gadget address or 0.
  2444. *        ccr    On d0.
  2445. *
  2446. ;--------------------------------------------------------------------
  2447.  
  2448. ;------------------
  2449.     IFD    xxx_FindGadget
  2450. FindGadget:
  2451.  
  2452. ;------------------
  2453. ; Do.
  2454. ;
  2455. \do:    movem.l    d1/a1,-(sp)
  2456.     move.l    d0,d1
  2457.     move.l    gfw_glists(a2),a1
  2458. \l1:    move.l    a1,d0
  2459.     beq.s    \done
  2460.     tst.l    (a1)
  2461.     beq.s    \none
  2462.     move.l    d1,d0
  2463.     CALL_    FindGadgetInKey
  2464.     bne.s    \done
  2465.     move.l    (a1),a1
  2466.     bra.s    \l1
  2467.  
  2468. \none:    moveq    #0,d0
  2469. \done:    movem.l    (sp)+,d1/a1
  2470.     rts
  2471.  
  2472.     ENDIF
  2473. ;------------------
  2474.  
  2475.  
  2476.  
  2477.  
  2478. ;--------------------------------------------------------------------
  2479. *
  2480. * FindGadgetInKey    Find a gadget in a GadgetKey. It needn't to be added
  2481. *            to the window yet.
  2482. *
  2483. * INPUT:    d0    ID
  2484. *        a1    GadgetKey
  2485. *
  2486. * RESULT:    d0    Gadget address or 0.
  2487. *        ccr    On d0.
  2488. *
  2489. ;--------------------------------------------------------------------
  2490.  
  2491. ;------------------
  2492.     IFD    xxx_FindGadgetInKey
  2493. FindGadgetInKey:
  2494.  
  2495. ;------------------
  2496. ; Do.
  2497. ;
  2498. \do:    movem.l    d1/d2/a0/a1,-(sp)
  2499.     move.l    gfg_table(a1),a0
  2500.     moveq    #0,d2
  2501.     move.l    gfg_gnumof(a1),d1
  2502.     beq.s    \done
  2503.  
  2504. \l2:    move.l    (a0)+,a1
  2505.     cmp.w    $26(a1),d0
  2506.     bne.s    \n1
  2507.     move.l    a1,d2
  2508.     bra.s    \done
  2509.  
  2510. \n1:    subq.l    #1,d1
  2511.     bne.s    \l2
  2512.  
  2513. \done:    move.l    d2,d0
  2514.     movem.l    (sp)+,d1/d2/a0/a1
  2515.     rts
  2516.  
  2517.     ENDIF
  2518. ;------------------
  2519.  
  2520.  
  2521.  
  2522.  
  2523. ;--------------------------------------------------------------------
  2524.  
  2525. ;------------------
  2526. ; Two scaling subroutines.
  2527. ;
  2528. ;    d0=position
  2529. ;    a4=WindowKey
  2530. ;
  2531.     IFD    xxx_gtf_scaled0x
  2532. gtf_scaled0x:
  2533.     mulu    gfw_fontx(a4),d0
  2534.     addq.l    #7,d0
  2535.     lsr.l    #3,d0
  2536.     rts
  2537.     ENDIF
  2538.  
  2539.     IFD    xxx_gtf_scaled0y
  2540. gtf_scaled0y:
  2541.     mulu    gfw_fonty(a4),d0
  2542.     addq.l    #7,d0
  2543.     lsr.l    #3,d0
  2544.     rts
  2545.     ENDIF
  2546.  
  2547. ;------------------
  2548.  
  2549. ;--------------------------------------------------------------------
  2550.  
  2551. ;------------------
  2552. ; Includes.
  2553. ;
  2554.     IFND    ely_defined
  2555.     include    graphicslib.r
  2556.     include    intuitionlib.r
  2557.     ENDIF
  2558.  
  2559. ;------------------
  2560. ; Data.
  2561.     IFND    ely_defined
  2562. gtf_gadtoolsbase:    dc.l    0
  2563.     ENDIF
  2564. gtf_pubscreenname:    dc.l    0
  2565. gtf_topazfont:        dc.l    0
  2566. gtf_defaultfont:    dc.l    0
  2567. gtf_screen:        dc.l    0
  2568. gtf_prev:        dc.l    0
  2569. gtf_refgnum:        dc.l    0
  2570. gtf_pattern:        dc.l    0
  2571. gtf_status:        dc.b    0
  2572. gtf_locked:        dc.b    0
  2573.  
  2574. gtf_pubscreenfallback:    dc.b    -1    ;turned on as default
  2575. gtf_nolimscale:        dc.b    0    ;turn off scaling of min/max values
  2576.  
  2577.  
  2578.     IFD    xxx_gtf_tagspace
  2579. gtf_tagspace:        ds.l    30,0
  2580.     ENDIF
  2581.  
  2582.     IFD    xxx_OpenScaledWindow
  2583. gtf_minmax        dc.l    0,0
  2584.     ENDIF
  2585.  
  2586.     IFD    xxx_gtf_newgadget
  2587. gtf_newgadget:        ds.b    30,0
  2588.     ENDIF
  2589.  
  2590.     IFND    ely_defined
  2591. gtf_gadtoolsname:    dc.b    "gadtools.library",0,0
  2592.     ENDIF
  2593.  
  2594. ;------------------
  2595. ; The text attribute structures.
  2596. ;
  2597. gtf_topazattr:
  2598.     dc.l    0
  2599.     dc.w    8
  2600.     dc.b    0,%01000001
  2601. gtf_topazname:
  2602.     dc.b    "topaz.font",0,0
  2603.  
  2604. gtf_defaultattr:
  2605.     dc.l    0
  2606.     dc.w    0
  2607.     dc.b    0,0
  2608.  
  2609. gtf_intuitext:
  2610.     dc.l    0,0,0,0,0
  2611.  
  2612. gtf_beveltags2:
  2613.     dc.l    GTBB_Recessed,-1
  2614. gtf_beveltags:
  2615.     dc.l    GT_VisualInfo,0
  2616. gtf_tagend:
  2617.     dc.l    0
  2618.  
  2619. ;------------------
  2620.  
  2621. ;--------------------------------------------------------------------
  2622.  
  2623. ;------------------
  2624.     base    gtf_oldbase
  2625.  
  2626. ;------------------
  2627.     endif
  2628.  
  2629.     end
  2630.  
  2631.