ptk-icon-view.c
来自「台湾人开发的Linux下的文件管理器」· C语言 代码 · 共 1,591 行 · 第 1/5 页
C
1,591 行
{ PtkIconView * icon_view = PTK_ICON_VIEW ( object ); switch ( prop_id ) { case PROP_COLUMN_SPACING: ptk_icon_view_set_column_spacing ( icon_view, g_value_get_int ( value ) ); break; case PROP_COLUMNS: ptk_icon_view_set_columns ( icon_view, g_value_get_int ( value ) ); break; case PROP_ITEM_WIDTH: ptk_icon_view_set_item_width ( icon_view, g_value_get_int ( value ) ); break; case PROP_MARGIN: ptk_icon_view_set_margin ( icon_view, g_value_get_int ( value ) ); break; case PROP_MARKUP_COLUMN: ptk_icon_view_set_markup_column ( icon_view, g_value_get_int ( value ) ); break; case PROP_MODEL: ptk_icon_view_set_model ( icon_view, g_value_get_object ( value ) ); break; case PROP_ORIENTATION: ptk_icon_view_set_orientation ( icon_view, g_value_get_enum ( value ) ); break; case PROP_PIXBUF_COLUMN: ptk_icon_view_set_pixbuf_column ( icon_view, g_value_get_int ( value ) ); break; case PROP_REORDERABLE: ptk_icon_view_set_reorderable ( icon_view, g_value_get_boolean ( value ) ); break; case PROP_ROW_SPACING: ptk_icon_view_set_row_spacing ( icon_view, g_value_get_int ( value ) ); break; case PROP_SELECTION_MODE: ptk_icon_view_set_selection_mode ( icon_view, g_value_get_enum ( value ) ); break; case PROP_SPACING: ptk_icon_view_set_spacing ( icon_view, g_value_get_int ( value ) ); break; case PROP_TEXT_COLUMN: ptk_icon_view_set_text_column ( icon_view, g_value_get_int ( value ) ); break; case PROP_ENABLE_SEARCH: ptk_icon_view_set_enable_search ( icon_view, g_value_get_boolean ( value ) ); break; case PROP_SEARCH_COLUMN: ptk_icon_view_set_search_column ( icon_view, g_value_get_int ( value ) ); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID ( object, prop_id, pspec ); break; }}static voidptk_icon_view_realize ( GtkWidget *widget ){ GdkWindowAttr attributes; PtkIconView *icon_view = PTK_ICON_VIEW ( widget ); gint attributes_mask; GTK_WIDGET_SET_FLAGS ( widget, GTK_REALIZED ); /* Allocate the clipping window */ attributes.window_type = GDK_WINDOW_CHILD; attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gtk_widget_get_visual ( widget ); attributes.colormap = gtk_widget_get_colormap ( widget ); attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; widget->window = gdk_window_new ( gtk_widget_get_parent_window ( widget ), &attributes, attributes_mask ); gdk_window_set_user_data ( widget->window, widget ); /* Allocate the icons window */ attributes.x = 0; attributes.y = 0; attributes.width = MAX ( icon_view->priv->width, widget->allocation.width ); attributes.height = MAX ( icon_view->priv->height, widget->allocation.height ); attributes.event_mask = GDK_EXPOSURE_MASK | GDK_SCROLL_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | gtk_widget_get_events ( widget ); icon_view->priv->bin_window = gdk_window_new ( widget->window, &attributes, attributes_mask ); gdk_window_set_user_data ( icon_view->priv->bin_window, widget ); /* Attach style/background */ widget->style = gtk_style_attach ( widget->style, widget->window ); gdk_window_set_background ( icon_view->priv->bin_window, &widget->style->base[ widget->state ] ); gdk_window_set_background ( widget->window, &widget->style->base[ widget->state ] ); /* map the icons window */ gdk_window_show ( icon_view->priv->bin_window );}static voidptk_icon_view_unrealize ( GtkWidget *widget ){ PtkIconView * icon_view = PTK_ICON_VIEW ( widget ); /* drop the icons window */ gdk_window_set_user_data ( icon_view->priv->bin_window, NULL ); gdk_window_destroy ( icon_view->priv->bin_window ); icon_view->priv->bin_window = NULL; /* let GtkWidget destroy children and widget->window */ if ( GTK_WIDGET_CLASS ( ptk_icon_view_parent_class ) ->unrealize ) ( *GTK_WIDGET_CLASS ( ptk_icon_view_parent_class ) ->unrealize ) ( widget );}static voidptk_icon_view_size_request ( GtkWidget *widget, GtkRequisition *requisition ){ PtkIconViewChild * child; GtkRequisition child_requisition; PtkIconView *icon_view = PTK_ICON_VIEW ( widget ); GList *lp; /* well, this is easy */ requisition->width = icon_view->priv->width; requisition->height = icon_view->priv->height; /* handle the child widgets */ for ( lp = icon_view->priv->children; lp != NULL; lp = lp->next ) { child = lp->data; if ( GTK_WIDGET_VISIBLE ( child->widget ) ) gtk_widget_size_request ( child->widget, &child_requisition ); }}static voidptk_icon_view_allocate_children ( PtkIconView *icon_view ){ const PtkIconViewChild * child; GtkAllocation allocation; const GList *lp; gint focus_line_width; gint focus_padding; for ( lp = icon_view->priv->children; lp != NULL; lp = lp->next ) { child = PTK_ICON_VIEW_CHILD ( lp->data ); /* totally ignore our child's requisition */ if ( child->cell < 0 ) allocation = child->item->area; else allocation = child->item->box[ child->cell ]; /* increase the item area by focus width/padding */ gtk_widget_style_get ( GTK_WIDGET ( icon_view ), "focus-line-width", &focus_line_width, "focus-padding", &focus_padding, NULL ); allocation.x = MAX ( 0, allocation.x - ( focus_line_width + focus_padding ) ); allocation.y = MAX ( 0, allocation.y - ( focus_line_width + focus_padding ) ); allocation.width = MIN ( icon_view->priv->width - allocation.x, allocation.width + 2 * ( focus_line_width + focus_padding ) ); allocation.height = MIN ( icon_view->priv->height - allocation.y, allocation.height + 2 * ( focus_line_width + focus_padding ) ); /* allocate the area to the child */ gtk_widget_size_allocate ( child->widget, &allocation ); }}static voidptk_icon_view_size_allocate ( GtkWidget *widget, GtkAllocation *allocation ){ GtkAdjustment * hadjustment; GtkAdjustment *vadjustment; PtkIconView *icon_view = PTK_ICON_VIEW ( widget ); /* apply the new size allocation */ widget->allocation = *allocation; /* move/resize the clipping window, the icons window * will be handled by ptk_icon_view_layout(). */ if ( GTK_WIDGET_REALIZED ( widget ) ) gdk_window_move_resize ( widget->window, allocation->x, allocation->y, allocation->width, allocation->height ); /* layout the items */ ptk_icon_view_layout ( icon_view ); /* allocate space to the widgets (editing) */ ptk_icon_view_allocate_children ( icon_view ); /* update the horizontal scroll adjustment accordingly */ hadjustment = icon_view->priv->hadjustment; hadjustment->page_size = allocation->width; hadjustment->page_increment = allocation->width * 0.9; hadjustment->step_increment = allocation->width * 0.1; hadjustment->lower = 0; hadjustment->upper = MAX ( allocation->width, icon_view->priv->width ); if ( hadjustment->value > hadjustment->upper - hadjustment->page_size ) gtk_adjustment_set_value ( hadjustment, MAX ( 0, hadjustment->upper - hadjustment->page_size ) ); gtk_adjustment_changed ( hadjustment ); /* update the vertical scroll adjustment accordingly */ vadjustment = icon_view->priv->vadjustment; vadjustment->page_size = allocation->height; vadjustment->page_increment = allocation->height * 0.9; vadjustment->step_increment = allocation->height * 0.1; vadjustment->lower = 0; vadjustment->upper = MAX ( allocation->height, icon_view->priv->height ); if ( vadjustment->value > vadjustment->upper - vadjustment->page_size ) gtk_adjustment_set_value ( vadjustment, MAX ( 0, vadjustment->upper - vadjustment->page_size ) ); gtk_adjustment_changed ( vadjustment );}static voidptk_icon_view_style_set ( GtkWidget *widget, GtkStyle *previous_style ){ PtkIconView * icon_view = PTK_ICON_VIEW ( widget ); /* let GtkWidget do its work */ ( *GTK_WIDGET_CLASS ( ptk_icon_view_parent_class ) ->style_set ) ( widget, previous_style ); /* apply the new style for the bin_window if we're realized */ if ( GTK_WIDGET_REALIZED ( widget ) ) gdk_window_set_background ( icon_view->priv->bin_window, &widget->style->base[ widget->state ] );}static gbooleanptk_icon_view_expose_event ( GtkWidget *widget, GdkEventExpose *event ){ PtkIconViewDropPosition dest_pos; PtkIconViewItem *dest_item = NULL; PtkIconViewItem *item; PtkIconView *icon_view = PTK_ICON_VIEW ( widget ); GtkTreePath *path; GdkRectangle rubber_rect; const GList *lp; gint dest_index = -1; /* verify that the expose happened on the icon window */ if ( G_UNLIKELY ( event->window != icon_view->priv->bin_window ) ) return FALSE; /* Paint background pixmap if it exists */ if ( icon_view->priv->pixmap ) { gdk_draw_drawable( event->window, widget->style->fg_gc[ GTK_STATE_NORMAL ], icon_view->priv->pixmap, icon_view->priv->pixmap_x_offset + event->area.x, icon_view->priv->pixmap_y_offset + event->area.y, event->area.x, event->area.y, event->area.width, event->area.height ); } /* don't handle expose if the layout isn't done yet; the layout * method will schedule a redraw when done. */ if ( G_UNLIKELY ( icon_view->priv->layout_idle_id >= 0 ) ) return FALSE; /* check if we need to draw a drag indicator */ ptk_icon_view_get_drag_dest_item ( icon_view, &path, &dest_pos ); if ( G_UNLIKELY ( path != NULL ) ) { dest_index = gtk_tree_path_get_indices ( path ) [ 0 ]; gtk_tree_path_free ( path ); } /* paint the rubberband background */ if ( G_UNLIKELY ( icon_view->priv->doing_rubberband ) ) { /* calculate the rubberband area */ rubber_rect.x = MIN ( icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2 ); rubber_rect.y = MIN ( icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2 ); rubber_rect.width = ABS ( icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2 ) + 1; rubber_rect.height = ABS ( icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2 ) + 1; /* we take advantage of double-buffering here and use only a single * draw_rectangle() operation w/o having to take care of clipping. */ gdk_draw_rect
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?