📄 gemhashview.c.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 "gemhashview.h"#include "gemhashviewcell.h"static void gem_hash_view_class_init (GemHashViewClass *klass);static void gem_hash_view_init (GemHashView *view);static void gem_hash_view_destroy (GtkObject *object);static GemScrolledWindowClass * parent_class = NULL;GTypegem_hash_view_get_type (void){ static GType view_type = 0; if (!view_type) { static const GTypeInfo view_info = { sizeof (GemHashViewClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) gem_hash_view_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (GemHashView), 0, /* n_preallocs */ (GInstanceInitFunc) gem_hash_view_init, NULL, }; view_type = g_type_register_static(GEM_TYPE_SCROLLED_WINDOW, "GemHashView", &view_info, 0); } return view_type;}static voidgem_hash_view_class_init (GemHashViewClass * klass){ GtkObjectClass *object_class; object_class = (GtkObjectClass*) klass; parent_class = g_type_class_peek_parent (klass); object_class->destroy = gem_hash_view_destroy; return;}static voidgem_hash_view_destroy (GtkObject *object){ GemHashView * view = GEM_HASH_VIEW(object); if (view->items) { g_hash_table_destroy(view->items); view->items = NULL; } (*GTK_OBJECT_CLASS(parent_class)->destroy)(object); return;}static void gem_hash_view_show_cell_func (gpointer key, gpointer value, gpointer user_data){ GemHashViewCell * cell = (GemHashViewCell *)value; if (gem_hash_view_cell_get_visible(cell) == FALSE) { gtk_widget_hide_all(GTK_WIDGET(cell)); } return;}static voidgem_hash_view_show_cb (GtkWidget *widget, gpointer user_data){ GemHashView * view = GEM_HASH_VIEW(widget); if (g_hash_table_size(view->items) > 0) { g_hash_table_foreach(view->items, (GHFunc)gem_hash_view_show_cell_func, NULL); } if (TRUE) { GemHashViewCell * cell = gem_hash_view_get_item(view, view->focused_item); if (cell && gem_hash_view_cell_get_visible(cell)) { gem_hash_view_cell_set_focus(cell); } } return;}static void gem_hash_view_hide_cell_func (gpointer key, gpointer value, gpointer user_data){ GemHashViewCell * cell = (GemHashViewCell *)value; gem_hash_view_cell_set_value(cell, ""); return;}static voidgem_hash_view_hide_cb (GtkWidget *widget, gpointer user_data){ GemHashView * view = GEM_HASH_VIEW(widget); if (g_hash_table_size(view->items) > 0) { g_hash_table_foreach(view->items, (GHFunc)gem_hash_view_hide_cell_func, NULL); } return;} static voidgem_hash_view_init (GemHashView * view){ g_print("%s(): entering...\n",__FUNCTION__); view->layout = gtk_vbox_new(FALSE, 0); gem_scrolled_window_add_with_viewport(GEM_SCROLLED_WINDOW(view), GTK_CONTAINER(view->layout)); if (TRUE) { GtkWidget * viewport = NULL; GdkColor white_bg = {0, 0xFFFF, 0xFFFF, 0xFFFF}; viewport = gem_scrolled_window_get_viewport(GEM_SCROLLED_WINDOW(view)); if (viewport) { gtk_widget_modify_bg(GTK_WIDGET(viewport), GTK_STATE_NORMAL, &white_bg); } } view->items = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL); view->editable = TRUE; view->status = GEM_HV_STATUS_SAVE; view->focused_item = -1; g_signal_connect(G_OBJECT(view), "show", G_CALLBACK(gem_hash_view_show_cb), NULL); g_signal_connect(G_OBJECT(view), "hide", G_CALLBACK(gem_hash_view_hide_cb), NULL); return;}GtkWidget *gem_hash_view_new (void){ return gtk_widget_new(GEM_TYPE_HASH_VIEW, NULL);}void gem_hash_view_set_item (GemHashView *view, gint id, GemHashViewCell *cell){ gint * key = NULL; key = g_new0(gint , 1); *key = id; g_hash_table_replace(view->items, key, (gpointer)cell); return;}GemHashViewCell *gem_hash_view_get_item (GemHashView *view, gint id){ return GEM_HASH_VIEW_CELL(g_hash_table_lookup(view->items, &id));}voidgem_hash_view_set_value (GemHashView *view, gint id, const gchar *value){ GemHashViewCell * cell = NULL; cell = gem_hash_view_get_item(view, id);/* g_print("%s(): id = %d, cell = 0x%08x\n", __FUNCTION__, id, (guint32)cell); g_print("%s() :value = %d\n",__FUNCTION__,value);*/ if (cell == NULL) { return; } gem_hash_view_cell_set_value(cell, value); return;}G_CONST_RETURN gchar *gem_hash_view_get_value (GemHashView *view, gint id){ GemHashViewCell * cell = NULL; cell = gem_hash_view_get_item(view, id); if (cell == NULL) { return NULL; } return gem_hash_view_cell_get_value(cell);}static void gem_hash_view_set_editable_cell_func (gpointer key, gpointer value, gpointer user_data){ GemHashView * view = GEM_HASH_VIEW(user_data); GemHashViewCell * cell = (GemHashViewCell *)value;/* g_print("%s(): %s %s Edit\n", __FUNCTION__, view->editable ? "Enable" : "Disable", G_OBJECT_TYPE_NAME(cell));*/ gem_hash_view_cell_set_editable(cell, view->editable); return;}voidgem_hash_view_set_editable (GemHashView *view, gboolean editable){ view->editable = editable; if (g_hash_table_size(view->items) > 0) { g_hash_table_foreach(view->items, (GHFunc)gem_hash_view_set_editable_cell_func, (gpointer)view); } return;}gbooleangem_hash_view_get_editable (GemHashView * view){ return view->editable;}voidgem_hash_view_set_focus_item (GemHashView *view, gint id){ view->focused_item = id; return;}gint gem_hash_view_get_focus_item (GemHashView * view){ return view->focused_item;}/*vi:ts=2:nowrap:ai:expandtab */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -