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

📄 gemscrolledwindow.c.svn-base

📁 一款Linux手机上应用的文件管理器 系统要求就安装Gtk+2.0
💻 SVN-BASE
字号:
/*	libgemwidget - Gtk+ Embedded Widget library * *	Authors: YE Nan <nan.ye@orange-ftgourp.com>  *	 *	This software and associated documentation files (the "Software")  *	are copyright (C) 2005 LiPS Linux Phone Standards Forum [FranceTelecom]  *	All Rights Reserved.  * *	A copyright license is hereby granted for redistribution and use of  *	the Software in source and binary forms, with or without modification,  *	provided that the following conditions are met:  *	- Redistributions of source code must retain the above copyright notice,  *	this copyright license and the following disclaimer.  *  - Redistributions in binary form must reproduce the above copyright  * 	notice, this copyright license and the following disclaimer in the  *	documentation and/or other materials provided with the distribution.  *	- Neither the name of LiPS  nor the names of its Members may be used  *	to endorse or promote products derived from the Software without  *	specific prior written permission.  * *	A patent license for any Necessary Claims owned by Members of LiPS Forum  *	to make, have made, use, import, offer to sell, lease and sell or otherwise  *	distribute any implementation compliant with the any specification adopted  *	by the LiPS Forumcan be obtained from the respective Members on reasonable  *	and non-discriminatory terms and conditions and under reciprocity, as  *	regulated in more detail in the Internal Policy of the LiPS Forum.  * *	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER, ITS MEMBERS AND CONTRIBUTORS  *	"AS IS", AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,  *	THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE  *	AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER,  *	ITS MEMBERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,  *	PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;  *	OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  *	WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  *	POSSIBILITY OF SUCH DAMAGE.  */#include <gtk/gtk.h>#include "gemscrolledwindow.h"static void	gem_scrolled_window_class_init		(GemScrolledWindowClass			*klass);static void	gem_scrolled_window_init					(GemScrolledWindow					*window);static void	gem_scrolled_window_finalize			(GObject										*object);static GtkFrameClass * parent_class = NULL;GTypegem_scrolled_window_get_type (void){	static GType auto_scrolled_window_type = 0;  if (!auto_scrolled_window_type)	{		static const GTypeInfo auto_scrolled_window_info =		{			sizeof (GemScrolledWindowClass),			NULL,		/* base_init */			NULL,		/* base_finalize */			(GClassInitFunc) gem_scrolled_window_class_init,			NULL,		/* class_finalize */			NULL,		/* class_data */			sizeof (GemScrolledWindow),			0,			/* n_preallocs */			(GInstanceInitFunc) gem_scrolled_window_init,		};		auto_scrolled_window_type = g_type_register_static (GTK_TYPE_FRAME,																												"GemScrolledWindow", 																												&auto_scrolled_window_info, 																												0);	}	return auto_scrolled_window_type;}static voidgem_scrolled_window_class_init (GemScrolledWindowClass * klass){  GObjectClass * object_class;  object_class = (GObjectClass *)klass;	parent_class = g_type_class_peek_parent (klass);	  object_class->finalize = gem_scrolled_window_finalize; 	  	return;}static voidgem_scrolled_window_finalize (GObject * object){	G_OBJECT_CLASS(parent_class)->finalize(object);		return;}static voidgem_scrolled_window_set_focus_child_cb (GtkContainer		*container,																				GtkWidget				*widget,																				gpointer				 user_data){	GemScrolledWindow * scrolled_window = (GemScrolledWindow *)user_data;	GtkScrolledWindow * sw = GTK_SCROLLED_WINDOW(scrolled_window->sw);	GtkAdjustment * hadjustment = NULL;	GtkAdjustment * vadjustment = NULL;	GtkWidget * focused_child = NULL;		hadjustment = gtk_scrolled_window_get_hadjustment(sw);	vadjustment = gtk_scrolled_window_get_vadjustment(sw);	focused_child = widget;	if (focused_child)	{/*		GtkWidget * parent = NULL;		parent = gtk_widget_get_parent(focused_child);*/		//		if (GTK_WIDGET_REALIZED(focused_child))		{			gint x, y;						gtk_widget_translate_coordinates(focused_child,																			 GTK_WIDGET(container),																			 0, 0,																			 &x, &y);						if (vadjustment)			{				gdouble lower;				gdouble upper;				gdouble prop;								g_object_get(vadjustment,										 "lower", &lower,										 "upper", &upper,										 NULL);										 				prop = (upper - lower) / (gdouble)GTK_WIDGET(container)->allocation.height;/*				g_print("%s(): prop(%f), clamp[%f, %f]\n",												__FUNCTION__,												prop,												y * prop,												(y + focused_child->allocation.height) * prop);*/																gtk_adjustment_clamp_page(vadjustment,																	y * prop,																	(y + focused_child->allocation.height) * prop);							}									if (hadjustment)			{				gdouble lower;				gdouble upper;				gdouble prop;								g_object_get(vadjustment,										 "lower", &lower,										 "upper", &upper,										 NULL);										 				prop = (upper - lower) / (gdouble)GTK_WIDGET(container)->allocation.width;								gtk_adjustment_clamp_page(hadjustment,																	x * prop,																	(x + focused_child->allocation.width) * prop);							}					}	}		scrolled_window->focused_child = widget;	return;}static voidgem_scrolled_window_size_allocate_cb (GtkWidget				*widget,                                      GtkAllocation		*allocation,                                      gpointer				 user_data){	GemScrolledWindow * scrolled_window = GEM_SCROLLED_WINDOW(widget);	GtkScrolledWindow * sw = GTK_SCROLLED_WINDOW(scrolled_window->sw);	GtkContainer * container = GTK_CONTAINER(user_data);	GtkWidget * focused_child = NULL;	GtkAdjustment * hadjustment = NULL;	GtkAdjustment * vadjustment = NULL;		hadjustment = gtk_scrolled_window_get_hadjustment(sw);	vadjustment = gtk_scrolled_window_get_vadjustment(sw);	focused_child = scrolled_window->focused_child;/*	g_print("%s(): focused_child(0x%08x), orig(%d, %d), size(%d, %d)\n", 					__FUNCTION__,					focused_child,					focused_child->allocation.x,					focused_child->allocation.y,					focused_child->allocation.width,					focused_child->allocation.height);*/		if (focused_child)	{/*		GtkWidget * parent = NULL;		parent = gtk_widget_get_parent(focused_child);		g_print("%s(): parent(0x%08x), orig(%d, %d), size(%d, %d)\n", 						__FUNCTION__,						parent,						parent->allocation.x,						parent->allocation.y,						parent->allocation.width,						parent->allocation.height);*/				if (GTK_WIDGET_REALIZED(focused_child))		{			gint x, y;						gtk_widget_translate_coordinates(focused_child,																			 GTK_WIDGET(container),																			 0, 0,																			 &x, &y);/*			g_print("%s(): [%d, %d] -> [%d, %d]\n", 							__FUNCTION__,							focused_child->allocation.x,							focused_child->allocation.y,							x,							y);*/						if (vadjustment)			{				gdouble lower;				gdouble upper;				gdouble prop;				gdouble page_size;								g_object_get(vadjustment,										 "lower", &lower,										 "upper", &upper,										 "page-size", &page_size,										 NULL);				prop = (upper - lower) / (gdouble)GTK_WIDGET(container)->allocation.height;/*				g_print("%s(): page-size(%f), prop(%f), clamp[%f, %f]\n",								__FUNCTION__,								page_size,								prop,								y * prop,								(y + focused_child->allocation.height) * prop);*/												gtk_adjustment_clamp_page(vadjustment, 																	y * prop,																	(y + focused_child->allocation.height) * prop);			}									if (hadjustment)			{				gdouble lower;				gdouble upper;				gdouble prop;				gdouble page_size;								g_object_get(hadjustment,										 "lower", &lower,										 "upper", &upper,										 "page-size", &page_size,										 NULL);										 				prop = (upper - lower) / (gdouble)GTK_WIDGET(container)->allocation.width;								gtk_adjustment_clamp_page(hadjustment,																	x * prop,																	(x + focused_child->allocation.width) * prop);			}					}	}	return;}static voidgem_scrolled_window_init (GemScrolledWindow * scrolled_window){	scrolled_window->sw = gtk_scrolled_window_new(NULL, NULL);		gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window->sw), 																 GTK_POLICY_NEVER, 																 GTK_POLICY_AUTOMATIC);	gtk_container_add(GTK_CONTAINER(scrolled_window), 										scrolled_window->sw);	gtk_widget_show(scrolled_window->sw); 	scrolled_window->viewport				= NULL;	 	scrolled_window->child					= NULL; 	scrolled_window->focused_child	= NULL;		return;}GtkWidget *gem_scrolled_window_new (void){  return gtk_widget_new(GEM_TYPE_SCROLLED_WINDOW,  											NULL);}void gem_scrolled_window_add_with_viewport (GemScrolledWindow			*scrolled_window,																			 GtkContainer						*container){	GtkScrolledWindow * sw = GTK_SCROLLED_WINDOW(scrolled_window->sw);	g_assert(GTK_IS_CONTAINER(container));	if (scrolled_window->viewport == NULL)	{		scrolled_window->viewport = gtk_viewport_new(NULL, NULL);					gtk_container_add(GTK_CONTAINER(sw),											scrolled_window->viewport);	}		gtk_container_add(GTK_CONTAINER(scrolled_window->viewport),										GTK_WIDGET(container));	/*	gtk_container_set_focus_hadjustment(GTK_CONTAINER(widget), 																			gtk_scrolled_window_get_hadjustment(sw));	gtk_container_set_focus_vadjustment(GTK_CONTAINER(widget),																			gtk_scrolled_window_get_vadjustment(sw));*/	g_signal_connect(G_OBJECT(container),									 "set-focus-child",									 G_CALLBACK(gem_scrolled_window_set_focus_child_cb), 									 scrolled_window);	//	g_signal_connect(G_OBJECT(scrolled_window),//									 "size-allocate",//									 G_CALLBACK(gem_scrolled_window_size_allocate_cb), //									 (gpointer)container);		return;		}void gem_scrolled_window_add (GemScrolledWindow		*scrolled_window,												 GtkContainer					*container){	GtkScrolledWindow * sw = GTK_SCROLLED_WINDOW(scrolled_window->sw);	g_assert(GTK_IS_CONTAINER(container));		gtk_container_add(GTK_CONTAINER(sw),										GTK_WIDGET(container));/*	gtk_container_set_focus_hadjustment(GTK_CONTAINER(container), 																			gtk_scrolled_window_get_hadjustment(sw));	gtk_container_set_focus_vadjustment(GTK_CONTAINER(container),																			gtk_scrolled_window_get_vadjustment(sw));*/	g_signal_connect(G_OBJECT(container),									 "set-focus-child",									 G_CALLBACK(gem_scrolled_window_set_focus_child_cb), 									 scrolled_window);	g_signal_connect(G_OBJECT(scrolled_window),									 "size-allocate",									 G_CALLBACK(gem_scrolled_window_size_allocate_cb), 									 (gpointer)container);	if (scrolled_window->viewport)	{		gtk_widget_destroy(scrolled_window->viewport);		scrolled_window->viewport = NULL;	}									 	return;	}GtkWidget *gem_scrolled_window_get_viewport (GemScrolledWindow		*scrolled_window){	return scrolled_window->viewport;}/*vi:ts=2:nowrap:ai:expandtab */

⌨️ 快捷键说明

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