Ticket #9823: 0001-BStringView-Enabled-scripting.-Fixes-9823.patch

File 0001-BStringView-Enabled-scripting.-Fixes-9823.patch, 3.6 KB (added by jscipione, 11 years ago)

Enables scripting allowing you to get and set Text and Alignment properties

  • src/kits/interface/StringView.cpp

    From 9bdeeef130a425d17ab720d4243e784bed8fe6e7 Mon Sep 17 00:00:00 2001
    From: John Scipione <jscipione@gmail.com>
    Date: Wed, 19 Jun 2013 17:14:38 -0400
    Subject: [PATCH] BStringView: Enabled scripting. Fixes #9823
    
    Configure BStringView to respond to messages to get and set Text and Align
    properties. Fill out ResolveSpecifier() and GetSupportedSuites accordingly.
    
    This goes above and beyond what BeOS R5 did, but, doesn't break backwards
    compat so should be acceptable.
    ---
     src/kits/interface/StringView.cpp | 89 +++++++++++++++++++++++++++++++++++++--
     1 file changed, 85 insertions(+), 4 deletions(-)
    
    diff --git a/src/kits/interface/StringView.cpp b/src/kits/interface/StringView.cpp
    index 8c6981e..0ccd7e5 100644
    a b  
    1919
    2020#include <LayoutUtils.h>
    2121#include <Message.h>
     22#include <PropertyInfo.h>
    2223#include <View.h>
    2324#include <Window.h>
    2425
    2526#include <binary_compatibility/Interface.h>
    2627
    2728
     29static property_info sPropertyList[] = {
     30    {
     31        "Text",
     32        { B_GET_PROPERTY, B_SET_PROPERTY },
     33        { B_DIRECT_SPECIFIER },
     34        NULL, 0,
     35        { B_STRING_TYPE }
     36    },
     37    {
     38        "Align",
     39        { B_GET_PROPERTY, B_SET_PROPERTY },
     40        { B_DIRECT_SPECIFIER },
     41        NULL, 0,
     42        { B_INT32_TYPE }
     43    },
     44    {}
     45};
     46
     47
    2848BStringView::BStringView(BRect frame, const char* name, const char* text,
    2949            uint32 resizeMask, uint32 flags)
    3050    :   BView(frame, name, resizeMask, flags | B_FULL_UPDATE_ON_RESIZE),
    BStringView::Draw(BRect updateRect)  
    261281void
    262282BStringView::MessageReceived(BMessage* message)
    263283{
     284    if (message->what == B_GET_PROPERTY || message->what == B_SET_PROPERTY) {
     285        int32 index;
     286        BMessage specifier;
     287        int32 form;
     288        const char* property;
     289        if (message->GetCurrentSpecifier(&index, &specifier, &form, &property)
     290                != B_OK) {
     291            BView::MessageReceived(message);
     292            return;
     293        }
     294
     295        BMessage reply(B_REPLY);
     296        bool handled = false;
     297        if (strcmp(property, "Text") == 0) {
     298            if (message->what == B_GET_PROPERTY) {
     299                reply.AddString("result", fText);
     300                handled = true;
     301            } else {
     302                const char* text;
     303                if (message->FindString("data", &text) == B_OK) {
     304                    SetText(text);
     305                    reply.AddInt32("error", B_OK);
     306                    handled = true;
     307                }
     308            }
     309        } else if (strcmp(property, "Align") == 0) {
     310            if (message->what == B_GET_PROPERTY) {
     311                reply.AddInt32("result", (int32)fAlign);
     312                handled = true;
     313            } else {
     314                int32 value;
     315                if (message->FindInt32("data", &value) == B_OK) {
     316                    SetAlignment((alignment)value);
     317                    reply.AddInt32("error", B_OK);
     318                    handled = true;
     319                }
     320            }
     321        }
     322
     323        if (handled) {
     324            message->SendReply(&reply);
     325            return;
     326        }
     327    }
     328
    264329    BView::MessageReceived(message);
    265330}
    266331
    BStringView::Alignment() const  
    331396
    332397
    333398BHandler*
    334 BStringView::ResolveSpecifier(BMessage* msg, int32 index,
     399BStringView::ResolveSpecifier(BMessage* message, int32 index,
    335400    BMessage* specifier, int32 form, const char* property)
    336401{
    337     return NULL;
     402    BPropertyInfo propInfo(sPropertyList);
     403    if (propInfo.FindMatch(message, 0, specifier, form, property) >= B_OK)
     404        return this;
     405
     406    return BView::ResolveSpecifier(message, index, specifier, form, property);
    338407}
    339408
    340409
    341410status_t
    342 BStringView::GetSupportedSuites(BMessage* message)
     411BStringView::GetSupportedSuites(BMessage* data)
    343412{
    344     return BView::GetSupportedSuites(message);
     413    if (data == NULL)
     414        return B_BAD_VALUE;
     415
     416    status_t status = data->AddString("suites", "suite/vnd.Be-string-view");
     417    if (status != B_OK)
     418        return status;
     419
     420    BPropertyInfo propertyInfo(sPropertyList);
     421    status = data->AddFlat("messages", &propertyInfo);
     422    if (status != B_OK)
     423        return status;
     424
     425    return BView::GetSupportedSuites(data);
    345426}
    346427
    347428