📄 gemnotification.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 <gtk/gtk.h>#include <gdk/gdkkeysyms.h>#include <gemnotification.h>#define INNER_SPACE 10static void gem_notification_class_init (GemNotificationClass *klass);static void gem_notification_init (GemNotification *window);static void gem_notification_destroy (GtkObject *object);static GtkWindowClass * parent_class = NULL;GTypegem_notification_get_type (void){ static GType notification_type = 0; if (!notification_type) { static const GTypeInfo notification_info = { sizeof (GemNotificationClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) gem_notification_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (GemNotification), 0, /* n_preallocs */ (GInstanceInitFunc) gem_notification_init, }; notification_type = g_type_register_static(GTK_TYPE_WINDOW, "GemNotification", ¬ification_info, 0); } return notification_type;}static voidgem_notification_class_init (GemNotificationClass * klass){ GtkObjectClass *object_class; object_class = (GtkObjectClass*) klass; parent_class = g_type_class_peek_parent (klass); object_class->destroy = gem_notification_destroy; return;}static voidgem_notification_destroy (GtkObject *object){ GemNotification *notification = GEM_NOTIFICATION(object); if (notification->timeout) { g_source_remove(notification->timeout); notification->timeout = 0; } (* GTK_OBJECT_CLASS(parent_class)->destroy)(object); return;}static gbooleangem_notification_expose (GtkWidget *widget, GdkEventExpose *event, gpointer user_data){ gint x, y; gint w, h; GdkGC * gc = NULL; GdkColor color; gint i; 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("DarkOrange", &color); gdk_gc_set_rgb_fg_color(gc, &color); for (i = 0; i < INNER_SPACE / 4 ; i++) { gdk_draw_rectangle(widget->window, gc, FALSE, x + i + 1, y + i + 1, w - (i + 1) * 2 - 1, h - (i + 1) * 2 - 1); } gdk_gc_unref(gc); return FALSE;}static voidgem_notification_show (GtkWidget *widget, gpointer user_data){ GemNotification * window = GEM_NOTIFICATION(widget); if (window->hide_text) { gtk_widget_hide(window->text_nc); } if (window->hide_graphic) { gtk_widget_hide(window->graphic_nc); } if (window->hide_progress) { gtk_widget_hide(window->progress_nc); } return;}static gbooleangem_notification_progress_bar_timeout (GemNotification * window){ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(window->progress_nc), window->fraction); return TRUE;}static voidgem_notification_init (GemNotification * window){ GtkWidget * vbox = NULL; GtkWidget * hbox = NULL; window->text_nc = gtk_label_new(NULL); window->graphic_nc = gtk_image_new(); window->progress_nc = gtk_progress_bar_new(); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), window->text_nc, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), window->graphic_nc, FALSE, FALSE, 0); vbox = gtk_vbox_new(FALSE, 10); gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), window->progress_nc, TRUE, TRUE, 0);// gtk_container_set_border_width(GTK_CONTAINER(hbox), 10); gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); if (TRUE) { GdkColor color; gdk_color_parse("white", &color); gtk_widget_modify_bg(GTK_WIDGET(window), GTK_STATE_NORMAL, &color); } gtk_container_add(GTK_CONTAINER(window), vbox); g_signal_connect(G_OBJECT(vbox), "expose-event", G_CALLBACK(gem_notification_expose), NULL); g_signal_connect(G_OBJECT(window), "show", G_CALLBACK(gem_notification_show), NULL); window->fraction = 0.0; window->timeout = g_timeout_add(100, (GSourceFunc)gem_notification_progress_bar_timeout, (gpointer)window); window->hide_text = FALSE; window->hide_graphic = FALSE; window->hide_progress = FALSE; return;}GtkWidget*gem_notification_new (void){ return g_object_new (GEM_TYPE_NOTIFICATION, "type", GTK_WINDOW_POPUP, "accept-focus", TRUE, NULL);}voidgem_notification_set_image_from_file(GemNotification * window, const gchar * fname){ GtkRequisition req; gtk_image_set_from_file(GTK_IMAGE(window->graphic_nc), fname); gtk_widget_size_request(window->graphic_nc, &req); g_print("%s(): [%03d, %03d]\n", __FUNCTION__, req.width, req.height); return;}voidgem_notification_set_text(GemNotification * window, const gchar * text){ gtk_label_set_text(GTK_LABEL(window->text_nc), text); return;}voidgem_notification_set_progross_fraction(GemNotification * window, gdouble fraction){// g_print("%s(): entering, fraction = %f\n", __FUNCTION__, fraction); if (window->fraction != fraction) { window->fraction = fraction; } return;}void gem_notification_hide_text (GemNotification *window){ window->hide_text = TRUE; return;}voidgem_notification_hide_graphic (GemNotification *window){ window->hide_graphic = TRUE; return;}voidgem_notification_hide_progressbar (GemNotification *window){ window->hide_progress = TRUE; return;}/*vi:ts=2:nowrap:ai:expandtab */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -