1
1

Moved the text icon layout code from here.

Этот коммит содержится в:
Miguel de Icaza 1998-05-18 22:48:48 +00:00
родитель c50ced7273
Коммит f4a5f85ecf
4 изменённых файлов: 62 добавлений и 199 удалений

Просмотреть файл

@ -1,3 +1,8 @@
1998-05-15 Miguel de Icaza <miguel@nuclecu.unam.mx>
* gscreen.c (create_popup_submenu): Use continue, not break on
this loop.
Sat May 16 02:29:51 1998 Tom Tromey <tromey@cygnus.com>
* gdesktop.c (url_dropped): `exec' field of desktop entry now a

Просмотреть файл

@ -23,154 +23,6 @@ int want_transparent_text = 0;
* - Federico
*/
struct text_info {
GList *rows;
GdkFont *font;
int width;
int height;
int baseline_skip;
};
static void
free_string (gpointer data, gpointer user_data)
{
if (data)
g_free (data);
}
static void
text_info_free (struct text_info *ti)
{
g_list_foreach (ti->rows, free_string, NULL);
g_list_free (ti->rows);
g_free (ti);
}
static struct text_info *
layout_text (GtkWidget *widget, char *text)
{
struct text_info *ti;
char *row_end, *row_text, *break_pos;
int i, row_width, window_width;
size_t len;
ti = g_new (struct text_info, 1);
ti->rows = NULL;
ti->font = widget->style->font;
ti->width = 0;
ti->height = 0;
ti->baseline_skip = ti->font->ascent + ti->font->descent;
window_width = 0;
while (*text) {
row_end = strchr (text, '\n');
if (!row_end)
row_end = strchr (text, '\0');
len = row_end - text + 1;
row_text = g_new (char, len);
memcpy (row_text, text, len - 1);
row_text[len - 1] = '\0';
/* Adjust the window's width or shorten the row until
* it fits in the window.
*/
while (1) {
row_width = gdk_string_width (ti->font, row_text);
if (!window_width) {
/* make an initial guess at window's width */
if (row_width > SNAP_X)
window_width = SNAP_X;
else
window_width = row_width;
}
if (row_width <= window_width)
break;
if (strchr (row_text, ' ')) {
/* the row is currently too wide, but we have
* blanks in the row so we can break it into
* smaller pieces
*/
int avg_width = row_width / strlen (row_text);
i = window_width;
if (avg_width != 0)
i /= avg_width;
if ((size_t) i >= len)
i = len - 1;
break_pos = strchr (row_text + i, ' ');
if (!break_pos) {
break_pos = row_text+ i;
while (*--break_pos != ' ');
}
*break_pos = '\0';
} else {
/* We can't break this row into any smaller
* pieces, so we have no choice but to widen
* the window
*
* For MC, we may want to modify the code above
* so that it can also split the string on the
* slahes of filenames.
*/
window_width = row_width;
break;
}
}
if (row_width > ti->width)
ti->width = row_width;
ti->rows = g_list_append (ti->rows, row_text);
ti->height += ti->baseline_skip;
text += strlen (row_text);
if (!*text)
break;
if (text[0] == '\n' && text[1]) {
/* end of paragraph and there is more text to come */
ti->rows = g_list_append (ti->rows, NULL);
ti->height += ti->baseline_skip / 2;
}
text++; /* skip blank or newline */
}
return ti;
}
static void
paint_text (struct text_info *ti, GdkDrawable *drawable, GdkGC *gc, int x_ofs, int y_ofs)
{
int y, w;
GList *item;
y = y_ofs + ti->font->ascent;
for (item = ti->rows; item; item = item->next) {
if (item->data) {
w = gdk_string_width (ti->font, item->data);
gdk_draw_string (drawable, ti->font, gc, x_ofs + (ti->width - w) / 2, y, item->data);
y += ti->baseline_skip;
} else
y += ti->baseline_skip / 2;
}
}
static void
set_window_text (GtkWidget *window, GdkImlibImage *im, char *text)
@ -179,12 +31,12 @@ set_window_text (GtkWidget *window, GdkImlibImage *im, char *text)
GdkPixmap *im_pixmap;
GdkBitmap *mask;
GdkBitmap *im_mask;
struct text_info *ti;
struct gnome_icon_text_info *ti;
GdkColor color;
GdkGC *p_gc, *m_gc;
int width, height;
ti = layout_text (window, text);
ti = gnome_icon_layout_text (window->style->font, text, SNAP_X);
width = MAX (ti->width, im->rgb_width);
height = im->rgb_height + SPACING + ti->height;
@ -296,16 +148,18 @@ set_window_text (GtkWidget *window, GdkImlibImage *im, char *text)
} else {
color.pixel = 1;
gdk_gc_set_foreground (m_gc, &color);
paint_text (ti, mask, m_gc,
(width - ti->width) / 2,
im->rgb_height + SPACING);
gnome_icon_paint_text (ti, mask, m_gc,
(width - ti->width) / 2,
im->rgb_height + SPACING,
ti->width);
}
gdk_color_white (gdk_imlib_get_colormap (), &color);
gdk_gc_set_foreground (p_gc, &color);
paint_text (ti, pixmap, p_gc,
(width - ti->width) / 2,
im->rgb_height + SPACING);
gnome_icon_paint_text (ti, pixmap, p_gc,
(width - ti->width) / 2,
im->rgb_height + SPACING,
ti->width);
/* Set contents of window */
@ -319,7 +173,7 @@ set_window_text (GtkWidget *window, GdkImlibImage *im, char *text)
gdk_pixmap_unref (pixmap);
gdk_pixmap_unref (mask);
text_info_free (ti);
gnome_icon_text_info_free (ti);
}
static void

Просмотреть файл

@ -1,6 +1,6 @@
msgid ""
msgstr ""
"Date: 1998-05-13 21:20:19-0500\n"
"Date: 1998-05-18 14:24:05-0500\n"
"From: Miguel de Icaza,computo,622-4680 <miguel@metropolis.nuclecu.unam.mx>\n"
"Content-Type: text/plain; charset=\n"
"Xgettext-Options: --default-domain=mc --directory=.. --add-comments --keyword=_ --keyword=N_ --files-from=./POTFILES.in\n"
@ -62,7 +62,7 @@ msgstr ""
msgid " Save As "
msgstr ""
#: edit/editcmd.c:413 edit/editcmd.c:722 edit/editcmd.c:734 edit/editcmd.c:835 edit/editcmd.c:918 gnome/gdesktop.c:1303 src/ext.c:295 src/help.c:320 src/main.c:685 src/subshell.c:696 src/subshell.c:722 src/utilunix.c:374 src/utilunix.c:378 src/utilunix.c:444
#: edit/editcmd.c:413 edit/editcmd.c:722 edit/editcmd.c:734 edit/editcmd.c:835 edit/editcmd.c:918 gnome/gdesktop.c:1306 src/ext.c:295 src/help.c:320 src/main.c:685 src/subshell.c:696 src/subshell.c:722 src/utilunix.c:374 src/utilunix.c:378 src/utilunix.c:444
msgid " Warning "
msgstr ""
@ -308,11 +308,11 @@ msgstr ""
msgid "Cancel quit"
msgstr ""
#: edit/editcmd.c:1969 gnome/gcmd.c:94 gnome/gdesktop.c:806 gnome/gdesktop.c:1118 src/cmd.c:248 src/file.c:2328 src/file.c:2654 src/file.c:2844 src/hotlist.c:1027 src/main.c:840 src/screen.c:2040 src/subshell.c:697 src/subshell.c:723 src/tree.c:1195 src/view.c:410
#: edit/editcmd.c:1969 gnome/gcmd.c:94 gnome/gdesktop.c:806 gnome/gdesktop.c:1121 src/cmd.c:248 src/file.c:2328 src/file.c:2654 src/file.c:2844 src/hotlist.c:1027 src/main.c:840 src/screen.c:2040 src/subshell.c:697 src/subshell.c:723 src/tree.c:1195 src/view.c:410
msgid "&Yes"
msgstr ""
#: edit/editcmd.c:1969 gnome/gcmd.c:94 gnome/gdesktop.c:806 gnome/gdesktop.c:1118 src/cmd.c:248 src/file.c:2328 src/file.c:2653 src/file.c:2844 src/hotlist.c:1027 src/main.c:840 src/screen.c:2040 src/subshell.c:697 src/subshell.c:723 src/tree.c:1195 src/view.c:410
#: edit/editcmd.c:1969 gnome/gcmd.c:94 gnome/gdesktop.c:806 gnome/gdesktop.c:1121 src/cmd.c:248 src/file.c:2328 src/file.c:2653 src/file.c:2844 src/hotlist.c:1027 src/main.c:840 src/screen.c:2040 src/subshell.c:697 src/subshell.c:723 src/tree.c:1195 src/view.c:410
msgid "&No"
msgstr ""
@ -2605,7 +2605,7 @@ msgstr ""
msgid " The shell is already running a command "
msgstr ""
#: gnome/gcmd.c:92 gnome/gdesktop.c:1116 src/main.c:838 src/screen.c:2038
#: gnome/gcmd.c:92 gnome/gdesktop.c:1119 src/main.c:838 src/screen.c:2038
msgid " The Midnight Commander "
msgstr ""
@ -3208,7 +3208,7 @@ msgstr ""
msgid " %s bytes in %d file%s"
msgstr ""
#: gnome/gscreen.c:1490 src/screen.c:671
#: gnome/gscreen.c:1492 src/screen.c:671
msgid "<readlink failed>"
msgstr ""
@ -3216,11 +3216,11 @@ msgstr ""
msgid "Unknow tag on display format: "
msgstr ""
#: gnome/gdesktop.c:1117 src/screen.c:2039
#: gnome/gdesktop.c:1120 src/screen.c:2039
msgid " Do you really want to execute? "
msgstr ""
#: gnome/glayout.c:274 gnome/gscreen.c:515 src/screen.c:2258 src/screen.c:2292
#: gnome/glayout.c:274 gnome/gscreen.c:516 src/screen.c:2258 src/screen.c:2292
msgid "View"
msgstr ""
@ -3732,19 +3732,19 @@ msgstr ""
msgid "Do you want to delete "
msgstr ""
#: gnome/gdesktop.c:1008 gnome/gscreen.c:511
#: gnome/gdesktop.c:1008 gnome/gscreen.c:512
msgid "Properties"
msgstr ""
#: gnome/gdesktop.c:1127
#: gnome/gdesktop.c:1130
msgid "Open with..."
msgstr ""
#: gnome/gdesktop.c:1128 gnome/gscreen.c:463
#: gnome/gdesktop.c:1131 gnome/gscreen.c:464
msgid "Enter extra arguments:"
msgstr ""
#: gnome/gdesktop.c:1303
#: gnome/gdesktop.c:1306
msgid " Could not open %s directory"
msgstr ""
@ -3756,7 +3756,7 @@ msgstr ""
msgid "Opens a terminal"
msgstr ""
#: gnome/glayout.c:269 gnome/gscreen.c:530
#: gnome/glayout.c:269 gnome/gscreen.c:531
msgid "Copy..."
msgstr ""
@ -3780,7 +3780,7 @@ msgstr ""
msgid "Creates a new folder"
msgstr ""
#: gnome/glayout.c:272 gnome/gscreen.c:532
#: gnome/glayout.c:272 gnome/gscreen.c:533
msgid "Delete..."
msgstr ""
@ -4077,115 +4077,115 @@ msgstr ""
msgid "Select icon"
msgstr ""
#: gnome/gscreen.c:462
#: gnome/gscreen.c:463
msgid " Open with..."
msgstr ""
#: gnome/gscreen.c:513
#: gnome/gscreen.c:514
msgid "Open"
msgstr ""
#: gnome/gscreen.c:514
#: gnome/gscreen.c:515
msgid "Open with"
msgstr ""
#: gnome/gscreen.c:516
#: gnome/gscreen.c:517
msgid "View unfiltered"
msgstr ""
#: gnome/gscreen.c:518
#: gnome/gscreen.c:519
msgid "Link..."
msgstr ""
#: gnome/gscreen.c:519
#: gnome/gscreen.c:520
msgid "Symlink..."
msgstr ""
#: gnome/gscreen.c:520
#: gnome/gscreen.c:521
msgid "Edit symlink..."
msgstr ""
#: gnome/gscreen.c:531
#: gnome/gscreen.c:532
msgid "Rename/move.."
msgstr ""
#: gnome/gscreen.c:1298
#: gnome/gscreen.c:1300
msgid "All files"
msgstr ""
#: gnome/gscreen.c:1300
#: gnome/gscreen.c:1302
msgid "Archives and compressed files"
msgstr ""
#: gnome/gscreen.c:1302
#: gnome/gscreen.c:1304
msgid "RPM/DEB files"
msgstr ""
#: gnome/gscreen.c:1304
#: gnome/gscreen.c:1306
msgid "Text/Document files"
msgstr ""
#: gnome/gscreen.c:1306
#: gnome/gscreen.c:1308
msgid "HTML and SGML files"
msgstr ""
#: gnome/gscreen.c:1308
#: gnome/gscreen.c:1310
msgid "Postscript and PDF files"
msgstr ""
#: gnome/gscreen.c:1310
#: gnome/gscreen.c:1312
msgid "Spreadsheet files"
msgstr ""
#: gnome/gscreen.c:1312
#: gnome/gscreen.c:1314
msgid "Image files"
msgstr ""
#: gnome/gscreen.c:1315
#: gnome/gscreen.c:1317
msgid "Video/animation files"
msgstr ""
#: gnome/gscreen.c:1317
#: gnome/gscreen.c:1319
msgid "Audio files"
msgstr ""
#: gnome/gscreen.c:1319
#: gnome/gscreen.c:1321
msgid "C program files"
msgstr ""
#: gnome/gscreen.c:1321
#: gnome/gscreen.c:1323
msgid "C++ program files"
msgstr ""
#: gnome/gscreen.c:1323
#: gnome/gscreen.c:1325
msgid "Objective-C program files"
msgstr ""
#: gnome/gscreen.c:1325
#: gnome/gscreen.c:1327
msgid "Scheme program files"
msgstr ""
#: gnome/gscreen.c:1327
#: gnome/gscreen.c:1329
msgid "Assembler program files"
msgstr ""
#: gnome/gscreen.c:1329
#: gnome/gscreen.c:1331
msgid "Misc. program files"
msgstr ""
#: gnome/gscreen.c:1331
#: gnome/gscreen.c:1333
msgid "Font files"
msgstr ""
#: gnome/gscreen.c:1456
#: gnome/gscreen.c:1458
msgid "Search: "
msgstr ""
#: gnome/gscreen.c:1466
#: gnome/gscreen.c:1468
msgid " %s bytes in %d file%s"
msgstr ""
#: gnome/gscreen.c:1541
#: gnome/gscreen.c:1543
msgid "Filter"
msgstr ""

Просмотреть файл

@ -1,3 +1,7 @@
1998-05-18 Miguel de Icaza <miguel@nuclecu.unam.mx>
* menu.c (menubar_drop_compute): Check for inrange items.
1998-05-15 Miguel de Icaza <miguel@nuclecu.unam.mx>
* color.c (init_colors): Provide X-only version of color