BView::MouseUp/KeyDown/KeyUp() hook methods are called for the BView for which the action takes place

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11241 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adi Oanca
2005-02-03 22:46:58 +00:00
parent 239fc54e70
commit 79c8040e93
+34 -23
View File
@@ -788,30 +788,34 @@ void BWindow::DispatchMessage(BMessage *msg, BHandler *target)
uint32 modifiers; uint32 modifiers;
int32 raw_char; int32 raw_char;
const char *string=NULL; const char *string=NULL;
int32 viewToken;
msg->FindInt32( "modifiers", (int32*)&modifiers ); msg->FindInt32( "modifiers", (int32*)&modifiers );
msg->FindInt32( "raw_char", &raw_char ); msg->FindInt32( "raw_char", &raw_char );
msg->FindString( "bytes", &string ); msg->FindString( "bytes", &string );
msg->FindInt32( "haiku:token", &viewToken );
msg->RemoveName("haiku:token");
// TODO: it is NOT "bytes" field you should pass to KeyDown(), it is "byte" field. if ( !handleKeyDown( string[0], (uint32)modifiers) )
if ( !handleKeyDown( raw_char, (uint32)modifiers) )
{ {
if(fFocus) if(fFocus)
fFocus->KeyDown( string, strlen(string)-1 ); fFocus->KeyDown( string, strlen(string)-1 );
else else
BLooper::DispatchMessage(msg, target); printf("Adi: No Focus\n");
} }
break; break;
} }
case B_KEY_UP: case B_KEY_UP:
{ {
const char *string=NULL; const char *string=NULL;
int32 viewToken;
msg->FindString( "bytes", &string ); msg->FindString( "bytes", &string );
msg->FindInt32( "haiku:token", &viewToken );
msg->RemoveName("haiku:token");
if(fFocus) if(fFocus)
fFocus->KeyUp( string, strlen(string)-1 ); fFocus->KeyUp( string, strlen(string)-1 );
else
BLooper::DispatchMessage(msg, target);
break; break;
} }
@@ -870,7 +874,7 @@ void BWindow::DispatchMessage(BMessage *msg, BHandler *target)
targetView->MouseDown(where); targetView->MouseDown(where);
} }
// TODO: use the following line later, instead of the above 2. // TODO: use the following line later, instead of the above.
// sendMessageUsingEventMask( B_MOUSE_DOWN, where ); // sendMessageUsingEventMask( B_MOUSE_DOWN, where );
break; break;
} }
@@ -878,11 +882,23 @@ void BWindow::DispatchMessage(BMessage *msg, BHandler *target)
{ {
BPoint where; BPoint where;
uint32 modifiers; uint32 modifiers;
int32 viewToken;
BView *targetView;
msg->FindPoint( "where", &where ); msg->FindPoint( "where", &where );
msg->FindInt32( "modifiers", (int32*)&modifiers ); msg->FindInt32( "modifiers", (int32*)&modifiers );
msg->FindInt32( "haiku:token", &viewToken );
msg->RemoveName("haiku:token");
sendMessageUsingEventMask( B_MOUSE_UP, where ); targetView = findView(top_view, viewToken);
if (viewToken != B_NULL_TOKEN && targetView)
{
targetView->ConvertFromScreen(&where);
targetView->MouseUp(where);
}
// TODO: use the following line later, instead of the above.
// sendMessageUsingEventMask( B_MOUSE_UP, where );
break; break;
} }
case B_MOUSE_MOVED: case B_MOUSE_MOVED:
@@ -2606,12 +2622,12 @@ void BWindow::activateView( BView *aView, bool active ){
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool BWindow::handleKeyDown( int32 raw_char, uint32 modifiers){ bool BWindow::handleKeyDown( const char key, uint32 modifiers){
// TODO: ask people if using 'raw_char' is OK ? // TODO: ask people if using 'raw_char' is OK ?
// handle BMenuBar key // handle BMenuBar key
if ( (raw_char == B_ESCAPE) && (modifiers & B_COMMAND_KEY) if ( (key == B_ESCAPE) && (modifiers & B_COMMAND_KEY)
&& fKeyMenuBar) && fKeyMenuBar)
{ {
@@ -2623,20 +2639,15 @@ bool BWindow::handleKeyDown( int32 raw_char, uint32 modifiers){
} }
// Command+q has been pressed, so, we will quit // Command+q has been pressed, so, we will quit
if ( (raw_char == 'Q' || raw_char == 'q') && modifiers & B_COMMAND_KEY) if ( (key == 'Q' || key == 'q') && modifiers & B_COMMAND_KEY)
{ {
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
return true; return true;
} }
// Keyboard navigation through views!!!! // Keyboard navigation through views!!!!
if ( raw_char == B_TAB) if ( key == B_TAB)
{ {
// even if we have no focus view, we'll say that we will handle TAB key
if (!fFocus)
return true;
BView *nextFocus; BView *nextFocus;
if (modifiers & B_CONTROL_KEY & B_SHIFT_KEY) if (modifiers & B_CONTROL_KEY & B_SHIFT_KEY)
@@ -2656,7 +2667,7 @@ bool BWindow::handleKeyDown( int32 raw_char, uint32 modifiers){
else else
nextFocus = findNextView( fFocus, B_NAVIGABLE ); nextFocus = findNextView( fFocus, B_NAVIGABLE );
if ( nextFocus ) if ( nextFocus && nextFocus != fFocus)
setFocus( nextFocus, false ); setFocus( nextFocus, false );
return true; return true;
@@ -2664,7 +2675,7 @@ bool BWindow::handleKeyDown( int32 raw_char, uint32 modifiers){
// Handle shortcuts // Handle shortcuts
int index; int index;
if ( (index = findShortcut(raw_char, modifiers)) >=0) if ( (index = findShortcut(key, modifiers)) >=0)
{ {
_BCmdKey *cmdKey; _BCmdKey *cmdKey;
@@ -2706,7 +2717,7 @@ bool BWindow::handleKeyDown( int32 raw_char, uint32 modifiers){
} }
// if <ENTER> is pressed and we have a default button // if <ENTER> is pressed and we have a default button
if (DefaultButton() && (raw_char == B_ENTER)) if (DefaultButton() && (key == B_ENTER))
{ {
const char *chars; // just to be sure const char *chars; // just to be sure
CurrentMessage()->FindString("bytes", &chars); CurrentMessage()->FindString("bytes", &chars);
@@ -2970,11 +2981,11 @@ BView* BWindow::findView(BView* aView, BPoint point) const
BView* BWindow::findNextView( BView *focus, uint32 flags) BView* BWindow::findNextView( BView *focus, uint32 flags)
{ {
bool found; if (focus == NULL)
found = false; focus = top_view;
BView *nextFocus; bool found = false;
nextFocus = focus; BView *nextFocus = focus;
// Ufff... this toked me some time... this is the best form I've reached. // Ufff... this toked me some time... this is the best form I've reached.
// This algorithm searches the tree for BViews that accept focus. // This algorithm searches the tree for BViews that accept focus.