Add support for line wrappping.

* libnautilus-extensions/nautilus-label.c:
	(nautilus_label_initialize), (nautilus_label_destroy),
	(render_buffer_pixbuf), (label_recompute_line_geometries),
	(nautilus_label_set_line_offset),
	(nautilus_label_get_drop_shadow_color),
	(nautilus_label_set_line_wrap), (nautilus_label_get_line_wrap),
	(nautilus_label_set_line_wrap_width),
	(nautilus_label_get_line_wrap_width),
	(nautilus_label_set_line_wrap_separators),
	(nautilus_label_get_line_wrap_separators):
	* libnautilus-extensions/nautilus-label.h:
	Add support for line wrappping.

	* src/nautilus-shell.c: (display_caveat):
	Change the caveat text to not use hard coded new lines and use the
	new NautilusLabel text wrapping feature instead.

	* test/.cvsignore:
	* test/Makefile.am:
	* test/test-nautilus-label.c: (main):
	* test/test-nautilus-wrapped-label.c: (delete_event),
	(create_gtk_label), (create_nautilus_label),
	(create_gtk_label_window), (create_nautilus_label_window), (main):
	Add a test for the NautilusLabel line wrapping feature.
This commit is contained in:
Ramiro Estrugo 2000-10-16 18:22:11 +00:00
parent 2c8f67f129
commit 33dad502eb
10 changed files with 677 additions and 23 deletions

View file

@ -1,3 +1,30 @@
2000-10-16 Ramiro Estrugo <ramiro@eazel.com>
* libnautilus-extensions/nautilus-label.c:
(nautilus_label_initialize), (nautilus_label_destroy),
(render_buffer_pixbuf), (label_recompute_line_geometries),
(nautilus_label_set_line_offset),
(nautilus_label_get_drop_shadow_color),
(nautilus_label_set_line_wrap), (nautilus_label_get_line_wrap),
(nautilus_label_set_line_wrap_width),
(nautilus_label_get_line_wrap_width),
(nautilus_label_set_line_wrap_separators),
(nautilus_label_get_line_wrap_separators):
* libnautilus-extensions/nautilus-label.h:
Add support for line wrappping.
* src/nautilus-shell.c: (display_caveat):
Change the caveat text to not use hard coded new lines and use the
new NautilusLabel text wrapping feature instead.
* test/.cvsignore:
* test/Makefile.am:
* test/test-nautilus-label.c: (main):
* test/test-nautilus-wrapped-label.c: (delete_event),
(create_gtk_label), (create_nautilus_label),
(create_gtk_label_window), (create_nautilus_label_window), (main):
Add a test for the NautilusLabel line wrapping feature.
2000-10-16 Gene Z. Ragan <gzr@eazel.com>
Fixed an error where I was escaping the wrong item

View file

@ -25,6 +25,7 @@
#include <config.h>
#include "nautilus-label.h"
#include <libgnome/gnome-i18n.h>
#include "nautilus-gtk-macros.h"
#include "nautilus-gdk-extensions.h"
#include "nautilus-gdk-pixbuf-extensions.h"
@ -66,6 +67,12 @@ struct _NautilusLabelDetail
guint num_text_lines;
guint max_text_line_width;
guint total_text_line_height;
/* Line wrapping */
gboolean line_wrap;
guint line_wrap_width;
char *line_wrap_separators;
NautilusTextLayout **text_layouts;
};
/* GtkObjectClass methods */
@ -164,6 +171,11 @@ nautilus_label_initialize (NautilusLabel *label)
label->detail->line_offset = 2;
label->detail->drop_shadow_offset = 0;
label->detail->line_wrap = FALSE;
label->detail->line_wrap_width = 400;
label->detail->line_wrap_separators = g_strdup (_(" -_,;.?/&"));
label->detail->text_layouts = NULL;
}
/* GtkObjectClass methods */
@ -182,6 +194,17 @@ nautilus_label_destroy (GtkObject *object)
g_free (label->detail->text_line_widths);
g_free (label->detail->text_line_heights);
if (label->detail->text_layouts != NULL) {
guint i;
for (i = 0; i < label->detail->num_text_lines; i++) {
g_assert (label->detail->text_layouts[i] != NULL);
nautilus_text_layout_free (label->detail->text_layouts[i]);
}
g_free (label->detail->text_layouts);
}
g_free (label->detail);
/* Chain destroy */
@ -344,7 +367,44 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
text_x = 0;
text_y = 0;
if (label->detail->num_text_lines > 0) {
if (label->detail->num_text_lines == 0) {
return;
}
/* Line wrapping */
if (label->detail->line_wrap) {
guint i;
guint x = 0;
guint y = 0;
for (i = 0; i < label->detail->num_text_lines; i++) {
const NautilusTextLayout *text_layout = label->detail->text_layouts[i];
if (label->detail->drop_shadow_offset > 0) {
nautilus_text_layout_paint (text_layout,
buffer,
x + label->detail->drop_shadow_offset,
y + label->detail->drop_shadow_offset,
label->detail->text_justification,
label->detail->drop_shadow_color,
FALSE,
FALSE);
}
nautilus_text_layout_paint (text_layout,
buffer,
x,
y,
label->detail->text_justification,
label->detail->text_color,
FALSE,
FALSE);
y += text_layout->height;
}
}
/* No line wrapping */
else {
if (label->detail->drop_shadow_offset > 0) {
text_x += label->detail->drop_shadow_offset;
text_y += label->detail->drop_shadow_offset;
@ -427,17 +487,69 @@ label_recompute_line_geometries (NautilusLabel *label)
label->detail->text_line_widths = NULL;
label->detail->text_line_heights = NULL;
if (label->detail->text_layouts != NULL) {
guint i;
for (i = 0; i < label->detail->num_text_lines; i++) {
g_assert (label->detail->text_layouts[i] != NULL);
nautilus_text_layout_free (label->detail->text_layouts[i]);
}
g_free (label->detail->text_layouts);
label->detail->text_layouts = NULL;
}
label->detail->num_text_lines = 0;
label->detail->max_text_line_width = 0;
label->detail->total_text_line_height = 0;
if (nautilus_strlen (label->detail->text) > 0) {
label->detail->num_text_lines = nautilus_str_count_characters (label->detail->text, '\n') + 1;
if (nautilus_strlen (label->detail->text) == 0) {
return;
}
label->detail->num_text_lines = nautilus_str_count_characters (label->detail->text, '\n') + 1;
/* Line wrapping */
if (label->detail->line_wrap) {
char **pieces;
guint i;
label->detail->text_layouts = g_new (NautilusTextLayout *, label->detail->num_text_lines);
pieces = g_strsplit (label->detail->text, "\n", 0);
for (i = 0; pieces[i] != NULL; i++) {
char *text_piece = pieces[i];
g_assert (i < label->detail->num_text_lines);
/* Make empty lines appear. A single '\n' for example. */
if (text_piece[0] == '\0') {
text_piece = " ";
}
label->detail->text_layouts[i] = nautilus_text_layout_new (label->detail->font,
label->detail->font_size,
text_piece,
label->detail->line_wrap_separators,
label->detail->line_wrap_width,
TRUE);
label->detail->total_text_line_height += label->detail->text_layouts[i]->height;
if (label->detail->text_layouts[i]->width > label->detail->max_text_line_width) {
label->detail->max_text_line_width = label->detail->text_layouts[i]->width;
}
}
g_strfreev (pieces);
}
/* No line wrapping */
else {
label->detail->text_line_widths = g_new (guint, label->detail->num_text_lines);
label->detail->text_line_heights = g_new (guint, label->detail->num_text_lines);
nautilus_scalable_font_measure_text_lines (label->detail->font,
label->detail->font_size,
label->detail->font_size,
@ -668,7 +780,7 @@ nautilus_label_get_text_justification (const NautilusLabel *label)
*/
void
nautilus_label_set_line_offset (NautilusLabel *label,
guint line_offset)
guint line_offset)
{
g_return_if_fail (NAUTILUS_IS_LABEL (label));
@ -775,7 +887,138 @@ nautilus_label_get_drop_shadow_color (const NautilusLabel *label)
{
g_return_val_if_fail (label != NULL, 0);
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
return label->detail->drop_shadow_color;
}
/**
* nautilus_label_set_line_wrap:
*
* @label: A NautilusLabel
* @line_wrap: A boolean value indicating whether the label should
* line wrap words if they dont fit in the horizontally allocated
* space.
*
*/
void
nautilus_label_set_line_wrap (NautilusLabel *label,
gboolean line_wrap)
{
g_return_if_fail (NAUTILUS_IS_LABEL (label));
if (label->detail->line_wrap == line_wrap) {
return;
}
label->detail->line_wrap = line_wrap;
label_recompute_line_geometries (label);
gtk_widget_queue_resize (GTK_WIDGET (label));
}
/**
* nautilus_label_get_line_wrap:
*
* @label: A NautilusLabel
*
* Return value: A boolean value indicating whether the label
* is currently line wrapping text.
*/
gboolean
nautilus_label_get_line_wrap (const NautilusLabel *label)
{
g_return_val_if_fail (label != NULL, FALSE);
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), FALSE);
return label->detail->line_wrap;
}
/**
* nautilus_label_set_line_wrap_width:
*
* @label: A NautilusLabel
* @line_wrap_width: The new line wrap width.
*
* The line wrap width is something.
*
*/
void
nautilus_label_set_line_wrap_width (NautilusLabel *label,
guint line_wrap_width)
{
g_return_if_fail (NAUTILUS_IS_LABEL (label));
if (label->detail->line_wrap_width == line_wrap_width) {
return;
}
label->detail->line_wrap_width = line_wrap_width;
label_recompute_line_geometries (label);
gtk_widget_queue_resize (GTK_WIDGET (label));
}
/**
* nautilus_label_get_line_wrap_width:
*
* @label: A NautilusLabel
*
* Return value: A boolean value indicating whether the label
* is currently line wrapping text.
*/
guint
nautilus_label_get_line_wrap_width (const NautilusLabel *label)
{
g_return_val_if_fail (label != NULL, FALSE);
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), FALSE);
return label->detail->line_wrap_width;
}
/**
* nautilus_label_set_line_wrap_separators:
*
* @label: A NautilusLabel
* @line_wrap_separators: The new line wrap separators.
*
* The line wrap separators is something.
*
*/
void
nautilus_label_set_line_wrap_separators (NautilusLabel *label,
const char *line_wrap_separators)
{
g_return_if_fail (NAUTILUS_IS_LABEL (label));
g_return_if_fail (line_wrap_separators != NULL);
g_return_if_fail (line_wrap_separators[0] != '\0');
g_return_if_fail (strlen (line_wrap_separators) > 0);
if (nautilus_str_is_equal (label->detail->line_wrap_separators, line_wrap_separators)) {
return;
}
label->detail->line_wrap_separators = g_strdup (line_wrap_separators);
label_recompute_line_geometries (label);
gtk_widget_queue_resize (GTK_WIDGET (label));
}
/**
* nautilus_label_get_line_wrap_separators:
*
* @label: A NautilusLabel
*
* Return value: A boolean value indicating whether the label
* is currently line wrapping text.
*/
char *
nautilus_label_get_line_wrap_separators (const NautilusLabel *label)
{
g_return_val_if_fail (label != NULL, FALSE);
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), FALSE);
return g_strdup (label->detail->line_wrap_separators);
}

View file

@ -103,6 +103,15 @@ guint nautilus_label_get_drop_shadow_offset (const NautilusLab
void nautilus_label_set_drop_shadow_color (NautilusLabel *label,
guint32 color);
guint32 nautilus_label_get_drop_shadow_color (const NautilusLabel *label);
void nautilus_label_set_line_wrap (NautilusLabel *label,
gboolean line_wrap);
gboolean nautilus_label_get_line_wrap (const NautilusLabel *label);
void nautilus_label_set_line_wrap_width (NautilusLabel *label,
guint line_wrap_width);
guint nautilus_label_get_line_wrap_width (const NautilusLabel *label);
void nautilus_label_set_line_wrap_separators (NautilusLabel *label,
const char *separators);
char * nautilus_label_get_line_wrap_separators (const NautilusLabel *label);
END_GNOME_DECLS

View file

@ -25,6 +25,7 @@
#include <config.h>
#include "nautilus-label.h"
#include <libgnome/gnome-i18n.h>
#include "nautilus-gtk-macros.h"
#include "nautilus-gdk-extensions.h"
#include "nautilus-gdk-pixbuf-extensions.h"
@ -66,6 +67,12 @@ struct _NautilusLabelDetail
guint num_text_lines;
guint max_text_line_width;
guint total_text_line_height;
/* Line wrapping */
gboolean line_wrap;
guint line_wrap_width;
char *line_wrap_separators;
NautilusTextLayout **text_layouts;
};
/* GtkObjectClass methods */
@ -164,6 +171,11 @@ nautilus_label_initialize (NautilusLabel *label)
label->detail->line_offset = 2;
label->detail->drop_shadow_offset = 0;
label->detail->line_wrap = FALSE;
label->detail->line_wrap_width = 400;
label->detail->line_wrap_separators = g_strdup (_(" -_,;.?/&"));
label->detail->text_layouts = NULL;
}
/* GtkObjectClass methods */
@ -182,6 +194,17 @@ nautilus_label_destroy (GtkObject *object)
g_free (label->detail->text_line_widths);
g_free (label->detail->text_line_heights);
if (label->detail->text_layouts != NULL) {
guint i;
for (i = 0; i < label->detail->num_text_lines; i++) {
g_assert (label->detail->text_layouts[i] != NULL);
nautilus_text_layout_free (label->detail->text_layouts[i]);
}
g_free (label->detail->text_layouts);
}
g_free (label->detail);
/* Chain destroy */
@ -344,7 +367,44 @@ render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
text_x = 0;
text_y = 0;
if (label->detail->num_text_lines > 0) {
if (label->detail->num_text_lines == 0) {
return;
}
/* Line wrapping */
if (label->detail->line_wrap) {
guint i;
guint x = 0;
guint y = 0;
for (i = 0; i < label->detail->num_text_lines; i++) {
const NautilusTextLayout *text_layout = label->detail->text_layouts[i];
if (label->detail->drop_shadow_offset > 0) {
nautilus_text_layout_paint (text_layout,
buffer,
x + label->detail->drop_shadow_offset,
y + label->detail->drop_shadow_offset,
label->detail->text_justification,
label->detail->drop_shadow_color,
FALSE,
FALSE);
}
nautilus_text_layout_paint (text_layout,
buffer,
x,
y,
label->detail->text_justification,
label->detail->text_color,
FALSE,
FALSE);
y += text_layout->height;
}
}
/* No line wrapping */
else {
if (label->detail->drop_shadow_offset > 0) {
text_x += label->detail->drop_shadow_offset;
text_y += label->detail->drop_shadow_offset;
@ -427,17 +487,69 @@ label_recompute_line_geometries (NautilusLabel *label)
label->detail->text_line_widths = NULL;
label->detail->text_line_heights = NULL;
if (label->detail->text_layouts != NULL) {
guint i;
for (i = 0; i < label->detail->num_text_lines; i++) {
g_assert (label->detail->text_layouts[i] != NULL);
nautilus_text_layout_free (label->detail->text_layouts[i]);
}
g_free (label->detail->text_layouts);
label->detail->text_layouts = NULL;
}
label->detail->num_text_lines = 0;
label->detail->max_text_line_width = 0;
label->detail->total_text_line_height = 0;
if (nautilus_strlen (label->detail->text) > 0) {
label->detail->num_text_lines = nautilus_str_count_characters (label->detail->text, '\n') + 1;
if (nautilus_strlen (label->detail->text) == 0) {
return;
}
label->detail->num_text_lines = nautilus_str_count_characters (label->detail->text, '\n') + 1;
/* Line wrapping */
if (label->detail->line_wrap) {
char **pieces;
guint i;
label->detail->text_layouts = g_new (NautilusTextLayout *, label->detail->num_text_lines);
pieces = g_strsplit (label->detail->text, "\n", 0);
for (i = 0; pieces[i] != NULL; i++) {
char *text_piece = pieces[i];
g_assert (i < label->detail->num_text_lines);
/* Make empty lines appear. A single '\n' for example. */
if (text_piece[0] == '\0') {
text_piece = " ";
}
label->detail->text_layouts[i] = nautilus_text_layout_new (label->detail->font,
label->detail->font_size,
text_piece,
label->detail->line_wrap_separators,
label->detail->line_wrap_width,
TRUE);
label->detail->total_text_line_height += label->detail->text_layouts[i]->height;
if (label->detail->text_layouts[i]->width > label->detail->max_text_line_width) {
label->detail->max_text_line_width = label->detail->text_layouts[i]->width;
}
}
g_strfreev (pieces);
}
/* No line wrapping */
else {
label->detail->text_line_widths = g_new (guint, label->detail->num_text_lines);
label->detail->text_line_heights = g_new (guint, label->detail->num_text_lines);
nautilus_scalable_font_measure_text_lines (label->detail->font,
label->detail->font_size,
label->detail->font_size,
@ -668,7 +780,7 @@ nautilus_label_get_text_justification (const NautilusLabel *label)
*/
void
nautilus_label_set_line_offset (NautilusLabel *label,
guint line_offset)
guint line_offset)
{
g_return_if_fail (NAUTILUS_IS_LABEL (label));
@ -775,7 +887,138 @@ nautilus_label_get_drop_shadow_color (const NautilusLabel *label)
{
g_return_val_if_fail (label != NULL, 0);
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
return label->detail->drop_shadow_color;
}
/**
* nautilus_label_set_line_wrap:
*
* @label: A NautilusLabel
* @line_wrap: A boolean value indicating whether the label should
* line wrap words if they dont fit in the horizontally allocated
* space.
*
*/
void
nautilus_label_set_line_wrap (NautilusLabel *label,
gboolean line_wrap)
{
g_return_if_fail (NAUTILUS_IS_LABEL (label));
if (label->detail->line_wrap == line_wrap) {
return;
}
label->detail->line_wrap = line_wrap;
label_recompute_line_geometries (label);
gtk_widget_queue_resize (GTK_WIDGET (label));
}
/**
* nautilus_label_get_line_wrap:
*
* @label: A NautilusLabel
*
* Return value: A boolean value indicating whether the label
* is currently line wrapping text.
*/
gboolean
nautilus_label_get_line_wrap (const NautilusLabel *label)
{
g_return_val_if_fail (label != NULL, FALSE);
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), FALSE);
return label->detail->line_wrap;
}
/**
* nautilus_label_set_line_wrap_width:
*
* @label: A NautilusLabel
* @line_wrap_width: The new line wrap width.
*
* The line wrap width is something.
*
*/
void
nautilus_label_set_line_wrap_width (NautilusLabel *label,
guint line_wrap_width)
{
g_return_if_fail (NAUTILUS_IS_LABEL (label));
if (label->detail->line_wrap_width == line_wrap_width) {
return;
}
label->detail->line_wrap_width = line_wrap_width;
label_recompute_line_geometries (label);
gtk_widget_queue_resize (GTK_WIDGET (label));
}
/**
* nautilus_label_get_line_wrap_width:
*
* @label: A NautilusLabel
*
* Return value: A boolean value indicating whether the label
* is currently line wrapping text.
*/
guint
nautilus_label_get_line_wrap_width (const NautilusLabel *label)
{
g_return_val_if_fail (label != NULL, FALSE);
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), FALSE);
return label->detail->line_wrap_width;
}
/**
* nautilus_label_set_line_wrap_separators:
*
* @label: A NautilusLabel
* @line_wrap_separators: The new line wrap separators.
*
* The line wrap separators is something.
*
*/
void
nautilus_label_set_line_wrap_separators (NautilusLabel *label,
const char *line_wrap_separators)
{
g_return_if_fail (NAUTILUS_IS_LABEL (label));
g_return_if_fail (line_wrap_separators != NULL);
g_return_if_fail (line_wrap_separators[0] != '\0');
g_return_if_fail (strlen (line_wrap_separators) > 0);
if (nautilus_str_is_equal (label->detail->line_wrap_separators, line_wrap_separators)) {
return;
}
label->detail->line_wrap_separators = g_strdup (line_wrap_separators);
label_recompute_line_geometries (label);
gtk_widget_queue_resize (GTK_WIDGET (label));
}
/**
* nautilus_label_get_line_wrap_separators:
*
* @label: A NautilusLabel
*
* Return value: A boolean value indicating whether the label
* is currently line wrapping text.
*/
char *
nautilus_label_get_line_wrap_separators (const NautilusLabel *label)
{
g_return_val_if_fail (label != NULL, FALSE);
g_return_val_if_fail (NAUTILUS_IS_LABEL (label), FALSE);
return g_strdup (label->detail->line_wrap_separators);
}

View file

@ -103,6 +103,15 @@ guint nautilus_label_get_drop_shadow_offset (const NautilusLab
void nautilus_label_set_drop_shadow_color (NautilusLabel *label,
guint32 color);
guint32 nautilus_label_get_drop_shadow_color (const NautilusLabel *label);
void nautilus_label_set_line_wrap (NautilusLabel *label,
gboolean line_wrap);
gboolean nautilus_label_get_line_wrap (const NautilusLabel *label);
void nautilus_label_set_line_wrap_width (NautilusLabel *label,
guint line_wrap_width);
guint nautilus_label_get_line_wrap_width (const NautilusLabel *label);
void nautilus_label_set_line_wrap_separators (NautilusLabel *label,
const char *separators);
char * nautilus_label_get_line_wrap_separators (const NautilusLabel *label);
END_GNOME_DECLS

View file

@ -200,19 +200,21 @@ display_caveat (GtkWindow *parent_window)
}
text = nautilus_label_new
(_("The Nautilus shell is under development; it's not\n"
"ready for daily use. Some features are not yet done,\n"
"partly done, or unstable. The program doesn't look\n"
"or act exactly the way it will in version 1.0."
"\n\n"
"If you do decide to test this version of Nautilus, \n"
"beware. The program could do something \n"
"unpredictable and may even delete or overwrite \n"
"files on your computer."
"\n\n"
(_("The Nautilus shell is under development; it's not "
"ready for daily use. Some features are not yet done, "
"partly done, or unstable. The program doesn't look "
"or act exactly the way it will in version 1.0.\n"
"\n"
"If you do decide to test this version of Nautilus, "
"beware. The program could do something "
"unpredictable and may even delete or overwrite "
"files on your computer.\n"
"\n"
"For more information, visit http://nautilus.eazel.com."));
nautilus_label_set_font_size (NAUTILUS_LABEL (text), 12);
nautilus_label_set_text_justification (NAUTILUS_LABEL (text), GTK_JUSTIFY_LEFT);
nautilus_label_set_line_wrap (NAUTILUS_LABEL (text), TRUE);
nautilus_label_set_line_wrap_width (NAUTILUS_LABEL (text), 300);
gtk_widget_show (text);
gtk_box_pack_start (GTK_BOX (hbox), text, FALSE, FALSE, 0);

View file

@ -9,6 +9,7 @@ test-nautilus-font
test-nautilus-font-picker
test-nautilus-image
test-nautilus-label
test-nautilus-wrapped-label
test-nautilus-mime-actions
test-nautilus-mime-actions-set
test-nautilus-password-dialog

View file

@ -32,6 +32,7 @@ noinst_PROGRAMS =\
test-nautilus-font-picker \
test-nautilus-image \
test-nautilus-label \
test-nautilus-wrapped-label \
test-nautilus-mime-actions \
test-nautilus-mime-actions-set \
test-nautilus-password-dialog \
@ -44,6 +45,7 @@ test_nautilus_font_SOURCES = test-nautilus-font.c
test_nautilus_font_picker_SOURCES = test-nautilus-font-picker.c
test_nautilus_image_SOURCES = test-nautilus-image.c
test_nautilus_label_SOURCES = test-nautilus-label.c
test_nautilus_wrapped_label_SOURCES = test-nautilus-wrapped-label.c
test_nautilus_mime_actions_SOURCES = test-nautilus-mime-actions.c
test_nautilus_mime_actions_set_SOURCES = test-nautilus-mime-actions-set.c
test_nautilus_password_dialog_SOURCES = test-nautilus-password-dialog.c

View file

@ -759,7 +759,7 @@ main (int argc, char* argv[])
main_box = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), main_box);
label = nautilus_label_new ("Label that\n\ndoesn't\n\nsuck");
label = nautilus_label_new ("Label that doesn't suck");
bottom_box = gtk_vbox_new (FALSE, 4);

View file

@ -0,0 +1,118 @@
#include <config.h>
#include <gtk/gtk.h>
#include <libnautilus-extensions/nautilus-label.h>
#include <libnautilus-extensions/nautilus-gdk-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
static void
delete_event (GtkWidget *widget, GdkEvent *event, gpointer callback_data)
{
gtk_main_quit ();
}
static const char text[] =
"The Nautilus shell is under development; it's not "
"ready for daily use. Some features are not yet done, "
"partly done, or unstable. The program doesn't look "
"or act exactly the way it will in version 1.0."
"\n\n"
"If you do decide to test this version of Nautilus, "
"beware. The program could do something "
"unpredictable and may even delete or overwrite "
"files on your computer."
"\n\n"
"For more information, visit http://nautilus.eazel.com.";
static GtkWidget *
create_gtk_label ()
{
GtkWidget *label;
label = gtk_label_new (text);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
return label;
}
static GtkWidget *
create_nautilus_label ()
{
GtkWidget *label;
label = nautilus_label_new (text);
nautilus_label_set_font_size (NAUTILUS_LABEL (label), 20);
nautilus_label_set_line_wrap (NAUTILUS_LABEL (label), TRUE);
nautilus_label_set_text_justification (NAUTILUS_LABEL (label), GTK_JUSTIFY_LEFT);
nautilus_label_set_drop_shadow_offset (NAUTILUS_LABEL (label), 1);
nautilus_buffered_widget_set_background_type (NAUTILUS_BUFFERED_WIDGET(label), NAUTILUS_BACKGROUND_SOLID);
nautilus_buffered_widget_set_background_color (NAUTILUS_BUFFERED_WIDGET(label), NAUTILUS_RGB_COLOR_WHITE);
nautilus_label_set_drop_shadow_color (NAUTILUS_LABEL (label), NAUTILUS_RGB_COLOR_BLUE);
nautilus_label_set_text_color (NAUTILUS_LABEL (label), NAUTILUS_RGB_COLOR_RED);
return label;
}
static GtkWidget *
create_gtk_label_window (void)
{
GtkWidget *gtk_window;
GtkWidget *gtk_vbox;
GtkWidget *gtk_label;
gtk_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
nautilus_gtk_widget_set_background_color (gtk_window, "white");
gtk_signal_connect (GTK_OBJECT (gtk_window), "delete_event", GTK_SIGNAL_FUNC (delete_event), NULL);
gtk_window_set_title (GTK_WINDOW (gtk_window), "Gtk Wrapped Label Test");
gtk_window_set_policy (GTK_WINDOW (gtk_window), TRUE, TRUE, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (gtk_window), 10);
gtk_vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (gtk_window), gtk_vbox);
gtk_label = create_gtk_label ();
gtk_box_pack_start (GTK_BOX (gtk_vbox), gtk_label, TRUE, TRUE, 0);
return gtk_window;
}
static GtkWidget *
create_nautilus_label_window (void)
{
GtkWidget *nautilus_window;
GtkWidget *nautilus_vbox;
GtkWidget *nautilus_label;
nautilus_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
nautilus_gtk_widget_set_background_color (nautilus_window, "white");
gtk_signal_connect (GTK_OBJECT (nautilus_window), "delete_event", GTK_SIGNAL_FUNC (delete_event), NULL);
gtk_window_set_title (GTK_WINDOW (nautilus_window), "Nautilus Wrapped Label Test");
gtk_window_set_policy (GTK_WINDOW (nautilus_window), TRUE, TRUE, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (nautilus_window), 10);
nautilus_vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (nautilus_window), nautilus_vbox);
nautilus_label = create_nautilus_label ();
gtk_box_pack_start (GTK_BOX (nautilus_vbox), nautilus_label, TRUE, TRUE, 0);
return nautilus_window;
}
int
main (int argc, char* argv[])
{
GtkWidget *nautilus_window;
GtkWidget *gtk_window;
gtk_init (&argc, &argv);
gdk_rgb_init ();
nautilus_window = create_nautilus_label_window ();
gtk_window = create_gtk_label_window ();
gtk_widget_show_all (nautilus_window);
gtk_widget_show_all (gtk_window);
gtk_main ();
return 0;
}