4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2002, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* display.c - code for arranging and displaying file items */
31 #include <sys/param.h>
38 #include <gdk/gdkkeysyms.h>
44 #include "collection.h"
46 #include "gui_support.h"
56 #include "minibuffer.h"
61 #define ROW_HEIGHT_SMALL 20
62 #define ROW_HEIGHT_FULL_INFO 44
63 #define MIN_ITEM_WIDTH 64
65 #define MIN_TRUNCATE 0
66 #define MAX_TRUNCATE 250
68 #define HUGE_WRAP (1.5 * o_large_width.int_value)
71 static Option o_intelligent_sort
;
72 static Option o_display_dirs_first
;
73 Option o_display_size
;
74 Option o_display_details
;
75 Option o_display_sort_by
;
76 static Option o_large_width
;
77 static Option o_small_width
;
78 Option o_display_show_hidden
;
79 Option o_display_show_thumbs
;
80 Option o_display_inherit_options
;
83 /* GC for drawing colour filenames */
84 static GdkGC
*type_gc
= NULL
;
86 typedef struct _Template Template
;
90 GdkRectangle leafname
;
94 #define SHOW_RECT(ite, template) \
95 g_print("%s: %dx%d+%d+%d %dx%d+%d+%d\n", \
97 (template)->leafname.width, (template)->leafname.height,\
98 (template)->leafname.x, (template)->leafname.y, \
99 (template)->icon.width, (template)->icon.height, \
100 (template)->icon.x, (template)->icon.y)
102 /* Static prototypes */
103 static void fill_template(GdkRectangle
*area
, CollectionItem
*item
,
104 FilerWindow
*filer_window
, Template
*template);
105 static void huge_template(GdkRectangle
*area
, CollectionItem
*colitem
,
106 FilerWindow
*filer_window
, Template
*template);
107 static void large_template(GdkRectangle
*area
, CollectionItem
*colitem
,
108 FilerWindow
*filer_window
, Template
*template);
109 static void small_template(GdkRectangle
*area
, CollectionItem
*colitem
,
110 FilerWindow
*filer_window
, Template
*template);
111 static void huge_full_template(GdkRectangle
*area
, CollectionItem
*colitem
,
112 FilerWindow
*filer_window
, Template
*template);
113 static void large_full_template(GdkRectangle
*area
, CollectionItem
*colitem
,
114 FilerWindow
*filer_window
, Template
*template);
115 static void small_full_template(GdkRectangle
*area
, CollectionItem
*colitem
,
116 FilerWindow
*filer_window
, Template
*template);
117 static void draw_item(GtkWidget
*widget
,
118 CollectionItem
*item
,
120 FilerWindow
*filer_window
);
121 static gboolean
test_point(Collection
*collection
,
122 int point_x
, int point_y
,
123 CollectionItem
*item
,
124 int width
, int height
,
125 FilerWindow
*filer_window
);
126 static void display_details_set(FilerWindow
*filer_window
, DetailsType details
);
127 static void display_style_set(FilerWindow
*filer_window
, DisplayStyle style
);
128 static void options_changed(void);
129 static char *details(FilerWindow
*filer_window
, DirItem
*item
);
130 static void draw_string(GtkWidget
*widget
,
132 GdkRectangle
*area
, /* Area available on screen */
133 int width
, /* Width of the full string */
134 GtkStateType selection_state
,
145 /****************************************************************
146 * EXTERNAL INTERFACE *
147 ****************************************************************/
151 option_add_int(&o_intelligent_sort
, "display_intelligent_sort", 1);
152 option_add_int(&o_display_dirs_first
, "display_dirs_first", FALSE
);
153 option_add_int(&o_display_size
, "display_size", LARGE_ICONS
);
154 option_add_int(&o_display_details
, "display_details", DETAILS_NONE
);
155 option_add_int(&o_display_sort_by
, "display_sort_by", SORT_BY_NAME
);
156 option_add_int(&o_large_width
, "display_large_width", 89);
157 option_add_int(&o_small_width
, "display_small_width", 250);
158 option_add_int(&o_display_show_hidden
, "display_show_hidden", FALSE
);
159 option_add_int(&o_display_show_thumbs
, "display_show_thumbs", FALSE
);
160 option_add_int(&o_display_inherit_options
,"display_inherit_options",
162 option_add_notify(options_changed
);
165 /* A template contains the locations of the three rectangles (for the icon,
166 * name and extra details).
167 * Fill in the empty 'template' with the rectanges for this item.
169 static void fill_template(GdkRectangle
*area
, CollectionItem
*colitem
,
170 FilerWindow
*filer_window
, Template
*template)
172 DisplayStyle style
= filer_window
->display_style
;
173 ViewData
*view
= (ViewData
*) colitem
->view_data
;
177 template->details
.width
= view
->details_width
;
178 template->details
.height
= view
->details_height
;
180 if (style
== SMALL_ICONS
)
181 small_full_template(area
, colitem
,
182 filer_window
, template);
183 else if (style
== LARGE_ICONS
)
184 large_full_template(area
, colitem
,
185 filer_window
, template);
187 huge_full_template(area
, colitem
,
188 filer_window
, template);
192 if (style
== HUGE_ICONS
)
193 huge_template(area
, colitem
, filer_window
, template);
194 else if (style
== LARGE_ICONS
)
195 large_template(area
, colitem
, filer_window
, template);
197 small_template(area
, colitem
, filer_window
, template);
201 /* Return the size needed for this item */
202 void calc_size(FilerWindow
*filer_window
, CollectionItem
*colitem
,
203 int *width
, int *height
)
205 int pix_width
, pix_height
;
207 DisplayStyle style
= filer_window
->display_style
;
208 ViewData
*view
= (ViewData
*) colitem
->view_data
;
210 if (filer_window
->details_type
== DETAILS_NONE
)
212 if (style
== HUGE_ICONS
)
216 if (!view
->image
->huge_pixbuf
)
217 pixmap_make_huge(view
->image
);
218 pix_width
= view
->image
->huge_width
;
219 pix_height
= view
->image
->huge_height
;
223 pix_width
= HUGE_WIDTH
* 3 / 2;
224 pix_height
= HUGE_HEIGHT
* 3 / 2;
226 *width
= MAX(pix_width
, view
->name_width
) + 4;
227 *height
= view
->name_height
+ pix_height
+ 4;
229 else if (style
== SMALL_ICONS
)
231 w
= MIN(view
->name_width
, o_small_width
.int_value
);
232 *width
= SMALL_WIDTH
+ 12 + w
;
233 *height
= MAX(view
->name_height
, SMALL_HEIGHT
) + 4;
238 pix_width
= view
->image
->width
;
240 pix_width
= HUGE_WIDTH
* 3 / 2;
241 *width
= MAX(pix_width
, view
->name_width
) + 4;
242 *height
= view
->name_height
+ ICON_HEIGHT
+ 2;
247 w
= view
->details_width
;
248 if (style
== HUGE_ICONS
)
250 *width
= HUGE_WIDTH
+ 12 + MAX(w
, view
->name_width
);
251 *height
= HUGE_HEIGHT
- 4;
253 else if (style
== SMALL_ICONS
)
257 *width
= SMALL_WIDTH
+ view
->name_width
+ 12 + w
;
258 text_height
= MAX(view
->name_height
,
259 view
->details_height
);
260 *height
= MAX(text_height
, SMALL_HEIGHT
) + 4;
264 *width
= ICON_WIDTH
+ 12 + MAX(w
, view
->name_width
);
265 *height
= ICON_HEIGHT
;
270 /* Draw this icon (including any symlink or mount symbol) inside the
273 void draw_huge_icon(GtkWidget
*widget
,
286 width
= image
->huge_width
;
287 height
= image
->huge_height
;
288 image_x
= area
->x
+ ((area
->width
- width
) >> 1);
289 image_y
= MAX(0, area
->height
- height
- 6);
291 gdk_pixbuf_render_to_drawable_alpha(
292 selected
? image
->huge_pixbuf_lit
293 : image
->huge_pixbuf
,
296 image_x
, area
->y
+ image_y
, /* dest */
298 GDK_PIXBUF_ALPHA_FULL
, 128, /* (unused) */
299 GDK_RGB_DITHER_NORMAL
, 0, 0);
301 if (item
->flags
& ITEM_FLAG_SYMLINK
)
303 gdk_pixbuf_render_to_drawable_alpha(im_symlink
->pixbuf
,
306 image_x
, area
->y
+ 2, /* dest */
308 GDK_PIXBUF_ALPHA_FULL
, 128, /* (unused) */
309 GDK_RGB_DITHER_NORMAL
, 0, 0);
311 else if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
313 MaskedPixmap
*mp
= item
->flags
& ITEM_FLAG_MOUNTED
317 gdk_pixbuf_render_to_drawable_alpha(mp
->pixbuf
,
320 image_x
, area
->y
+ 2, /* dest */
322 GDK_PIXBUF_ALPHA_FULL
, 128, /* (unused) */
323 GDK_RGB_DITHER_NORMAL
, 0, 0);
327 /* Draw this icon (including any symlink or mount symbol) inside the
330 void draw_large_icon(GtkWidget
*widget
,
344 width
= MIN(image
->width
, ICON_WIDTH
);
345 height
= MIN(image
->height
, ICON_HEIGHT
);
346 image_x
= area
->x
+ ((area
->width
- width
) >> 1);
347 image_y
= MAX(0, area
->height
- height
- 6);
349 gdk_pixbuf_render_to_drawable_alpha(
350 selected
? image
->pixbuf_lit
: image
->pixbuf
,
353 image_x
, area
->y
+ image_y
, /* dest */
355 GDK_PIXBUF_ALPHA_FULL
, 128, /* (unused) */
356 GDK_RGB_DITHER_NORMAL
, 0, 0);
358 if (item
->flags
& ITEM_FLAG_SYMLINK
)
360 gdk_pixbuf_render_to_drawable_alpha(im_symlink
->pixbuf
,
363 image_x
, area
->y
+ 2, /* dest */
365 GDK_PIXBUF_ALPHA_FULL
, 128, /* (unused) */
366 GDK_RGB_DITHER_NORMAL
, 0, 0);
368 else if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
370 MaskedPixmap
*mp
= item
->flags
& ITEM_FLAG_MOUNTED
374 gdk_pixbuf_render_to_drawable_alpha(mp
->pixbuf
,
377 image_x
, area
->y
+ 2, /* dest */
379 GDK_PIXBUF_ALPHA_FULL
, 128, /* (unused) */
380 GDK_RGB_DITHER_NORMAL
, 0, 0);
384 /* The sort functions aren't called from outside, but they are
385 * passed as arguments to display_set_sort_fn().
388 #define IS_A_DIR(item) (item->base_type == TYPE_DIRECTORY && \
389 !(item->flags & ITEM_FLAG_APPDIR))
392 if (o_display_dirs_first.int_value) { \
393 gboolean id1 = IS_A_DIR(i1); \
394 gboolean id2 = IS_A_DIR(i2); \
395 if (id1 && !id2) return -1; \
396 if (id2 && !id1) return 1; \
399 int sort_by_name(const void *item1
, const void *item2
)
401 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
402 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
403 char *n1
= i1
->leafname_collate
;
404 char *n2
= i2
->leafname_collate
;
408 if (!o_intelligent_sort
.int_value
)
409 return strcmp(i1
->leafname
, i2
->leafname
);
411 /* The following code was copied from PicoGUI (was LGPL) */
413 /* Sort the files, in a way that should make sense to users.
414 * Case is ignored, punctuation is ignored. If the file contains
415 * numbers, the numbers are sorted numerically.
419 char c1
= *n1
, c2
= *n2
;
421 /* If they are both numbers, sort them numerically */
422 if (isdigit(c1
) && isdigit(c2
))
426 u1
= strtoul(n1
, &p
, 10);
428 u2
= strtoul(n2
, &p
, 10);
437 /* Do a case-insensitive asciibetical sort */
450 return 1; /* First string is longer, so comes after */
454 /* If the strings are equal at the end of this, fallback to a straight
455 * ASCII sort so at least it's deterministic.
457 return strcmp(i1
->leafname
, i2
->leafname
);
460 int sort_by_type(const void *item1
, const void *item2
)
462 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
463 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
466 int diff
= i1
->base_type
- i2
->base_type
;
469 diff
= (i1
->flags
& ITEM_FLAG_APPDIR
)
470 - (i2
->flags
& ITEM_FLAG_APPDIR
);
472 return diff
> 0 ? 1 : -1;
479 diff
= strcmp(m1
->media_type
, m2
->media_type
);
481 diff
= strcmp(m1
->subtype
, m2
->subtype
);
489 return diff
> 0 ? 1 : -1;
491 return sort_by_name(item1
, item2
);
494 int sort_by_date(const void *item1
, const void *item2
)
496 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
497 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
501 return i1
->mtime
> i2
->mtime
? -1 :
502 i1
->mtime
< i2
->mtime
? 1 :
503 sort_by_name(item1
, item2
);
506 int sort_by_size(const void *item1
, const void *item2
)
508 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
509 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
513 return i1
->size
> i2
->size
? -1 :
514 i1
->size
< i2
->size
? 1 :
515 sort_by_name(item1
, item2
);
518 /* Make the items as small as possible */
519 void shrink_grid(FilerWindow
*filer_window
)
522 Collection
*col
= filer_window
->collection
;
523 int width
= MIN_ITEM_WIDTH
;
524 int height
= SMALL_HEIGHT
;
526 for (i
= 0; i
< col
->number_of_items
; i
++)
530 calc_size(filer_window
, &col
->items
[i
], &w
, &h
);
537 collection_set_item_size(col
, width
, height
);
540 void display_set_sort_fn(FilerWindow
*filer_window
,
541 int (*fn
)(const void *a
, const void *b
))
543 if (filer_window
->sort_fn
== fn
)
546 filer_window
->sort_fn
= fn
;
548 collection_qsort(filer_window
->collection
,
549 filer_window
->sort_fn
);
552 void display_set_layout(FilerWindow
*filer_window
,
556 g_return_if_fail(filer_window
!= NULL
);
558 display_style_set(filer_window
, style
);
559 display_details_set(filer_window
, details
);
561 shrink_grid(filer_window
);
563 if (o_filer_auto_resize
.int_value
!= RESIZE_NEVER
)
564 filer_window_autosize(filer_window
, TRUE
);
567 /* Set the 'Show Thumbnails' flag for this window */
568 void display_set_thumbs(FilerWindow
*filer_window
, gboolean thumbs
)
570 if (filer_window
->show_thumbs
== thumbs
)
573 filer_window
->show_thumbs
= thumbs
;
575 display_update_views(filer_window
);
577 gtk_widget_queue_draw(GTK_WIDGET(filer_window
->collection
));
580 filer_cancel_thumbnails(filer_window
);
582 filer_set_title(filer_window
);
584 filer_create_thumbs(filer_window
);
587 /* Set the 'Show Hidden' flag for this window */
588 void display_set_hidden(FilerWindow
*filer_window
, gboolean hidden
)
590 if (filer_window
->show_hidden
== hidden
)
593 filer_window
->show_hidden
= hidden
;
595 filer_detach_rescan(filer_window
);
597 filer_set_title(filer_window
);
600 /* Highlight (wink or cursor) this item in the filer window. If the item
601 * isn't already there but we're scanning then highlight it if it
604 void display_set_autoselect(FilerWindow
*filer_window
, const gchar
*leaf
)
609 g_return_if_fail(filer_window
!= NULL
);
610 col
= filer_window
->collection
;
612 for (i
= 0; i
< col
->number_of_items
; i
++)
614 DirItem
*item
= (DirItem
*) col
->items
[i
].data
;
616 if (strcmp(item
->leafname
, leaf
) == 0)
618 if (col
->cursor_item
!= -1)
619 collection_set_cursor_item(col
, i
);
621 collection_wink_item(col
, i
);
628 g_free(filer_window
->auto_select
);
630 filer_window
->auto_select
= g_strdup(leaf
);
632 filer_window
->auto_select
= NULL
;
635 gboolean
display_is_truncated(FilerWindow
*filer_window
, int i
)
638 Collection
*collection
= filer_window
->collection
;
639 CollectionItem
*colitem
= &collection
->items
[i
];
640 int col
= i
% collection
->columns
;
641 int row
= i
/ collection
->columns
;
643 ViewData
*view
= (ViewData
*) colitem
->view_data
;
645 if (filer_window
->display_style
== LARGE_ICONS
||
646 filer_window
->display_style
== HUGE_ICONS
)
647 return FALSE
; /* These wrap rather than truncate */
649 area
.x
= col
* collection
->item_width
;
650 area
.y
= row
* collection
->item_height
;
651 area
.height
= collection
->item_height
;
653 if (col
== collection
->columns
- 1)
654 area
.width
= GTK_WIDGET(collection
)->allocation
.width
- area
.x
;
656 area
.width
= collection
->item_width
;
658 fill_template(&area
, colitem
, filer_window
, &template);
660 return template.leafname
.width
< view
->name_width
;
663 /* Change the icon size (wraps) */
664 void display_change_size(FilerWindow
*filer_window
, gboolean bigger
)
668 g_return_if_fail(filer_window
!= NULL
);
670 switch (filer_window
->display_style
)
673 new = bigger
? HUGE_ICONS
: SMALL_ICONS
;
676 new = bigger
? SMALL_ICONS
: LARGE_ICONS
;
679 new = bigger
? LARGE_ICONS
: HUGE_ICONS
;
683 display_set_layout(filer_window
, new, filer_window
->details_type
);
686 ViewData
*display_create_viewdata(FilerWindow
*filer_window
, DirItem
*item
)
690 view
= g_new(ViewData
, 1);
693 view
->details
= NULL
;
696 display_update_view(filer_window
, item
, view
, TRUE
);
701 void display_free_colitem(Collection
*collection
, CollectionItem
*colitem
)
703 ViewData
*view
= (ViewData
*) colitem
->view_data
;
710 g_object_unref(G_OBJECT(view
->layout
));
714 g_object_unref(G_OBJECT(view
->details
));
717 g_object_unref(view
->image
);
722 /* Recalculate all the ViewData structs for this window.
723 * Useful when the display style has changed.
725 void display_update_views(FilerWindow
*filer_window
)
727 Collection
*collection
= filer_window
->collection
;
730 for (i
= 0; i
< collection
->number_of_items
; i
++)
732 CollectionItem
*ci
= &collection
->items
[i
];
734 display_update_view(filer_window
, (DirItem
*) ci
->data
,
735 (ViewData
*) ci
->view_data
, TRUE
);
739 /****************************************************************
740 * INTERNAL FUNCTIONS *
741 ****************************************************************/
743 static void options_changed(void)
745 GList
*next
= all_filer_windows
;
749 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
751 if (o_large_width
.has_changed
|| o_small_width
.has_changed
)
753 /* Recreate PangoLayout */
754 display_update_views(filer_window
);
757 if (o_intelligent_sort
.has_changed
||
758 o_display_dirs_first
.has_changed
)
760 collection_qsort(filer_window
->collection
,
761 filer_window
->sort_fn
);
763 shrink_grid(filer_window
);
764 gtk_widget_queue_draw(filer_window
->window
);
770 static void huge_template(GdkRectangle
*area
, CollectionItem
*colitem
,
771 FilerWindow
*filer_window
, Template
*template)
773 int col_width
= filer_window
->collection
->item_width
;
775 ViewData
*view
= (ViewData
*) colitem
->view_data
;
776 MaskedPixmap
*image
= view
->image
;
780 if (!image
->huge_pixbuf
)
781 pixmap_make_huge(image
);
782 template->icon
.width
= image
->huge_width
;
783 template->icon
.height
= image
->huge_height
;
787 template->icon
.width
= HUGE_WIDTH
* 3 / 2;
788 template->icon
.height
= HUGE_HEIGHT
;
791 template->leafname
.width
= view
->name_width
;
792 template->leafname
.height
= view
->name_height
;
794 text_x
= area
->x
+ ((col_width
- template->leafname
.width
) >> 1);
795 text_y
= area
->y
+ area
->height
- template->leafname
.height
;
797 template->leafname
.x
= text_x
;
798 template->leafname
.y
= text_y
;
800 template->icon
.x
= area
->x
+ ((col_width
- template->icon
.width
) >> 1);
801 template->icon
.y
= template->leafname
.y
- template->icon
.height
- 2;
804 static void large_template(GdkRectangle
*area
, CollectionItem
*colitem
,
805 FilerWindow
*filer_window
, Template
*template)
807 int col_width
= filer_window
->collection
->item_width
;
811 ViewData
*view
= (ViewData
*) colitem
->view_data
;
812 MaskedPixmap
*image
= view
->image
;
818 iwidth
= MIN(image
->width
, ICON_WIDTH
);
819 iheight
= MIN(image
->height
+ 6, ICON_HEIGHT
);
824 iheight
= ICON_HEIGHT
;
826 image_x
= area
->x
+ ((col_width
- iwidth
) >> 1);
828 template->leafname
.width
= view
->name_width
;
829 template->leafname
.height
= view
->name_height
;
831 text_x
= area
->x
+ ((col_width
- template->leafname
.width
) >> 1);
832 text_y
= area
->y
+ ICON_HEIGHT
+ 2;
834 template->leafname
.x
= text_x
;
835 template->leafname
.y
= text_y
;
837 image_y
= text_y
- iheight
;
838 image_y
= MAX(area
->y
, image_y
);
840 template->icon
.x
= image_x
;
841 template->icon
.y
= image_y
;
842 template->icon
.width
= iwidth
;
843 template->icon
.height
= MIN(ICON_HEIGHT
, iheight
);
846 static void small_template(GdkRectangle
*area
, CollectionItem
*colitem
,
847 FilerWindow
*filer_window
, Template
*template)
849 int text_x
= area
->x
+ SMALL_WIDTH
+ 4;
851 int max_text_width
= area
->width
- SMALL_WIDTH
- 4;
852 ViewData
*view
= (ViewData
*) colitem
->view_data
;
854 low_text_y
= area
->y
+ area
->height
/ 2 - view
->name_height
/ 2;
856 template->leafname
.x
= text_x
;
857 template->leafname
.y
= low_text_y
;
858 template->leafname
.width
= MIN(max_text_width
, view
->name_width
);
859 template->leafname
.height
= view
->name_height
;
861 template->icon
.x
= area
->x
;
862 template->icon
.y
= area
->y
+ 1;
863 template->icon
.width
= SMALL_WIDTH
;
864 template->icon
.height
= SMALL_HEIGHT
;
867 static void huge_full_template(GdkRectangle
*area
, CollectionItem
*colitem
,
868 FilerWindow
*filer_window
, Template
*template)
870 int max_text_width
= area
->width
- HUGE_WIDTH
- 4;
871 ViewData
*view
= (ViewData
*) colitem
->view_data
;
872 MaskedPixmap
*image
= view
->image
;
876 if (!image
->huge_pixbuf
)
877 pixmap_make_huge(image
);
878 template->icon
.width
= image
->huge_width
;
879 template->icon
.height
= image
->huge_height
;
883 template->icon
.width
= HUGE_WIDTH
* 3 / 2;
884 template->icon
.height
= HUGE_HEIGHT
;
887 template->icon
.x
= area
->x
+ (HUGE_WIDTH
- template->icon
.width
) / 2;
888 template->icon
.y
= area
->y
+ (area
->height
- template->icon
.height
) / 2;
890 template->leafname
.x
= area
->x
+ HUGE_WIDTH
+ 4;
891 template->leafname
.y
= area
->y
+ area
->height
/ 2
892 - (view
->name_height
+ 2 + view
->details_height
) / 2;
893 template->leafname
.width
= MIN(max_text_width
, view
->name_width
);
894 template->leafname
.height
= view
->name_height
;
897 return; /* Not scanned yet */
899 template->details
.x
= template->leafname
.x
;
900 template->details
.y
= template->leafname
.y
+ view
->name_height
+ 2;
903 static void large_full_template(GdkRectangle
*area
, CollectionItem
*colitem
,
904 FilerWindow
*filer_window
, Template
*template)
906 int max_text_width
= area
->width
- ICON_WIDTH
- 4;
907 ViewData
*view
= (ViewData
*) colitem
->view_data
;
908 MaskedPixmap
*image
= view
->image
;
912 template->icon
.width
= image
->width
;
913 template->icon
.height
= image
->height
;
917 template->icon
.width
= ICON_WIDTH
;
918 template->icon
.height
= ICON_HEIGHT
;
921 template->icon
.x
= area
->x
+ (ICON_WIDTH
- template->icon
.width
) / 2;
922 template->icon
.y
= area
->y
+ (area
->height
- template->icon
.height
) / 2;
925 template->leafname
.x
= area
->x
+ ICON_WIDTH
+ 4;
926 template->leafname
.y
= area
->y
+ area
->height
/ 2
927 - (view
->name_height
+ 2 + view
->details_height
) / 2;
928 template->leafname
.width
= MIN(max_text_width
, view
->name_width
);
929 template->leafname
.height
= view
->name_height
;
932 return; /* Not scanned yet */
934 template->details
.x
= template->leafname
.x
;
935 template->details
.y
= template->leafname
.y
+ view
->name_height
+ 2;
938 static void small_full_template(GdkRectangle
*area
, CollectionItem
*colitem
,
939 FilerWindow
*filer_window
, Template
*template)
941 int col_width
= filer_window
->collection
->item_width
;
942 ViewData
*view
= (ViewData
*) colitem
->view_data
;
944 small_template(area
, colitem
, filer_window
, template);
947 return; /* Not scanned yet */
949 template->details
.x
= area
->x
+ col_width
- template->details
.width
;
950 template->details
.y
= area
->y
+ area
->height
/ 2 - \
951 view
->details_height
/ 2;
954 #define INSIDE(px, py, area) \
955 (px >= area.x && py >= area.y && \
956 px <= area.x + area.width && py <= area.y + area.height)
958 static gboolean
test_point(Collection
*collection
,
959 int point_x
, int point_y
,
960 CollectionItem
*colitem
,
961 int width
, int height
,
962 FilerWindow
*filer_window
)
966 ViewData
*view
= (ViewData
*) colitem
->view_data
;
971 area
.height
= height
;
973 fill_template(&area
, colitem
, filer_window
, &template);
975 return INSIDE(point_x
, point_y
, template.leafname
) ||
976 INSIDE(point_x
, point_y
, template.icon
) ||
977 (view
->details
&& INSIDE(point_x
, point_y
, template.details
));
980 static void draw_small_icon(GtkWidget
*widget
,
986 int width
, height
, image_x
, image_y
;
991 if (!image
->sm_pixbuf
)
992 pixmap_make_small(image
);
994 width
= MIN(image
->sm_width
, SMALL_WIDTH
);
995 height
= MIN(image
->sm_height
, SMALL_HEIGHT
);
996 image_x
= area
->x
+ ((area
->width
- width
) >> 1);
997 image_y
= MAX(0, SMALL_HEIGHT
- image
->sm_height
);
999 gdk_pixbuf_render_to_drawable_alpha(
1000 selected
? image
->sm_pixbuf_lit
: image
->sm_pixbuf
,
1003 image_x
, area
->y
+ image_y
, /* dest */
1005 GDK_PIXBUF_ALPHA_FULL
, 128, /* (unused) */
1006 GDK_RGB_DITHER_NORMAL
, 0, 0);
1008 if (item
->flags
& ITEM_FLAG_SYMLINK
)
1010 gdk_pixbuf_render_to_drawable_alpha(im_symlink
->pixbuf
,
1013 image_x
, area
->y
+ 8, /* dest */
1015 GDK_PIXBUF_ALPHA_FULL
, 128, /* (unused) */
1016 GDK_RGB_DITHER_NORMAL
, 0, 0);
1018 else if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
1020 MaskedPixmap
*mp
= item
->flags
& ITEM_FLAG_MOUNTED
1024 gdk_pixbuf_render_to_drawable_alpha(mp
->pixbuf
,
1027 image_x
+ 2, area
->y
+ 2, /* dest */
1029 GDK_PIXBUF_ALPHA_FULL
, 128, /* (unused) */
1030 GDK_RGB_DITHER_NORMAL
, 0, 0);
1034 /* Return a new string giving details of this item, or NULL if details
1035 * are not being displayed. If details are not yet available, return
1036 * a string of the right length.
1038 static char *details(FilerWindow
*filer_window
, DirItem
*item
)
1040 mode_t m
= item
->mode
;
1042 gboolean scanned
= item
->base_type
!= TYPE_UNKNOWN
;
1044 if (filer_window
->details_type
== DETAILS_NONE
)
1047 if (scanned
&& item
->lstat_errno
)
1048 buf
= g_strdup_printf(_("lstat(2) failed: %s"),
1049 g_strerror(item
->lstat_errno
));
1050 else if (filer_window
->details_type
== DETAILS_SUMMARY
)
1055 return g_strdup("XXXX ---,---,---/--- "
1056 "12345678 12345678 "
1057 "12345M 00:00:00 01 Mmm Yyyy");
1059 time
= pretty_time(&item
->mtime
);
1061 buf
= g_strdup_printf("%s %s %-8.8s %-8.8s %s %s",
1062 item
->flags
& ITEM_FLAG_APPDIR
? "App " :
1063 S_ISDIR(m
) ? "Dir " :
1064 S_ISCHR(m
) ? "Char" :
1065 S_ISBLK(m
) ? "Blck" :
1066 S_ISLNK(m
) ? "Link" :
1067 S_ISSOCK(m
) ? "Sock" :
1068 S_ISFIFO(m
) ? "Pipe" : "File",
1069 pretty_permissions(m
),
1070 user_name(item
->uid
),
1071 group_name(item
->gid
),
1072 format_size_aligned(item
->size
),
1076 else if (filer_window
->details_type
== DETAILS_TYPE
)
1078 MIME_type
*type
= item
->mime_type
;
1081 return g_strdup("(application/octet-stream)");
1083 buf
= g_strdup_printf("(%s/%s)",
1084 type
->media_type
, type
->subtype
);
1086 else if (filer_window
->details_type
== DETAILS_TIMES
)
1088 guchar
*ctime
, *mtime
, *atime
;
1090 ctime
= pretty_time(&item
->ctime
);
1091 mtime
= pretty_time(&item
->mtime
);
1092 atime
= pretty_time(&item
->atime
);
1094 buf
= g_strdup_printf("a[%s] c[%s] m[%s]", atime
, ctime
, mtime
);
1099 else if (filer_window
->details_type
== DETAILS_PERMISSIONS
)
1102 return g_strdup("---,---,---/--- 12345678 12345678");
1104 buf
= g_strdup_printf("%s %-8.8s %-8.8s",
1105 pretty_permissions(m
),
1106 user_name(item
->uid
),
1107 group_name(item
->gid
));
1113 if (filer_window
->display_style
== SMALL_ICONS
)
1114 return g_strdup("12345M");
1116 return g_strdup("12345 bytes");
1119 if (item
->base_type
!= TYPE_DIRECTORY
)
1121 if (filer_window
->display_style
== SMALL_ICONS
)
1122 buf
= g_strdup(format_size_aligned(item
->size
));
1124 buf
= g_strdup(format_size(item
->size
));
1127 buf
= g_strdup("-");
1133 static void draw_item(GtkWidget
*widget
,
1134 CollectionItem
*colitem
,
1136 FilerWindow
*filer_window
)
1138 DirItem
*item
= (DirItem
*) colitem
->data
;
1139 gboolean selected
= colitem
->selected
;
1141 ViewData
*view
= (ViewData
*) colitem
->view_data
;
1143 g_return_if_fail(view
!= NULL
);
1145 fill_template(area
, colitem
, filer_window
, &template);
1147 /* Set up GC for coloured file types */
1149 type_gc
= gdk_gc_new(widget
->window
);
1151 gdk_gc_set_foreground(type_gc
, type_get_colour(item
,
1152 &widget
->style
->fg
[GTK_STATE_NORMAL
]));
1154 if (template.icon
.width
<= SMALL_WIDTH
&&
1155 template.icon
.height
<= SMALL_HEIGHT
)
1157 draw_small_icon(widget
, &template.icon
,
1158 item
, view
->image
, selected
);
1160 else if (template.icon
.width
<= ICON_WIDTH
&&
1161 template.icon
.height
<= ICON_HEIGHT
)
1163 draw_large_icon(widget
, &template.icon
,
1164 item
, view
->image
, selected
);
1168 draw_huge_icon(widget
, &template.icon
,
1169 item
, view
->image
, selected
);
1172 draw_string(widget
, view
->layout
,
1175 filer_window
->selection_state
,
1178 draw_string(widget
, view
->details
,
1180 template.details
.width
,
1181 filer_window
->selection_state
,
1185 /* Note: Call shrink_grid after this */
1186 static void display_details_set(FilerWindow
*filer_window
, DetailsType details
)
1188 if (filer_window
->details_type
== details
)
1190 filer_window
->details_type
= details
;
1191 display_update_views(filer_window
);
1193 gtk_widget_queue_draw(GTK_WIDGET(filer_window
->collection
));
1196 /* Note: Call shrink_grid after this */
1197 static void display_style_set(FilerWindow
*filer_window
, DisplayStyle style
)
1199 if (filer_window
->display_style
== style
)
1202 filer_window
->display_style
= style
;
1204 display_update_views(filer_window
);
1206 collection_set_functions(filer_window
->collection
,
1207 (CollectionDrawFunc
) draw_item
,
1208 (CollectionTestFunc
) test_point
,
1212 void display_update_view(FilerWindow
*filer_window
,
1215 gboolean update_name_layout
)
1217 DisplayStyle style
= filer_window
->display_style
;
1219 int wrap_width
= -1;
1221 static PangoFontDescription
*monospace
= NULL
;
1224 monospace
= pango_font_description_from_string("monospace");
1228 g_object_unref(G_OBJECT(view
->details
));
1229 view
->details
= NULL
;
1232 str
= details(filer_window
, item
);
1235 PangoAttrList
*list
;
1236 int perm_offset
= -1;
1238 view
->details
= gtk_widget_create_pango_layout(
1239 filer_window
->window
, str
);
1242 pango_layout_set_font_description(view
->details
, monospace
);
1243 pango_layout_get_size(view
->details
, &w
, &h
);
1244 view
->details_width
= w
/ PANGO_SCALE
;
1245 view
->details_height
= h
/ PANGO_SCALE
;
1247 if (filer_window
->details_type
== DETAILS_SUMMARY
)
1249 else if (filer_window
->details_type
== DETAILS_PERMISSIONS
)
1251 if (perm_offset
> -1)
1253 PangoAttribute
*attr
;
1255 attr
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1257 perm_offset
+= 4 * applicable(item
->uid
, item
->gid
);
1258 attr
->start_index
= perm_offset
;
1259 attr
->end_index
= perm_offset
+ 3;
1261 list
= pango_attr_list_new();
1262 pango_attr_list_insert(list
, attr
);
1263 pango_layout_set_attributes(view
->details
, list
);
1269 g_object_unref(view
->image
);
1273 if (filer_window
->show_thumbs
&& item
->base_type
== TYPE_FILE
&&
1274 strcmp(item
->mime_type
->media_type
, "image") == 0)
1278 path
= make_path(filer_window
->real_path
, item
->leafname
)->str
;
1280 view
->image
= g_fscache_lookup_full(pixmap_cache
, path
,
1281 FSCACHE_LOOKUP_ONLY_NEW
, NULL
);
1286 view
->image
= item
->image
;
1288 g_object_ref(view
->image
);
1291 if (view
->layout
&& update_name_layout
)
1293 g_object_unref(G_OBJECT(view
->layout
));
1294 view
->layout
= NULL
;
1301 else if (g_utf8_validate(item
->leafname
, -1, NULL
))
1303 view
->layout
= gtk_widget_create_pango_layout(
1304 filer_window
->window
, item
->leafname
);
1308 PangoAttrList
*list
;
1309 PangoAttribute
*attr
;
1312 utf8
= to_utf8(item
->leafname
);
1313 view
->layout
= gtk_widget_create_pango_layout(
1314 filer_window
->window
, utf8
);
1317 attr
= pango_attr_foreground_new(0xffff, 0, 0);
1318 attr
->start_index
= 0;
1319 attr
->end_index
= 1000;
1320 list
= pango_attr_list_new();
1321 pango_attr_list_insert(list
, attr
);
1322 pango_layout_set_attributes(view
->layout
, list
);
1325 if (filer_window
->details_type
== DETAILS_NONE
)
1327 if (style
== HUGE_ICONS
)
1328 wrap_width
= HUGE_WRAP
* PANGO_SCALE
;
1329 else if (style
== LARGE_ICONS
)
1330 wrap_width
= o_large_width
.int_value
* PANGO_SCALE
;
1333 if (wrap_width
!= -1)
1334 pango_layout_set_width(view
->layout
, wrap_width
);
1336 pango_layout_get_size(view
->layout
, &w
, &h
);
1337 view
->name_width
= w
/ PANGO_SCALE
;
1338 view
->name_height
= h
/ PANGO_SCALE
;
1341 /* 'box' renders a background box if the string is also selected */
1342 static void draw_string(GtkWidget
*widget
,
1343 PangoLayout
*layout
,
1344 GdkRectangle
*area
, /* Area available on screen */
1345 int width
, /* Width of the full string */
1346 GtkStateType selection_state
,
1350 GdkGC
*gc
= selected
1351 ? widget
->style
->fg_gc
[selection_state
]
1354 if (selected
&& box
)
1355 gtk_paint_flat_box(widget
->style
, widget
->window
,
1356 selection_state
, GTK_SHADOW_NONE
,
1357 NULL
, widget
, "text",
1359 MIN(width
, area
->width
),
1362 if (width
> area
->width
)
1364 gdk_gc_set_clip_origin(gc
, 0, 0);
1365 gdk_gc_set_clip_rectangle(gc
, area
);
1368 gdk_draw_layout(widget
->window
, gc
, area
->x
, area
->y
, layout
);
1370 if (width
> area
->width
)
1372 static GdkGC
*red_gc
= NULL
;
1377 GdkColor red
= {0, 0xffff, 0, 0};
1379 red_gc
= gdk_gc_new(widget
->window
);
1380 gdk_colormap_alloc_colors(
1381 gtk_widget_get_colormap(widget
),
1382 &red
, 1, FALSE
, TRUE
, &success
);
1383 gdk_gc_set_foreground(red_gc
, &red
);
1385 gdk_draw_rectangle(widget
->window
, red_gc
, TRUE
,
1386 area
->x
+ area
->width
- 1, area
->y
,
1388 gdk_gc_set_clip_rectangle(gc
, NULL
);