コード例 #1
0
static gchar *
convert_keysym_state_to_string (GtkCellRendererAccel *accel,
				guint                 keysym,
                                GdkModifierType       mask,
				guint                 keycode)
{
  if (keysym == 0 && keycode == 0)
    /* This label is displayed in a treeview cell displaying
     * a disabled accelerator key combination.
     */
    return g_strdup (C_("Accelerator", "Disabled"));
  else 
    {
      if (accel->accel_mode == GTK_CELL_RENDERER_ACCEL_MODE_GTK)
	return gtk_accelerator_get_label (keysym, mask);
      else 
	{
	  gchar *name;

	  name = gtk_accelerator_name (keysym, mask);
	  if (keysym == 0)
	    {
	      gchar *tmp;

	      tmp = name;
	      name = g_strdup_printf ("%s0x%02x", tmp, keycode);
	      g_free (tmp);
	    }

	  return name;
	}
    }
}
コード例 #2
0
ファイル: fkeys.c プロジェクト: CardinalSins/hexchat
static void
key_dialog_load (GtkListStore *store)
{
	struct key_binding *kb = NULL;
	char *label_text, *accel_text;
	GtkTreeIter iter;
	GSList *list = keybind_list;

	while (list)
	{
		kb = (struct key_binding*)list->data;

		label_text = gtk_accelerator_get_label (kb->keyval, kb->mod);
		accel_text = gtk_accelerator_name (kb->keyval, kb->mod);

		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter,
							KEY_COLUMN, label_text,
							ACCEL_COLUMN, accel_text,
							ACTION_COLUMN, key_actions[kb->action].name,
							D1_COLUMN, kb->data1,
							D2_COLUMN, kb->data2, -1);

		g_free (accel_text);
		g_free (label_text);

		list = g_slist_next (list);
	}
}
コード例 #3
0
ファイル: accelerators.c プロジェクト: Azania/java-gnome
int main(int argc, char **argv) {
	gtk_init(&argc, &argv);

	printf("%s\n", gtk_accelerator_name(GDK_q, GDK_CONTROL_MASK));
	printf("%s\n", gtk_accelerator_get_label(GDK_q, GDK_CONTROL_MASK));

	return 0;
}
コード例 #4
0
static char*
binding_display_name (guint            keyval,
                      GdkModifierType  mask)
{
	if (keyval != 0)
		return gtk_accelerator_get_label (keyval, mask);

	return g_strdup (_("Disabled"));
}
コード例 #5
0
ファイル: colorlabel.c プロジェクト: eworm-de/claws-mail
/* colorlabel_create_check_color_menu_item() - creates a color
 * menu item with a check box */
GtkWidget *colorlabel_create_check_color_menu_item(gint color_index, gboolean force, gint menu_index)
{
	GtkWidget *label; 
	GtkWidget *hbox; 
	GtkWidget *vbox; 
	GtkWidget *item;
	gchar *accel;
	
	G_RETURN_VAL_IF_INVALID_COLOR(color_index, NULL);

	item = gtk_check_menu_item_new();

	if (force) {
		label_colors[menu_index][color_index].changed |= LCCF_COLOR;
		label_colors[menu_index][color_index].changed |= LCCF_LABEL;
	}
	colorlabel_recreate(color_index);

	/* XXX: gnome-core::panel::menu.c is a great example of
	 * how to create pixmap menus */
	label = gtk_label_new(label_colors[menu_index][color_index].label);

	gtk_widget_show(label);
	hbox = gtk_hbox_new(FALSE, 0);
	gtk_widget_show(hbox);
	gtk_container_add(GTK_CONTAINER(item), hbox);

	vbox = gtk_vbox_new(TRUE, 0);
	gtk_widget_show(vbox);
	gtk_container_set_border_width(GTK_CONTAINER(vbox), 1);

	gtk_container_add(GTK_CONTAINER(vbox),
			  label_colors[menu_index][color_index].widget);
	gtk_widget_show(label_colors[menu_index][color_index].widget);

	gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 4);
	if (color_index < 9) {
		accel = gtk_accelerator_get_label(GDK_KEY_1+color_index, GDK_CONTROL_MASK);
		label = gtk_label_new(accel);
		gtk_widget_show(label);
		gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
		g_free(accel);
		gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 4);
		g_object_set_data(G_OBJECT(item), "accel_label", label);
	} else {
		label = gtk_label_new("");
		gtk_widget_show(label);
		gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
		gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 4);
		g_object_set_data(G_OBJECT(item), "accel_label", label);
	}
	return item;
}
コード例 #6
0
ファイル: snippets.c プロジェクト: bqv/gummi-vim
void snippets_accel_connect (GuSnippets* sc, guint keyval, GdkModifierType mod,
        GClosure* closure) {
    gchar* acc = NULL;
    gtk_accel_group_connect (sc->accel_group, keyval,
            gtk_accelerator_get_default_mod_mask () & mod, GTK_ACCEL_VISIBLE,
            closure);

    acc = gtk_accelerator_get_label (keyval,
            gtk_accelerator_get_default_mod_mask () & mod);
    slog (L_DEBUG, "Accelerator `%s' connected\n", acc);
    g_free (acc);
}
コード例 #7
0
ファイル: gimpwidgets-utils.c プロジェクト: Amerekanets/gimp
static void
gimp_widget_accel_changed (GtkAccelGroup   *accel_group,
                           guint            unused1,
                           GdkModifierType  unused2,
                           GClosure        *accel_closure,
                           GtkWidget       *widget)
{
  GClosure *widget_closure;

  widget_closure = g_object_get_data (G_OBJECT (widget), "gimp-accel-closure");

  if (accel_closure == widget_closure)
    {
      GtkAction   *action;
      GtkAccelKey *accel_key;
      gchar       *orig_tooltip;
      gchar       *tooltip;
      const gchar *help_id;

      action = g_object_get_data (G_OBJECT (widget), "gimp-accel-action");

      g_object_get (action, "tooltip", &orig_tooltip, NULL);
      help_id = g_object_get_qdata (G_OBJECT (action), GIMP_HELP_ID);

      accel_key = gtk_accel_group_find (accel_group,
                                        gimp_widget_accel_find_func,
                                        accel_closure);

      if (accel_key            &&
          accel_key->accel_key &&
          accel_key->accel_flags & GTK_ACCEL_VISIBLE)
        {
          gchar *accel = gtk_accelerator_get_label (accel_key->accel_key,
                                                    accel_key->accel_mods);

          tooltip = g_strdup_printf ("%s  (%s)", orig_tooltip, accel);
          g_free (accel);
        }
      else
        {
          tooltip = g_strdup (orig_tooltip);
        }

      gimp_help_set_help_data (widget, tooltip, help_id);

      g_free (tooltip);
      g_free (orig_tooltip);
    }
}
コード例 #8
0
static void
gimp_widget_accel_changed (GtkAccelGroup   *accel_group,
                           guint            unused1,
                           GdkModifierType  unused2,
                           GClosure        *accel_closure,
                           GtkWidget       *widget)
{
  GClosure *widget_closure;

  widget_closure = g_object_get_data (G_OBJECT (widget), "gimp-accel-closure");

  if (accel_closure == widget_closure)
    {
      GtkAction   *action;
      GtkAccelKey *accel_key;
      const gchar *tooltip;
      const gchar *help_id;

      action = g_object_get_data (G_OBJECT (widget), "gimp-accel-action");

      tooltip = gtk_action_get_tooltip (action);
      help_id = g_object_get_qdata (G_OBJECT (action), GIMP_HELP_ID);

      accel_key = gtk_accel_group_find (accel_group,
                                        gimp_widget_accel_find_func,
                                        accel_closure);

      if (accel_key            &&
          accel_key->accel_key &&
          accel_key->accel_flags & GTK_ACCEL_VISIBLE)
        {
          gchar *escaped = g_markup_escape_text (tooltip, -1);
          gchar *accel   = gtk_accelerator_get_label (accel_key->accel_key,
                                                      accel_key->accel_mods);
          gchar *tmp     = g_strdup_printf ("%s  <b>%s</b>", escaped, accel);

          g_free (accel);
          g_free (escaped);

          gimp_help_set_help_data_with_markup (widget, tmp, help_id);
          g_free (tmp);
        }
      else
        {
          gimp_help_set_help_data (widget, tooltip, help_id);
        }
    }
}
コード例 #9
0
ファイル: accelgroup.c プロジェクト: amery/clip-angelo
int
clip_GTK_ACCELERATORGETLABEL(ClipMachine * ClipMachineMemory)
{
   guint     accelerator_key = _clip_parni(ClipMachineMemory, 1);

   GdkModifierType type = _clip_parni(ClipMachineMemory, 2);

   gchar    *label;

   CHECKARG(1, NUMERIC_type_of_ClipVarType);
   CHECKARG(2, NUMERIC_type_of_ClipVarType);

   label = gtk_accelerator_get_label(accelerator_key, type);

   LOCALE_FROM_UTF(label);
   _clip_retc(ClipMachineMemory, label);
   FREE_TEXT(label);

   return 0;
 err:
   return 1;
}
コード例 #10
0
ファイル: accelerator.cpp プロジェクト: xonotic/netradient
void accelerator_write( const Accelerator& accelerator, TextOutputStream& ostream ){
#if 0
	if ( accelerator.modifiers & GDK_SHIFT_MASK ) {
		ostream << "Shift + ";
	}
	if ( accelerator.modifiers & GDK_MOD1_MASK ) {
		ostream << "Alt + ";
	}
	if ( accelerator.modifiers & GDK_CONTROL_MASK ) {
		ostream << "Control + ";
	}

	const char* keyName = global_keys_find( accelerator.key );
	if ( !string_empty( keyName ) ) {
		ostream << keyName;
	}
	else
	{
		ostream << static_cast<char>( accelerator.key );
	}
#endif
	ostream << gtk_accelerator_get_label( accelerator.key, accelerator.modifiers );
}
コード例 #11
0
ファイル: fkeys.c プロジェクト: CardinalSins/hexchat
static void
key_dialog_set_key (GtkCellRendererAccel *accel, gchar *pathstr, guint accel_key, 
					GdkModifierType accel_mods, guint hardware_keycode, gpointer userdata)
{
	GtkTreeModel *model = get_store ();
	GtkTreePath *path = gtk_tree_path_new_from_string (pathstr);
	GtkTreeIter iter;
	gchar *label_name, *accel_name;

	/* Shift tab requires an exception, hopefully that list ends here.. */
	if (accel_key == GDK_KEY_Tab && accel_mods & GDK_SHIFT_MASK)
		accel_key = GDK_KEY_ISO_Left_Tab;

	label_name = gtk_accelerator_get_label (accel_key, key_modifier_get_valid (accel_mods));
	accel_name = gtk_accelerator_name (accel_key, key_modifier_get_valid (accel_mods));

	gtk_tree_model_get_iter (model, &iter, path);
	gtk_list_store_set (GTK_LIST_STORE (model), &iter, KEY_COLUMN, label_name,
						ACCEL_COLUMN, accel_name, -1);

	gtk_tree_path_free (path);
	g_free (label_name);
	g_free (accel_name);
}
コード例 #12
0
ファイル: hotkey_editor.c プロジェクト: esotericnomen/artha
static void accel_edited_callback(GtkCellRendererText *cell, const char *path_string, guint accel_key, 
				  GdkModifierType accel_mods, guint hardware_keycode, gpointer data)
{
	GtkTreeView *view = (GtkTreeView *)data;
	GtkTreeModel *model = NULL;
	GtkTreeIter iter = {0};
	GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
	GtkAccelKey *key_entry = NULL, temp_key = {0};
	GtkWidget *msg_dialog = NULL;
	gchar *temp_str = NULL;

	model = gtk_tree_view_get_model (view);
	gtk_tree_model_get_iter (model, &iter, path);
	gtk_tree_path_free (path);
	gtk_tree_model_get (model, &iter, HOTKEY_COLUMN, &key_entry, -1);

	/* sanity check and check to see if the same key combo was pressed again */
	if (key_entry == NULL || 
	(key_entry->accel_key == accel_key && 
	key_entry->accel_mods == accel_mods && 
	key_entry->accel_flags == hardware_keycode))
		return;

	/* CapsLock isn't supported as a keybinding modifier, so keep it from confusing us */
	accel_mods &= ~GDK_LOCK_MASK;

	temp_key.accel_key = accel_key;
	temp_key.accel_flags = hardware_keycode;
	temp_key.accel_mods   = accel_mods;


	/* Check for unmodified keys */
	if (temp_key.accel_mods == 0 && temp_key.accel_key != 0)
	{
		if ((temp_key.accel_key >= GDK_a && temp_key.accel_key <= GDK_z)
		   || (temp_key.accel_key >= GDK_A && temp_key.accel_key <= GDK_Z)
		   || (temp_key.accel_key >= GDK_0 && temp_key.accel_key <= GDK_9)
		   || (temp_key.accel_key >= GDK_kana_fullstop && temp_key.accel_key <= GDK_semivoicedsound)
		   || (temp_key.accel_key >= GDK_Arabic_comma && temp_key.accel_key <= GDK_Arabic_sukun)
		   || (temp_key.accel_key >= GDK_Serbian_dje && temp_key.accel_key <= GDK_Cyrillic_HARDSIGN)
		   || (temp_key.accel_key >= GDK_Greek_ALPHAaccent && temp_key.accel_key <= GDK_Greek_omega)
		   || (temp_key.accel_key >= GDK_hebrew_doublelowline && temp_key.accel_key <= GDK_hebrew_taf)
		   || (temp_key.accel_key >= GDK_Thai_kokai && temp_key.accel_key <= GDK_Thai_lekkao)
		   || (temp_key.accel_key >= GDK_Hangul && temp_key.accel_key <= GDK_Hangul_Special)
		   || (temp_key.accel_key >= GDK_Hangul_Kiyeog && temp_key.accel_key <= GDK_Hangul_J_YeorinHieuh)
		   || keyval_is_forbidden (temp_key.accel_key))
		{
			temp_str = gtk_accelerator_get_label (accel_key, accel_mods);

			msg_dialog = gtk_message_dialog_new (
						GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view))),
						GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
						GTK_MESSAGE_WARNING,
						GTK_BUTTONS_OK, 
						STR_INVALID_HOTKEY, 
						temp_str);
			g_object_set(msg_dialog, "title", STR_INVALID_HOTKEY_TITLE, NULL);

			g_free (temp_str); temp_str = NULL;
			gtk_dialog_run (GTK_DIALOG (msg_dialog));
			gtk_widget_destroy (msg_dialog);
			msg_dialog = NULL;

			return;
		}
	}

	/* try registering the new key combo */
	if(grab_ungrab_with_ignorable_modifiers(&temp_key, TRUE))
	{
		/* unregistering previous hotkey is not necessary on Win32
		   since the same prev. hotkey is modified to the new one */
#ifndef G_OS_WIN32
		/* unregister the previous hotkey */
		grab_ungrab_with_ignorable_modifiers(key_entry, FALSE);
#endif

		/* set the value in the list store to the newly set key combo
		   so that it gets reflected in the Accel Cell Renderer */
		key_entry->accel_key = accel_key;
		key_entry->accel_flags = hardware_keycode;
		key_entry->accel_mods = accel_mods;
	}
	else
	{
		temp_str = gtk_accelerator_get_label (accel_key, accel_mods);

		msg_dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view))),
							GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
							GTK_MESSAGE_WARNING,
							GTK_BUTTONS_OK, 
							STR_DUPLICATE_HOTKEY, 
							temp_str);
		g_object_set(msg_dialog, "title", STR_INVALID_HOTKEY_TITLE, NULL);

		g_free (temp_str); temp_str = NULL;
		gtk_dialog_run (GTK_DIALOG (msg_dialog));
		gtk_widget_destroy (msg_dialog);

		return;
	}
}
コード例 #13
0
static void
accel_edited_callback (GtkCellRendererAccel *cell,
                       gchar                *path_string,
                       guint                 keyval,
                       GdkModifierType       mask,
                       guint                 hardware_keycode,
                       GtkTreeView          *view)
{
	GtkTreeModel *model;
	GtkTreePath *path;
	GtkTreeIter iter;
	KeyEntry *ke;
	GtkAccelGroupEntry *entries;
	guint n_entries;
	char *str;

	model = gtk_tree_view_get_model (view);

	path = gtk_tree_path_new_from_string (path_string);
	if (!path)
		return;

	if (!gtk_tree_model_get_iter (model, &iter, path))
	{
		gtk_tree_path_free (path);
		return;
	}
	gtk_tree_path_free (path);

	gtk_tree_model_get (model, &iter, KEYVAL_COLUMN, &ke, -1);

	/* sanity check */
	if (ke == NULL)
		return;

	/* Check if we already have an entry using this accel */
	entries = gtk_accel_group_query (notification_group, keyval, mask, &n_entries);
	if (n_entries > 0)
	{
		if (entries[0].accel_path_quark != g_quark_from_string (ke->accel_path))
		{
			GtkWidget *dialog;
			char *name;
			KeyEntry *other_key;

			name = gtk_accelerator_get_label (keyval, mask);
			other_key = entries[0].closure->data;
			g_assert (other_key);

			dialog =
			    gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view))),
			                            GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
			                            GTK_MESSAGE_WARNING,
			                            GTK_BUTTONS_OK,
			                            _("The shortcut key “%s” is already bound to the “%s” action"),
			                            name,

other_key->user_visible_name ? _(other_key->user_visible_name) : other_key->gsettings_key);
			g_free (name);

			g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
			gtk_window_present (GTK_WINDOW (dialog));
		}

		return;
	}

	str = binding_name (keyval, mask);

	_terminal_debug_print (TERMINAL_DEBUG_ACCELS,
	                       "Edited path %s keyval %s, setting GSettings to %s\n",
	                       ke->accel_path,
	                       gdk_keyval_name (keyval) ? gdk_keyval_name (keyval) : "null",
	                       str);
#ifdef MATE_ENABLE_DEBUG
	_TERMINAL_DEBUG_IF (TERMINAL_DEBUG_ACCELS)
	{
		GtkAccelKey old_key;

		if (gtk_accel_map_lookup_entry (ke->accel_path, &old_key))
		{
			_terminal_debug_print (TERMINAL_DEBUG_ACCELS,
			                       "  Old entry of path %s is keyval %s mask %x\n",
			                       ke->accel_path, gdk_keyval_name (old_key.accel_key), old_key.accel_mods);
		}
		else
		{
			_terminal_debug_print (TERMINAL_DEBUG_ACCELS,
			                       "  Failed to look up the old entry of path %s\n",
			                       ke->accel_path);
		}
	}
#endif

	g_settings_set_string (settings_keybindings,
	                       ke->gsettings_key,
	                       str);
	g_free (str);
}
コード例 #14
0
ファイル: gimpactionview.c プロジェクト: Gnilichko/gimp
static void
gimp_action_view_conflict_confirm (GimpActionView  *view,
                                   GtkAction       *action,
                                   guint            accel_key,
                                   GdkModifierType  accel_mask,
                                   const gchar     *accel_path)
{
  GimpActionGroup *group;
  gchar           *label;
  gchar           *accel_string;
  ConfirmData     *confirm_data;
  GtkWidget       *dialog;
  GimpMessageBox  *box;

  g_object_get (action, "action-group", &group, NULL);

  label = gimp_strip_uline (gtk_action_get_label (action));

  accel_string = gtk_accelerator_get_label (accel_key, accel_mask);

  confirm_data = g_slice_new (ConfirmData);

  confirm_data->manager    = view->manager;
  confirm_data->accel_path = g_strdup (accel_path);
  confirm_data->accel_key  = accel_key;
  confirm_data->accel_mask = accel_mask;

  dialog =
    gimp_message_dialog_new (_("Conflicting Shortcuts"),
                             GIMP_STOCK_WARNING,
                             gtk_widget_get_toplevel (GTK_WIDGET (view)), 0,
                             gimp_standard_help_func, NULL,

                             GTK_STOCK_CANCEL,         GTK_RESPONSE_CANCEL,
                             _("_Reassign shortcut"),  GTK_RESPONSE_OK,

                             NULL);

  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);
  g_signal_connect (dialog, "response",
                    G_CALLBACK (gimp_action_view_conflict_response),
                    confirm_data);

  box = GIMP_MESSAGE_DIALOG (dialog)->box;

  gimp_message_box_set_primary_text (box,
                                     _("Shortcut \"%s\" is already taken "
                                       "by \"%s\" from the \"%s\" group."),
                                     accel_string, label, group->label);
  gimp_message_box_set_text (box,
                             _("Reassigning the shortcut will cause it "
                               "to be removed from \"%s\"."),
                             label);

  g_free (label);
  g_free (accel_string);

  g_object_unref (group);

  gtk_widget_show (dialog);
}
コード例 #15
0
ファイル: gui.c プロジェクト: Alex-Sjoberg/Pioneers
/** Show the accelerators in the toolbar */
static void gui_toolbar_show_accelerators(gboolean show_accelerators)
{
	GtkToolbar *tb;
	gint n, i;

	toolbar_show_accelerators = show_accelerators;

	tb = GTK_TOOLBAR(toolbar);

	n = gtk_toolbar_get_n_items(tb);
	for (i = 0; i < n; i++) {
		GtkToolItem *ti;
		GtkToolButton *tbtn;
		gchar *text;
		gint j;

		ti = gtk_toolbar_get_nth_item(tb, i);
		tbtn = GTK_TOOL_BUTTON(ti);
		g_assert(tbtn != NULL);
		if (gtk_major_version == 2 && gtk_minor_version == 10) {
			/* Work around a gtk+ 2.10 bug (#434261) that
			 * mishandles strings like (Fn) in labels.
			 */
			/** @todo BW 2007-04-29 Remove this when gtk 2.10
			 * is no longer supported. */
			gtk_tool_button_set_use_underline(tbtn, FALSE);
		}
		text = g_strdup(gtk_tool_button_get_label(tbtn));
		if (strchr(text, '\n'))
			*strchr(text, '\n') = '\0';
		/* Find the matching entry */
		for (j = 0; j < G_N_ELEMENTS(entries); j++) {
			if (strcmp(text, _(entries[j].label)) == 0) {
				if (show_accelerators) {
					gchar *label;

					if (entries[j].accelerator == NULL
					    ||
					    strlen(entries[j].accelerator)
					    == 0)
						label =
						    g_strdup_printf("%s\n",
								    text);
					else {
						gchar *accelerator_text;
						guint accelerator_key;
						GdkModifierType
						    accelerator_mods;
						gtk_accelerator_parse
						    (entries
						     [j].accelerator,
						     &accelerator_key,
						     &accelerator_mods);
						accelerator_text =
						    gtk_accelerator_get_label
						    (accelerator_key,
						     accelerator_mods);
						label =
						    g_strdup_printf
						    ("%s\n(%s)", text,
						     accelerator_text);
						g_free(accelerator_text);
					}
					gtk_tool_button_set_label(tbtn,
								  label);
					g_free(label);
				} else {
					gtk_tool_button_set_label(tbtn,
								  _(entries
								    [j].
								    label));
				}
				break;
			}
		}
		g_free(text);
	}
	config_set_int("settings/toolbar_show_accelerators",
		       toolbar_show_accelerators);
}
コード例 #16
0
ファイル: xfce-shortcuts.c プロジェクト: canatella/libxfce4ui
gint
xfce_shortcut_conflict_dialog (GtkWindow   *parent,
                               const gchar *owner,
                               const gchar *other,
                               const gchar *shortcut,
                               const gchar *owner_action,
                               const gchar *other_action,
                               gboolean     ignore_same_provider)
{
  GdkModifierType  modifiers;
  gboolean         handled;
  gchar           *other_action_name;
  gchar           *other_button_text;
  gchar           *owner_action_name;
  gchar           *owner_button_text;
  gchar           *secondary_text;
  gchar           *shortcut_label;
  gchar           *title;
  guint            keyval;
  gint             response;
  gint             i;

  /* Default values */
  response = GTK_RESPONSE_ACCEPT;
  handled = FALSE;

  /* Make sure to use the translations from libxfce4ui */
  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

  if (g_utf8_collate (owner, other) == 0 && ignore_same_provider)
    return GTK_RESPONSE_ACCEPT;

  /* Get the shortcut label */
  gtk_accelerator_parse (shortcut, &keyval, &modifiers);
  shortcut_label = gtk_accelerator_get_label (keyval, modifiers);

  if (g_utf8_collate (owner, other) == 0 && g_utf8_collate (owner_action, other_action) == 0)
    {
      /* This shortcut already exists in the provider, we don't want it twice */

      /* Warn the user */
      xfce_dialog_show_warning (parent, _("Please use another key combination."),
                                _("%s already triggers this action."), shortcut_label);

      return GTK_RESPONSE_REJECT;
    }

  title = g_strdup_printf (_("Conflicting actions for %s"), shortcut_label);

  for (i = 0; conflict_messages[i].message != NULL; ++i)
    if (g_utf8_collate (conflict_messages[i].owner_name, owner) == 0 &&
        g_utf8_collate (conflict_messages[i].other_name, other) == 0)
      {
        if (owner_action == NULL)
          owner_action_name = NULL;
        else if (g_utf8_collate (owner, "xfwm4") == 0)
          {
            DBG ("Owner action %s is an xfwm4 action, get the string", owner_action);

            /* We need to get the human readable string of the action name */
            owner_action_name =
              g_strdup (xfce_shortcuts_xfwm4_get_feature_name (owner_action));

          }
        else
          owner_action_name = g_strdup(owner_action);

        DBG ("Owner action name: %s", owner_action_name);

        if (other_action == NULL)
          other_action_name = NULL;
        else if (g_utf8_collate (other, "xfwm4") == 0)
          {
            /* We need to get the human readable string of the action name */

            other_action_name =
              g_strdup (xfce_shortcuts_xfwm4_get_feature_name (other_action));

          }
        else
          other_action_name = g_strdup (other_action);

        secondary_text = g_strdup_printf (_(conflict_messages[i].message), other_action_name);

        owner_button_text = g_strdup_printf (_(conflict_messages[i].owner_button_text), owner_action_name);
        other_button_text = g_strdup_printf (_(conflict_messages[i].other_button_text), other_action_name);

        response = xfce_message_dialog (parent, title, GTK_STOCK_DIALOG_QUESTION,
                                        title, secondary_text,
                                        XFCE_BUTTON_TYPE_MIXED, NULL, owner_button_text, GTK_RESPONSE_ACCEPT,
                                        XFCE_BUTTON_TYPE_MIXED, NULL, other_button_text, GTK_RESPONSE_REJECT,
                                        NULL);

        g_free (other_button_text);
        g_free (owner_button_text);
        g_free (secondary_text);
        g_free (other_action_name);
        g_free (owner_action_name);
        g_free (shortcut_label);

        handled = TRUE;
        break;
      }

  if (G_UNLIKELY (!handled))
    {
      xfce_message_dialog (parent, title, GTK_STOCK_DIALOG_ERROR,
                           title, _("This shortcut is already being used for something else."),
                           GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
      response = GTK_RESPONSE_REJECT;
    }

  g_free (title);

  return response;
}
コード例 #17
0
StdStrBuf C4KeyCodeEx::KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool fShort)
{
	// Gamepad keys
	if (Key_IsGamepad(wCode))
	{
		int iGamepad = Key_GetGamepad(wCode);
		int gamepad_event = Key_GetGamepadEvent(wCode);
		switch (gamepad_event)
		{
		case KEY_JOY_Left:  return FormatString("Joy%dLeft", iGamepad+1);
		case KEY_JOY_Up:    return FormatString("Joy%dUp", iGamepad+1);
		case KEY_JOY_Down:  return FormatString("Joy%dDown", iGamepad+1);
		case KEY_JOY_Right: return FormatString("Joy%dRight", iGamepad+1);
		default:
			if (Key_IsGamepadAxis(wCode))
			{
				if (fHumanReadable)
					// This is still not great, but it is not really possible to assign unknown axes to "left/right" "up/down"...
					return FormatString("[%d] %s", int(1 + Key_GetGamepadAxisIndex(wCode)), Key_IsGamepadAxisHigh(wCode) ? "Max" : "Min");
				else
					return FormatString("Joy%dAxis%d%s", iGamepad+1, static_cast<int>(Key_GetGamepadAxisIndex(wCode)+1), Key_IsGamepadAxisHigh(wCode) ? "Max" : "Min");
			}
			else
			{
				// button
				if (fHumanReadable)
					// If there should be gamepads around with A B C D... on the buttons, we might create a display option to show letters instead...
					return FormatString("< %d >", int(1 + Key_GetGamepadButtonIndex(wCode)));
				else
					return FormatString("Joy%d%c", iGamepad+1, static_cast<char>(Key_GetGamepadButtonIndex(wCode) + 'A'));
			}
		}
	}
	// Mouse keys
	if (Key_IsMouse(wCode))
	{
		int mouse_id = Key_GetMouse(wCode);
		int mouse_event = Key_GetMouseEvent(wCode);
		const char *mouse_str = "Mouse";
		switch (mouse_event)
		{
		case KEY_MOUSE_Move:              return FormatString("%s%dMove", mouse_str, mouse_id);
		case KEY_MOUSE_Wheel1Up:          return FormatString("%s%dWheel1Up", mouse_str, mouse_id);
		case KEY_MOUSE_Wheel1Down:        return FormatString("%s%dWheel1Down", mouse_str, mouse_id);
		case KEY_MOUSE_ButtonLeft:        return FormatString("%s%dLeft", mouse_str, mouse_id);
		case KEY_MOUSE_ButtonRight:       return FormatString("%s%dRight", mouse_str, mouse_id);
		case KEY_MOUSE_ButtonMiddle:      return FormatString("%s%dMiddle", mouse_str, mouse_id);
		case KEY_MOUSE_ButtonLeftDouble:  return FormatString("%s%dLeftDouble", mouse_str, mouse_id);
		case KEY_MOUSE_ButtonRightDouble: return FormatString("%s%dRightDouble", mouse_str, mouse_id);
		case KEY_MOUSE_ButtonMiddleDouble:return FormatString("%s%dMiddleDouble", mouse_str, mouse_id);
		default:
			// extended mouse button
		{
			uint8_t btn = Key_GetMouseEvent(wCode);
			if (btn >= KEY_MOUSE_Button1Double)
				return FormatString("%s%dButton%dDouble", mouse_str, mouse_id, int(btn-KEY_MOUSE_Button1Double));
			else
				return FormatString("%s%dButton%d", mouse_str, mouse_id, int(btn-KEY_MOUSE_Button1));
		}
		}
	}

	// it's a keyboard key
	if (!fHumanReadable) {
		// for config files and such: dump scancode
		return FormatString("$%x", static_cast<unsigned int>(wCode));
	}
#if defined(_WIN32)

//  TODO: Works?
//  StdStrBuf Name; Name.SetLength(1000);
//  int res = GetKeyNameText(wCode, Name.getMData(), Name.getSize());
//  if(!res)
//    // not found: Compose as direct code
//    return FormatString("\\x%x", (DWORD) wCode);
//  // Set size
//  Name.SetLength(res);
//  return Name;

	wchar_t buf[100];
	int len = GetKeyNameText(wCode<<16, buf, 100);
	if (len > 0) {
		// buf is nullterminated name
		return StdStrBuf(buf);
	}
#elif defined (USE_COCOA)
	// query map
	const C4KeyCodeMapEntry *pCheck = KeyCodeMap;
	while (pCheck->szName)
			if (wCode == pCheck->wCode) return StdStrBuf((pCheck->szShortName && fShort) ? pCheck->szShortName : pCheck->szName); else ++pCheck;
	// not found: Compose as direct code
	return FormatString("\\x%x", static_cast<unsigned int>(wCode));
#elif defined(USE_X11)
	Display * const dpy = gdk_x11_display_get_xdisplay(gdk_display_get_default());
	KeySym keysym = (KeySym)XkbKeycodeToKeysym(dpy,wCode+8,0,0);
	char* name = NULL;
	if (keysym != NoSymbol) { // is the keycode without shift modifiers mapped to a symbol?
		#if defined(USE_GTK3)
		name = gtk_accelerator_get_label_with_keycode(dpy, keysym, wCode+8, (GdkModifierType)0);
		#else
		name = gtk_accelerator_get_label(keysym, (GdkModifierType)0);
		#endif
	}
	if (name) { // is there a string representation of the keysym?
		// prevent memleak
		StdStrBuf buf;
		buf.Take(name);
		return buf;
	}
#elif defined(USE_SDL_MAINLOOP)
	return StdStrBuf(getKeyName(wCode).c_str());
#endif
	return FormatString("$%x", static_cast<unsigned int>(wCode));
}
コード例 #18
0
ファイル: debug-commands.c プロジェクト: AjayRamanathan/gimp
void
debug_dump_keyboard_shortcuts_cmd_callback (GtkAction *action,
                                            gpointer   data)
{
  GimpDisplay      *display;
  GimpImageWindow  *window;
  GtkUIManager     *manager;
  GtkAccelGroup    *accel_group;
  GList            *group_it;
  GList            *strings = NULL;
  return_if_no_display (display, data);

  window  = gimp_display_shell_get_window (gimp_display_get_shell (display));
  manager = GTK_UI_MANAGER (gimp_image_window_get_ui_manager (window));

  accel_group = gtk_ui_manager_get_accel_group (manager);

  /* Gather formated strings of keyboard shortcuts */
  for (group_it = gtk_ui_manager_get_action_groups (manager);
       group_it;
       group_it = g_list_next (group_it))
    {
      GimpActionGroup *group     = group_it->data;
      GList           *actions   = NULL;
      GList           *action_it = NULL;

      actions = gtk_action_group_list_actions (GTK_ACTION_GROUP (group));
      actions = g_list_sort (actions, (GCompareFunc) gimp_action_name_compare);

      for (action_it = actions; action_it; action_it = g_list_next (action_it))
        {
          GtkAction   *action        = action_it->data;
          const gchar *name          = gtk_action_get_name (action);
          GClosure    *accel_closure = NULL;

          if (strstr (name, "-menu")  ||
              strstr (name, "-popup") ||
              name[0] == '<')
              continue;

          accel_closure = gtk_action_get_accel_closure (action);

          if (accel_closure)
            {
              GtkAccelKey *key = gtk_accel_group_find (accel_group,
                                                       debug_accel_find_func,
                                                       accel_closure);
              if (key            &&
                  key->accel_key &&
                  key->accel_flags & GTK_ACCEL_VISIBLE)
                {
                  const gchar *label_tmp;
                  gchar       *label;
                  gchar       *key_string;

                  label_tmp  = gtk_action_get_label (action);
                  label      = gimp_strip_uline (label_tmp);
                  key_string = gtk_accelerator_get_label (key->accel_key,
                                                          key->accel_mods);

                  strings = g_list_prepend (strings,
                                            g_strdup_printf ("%-20s %s",
                                                             key_string, label));

                  g_free (key_string);
                  g_free (label);
                }
            }
        }

      g_list_free (actions);
    }

  /* Sort and prints the strings */
  {
    GList *string_it = NULL;

    strings = g_list_sort (strings, (GCompareFunc) strcmp);

    for (string_it = strings; string_it; string_it = g_list_next (string_it))
      {
        g_print ("%s\n", (gchar *) string_it->data);
        g_free (string_it->data);
      }

    g_list_free (strings);
  }
}
コード例 #19
0
static void
gimp_display_shell_close_dialog (GimpDisplayShell *shell,
                                 GimpImage        *image)
{
  GtkWidget       *dialog;
  GimpMessageBox  *box;
  GtkWidget       *label;
  GtkAccelGroup   *accel_group;
  GClosure        *closure;
  GSource         *source;
  guint            accel_key;
  GdkModifierType  accel_mods;
  gchar           *title;
  gchar           *accel_string;
  gchar           *hint;
  gchar           *markup;
  GFile           *file;

  if (shell->close_dialog)
    {
      gtk_window_present (GTK_WINDOW (shell->close_dialog));
      return;
    }

  file = gimp_image_get_file (image);

  title = g_strdup_printf (_("Close %s"), gimp_image_get_display_name (image));

  shell->close_dialog =
    dialog = gimp_message_dialog_new (title, "document-save",
                                      GTK_WIDGET (shell),
                                      GTK_DIALOG_DESTROY_WITH_PARENT,
                                      gimp_standard_help_func, NULL,
                                      NULL);
  g_free (title);

  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
                          _("_Discard Changes"), GTK_RESPONSE_CLOSE,
                          GTK_STOCK_CANCEL,      GTK_RESPONSE_CANCEL,
                          (file ?
                           GTK_STOCK_SAVE :
                           GTK_STOCK_SAVE_AS),   RESPONSE_SAVE,
                          NULL);

  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);

  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                           RESPONSE_SAVE,
                                           GTK_RESPONSE_CLOSE,
                                           GTK_RESPONSE_CANCEL,
                                           -1);

  g_signal_connect (dialog, "destroy",
                    G_CALLBACK (gtk_widget_destroyed),
                    &shell->close_dialog);

  g_signal_connect (dialog, "response",
                    G_CALLBACK (gimp_display_shell_close_response),
                    shell);

  /* connect <Primary>D to the quit/close button */
  accel_group = gtk_accel_group_new ();
  gtk_window_add_accel_group (GTK_WINDOW (shell->close_dialog), accel_group);
  g_object_unref (accel_group);

  closure = g_closure_new_object (sizeof (GClosure),
                                  G_OBJECT (shell->close_dialog));
  g_closure_set_marshal (closure, gimp_display_shell_close_accel_marshal);
  gtk_accelerator_parse ("<Primary>D", &accel_key, &accel_mods);
  gtk_accel_group_connect (accel_group, accel_key, accel_mods, 0, closure);

  box = GIMP_MESSAGE_DIALOG (dialog)->box;

  accel_string = gtk_accelerator_get_label (accel_key, accel_mods);
  hint = g_strdup_printf (_("Press %s to discard all changes and close the image."),
                          accel_string);
  markup = g_strdup_printf ("<i><small>%s</small></i>", hint);

  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
  gtk_label_set_markup (GTK_LABEL (label), markup);
  gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  g_free (markup);
  g_free (hint);
  g_free (accel_string);

  g_signal_connect_object (image, "name-changed",
                           G_CALLBACK (gimp_display_shell_close_name_changed),
                           box, 0);
  g_signal_connect_object (image, "exported",
                           G_CALLBACK (gimp_display_shell_close_exported),
                           box, 0);

  gimp_display_shell_close_name_changed (image, box);

  closure =
    g_cclosure_new_object (G_CALLBACK (gimp_display_shell_close_time_changed),
                           G_OBJECT (box));

  /*  update every 10 seconds  */
  source = g_timeout_source_new_seconds (10);
  g_source_set_closure (source, closure);
  g_source_attach (source, NULL);
  g_source_unref (source);

  /*  The dialog is destroyed with the shell, so it should be safe
   *  to hold an image pointer for the lifetime of the dialog.
   */
  g_object_set_data (G_OBJECT (box), "gimp-image", image);

  gimp_display_shell_close_time_changed (box);

  gtk_widget_show (dialog);
}