home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / gdyntext / charmap_window.c next >
Encoding:
C/C++ Source or Header  |  2000-08-31  |  5.4 KB  |  172 lines

  1. /*
  2.  * GIMP Dynamic Text -- This is a plug-in for The GIMP 1.0
  3.  * Copyright (C) 1998,1999,2000 Marco Lamberto <lm@geocities.com>
  4.  * Web page: http://www.geocities.com/Tokyo/1474/gimp/
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  *
  20.  * $Id: charmap_window.c,v 1.6 2000/08/30 08:20:23 yosh Exp $
  21.  */
  22.  
  23. #include "config.h"
  24.  
  25. #include <stdio.h>
  26. #include <gtk/gtk.h>
  27.  
  28. #include "libgimp/stdplugins-intl.h"
  29.  
  30. #include "charmap.h"
  31. #include "charmap_window.h"
  32.  
  33.  
  34. static void charmap_window_class_init(CharMapWindowClass *class);
  35. static void charmap_window_init(CharMapWindow *mw);
  36. void on_charmap_char_selected(GtkWidget *widget, gpointer data);
  37.  
  38.  
  39. static GtkWindowClass *charmap_window_parent_class = NULL;
  40.  
  41.  
  42. guint charmap_window_get_type(void)
  43. {
  44.     static guint cmw_type = 0;
  45.  
  46.     if (!cmw_type) {
  47.         GtkTypeInfo cmw_info = {
  48.             "CharMapWindow",
  49.             sizeof(CharMapWindow),
  50.             sizeof(CharMapWindowClass),
  51.             (GtkClassInitFunc)charmap_window_class_init,
  52.             (GtkObjectInitFunc)charmap_window_init,
  53.             (GtkArgSetFunc)NULL,
  54.             (GtkArgGetFunc)NULL,
  55. #ifdef GTK_HAVE_FEATURES_1_1_12
  56.             (GtkClassInitFunc)NULL,
  57. #endif
  58.         };
  59.         cmw_type = gtk_type_unique(gtk_window_get_type(), &cmw_info);
  60.     }
  61.     return cmw_type;
  62. }
  63.  
  64.  
  65. static void charmap_window_class_init(CharMapWindowClass *klass)
  66. {
  67.     GtkObjectClass *object_class;
  68.  
  69.     object_class = (GtkObjectClass *)klass;
  70.     charmap_window_parent_class = gtk_type_class(gtk_window_get_type());
  71. }
  72.  
  73.  
  74. static void charmap_window_init(CharMapWindow *cmw)
  75. {
  76.     GtkWidget *vbox;
  77.     GtkWidget *hbox1;
  78.     GtkWidget *hbox2;
  79.     GtkWidget *hbbox1;
  80.     GtkWidget *frame;
  81.     GtkWidget *label;
  82.     GtkTooltips *tooltips;
  83.     
  84.     tooltips = gtk_tooltips_new();
  85.  
  86.   vbox = gtk_vbox_new(FALSE, 5);
  87.   gtk_container_add(GTK_CONTAINER(cmw), vbox);
  88.   gtk_widget_show(vbox);
  89.  
  90.   cmw->scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
  91.   gtk_box_pack_start(GTK_BOX(vbox), cmw->scrolledwindow, TRUE, TRUE, 0);
  92.   gtk_container_set_border_width(GTK_CONTAINER(cmw->scrolledwindow), 2);
  93.   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(cmw->scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  94.   gtk_widget_show(cmw->scrolledwindow);
  95.  
  96.   cmw->charmap = charmap_new();
  97. #ifdef GTK_HAVE_FEATURES_1_1_12
  98.     gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(cmw->scrolledwindow), cmw->charmap);
  99. #else
  100.   gtk_container_add(GTK_CONTAINER(cmw->scrolledwindow), cmw->charmap);
  101. #endif
  102.     gtk_signal_connect(GTK_OBJECT(cmw->charmap), "char_selected",
  103.         GTK_SIGNAL_FUNC(on_charmap_char_selected), cmw);
  104.   gtk_widget_show(cmw->charmap);
  105.  
  106.   hbox1 = gtk_hbox_new(FALSE, 5);
  107.   gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, TRUE, 0);
  108.   gtk_widget_show(hbox1);
  109.  
  110.     frame = gtk_frame_new(NULL);
  111.   gtk_box_pack_start(GTK_BOX(hbox1), frame, FALSE, FALSE, 0);
  112.     gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
  113.     gtk_widget_show(frame);
  114.  
  115.   hbox2 = gtk_hbox_new(FALSE, 5);
  116.   gtk_container_add(GTK_CONTAINER(frame), hbox2);
  117.   gtk_widget_show(hbox2);
  118.  
  119.     label = gtk_label_new(_("Selected char:"));
  120.   gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 4);
  121.   gtk_widget_show(label);
  122.  
  123.     cmw->label = gtk_label_new("   ");
  124.   gtk_box_pack_start(GTK_BOX(hbox2), cmw->label, FALSE, TRUE, 5);
  125.   gtk_widget_show(cmw->label);
  126.  
  127.     hbbox1 = gtk_hbutton_box_new();
  128.   gtk_box_pack_end(GTK_BOX(hbox1), hbbox1, FALSE, FALSE, 0);
  129.     gtk_button_box_set_layout(GTK_BUTTON_BOX(hbbox1), GTK_BUTTONBOX_END);
  130.     gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbbox1), 4);
  131.   gtk_widget_show(hbbox1);
  132.  
  133.   cmw->insert_button = gtk_button_new_with_label(_("Insert"));
  134.   gtk_box_pack_start(GTK_BOX(hbbox1), cmw->insert_button, FALSE, FALSE, 0);
  135.   GTK_WIDGET_SET_FLAGS(cmw->insert_button, GTK_CAN_DEFAULT);
  136.     gtk_tooltips_set_tip(tooltips, cmw->insert_button, _("Insert the selected char at the cursor position"), NULL);
  137.   gtk_widget_show(cmw->insert_button);
  138.  
  139.   cmw->close_button = gtk_button_new_with_label(_("Close"));
  140.   gtk_box_pack_start(GTK_BOX(hbbox1), cmw->close_button, FALSE, FALSE, 0);
  141.   GTK_WIDGET_SET_FLAGS(cmw->close_button, GTK_CAN_DEFAULT);
  142.   gtk_widget_grab_default(cmw->close_button);
  143.   gtk_widget_show(cmw->close_button);
  144. }
  145.  
  146.  
  147. GtkWidget* charmap_window_new(const gchar *title)
  148. {
  149.     CharMapWindow *cmw;
  150.  
  151.     cmw = gtk_type_new(charmap_window_get_type());
  152.     gtk_window_set_title(GTK_WINDOW(cmw), title);
  153.     gtk_container_set_border_width(GTK_CONTAINER(cmw), 4);
  154.     gtk_window_set_policy(GTK_WINDOW(cmw), TRUE, TRUE, FALSE);
  155.  
  156.     return GTK_WIDGET(cmw);
  157. }
  158.  
  159.  
  160. void on_charmap_char_selected(GtkWidget *widget, gpointer data)
  161. {
  162.     CharMapWindow *cmw;
  163.     gchar lab[2];
  164.  
  165.     cmw = (CharMapWindow *)data;
  166.     lab[0] = CHARMAP(cmw->charmap)->current_char;
  167.     lab[1] = 0;
  168.     gtk_label_set_text(GTK_LABEL(cmw->label), lab);
  169. }
  170.  
  171. /* vim: set ts=2 sw=2 tw=79 ai nowrap: */
  172.