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(const char* name, uint32 flags); 35 virtual ~ShowImageView(); 36 37 virtual void AttachedToWindow(); 38 virtual void FrameResized(float width, float height); 39 virtual void Draw(BRect updateRect); 40 virtual void MouseDown(BPoint point); 41 virtual void MouseMoved(BPoint point, uint32 state, 42 const BMessage* dragMessage); 43 virtual void MouseUp(BPoint point); 44 virtual void KeyDown(const char* bytes, int32 numBytes); 45 virtual void Pulse(); 46 47 virtual void MessageReceived(BMessage* message); 48 virtual void WindowActivated(bool active); 49 50 void SetTrackerMessenger( 51 const BMessenger& trackerMessenger); 52 status_t SetImage(const BMessage* message); 53 status_t SetImage(const entry_ref* ref, BBitmap* bitmap, 54 BitmapOwner* bitmapOwner); Image()55 const entry_ref* Image() const { return &fCurrentRef; } 56 BBitmap* Bitmap(); 57 58 BPoint ImageToView(BPoint p) const; 59 BPoint ViewToImage(BPoint p) const; 60 BRect ImageToView(BRect r) const; 61 void ConstrainToImage(BPoint& point) const; 62 void ConstrainToImage(BRect& rect) const; 63 64 void SaveToFile(BDirectory* dir, const char* name, 65 BBitmap* bitmap, 66 const translation_format* format); 67 68 void SetScaleBilinear(bool b); ScaleBilinear()69 bool ScaleBilinear() { return fScaleBilinear; } 70 void SetShowCaption(bool show); 71 void SetStretchToBounds(bool enable); StretchesToBounds()72 bool StretchesToBounds() const 73 { return fStretchToBounds; } 74 void SetHideIdlingCursor(bool hide); 75 76 void FixupScrollBar(enum orientation orientation, 77 float bitmapLength, float viewLength); 78 void FixupScrollBars(); 79 80 void SetSelectionMode(bool selectionMode); IsSelectionModeEnabled()81 bool IsSelectionModeEnabled() const 82 { return fSelectionMode; } 83 void SelectAll(); 84 void ClearSelection(); 85 86 void CopySelectionToClipboard(); 87 88 void FitToBounds(); ForceOriginalSize(bool force)89 void ForceOriginalSize(bool force) 90 { fForceOriginalSize = force; } 91 void SetZoom(float zoom, 92 BPoint where = BPoint(-1, -1)); Zoom()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 entry_ref fCurrentRef; 185 186 BitmapOwner* fBitmapOwner; 187 BBitmap* fBitmap; 188 BBitmap* fDisplayBitmap; 189 BBitmap* fSelectionBitmap; 190 191 float fZoom; 192 193 bool fScaleBilinear; 194 195 BPoint fBitmapLocationInView; 196 197 bool fStretchToBounds; 198 bool fForceOriginalSize; 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