Hash :
94046104
Author :
Thomas de Grivel
Date :
2020-02-24T15:19:27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
/*
pw13_gtk - A Patchwork13! GTK+2 User Interface
Copyright (C) 2005 Thomas de Grivel <billitch@yahoo.fr>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
output.c - gtk output widget
*/
#include <string.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include "output.h"
#include "input.h"
#include "drag_and_drop.h"
#include "patch.h"
#include "patchwork.h"
#include "connect.h"
static GtkTargetEntry drag_from_output_targets[] = {PW13_DRAG_OUTPUT_TARGET};
static GtkTargetEntry drag_to_output_targets[] = {PW13_DRAG_INPUT_TARGET};
/* signal callbacks */
static void output_drag_data_get (GtkWidget *widget,
GdkDragContext *dc,
GtkSelectionData *sd,
guint info, guint time,
Pw13_GtkOutput *o)
{
time = time;
/*
printf ("output drag_data_get signal received\n");
*/
if (!widget || !dc)
return;
if (info == PW13_DRAG_OUTPUT) {
char buf[16];
sprintf (buf, "%x", (unsigned int) o);
/*
printf ("output data_set: %s\n", buf);
*/
gtk_selection_data_set (sd, sd->target, 8, (guchar*) buf, strlen (buf));
}
}
static void output_reconnect (Pw13_GtkOutput *o)
{
Pw13_List *L = o->p->pw->connections;
while (L) {
Pw13_GtkConnect *c = (Pw13_GtkConnect*) L->elem;
if (c->o == o && c->i->active) {
printf("output reconnect \n");
pw13_connect (o->o, c->i->i);
}
L = L->suiv;
}
}
static void output_checkbox_toggled (GtkButton *checkbox, Pw13_GtkOutput *o)
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(checkbox)) == TRUE) {
o->active = 1;
output_reconnect (o);
}
else {
Pw13_List *L = o->o->connected_to;
Pw13_Input *i;
while (L) {
printf ("output disconnect \n");
fflush (stdout);
i = (Pw13_Input*) L->elem;
pw13_disconnect (i);
L = L->suiv;
}
o->active = 0;
}
gtk_widget_queue_draw (GTK_WIDGET (o->p->pw->layout));
}
static void connect_output_signals (Pw13_GtkOutput *o)
{
g_signal_connect (G_OBJECT (o->checkbox), "drag_data_get",
G_CALLBACK (output_drag_data_get), o);
g_signal_connect_after (G_OBJECT (o->checkbox), "toggled",
G_CALLBACK (output_checkbox_toggled), o);
}
Pw13_GtkOutput * pw13_gtk_output_new (Pw13_Output *output, Pw13_GtkPatch *p)
{
Pw13_GtkOutput *o = malloc (sizeof (Pw13_GtkOutput));
if (!o)
exit (1);
o->o = output;
o->o->custom_data = o;
o->widget = gtk_hbox_new (FALSE, 1);
o->name = gtk_label_new (output->name);
o->type = gtk_label_new (output->data_type->name);
o->checkbox = gtk_check_button_new ();
gtk_box_pack_end (GTK_BOX (o->widget), o->checkbox, FALSE, FALSE, 0);
gtk_box_pack_end (GTK_BOX (o->widget), o->name, FALSE, FALSE, 0);
gtk_box_pack_end (GTK_BOX (o->widget), gtk_label_new(") "), FALSE, FALSE,0);
gtk_box_pack_end (GTK_BOX (o->widget), o->type, FALSE, FALSE, 0);
gtk_box_pack_end (GTK_BOX (o->widget), gtk_label_new ("("), FALSE,FALSE,0);
gtk_widget_show_all (o->widget);
o->p = p;
if (p)
gtk_box_pack_start (GTK_BOX (p->outputs_box), o->widget, TRUE, TRUE, 0);
gtk_drag_source_set (o->checkbox, GDK_BUTTON1_MASK,
drag_from_output_targets, 1, GDK_ACTION_LINK);
gtk_drag_dest_set (o->checkbox, 0, drag_to_output_targets, 1,
GDK_ACTION_LINK);
connect_output_signals (o);
return o;
}