1 /*
2  * Copyright (C) 2002 2003 2004, Magnus Hjorth
3  *
4  * This file is part of mhWaveEdit.
5  *
6  * mhWaveEdit 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  * mhWaveEdit 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 mhWaveEdit; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 
22 #include <config.h>
23 
24 #include <math.h>
25 #include <gtk/gtk.h>
26 #include "mainwindow.h"
27 #include "effectdialog.h"
28 #include "effectbrowser.h"
29 #include "main.h"
30 #include "um.h"
31 
32 enum { APPLY_SIGNAL, SETUP_SIGNAL, TARGET_CHANGED_SIGNAL, LAST_SIGNAL };
33 static guint effect_dialog_signals[LAST_SIGNAL] = { 0 };
34 
effect_dialog_class_init(GtkObjectClass * klass)35 static void effect_dialog_class_init(GtkObjectClass *klass)
36 {
37      EFFECT_DIALOG_CLASS(klass)->apply = NULL;
38      EFFECT_DIALOG_CLASS(klass)->setup = NULL;
39      EFFECT_DIALOG_CLASS(klass)->target_changed = NULL;
40 
41      effect_dialog_signals[APPLY_SIGNAL] =
42 	  gtk_signal_new("apply",GTK_RUN_LAST,GTK_CLASS_TYPE(klass),
43 			 GTK_SIGNAL_OFFSET(EffectDialogClass,apply),
44 			 gtk_marshal_BOOL__NONE,GTK_TYPE_BOOL,0);
45      effect_dialog_signals[SETUP_SIGNAL] =
46          gtk_signal_new("setup",GTK_RUN_FIRST,GTK_CLASS_TYPE(klass),
47                         GTK_SIGNAL_OFFSET(EffectDialogClass,setup),
48                         gtk_marshal_NONE__NONE,GTK_TYPE_NONE,0);
49      effect_dialog_signals[TARGET_CHANGED_SIGNAL] =
50 	  gtk_signal_new("target-changed",GTK_RUN_FIRST,GTK_CLASS_TYPE(klass),
51 			 GTK_SIGNAL_OFFSET(EffectDialogClass,target_changed),
52 			 gtk_marshal_NONE__NONE,GTK_TYPE_NONE,0);
53 
54      gtk_object_class_add_signals(klass,effect_dialog_signals,LAST_SIGNAL);
55 }
56 
effect_dialog_apply(EffectDialog * ed)57 gboolean effect_dialog_apply(EffectDialog *ed)
58 {
59      gboolean r;
60      gtk_signal_emit(GTK_OBJECT(ed),effect_dialog_signals[APPLY_SIGNAL],&r);
61      return r;
62 }
63 
effect_dialog_init(EffectDialog * v)64 static void effect_dialog_init(EffectDialog *v)
65 {
66      GtkWidget *b;
67 
68      gtk_box_set_spacing(GTK_BOX(v),3);
69 
70      b = gtk_hbox_new ( FALSE, 3 );
71      v->input_area = GTK_CONTAINER(b);
72      gtk_box_pack_start ( GTK_BOX(v), b, FALSE, FALSE, 0 );
73      gtk_widget_show ( b );
74 
75      gtk_container_set_border_width(GTK_CONTAINER(v),5);
76 }
77 
effect_dialog_get_type(void)78 GtkType effect_dialog_get_type(void)
79 {
80      static GtkType id = 0;
81      if (!id) {
82 	  GtkTypeInfo info = {
83 	       "EffectDialog",
84 	       sizeof(EffectDialog),
85 	       sizeof(EffectDialogClass),
86 	       (GtkClassInitFunc) effect_dialog_class_init,
87 	       (GtkObjectInitFunc) effect_dialog_init
88 	  };
89 	  id = gtk_type_unique(gtk_vbox_get_type(),&info);
90      }
91      return id;
92 }
93 
effect_dialog_eb_target_changed(DocumentList * dl,gpointer user_data)94 static void effect_dialog_eb_target_changed(DocumentList *dl,
95 					    gpointer user_data)
96 {
97      /* puts("effect_dialog_eb_target_changed"); */
98      gtk_signal_emit(GTK_OBJECT(user_data),
99 		     effect_dialog_signals[TARGET_CHANGED_SIGNAL]);
100 }
101 
effect_dialog_setup(EffectDialog * ed,gchar * effect_name,gpointer eb)102 void effect_dialog_setup(EffectDialog *ed, gchar *effect_name, gpointer eb)
103 {
104      g_assert(ed->eb == NULL && eb != NULL);
105      ed->eb = eb;
106      ed->effect_name = effect_name;
107      gtk_signal_connect_while_alive
108 	  (GTK_OBJECT(EFFECT_BROWSER(eb)->dl),"document_changed",
109 	   GTK_SIGNAL_FUNC(effect_dialog_eb_target_changed),ed,GTK_OBJECT(ed));
110      gtk_signal_emit(GTK_OBJECT(ed),
111                      effect_dialog_signals[SETUP_SIGNAL]);
112 }
113 
114