Exemplo n.º 1
0
/*
 * Creates a new GtkWidget of class GnomeMessageBox, performing any specialized
 * initialization needed for the widget to work correctly in this environment.
 * If a dialog box is used to initialize the widget, return NULL from this
 * function, and call data->callback with your new widget when it is done.
 * If the widget needs a special destroy handler, add a signal here.
 */
static GtkWidget*
gb_gnome_message_box_new (GbWidgetNewData *data)
{
  GtkWidget *new_widget;
  GList *elem;

  if (data->action == GB_CREATING)
    {
      /* When creating a new dialog, we add a few standard buttons, which
	 the user can change/delete easily. */
      new_widget = gnome_message_box_new ("", GNOME_MESSAGE_BOX_INFO,
					  GNOME_STOCK_BUTTON_OK, NULL);

      /* Now turn the buttons into GbWidgets so the user can edit them. */
      elem = GNOME_DIALOG (new_widget)->buttons;
      gb_widget_create_from (GTK_WIDGET (elem->data), "button");
      gtk_object_set_data (GTK_OBJECT (elem->data), "GtkButton::stock_button",
			   GINT_TO_POINTER (GladeStockButtonOK));
    }
  else
    {
      /* FIXME: We create it with an OK button, and then remove the button,
	 to work around a bug in gnome_message_box_new() - it tries to set the
	 keyboard focus to the last button, which may not exist. It also
	 ensures that gnome_dialog_init_action_area() has been called. */
      new_widget = gnome_message_box_new ("",  GNOME_MESSAGE_BOX_INFO,
					  GNOME_STOCK_BUTTON_OK, NULL);

      gtk_container_remove (GTK_CONTAINER (GNOME_DIALOG (new_widget)->action_area), GNOME_DIALOG (new_widget)->buttons->data);
      GNOME_DIALOG (new_widget)->buttons = NULL;
    }

  gb_widget_create_from (GNOME_DIALOG (new_widget)->vbox,
			 data->action == GB_CREATING ? "dialog-vbox" : NULL);
  gb_widget_set_child_name (GNOME_DIALOG (new_widget)->vbox, DialogVBox);

  gb_widget_create_from (GNOME_DIALOG (new_widget)->action_area,
			 data->action == GB_CREATING ? "dialog-action_area"
						     : NULL);
  gb_widget_set_child_name (GNOME_DIALOG (new_widget)->action_area,
			    DialogActionArea);

  /* We connect a close signal handler which always returns TRUE so that
     the built-in close functionality is skipped. */
  gtk_signal_connect (GTK_OBJECT (new_widget), "close",
		      GTK_SIGNAL_FUNC (gtk_true), NULL);

  /* Now we connect our normal delete_event handler. */
  gtk_signal_connect (GTK_OBJECT (new_widget), "delete_event",
		      GTK_SIGNAL_FUNC (editor_close_window), NULL);

  return new_widget;
}
Exemplo n.º 2
0
static GtkWidget *
reply_dialog (const gchar * question, GnomeReplyCallback callback, gpointer data,
	      gboolean yes_or_ok, gboolean modal, GtkWindow * parent)
{
  GtkWidget * mbox;
  callback_info * info;

  if (yes_or_ok) {
    mbox = gnome_message_box_new(question, GNOME_MESSAGE_BOX_QUESTION,
				 GNOME_STOCK_BUTTON_NO, 
				 GNOME_STOCK_BUTTON_YES, NULL);
  }
  else {
    mbox = gnome_message_box_new(question, GNOME_MESSAGE_BOX_QUESTION,
				 GNOME_STOCK_BUTTON_CANCEL, 
				 GNOME_STOCK_BUTTON_OK, NULL);
  }

  if (callback != NULL) {
    info = g_new(callback_info, 1);

    info->function = callback;
    info->data = data;

    g_signal_connect_data (mbox, "clicked",
			   G_CALLBACK (dialog_reply_callback),
			   info,
			   (GClosureNotify) g_free,
			   0);
  }

  if (modal) {
    gtk_window_set_modal(GTK_WINDOW(mbox),TRUE);
  }

  if (parent != NULL) {
    gnome_dialog_set_parent(GNOME_DIALOG(mbox),parent);
  }

  gtk_widget_show(mbox);
  return mbox;
}
Exemplo n.º 3
0
int error_dialog (char *message)
{
    GtkWidget *dialog;
    int test;

    dialog =
        gnome_message_box_new (message, GNOME_MESSAGE_BOX_ERROR,
                               GNOME_STOCK_BUTTON_CLOSE, NULL);
    test = gnome_dialog_run (GNOME_DIALOG (dialog));
    return test;
}
Exemplo n.º 4
0
static GtkWidget *
request_dialog (const gchar * request, const gchar * default_text, const guint16 max_length,
		GnomeStringCallback callback, gpointer data,
		gboolean password,
		GtkWindow * parent)
{
  GtkWidget * mbox;
  callback_info * info;
  GtkWidget * entry;

  mbox = gnome_message_box_new ( request, GNOME_MESSAGE_BOX_QUESTION,
				 GNOME_STOCK_BUTTON_CANCEL, 
				 GNOME_STOCK_BUTTON_OK,
				 NULL );
  gnome_dialog_set_default ( GNOME_DIALOG(mbox), 1 );

  /* set up text entry widget */
  entry = gtk_entry_new();
  if (password) gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE);
  if ((default_text != NULL) && (*default_text))
    gtk_entry_set_text(GTK_ENTRY(entry), default_text);
  if (max_length > 0)
    gtk_entry_set_max_length(GTK_ENTRY(entry), max_length);

  gtk_box_pack_end ( GTK_BOX(GNOME_DIALOG(mbox)->vbox), 
		     entry, FALSE, FALSE, GNOME_PAD_SMALL );

  /* If Return is pressed in the text entry, propagate to the buttons */
  gnome_dialog_editable_enters(GNOME_DIALOG(mbox), GTK_EDITABLE(entry));

  info = g_new(callback_info, 1);

  info->function = callback;
  info->data = data;
  info->entry = GTK_ENTRY(entry);

  g_signal_connect_data (mbox, "clicked",
			 G_CALLBACK (dialog_string_callback),
			 info,
			 (GClosureNotify) g_free,
			 0);

  if (parent != NULL) {
    gnome_dialog_set_parent(GNOME_DIALOG(mbox),parent);
  }

  gtk_widget_grab_focus (entry);

  gtk_widget_show (entry);
  gtk_widget_show (mbox);
  return mbox;
}
Exemplo n.º 5
0
static GtkWidget *
show_ok_box(const gchar * message, const gchar * type, GtkWindow * parent)
{  
  GtkWidget * mbox;

  mbox = gnome_message_box_new (message, type,
				GNOME_STOCK_BUTTON_OK, NULL);
  
  if (parent != NULL) {
    gnome_dialog_set_parent(GNOME_DIALOG(mbox),parent);
  }

  gtk_widget_show (mbox);
  return mbox;
}
Exemplo n.º 6
0
void ghack_save_game_cb(GtkWidget *widget, gpointer data)
{
    GtkWidget *box;
    box = gnome_message_box_new(_("Quit and save the current game?"),
                                GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_YES,
                                GNOME_STOCK_BUTTON_NO, NULL);
    gnome_dialog_set_default( GNOME_DIALOG(box), 1);
    gnome_dialog_set_parent (GNOME_DIALOG (box),
                             GTK_WINDOW (ghack_get_main_window ()) );
    gnome_dialog_set_accelerator (GNOME_DIALOG(box), 1, 'n', 0);
    gnome_dialog_set_accelerator (GNOME_DIALOG(box), 0, 'y', 0);

    gtk_window_set_modal( GTK_WINDOW(box), TRUE);
    gtk_signal_connect( GTK_OBJECT(box), "clicked",
                        (GtkSignalFunc)ghack_save_game, NULL);
    gtk_widget_show(box);
}
Exemplo n.º 7
0
static int
game_quit_callback (GtkWidget *widget, void *data)
{
	GtkWidget *box;
	
	box = gnome_message_box_new (_("Do you really want to quit?"),
				     GNOME_MESSAGE_BOX_QUESTION,
				     GNOME_STOCK_BUTTON_YES,
				     GNOME_STOCK_BUTTON_NO,
				     NULL);
	gnome_dialog_set_parent (GNOME_DIALOG(box), GTK_WINDOW(app));
	gnome_dialog_set_default (GNOME_DIALOG (box), 0);
	gtk_window_set_modal (GTK_WINDOW (box), TRUE);
	gtk_signal_connect (GTK_OBJECT (box), "clicked",
			   (GtkSignalFunc)game_maybe_quit, NULL);
	gtk_widget_show (box);

	return TRUE;
}
Exemplo n.º 8
0
void find_compile_regex(GnomeFindDialog *find_dialog)
{
  int cflags;
  int regex_result;
  char errbuf[ERRBUF_SIZE];
  char messagebuf[MSGBUF_SIZE];

  GtkWidget *message_dialog;

  if(find_params.regex == TRUE) {
    /* compile the regular expression */
    cflags = REG_EXTENDED;
    if(find_params.case_sensitive == FALSE) {
      cflags = cflags | REG_ICASE;
    }

    preg = (regex_t *) g_malloc(sizeof(regex_t));

    regex_result = regcomp(preg, find_params.find_text, cflags);

    if(regex_result != 0) {
      regerror(regex_result, preg, errbuf, ERRBUF_SIZE);
      g_snprintf(messagebuf, MSGBUF_SIZE, "Error compiling regular expression: %s", errbuf);

      message_dialog = gnome_message_box_new(messagebuf,
					     GNOME_MESSAGE_BOX_ERROR,
					     GNOME_STOCK_BUTTON_OK,
					     NULL);
      if (find_dialog != NULL ) {
	gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(find_dialog));
      }
      else {
	gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(R_gtk_main_window));
      }
      gnome_dialog_run_and_close(GNOME_DIALOG(message_dialog));

      return;
    }
  }
}
Exemplo n.º 9
0
void find_process_result(GnomeFindDialog *find_dialog, int find_result)
{
  find_selection *find_select;

  GtkWidget *message_dialog;

  if (find_dialog != NULL)
    g_return_if_fail(GNOME_IS_FIND_DIALOG(find_dialog));

  switch (find_result) {
  case GNOME_FIND_NOMATCH:
    message_dialog = gnome_message_box_new("Could not find text in console output.",
					   GNOME_MESSAGE_BOX_WARNING,
					   GNOME_STOCK_BUTTON_OK,
					   NULL);
    if (find_dialog != NULL ) {
      gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(find_dialog));
    }
    else {
      gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(R_gtk_main_window));
    }
    gnome_dialog_run_and_close (GNOME_DIALOG(message_dialog));
    if(find_dialog != NULL) 
    gnome_dialog_set_default(GNOME_DIALOG(find_dialog), GNOME_FIND_BUTTON_FIND);
    break;
    
  case GNOME_FIND_MATCH:
    find_select = (find_selection *) find_current_match->data;
    gtk_editable_set_position(GTK_EDITABLE(R_gtk_terminal_text),
				find_select->select_end);
    gtk_editable_select_region(GTK_EDITABLE(R_gtk_terminal_text),
				 find_select->select_start,
				 find_select->select_end);
    break;
  }
}
Exemplo n.º 10
0
/* Display the file named str.  Complain about missing files
                   iff complain is TRUE.
*/
void gnome_display_file(const char *filename,BOOLEAN_P must_exist)
{
	/* Strange -- for some reason it makes us create a new text window
	 * instead of reusing any existing ones -- perhaps we can work out
	 * some way to reuse stuff -- but for now just make and destroy new
	 * ones each time */
        
	dlb *f;
       
        f = dlb_fopen(filename, "r");
        if (!f) {
	  if (must_exist) {
	    GtkWidget *box;
            char message[90];
            sprintf(message, "Warning! Could not find file: %s\n",filename);

	    box = gnome_message_box_new (_(message),
		    GNOME_MESSAGE_BOX_ERROR,
		    GNOME_STOCK_BUTTON_OK,
		    NULL);
	    gnome_dialog_set_default( GNOME_DIALOG(box), 0);
	    gnome_dialog_set_parent (GNOME_DIALOG (box), 
		    GTK_WINDOW (ghack_get_main_window ()) );
	    gtk_window_set_modal( GTK_WINDOW(box), TRUE);
	    gtk_widget_show (box);
	  }
        }
	else {
    	  GtkWidget *txtwin, *gless, *frametxt;
#define LLEN 128
	  char line[LLEN], *textlines;
	  int num_lines, charcount;

	  txtwin = gnome_dialog_new("Text Window", GNOME_STOCK_BUTTON_OK,
				    NULL);
          gtk_widget_set_usize(GTK_WIDGET(txtwin), 500, 400);
          gtk_window_set_policy(GTK_WINDOW(txtwin), TRUE, TRUE, FALSE);
          gtk_window_set_title(GTK_WINDOW(txtwin), "Text Window");
	  gnome_dialog_set_default( GNOME_DIALOG(txtwin), 0);
	  gtk_window_set_modal( GTK_WINDOW(txtwin), TRUE);
	  frametxt = gtk_frame_new ("");
	  gtk_widget_show (frametxt);

	  /*
	   * Count the number of lines and characters in the file.
	   */
	  num_lines = 0;
	  charcount = 1;
	  while (dlb_fgets(line, LLEN, f)) {
	    num_lines++;
	    charcount += strlen(line);
	  }
	  (void) dlb_fclose(f);
	  
	  /* Ignore empty files */
	  if (num_lines == 0) return;

	  /*
	   * Re-open the file and read the data into a buffer.  
	   */
	  textlines = (char *) alloc((unsigned int) charcount);
	  textlines[0] = '\0';
	  f = dlb_fopen( filename, RDTMODE);

	  while (dlb_fgets(line, LLEN, f)) {
	    (void) strcat(textlines, line);
	  }
	  (void) dlb_fclose(f);

	  gless = gnome_less_new ();
	  gnome_less_show_string (GNOME_LESS (gless), textlines);
	  gtk_container_add (GTK_CONTAINER (frametxt), gless);
          gtk_box_pack_start(GTK_BOX (GNOME_DIALOG (txtwin)->vbox), frametxt,
                             TRUE, TRUE, 0);
	  gtk_widget_show_all( txtwin);
	  gtk_window_set_modal( GTK_WINDOW(txtwin), TRUE);
	  gnome_dialog_set_parent (GNOME_DIALOG (txtwin), 
		  GTK_WINDOW (ghack_get_main_window ()) );
	  gnome_dialog_run_and_close (GNOME_DIALOG (txtwin));
	  free(textlines);
        }
}
Exemplo n.º 11
0
int ghack_yes_no_dialog( const char *question, 
		      const char *choices, int def)
{
    int i=0, ret;
    gchar button_name[BUFSZ];
    GtkWidget *box;
    GtkWidget* mainWnd=NULL;

    box = gnome_message_box_new ( question, GNOME_MESSAGE_BOX_QUESTION, NULL);
    /* add buttons for each choice */
    if (!strcmp(GNOME_STOCK_BUTTON_OK, choices)) {
	gnome_dialog_append_button ( GNOME_DIALOG(box), GNOME_STOCK_BUTTON_OK);
	gnome_dialog_set_default( GNOME_DIALOG(box), 0);
	gnome_dialog_set_accelerator( GNOME_DIALOG(box), 0, 'o', 0);
#if 0
	g_print("Setting accelerator '%c' for button %d\n", 'o', 0);
#endif
    }
    else {
	for( ; choices[i]!='\0'; i++) {
	    if (choices[i]=='y') {
		sprintf( button_name, GNOME_STOCK_BUTTON_YES);
	    }
	    else if (choices[i]=='n') {
		sprintf( button_name, GNOME_STOCK_BUTTON_NO);
	    }
	    else if (choices[i] == 'q') {
	        sprintf( button_name, "Quit");
	    } else {
		sprintf( button_name, "%c", choices[i]);
	    }
	    if (def==choices[i])
		gnome_dialog_set_default( GNOME_DIALOG(box), i);
	    gnome_dialog_append_button ( GNOME_DIALOG(box), button_name);
	    gnome_dialog_set_accelerator( GNOME_DIALOG(box), i, choices[i], 0);
#if 0
	    g_print("Setting accelerator '%c' for button %d\n", choices[i], i);
#endif
	}
    }
#if 0
    /* Perhaps add in a quit game button, like this... */
    gnome_dialog_append_button ( GNOME_DIALOG(box), GNOME_STOCK_BUTTON_CLOSE);
    gnome_dialog_set_accelerator( GNOME_DIALOG(box), i, choices[i], 0);
    g_print("Setting accelerator '%c' for button %d\n", 'Q', i);
#endif

    gnome_dialog_set_close(GNOME_DIALOG (box), TRUE);
    mainWnd = ghack_get_main_window ();
    gtk_window_set_modal( GTK_WINDOW(box), TRUE);
    gtk_window_set_title( GTK_WINDOW(box), "GnomeHack");
    if ( mainWnd != NULL ) {
	gnome_dialog_set_parent (GNOME_DIALOG (box), 
		GTK_WINDOW ( mainWnd) );
    }

    ret=gnome_dialog_run_and_close ( GNOME_DIALOG (box));
    
#if 0
    g_print("You selected button %d\n", ret);
#endif
    
    if (ret==-1)
	return( '\033');
    else
	return( choices[ret]);
}
Exemplo n.º 12
0
Arquivo: gat.c Projeto: piki/gat
/** Make a modal ok-cancel dialog and return 1 for ok or 0 for cancel.
 *    @param title The window title (goes in the title bar)
 *    @param label The label (goes above ok and cancel buttons)
 */
int make_ok_cancel_dialog(char *title, char *label) {
  GtkWidget *dialog = gnome_message_box_new(label, GNOME_MESSAGE_BOX_QUESTION,
    GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL);
  gtk_widget_show(dialog);
  return (gnome_dialog_run(GNOME_DIALOG(dialog)) == 0);
}
Exemplo n.º 13
0
int find_update_line_cache(GnomeFindDialog *find_dialog)
{
  int find_text_len;
  int eflags;
  regmatch_t pmatch[1];
  int regex_result;
  char errbuf[ERRBUF_SIZE];
  char messagebuf[MSGBUF_SIZE];
  int strcmp_result;
  int tmp_find_pos;
  gchar *find_line_cache;
  find_selection *find_select;

  GtkWidget *message_dialog;

  /* initialisation */
  find_line_cache = NULL;
  find_text_len = strlen(find_params.find_text);
  line_cache_update = FALSE;

  /* free matches list if necessary */
  if (find_current_match != NULL) {
    find_current_match = g_list_first(find_current_match);
    g_list_foreach(find_current_match, find_free_select, NULL);
    g_list_free(find_current_match);
    find_current_match = NULL;
  }

  /* Move one line */
  switch (find_params.direction) {
  case GNOME_FIND_FORWARDS:
    do {
      if(find_pos > find_pos_max) {
	if(find_params.wrap_search == TRUE) {
	  find_pos = 0;
	  search_wrapped = TRUE;
	}
	else {
	  return GNOME_FIND_NOMATCH;
	}
      }
      else {
	find_pos++;
	if((search_wrapped) && (find_pos >= find_pos_init)) {
	  return GNOME_FIND_NOMATCH;
	}
      }
    } while (find_text_cache[find_pos] == '\n');
    break;
    
  case GNOME_FIND_BACKWARDS:
    do {
      if(find_pos < 0) {
	if(find_params.wrap_search == TRUE) {
	  find_pos = find_pos_max;
	  search_wrapped = TRUE;
	}
	else {
	  return GNOME_FIND_NOMATCH;
	}
      }
      else {
	find_pos--;
	if((search_wrapped) && (find_pos <= find_pos_init)) {
	  return GNOME_FIND_NOMATCH;
	}
      }
    } while (find_text_cache[find_pos] == '\n');
    break;
  }

  line_cache_start = line_cache_end = find_pos;

  while ((line_cache_start > 0) && (find_text_cache[line_cache_start - 1] != '\n')) {
    line_cache_start--;
  }
  while ((line_cache_end < find_pos_max) && (find_text_cache[line_cache_end + 1] != '\n')) {
    line_cache_end++;
  }
  
  /* Grab the line */
  find_line_cache = g_strndup(find_text_cache + line_cache_start,
			      line_cache_end - line_cache_start + 1);

  /* Search line */
  if (find_params.regex == TRUE) {
    /* Regular expression search */
    tmp_find_pos = 0; 
    eflags = 0;
    do {
      if (tmp_find_pos != 0) {
	eflags = REG_NOTBOL;
      }

      /* execute the match */
      regex_result = regexec(preg, find_line_cache + tmp_find_pos, 1, pmatch, eflags);

      if(regex_result == 0) {
	/* construct list item if found */
	find_select = g_new(find_selection, 1);
	find_select->select_start = line_cache_start + tmp_find_pos + pmatch[0].rm_so;
	find_select->select_end = line_cache_start + tmp_find_pos + pmatch[0].rm_eo;
	find_current_match = g_list_append(find_current_match, (gpointer) find_select);

	tmp_find_pos += pmatch[0].rm_so + 1;
      }
      else if (regex_result != REG_NOMATCH) {
	/* report regexec errors and terminate the search */
	regerror(regex_result, preg, errbuf, ERRBUF_SIZE);
	g_snprintf(messagebuf, MSGBUF_SIZE,
		   "Error matching regular expression: %s", errbuf);

	message_dialog = gnome_message_box_new(messagebuf,
					       GNOME_MESSAGE_BOX_ERROR,
					       GNOME_STOCK_BUTTON_OK,
					       NULL);
	if (find_dialog != NULL ) {
	  gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(find_dialog));
	}
	else {
	  gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(R_gtk_main_window));
	}
	gnome_dialog_run_and_close(GNOME_DIALOG(message_dialog));

	if (find_line_cache != NULL) {
	  g_free(find_line_cache);
	}

	return GNOME_FIND_NOMATCH;
      }
    } while ((tmp_find_pos <= (line_cache_end - line_cache_start)) && (regex_result == 0));
  }
  else {
    /* Literal search */
    for (tmp_find_pos = line_cache_start; tmp_find_pos <= line_cache_end; tmp_find_pos++) {
      if (find_params.case_sensitive == TRUE) {
	strcmp_result = strncmp(find_params.find_text,
				find_text_cache + tmp_find_pos,	find_text_len);
      }
      else {
	strcmp_result = g_strncasecmp(find_params.find_text,
				      find_text_cache + tmp_find_pos, 
				      find_text_len);
      }

      /* construct list item if found */
      if(strcmp_result == 0) {
	find_select = g_new(find_selection, 1);
	find_select->select_start = tmp_find_pos;
	find_select->select_end = tmp_find_pos + find_text_len;
	find_current_match = g_list_append(find_current_match, (gpointer) find_select);
      }
    }
  }

  if (find_line_cache != NULL) {
    g_free(find_line_cache);
  }

  /* Return result */
  if (find_current_match != NULL) {
    if(find_params.direction == GNOME_FIND_BACKWARDS)
      find_current_match = g_list_last(find_current_match);
    return GNOME_FIND_MATCH;
  }

  return GNOME_FIND_NOTFOUND;
}