00001 #include "SdlArs.h" 00002 00003 namespace Ars 00004 { 00005 XToolTip::XToolTip( Window *pToolWindow, const int aNrMSec ) 00006 : nrMSec( aNrMSec ) 00007 { 00008 SetParent( pToolWindow ); 00009 timer = new Timer( this ); 00010 } 00011 00012 00013 XToolTip::~XToolTip(void) 00014 { 00015 if( timer ) 00016 delete timer; 00017 timer = 0; 00018 } 00019 00020 const bool XToolTip::SetupWindow( const Message &msg ) 00021 { 00022 XLabel::SetupWindow( msg ); 00023 00024 MessageServer::Instance().RegisterMessageClient(this, Message::MOUSE_MOVE); 00025 MessageServer::Instance().RegisterMessageClient(this, Message::CTRL_TIMER); 00026 00027 HideTip(); 00028 00029 return true; 00030 } 00031 00032 void XToolTip::SetWndText( const std::string &sText ) 00033 { 00034 XLabel::SetWndText( sText ); 00035 XPoint p = GetTextSize( GetWindowText() ); 00036 clientRect.w = w = p.x + 4; 00037 clientRect.h = h = p.y + GetFontSize(); 00038 } 00039 00040 void XToolTip::ShowTip( const XPoint &p ) 00041 { 00042 if( GetParent()->IsVisible() ) 00043 { 00044 x = p.x; 00045 y = p.y; 00046 ShowWindow(); 00047 UpdateWindow( true ); 00048 } 00049 } 00050 00051 00052 void XToolTip::HideTip(void) 00053 { 00054 HideWindow(); 00055 UpdateWindow( true ); 00056 } 00057 00058 const bool XToolTip::evTimer( const CtrlMessage &msg ) 00059 { 00060 bool ans = XLabel::evTimer( msg ); 00061 00062 if( msg.Destination() == this ) 00063 { 00064 ShowTip( lastMousePosition + XPoint( -6 , 18 ) ); 00065 ans = true; 00066 } 00067 return ans; 00068 } 00069 00070 const bool XToolTip::evMouseMove( const MouseMessage &msg ) 00071 { 00072 if( GetParent()->GetParent() ) 00073 { 00074 lastMousePosition = msg.Point; 00075 timer->StopTimer(); 00076 if( IsVisible() ) 00077 HideTip(); 00078 00079 if( GetParent()->FindWindow( &msg.Point ) == GetParent() ) 00080 timer->StartTimer( nrMSec ); 00081 } 00082 return XLabel::evMouseMove( msg ); 00083 } 00084 00085 }