1 /*
2  * gog-view.h : A sized render engine for an item.
3  *
4  * Copyright (C) 2003-2004 Jody Goldberg (jody@gnome.org)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) version 3.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19  * USA
20  */
21 #ifndef GOG_VIEW_H
22 #define GOG_VIEW_H
23 
24 #include <goffice/goffice.h>
25 
26 G_BEGIN_DECLS
27 
28 /*****************************************************************************/
29 
30 typedef struct _GogToolAction GogToolAction;
31 
32 typedef struct {
33 	char const 	*name;
34 
35 	/* GdkCursorType	 cursor_type; Not compatible with --without-gtk */
36 	int	 	cursor_type;
37 
38 	gboolean 	(*point) 	(GogView *view, double x, double y, GogObject **object);
39 	void 		(*render)	(GogView *view);
40 	void 		(*init)		(GogToolAction *action);
41 	void 		(*move)		(GogToolAction *action, double x, double y);
42 	void		(*double_click)	(GogToolAction *action);
43 	void 		(*destroy)	(GogToolAction *action);
44 } GogTool;
45 
46 struct _GogToolAction {
47 	double 		 start_x, start_y;
48 	GogView 	*view;
49 	GogTool 	*tool;
50 	gpointer	 data;
51 	/* private */
52 	unsigned int ref_count;
53 };
54 
55 GType        gog_tool_action_get_type   (void);
56 GogToolAction 	*gog_tool_action_new 	(GogView *view, GogTool *tool, double x, double y);
57 void 		 gog_tool_action_move 		(GogToolAction *action, double x, double y);
58 void 		 gog_tool_action_double_click 	(GogToolAction *action);
59 void 		 gog_tool_action_free 		(GogToolAction *action);
60 
61 /*****************************************************************************/
62 
63 struct _GogView {
64 	GObject	 base;
65 
66 	GogObject *model;
67 
68 	GogRenderer *renderer;  /* not NULL */
69 	GogView	    *parent;	/* potentially NULL */
70 	GSList	    *children;
71 
72 	GogViewAllocation  allocation;	/* in renderer units */
73 	GogViewAllocation  residual;	/* left over after compass children are placed */
74 	unsigned allocation_valid: 1;  /* adjust our layout when child changes size */
75 	unsigned child_allocations_valid: 1;  /* some children need to adjust their layout */
76 	unsigned being_updated: 1;
77 
78 	GSList	*toolkit; 	/* List of GogTool */
79 	void		*_priv; /* for future use */
80 };
81 
82 typedef struct {
83 	GObjectClass	base;
84 
85 	unsigned int clip; 	/* Automaticaly clip to object bounding box */
86 
87 	/* Virtuals */
88 	void	 (*state_init)    (GogView *view);
89 	void	 (*padding_request) 		(GogView *view, GogViewAllocation const *bbox,
90 						 GogViewPadding *padding);
91 	void	 (*size_request)    		(GogView *view, GogViewRequisition const *available,
92 						 GogViewRequisition *requisition);
93 	void	 (*size_allocate)   		(GogView *view, GogViewAllocation const *allocation);
94 
95 	void	 (*render)        		(GogView *view, GogViewAllocation const *bbox);
96 
97 	void	 (*build_toolkit)		(GogView *view);
98 	char    *(*get_tip_at_point)		(GogView *view, double x, double y);
99 	void	 (*natural_size)    		(GogView *view, GogViewRequisition *req);
100 	/*<private>*/
101 	void	 (*reserved1)		(GogView *view);
102 	void	 (*reserved2)		(GogView *view);
103 } GogViewClass;
104 
105 #define GOG_TYPE_VIEW		(gog_view_get_type ())
106 #define GOG_VIEW(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GOG_TYPE_VIEW, GogView))
107 #define GOG_IS_VIEW(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GOG_TYPE_VIEW))
108 #define GOG_VIEW_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST ((k), GOG_TYPE_VIEW, GogViewClass))
109 #define GOG_IS_VIEW_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GOG_TYPE_VIEW))
110 #define GOG_VIEW_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GOG_TYPE_VIEW, GogViewClass))
111 
112 GType      gog_view_get_type (void);
113 
114 GogObject *gog_view_get_model	     (GogView const *view);
115 void	   gog_view_render	     (GogView *view, GogViewAllocation const *bbox);
116 void       gog_view_queue_redraw     (GogView *view);
117 void       gog_view_queue_resize     (GogView *view);
118 void	   gog_view_padding_request  (GogView *view, GogViewAllocation const *bbox, GogViewPadding *padding);
119 void       gog_view_size_request     (GogView *view, GogViewRequisition const *available,
120 				      GogViewRequisition *requisition);
121 void       gog_view_size_allocate    (GogView *view, GogViewAllocation const *allocation);
122 gboolean   gog_view_update_sizes     (GogView *view);
123 GogView   *gog_view_find_child_view  (GogView const *container,
124 				      GogObject const *target_model);
125 void       gog_view_get_natural_size (GogView *view, GogViewRequisition *requisition);
126 
127 GSList const	*gog_view_get_toolkit		(GogView *view);
128 void 		 gog_view_render_toolkit 	(GogView *view);
129 GogTool		*gog_view_get_tool_at_point 	(GogView *view, double x, double y,
130 						 GogObject **gobj);
131 GogView 	*gog_view_get_view_at_point	(GogView *view, double x, double y,
132 						 GogObject **obj, GogTool **tool);
133 char		*gog_view_get_tip_at_point      (GogView *view, double x, double y);
134 
135     /* protected */
136 void gog_view_size_child_request (GogView *view,
137 				  GogViewRequisition const *available,
138 				  GogViewRequisition *req,
139 				  GogViewRequisition *min_req);
140 
141 G_END_DECLS
142 
143 #endif /* GOG_VIEW_H */
144