Commit edb73867 authored by Arturo Espinosa's avatar Arturo Espinosa

WOOOHOO!



WOOOHOO!

We have the font selector now :-)

A nice, crisp, glade-quality, clean-code, beautiful miggeee-hack font-selector

MIguel
parent 17e87cc5
1999-07-12 Miguel de Icaza <miguel@gnu.org>
* src/cell.c (cell_set_font): Now takes a "points" argument.
* src/Gnumeric.idl (Sheet): Take a double for the cell_set_font
points parameter.
1999-07-11 Raja R Harinath <harinath@cs.umn.edu>
* configure.in: Don't use `foo >& /dev/null' style redirection,
......@@ -5,8 +12,19 @@
1999-07-11 Miguel de Icaza <miguel@gnu.org>
* src/dialog-cell-format.c (apply_font_format): Use the
FontSelector here.
* src/widget-font-selector.c (reload_preview): New approach for
font loading, by using the scale explicitly I got it to work ;-).
(font_selector_choose): New routine to set the font style.
* src/sheet.c (sheet_init_default_styles): Change of plans, we are
going to use 80 units for the default width.
* src/widget-font-selector.c: New file. A simplified and robust
font selector for Gnumeric.
(fs_fill_font_name_list): Free this.
1999-07-11 Jody Goldberg <jgoldberg@home.com>
......
1999-07-12 Miguel de Icaza <miguel@gnu.org>
* src/cell.c (cell_set_font): Now takes a "points" argument.
* src/Gnumeric.idl (Sheet): Take a double for the cell_set_font
points parameter.
1999-07-11 Raja R Harinath <harinath@cs.umn.edu>
* configure.in: Don't use `foo >& /dev/null' style redirection,
......@@ -5,8 +12,19 @@
1999-07-11 Miguel de Icaza <miguel@gnu.org>
* src/dialog-cell-format.c (apply_font_format): Use the
FontSelector here.
* src/widget-font-selector.c (reload_preview): New approach for
font loading, by using the scale explicitly I got it to work ;-).
(font_selector_choose): New routine to set the font style.
* src/sheet.c (sheet_init_default_styles): Change of plans, we are
going to use 80 units for the default width.
* src/widget-font-selector.c: New file. A simplified and robust
font selector for Gnumeric.
(fs_fill_font_name_list): Free this.
1999-07-11 Jody Goldberg <jgoldberg@home.com>
......
......@@ -429,9 +429,11 @@ init_plugin (PluginData *pd)
FunctionCategory *cat;
char *init_file_name;
#if 0
cat = function_get_category ("Guile");
function_add_args (cat, "scm_eval", "s", "expr", NULL, func_scm_eval);
function_add_nodes (cat, "scm_apply", 0, "symbol", NULL, func_scm_apply);
#endif
pd->can_unload = no_unloading_for_me;
pd->title = g_strdup(_("Guile Plugin"));
......
......@@ -94,7 +94,7 @@ module GNOME {
string cell_get_format (in long col, in long row)
raises (OutOfRange);
void cell_set_font (in long col, in long row, in string font, in short points)
void cell_set_font (in long col, in long row, in string font, in double points)
raises (OutOfRange);
string cell_get_font (in long col, in long row)
raises (OutOfRange);
......
......@@ -179,7 +179,7 @@ cell_set_font_from_style (Cell *cell, StyleFont *style_font)
}
void
cell_set_font (Cell *cell, const char *font_name)
cell_set_font (Cell *cell, const char *font_name, double points)
{
StyleFont *style_font;
Sheet *sheet;
......@@ -190,7 +190,7 @@ cell_set_font (Cell *cell, const char *font_name)
sheet = cell->sheet;
style_font = style_font_new (
font_name,
cell->style->font->size,
points,
sheet->last_zoom_factor_used,
cell->style->font->is_bold,
cell->style->font->is_italic);
......
......@@ -128,7 +128,7 @@ void cell_set_array_formula (Sheet *sheet, int rowa, int cola,
void cell_set_format (Cell *cell, const char *format);
void cell_set_format_simple (Cell *cell, const char *format);
void cell_set_format_from_style (Cell *cell, StyleFormat *style_format);
void cell_set_font (Cell *cell, const char *font_name);
void cell_set_font (Cell *cell, const char *font_name, double points);
void cell_set_style (Cell *cell, Style *reference_style);
void cell_set_comment (Cell *cell, const char *str);
void cell_comment_destroy (Cell *cell);
......
......@@ -468,7 +468,7 @@ Sheet_cell_set_font (PortableServer_Servant servant,
const CORBA_long col,
const CORBA_long row,
const CORBA_char * font,
const CORBA_short points,
const CORBA_double points,
CORBA_Environment *ev)
{
Sheet *sheet = sheet_from_servant (servant);
......@@ -478,7 +478,7 @@ Sheet_cell_set_font (PortableServer_Servant servant,
verify_row (row);
cell = sheet_cell_fetch (sheet, col, row);
cell_set_font (cell, font);
cell_set_font (cell, font, points);
}
static CORBA_char *
......
......@@ -536,26 +536,34 @@ create_font_page (GtkWidget *prop_win, CellList *cells)
static void
apply_font_format (Style *style, Sheet *sheet, CellList *cells)
{
GnomeFontSelection *font_sel = GNOME_FONT_SELECTION (font_widget);
FontSelector *font_sel = FONT_SELECTOR (font_widget);
GnomeDisplayFont *gnome_display_font;
GnomeFont *gnome_font;
GList *l;
char *font_name;
char *family_name;
double height;
gnome_display_font = gnome_font_selection_get_font (font_sel);
gnome_display_font = font_sel->display_font;
if (!gnome_display_font)
return;
gnome_font = gnome_display_font->gnome_font;
font_name = gnome_font->fontmap_entry->font_name;
family_name = gnome_font->fontmap_entry->familyname;
height = gnome_display_font->gnome_font->size;
style->valid_flags |= STYLE_FONT;
style->font = style_font_new (
family_name,
gnome_font->size,
sheet->last_zoom_factor_used,
gnome_font->fontmap_entry->weight_code >= GNOME_FONT_BOLD,
gnome_font->fontmap_entry->italic);
/* Apply the new font to all of the cell rows */
for (; cells; cells = cells->next){
Cell *cell = cells->data;
cell_set_font (cell, font_name);
cell_set_font_from_style (cell, style->font);
}
/* Now apply it to every row in the selection */
......@@ -578,13 +586,6 @@ apply_font_format (Style *style, Sheet *sheet, CellList *cells)
sheet_row_set_internal_height (sheet, ri, height);
}
}
style->valid_flags |= STYLE_FONT;
style->font = style_font_new (
font_name,
gnome_font->size,
sheet->last_zoom_factor_used,
gnome_font->fontmap_entry->weight_code >= GNOME_FONT_BOLD,
gnome_font->fontmap_entry->italic);
}
......
......@@ -536,26 +536,34 @@ create_font_page (GtkWidget *prop_win, CellList *cells)
static void
apply_font_format (Style *style, Sheet *sheet, CellList *cells)
{
GnomeFontSelection *font_sel = GNOME_FONT_SELECTION (font_widget);
FontSelector *font_sel = FONT_SELECTOR (font_widget);
GnomeDisplayFont *gnome_display_font;
GnomeFont *gnome_font;
GList *l;
char *font_name;
char *family_name;
double height;
gnome_display_font = gnome_font_selection_get_font (font_sel);
gnome_display_font = font_sel->display_font;
if (!gnome_display_font)
return;
gnome_font = gnome_display_font->gnome_font;
font_name = gnome_font->fontmap_entry->font_name;
family_name = gnome_font->fontmap_entry->familyname;
height = gnome_display_font->gnome_font->size;
style->valid_flags |= STYLE_FONT;
style->font = style_font_new (
family_name,
gnome_font->size,
sheet->last_zoom_factor_used,
gnome_font->fontmap_entry->weight_code >= GNOME_FONT_BOLD,
gnome_font->fontmap_entry->italic);
/* Apply the new font to all of the cell rows */
for (; cells; cells = cells->next){
Cell *cell = cells->data;
cell_set_font (cell, font_name);
cell_set_font_from_style (cell, style->font);
}
/* Now apply it to every row in the selection */
......@@ -578,13 +586,6 @@ apply_font_format (Style *style, Sheet *sheet, CellList *cells)
sheet_row_set_internal_height (sheet, ri, height);
}
}
style->valid_flags |= STYLE_FONT;
style->font = style_font_new (
font_name,
gnome_font->size,
sheet->last_zoom_factor_used,
gnome_font->fontmap_entry->weight_code >= GNOME_FONT_BOLD,
gnome_font->fontmap_entry->italic);
}
......
......@@ -84,7 +84,7 @@ static void
sheet_init_default_styles (Sheet *sheet)
{
/* Sizes seem to match excel */
col_row_info_init (&sheet->default_col_style, 62.0);
col_row_info_init (&sheet->default_col_style, 80.0);
col_row_info_init (&sheet->default_row_style, 18.0);
}
......@@ -148,7 +148,7 @@ sheet_rename (Sheet *sheet, const char *new_name)
SheetView *
sheet_new_sheet_view (Sheet *sheet)
{
SheetView *sheet_view;
GtkWidget *sheet_view;
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
......@@ -158,7 +158,7 @@ sheet_new_sheet_view (Sheet *sheet)
sheet->sheet_views = g_list_prepend (sheet->sheet_views, sheet_view);
return sheet_view;
return GTK_WIDGET (sheet_view);
}
void
......@@ -202,7 +202,7 @@ sheet_new (Workbook *wb, const char *name)
if (0)
sheet_init_dummy_stuff (sheet);
sheet_view = sheet_new_sheet_view (sheet);
sheet_view = GTK_WIDGET (sheet_new_sheet_view (sheet));
sheet_selection_append (sheet, 0, 0);
......
......@@ -11,6 +11,7 @@
#include "widget-font-selector.h"
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <string.h>
/*
* Inside this file we define a number of aliases for the
......@@ -19,184 +20,183 @@
* I do want to avoid typing.
*/
#define FS(x) FONT_SELECTOR(x)
typedef FontSelector Fs;
typedef FontSelectorClass FsClass;
static GtkHBoxClass *fs_parent_class;
static void
reload_preview (FontSelector *fs)
{
char *name = gtk_entry_get_text (GTK_ENTRY (fs->font_name_entry));
GtkStyle *style;
GnomeFont *gnome_font;
GnomeDisplayFont *display_font;
gnome_font = gnome_font_new_closest (
name,
fs->is_bold ? GNOME_FONT_BOLD : GNOME_FONT_BOOK,
fs->is_italic,
fs->size);
if (!gnome_font){
g_warning ("Uh oh, can not get the font!");
return;
}
display_font = gnome_font_get_display_font (gnome_font);
if (!display_font){
g_warning ("Uh oh, can not get the display font");
return;
}
if (!display_font->gdk_font){
gtk_object_unref (GTK_OBJECT (gnome_font));
return;
}
fs->gnome_font = gnome_font;
fs->display_font = display_font;
style = gtk_style_new ();
gdk_font_unref (style->font);
style->font = fs->display_font->gdk_font;
gdk_font_ref (style->font);
gtk_widget_set_style (fs->font_preview, style);
gtk_style_unref (style);
}
static void
font_selected (GtkCList *font_list, int col, int row, GdkEvent *event, FontSelector *fs)
{
int row;
gchar *text;
if (font_list->selection == NULL)
return;
row = GPOINTER_TO_INT (font_list->selection->data);
gtk_clist_get_text (font_list, row, 0, &text);
printf ("Text at %d, %s\n", row, text);
gtk_entry_set_text (GTK_ENTRY (fs->font_name_entry), text);
reload_preview (fs);
}
static void
fs_fill_font_name_list (FontSelector *fs)
{
GnomeFontClass *gfc = gtk_type_class (gnome_font_get_type ());
GList *font_list = gnome_font_family_list (gfc);
GList *l;
for (l = font_list; l; l = l->next){
char *name = l->data;
char *array [1];
array [0] = name;
gtk_clist_append (GTK_CLIST (fs->font_name_list), array);
}
gtk_signal_connect (
GTK_OBJECT (fs->font_name_list), "select_row",
GTK_SIGNAL_FUNC(font_selected), fs);
}
static char *styles [] = {
N_("Normal"),
N_("Bold"),
N_("Bold italic"),
N_("Italic"),
NULL
static int point_sizes [] = {
4, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22,
24, 26, 28, 32, 36, 40, 48, 56, 64, 72, 0
};
static void
style_selected (GtkCList *style_list, int col, int row, GdkEvent *event, FontSelector *fs)
{
int row;
if (style_list->selection == NULL)
return;
row = GPOINTER_TO_INT (style_list->selection->data);
switch (row){
case 0:
fs->is_bold = fs->is_italic = FALSE;
break;
case 1:
fs->is_bold = TRUE;
fs->is_italic = FALSE;
break;
case 2:
fs->is_bold = fs->is_italic = TRUE;
break;
case 3:
fs->is_italic = TRUE;
fs->is_bold = FALSE;
break;
}
gtk_entry_set_text (GTK_ENTRY (fs->font_style_entry), _(styles [row]));
reload_preview (fs);
}
static void
fs_fill_font_style_list (FontSelector *fs)
{
GtkCList *style_list = GTK_CLIST (fs->font_style_list);
int i;
for (i = 0; styles [i] != NULL; i++){
char *array [1];
array [0] = _(styles [i]);
gtk_clist_append (style_list, array);
}
gtk_signal_connect (
GTK_OBJECT (fs->font_style_list), "select_row",
GTK_SIGNAL_FUNC(style_selected), fs);
}
static void
size_selected (GtkCList *size_list, int col, int row, GdkEvent *event, FontSelector *fs)
{
int row;
gchar *text;
if (size_list->selection == NULL)
return;
row = GPOINTER_TO_INT (size_list->selection->data);
gtk_clist_get_text (size_list, row, 0, &text);
gtk_entry_set_text (GTK_ENTRY (fs->font_size_entry), text);
}
static void
size_changed (GtkEntry *entry, FontSelector *fs)
{
char *text;
double size;
text = gtk_entry_get_text (entry);
size = atof (text);
if (size > 0 && size < 128){
fs->size = size;
reload_preview (fs);
}
}
static void
fs_fill_font_size_list (FontSelector *fs)
{
int i;
static int point_sizes [] = {
4, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22,
24, 26, 28, 32, 36, 40, 48, 56, 64, 72, 0 };
for (i = 0; point_sizes [i] != 0; i++){
char buffer [10];
char *array [1];
static void
reload_preview (FontSelector *fs)
{
char *name = gtk_entry_get_text (GTK_ENTRY (fs->font_name_entry));
GtkStyle *style;
GnomeFont *gnome_font;
GnomeDisplayFont *display_font;
gnome_font = gnome_font_new_closest (
name,
fs->is_bold ? GNOME_FONT_BOLD : GNOME_FONT_BOOK,
fs->is_italic,
fs->size);
if (!gnome_font){
g_warning ("Uh oh, can not get the font!");
return;
}
display_font = gnome_get_display_font (
name,
fs->is_bold ? GNOME_FONT_BOLD : GNOME_FONT_BOOK,
fs->is_italic,
fs->size,
1.0);
if (!display_font){
g_warning ("Uh oh, can not get the display font");
return;
}
if (!display_font->gdk_font){
gtk_object_unref (GTK_OBJECT (gnome_font));
return;
}
fs->gnome_font = gnome_font;
fs->display_font = display_font;
style = gtk_style_new ();
gdk_font_unref (style->font);
style->font = fs->display_font->gdk_font;
gdk_font_ref (style->font);
gtk_widget_set_style (fs->font_preview, style);
gtk_style_unref (style);
}
static void
font_selected (GtkCList *font_list, int col, int row, GdkEvent *event, FontSelector *fs)
{
gchar *text;
gtk_clist_get_text (font_list, GPOINTER_TO_INT (font_list->selection->data), 0, &text);
printf ("Text at %d, %s\n", row, text);
gtk_entry_set_text (GTK_ENTRY (fs->font_name_entry), text);
reload_preview (fs);
}
static void
fs_fill_font_name_list (FontSelector *fs)
{
GnomeFontClass *gfc = gtk_type_class (gnome_font_get_type ());
GList *l;
fs->family_list = gnome_font_family_list (gfc);
for (l = fs->family_list; l; l = l->next){
char *name = l->data;
char *array [1];
array [0] = name;
gtk_clist_append (GTK_CLIST (fs->font_name_list), array);
}
gtk_signal_connect (
GTK_OBJECT (fs->font_name_list), "select_row",
GTK_SIGNAL_FUNC(font_selected), fs);
}
static char *styles [] = {
N_("Normal"),
N_("Bold"),
N_("Bold italic"),
N_("Italic"),
NULL
};
static void
style_selected (GtkCList *style_list, int col, int row, GdkEvent *event, FontSelector *fs)
{
row = GPOINTER_TO_INT (style_list->selection->data);
switch (row){
case 0:
fs->is_bold = fs->is_italic = FALSE;
break;
case 1:
fs->is_bold = TRUE;
fs->is_italic = FALSE;
break;
case 2:
fs->is_bold = fs->is_italic = TRUE;
break;
case 3:
fs->is_italic = TRUE;
fs->is_bold = FALSE;
break;
}
gtk_entry_set_text (GTK_ENTRY (fs->font_style_entry), _(styles [row]));
reload_preview (fs);
}
static void
fs_fill_font_style_list (FontSelector *fs)
{
GtkCList *style_list = GTK_CLIST (fs->font_style_list);
int i;
for (i = 0; styles [i] != NULL; i++){
char *array [1];
array [0] = _(styles [i]);
gtk_clist_append (style_list, array);
}
gtk_signal_connect (
GTK_OBJECT (fs->font_style_list), "select_row",
GTK_SIGNAL_FUNC(style_selected), fs);
}
static void
size_selected (GtkCList *size_list, int col, int row, GdkEvent *event, FontSelector *fs)
{
gchar *text;
row = GPOINTER_TO_INT (size_list->selection->data);
gtk_clist_get_text (size_list, row, 0, &text);
gtk_entry_set_text (GTK_ENTRY (fs->font_size_entry), text);
}
static void
size_changed (GtkEntry *entry, FontSelector *fs)
{
char *text;
double size;
text = gtk_entry_get_text (entry);
size = atof (text);
if (size > 0 && size < 128){
fs->size = size;
reload_preview (fs);
}
}
static void
fs_fill_font_size_list (FontSelector *fs)
{
int i;
for (i = 0; point_sizes [i] != 0; i++){
char buffer [10];
char *array [1];
sprintf (buffer, "%d", point_sizes [i]);
array [0] = buffer;
......@@ -248,7 +248,9 @@ fs_destroy (GtkObject *object)
if (fs->gnome_font)
gtk_object_unref (GTK_OBJECT (fs->gnome_font));
if (fs->display_font)
gtk_object_unref (GTK_OBJECT (fs->display_font));
gtk_object_unref (GTK_OBJECT (fs->display_font));
gnome_font_family_list_free (fs->family_list);
(