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 "pgmessageobject.h"
00030 #include "pgapplication.h"
00031 #include "pgwidget.h"
00032 #include "pglog.h"
00033
00034 #include <iostream>
00035 #include <algorithm>
00036
00037
00038
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
00048 my_canReceiveMessages = true;
00049 my_oldCapture = NULL;
00050 my_oldFocus = NULL;
00051
00052
00053 }
00054
00055
00058 PG_MessageObject::~PG_MessageObject() {
00059 sigDelete(this);
00060
00061
00062
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
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
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;
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
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 PG_MessageObject* PG_MessageObject::GetCapture() {
00290 return captureObject;
00291 }
00292
00293 bool PG_MessageObject::IsEnabled() {
00294 return my_canReceiveMessages;
00295 }