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
00026
00027
00028
00029 #include <cstring>
00030
00031 #include "pgapplication.h"
00032 #include "pgeventsupplier.h"
00033 #include "pgwidget.h"
00034 #include "pglineedit.h"
00035 #include "pgtooltiphelp.h"
00036
00037
00038
00039 PG_LineEdit* PG_ToolTipHelp::toolTipLabel = NULL;
00040 PG_ToolTipHelp::Ticker* PG_ToolTipHelp::ticker = NULL;
00041
00042
00043 PG_ToolTipHelp :: PG_ToolTipHelp( PG_Widget* parent, const std::string& text, int delay, const std::string &style )
00044 : parentWidget(parent), lastTick(0), status(off), labelStyle(style), my_delay(delay) {
00045 if ( !parent )
00046 return;
00047
00048 parent->sigMouseEnter.connect( SigC::slot( *this, &PG_ToolTipHelp::onParentEnter ), parent );
00049 parent->sigMouseLeave.connect( SigC::slot( *this, &PG_ToolTipHelp::onParentLeave ), parent );
00050 parent->sigMouseMotion.connect( SigC::slot( *this, &PG_ToolTipHelp::onMouseMotion ));
00051 PG_Application::GetApp()->sigAppIdle.connect( SigC::slot( *this, &PG_ToolTipHelp::onIdle ));
00052 PG_Application::GetApp()->EnableAppIdleCalls();
00053
00054 parent->sigDelete.connect( SigC::slot( *this, &PG_ToolTipHelp::onParentDelete ));
00055
00056 SetText( text );
00057 }
00058
00059
00060 void PG_ToolTipHelp :: SetText( const std::string& text ) {
00061 my_text = text;
00062 }
00063
00064 bool PG_ToolTipHelp :: onIdle( ) {
00065 if ( !ticker )
00066 return false;
00067
00068 if ( status != counting )
00069 return false;
00070
00071 if ( status == counting && !parentWidget->IsMouseInside() ) {
00072 status = off;
00073 return false;
00074 }
00075
00076 if ( ticker->getTicker() > lastTick + 10 ) {
00077 if ( status < shown ) {
00078 int x, y;
00079 PG_Application::GetEventSupplier()->GetMouseState( x,y );
00080 ShowHelp( PG_Point(x+5,y+10) );
00081 status = shown;
00082 }
00083 return true;
00084 }
00085 return false;
00086 }
00087
00088
00089 bool PG_ToolTipHelp :: onParentEnter( void* dummy ) {
00090 if ( !ticker )
00091 ticker = new Ticker(100);
00092
00093 status = counting;
00094
00095 lastTick = ticker->getTicker();
00096 return true;
00097 }
00098
00099 bool PG_ToolTipHelp :: onParentLeave( void* dummy ) {
00100
00101 if ( toolTipLabel && toolTipLabel->IsMouseInside() )
00102 return false;
00103
00104 HideHelp();
00105 status = off;
00106 return false;
00107 }
00108
00109
00110 bool PG_ToolTipHelp :: onParentDelete( const PG_MessageObject* object ) {
00111 if ( status != off)
00112 HideHelp();
00113
00114 delete this;
00115 return true;
00116 }
00117
00118 bool PG_ToolTipHelp :: onMouseMotion( const SDL_MouseMotionEvent *motion ) {
00119 if ( ticker )
00120 lastTick = ticker->getTicker();
00121
00122 status = counting;
00123
00124 HideHelp();
00125 return true;
00126 }
00127
00128
00129 void PG_ToolTipHelp :: ShowHelp( const PG_Point& pos ) {
00130 PG_Point mousePos = pos;
00131
00132
00133
00134
00135
00136
00137 if ( toolTipLabel )
00138 delete toolTipLabel;
00139
00140 toolTipLabel = new PG_LineEdit( NULL, PG_Rect( mousePos.x, mousePos.y, 0, 0 ), labelStyle );
00141 toolTipLabel->SetText( my_text );
00142 toolTipLabel->SetEditable( false );
00143
00144 Uint16 w;
00145 Uint16 h;
00146 toolTipLabel->GetTextSize( w, h );
00147
00148 PG_Rect r = *toolTipLabel;
00149 r.w = w + 6;
00150 r.h = h + 4;
00151 if ( r.x + r.w > PG_Application::GetScreen()->w )
00152 r.x = PG_Application::GetScreen()->w - r.w;
00153
00154 if ( r.y + r.h > PG_Application::GetScreen()->h )
00155 r.y = PG_Application::GetScreen()->h - r.h;
00156
00157 toolTipLabel->MoveWidget( r, false );
00158 toolTipLabel->Show();
00159 toolTipLabel->sigMouseMotion.connect( SigC::slot( *this, &PG_ToolTipHelp::onMouseMotion ));
00160 }
00161
00162 void PG_ToolTipHelp :: HideHelp( ) {
00163 if ( toolTipLabel ) {
00164 delete toolTipLabel;
00165 toolTipLabel = NULL;
00166 }
00167 }
00168