treewide: Use struct fmt_spec by value instead of pointer in most cases.
[pspp] / src / ui / gui / helper.h
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2004, 2009, 2010, 2011, 2012  Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17
18 #ifndef __MISC_H__
19 #define __MISC_H__
20
21
22 #include <data/format.h>
23 #include <data/value.h>
24
25 #include <gtk/gtk.h>
26
27 #include "psppire-dict.h"
28
29 gchar *paste_syntax_to_window (gchar *syntax);
30
31 struct fmt_spec;
32
33 /* Returns a new GParamSpec for a string.  An attempt to store the empty string
34    in the parameter will be silently translated into storing a null pointer. */
35 static inline GParamSpec *
36 null_if_empty_param (const gchar *name, const gchar *nick,
37                      const gchar *blurb, const gchar *default_value,
38                      GParamFlags flags)
39 {
40   GParamSpec *param;
41
42   param = g_param_spec_string (name, nick, blurb, default_value, flags);
43   ((GParamSpecString *) param)->null_fold_if_empty = TRUE;
44   return param;
45 }
46
47 gchar * value_to_text (union value v, const struct variable *);
48 gchar * value_to_text__ (union value v, struct fmt_spec, const char *encoding);
49
50
51 union value *text_to_value (const gchar *text, const struct variable *,
52                             union value *);
53 union value *text_to_value__ (const gchar *text, struct fmt_spec,
54                               const gchar *encoding, union value *);
55
56 /* Create a deep copy of SRC */
57 GtkListStore * clone_list_store (const GtkListStore *src);
58
59 /* gtk_box_pack_start_defaults is deprecated.
60    Therefore we roll our own until a better solution is found */
61 static inline void
62 psppire_box_pack_start_defaults (GtkBox *box, GtkWidget *widget)
63 {
64   gtk_box_pack_start (box, widget, TRUE, TRUE, 0);
65 }
66
67 /* Starting with gcc8 the warning Wcast-function-type will
68    trigger if no intermediate (void (*)(void)) cast is done
69    for a function cast to GFunc when the number of parameters
70    is not 2. The reason is that the compiler behaviour in this
71    situation is undefined according to C standard although many
72    implementations rely on this. */
73 #define GFUNC_COMPAT_CAST(x) ((GFunc) (void (*)(void)) (x))
74
75
76 /* Return the width of an upper case M (in pixels) when rendered onto
77    WIDGET with its current style.  */
78 gdouble width_of_m (GtkWidget *widget);
79
80 #endif
81