fix some more bugs in scripting handling, this seems to never end

Having canna input method installed shouldn't crash Haiku anymore


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17810 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2006-06-12 23:45:55 +00:00
parent 4b25c48853
commit da08acb8bf
3 changed files with 236 additions and 280 deletions

View File

@ -53,7 +53,7 @@ static property_info sShelfPropertyList[] = {
"... of Replicant {index | name | id} of ...", 0, "... of Replicant {index | name | id} of ...", 0,
}, },
{} { 0, { 0 }, { 0 }, 0, 0 }
}; };
static property_info sReplicantPropertyList[] = { static property_info sReplicantPropertyList[] = {
@ -90,7 +90,9 @@ static property_info sReplicantPropertyList[] = {
{ }, { },
{ B_DIRECT_SPECIFIER }, { B_DIRECT_SPECIFIER },
NULL, 0, NULL, 0,
} },
{ 0, { 0 }, { 0 }, 0, 0 }
}; };

View File

@ -3499,11 +3499,10 @@ BView::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier,
return this; return this;
BPropertyInfo propertyInfo(sViewPropInfo); BPropertyInfo propertyInfo(sViewPropInfo);
status_t err = B_BAD_SCRIPT_SYNTAX;
BMessage replyMsg(B_REPLY);
switch (propertyInfo.FindMatch(msg, index, specifier, what, property)) { switch (propertyInfo.FindMatch(msg, index, specifier, what, property)) {
case B_ERROR:
break;
case 0: case 0:
case 1: case 1:
case 2: case 2:
@ -3515,87 +3514,75 @@ BView::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier,
if (fShelf) { if (fShelf) {
msg->PopSpecifier(); msg->PopSpecifier();
return fShelf; return fShelf;
} else {
BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD);
replyMsg.AddInt32("error", B_NAME_NOT_FOUND);
replyMsg.AddString("message", "This window doesn't have a shelf");
msg->SendReply(&replyMsg);
return NULL;
} }
err = B_NAME_NOT_FOUND;
replyMsg.AddString("message", "This window doesn't have a shelf");
break; break;
case 6: case 6: {
case 7: if (!fFirstChild) {
case 8: err = B_NAME_NOT_FOUND;
{ replyMsg.AddString("message", "This window doesn't have children.");
if (fFirstChild) { break;
BView *child; }
switch (msg->what) { BView *child = NULL;
case B_INDEX_SPECIFIER: switch (what) {
{ case B_INDEX_SPECIFIER: {
int32 index; int32 index;
msg->FindInt32("data", &index); err = specifier->FindInt32("index", &index);
if (err == B_OK)
child = ChildAt(index); child = ChildAt(index);
break; break;
} }
case B_REVERSE_INDEX_SPECIFIER: case B_REVERSE_INDEX_SPECIFIER: {
{
int32 rindex; int32 rindex;
msg->FindInt32("data", &rindex); err = specifier->FindInt32("index", &rindex);
if (err == B_OK)
child = ChildAt(CountChildren() - rindex); child = ChildAt(CountChildren() - rindex);
break; break;
} }
case B_NAME_SPECIFIER: case B_NAME_SPECIFIER: {
{
const char *name; const char *name;
msg->FindString("data", &name); err = specifier->FindString("name", &name);
if (err == B_OK)
child = FindView(name); child = FindView(name);
break; break;
} }
default:
child = NULL;
break;
} }
if (child != NULL) { if (child != NULL) {
msg->PopSpecifier(); msg->PopSpecifier();
return child; return child;
} else { }
BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD);
replyMsg.AddInt32("error", B_BAD_INDEX); if (err == B_OK)
err = B_BAD_INDEX;
replyMsg.AddString("message", "Cannot find view at/with specified index/name."); replyMsg.AddString("message", "Cannot find view at/with specified index/name.");
msg->SendReply(&replyMsg);
return NULL;
}
} else {
BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD);
replyMsg.AddInt32("error", B_NAME_NOT_FOUND);
replyMsg.AddString("message", "This window doesn't have children.");
msg->SendReply(&replyMsg);
return NULL;
}
break; break;
} }
default: default:
break; return BHandler::ResolveSpecifier(msg, index, specifier, what, property);
} }
return BHandler::ResolveSpecifier(msg, index, specifier, what, property); if (err == B_BAD_SCRIPT_SYNTAX) {
replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD;
replyMsg.AddString("message", "Didn't understand the specifier(s)");
} else if (err < B_OK) {
replyMsg.what = B_ERROR;
replyMsg.AddString("message", strerror(err));
}
replyMsg.AddInt32("error", err);
msg->SendReply(&replyMsg);
return NULL;
} }
void void
BView::MessageReceived(BMessage *msg) BView::MessageReceived(BMessage *msg)
{ {
BMessage specifier;
int32 what;
const char *prop;
int32 index;
status_t err;
if (!msg->HasSpecifiers()) { if (!msg->HasSpecifiers()) {
switch (msg->what) { switch (msg->what) {
case B_VIEW_RESIZED: case B_VIEW_RESIZED:
@ -3652,90 +3639,66 @@ BView::MessageReceived(BMessage *msg)
} }
default: default:
BHandler::MessageReceived(msg); return BHandler::MessageReceived(msg);
break;
} }
return; return;
} }
err = msg->GetCurrentSpecifier(&index, &specifier, &what, &prop); BMessage replyMsg(B_REPLY);
if (err == B_OK) { status_t err = B_BAD_SCRIPT_SYNTAX;
BMessage replyMsg; int32 index;
BMessage specifier;
int32 what;
const char *prop;
switch (msg->what) { if (msg->GetCurrentSpecifier(&index, &specifier, &what, &prop) != B_OK)
case B_GET_PROPERTY: return BHandler::MessageReceived(msg);
{
replyMsg.what = B_NO_ERROR;
replyMsg.AddInt32("error", B_OK);
if (strcmp(prop, "Frame") == 0) BPropertyInfo propertyInfo(sViewPropInfo);
replyMsg.AddRect("result", Frame()); switch (propertyInfo.FindMatch(msg, index, &specifier, what, prop)) {
else if (strcmp(prop, "Hidden") == 0) case 0:
replyMsg.AddBool( "result", IsHidden()); err = replyMsg.AddRect("result", Frame());
break; break;
} case 1: {
case B_SET_PROPERTY:
{
if (strcmp(prop, "Frame") == 0) {
BRect newFrame; BRect newFrame;
if (msg->FindRect("data", &newFrame) == B_OK) { err = msg->FindRect("data", &newFrame);
if (err == B_OK) {
MoveTo(newFrame.LeftTop()); MoveTo(newFrame.LeftTop());
ResizeTo(newFrame.right, newFrame.bottom); ResizeTo(newFrame.right, newFrame.bottom);
replyMsg.what = B_NO_ERROR;
replyMsg.AddInt32("error", B_OK);
} else {
replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD;
replyMsg.AddInt32("error", B_BAD_SCRIPT_SYNTAX);
replyMsg.AddString("message", "Didn't understand the specifier(s)");
} }
} else if (strcmp(prop, "Hidden") == 0) { break;
}
case 2:
err = replyMsg.AddBool( "result", IsHidden());
break;
case 3: {
bool newHiddenState; bool newHiddenState;
if (msg->FindBool("data", &newHiddenState) == B_OK) { err = msg->FindBool("data", &newHiddenState);
if (!IsHidden() && newHiddenState == true) { if (err == B_OK) {
if (!IsHidden() && newHiddenState == true)
Hide(); Hide();
else if (IsHidden() && newHiddenState == false)
replyMsg.what = B_NO_ERROR;
replyMsg.AddInt32( "error", B_OK);
}
else if (IsHidden() && newHiddenState == false) {
Show(); Show();
replyMsg.what = B_NO_ERROR;
replyMsg.AddInt32("error", B_OK);
} else {
replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD;
replyMsg.AddInt32("error", B_BAD_SCRIPT_SYNTAX);
replyMsg.AddString("message", "Didn't understand the specifier(s)");
}
} else {
replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD;
replyMsg.AddInt32("error", B_BAD_SCRIPT_SYNTAX);
replyMsg.AddString("message", "Didn't understand the specifier(s)");
} }
} }
case 5:
err = replyMsg.AddInt32("result", CountChildren());
break; break;
default:
return BHandler::MessageReceived(msg);
} }
case B_COUNT_PROPERTIES: if (err == B_BAD_SCRIPT_SYNTAX) {
if (strcmp(prop, "View") == 0) { replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD;
replyMsg.what = B_NO_ERROR;
replyMsg.AddInt32("error", B_OK);
replyMsg.AddInt32("result", CountChildren());
}
break;
}
msg->SendReply(&replyMsg);
} else {
BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD);
replyMsg.AddInt32("error" , B_BAD_SCRIPT_SYNTAX);
replyMsg.AddString("message", "Didn't understand the specifier(s)"); replyMsg.AddString("message", "Didn't understand the specifier(s)");
} else if (err < B_OK) {
msg->SendReply(&replyMsg); replyMsg.what = B_ERROR;
replyMsg.AddString("message", strerror(err));
} }
replyMsg.AddInt32("error", err);
msg->SendReply(&replyMsg);
} }

View File

@ -661,14 +661,7 @@ BWindow::MessageReceived(BMessage *msg)
BMessage replyMsg(B_REPLY); BMessage replyMsg(B_REPLY);
bool handled = false; bool handled = false;
switch (msg->what) {
case B_GET_PROPERTY:
case B_SET_PROPERTY:
case B_CREATE_PROPERTY:
case B_DELETE_PROPERTY:
case B_COUNT_PROPERTIES:
case B_EXECUTE_PROPERTY:
case B_GET_SUPPORTED_SUITES: {
BMessage specifier; BMessage specifier;
int32 what; int32 what;
const char *prop; const char *prop;
@ -795,8 +788,6 @@ BWindow::MessageReceived(BMessage *msg)
default: default:
return BLooper::MessageReceived(msg); return BLooper::MessageReceived(msg);
} }
}
}
if (handled) { if (handled) {
if (msg->what == B_SET_PROPERTY) if (msg->what == B_SET_PROPERTY)