Mercurial > sdl-ios-xcode
annotate src/video/bwindow/SDL_BWin.h @ 4170:092c0bc69155 SDL-1.2
Fixed bug #618
Description From Tim Angus 2008-08-30 12:23:56 (-) [reply]
As we all know SDL 1.2 doesn't handle dead keys well since one key press
potentially equals two (or more) characters. For example, on many layouts,
keying <backquote>,<space> results in <no character>,<backquote><space>. Since
the unicode member of the SDL_keysym struct only has room for one character,
only one can be returned.
On Linux, the first character is returned. On Windows however, unless the exact
number of characters generated by the keypress is 1, nothing is returned. The
following patch addresses this inconsistency.
Updated patch which includes a further fix to the handling of the numpad when
numlock is on. This further fix is courtesy Amanieu d'Antras.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 13 Apr 2009 08:42:09 +0000 |
parents | a1b03ba2fcd0 |
children | 0620847bf1a8 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
1
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifndef _SDL_BWin_h | |
24 #define _SDL_BWin_h | |
25 | |
1367
e440d5c488c1
Fixes for BeOS and Solaris builds
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
26 #include "SDL_config.h" |
e440d5c488c1
Fixes for BeOS and Solaris builds
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
27 |
0 | 28 #include <stdio.h> |
29 #include <AppKit.h> | |
30 #include <InterfaceKit.h> | |
31 #include <be/game/DirectWindow.h> | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
32 #if SDL_VIDEO_OPENGL |
0 | 33 #include <be/opengl/GLView.h> |
34 #endif | |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
35 #include <support/UTF8.h> |
0 | 36 |
1367
e440d5c488c1
Fixes for BeOS and Solaris builds
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
37 #include "../../main/beos/SDL_BeApp.h" |
0 | 38 #include "SDL_events.h" |
39 #include "SDL_BView.h" | |
40 | |
41 extern "C" { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
42 #include "../../events/SDL_events_c.h" |
3878 | 43 |
44 extern int mouse_relative; | |
0 | 45 }; |
46 | |
47 class SDL_BWin : public BDirectWindow | |
48 { | |
49 public: | |
50 SDL_BWin(BRect bounds) : | |
51 BDirectWindow(bounds, "Untitled", B_TITLED_WINDOW, 0) { | |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
52 last_buttons = 0; |
0 | 53 the_view = NULL; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
54 #if SDL_VIDEO_OPENGL |
0 | 55 SDL_GLView = NULL; |
56 #endif | |
57 SDL_View = NULL; | |
58 Unlock(); | |
59 shown = false; | |
60 inhibit_resize = false; | |
61 } | |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
62 |
0 | 63 virtual ~SDL_BWin() { |
64 Lock(); | |
65 if ( the_view ) { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
66 #if SDL_VIDEO_OPENGL |
0 | 67 if ( the_view == SDL_GLView ) { |
68 SDL_GLView->UnlockGL(); | |
69 } | |
70 #endif | |
71 RemoveChild(the_view); | |
72 the_view = NULL; | |
73 } | |
74 Unlock(); | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
75 #if SDL_VIDEO_OPENGL |
0 | 76 if ( SDL_GLView ) { |
77 delete SDL_GLView; | |
78 } | |
79 #endif | |
80 if ( SDL_View ) { | |
81 delete SDL_View; | |
82 } | |
83 } | |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
84 |
0 | 85 |
86 /* Override the Show() method so we can tell when we've been shown */ | |
87 virtual void Show(void) { | |
88 BWindow::Show(); | |
89 shown = true; | |
90 } | |
91 virtual bool Shown(void) { | |
92 return (shown); | |
93 } | |
94 /* If called, the next resize event will not be forwarded to SDL. */ | |
95 virtual void InhibitResize(void) { | |
96 inhibit_resize=true; | |
97 } | |
98 /* Handle resizing of the window */ | |
99 virtual void FrameResized(float width, float height) { | |
100 if(inhibit_resize) | |
101 inhibit_resize = false; | |
102 else | |
103 SDL_PrivateResize((int)width, (int)height); | |
104 } | |
906
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
105 virtual int CreateView(Uint32 flags, Uint32 gl_flags) { |
0 | 106 int retval; |
107 | |
108 retval = 0; | |
109 Lock(); | |
110 if ( flags & SDL_OPENGL ) { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
111 #if SDL_VIDEO_OPENGL |
0 | 112 if ( SDL_GLView == NULL ) { |
113 SDL_GLView = new BGLView(Bounds(), "SDL GLView", | |
906
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
114 B_FOLLOW_ALL_SIDES, (B_WILL_DRAW|B_FRAME_EVENTS), |
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
115 gl_flags); |
4013
5804139bdf0b
Use GL direct updates when possible
Sam Lantinga <slouken@libsdl.org>
parents:
4012
diff
changeset
|
116 SDL_GLView->EnableDirectMode(true); |
0 | 117 } |
118 if ( the_view != SDL_GLView ) { | |
119 if ( the_view ) { | |
120 RemoveChild(the_view); | |
121 } | |
122 AddChild(SDL_GLView); | |
123 SDL_GLView->LockGL(); | |
124 the_view = SDL_GLView; | |
125 } | |
126 #else | |
127 SDL_SetError("OpenGL support not enabled"); | |
128 retval = -1; | |
129 #endif | |
130 } else { | |
131 if ( SDL_View == NULL ) { | |
132 SDL_View = new SDL_BView(Bounds()); | |
133 } | |
134 if ( the_view != SDL_View ) { | |
135 if ( the_view ) { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
136 #if SDL_VIDEO_OPENGL |
0 | 137 if ( the_view == SDL_GLView ) { |
138 SDL_GLView->UnlockGL(); | |
139 } | |
140 #endif | |
141 RemoveChild(the_view); | |
142 } | |
143 AddChild(SDL_View); | |
144 the_view = SDL_View; | |
145 } | |
146 } | |
147 Unlock(); | |
148 return(retval); | |
149 } | |
150 virtual void SetBitmap(BBitmap *bitmap) { | |
151 SDL_View->SetBitmap(bitmap); | |
152 } | |
4012 | 153 virtual void SetXYOffset(int x, int y) { |
154 #if SDL_VIDEO_OPENGL | |
155 if ( the_view == SDL_GLView ) { | |
156 return; | |
157 } | |
158 #endif | |
159 SDL_View->SetXYOffset(x, y); | |
160 } | |
161 virtual void GetXYOffset(int &x, int &y) { | |
162 #if SDL_VIDEO_OPENGL | |
163 if ( the_view == SDL_GLView ) { | |
164 x = 0; | |
165 y = 0; | |
166 return; | |
167 } | |
168 #endif | |
169 SDL_View->GetXYOffset(x, y); | |
170 } | |
171 virtual void GetXYOffset(float &x, float &y) { | |
172 #if SDL_VIDEO_OPENGL | |
173 if ( the_view == SDL_GLView ) { | |
174 x = 0.0f; | |
175 y = 0.0f; | |
176 return; | |
177 } | |
178 #endif | |
179 SDL_View->GetXYOffset(x, y); | |
180 } | |
0 | 181 virtual bool BeginDraw(void) { |
182 return(Lock()); | |
183 } | |
184 virtual void DrawAsync(BRect updateRect) { | |
185 SDL_View->DrawAsync(updateRect); | |
186 } | |
187 virtual void EndDraw(void) { | |
188 SDL_View->Sync(); | |
189 Unlock(); | |
190 } | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
191 #if SDL_VIDEO_OPENGL |
0 | 192 virtual void SwapBuffers(void) { |
193 SDL_GLView->UnlockGL(); | |
194 SDL_GLView->LockGL(); | |
195 SDL_GLView->SwapBuffers(); | |
196 } | |
197 #endif | |
198 virtual BView *View(void) { | |
199 return(the_view); | |
200 } | |
201 | |
202 /* Hook functions -- overridden */ | |
203 virtual void Minimize(bool minimize) { | |
204 /* This is only called when mimimized, not when restored */ | |
205 //SDL_PrivateAppActive(minimize, SDL_APPACTIVE); | |
206 BWindow::Minimize(minimize); | |
207 } | |
208 virtual void WindowActivated(bool active) { | |
209 SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS); | |
210 } | |
211 virtual bool QuitRequested(void) { | |
212 if ( SDL_BeAppActive > 0 ) { | |
213 SDL_PrivateQuit(); | |
214 /* We don't ever actually close the window here because | |
215 the application should respond to the quit request, | |
216 or ignore it as desired. | |
217 */ | |
218 return(false); | |
219 } | |
220 return(true); /* Close the app window */ | |
221 } | |
906
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
222 virtual void Quit() { |
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
223 if (!IsLocked()) |
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
224 Lock(); |
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
225 BDirectWindow::Quit(); |
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
226 } |
0 | 227 |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
228 virtual int16 Translate2Unicode(const char *buf) { |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
229 int32 state, srclen, dstlen; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
230 unsigned char destbuf[2]; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
231 Uint16 unicode = 0; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
232 |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
233 if ((uchar)buf[0] > 127) { |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
234 state = 0; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
235 srclen = SDL_strlen(buf); |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
236 dstlen = sizeof(destbuf); |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
237 convert_from_utf8(B_UNICODE_CONVERSION, buf, &srclen, (char *)destbuf, &dstlen, &state); |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
238 unicode = destbuf[0]; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
239 unicode <<= 8; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
240 unicode |= destbuf[1]; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
241 } else |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
242 unicode = buf[0]; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
243 |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
244 /* For some reason function keys map to control characters */ |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
245 # define CTRL(X) ((X)-'@') |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
246 switch (unicode) { |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
247 case CTRL('A'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
248 case CTRL('B'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
249 case CTRL('C'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
250 case CTRL('D'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
251 case CTRL('E'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
252 case CTRL('K'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
253 case CTRL('L'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
254 case CTRL('P'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
255 if ( ! (SDL_GetModState() & KMOD_CTRL) ) |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
256 unicode = 0; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
257 break; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
258 /* Keyboard input maps newline to carriage return */ |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
259 case '\n': |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
260 unicode = '\r'; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
261 break; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
262 default: |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
263 break; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
264 } |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
265 |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
266 return unicode; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
267 } |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
268 |
3878 | 269 virtual void DispatchMessage(BMessage *msg, BHandler *target); |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
270 |
0 | 271 private: |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
272 #if SDL_VIDEO_OPENGL |
0 | 273 BGLView *SDL_GLView; |
274 #endif | |
275 SDL_BView *SDL_View; | |
276 BView *the_view; | |
277 bool shown; | |
278 bool inhibit_resize; | |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
279 int32 last_buttons; |
0 | 280 }; |
281 | |
282 #endif /* _SDL_BWin_h */ |