1 /*  HomeBank -- Free, easy, personal accounting for everyone.
2  *  Copyright (C) 1995-2021 Maxime DOYEN
3  *
4  *  This file is part of HomeBank.
5  *
6  *  HomeBank is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  HomeBank 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, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef __CHARTPROGRESS_H__
21 #define __CHARTPROGRESS_H__
22 
23 #include "gtk-chart-colors.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 
29 
30 /* Macro for casting a pointer to a GtkWidget or GtkWidgetClass pointer.
31  * Macros for testing whether `widget' or `klass' are of type GTK_TYPE_WIDGET.
32  */
33 #define GTK_TYPE_CHARTPROGRESS            (ui_chart_progress_get_type ())
34 #define GTK_CHARTPROGRESS(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CHARTPROGRESS, ChartProgress))
35 #define GTK_CHARTPROGRESS_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CHARTPROGRESS, ChartProgressClass)
36 #define GTK_IS_CHARTPROGRESS(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CHARTPROGRESS))
37 #define GTK_IS_CHARTPROGRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CHARTPROGRESS))
38 #define GTK_CHARTPROGRESS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CHARTPROGRESS, ChartProgressClass))
39 
40 typedef struct _ChartProgress		ChartProgress;
41 typedef struct _ChartProgressClass	ChartProgressClass;
42 
43 typedef struct _StackItem	    StackItem;
44 typedef struct _HbtkDrawProgContext		HbtkDrawProgContext;
45 
46 typedef gchar (* ChartProgressPrintIntFunc)    (gint value, gboolean minor);
47 typedef gchar (* ChartProgressPrintDoubleFunc) (gdouble value, gboolean minor);
48 
49 /* = = = = = = = = = = */
50 /* = = = = = = = = = = = = = = = = = = = = */
51 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
52 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
53 
54 #define GTK_CHARTPROGRESS_BARW 		32
55 #define CHART_BUFFER_LENGTH 128
56 
57 
58 #define DEFAULT_DELAY 500           /* Default delay in ms */
59 
60 
61 #define CHART_MARGIN	18 //standard a4 margin
62 #define CHART_SPACING   6
63 
64 
65 
66 struct _StackItem
67 {
68 	/* data part */
69 	gchar	 *label;
70 	gdouble  spent;
71 	gdouble	 budget;
72 	gdouble  result;
73 	gchar    *status;
74 
75 	/* draw stuffs */
76 	gdouble  rate;
77 	gboolean warn;
78 
79 	/* tmp datas */
80 	gdouble	 rawrate;
81 
82 };
83 
84 struct _HbtkDrawProgContext
85 {
86 	gboolean	isprint;
87 	gboolean	darktheme;
88 
89 	gint	first, visible;
90 	double barw, blkw;
91 
92 	/* drawing datas */
93 	double	l, t, b, r, w, h;
94 	double  graph_width, graph_height;	//graph dimension
95 
96 	/* zones height */
97 	double  title_zh;
98 	double  subtitle_zh, subtitle_y;
99 	double  header_zh, header_y;
100 	double  item_zh;
101 
102 	/* column width */
103 	double	cat_col_w;
104 	double  bud_col_w;
105 	double	res_col_w;
106 	double	rel_col_w;
107 
108 
109 };
110 
111 
112 /* you should access only the entry and list fields directly */
113 struct _ChartProgress
114 {
115 	/*< private >*/
116 	GtkBox			hbox;
117 
118 	GtkWidget		*drawarea;
119 	GtkAdjustment	*adjustment;
120 	GtkWidget		*scrollbar;
121 
122 	/* data storage */
123 	gint		nb_items;
124 	GArray		*items;
125 
126 	/*gchar		**titles;
127 	gdouble		*spent;
128 	gdouble		*budget;*/
129 
130 	gchar		*title;
131 	gchar		*subtitle;
132 
133 	gchar	    *budget_title;
134 	gchar	    *result_title;
135 
136 	gboolean	minor;
137 	guint32		kcur;
138 	gdouble		minor_rate;
139 	gchar		*minor_symbol;
140 
141 
142 
143 	/* color datas */
144 	GtkColorScheme color_scheme;
145 
146 	/* buffer surface */
147 	cairo_surface_t	 *surface;
148 
149 	gint	hover, lasthover;
150 
151 	struct _HbtkDrawProgContext context;
152 	PangoFontDescription *pfd;
153 	gint				pfd_size;
154 
155 	gchar   buffer[CHART_BUFFER_LENGTH];
156 
157 };
158 
159 
160 typedef struct
161 {
162 	ChartProgress *chart;
163 	HbtkDrawProgContext drawctx;
164 	gint num_pages;
165 } GtkChartProgPrintData;
166 
167 
168 
169 struct _ChartProgressClass {
170 	GtkBoxClass parent_class;
171 
172   /* Padding for future expansion */
173   void (*_gtk_reserved1) (void);
174   void (*_gtk_reserved2) (void);
175   void (*_gtk_reserved3) (void);
176   void (*_gtk_reserved4) (void);
177 };
178 
179 
180 GType      ui_chart_progress_get_type (void);
181 
182 
183 /* public function */
184 GtkWidget *ui_chart_progress_new(void);
185 
186 void gtk_chart_progress_print(ChartProgress *chart, GtkWindow *parent, gchar *dirname, gchar *filename);
187 
188 void ui_chart_progress_set_color_scheme(ChartProgress * chart, gint colorscheme);
189 void ui_chart_progress_set_dualdatas(ChartProgress *chart, GtkTreeModel *model, gchar *coltitle1, gchar *coltitle2, gchar *title, gchar *subtitle);
190 void ui_chart_progress_set_title(ChartProgress * chart, gchar *title);
191 void ui_chart_progress_set_subtitle(ChartProgress * chart, gchar *subtitle);
192 void ui_chart_progress_set_barw(ChartProgress * chart, gdouble barw);
193 void ui_chart_progress_show_minor(ChartProgress * chart, gboolean minor);
194 
195 void ui_chart_progress_set_minor_prefs(ChartProgress * chart, gdouble rate, gchar *symbol);
196 void ui_chart_progress_set_currency(ChartProgress * chart, guint32 kcur);
197 
198 #ifdef __cplusplus
199 }
200 #endif /* __cplusplus */
201 
202 #endif /* __CHARTPROGRESS_H__ */
203