⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dw_gtk_scrolled_frame.c

📁 微型浏览器
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * File: dw_gtk_scrolled_frame.c * * Copyright (C) 2001  Sebastian Geerken <S.Geerken@ping.de> *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *//* * GtkDwScrolledFrame is a container for the GtkDwViewport, it adds * a focus around the child and is responsible for focus, keys and the * button 2 dragging. */#include <gtk/gtk.h>#include <gdk/gdkkeysyms.h>#include "dw_gtk_scrolled_frame.h"static GtkBinClass *parent_class = NULL;/* object/class initialisation */static void Dw_gtk_scrolled_frame_init(GtkDwScrolledFrame * frame);static void Dw_gtk_scrolled_frame_class_init(GtkDwScrolledFrameClass * klass);/* GtkObject methods */static void Dw_gtk_scrolled_frame_destroy(GtkObject * object);/* GtkWidget methods */static void Dw_gtk_scrolled_frame_realize(GtkWidget * widget);static void Dw_gtk_scrolled_frame_unrealize(GtkWidget * widget);static void Dw_gtk_scrolled_frame_size_request(GtkWidget * widget, GtkRequisition * requisition);static void Dw_gtk_scrolled_frame_size_allocate(GtkWidget * widget, GtkAllocation * allocation);static void Dw_gtk_scrolled_frame_draw(GtkWidget * widget, GdkRectangle * area);static void Dw_gtk_scrolled_frame_draw_focus(GtkWidget * widget);static gint Dw_gtk_scrolled_frame_expose(GtkWidget * widget, GdkEventExpose * event);static gint Dw_gtk_scrolled_frame_key_press(GtkWidget * widget, GdkEventKey * event);static gint Dw_gtk_scrolled_frame_focus_in(GtkWidget * widget, GdkEventFocus * event);static gint Dw_gtk_scrolled_frame_focus_out(GtkWidget * widget, GdkEventFocus * event);static gint Dw_gtk_scrolled_frame_button_press(GtkWidget * widget, GdkEventButton * event);static gint Dw_gtk_scrolled_frame_button_release(GtkWidget * widget, GdkEventButton * event);static gint Dw_gtk_scrolled_frame_motion_notify(GtkWidget * widget, GdkEventMotion * event);/* GtkContainer methods */static void Dw_gtk_scrolled_frame_add(GtkContainer * container, GtkWidget * widget);static gint Dw_gtk_scrolled_frame_focus(GtkContainer * container, GtkDirectionType direction);/* GtkDwScrolledFrame methods */static void Dw_gtk_scrolled_frame_set_scroll_adjustments(GtkDwScrolledFrame * frame, GtkAdjustment * hadjustment, GtkAdjustment * vadjustment);static gint Dw_gtk_scrolled_frame_set_hadjustment_value(GtkDwScrolledFrame * frame, gfloat pos);static gint Dw_gtk_scrolled_frame_set_vadjustment_value(GtkDwScrolledFrame * frame, gfloat pos);enum {	SET_SCROLL_ADJUSTMENTS,	USER_HCHANGED,	USER_VCHANGED,	LAST_SIGNAL};static guint frame_signals[LAST_SIGNAL] = { 0 };/* * Standard Gtk+ function */GtkType a_Dw_gtk_scrolled_frame_get_type(void){	static GtkType type = 0;	if (!type) {		GtkTypeInfo info = {			"GtkDwScrolledFrame",			sizeof(GtkDwScrolledFrame),			sizeof(GtkDwScrolledFrameClass),			(GtkClassInitFunc) Dw_gtk_scrolled_frame_class_init,			(GtkObjectInitFunc) Dw_gtk_scrolled_frame_init,			(GtkArgSetFunc) NULL,			(GtkArgGetFunc) NULL,		};		type = gtk_type_unique(GTK_TYPE_BIN, &info);	}	return type;}/* * Standard Gtk+ function */GtkWidget *a_Dw_gtk_scrolled_frame_new(GtkAdjustment * hadjustment, GtkAdjustment * vadjustment){	GtkWidget *widget;	GtkDwScrolledFrame *frame;	widget = gtk_widget_new(GTK_TYPE_DW_SCROLLED_FRAME, NULL);	frame = GTK_DW_SCROLLED_FRAME(widget);	frame->hadjustment = hadjustment;	frame->vadjustment = vadjustment;	return widget;}/********************************* *                               * *  object/class initialisation  * *                               * *********************************//* * Standard Gtk+ function */static void Dw_gtk_scrolled_frame_init(GtkDwScrolledFrame * frame){	GTK_WIDGET_SET_FLAGS(frame, GTK_CAN_FOCUS);	GTK_WIDGET_UNSET_FLAGS(frame, GTK_NO_WINDOW);	frame->hadjustment = NULL;	frame->vadjustment = NULL;	frame->button2_pressed = FALSE;	frame->drag_idle_id = -1;}/* * Standard Gtk+ function */static void Dw_gtk_scrolled_frame_class_init(GtkDwScrolledFrameClass * klass){	GtkObjectClass *object_class;	GtkWidgetClass *widget_class;	GtkContainerClass *container_class;	parent_class = gtk_type_class(gtk_bin_get_type());	object_class = (GtkObjectClass *) klass;	widget_class = (GtkWidgetClass *) klass;	container_class = (GtkContainerClass *) klass;	frame_signals[SET_SCROLL_ADJUSTMENTS] = gtk_signal_new("set_scroll_adjustments", GTK_RUN_LAST, object_class->type, GTK_SIGNAL_OFFSET(GtkDwScrolledFrameClass, set_scroll_adjustments), gtk_marshal_NONE__POINTER_POINTER, GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);	widget_class->set_scroll_adjustments_signal = frame_signals[SET_SCROLL_ADJUSTMENTS];	frame_signals[USER_HCHANGED] = gtk_signal_new("user_hchanged", GTK_RUN_LAST | GTK_RUN_ACTION, object_class->type, GTK_SIGNAL_OFFSET(GtkDwScrolledFrameClass, user_hchanged), gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0);	frame_signals[USER_VCHANGED] = gtk_signal_new("user_vchanged", GTK_RUN_LAST | GTK_RUN_ACTION, object_class->type, GTK_SIGNAL_OFFSET(GtkDwScrolledFrameClass, user_vchanged), gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0);	gtk_object_class_add_signals(object_class, frame_signals, LAST_SIGNAL);	object_class->destroy = Dw_gtk_scrolled_frame_destroy;	widget_class->realize = Dw_gtk_scrolled_frame_realize;	widget_class->unrealize = Dw_gtk_scrolled_frame_unrealize;	widget_class->size_request = Dw_gtk_scrolled_frame_size_request;	widget_class->size_allocate = Dw_gtk_scrolled_frame_size_allocate;	widget_class->draw_focus = Dw_gtk_scrolled_frame_draw_focus;	widget_class->draw = Dw_gtk_scrolled_frame_draw;	widget_class->expose_event = Dw_gtk_scrolled_frame_expose;	widget_class->key_press_event = Dw_gtk_scrolled_frame_key_press;	widget_class->focus_in_event = Dw_gtk_scrolled_frame_focus_in;	widget_class->focus_out_event = Dw_gtk_scrolled_frame_focus_out;	widget_class->button_press_event = Dw_gtk_scrolled_frame_button_press;	widget_class->button_release_event = Dw_gtk_scrolled_frame_button_release;	widget_class->motion_notify_event = Dw_gtk_scrolled_frame_motion_notify;	container_class->add = Dw_gtk_scrolled_frame_add;	container_class->focus = Dw_gtk_scrolled_frame_focus;	klass->set_scroll_adjustments = Dw_gtk_scrolled_frame_set_scroll_adjustments;	klass->user_hchanged = NULL;	klass->user_vchanged = NULL;}/*********************** *                     * *  GtkObject methods  * *                     * ***********************//* * Standard Gtk+ function */static void Dw_gtk_scrolled_frame_destroy(GtkObject * object){	GtkDwScrolledFrame *frame;	frame = GTK_DW_SCROLLED_FRAME(object);	if (frame->drag_idle_id != -1)		gtk_idle_remove(frame->drag_idle_id);	(*(GTK_OBJECT_CLASS(parent_class)->destroy)) (object);}/*********************** *                     * *  GtkWidget methods  * *                     * ***********************//* * Standard Gtk+ function */static void Dw_gtk_scrolled_frame_realize(GtkWidget * widget){	GdkWindowAttr attributes;	GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);	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 = (gtk_widget_get_events(widget)				 | GDK_EXPOSURE_MASK | GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK);	widget->window = gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP);	gdk_window_set_user_data(widget->window, widget);	widget->style = gtk_style_attach(widget->style, widget->window);	gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);	GTK_DW_SCROLLED_FRAME(widget)->drag_cursor = gdk_cursor_new(GDK_FLEUR);}/* * Standard Gtk+ function */static void Dw_gtk_scrolled_frame_unrealize(GtkWidget * widget){	gdk_cursor_destroy(GTK_DW_SCROLLED_FRAME(widget)->drag_cursor);}/* * Standard Gtk+ function */static void Dw_gtk_scrolled_frame_size_allocate(GtkWidget * widget, GtkAllocation * allocation){	GtkBin *bin;	gint border_width;	GtkAllocation child_allocation;	widget->allocation = *allocation;	bin = GTK_BIN(widget);	if (GTK_WIDGET_REALIZED(widget))		gdk_window_move_resize(widget->window, allocation->x, allocation->y, allocation->width, allocation->height);	if (bin->child) {		border_width = GTK_CONTAINER(widget)->border_width;		child_allocation.width = MAX(allocation->width - 2 * (widget->style->klass->xthickness + border_width), 1);		child_allocation.height = MAX(allocation->height - 2 * (widget->style->klass->ythickness + border_width), 1);		child_allocation.x = (allocation->width - child_allocation.width) / 2;		child_allocation.y = (allocation->height - child_allocation.height) / 2;		gtk_widget_size_allocate(bin->child, &child_allocation);	}}/* * Standard Gtk+ function */static void Dw_gtk_scrolled_frame_size_request(GtkWidget * widget, GtkRequisition * requisition){	GtkBin *bin;	gint border_width;	GtkRequisition child_requisition;	bin = GTK_BIN(widget);	if (bin->child) {		border_width = GTK_CONTAINER(widget)->border_width;		gtk_widget_size_request(bin->child, &child_requisition);		requisition->width = child_requisition.width + 2 * (widget->style->klass->xthickness + border_width);		requisition->height = child_requisition.height + 2 * (widget->style->klass->ythickness + border_width);	} else {		requisition->width = 100;		requisition->height = 100;	}}/* * Draw the frame, eventually with a focus border */static void Dw_gtk_scrolled_frame_paint_shadow(GtkWidget * widget, GdkRectangle * area){	gint border_width;	if (GTK_WIDGET_DRAWABLE(widget)) {		border_width = GTK_CONTAINER(widget)->border_width;		if (GTK_WIDGET_HAS_FOCUS(widget)) {			gtk_draw_shadow(widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_IN, border_width + 1, border_width + 1, widget->allocation.width - 2 * (border_width + 1), widget->allocation.height - 2 * (border_width + 1));			gtk_paint_focus(widget->style, widget->window, area, widget, "button", border_width, border_width, widget->allocation.width - 2 * border_width - 1, widget->allocation.height - 2 * border_width - 1);		} else {			gtk_draw_shadow(widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_IN, border_width, border_width, widget->allocation.width - 2 * border_width, widget->allocation.height - 2 * border_width);		}	}}/* * Standard Gtk+ function */static void Dw_gtk_scrolled_frame_draw_focus(GtkWidget * widget){	Dw_gtk_scrolled_frame_paint_shadow(widget, NULL);}/* * Standard Gtk+ function */static void Dw_gtk_scrolled_frame_draw(GtkWidget * widget, GdkRectangle * area){	(*(GTK_WIDGET_CLASS(parent_class)->draw)) (widget, area);	Dw_gtk_scrolled_frame_paint_shadow(widget, area);}/* * Standard Gtk+ function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -