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:
parent
269d3bd5bc
commit
e91315aa2d
@ -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, &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);
|
||||
}
|
||||
|
||||
if (propInfo.FindMatch(message, 0, specifier, what, property) >= B_OK)
|
||||
return this;
|
||||
BMessage reply(B_MESSAGE_NOT_UNDERSTOOD);
|
||||
reply.AddInt32("error", err);
|
||||
reply.AddString("message", strerror(err));
|
||||
message->SendReply(&reply);
|
||||
|
||||
return BLooper::ResolveSpecifier(message, index, specifier, what,
|
||||
property);
|
||||
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();
|
||||
@ -961,8 +1054,7 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
|
||||
for (int32 i=0; err == B_OK && i<count; i++) {
|
||||
BMessenger messenger(LooperAt(i));
|
||||
err = reply.AddMessenger("result", messenger);
|
||||
}
|
||||
|
||||
}
|
||||
} else if (strcmp("Windows", property) == 0) {
|
||||
int32 count = CountWindows();
|
||||
err = B_OK;
|
||||
@ -971,31 +1063,23 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
|
||||
err = reply.AddMessenger("result", messenger);
|
||||
}
|
||||
} else if (strcmp("Window", property) == 0) {
|
||||
switch (specifier->what) {
|
||||
case B_INDEX_SPECIFIER: {
|
||||
switch (what) {
|
||||
case B_INDEX_SPECIFIER:
|
||||
case B_REVERSE_INDEX_SPECIFIER: {
|
||||
int32 ind = -1;
|
||||
if (specifier->FindInt32("index", &ind)!=B_OK)
|
||||
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 (!win)
|
||||
break;
|
||||
}
|
||||
BMessenger messenger(win);
|
||||
err = reply.AddMessenger("result", messenger);
|
||||
break;
|
||||
}
|
||||
case B_REVERSE_INDEX_SPECIFIER: {
|
||||
int32 rindex;
|
||||
if (specifier->FindInt32("index", &rindex) != B_OK)
|
||||
break;
|
||||
BWindow *win = WindowAt(CountWindows() - rindex);
|
||||
if (!win) {
|
||||
break;
|
||||
}
|
||||
BMessenger messenger(win);
|
||||
err = reply.AddMessenger("result", messenger);
|
||||
break;
|
||||
}
|
||||
case B_NAME_SPECIFIER: {
|
||||
const char *name;
|
||||
err = specifier->FindString("name", &name);
|
||||
@ -1004,15 +1088,57 @@ BApplication::ScriptReceived(BMessage *message, int32 index,
|
||||
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)
|
||||
if (win && win->Name() && strlen(win->Name()) == strlen(name)
|
||||
&& !strcmp(win->Name(), name)) {
|
||||
BMessenger messenger(win);
|
||||
err = reply.AddMessenger("result", messenger);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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));
|
||||
|
@ -664,7 +664,7 @@ BLooper::ResolveSpecifier(BMessage* msg, int32 index,
|
||||
string comparisons -- which wouldn't tell the whole story anyway,
|
||||
because of the same name being used for multiple properties.
|
||||
*/
|
||||
BPropertyInfo propertyInfo(gLooperPropInfo);
|
||||
BPropertyInfo propertyInfo(gLooperPropInfo);
|
||||
uint32 data;
|
||||
status_t err = B_OK;
|
||||
const char* errMsg = "";
|
||||
@ -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,111 +663,138 @@ 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;
|
||||
|
||||
if (!strcmp(prop, "Feel")) {
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddInt32("result", (uint32)Feel());
|
||||
handled = true;
|
||||
} else {
|
||||
uint32 newFeel;
|
||||
if (msg->FindInt32("data", (int32 *)&newFeel) == B_OK) {
|
||||
SetFeel((window_feel)newFeel);
|
||||
return BLooper::MessageReceived(msg);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Flags")) {
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddInt32("result", Flags());
|
||||
handled = true;
|
||||
} else {
|
||||
uint32 newFlags;
|
||||
if (msg->FindInt32("data", (int32 *)&newFlags) == B_OK) {
|
||||
SetFlags(newFlags);
|
||||
break;
|
||||
case 1:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddInt32("result", (uint32)Feel());
|
||||
handled = true;
|
||||
} else {
|
||||
uint32 newFeel;
|
||||
if (msg->FindInt32("data", (int32 *)&newFeel) == B_OK) {
|
||||
SetFeel((window_feel)newFeel);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Frame")) {
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddRect("result", Frame());
|
||||
handled = true;
|
||||
} else {
|
||||
BRect newFrame;
|
||||
if (msg->FindRect("data", &newFrame) == B_OK) {
|
||||
MoveTo(newFrame.LeftTop());
|
||||
ResizeTo(newFrame.Width(), newFrame.Height());
|
||||
break;
|
||||
case 2:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddInt32("result", Flags());
|
||||
handled = true;
|
||||
} else {
|
||||
uint32 newFlags;
|
||||
if (msg->FindInt32("data", (int32 *)&newFlags) == B_OK) {
|
||||
SetFlags(newFlags);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Hidden")) {
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddBool("result", IsHidden());
|
||||
handled = true;
|
||||
} else {
|
||||
bool hide;
|
||||
if (msg->FindBool("data", &hide) == B_OK) {
|
||||
if (hide) {
|
||||
if (!IsHidden())
|
||||
Hide();
|
||||
} else if (IsHidden())
|
||||
Show();
|
||||
|
||||
break;
|
||||
case 3:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddRect("result", Frame());
|
||||
handled = true;
|
||||
} else {
|
||||
BRect newFrame;
|
||||
if (msg->FindRect("data", &newFrame) == B_OK) {
|
||||
MoveTo(newFrame.LeftTop());
|
||||
ResizeTo(newFrame.Width(), newFrame.Height());
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Look")) {
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddInt32("result", (uint32)Look());
|
||||
handled = true;
|
||||
} else {
|
||||
uint32 newLook;
|
||||
if (msg->FindInt32("data", (int32 *)&newLook) == B_OK) {
|
||||
SetLook((window_look)newLook);
|
||||
break;
|
||||
case 4:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddBool("result", IsHidden());
|
||||
handled = true;
|
||||
} else {
|
||||
bool hide;
|
||||
if (msg->FindBool("data", &hide) == B_OK) {
|
||||
if (hide) {
|
||||
if (!IsHidden())
|
||||
Hide();
|
||||
} else if (IsHidden())
|
||||
Show();
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Title")) {
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddString("result", Title());
|
||||
handled = true;
|
||||
} else {
|
||||
const char *newTitle = NULL;
|
||||
if (msg->FindString("data", &newTitle) == B_OK) {
|
||||
SetTitle(newTitle);
|
||||
break;
|
||||
case 5:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddInt32("result", (uint32)Look());
|
||||
handled = true;
|
||||
} else {
|
||||
uint32 newLook;
|
||||
if (msg->FindInt32("data", (int32 *)&newLook) == B_OK) {
|
||||
SetLook((window_look)newLook);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Workspaces")) {
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddInt32( "result", Workspaces());
|
||||
handled = true;
|
||||
} else {
|
||||
uint32 newWorkspaces;
|
||||
if (msg->FindInt32("data", (int32 *)&newWorkspaces) == B_OK) {
|
||||
SetWorkspaces(newWorkspaces);
|
||||
break;
|
||||
case 6:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddString("result", Title());
|
||||
handled = true;
|
||||
} else {
|
||||
const char *newTitle = NULL;
|
||||
if (msg->FindString("data", &newTitle) == B_OK) {
|
||||
SetTitle(newTitle);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(prop, "Minimize")) {
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddBool("result", IsMinimized());
|
||||
handled = true;
|
||||
} else {
|
||||
bool minimize;
|
||||
if (msg->FindBool("data", &minimize) == B_OK) {
|
||||
Minimize(minimize);
|
||||
break;
|
||||
case 7:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddInt32( "result", Workspaces());
|
||||
handled = true;
|
||||
} else {
|
||||
uint32 newWorkspaces;
|
||||
if (msg->FindInt32("data", (int32 *)&newWorkspaces) == B_OK) {
|
||||
SetWorkspaces(newWorkspaces);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
if (msg->what == B_GET_PROPERTY) {
|
||||
replyMsg.AddBool("result", IsMinimized());
|
||||
handled = true;
|
||||
} else {
|
||||
bool minimize;
|
||||
if (msg->FindBool("data", &minimize) == B_OK) {
|
||||
Minimize(minimize);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return BLooper::MessageReceived(msg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user