3 * Copyright (C) 2005 Laboratoire d'Informatique de Paris 6
4 * Author: Pierre Duquesne
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.
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.
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.
26 int aadlbox_point_near_port(Aadlbox
*aadlbox
, Point
*p
);
30 /***********************************************
31 ** U N D O / R E D O **
32 ***********************************************/
34 struct EditPortDeclarationChange
36 ObjectChange obj_change
;
46 static void edit_port_declaration_apply
47 (struct EditPortDeclarationChange
*change
, DiaObject
*obj
)
49 Aadlbox
*aadlbox
= (Aadlbox
*) obj
;
50 int port_num
= change
->port_num
;
53 aadlbox
->ports
[port_num
]->declaration
= change
->newvalue
;
57 static void edit_port_declaration_revert
58 (struct EditPortDeclarationChange
*change
, DiaObject
*obj
)
60 Aadlbox
*aadlbox
= (Aadlbox
*) obj
;
61 int port_num
= change
->port_num
;
64 aadlbox
->ports
[port_num
]->declaration
= change
->oldvalue
;
68 static void edit_port_declaration_free (struct EditPortDeclarationChange
*change
)
71 g_free(change
->oldvalue
);
73 g_free(change
->newvalue
);
78 /***********************************************
79 ** G T K W I N D O W **
80 ***********************************************/
82 static GtkWidget
*entry
;
85 static void save_text()
87 text
= (gchar
*) g_malloc (strlen(gtk_entry_get_text (GTK_ENTRY (entry
)))+1);
88 strcpy(text
, gtk_entry_get_text (GTK_ENTRY (entry
)));
91 static gboolean
delete_event ( GtkWidget
*widget
,
100 static void enter_callback( GtkWidget
*widget
,
104 gtk_widget_destroy(window
);
107 static gboolean
focus_out_event( GtkWidget
*widget
,
108 GdkEventButton
*event
,
112 gtk_widget_destroy(window
);
117 /* I have to write this little GTK code, because there's no way to know
118 which point was clicked if I use the properties functions (get_props, ...)*/
120 ObjectChange
*edit_port_declaration_callback (DiaObject
*obj
,
121 Point
*clicked
, gpointer data
)
126 struct EditPortDeclarationChange
*change
;
128 Aadlbox
*aadlbox
= (Aadlbox
*) obj
;
133 port_num
= aadlbox_point_near_port(aadlbox
, clicked
);
134 port
= aadlbox
->ports
[port_num
];
137 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
138 gtk_window_set_position (GTK_WINDOW (window
), GTK_WIN_POS_CENTER
);
139 gtk_widget_set_usize(window
,400,50);
140 gtk_window_set_title(GTK_WINDOW(window
) , "Port Declaration");
141 gtk_container_set_border_width(GTK_CONTAINER(window
),5);
143 vbox
= gtk_vbox_new (FALSE
, 0);
144 gtk_container_add (GTK_CONTAINER (window
), vbox
);
145 gtk_widget_show (vbox
);
147 entry
= gtk_entry_new ();
148 gtk_entry_set_max_length (GTK_ENTRY (entry
), 1024);
149 gtk_entry_set_text (GTK_ENTRY (entry
), port
->declaration
);
150 gtk_box_pack_start (GTK_BOX (vbox
), entry
, TRUE
, TRUE
, 0);
151 gtk_widget_show(entry
);
153 button
= gtk_button_new_from_stock (GTK_STOCK_OK
);
154 gtk_box_pack_start (GTK_BOX (vbox
), button
, TRUE
, TRUE
, 0);
155 GTK_WIDGET_SET_FLAGS (button
, GTK_CAN_DEFAULT
);
156 gtk_widget_grab_default (button
);
157 gtk_widget_show (button
);
161 g_signal_connect (G_OBJECT (window
), "destroy",
162 G_CALLBACK (gtk_main_quit
), NULL
);
164 g_signal_connect_swapped (G_OBJECT (window
), "delete_event",
165 G_CALLBACK(delete_event
),
168 g_signal_connect (G_OBJECT (entry
), "activate",
169 G_CALLBACK (enter_callback
),
172 g_signal_connect (G_OBJECT (button
), "clicked",
173 G_CALLBACK (enter_callback
),
177 /* avoid bug when quitting DIA with this window opened */
178 g_signal_connect (G_OBJECT (window
), "focus_out_event",
179 G_CALLBACK (focus_out_event
),
183 gtk_widget_show (window
);
187 /* Text has been edited - widgets destroyed */
189 change
= (struct EditPortDeclarationChange
*)
190 g_malloc (sizeof(struct EditPortDeclarationChange
));
192 change
->obj_change
.apply
=
193 (ObjectChangeApplyFunc
) edit_port_declaration_apply
;
195 change
->obj_change
.revert
=
196 (ObjectChangeRevertFunc
) edit_port_declaration_revert
;
198 change
->obj_change
.free
=
199 (ObjectChangeFreeFunc
) edit_port_declaration_free
;
201 change
->port_num
= port_num
;
203 change
->newvalue
= text
;
204 change
->oldvalue
= aadlbox
->ports
[port_num
]->declaration
;
206 change
->obj_change
.apply(change
, obj
);
208 return (ObjectChange
*) change
;