2007-06-09 16:01:39 +04:00
|
|
|
/*
|
2011-02-21 01:33:05 +03:00
|
|
|
* Copyright 2006-2011, Haiku.
|
2007-06-09 16:01:39 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Stephan Aßmus <superstippi@gmx.de>
|
|
|
|
*/
|
2011-02-21 01:33:05 +03:00
|
|
|
#ifndef ICON_BUTTON_H
|
|
|
|
#define ICON_BUTTON_H
|
2007-06-09 16:01:39 +04:00
|
|
|
|
|
|
|
|
2011-02-21 01:33:05 +03:00
|
|
|
//! GUI class that loads an image from disk and shows it as clickable button.
|
2007-06-09 16:01:39 +04:00
|
|
|
|
|
|
|
|
2011-05-21 01:10:15 +04:00
|
|
|
#include <Control.h>
|
2007-06-09 16:01:39 +04:00
|
|
|
#include <String.h>
|
|
|
|
|
2011-02-21 01:33:05 +03:00
|
|
|
|
2007-06-09 16:01:39 +04:00
|
|
|
class BBitmap;
|
|
|
|
class BMimeType;
|
|
|
|
|
2011-02-21 01:33:05 +03:00
|
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
|
|
|
|
|
2011-05-21 01:10:15 +04:00
|
|
|
class BIconButton : public BControl {
|
2008-11-17 01:13:21 +03:00
|
|
|
public:
|
2011-02-21 01:33:05 +03:00
|
|
|
BIconButton(const char* name,
|
2011-05-21 01:10:15 +04:00
|
|
|
const char* label = NULL,
|
|
|
|
BMessage* message = NULL,
|
|
|
|
BHandler* target = NULL);
|
2011-02-21 01:33:05 +03:00
|
|
|
virtual ~BIconButton();
|
2007-06-09 16:01:39 +04:00
|
|
|
|
|
|
|
// BView interface
|
|
|
|
virtual void MessageReceived(BMessage* message);
|
|
|
|
virtual void AttachedToWindow();
|
2011-02-21 01:33:05 +03:00
|
|
|
|
2007-06-09 16:01:39 +04:00
|
|
|
virtual void Draw(BRect updateRect);
|
2011-02-21 01:33:05 +03:00
|
|
|
virtual bool ShouldDrawBorder() const;
|
|
|
|
virtual void DrawBorder(BRect& frame,
|
|
|
|
const BRect& updateRect,
|
|
|
|
const rgb_color& backgroundColor,
|
|
|
|
uint32 controlLookFlags);
|
|
|
|
virtual void DrawBackground(BRect& frame,
|
|
|
|
const BRect& updateRect,
|
|
|
|
const rgb_color& backgroundColor,
|
|
|
|
uint32 controlLookFlags);
|
|
|
|
|
2007-06-09 16:01:39 +04:00
|
|
|
virtual void MouseDown(BPoint where);
|
|
|
|
virtual void MouseUp(BPoint where);
|
|
|
|
virtual void MouseMoved(BPoint where, uint32 transit,
|
|
|
|
const BMessage* message);
|
|
|
|
virtual void GetPreferredSize(float* width,
|
|
|
|
float* height);
|
2008-10-14 22:32:31 +04:00
|
|
|
virtual BSize MinSize();
|
|
|
|
virtual BSize MaxSize();
|
|
|
|
|
2007-06-09 16:01:39 +04:00
|
|
|
|
|
|
|
// BInvoker interface
|
|
|
|
virtual status_t Invoke(BMessage* message = NULL);
|
|
|
|
|
2011-05-21 01:10:15 +04:00
|
|
|
// BControl interface
|
2007-06-09 16:01:39 +04:00
|
|
|
virtual void SetValue(int32 value);
|
2011-05-21 01:10:15 +04:00
|
|
|
virtual void SetEnabled(bool enable);
|
2007-06-09 16:01:39 +04:00
|
|
|
|
2011-05-21 01:10:15 +04:00
|
|
|
// BIconButton
|
|
|
|
bool IsValid() const;
|
2007-06-09 16:01:39 +04:00
|
|
|
|
|
|
|
void SetPressed(bool pressed);
|
|
|
|
bool IsPressed() const;
|
|
|
|
|
2011-02-21 01:33:05 +03:00
|
|
|
status_t SetIcon(int32 resourceID);
|
2007-06-09 16:01:39 +04:00
|
|
|
status_t SetIcon(const char* pathToBitmap);
|
2013-12-22 05:31:47 +04:00
|
|
|
virtual status_t SetIcon(const BBitmap* bitmap,
|
|
|
|
uint32 flags = 0);
|
2007-06-09 16:01:39 +04:00
|
|
|
status_t SetIcon(const BMimeType* fileType,
|
2011-05-21 01:10:15 +04:00
|
|
|
bool small = true);
|
2007-06-09 16:01:39 +04:00
|
|
|
status_t SetIcon(const unsigned char* bitsFromQuickRes,
|
2011-05-21 01:10:15 +04:00
|
|
|
uint32 width, uint32 height,
|
|
|
|
color_space format,
|
|
|
|
bool convertToBW = false);
|
2007-06-09 16:01:39 +04:00
|
|
|
void ClearIcon();
|
2011-02-21 01:33:05 +03:00
|
|
|
void TrimIcon(bool keepAspect = true);
|
2007-06-09 16:01:39 +04:00
|
|
|
|
|
|
|
BBitmap* Bitmap() const;
|
|
|
|
// caller has to delete the returned bitmap
|
|
|
|
|
2008-11-17 01:13:21 +03:00
|
|
|
protected:
|
2011-05-21 01:10:15 +04:00
|
|
|
bool IsInside() const;
|
|
|
|
void SetInside(bool inside);
|
2007-06-09 16:01:39 +04:00
|
|
|
|
2011-02-21 01:33:05 +03:00
|
|
|
private:
|
2007-06-09 16:01:39 +04:00
|
|
|
BBitmap* _ConvertToRGB32(const BBitmap* bitmap) const;
|
|
|
|
status_t _MakeBitmaps(const BBitmap* bitmap);
|
|
|
|
void _DeleteBitmaps();
|
|
|
|
void _SendMessage() const;
|
|
|
|
void _Update();
|
2011-05-21 01:10:15 +04:00
|
|
|
void _SetTracking(bool state);
|
|
|
|
void _SetFlags(uint32 flags, bool set);
|
|
|
|
bool _HasFlags(uint32 flags) const;
|
2007-06-09 16:01:39 +04:00
|
|
|
|
2011-02-21 01:33:05 +03:00
|
|
|
private:
|
2007-06-09 16:01:39 +04:00
|
|
|
uint32 fButtonState;
|
|
|
|
BBitmap* fNormalBitmap;
|
|
|
|
BBitmap* fDisabledBitmap;
|
|
|
|
BBitmap* fClickedBitmap;
|
|
|
|
BBitmap* fDisabledClickedBitmap;
|
|
|
|
|
|
|
|
BHandler* fTargetCache;
|
|
|
|
};
|
|
|
|
|
2011-02-21 01:33:05 +03:00
|
|
|
|
|
|
|
} // namespac BPrivate
|
|
|
|
|
|
|
|
|
|
|
|
using BPrivate::BIconButton;
|
|
|
|
|
|
|
|
|
2007-06-09 16:01:39 +04:00
|
|
|
#endif // ICON_BUTTON_H
|