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 28 29 class BitmapOwner; 30 31 32 class ShowImageView : public BView { 33 public: 34 ShowImageView(BRect rect, const char* name, 35 uint32 resizingMode, uint32 flags); 36 virtual ~ShowImageView(); 37 38 virtual void AttachedToWindow(); 39 virtual void FrameResized(float width, float height); 40 virtual void Draw(BRect updateRect); 41 virtual void MouseDown(BPoint point); 42 virtual void MouseMoved(BPoint point, uint32 state, 43 const BMessage* dragMessage); 44 virtual void MouseUp(BPoint point); 45 virtual void KeyDown(const char* bytes, int32 numBytes); 46 virtual void Pulse(); 47 48 virtual void MessageReceived(BMessage* message); 49 virtual void WindowActivated(bool active); 50 51 void SetTrackerMessenger( 52 const BMessenger& trackerMessenger); 53 status_t SetImage(const BMessage* message); 54 status_t SetImage(const entry_ref* ref, BBitmap* bitmap, 55 BitmapOwner* bitmapOwner); 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 SelectAll(); 85 void ClearSelection(); 86 87 void CopySelectionToClipboard(); 88 89 void FitToBounds(); 90 void ForceOriginalSize(bool force) 91 { fForceOriginalSize = force; } 92 void SetZoom(float zoom, 93 BPoint where = BPoint(-1, -1)); 94 float Zoom() const 95 { return fZoom; } 96 void ZoomIn(BPoint where = BPoint(-1, -1)); 97 void ZoomOut(BPoint where = BPoint(-1, -1)); 98 99 // Image manipulation 100 void Rotate(int degree); // 90 and 270 only 101 void Flip(bool vertical); 102 void ResizeImage(int width, int height); 103 104 void SetIcon(bool clear); 105 106 private: 107 enum image_orientation { 108 k0, // 0 109 k90, // 1 110 k180, // 2 111 k270, // 3 112 k0V, // 4 113 k90V, // 5 114 k0H, // 6 115 k270V, // 7 116 kNumberOfOrientations, 117 }; 118 119 void _SetHasSelection(bool bHasSelection); 120 void _AnimateSelection(bool a); 121 void _SendMessageToWindow(BMessage* message); 122 void _SendMessageToWindow(uint32 code); 123 void _Notify(); 124 void _UpdateStatusText(); 125 void _GetMergeRects(BBitmap* merge, 126 BRect selection, BRect& srcRect, 127 BRect& dstRect); 128 void _GetSelectionMergeRects(BRect& srcRect, 129 BRect& dstRect); 130 status_t _SetSelection(const entry_ref* ref, 131 BPoint point); 132 void _MergeWithBitmap(BBitmap* merge, 133 BRect selection); 134 void _MergeSelection(); 135 void _DeleteScaler(); 136 void _DeleteBitmap(); 137 void _DeleteSelectionBitmap(); 138 139 void _DoImageOperation( 140 enum ImageProcessor::operation op, 141 bool quiet = false); 142 void _UserDoImageOperation( 143 enum ImageProcessor::operation op, 144 bool quiet = false); 145 bool _ShouldStretch() const; 146 float _FitToBoundsZoom() const; 147 BRect _AlignBitmap(); 148 BBitmap* _CopySelection(uchar alpha = 255, 149 bool imageSize = true); 150 bool _AddSupportedTypes(BMessage* message, 151 BBitmap* bitmap); 152 void _BeginDrag(BPoint sourcePoint); 153 void _SendInMessage(BMessage* message, 154 BBitmap* bitmap, 155 translation_format* format); 156 bool _OutputFormatForType(BBitmap* bitmap, 157 const char* type, 158 translation_format* format); 159 void _HandleDrop(BMessage* message); 160 void _ScrollBitmap(BPoint point); 161 void _UpdateSelectionRect(BPoint point, bool final); 162 void _DrawBackground(BRect aroundFrame); 163 void _LayoutCaption(BFont& font, BPoint& textPos, 164 BRect& background); 165 void _DrawCaption(); 166 void _UpdateCaption(); 167 168 void _DrawImage(BRect rect); 169 float _LimitToRange(float v, orientation o, 170 bool absolute); 171 void _ScrollRestricted(float x, float y, 172 bool absolute); 173 void _ScrollRestrictedTo(float x, float y); 174 void _ScrollRestrictedBy(float x, float y); 175 void _MouseWheelChanged(BMessage* message); 176 void _ShowPopUpMenu(BPoint screen); 177 void _SettingsSetBool(const char* name, bool value); 178 void _SetIcon(bool clear, icon_size which); 179 void _ToggleSlideShow(); 180 void _StopSlideShow(); 181 void _ExitFullScreen(); 182 void _ShowToolBarIfEnabled(bool show); 183 184 private: 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 fForceOriginalSize; 200 bool fHideCursor; 201 bool fScrollingBitmap; 202 bool fCreatingSelection; 203 BPoint fFirstPoint; 204 // first point in image space of selection 205 bool fSelectionMode; 206 bool fAnimateSelection; 207 bool fHasSelection; 208 SelectionBox fSelectionBox; 209 BRect fCopyFromRect; 210 // the portion of the background bitmap the selection is made 211 // from 212 213 bool fShowCaption; 214 BString fCaption; 215 216 BString fFormatDescription; 217 BString fMimeType; 218 219 bool fShowingPopUpMenu; 220 221 int fHideCursorCountDown; 222 // Hides the cursor when it reaches zero 223 int fStickyZoomCountDown; 224 // Make the zoom sticky at 1.0 when zoomed with the mousewheel 225 226 bool fIsActiveWin; 227 // Is the parent window the active window? 228 229 BCursor* fDefaultCursor; 230 BCursor* fGrabCursor; 231 232 image_orientation fImageOrientation; 233 static image_orientation fTransformation[ 234 ImageProcessor 235 ::kNumberOfAffineTransformations] 236 [kNumberOfOrientations]; 237 }; 238 239 #endif // SHOW_IMAGE_VIEW_H 240