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:
+150
-23
@@ -626,12 +626,105 @@ BApplication::ResolveSpecifier(BMessage *message, int32 index,
|
||||
BMessage *specifier, int32 what, const char *property)
|
||||
{
|
||||
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;
|
||||
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,
|
||||
property);
|
||||
}
|
||||
|
||||
BMessage reply(B_MESSAGE_NOT_UNDERSTOOD);
|
||||
reply.AddInt32("error", err);
|
||||
reply.AddString("message", strerror(err));
|
||||
message->SendReply(&reply);
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -922,7 +1015,7 @@ BApplication::GetSupportedSuites(BMessage *data)
|
||||
BPropertyInfo propertyInfo(sPropertyInfo);
|
||||
status = data->AddFlat("messages", &propertyInfo);
|
||||
if (status == B_OK)
|
||||
status = BHandler::GetSupportedSuites(data);
|
||||
status = BLooper::GetSupportedSuites(data);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -953,7 +1046,7 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
|
||||
BMessage reply(B_REPLY);
|
||||
status_t err = B_BAD_SCRIPT_SYNTAX;
|
||||
|
||||
switch (what) {
|
||||
switch (message->what) {
|
||||
case B_GET_PROPERTY:
|
||||
if (strcmp("Loopers", property) == 0) {
|
||||
int32 count = CountLoopers();
|
||||
@@ -962,7 +1055,6 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
|
||||
BMessenger messenger(LooperAt(i));
|
||||
err = reply.AddMessenger("result", messenger);
|
||||
}
|
||||
|
||||
} else if (strcmp("Windows", property) == 0) {
|
||||
int32 count = CountWindows();
|
||||
err = B_OK;
|
||||
@@ -971,27 +1063,19 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
|
||||
err = reply.AddMessenger("result", messenger);
|
||||
}
|
||||
} else if (strcmp("Window", property) == 0) {
|
||||
switch (specifier->what) {
|
||||
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;
|
||||
}
|
||||
switch (what) {
|
||||
case B_INDEX_SPECIFIER:
|
||||
case B_REVERSE_INDEX_SPECIFIER: {
|
||||
int32 rindex;
|
||||
if (specifier->FindInt32("index", &rindex) != B_OK)
|
||||
int32 ind = -1;
|
||||
err = specifier->FindInt32("index", &ind);
|
||||
if (err != B_OK)
|
||||
break;
|
||||
BWindow *win = WindowAt(CountWindows() - rindex);
|
||||
if (!win) {
|
||||
if (what == B_REVERSE_INDEX_SPECIFIER)
|
||||
ind = CountWindows() - ind;
|
||||
err = B_BAD_INDEX;
|
||||
BWindow *win = WindowAt(ind);
|
||||
if (!win)
|
||||
break;
|
||||
}
|
||||
BMessenger messenger(win);
|
||||
err = reply.AddMessenger("result", messenger);
|
||||
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;
|
||||
case B_COUNT_PROPERTIES:
|
||||
@@ -1023,8 +1149,9 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (err == B_BAD_SCRIPT_SYNTAX)
|
||||
if (err == B_BAD_SCRIPT_SYNTAX) {
|
||||
return false;
|
||||
}
|
||||
if (err < B_OK) {
|
||||
reply.what = B_ERROR;
|
||||
reply.AddString("message", strerror(err));
|
||||
|
||||
@@ -716,7 +716,7 @@ BLooper::GetSupportedSuites(BMessage* data)
|
||||
if (data == NULL)
|
||||
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) {
|
||||
BPropertyInfo PropertyInfo(gLooperPropInfo);
|
||||
status = data->AddFlat("messages", &PropertyInfo);
|
||||
|
||||
@@ -644,13 +644,7 @@ BWindow::EndViewTransaction()
|
||||
bool
|
||||
BWindow::IsFront() const
|
||||
{
|
||||
if (IsActive())
|
||||
return true;
|
||||
|
||||
if (IsModal())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return (IsActive() || IsModal());
|
||||
}
|
||||
|
||||
|
||||
@@ -669,16 +663,35 @@ BWindow::MessageReceived(BMessage *msg)
|
||||
|
||||
switch (msg->what) {
|
||||
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;
|
||||
int32 what;
|
||||
const char *prop;
|
||||
int32 index;
|
||||
|
||||
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) {
|
||||
replyMsg.AddInt32("result", (uint32)Feel());
|
||||
handled = true;
|
||||
@@ -689,7 +702,8 @@ BWindow::MessageReceived(BMessage *msg)
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Flags")) {
|
||||
break;
|
||||
case 2:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddInt32("result", Flags());
|
||||
handled = true;
|
||||
@@ -700,7 +714,8 @@ BWindow::MessageReceived(BMessage *msg)
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Frame")) {
|
||||
break;
|
||||
case 3:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddRect("result", Frame());
|
||||
handled = true;
|
||||
@@ -712,7 +727,8 @@ BWindow::MessageReceived(BMessage *msg)
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Hidden")) {
|
||||
break;
|
||||
case 4:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddBool("result", IsHidden());
|
||||
handled = true;
|
||||
@@ -724,11 +740,11 @@ BWindow::MessageReceived(BMessage *msg)
|
||||
Hide();
|
||||
} else if (IsHidden())
|
||||
Show();
|
||||
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Look")) {
|
||||
break;
|
||||
case 5:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddInt32("result", (uint32)Look());
|
||||
handled = true;
|
||||
@@ -739,7 +755,8 @@ BWindow::MessageReceived(BMessage *msg)
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Title")) {
|
||||
break;
|
||||
case 6:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddString("result", Title());
|
||||
handled = true;
|
||||
@@ -750,7 +767,8 @@ BWindow::MessageReceived(BMessage *msg)
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Workspaces")) {
|
||||
break;
|
||||
case 7:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddInt32( "result", Workspaces());
|
||||
handled = true;
|
||||
@@ -761,7 +779,8 @@ BWindow::MessageReceived(BMessage *msg)
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Minimize")) {
|
||||
break;
|
||||
case 11:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddBool("result", IsMinimized());
|
||||
handled = true;
|
||||
@@ -772,8 +791,10 @@ BWindow::MessageReceived(BMessage *msg)
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return BLooper::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user