1 /* Copyright 2006, 2007, 2008, Soren Sandmann <sandmann@daimi.au.dk>
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the
15  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
16  * Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef __SCROLLAREA_H__
20 #define __SCROLLAREA_H__
21 
22 #include <cairo.h>
23 #include <gtk/gtk.h>
24 
25 #define FOO_TYPE_SCROLL_AREA            (foo_scroll_area_get_type ())
26 #define FOO_SCROLL_AREA(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOO_TYPE_SCROLL_AREA, FooScrollArea))
27 #define FOO_SCROLL_AREA_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  FOO_TYPE_SCROLL_AREA, FooScrollAreaClass))
28 #define FOO_IS_SCROLL_AREA(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOO_TYPE_SCROLL_AREA))
29 #define FOO_IS_SCROLL_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  FOO_TYPE_SCROLL_AREA))
30 #define FOO_SCROLL_AREA_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  FOO_TYPE_SCROLL_AREA, FooScrollAreaClass))
31 
32 typedef struct FooScrollArea FooScrollArea;
33 typedef struct FooScrollAreaClass FooScrollAreaClass;
34 typedef struct FooScrollAreaPrivate FooScrollAreaPrivate;
35 typedef struct FooScrollAreaEvent FooScrollAreaEvent;
36 
37 typedef enum
38 {
39     FOO_BUTTON_PRESS,
40     FOO_BUTTON_RELEASE,
41     FOO_MOTION
42 } FooScrollAreaEventType;
43 
44 struct FooScrollAreaEvent
45 {
46     FooScrollAreaEventType	type;
47     int				x;
48     int				y;
49 };
50 
51 typedef void (* FooScrollAreaEventFunc) (FooScrollArea      *area,
52 					 FooScrollAreaEvent *event,
53 					 gpointer            data);
54 
55 struct FooScrollArea
56 {
57     GtkContainer parent_instance;
58 
59     FooScrollAreaPrivate *priv;
60 };
61 
62 struct FooScrollAreaClass
63 {
64     GtkContainerClass parent_class;
65 
66     void (*set_scroll_adjustments) (FooScrollArea *scroll_area,
67 				    GtkAdjustment *hadjustment,
68 				    GtkAdjustment *vadjustment);
69 
70     void (*viewport_changed) (FooScrollArea *scroll_area,
71 			      GdkRectangle  *old_viewport,
72 			      GdkRectangle  *new_viewport);
73 
74     void (*paint) (FooScrollArea *scroll_area,
75 		   cairo_t       *cr,
76 		   GdkRectangle  *extents,
77 		   cairo_region_t *region);
78 };
79 
80 GType foo_scroll_area_get_type (void);
81 
82 FooScrollArea *foo_scroll_area_new (void);
83 
84 /* Set the requisition for the widget. */
85 void	      foo_scroll_area_set_min_size (FooScrollArea *scroll_area,
86 					    int		   min_width,
87 					    int            min_height);
88 
89 /* Set how much of the canvas can be scrolled into view */
90 void	      foo_scroll_area_set_size (FooScrollArea	       *scroll_area,
91 					int			width,
92 					int			height);
93 void	      foo_scroll_area_set_size_fixed_y (FooScrollArea  *scroll_area,
94 						int		width,
95 						int		height,
96 						int		old_y,
97 						int		new_y);
98 void	      foo_scroll_area_set_viewport_pos (FooScrollArea  *scroll_area,
99 						int		x,
100 						int		y);
101 void	      foo_scroll_area_get_viewport (FooScrollArea *scroll_area,
102 					    GdkRectangle  *viewport);
103 void          foo_scroll_area_add_input_from_stroke (FooScrollArea           *scroll_area,
104 						     cairo_t	                *cr,
105 						     FooScrollAreaEventFunc   func,
106 						     gpointer                 data);
107 void          foo_scroll_area_add_input_from_fill (FooScrollArea *scroll_area,
108 						      cairo_t	      *cr,
109 						      FooScrollAreaEventFunc func,
110 						      gpointer       data);
111 void          foo_scroll_area_invalidate_region (FooScrollArea *area,
112 						 cairo_region_t *region);
113 void	      foo_scroll_area_invalidate (FooScrollArea *scroll_area);
114 void	      foo_scroll_area_invalidate_rect (FooScrollArea *scroll_area,
115 					       int	      x,
116 					       int	      y,
117 					       int	      width,
118 					       int	      height);
119 void foo_scroll_area_begin_grab (FooScrollArea *scroll_area,
120 				 FooScrollAreaEventFunc func,
121 				 gpointer       input_data);
122 void foo_scroll_area_end_grab (FooScrollArea *scroll_area);
123 gboolean foo_scroll_area_is_grabbed (FooScrollArea *scroll_area);
124 
125 void foo_scroll_area_begin_auto_scroll (FooScrollArea *scroll_area);
126 void foo_scroll_area_auto_scroll (FooScrollArea *scroll_area,
127 				  FooScrollAreaEvent *event);
128 void foo_scroll_area_end_auto_scroll (FooScrollArea *scroll_area);
129 
130 #endif /* __SCROLLAREA_H__ */
131