From 0d92f1ac67d8e524f91e1baf5024bbd9a65b4bf9 Mon Sep 17 00:00:00 2001
From: Augustin Cavalier <waddlesplash@gmail.com>
Date: Thu, 13 Nov 2014 21:06:39 -0500
Subject: [PATCH] Button: add a SetIcon(resourceID) convenience method.
Mostly copied from BIconButton.
---
docs/user/interface/Control.dox | 22 ++++++++++++++++++++++
headers/os/interface/Control.h | 2 ++
src/kits/interface/Control.cpp | 36 ++++++++++++++++++++++++++++++++++++
3 files changed, 60 insertions(+)
diff --git a/docs/user/interface/Control.dox b/docs/user/interface/Control.dox
index b8a608f..309fb81 100644
a
|
b
|
|
495 | 495 | |
496 | 496 | |
497 | 497 | /*! |
| 498 | \fn status_t BControl::SetIcon(const int32 resourceID, uint32 flags) |
| 499 | \brief This convenience method is used to set the bitmaps |
| 500 | for the standard states from a single bitmap. |
| 501 | |
| 502 | \param resourceID The ID of a vector icon resource in the |
| 503 | application's binary. |
| 504 | \param flags Modify how the icon is set. |
| 505 | - \c B_TRIM_ICON_BITMAP Crop the bitmap to the not fully transparent |
| 506 | area, may change the icon size. |
| 507 | - \c B_TRIM_ICON_BITMAP_KEEP_ASPECT Like \c B_TRIM_BITMAP, but keeps |
| 508 | the aspect ratio. |
| 509 | - \c B_CREATE_ACTIVE_ICON_BITMAP |
| 510 | - \c B_CREATE_PARTIALLY_ACTIVE_ICON_BITMAP |
| 511 | - \c B_CREATE_DISABLED_ICON_BITMAPS |
| 512 | |
| 513 | \return \c B_OK if the icon was set or an error code otherwise. |
| 514 | |
| 515 | \since Haiku R1 |
| 516 | */ |
| 517 | |
| 518 | |
| 519 | /*! |
498 | 520 | \fn status_t BControl::SetIconBitmap(const BBitmap* bitmap, |
499 | 521 | uint32 which, uint32 flags) |
500 | 522 | \brief Icon bitmaps for various states of the control (off, on, |
diff --git a/headers/os/interface/Control.h b/headers/os/interface/Control.h
index 94edfd7..e79fe91 100644
a
|
b
|
public:
|
76 | 76 | |
77 | 77 | virtual status_t SetIcon(const BBitmap* bitmap, |
78 | 78 | uint32 flags = 0); |
| 79 | status_t SetIcon(const int32 resourceID, |
| 80 | uint32 flags = 0); |
79 | 81 | status_t SetIconBitmap(const BBitmap* bitmap, |
80 | 82 | uint32 which, uint32 flags = 0); |
81 | 83 | const BBitmap* IconBitmap(uint32 which) const; |
diff --git a/src/kits/interface/Control.cpp b/src/kits/interface/Control.cpp
index 6cef099..208ed1e 100644
a
|
b
|
|
14 | 14 | #include <stdlib.h> |
15 | 15 | #include <string.h> |
16 | 16 | |
| 17 | #include <Application.h> |
| 18 | #include <Bitmap.h> |
17 | 19 | #include <Control.h> |
| 20 | #include <IconUtils.h> |
18 | 21 | #include <PropertyInfo.h> |
| 22 | #include <Resources.h> |
| 23 | #include <Roster.h> |
19 | 24 | #include <Window.h> |
20 | 25 | |
21 | 26 | #include <binary_compatibility/Interface.h> |
… |
… |
BControl::SetIcon(const BBitmap* bitmap, uint32 flags)
|
542 | 547 | |
543 | 548 | |
544 | 549 | status_t |
| 550 | BControl::SetIcon(const int32 resourceID, uint32 flags) |
| 551 | { |
| 552 | app_info info; |
| 553 | status_t status = be_app->GetAppInfo(&info); |
| 554 | if (status != B_OK) |
| 555 | return status; |
| 556 | |
| 557 | BResources resources(&info.ref); |
| 558 | status = resources.InitCheck(); |
| 559 | if (status != B_OK) |
| 560 | return status; |
| 561 | |
| 562 | size_t size; |
| 563 | const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE, resourceID, |
| 564 | &size); |
| 565 | if (data == NULL) |
| 566 | return B_ENTRY_NOT_FOUND; |
| 567 | |
| 568 | BBitmap bitmap(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK, B_RGBA32); |
| 569 | status = bitmap.InitCheck(); |
| 570 | if (status != B_OK) |
| 571 | return status; |
| 572 | status = BIconUtils::GetVectorIcon(reinterpret_cast<const uint8*>(data), |
| 573 | size, &bitmap); |
| 574 | if (status != B_OK) |
| 575 | return status; |
| 576 | return SetIcon(&bitmap, flags); |
| 577 | } |
| 578 | |
| 579 | |
| 580 | status_t |
545 | 581 | BControl::SetIconBitmap(const BBitmap* bitmap, uint32 which, uint32 flags) |
546 | 582 | { |
547 | 583 | status_t error = BIcon::SetIconBitmap(bitmap, which, flags, fIcon); |