src/video/bwindow/SDL_BWin.h
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
    44 };
    44 };
    45 
    45 
    46 class SDL_BWin:public BDirectWindow
    46 class SDL_BWin:public BDirectWindow
    47 {
    47 {
    48   public:
    48   public:
    49     SDL_BWin (BRect bounds):BDirectWindow (bounds, "Untitled",
    49     SDL_BWin(BRect bounds):BDirectWindow(bounds, "Untitled",
    50                                            B_TITLED_WINDOW, 0)
    50                                          B_TITLED_WINDOW, 0)
    51     {
    51     {
    52         InitKeyboard ();
    52         InitKeyboard();
    53         last_buttons = 0;
    53         last_buttons = 0;
    54 
    54 
    55         the_view = NULL;
    55         the_view = NULL;
    56 #if SDL_VIDEO_OPENGL
    56 #if SDL_VIDEO_OPENGL
    57         SDL_GLView = NULL;
    57         SDL_GLView = NULL;
    58 #endif
    58 #endif
    59         SDL_View = NULL;
    59         SDL_View = NULL;
    60         Unlock ();
    60         Unlock();
    61         shown = false;
    61         shown = false;
    62         inhibit_resize = false;
    62         inhibit_resize = false;
    63     }
    63     }
    64 
    64 
    65     virtual ~ SDL_BWin ()
    65     virtual ~ SDL_BWin()
    66     {
    66     {
    67         Lock ();
    67         Lock();
    68         if (the_view) {
    68         if (the_view) {
    69 #if SDL_VIDEO_OPENGL
    69 #if SDL_VIDEO_OPENGL
    70             if (the_view == SDL_GLView) {
    70             if (the_view == SDL_GLView) {
    71                 SDL_GLView->UnlockGL ();
    71                 SDL_GLView->UnlockGL();
    72             }
    72             }
    73 #endif
    73 #endif
    74             RemoveChild (the_view);
    74             RemoveChild(the_view);
    75             the_view = NULL;
    75             the_view = NULL;
    76         }
    76         }
    77         Unlock ();
    77         Unlock();
    78 #if SDL_VIDEO_OPENGL
    78 #if SDL_VIDEO_OPENGL
    79         if (SDL_GLView) {
    79         if (SDL_GLView) {
    80             delete SDL_GLView;
    80             delete SDL_GLView;
    81         }
    81         }
    82 #endif
    82 #endif
    83         if (SDL_View) {
    83         if (SDL_View) {
    84             delete SDL_View;
    84             delete SDL_View;
    85         }
    85         }
    86     }
    86     }
    87 
    87 
    88     virtual void InitKeyboard (void)
    88     virtual void InitKeyboard(void)
    89     {
    89     {
    90         for (uint i = 0; i < SDL_TABLESIZE (keymap); ++i)
    90         for (uint i = 0; i < SDL_TABLESIZE(keymap); ++i)
    91             keymap[i] = SDLK_UNKNOWN;
    91             keymap[i] = SDLK_UNKNOWN;
    92 
    92 
    93         keymap[0x01] = SDLK_ESCAPE;
    93         keymap[0x01] = SDLK_ESCAPE;
    94         keymap[B_F1_KEY] = SDLK_F1;
    94         keymap[B_F1_KEY] = SDLK_F1;
    95         keymap[B_F2_KEY] = SDLK_F2;
    95         keymap[B_F2_KEY] = SDLK_F2;
   198         keymap[0x6a] = SDLK_KP_EQUALS;
   198         keymap[0x6a] = SDLK_KP_EQUALS;
   199         keymap[0x6b] = SDLK_POWER;
   199         keymap[0x6b] = SDLK_POWER;
   200     }
   200     }
   201 
   201 
   202     /* Override the Show() method so we can tell when we've been shown */
   202     /* Override the Show() method so we can tell when we've been shown */
   203     virtual void Show (void)
   203     virtual void Show(void)
   204     {
   204     {
   205         BWindow::Show ();
   205         BWindow::Show();
   206         shown = true;
   206         shown = true;
   207     }
   207     }
   208     virtual bool Shown (void)
   208     virtual bool Shown(void)
   209     {
   209     {
   210         return (shown);
   210         return (shown);
   211     }
   211     }
   212     /* If called, the next resize event will not be forwarded to SDL. */
   212     /* If called, the next resize event will not be forwarded to SDL. */
   213     virtual void InhibitResize (void)
   213     virtual void InhibitResize(void)
   214     {
   214     {
   215         inhibit_resize = true;
   215         inhibit_resize = true;
   216     }
   216     }
   217     /* Handle resizing of the window */
   217     /* Handle resizing of the window */
   218     virtual void FrameResized (float width, float height)
   218     virtual void FrameResized(float width, float height)
   219     {
   219     {
   220         if (inhibit_resize)
   220         if (inhibit_resize)
   221             inhibit_resize = false;
   221             inhibit_resize = false;
   222         else
   222         else
   223             SDL_PrivateResize ((int) width, (int) height);
   223             SDL_PrivateResize((int) width, (int) height);
   224     }
   224     }
   225     virtual int CreateView (Uint32 flags, Uint32 gl_flags)
   225     virtual int CreateView(Uint32 flags, Uint32 gl_flags)
   226     {
   226     {
   227         int retval;
   227         int retval;
   228 
   228 
   229         retval = 0;
   229         retval = 0;
   230         Lock ();
   230         Lock();
   231         if (flags & SDL_INTERNALOPENGL) {
   231         if (flags & SDL_INTERNALOPENGL) {
   232 #if SDL_VIDEO_OPENGL
   232 #if SDL_VIDEO_OPENGL
   233             if (SDL_GLView == NULL) {
   233             if (SDL_GLView == NULL) {
   234                 SDL_GLView = new BGLView (Bounds (), "SDL GLView",
   234                 SDL_GLView = new BGLView(Bounds(), "SDL GLView",
   235                                           B_FOLLOW_ALL_SIDES,
   235                                          B_FOLLOW_ALL_SIDES,
   236                                           (B_WILL_DRAW | B_FRAME_EVENTS),
   236                                          (B_WILL_DRAW | B_FRAME_EVENTS),
   237                                           gl_flags);
   237                                          gl_flags);
   238             }
   238             }
   239             if (the_view != SDL_GLView) {
   239             if (the_view != SDL_GLView) {
   240                 if (the_view) {
   240                 if (the_view) {
   241                     RemoveChild (the_view);
   241                     RemoveChild(the_view);
   242                 }
   242                 }
   243                 AddChild (SDL_GLView);
   243                 AddChild(SDL_GLView);
   244                 SDL_GLView->LockGL ();
   244                 SDL_GLView->LockGL();
   245                 the_view = SDL_GLView;
   245                 the_view = SDL_GLView;
   246             }
   246             }
   247 #else
   247 #else
   248             SDL_SetError ("OpenGL support not enabled");
   248             SDL_SetError("OpenGL support not enabled");
   249             retval = -1;
   249             retval = -1;
   250 #endif
   250 #endif
   251         } else {
   251         } else {
   252             if (SDL_View == NULL) {
   252             if (SDL_View == NULL) {
   253                 SDL_View = new SDL_BView (Bounds ());
   253                 SDL_View = new SDL_BView(Bounds());
   254             }
   254             }
   255             if (the_view != SDL_View) {
   255             if (the_view != SDL_View) {
   256                 if (the_view) {
   256                 if (the_view) {
   257 #if SDL_VIDEO_OPENGL
   257 #if SDL_VIDEO_OPENGL
   258                     if (the_view == SDL_GLView) {
   258                     if (the_view == SDL_GLView) {
   259                         SDL_GLView->UnlockGL ();
   259                         SDL_GLView->UnlockGL();
   260                     }
   260                     }
   261 #endif
   261 #endif
   262                     RemoveChild (the_view);
   262                     RemoveChild(the_view);
   263                 }
   263                 }
   264                 AddChild (SDL_View);
   264                 AddChild(SDL_View);
   265                 the_view = SDL_View;
   265                 the_view = SDL_View;
   266             }
   266             }
   267         }
   267         }
   268         Unlock ();
   268         Unlock();
   269         return (retval);
   269         return (retval);
   270     }
   270     }
   271     virtual void SetBitmap (BBitmap * bitmap)
   271     virtual void SetBitmap(BBitmap * bitmap)
   272     {
   272     {
   273         SDL_View->SetBitmap (bitmap);
   273         SDL_View->SetBitmap(bitmap);
   274     }
   274     }
   275     virtual void SetXYOffset (int x, int y)
   275     virtual void SetXYOffset(int x, int y)
   276     {
   276     {
   277 #if SDL_VIDEO_OPENGL
   277 #if SDL_VIDEO_OPENGL
   278         if (the_view == SDL_GLView) {
   278         if (the_view == SDL_GLView) {
   279             return;
   279             return;
   280         }
   280         }
   281 #endif
   281 #endif
   282         SDL_View->SetXYOffset (x, y);
   282         SDL_View->SetXYOffset(x, y);
   283     }
   283     }
   284     virtual void GetXYOffset (int &x, int &y)
   284     virtual void GetXYOffset(int &x, int &y)
   285     {
   285     {
   286 #if SDL_VIDEO_OPENGL
   286 #if SDL_VIDEO_OPENGL
   287         if (the_view == SDL_GLView) {
   287         if (the_view == SDL_GLView) {
   288             x = 0;
   288             x = 0;
   289             y = 0;
   289             y = 0;
   290             return;
   290             return;
   291         }
   291         }
   292 #endif
   292 #endif
   293         SDL_View->GetXYOffset (x, y);
   293         SDL_View->GetXYOffset(x, y);
   294     }
   294     }
   295     virtual bool BeginDraw (void)
   295     virtual bool BeginDraw(void)
   296     {
   296     {
   297         return (Lock ());
   297         return (Lock());
   298     }
   298     }
   299     virtual void DrawAsync (BRect updateRect)
   299     virtual void DrawAsync(BRect updateRect)
   300     {
   300     {
   301         SDL_View->DrawAsync (updateRect);
   301         SDL_View->DrawAsync(updateRect);
   302     }
   302     }
   303     virtual void EndDraw (void)
   303     virtual void EndDraw(void)
   304     {
   304     {
   305         SDL_View->Sync ();
   305         SDL_View->Sync();
   306         Unlock ();
   306         Unlock();
   307     }
   307     }
   308 #if SDL_VIDEO_OPENGL
   308 #if SDL_VIDEO_OPENGL
   309     virtual void SwapBuffers (void)
   309     virtual void SwapBuffers(void)
   310     {
   310     {
   311         SDL_GLView->UnlockGL ();
   311         SDL_GLView->UnlockGL();
   312         SDL_GLView->LockGL ();
   312         SDL_GLView->LockGL();
   313         SDL_GLView->SwapBuffers ();
   313         SDL_GLView->SwapBuffers();
   314     }
   314     }
   315 #endif
   315 #endif
   316     virtual BView *View (void)
   316     virtual BView *View(void)
   317     {
   317     {
   318         return (the_view);
   318         return (the_view);
   319     }
   319     }
   320 
   320 
   321     /* Hook functions -- overridden */
   321     /* Hook functions -- overridden */
   322     virtual void Minimize (bool minimize)
   322     virtual void Minimize(bool minimize)
   323     {
   323     {
   324         /* This is only called when mimimized, not when restored */
   324         /* This is only called when mimimized, not when restored */
   325         //SDL_PrivateAppActive(minimize, SDL_APPACTIVE);
   325         //SDL_PrivateAppActive(minimize, SDL_APPACTIVE);
   326         BWindow::Minimize (minimize);
   326         BWindow::Minimize(minimize);
   327     }
   327     }
   328     virtual void WindowActivated (bool active)
   328     virtual void WindowActivated(bool active)
   329     {
   329     {
   330         SDL_PrivateAppActive (active, SDL_APPINPUTFOCUS);
   330         SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS);
   331     }
   331     }
   332     virtual bool QuitRequested (void)
   332     virtual bool QuitRequested(void)
   333     {
   333     {
   334         if (SDL_BeAppActive > 0) {
   334         if (SDL_BeAppActive > 0) {
   335             SDL_PrivateQuit ();
   335             SDL_PrivateQuit();
   336             /* We don't ever actually close the window here because
   336             /* We don't ever actually close the window here because
   337                the application should respond to the quit request,
   337                the application should respond to the quit request,
   338                or ignore it as desired.
   338                or ignore it as desired.
   339              */
   339              */
   340             return (false);
   340             return (false);
   341         }
   341         }
   342         return (true);          /* Close the app window */
   342         return (true);          /* Close the app window */
   343     }
   343     }
   344     virtual void Quit ()
   344     virtual void Quit()
   345     {
   345     {
   346         if (!IsLocked ())
   346         if (!IsLocked())
   347             Lock ();
   347             Lock();
   348         BDirectWindow::Quit ();
   348         BDirectWindow::Quit();
   349     }
   349     }
   350 
   350 
   351     virtual int16 Translate2Unicode (const char *buf)
   351     virtual int16 Translate2Unicode(const char *buf)
   352     {
   352     {
   353         int32 state, srclen, dstlen;
   353         int32 state, srclen, dstlen;
   354         unsigned char destbuf[2];
   354         unsigned char destbuf[2];
   355         Uint16 unicode = 0;
   355         Uint16 unicode = 0;
   356 
   356 
   357         if ((uchar) buf[0] > 127) {
   357         if ((uchar) buf[0] > 127) {
   358             state = 0;
   358             state = 0;
   359             srclen = SDL_strlen (buf);
   359             srclen = SDL_strlen(buf);
   360             dstlen = sizeof (destbuf);
   360             dstlen = sizeof(destbuf);
   361             convert_from_utf8 (B_UNICODE_CONVERSION, buf, &srclen,
   361             convert_from_utf8(B_UNICODE_CONVERSION, buf, &srclen,
   362                                (char *) destbuf, &dstlen, &state);
   362                               (char *) destbuf, &dstlen, &state);
   363             unicode = destbuf[0];
   363             unicode = destbuf[0];
   364             unicode <<= 8;
   364             unicode <<= 8;
   365             unicode |= destbuf[1];
   365             unicode |= destbuf[1];
   366         } else
   366         } else
   367             unicode = buf[0];
   367             unicode = buf[0];
   368 
   368 
   369         /* For some reason function keys map to control characters */
   369         /* For some reason function keys map to control characters */
   370 # define CTRL(X)	((X)-'@')
   370 # define CTRL(X)	((X)-'@')
   371         switch (unicode) {
   371         switch (unicode) {
   372         case CTRL ('A'):
   372         case CTRL('A'):
   373         case CTRL ('B'):
   373         case CTRL('B'):
   374         case CTRL ('C'):
   374         case CTRL('C'):
   375         case CTRL ('D'):
   375         case CTRL('D'):
   376         case CTRL ('E'):
   376         case CTRL('E'):
   377         case CTRL ('K'):
   377         case CTRL('K'):
   378         case CTRL ('L'):
   378         case CTRL('L'):
   379         case CTRL ('P'):
   379         case CTRL('P'):
   380             if (!(SDL_GetModState () & KMOD_CTRL))
   380             if (!(SDL_GetModState() & KMOD_CTRL))
   381                 unicode = 0;
   381                 unicode = 0;
   382             break;
   382             break;
   383             /* Keyboard input maps newline to carriage return */
   383             /* Keyboard input maps newline to carriage return */
   384         case '\n':
   384         case '\n':
   385             unicode = '\r';
   385             unicode = '\r';
   389         }
   389         }
   390 
   390 
   391         return unicode;
   391         return unicode;
   392     }
   392     }
   393 
   393 
   394     virtual void DispatchMessage (BMessage * msg, BHandler * target)
   394     virtual void DispatchMessage(BMessage * msg, BHandler * target)
   395     {
   395     {
   396         switch (msg->what) {
   396         switch (msg->what) {
   397         case B_MOUSE_MOVED:
   397         case B_MOUSE_MOVED:
   398             {
   398             {
   399                 BPoint where;
   399                 BPoint where;
   400                 int32 transit;
   400                 int32 transit;
   401                 if (msg->FindPoint ("where", &where) == B_OK
   401                 if (msg->FindPoint("where", &where) == B_OK
   402                     && msg->FindInt32 ("be:transit", &transit) == B_OK) {
   402                     && msg->FindInt32("be:transit", &transit) == B_OK) {
   403                     if (transit == B_EXITED_VIEW) {
   403                     if (transit == B_EXITED_VIEW) {
   404                         if (SDL_GetAppState () & SDL_APPMOUSEFOCUS) {
   404                         if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) {
   405                             SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
   405                             SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
   406                             be_app->SetCursor (B_HAND_CURSOR);
   406                             be_app->SetCursor(B_HAND_CURSOR);
   407                         }
   407                         }
   408                     } else {
   408                     } else {
   409                         int x, y;
   409                         int x, y;
   410                         if (!(SDL_GetAppState () & SDL_APPMOUSEFOCUS)) {
   410                         if (!(SDL_GetAppState() & SDL_APPMOUSEFOCUS)) {
   411                             SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
   411                             SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   412                             SDL_SetCursor (NULL);
   412                             SDL_SetCursor(NULL);
   413                         }
   413                         }
   414                         GetXYOffset (x, y);
   414                         GetXYOffset(x, y);
   415                         x = (int) where.x - x;
   415                         x = (int) where.x - x;
   416                         y = (int) where.y - y;
   416                         y = (int) where.y - y;
   417                         SDL_PrivateMouseMotion (0, 0, x, y);
   417                         SDL_PrivateMouseMotion(0, 0, x, y);
   418                     }
   418                     }
   419                 }
   419                 }
   420                 break;
   420                 break;
   421             }
   421             }
   422 
   422 
   424             {
   424             {
   425                 /*      it looks like mouse down is send only for first clicked
   425                 /*      it looks like mouse down is send only for first clicked
   426                    button, each next is not send while last one is holded */
   426                    button, each next is not send while last one is holded */
   427                 int32 buttons;
   427                 int32 buttons;
   428                 int sdl_buttons = 0;
   428                 int sdl_buttons = 0;
   429                 if (msg->FindInt32 ("buttons", &buttons) == B_OK) {
   429                 if (msg->FindInt32("buttons", &buttons) == B_OK) {
   430                     /* Add any mouse button events */
   430                     /* Add any mouse button events */
   431                     if (buttons & B_PRIMARY_MOUSE_BUTTON) {
   431                     if (buttons & B_PRIMARY_MOUSE_BUTTON) {
   432                         sdl_buttons |= SDL_BUTTON_LEFT;
   432                         sdl_buttons |= SDL_BUTTON_LEFT;
   433                     }
   433                     }
   434                     if (buttons & B_SECONDARY_MOUSE_BUTTON) {
   434                     if (buttons & B_SECONDARY_MOUSE_BUTTON) {
   435                         sdl_buttons |= SDL_BUTTON_RIGHT;
   435                         sdl_buttons |= SDL_BUTTON_RIGHT;
   436                     }
   436                     }
   437                     if (buttons & B_TERTIARY_MOUSE_BUTTON) {
   437                     if (buttons & B_TERTIARY_MOUSE_BUTTON) {
   438                         sdl_buttons |= SDL_BUTTON_MIDDLE;
   438                         sdl_buttons |= SDL_BUTTON_MIDDLE;
   439                     }
   439                     }
   440                     SDL_PrivateMouseButton (SDL_PRESSED, sdl_buttons, 0, 0);
   440                     SDL_PrivateMouseButton(SDL_PRESSED, sdl_buttons, 0, 0);
   441 
   441 
   442                     last_buttons = buttons;
   442                     last_buttons = buttons;
   443                 }
   443                 }
   444                 break;
   444                 break;
   445             }
   445             }
   455                    first button down (ie. it's no send if we click another button
   455                    first button down (ie. it's no send if we click another button
   456                    without releasing previous one first) - but that's probably
   456                    without releasing previous one first) - but that's probably
   457                    because of how drivers are written?, not BeOS itself. */
   457                    because of how drivers are written?, not BeOS itself. */
   458                 int32 buttons;
   458                 int32 buttons;
   459                 int sdl_buttons = 0;
   459                 int sdl_buttons = 0;
   460                 if (msg->FindInt32 ("buttons", &buttons) == B_OK) {
   460                 if (msg->FindInt32("buttons", &buttons) == B_OK) {
   461                     /* Add any mouse button events */
   461                     /* Add any mouse button events */
   462                     if ((buttons ^ B_PRIMARY_MOUSE_BUTTON) & last_buttons) {
   462                     if ((buttons ^ B_PRIMARY_MOUSE_BUTTON) & last_buttons) {
   463                         sdl_buttons |= SDL_BUTTON_LEFT;
   463                         sdl_buttons |= SDL_BUTTON_LEFT;
   464                     }
   464                     }
   465                     if ((buttons ^ B_SECONDARY_MOUSE_BUTTON) & last_buttons) {
   465                     if ((buttons ^ B_SECONDARY_MOUSE_BUTTON) & last_buttons) {
   466                         sdl_buttons |= SDL_BUTTON_RIGHT;
   466                         sdl_buttons |= SDL_BUTTON_RIGHT;
   467                     }
   467                     }
   468                     if ((buttons ^ B_TERTIARY_MOUSE_BUTTON) & last_buttons) {
   468                     if ((buttons ^ B_TERTIARY_MOUSE_BUTTON) & last_buttons) {
   469                         sdl_buttons |= SDL_BUTTON_MIDDLE;
   469                         sdl_buttons |= SDL_BUTTON_MIDDLE;
   470                     }
   470                     }
   471                     SDL_PrivateMouseButton (SDL_RELEASED, sdl_buttons, 0, 0);
   471                     SDL_PrivateMouseButton(SDL_RELEASED, sdl_buttons, 0, 0);
   472 
   472 
   473                     last_buttons = buttons;
   473                     last_buttons = buttons;
   474                 }
   474                 }
   475                 break;
   475                 break;
   476             }
   476             }
   477 
   477 
   478         case B_MOUSE_WHEEL_CHANGED:
   478         case B_MOUSE_WHEEL_CHANGED:
   479             {
   479             {
   480                 float x, y;
   480                 float x, y;
   481                 x = y = 0;
   481                 x = y = 0;
   482                 if (msg->FindFloat ("be:wheel_delta_x", &x) == B_OK
   482                 if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK
   483                     && msg->FindFloat ("be:wheel_delta_y", &y) == B_OK) {
   483                     && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) {
   484                     if (x < 0 || y < 0) {
   484                     if (x < 0 || y < 0) {
   485                         SDL_PrivateMouseButton (SDL_PRESSED,
   485                         SDL_PrivateMouseButton(SDL_PRESSED,
   486                                                 SDL_BUTTON_WHEELDOWN, 0, 0);
   486                                                SDL_BUTTON_WHEELDOWN, 0, 0);
   487                         SDL_PrivateMouseButton (SDL_RELEASED,
   487                         SDL_PrivateMouseButton(SDL_RELEASED,
   488                                                 SDL_BUTTON_WHEELDOWN, 0, 0);
   488                                                SDL_BUTTON_WHEELDOWN, 0, 0);
   489                     } else if (x > 0 || y > 0) {
   489                     } else if (x > 0 || y > 0) {
   490                         SDL_PrivateMouseButton (SDL_PRESSED,
   490                         SDL_PrivateMouseButton(SDL_PRESSED,
   491                                                 SDL_BUTTON_WHEELUP, 0, 0);
   491                                                SDL_BUTTON_WHEELUP, 0, 0);
   492                         SDL_PrivateMouseButton (SDL_RELEASED,
   492                         SDL_PrivateMouseButton(SDL_RELEASED,
   493                                                 SDL_BUTTON_WHEELUP, 0, 0);
   493                                                SDL_BUTTON_WHEELUP, 0, 0);
   494                     }
   494                     }
   495                 }
   495                 }
   496                 break;
   496                 break;
   497             }
   497             }
   498 
   498 
   501             {
   501             {
   502                 int32 key;
   502                 int32 key;
   503                 int32 modifiers;
   503                 int32 modifiers;
   504                 int32 key_repeat;
   504                 int32 key_repeat;
   505                 /* Workaround for SDL message queue being filled too fast because of BeOS own key-repeat mechanism */
   505                 /* Workaround for SDL message queue being filled too fast because of BeOS own key-repeat mechanism */
   506                 if (msg->FindInt32 ("be:key_repeat", &key_repeat) == B_OK
   506                 if (msg->FindInt32("be:key_repeat", &key_repeat) == B_OK
   507                     && key_repeat > 0)
   507                     && key_repeat > 0)
   508                     break;
   508                     break;
   509 
   509 
   510                 if (msg->FindInt32 ("key", &key) == B_OK
   510                 if (msg->FindInt32("key", &key) == B_OK
   511                     && msg->FindInt32 ("modifiers", &modifiers) == B_OK) {
   511                     && msg->FindInt32("modifiers", &modifiers) == B_OK) {
   512                     SDL_keysym keysym;
   512                     SDL_keysym keysym;
   513                     keysym.scancode = key;
   513                     keysym.scancode = key;
   514                     if ((key > 0) && (key < 128)) {
   514                     if ((key > 0) && (key < 128)) {
   515                         keysym.sym = keymap[key];
   515                         keysym.sym = keymap[key];
   516                     } else {
   516                     } else {
   521                        anyway, and doesn't care about what we setup here */
   521                        anyway, and doesn't care about what we setup here */
   522                     keysym.mod = KMOD_NONE;
   522                     keysym.mod = KMOD_NONE;
   523                     keysym.unicode = 0;
   523                     keysym.unicode = 0;
   524                     if (SDL_TranslateUNICODE) {
   524                     if (SDL_TranslateUNICODE) {
   525                         const char *bytes;
   525                         const char *bytes;
   526                         if (msg->FindString ("bytes", &bytes) == B_OK) {
   526                         if (msg->FindString("bytes", &bytes) == B_OK) {
   527                             /*      FIX THIS?
   527                             /*      FIX THIS?
   528                                this cares only about first "letter",
   528                                this cares only about first "letter",
   529                                so if someone maps some key to print
   529                                so if someone maps some key to print
   530                                "BeOS rulez!" only "B" will be used. */
   530                                "BeOS rulez!" only "B" will be used. */
   531                             keysym.unicode = Translate2Unicode (bytes);
   531                             keysym.unicode = Translate2Unicode(bytes);
   532                         }
   532                         }
   533                     }
   533                     }
   534                     SDL_PrivateKeyboard (SDL_PRESSED, &keysym);
   534                     SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   535                 }
   535                 }
   536                 break;
   536                 break;
   537             }
   537             }
   538 
   538 
   539         case B_KEY_UP:
   539         case B_KEY_UP:
   540         case B_UNMAPPED_KEY_UP:        /* modifier keys are unmapped */
   540         case B_UNMAPPED_KEY_UP:        /* modifier keys are unmapped */
   541             {
   541             {
   542                 int32 key;
   542                 int32 key;
   543                 int32 modifiers;
   543                 int32 modifiers;
   544                 if (msg->FindInt32 ("key", &key) == B_OK
   544                 if (msg->FindInt32("key", &key) == B_OK
   545                     && msg->FindInt32 ("modifiers", &modifiers) == B_OK) {
   545                     && msg->FindInt32("modifiers", &modifiers) == B_OK) {
   546                     SDL_keysym keysym;
   546                     SDL_keysym keysym;
   547                     keysym.scancode = key;
   547                     keysym.scancode = key;
   548                     if ((key > 0) && (key < 128)) {
   548                     if ((key > 0) && (key < 128)) {
   549                         keysym.sym = keymap[key];
   549                         keysym.sym = keymap[key];
   550                     } else {
   550                     } else {
   552                     }
   552                     }
   553                     keysym.mod = KMOD_NONE;     /* FIX THIS? */
   553                     keysym.mod = KMOD_NONE;     /* FIX THIS? */
   554                     keysym.unicode = 0;
   554                     keysym.unicode = 0;
   555                     if (SDL_TranslateUNICODE) {
   555                     if (SDL_TranslateUNICODE) {
   556                         const char *bytes;
   556                         const char *bytes;
   557                         if (msg->FindString ("bytes", &bytes) == B_OK) {
   557                         if (msg->FindString("bytes", &bytes) == B_OK) {
   558                             keysym.unicode = Translate2Unicode (bytes);
   558                             keysym.unicode = Translate2Unicode(bytes);
   559                         }
   559                         }
   560                     }
   560                     }
   561                     SDL_PrivateKeyboard (SDL_RELEASED, &keysym);
   561                     SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
   562                 }
   562                 }
   563                 break;
   563                 break;
   564             }
   564             }
   565 
   565 
   566         default:
   566         default:
   570                - PrintScreen to make screenshot into /boot/home
   570                - PrintScreen to make screenshot into /boot/home
   571                - etc.. */
   571                - etc.. */
   572             //BDirectWindow::DispatchMessage(msg, target);
   572             //BDirectWindow::DispatchMessage(msg, target);
   573             break;
   573             break;
   574         }
   574         }
   575         BDirectWindow::DispatchMessage (msg, target);
   575         BDirectWindow::DispatchMessage(msg, target);
   576     }
   576     }
   577 
   577 
   578   private:
   578   private:
   579 #if SDL_VIDEO_OPENGL
   579 #if SDL_VIDEO_OPENGL
   580     BGLView * SDL_GLView;
   580     BGLView * SDL_GLView;