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

arsform.cpp

Go to the documentation of this file.
00001 #include "SdlArs.h"
00002 
00003 namespace Ars
00004 {
00005 
00006 Form::~Form( void )
00007 {
00008         for( vector<Window *>::iterator it = begin() ; it != end() ; ++it )
00009         {
00010                 if( (*it)->GetParent() == 0 )
00011                         delete *it;
00012         }
00013         clear();
00014 }
00015 
00016 Window *Form::FindWindowParent( const XRect &r )
00017 {
00018         Window  *ans = 0;
00019 
00020         for( vector<Window *>::iterator it = begin() ; it != end() ; ++it )
00021         {
00022                 if( (*it)->x == r.x && (*it)->y == r.y && (*it)->Bottom() == r.Bottom() && (*it)->Right() == r.Right() )
00023                         continue;
00024                 if( r.x >= (*it)->x && r.Right() <= (*it)->Right() && r.y >= (*it)->y && r.Bottom() <= (*it)->Bottom() )
00025                         if( ans == 0 ||
00026                                 ((*it)->x >= ans->GetWindowRect().x && (*it)->Right() <= ans->GetWindowRect().Right() && (*it)->y >= ans->GetWindowRect().y && (*it)->Bottom() <= ans->GetWindowRect().Bottom()) )
00027                                 ans = (*it);
00028         }
00029 
00030         return ans;
00031 }
00032 
00033 Window *Form::GetArsObject( const int obId )
00034 {
00035         for( vector<Window *>::iterator it = begin() ; it != end() ; ++it )
00036                 if( (*it)->GetId() == obId )
00037                         return (*it);
00038 
00039         return 0;
00040 }
00041 
00042 void Form::Draw( void )
00043 {
00044         for( vector<Window *>::iterator it = begin() ; it != end() ; ++it )
00045                 (*it)->ResetFlags( F_HIDETREE );
00046         
00047         if( !empty() )
00048                 ArsSendMessage( Message( Message::APP_PAINT  , *begin() ) );
00049 }
00050 
00051 void Form::InitDialog( Window *This )
00052 {
00053         while( !MessageServer::Instance().empty() )
00054                 MessageServer::Instance().ProcessMessage();
00055 
00056         for( vector<Window *>::iterator it = begin() ; it != end() ; ++it )
00057         {
00058                 ArsSendMessage( Message( Message::SETUP_WINDOW , (*it) ) );
00059                 (*it)->SetFlags( F_HIDETREE );
00060                 if( (*it)->GetParent() == 0 )
00061                 {
00062                         Window  *w = FindWindowParent( (*it)->GetWindowRect() );
00063                         if( w == 0 || w == (*it) )
00064                                 (*it)->SetParent( This );
00065                         else
00066                                 (*it)->SetParent( w );
00067                 }
00068         }
00069 
00070         while( !MessageServer::Instance().empty() )
00071                 MessageServer::Instance().ProcessMessage();
00072 }
00073 
00074 void Form::ShutdownDialog( Window *This )
00075 {
00076         while( !MessageServer::Instance().empty() )
00077                 MessageServer::Instance().ProcessMessage();
00078 
00079         (*begin())->SetParent( 0 );
00080 
00081         while( !MessageServer::Instance().empty() )
00082                 MessageServer::Instance().ProcessMessage();
00083         
00084         This->SetDirty();
00085         ArsSendMessage( Message( Message::APP_PAINT  , This ) );
00086 }
00087 
00088 void Form::DoDialog( const int aWait )
00089 {
00090         SDL_Event event;
00091         if( ArsApplication::GetInstance()->IsRunning() )
00092         {
00093                 while( SDL_PollEvent( &event ) )
00094                         ArsApplication::GetInstance()->HandleSDLEvent( event );
00095 
00096                 while( !MessageServer::Instance().empty() )
00097                         ProcessMessage();
00098 
00099                 if( aWait )
00100                         SDL_Delay( aWait );
00101         }
00102 }
00103 
00104 void Form::ProcessMessage( void )
00105 {
00106         if( !MessageServer::Instance().empty() )
00107         {
00108                 Message *msg2 = MessageServer::Instance().front();
00109                 Message &msg = *msg2;
00110                 MessageServer::Instance().pop_front();
00111                 std::map<Message::EMessageType,std::vector< std::pair<MessageClient *, bool> > >::iterator at = MessageServer::Instance().messageClients.find( msg.MessageType() );
00113                 if( at != MessageServer::Instance().messageClients.end() )
00114                 {
00115                         if( msg.Destination() == 0 )
00116                         {
00117                                 bool ans = false;
00118                                 std::vector< std::pair<MessageClient *, bool> > tmp = at->second;
00119                                 for( std::vector< std::pair<MessageClient *, bool> >::iterator it = tmp.begin() ; it != tmp.end() ; ++it )
00120                                 {
00121                                         if( it->second )
00122                                         {
00123                                                 Window  *wnd = *begin();
00124                                                 Window  *tgt = 0;
00125                                                 XToolTip        *tt = 0;
00126                                                 try{    
00127                                                         tgt = dynamic_cast<Window *>( it->first );
00128                                                         tt = dynamic_cast<XToolTip *>( it->first );
00129                                                 }catch( ... ) 
00130                                                 { 
00131                                                         tgt = 0;        tt = 0; 
00132                                                         MessageServer::Instance().DeregisterMessageClient( it->first );
00133                                                 }
00134                                                 if( wnd->IsChild( tgt ) || tt != 0 )
00135                                                         if( it->first->HandleMessage( msg ) )
00136                                                                 ans = true;
00137                                         }
00138                                 }
00139                         }
00140                         else 
00141                                 HandleTillRoot( msg );
00142                 }
00143                 delete msg2;
00144         }
00145 
00146         for( std::map<Message::EMessageType,std::vector< std::pair<MessageClient *, bool> > >::iterator at = MessageServer::Instance().messageClients.begin() ; at != MessageServer::Instance().messageClients.end() ; ++at )
00147                 for( std::vector< std::pair<MessageClient *, bool> >::iterator it = at->second.begin() ; it != at->second.end() ; )
00148                         if( !it->second )
00149                         {
00150                                 at->second.erase( it );
00151                                 it = at->second.begin();
00152                         }
00153                         else
00154                                 ++it;
00155 }
00156 
00157 void Form::HandleTillRoot( Message &msg )
00158 {
00159         bool stopLoop = false;
00160 
00161         while( !stopLoop )
00162         {
00163                 if( MessageServer::Instance().IsRegistered( msg.MessageType() , msg.Destination() ) && (*begin())->IsChild( dynamic_cast<Window *>( msg.Destination() ) ) )
00164                         stopLoop = msg.Destination()->HandleMessage( msg );
00165 
00166                 if( !stopLoop )
00167                 {
00168                         Window *wnd = dynamic_cast<Window *>( msg.Destination() );
00169 
00170                         if( wnd && wnd->GetParent() )
00171                                 msg.SetTarget( wnd->GetParent() );
00172                         else
00173                                 stopLoop = true;
00174                 }
00175         }
00176 }
00177 
00178 
00179 }
00180 

Generated on Fri Dec 5 04:05:58 2003 for Borqueror by doxygen 1.3.3