📄 gemapptest.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 <gtk/gtk.h>#include <gem.h>#define GEMAPPTEST_IAC_SERVICE "gem.apptest.service"#define GEMAPPTEST_IAC_OBJECT "/gem/apptest/service"#define GEMAPPTEST_IAC_INTERFACE "gem.apptest.service.interface"#define GEMAPPTEST_IAC_METHOD_W1 "demo_windoe_type_1"#define GEMAPPTEST_IAC_METHOD_W2 "demo_windoe_type_2"#define GEMAPPTEST_IAC_METHOD_W3 "demo_windoe_type_3"typedef enum { DEMO_WINDOW_TYPE_1 = 1, DEMO_WINDOW_TYPE_2, DEMO_WINDOW_TYPE_3, NUM_DEMO_WINDOWS,} DemoWindowType;GtkWidget * demo_windows[NUM_DEMO_WINDOWS] = { NULL, NULL, NULL,};static GtkWidget * create_demo_window (DemoWindowType type, gboolean main);static voidpop_button_clicked_cb (GtkButton *button, gpointer user_data){ GemApplication * app = NULL; GtkWidget * window = NULL; DemoWindowType type = (DemoWindowType)GPOINTER_TO_INT(user_data); window = create_demo_window(type, FALSE); app = gem_application_get_instance(); gem_application_add_window(app, window); gtk_widget_show_all(window); return;}static voidexit_button_clicked_cb (GtkButton *button, gpointer user_data){ GtkWidget * window = GTK_WIDGET(user_data);/* g_print("%s(): entering, 0x%08x\n", __FUNCTION__, (guint32)window);*/ gtk_widget_destroy(window); return;}static voidback_button_clicked_cb (GtkButton *button, gpointer user_data){ GtkWidget * window = GTK_WIDGET(user_data); gtk_widget_hide_all(window); return;}static GtkWidget *create_demo_window (DemoWindowType type, gboolean main){ GtkWidget * window = NULL; GtkWidget * button = NULL; GtkWidget * vbox = NULL; if (demo_windows[type] == NULL) { window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_print("%s(): DemoWindow [%d, 0x%08x]\n", __FUNCTION__, type, (guint32)window); vbox = gtk_vbox_new(TRUE, 0); button = gtk_button_new_with_label("Pop One"); if (TRUE) { DemoWindowType next_type; next_type = type + 1; if (next_type < NUM_DEMO_WINDOWS) { g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(pop_button_clicked_cb), GINT_TO_POINTER(next_type)); } else { gtk_widget_set_sensitive(button, FALSE); } } gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 0); if (main) { button = gtk_button_new_with_label("Exit"); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(exit_button_clicked_cb), (gpointer)window); } else { button = gtk_button_new_with_label("Back"); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(back_button_clicked_cb), (gpointer)window); } gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); demo_windows[type] = window; } else { window = demo_windows[type]; } return window;}static iac_return_t interface_handler (const gchar *interface, const gchar *method, iac_arguments_t *args, iac_arguments_t *retval, gpointer user_data){ iac_return_t ret = IAC_OK; GtkWidget * window = NULL; g_print("%s(): interface :%s\n", __FUNCTION__, interface); g_print("%s(): method :%s\n", __FUNCTION__, method); iac_arguments_print(args); if (g_strcasecmp(method, GEMAPPTEST_IAC_METHOD_W1) == 0) { window = create_demo_window(DEMO_WINDOW_TYPE_1, TRUE); g_print("%s(): create demo window %d, [0x%08x]\n", __FUNCTION__, DEMO_WINDOW_TYPE_1, (guint32)window); } else if (g_strcasecmp(method, GEMAPPTEST_IAC_METHOD_W2) == 0) { window = create_demo_window(DEMO_WINDOW_TYPE_2, FALSE); g_print("%s(): create demo window %d, [0x%08x]\n", __FUNCTION__, DEMO_WINDOW_TYPE_2, (guint32)window); } else if (g_strcasecmp(method, GEMAPPTEST_IAC_METHOD_W3) == 0) { window = create_demo_window(DEMO_WINDOW_TYPE_3, FALSE); g_print("%s(): create demo window %d, [0x%08x]\n", __FUNCTION__, DEMO_WINDOW_TYPE_3, (guint32)window); } else { ret = IAC_ERROR; } if (ret != IAC_ERROR) { GemApplication *app = NULL; app = gem_application_get_instance(); gem_application_add_window(app, window); gtk_widget_show_all(window); gtk_window_present(GTK_WINDOW(window)); } return ret;}static voidstart_iac_service (void){ GemApplication * app = gem_application_get_instance(); iac_context_t * context = NULL; context = gem_application_get_iac_context(app); if (context) { iac_register_service(context, GEMAPPTEST_IAC_SERVICE); iac_register_listener(context, GEMAPPTEST_IAC_OBJECT, GEMAPPTEST_IAC_INTERFACE, interface_handler, NULL); } return;}int main (int argc, char * argv[]){ GemApplication * app = NULL; GtkWidget * main_window = NULL; gtk_init(&argc, &argv); app = gem_application_get_instance(); main_window = create_demo_window(DEMO_WINDOW_TYPE_1, TRUE); gem_application_set_main_window(app, main_window); start_iac_service(); gem_application_run(app); gem_application_destroy(app); g_print("%s(): final leave\n", __FUNCTION__); return EXIT_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -