19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Micah Dowty
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    micahjd@users.sourceforge.net
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL.h"
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_sysevents.h"
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h"
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_pgvideo.h"
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_pgevents_c.h"
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint PG_HandleClose(struct pgEvent *evt)
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_PrivateQuit();
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return 1;               /* Intercept the event's normal quit handling */
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint PG_HandleResize(struct pgEvent *evt)
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_PrivateResize(evt->e.size.w, evt->e.size.h);
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return 0;
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint PG_HandleKey(struct pgEvent *evt)
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_keysym sym;
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_memset(&sym,0,sizeof(sym));
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	sym.sym = evt->e.kbd.key;
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	sym.mod = evt->e.kbd.mods;
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return 0;
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint PG_HandleChar(struct pgEvent *evt)
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_keysym sym;
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_memset(&sym,0,sizeof(sym));
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	sym.unicode = evt->e.kbd.key;
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	sym.mod = evt->e.kbd.mods;
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return 0;
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint PG_HandleMouseButton(struct pgEvent *evt)
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* We need to focus the canvas when it's clicked */
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if (evt->extra) {
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	        SDL_VideoDevice *this = (SDL_VideoDevice *) evt->extra;
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		pgFocus(this->hidden->wCanvas);
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_PrivateMouseButton(evt->type == PG_WE_PNTR_DOWN, evt->e.pntr.chbtn,
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			       evt->e.pntr.x, evt->e.pntr.y);
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return 0;
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint PG_HandleMouseMotion(struct pgEvent *evt)
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_PrivateMouseMotion(evt->e.pntr.btn,0,evt->e.pntr.x, evt->e.pntr.y);
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return 0;
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid PG_PumpEvents(_THIS)
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* Process all pending events */
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        pgEventPoll();
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid PG_InitOSKeymap(_THIS)
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* We need no keymap */
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid PG_InitEvents(_THIS)
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* Turn on all the mouse and keyboard triggers for our canvas, normally less important
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	 * events like mouse movement are ignored to save bandwidth. */
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        pgSetWidget(this->hidden->wCanvas, PG_WP_TRIGGERMASK,
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		    pgGetWidget(this->hidden->wCanvas, PG_WP_TRIGGERMASK) |
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		    PG_TRIGGER_UP | PG_TRIGGER_DOWN | PG_TRIGGER_MOVE |
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		    PG_TRIGGER_KEYUP | PG_TRIGGER_KEYDOWN | PG_TRIGGER_CHAR,0);
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Start our canvas out focused, so we get keyboard input */
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pgFocus(this->hidden->wCanvas);
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* Set up bindings for all the above event handlers */
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        pgBind(this->hidden->wApp,    PG_WE_CLOSE, &PG_HandleClose, NULL);
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        pgBind(this->hidden->wCanvas, PG_WE_BUILD, &PG_HandleResize, NULL);
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        pgBind(this->hidden->wCanvas, PG_WE_KBD_CHAR, &PG_HandleChar, NULL);
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        pgBind(this->hidden->wCanvas, PG_WE_KBD_KEYUP, &PG_HandleKey, NULL);
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        pgBind(this->hidden->wCanvas, PG_WE_KBD_KEYDOWN, &PG_HandleKey, NULL);
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        pgBind(this->hidden->wCanvas, PG_WE_PNTR_MOVE, &PG_HandleMouseMotion, NULL);
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        pgBind(this->hidden->wCanvas, PG_WE_PNTR_UP, &PG_HandleMouseButton, NULL);
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        pgBind(this->hidden->wCanvas, PG_WE_PNTR_DOWN, &PG_HandleMouseButton, this);
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* end of SDL_pgevents.c ... */
118