1
1
Этот коммит содержится в:
Miguel de Icaza 1998-10-30 17:08:03 +00:00
родитель df4e1cb8c3
Коммит e704d53f77
6 изменённых файлов: 167 добавлений и 72 удалений

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

@ -1,3 +1,16 @@
1998-10-30 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gmetadata.c (meta_get_icon_pos): Renamed from
meta_get_desktop_icon_pos().
(meta_set_icon_pos): New public function to save the icon position
information.
* gdesktop-icon.c (canvas_size_allocated): New function. We reset
the canvas scrolling region here, when the canvas gets size
allocated, to ensure that the canvas has always the correct
scrolling region. We do it here instead of in the reshape()
function to avoid flicker.
1998-10-29 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gmetadata.[ch]: New files with functions to handle all metadata

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

@ -65,65 +65,6 @@ desktop_icon_class_init (DesktopIconClass *class)
widget_class->realize = desktop_icon_realize;
}
/* Computes and sets a new window shape for the desktop icon */
static void
create_window_shape (DesktopIcon *dicon, int icon_width, int icon_height, int text_width, int text_height)
{
GdkImlibImage *im;
GdkBitmap *mask;
GdkBitmap *im_mask;
GdkGC *mgc;
GdkColor c;
/* Create the initial mask and clear it */
mask = gdk_pixmap_new (GTK_WIDGET (dicon)->window, dicon->width, dicon->height, 1);
mgc = gdk_gc_new (mask);
c.pixel = 0;
gdk_gc_set_foreground (mgc, &c);
gdk_draw_rectangle (mask, mgc, TRUE, 0, 0, dicon->width, dicon->height);
c.pixel = 1;
gdk_gc_set_foreground (mgc, &c);
/* Paint the mask of the image */
im = GNOME_CANVAS_IMAGE (dicon->icon)->im;
gdk_imlib_render (im, icon_width, icon_height);
im_mask = gdk_imlib_move_mask (im);
#if 0
if (im_mask && desktop_use_shaped_icons) {
#else
if (im_mask && want_transparent_icons) {
#endif
gdk_draw_pixmap (mask,
mgc,
im_mask,
0, 0,
(dicon->width - icon_width) / 2, 0,
icon_width, icon_height);
gdk_imlib_free_bitmap (im_mask);
} else
gdk_draw_rectangle (mask, mgc, TRUE,
(dicon->width - icon_width) / 2, 0,
icon_width, icon_height);
/* Fill the area for the text */
gdk_draw_rectangle (mask, mgc, TRUE,
(dicon->width - text_width) / 2,
icon_height + SPACING,
text_width, text_height);
if (!GTK_WIDGET_REALIZED (dicon))
gtk_widget_realize (GTK_WIDGET (dicon));
gtk_widget_shape_combine_mask (GTK_WIDGET (dicon), mask, 0, 0);
gdk_bitmap_unref (mask);
gdk_gc_unref (mgc);
}
/* Callback used when the size of the icon text item changes */
static void
size_changed (GnomeIconTextItem *text, gpointer data)
@ -135,15 +76,31 @@ size_changed (GnomeIconTextItem *text, gpointer data)
desktop_icon_reshape (dicon);
}
/* Callback used when the desktop icon's canvas is size_allocated. We reset the canvas scrolling
* region here, instead of doing it when the window shape changes, to avoid flicker.
*/
static void
canvas_size_allocated (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
{
gnome_canvas_set_scroll_region (GNOME_CANVAS (widget), 0, 0, allocation->width, allocation->height);
}
static void
desktop_icon_init (DesktopIcon *dicon)
{
/* Set the window policy */
gtk_window_set_policy (GTK_WINDOW (dicon), TRUE, TRUE, TRUE);
/* Create the canvas */
gtk_widget_push_visual (gdk_imlib_get_visual ());
gtk_widget_push_colormap (gdk_imlib_get_colormap ());
dicon->canvas = gnome_canvas_new ();
gtk_signal_connect (GTK_OBJECT (dicon->canvas), "size_allocate",
(GtkSignalFunc) canvas_size_allocated,
NULL);
gtk_widget_pop_colormap ();
gtk_widget_pop_visual ();
@ -322,6 +279,65 @@ desktop_icon_set_text (DesktopIcon *dicon, char *text)
desktop_icon_reshape (dicon);
}
/* Computes and sets a new window shape for the desktop icon */
static void
create_window_shape (DesktopIcon *dicon, int icon_width, int icon_height, int text_width, int text_height)
{
GdkImlibImage *im;
GdkBitmap *mask;
GdkBitmap *im_mask;
GdkGC *mgc;
GdkColor c;
/* Create the initial mask and clear it */
mask = gdk_pixmap_new (GTK_WIDGET (dicon)->window, dicon->width, dicon->height, 1);
mgc = gdk_gc_new (mask);
c.pixel = 0;
gdk_gc_set_foreground (mgc, &c);
gdk_draw_rectangle (mask, mgc, TRUE, 0, 0, dicon->width, dicon->height);
c.pixel = 1;
gdk_gc_set_foreground (mgc, &c);
/* Paint the mask of the image */
im = GNOME_CANVAS_IMAGE (dicon->icon)->im;
gdk_imlib_render (im, icon_width, icon_height);
im_mask = gdk_imlib_move_mask (im);
#if 0
if (im_mask && desktop_use_shaped_icons) {
#else
if (im_mask && want_transparent_icons) {
#endif
gdk_draw_pixmap (mask,
mgc,
im_mask,
0, 0,
(dicon->width - icon_width) / 2, 0,
icon_width, icon_height);
gdk_imlib_free_bitmap (im_mask);
} else
gdk_draw_rectangle (mask, mgc, TRUE,
(dicon->width - icon_width) / 2, 0,
icon_width, icon_height);
/* Fill the area for the text */
gdk_draw_rectangle (mask, mgc, TRUE,
(dicon->width - text_width) / 2,
icon_height + SPACING,
text_width, text_height);
if (!GTK_WIDGET_REALIZED (dicon))
gtk_widget_realize (GTK_WIDGET (dicon));
gtk_widget_shape_combine_mask (GTK_WIDGET (dicon), mask, 0, 0);
gdk_bitmap_unref (mask);
gdk_gc_unref (mgc);
}
/**
* desktop_icon_reshape
* @dicon: The desktop icon whose shape will be recalculated

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

@ -9,6 +9,7 @@
#include <config.h>
#include <gnome.h>
#include "gdesktop.h"
#include "gmetadata.h"
#include "../vfs/vfs.h"
@ -20,13 +21,16 @@
struct desktop_icon_info {
GtkWidget *dicon; /* The desktop icon widget */
int x, y; /* Position in the desktop */
char *filename; /* The file this icon refers to */
char *filename; /* The file this icon refers to (relative to the desktop_directory) */
int selected : 1; /* Is the icon selected? */
};
/* Should use a shaped window for icons? If not, use a solid square. */
/* Configuration options for the desktop */
int desktop_use_shaped_icons = TRUE;
int desktop_auto_placement = FALSE;
int desktop_snap_icons = FALSE;
/* The computed name of the user's desktop directory */
static char *desktop_directory;
@ -40,6 +44,16 @@ static int *layout_slots;
static GList *desktop_icons;
/* Places a desktop icon. If auto_pos is true, then the function will look for a place to position
* the icon automatically, else it will use the specified coordinates, snapped to the grid if the
* global desktop_snap_icons flag is set.
*/
static void
desktop_icon_info_place (struct desktop_icon_info *dii, int auto_pos, int xpos, int ypos)
{
/* FIXME */
}
/* Creates a new desktop icon. The filename is the pruned filename inside the desktop directory.
* If auto_pos is true, then the function will look for a place to position the icon automatically,
* else it will use the specified coordinates.
@ -47,7 +61,23 @@ static GList *desktop_icons;
static void
desktop_icon_info_new (char *filename, int auto_pos, int xpos, int ypos)
{
struct desktop_icon_info *dii;
char *full_name;
char *icon_name;
full_name = g_concat_dir_and_file (desktop_directory, filename);
icon_name = meta_get_icon_for_file (full_name);
dii = g_new (struct desktop_icon_info, 1);
dii->widget = desktop_icon_new (icon_name, filename);
dii->filename = g_strdup (filename);
dii->selected = FALSE;
g_free (full_name);
g_free (icon_name);
desktop_icon_info_place (dii, auto_pos, xpos, ypos);
gtk_widget_show (dii->dicon);
}
/* Creates the layout information array */
@ -97,6 +127,7 @@ load_initial_desktop_icons (void)
{
struct dirent *dirent;
DIR *dir;
char *full_name;
int have_pos, x, y;
dir = mc_opendir (desktop_directory);
@ -113,7 +144,12 @@ load_initial_desktop_icons (void)
|| ((dirent->d_name[0] == '.') && (dirent->d_name[1] == '.') && (dirent->d_name[2] == 0)))
continue;
desktop_icon_info_new (dirent->d_name, TRUE, 0, 0);
full_name = g_concat_dir_and_file (desktop_directory, dirent->d_name);
have_pos = meta_get_icon_pos (full_name, &x, &y);
desktop_icon_info_new (dirent->d_name, have_pos, x, y);
g_free (full_name);
}
mc_closedir (dir);

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

@ -19,7 +19,9 @@
/* Configuration options for the desktop */
extern int desktop_use_shaped_icons; /* Specifies whether to use shaped icons or not (for slow X servers) */
extern int desktop_use_shaped_icons; /* Whether to use shaped icons or not (for slow X servers) */
extern int desktop_auto_placement; /* Whether to auto-place icons or not (user placement) */
extern int desktop_snap_icons; /* Whether to snap icons to the grid or not */
/* Initializes the desktop -- init DnD, load the default desktop icons, etc. */

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

@ -9,6 +9,8 @@
#include <sys/stat.h>
#include <libgnome/libgnome.h>
#include "gmetadata.h"
#include "fs.h"
#include "../vfs/vfs.h"
#define ICON_FILENAME "icon-filename"
@ -33,7 +35,7 @@ meta_get_icon_for_file (char *filename)
struct stat s;
int retval;
g_return_if_fail (filename != NULL);
g_return_val_if_fail (filename != NULL, NULL);
if (gnome_metadata_get (filename, ICON_FILENAME, &size, &buf) != 0) {
/* Return a default icon */
@ -50,17 +52,18 @@ meta_get_icon_for_file (char *filename)
}
/**
* meta_get_desktop_icon_pos
* meta_get_icon_pos
* @filename: The file under ~/desktop for which to get the icon position
* @x: The x position will be stored here. Must be non-NULL.
* @y: The y position will be stored here. Must be non-NULL.
*
* Checks if the specified file in the user's desktop directory has an icon position
* associated to it. If so, returns TRUE and fills in the x and y values. Otherwise
* it returns FALSE and x and y are not modified.
* Checks if the specified file has an icon position associated to it. If so, returns TRUE and
* fills in the x and y values. Otherwise it returns FALSE and x and y are not modified.
*
* Icon position information is expected to be saved using the meta_set_icon_pos() function.
*/
int
meta_get_desktop_icon_pos (char *filename, int *x, int *y)
meta_get_icon_pos (char *filename, int *x, int *y)
{
int size;
char *buf;
@ -82,3 +85,25 @@ meta_get_desktop_icon_pos (char *filename, int *x, int *y)
*y = ty;
return TRUE;
}
/**
* meta_set_icon_pos
* @filename: The file for which to save icon position information
* @x: X position of the icon
* @y: Y position of the icon
*
* Saves the icon position information for the specified file. This is expected to be read back
* using the meta_get_icon_pos() function.
*/
void
meta_set_icon_pos (char *filename, int x, int y)
{
char buf[100];
g_return_if_fail (filename != NULL);
sprintf (buf, "%d %d", x, y);
if (gnome_metadata_set (filename, ICON_POSITION, strlen (buf) + 1, buf) != 0)
g_warning ("Error setting the icon position metadata for \"%s\"", filename);
}

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

@ -12,10 +12,13 @@
/* Returns the icon filename for the specified file. You must free the name. */
char *meta_get_icon_for_file (char *filename);
/* Returns the coordinates of the desktop icon corresponding to the specified file. If no position
/* Returns the coordinates of the icon corresponding to the specified file. If no position
* has been set, returns FALSE. Else it returns TRUE and sets the *x and *y values.
*/
int meta_get_desktop_icon_pos (char *filename, int *x, int *y);
int meta_get_icon_pos (char *filename, int *x, int *y);
/* Saves the icon position for the specified file */
void meta_set_icon_pos (char *filename, int x, int y);
#endif