Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgmessageobject.cpp

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2007-04-13 16:16:00 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/core/pgmessageobject.cpp,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 #include "pgmessageobject.h"
00030 #include "pgapplication.h"
00031 #include "pgwidget.h"
00032 #include "pglog.h"
00033 
00034 #include <iostream>
00035 #include <algorithm>
00036 
00037 // static variables for message processing
00038 //vector<PG_MessageObject*> PG_MessageObject::objectList;
00039 PG_MessageObject* PG_MessageObject::captureObject = NULL;
00040 PG_MessageObject* PG_MessageObject::inputFocusObject = NULL;
00041 PG_Widget* PG_MessageObject::lastwidget = NULL;
00042 
00045 PG_MessageObject::PG_MessageObject() {
00046 
00047         // init vars
00048         my_canReceiveMessages = true;
00049         my_oldCapture = NULL;
00050         my_oldFocus = NULL;
00051 
00052         //objectList.push_back(this);
00053 }
00054 
00055 
00058 PG_MessageObject::~PG_MessageObject() {
00059         sigDelete(this);
00060         //RemoveObject(this);
00061 
00062         //PG_UnregisterEventObject(this);
00063 
00064         if (inputFocusObject == this) {
00065                 inputFocusObject = NULL;
00066         }
00067 
00068         if (lastwidget == this) {
00069                 lastwidget = NULL;
00070         }
00071 
00072         if (captureObject == this) {
00073                 captureObject = NULL;
00074         }
00075 }
00076 
00079 void PG_MessageObject::EnableReceiver(bool enable) {
00080         my_canReceiveMessages = enable;
00081 }
00082 
00083 
00086 bool PG_MessageObject::ProcessEvent(const SDL_Event* event) {
00087 
00088         // check if we are able to process messages
00089         if(!my_canReceiveMessages) {
00090                 return false;
00091         }
00092 
00093         if(event->type != SDL_USEREVENT) {
00094                 if(captureObject != this)
00095                         if(!AcceptEvent(event)) {
00096                                 return false;
00097                         }
00098         }
00099 
00100         if((captureObject != NULL) && (captureObject != this)) {
00101                 return false;
00102         }
00103 
00104         bool rc = false;
00105 
00106         // dispatch message
00107         switch(event->type) {
00108                 case SDL_ACTIVEEVENT:
00109                         rc = eventActive(&event->active) || sigActive(this, &event->active);
00110                         break;
00111 
00112                 case SDL_KEYDOWN:
00113                         rc = eventKeyDown(&event->key) || sigKeyDown(this, &event->key);
00114                         break;
00115 
00116                 case SDL_KEYUP:
00117                         rc = eventKeyUp(&event->key) || sigKeyUp(this, &event->key);
00118                         ;
00119                         break;
00120 
00121                 case SDL_MOUSEMOTION:
00122                         rc = eventMouseMotion(&event->motion) || sigMouseMotion(this, &event->motion);
00123                         break;
00124 
00125                 case SDL_MOUSEBUTTONDOWN:
00126                         rc = eventMouseButtonDown(&event->button) || sigMouseButtonDown(this, &event->button);
00127                         break;
00128 
00129                 case SDL_MOUSEBUTTONUP:
00130                         rc = eventMouseButtonUp(&event->button) || sigMouseButtonUp(this, &event->button);
00131                         break;
00132 
00133                 case SDL_QUIT:
00134                         rc = eventQuit(PG_Application::IDAPPLICATION, NULL, (unsigned long)&event->quit) || sigQuit(this);
00135                         break;
00136 
00137                 case SDL_SYSWMEVENT:
00138                         rc = eventSysWM(&event->syswm) || sigSysWM(this, &event->syswm);
00139                         break;
00140 
00141                 case SDL_VIDEORESIZE:
00142                         rc = eventResize(&event->resize) || sigVideoResize(this, &event->resize);
00143                         break;
00144 
00145                 default:
00146                         rc = false;
00147                         break;
00148         }
00149 
00150         return rc;
00151 }
00152 
00153 
00156 bool PG_MessageObject::eventActive(const SDL_ActiveEvent* active) {
00157         return false;
00158 }
00159 
00160 
00161 bool PG_MessageObject::eventKeyDown(const SDL_KeyboardEvent* key) {
00162         return false;
00163 }
00164 
00165 
00166 bool PG_MessageObject::eventKeyUp(const SDL_KeyboardEvent* key) {
00167         return false;
00168 }
00169 
00170 
00171 bool PG_MessageObject::eventMouseMotion(const SDL_MouseMotionEvent* motion) {
00172         return false;
00173 }
00174 
00175 
00176 bool PG_MessageObject::eventMouseButtonDown(const SDL_MouseButtonEvent* button) {
00177         return false;
00178 }
00179 
00180 
00181 bool PG_MessageObject::eventMouseButtonUp(const SDL_MouseButtonEvent* button) {
00182         return false;
00183 }
00184 
00185 
00186 bool PG_MessageObject::eventQuit(int id, PG_MessageObject* widget, unsigned long data) {
00187         return false;
00188 }
00189 
00190 bool PG_MessageObject::eventQuitModal(int id, PG_MessageObject* widget, unsigned long data) {
00191         return false;
00192 }
00193 
00194 
00195 bool PG_MessageObject::eventSysWM(const SDL_SysWMEvent* syswm) {
00196         return false;
00197 }
00198 
00199 
00200 bool PG_MessageObject::eventResize(const SDL_ResizeEvent* event) {
00201         return false;
00202 }
00203 
00204 bool PG_MessageObject::AcceptEvent(const SDL_Event* event) {
00205         return true;                            // PG_MessageObject accepts all events
00206 }
00207 
00210 PG_MessageObject* PG_MessageObject::SetCapture() {
00211         if(captureObject == this)
00212                 return my_oldCapture;
00213 
00214         my_oldCapture = captureObject;
00215         captureObject = this;
00216         return my_oldCapture;
00217 }
00218 
00219 
00220 void PG_MessageObject::ReleaseCapture() {
00221         if(captureObject != this) {
00222                 return;
00223         }
00224 
00225         captureObject = my_oldCapture;
00226 }
00227 
00228 PG_MessageObject* PG_MessageObject::SetInputFocus() {
00229         if(inputFocusObject == this)
00230                 return my_oldFocus;
00231 
00232         my_oldFocus = inputFocusObject;
00233 
00234         if(my_oldFocus != NULL) {
00235                 my_oldFocus->eventInputFocusLost(inputFocusObject);
00236         }
00237 
00238         inputFocusObject = this;
00239         return my_oldFocus;
00240 }
00241 
00242 
00244 void PG_MessageObject::eventInputFocusLost(PG_MessageObject* newfocus) {}
00245 
00246 
00248 void PG_MessageObject::ReleaseInputFocus() {
00249         if(inputFocusObject != this) {
00250                 return;
00251         }
00252 
00253         inputFocusObject = NULL;
00254 }
00255 
00256 /*SDL_Event PG_MessageObject::WaitEvent(Uint32 delay) {
00257         static SDL_Event event;
00258  
00259         while(SDL_PollEvent(&event) == 0) {
00260                 //              eventIdle();
00261                 if(delay > 0) {
00262                         SDL_Delay(delay);
00263                 }
00264         }
00265  
00266         return event;
00267 }*/
00268 
00269 
00272 /*bool PG_MessageObject::RemoveObject(PG_MessageObject* obj) {
00273         vector<PG_MessageObject*>::iterator list = objectList.begin();
00274  
00275         // search the object
00276         list = find(objectList.begin(), objectList.end(), obj);
00277  
00278         // check if object was found
00279         if(list == objectList.end()) {
00280                 return false;
00281         }
00282  
00283         // mark object for removal
00284         *list = NULL;
00285         
00286         return true;
00287 }*/
00288 
00289 PG_MessageObject* PG_MessageObject::GetCapture() {
00290         return captureObject;
00291 }
00292 
00293 bool PG_MessageObject::IsEnabled() {
00294         return my_canReceiveMessages;
00295 }

Generated on Tue Jun 24 01:27:48 2008 for Advanced Strategic Command by  doxygen 1.4.2