Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

xtextbox.cpp

Go to the documentation of this file.
00001 #include "SdlArs.h"
00002 
00003 namespace Ars
00004 {
00005 XTextBox::XTextBox( void )
00006 : vScrollBar( 0 )
00007 {
00008         vScrollBar = new XScrollBar();
00009 }
00010 
00011 XTextBox::~XTextBox( void )
00012 {
00013         if( vScrollBar )
00014                 delete vScrollBar;
00015         vScrollBar = 0;
00016 }
00017 
00018 void XTextBox::Init( icstring &aStr )
00019 {
00020         XLabel::Init( aStr );
00021 
00022         vScrollBar->SetFgColor( GetFgColor() );
00023         vScrollBar->SetBgColor( GetBgColor() );
00024         vScrollBar->SetFont( GetFont() );
00025         vScrollBar->SetState( S_SUNKEN );
00026         vScrollBar->SetFlags( F_NONE );
00027         icstring tmp = Rsrc::FindCrdOf( aStr, "scrollbar" );
00028         vScrollBar->Init( tmp );
00029 
00030         vScrollBar->SetWindowRect( XRect( Right() - 20, y , 20 , Height() ) );
00031 }
00032 
00033 const bool XTextBox::SetupWindow( const Message &msg )
00034 {
00035         XLabel::SetupWindow( msg );
00036 
00037         vScrollBar->SetParent( this );
00038         vScrollBar->SetupWindow( msg );
00039 
00040         MessageServer::Instance().RegisterMessageClient(this, Message::CTRL_VALUECHANGE);
00041         MessageServer::Instance().RegisterMessageClient(this, Message::CTRL_VALUECHANGING);
00042 
00043         return true;
00044 }
00045 
00046 void XTextBox::DrawBG( void )
00047 {
00048         w -= 21;
00049         XLabel::DrawBG();
00050         w += 21;
00051 }
00052 
00053 void XTextBox::Draw(void)
00054 {
00055         w -= 21;
00056         XBox::Draw();
00057         w += 21;
00058         XRect r( GetClientRect() );
00059         r.w -= 21;
00060 
00061         int iStartIndex = vScrollBar->GetPosition();
00062         int     n = (Height() + GetFontSize() - 1) / GetFontSize();
00063 
00064         for( int j = 0; j < n ; ++j )
00065         {
00066                 int     i = j + iStartIndex;
00067                 if( i < (int)textList.size() )
00068                 {
00069                         XRect ItemRect( r.x , r.y + (i - iStartIndex) * GetFontSize() , r.Width() , GetFontSize() );
00070                         if( ItemRect.Overlaps(r ) )
00071                         {
00072                                 ItemRect.ClipTo( r );
00073                                 ItemRect.SetBottom(ItemRect.Bottom() - 1);
00074                                 ItemRect.Grow(-1);
00075                                 TextOutStr( ItemRect ,  textList[i] , GetFgColor() );
00076                         }
00077                 }
00078         }
00079 }
00080 
00081 void XTextBox::SetWndText( const std::string &sWindowText )
00082 {
00083         XLabel::SetWndText( sWindowText );
00084 
00085         textList.clear();
00086 
00087         size_t  n0 = 0 , n1 = sWindowText.find( '\n' , n0 );
00088         while( n1 != string::npos )
00089         {
00090                 textList.push_back( sWindowText.substr( n0 , n1 - n0 ) );
00091                 n0 = n1 + 1;
00092                 n1 = sWindowText.find( '\n' , n0 );
00093         }
00094         int iMax = textList.size() + 1;
00095         int     n = Height() / GetFontSize();
00096         iMax -= n;
00097         vScrollBar->SetLimits( 0 , max( 0 , iMax ) );
00098         SetDirty( true );
00099 }
00100 
00101 void XTextBox::SetWindowRect( const XRect &WindowRect )
00102 {
00103         XLabel::SetWindowRect( WindowRect );
00104 
00105         XRect ScrollbarRect( *this );
00106         ScrollbarRect.Grow(-1);
00107         vScrollBar->SetWindowRect( XRect( ScrollbarRect.Right() - 12 , ScrollbarRect.y , ScrollbarRect.Width(), ScrollbarRect.Height() ) );
00108         clientRect = XRect( 2 , 2 , Width() - 16 , Height() - 4 );
00109 }
00110 
00111 const bool XTextBox::evValueChange( const CtrlMessage &msg )
00112 {
00113         bool ans = XLabel::evValueChange( msg );
00114 
00115         if( !textList.empty() )
00116         {
00117                 if( msg.source == vScrollBar )
00118                 {
00119                         SetDirty();
00120                         ans = true;
00121                 }
00122         }
00123         return ans;
00124 }
00125 
00126 const bool XTextBox::evValueChanging( const CtrlMessage &msg )
00127 {
00128         bool ans = XLabel::evValueChanging( msg );
00129 
00130         if( !textList.empty() )
00131         {
00132                 if( msg.source == vScrollBar )
00133                 {
00134                         SetDirty();
00135                         ans = true;
00136                 }
00137         }
00138         return ans;
00139 }
00140 
00141 }

Generated on Fri Dec 5 04:06:01 2003 for Borqueror by doxygen 1.3.3