Example #1
0
// Show      - Show the titletip if needed.
// rectTitle - The rectangle within which the original title
//             is constrained - in client coordinates.
// cpcTitleText - The text to be displayed.
// nOffsetX  - Number of pixels that the text is offset from
//             the left border of the cell.
void
ZListTip::Show( CRect rectTitle, zCPCHAR cpcTitleText,
                int nOffsetX /* = 0 */,
                LPRECT pHoverRect /* = 0 */,
                const LOGFONT *pLogFont /* = 0 */,
                COLORREF clrText /* = CLR_DEFAULT */,
                COLORREF clrBack /* = CLR_DEFAULT */ )
{
#ifdef DEBUG_ALL
   TraceLine( "ZListTip::Show %s   Delay: %d", cpcTitleText, m_lHoverDelay );
#endif

   m_csTitle = cpcTitleText;

   // If window is not valid, display rect is empty, text is empty,
   // title tip is already displayed, or app does not have focus ...
   // don't do anything.
   if ( mIs_hWnd( m_hWnd ) == 0 || rectTitle.IsRectEmpty( ) ||
        cpcTitleText == 0 || *cpcTitleText == 0 ||
        mIs_hWndVisible( m_hWnd ) || GetFocus( ) == 0 )
   {
      return;
   }

   // Define the rectangle outside which the titletip will be hidden.
   // We add a buffer of one pixel around the rectangle.
   m_rectTitle.top = -1;
   m_rectTitle.left = -1;
   m_rectTitle.right = rectTitle.Width( );
   m_rectTitle.bottom = rectTitle.Height( ) + 1;

   // Determine the width of the text.
   m_pParentWnd->ClientToScreen( rectTitle );

   CClientDC dc( this );
   CFont *pFontDC;
// if ( pLogFont )
// {
//    CFont font;
//    font.CreateFontIndirect( pLogFont );
//    pFontDC = dc.SelectObject( &font );
// }
// else
   {
      // Use same font as ctrl.
      pFontDC = dc.SelectObject( m_pParentWnd->GetFont( ) );
   }

   m_nOffsetX = nOffsetX - 1;
   CRect rectDisplay = rectTitle;
   CSize size = dc.GetTextExtent( m_csTitle );
   rectDisplay.top--;
   rectDisplay.left--;
   rectDisplay.right = rectDisplay.left + size.cx + 2 * m_nOffsetX;
   dc.SelectObject( pFontDC );

   if ( rectDisplay.right > rectTitle.right + 1 )
   {
      UINT uFlags = SWP_NOACTIVATE;
      if ( m_lHoverDelay == 0 )
      {
         uFlags |= SWP_SHOWWINDOW;
      }
      else
      if ( m_lHoverDelay > 0 )
      {
         if ( m_uToolTipTimerId )
            KillTimer( m_uToolTipTimerId );

         m_uToolTipTimerId = SetTimer( g_nIdShowToolTipEvt, m_lHoverDelay, 0 );
      // TraceLine( "ZListTip::Show Timer Id: %d", m_uToolTipTimerId );
      }

      SetWindowPos( &wndTop, rectDisplay.left, rectDisplay.top,
                    rectDisplay.Width( ), rectDisplay.Height( ), uFlags );
      DrawTipText( );
      SetCapture( );
   }
}