2 * (C) 1998 The Free Software Foundation
4 * Author: Miguel de Icaza (miguel@kernel.org)
6 * Clipped label: This label is differnt from the one on Gtk as it
7 * does requests no space, but uses all that is given to it.
9 * It does not queue an resize when changing the text.
13 #include "gcliplabel.h"
14 #include <gtk/gtkcompat.h>
16 static void gtk_clip_label_class_init (GtkClipLabelClass
*klass
);
17 static void gtk_clip_label_size_request (GtkWidget
*widget
,
18 GtkRequisition
*requisition
);
19 static void gtk_clip_label_size_allocate (GtkWidget
*widget
,
20 GtkAllocation
*allocation
);
22 static GtkLabelClass
*parent_class
= NULL
;
25 gtk_clip_label_get_type ()
27 static guint label_type
= 0;
31 GtkTypeInfo clip_label_info
=
34 sizeof (GtkClipLabel
),
35 sizeof (GtkClipLabelClass
),
36 (GtkClassInitFunc
) gtk_clip_label_class_init
,
37 (GtkObjectInitFunc
) NULL
,
42 label_type
= gtk_type_unique (gtk_label_get_type (), &clip_label_info
);
49 gtk_clip_label_class_init (GtkClipLabelClass
*class)
51 GtkWidgetClass
*widget_class
;
53 parent_class
= gtk_type_class (gtk_label_get_type ());
55 widget_class
= (GtkWidgetClass
*) class;
56 widget_class
->size_request
= gtk_clip_label_size_request
;
57 widget_class
->size_allocate
= gtk_clip_label_size_allocate
;
61 gtk_clip_label_set (GtkLabel
*label
,
64 gtk_label_set_text (label
, str
);
68 gtk_clip_label_new (const char *str
)
72 g_return_val_if_fail (str
!= NULL
, NULL
);
74 label
= gtk_type_new (gtk_clip_label_get_type ());
76 gtk_label_set_text (GTK_LABEL (label
), str
);
78 return GTK_WIDGET (label
);
82 gtk_clip_label_size_request (GtkWidget
*widget
,
83 GtkRequisition
*requisition
)
87 g_return_if_fail (widget
!= NULL
);
88 g_return_if_fail (GTK_IS_CLIP_LABEL (widget
));
89 g_return_if_fail (requisition
!= NULL
);
91 label
= GTK_CLIP_LABEL (widget
);
93 ((GtkWidgetClass
*)parent_class
)->size_request (widget
, requisition
);
95 requisition
->width
= GTK_LABEL (label
)->misc
.xpad
* 2;
99 gtk_clip_label_size_allocate (GtkWidget
*widget
,
100 GtkAllocation
*alloc
)
102 ((GtkWidgetClass
*)parent_class
)->size_allocate (widget
, alloc
);
104 widget
->requisition
.width
= alloc
->width
;