vfs: check userland buffers before reading them.
[haiku.git] / src / apps / icon-o-matic / CanvasView.h
blob57dfa94dbf106bf8614f7038a05414187ecd046b
1 /*
2 * Copyright 2006-2007, 2011, Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5 #ifndef CANVAS_VIEW_H
6 #define CANVAS_VIEW_H
9 #include "Icon.h"
10 #include "Scrollable.h"
11 #include "StateView.h"
14 class BBitmap;
16 _BEGIN_ICON_NAMESPACE
17 class IconRenderer;
18 _END_ICON_NAMESPACE
20 _USING_ICON_NAMESPACE
23 enum {
24 SNAPPING_OFF = 0,
25 SNAPPING_64,
26 SNAPPING_32,
27 SNAPPING_16,
31 class CanvasView : public StateView, public Scrollable, public IconListener {
32 public:
33 CanvasView(BRect frame);
34 virtual ~CanvasView();
36 // StateView interface
37 virtual void AttachedToWindow();
38 virtual void FrameResized(float width, float height);
39 virtual void Draw(BRect updateRect);
41 virtual void MouseDown(BPoint where);
42 virtual void MouseUp(BPoint where);
43 virtual void MouseMoved(BPoint where, uint32 transit,
44 const BMessage* dragMessage);
45 virtual void FilterMouse(BPoint* where) const;
47 virtual bool MouseWheelChanged(BPoint where,
48 float x, float y);
50 // Scrollable interface
51 protected:
52 virtual void SetScrollOffset(BPoint newOffset);
53 virtual void ScrollOffsetChanged(BPoint oldOffset,
54 BPoint newOffset);
55 virtual void VisibleSizeChanged(float oldWidth,
56 float oldHeight, float newWidth,
57 float newHeight);
58 // IconListener interface
59 public:
60 virtual void AreaInvalidated(const BRect& area);
62 // CanvasView
63 void SetIcon(Icon* icon);
65 inline float ZoomLevel() const
66 { return fZoomLevel; }
68 void SetMouseFilterMode(uint32 mode);
69 uint32 MouseFilterMode() const
70 { return fMouseFilterMode; }
72 void ConvertFromCanvas(BPoint* point) const;
73 void ConvertToCanvas(BPoint* point) const;
75 void ConvertFromCanvas(BRect* rect) const;
76 void ConvertToCanvas(BRect* rect) const;
78 protected:
79 // StateView interface
80 virtual bool _HandleKeyDown(uint32 key, uint32 modifiers);
81 virtual bool _HandleKeyUp(uint32 key, uint32 modifiers);
83 // CanvasView
84 BRect _CanvasRect() const;
86 void _AllocBackBitmap(float width,
87 float height);
88 void _FreeBackBitmap();
89 void _DrawInto(BView* view,
90 BRect updateRect);
92 void _MakeBackground();
94 void _UpdateToolCursor();
96 private:
97 double _NextZoomInLevel(double zoom) const;
98 double _NextZoomOutLevel(double zoom) const;
99 void _SetZoom(double zoomLevel,
100 bool mouseIsAnchor = true);
101 BRect _LayoutCanvas();
103 private:
104 BBitmap* fBitmap;
105 BBitmap* fBackground;
107 Icon* fIcon;
108 IconRenderer* fRenderer;
109 BRect fDirtyIconArea;
111 BPoint fCanvasOrigin;
112 double fZoomLevel;
114 bool fSpaceHeldDown;
115 bool fInScrollTo;
116 bool fScrollTracking;
117 BPoint fScrollTrackingStart;
118 BPoint fScrollOffsetStart;
120 uint32 fMouseFilterMode;
123 #endif // CANVAS_VIEW_H