1 /********************************************************************\
2  * dialog-utils.h -- utility functions for creating dialogs         *
3  *                   for GnuCash                                    *
4  * Copyright (C) 1999-2000 Linas Vepstas                            *
5  * Copyright (C) 2005 David Hampton <hampton@employees.org>         *
6  *                                                                  *
7  * This program is free software; you can redistribute it and/or    *
8  * modify it under the terms of the GNU General Public License as   *
9  * published by the Free Software Foundation; either version 2 of   *
10  * the License, or (at your option) any later version.              *
11  *                                                                  *
12  * This program is distributed in the hope that it will be useful,  *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
15  * GNU General Public License for more details.                     *
16  *                                                                  *
17  * You should have received a copy of the GNU General Public License*
18  * along with this program; if not, contact:                        *
19  *                                                                  *
20  * Free Software Foundation           Voice:  +1-617-542-5942       *
21  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
22  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
23  *                                                                  *
24 \********************************************************************/
25 
26 #ifndef DIALOG_UTILS_H
27 #define DIALOG_UTILS_H
28 
29 #include <gtk/gtk.h>
30 #include "qof.h"
31 
32 #define GNC_PREF_GRID_LINES_HORIZONTAL "grid-lines-horizontal"
33 #define GNC_PREF_GRID_LINES_VERTICAL   "grid-lines-vertical"
34 
35 void gnc_set_label_color (GtkWidget *label, gnc_numeric value);
36 
37 /********************************************************************\
38  * Returns the window size to use for the given option prefix,      *
39  * if window sizes are being saved, otherwise returns 0 for both.   *
40  *                                                                  *
41  * Args: prefix - the option name prefix                            *
42  *       window - the window being restored                         *
43  *       parent - the parent window for first use alignment         *
44  * Returns: nothing                                                 *
45  \*******************************************************************/
46 void gnc_restore_window_size (const char *prefix, GtkWindow *window,
47                               GtkWindow *parent);
48 
49 /********************************************************************\
50  * Save the window size into options whose names are determined     *
51  * by the string prefix.                                            *
52  *                                                                  *
53  * Args: prefix - determines the options used to save the values    *
54  *       window - the window being saved                            *
55  * Returns: nothing                                                 *
56 \********************************************************************/
57 void gnc_save_window_size (const char *section, GtkWindow *window);
58 
59 /********************************************************************\
60  * Adjust the window size if it is bigger than the screen size.     *
61  *                                                                  *
62  * Args: window - the window to adjust                              *
63  * Returns: nothing                                                 *
64 \********************************************************************/
65 void gnc_window_adjust_for_screen (GtkWindow * window);
66 
67 /********************************************************************\
68  * Sets the alignament of a Label Widget, GTK3 version specific.    *
69  *                                                                  *
70  * Args: widget - the label widget to set alignment on              *
71  *       xalign - x alignment                                       *
72  *       yalign - y alignment                                       *
73  * Returns: nothing                                                 *
74 \********************************************************************/
75 void gnc_label_set_alignment (GtkWidget *widget, gfloat xalign, gfloat yalign);
76 
77 /********************************************************************\
78  * Get the preference for showing tree view grid lines              *
79  *                                                                  *
80  * Args: none                                                       *
81  * Returns:  GtkTreeViewGridLines setting                           *
82 \********************************************************************/
83 GtkTreeViewGridLines gnc_tree_view_get_grid_lines_pref (void);
84 
85 /********************************************************************\
86  * Add a style context to a Widget so it can be altered with css    *
87  *                                                                  *
88  * Args:    widget - widget to add css style too                    *
89  *       gnc_class - character string for css class name            *
90  * Returns:  nothing                                                *
91 \********************************************************************/
92 void gnc_widget_style_context_add_class (GtkWidget *widget, const char *gnc_class);
93 
94 /********************************************************************\
95  * Remove a style context class from a Widget                       *
96  *                                                                  *
97  * Args:    widget - widget to remove style class from              *
98  *       gnc_class - character string for css class name            *
99  * Returns:  nothing                                                *
100 \********************************************************************/
101 void gnc_widget_style_context_remove_class (GtkWidget *widget, const char *gnc_class);
102 
103 /********************************************************************\
104  * Draw an arrow on a Widget so it can be altered with css          *
105  *                                                                  *
106  * Args:     widget - widget to add arrow to in the draw callback   *
107  *               cr - cairo context for the draw callback           *
108  *        direction - 0 for up, 1 for down                          *
109  * Returns:  TRUE, stop other handlers being invoked for the event  *
110 \********************************************************************/
111 gboolean gnc_draw_arrow_cb (GtkWidget *widget, cairo_t *cr, gpointer direction);
112 
113 gboolean gnc_gdate_in_valid_range (GDate *test_date, gboolean warn);
114 
115 gboolean gnc_handle_date_accelerator (GdkEventKey *event,
116                                       struct tm *tm,
117                                       const char *date_str);
118 
119 gboolean gnc_builder_add_from_file (GtkBuilder *builder, const char *filename, const char *root);
120 
121 void gnc_builder_connect_full_func (GtkBuilder *builder,
122                                     GObject *signal_object,
123                                     const gchar *signal_name,
124                                     const gchar *handler_name,
125                                     GObject *connect_object,
126                                     GConnectFlags flags,
127                                     gpointer user_data);
128 
129 /** This function generates a button with icon and adds it to a
130  *  GtkDialog.  This is similar to just adding a stock button to the
131  *  dialog, only you can add an arbitrary pairing of button and label,
132  *  which the stock system doesn't provide.
133  *
134  *  @param dialog The dialog where the button should be added.
135  *
136  *  @param label The text of the button.
137  *
138  *  @param icon_name The name of the icon button to use.
139  *
140  *  @param response The response id to return if this button is
141  *  clicked.*/
142 void gnc_gtk_dialog_add_button (GtkWidget *dialog,
143                                 const gchar *label,
144                                 const gchar *icon_name,
145                                 guint response);
146 
147 /** Note: This dialog is modal!  (It calls gtk_dialog_run() which is modal.)
148  */
149 gint
150 gnc_dialog_run(GtkDialog *dialog, const gchar *pref_key);
151 
152 /* If this is a new book, this function can be used to display book options
153  * dialog so user can specify options, before any transactions can be
154  * imported/entered, since the book options can affect how transactions are
155  * created. Note: This dialog is modal! */
156 gboolean gnc_new_book_option_display (GtkWidget *parent);
157 
158 /** This function returns a widget for selecting a cost policy
159   */
160 GtkWidget *
161 gnc_cost_policy_select_new (void);
162 
163 /** This function returns the color string for the CSS 'gnc-class-negative-numbers' class,
164  *  the returned value must be freed.
165  */
166 gchar* gnc_get_negative_color (void);
167 
168 #endif /* DIALOG_UTILS_H */
169