BControl: Add icon support
The icon is meant as an addition to or replacement of the label. Icon bitmaps for various states of the control (off, on, partially on, each enabled or disabled, plus up to 125 custom states) can be set individually via SetIconBitmap() (getter IconBitmap()). The convenience method SetIcon() can be used to set the bitmaps for the standard states from a single bitmap; it also supports cropping the icon to its non-transparent area. Code borrowed from BIconButton.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2009, Haiku, Inc. All rights reserved.
|
||||
* Copyright 2001-2013, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _CONTROL_H
|
||||
@@ -16,10 +16,42 @@ enum {
|
||||
B_CONTROL_PARTIALLY_ON = 2
|
||||
};
|
||||
|
||||
class BBitmap;
|
||||
class BWindow;
|
||||
|
||||
|
||||
class BControl : public BView, public BInvoker {
|
||||
public:
|
||||
// Values for [Set]IconBitmap(). Not all types are applicable for
|
||||
// all controls.
|
||||
enum {
|
||||
B_OFF_BITMAP = 0x00,
|
||||
B_ON_BITMAP = 0x01,
|
||||
B_PARTIALLY_ON_BITMAP = 0x02,
|
||||
|
||||
// flag, can be combined with any of the above
|
||||
B_DISABLED_BITMAP = 0x80,
|
||||
// disabled version of the specified bitmap
|
||||
};
|
||||
|
||||
// flags for SetIconBitmap()
|
||||
enum {
|
||||
B_KEEP_BITMAP = 0x0001,
|
||||
// transfer bitmap ownership to BControl object
|
||||
};
|
||||
|
||||
// flags for SetIcon()
|
||||
enum {
|
||||
B_TRIM_BITMAP = 0x0100,
|
||||
// crop the bitmap to the not fully transparent area, may
|
||||
// change the icon size
|
||||
B_TRIM_BITMAP_KEEP_ASPECT = 0x0200,
|
||||
// like B_TRIM_BITMAP, but keeps the aspect ratio
|
||||
B_CREATE_ON_BITMAP = 0x0400,
|
||||
B_CREATE_PARTIALLY_ON_BITMAP = 0x0800,
|
||||
B_CREATE_DISABLED_BITMAPS = 0x1000,
|
||||
};
|
||||
|
||||
public:
|
||||
BControl(BRect frame, const char* name,
|
||||
const char* label, BMessage* message,
|
||||
@@ -70,6 +102,12 @@ public:
|
||||
|
||||
virtual status_t Perform(perform_code d, void* arg);
|
||||
|
||||
virtual status_t SetIcon(const BBitmap* bitmap,
|
||||
uint32 flags = 0);
|
||||
status_t SetIconBitmap(const BBitmap* bitmap,
|
||||
uint32 which, uint32 flags = 0);
|
||||
const BBitmap* IconBitmap(uint32 which) const;
|
||||
|
||||
protected:
|
||||
bool IsFocusChanging() const;
|
||||
bool IsTracking() const;
|
||||
@@ -78,7 +116,16 @@ protected:
|
||||
void SetValueNoUpdate(int32 value);
|
||||
|
||||
private:
|
||||
virtual void _ReservedControl1();
|
||||
struct IconData;
|
||||
|
||||
private:
|
||||
static BBitmap* _ConvertToRGB32(const BBitmap* bitmap,
|
||||
bool noAppServerLink = false);
|
||||
static status_t _TrimBitmap(const BBitmap* bitmap,
|
||||
bool keepAspect, BBitmap*& _trimmedBitmap);
|
||||
status_t _MakeBitmaps(const BBitmap* bitmap,
|
||||
uint32 flags);
|
||||
|
||||
virtual void _ReservedControl2();
|
||||
virtual void _ReservedControl3();
|
||||
virtual void _ReservedControl4();
|
||||
@@ -87,14 +134,20 @@ private:
|
||||
|
||||
void InitData(BMessage* data = NULL);
|
||||
|
||||
private:
|
||||
char* fLabel;
|
||||
int32 fValue;
|
||||
bool fEnabled;
|
||||
bool fFocusChanging;
|
||||
bool fTracking;
|
||||
bool fWantsNav;
|
||||
IconData* fIconData;
|
||||
|
||||
uint32 _reserved[4];
|
||||
#ifdef B_HAIKU_64_BIT
|
||||
uint32 _reserved[2];
|
||||
#else
|
||||
uint32 _reserved[3];
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // _CONTROL_H
|
||||
|
||||
@@ -29,12 +29,12 @@ enum {
|
||||
PERFORM_CODE_LAYOUT_INVALIDATED = 1007,
|
||||
PERFORM_CODE_DO_LAYOUT = 1008,
|
||||
PERFORM_CODE_GET_TOOL_TIP_AT = 1009,
|
||||
PERFORM_CODE_LAYOUT_CHANGED = 1010,
|
||||
PERFORM_CODE_SET_ICON = 1011,
|
||||
|
||||
// support kit
|
||||
PERFORM_CODE_ALL_ARCHIVED = 1010,
|
||||
PERFORM_CODE_ALL_UNARCHIVED = 1011,
|
||||
|
||||
PERFORM_CODE_LAYOUT_CHANGED = 1012
|
||||
PERFORM_CODE_ALL_ARCHIVED = 2000,
|
||||
PERFORM_CODE_ALL_UNARCHIVED = 2001,
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -51,4 +51,10 @@ struct perform_data_get_tool_tip_at {
|
||||
bool return_value;
|
||||
};
|
||||
|
||||
struct perform_data_set_icon {
|
||||
const BBitmap* icon;
|
||||
uint32 flags;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _BINARY_COMPATIBILITY_INTERFACE_H_ */
|
||||
|
||||
Reference in New Issue
Block a user