1 /********************************************************************************
2 *                                                                               *
3 *                       I m a g e   V i e w   W i d g e t                       *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 2000,2020 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify          *
9 * it under the terms of the GNU Lesser General Public License as published by   *
10 * the Free Software Foundation; either version 3 of the License, or             *
11 * (at your option) any later version.                                           *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
16 * GNU Lesser General Public License for more details.                           *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public License      *
19 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
20 ********************************************************************************/
21 #ifndef FXIMAGEVIEW_H
22 #define FXIMAGEVIEW_H
23 
24 #ifndef FXSCROLLAREA_H
25 #include "FXScrollArea.h"
26 #endif
27 
28 namespace FX {
29 
30 
31 class FXImage;
32 
33 
34 /// Image alignment styles
35 enum {
36   IMAGEVIEW_NORMAL    = 0,              /// Normal mode is centered
37   IMAGEVIEW_CENTER_X  = 0,              /// Centered horizontally
38   IMAGEVIEW_LEFT      = 0x00100000,     /// Left-aligned
39   IMAGEVIEW_RIGHT     = 0x00200000,     /// Right-aligned
40   IMAGEVIEW_CENTER_Y  = 0,              /// Centered vertically
41   IMAGEVIEW_TOP       = 0x00400000,     /// Top-aligned
42   IMAGEVIEW_BOTTOM    = 0x00800000      /// Bottom-aligned
43   };
44 
45 
46 /**
47 * The Image View widget display a scrollable view of an image.
48 */
49 class FXAPI FXImageView : public FXScrollArea {
50   FXDECLARE(FXImageView)
51 protected:
52   FXImage *image;         // Image to view
53   FXint    grabx;         // Grab point x
54   FXint    graby;         // Grab point y
55 protected:
56   FXImageView();
57 private:
58   FXImageView(const FXImageView&);
59   FXImageView &operator=(const FXImageView&);
60 public:
61   long onPaint(FXObject*,FXSelector,void*);
62   long onMotion(FXObject*,FXSelector,void*);
63   long onRightBtnPress(FXObject*,FXSelector,void*);
64   long onRightBtnRelease(FXObject*,FXSelector,void*);
65 public:
66   enum {
67     ID_XYZ=FXScrollArea::ID_LAST,
68     ID_LAST
69     };
70 public:
71 
72   /// Construct a scroll window
73   FXImageView(FXComposite* p,FXImage* img=NULL,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
74 
75   /// Create server-side resources
76   virtual void create();
77 
78   /// Detach server-side resources
79   virtual void detach();
80 
81   /// Perform layout
82   virtual void layout();
83 
84   /// Image view widget can receive focus
85   virtual FXbool canFocus() const;
86 
87   /// Return the width of the contents
88   virtual FXint getContentWidth();
89 
90   /// Return the height of the contents
91   virtual FXint getContentHeight();
92 
93   /// Change image
94   void setImage(FXImage* img);
95 
96   /// Return image
getImage()97   FXImage* getImage() const { return image; }
98 
99   /// Set the current alignment.
100   void setAlignment(FXuint mode);
101 
102   /// Get the current alignment.
103   FXuint getAlignment() const;
104 
105   /// Save list to a stream
106   virtual void save(FXStream& store) const;
107 
108   /// Load list from a stream
109   virtual void load(FXStream& store);
110 
111   /// Destroy
112   virtual ~FXImageView();
113   };
114 
115 }
116 
117 #endif
118