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

  1. #include "FiveWin.ch"
  2. #include "Constant.ch"
  3.  
  4.  
  5. #define LTGRAY_BRUSH       1
  6. #define TRANSPARENT        1
  7.  
  8. #define SS_CENTER          1
  9.  
  10. #define DLGC_BUTTON     8192   // 0x2000
  11.  
  12. #define COLOR_WINDOW       5
  13. #define COLOR_WINDOWTEXT   8
  14.  
  15. #define WM_NCHITTEST     132  // 0x84
  16.  
  17. //----------------------------------------------------------------------------//
  18.  
  19. CLASS TSay FROM TControl
  20.  
  21.    DATA   lBorder, lCenter
  22.    DATA   cPicture
  23.    DATA   bGet
  24.  
  25.    METHOD New( nRow, nCol, bText, oWnd, cPicture, oFont,;
  26.                lCentered, lBorder, lPixels, nClrText, nClrBack,;
  27.                nWidth, nHeight, lDesign, lUpdate ) CONSTRUCTOR
  28.  
  29.    METHOD ReDefine( nId, bText, oWnd, lCentered, lBorder, nClrText,;
  30.                     nClrBack, lUpdate, oFont )  CONSTRUCTOR
  31.  
  32.    METHOD cToChar() INLINE  Super:cToChar( "STATIC" )
  33.  
  34.    METHOD Default()
  35.  
  36.    METHOD cGenPrg()
  37.  
  38.    METHOD HandleEvent( nMsg, nWParam, nLParam )
  39.  
  40.    METHOD Init( hDlg )
  41.  
  42.    METHOD Refresh() INLINE If( ::bGet != nil, ::SetText( Eval( ::bGet ) ),)
  43.  
  44.    METHOD SetText( cText ) INLINE ;
  45.                     ::cCaption := If( ::cPicture != nil,;
  46.                                   Transform( cText, ::cPicture ),;
  47.                                   cValToChar( cText ) ),;
  48.                     SetWindowText( ::hWnd, ::cCaption )
  49.  
  50. ENDCLASS
  51.  
  52. //----------------------------------------------------------------------------//
  53.  
  54. METHOD New( nRow, nCol, bText, oWnd, cPicture, oFont,;
  55.             lCentered, lBorder, lPixels, nClrText, nClrBack,;
  56.             nWidth, nHeight, lDesign, lUpdate ) CLASS TSay
  57.  
  58.    DEFAULT lBorder  := .f., lCentered := .f., lPixels := .f.,;
  59.            oWnd     := GetWndDefault(),;
  60.            nClrText := oWnd:nClrText, nClrBack := oWnd:nClrPane,;
  61.            nHeight  := If( oFont != nil, Abs( oFont:nHeight ), SAY_CHARPIX_H ),;
  62.            lDesign  := .f., bText := { || "" },;
  63.            lUpdate  := .f.
  64.  
  65.    ::bGet      = bText
  66.    ::cPicture  = cPicture
  67.    ::cCaption  = If( Empty( cPicture ), cValToChar( Eval( bText ) ),;
  68.                      Transform( Eval( bText ), cPicture ) )
  69.  
  70.    DEFAULT nWidth := ( If( oFont != nil, Abs( oFont:nWidth ), SAY_CHARPIX_W ) * Len( ::cCaption ) ) - 4     // 8
  71.  
  72.    ::lBorder = lBorder
  73.    ::lCenter = lCentered
  74.  
  75.    if ! lPixels
  76.       ::nTop  = nRow * If( oFont != nil, Abs( oFont:nHeight ), SAY_CHARPIX_H ) + 2      // 13
  77.       ::nLeft = nCol * If( oFont != nil, Abs( oFont:nWidth ), SAY_CHARPIX_W )             // 8
  78.    else
  79.       ::nTop  = nRow
  80.       ::nLeft = nCol
  81.    endif
  82.  
  83.    ::nBottom   = ::nTop + nHeight - 1
  84.    ::nRight    = ::nLeft + nWidth - 1
  85.  
  86.    ::oWnd      = oWnd
  87.    ::oFont     = oFont
  88.    ::nId       = ::GetNewId()
  89.    ::nStyle    = nOR( WS_CHILD, WS_VISIBLE ,;
  90.                       If( ::lCenter , SS_CENTER, SS_LEFT ),;
  91.                       If( ::lBorder, WS_BORDER, 0 ),;
  92.                       If( lDesign, WS_THICKFRAME, 0 ) )
  93.    ::lDrag     = lDesign
  94.    ::lCaptured = .f.
  95.    ::lUpdate   = lUpdate
  96.  
  97.    ::SetColor( nClrText, nClrBack )
  98.  
  99.    if oWnd:lVisible
  100.       ::Create( "STATIC" )
  101.       ::Default()
  102.       oWnd:AddControl( Self )
  103.    else
  104.       oWnd:DefControl( Self )
  105.    endif
  106.  
  107. return nil
  108.  
  109. //----------------------------------------------------------------------------//
  110.  
  111. METHOD ReDefine( nId, bText, oWnd, cPicture, lCentered, lBorder,;
  112.                  nClrText, nClrBack, lUpdate, oFont ) CLASS TSay
  113.  
  114.    DEFAULT lCentered := .f., lBorder := .f.,;
  115.            nClrText  := oWnd:nClrText, nClrBack := oWnd:nClrPane,;
  116.            lUpdate   := .f.
  117.  
  118.    ::nId       = nId
  119.    ::bGet      = bText
  120.    ::cPicture  = cPicture
  121.    ::oFont     = oFont
  122.  
  123.    if bText != nil
  124.       ::cCaption = If( Empty( cPicture ), cValToChar( Eval( bText ) ),;
  125.                        Transform( Eval( bText ), cPicture ) )
  126.    endif
  127.  
  128.    ::oWnd      = oWnd
  129.    ::hWnd      = 0
  130.    ::lBorder   = lBorder
  131.    ::lCenter   = lCentered
  132.    ::lDrag     = .f.
  133.    ::lCaptured = .f.
  134.    ::lUpdate   = lUpdate
  135.  
  136.    ::SetColor( nClrText, nClrBack )
  137.    oWnd:DefControl( Self )
  138.  
  139. return nil
  140.  
  141. //----------------------------------------------------------------------------//
  142.  
  143. METHOD Init( hDlg ) CLASS TSay
  144.  
  145.    Super:Init( hDlg )
  146.  
  147.    if ! Empty( ::cCaption )
  148.       SetWindowText( ::hWnd, ::cCaption )
  149.    else
  150.       ::cCaption = GetWindowText( ::hWnd )
  151.    endif
  152.  
  153. return nil
  154.  
  155. //----------------------------------------------------------------------------//
  156.  
  157. METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TSay
  158.  
  159.    if ::lDrag .and. nMsg == WM_NCHITTEST      // To have a standard behavior on Clicks
  160.       return DefWindowProc( ::hWnd, nMsg, nWParam, nLParam )
  161.    endif
  162.  
  163. return Super:HandleEvent( nMsg, nWParam, nLParam )
  164.  
  165. //----------------------------------------------------------------------------//
  166.  
  167. METHOD Default() CLASS TSay
  168.  
  169.    if ::oFont != nil
  170.       ::SetFont( ::oFont )
  171.    else
  172.       ::SetFont( ::oWnd:oFont )
  173.    endif
  174.  
  175. return nil
  176.  
  177. //----------------------------------------------------------------------------//
  178.  
  179. METHOD cGenPrg() CLASS TSay
  180.  
  181.    local cCode := CRLF + "   @ " + Str( ::nTop, 3 ) + ", " + ;
  182.                   Str( ::nLeft, 3 ) + ' SAY "' + ::cCaption + ;
  183.                   '" SIZE ' + Str( ::nRight - ::nTop, 3 ) + ", " + ;
  184.                   Str( ::nBottom - ::nTop, 3 ) + " PIXEL OF oWnd" + CRLF
  185. return cCode
  186.  
  187. //----------------------------------------------------------------------------//
  188.