Ticket #11394: 0003-Button-add-a-SetIcon-resourceID-convenience-method.patch

File 0003-Button-add-a-SetIcon-resourceID-convenience-method.patch, 3.5 KB (added by waddlesplash, 10 years ago)
  • docs/user/interface/Control.dox

    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  
    495495
    496496
    497497/*!
     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/*!
    498520    \fn status_t BControl::SetIconBitmap(const BBitmap* bitmap,
    499521        uint32 which, uint32 flags)
    500522    \brief Icon bitmaps for various states of the control (off, on,
  • headers/os/interface/Control.h

    diff --git a/headers/os/interface/Control.h b/headers/os/interface/Control.h
    index 94edfd7..e79fe91 100644
    a b public:  
    7676
    7777    virtual status_t            SetIcon(const BBitmap* bitmap,
    7878                                    uint32 flags = 0);
     79            status_t            SetIcon(const int32 resourceID,
     80                                    uint32 flags = 0);
    7981            status_t            SetIconBitmap(const BBitmap* bitmap,
    8082                                    uint32 which, uint32 flags = 0);
    8183            const BBitmap*      IconBitmap(uint32 which) const;
  • src/kits/interface/Control.cpp

    diff --git a/src/kits/interface/Control.cpp b/src/kits/interface/Control.cpp
    index 6cef099..208ed1e 100644
    a b  
    1414#include <stdlib.h>
    1515#include <string.h>
    1616
     17#include <Application.h>
     18#include <Bitmap.h>
    1719#include <Control.h>
     20#include <IconUtils.h>
    1821#include <PropertyInfo.h>
     22#include <Resources.h>
     23#include <Roster.h>
    1924#include <Window.h>
    2025
    2126#include <binary_compatibility/Interface.h>
    BControl::SetIcon(const BBitmap* bitmap, uint32 flags)  
    542547
    543548
    544549status_t
     550BControl::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
     580status_t
    545581BControl::SetIconBitmap(const BBitmap* bitmap, uint32 which, uint32 flags)
    546582{
    547583    status_t error = BIcon::SetIconBitmap(bitmap, which, flags, fIcon);