Example #1
0
static void
update (void)
{
  GString *s;
  char *font_desc;
  char *font_settings;
  const char *text;
  gboolean has_feature;
  int i;

  text = gtk_entry_get_text (GTK_ENTRY (entry));

  font_desc = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (font));

  s = g_string_new ("");

  has_feature = FALSE;
  for (i = 0; i < 24; i++)
    {
      if (!gtk_widget_is_sensitive (toggle[i]))
        continue;

      if (GTK_IS_RADIO_BUTTON (toggle[i]))
        {
          if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle[i])))
            {
              if (has_feature)
                g_string_append (s, ", ");
              g_string_append (s, gtk_buildable_get_name (GTK_BUILDABLE (toggle[i])));
              g_string_append (s, " 1");
              has_feature = TRUE;
            }
        }
      else
        {
          if (has_feature)
            g_string_append (s, ", ");
          g_string_append (s, gtk_buildable_get_name (GTK_BUILDABLE (toggle[i])));
          if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle[i])))
            g_string_append (s, " 1");
          else
            g_string_append (s, " 0");
          has_feature = TRUE;
        }
    }

  font_settings = g_string_free (s, FALSE);

  gtk_label_set_text (GTK_LABEL (settings), font_settings);

  s = g_string_new ("");
  g_string_append_printf (s, "<span font_desc='%s' font_features='%s'>%s</span>", font_desc, font_settings, text);

  gtk_label_set_markup (GTK_LABEL (label), s->str);

  g_string_free (s, TRUE);

  g_free (font_desc);
  g_free (font_settings);
}
Example #2
0
static void onTimerFontSelectClick(GtkWidget *widget, gpointer data)
{
	/* Unused parameters. */
	(void)widget;
	(void)data;

	GtkWidget *fontChooser = NULL;
	PangoFontDescription *font_desc = NULL;

	fontChooser = gtk_font_chooser_dialog_new("Select Timer Font", NULL);
	gtk_font_chooser_set_font(
			GTK_FONT_CHOOSER(fontChooser), prefs.font_timer);

	if (gtk_dialog_run(GTK_DIALOG(fontChooser)) == GTK_RESPONSE_OK)
	{
		if (prefs.font_timer != NULL)
			g_free(prefs.font_timer);

		prefs.font_timer = gtk_font_chooser_get_font(
				GTK_FONT_CHOOSER(fontChooser));
		font_desc = pango_font_description_from_string(prefs.font_timer);
		gtk_widget_modify_font(timeElapsedLabel, font_desc);
		pango_font_description_free(font_desc);
	}

	gtk_widget_destroy(fontChooser);
}
Example #3
0
static gboolean
font_fetch(void)
{
	gchar   *font_name;


#if GTK_CHECK_VERSION(3,2,0)
	font_name = g_strdup(gtk_font_chooser_get_font(
	      GTK_FONT_CHOOSER(font_browse_w)));
#else
	font_name = g_strdup(gtk_font_selection_get_font_name(
	      GTK_FONT_SELECTION(font_browse_w)));
#endif /* GTK_CHECK_VERSION(3,2,0) */
	if (font_name == NULL) {
		/* No font was selected; let the user know, but don't
		   tear down the font selection dialog, so they can
		   try again. */
		simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
		   "You have not selected a font.");
		return FALSE;
	}

	if (!user_font_test(font_name)) {
		/* The font isn't usable; "user_font_test()" has already
		   told the user why.  Don't tear down the font selection
		   dialog. */
		g_free(font_name);
		return FALSE;
	}
	new_font_name = font_name;
	return TRUE;
}
Example #4
0
G_MODULE_EXPORT void
action_font_activate_cb(GtkWidget *widget, EDITOR *e)
{
	GtkWidget *dialog;
	gchar *selected_text = NULL;
	gchar *size = NULL;
#ifdef HAVE_GTK_32
	dialog = gtk_font_chooser_dialog_new("Select font", NULL);
	gtk_font_chooser_set_font((GtkFontChooser *)dialog,
#else
	dialog = gtk_font_selection_dialog_new("Select font");
	gtk_font_selection_dialog_set_font_name((GtkFontSelectionDialog *)
						dialog,
#endif
				  "Droid Sans 14");

	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
#ifdef HAVE_GTK_32
		const gchar *fontname = gtk_font_chooser_get_font((GtkFontChooser *)dialog);
#else
		const gchar *fontname = gtk_font_selection_dialog_get_font_name((GtkFontSelectionDialog *)dialog);
#endif
		GString *name = g_string_new(fontname);
		size = get_font_size_from_name(name);
		g_string_free(name, TRUE);

		selected_text = editor_get_selected_text(e);
#ifdef HAVE_GTK_32
		PangoFontDescription *font_description =
			gtk_font_chooser_get_font_desc((GtkFontChooser *)
						       dialog);
		fontname = pango_font_description_get_family(font_description);
#else
		PangoFontDescription *font_description =
			pango_font_description_from_string(fontname);
		fontname = pango_font_description_get_family(font_description);
#endif

		gchar *script = g_strdup_printf("<SPAN STYLE=\"font-family:%s;font-size:%spx;\">%s</SPAN>",
						fontname, size, selected_text);

		editor_insert_html(script, e);
		g_free(script);
	}
	if (size)
		g_free(size);
	if (selected_text)
		g_free(selected_text);
	gtk_widget_destroy(dialog);
}
Example #5
0
void calendar_select_font (GtkWidget    *button,
                                 CalendarData *calendar)
{
  const char *font = NULL;
  GtkCssProvider *provider;
  gchar *data;

  if (calendar->window)
    {
      provider = g_object_get_data (G_OBJECT (calendar->window), "css-provider");
      if (!provider)
        {
          provider = gtk_css_provider_new ();
          gtk_style_context_add_provider (gtk_widget_get_style_context (calendar->window), GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
          g_object_set_data_full (G_OBJECT (calendar->window), "css-provider", provider, g_object_unref);
        }
      font = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (button));
      data = g_strdup_printf ("GtkCalendar { font: %s; }", font);
      gtk_css_provider_load_from_data (provider, data, -1);
      g_free (data);
    }
}
Example #6
0
static void
notify_font_cb (GtkFontChooser *fontchooser, GParamSpec *pspec, gpointer data)
{
  PangoFontFamily *family;
  PangoFontFace *face;

  g_debug ("Changed font name %s", gtk_font_chooser_get_font (fontchooser));

  family = gtk_font_chooser_get_font_family (fontchooser);
  face = gtk_font_chooser_get_font_face (fontchooser);
  if (family)
    {
       g_debug ("  Family: %s is-monospace:%s",
                pango_font_family_get_name (family),
                pango_font_family_is_monospace (family) ? "true" : "false");
    }
  else
    g_debug ("  No font family!");

  if (face)
    g_debug ("  Face description: %s", pango_font_face_get_face_name (face));
  else
    g_debug ("  No font face!");
}
Example #7
0
void on_font_select_activate (GtkAction * menuitem, gpointer user_data)
{
  GtkWidget *font_selection_dialog = NULL;
  const gchar *font_name = gui_editor_get_font (app->editor);
  gint action = 0;
  g_assert (app->editor);
  font_selection_dialog = gtk_font_chooser_dialog_new (_("Select font"), NULL);
  gtk_font_chooser_set_font (GTK_FONT_CHOOSER (font_selection_dialog), font_name);
  action = gtk_dialog_run (GTK_DIALOG (font_selection_dialog));
  switch (action) 
  {
    case GTK_RESPONSE_OK:
      font_name = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (font_selection_dialog));
      if (font_name)
      {
        gui_editor_set_font (app->editor, font_name);
      }
      break;
    default:
      break;
  }
  
  gtk_widget_destroy(font_selection_dialog);
}
static int gtkFontDlgPopup(Ihandle* ih, int x, int y)
{
  InativeHandle* parent = iupDialogGetNativeParent(ih);
  GtkWidget* dialog;
  int response;
  char* preview_text, *standardfont;

  iupAttribSetInt(ih, "_IUPDLG_X", x);   /* used in iupDialogUpdatePosition */
  iupAttribSetInt(ih, "_IUPDLG_Y", y);

#if GTK_CHECK_VERSION(3, 2, 0)
  dialog = gtk_font_chooser_dialog_new(iupgtkStrConvertToSystem(iupAttribGet(ih, "TITLE")), GTK_WINDOW(parent));
#else
  dialog = gtk_font_selection_dialog_new(iupgtkStrConvertToSystem(iupAttribGet(ih, "TITLE")));
#endif
  if (!dialog)
    return IUP_ERROR;

#if !GTK_CHECK_VERSION(3, 2, 0)
  if (parent)
    gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
#endif

  standardfont = iupAttribGet(ih, "VALUE");
  if (!standardfont)
    standardfont = IupGetGlobal("DEFAULTFONT");
#if GTK_CHECK_VERSION(3, 2, 0)
  gtk_font_chooser_set_font(GTK_FONT_CHOOSER(dialog), standardfont);
#else
  gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dialog), standardfont);
#endif

  preview_text = iupAttribGet(ih, "PREVIEWTEXT");
  if (preview_text)
  {
    preview_text = iupgtkStrConvertToSystem(preview_text);
#if GTK_CHECK_VERSION(3, 2, 0)
    if (iupStrEqualNoCase(preview_text, "NONE"))
      gtk_font_chooser_set_show_preview_entry(GTK_FONT_CHOOSER(dialog), FALSE);
    else
      gtk_font_chooser_set_preview_text(GTK_FONT_CHOOSER(dialog), preview_text);
#else
    gtk_font_selection_dialog_set_preview_text(GTK_FONT_SELECTION_DIALOG(dialog), preview_text);
#endif
  }

  if (IupGetCallback(ih, "HELP_CB"))
  {
#if GTK_CHECK_VERSION(3, 10, 0)
    const char* help = "_Help";
#else
    const char* help = GTK_STOCK_HELP;
#endif

    gtk_dialog_add_button(GTK_DIALOG(dialog), help, GTK_RESPONSE_HELP);
  }
  
  /* initialize the widget */
  gtk_widget_realize(GTK_WIDGET(dialog));
  
  ih->handle = GTK_WIDGET(dialog);
  iupDialogUpdatePosition(ih);
  ih->handle = NULL;
                                    
  do 
  {
    response = gtk_dialog_run(GTK_DIALOG(dialog));

    if (response == GTK_RESPONSE_HELP)
    {
      Icallback cb = IupGetCallback(ih, "HELP_CB");
      if (cb && cb(ih) == IUP_CLOSE)
        response = GTK_RESPONSE_CANCEL;
    }
  } while (response == GTK_RESPONSE_HELP);

  if (response == GTK_RESPONSE_OK)
  {
#if GTK_CHECK_VERSION(3, 2, 0)
    char* fontname = gtk_font_chooser_get_font(GTK_FONT_CHOOSER(dialog));
#else
    char* fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog));
#endif
    iupAttribSetStr(ih, "VALUE", fontname);
    g_free(fontname);
    iupAttribSet(ih, "STATUS", "1");
  }
  else
  {
    iupAttribSet(ih, "VALUE", NULL);
    iupAttribSet(ih, "STATUS", NULL);
  }

  gtk_widget_destroy(GTK_WIDGET(dialog));  

  return IUP_NOERROR;
}
Example #9
0
static void
value_icon_activate (GtkCellRendererToggle *cell_renderer,
                     gchar *path,
                     GladeEPropAttrs *eprop_attrs)
{
  GtkWidget *dialog;
  GtkTreeIter iter;
  PangoAttrType type;
  AttrEditType edit_type;
  GdkRGBA color = {0,};
  gchar *text = NULL, *new_text;

  /* Find type etc */
  if (!gtk_tree_model_get_iter_from_string (eprop_attrs->model, &iter, path))
    return;

  gtk_tree_model_get (eprop_attrs->model, &iter,
                      COLUMN_TEXT, &text,
                      COLUMN_TYPE, &type, 
		      COLUMN_EDIT_TYPE, &edit_type, -1);

  /* Launch dialog etc. */
  switch (edit_type)
    {
      case EDIT_COLOR:
        dialog = gtk_color_chooser_dialog_new (_("Select a color"),
                                               GTK_WINDOW (glade_app_get_window ()));
        /* Get response etc... */
        if (text && gdk_rgba_parse (&color, text))
          gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (dialog), &color);

        gtk_dialog_run (GTK_DIALOG (dialog));

        gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), &color);
        
        /* Use GdkColor string format */
        if (((guint8)(color.red * 0xFF)) * 0x101 == (guint16)(color.red * 0xFFFF) &&
            ((guint8)(color.green * 0xFF)) * 0x101 == (guint16)(color.green * 0xFFFF) &&
            ((guint8)(color.blue * 0xFF)) * 0x101 == (guint16)(color.blue * 0xFFFF))
          new_text = g_strdup_printf ("#%02X%02X%02X",
                                      (guint8)(color.red * 0xFF),
                                      (guint8)(color.green * 0xFF),
                                      (guint8)(color.blue * 0xFF));
        else
          new_text = g_strdup_printf ("#%04X%04X%04X",
                                      (guint16)(color.red * 0xFFFF),
                                      (guint16)(color.green * 0xFFFF),
                                      (guint16)(color.blue * 0xFFFF));

        gtk_list_store_set (GTK_LIST_STORE (eprop_attrs->model), &iter,
                            COLUMN_TEXT, new_text,
                            COLUMN_NAME_WEIGHT, PANGO_WEIGHT_BOLD,
                            COLUMN_TEXT_STYLE, PANGO_STYLE_NORMAL,
                            COLUMN_TEXT_FG, "Black", -1);
        g_free (new_text);

        gtk_widget_destroy (dialog);
        break;

      case EDIT_FONT:
        dialog = gtk_font_chooser_dialog_new (_("Select a font"),
                                              GTK_WINDOW (glade_app_get_window ()));

        /* Get response etc... */
        if (text)
          gtk_font_chooser_set_font (GTK_FONT_CHOOSER (dialog), text);

        gtk_dialog_run (GTK_DIALOG (dialog));

        new_text = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (dialog));

        gtk_list_store_set (GTK_LIST_STORE (eprop_attrs->model), &iter,
                            COLUMN_TEXT, new_text,
                            COLUMN_NAME_WEIGHT, PANGO_WEIGHT_BOLD,
                            COLUMN_TEXT_STYLE, PANGO_STYLE_NORMAL,
                            COLUMN_TEXT_FG, "Black", -1);
        g_free (new_text);

        gtk_widget_destroy (dialog);
        break;

      default:
        break;
    }

  sync_object (eprop_attrs, FALSE);

  g_free (text);
}