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 #include <cairo.h>
19 #include <gtk/gtk.h>
20 
21 #define GdkRegion cairo_region_t
22 #define gdk_region_new cairo_region_create
23 #define gdk_region_destroy cairo_region_destroy
24 #define gdk_region_rectangle cairo_region_create_rectangle
25 #define gdk_region_subtract cairo_region_subtract
26 #define gdk_region_intersect cairo_region_intersect
27 #define gdk_region_empty cairo_region_is_empty
28 #define gdk_region_copy cairo_region_copy
29 #define gdk_region_get_clipbox cairo_region_get_extents
30 #define gdk_region_offset cairo_region_translate
31 #define gdk_region_point_in cairo_region_contains_point
32 #define gdk_region_union cairo_region_union
33 
34 #define FOO_TYPE_SCROLL_AREA            (foo_scroll_area_get_type ())
35 #define FOO_SCROLL_AREA(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOO_TYPE_SCROLL_AREA, FooScrollArea))
36 #define FOO_SCROLL_AREA_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  FOO_TYPE_SCROLL_AREA, FooScrollAreaClass))
37 #define FOO_IS_SCROLL_AREA(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOO_TYPE_SCROLL_AREA))
38 #define FOO_IS_SCROLL_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  FOO_TYPE_SCROLL_AREA))
39 #define FOO_SCROLL_AREA_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  FOO_TYPE_SCROLL_AREA, FooScrollAreaClass))
40 
41 typedef struct FooScrollArea FooScrollArea;
42 typedef struct FooScrollAreaClass FooScrollAreaClass;
43 typedef struct FooScrollAreaPrivate FooScrollAreaPrivate;
44 typedef struct FooScrollAreaEvent FooScrollAreaEvent;
45 
46 typedef enum
47 {
48     FOO_BUTTON_PRESS,
49     FOO_BUTTON_RELEASE,
50     FOO_MOTION,
51     FOO_MOTION_OUTSIDE
52 } FooScrollAreaEventType;
53 
54 struct FooScrollAreaEvent
55 {
56     FooScrollAreaEventType type;
57     int                    x;
58     int                    y;
59 };
60 
61 typedef void (* FooScrollAreaEventFunc) (FooScrollArea      *area,
62                                          FooScrollAreaEvent *event,
63                                          gpointer            data);
64 
65 struct FooScrollArea
66 {
67     GtkContainer parent_instance;
68 
69     FooScrollAreaPrivate *priv;
70 };
71 
72 struct FooScrollAreaClass
73 {
74     GtkContainerClass parent_class;
75 
76     void (*set_scroll_adjustments) (FooScrollArea *scroll_area,
77                                     GtkAdjustment *hadjustment,
78                                     GtkAdjustment *vadjustment);
79 
80     void (*viewport_changed)       (FooScrollArea *scroll_area,
81                                     GdkRectangle  *old_viewport,
82                                     GdkRectangle  *new_viewport);
83 
84     void (*paint)                  (FooScrollArea *scroll_area,
85                                     cairo_t       *cr,
86                                     GdkRectangle  *extents,
87                                     GdkRegion     *region);
88 };
89 
90 GType foo_scroll_area_get_type (void);
91 
92 FooScrollArea *foo_scroll_area_new (void);
93 
94 /* Set the requisition for the widget. */
95 void foo_scroll_area_set_min_size          (FooScrollArea          *scroll_area,
96                                             int                     min_width,
97                                             int                     min_height);
98 
99 /* Set how much of the canvas can be scrolled into view */
100 void foo_scroll_area_set_size              (FooScrollArea          *scroll_area,
101                                             int                     width,
102                                             int                     height);
103 void foo_scroll_area_set_size_fixed_y      (FooScrollArea          *scroll_area,
104                                             int                     width,
105                                             int                     height,
106                                             int                     old_y,
107                                             int                     new_y);
108 void foo_scroll_area_set_viewport_pos      (FooScrollArea          *scroll_area,
109                                             int                     x,
110                                             int                     y);
111 void foo_scroll_area_get_viewport          (FooScrollArea          *scroll_area,
112                                             GdkRectangle           *viewport);
113 void foo_scroll_area_add_input_from_stroke (FooScrollArea          *scroll_area,
114                                             cairo_t	               *cr,
115                                             FooScrollAreaEventFunc  func,
116                                             gpointer                data);
117 void foo_scroll_area_add_input_from_fill   (FooScrollArea          *scroll_area,
118                                             cairo_t                *cr,
119                                             FooScrollAreaEventFunc  func,
120                                             gpointer                data);
121 void foo_scroll_area_invalidate_region     (FooScrollArea          *area,
122                                             GdkRegion              *region);
123 void foo_scroll_area_invalidate            (FooScrollArea          *scroll_area);
124 void foo_scroll_area_invalidate_rect       (FooScrollArea          *scroll_area,
125                                             int                     x,
126                                             int                     y,
127                                             int                     width,
128                                             int                     height);
129 void     foo_scroll_area_begin_grab        (FooScrollArea          *scroll_area,
130                                             FooScrollAreaEventFunc  func,
131                                             gpointer                input_data);
132 void     foo_scroll_area_end_grab          (FooScrollArea          *scroll_area);
133 gboolean foo_scroll_area_is_grabbed        (FooScrollArea          *scroll_area);
134 void     foo_scroll_area_begin_auto_scroll (FooScrollArea          *scroll_area);
135 void     foo_scroll_area_auto_scroll       (FooScrollArea          *scroll_area,
136                                             FooScrollAreaEvent     *event);
137 void     foo_scroll_area_end_auto_scroll   (FooScrollArea          *scroll_area);
138