📄 gemapplication.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 <X11/Xatom.h>#include <iac.h>#include "gemapplication.h"#include "gem_internal.h"enum { APP_QUIT, LAST_SIGNAL};static guint application_signals[LAST_SIGNAL];typedef struct _GemAppWinEntry { GtkWidget *window; GtkWidget *under; GtkWidget *above;} GemAppWinEntry;typedef struct _GemApplicationPriv GemApplicationPriv;struct _GemApplicationPriv{ GSList *windows; GtkWidget *main_window; iac_context_t *iac_context;};#define GEM_APPLICATION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ GEM_TYPE_APPLICATION, \ GemApplicationPriv));static void gem_application_init (GemApplication *app);static void gem_application_finalize (GObject *object);static void gem_application_class_init (GemApplicationClass *klass);static void gem_application_window_destroy_cb (GtkObject *object, gpointer user_data);static void gem_application_window_show_cb (GtkWidget *widget, gpointer user_data);static void gem_application_window_hide_cb (GtkWidget *widget, gpointer user_data);static void gem_application_list_windows (GemApplication *app);static GObjectClass * parent_class = NULL;GTypegem_application_get_type (void){ static GType app_type = 0; if (!app_type) { static const GTypeInfo app_info = { sizeof(GemApplicationClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) gem_application_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof(GemApplication), 0, /* n_preallocs */ (GInstanceInitFunc) gem_application_init, }; app_type = g_type_register_static(G_TYPE_OBJECT, "GemApplication", &app_info, 0); } return app_type;}static voidgem_application_class_init (GemApplicationClass * klass){ GObjectClass *object_class = G_OBJECT_CLASS(klass); parent_class = g_type_class_peek_parent (klass); g_type_class_add_private(klass, sizeof(GemApplicationPriv)); object_class->finalize = gem_application_finalize; klass->app_quit = NULL; /* Action signals */ application_signals[APP_QUIT] = g_signal_new("app_quit", G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(GemApplicationClass, app_quit), NULL, NULL, gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); return;}static voidgem_application_destroy_window (gpointer data, gpointer user_data){ GemApplication * app = GEM_APPLICATION(user_data); GemApplicationPriv * priv = GEM_APPLICATION_GET_PRIVATE(app); GemAppWinEntry * entry = (GemAppWinEntry *)data;/* g_print("%s(): entry 0x%08x\n", __FUNCTION__, (guint32)entry);*/ if (entry) { GtkWidget * widget = entry->window; g_object_disconnect(G_OBJECT(widget), "any_signal::destroy", G_CALLBACK(gem_application_window_destroy_cb), (gpointer)app, NULL); g_object_disconnect(G_OBJECT(widget), "any_signal::show", G_CALLBACK(gem_application_window_show_cb), (gpointer)entry, NULL); g_object_disconnect(G_OBJECT(widget), "any_signal::hide", G_CALLBACK(gem_application_window_hide_cb), (gpointer)entry, NULL); gtk_widget_destroy(widget); priv->windows = g_slist_remove(priv->windows, (gconstpointer)entry); g_free(entry); } return;}static voidgem_application_finalize (GObject * object){ GemApplication * app = GEM_APPLICATION(object); GemApplicationPriv * priv = GEM_APPLICATION_GET_PRIVATE(app); if (priv->windows) { /* * remove and destroy all window in * application list */ g_slist_foreach(priv->windows, gem_application_destroy_window, (gpointer)app); g_slist_free(priv->windows); priv->windows = NULL; } priv->main_window = NULL; if (priv->iac_context) { iac_deinitialize(priv->iac_context); priv->iac_context = NULL; } G_OBJECT_CLASS(parent_class)->finalize(object); return;}static voidgem_application_init (GemApplication * app){ GemApplicationPriv *priv = GEM_APPLICATION_GET_PRIVATE(app); priv->windows = NULL; priv->main_window = NULL; priv->iac_context = NULL; return;}/** * gem_application_get_instance: * * Returns a #GemApplication instance of current process. * * Return value: Returns the #GemApplication for the current process. * The object is created on the first call. **/GemApplication *gem_application_get_instance (void){ static GemApplication * application = NULL; if (!application) { if (gem_initialize() == FALSE) { g_print("%s(): gem_widget_init() failure\n", __FUNCTION__); return NULL; } application = g_object_new(GEM_TYPE_APPLICATION, NULL); } return application;}static voidgem_application_window_destroy_cb (GtkObject *object, gpointer user_data){ GemApplication * app = GEM_APPLICATION(user_data); GemApplicationPriv *priv = GEM_APPLICATION_GET_PRIVATE(app); /* * if widget is destroyed, we should remove it from list. * And if it is main window of application, it leads a * quit from main loop */ gem_application_remove_window(app, GTK_WIDGET(object)); if (GTK_WIDGET(object) == priv->main_window) { gem_application_quit(app); } return;}static voidgem_application_window_show_cb (GtkWidget *widget, gpointer user_data){ GemApplication * app = gem_application_get_instance(); GemApplicationPriv *priv = GEM_APPLICATION_GET_PRIVATE(app); GemAppWinEntry * entry = (GemAppWinEntry *)user_data; entry->under = NULL; entry->above = NULL; if (TRUE) { GSList *iter = NULL; for (iter = priv->windows; iter; iter = g_slist_next(iter)) { GemAppWinEntry * tmp = (GemAppWinEntry *)iter->data; GtkWidget * window = tmp->window; if (gtk_window_is_active(GTK_WINDOW(window))) { g_print("%s(): ACTIVE WINDOW: 0x%08x\n", __FUNCTION__,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -