-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.c
77 lines (63 loc) · 1.63 KB
/
misc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* various ancillary functions */
#include <string.h>
#include "misc.h"
void DestroyWindow(GtkWidget *w, gpointer window)
{
gtk_widget_destroy((GtkWidget *)window);
}
gint GotOK(GtkWidget *w, GdkEventKey *event, gpointer Button)
{
GdkEvent *dummyevent;
gint return_val;
if(event->keyval==GDK_KEY_Return) {
dummyevent=(GdkEvent*)g_malloc(sizeof(GdkEvent));
g_signal_emit_by_name((GObject *) Button,
"clicked", &dummyevent, &return_val);
g_free(dummyevent);
return TRUE;
}
return FALSE;
}
gint GotOKInDialog(GtkWidget *w, GdkEventKey *event, gpointer dialog)
{
gint return_val;
if(event->keyval==GDK_KEY_Return)
{
gtk_dialog_response( GTK_DIALOG( dialog ), OK_BUTTON );
return TRUE;
}
return FALSE;
}
/* find the length (in characters) of the longest entry in a GList
containing string data. */
gint getLongestEntry(GList *list)
{
GList *plist;
gint longest = 0;
gint length;
plist = list;
while ( plist != NULL )
{
length = strlen( (gchar*)plist->data );
if ( length > longest )
longest = length;
plist = g_list_next(plist);
}
return longest;
}
/* displays the message in an "OK" style dialog box.
messageType indicates Warning, Error, etc (see GtkMessageDialog).
*/
void showMessageDialog( gchar *message, GtkMessageType messageType )
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new( NULL,
0,
messageType,
GTK_BUTTONS_OK,
"%s", message);
g_signal_connect_swapped (G_OBJECT (dialog), "response",
G_CALLBACK (gtk_widget_destroy),
G_OBJECT (dialog));
gtk_widget_show(dialog);
}