static void mz_files_view_class_init(MzFilesViewClass *klass) {
printf("mz_files_view_class_init\n");
klass->parent_class.snapshot = mz_files_view_snapshot;
+ klass->parent_class.measure = mz_files_view_measure;
+ klass->parent_class.size_allocate = mz_files_view_size_allocate;
}
static void mz_files_view_init(MzFilesView *self) {
self->items = NULL;
self->numitems = 0;
+ self->current_width = 0;
+
// event handler
GtkGesture *drag = gtk_gesture_drag_new();
g_signal_connect(drag, "drag-begin", G_CALLBACK(drag_begin_cb), self);
int width = gtk_widget_get_width(widget);
int height = gtk_widget_get_height(widget);
+ //printf("wh: %d x %d\n", width, height);
+
+ view->current_width = width;
int item_width = 80;
int item_height = 120;
cls->snapshot(widget, snapshot);
}
+void mz_files_view_measure(GtkWidget *widget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline)
+{
+ //printf("mz_files_view_measure\n");
+ //printf("for size: %d - %d %d %d %d\n", for_size, *minimum, *natural, *minimum_baseline, *natural_baseline);
+
+ MzFilesView *view = (MzFilesView*)widget;
+
+ if(view->numitems == 0 || view->current_width == 0) {
+ return;
+ }
+
+ if(orientation == GTK_ORIENTATION_VERTICAL) {
+ int item_width = 80;
+ int item_height = 120;
+ int items_per_line = view->current_width / item_width;
+
+ int lines = view->numitems / items_per_line;
+ int r = lines*items_per_line < view->numitems ? 1 : 0;
+ //printf("nitems: %d ipl lines: %d: %d\n", (int)view->numitems, items_per_line, lines+r);
+
+ int height = (lines+r) * item_height;
+ //printf("minimum height: %d\n", height);
+
+ *minimum = height;
+ *natural = height;
+ }
+}
+
+static void mz_files_view_size_allocate(
+ GtkWidget *widget,
+ int width,
+ int height,
+ int baseline)
+{
+ GtkWidgetClass *parent_class = mz_files_view_parent_class;
+ if (parent_class->size_allocate)
+ parent_class->size_allocate(widget, width, height, baseline);
+
+ MzFilesView *view = (MzFilesView *)widget;
+ if (view->current_width != width) {
+ view->current_width = width;
+ gtk_widget_queue_resize(widget);
+ }
+}
+
/* -------------------------- event handler -------------------------- */
}
}
+ gtk_widget_queue_resize(GTK_WIDGET(view));
gtk_widget_queue_draw(GTK_WIDGET(view));
}
MzIconGadget *items;
size_t numitems;
+ int current_width;
MzViewSection *sections;
size_t numsections;
} MzFilesView;
void mz_files_view_snapshot(GtkWidget *widget, GtkSnapshot *snapshot);
+void mz_files_view_measure(GtkWidget *widget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline);
+
+static void mz_files_view_size_allocate(
+ GtkWidget *widget,
+ int width,
+ int height,
+ int baseline);
+
void mz_update_files_view(MzFilesView *view, FilesSection *sections, size_t numsections);
void mz_files_view_remove_items(MzFilesView *view);
#ifdef GTK_MAJOR_VERSION
static UIWIDGET create_filesview(UiObject *obj, UiWidgetArgs args, void *userdata) {
+ MainWindow *win = userdata;
MzFilesView *view = mz_files_view_new();
- return GTK_WIDGET(view);
+ win->files_gridview = GTK_WIDGET(view);
+
+ GtkWidget *sw = gtk_scrolled_window_new();
+ gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), GTK_WIDGET(view));
+ return sw;
}
#endif
void window_create_browser_view(UiObject *obj, MainWindow *win) {
ui_tabview(obj, .tabview = UI_TABVIEW_INVISIBLE, .varname = "view") {
ui_tab(obj, "iconview") {
- win->files_gridview = ui_customwidget(obj, create_filesview, NULL, .fill = UI_ON);
+ ui_customwidget(obj, create_filesview, win, .fill = UI_ON);
}
ui_tab(obj, "listview") {