now uses KeyDown() KeyUp() MessageReceived() instead of Pulse()

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8353 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2004-07-07 21:51:43 +00:00
parent 9dc11f9bc7
commit 99e5df6eec
2 changed files with 115 additions and 30 deletions

View File

@ -12,7 +12,21 @@
#include "KeymapWindow.h" #include "KeymapWindow.h"
#include "KeymapListItem.h" #include "KeymapListItem.h"
#include "KeymapApplication.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 ) KeymapWindow::KeymapWindow( BRect frame )
: BWindow( frame, WINDOW_TITLE, B_TITLED_WINDOW, : BWindow( frame, WINDOW_TITLE, B_TITLED_WINDOW,
@ -53,11 +67,10 @@ KeymapWindow::KeymapWindow( BRect frame )
fMapView = new MapView(BRect(149,29,601,209), "mapView"); fMapView = new MapView(BRect(149,29,601,209), "mapView");
AddChild(fMapView); AddChild(fMapView);
SetPulseRate(10000);
} }
BMenuBar * BMenuBar *
KeymapWindow::AddMenuBar() KeymapWindow::AddMenuBar()
{ {
@ -261,6 +274,37 @@ KeymapWindow::MessageReceived( BMessage* message )
case REVERT: // do nothing, just like the original case REVERT: // do nothing, just like the original
break; 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: default:
BWindow::MessageReceived( message ); BWindow::MessageReceived( message );
break; break;
@ -331,12 +375,19 @@ KeymapWindow::UseKeymap()
MapView::MapView(BRect rect, const char *name) 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 void
MapView::Draw(BRect rect) MapView::Draw(BRect rect)
{ {
@ -845,7 +896,7 @@ MapView::DrawKey(BRect rect, bool pressed, bool vertical)
SetHighColor(0,0,0); SetHighColor(0,0,0);
StrokeRect(r); StrokeRect(r);
if(!pressed) { if (!pressed) {
r.InsetBySelf(1,1); r.InsetBySelf(1,1);
SetHighColor(64,64,64); SetHighColor(64,64,64);
StrokeRect(r); StrokeRect(r);
@ -886,7 +937,7 @@ MapView::DrawKey(BRect rect, bool pressed, bool vertical)
r.bottom -= 1; r.bottom -= 1;
BRect fillRect = r; BRect fillRect = r;
if(!vertical) { if (!vertical) {
int32 w1 = 4; int32 w1 = 4;
int32 w2 = 3; int32 w2 = 3;
if(rect.Width() > 20) { if(rect.Width() > 20) {
@ -959,27 +1010,58 @@ MapView::DrawBorder(BRect borderRect)
StrokeLine(BPoint(borderRect.right, borderRect.top + 1)); 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) { void
need_update = true; MapView::MessageReceived(BMessage *msg)
} {
switch (msg->what) {
for (int8 i=0; i<16; i++) case B_KEY_DOWN:
if (fOldKeyInfo.key_states[i] != info.key_states[i]) { case B_KEY_UP:
need_update = true; 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; break;
} }
default:
if (need_update) { BView::MessageReceived(msg);
fOldKeyInfo.modifiers = info.modifiers; }
for (int8 j=0; j<16; j++)
fOldKeyInfo.key_states[j] = info.key_states[j]; }
Invalidate();
}
void
MapView::KeyDown(const char* bytes, int32 numBytes)
{
MessageReceived(Window()->CurrentMessage());
}
void
MapView::KeyUp(const char* bytes, int32 numBytes)
{
MessageReceived(Window()->CurrentMessage());
} }

View File

@ -1,12 +1,10 @@
#ifndef OBOS_KEYMAP_WINDOW_H #ifndef OBOS_KEYMAP_WINDOW_H
#define OBOS_KEYMAP_WINDOW_H #define OBOS_KEYMAP_WINDOW_H
#include <interface/Window.h> #include <interface/Window.h>
#include <support/List.h> #include <support/List.h>
#include <interface/MenuBar.h> #include <interface/MenuBar.h>
#if !DEBUG #if !DEBUG
#define WINDOW_TITLE "Keymap" #define WINDOW_TITLE "Keymap"
#else #else
@ -25,8 +23,12 @@ public:
void Draw(BRect rect); void Draw(BRect rect);
void DrawKey(BRect rect, bool pressed, bool vertical = false); void DrawKey(BRect rect, bool pressed, bool vertical = false);
void DrawBorder(BRect borderRect); 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; key_info fOldKeyInfo;
}; };
@ -36,6 +38,7 @@ public:
KeymapWindow( BRect frame ); KeymapWindow( BRect frame );
bool QuitRequested(); bool QuitRequested();
void MessageReceived( BMessage* message ); void MessageReceived( BMessage* message );
//void AllAttached();
protected: protected:
KeymapApplication *fApplication; KeymapApplication *fApplication;