how may I create a label with the symbol font ?
- From: Pablo De Napoli <pdenapo mate dm uba ar>
- To: gtk-list gnome org
- Subject: how may I create a label with the symbol font ?
- Date: Thu, 29 Nov 2001 14:45:21 -0300 (ARST)
Hi!
I want to report I think is a bug in gtk, but may be that I'm not using
gtk styles in a right way. I'm using gtk+ version 1.2.10
(I've tried to send this mail to the gnome bug-reporting system
(submitbus gnome org), but thishas failed.)
What I want to do is to create a toolbar with a button for each greek letter
(the idea is to use this in an IDE for TeX/LaTeX). I've tried to do this, by
calling gtk_widget_set_style to change the font of the labels in the toolbar
using the "symbol" font, but the label's font hasn't changed.
I've created a test program that shows that. It is a modification of
Gcalendar. You may select a font from a font selection dialog, and then
both my_label and my_button in the toolbar are supossed to change into the
selected font (in function font_selection_ok). But as you will see, the label
"my_label" does change, but the button "my_button" does not (try to select the
symbol font, or any other)
Note that both widgets play the same role in the lines bellow:
gdk_font_ref (style->font);
g_assert(GTK_IS_WIDGET(my_button));
gtk_widget_set_style (my_button, style);
gdk_font_ref (style->font);
gtk_widget_set_style (my_label, style);
Why does it happend ? Is it a bug in gtk ? or am I doing something wrong ?
Anyway I think this subject should be better documented in the gtk
documentation. May be you may include the program
below as an example in the tutorial (once it works fine).
By the way (I don't think this matters too much): I'm using Linux
(kernel 2.2.19, debian distribution, Xfree86 (version 3.3.6), libc
2.2.4-3)
Plese help me. Note that I'm not a member of this list: so please answer
to me at pdenapo dm uba ar
Thank you
Pablo De Napoli
============== change_font.c ======================================
/* A test program showing how to change fonts in Gtk
* (C) 2001 Pablo De Napoli
* based on G Calendar
* Copyright (C) 1998 Cesar Miquel, Shawn T. Amundson, Mattias Grönlund
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
#define DEF_PAD 10
#define DEF_PAD_SMALL 5
void create();
gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data);
void destroy (GtkWidget *widget, gpointer data);
int main(int argc, char *argv[]);
void font_selection_ok(GtkWidget * button, gpointer data);
void font_selection_destroy(GtkWidget * button, GtkWidget widget);
void select_font(GtkWidget * button, gpointer calendar);
void create_window_destroy(GtkWidget * ignore, gpointer data);
void create_window(GtkWidget * ignored, gpointer data);
void window_destroy(GtkWidget * ignore, gpointer data);
void create_widgets();
GtkWidget* toolbar;
GtkWidget* my_button;
GtkWidget* my_label;
GtkWidget* window;
GtkWidget* font_dialog=NULL;
void
toolbar_cb (GtkWidget* widget,char* data)
{
g_print("%s\n",data);
}
void
font_selection_ok(GtkWidget * button, gpointer data)
{
GtkStyle *style;
GdkFont *font;
char* font_name;
g_print("font_slection_ok started\n");
font_name = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (font_dialog));
g_print("Using font: %s \n",font_name);
if (window)
{
font = gtk_font_selection_dialog_get_font(GTK_FONT_SELECTION_DIALOG(font_dialog));
if (font)
{
g_print("gtk_font_selection_get_font worked ok!\n");
style = gtk_style_copy (gtk_widget_get_style (window));
gdk_font_unref (style->font);
style->font = font;
gdk_font_ref (style->font);
g_assert(GTK_IS_WIDGET(my_button));
gtk_widget_set_style (my_button, style);
gdk_font_ref (style->font);
gtk_widget_set_style (my_label, style);
}
}
}
void select_font(GtkWidget * button, gpointer data)
{
GtkWidget* font_selection_window;
if (!font_dialog) {
font_selection_window = gtk_font_selection_dialog_new ("Font Selection Dialog");
g_return_if_fail(GTK_IS_FONT_SELECTION_DIALOG(font_selection_window));
font_dialog = font_selection_window;
gtk_window_position (GTK_WINDOW (font_selection_window), GTK_WIN_POS_MOUSE);
gtk_signal_connect (GTK_OBJECT (font_selection_window), "destroy",
GTK_SIGNAL_FUNC (gtk_widget_destroyed),
&font_dialog);
gtk_signal_connect (GTK_OBJECT (GTK_FONT_SELECTION_DIALOG (font_selection_window)->ok_button),
"clicked", GTK_SIGNAL_FUNC(font_selection_ok),
NULL);
gtk_signal_connect_object (GTK_OBJECT (GTK_FONT_SELECTION_DIALOG (font_selection_window)->cancel_button),
"clicked",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (font_dialog));
}
font_selection_window=font_dialog;
if (!GTK_WIDGET_VISIBLE (font_selection_window))
gtk_widget_show (font_selection_window);
else
gtk_widget_destroy (font_selection_window);
}
void
create_widgets()
{
GtkWidget *vbox;
GtkWidget *button;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_container_border_width (GTK_CONTAINER (window), 5);
gtk_signal_connect(GTK_OBJECT(window), "destroy",
GTK_SIGNAL_FUNC(gtk_main_quit),
NULL);
gtk_signal_connect(GTK_OBJECT(window), "delete-event",
GTK_SIGNAL_FUNC(gtk_false),
NULL);
gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, TRUE);
vbox = gtk_vbox_new(FALSE, DEF_PAD);
gtk_container_add (GTK_CONTAINER (window), vbox);
toolbar =gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,GTK_TOOLBAR_TEXT);
gtk_box_pack_start(GTK_BOX(vbox),toolbar,TRUE,TRUE,DEF_PAD);
gtk_widget_show(toolbar);
my_button = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),"my toolbar",
"This is a toolbar",NULL,NULL, GTK_SIGNAL_FUNC(toolbar_cb),"hello toolbar!");
my_label=gtk_label_new("my label");
gtk_box_pack_start(GTK_BOX(vbox),my_label,TRUE,TRUE,DEF_PAD);
/* Build the font-button */
button = gtk_button_new_with_label("Font...");
gtk_signal_connect (GTK_OBJECT (button),
"clicked",
GTK_SIGNAL_FUNC(select_font),
NULL);
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show_all(window);
}
int
main(int argc, char *argv[])
{
gtk_set_locale ();
gtk_init (&argc, &argv);
create_widgets();
gtk_main ();
return 0;
}
==========================================================================
========================= Makefile =======================================
CC = gcc
change_font: change_font.c
$(CC) -Wall `gnome-config --cflags gnomeui` -g change_font.c -o change_font `gnome-config --libs gnomeui`
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]