📄 abookitemsview.c
字号:
/* addressbook - Address book *abookitemsview.c - * *Authors: YE Nan <nan.ye@orange-ftgroup.com> * ZHAO Liangjing <liangjing.zhao@orange-ftgroup.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 "abookitemsview.h"#include "abookviewcellstd.h"static void ab_items_view_class_init (ABItemsViewClass *klass);static void ab_items_view_init (ABItemsView *view);static void ab_items_view_destroy (GtkObject *object);static GtkAutoScrolledWindowClass *parent_class = NULL;GTypeab_items_view_get_type (void){ static GType view_type = 0; if (!view_type) { static const GTypeInfo view_info = { sizeof (ABItemsViewClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) ab_items_view_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (ABItemsView), 0, /* n_preallocs */ (GInstanceInitFunc) ab_items_view_init, NULL, }; view_type = g_type_register_static (GTK_TYPE_AUTO_SCROLLED_WINDOW, "ABItemsView", &view_info, 0); } return view_type;}static voidab_items_view_class_init (ABItemsViewClass *klass){ GtkObjectClass *object_class; object_class = (GtkObjectClass *) klass; parent_class = g_type_class_peek_parent (klass); object_class->destroy = ab_items_view_destroy; return;}static voidab_items_view_destroy (GtkObject *object){ ABItemsView *view = AB_ITEMS_VIEW (object); if (view->items) { g_hash_table_destroy (view->items); view->items = NULL; } (*GTK_OBJECT_CLASS (parent_class)->destroy) (object); return;}static voidab_items_view_show_cell_func (gpointer key, gpointer value, gpointer user_data){ ABookViewCell *cell = (ABookViewCell *) value; if (abook_view_cell_get_visualizable (cell) == FALSE) { gtk_widget_hide_all (GTK_WIDGET (cell)); } return;}static voidab_items_view_show_cb (GtkWidget *widget, gpointer user_data){ ABItemsView *view = AB_ITEMS_VIEW (widget); if (g_hash_table_size (view->items) > 0) { g_hash_table_foreach (view->items, (GHFunc) ab_items_view_show_cell_func, NULL); } if (TRUE) { ABookViewCell *cell = ab_items_view_get_item (view, view->focused_item); if (cell->visualizable) { abook_view_cell_set_focus (cell); } } return;}static voidab_items_view_hide_cell_func (gpointer key, gpointer value, gpointer user_data){ ABookViewCell *cell = (ABookViewCell *) value; abook_view_cell_set_value (cell, ""); return;}static voidab_items_view_hide_cb (GtkWidget *widget, gpointer user_data){ ABItemsView *view = AB_ITEMS_VIEW (widget); if (g_hash_table_size (view->items) > 0) { g_hash_table_foreach (view->items, (GHFunc) ab_items_view_hide_cell_func, NULL); } return;}static voidab_items_view_init (ABItemsView *view){ GtkWidget *cell = NULL; view->layout = gtk_vbox_new (FALSE, 0); gtk_auto_scrolled_window_add_with_viewport (GTK_AUTO_SCROLLED_WINDOW (view), view->layout); if (TRUE) { GtkWidget *viewport = NULL; GdkColor white_bg = { 0, 0xFFFF, 0xFFFF, 0xFFFF }; viewport = gtk_auto_scrolled_window_get_viewport (GTK_AUTO_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); /* UID Cell */ cell = abook_view_cell_std_new ("<span color=\"Blue\">UUID</span>"); abook_view_cell_set_visualizable (ABOOK_VIEW_CELL (cell), FALSE); ab_items_view_set_item (AB_ITEMS_VIEW (view), AB_IV_UID, ABOOK_VIEW_CELL (cell)); gtk_box_pack_start (GTK_BOX (view->layout), cell, FALSE, FALSE, 5); view->editable = TRUE; view->status = AB_IV_STATUS_CANCEL; view->focused_item = AB_IV_UID; g_signal_connect (G_OBJECT (view), "show", G_CALLBACK (ab_items_view_show_cb), NULL); g_signal_connect (G_OBJECT (view), "hide", G_CALLBACK (ab_items_view_hide_cb), NULL); return;}GtkWidget *ab_items_view_new (void){ return gtk_widget_new (AB_TYPE_ITEMS_VIEW, NULL);}voidab_items_view_set_item (ABItemsView *view, ABItemsViewID id, ABookViewCell *cell){ ABItemsViewID *key = NULL; key = g_new0 (ABItemsViewID, 1); *key = id; g_hash_table_replace (view->items, key, (gpointer) cell); return;}ABookViewCell *ab_items_view_get_item (ABItemsView *view, ABItemsViewID id){ return ABOOK_VIEW_CELL (g_hash_table_lookup (view->items, &id));}voidab_items_view_set_value (ABItemsView *view, ABItemsViewID id, const gchar *value){ ABookViewCell *cell = NULL; cell = ab_items_view_get_item (view, id);/* g_print("%s(): id = %d, cell = 0x%08x\n", __FUNCTION__, id, (guint32)cell);*/ if (cell == NULL) { return; } abook_view_cell_set_value (cell, value); return;}G_CONST_RETURN gchar *ab_items_view_get_value (ABItemsView *view, ABItemsViewID id){ ABookViewCell *cell = NULL; cell = ab_items_view_get_item (view, id); if (cell == NULL) { return NULL; } return abook_view_cell_get_value (cell);}static voidab_items_view_set_editable_cell_func (gpointer key, gpointer value, gpointer user_data){ ABItemsView *view = AB_ITEMS_VIEW (user_data); ABookViewCell *cell = (ABookViewCell *) value; abook_view_cell_set_editable (cell, view->editable); return;}voidab_items_view_set_editable (ABItemsView *view, gboolean editable){ view->editable = editable; if (g_hash_table_size (view->items) > 0) { g_hash_table_foreach (view->items, (GHFunc) ab_items_view_set_editable_cell_func, (gpointer) view); } return;}gbooleanab_items_view_get_editable (ABItemsView *view){ return view->editable;}voidab_items_view_set_focus_item (ABItemsView *view, ABItemsViewID id){ view->focused_item = id; return;}ABItemsViewIDab_items_view_get_focus_item (ABItemsView *view){ return view->focused_item;}/* vi:ts=2:nowrap:ai:expandtab*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -