cwd input line works/filter handling works/clipping label widget/flashing removed -mig

This commit is contained in:
Miguel de Icaza 1998-03-24 05:25:56 +00:00
parent 38f7b63645
commit f29db51778
10 changed files with 277 additions and 75 deletions

View File

@ -1,3 +1,13 @@
1998-03-23 Miguel de Icaza <miguel@nuclecu.unam.mx>
* gscreen.c (x_fill_panel): Colors are properly displayed now.
Use the clipped labels.
* gcliplabel.c, gcliplabel.h: Derived label that does label
clipping (it does not request the allocation for the whole string,
but settles with whatever is provided in the size_allocation).
1998-03-23 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gtrans.c (create_transparent_text_window): Set the window's

View File

@ -31,7 +31,8 @@ GNOMESRCS = \
gcmd.c \
gprop.c \
gmc-chargrid.c \
gpageprop.c
gpageprop.c \
gcliplabel.c
GNOMEHDRS = \
gmain.h \
@ -42,7 +43,8 @@ GNOMEHDRS = \
gcmd.h \
gprop.h \
gpageprop.h \
gmc-chargrid.h
gmc-chargrid.h \
gcliplabel.h
ICONS = \
$(srcdir)/directory-ok.xpm \
@ -83,7 +85,8 @@ OBJS = $(LOBJS) $(OOBJS) \
gmc-chargrid.o \
gview.o \
gprop.o \
gpageprop.o
gpageprop.o \
gcliplabel.o
#
# Distribution variables

137
gnome/gcliplabel.c Normal file
View File

@ -0,0 +1,137 @@
/*
* (C) 1998 The Free Software Foundation
*
* Author: Miguel de Icaza (miguel@kernel.org)
*
* Clipped label: This label is differnt from the one on Gtk as it
* does requests no space, but uses all that is given to it.
*
* It does not queue an resize when changing the text.
* */
#include <string.h>
#include "gcliplabel.h"
static void gtk_clip_label_class_init (GtkClipLabelClass *klass);
static void gtk_clip_label_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_clip_label_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static GtkLabelClass *parent_class = NULL;
guint
gtk_clip_label_get_type ()
{
static guint label_type = 0;
if (!label_type)
{
GtkTypeInfo clip_label_info =
{
"GtkClipLabel",
sizeof (GtkClipLabel),
sizeof (GtkClipLabelClass),
(GtkClassInitFunc) gtk_clip_label_class_init,
(GtkObjectInitFunc) NULL,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL
};
label_type = gtk_type_unique (gtk_label_get_type (), &clip_label_info);
}
return label_type;
}
static void
gtk_clip_label_class_init (GtkClipLabelClass *class)
{
GtkWidgetClass *widget_class;
parent_class = gtk_type_class (gtk_label_get_type ());
widget_class = (GtkWidgetClass*) class;
widget_class->size_request = gtk_clip_label_size_request;
widget_class->size_allocate = gtk_clip_label_size_allocate;
}
void
gtk_clip_label_set (GtkLabel *label,
const char *str)
{
char* p;
g_return_if_fail (label != NULL);
g_return_if_fail (GTK_IS_LABEL (label));
g_return_if_fail (str != NULL);
if (label->label)
g_free (label->label);
label->label = g_strdup (str);
if (label->row)
g_slist_free (label->row);
label->row = NULL;
label->row = g_slist_append (label->row, label->label);
p = label->label;
while ((p = strchr(p, '\n')))
label->row = g_slist_append (label->row, ++p);
if (GTK_WIDGET_VISIBLE (label))
{
if (GTK_WIDGET_MAPPED (label))
gdk_window_clear_area (GTK_WIDGET (label)->window,
GTK_WIDGET (label)->allocation.x,
GTK_WIDGET (label)->allocation.y,
GTK_WIDGET (label)->allocation.width,
GTK_WIDGET (label)->allocation.height);
gtk_widget_queue_draw (GTK_WIDGET (label));
}
}
GtkWidget*
gtk_clip_label_new (const char *str)
{
GtkClipLabel *label;
g_return_val_if_fail (str != NULL, NULL);
label = gtk_type_new (gtk_clip_label_get_type ());
gtk_label_set (GTK_LABEL (label), str);
return GTK_WIDGET (label);
}
static void
gtk_clip_label_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkClipLabel *label;
GSList *row;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_CLIP_LABEL (widget));
g_return_if_fail (requisition != NULL);
label = GTK_CLIP_LABEL (widget);
((GtkWidgetClass *)parent_class)->size_request (widget, requisition);
requisition->width = GTK_LABEL (label)->misc.xpad * 2;
}
static void
gtk_clip_label_size_allocate (GtkWidget *widget,
GtkAllocation *alloc)
{
((GtkWidgetClass *)parent_class)->size_allocate (widget, alloc);
widget->requisition.width = alloc->width;
}

42
gnome/gcliplabel.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef __GTK_CLIP_LABEL_H__
#define __GTK_CLIP_LABEL_H__
#include <gdk/gdk.h>
#include <gtk/gtklabel.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define GTK_CLIP_LABEL(obj) GTK_CHECK_CAST (obj, gtk_clip_label_get_type (), GtkClipLabel)
#define GTK_CLIP_LABEL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_clip_label_get_type (), GtkClipLabelClass)
#define GTK_IS_CLIP_LABEL(obj) GTK_CHECK_TYPE (obj, gtk_clip_label_get_type ())
typedef struct _GtkClipLabel GtkClipLabel;
typedef struct _GtkClipLabelClass GtkClipLabelClass;
struct _GtkClipLabel
{
GtkLabel misc;
};
struct _GtkClipLabelClass
{
GtkLabelClass parent_class;
};
guint gtk_clip_label_get_type (void);
GtkWidget* gtk_clip_label_new (const char *str);
void gtk_clip_label_set (GtkLabel *label,
const char *str);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GTK_CLIP_LABEL_H__ */

View File

@ -96,10 +96,12 @@ get_desktop_icon (char *pathname)
fname = regex_command (x_basename (pathname), "Icon", 0, 0);
/* Try the GNOME icon */
if (fname){
full_fname = gnome_unconditional_pixmap_file (fname);
if (exist_file (full_fname))
return full_fname;
g_free (full_fname);
}
/* Try a mc icon */
full_fname = concat_dir_and_file (ICONDIR, fname);

View File

@ -17,6 +17,7 @@
#include "boxes.h"
#include "panelize.h"
#include "gcmd.h"
#include "gcliplabel.h"
#define UNDEFINED_INDEX -1

View File

@ -322,20 +322,36 @@ dialog_panel_callback (struct Dlg_head *h, int id, int msg)
{
WPanel *p;
WInput *in;
void *current_widget; /* The widget.wdata of the current widget */
if (msg == DLG_KEY && id == '\n'){
if (h->current->widget->callback == (callback_fn) panel_callback)
return 0;
/*
* If this was a keystroke, and the current widget is not the
* panel, it is the filter
*/
p = (WPanel *) h->current->next->widget;
in = (WInput *) h->current->widget;
/* Find out which one of the widgets is the WPanel */
p = (WPanel *) find_widget_type (h, (callback_fn) panel_callback);
g_return_if_fail (p != 0);
current_widget = (void *) h->current->widget;
printf ("Got an enter\n");
if (current_widget == p->filter_w){
printf ("It is the filter\n");
in = (WInput *) current_widget;
set_panel_filter_to (p, strdup (in->buffer));
}
if (current_widget == p->current_dir){
WInput *in = p->current_dir;
do_panel_cd (p, in->buffer, cd_parse_command);
assign_text (in, p->cwd);
update_input (in);
return MSG_HANDLED;
}
}
return default_dlg_callback (h, id, msg);
}

View File

@ -29,6 +29,7 @@
#include "dialog.h"
#include "gdesktop.h"
#include "gpageprop.h"
#include "gcliplabel.h"
/* The pixmaps */
#include "directory.xpm"
@ -70,7 +71,8 @@ repaint_file (WPanel *panel, int file_index, int move, int attr, int isstatus)
void
show_dir (WPanel *panel)
{
gtk_entry_set_text (GTK_ENTRY (panel->current_dir), panel->cwd);
assign_text (panel->current_dir, panel->cwd);
update_input (panel->current_dir);
}
static void
@ -135,7 +137,7 @@ x_fill_panel (WPanel *panel)
}
gtk_clist_append (cl, texts);
color = file_entry_color (fe);
color = file_compute_color (fe->f.marked ? MARKED : NORMAL, fe);
panel_file_list_set_row_colors (cl, i, color);
if (type_col != -1)
panel_file_list_set_type_bitmap (cl, i, type_col, color, fe);
@ -191,7 +193,6 @@ x_select_item (WPanel *panel)
gtk_clist_select_row (clist, panel->selected, 0);
if (gtk_clist_row_is_visible (clist, panel->selected) != GTK_VISIBILITY_FULL){
printf ("No fue visible %d\n", panel->selected);
gtk_clist_moveto (clist, panel->selected, 0, 0.5, 0.0);
}
}
@ -205,8 +206,8 @@ x_unselect_item (WPanel *panel)
void
x_filter_changed (WPanel *panel)
{
gtk_entry_set_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (panel->filter_w))),
panel->filter ? panel->filter : "");
assign_text (panel->filter_w, panel->filter ? panel->filter : "");
update_input (panel->filter_w);
}
void
@ -226,7 +227,7 @@ panel_file_list_configure_contents (GtkWidget *file_list, WPanel *panel, int mai
int char_width, usable_pixels, extra_pixels, width;
int total_columns, extra_columns;
int expand_space, extra_space, shrink_space;
int lost_pixels;
int lost_pixels, display_the_mini_info;
/* Pass 1: Count minimum columns,
* set field_len to default to the requested_field_len
@ -264,8 +265,17 @@ panel_file_list_configure_contents (GtkWidget *file_list, WPanel *panel, int mai
} else
extra_space = expand_space = 0;
/* Hack: the default mini-info display only gets displayed
* if panel->estimated_total is not zero, ie, if this has been
* initialized for the first time.
*/
display_the_mini_info = (panel->estimated_total == 0);
panel->estimated_total = total_columns;
if (display_the_mini_info)
display_mini_info (panel);
/* If we dont have enough space, shorten the fields */
if (used_columns > total_columns){
expand_space = 0;
@ -672,7 +682,6 @@ panel_build_selected_file_list (WPanel *panel, int *file_list_len)
if (panel->dir.list [i].f.marked)
total_len += (cwdlen + panel->dir.list [i].fnamelen + 1);
printf ("Total lenght: %d\n", total_len);
data = copy = xmalloc (total_len, "build_selected_file_list");
for (i = 0; i < panel->count; i++)
if (panel->dir.list [i].f.marked){
@ -715,8 +724,6 @@ panel_drag_request (GtkWidget *widget, GdkEventDragRequest *event, WPanel *panel
static void
panel_drop_enter (GtkWidget *widget, GdkEvent *event)
{
printf ("%s\n", event->type == GDK_DROP_ENTER ? "DROP ENTER" :
(event->type == GDK_DROP_LEAVE ? "DROP LEAVE" : "?"));
}
static void
@ -902,14 +909,8 @@ panel_switch_new_display_mode (WPanel *panel)
panel_update_contents (panel);
}
static void
change_cwd (GtkWidget *entry, WPanel *panel)
{
printf ("Cambiando a...%s\n", "xxx");
}
static GtkWidget *
panel_create_cwd (Dlg_head *h, WPanel *panel, GtkWidget **the_entry)
panel_create_cwd (Dlg_head *h, WPanel *panel, void **entry)
{
WInput *in;
@ -919,11 +920,7 @@ panel_create_cwd (Dlg_head *h, WPanel *panel, GtkWidget **the_entry)
/* Force the creation of the gtk widget */
send_message_to (h, (Widget *) in, WIDGET_INIT, 0);
*the_entry = gnome_entry_gtk_entry (GNOME_ENTRY (in->widget.wdata));
gtk_signal_connect (GTK_OBJECT (*the_entry),
"activate",
GTK_SIGNAL_FUNC (change_cwd), panel);
*entry = in;
return GTK_WIDGET (in->widget.wdata);
}
@ -932,7 +929,7 @@ panel_change_filter (GtkWidget *entry, WPanel *panel)
{
char *reg_exp;
reg_exp = gtk_entry_get_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (entry))));
reg_exp = ((WInput *)panel->filter_w)->buffer;
set_panel_filter_to (panel, strdup (reg_exp));
}
@ -1102,7 +1099,7 @@ display_mini_info (WPanel *panel)
if (panel->searching){
char *str = copy_strings ("Search: ", panel->search_buffer, NULL);
gtk_label_set (label, str);
gtk_clip_label_set (label, str);
free (str);
return;
}
@ -1110,11 +1107,12 @@ display_mini_info (WPanel *panel)
if (panel->marked){
char buffer [120];
sprintf (buffer, " %s bytes in %d files%s",
sprintf (buffer, " %s bytes in %d file%s",
size_trunc_sep (panel->total), panel->marked,
panel->marked == 1 ? "" : "s");
gtk_label_set (label, buffer);
gtk_clip_label_set (label, buffer);
return;
}
if (S_ISLNK (panel->dir.list [panel->selected].buf.st_mode)){
@ -1130,10 +1128,10 @@ display_mini_info (WPanel *panel)
link_target [len] = 0;
str = copy_strings ("-> ", link_target, NULL);
gtk_label_set (label, str);
gtk_clip_label_set (label, str);
free (str);
} else
gtk_label_set (label, "<readlink failed>");
gtk_clip_label_set (label, "<readlink failed>");
return;
}
@ -1144,14 +1142,13 @@ display_mini_info (WPanel *panel)
buffer = xmalloc (len + 2, "display_mini_info");
format_file (buffer, panel, panel->selected, panel->estimated_total-2, 0, 1);
buffer [len] = 0;
gtk_label_set (label, buffer);
gtk_clip_label_set (label, buffer);
free (buffer);
}
}
static GtkWidget *
panel_create_filter (Dlg_head *h, WPanel *panel, GtkWidget **filter_w)
panel_create_filter (Dlg_head *h, WPanel *panel, void **filter_w)
{
GtkWidget *fhbox;
GtkWidget *button;
@ -1191,18 +1188,9 @@ panel_create_filter (Dlg_head *h, WPanel *panel, GtkWidget **filter_w)
/* Force the creation of the gtk widget */
send_message_to (h, (Widget *) in, WIDGET_INIT, 0);
*filter_w = (GtkWidget *) in->widget.wdata;
*filter_w = in;
/* We do not want the focus by default (and the previos add_widget just gave it to us) */
h->current = h->current->prev;
gtk_signal_connect (GTK_OBJECT (gnome_entry_gtk_entry (GNOME_ENTRY (*filter_w))),
"activate",
GTK_SIGNAL_FUNC (panel_change_filter),
panel);
gtk_box_pack_start (GTK_BOX (fhbox), *filter_w, TRUE, TRUE, 0);
gtk_widget_show (*filter_w);
gtk_box_pack_start (GTK_BOX (fhbox), GTK_WIDGET (in->widget.wdata), TRUE, TRUE, 0);
return fhbox;
}
@ -1211,23 +1199,24 @@ void
x_create_panel (Dlg_head *h, widget_data parent, WPanel *panel)
{
GtkWidget *status_line, *filter, *vbox;
GtkWidget *ministatus_align, *frame, *cwd;
GtkWidget *frame, *cwd;
panel->table = gtk_table_new (2, 1, 0);
panel->list = panel_create_file_list (panel);
filter = panel_create_filter (h, panel, &panel->filter_w);
cwd = panel_create_cwd (h, panel, &panel->current_dir);
filter = panel_create_filter (h, panel, (GtkWidget **) &panel->filter_w);
/* We do not want the focus by default (and the previos add_widget just gave it to us) */
h->current = h->current->prev;
/* ministatus */
ministatus_align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
panel->ministatus = gtk_label_new ("");
gtk_container_add (GTK_CONTAINER (ministatus_align), panel->ministatus);
panel->ministatus = gtk_clip_label_new ("");
gtk_misc_set_alignment (GTK_MISC (panel->ministatus), 0.0, 0.0);
gtk_misc_set_padding (GTK_MISC (panel->ministatus), 3, 0);
status_line = gtk_hbox_new (0, 0);
gtk_label_set_justify (GTK_LABEL (panel->ministatus), GTK_JUSTIFY_LEFT);
gtk_box_pack_start (GTK_BOX (status_line), cwd, 1, 1, 0);
gtk_box_pack_end (GTK_BOX (status_line), filter, 0, 0, 0);
@ -1235,8 +1224,12 @@ x_create_panel (Dlg_head *h, widget_data parent, WPanel *panel)
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_border_width (GTK_CONTAINER (frame), 3);
panel->status = gtk_label_new ("");
panel->status = gtk_clip_label_new ("");
gtk_misc_set_alignment (GTK_MISC (panel->status), 0.0, 0.5);
gtk_misc_set_padding (GTK_MISC (panel->status), 3, 0);
gtk_container_add (GTK_CONTAINER (frame), panel->status);
gtk_label_set_justify (GTK_LABEL (panel->status), GTK_JUSTIFY_LEFT);
gtk_table_attach (GTK_TABLE (panel->table), panel->list, 0, 1, 1, 2,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
@ -1246,10 +1239,9 @@ x_create_panel (Dlg_head *h, widget_data parent, WPanel *panel)
gtk_table_attach (GTK_TABLE (panel->table), status_line, 0, 1, 0, 1,
GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
gtk_table_attach (GTK_TABLE (panel->table), ministatus_align, 0, 1, 2, 3,
gtk_table_attach (GTK_TABLE (panel->table), panel->ministatus, 0, 1, 2, 3,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
0, 0, 0);
gtk_table_attach (GTK_TABLE (panel->table), frame, 0, 1, 3, 4,
GTK_EXPAND | GTK_FILL,
0, 0, 0);

View File

@ -259,7 +259,6 @@ x_update_input (WInput *in)
return;
gtk_entry_set_text (entry, in->buffer);
printf ("POniendo el putno en %d\n", in->point);
gtk_entry_set_position (entry, in->point);
gtk_widget_draw (GTK_WIDGET (gnome_entry), NULL);
}

View File

@ -112,11 +112,11 @@ typedef struct {
/* These are standard GtkWidgets */
void *table;
void *list;
void *current_dir;
void *filter_w;
void *status;
void *ministatus;
void *filter_w; /* A WInput* */
void *current_dir; /* A WInput* */
int estimated_total;
#endif
} WPanel;