📄 gemtreeview.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 <libintl.h>#include <ctype.h>#include <string.h>#include <gtk/gtk.h>#include <gdk/gdkkeysyms.h>#include <gdk/gdkx.h>#include <gtkautoscrolledwindow.h>#include "gem_internaltreeview.h"#include "gemtreeview.h"#include "gemresource.h"#include "gemenv.h"#define _(x) gettext(x)static void gem_tree_view_class_init (GemTreeViewClass *klass);static void gem_tree_view_init (GemTreeView *window);GtkWidget *gem_tree_view_get_search_box (GemTreeView * view);//static gboolean gem_tree_view_key_press_event_cb (GtkWidget *widget, GdkEventKey *event);static gboolean searchentry_visible = TRUE;GTypegem_tree_view_get_type (void){ static GType treeview_type = 0; if (!treeview_type) { static const GTypeInfo treeview_info = { sizeof (GemTreeViewClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) gem_tree_view_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (GemTreeView), 0, /* n_preallocs */ (GInstanceInitFunc) gem_tree_view_init, }; treeview_type = g_type_register_static(GTK_TYPE_FRAME, "GemTreeView", &treeview_info, 0); } return treeview_type;}static voidgem_tree_view_class_init (GemTreeViewClass * klass){// widget_class->key_press_event = gem_tree_view_key_press_event_cb; return;}static gint gem_tree_view_sort_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data){ GemTreeView * view = (GemTreeView *)user_data; gint ret = 0; gchar * str1 = NULL; gchar * str2 = NULL; if (view->search_column == -1) { return 0; } gtk_tree_model_get(model, a, view->search_column, &str1, -1); gtk_tree_model_get(model, b, view->search_column, &str2, -1); if (str1 == NULL && str2 == NULL) { ret = 0; } else if (str1 == NULL || str2 == NULL) { ret = (str1 == NULL) ? -1 : 1; } else if (g_strcasecmp (str1,"All")==0 ) { ret = -1; g_print("%s() LINE(%d) ret(%d)\n",__FUNCTION__,__LINE__,ret); } else if (g_strcasecmp (str2,"All")==0 ) { ret = 1; g_print("%s() LINE(%d) ret(%d)\n",__FUNCTION__,__LINE__,ret); } else { ret = g_utf8_collate(str1, str2); } g_free(str1); g_free(str2); return ret;}static gboolean gem_tree_view_entry_key_press_event_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data){ if (event->keyval == GDK_Return) { return FALSE; } else if (event->keyval == GDK_Right) { return FALSE; } else if (event->keyval == GDK_Left) { return FALSE; } return FALSE;}static void gem_tree_view_entry_changed_cb (GtkEditable *editable, gpointer user_data){ GemTreeView * view = (GemTreeView *)user_data; if (TRUE) { GtkTreeView * tree = NULL; GtkTreeModel * model = NULL; tree = (GtkTreeView *)view->treeview; model = gtk_tree_view_get_model(tree); if (tree && model) { GtkTreeIter iter; gchar * string = NULL; string = g_utf8_strup(gtk_entry_get_text(GTK_ENTRY(editable)), -1); g_strstrip(string); if (gtk_tree_model_iter_n_children(model, NULL) > 0 && gtk_tree_model_get_iter_first(model, &iter)) { do { gchar * str = NULL; gchar * caseless = NULL; gtk_tree_model_get(model, &iter, view->search_column, &str, -1); caseless = g_utf8_strup(str, -1); g_print("%s(): caseless = %s, string = %s\n", __FUNCTION__, caseless, string); if (g_strstr_len(caseless, strlen(caseless), string) == caseless) { GtkTreePath * path = NULL; path = gtk_tree_model_get_path(model, &iter); if (path) { gtk_tree_view_set_cursor(tree, path, NULL, FALSE); } gtk_tree_path_free(path); break; } g_free(caseless); g_free(str); } while (gtk_tree_model_iter_next(model, &iter)); } // g_object_unref(model); g_free(string); } } return;}static GdkFilterReturngem_tree_view_key_press_snooper (GdkXEvent *xevent, GdkEvent *event, GemTreeView *view){ GdkFilterReturn ret = GDK_FILTER_CONTINUE; XEvent *ev = (XEvent*)xevent; if (ev->type != KeyPress) { return ret; } if (TRUE) { Window toplevel_window; int revert = RevertToNone; XGetInputFocus(GDK_DISPLAY(), &toplevel_window, &revert);/* g_print("%s(): w(%d), toplevel_window(%d)\n", __FUNCTION__, (guint32)GDK_WINDOW_XID(GTK_WIDGET(sb)->window), (guint32)toplevel_window);*/ if (GDK_WINDOW_XID(GTK_WIDGET(view)->window) != toplevel_window) { return ret; } } if (XKeycodeToKeysym(GDK_DISPLAY(), ev->xkey.keycode, 0) == GDK_Up) { GtkTreeView * tree = NULL; GtkTreeModel * model = NULL; tree = (GtkTreeView *)view->treeview; model = gtk_tree_view_get_model(tree); if (tree && model) { GtkTreePath * path = NULL; gtk_tree_view_get_cursor(GTK_TREE_VIEW(tree), &path, NULL); // g_print("%s(): Up curr = %s tree = 0x%08x \n", __FUNCTION__, gtk_tree_path_to_string(path),GTK_TREE_VIEW(tree)); if (path) { GtkTreePath * p; gint count; count = gtk_tree_model_iter_n_children(model, NULL); p = gtk_tree_path_copy(path); gtk_tree_path_prev(path); g_print("%s(): Up prev = %s\n", __FUNCTION__, gtk_tree_path_to_string(path)); if (!gtk_tree_path_compare(path, p)) { path = gtk_tree_path_new_from_indices(count - 1, -1); } gtk_tree_path_free(p); gtk_tree_view_set_cursor(GTK_TREE_VIEW(tree), path, NULL, FALSE); gtk_tree_path_free(path); } // g_object_unref(model); ret = GDK_FILTER_REMOVE; } } else if (XKeycodeToKeysym(GDK_DISPLAY(), ev->xkey.keycode, 0) == GDK_Down) { GtkTreeView * tree = NULL; GtkTreeModel * model = NULL; tree = (GtkTreeView *)view->treeview; model = gtk_tree_view_get_model(tree); if (tree && model) { GtkTreePath * path = NULL; gtk_tree_view_get_cursor(GTK_TREE_VIEW(tree), &path, NULL); // g_print("%s(): Down curr = %s\n", __FUNCTION__, gtk_tree_path_to_string(path)); if (path) { GtkTreePath * p; gint count; count = gtk_tree_model_iter_n_children(model, NULL); p = gtk_tree_path_new_from_indices(count, -1); gtk_tree_path_next(path);// g_print("%s(): Down next = %s\n", __FUNCTION__, gtk_tree_path_to_string(path)); if (!gtk_tree_path_compare(path, p)) { path = gtk_tree_path_new_first(); } gtk_tree_path_free(p); } else { path = gtk_tree_path_new_first(); } gtk_tree_view_set_cursor(GTK_TREE_VIEW(tree), path, NULL, FALSE);// g_object_unref(model); ret = GDK_FILTER_REMOVE; } } else if (XKeycodeToKeysym(GDK_DISPLAY(), ev->xkey.keycode, 0) == GDK_Left || XKeycodeToKeysym(GDK_DISPLAY(), ev->xkey.keycode, 0) == GDK_Right) { GdkEvent *new_event; new_event = gdk_event_copy ((GdkEvent *) event); ((GdkEventKey *) new_event)->window = GTK_WIDGET(view)->window; gtk_widget_event(GTK_WIDGET(view), new_event); ret = GDK_FILTER_REMOVE; } else if (XKeycodeToKeysym(GDK_DISPLAY(), ev->xkey.keycode, 0) == GDK_Return || XKeycodeToKeysym(GDK_DISPLAY(), ev->xkey.keycode, 0) == GDK_space) { if (!GTK_WIDGET_HAS_FOCUS(view->search_entry)) { GdkEvent *new_event;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -