home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4611 / fw16d.ins / SOURCE / CLASSES / BTNBMP.PRG < prev    next >
Text File  |  1994-06-12  |  7KB  |  275 lines

  1. #include "FiveWin.ch"
  2.  
  3. #define LTGRAY_BRUSH 1
  4. #define RT_BITMAP    2
  5.  
  6. static lRegistered := .f.
  7.  
  8. //----------------------------------------------------------------------------//
  9.  
  10. CLASS TBtnBmp FROM TControl
  11.  
  12.    DATA   bAction, cMsg
  13.    DATA   lPressed, lCaptured, lAdjust
  14.    DATA   hBmpPal1, hBmpPal2
  15.  
  16.    METHOD New( nTop, nLeft, nWidth, nHeight,;
  17.                cResName1, cResName2, cBmpFile1, cBmpFile2,;
  18.                bAction, oWnd, cMsg ) CONSTRUCTOR
  19.  
  20.    METHOD NewBar( cResName1, cResName2, cBmpFile1, cBmpFile2,;
  21.                   cMsg, bAction, lGroup, oBar, lAdjust ) CONSTRUCTOR
  22.  
  23.    METHOD Click()
  24.    METHOD FreeBitmaps()
  25.    METHOD cGenPRG()
  26.    METHOD HandleEvent( nMsg, nWParam, nLParam )
  27.    METHOD LButtonDown()
  28.    METHOD LButtonUp( nRow, nCol )
  29.    METHOD LoadBitmaps( cResName1, cResName2, cBmpFile1, cBmpFile2 )
  30.  
  31.    METHOD Paint() INLINE ;
  32.           PalBtnPaint( ::hWnd, ::hBmpPal1, ::hBmpPal2, ::lPressed, ::lAdjust )
  33.  
  34.    METHOD MouseMove( nRow, nCol, nKeyFlags )
  35.    METHOD Release()
  36.    METHOD SetFile( cBmpUpFile, cBmpDownFile )
  37.  
  38. ENDCLASS
  39.  
  40. //----------------------------------------------------------------------------//
  41.  
  42. METHOD New( nTop, nLeft, nWidth, nHeight,;
  43.             cResName1, cResName2, cBmpFile1, cBmpFile2,;
  44.             bAction, oWnd, cMsg )  CLASS TBtnBmp
  45.    
  46.    DEFAULT cMsg := " "
  47.  
  48.    ::nStyle    = nOR( WS_BORDER, WS_CHILD, WS_VISIBLE )
  49.    ::nId       = ::GetNewId()
  50.    ::oWnd      = oWnd
  51.    ::bAction   = bAction
  52.    ::cMsg      = cMsg
  53.    ::nTop      = nTop
  54.    ::nLeft     = nLeft
  55.    ::nBottom   = nTop + nHeight - 1
  56.    ::nRight    = nLeft + nWidth - 1
  57.    ::lPressed  = .f.
  58.    ::lDrag     = .f.
  59.    ::lCaptured = .f.
  60.    ::nClrPane  = GetStockObject( LTGRAY_BRUSH )
  61.  
  62.    ::hBmpPal1  = 0
  63.    ::hBmpPal2  = 0
  64.  
  65.    if ! lRegistered
  66.       ::Register( nOR( CS_VREDRAW, CS_HREDRAW, CS_GLOBALCLASS ) )
  67.       lRegistered = .t.
  68.    endif
  69.  
  70.    if oWnd:lVisible
  71.       ::Create()
  72.    else
  73.       oWnd:DefControl( Self )
  74.    endif
  75.  
  76.    ::LoadBitmaps( cResName1, cResName2, cBmpFile1, cBmpFile2 )
  77.  
  78. return nil
  79.  
  80. //----------------------------------------------------------------------------//
  81.  
  82. METHOD NewBar( cResName1, cResName2, cBmpFile1, cBmpFile2, cMsg, bAction,;
  83.                lGroup, oBar, lAdjust ) CLASS TBtnBmp
  84.  
  85.    DEFAULT cMsg := "", lAdjust := .f.
  86.  
  87.    ::nStyle    = nOR( WS_BORDER, WS_CHILD, WS_VISIBLE )
  88.    ::nId       = ::GetNewId()
  89.    ::oWnd      = oBar
  90.    ::bAction   = bAction
  91.    ::cMsg      = cMsg
  92.    ::nTop      = oBar:GetBtnTop( lGroup )
  93.    ::nLeft     = oBar:GetBtnLeft( lGroup )
  94.    ::nBottom   = ::nTop + oBar:nBtnHeight + 1 - If( oBar:l3D, 6, 0 )
  95.    ::nRight    = ::nLeft + oBar:nBtnWidth - If( oBar:l3D, 2, 0 )
  96.    ::lPressed  = .f.
  97.    ::lCaptured = .f.
  98.    ::lDrag     = .f.
  99.    ::lAdjust   = lAdjust
  100.    ::nClrPane  = CLR_LIGHTGRAY
  101.  
  102.    ::hBmpPal1  = 0
  103.    ::hBmpPal2  = 0
  104.  
  105.    if ! lRegistered
  106.       ::Register( nOR( CS_VREDRAW, CS_HREDRAW, CS_GLOBALCLASS ) )
  107.       lRegistered = .t.
  108.    endif
  109.  
  110.    ::Create()
  111.    oBar:Add( Self )
  112.  
  113.    ::LoadBitmaps( cResName1, cResName2, cBmpFile1, cBmpFile2 )
  114.  
  115. return nil
  116.  
  117. //----------------------------------------------------------------------------//
  118.  
  119. METHOD Click() CLASS TBtnBmp
  120.  
  121.    if ::bAction != nil
  122.       Eval( ::bAction )
  123.    endif
  124.  
  125. return nil
  126.  
  127. //----------------------------------------------------------------------------//
  128.  
  129. METHOD cGenPRG() CLASS TBtnBmp
  130.  
  131.    local cPrg := ""
  132.  
  133.    cPrg += CRLF + CRLF + "   DEFINE BUTTON OF oBar " + ;
  134.               'ACTION MsgInfo( "Not defined yet" )'
  135.  
  136. return cPrg
  137.  
  138. //----------------------------------------------------------------------------//
  139.  
  140. METHOD HandleEvent( nMsg, nWParam, nLParam )  CLASS TBtnBmp
  141.  
  142.     do case
  143.        case nMsg == WM_LBUTTONUP
  144.             return ::LButtonUp( nHiWord( nLParam ), nLoWord( nLParam ) )
  145.  
  146.        case nMsg == WM_PAINT
  147.             ::BeginPaint()
  148.             ::Paint()
  149.             ::EndPaint()
  150.             return 0
  151.     endcase
  152.  
  153. return Super:HandleEvent( nMsg, nWParam, nLParam )  
  154.  
  155. //---------------------------------------------------------------------------//
  156.  
  157. METHOD LButtonDown()  CLASS TBtnBmp
  158.  
  159.     ::lPressed  = .t.
  160.     ::lCaptured = .t.
  161.     ::Capture()
  162.     ::Refresh( .f. )
  163.  
  164. return 0
  165.  
  166. //----------------------------------------------------------------------------//
  167.  
  168. METHOD LButtonUp( nRow, nCol )  CLASS TBtnBmp
  169.  
  170.    local lClick := IsOverWnd( ::hWnd, nRow, nCol )
  171.  
  172.    if ::lCaptured
  173.       ::lCaptured = .f.
  174.       if ::lPressed
  175.          ::lPressed = .f.
  176.          ::Refresh( .f. )
  177.       endif
  178.       ReleaseCapture()
  179.       if lClick
  180.          ::Click()
  181.       endif
  182.    endif
  183.  
  184. return 0
  185.  
  186. //----------------------------------------------------------------------------//
  187.  
  188. METHOD Release() CLASS TBtnBmp
  189.  
  190.    ::FreeBitmaps()
  191.    Super:Release()
  192.  
  193. return 0
  194.  
  195. //----------------------------------------------------------------------------//
  196.  
  197. METHOD SetFile( cBmpUpFile, cBmpDownFile ) CLASS TBtnBmp
  198.  
  199.    ::FreeBitmaps()
  200.    ::LoadBitmaps( nil, nil, cBmpUpFile, cBmpDownFile )
  201.    ::Refresh()
  202.  
  203. return nil
  204.  
  205. //----------------------------------------------------------------------------//
  206.  
  207. METHOD FreeBitmaps() CLASS TBtnBmp
  208.  
  209.    if ::hBmpPal1 != 0
  210.       PalBmpFree( ::hBmpPal1 )
  211.    endif
  212.  
  213.    if ::hBmpPal2 != 0
  214.       PalBmpFree( ::hBmpPal2 )
  215.    endif
  216.  
  217.    ::hBmpPal1 = 0
  218.    ::hBmpPal2 = 0
  219.  
  220. return nil
  221.  
  222. //----------------------------------------------------------------------------//
  223.  
  224. METHOD LoadBitmaps( cResName1, cResName2, cBmpFile1, cBmpFile2 ) CLASS TBtnBmp
  225.  
  226.    if ! Empty( cResName1 )
  227.       ::hBmpPal1 := PalBmpLoad( cResName1 )
  228.    endif
  229.  
  230.    if ! Empty( cResName2 )
  231.       ::hBmpPal2 := PalBmpLoad( cResName2 )
  232.    endif
  233.  
  234.    if ! Empty( cBmpFile1 )
  235.       if File( cBmpFile1 )
  236.          ::hBmpPal1  := PalBmpRead( ::GetDC(), cBmpFile1 )
  237.          ::ReleaseDC()
  238.       endif
  239.    endif
  240.  
  241.    if ! Empty( cBmpFile2 )
  242.       if File( cBmpFile2 )
  243.          ::hBmpPal2  := PalBmpRead( ::GetDC(), cBmpFile2 )
  244.          ::ReleaseDC()
  245.       endif
  246.    endif
  247.  
  248.    if !empty( ::hBmpPal1 )
  249.       PalBmpNew( ::hWnd, ::hBmpPal1 )
  250.    endif
  251.  
  252.    if !empty( ::hBmpPal2 )
  253.       PalBmpNew( ::hWnd, ::hBmpPal2 )
  254.    endif
  255.  
  256. return nil
  257.  
  258. //----------------------------------------------------------------------------//
  259.  
  260. METHOD MouseMove( nRow, nCol, nKeyFlags ) CLASS TBtnBmp
  261.  
  262.    Super:MouseMove( nRow, nCol, nKeyFlags )
  263.  
  264.    if ::lCaptured
  265.       if ::lPressed != IsOverWnd( ::hWnd, nRow, nCol )
  266.          ::lPressed = ! ::lPressed
  267.          ::Refresh( .f. )
  268.       endif
  269.    endif
  270.    ::oWnd:SetMsg( ::cMsg )
  271.  
  272. return 0
  273.  
  274. //----------------------------------------------------------------------------//
  275.