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 / message_window.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-22  |  4.6 KB  |  162 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: message_window.c,v 1.7 2000/10/17 18:32:42 neo Exp $
  21.  */
  22.  
  23. #include <gtk/gtk.h>
  24. #include "libgimp/gimpui.h"
  25. #include "libgimp/stdplugins-intl.h"
  26. #include "message_window.h"
  27.  
  28.  
  29. static void message_window_class_init (MessageWindowClass *class);
  30. static void message_window_init       (MessageWindow      *mw);
  31.  
  32.  
  33. static GtkWindowClass *message_window_parent_class = NULL;
  34.  
  35.  
  36. guint 
  37. message_window_get_type (void)
  38. {
  39.   static guint mw_type = 0;
  40.   
  41.   if (!mw_type) 
  42.     {
  43.       GtkTypeInfo mw_info = 
  44.       {
  45.     "MessageWindow",
  46.     sizeof(MessageWindow),
  47.     sizeof(MessageWindowClass),
  48.     (GtkClassInitFunc)message_window_class_init,
  49.     (GtkObjectInitFunc)message_window_init,
  50.     (GtkArgSetFunc)NULL,
  51.     (GtkArgGetFunc)NULL,
  52. #ifdef GTK_HAVE_FEATURES_1_1_12
  53.     (GtkClassInitFunc)NULL,
  54. #endif
  55.       };
  56.       mw_type = gtk_type_unique (gtk_window_get_type (), &mw_info);
  57.     }
  58.   return mw_type;
  59. }
  60.  
  61.  
  62. static void 
  63. message_window_class_init (MessageWindowClass *klass)
  64. {
  65.   GtkObjectClass *object_class;
  66.   
  67.   object_class = (GtkObjectClass *)klass;
  68.   message_window_parent_class = gtk_type_class (gtk_window_get_type());
  69. }
  70.  
  71.  
  72. static void 
  73. message_window_init (MessageWindow *mw)
  74. {
  75.   GtkWidget *vbox;
  76.   GtkWidget *hbox1;
  77.   GtkWidget *hbbox1;
  78.   GtkWidget *vscrollbar;
  79.   GtkWidget *hseparator;
  80.   GtkStyle  *style;
  81.  
  82.   mw->contains_messages = FALSE;
  83.  
  84.   vbox = gtk_vbox_new (FALSE, 5);
  85.   gtk_container_add (GTK_CONTAINER(mw), vbox);
  86.   gtk_widget_show (vbox);
  87.  
  88.   hbox1 = gtk_hbox_new (FALSE, 0);
  89.   gtk_box_pack_start (GTK_BOX(vbox), hbox1, TRUE, TRUE, 0);
  90.   gtk_widget_show (hbox1);
  91.  
  92.   mw->text = gtk_text_new (NULL, NULL);
  93.   gtk_box_pack_start (GTK_BOX(hbox1), mw->text, TRUE, TRUE, 5);
  94.   gtk_widget_show (mw->text);
  95.  
  96.   style = gtk_widget_get_style (mw->text);
  97.   gtk_style_unref (style);
  98.   style->base[GTK_STATE_NORMAL] = style->bg[GTK_STATE_NORMAL];
  99.   gtk_style_ref (style);
  100.   gtk_widget_set_style (mw->text, style);
  101.   
  102.   vscrollbar = gtk_vscrollbar_new (GTK_TEXT(mw->text)->vadj);
  103.   gtk_box_pack_start (GTK_BOX (hbox1), vscrollbar, FALSE, TRUE, 0);
  104.   gtk_widget_show (vscrollbar);
  105.     
  106.   hseparator = gtk_hseparator_new ();
  107.   gtk_box_pack_start (GTK_BOX(vbox), hseparator, FALSE, TRUE, 0);
  108.   gtk_widget_show (hseparator);
  109.  
  110.   hbbox1 = gtk_hbutton_box_new ();
  111.   gtk_box_pack_start (GTK_BOX(vbox), hbbox1, FALSE, FALSE, 0);
  112.   gtk_button_box_set_layout (GTK_BUTTON_BOX(hbbox1), GTK_BUTTONBOX_END);
  113.   gtk_widget_show (hbbox1);
  114.  
  115.   mw->dismiss_button = gtk_button_new_with_label(_("Dismiss"));
  116.   GTK_WIDGET_SET_FLAGS (mw->dismiss_button, GTK_CAN_DEFAULT);
  117.   gtk_box_pack_end (GTK_BOX(hbbox1), mw->dismiss_button, FALSE, TRUE, 0);
  118.   gtk_widget_grab_default (mw->dismiss_button);
  119.   gtk_widget_show (mw->dismiss_button);
  120. }
  121.  
  122.  
  123. GtkWidget *
  124. message_window_new (const gchar *title)
  125. {
  126.   MessageWindow *mw;
  127.   
  128.   mw = gtk_type_new (message_window_get_type());
  129.   gtk_window_set_title (GTK_WINDOW(mw), title);
  130.   gimp_dialog_set_icon (GTK_WINDOW (mw));
  131.   gtk_container_set_border_width (GTK_CONTAINER(mw), 4);
  132.   gtk_window_set_policy (GTK_WINDOW(mw), TRUE, TRUE, FALSE);
  133.   
  134.   return GTK_WIDGET(mw);
  135. }
  136.  
  137.  
  138. void 
  139. message_window_append (MessageWindow *mw, 
  140.                const gchar   *msg)
  141. {
  142.   gtk_widget_realize (mw->text);
  143.   gtk_text_freeze (GTK_TEXT(mw->text));
  144.   gtk_text_insert (GTK_TEXT(mw->text), NULL, NULL, NULL, "* ", -1);
  145.   gtk_text_insert (GTK_TEXT(mw->text), NULL, NULL, NULL, msg, -1);
  146.   gtk_text_thaw (GTK_TEXT(mw->text));
  147.   mw->contains_messages = TRUE;
  148.   g_print ("* %s", msg);
  149. }
  150.  
  151.  
  152. void 
  153. message_window_clear (MessageWindow *mw)
  154. {
  155.   gtk_widget_realize (mw->text);
  156.   gtk_text_freeze (GTK_TEXT(mw->text));
  157.   gtk_editable_delete_text (GTK_EDITABLE(mw->text), 0, -1);
  158.   gtk_text_thaw (GTK_TEXT(mw->text));
  159.   mw->contains_messages = FALSE;
  160. }
  161.  
  162.