PIPS
gtk_help.c
Go to the documentation of this file.
1 /*
2 
3  $Id: gtk_help.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 
28 #include <stdlib.h>
29 #include <stdio.h>
30 
31 #include <sys/time.h>
32 #include <sys/resource.h>
33 
34 #include "genC.h"
35 #include "top-level.h"
36 #include "misc.h"
37 
38 #undef test_undefined // also defined in glib included from gtk
39 #include <gtk/gtk.h>
40 #include "gpips.h"
41 
42 #define min(a,b) ((a) < (b) ? (a) : (b))
43 #define HELP_LINES 32
44 
45 /* The URL of the PIPS documentation at the ï¿œcole des Mines de Paris: */
46 #define PIPS_DOCUMENTATION_URL "http://www.cri.ensmp.fr/pips"
47 static GtkWidget *lines[HELP_LINES]; /* GRRRRRRRR FC. */
49 
50 void display_help(char * topic) {
51  int i, n;
52 
53  if(help_list != NULL)
55  // if (!help_list) /* lazy */
57 
58  get_help_topic(topic, help_list);
60 
61  for (i = 0; i < min(HELP_LINES, n); i++) {
62  gtk_label_set_text(GTK_LABEL(lines[i]), gen_array_item(help_list, i));
63  // xv_set(lines[i], PANEL_LABEL_STRING, gen_array_item(help_list, i), 0);
64  }
65 
66  for (i = min(HELP_LINES, n); i < HELP_LINES; i++) {
67  gtk_label_set_text(GTK_LABEL(lines[i]), "");
68  }
69 
70  gtk_widget_show_all(help_window);
71 }
72 
73 static void close_help_notify(GtkWidget *widget, gpointer *data) {
75  hide_window(help_window, NULL, NULL);
76 }
77 
79  guint i;
80  GtkWidget *vbox;
81  GtkWidget *close_button;
82  // help_panel = xv_create(help_frame, PANEL, NULL);
83  help_frame = gtk_frame_new(NULL);
84  gtk_container_add(GTK_CONTAINER(help_window), help_frame);
85 
86  // Literal translation from XV
87  // need to put in in a more gtk-like form
88  vbox = gtk_vbox_new(FALSE, 0);
89  for (i = 0; i < HELP_LINES; i++) {
90  // lines[i] = xv_create(help_panel, PANEL_MESSAGE, XV_X, 15, XV_Y, 15*
91  // (i +1),
92  // 0);
93  // }
94  lines[i] = gtk_label_new(NULL);
95  gtk_box_pack_start(GTK_BOX(vbox), lines[i], FALSE, FALSE, 0);
96  gtk_widget_show(lines[i]);
97  }
98  // xv_create(help_panel, PANEL_BUTTON, PANEL_LABEL_STRING, "CLOSE", XV_X,
99  // HELP_WIDTH / 2 - 28, XV_Y, 15* (HELP_LINES +1),
100  // PANEL_NOTIFY_PROC, close_help_notify,
101  // 0);
102  close_button = gtk_button_new_with_label("CLOSE");
103  gtk_box_pack_start(GTK_BOX(vbox), close_button, FALSE, FALSE, 15);
104  gtk_widget_show(close_button);
105 
106  gtk_container_add(GTK_CONTAINER(help_frame), vbox);
107 
108  gtk_signal_connect(GTK_OBJECT(close_button), "clicked", GTK_SIGNAL_FUNC(
109  close_help_notify), NULL);
110 
111  gtk_widget_show_all(help_frame);
112 }
113 
114 static void help_notify(GtkWidget * widget, gpointer data) {
115  // display_help((char *) xv_get(menu_item, MENU_CLIENT_DATA));
116  display_help((char *) data);
117 }
118 
119 static void help_launch_pips_firefox(GtkWidget * widget, gpointer data) {
120  safe_system("firefox " PIPS_DOCUMENTATION_URL " &");
121 }
122 static char * menu_data[] = { "A few introductory words...", "Introduction",
123  "A few words about \"Workspace\"...", "Workspace",
124  "A few words about \"Module\"...", "Module",
125  "A few words about \"Directory\"...", "Directory",
126  "A few words about \"View\"...", "View",
127  "A few words about \"Transform/Edit\"...", "Transform/Edit",
128  "A few words about \"Compile\"...", "Compile",
129  "A few words about \"Options\"...", "Options",
130  "A few words about \"Log\"...", "Log" };
131 
133  guint i;
134  GtkWidget *help_menu, *help_menu_item;
135  help_menu = gtk_menu_new();
136  help_menu_item = gtk_menu_item_new_with_label("Help");
137  gtk_menu_item_set_submenu(GTK_MENU_ITEM(help_menu_item), help_menu);
138 
139  GtkWidget * menu_item;
140  for (i = 0; i < 9; i++) {
141  menu_item = gtk_menu_item_new_with_label(menu_data[i * 2]);
142  g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(
143  help_notify), menu_data[i * 2 + 1]);
144  gtk_menu_append(GTK_MENU(help_menu), menu_item);
145  }
146 
147  gtk_menu_append(GTK_MENU(help_menu), gtk_separator_menu_item_new());
148 
149  menu_item = gtk_menu_item_new_with_label(
150  "The PIPS documentation on Internet with Firefox...");
151  g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(
152  help_launch_pips_firefox), NULL);
153  gtk_menu_append(GTK_MENU(help_menu), menu_item);
154 
155  gtk_widget_show(help_menu_item);
156  gtk_widget_show_all(help_menu);
157  gtk_menu_bar_append(main_window_menu_bar, help_menu_item);
158 }
size_t gen_array_nitems(const gen_array_t a)
Definition: array.c:131
void gen_array_full_free(gen_array_t a)
Definition: array.c:77
gen_array_t gen_array_make(size_t size)
declarations...
Definition: array.c:40
void * gen_array_item(const gen_array_t a, size_t i)
Definition: array.c:143
void gen_array_free(gen_array_t a)
Definition: array.c:70
GtkWidget * help_frame
Definition: gpips-local.h:43
GtkWidget * main_window_menu_bar
Definition: gpips.c:62
GtkWidget * help_window
Definition: gpips-local.h:37
void create_help_menu()
Definition: gtk_help.c:132
void create_help_window()
Definition: gtk_help.c:78
#define PIPS_DOCUMENTATION_URL
The URL of the PIPS documentation at the ï¿œcole des Mines de Paris:
Definition: gtk_help.c:46
static char * menu_data[]
Definition: gtk_help.c:122
void display_help(char *topic)
Definition: gtk_help.c:50
#define HELP_LINES
Definition: gtk_help.c:43
static void help_launch_pips_firefox(GtkWidget *widget, gpointer data)
Definition: gtk_help.c:119
static void close_help_notify(GtkWidget *widget, gpointer *data)
Definition: gtk_help.c:73
static GtkWidget * lines[HELP_LINES]
Definition: gtk_help.c:47
static gen_array_t help_list
GRRRRRRRR FC.
Definition: gtk_help.c:48
#define min(a, b)
Definition: gtk_help.c:42
static void help_notify(GtkWidget *widget, gpointer data)
Definition: gtk_help.c:114
gint hide_window(GtkWidget *window, GdkEvent *ev __attribute__((unused)), gpointer data __attribute__((unused)))
Definition: gtk_utils.c:89
void get_help_topic(string topic, gen_array_t array)
Definition: help.c:64
void safe_system(string)
system.c
Definition: system.c:38
struct _gen_array_chunk_t * gen_array_t
Definition: newgen_array.h:24