RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / preferences / filetypes / IconView.h
blobd7f3762e9cafb770f861bd4b8e49ab267b2616ff
1 /*
2 * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef ICON_VIEW_H
6 #define ICON_VIEW_H
9 #include <Control.h>
10 #include <Entry.h>
11 #include <Messenger.h>
12 #include <Mime.h>
13 #include <String.h>
16 enum icon_source {
17 kNoIcon = 0,
18 kOwnIcon,
19 kApplicationIcon,
20 kSupertypeIcon
24 class Icon {
25 public:
26 Icon();
27 Icon(const Icon& source);
28 ~Icon();
30 void SetTo(const BAppFileInfo& info,
31 const char* type = NULL);
32 void SetTo(const entry_ref& ref,
33 const char* type = NULL);
34 void SetTo(const BMimeType& type,
35 icon_source* _source = NULL);
36 status_t CopyTo(BAppFileInfo& info,
37 const char* type = NULL,
38 bool force = false) const;
39 status_t CopyTo(const entry_ref& ref,
40 const char* type = NULL,
41 bool force = false) const;
42 status_t CopyTo(BMimeType& type,
43 bool force = false) const;
44 status_t CopyTo(BMessage& message) const;
46 void SetData(const uint8* data, size_t size);
47 void SetLarge(const BBitmap* large);
48 void SetMini(const BBitmap* large);
49 void Unset();
51 bool HasData() const;
52 status_t GetData(icon_size which,
53 BBitmap** _bitmap) const;
54 status_t GetData(uint8** _data, size_t* _size) const;
56 status_t GetIcon(BBitmap* bitmap) const;
58 Icon& operator=(const Icon& source);
60 void AdoptLarge(BBitmap* large);
61 void AdoptMini(BBitmap* mini);
62 void AdoptData(uint8* data, size_t size);
64 static BBitmap* AllocateBitmap(int32 size, int32 space = -1);
66 private:
67 BBitmap* fLarge;
68 BBitmap* fMini;
69 uint8* fData;
70 size_t fSize;
74 class BSize;
77 class IconView : public BControl {
78 public:
79 IconView(const char* name,
80 uint32 flags = B_NAVIGABLE);
81 virtual ~IconView();
83 virtual void AttachedToWindow();
84 virtual void DetachedFromWindow();
85 virtual void MessageReceived(BMessage* message);
86 virtual void Draw(BRect updateRect);
87 virtual void GetPreferredSize(float* _width, float* _height);
89 virtual BSize MaxSize();
90 virtual BSize MinSize();
91 virtual BSize PreferredSize();
93 virtual void MouseDown(BPoint where);
94 virtual void MouseUp(BPoint where);
95 virtual void MouseMoved(BPoint where, uint32 transit,
96 const BMessage* dragMessage);
97 virtual void KeyDown(const char* bytes, int32 numBytes);
99 virtual void MakeFocus(bool focus = true);
101 void SetTo(const entry_ref& file,
102 const char* fileType = NULL);
103 void SetTo(const BMimeType& type);
104 void SetTo(::Icon* icon);
105 void Unset();
106 void Update();
108 void SetIconSize(int32 size);
109 void ShowIconHeap(bool show);
110 void ShowEmptyFrame(bool show);
111 status_t SetTarget(const BMessenger& target);
112 void SetModificationMessage(BMessage* message);
113 status_t Invoke(BMessage* message = NULL);
115 ::Icon* Icon();
116 int32 IconSize() const { return fIconSize; }
117 icon_source IconSource() const { return fSource; }
118 status_t GetRef(entry_ref& ref) const;
119 status_t GetMimeType(BMimeType& type) const;
121 #if __GNUC__ == 2
122 virtual status_t SetTarget(BMessenger target);
123 virtual status_t SetTarget(const BHandler* handler,
124 const BLooper* looper = NULL);
125 #else
126 using BControl::SetTarget;
127 #endif
130 protected:
131 virtual bool AcceptsDrag(const BMessage* message);
132 virtual BRect BitmapRect() const;
134 private:
135 void _AddOrEditIcon();
136 void _SetIcon(BBitmap* large, BBitmap* mini,
137 const uint8* data, size_t size,
138 bool force = false);
139 void _SetIcon(entry_ref* ref);
140 void _RemoveIcon();
141 void _DeleteIcons();
142 void _StartWatching();
143 void _StopWatching();
145 BMessenger fTarget;
146 BMessage* fModificationMessage;
147 int32 fIconSize;
148 BBitmap* fIcon;
149 BBitmap* fHeapIcon;
151 bool fHasRef;
152 bool fHasType;
153 entry_ref fRef;
154 BMimeType fType;
155 icon_source fSource;
156 ::Icon* fIconData;
158 BPoint fDragPoint;
159 bool fTracking;
160 bool fDragging;
161 bool fDropTarget;
162 bool fShowEmptyFrame;
166 static const uint32 kMsgIconInvoked = 'iciv';
167 static const uint32 kMsgRemoveIcon = 'icrm';
168 static const uint32 kMsgAddIcon = 'icad';
169 static const uint32 kMsgEditIcon = 'iced';
172 extern status_t icon_for_type(const BMimeType& type, uint8** _data,
173 size_t* _size, icon_source* _source = NULL);
174 extern status_t icon_for_type(const BMimeType& type, BBitmap& bitmap,
175 icon_size size, icon_source* _source = NULL);
178 #endif // ICON_VIEW_H