Shortcuts now at least somehow work, but the mechanism is still broken.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14867 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include <MessageUtils.h>
|
#include <MessageUtils.h>
|
||||||
#include <WindowAux.h>
|
#include <WindowAux.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@@ -1127,7 +1128,6 @@ void
|
|||||||
BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *msg, BHandler *target)
|
BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *msg, BHandler *target)
|
||||||
{
|
{
|
||||||
// NOTE: I'm not sure if it is OK to use 'key'
|
// NOTE: I'm not sure if it is OK to use 'key'
|
||||||
// TODO: What about locking?!?
|
|
||||||
|
|
||||||
if (msg == NULL)
|
if (msg == NULL)
|
||||||
return;
|
return;
|
||||||
@@ -1135,8 +1135,8 @@ BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *msg, BHandler *targ
|
|||||||
int64 when = real_time_clock_usecs();
|
int64 when = real_time_clock_usecs();
|
||||||
msg->AddInt64("when", when);
|
msg->AddInt64("when", when);
|
||||||
|
|
||||||
// TODO: make sure key is a lowercase char !!!
|
// TODO: support unicode here
|
||||||
|
key = tolower(key);
|
||||||
modifiers = modifiers | B_COMMAND_KEY;
|
modifiers = modifiers | B_COMMAND_KEY;
|
||||||
|
|
||||||
_BCmdKey *cmdKey = new _BCmdKey(key, modifiers, msg);
|
_BCmdKey *cmdKey = new _BCmdKey(key, modifiers, msg);
|
||||||
@@ -1154,7 +1154,6 @@ BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *msg, BHandler *targ
|
|||||||
void
|
void
|
||||||
BWindow::RemoveShortcut(uint32 key, uint32 modifiers)
|
BWindow::RemoveShortcut(uint32 key, uint32 modifiers)
|
||||||
{
|
{
|
||||||
// TODO: What about locking?!?
|
|
||||||
int32 index = findShortcut(key, modifiers | B_COMMAND_KEY);
|
int32 index = findShortcut(key, modifiers | B_COMMAND_KEY);
|
||||||
if (index >=0) {
|
if (index >=0) {
|
||||||
_BCmdKey *cmdKey = (_BCmdKey *)accelList.ItemAt(index);
|
_BCmdKey *cmdKey = (_BCmdKey *)accelList.ItemAt(index);
|
||||||
@@ -1966,7 +1965,8 @@ BWindow::InitData(BRect frame, const char* title, window_look look,
|
|||||||
AddShortcut('C', B_COMMAND_KEY, new BMessage(B_COPY), NULL);
|
AddShortcut('C', B_COMMAND_KEY, new BMessage(B_COPY), NULL);
|
||||||
AddShortcut('V', B_COMMAND_KEY, new BMessage(B_PASTE), NULL);
|
AddShortcut('V', B_COMMAND_KEY, new BMessage(B_PASTE), NULL);
|
||||||
AddShortcut('A', B_COMMAND_KEY, new BMessage(B_SELECT_ALL), NULL);
|
AddShortcut('A', B_COMMAND_KEY, new BMessage(B_SELECT_ALL), NULL);
|
||||||
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
|
if ((fFlags & B_NOT_CLOSABLE) == 0)
|
||||||
|
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_CLOSE_REQUESTED));
|
||||||
|
|
||||||
fPulseEnabled = false;
|
fPulseEnabled = false;
|
||||||
fPulseRate = 0;
|
fPulseRate = 0;
|
||||||
@@ -2436,12 +2436,6 @@ BWindow::_HandleKeyDown(char key, uint32 modifiers)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command+q has been pressed, so, we will quit
|
|
||||||
if ((key == 'Q' || key == 'q') && (modifiers & B_COMMAND_KEY) != 0) {
|
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keyboard navigation through views
|
// Keyboard navigation through views
|
||||||
// (B_OPTION_KEY makes BTextViews and friends navigable, even in editing mode)
|
// (B_OPTION_KEY makes BTextViews and friends navigable, even in editing mode)
|
||||||
if (key == B_TAB && (modifiers & (B_COMMAND_KEY | B_OPTION_KEY)) != 0) {
|
if (key == B_TAB && (modifiers & (B_COMMAND_KEY | B_OPTION_KEY)) != 0) {
|
||||||
@@ -2450,10 +2444,23 @@ BWindow::_HandleKeyDown(char key, uint32 modifiers)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle shortcuts
|
// Handle shortcuts
|
||||||
int index;
|
if ((modifiers & B_COMMAND_KEY) != 0) {
|
||||||
|
// Command+q has been pressed, so, we will quit
|
||||||
|
if (key == 'Q' || key == 'q') {
|
||||||
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we only must consider temporary modifiers for the shortcuts
|
||||||
|
modifiers &= B_COMMAND_KEY | B_OPTION_KEY | B_SHIFT_KEY
|
||||||
|
| B_CONTROL_KEY | B_MENU_KEY;
|
||||||
|
|
||||||
|
int32 index;
|
||||||
if ((index = findShortcut(key, modifiers)) >= 0) {
|
if ((index = findShortcut(key, modifiers)) >= 0) {
|
||||||
_BCmdKey *cmdKey = (_BCmdKey*)accelList.ItemAt(index);
|
_BCmdKey *cmdKey = (_BCmdKey*)accelList.ItemAt(index);
|
||||||
|
|
||||||
|
// TODO: using MessageReceived() here removes the possibility to filter the messages!
|
||||||
|
|
||||||
// we'll give the message to the focus view
|
// we'll give the message to the focus view
|
||||||
if (cmdKey->targetToken == B_ANY_TOKEN) {
|
if (cmdKey->targetToken == B_ANY_TOKEN) {
|
||||||
fFocus->MessageReceived(cmdKey->message);
|
fFocus->MessageReceived(cmdKey->message);
|
||||||
@@ -2482,11 +2489,12 @@ BWindow::_HandleKeyDown(char key, uint32 modifiers)
|
|||||||
target->MessageReceived(cmdKey->message);
|
target->MessageReceived(cmdKey->message);
|
||||||
else {
|
else {
|
||||||
// if no handler was found, BWindow will handle the message
|
// if no handler was found, BWindow will handle the message
|
||||||
MessageReceived(cmdKey->message);
|
PostMessage(cmdKey->message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if <ENTER> is pressed and we have a default button
|
// if <ENTER> is pressed and we have a default button
|
||||||
if (DefaultButton() && key == B_ENTER) {
|
if (DefaultButton() && key == B_ENTER) {
|
||||||
@@ -2539,6 +2547,8 @@ int32
|
|||||||
BWindow::findShortcut(uint32 key, uint32 modifiers)
|
BWindow::findShortcut(uint32 key, uint32 modifiers)
|
||||||
{
|
{
|
||||||
int32 count = accelList.CountItems();
|
int32 count = accelList.CountItems();
|
||||||
|
// TODO: support unicode here
|
||||||
|
key = tolower(key);
|
||||||
|
|
||||||
for (int32 index = 0; index < count; index++) {
|
for (int32 index = 0; index < count; index++) {
|
||||||
_BCmdKey *cmdKey = (_BCmdKey *)accelList.ItemAt(index);
|
_BCmdKey *cmdKey = (_BCmdKey *)accelList.ItemAt(index);
|
||||||
|
|||||||
Reference in New Issue
Block a user