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
|
|
19 | 19 | |
20 | 20 | #include <LayoutUtils.h> |
21 | 21 | #include <Message.h> |
| 22 | #include <PropertyInfo.h> |
22 | 23 | #include <View.h> |
23 | 24 | #include <Window.h> |
24 | 25 | |
25 | 26 | #include <binary_compatibility/Interface.h> |
26 | 27 | |
27 | 28 | |
| 29 | static 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 | |
28 | 48 | BStringView::BStringView(BRect frame, const char* name, const char* text, |
29 | 49 | uint32 resizeMask, uint32 flags) |
30 | 50 | : BView(frame, name, resizeMask, flags | B_FULL_UPDATE_ON_RESIZE), |
… |
… |
BStringView::Draw(BRect updateRect)
|
261 | 281 | void |
262 | 282 | BStringView::MessageReceived(BMessage* message) |
263 | 283 | { |
| 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 | |
264 | 329 | BView::MessageReceived(message); |
265 | 330 | } |
266 | 331 | |
… |
… |
BStringView::Alignment() const
|
331 | 396 | |
332 | 397 | |
333 | 398 | BHandler* |
334 | | BStringView::ResolveSpecifier(BMessage* msg, int32 index, |
| 399 | BStringView::ResolveSpecifier(BMessage* message, int32 index, |
335 | 400 | BMessage* specifier, int32 form, const char* property) |
336 | 401 | { |
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); |
338 | 407 | } |
339 | 408 | |
340 | 409 | |
341 | 410 | status_t |
342 | | BStringView::GetSupportedSuites(BMessage* message) |
| 411 | BStringView::GetSupportedSuites(BMessage* data) |
343 | 412 | { |
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); |
345 | 426 | } |
346 | 427 | |
347 | 428 | |