PIPS
gtk_utils.c
Go to the documentation of this file.
1 /*
2 
3  $Id: gtk_utils.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <sys/param.h>
30 
31 #include <sys/time.h>
32 #include <sys/resource.h>
33 
34 #include "genC.h"
35 #include "misc.h"
36 
37 #undef test_undefined // also defined in glib included from gtk
38 #include <gtk/gtk.h>
39 #include "gpips.h"
40 
41 extern char *getwd();
42 
43 const char * gpips_gtk_menu_item_get_label(GtkWidget * w) {
44  guint i;
45  const char * label;
46  GtkWidget * child;
47  if (!GTK_IS_MENU_ITEM(w))
48  return NULL;
49  GList * children = gtk_container_get_children(GTK_CONTAINER(w));
50  for (i = 0; i < g_list_length(children); i++) {
51  child = (GtkWidget *) g_list_nth_data(children, i);
52  if (!GTK_IS_LABEL(child))
53  continue;
54  label = gtk_label_get_text(GTK_LABEL(child));
55  }
56  g_list_free(children);
57  return (label);
58 }
59 
60 bool gpips_gtk_widget_get_sensitive(GtkWidget * w) {
61  return GTK_WIDGET_SENSITIVE(w);
62 }
63 
64 void gpips_gtk_menu_item_set_label(GtkWidget * w, gchar * text) {
65  guint i;
66  GtkWidget * child;
67  if (!GTK_IS_MENU_ITEM(w))
68  return;
69  GList * children = gtk_container_get_children(GTK_CONTAINER(w));
70  for (i = 0; i < g_list_length(children); i++) {
71  child = (GtkWidget *) g_list_nth_data(children, i);
72  if (!GTK_IS_LABEL(child))
73  continue;
74  gtk_label_set_text(GTK_LABEL(child), text);
75  }
76  g_list_free(children);
77 }
78 
79 GtkWidget * gpips_gtk_dialog_get_content_area(GtkDialog *dialog) {
80  g_return_val_if_fail(GTK_IS_DIALOG(dialog), NULL);
81  return dialog->vbox;
82 }
83 
84 gdouble gpips_gtk_adjustment_get_upper(GtkAdjustment *adjustment) {
85  g_return_val_if_fail(GTK_IS_ADJUSTMENT(adjustment), 0.0);
86  return adjustment->upper;
87 }
88 
89 gint hide_window(GtkWidget *window, GdkEvent *ev __attribute__((unused)), gpointer data __attribute__((unused))) {
90  gtk_widget_hide(GTK_WIDGET(window));
91  return TRUE;
92 }
93 
94 gint load_file(const gchar *filename, gchar ** data) {
95  int size = 0;
96  FILE *f = fopen(filename, "rb");
97  if (f == NULL) {
98  *data = NULL;
99  return -1; // -1 means file opening fail
100  }
101 
102  fseek(f, 0, SEEK_END);
103  size = ftell(f);
104  fseek(f, 0, SEEK_SET);
105 
106  *data = (char *) malloc(size + 1);
107 
108  if (size != fread(*data, sizeof(char), size, f)) {
109  free(*data);
110  return -2; // -2 means file reading fail
111  }
112  fclose(f);
113  (*data)[size] = 0;
114  return size;
115 }
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
void * malloc(YYSIZE_T)
void free(void *)
bool gpips_gtk_widget_get_sensitive(GtkWidget *w)
Definition: gtk_utils.c:60
const char * gpips_gtk_menu_item_get_label(GtkWidget *w)
Definition: gtk_utils.c:43
gint hide_window(GtkWidget *window, GdkEvent *ev __attribute__((unused)), gpointer data __attribute__((unused)))
Definition: gtk_utils.c:89
GtkWidget * gpips_gtk_dialog_get_content_area(GtkDialog *dialog)
Definition: gtk_utils.c:79
char * getwd()
void gpips_gtk_menu_item_set_label(GtkWidget *w, gchar *text)
Definition: gtk_utils.c:64
gint load_file(const gchar *filename, gchar **data)
Definition: gtk_utils.c:94
gdouble gpips_gtk_adjustment_get_upper(GtkAdjustment *adjustment)
Definition: gtk_utils.c:84
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15