scripting in BApplication is mostly fixed

BLooper had a be-handler named suite
BWindow is now exposing Active
scripting to BViews isn't working yet


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17797 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2006-06-11 23:01:33 +00:00
parent 269d3bd5bc
commit e91315aa2d
3 changed files with 268 additions and 120 deletions
+150 -23
View File
@@ -626,14 +626,107 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index,
BMessage *specifier, int32 what, const char *property) BMessage *specifier, int32 what, const char *property)
{ {
BPropertyInfo propInfo(sPropertyInfo); BPropertyInfo propInfo(sPropertyInfo);
status_t err = B_OK;
uint32 data;
if (propInfo.FindMatch(message, 0, specifier, what, property) >= B_OK) if (propInfo.FindMatch(message, 0, specifier, what, property, &data) >=0) {
switch (data) {
case 0: {
int32 ind = -1;
err = specifier->FindInt32("index", &ind);
if (err != B_OK)
break;
if (what == B_REVERSE_INDEX_SPECIFIER)
ind = CountWindows() - ind;
err = B_BAD_INDEX;
BWindow *win = WindowAt(ind);
if (win) {
if (index <= 0 && message->what == B_GET_PROPERTY)
return this; return this;
message->PopSpecifier();
BMessenger(win).SendMessage(message);
return NULL;
}
break;
}
case 1: {
const char *name;
err = specifier->FindString("name", &name);
if (err != B_OK)
break;
err = B_NAME_NOT_FOUND;
for (int32 i=0; i<CountWindows(); i++) {
BWindow *win = WindowAt(i);
if (win && win->Name() && strlen(win->Name()) == strlen(name)
&& !strcmp(win->Name(), name)) {
if (index <= 0 && message->what == B_GET_PROPERTY)
return this;
message->PopSpecifier();
BMessenger(win).SendMessage(message);
return NULL;
}
}
break;
}
case 2: {
int32 ind = -1;
err = specifier->FindInt32("index", &ind);
if (err != B_OK)
break;
if (what == B_REVERSE_INDEX_SPECIFIER)
ind = CountLoopers() - ind;
err = B_BAD_INDEX;
BLooper *looper = LooperAt(ind);
if (looper) {
if (index <= 0)
return this;
message->PopSpecifier();
BMessenger(looper).SendMessage(message);
return NULL;
}
break;
}
case 3:
//if (index == 0)
// return this;
break;
case 4: {
const char *name;
err = specifier->FindString("name", &name);
if (err != B_OK)
break;
err = B_NAME_NOT_FOUND;
for (int32 i=0; i<CountLoopers(); i++) {
BLooper *looper = LooperAt(i);
if (looper && looper->Name() && strlen(looper->Name()) == strlen(name)
&& !strcmp(looper->Name(), name)) {
if (index <= 0)
return this;
message->PopSpecifier();
BMessenger(looper).SendMessage(message);
return NULL;
}
}
break;
}
case 5:
return this;
}
} else {
return BLooper::ResolveSpecifier(message, index, specifier, what, return BLooper::ResolveSpecifier(message, index, specifier, what,
property); property);
} }
BMessage reply(B_MESSAGE_NOT_UNDERSTOOD);
reply.AddInt32("error", err);
reply.AddString("message", strerror(err));
message->SendReply(&reply);
return NULL;
}
void void
BApplication::ShowCursor() BApplication::ShowCursor()
@@ -922,7 +1015,7 @@ BApplication::GetSupportedSuites(BMessage *data)
BPropertyInfo propertyInfo(sPropertyInfo); BPropertyInfo propertyInfo(sPropertyInfo);
status = data->AddFlat("messages", &propertyInfo); status = data->AddFlat("messages", &propertyInfo);
if (status == B_OK) if (status == B_OK)
status = BHandler::GetSupportedSuites(data); status = BLooper::GetSupportedSuites(data);
} }
return status; return status;
@@ -953,7 +1046,7 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
BMessage reply(B_REPLY); BMessage reply(B_REPLY);
status_t err = B_BAD_SCRIPT_SYNTAX; status_t err = B_BAD_SCRIPT_SYNTAX;
switch (what) { switch (message->what) {
case B_GET_PROPERTY: case B_GET_PROPERTY:
if (strcmp("Loopers", property) == 0) { if (strcmp("Loopers", property) == 0) {
int32 count = CountLoopers(); int32 count = CountLoopers();
@@ -962,7 +1055,6 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
BMessenger messenger(LooperAt(i)); BMessenger messenger(LooperAt(i));
err = reply.AddMessenger("result", messenger); err = reply.AddMessenger("result", messenger);
} }
} else if (strcmp("Windows", property) == 0) { } else if (strcmp("Windows", property) == 0) {
int32 count = CountWindows(); int32 count = CountWindows();
err = B_OK; err = B_OK;
@@ -971,27 +1063,19 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
err = reply.AddMessenger("result", messenger); err = reply.AddMessenger("result", messenger);
} }
} else if (strcmp("Window", property) == 0) { } else if (strcmp("Window", property) == 0) {
switch (specifier->what) { switch (what) {
case B_INDEX_SPECIFIER: { case B_INDEX_SPECIFIER:
int32 ind = -1;
if (specifier->FindInt32("index", &ind)!=B_OK)
break;
BWindow *win = WindowAt(ind);
if (!win) {
break;
}
BMessenger messenger(win);
err = reply.AddMessenger("result", messenger);
break;
}
case B_REVERSE_INDEX_SPECIFIER: { case B_REVERSE_INDEX_SPECIFIER: {
int32 rindex; int32 ind = -1;
if (specifier->FindInt32("index", &rindex) != B_OK) err = specifier->FindInt32("index", &ind);
if (err != B_OK)
break; break;
BWindow *win = WindowAt(CountWindows() - rindex); if (what == B_REVERSE_INDEX_SPECIFIER)
if (!win) { ind = CountWindows() - ind;
err = B_BAD_INDEX;
BWindow *win = WindowAt(ind);
if (!win)
break; break;
}
BMessenger messenger(win); BMessenger messenger(win);
err = reply.AddMessenger("result", messenger); err = reply.AddMessenger("result", messenger);
break; break;
@@ -1013,6 +1097,48 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
} }
} }
} }
} else if (strcmp("Looper", property) == 0) {
switch (what) {
case B_INDEX_SPECIFIER:
case B_REVERSE_INDEX_SPECIFIER: {
int32 ind = -1;
err = specifier->FindInt32("index", &ind);
if (err != B_OK)
break;
if (what == B_REVERSE_INDEX_SPECIFIER)
ind = CountLoopers() - ind;
err = B_BAD_INDEX;
BLooper *looper = LooperAt(ind);
if (!looper)
break;
BMessenger messenger(looper);
err = reply.AddMessenger("result", messenger);
break;
}
case B_NAME_SPECIFIER: {
const char *name;
err = specifier->FindString("name", &name);
if (err != B_OK)
break;
err = B_NAME_NOT_FOUND;
for (int32 i=0; i<CountLoopers(); i++) {
BLooper *looper = LooperAt(i);
if (looper && looper->Name() && strlen(looper->Name()) == strlen(name)
&& !strcmp(looper->Name(), name)) {
BMessenger messenger(looper);
err = reply.AddMessenger("result", messenger);
break;
}
}
break;
}
case B_ID_SPECIFIER: {
// TODO
break;
}
}
} else if (strcmp("Name", property) == 0) {
err = reply.AddString("result", Name());
} }
break; break;
case B_COUNT_PROPERTIES: case B_COUNT_PROPERTIES:
@@ -1023,8 +1149,9 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
} }
break; break;
} }
if (err == B_BAD_SCRIPT_SYNTAX) if (err == B_BAD_SCRIPT_SYNTAX) {
return false; return false;
}
if (err < B_OK) { if (err < B_OK) {
reply.what = B_ERROR; reply.what = B_ERROR;
reply.AddString("message", strerror(err)); reply.AddString("message", strerror(err));
+1 -1
View File
@@ -716,7 +716,7 @@ BLooper::GetSupportedSuites(BMessage* data)
if (data == NULL) if (data == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
status_t status = data->AddString("suites", "suite/vnd.Be-handler"); status_t status = data->AddString("suites", "suite/vnd.Be-looper");
if (status == B_OK) { if (status == B_OK) {
BPropertyInfo PropertyInfo(gLooperPropInfo); BPropertyInfo PropertyInfo(gLooperPropInfo);
status = data->AddFlat("messages", &PropertyInfo); status = data->AddFlat("messages", &PropertyInfo);
+40 -19
View File
@@ -644,13 +644,7 @@ BWindow::EndViewTransaction()
bool bool
BWindow::IsFront() const BWindow::IsFront() const
{ {
if (IsActive()) return (IsActive() || IsModal());
return true;
if (IsModal())
return true;
return false;
} }
@@ -669,16 +663,35 @@ BWindow::MessageReceived(BMessage *msg)
switch (msg->what) { switch (msg->what) {
case B_GET_PROPERTY: case B_GET_PROPERTY:
case B_SET_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;
int32 index; int32 index;
if (msg->GetCurrentSpecifier(&index, &specifier, &what, &prop) != B_OK) if (msg->GetCurrentSpecifier(&index, &specifier, &what, &prop) != B_OK)
break; return BLooper::MessageReceived(msg);
if (!strcmp(prop, "Feel")) { BPropertyInfo propertyInfo(sWindowPropInfo);
switch (propertyInfo.FindMatch(msg, index, &specifier, what, prop)) {
case 0:
if (msg->what == B_GET_PROPERTY) {
replyMsg.AddBool("result", IsActive());
handled = true;
} else if (msg->what == B_SET_PROPERTY) {
bool newActive;
if (msg->FindBool("data", &newActive) == B_OK) {
Activate(newActive);
handled = true;
}
}
break;
case 1:
if (msg->what == B_GET_PROPERTY) { if (msg->what == B_GET_PROPERTY) {
replyMsg.AddInt32("result", (uint32)Feel()); replyMsg.AddInt32("result", (uint32)Feel());
handled = true; handled = true;
@@ -689,7 +702,8 @@ BWindow::MessageReceived(BMessage *msg)
handled = true; handled = true;
} }
} }
} else if (!strcmp(prop, "Flags")) { break;
case 2:
if (msg->what == B_GET_PROPERTY) { if (msg->what == B_GET_PROPERTY) {
replyMsg.AddInt32("result", Flags()); replyMsg.AddInt32("result", Flags());
handled = true; handled = true;
@@ -700,7 +714,8 @@ BWindow::MessageReceived(BMessage *msg)
handled = true; handled = true;
} }
} }
} else if (!strcmp(prop, "Frame")) { break;
case 3:
if (msg->what == B_GET_PROPERTY) { if (msg->what == B_GET_PROPERTY) {
replyMsg.AddRect("result", Frame()); replyMsg.AddRect("result", Frame());
handled = true; handled = true;
@@ -712,7 +727,8 @@ BWindow::MessageReceived(BMessage *msg)
handled = true; handled = true;
} }
} }
} else if (!strcmp(prop, "Hidden")) { break;
case 4:
if (msg->what == B_GET_PROPERTY) { if (msg->what == B_GET_PROPERTY) {
replyMsg.AddBool("result", IsHidden()); replyMsg.AddBool("result", IsHidden());
handled = true; handled = true;
@@ -724,11 +740,11 @@ BWindow::MessageReceived(BMessage *msg)
Hide(); Hide();
} else if (IsHidden()) } else if (IsHidden())
Show(); Show();
handled = true; handled = true;
} }
} }
} else if (!strcmp(prop, "Look")) { break;
case 5:
if (msg->what == B_GET_PROPERTY) { if (msg->what == B_GET_PROPERTY) {
replyMsg.AddInt32("result", (uint32)Look()); replyMsg.AddInt32("result", (uint32)Look());
handled = true; handled = true;
@@ -739,7 +755,8 @@ BWindow::MessageReceived(BMessage *msg)
handled = true; handled = true;
} }
} }
} else if (!strcmp(prop, "Title")) { break;
case 6:
if (msg->what == B_GET_PROPERTY) { if (msg->what == B_GET_PROPERTY) {
replyMsg.AddString("result", Title()); replyMsg.AddString("result", Title());
handled = true; handled = true;
@@ -750,7 +767,8 @@ BWindow::MessageReceived(BMessage *msg)
handled = true; handled = true;
} }
} }
} else if (!strcmp(prop, "Workspaces")) { break;
case 7:
if (msg->what == B_GET_PROPERTY) { if (msg->what == B_GET_PROPERTY) {
replyMsg.AddInt32( "result", Workspaces()); replyMsg.AddInt32( "result", Workspaces());
handled = true; handled = true;
@@ -761,7 +779,8 @@ BWindow::MessageReceived(BMessage *msg)
handled = true; handled = true;
} }
} }
} else if (!strcmp(prop, "Minimize")) { break;
case 11:
if (msg->what == B_GET_PROPERTY) { if (msg->what == B_GET_PROPERTY) {
replyMsg.AddBool("result", IsMinimized()); replyMsg.AddBool("result", IsMinimized());
handled = true; handled = true;
@@ -772,8 +791,10 @@ BWindow::MessageReceived(BMessage *msg)
handled = true; handled = true;
} }
} }
}
break; break;
default:
return BLooper::MessageReceived(msg);
}
} }
} }