vfs: check userland buffers before reading them.
[haiku.git] / headers / private / shared / IconButton.h
blob29f75355bf1ec351d470b91a35fef6f0f1099df6
1 /*
2 * Copyright 2006-2011, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
8 #ifndef ICON_BUTTON_H
9 #define ICON_BUTTON_H
12 //! GUI class that loads an image from disk and shows it as clickable button.
15 #include <Control.h>
16 #include <String.h>
19 class BBitmap;
20 class BMimeType;
23 namespace BPrivate {
26 class BIconButton : public BControl {
27 public:
28 BIconButton(const char* name,
29 const char* label = NULL,
30 BMessage* message = NULL,
31 BHandler* target = NULL);
32 virtual ~BIconButton();
34 // BView interface
35 virtual void MessageReceived(BMessage* message);
36 virtual void AttachedToWindow();
38 virtual void Draw(BRect updateRect);
39 virtual bool ShouldDrawBorder() const;
40 virtual void DrawBorder(BRect& frame,
41 const BRect& updateRect,
42 const rgb_color& backgroundColor,
43 uint32 controlLookFlags);
44 virtual void DrawBackground(BRect& frame,
45 const BRect& updateRect,
46 const rgb_color& backgroundColor,
47 uint32 controlLookFlags);
49 virtual void MouseDown(BPoint where);
50 virtual void MouseUp(BPoint where);
51 virtual void MouseMoved(BPoint where, uint32 transit,
52 const BMessage* message);
53 virtual void GetPreferredSize(float* width,
54 float* height);
55 virtual BSize MinSize();
56 virtual BSize MaxSize();
59 // BInvoker interface
60 virtual status_t Invoke(BMessage* message = NULL);
62 // BControl interface
63 virtual void SetValue(int32 value);
64 virtual void SetEnabled(bool enable);
66 // BIconButton
67 bool IsValid() const;
69 void SetPressed(bool pressed);
70 bool IsPressed() const;
72 status_t SetIcon(int32 resourceID);
73 status_t SetIcon(const char* pathToBitmap);
74 virtual status_t SetIcon(const BBitmap* bitmap,
75 uint32 flags = 0);
76 status_t SetIcon(const BMimeType* fileType,
77 bool small = true);
78 status_t SetIcon(const unsigned char* bitsFromQuickRes,
79 uint32 width, uint32 height,
80 color_space format,
81 bool convertToBW = false);
82 void ClearIcon();
83 void TrimIcon(bool keepAspect = true);
85 BBitmap* Bitmap() const;
86 // caller has to delete the returned bitmap
88 protected:
89 bool IsInside() const;
90 void SetInside(bool inside);
92 private:
93 BBitmap* _ConvertToRGB32(const BBitmap* bitmap) const;
94 status_t _MakeBitmaps(const BBitmap* bitmap);
95 void _DeleteBitmaps();
96 void _SendMessage() const;
97 void _Update();
98 void _SetTracking(bool state);
99 void _SetFlags(uint32 flags, bool set);
100 bool _HasFlags(uint32 flags) const;
102 private:
103 uint32 fButtonState;
104 BBitmap* fNormalBitmap;
105 BBitmap* fDisabledBitmap;
106 BBitmap* fClickedBitmap;
107 BBitmap* fDisabledClickedBitmap;
109 BHandler* fTargetCache;
113 } // namespac BPrivate
116 using BPrivate::BIconButton;
119 #endif // ICON_BUTTON_H