xref: /haiku/src/apps/resedit/BitmapView.h (revision 09a03cb8270174f8b983db85c0f7c91821239cd8)
1 #ifndef BMPVIEW_H
2 #define BMPVIEW_H
3 
4 #include <Bitmap.h>
5 #include <Message.h>
6 #include <Invoker.h>
7 #include <PopUpMenu.h>
8 #include <String.h>
9 #include <View.h>
10 
11 enum
12 {
13 	M_BITMAP_ADDED = 'mbma',
14 	M_BITMAP_REMOVED = 'mbmr'
15 };
16 
17 class BitmapView : public BView, public BInvoker
18 {
19 public:
20 	BitmapView(BRect frame, const char *name, BMessage *mod, BBitmap *bitmap,
21 				const char *label = NULL, border_style = B_PLAIN_BORDER,
22 				int32 resize = B_FOLLOW_LEFT | B_FOLLOW_TOP, int32 flags = B_WILL_DRAW);
23 	~BitmapView(void);
24 	virtual void AttachedToWindow(void);
25 
26 	virtual void Draw(BRect rect);
27 	virtual void MessageReceived(BMessage *msg);
28 	virtual void MouseDown(BPoint pt);
29 	virtual void FrameResized(float w, float h);
30 
31 	virtual void SetBitmap(BBitmap *bitmap);
GetBitmap(void)32 	BBitmap *GetBitmap(void) const { return fBitmap; }
33 
IsEnabled(void)34 	bool IsEnabled(void) const { return fEnabled; }
35 	virtual void SetEnabled(bool value);
36 
37 //	const char *Label(void) const { return fLabel.String(); }
38 //	virtual void SetLabel(const char *label);
39 
Style(void)40 	border_style Style(void) const { return fBorderStyle; }
41 	virtual void SetStyle(border_style style);
42 
IsFixedSize(void)43 	bool IsFixedSize(void) const { return fFixedSize; }
44 	void SetFixedSize(bool isfixed);
45 
AcceptsDrops(void)46 	bool AcceptsDrops(void) const { return fAcceptDrops; }
47 	virtual void SetAcceptDrops(bool accept);
48 
AcceptsPaste(void)49 	bool AcceptsPaste(void) const { return fAcceptPaste; }
50 	virtual void SetAcceptPaste(bool accept);
51 
ConstrainsDrops(void)52 	bool ConstrainsDrops(void) const { return fConstrainDrops; }
53 	virtual void SetConstrainDrops(bool value);
54 
55 	void MaxBitmapSize(float *width, float *height) const;
56 	virtual void SetMaxBitmapSize(const float &width, const float &height);
57 
IsBitmapRemovable(void)58 	bool IsBitmapRemovable(void) const { return fRemovableBitmap; }
59 	void SetBitmapRemovable(bool isremovable);
60 
61 	void RemoveBitmap(void);
62 	void PasteBitmap(void);
63 
64 private:
65 	void CalculateBitmapRect(void);
66 	void ConstrainBitmap(void);
67 
68 	bool ClipboardHasBitmap(void);
69 	BBitmap *BitmapFromClipboard(void);
70 
71 	float fNoPhotoWidths[4];
72 	BPoint fNoPhotoOffsets[4];
73 
74 	BBitmap *fBitmap;
75 	BRect fBitmapRect;
76 	bool fEnabled;
77 	BString fLabel;
78 	border_style fBorderStyle;
79 	bool fFixedSize;
80 	bool fAcceptDrops;
81 	bool fAcceptPaste;
82 	bool fConstrainDrops;
83 	float fMaxWidth, fMaxHeight;
84 	bool fRemovableBitmap;
85 	BPopUpMenu *fPopUpMenu;
86 	uint32 fMouseButtons;
87 	BMenuItem *fPasteItem;
88 	BMenuItem *fRemoveItem;
89 };
90 
91 BRect ScaleRectToFit(const BRect &from, const BRect &to);
92 
93 #endif
94