2 * Copyright 2006-2011, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
7 * Axel Dörfler, axeld@pinc-software.de.
11 #include "IconButton.h"
16 #include <Application.h>
19 #include <ControlLook.h>
21 #include <IconUtils.h>
27 #include <Resources.h>
29 #include <TranslationUtils.h>
38 STATE_PRESSED
= 0x0002,
39 STATE_INSIDE
= 0x0008,
40 STATE_FORCE_PRESSED
= 0x0010,
45 BIconButton::BIconButton(const char* name
, const char* label
,
46 BMessage
* message
, BHandler
* target
)
48 BControl(name
, label
, message
, B_WILL_DRAW
),
51 fDisabledBitmap(NULL
),
53 fDisabledClickedBitmap(NULL
),
57 SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR
));
58 SetViewColor(B_TRANSPARENT_32_BIT
);
62 BIconButton::~BIconButton()
69 BIconButton::MessageReceived(BMessage
* message
)
71 switch (message
->what
) {
73 BView::MessageReceived(message
);
80 BIconButton::AttachedToWindow()
84 if (ViewUIColor() != B_NO_COLOR
)
85 SetLowUIColor(ViewUIColor());
87 SetTarget(fTargetCache
);
94 BIconButton::Draw(BRect updateRect
)
96 rgb_color background
= LowColor();
101 BBitmap
* bitmap
= fNormalBitmap
;
103 flags
|= BControlLook::B_DISABLED
;
104 bitmap
= fDisabledBitmap
;
106 if (_HasFlags(STATE_PRESSED
) || _HasFlags(STATE_FORCE_PRESSED
))
107 flags
|= BControlLook::B_ACTIVATED
;
109 if (ShouldDrawBorder()) {
110 DrawBorder(r
, updateRect
, background
, flags
);
111 DrawBackground(r
, updateRect
, background
, flags
);
113 SetHighColor(background
);
117 if (bitmap
&& bitmap
->IsValid()) {
118 if (bitmap
->ColorSpace() == B_RGBA32
119 || bitmap
->ColorSpace() == B_RGBA32_BIG
) {
120 SetDrawingMode(B_OP_ALPHA
);
121 SetBlendingMode(B_PIXEL_ALPHA
, B_ALPHA_OVERLAY
);
123 float x
= r
.left
+ floorf((r
.Width()
124 - bitmap
->Bounds().Width()) / 2.0 + 0.5);
125 float y
= r
.top
+ floorf((r
.Height()
126 - bitmap
->Bounds().Height()) / 2.0 + 0.5);
127 DrawBitmap(bitmap
, BPoint(x
, y
));
133 BIconButton::ShouldDrawBorder() const
135 return (IsEnabled() && (IsInside() || IsTracking()))
136 || _HasFlags(STATE_FORCE_PRESSED
);
141 BIconButton::DrawBorder(BRect
& frame
, const BRect
& updateRect
,
142 const rgb_color
& backgroundColor
, uint32 flags
)
144 be_control_look
->DrawButtonFrame(this, frame
, updateRect
, backgroundColor
,
145 backgroundColor
, flags
);
150 BIconButton::DrawBackground(BRect
& frame
, const BRect
& updateRect
,
151 const rgb_color
& backgroundColor
, uint32 flags
)
153 be_control_look
->DrawButtonBackground(this, frame
, updateRect
,
154 backgroundColor
, flags
);
159 BIconButton::MouseDown(BPoint where
)
165 if (Bounds().Contains(where
)) {
166 SetMouseEventMask(B_POINTER_EVENTS
, B_LOCK_WINDOW_FOCUS
);
167 _SetFlags(STATE_PRESSED
, true);
170 _SetFlags(STATE_PRESSED
, false);
178 BIconButton::MouseUp(BPoint where
)
183 if (IsEnabled() && _HasFlags(STATE_PRESSED
)
184 && Bounds().Contains(where
)) {
186 } else if (Bounds().Contains(where
))
189 _SetFlags(STATE_PRESSED
, false);
195 BIconButton::MouseMoved(BPoint where
, uint32 transit
, const BMessage
* message
)
201 Window()->CurrentMessage()->FindInt32("buttons", (int32
*)&buttons
);
202 // catch a mouse up event that we might have missed
203 if (!buttons
&& _HasFlags(STATE_PRESSED
)) {
207 if (buttons
!= 0 && !IsTracking())
210 SetInside((transit
== B_INSIDE_VIEW
|| transit
== B_ENTERED_VIEW
)
213 _SetFlags(STATE_PRESSED
, Bounds().Contains(where
));
218 BIconButton::GetPreferredSize(float* width
, float* height
)
220 float minWidth
= 0.0f
;
221 float minHeight
= 0.0f
;
223 minWidth
+= fNormalBitmap
->Bounds().IntegerWidth() + 1.0f
;
224 minHeight
+= fNormalBitmap
->Bounds().IntegerHeight() + 1.0f
;
227 const float kMinSpace
= 15.0f
;
228 if (minWidth
< kMinSpace
)
229 minWidth
= kMinSpace
;
230 if (minHeight
< kMinSpace
)
231 minHeight
= kMinSpace
;
233 float hPadding
= max_c(6.0f
, ceilf(minHeight
/ 4.0f
));
234 float vPadding
= max_c(6.0f
, ceilf(minWidth
/ 4.0f
));
236 if (Label() != NULL
&& Label()[0] != '\0') {
239 minHeight
+= ceilf(fh
.ascent
+ fh
.descent
) + vPadding
;
240 minWidth
+= StringWidth(Label()) + vPadding
;
244 *width
= minWidth
+ hPadding
;
246 *height
= minHeight
+ vPadding
;
251 BIconButton::MinSize()
254 GetPreferredSize(&size
.width
, &size
.height
);
260 BIconButton::MaxSize()
267 BIconButton::Invoke(BMessage
* message
)
271 if (message
!= NULL
) {
272 BMessage
clone(*message
);
273 clone
.AddInt64("be:when", system_time());
274 clone
.AddPointer("be:source", (BView
*)this);
275 clone
.AddInt32("be:value", Value());
276 return BInvoker::Invoke(&clone
);
278 return BInvoker::Invoke(message
);
283 BIconButton::SetPressed(bool pressed
)
285 _SetFlags(STATE_FORCE_PRESSED
, pressed
);
290 BIconButton::IsPressed() const
292 return _HasFlags(STATE_FORCE_PRESSED
);
297 BIconButton::SetIcon(int32 resourceID
)
300 status_t status
= be_app
->GetAppInfo(&info
);
304 BResources
resources(&info
.ref
);
305 status
= resources
.InitCheck();
310 const void* data
= resources
.LoadResource(B_VECTOR_ICON_TYPE
, resourceID
,
313 BBitmap
bitmap(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK
, B_RGBA32
);
314 status
= bitmap
.InitCheck();
317 status
= BIconUtils::GetVectorIcon(reinterpret_cast<const uint8
*>(data
),
321 return SetIcon(&bitmap
);
323 // const void* data = resources.LoadResource(B_BITMAP_TYPE, resourceID, &size);
329 BIconButton::SetIcon(const char* pathToBitmap
)
331 if (pathToBitmap
== NULL
)
334 status_t status
= B_BAD_VALUE
;
335 BBitmap
* fileBitmap
= NULL
;
336 // try to load bitmap from either relative or absolute path
337 BEntry
entry(pathToBitmap
, true);
338 if (!entry
.Exists()) {
340 status
= be_app
->GetAppInfo(&info
);
341 if (status
== B_OK
) {
342 BEntry
app_entry(&info
.ref
, true);
344 app_entry
.GetPath(&path
);
345 status
= path
.InitCheck();
346 if (status
== B_OK
) {
347 status
= path
.GetParent(&path
);
348 if (status
== B_OK
) {
349 status
= path
.Append(pathToBitmap
, true);
351 fileBitmap
= BTranslationUtils::GetBitmap(path
.Path());
353 printf("BIconButton::SetIcon() - path.Append() failed: "
354 "%s\n", strerror(status
));
357 printf("BIconButton::SetIcon() - path.GetParent() failed: "
358 "%s\n", strerror(status
));
361 printf("BIconButton::SetIcon() - path.InitCheck() failed: "
362 "%s\n", strerror(status
));
365 printf("BIconButton::SetIcon() - be_app->GetAppInfo() failed: "
366 "%s\n", strerror(status
));
369 fileBitmap
= BTranslationUtils::GetBitmap(pathToBitmap
);
371 status
= _MakeBitmaps(fileBitmap
);
380 BIconButton::SetIcon(const BBitmap
* bitmap
, uint32 flags
)
382 if (bitmap
&& bitmap
->ColorSpace() == B_CMAP8
) {
383 status_t status
= bitmap
->InitCheck();
384 if (status
>= B_OK
) {
385 if (BBitmap
* rgb32Bitmap
= _ConvertToRGB32(bitmap
)) {
386 status
= _MakeBitmaps(rgb32Bitmap
);
389 status
= B_NO_MEMORY
;
393 return _MakeBitmaps(bitmap
);
398 BIconButton::SetIcon(const BMimeType
* fileType
, bool small
)
400 status_t status
= fileType
? fileType
->InitCheck() : B_BAD_VALUE
;
401 if (status
>= B_OK
) {
402 BBitmap
* mimeBitmap
= new(std::nothrow
) BBitmap(BRect(0.0, 0.0, 15.0,
404 if (mimeBitmap
&& mimeBitmap
->IsValid()) {
405 status
= fileType
->GetIcon(mimeBitmap
, small
? B_MINI_ICON
407 if (status
>= B_OK
) {
408 if (BBitmap
* bitmap
= _ConvertToRGB32(mimeBitmap
)) {
409 status
= _MakeBitmaps(bitmap
);
412 printf("BIconButton::SetIcon() - B_RGB32 bitmap is not "
416 printf("BIconButton::SetIcon() - fileType->GetIcon() failed: "
417 "%s\n", strerror(status
));
420 printf("BIconButton::SetIcon() - B_CMAP8 bitmap is not valid\n");
423 printf("BIconButton::SetIcon() - fileType is not valid: %s\n",
431 BIconButton::SetIcon(const unsigned char* bitsFromQuickRes
,
432 uint32 width
, uint32 height
, color_space format
, bool convertToBW
)
434 status_t status
= B_BAD_VALUE
;
435 if (bitsFromQuickRes
&& width
> 0 && height
> 0) {
436 BBitmap
* quickResBitmap
= new(std::nothrow
) BBitmap(BRect(0.0, 0.0,
437 width
- 1.0, height
- 1.0), format
);
438 status
= quickResBitmap
? quickResBitmap
->InitCheck() : B_ERROR
;
439 if (status
>= B_OK
) {
440 // It doesn't look right to copy BitsLength() bytes, but bitmaps
441 // exported from QuickRes still contain their padding, so it is
443 memcpy(quickResBitmap
->Bits(), bitsFromQuickRes
,
444 quickResBitmap
->BitsLength());
445 if (format
!= B_RGB32
&& format
!= B_RGBA32
446 && format
!= B_RGB32_BIG
&& format
!= B_RGBA32_BIG
) {
447 // colorspace needs conversion
448 BBitmap
* bitmap
= new(std::nothrow
) BBitmap(
449 quickResBitmap
->Bounds(), B_RGB32
, true);
450 if (bitmap
&& bitmap
->IsValid()) {
451 if (bitmap
->Lock()) {
452 BView
* helper
= new BView(bitmap
->Bounds(), "helper",
453 B_FOLLOW_NONE
, B_WILL_DRAW
);
454 bitmap
->AddChild(helper
);
455 helper
->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR
));
456 helper
->FillRect(helper
->Bounds());
457 helper
->SetDrawingMode(B_OP_OVER
);
458 helper
->DrawBitmap(quickResBitmap
, BPoint(0.0, 0.0));
462 status
= _MakeBitmaps(bitmap
);
464 printf("BIconButton::SetIcon() - B_RGB32 bitmap is not "
469 // native colorspace (32 bits)
471 // convert to gray scale icon
472 uint8
* bits
= (uint8
*)quickResBitmap
->Bits();
473 uint32 bpr
= quickResBitmap
->BytesPerRow();
474 for (uint32 y
= 0; y
< height
; y
++) {
475 uint8
* handle
= bits
;
477 for (uint32 x
= 0; x
< width
; x
++) {
478 gray
= uint8((116 * handle
[0] + 600 * handle
[1]
479 + 308 * handle
[2]) / 1024);
488 status
= _MakeBitmaps(quickResBitmap
);
491 printf("BIconButton::SetIcon() - error allocating bitmap: "
492 "%s\n", strerror(status
));
494 delete quickResBitmap
;
501 BIconButton::ClearIcon()
509 BIconButton::TrimIcon(bool keepAspect
)
511 if (fNormalBitmap
== NULL
)
514 uint8
* bits
= (uint8
*)fNormalBitmap
->Bits();
515 uint32 bpr
= fNormalBitmap
->BytesPerRow();
516 uint32 width
= fNormalBitmap
->Bounds().IntegerWidth() + 1;
517 uint32 height
= fNormalBitmap
->Bounds().IntegerHeight() + 1;
518 BRect
trimmed(INT32_MAX
, INT32_MAX
, INT32_MIN
, INT32_MIN
);
519 for (uint32 y
= 0; y
< height
; y
++) {
521 bool rowHasAlpha
= false;
522 for (uint32 x
= 0; x
< width
; x
++) {
525 if (x
< trimmed
.left
)
527 if (x
> trimmed
.right
)
535 if (y
> trimmed
.bottom
)
540 if (!trimmed
.IsValid())
543 float minInset
= trimmed
.left
;
544 minInset
= min_c(minInset
, trimmed
.top
);
545 minInset
= min_c(minInset
, fNormalBitmap
->Bounds().right
547 minInset
= min_c(minInset
, fNormalBitmap
->Bounds().bottom
549 trimmed
= fNormalBitmap
->Bounds().InsetByCopy(minInset
, minInset
);
551 trimmed
= trimmed
& fNormalBitmap
->Bounds();
552 BBitmap
trimmedBitmap(trimmed
.OffsetToCopy(B_ORIGIN
),
553 B_BITMAP_NO_SERVER_LINK
, B_RGBA32
);
554 bits
= (uint8
*)fNormalBitmap
->Bits();
555 bits
+= 4 * (int32
)trimmed
.left
+ bpr
* (int32
)trimmed
.top
;
556 uint8
* dst
= (uint8
*)trimmedBitmap
.Bits();
557 uint32 trimmedWidth
= trimmedBitmap
.Bounds().IntegerWidth() + 1;
558 uint32 trimmedHeight
= trimmedBitmap
.Bounds().IntegerHeight() + 1;
559 uint32 trimmedBPR
= trimmedBitmap
.BytesPerRow();
560 for (uint32 y
= 0; y
< trimmedHeight
; y
++) {
561 memcpy(dst
, bits
, trimmedWidth
* 4);
565 SetIcon(&trimmedBitmap
);
570 BIconButton::IsValid() const
572 return (fNormalBitmap
&& fDisabledBitmap
&& fClickedBitmap
573 && fDisabledClickedBitmap
574 && fNormalBitmap
->IsValid()
575 && fDisabledBitmap
->IsValid()
576 && fClickedBitmap
->IsValid()
577 && fDisabledClickedBitmap
->IsValid());
582 BIconButton::Bitmap() const
584 BBitmap
* bitmap
= NULL
;
585 if (fNormalBitmap
&& fNormalBitmap
->IsValid()) {
586 bitmap
= new(std::nothrow
) BBitmap(fNormalBitmap
);
587 if (bitmap
!= NULL
&& bitmap
->IsValid()) {
588 // TODO: remove this functionality when we use real transparent
590 uint8
* bits
= (uint8
*)bitmap
->Bits();
591 uint32 bpr
= bitmap
->BytesPerRow();
592 uint32 width
= bitmap
->Bounds().IntegerWidth() + 1;
593 uint32 height
= bitmap
->Bounds().IntegerHeight() + 1;
594 color_space format
= bitmap
->ColorSpace();
595 if (format
== B_CMAP8
) {
596 // replace gray with magic transparent index
597 } else if (format
== B_RGB32
) {
598 for (uint32 y
= 0; y
< height
; y
++) {
599 uint8
* bitsHandle
= bits
;
600 for (uint32 x
= 0; x
< width
; x
++) {
601 if (bitsHandle
[0] == 216
602 && bitsHandle
[1] == 216
603 && bitsHandle
[2] == 216) {
604 // make this pixel completely transparent
622 BIconButton::SetValue(int32 value
)
624 BControl::SetValue(value
);
625 _SetFlags(STATE_PRESSED
, value
!= 0);
630 BIconButton::SetEnabled(bool enabled
)
632 BControl::SetEnabled(enabled
);
640 // #pragma mark - protected
644 BIconButton::IsInside() const
646 return _HasFlags(STATE_INSIDE
);
651 BIconButton::SetInside(bool inside
)
653 _SetFlags(STATE_INSIDE
, inside
);
657 // #pragma mark - private
661 BIconButton::_ConvertToRGB32(const BBitmap
* bitmap
) const
663 BBitmap
* convertedBitmap
= new(std::nothrow
) BBitmap(bitmap
->Bounds(),
664 B_BITMAP_ACCEPTS_VIEWS
, B_RGBA32
);
665 if (convertedBitmap
&& convertedBitmap
->IsValid()) {
666 memset(convertedBitmap
->Bits(), 0, convertedBitmap
->BitsLength());
667 if (convertedBitmap
->Lock()) {
668 BView
* helper
= new BView(bitmap
->Bounds(), "helper",
669 B_FOLLOW_NONE
, B_WILL_DRAW
);
670 convertedBitmap
->AddChild(helper
);
671 helper
->SetDrawingMode(B_OP_OVER
);
672 helper
->DrawBitmap(bitmap
, BPoint(0.0, 0.0));
674 convertedBitmap
->Unlock();
677 delete convertedBitmap
;
678 convertedBitmap
= NULL
;
680 return convertedBitmap
;
685 BIconButton::_MakeBitmaps(const BBitmap
* bitmap
)
687 status_t status
= bitmap
? bitmap
->InitCheck() : B_BAD_VALUE
;
688 if (status
== B_OK
) {
689 // make our own versions of the bitmap
690 BRect
b(bitmap
->Bounds());
692 color_space format
= bitmap
->ColorSpace();
693 fNormalBitmap
= new(std::nothrow
) BBitmap(b
, format
);
694 fDisabledBitmap
= new(std::nothrow
) BBitmap(b
, format
);
695 fClickedBitmap
= new(std::nothrow
) BBitmap(b
, format
);
696 fDisabledClickedBitmap
= new(std::nothrow
) BBitmap(b
, format
);
698 // copy bitmaps from file bitmap
699 uint8
* nBits
= (uint8
*)fNormalBitmap
->Bits();
700 uint8
* dBits
= (uint8
*)fDisabledBitmap
->Bits();
701 uint8
* cBits
= (uint8
*)fClickedBitmap
->Bits();
702 uint8
* dcBits
= (uint8
*)fDisabledClickedBitmap
->Bits();
703 uint8
* fBits
= (uint8
*)bitmap
->Bits();
704 int32 nbpr
= fNormalBitmap
->BytesPerRow();
705 int32 fbpr
= bitmap
->BytesPerRow();
706 int32 pixels
= b
.IntegerWidth() + 1;
707 int32 lines
= b
.IntegerHeight() + 1;
708 // nontransparent version:
709 if (format
== B_RGB32
|| format
== B_RGB32_BIG
) {
710 // iterate over color components
711 for (int32 y
= 0; y
< lines
; y
++) {
712 for (int32 x
= 0; x
< pixels
; x
++) {
713 int32 nOffset
= 4 * x
;
714 int32 fOffset
= 4 * x
;
715 nBits
[nOffset
+ 0] = fBits
[fOffset
+ 0];
716 nBits
[nOffset
+ 1] = fBits
[fOffset
+ 1];
717 nBits
[nOffset
+ 2] = fBits
[fOffset
+ 2];
718 nBits
[nOffset
+ 3] = 255;
719 // clicked bits are darker (lame method...)
720 cBits
[nOffset
+ 0] = (uint8
)((float)nBits
[nOffset
+ 0]
722 cBits
[nOffset
+ 1] = (uint8
)((float)nBits
[nOffset
+ 1]
724 cBits
[nOffset
+ 2] = (uint8
)((float)nBits
[nOffset
+ 2]
726 cBits
[nOffset
+ 3] = 255;
727 // disabled bits have less contrast (lame method...)
729 float dist
= (nBits
[nOffset
+ 0] - grey
) * 0.4;
730 dBits
[nOffset
+ 0] = (uint8
)(grey
+ dist
);
731 dist
= (nBits
[nOffset
+ 1] - grey
) * 0.4;
732 dBits
[nOffset
+ 1] = (uint8
)(grey
+ dist
);
733 dist
= (nBits
[nOffset
+ 2] - grey
) * 0.4;
734 dBits
[nOffset
+ 2] = (uint8
)(grey
+ dist
);
735 dBits
[nOffset
+ 3] = 255;
736 // disabled bits have less contrast (lame method...)
738 dist
= (nBits
[nOffset
+ 0] - grey
) * 0.4;
739 dcBits
[nOffset
+ 0] = (uint8
)(grey
+ dist
);
740 dist
= (nBits
[nOffset
+ 1] - grey
) * 0.4;
741 dcBits
[nOffset
+ 1] = (uint8
)(grey
+ dist
);
742 dist
= (nBits
[nOffset
+ 2] - grey
) * 0.4;
743 dcBits
[nOffset
+ 2] = (uint8
)(grey
+ dist
);
744 dcBits
[nOffset
+ 3] = 255;
752 // transparent version:
753 } else if (format
== B_RGBA32
|| format
== B_RGBA32_BIG
) {
754 // iterate over color components
755 for (int32 y
= 0; y
< lines
; y
++) {
756 for (int32 x
= 0; x
< pixels
; x
++) {
757 int32 nOffset
= 4 * x
;
758 int32 fOffset
= 4 * x
;
759 nBits
[nOffset
+ 0] = fBits
[fOffset
+ 0];
760 nBits
[nOffset
+ 1] = fBits
[fOffset
+ 1];
761 nBits
[nOffset
+ 2] = fBits
[fOffset
+ 2];
762 nBits
[nOffset
+ 3] = fBits
[fOffset
+ 3];
763 // clicked bits are darker (lame method...)
764 cBits
[nOffset
+ 0] = (uint8
)(nBits
[nOffset
+ 0] * 0.8);
765 cBits
[nOffset
+ 1] = (uint8
)(nBits
[nOffset
+ 1] * 0.8);
766 cBits
[nOffset
+ 2] = (uint8
)(nBits
[nOffset
+ 2] * 0.8);
767 cBits
[nOffset
+ 3] = fBits
[fOffset
+ 3];
768 // disabled bits have less opacity
770 uint8 grey
= ((uint16
)nBits
[nOffset
+ 0] * 10
771 + nBits
[nOffset
+ 1] * 60
772 + nBits
[nOffset
+ 2] * 30) / 100;
773 float dist
= (nBits
[nOffset
+ 0] - grey
) * 0.3;
774 dBits
[nOffset
+ 0] = (uint8
)(grey
+ dist
);
775 dist
= (nBits
[nOffset
+ 1] - grey
) * 0.3;
776 dBits
[nOffset
+ 1] = (uint8
)(grey
+ dist
);
777 dist
= (nBits
[nOffset
+ 2] - grey
) * 0.3;
778 dBits
[nOffset
+ 2] = (uint8
)(grey
+ dist
);
779 dBits
[nOffset
+ 3] = (uint8
)(fBits
[fOffset
+ 3] * 0.3);
780 // disabled bits have less contrast (lame method...)
781 dcBits
[nOffset
+ 0] = (uint8
)(dBits
[nOffset
+ 0] * 0.8);
782 dcBits
[nOffset
+ 1] = (uint8
)(dBits
[nOffset
+ 1] * 0.8);
783 dcBits
[nOffset
+ 2] = (uint8
)(dBits
[nOffset
+ 2] * 0.8);
784 dcBits
[nOffset
+ 3] = (uint8
)(fBits
[fOffset
+ 3] * 0.3);
792 // unsupported format
794 printf("BIconButton::_MakeBitmaps() - bitmap has unsupported "
796 status
= B_MISMATCHED_VALUES
;
800 printf("BIconButton::_MakeBitmaps() - error allocating local "
802 status
= B_NO_MEMORY
;
806 printf("BIconButton::_MakeBitmaps() - bitmap is not valid\n");
812 BIconButton::_DeleteBitmaps()
814 delete fNormalBitmap
;
815 fNormalBitmap
= NULL
;
816 delete fDisabledBitmap
;
817 fDisabledBitmap
= NULL
;
818 delete fClickedBitmap
;
819 fClickedBitmap
= NULL
;
820 delete fDisabledClickedBitmap
;
821 fDisabledClickedBitmap
= NULL
;
826 BIconButton::_Update()
836 BIconButton::_SetFlags(uint32 flags
, bool set
)
838 if (_HasFlags(flags
) != set
) {
840 fButtonState
|= flags
;
842 fButtonState
&= ~flags
;
844 if ((flags
& STATE_PRESSED
) != 0)
845 SetValueNoUpdate(set
? B_CONTROL_ON
: B_CONTROL_OFF
);
852 BIconButton::_HasFlags(uint32 flags
) const
854 return (fButtonState
& flags
) != 0;
858 //! This one calls _Update() if needed; BControl::SetTracking() isn't virtual.
860 BIconButton::_SetTracking(bool tracking
)
862 if (IsTracking() == tracking
)
865 SetTracking(tracking
);
870 } // namespace BPrivate