📄 abookviewcellstd.c
字号:
/* addressbook - Address book *abookviewcellstd.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 <stdio.h>#include <stdlib.h>#include <string.h>#include <glib.h>#include <gtk/gtk.h>#include <gdk/gdkkeysyms.h>#include "abookviewcell.h"#include "abookviewcellstd.h"static void abook_view_cell_std_class_init (ABookViewCellStdClass *klass);static void abook_view_cell_std_init (ABookViewCellStd *view);static void abook_view_cell_std_destroy (GtkObject *object);static void abook_view_cell_std_set_value (ABookViewCell *cell, const gchar *val);static G_CONST_RETURN gchar *abook_view_cell_std_get_value (ABookViewCell * cell);static void abook_view_cell_std_set_editable (ABookViewCell *cell, gboolean editable);static void abook_view_cell_std_set_focus (ABookViewCell *cell);static ABookViewCellClass *parent_class = NULL;GTypeabook_view_cell_std_get_type (void){ static GType cell_type = 0; if (!cell_type) { static const GTypeInfo cell_info = { sizeof (ABookViewCellStdClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) abook_view_cell_std_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (ABookViewCellStd), 0, /* n_preallocs */ (GInstanceInitFunc) abook_view_cell_std_init, NULL, }; cell_type = g_type_register_static (ABOOK_TYPE_VIEW_CELL, "ABookViewCellStd", &cell_info, 0); } return cell_type;}static voidabook_view_cell_std_class_init (ABookViewCellStdClass *klass){ GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); parent_class = g_type_class_peek_parent (klass); object_class->destroy = abook_view_cell_std_destroy; ABOOK_VIEW_CELL_CLASS (klass)->set_value = abook_view_cell_std_set_value; ABOOK_VIEW_CELL_CLASS (klass)->get_value = abook_view_cell_std_get_value; ABOOK_VIEW_CELL_CLASS (klass)->set_editable = abook_view_cell_std_set_editable; ABOOK_VIEW_CELL_CLASS (klass)->set_focus = abook_view_cell_std_set_focus; return;}static voidabook_view_cell_std_destroy (GtkObject *object){ ABookViewCellStd *cell = ABOOK_VIEW_CELL_STD (object); if (cell->timer != -1) { g_source_remove (cell->timer); } gtk_widget_destroy (cell->info_window); (*GTK_OBJECT_CLASS (parent_class)->destroy) (object); return;}#define INFO_INNER_SPACE 5static gbooleanabook_view_cell_std_label_info_expose (GtkWidget *widget, GdkEventExpose *event, gpointer user_data){ gint x, y; gint w, h; GdkGC *gc = NULL; GdkColor color; gint i; g_print ("%s(): entring\n", __FUNCTION__); x = widget->allocation.x; y = widget->allocation.x; w = widget->allocation.width; h = widget->allocation.height; gc = gdk_gc_new (widget->window); if (gc == NULL) { g_print ("%s(): gc failure.\n", __FUNCTION__); return FALSE; } gdk_color_parse ("Black", &color); gdk_gc_set_rgb_fg_color (gc, &color); for (i = 0; i < INFO_INNER_SPACE / 4; i++) { gdk_draw_rectangle (widget->window, gc, FALSE, x + i, y + i, w - i *2 - 1, h - i *2 - 1); } gdk_gc_unref (gc); return FALSE;}static gbooleanabook_view_cell_std_label_info_show (gpointer user_data){ ABookViewCellStd *cell = ABOOK_VIEW_CELL_STD (user_data); const gchar *content = NULL; content = gtk_entry_get_text (GTK_ENTRY (cell->entry)); g_print ("%s(): content = %s\n", __FUNCTION__, content); if (strlen (content) > 0) { if (TRUE) { gint ox; gint oy; gint dx; gint dy; gint w; gint h; gdk_window_get_root_origin (cell->entry->window, &ox, &oy); g_print ("%s(): origin: ox = %03d, oy = %03d\n", __FUNCTION__, ox, oy); w = cell->entry->allocation.width; h = cell->entry->allocation.height; g_print ("%s(): origin: w = %03d, h = %03d\n", __FUNCTION__, w, h); gdk_window_get_position (cell->entry->window, &dx, &dy); g_print ("%s(): gdk_window: x = %03d, y = %03d\n", __FUNCTION__, dx, dy); gtk_widget_set_size_request (cell->info_window, w, -1); gtk_window_move (GTK_WINDOW (cell->info_window), ox + dx, oy + dy + h); } gtk_label_set_text (GTK_LABEL (cell->info_label), content);// gtk_widget_show_all(cell->info_window); } return FALSE;}static gbooleanabook_view_cell_std_label_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, gpointer user_data){ ABookViewCellStd *cell = ABOOK_VIEW_CELL_STD (user_data); g_print ("%s(): entering\n", __FUNCTION__); if (cell->timer != -1) { g_source_remove (cell->timer); } cell->timer = g_timeout_add (1 *1000, abook_view_cell_std_label_info_show, (gpointer) cell); return FALSE;}static gbooleanabook_view_cell_std_label_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, gpointer user_data){ ABookViewCellStd *cell = ABOOK_VIEW_CELL_STD (user_data); if (cell->timer != -1) { g_source_remove (cell->timer); } gtk_widget_hide_all (cell->info_window); return FALSE;}static gbooleanabook_view_cell_std_entry_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, gpointer user_data){ gtk_entry_set_has_frame (GTK_ENTRY (widget), TRUE); gtk_editable_select_region (GTK_EDITABLE (widget), 0, 0); gtk_editable_set_position (GTK_EDITABLE (widget), -1); return FALSE;}static gbooleanabook_view_cell_std_entry_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, gpointer user_data){ gtk_entry_set_has_frame (GTK_ENTRY (widget), FALSE); gtk_editable_select_region (GTK_EDITABLE (widget), 0, 0); return FALSE;}static voidabook_view_cell_std_init (ABookViewCellStd *cell){ cell->label = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (cell->label), 0, 0); gtk_label_set_markup (GTK_LABEL (cell->label), "unamed"); g_signal_connect (G_OBJECT (cell->label), "focus-in-event", G_CALLBACK (abook_view_cell_std_label_focus_in_cb), (gpointer) cell); g_signal_connect (G_OBJECT (cell->label), "focus-out-event", G_CALLBACK (abook_view_cell_std_label_focus_out_cb), (gpointer) cell); cell->entry = gtk_entry_new (); gtk_entry_set_has_frame (GTK_ENTRY (cell->entry), FALSE); g_signal_connect (G_OBJECT (cell->entry), "focus-in-event", G_CALLBACK (abook_view_cell_std_entry_focus_in_cb), NULL); g_signal_connect (G_OBJECT (cell->entry), "focus-out-event", G_CALLBACK (abook_view_cell_std_entry_focus_out_cb), NULL); gtk_widget_set_size_request (GTK_WIDGET (cell), -1, 60); gtk_box_pack_start (GTK_BOX (cell), cell->label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (cell), cell->entry, FALSE, FALSE, 0); cell->timer = -1; cell->info_window = gtk_window_new (GTK_WINDOW_POPUP); cell->info_label = gtk_label_new (""); if (TRUE) { GtkWidget *vbox = NULL; GdkColor color; vbox = gtk_vbox_new (0, FALSE); gtk_container_set_border_width (GTK_CONTAINER (vbox), INFO_INNER_SPACE); gdk_color_parse ("LightBlue", &color); gtk_widget_modify_bg (cell->info_window, GTK_STATE_NORMAL, &color); g_signal_connect (G_OBJECT (vbox), "expose-event", G_CALLBACK (abook_view_cell_std_label_info_expose), NULL); gtk_box_pack_start (GTK_BOX (vbox), cell->info_label, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (cell->info_window), vbox); } return;}GtkWidget *abook_view_cell_std_new (const gchar *label){ GtkWidget *widget = NULL; widget = gtk_widget_new (ABOOK_TYPE_VIEW_CELL_STD, NULL); if (label) { ABookViewCellStd *cell = ABOOK_VIEW_CELL_STD (widget); gtk_label_set_markup (GTK_LABEL (cell->label), label); } return widget;}static voidabook_view_cell_std_set_value (ABookViewCell *cell, const gchar *val){ ABookViewCellStd *cell_std = ABOOK_VIEW_CELL_STD (cell); gtk_entry_set_text (GTK_ENTRY (cell_std->entry), val); return;}static G_CONST_RETURN gchar *abook_view_cell_std_get_value (ABookViewCell *cell){ ABookViewCellStd *cell_std = ABOOK_VIEW_CELL_STD (cell); const gchar *value = NULL; value = gtk_entry_get_text (GTK_ENTRY (cell_std->entry)); return value;}static voidabook_view_cell_std_set_editable (ABookViewCell *cell, gboolean editable){ ABookViewCellStd *cell_std = ABOOK_VIEW_CELL_STD (cell); GtkWidget *entry = cell_std->entry; GtkWidget *label = cell_std->label; gtk_editable_set_editable (GTK_EDITABLE (entry), editable); if (editable) { GTK_WIDGET_UNSET_FLAGS (label, GTK_CAN_FOCUS); GTK_WIDGET_SET_FLAGS (entry, GTK_CAN_FOCUS); } else { GTK_WIDGET_SET_FLAGS (label, GTK_CAN_FOCUS); GTK_WIDGET_UNSET_FLAGS (entry, GTK_CAN_FOCUS); } return;}static voidabook_view_cell_std_set_focus (ABookViewCell *cell){ ABookViewCellStd *cell_std = ABOOK_VIEW_CELL_STD (cell); if (abook_view_cell_get_editable (cell)) { gtk_widget_grab_focus (cell_std->entry); } else { gtk_widget_grab_focus (cell_std->label); } return;}GtkWidget *abook_view_cell_std_get_entry (ABookViewCellStd *cell){ return cell->entry;}GtkWidget *abook_view_cell_std_get_label (ABookViewCellStd *cell){ return cell->label;}/* vi:ts=2:nowrap:ai:expandtab*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -