1 /* 2 * Copyright 2003-2011, Haiku, Inc. All Rights Reserved. 3 * Copyright 2004-2005 yellowTAB GmbH. All Rights Reserverd. 4 * Copyright 2006 Bernd Korz. All Rights Reserved 5 * Distributed under the terms of the MIT License. 6 * 7 * Authors: 8 * Fernando Francisco de Oliveira 9 * Michael Wilber 10 * Michael Pfeiffer 11 * yellowTAB GmbH 12 * Bernd Korz 13 */ 14 #ifndef SHOW_IMAGE_VIEW_H 15 #define SHOW_IMAGE_VIEW_H 16 17 18 #include <Bitmap.h> 19 #include <Entry.h> 20 #include <NodeInfo.h> 21 #include <String.h> 22 #include <TranslatorRoster.h> 23 #include <View.h> 24 25 #include "Filter.h" 26 #include "SelectionBox.h" 27 #include "ShowImageUndo.h" 28 29 30 class BitmapOwner; 31 32 33 class ShowImageView : public BView { 34 public: 35 ShowImageView(BRect rect, const char* name, 36 uint32 resizingMode, uint32 flags); 37 virtual ~ShowImageView(); 38 39 virtual void AttachedToWindow(); 40 virtual void FrameResized(float width, float height); 41 virtual void Draw(BRect updateRect); 42 virtual void MouseDown(BPoint point); 43 virtual void MouseMoved(BPoint point, uint32 state, 44 const BMessage* dragMessage); 45 virtual void MouseUp(BPoint point); 46 virtual void KeyDown(const char* bytes, int32 numBytes); 47 virtual void Pulse(); 48 49 virtual void MessageReceived(BMessage* message); 50 virtual void WindowActivated(bool active); 51 52 void SetTrackerMessenger( 53 const BMessenger& trackerMessenger); 54 status_t SetImage(const BMessage* message); 55 status_t SetImage(const entry_ref* ref, BBitmap* bitmap); 56 const entry_ref* Image() const { return &fCurrentRef; } 57 BBitmap* Bitmap(); 58 59 BPoint ImageToView(BPoint p) const; 60 BPoint ViewToImage(BPoint p) const; 61 BRect ImageToView(BRect r) const; 62 void ConstrainToImage(BPoint& point) const; 63 void ConstrainToImage(BRect& rect) const; 64 65 void SaveToFile(BDirectory* dir, const char* name, 66 BBitmap* bitmap, 67 const translation_format* format); 68 69 void SetScaleBilinear(bool b); 70 bool ScaleBilinear() { return fScaleBilinear; } 71 void SetShowCaption(bool show); 72 void SetStretchToBounds(bool enable); 73 bool StretchesToBounds() const 74 { return fStretchToBounds; } 75 void SetHideIdlingCursor(bool hide); 76 77 void FixupScrollBar(enum orientation orientation, 78 float bitmapLength, float viewLength); 79 void FixupScrollBars(); 80 81 void SetSelectionMode(bool selectionMode); 82 bool IsSelectionModeEnabled() const 83 { return fSelectionMode; } 84 void Undo(); 85 void SelectAll(); 86 void ClearSelection(); 87 88 void CopySelectionToClipboard(); 89 90 void FitToBounds(); 91 void SetZoom(float zoom, 92 BPoint where = BPoint(-1, -1)); 93 float Zoom() const 94 { return fZoom; } 95 void ZoomIn(BPoint where = BPoint(-1, -1)); 96 void ZoomOut(BPoint where = BPoint(-1, -1)); 97 98 // Image manipulation 99 void Rotate(int degree); // 90 and 270 only 100 void Flip(bool vertical); 101 void ResizeImage(int width, int height); 102 103 void SetIcon(bool clear); 104 105 private: 106 enum image_orientation { 107 k0, // 0 108 k90, // 1 109 k180, // 2 110 k270, // 3 111 k0V, // 4 112 k90V, // 5 113 k0H, // 6 114 k270V, // 7 115 kNumberOfOrientations, 116 }; 117 118 void _SetHasSelection(bool bHasSelection); 119 void _AnimateSelection(bool a); 120 void _SendMessageToWindow(BMessage* message); 121 void _SendMessageToWindow(uint32 code); 122 void _Notify(); 123 void _UpdateStatusText(); 124 void _GetMergeRects(BBitmap* merge, 125 BRect selection, BRect& srcRect, 126 BRect& dstRect); 127 void _GetSelectionMergeRects(BRect& srcRect, 128 BRect& dstRect); 129 status_t _SetSelection(const entry_ref* ref, 130 BPoint point); 131 void _MergeWithBitmap(BBitmap* merge, 132 BRect selection); 133 void _MergeSelection(); 134 void _DeleteScaler(); 135 void _DeleteBitmap(); 136 void _DeleteSelectionBitmap(); 137 138 void _DoImageOperation( 139 enum ImageProcessor::operation op, 140 bool quiet = false); 141 void _UserDoImageOperation( 142 enum ImageProcessor::operation op, 143 bool quiet = false); 144 bool _ShouldStretch() const; 145 float _FitToBoundsZoom() const; 146 BRect _AlignBitmap(); 147 BBitmap* _CopySelection(uchar alpha = 255, 148 bool imageSize = true); 149 bool _AddSupportedTypes(BMessage* message, 150 BBitmap* bitmap); 151 void _BeginDrag(BPoint sourcePoint); 152 void _SendInMessage(BMessage* message, 153 BBitmap* bitmap, 154 translation_format* format); 155 bool _OutputFormatForType(BBitmap* bitmap, 156 const char* type, 157 translation_format* format); 158 void _HandleDrop(BMessage* message); 159 void _ScrollBitmap(BPoint point); 160 void _UpdateSelectionRect(BPoint point, bool final); 161 void _DrawBackground(BRect aroundFrame); 162 void _LayoutCaption(BFont& font, BPoint& textPos, 163 BRect& background); 164 void _DrawCaption(); 165 void _UpdateCaption(); 166 167 void _DrawImage(BRect rect); 168 float _LimitToRange(float v, orientation o, 169 bool absolute); 170 void _ScrollRestricted(float x, float y, 171 bool absolute); 172 void _ScrollRestrictedTo(float x, float y); 173 void _ScrollRestrictedBy(float x, float y); 174 void _MouseWheelChanged(BMessage* message); 175 void _ShowPopUpMenu(BPoint screen); 176 void _SettingsSetBool(const char* name, bool value); 177 void _SetIcon(bool clear, icon_size which); 178 void _ToggleSlideShow(); 179 void _StopSlideShow(); 180 void _ExitFullScreen(); 181 void _ShowToolBarIfEnabled(bool show); 182 183 private: 184 ShowImageUndo fUndo; 185 entry_ref fCurrentRef; 186 187 BitmapOwner* fBitmapOwner; 188 BBitmap* fBitmap; 189 BBitmap* fDisplayBitmap; 190 BBitmap* fSelectionBitmap; 191 192 float fZoom; 193 194 bool fScaleBilinear; 195 196 BPoint fBitmapLocationInView; 197 198 bool fStretchToBounds; 199 bool fHideCursor; 200 bool fScrollingBitmap; 201 bool fCreatingSelection; 202 BPoint fFirstPoint; 203 // first point in image space of selection 204 bool fSelectionMode; 205 bool fAnimateSelection; 206 bool fHasSelection; 207 SelectionBox fSelectionBox; 208 BRect fCopyFromRect; 209 // the portion of the background bitmap the selection is made 210 // from 211 212 bool fShowCaption; 213 BString fCaption; 214 215 BString fFormatDescription; 216 BString fMimeType; 217 218 bool fShowingPopUpMenu; 219 220 int fHideCursorCountDown; 221 // Hides the cursor when it reaches zero 222 int fStickyZoomCountDown; 223 // Make the zoom sticky at 1.0 when zoomed with the mousewheel 224 225 bool fIsActiveWin; 226 // Is the parent window the active window? 227 228 BCursor* fDefaultCursor; 229 BCursor* fGrabCursor; 230 231 image_orientation fImageOrientation; 232 static image_orientation fTransformation[ 233 ImageProcessor 234 ::kNumberOfAffineTransformations] 235 [kNumberOfOrientations]; 236 }; 237 238 #endif // SHOW_IMAGE_VIEW_H 239