File: misc.c

package info (click to toggle)
gworldclock 1.4.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 980 kB
  • ctags: 158
  • sloc: sh: 3,855; ansic: 2,228; makefile: 68; sed: 16
file content (75 lines) | stat: -rw-r--r-- 1,633 bytes parent folder | download | duplicates (4)
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
/* various ancillary functions */

#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_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_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,
				    message);

   g_signal_connect_swapped (G_OBJECT (dialog), "response",
			     G_CALLBACK (gtk_widget_destroy),
			     GTK_OBJECT (dialog));
   gtk_widget_show(dialog);				     
}