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

xdropdown.cpp

Go to the documentation of this file.
00001 #include "SdlArs.h"
00002 
00003 namespace Ars
00004 {
00005 XDropDown::XDropDown( void )
00006 : listBox( 0 ) , dropButton( 0 )
00007 {
00008 }
00009 
00010 void XDropDown::Init( icstring &aStr )
00011 {
00012         XEditBox::Init( aStr );
00013 
00014         XRect r( *this );
00015         r.y += 20;
00016         r.h -= 20;
00017         r.Grow( -1 );
00018         if( !listBox )
00019                 listBox = new XListBox();
00020         listBox->SetWindowRect( r );
00021         listBox->SetBgColor( GetBgColor() );
00022         listBox->SetFgColor( GetFgColor().FadeColor( 32 ) );
00023         listBox->SetFlags( F_NONE );
00024         listBox->SetState( S_SUNKEN );
00025         listBox->SetFont( GetFont() );
00026         icstring        tmp = Rsrc::FindCrdOf( aStr , "listbox" );
00027         listBox->Init( tmp );
00028 
00029         r = *this;
00030         r.h = 20;
00031         r.Grow( -1 );
00032         
00033         tmp = Rsrc::FindCrdOf( aStr , "button" );
00034 
00035         if( !dropButton )
00036                 dropButton = new XButtonImage();
00037         dropButton->SetWindowRect( XRect( r.Right() - 20, r.y , 20 , r.Height() ) );
00038         dropButton->SetBgColor( GetBgColor() );
00039         dropButton->SetFgColor( GetFgColor().FadeColor( 32 ) );
00040         dropButton->SetFlags( F_SELECTABLE );
00041         dropButton->SetState( S_RAISED );
00042         dropButton->SetFont( GetFont() );
00043         dropButton->SetWndText( "\\/" );
00044         dropButton->Init( tmp );
00045 
00046         r = *this;
00047         r.h = 20;
00048         r.w -= 20;
00049         SetWindowRect( r );
00050 }
00051 
00052 const bool XDropDown::SetupWindow( const Message &msg )
00053 {
00054         XEditBox::SetupWindow( msg );
00055         
00056         listBox->SetParent( this );
00057         listBox->SetupWindow( msg );
00058 //      MessageServer::Instance().DeregisterMessageClient( listBox, Message::MOUSE_BUTTONDOWN );
00059 
00060         dropButton->SetParent( this );
00061         dropButton->SetupWindow( msg );
00062 
00063         HideListBox();
00064         MessageServer::Instance().RegisterMessageClient(this, Message::CTRL_LCLICK);
00065         MessageServer::Instance().RegisterMessageClient(this, Message::CTRL_VALUECHANGE);
00066 
00067         return true;
00068 }
00069 
00070 const bool XDropDown::evValueChange( const CtrlMessage &msg )
00071 {
00072         bool ans = XEditBox::evValueChange( msg );
00073 
00074         if( msg.Destination() == this )
00075         {
00076                 if( msg.source == listBox )
00077                 {
00078                         const XListItem &ListItem = listBox->GetItem( msg.value );
00079                         SetWndText( ListItem.itemText );
00080                         HideListBox();
00081                         ArsPostMessage( CtrlMessage( Message::CTRL_VALUECHANGE, GetParent() , this , 0 ) );
00082                         ans = true;
00083                 }
00084                 else if( msg.source == this )
00085                 {
00086                         listBox->SetAllSelections( false );
00087                         HideListBox();
00088                         ArsPostMessage( CtrlMessage( Message::CTRL_VALUECHANGE, GetParent(), this, 0));
00089                         ans = true;
00090                 }
00091         }
00092         return ans;
00093 }
00094 
00095 const bool XDropDown::evMouseLClick( const CtrlMessage &msg )
00096 {
00097         bool ans = XEditBox::evMouseLClick( msg );
00098 
00099         if( msg.source == dropButton )
00100         {
00101                 if( listBox->IsVisible() )
00102                         HideListBox();
00103                 else
00104                         ShowListBox();
00105                 ans = true;
00106         }
00107         return ans;
00108 }
00109 
00110 void XDropDown::ShowListBox( void )
00111 {
00112         if( !listBox->IsVisible() )
00113         {
00114                 listBox->ShowWindow();
00115                 listBox->UpdateWindow( true );
00116         }
00117 }
00118 
00119 void XDropDown::HideListBox( void )
00120 {
00121         if( listBox->IsVisible() )
00122         {
00123                 listBox->HideWindow();
00124                 listBox->UpdateWindow( true );
00125         }
00126 }
00127 
00128 const bool XDropDown::wmLostFocus( const CtrlMessage &msg )
00129 {
00130         bool ans = XEditBox::wmLostFocus( msg );
00131 
00132         if( !IsChild( (Window *)( msg.source ) ) )
00133         {
00134                 ans = listBox->IsVisible();
00135                 HideListBox();
00136         }
00137         return ans;
00138 
00139 }
00140 
00141 }
00142 

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