📄 gemhashviewcellstd.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 <stdio.h>#include <stdlib.h>#include <string.h>#include <gtk/gtk.h>#include <gemhashviewcell.h>#include <gemhashviewcellstd.h>static void gem_hash_view_cell_std_class_init (GemHashViewCellStdClass *klass);static void gem_hash_view_cell_std_init (GemHashViewCellStd *view);static void gem_hash_view_cell_std_finalize (GObject *object);static void gem_hash_view_cell_std_set_value (GemHashViewCell *cell, const gchar *val);static G_CONST_RETURN gchar * gem_hash_view_cell_std_get_value (GemHashViewCell *cell);static void gem_hash_view_cell_std_set_editable (GemHashViewCell *cell, gboolean editable);static void gem_hash_view_cell_std_set_focus (GemHashViewCell *cell);static GemHashViewCellClass * parent_class = NULL;GTypegem_hash_view_cell_std_get_type (void){ static GType cell_type = 0; if (!cell_type) { static const GTypeInfo cell_info = { sizeof (GemHashViewCellStdClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) gem_hash_view_cell_std_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (GemHashViewCellStd), 0, /* n_preallocs */ (GInstanceInitFunc) gem_hash_view_cell_std_init, NULL, }; cell_type = g_type_register_static(GEM_TYPE_HASH_VIEW_CELL, "GemHashViewCellStd", &cell_info, 0); } return cell_type;}static voidgem_hash_view_cell_std_class_init (GemHashViewCellStdClass * klass){ GObjectClass *object_class = G_OBJECT_CLASS(klass); GemHashViewCellClass *cell_class = GEM_HASH_VIEW_CELL_CLASS(klass); parent_class = g_type_class_peek_parent(klass); object_class->finalize = gem_hash_view_cell_std_finalize; cell_class->set_value = gem_hash_view_cell_std_set_value; cell_class->get_value = gem_hash_view_cell_std_get_value; cell_class->set_editable = gem_hash_view_cell_std_set_editable; cell_class->set_focus = gem_hash_view_cell_std_set_focus; return;}static voidgem_hash_view_cell_std_finalize (GObject *object){ G_OBJECT_CLASS(parent_class)->finalize(object); return;}static gboolean gem_hash_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); // gtk_widget_queue_draw(widget); return FALSE; }static gboolean gem_hash_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);// gtk_widget_queue_draw(widget); return FALSE; }static gbooleangem_hash_view_cell_std_entry_expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer user_data){ gint x, y; gint w, h; GdkGC * gc = NULL; GdkColor color; if (GTK_WIDGET_HAS_FOCUS(widget)) { return FALSE; } g_print("%s(): %s HAS_FOCUS (%s)\n", __FUNCTION__, gtk_widget_get_name(widget), GTK_WIDGET_HAS_FOCUS(widget) ? "TRUE" : "FALSE"); 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("CornflowerBlue", &color); gdk_color_parse("LightBlue", &color); gdk_gc_set_rgb_fg_color(gc, &color); gdk_gc_set_line_attributes(gc, 3, GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_MITER); gdk_draw_line(widget->window, gc, x, y + h - 1, x + w -1, y + h -1); gdk_gc_unref(gc); return TRUE;}static voidgem_hash_view_cell_std_init (GemHashViewCellStd * cell){ GtkWidget * vbox = NULL; GtkWidget * hbox = NULL; GtkWidget * alignment = NULL; 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"); 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(gem_hash_view_cell_std_entry_focus_in_cb), NULL); g_signal_connect(G_OBJECT(cell->entry), "focus-out-event", G_CALLBACK(gem_hash_view_cell_std_entry_focus_out_cb), NULL); /* g_signal_connect(G_OBJECT(cell->entry), "expose-event", G_CALLBACK(gem_hash_view_cell_std_entry_expose_cb), NULL);*//* hbox = gtk_hbox_new(FALSE, 0); alignment = gtk_alignment_new(0, 0, 0, 0); gtk_widget_set_size_request(alignment, 20, -1); gtk_box_pack_start(GTK_BOX(hbox), alignment, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), cell->entry, TRUE, TRUE, 0);*/ vbox = gtk_vbox_new(FALSE, 0); gtk_widget_set_size_request(GTK_WIDGET(vbox), -1, 60); gtk_box_pack_start(GTK_BOX(vbox), cell->label, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), cell->entry, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(cell), vbox); return;}/** * gem_hash_view_cell_std_new: * * @label: label text of #GemHashViewCellStd cell * * Creates a new #GemHashViewCellStd widget. **/GtkWidget *gem_hash_view_cell_std_new (const gchar * label){ GtkWidget * widget = NULL; widget = gtk_widget_new(GEM_TYPE_HASH_VIEW_CELL_STD, NULL); if (label) { GemHashViewCellStd * cell = GEM_HASH_VIEW_CELL_STD(widget); gtk_label_set_markup(GTK_LABEL(cell->label), label); } return widget;}static voidgem_hash_view_cell_std_set_value (GemHashViewCell *cell, const gchar *val){ GemHashViewCellStd * cell_std = GEM_HASH_VIEW_CELL_STD(cell); gtk_entry_set_text(GTK_ENTRY(cell_std->entry), val); return;}static G_CONST_RETURN gchar *gem_hash_view_cell_std_get_value (GemHashViewCell * cell){ GemHashViewCellStd * cell_std = GEM_HASH_VIEW_CELL_STD(cell); const gchar * value = NULL; value = gtk_entry_get_text(GTK_ENTRY(cell_std->entry)); return value;}static voidgem_hash_view_cell_std_set_editable (GemHashViewCell *cell, gboolean editable){ GemHashViewCellStd * cell_std = GEM_HASH_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 void gem_hash_view_cell_std_set_focus (GemHashViewCell *cell){ GemHashViewCellStd * cell_std = GEM_HASH_VIEW_CELL_STD(cell); if (gem_hash_view_cell_get_editable(cell)) { gtk_widget_grab_focus(cell_std->entry); } else { gtk_widget_grab_focus(cell_std->label); } return;}/** * gem_hash_view_cell_std_get_entry: * * @cell: a #GemHashViewCellStd instance * * Retrieves the #GtkEntry widget from the cell. **/GtkWidget *gem_hash_view_cell_std_get_entry (GemHashViewCellStd * cell){ return cell->entry;}/** * gem_hash_view_cell_std_get_label: * * @cell: a #GemHashViewCellStd instance * * Retrieves the #GtkLabel widget from the cell. **/GtkWidget *gem_hash_view_cell_std_get_label (GemHashViewCellStd * cell){ return cell->label;}/*vi:ts=2:nowrap:ai:expandtab */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -