00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "tooltip.hpp"
00026 #include "generic_bitmap.hpp"
00027 #include "generic_font.hpp"
00028 #include "os_factory.hpp"
00029 #include "os_graphics.hpp"
00030 #include "os_tooltip.hpp"
00031 #include "os_timer.hpp"
00032 #include "var_manager.hpp"
00033 #include "../utils/ustring.hpp"
00034
00035
00036 Tooltip::Tooltip( intf_thread_t *pIntf, const GenericFont &rFont, int delay ):
00037 SkinObject( pIntf ), m_rFont( rFont ), m_delay( delay ), m_pImage( NULL ),
00038 m_xPos( -1 ), m_yPos( -1 ), m_cmdShow( this )
00039 {
00040 OSFactory *pOsFactory = OSFactory::instance( pIntf );
00041 m_pTimer = pOsFactory->createOSTimer( m_cmdShow );
00042 m_pOsTooltip = pOsFactory->createOSTooltip();
00043
00044
00045 VarManager::instance( pIntf )->getTooltipText().addObserver( this );
00046 }
00047
00048
00049 Tooltip::~Tooltip()
00050 {
00051 VarManager::instance( getIntf() )->getTooltipText().delObserver( this );
00052 SKINS_DELETE( m_pTimer );
00053 SKINS_DELETE( m_pOsTooltip );
00054 if( m_pImage )
00055 {
00056 delete m_pImage;
00057 }
00058 }
00059
00060
00061 void Tooltip::show()
00062 {
00063
00064 m_pTimer->start( m_delay, true );
00065 }
00066
00067
00068 void Tooltip::hide()
00069 {
00070 m_pTimer->stop();
00071 m_pOsTooltip->hide();
00072 m_xPos = -1;
00073 m_yPos = -1;
00074 }
00075
00076
00077 void Tooltip::onUpdate( Subject<VarText> &rVariable )
00078 {
00079
00080 displayText( ((VarText&)rVariable).get() );
00081 }
00082
00083
00084 void Tooltip::displayText( const UString &rText )
00085 {
00086
00087 makeImage( rText );
00088
00089
00090 if( m_xPos != -1 )
00091 {
00092 m_pOsTooltip->show( m_xPos, m_yPos, *m_pImage );
00093 }
00094 }
00095
00096
00097 void Tooltip::makeImage( const UString &rText )
00098 {
00099
00100 GenericBitmap *pBmpTip = m_rFont.drawString( rText, 0 );
00101 if( !pBmpTip )
00102 {
00103 return;
00104 }
00105 int w = pBmpTip->getWidth() + 10;
00106 int h = m_rFont.getSize() + 8;
00107
00108
00109 if( m_pImage )
00110 {
00111 delete m_pImage;
00112 }
00113 m_pImage = OSFactory::instance( getIntf() )->createOSGraphics( w, h );
00114 m_pImage->fillRect( 0, 0, w, h, 0xffffd0 );
00115 m_pImage->drawRect( 0, 0, w, h, 0x000000 );
00116 m_pImage->drawBitmap( *pBmpTip, 0, 0, 5, 5, -1, -1, true );
00117
00118 delete pBmpTip;
00119 }
00120
00121
00122 void Tooltip::CmdShow::execute()
00123 {
00124 if( m_pParent->m_pImage )
00125 {
00126 if( m_pParent->m_xPos == -1 )
00127 {
00128
00129 OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00130 int x, y;
00131 pOsFactory->getMousePos( x, y );
00132 int scrWidth = pOsFactory->getScreenWidth();
00133 int scrHeight = pOsFactory->getScreenHeight();
00134 int w = m_pParent->m_pImage->getWidth();
00135 int h = m_pParent->m_pImage->getHeight();
00136
00137
00138 x -= (w / 2 + 4);
00139 y += (h + 5);
00140 if( x + w > scrWidth )
00141 x -= (x + w - scrWidth);
00142 else if( x < 0 )
00143 x = 0;
00144 if( y + h > scrHeight )
00145 y -= (2 * h + 20);
00146
00147 m_pParent->m_xPos = x;
00148 m_pParent->m_yPos = y;
00149 }
00150
00151
00152 m_pParent->m_pOsTooltip->show( m_pParent->m_xPos, m_pParent->m_yPos,
00153 *(m_pParent->m_pImage) );
00154 }
00155 }
00156