Home | History | Annotate | Download | only in qtopia
      1 /*
      2     SDL - Simple DirectMedia Layer
      3     Copyright (C) 1997-2006 Sam Lantinga
      4 
      5     This library is free software; you can redistribute it and/or
      6     modify it under the terms of the GNU Lesser General Public
      7     License as published by the Free Software Foundation; either
      8     version 2.1 of the License, or (at your option) any later version.
      9 
     10     This library is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13     Lesser General Public License for more details.
     14 
     15     You should have received a copy of the GNU Lesser General Public
     16     License along with this library; if not, write to the Free Software
     17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     18 
     19     Sam Lantinga
     20     slouken (at) libsdl.org
     21 */
     22 #include "SDL_config.h"
     23 
     24 #include <qpe/qpeapplication.h>
     25 
     26 #include <stdio.h>
     27 #include <string.h>
     28 #include "SDL_error.h"
     29 #include "SDL_events.h"
     30 #include "SDL_QWin.h"
     31 #include "SDL_lowvideo.h"
     32 #include "SDL_timer.h"
     33 
     34 extern "C" {
     35 #include "../../events/SDL_sysevents.h"
     36 #include "../../events/SDL_events_c.h"
     37 #include "SDL_sysevents_c.h"
     38 
     39   //  static SDLKey keymap[128];
     40 /* This is special because we know it will be run in a loop in a separate
     41    thread.  Normally this function should loop as long as there are input
     42    states changing, i.e. new events arriving.
     43 */
     44 void QT_PumpEvents(_THIS)
     45 {
     46   if(!qApp) {
     47     return;
     48   }
     49   //  printf("processing events: %p\n", qApp);
     50   //qApp->processOneEvent(); // wait for a event
     51   qApp->processEvents(); // and process all outstanding ones
     52 #if 0
     53   BView *view;
     54 	BRect bounds;
     55 	BPoint point;
     56 	uint32 buttons;
     57 	const uint32 button_masks[3] = {
     58 		B_PRIMARY_MOUSE_BUTTON,
     59 		B_TERTIARY_MOUSE_BUTTON,
     60 		B_SECONDARY_MOUSE_BUTTON,
     61 	};
     62 	unsigned int    i, j;
     63 
     64 	/* Check out the mouse buttons and position (slight race condition) */
     65 	if ( SDL_Win->Lock() ) {
     66 		/* Don't do anything if we have no view */
     67 		view = SDL_Win->View();
     68 		if ( ! view ) {
     69 			SDL_Win->Unlock();
     70 			return;
     71 		}
     72 		bounds = view->Bounds();
     73 		/* Get new input state, if still active */
     74 		if ( SDL_Win->IsActive() ) {
     75 			key_flip = !key_flip;
     76 			get_key_info(&keyinfo[key_flip]);
     77 			view->GetMouse(&point, &buttons, true);
     78 		} else {
     79 			key_flip = key_flip;
     80 			point = last_point;
     81 			buttons = last_buttons;
     82 		}
     83 		SDL_Win->Unlock();
     84 	} else {
     85 		return;
     86 	}
     87 
     88 	/* If our view is active, we'll find key changes here */
     89 	if ( SDL_memcmp(keyinfo[0].key_states, keyinfo[1].key_states, 16) != 0 ) {
     90 		for ( i=0; i<16; ++i ) {
     91 			Uint8 new_state, transition;
     92 
     93 			new_state = keyinfo[key_flip].key_states[i];
     94 			transition = keyinfo[!key_flip].key_states[i] ^
     95 					keyinfo[ key_flip].key_states[i];
     96 			for ( j=0; j<8; ++j ) {
     97 				if ( transition&0x80 )
     98 					QueueKey(i*8+j, new_state&0x80);
     99 				transition <<= 1;
    100 				new_state <<= 1;
    101 			}
    102 		}
    103 	}
    104 
    105 	/* We check keyboard, but not mouse if mouse isn't in window */
    106 	if ( ! bounds.Contains(point) ) {
    107 		/* Mouse moved outside our view? */
    108 		if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
    109 			SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
    110 			be_app->SetCursor(B_HAND_CURSOR);
    111 		}
    112 		return;
    113 	}
    114 	/* Has the mouse moved back into our view? */
    115 	if ( ! (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
    116 		/* Reset the B_HAND_CURSOR to our own */
    117 		SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
    118 		SDL_SetCursor(NULL);
    119 	}
    120 
    121 	/* Check for mouse motion */
    122 	if ( point != last_point ) {
    123 		int x, y;
    124 
    125 		SDL_Win->GetXYOffset(x, y);
    126 		x = (int)point.x - x;
    127 		y = (int)point.y - y;
    128 		SDL_PrivateMouseMotion(0, 0, x, y);
    129 	}
    130 	last_point = point;
    131 
    132 	/* Add any mouse button events */
    133 	for ( i=0; i<SDL_TABLESIZE(button_masks); ++i ) {
    134 		if ( (buttons ^ last_buttons) & button_masks[i] ) {
    135 			if ( buttons & button_masks[i] ) {
    136 				SDL_PrivateMouseButton(SDL_PRESSED, 1+i, 0, 0);
    137 			} else {
    138 				SDL_PrivateMouseButton(SDL_RELEASED, 1+i, 0, 0);
    139 			}
    140 		}
    141 	}
    142 	last_buttons = buttons;
    143 #endif
    144 }
    145 
    146 void QT_InitOSKeymap(_THIS)
    147 {
    148 #if 0
    149   unsigned int i;
    150 
    151   /* Initialize all the key states as "up" */
    152   key_flip = 0;
    153   SDL_memset(keyinfo[key_flip].key_states, 0, 16);
    154 
    155   /* Initialize the key translation table */
    156   for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
    157     keymap[i] = SDLK_UNKNOWN;
    158 
    159   //  keymap[0x01]		= SDLK_ESCAPE;
    160   //  keymap[B_F1_KEY]	= SDLK_F1;
    161   //  keymap[B_F2_KEY]	= SDLK_F2;
    162   //  keymap[B_F3_KEY]	= SDLK_F3;
    163   //  keymap[B_F4_KEY]	= SDLK_F4;
    164   //  keymap[B_F5_KEY]	= SDLK_F5;
    165   //  keymap[B_F6_KEY]	= SDLK_F6;
    166   //  keymap[B_F7_KEY]	= SDLK_F7;
    167   //  keymap[B_F8_KEY]	= SDLK_F8;
    168   //  keymap[B_F9_KEY]	= SDLK_F9;
    169   //  keymap[B_F10_KEY]	= SDLK_F10;
    170   //  keymap[B_F11_KEY]	= SDLK_F11;
    171   //  keymap[B_F12_KEY]	= SDLK_F12;
    172   //  keymap[B_PRINT_KEY]	= SDLK_PRINT;
    173   //keymap[B_SCROLL_KEY]	= SDLK_SCROLLOCK;
    174   //  keymap[B_PAUSE_KEY]	= SDLK_PAUSE;
    175   keymap[0x11]		= SDLK_BACKQUOTE;
    176   keymap[0x12]		= SDLK_1;
    177   keymap[0x13]		= SDLK_2;
    178   keymap[0x14]		= SDLK_3;
    179   keymap[0x15]		= SDLK_4;
    180   keymap[0x16]		= SDLK_5;
    181   keymap[0x17]		= SDLK_6;
    182   keymap[0x18]		= SDLK_7;
    183   keymap[0x19]		= SDLK_8;
    184   keymap[0x1a]		= SDLK_9;
    185   keymap[0x1b]		= SDLK_0;
    186   keymap[0x1c]		= SDLK_MINUS;
    187   keymap[0x1d]		= SDLK_EQUALS;
    188   keymap[0x1e]		= SDLK_BACKSPACE;
    189   keymap[0x1f]		= SDLK_INSERT;
    190   keymap[0x20]		= SDLK_HOME;
    191   keymap[0x21]		= SDLK_PAGEUP;
    192   //keymap[0x22]		= SDLK_NUMLOCK;
    193   keymap[0x23]		= SDLK_KP_DIVIDE;
    194   keymap[0x24]		= SDLK_KP_MULTIPLY;
    195   keymap[0x25]		= SDLK_KP_MINUS;
    196   keymap[0x26]		= SDLK_TAB;
    197   keymap[0x27]		= SDLK_q;
    198   keymap[0x28]		= SDLK_w;
    199   keymap[0x29]		= SDLK_e;
    200   keymap[0x2a]		= SDLK_r;
    201   keymap[0x2b]		= SDLK_t;
    202   keymap[0x2c]		= SDLK_y;
    203   keymap[0x2d]		= SDLK_u;
    204   keymap[0x2e]		= SDLK_i;
    205   keymap[0x2f]		= SDLK_o;
    206   keymap[0x30]		= SDLK_p;
    207   keymap[0x31]		= SDLK_LEFTBRACKET;
    208   keymap[0x32]		= SDLK_RIGHTBRACKET;
    209   keymap[0x33]		= SDLK_BACKSLASH;
    210   keymap[0x34]		= SDLK_DELETE;
    211   keymap[0x35]		= SDLK_END;
    212   keymap[0x36]		= SDLK_PAGEDOWN;
    213   keymap[0x37]		= SDLK_KP7;
    214   keymap[0x38]		= SDLK_KP8;
    215   keymap[0x39]		= SDLK_KP9;
    216   keymap[0x3a]		= SDLK_KP_PLUS;
    217   //keymap[0x3b]		= SDLK_CAPSLOCK;
    218   keymap[0x3c]		= SDLK_a;
    219   keymap[0x3d]		= SDLK_s;
    220   keymap[0x3e]		= SDLK_d;
    221   keymap[0x3f]		= SDLK_f;
    222   keymap[0x40]		= SDLK_g;
    223   keymap[0x41]		= SDLK_h;
    224   keymap[0x42]		= SDLK_j;
    225   keymap[0x43]		= SDLK_k;
    226   keymap[0x44]		= SDLK_l;
    227   keymap[0x45]		= SDLK_SEMICOLON;
    228   keymap[0x46]		= SDLK_QUOTE;
    229   keymap[0x47]		= SDLK_RETURN;
    230   keymap[0x48]		= SDLK_KP4;
    231   keymap[0x49]		= SDLK_KP5;
    232   keymap[0x4a]		= SDLK_KP6;
    233   keymap[0x4b]		= SDLK_LSHIFT;
    234   keymap[0x4c]		= SDLK_z;
    235   keymap[0x4d]		= SDLK_x;
    236   keymap[0x4e]		= SDLK_c;
    237   keymap[0x4f]		= SDLK_v;
    238   keymap[0x50]		= SDLK_b;
    239   keymap[0x51]		= SDLK_n;
    240   keymap[0x52]		= SDLK_m;
    241   keymap[0x53]		= SDLK_COMMA;
    242   keymap[0x54]		= SDLK_PERIOD;
    243   keymap[0x55]		= SDLK_SLASH;
    244   keymap[0x56]		= SDLK_RSHIFT;
    245   keymap[0x57]		= SDLK_UP;
    246   keymap[0x58]		= SDLK_KP1;
    247   keymap[0x59]		= SDLK_KP2;
    248   keymap[0x5a]		= SDLK_KP3;
    249   keymap[0x5b]		= SDLK_KP_ENTER;
    250   //keymap[0x5c]		= SDLK_LCTRL;
    251   //keymap[0x5d]		= SDLK_LALT;
    252   keymap[0x5e]		= SDLK_SPACE;
    253   //keymap[0x5f]		= SDLK_RALT;
    254   //keymap[0x60]		= SDLK_RCTRL;
    255   keymap[0x61]		= SDLK_LEFT;
    256   keymap[0x62]		= SDLK_DOWN;
    257   keymap[0x63]		= SDLK_RIGHT;
    258   keymap[0x64]		= SDLK_KP0;
    259   keymap[0x65]		= SDLK_KP_PERIOD;
    260   //keymap[0x66]		= SDLK_LMETA;
    261   //keymap[0x67]		= SDLK_RMETA;
    262   //keymap[0x68]		= SDLK_MENU;
    263   keymap[0x69]		= SDLK_EURO;
    264   keymap[0x6a]		= SDLK_KP_EQUALS;
    265   keymap[0x6b]		= SDLK_POWER;
    266 #endif
    267 }
    268 
    269 }; /* Extern C */
    270