hrev45807 adds 1 changeset to branch 'master' old head: 1103c53a39a8789923873fc9a431be4c018ec481 new head: bee420ffb6907e1d0ca5bdc9483d66ebcbb25dda overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=bee420f+%5E1103c53 ---------------------------------------------------------------------------- bee420f: BStringView: Add scripting support. Fixes #9823 Configure BStringView to respond to messages to get and set Text and Alignment properties. Fill out ResolveSpecifier() and GetSupportedSuites accordingly. BeOS R5 did not provide any additional scripting support for BStringView so this goes above and beyond what BeOS R5 did, but, doesn't break backwards compatability. [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev45807 Commit: bee420ffb6907e1d0ca5bdc9483d66ebcbb25dda URL: http://cgit.haiku-os.org/haiku/commit/?id=bee420f Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Jun 30 20:17:56 2013 UTC Ticket: https://dev.haiku-os.org/ticket/9823 ---------------------------------------------------------------------------- 1 file changed, 85 insertions(+), 4 deletions(-) src/kits/interface/StringView.cpp | 89 +++++++++++++++++++++++++++++++++-- ---------------------------------------------------------------------------- diff --git a/src/kits/interface/StringView.cpp b/src/kits/interface/StringView.cpp index 8c6981e..67991fb 100644 --- a/src/kits/interface/StringView.cpp +++ b/src/kits/interface/StringView.cpp @@ -19,12 +19,32 @@ #include <LayoutUtils.h> #include <Message.h> +#include <PropertyInfo.h> #include <View.h> #include <Window.h> #include <binary_compatibility/Interface.h> +static property_info sPropertyList[] = { + { + "Text", + { B_GET_PROPERTY, B_SET_PROPERTY }, + { B_DIRECT_SPECIFIER }, + NULL, 0, + { B_STRING_TYPE } + }, + { + "Alignment", + { B_GET_PROPERTY, B_SET_PROPERTY }, + { B_DIRECT_SPECIFIER }, + NULL, 0, + { B_INT32_TYPE } + }, + {} +}; + + BStringView::BStringView(BRect frame, const char* name, const char* text, uint32 resizeMask, uint32 flags) : BView(frame, name, resizeMask, flags | B_FULL_UPDATE_ON_RESIZE), @@ -261,6 +281,51 @@ BStringView::Draw(BRect updateRect) void BStringView::MessageReceived(BMessage* message) { + if (message->what == B_GET_PROPERTY || message->what == B_SET_PROPERTY) { + int32 index; + BMessage specifier; + int32 form; + const char* property; + if (message->GetCurrentSpecifier(&index, &specifier, &form, &property) + != B_OK) { + BView::MessageReceived(message); + return; + } + + BMessage reply(B_REPLY); + bool handled = false; + if (strcmp(property, "Text") == 0) { + if (message->what == B_GET_PROPERTY) { + reply.AddString("result", fText); + handled = true; + } else { + const char* text; + if (message->FindString("data", &text) == B_OK) { + SetText(text); + reply.AddInt32("error", B_OK); + handled = true; + } + } + } else if (strcmp(property, "Alignment") == 0) { + if (message->what == B_GET_PROPERTY) { + reply.AddInt32("result", (int32)fAlign); + handled = true; + } else { + int32 align; + if (message->FindInt32("data", &align) == B_OK) { + SetAlignment((alignment)align); + reply.AddInt32("error", B_OK); + handled = true; + } + } + } + + if (handled) { + message->SendReply(&reply); + return; + } + } + BView::MessageReceived(message); } @@ -331,17 +396,33 @@ BStringView::Alignment() const BHandler* -BStringView::ResolveSpecifier(BMessage* msg, int32 index, +BStringView::ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 form, const char* property) { - return NULL; + BPropertyInfo propInfo(sPropertyList); + if (propInfo.FindMatch(message, 0, specifier, form, property) >= B_OK) + return this; + + return BView::ResolveSpecifier(message, index, specifier, form, property); } status_t -BStringView::GetSupportedSuites(BMessage* message) +BStringView::GetSupportedSuites(BMessage* data) { - return BView::GetSupportedSuites(message); + if (data == NULL) + return B_BAD_VALUE; + + status_t status = data->AddString("suites", "suite/vnd.Be-string-view"); + if (status != B_OK) + return status; + + BPropertyInfo propertyInfo(sPropertyList); + status = data->AddFlat("messages", &propertyInfo); + if (status != B_OK) + return status; + + return BView::GetSupportedSuites(data); }