⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtkfontsel.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 5 页
字号:
  sprintf(buffer, _("%i fonts available with a total of %i styles."),	  fontsel_info->nfonts, fontsel_info->nstyles);  label = gtk_label_new(buffer);  gtk_widget_show (label);  gtk_box_pack_start (GTK_BOX (fontsel->info_vbox), label, FALSE, FALSE, 0);    gtk_signal_connect (GTK_OBJECT (fontsel), "switch_page",		      GTK_SIGNAL_FUNC(gtk_font_selection_switch_page),		      fontsel);      /* Create the Filter page. */  fontsel->filter_vbox = gtk_vbox_new (FALSE, 4);  gtk_widget_show (fontsel->filter_vbox);  gtk_container_set_border_width (GTK_CONTAINER (fontsel->filter_vbox), 2);  label = gtk_label_new(_("Filter"));  gtk_notebook_append_page (GTK_NOTEBOOK (fontsel),			    fontsel->filter_vbox, label);    /* Create the font type checkbuttons. */  frame = gtk_frame_new (NULL);  gtk_widget_show (frame);  gtk_box_pack_start (GTK_BOX (fontsel->filter_vbox), frame, FALSE, TRUE, 0);  hbox = gtk_hbox_new (FALSE, 20);  gtk_widget_show (hbox);  gtk_container_add (GTK_CONTAINER (frame), hbox);  label = gtk_label_new(_("Font Types:"));  gtk_widget_show (label);  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 10);  hbox2 = gtk_hbox_new (TRUE, 0);  gtk_widget_show (hbox2);  gtk_box_pack_start (GTK_BOX (hbox), hbox2, FALSE, TRUE, 0);  fontsel->type_bitmaps_button = gtk_check_button_new_with_label (_("Bitmap"));  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->type_bitmaps_button), TRUE);  gtk_widget_show (fontsel->type_bitmaps_button);  gtk_box_pack_start (GTK_BOX (hbox2), fontsel->type_bitmaps_button,		      FALSE, TRUE, 0);  fontsel->type_scalable_button = gtk_check_button_new_with_label (_("Scalable"));  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->type_scalable_button), TRUE);  gtk_widget_show (fontsel->type_scalable_button);  gtk_box_pack_start (GTK_BOX (hbox2), fontsel->type_scalable_button,		      FALSE, TRUE, 0);  fontsel->type_scaled_bitmaps_button = gtk_check_button_new_with_label (_("Scaled Bitmap"));  gtk_widget_show (fontsel->type_scaled_bitmaps_button);  gtk_box_pack_start (GTK_BOX (hbox2), fontsel->type_scaled_bitmaps_button,		      FALSE, TRUE, 0);  table = gtk_table_new (4, 3, FALSE);  gtk_table_set_col_spacings(GTK_TABLE(table), 2);  gtk_widget_show (table);  gtk_box_pack_start (GTK_BOX (fontsel->filter_vbox), table, TRUE, TRUE, 0);    for (prop = 0; prop < GTK_NUM_FONT_PROPERTIES; prop++)    {      gint left = filter_positions[prop][0];      gint top = filter_positions[prop][1];            label = gtk_label_new(_(xlfd_field_names[xlfd_index[prop]]));      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);      gtk_misc_set_padding (GTK_MISC (label), 0, 2);      gtk_widget_show(label);      gtk_table_attach (GTK_TABLE (table), label, left, left + 1,			top, top + 1, GTK_FILL, GTK_FILL, 0, 0);            clist = gtk_clist_new(1);      gtk_widget_set_usize (clist, 100, filter_heights[prop]);      gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_MULTIPLE);      gtk_clist_column_titles_hide(GTK_CLIST(clist));      gtk_clist_set_column_auto_resize (GTK_CLIST (clist), 0, TRUE);      scrolled_win = gtk_scrolled_window_new (NULL, NULL);      gtk_container_add (GTK_CONTAINER (scrolled_win), clist);      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),				      GTK_POLICY_AUTOMATIC,				      GTK_POLICY_AUTOMATIC);      gtk_widget_show(clist);      gtk_widget_show(scrolled_win);            /* For the bottom-right cell we add the 'Reset Filter' button. */      if (top == 2 && left == 2)	{	  vbox = gtk_vbox_new(FALSE, 0);	  gtk_widget_show(vbox);	  gtk_table_attach (GTK_TABLE (table), vbox, left, left + 1,			    top + 1, top + 2, GTK_FILL, GTK_FILL, 0, 0);	  	  gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);	  	  alignment = gtk_alignment_new(0.5, 0.0, 0.8, 0.0);	  gtk_widget_show(alignment);	  gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, TRUE, 4);	  	  button = gtk_button_new_with_label(_("Reset Filter"));	  gtk_widget_show(button);	  gtk_container_add(GTK_CONTAINER(alignment), button);	  gtk_signal_connect (GTK_OBJECT (button), "clicked",			      GTK_SIGNAL_FUNC(gtk_font_selection_reset_filter),			      fontsel);	}      else	gtk_table_attach (GTK_TABLE (table), scrolled_win,			  left, left + 1, top + 1, top + 2,			  GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);            gtk_signal_connect (GTK_OBJECT (clist), "select_row",			  GTK_SIGNAL_FUNC(gtk_font_selection_select_filter),			  fontsel);      gtk_signal_connect (GTK_OBJECT (clist), "unselect_row",			  GTK_SIGNAL_FUNC(gtk_font_selection_unselect_filter),			  fontsel);            /* Insert the property names, expanded, and in sorted order.	 But we make sure that the wildcard '*' is first. */      gtk_clist_freeze (GTK_CLIST(clist));      property = N_("*");      gtk_clist_append(GTK_CLIST(clist), &property);            for (i = 1; i < fontsel_info->nproperties[prop]; i++) {	property = _(fontsel_info->properties[prop][i]);	if (prop == SLANT)	  property = gtk_font_selection_expand_slant_code(property);	else if (prop == SPACING)	  property = gtk_font_selection_expand_spacing_code(property);		inserted = FALSE;	for (row = 1; row < GTK_CLIST(clist)->rows; row++)	  {	    gtk_clist_get_text(GTK_CLIST(clist), row, 0, &text);	    if (strcmp(property, text) < 0)	      {		inserted = TRUE;		gtk_clist_insert(GTK_CLIST(clist), row, &property);		break;	      }	  }	if (!inserted)	  row = gtk_clist_append(GTK_CLIST(clist), &property);	gtk_clist_set_row_data(GTK_CLIST(clist), row, GINT_TO_POINTER (i));      }      gtk_clist_select_row(GTK_CLIST(clist), 0, 0);      gtk_clist_thaw (GTK_CLIST(clist));      fontsel->filter_clists[prop] = clist;    }}GtkWidget *gtk_font_selection_new(){  GtkFontSelection *fontsel;    fontsel = gtk_type_new (GTK_TYPE_FONT_SELECTION);    return GTK_WIDGET (fontsel);}static voidgtk_font_selection_destroy (GtkObject *object){  GtkFontSelection *fontsel;    g_return_if_fail (object != NULL);  g_return_if_fail (GTK_IS_FONT_SELECTION (object));    fontsel = GTK_FONT_SELECTION (object);    /* All we have to do is unref the font, if we have one. */  if (fontsel->font)    gdk_font_unref (fontsel->font);    if (GTK_OBJECT_CLASS (font_selection_parent_class)->destroy)    (* GTK_OBJECT_CLASS (font_selection_parent_class)->destroy) (object);}/* This is called when the clist is exposed. Here we scroll to the current   font if necessary. */static voidgtk_font_selection_expose_list (GtkWidget		*widget,				GdkEventExpose		*event,				gpointer		 data){  GtkFontSelection *fontsel;  FontInfo *font_info;  GList *selection;  gint index;  #ifdef FONTSEL_DEBUG  g_message("In expose_list\n");#endif  fontsel = GTK_FONT_SELECTION(data);    font_info = fontsel_info->font_info;        /* Try to scroll the font family clist to the selected item */  selection = GTK_CLIST(fontsel->font_clist)->selection;  if (selection)    {      index = GPOINTER_TO_INT (selection->data);      if (gtk_clist_row_is_visible(GTK_CLIST(fontsel->font_clist), index)	  != GTK_VISIBILITY_FULL)	gtk_clist_moveto(GTK_CLIST(fontsel->font_clist), index, -1, 0.5, 0);    }        /* Try to scroll the font style clist to the selected item */  selection = GTK_CLIST(fontsel->font_style_clist)->selection;  if (selection)    {      index = GPOINTER_TO_INT (selection->data);      if (gtk_clist_row_is_visible(GTK_CLIST(fontsel->font_style_clist), index)	  != GTK_VISIBILITY_FULL)	gtk_clist_moveto(GTK_CLIST(fontsel->font_style_clist), index, -1,			 0.5, 0);    }        /* Try to scroll the font size clist to the selected item */  selection = GTK_CLIST(fontsel->size_clist)->selection;  if (selection)    {      index = GPOINTER_TO_INT (selection->data);      if (gtk_clist_row_is_visible(GTK_CLIST(fontsel->size_clist), index)	  != GTK_VISIBILITY_FULL)      gtk_clist_moveto(GTK_CLIST(fontsel->size_clist), index, -1, 0.5, 0);    }}/* This is called when the style clist is realized. We need to set any   charset rows to insensitive colours. */static voidgtk_font_selection_realize_list (GtkWidget		*widget,				 gpointer		 data){  GtkFontSelection *fontsel;  gint row;  GdkColor *inactive_fg, *inactive_bg;#ifdef FONTSEL_DEBUG  g_message("In realize_list\n");#endif  fontsel = GTK_FONT_SELECTION (data);  /* Set the colours for any charset rows to insensitive. */  inactive_fg = &fontsel->font_style_clist->style->fg[GTK_STATE_INSENSITIVE];  inactive_bg = &fontsel->font_style_clist->style->bg[GTK_STATE_INSENSITIVE];  for (row = 0; row < GTK_CLIST (fontsel->font_style_clist)->rows; row++)    {      if (GPOINTER_TO_INT (gtk_clist_get_row_data (GTK_CLIST (fontsel->font_style_clist), row)) == -1)	{	  gtk_clist_set_foreground (GTK_CLIST (fontsel->font_style_clist),				    row, inactive_fg);	  gtk_clist_set_background (GTK_CLIST (fontsel->font_style_clist),				    row, inactive_bg);	}    }}/* This is called when a family is selected in the list. */static voidgtk_font_selection_select_font (GtkWidget      *w,				gint	        row,				gint	        column,				GdkEventButton *bevent,				gpointer        data){  GtkFontSelection *fontsel;  FontInfo *font_info;  FontInfo *font;  #ifdef FONTSEL_DEBUG  g_message("In select_font\n");#endif  fontsel = GTK_FONT_SELECTION(data);  font_info = fontsel_info->font_info;    if (bevent && !GTK_WIDGET_HAS_FOCUS (w))    gtk_widget_grab_focus (w);    row = GPOINTER_TO_INT (gtk_clist_get_row_data (GTK_CLIST (fontsel->font_clist), row));  font = &font_info[row];  gtk_entry_set_text(GTK_ENTRY(fontsel->font_entry), font->family);    /* If it is already the current font, just return. */  if (fontsel->font_index == row)    return;    fontsel->font_index = row;  gtk_font_selection_show_available_styles (fontsel);  gtk_font_selection_select_best_style (fontsel, TRUE);}static gintgtk_font_selection_on_clist_key_press (GtkWidget        *clist,				       GdkEventKey      *event,				       GtkFontSelection *fontsel){#ifdef FONTSEL_DEBUG  g_message("In on_clist_key_press\n");#endif  if (event->keyval == GDK_Up)    return gtk_font_selection_select_next (fontsel, clist, -1);  else if (event->keyval == GDK_Down)    return gtk_font_selection_select_next (fontsel, clist, 1);  else    return FALSE;}static gbooleangtk_font_selection_select_next (GtkFontSelection *fontsel,				GtkWidget        *clist,				gint		  step){  GList *selection;  gint current_row, row;    selection = GTK_CLIST(clist)->selection;  if (!selection)    return FALSE;  current_row = GPOINTER_TO_INT (selection->data);    /* Stop the normal clist key handler from being run. */  gtk_signal_emit_stop_by_name (GTK_OBJECT (clist), "key_press_event");  for (row = current_row + step;       row >= 0 && row < GTK_CLIST(clist)->rows;       row += step)    {      /* If this is the style clist, make sure that the item is not a charset	 entry. */      if (clist == fontsel->font_style_clist)	if (GPOINTER_TO_INT (gtk_clist_get_row_data(GTK_CLIST(clist), row)) == -1)	  continue;            /* Now we've found the row to select. */      if (gtk_clist_row_is_visible(GTK_CLIST(clist), row)	  != GTK_VISIBILITY_FULL)	gtk_clist_moveto(GTK_CLIST(clist), row, -1, (step < 0) ? 0 : 1, 0);      gtk_clist_select_row(GTK_CLIST(clist), row, 0);      break;    }  return TRUE;}/* This fills the font style clist with all the possible style combinations   for the current font family. */static voidgtk_font_selection_show_available_styles (GtkFontSelection *fontsel){  FontInfo *font;  FontStyle *styles;  gint style, tmpstyle, row;  gint weight_index, slant_index, set_width_index, spacing_index;  gint charset_index;  gchar *weight, *slant, *set_width, *spacing;  gchar *charset = NULL;  gchar *new_item;  gchar buffer[XLFD_MAX_FIELD_LEN * 6 + 2];  GdkColor *inactive_fg, *inactive_bg;  gboolean show_charset;  #ifdef FONTSEL_DEBUG  g_message("In show_available_styles\n");#endif  font = &fontsel_info->font_info[fontsel->font_index];  styles = &fontsel_info->font_styles[font->style_index];    gtk_clist_freeze (GTK_CLIST(fontsel->font_style_clist));  gtk_clist_clear (GTK_CLIST(fontsel->font_style_clist));    /* First we mark all visible styles as not having been displayed yet,     and check if every style has the same charset. If not then we will     display the charset in the list before the styles. */  show_charset = FALSE;  charset_index = -1;  for (style = 0; style < font->nstyles; style++)    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -