From 99e5df6eec2b45c28bd30ca140884eafb2fcc9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Wed, 7 Jul 2004 21:51:43 +0000 Subject: [PATCH] now uses KeyDown() KeyUp() MessageReceived() instead of Pulse() git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8353 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/keymap/KeymapWindow.cpp | 134 ++++++++++++++++++++++++------ src/prefs/keymap/KeymapWindow.h | 11 ++- 2 files changed, 115 insertions(+), 30 deletions(-) diff --git a/src/prefs/keymap/KeymapWindow.cpp b/src/prefs/keymap/KeymapWindow.cpp index ec86fb6fa3..711196199b 100644 --- a/src/prefs/keymap/KeymapWindow.cpp +++ b/src/prefs/keymap/KeymapWindow.cpp @@ -12,7 +12,21 @@ #include "KeymapWindow.h" #include "KeymapListItem.h" #include "KeymapApplication.h" -#include "messages.h" + +#define MENU_FILE_OPEN 'mMFO' +#define MENU_FILE_SAVE 'mMFS' +#define MENU_FILE_SAVE_AS 'mMFA' +#define MENU_EDIT_UNDO 'mMEU' +#define MENU_EDIT_CUT 'mMEX' +#define MENU_EDIT_COPY 'mMEC' +#define MENU_EDIT_PASTE 'mMEV' +#define MENU_EDIT_CLEAR 'mMEL' +#define MENU_EDIT_SELECT_ALL 'mMEA' +#define MENU_FONT_CHANGED 'mMFC' +#define SYSTEM_MAP_SELECTED 'SmST' +#define USER_MAP_SELECTED 'UmST' +#define USE_KEYMAP 'UkyM' +#define REVERT 'Rvrt' KeymapWindow::KeymapWindow( BRect frame ) : BWindow( frame, WINDOW_TITLE, B_TITLED_WINDOW, @@ -53,11 +67,10 @@ KeymapWindow::KeymapWindow( BRect frame ) fMapView = new MapView(BRect(149,29,601,209), "mapView"); AddChild(fMapView); - - SetPulseRate(10000); } + BMenuBar * KeymapWindow::AddMenuBar() { @@ -261,6 +274,37 @@ KeymapWindow::MessageReceived( BMessage* message ) case REVERT: // do nothing, just like the original break; + case B_KEY_DOWN: + case B_KEY_UP: + case B_UNMAPPED_KEY_DOWN: + case B_UNMAPPED_KEY_UP: + case B_MODIFIERS_CHANGED: { + key_info info; + const uint8 *states; + ssize_t size; + bool need_update = false; + + if ((message->FindData("states", 'UBYT', (const void **)&states, &size)==B_OK) + && (message->FindInt32("modifiers", (int32 *)&info.modifiers) == B_OK)) { + if (fMapView->fOldKeyInfo.modifiers != info.modifiers) { + need_update = true; + } + + for (int8 i=0; i<16; i++) + if (fMapView->fOldKeyInfo.key_states[i] != states[i]) { + need_update = true; + break; + } + + if (need_update) { + fMapView->fOldKeyInfo.modifiers = info.modifiers; + for (int8 j=0; j<16; j++) + fMapView->fOldKeyInfo.key_states[j] = states[j]; + fMapView->Invalidate(); + } + } + break; + } default: BWindow::MessageReceived( message ); break; @@ -331,12 +375,19 @@ KeymapWindow::UseKeymap() MapView::MapView(BRect rect, const char *name) - : BView(rect, name, B_FOLLOW_LEFT|B_FOLLOW_TOP, B_WILL_DRAW | B_PULSE_NEEDED) + : BView(rect, name, B_FOLLOW_LEFT|B_FOLLOW_TOP, B_WILL_DRAW) { } +void +MapView::AttachedToWindow() +{ + SetEventMask(B_KEYBOARD_EVENTS, B_NO_POINTER_HISTORY); +} + + void MapView::Draw(BRect rect) { @@ -845,7 +896,7 @@ MapView::DrawKey(BRect rect, bool pressed, bool vertical) SetHighColor(0,0,0); StrokeRect(r); - if(!pressed) { + if (!pressed) { r.InsetBySelf(1,1); SetHighColor(64,64,64); StrokeRect(r); @@ -886,7 +937,7 @@ MapView::DrawKey(BRect rect, bool pressed, bool vertical) r.bottom -= 1; BRect fillRect = r; - if(!vertical) { + if (!vertical) { int32 w1 = 4; int32 w2 = 3; if(rect.Width() > 20) { @@ -959,27 +1010,58 @@ MapView::DrawBorder(BRect borderRect) StrokeLine(BPoint(borderRect.right, borderRect.top + 1)); } -void -MapView::Pulse() -{ - key_info info; - bool need_update = false; - get_key_info(&info); - if (fOldKeyInfo.modifiers != info.modifiers) { - need_update = true; - } - - for (int8 i=0; i<16; i++) - if (fOldKeyInfo.key_states[i] != info.key_states[i]) { - need_update = true; +void +MapView::MessageReceived(BMessage *msg) +{ + switch (msg->what) { + case B_KEY_DOWN: + case B_KEY_UP: + case B_UNMAPPED_KEY_DOWN: + case B_UNMAPPED_KEY_UP: + case B_MODIFIERS_CHANGED: { + key_info info; + const uint8 *states; + ssize_t size; + bool need_update = false; + + if ((msg->FindData("states", 'UBYT', (const void **)&states, &size)==B_OK) + && (msg->FindInt32("modifiers", (int32 *)&info.modifiers) == B_OK)) { + if (fOldKeyInfo.modifiers != info.modifiers) { + need_update = true; + } + + for (int8 i=0; i<16; i++) + if (fOldKeyInfo.key_states[i] != states[i]) { + need_update = true; + break; + } + + if (need_update) { + fOldKeyInfo.modifiers = info.modifiers; + for (int8 j=0; j<16; j++) + fOldKeyInfo.key_states[j] = states[j]; + Invalidate(); + } + } break; } - - if (need_update) { - fOldKeyInfo.modifiers = info.modifiers; - for (int8 j=0; j<16; j++) - fOldKeyInfo.key_states[j] = info.key_states[j]; - Invalidate(); - } + default: + BView::MessageReceived(msg); + } + +} + + +void +MapView::KeyDown(const char* bytes, int32 numBytes) +{ + MessageReceived(Window()->CurrentMessage()); +} + + +void +MapView::KeyUp(const char* bytes, int32 numBytes) +{ + MessageReceived(Window()->CurrentMessage()); } diff --git a/src/prefs/keymap/KeymapWindow.h b/src/prefs/keymap/KeymapWindow.h index 53b77da3bf..a3a4cfaf2a 100644 --- a/src/prefs/keymap/KeymapWindow.h +++ b/src/prefs/keymap/KeymapWindow.h @@ -1,12 +1,10 @@ #ifndef OBOS_KEYMAP_WINDOW_H #define OBOS_KEYMAP_WINDOW_H - #include #include #include - #if !DEBUG #define WINDOW_TITLE "Keymap" #else @@ -25,8 +23,12 @@ public: void Draw(BRect rect); void DrawKey(BRect rect, bool pressed, bool vertical = false); void DrawBorder(BRect borderRect); - void Pulse(); - + //void Pulse(); + void AttachedToWindow(); + void KeyDown(const char* bytes, int32 numBytes); + void KeyUp(const char* bytes, int32 numBytes); + void MessageReceived(BMessage *msg); + key_info fOldKeyInfo; }; @@ -36,6 +38,7 @@ public: KeymapWindow( BRect frame ); bool QuitRequested(); void MessageReceived( BMessage* message ); + //void AllAttached(); protected: KeymapApplication *fApplication;