1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 /* $Header: /cvs/gnome/dia/app/interface.c,v 1.61 2002/01/19 11:22:24 sdteffen Exp $ */
26 #include "layer_dialog.h"
27 #include "interface.h"
30 #include "preferences.h"
33 #include "diagram_tree_window.h"
34 #include <gdk-pixbuf/gdk-pixbuf.h>
36 static const GtkTargetEntry create_object_targets
[] = {
37 { "application/x-dia-object", 0, 0 },
40 ToolButton tool_data
[] =
42 { (char **) arrow_xpm
,
43 N_("Modify object(s)"),
45 { MODIFY_TOOL
, NULL
, NULL
}
47 { (char **) magnify_xpm
,
50 { MAGNIFY_TOOL
, NULL
, NULL
}
52 { (char **) scroll_xpm
,
53 N_("Scroll around the diagram"),
55 { SCROLL_TOOL
, NULL
, NULL
}
60 { CREATE_OBJECT_TOOL
, "Standard - Text", NULL
}
65 { CREATE_OBJECT_TOOL
, "Standard - Box", NULL
}
70 { CREATE_OBJECT_TOOL
, "Standard - Ellipse", NULL
}
75 { CREATE_OBJECT_TOOL
, "Standard - Polygon", NULL
}
78 N_("Create Beziergon"),
80 { CREATE_OBJECT_TOOL
, "Standard - Beziergon", NULL
}
85 { CREATE_OBJECT_TOOL
, "Standard - Line", NULL
}
90 { CREATE_OBJECT_TOOL
, "Standard - Arc", NULL
}
93 N_("Create Zigzagline"),
95 { CREATE_OBJECT_TOOL
, "Standard - ZigZagLine", NULL
}
98 N_("Create Polyline"),
100 { CREATE_OBJECT_TOOL
, "Standard - PolyLine", NULL
}
103 N_("Create Bezierline"),
105 { CREATE_OBJECT_TOOL
, "Standard - BezierLine", NULL
}
110 { CREATE_OBJECT_TOOL
, "Standard - Image", NULL
}
114 #define NUM_TOOLS (sizeof (tool_data) / sizeof (ToolButton))
115 const int num_tools
= NUM_TOOLS
;
120 static GtkWidget
*toolbox_shell
= NULL
;
121 static GtkWidget
*tool_widgets
[NUM_TOOLS
];
122 static GtkTooltips
*tool_tips
;
123 static GSList
*tool_group
= NULL
;
125 GtkWidget
*modify_tool_button
;
127 /* The popup shell is a pointer to the display shell that posted the latest
128 * popup menu. When this is null, and a command is invoked, then the
129 * assumption is that the command was a result of a keyboard accelerator
131 GtkWidget
*popup_shell
= NULL
;
134 origin_button_press(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
136 DDisplay
*ddisp
= (DDisplay
*)data
;
138 display_set_active(ddisp
);
139 ddisplay_popup_menu(ddisp
, event
);
141 /* stop the signal emission so the button doesn't grab the
143 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget
), "button_press_event");
148 #ifndef WITHOUT_ZOOM_COMBO
150 zoom_activate_callback(GtkWidget
*dummy
, gpointer user_data
) {
151 DDisplay
*ddisp
= (DDisplay
*)user_data
;
152 gchar
*zoom_text
= gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(ddisp
->zoom_status
)->entry
));
153 float zoom_amount
, magnify
;
155 if (sscanf(zoom_text
, "%f", &zoom_amount
)) {
159 magnify
= (zoom_amount
*DDISPLAY_NORMAL_ZOOM
/100.0)/ddisp
->zoom_factor
;
160 if (fabs(magnify
- 1.0) > 0.000001) {
161 visible
= &ddisp
->visible
;
162 middle
.x
= visible
->left
*0.5 + visible
->right
*0.5;
163 middle
.y
= visible
->top
*0.5 + visible
->bottom
*0.5;
164 ddisplay_zoom(ddisp
, &middle
, magnify
);
171 create_zoom_widget(DDisplay
*ddisp
) {
172 GtkWidget
*combo
= NULL
;
175 combo
= gtk_combo_new();
176 items
= g_list_append(items
, "400%");
177 items
= g_list_append(items
, "283%");
178 items
= g_list_append(items
, "200%");
179 items
= g_list_append(items
, "141%");
180 items
= g_list_append(items
, "100%");
181 items
= g_list_append(items
, "85%");
182 items
= g_list_append(items
, "70.7%");
183 items
= g_list_append(items
, "50%");
184 items
= g_list_append(items
, "35.4%");
185 items
= g_list_append(items
, "25%");
186 gtk_combo_set_popdown_strings (GTK_COMBO(combo
), items
);
187 gtk_combo_set_value_in_list(GTK_COMBO(combo
), FALSE
, FALSE
);
188 gtk_combo_disable_activate(GTK_COMBO(combo
));
190 gtk_signal_connect (GTK_OBJECT (GTK_COMBO(combo
)->entry
), "activate",
191 (GtkSignalFunc
) zoom_activate_callback
,
194 gtk_signal_connect (GTK_OBJECT (GTK_COMBO(combo
)->list
), "unmap",
195 (GtkSignalFunc
) zoom_activate_callback
,
198 gtk_signal_connect (GTK_OBJECT (GTK_COMBO(combo
)->list
), "selection-changed",
199 (GtkSignalFunc
) zoom_activate_callback
,
207 display_drop_callback(GtkWidget
*widget
, GdkDragContext
*context
,
208 gint x
, gint y
, guint time
)
210 if (gtk_drag_get_source_widget(context
) != NULL
) {
211 /* we only accept drops from the same instance of the application,
212 * as the drag data is a pointer in our address space */
215 gtk_drag_finish (context
, FALSE
, FALSE
, time
);
220 display_data_received_callback (GtkWidget
*widget
, GdkDragContext
*context
,
221 gint x
, gint y
, GtkSelectionData
*data
,
222 guint info
, guint time
, DDisplay
*ddisp
)
224 if (data
->format
== 8 && data
->length
== sizeof(ToolButtonData
*) &&
225 gtk_drag_get_source_widget(context
) != NULL
) {
226 ToolButtonData
*tooldata
= *(ToolButtonData
**)data
->data
;
228 /* g_message("Tool drop %s at (%d, %d)", (gchar *)tooldata->extra_data, x, y);*/
229 ddisplay_drop_object(ddisp
, x
, y
,
230 object_get_type((gchar
*)tooldata
->extra_data
),
231 tooldata
->user_data
);
232 gtk_drag_finish (context
, TRUE
, FALSE
, time
);
234 gtk_drag_finish (context
, FALSE
, FALSE
, time
);
238 create_display_shell(DDisplay
*ddisp
,
239 int width
, int height
,
240 char *title
, int use_mbar
, int top_level_window
)
242 GtkWidget
*table
, *widget
;
243 GtkWidget
*status_hbox
;
244 GtkWidget
*root_vbox
= NULL
;
245 #ifndef WITHOUT_ZOOM_COMBO
246 GtkWidget
*zoom_hbox
, *zoom_label
;
248 int s_width
, s_height
;
250 s_width
= gdk_screen_width ();
251 s_height
= gdk_screen_height ();
254 if (height
> s_height
)
257 /* The adjustment datums */
258 ddisp
->hsbdata
= GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, width
, 1, (width
-1)/4, width
-1));
259 ddisp
->vsbdata
= GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, height
, 1, (height
-1)/4, height
-1));
261 /* The toplevel shell */
262 if (top_level_window
) {
263 ddisp
->shell
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
264 gtk_window_set_title (GTK_WINDOW (ddisp
->shell
), title
);
265 gtk_window_set_wmclass (GTK_WINDOW (ddisp
->shell
), "diagram_window",
267 gtk_window_set_policy (GTK_WINDOW (ddisp
->shell
), TRUE
, TRUE
, TRUE
);
269 ddisp
->shell
= gtk_event_box_new ();
272 gtk_object_set_user_data (GTK_OBJECT (ddisp
->shell
), (gpointer
) ddisp
);
274 gtk_widget_set_events (ddisp
->shell
,
275 GDK_POINTER_MOTION_MASK
|
276 GDK_POINTER_MOTION_HINT_MASK
|
277 GDK_FOCUS_CHANGE_MASK
);
278 /* GDK_ALL_EVENTS_MASK */
280 gtk_signal_connect (GTK_OBJECT (ddisp
->shell
), "delete_event",
281 GTK_SIGNAL_FUNC (ddisplay_delete
),
283 gtk_signal_connect (GTK_OBJECT (ddisp
->shell
), "destroy",
284 GTK_SIGNAL_FUNC (ddisplay_destroy
),
286 gtk_signal_connect (GTK_OBJECT (ddisp
->shell
), "focus_out_event",
287 GTK_SIGNAL_FUNC (ddisplay_focus_out_event
),
289 gtk_signal_connect (GTK_OBJECT (ddisp
->shell
), "focus_in_event",
290 GTK_SIGNAL_FUNC (ddisplay_focus_in_event
),
292 gtk_signal_connect (GTK_OBJECT (ddisp
->shell
), "realize",
293 GTK_SIGNAL_FUNC (ddisplay_realize
),
295 gtk_signal_connect (GTK_OBJECT (ddisp
->shell
), "unrealize",
296 GTK_SIGNAL_FUNC (ddisplay_unrealize
),
299 /* Clipboard handling signals */
300 gtk_signal_connect (GTK_OBJECT(ddisp
->shell
), "selection_get",
301 GTK_SIGNAL_FUNC (get_selection_handler
), NULL
);
302 gtk_signal_connect (GTK_OBJECT(ddisp
->shell
), "selection_received",
303 GTK_SIGNAL_FUNC (received_selection_handler
), NULL
);
305 /* the table containing all widgets */
306 table
= gtk_table_new (4, 3, FALSE
);
307 gtk_table_set_col_spacing (GTK_TABLE (table
), 0, 1);
308 gtk_table_set_col_spacing (GTK_TABLE (table
), 1, 2);
309 gtk_table_set_row_spacing (GTK_TABLE (table
), 0, 1);
310 gtk_table_set_row_spacing (GTK_TABLE (table
), 1, 2);
311 gtk_container_set_border_width (GTK_CONTAINER (table
), 2);
314 root_vbox
= gtk_vbox_new (FALSE
, 1);
315 gtk_container_add (GTK_CONTAINER (ddisp
->shell
), root_vbox
);
316 gtk_box_pack_end (GTK_BOX (root_vbox
), table
, TRUE
, TRUE
, 0);
320 gtk_container_add (GTK_CONTAINER (ddisp
->shell
), table
);
324 /* scrollbars, rulers, canvas, menu popup button */
326 ddisp
->origin
= gtk_button_new();
327 GTK_WIDGET_UNSET_FLAGS(ddisp
->origin
, GTK_CAN_FOCUS
);
328 widget
= gtk_arrow_new(GTK_ARROW_RIGHT
, GTK_SHADOW_OUT
);
329 gtk_container_add(GTK_CONTAINER(ddisp
->origin
), widget
);
330 gtk_widget_show(widget
);
331 gtk_signal_connect(GTK_OBJECT(ddisp
->origin
), "button_press_event",
332 GTK_SIGNAL_FUNC(origin_button_press
), ddisp
);
335 ddisp
->origin
= gtk_frame_new (NULL
);
336 gtk_frame_set_shadow_type (GTK_FRAME (ddisp
->origin
), GTK_SHADOW_OUT
);
340 ddisp
->hrule
= gtk_hruler_new ();
341 gtk_signal_connect_object (GTK_OBJECT (ddisp
->shell
), "motion_notify_event",
342 (GtkSignalFunc
) GTK_WIDGET_CLASS (GTK_OBJECT (ddisp
->hrule
)->klass
)->motion_notify_event
,
343 GTK_OBJECT (ddisp
->hrule
));
345 ddisp
->vrule
= gtk_vruler_new ();
346 gtk_signal_connect_object (GTK_OBJECT (ddisp
->shell
), "motion_notify_event",
347 (GtkSignalFunc
) GTK_WIDGET_CLASS (GTK_OBJECT (ddisp
->vrule
)->klass
)->motion_notify_event
,
348 GTK_OBJECT (ddisp
->vrule
));
350 ddisp
->hsb
= gtk_hscrollbar_new (ddisp
->hsbdata
);
351 GTK_WIDGET_UNSET_FLAGS (ddisp
->hsb
, GTK_CAN_FOCUS
);
352 ddisp
->vsb
= gtk_vscrollbar_new (ddisp
->vsbdata
);
353 GTK_WIDGET_UNSET_FLAGS (ddisp
->vsb
, GTK_CAN_FOCUS
);
356 /* set up the scrollbar observers */
357 gtk_signal_connect (GTK_OBJECT (ddisp
->hsbdata
), "value_changed",
358 (GtkSignalFunc
) ddisplay_hsb_update
,
360 gtk_signal_connect (GTK_OBJECT (ddisp
->vsbdata
), "value_changed",
361 (GtkSignalFunc
) ddisplay_vsb_update
,
364 ddisp
->canvas
= gtk_drawing_area_new ();
365 gtk_drawing_area_size (GTK_DRAWING_AREA (ddisp
->canvas
), width
, height
);
366 gtk_widget_set_events (ddisp
->canvas
, CANVAS_EVENT_MASK
);
367 GTK_WIDGET_SET_FLAGS (ddisp
->canvas
, GTK_CAN_FOCUS
);
368 gtk_signal_connect (GTK_OBJECT (ddisp
->canvas
), "event",
369 (GtkSignalFunc
) ddisplay_canvas_events
,
372 gtk_drag_dest_set(ddisp
->canvas
, GTK_DEST_DEFAULT_ALL
,
373 create_object_targets
, 1, GDK_ACTION_COPY
);
374 gtk_signal_connect (GTK_OBJECT (ddisp
->canvas
), "drag_drop",
375 GTK_SIGNAL_FUNC(display_drop_callback
), NULL
);
376 gtk_signal_connect (GTK_OBJECT (ddisp
->canvas
), "drag_data_received",
377 GTK_SIGNAL_FUNC(display_data_received_callback
), ddisp
);
379 gtk_object_set_user_data (GTK_OBJECT (ddisp
->canvas
), (gpointer
) ddisp
);
380 /* pack all the widgets */
381 gtk_table_attach (GTK_TABLE (table
), ddisp
->origin
, 0, 1, 0, 1,
382 GTK_FILL
, GTK_FILL
, 0, 0);
383 gtk_table_attach (GTK_TABLE (table
), ddisp
->hrule
, 1, 2, 0, 1,
384 GTK_EXPAND
| GTK_SHRINK
| GTK_FILL
, GTK_FILL
, 0, 0);
385 gtk_table_attach (GTK_TABLE (table
), ddisp
->vrule
, 0, 1, 1, 2,
386 GTK_FILL
, GTK_EXPAND
| GTK_SHRINK
| GTK_FILL
, 0, 0);
387 gtk_table_attach (GTK_TABLE (table
), ddisp
->canvas
, 1, 2, 1, 2,
388 GTK_EXPAND
| GTK_SHRINK
| GTK_FILL
,
389 GTK_EXPAND
| GTK_SHRINK
| GTK_FILL
, 0, 0);
390 gtk_table_attach (GTK_TABLE (table
), ddisp
->hsb
, 0, 2, 2, 3,
391 GTK_EXPAND
| GTK_SHRINK
| GTK_FILL
, GTK_FILL
, 0, 0);
392 gtk_table_attach (GTK_TABLE (table
), ddisp
->vsb
, 2, 3, 0, 2,
393 GTK_FILL
, GTK_EXPAND
| GTK_SHRINK
| GTK_FILL
, 0, 0);
395 menus_get_image_menu (NULL
, &ddisp
->accel_group
);
396 if (top_level_window
)
397 gtk_window_add_accel_group(GTK_WINDOW(ddisp
->shell
), ddisp
->accel_group
);
401 char *display
= "<DisplayMBar>";
403 menus_get_image_menubar(&ddisp
->menu_bar
, &ddisp
->mbar_item_factory
);
404 gtk_box_pack_start (GTK_BOX (root_vbox
), ddisp
->menu_bar
, FALSE
, TRUE
, 0);
406 path
= g_string_new (display
);
407 g_string_append (path
,"/View/Show Rulers");
408 ddisp
->rulers
= menus_get_item_from_path(path
->str
, ddisp
->mbar_item_factory
);
409 g_string_append (g_string_assign(path
, display
),"/View/Visible Grid");
410 ddisp
->visible_grid
= menus_get_item_from_path(path
->str
, ddisp
->mbar_item_factory
);
411 g_string_append (g_string_assign(path
, display
),"/View/Snap To Grid");
412 ddisp
->snap_to_grid
= menus_get_item_from_path(path
->str
, ddisp
->mbar_item_factory
);
413 g_string_append (g_string_assign(path
, display
),"/View/Show Connection Points");
414 ddisp
->show_cx_pts_mitem
= menus_get_item_from_path(path
->str
, ddisp
->mbar_item_factory
);
416 g_string_append(g_string_assign(path
, display
),"/View/AntiAliased");
417 ddisp
->antialiased
= menus_get_item_from_path(path
->str
, ddisp
->mbar_item_factory
);
420 menus_initialize_updatable_items (&ddisp
->updatable_menu_items
, ddisp
->mbar_item_factory
, display
);
421 g_string_free (path
,FALSE
);
425 status_hbox
= gtk_hbox_new (FALSE
, 2);
428 ddisp->snap_status = snap_status_load_images(ddisp->shell);
430 widget = gtk_button_new ();
431 gtk_container_add(GTK_CONTAINER(widget), ddisp->snap_status);
432 gtk_widget_show(ddisp->snap_status);
435 gtk_signal_connect(GTK_OBJECT(ddisp->origin), "button_press_event",
436 GTK_SIGNAL_FUNC(origin_button_press), ddisp);
438 #ifdef WITHOUT_ZOOM_COMBO
439 ddisp
->zoom_status
= gtk_statusbar_new ();
440 ddisp
->modified_status
= gtk_statusbar_new ();
441 gtk_box_pack_start (GTK_BOX (status_hbox
), ddisp
->zoom_status
,
444 ddisp
->zoom_status
= create_zoom_widget(ddisp
);
445 ddisp
->modified_status
= gtk_statusbar_new ();
447 zoom_hbox
= gtk_hbox_new(FALSE
, 0);
448 zoom_label
= gtk_label_new(_("Zoom"));
449 gtk_box_pack_start (GTK_BOX(zoom_hbox
), zoom_label
,
451 gtk_box_pack_start (GTK_BOX(zoom_hbox
), ddisp
->zoom_status
,
454 gtk_box_pack_start (GTK_BOX (status_hbox
), zoom_hbox
, FALSE
, FALSE
, 0);
457 gtk_table_attach (GTK_TABLE (table
), status_hbox
, 0, 3, 3, 4,
458 GTK_FILL
, GTK_FILL
, 0, 0);
460 gtk_box_pack_start (GTK_BOX (status_hbox
), ddisp
->modified_status
,
463 gtk_widget_show (ddisp
->hsb
);
464 gtk_widget_show (ddisp
->vsb
);
465 gtk_widget_show (ddisp
->origin
);
466 gtk_widget_show (ddisp
->hrule
);
467 gtk_widget_show (ddisp
->vrule
);
468 gtk_widget_show (ddisp
->canvas
);
469 gtk_widget_show (ddisp
->zoom_status
);
470 #ifndef WITHOUT_ZOOM_COMBO
471 gtk_widget_show (zoom_hbox
);
472 gtk_widget_show (zoom_label
);
474 gtk_widget_show (ddisp
->modified_status
);
475 gtk_widget_show (status_hbox
);
476 gtk_widget_show (table
);
479 gtk_widget_show (ddisp
->menu_bar
);
480 gtk_widget_show (root_vbox
);
482 gtk_widget_show (ddisp
->shell
);
484 /* set the focus to the canvas area */
485 gtk_widget_grab_focus (ddisp
->canvas
);
489 tool_select_update (GtkWidget
*w
,
492 ToolButtonData
*tooldata
= (ToolButtonData
*) data
;
494 if (tooldata
== NULL
) {
495 g_warning(_("NULL tooldata in tool_select_update"));
499 if (tooldata
->type
!= -1) {
500 tool_select (tooldata
->type
, tooldata
->extra_data
, tooldata
->user_data
,
506 tool_button_press (GtkWidget
*w
,
507 GdkEventButton
*event
,
510 ToolButtonData
*tooldata
= (ToolButtonData
*) data
;
512 if ((event
->type
== GDK_2BUTTON_PRESS
) &&
513 (event
->button
== 1)) {
514 tool_options_dialog_show (tooldata
->type
, tooldata
->extra_data
,
515 tooldata
->user_data
, w
);
523 tool_drag_data_get (GtkWidget
*widget
, GdkDragContext
*context
,
524 GtkSelectionData
*selection_data
, guint info
,
525 guint32 time
, ToolButtonData
*tooldata
)
528 gtk_selection_data_set(selection_data
, selection_data
->target
,
529 8, (guchar
*)&tooldata
, sizeof(ToolButtonData
*));
534 tool_setup_drag_source(GtkWidget
*button
, ToolButtonData
*tooldata
,
535 GdkPixmap
*pixmap
, GdkBitmap
*mask
)
537 g_return_if_fail(tooldata
->type
== CREATE_OBJECT_TOOL
);
539 gtk_drag_source_set(button
, GDK_BUTTON1_MASK
,
540 create_object_targets
, 1,
541 GDK_ACTION_DEFAULT
|GDK_ACTION_COPY
);
542 gtk_signal_connect(GTK_OBJECT(button
), "drag_data_get",
543 GTK_SIGNAL_FUNC(tool_drag_data_get
), tooldata
);
545 gtk_drag_source_set_icon(button
, gtk_widget_get_colormap(button
),
550 tool_select_callback(GtkWidget
*widget
, gpointer data
) {
551 ToolButtonData
*tooldata
= (ToolButtonData
*)data
;
553 if (tooldata
== NULL
) {
554 g_warning("NULL tooldata in tool_select_callback");
558 if (tooldata
->type
!= -1) {
559 tool_select (tooldata
->type
, tooldata
->extra_data
,
560 tooldata
->user_data
,widget
);
565 create_tools(GtkWidget
*parent
)
568 GtkWidget
*pixmapwidget
;
576 for (i
= 0; i
< NUM_TOOLS
; i
++) {
577 tool_widgets
[i
] = button
= gtk_radio_button_new (tool_group
);
578 gtk_container_set_border_width (GTK_CONTAINER (button
), 0);
579 tool_group
= gtk_radio_button_group (GTK_RADIO_BUTTON (button
));
580 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button
), FALSE
);
582 gtk_wrap_box_pack(GTK_WRAP_BOX(parent
), button
,
583 TRUE
, TRUE
, FALSE
, TRUE
);
585 if (tool_data
[i
].callback_data
.type
== MODIFY_TOOL
) {
586 modify_tool_button
= GTK_WIDGET(button
);
589 if (tool_data
[i
].icon_data
==NULL
) {
592 object_get_type((char *)tool_data
[i
].callback_data
.extra_data
);
594 pixmap_data
= tool_data
[0].icon_data
;
596 pixmap_data
= type
->pixmap
;
598 pixmap_data
= tool_data
[i
].icon_data
;
601 style
= gtk_widget_get_style(button
);
602 pixmap
= gdk_pixmap_colormap_create_from_xpm_d(NULL
,
603 gtk_widget_get_colormap(button
), &mask
,
604 &style
->bg
[GTK_STATE_NORMAL
], pixmap_data
);
606 pixmapwidget
= gtk_pixmap_new(pixmap
, mask
);
608 gtk_misc_set_padding(GTK_MISC(pixmapwidget
), 4, 4);
610 gtk_container_add (GTK_CONTAINER (button
), pixmapwidget
);
612 gtk_signal_connect (GTK_OBJECT (button
), "toggled",
613 GTK_SIGNAL_FUNC (tool_select_update
),
614 &tool_data
[i
].callback_data
);
616 gtk_signal_connect (GTK_OBJECT (button
), "button_press_event",
617 GTK_SIGNAL_FUNC (tool_button_press
),
618 &tool_data
[i
].callback_data
);
620 if (tool_data
[i
].callback_data
.type
== CREATE_OBJECT_TOOL
)
621 tool_setup_drag_source(button
, &tool_data
[i
].callback_data
,
624 gdk_pixmap_unref(pixmap
);
625 if (mask
) gdk_bitmap_unref(mask
);
627 tool_data
[i
].callback_data
.widget
= button
;
629 gtk_tooltips_set_tip (tool_tips
, button
,
630 gettext(tool_data
[i
].tool_desc
), NULL
);
632 gtk_widget_show (pixmapwidget
);
633 gtk_widget_show (button
);
637 static GtkWidget
*sheet_option_menu
;
638 static GtkWidget
*sheet_menu
;
639 static GtkWidget
*sheet_wbox
;
643 create_sheet_page(GtkWidget
*parent
, Sheet
*sheet
)
646 SheetObject
*sheet_obj
;
649 GtkWidget
*pixmapwidget
;
652 ToolButtonData
*data
;
654 GtkWidget
*scrolled_window
;
658 scrolled_window
= gtk_scrolled_window_new(NULL
, NULL
);
659 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scrolled_window
),
660 GTK_POLICY_AUTOMATIC
,
661 GTK_POLICY_AUTOMATIC
);
663 rows
= (g_slist_length(sheet
->objects
) - 1) / COLUMNS
+ 1;
667 table
= gtk_hwrap_box_new(FALSE
);
668 gtk_wrap_box_set_aspect_ratio(GTK_WRAP_BOX(table
), COLUMNS
* 1.0 / rows
);
669 gtk_wrap_box_set_justify(GTK_WRAP_BOX(table
), GTK_JUSTIFY_TOP
);
670 gtk_wrap_box_set_line_justify(GTK_WRAP_BOX(table
), GTK_JUSTIFY_LEFT
);
672 style
= gtk_widget_get_style(parent
);
675 list
= sheet
->objects
;
676 while (list
!= NULL
) {
677 sheet_obj
= (SheetObject
*) list
->data
;
680 if (sheet_obj
->pixmap
!= NULL
) {
681 pixmap
= gdk_pixmap_colormap_create_from_xpm_d(NULL
,
682 gtk_widget_get_colormap(parent
), &mask
,
683 &style
->bg
[GTK_STATE_NORMAL
], sheet_obj
->pixmap
);
684 } else if (sheet_obj
->pixmap_file
!= NULL
) {
685 pixmap
= gdk_pixmap_colormap_create_from_xpm(NULL
,
686 gtk_widget_get_colormap(parent
), &mask
,
687 &style
->bg
[GTK_STATE_NORMAL
], sheet_obj
->pixmap_file
);
690 type
= object_get_type(sheet_obj
->object_type
);
691 pixmap
= gdk_pixmap_colormap_create_from_xpm_d(NULL
,
692 gtk_widget_get_colormap(parent
), &mask
,
693 &style
->bg
[GTK_STATE_NORMAL
], type
->pixmap
);
696 pixmapwidget
= gtk_pixmap_new(pixmap
, mask
);
699 button
= gtk_radio_button_new (tool_group
);
700 gtk_container_set_border_width (GTK_CONTAINER (button
), 0);
701 tool_group
= gtk_radio_button_group (GTK_RADIO_BUTTON (button
));
703 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button
), FALSE
);
706 gtk_container_add (GTK_CONTAINER (button
), pixmapwidget
);
707 gtk_wrap_box_pack(GTK_WRAP_BOX(table
), button
,
708 FALSE
, TRUE
, FALSE
, TRUE
);
709 if (sheet_obj
->line_break
)
710 gtk_wrap_box_set_child_forced_break(GTK_WRAP_BOX(table
),button
,TRUE
);
712 /* This is a Memory leak, these can't be freed.
713 Doesn't matter much anyway... */
715 data
= g_new(ToolButtonData
, 1);
716 data
->type
= CREATE_OBJECT_TOOL
;
717 data
->extra_data
= sheet_obj
->object_type
;
718 data
->user_data
= sheet_obj
->user_data
;
720 gtk_signal_connect (GTK_OBJECT (button
), "toggled",
721 GTK_SIGNAL_FUNC (tool_select_update
),
724 gtk_signal_connect (GTK_OBJECT (button
), "button_press_event",
725 GTK_SIGNAL_FUNC (tool_button_press
),
728 gtk_tooltips_set_tip (tool_tips
, button
,
729 gettext(sheet_obj
->description
), NULL
);
731 list
= g_slist_next(list
);
735 gtk_widget_show(table
);
736 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window
), table
);
738 return scrolled_window
;
743 fill_sheet_wbox(GtkWidget
*menu_item
, Sheet
*sheet
)
749 gtk_container_foreach(GTK_CONTAINER(sheet_wbox
),
750 (GtkCallback
)gtk_widget_destroy
, NULL
);
751 tool_group
= gtk_radio_button_group(GTK_RADIO_BUTTON(tool_widgets
[0]));
753 /* set the aspect ratio on the wbox */
754 rows
= (g_slist_length(sheet
->objects
) - 1) / COLUMNS
+ 1;
755 if (rows
<1) rows
= 1;
756 gtk_wrap_box_set_aspect_ratio(GTK_WRAP_BOX(sheet_wbox
),
757 COLUMNS
* 1.0 / rows
);
758 style
= gtk_widget_get_style(sheet_wbox
);
759 for (tmp
= sheet
->objects
; tmp
!= NULL
; tmp
= tmp
->next
) {
760 SheetObject
*sheet_obj
= tmp
->data
;
763 GtkWidget
*pixmapwidget
;
765 ToolButtonData
*data
;
767 if (sheet_obj
->pixmap
!= NULL
) {
768 pixmap
= gdk_pixmap_colormap_create_from_xpm_d(NULL
,
769 gtk_widget_get_colormap(sheet_wbox
), &mask
,
770 &style
->bg
[GTK_STATE_NORMAL
], sheet_obj
->pixmap
);
771 } else if (sheet_obj
->pixmap_file
!= NULL
) {
774 pixbuf
= gdk_pixbuf_new_from_file(sheet_obj
->pixmap_file
);
775 if (pixbuf
!= NULL
) {
776 gdk_pixbuf_render_pixmap_and_mask(pixbuf
, &pixmap
, &mask
, 1.0);
777 gdk_pixbuf_unref(pixbuf
);
781 type
= object_get_type(sheet_obj
->object_type
);
782 pixmap
= gdk_pixmap_colormap_create_from_xpm_d(NULL
,
783 gtk_widget_get_colormap(sheet_wbox
), &mask
,
784 &style
->bg
[GTK_STATE_NORMAL
], type
->pixmap
);
787 pixmapwidget
= gtk_pixmap_new(pixmap
, mask
);
788 gdk_pixmap_unref(pixmap
);
789 if (mask
) gdk_bitmap_unref(mask
);
791 pixmapwidget
= gtk_type_new(gtk_pixmap_get_type());
793 button
= gtk_radio_button_new (tool_group
);
794 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button
), FALSE
);
795 gtk_container_set_border_width (GTK_CONTAINER (button
), 0);
796 tool_group
= gtk_radio_button_group (GTK_RADIO_BUTTON (button
));
798 gtk_container_add (GTK_CONTAINER (button
), pixmapwidget
);
799 gtk_widget_show(pixmapwidget
);
801 gtk_wrap_box_pack(GTK_WRAP_BOX(sheet_wbox
), button
,
802 FALSE
, TRUE
, FALSE
, TRUE
);
803 gtk_widget_show(button
);
804 if (sheet_obj
->line_break
)
805 gtk_wrap_box_set_child_forced_break(GTK_WRAP_BOX(sheet_wbox
),
808 data
= g_new(ToolButtonData
, 1);
809 data
->type
= CREATE_OBJECT_TOOL
;
810 data
->extra_data
= sheet_obj
->object_type
;
811 data
->user_data
= sheet_obj
->user_data
;
812 gtk_object_set_data_full(GTK_OBJECT(button
), "Dia::ToolButtonData",
813 data
, (GdkDestroyNotify
)g_free
);
815 gtk_signal_connect (GTK_OBJECT (button
), "toggled",
816 GTK_SIGNAL_FUNC (tool_select_update
), data
);
817 gtk_signal_connect (GTK_OBJECT (button
), "button_press_event",
818 GTK_SIGNAL_FUNC (tool_button_press
), data
);
820 tool_setup_drag_source(button
, data
, pixmap
, mask
);
822 gtk_tooltips_set_tip (tool_tips
, button
,
823 gettext(sheet_obj
->description
), NULL
);
828 fill_sheet_menu(void)
832 gtk_container_foreach(GTK_CONTAINER(sheet_menu
),
833 (GtkCallback
)gtk_widget_destroy
, NULL
);
834 gtk_widget_ref(sheet_menu
);
835 gtk_option_menu_remove_menu(GTK_OPTION_MENU(sheet_option_menu
));
836 for (tmp
= get_sheets_list(); tmp
!= NULL
; tmp
= tmp
->next
) {
837 Sheet
*sheet
= tmp
->data
;
840 if (sheet
->objects
== NULL
)
843 menuitem
= gtk_menu_item_new_with_label(gettext(sheet
->name
));
844 gtk_signal_connect(GTK_OBJECT(menuitem
), "activate",
845 GTK_SIGNAL_FUNC(fill_sheet_wbox
), sheet
);
846 gtk_container_add(GTK_CONTAINER(sheet_menu
), menuitem
);
847 gtk_widget_show(menuitem
);
849 gtk_option_menu_set_menu(GTK_OPTION_MENU(sheet_option_menu
), sheet_menu
);
850 gtk_widget_unref(sheet_menu
);
851 gtk_menu_item_activate(
852 GTK_MENU_ITEM(GTK_OPTION_MENU(sheet_option_menu
)->menu_item
));
856 create_sheets(GtkWidget
*parent
)
858 GtkWidget
*separator
;
862 separator
= gtk_hseparator_new ();
863 /* add a bit of padding around the separator */
864 label
= gtk_vbox_new(FALSE
, 0);
865 gtk_box_pack_start(GTK_BOX(label
), separator
, TRUE
, TRUE
, 3);
866 gtk_widget_show(label
);
868 gtk_wrap_box_pack (GTK_WRAP_BOX(parent
), label
, TRUE
,TRUE
, FALSE
,FALSE
);
869 gtk_wrap_box_set_child_forced_break(GTK_WRAP_BOX(parent
), label
, TRUE
);
870 gtk_widget_show(separator
);
872 sheet_option_menu
= gtk_option_menu_new();
873 gtk_widget_set_usize(sheet_option_menu
, 20, -1);
874 sheet_menu
= gtk_menu_new();
875 gtk_option_menu_set_menu(GTK_OPTION_MENU(sheet_option_menu
), sheet_menu
);
876 gtk_wrap_box_pack(GTK_WRAP_BOX(parent
), sheet_option_menu
,
877 TRUE
, TRUE
, FALSE
, FALSE
);
878 gtk_wrap_box_set_child_forced_break(GTK_WRAP_BOX(parent
), sheet_option_menu
,
880 gtk_widget_show(sheet_option_menu
);
882 swin
= gtk_scrolled_window_new(NULL
, NULL
);
883 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin
),
884 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
885 gtk_wrap_box_pack(GTK_WRAP_BOX(parent
), swin
, TRUE
, TRUE
, TRUE
, TRUE
);
886 gtk_wrap_box_set_child_forced_break(GTK_WRAP_BOX(parent
), swin
, TRUE
);
887 gtk_widget_show(swin
);
889 sheet_wbox
= gtk_hwrap_box_new(FALSE
);
890 gtk_wrap_box_set_justify(GTK_WRAP_BOX(sheet_wbox
), GTK_JUSTIFY_TOP
);
891 gtk_wrap_box_set_line_justify(GTK_WRAP_BOX(sheet_wbox
), GTK_JUSTIFY_LEFT
);
892 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swin
), sheet_wbox
);
893 gtk_widget_show(sheet_wbox
);
899 create_color_area (GtkWidget
*parent
)
902 GtkWidget
*alignment
;
904 GtkWidget
*line_area
;
905 GdkPixmap
*default_pixmap
;
906 GdkPixmap
*swap_pixmap
;
911 gtk_widget_ensure_style(parent
);
912 style
= gtk_widget_get_style(parent
);
915 gdk_pixmap_colormap_create_from_xpm_d(NULL
,
916 gtk_widget_get_colormap(parent
), &mask
,
917 &style
->bg
[GTK_STATE_NORMAL
], default_xpm
);
919 gdk_pixmap_colormap_create_from_xpm_d(NULL
,
920 gtk_widget_get_colormap(parent
), &mask
,
921 &style
->bg
[GTK_STATE_NORMAL
], swap_xpm
);
923 frame
= gtk_frame_new (NULL
);
924 gtk_frame_set_shadow_type (GTK_FRAME (frame
), GTK_SHADOW_OUT
);
925 gtk_wrap_box_pack(GTK_WRAP_BOX(parent
), frame
, TRUE
, TRUE
, FALSE
, FALSE
);
926 gtk_wrap_box_set_child_forced_break(GTK_WRAP_BOX(parent
), frame
, TRUE
);
927 gtk_widget_realize (frame
);
929 hbox
= gtk_hbox_new (FALSE
, 1);
930 gtk_container_set_border_width (GTK_CONTAINER (hbox
), 0);
931 gtk_container_add (GTK_CONTAINER (frame
), hbox
);
934 alignment
= gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
935 gtk_container_set_border_width (GTK_CONTAINER (alignment
), 3);
937 col_area
= color_area_create (54, 42, default_pixmap
, swap_pixmap
);
938 gtk_container_add (GTK_CONTAINER (alignment
), col_area
);
941 gtk_box_pack_start (GTK_BOX (hbox
), alignment
, TRUE
, TRUE
, 0);
943 gtk_tooltips_set_tip (tool_tips
, col_area
, _("Foreground & background colors. The small black "
944 "and white squares reset colors. The small arrows swap colors. Double "
945 "click to change colors."),
948 gtk_widget_show (alignment
);
950 /* Linewidth area: */
951 alignment
= gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
952 gtk_container_set_border_width (GTK_CONTAINER (alignment
), 3);
954 line_area
= linewidth_area_create ();
955 gtk_container_add (GTK_CONTAINER (alignment
), line_area
);
956 gtk_box_pack_start (GTK_BOX (hbox
), alignment
, TRUE
, TRUE
, 0);
958 gtk_widget_show (alignment
);
960 gtk_widget_show (col_area
);
961 gtk_widget_show (line_area
);
962 gtk_widget_show (hbox
);
963 gtk_widget_show (frame
);
967 change_start_arrow_style(Arrow arrow
, gpointer user_data
)
969 attributes_set_default_start_arrow(arrow
);
972 change_end_arrow_style(Arrow arrow
, gpointer user_data
)
974 attributes_set_default_end_arrow(arrow
);
977 change_line_style(LineStyle lstyle
, real dash_length
, gpointer user_data
)
979 attributes_set_default_line_style(lstyle
, dash_length
);
983 create_lineprops_area(GtkWidget
*parent
)
987 chooser
= dia_arrow_chooser_new(TRUE
, change_start_arrow_style
, NULL
);
988 gtk_wrap_box_pack(GTK_WRAP_BOX(parent
), chooser
, FALSE
, TRUE
, FALSE
, TRUE
);
989 gtk_wrap_box_set_child_forced_break(GTK_WRAP_BOX(parent
), chooser
, TRUE
);
990 gtk_widget_show(chooser
);
992 chooser
= dia_line_chooser_new(change_line_style
, NULL
);
993 gtk_wrap_box_pack(GTK_WRAP_BOX(parent
), chooser
, TRUE
, TRUE
, FALSE
, TRUE
);
994 gtk_widget_show(chooser
);
996 chooser
= dia_arrow_chooser_new(FALSE
, change_end_arrow_style
, NULL
);
997 gtk_wrap_box_pack(GTK_WRAP_BOX(parent
), chooser
, FALSE
, TRUE
, FALSE
, TRUE
);
998 gtk_widget_show(chooser
);
1002 toolbox_delete (GtkWidget
*widget
, gpointer data
)
1004 if (!app_is_embedded())
1009 toolbox_destroy (GtkWidget
*widget
, gpointer data
)
1014 /* HB: file dnd stuff lent by The Gimp, not fully understood but working ...
1018 DIA_DND_TYPE_URI_LIST
,
1019 DIA_DND_TYPE_TEXT_PLAIN
,
1022 static GtkTargetEntry toolbox_target_table
[] =
1024 { "text/uri-list", 0, DIA_DND_TYPE_URI_LIST
},
1025 { "text/plain", 0, DIA_DND_TYPE_TEXT_PLAIN
}
1028 static guint toolbox_n_targets
= (sizeof (toolbox_target_table
) /
1029 sizeof (toolbox_target_table
[0]));
1032 dia_dnd_file_drag_data_received (GtkWidget
*widget
,
1033 GdkDragContext
*context
,
1036 GtkSelectionData
*data
,
1040 switch (context
->action
)
1042 case GDK_ACTION_DEFAULT
:
1043 case GDK_ACTION_COPY
:
1044 case GDK_ACTION_MOVE
:
1045 case GDK_ACTION_LINK
:
1046 case GDK_ACTION_ASK
:
1049 Diagram
*diagram
= NULL
;
1051 gchar
*sPath
= NULL
, *pFrom
, *pTo
;
1053 pFrom
= strstr((gchar
*) data
->data
, "file:");
1055 pFrom
+= 5; /* remove 'file:' */
1057 while (*pTo
!= 0 && *pTo
!= 0xd && *pTo
!= 0xa) pTo
++;
1058 sPath
= g_strndup(pFrom
, pTo
- pFrom
);
1060 diagram
= diagram_load (sPath
, NULL
);
1063 if (diagram
!= NULL
) {
1064 diagram_update_extents(diagram
);
1065 layer_dialog_set_diagram(diagram
);
1067 ddisp
= new_display(diagram
);
1070 pFrom
= strstr(pTo
, "file:");
1072 gtk_drag_finish (context
, TRUE
, FALSE
, time
);
1083 GtkWidget
*main_vbox
;
1086 GtkAccelGroup
*accel_group
;
1089 window
= gnome_app_new ("Dia", _("Diagram Editor"));
1091 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
1092 gtk_widget_ref (window
);
1093 gtk_window_set_title (GTK_WINDOW (window
), "Dia v" VERSION
);
1095 gtk_window_set_wmclass (GTK_WINDOW (window
), "toolbox_window",
1097 gtk_window_set_policy(GTK_WINDOW(window
), TRUE
, TRUE
, FALSE
);
1098 gtk_window_set_default_size(GTK_WINDOW(window
), 146, 349);
1100 gtk_signal_connect (GTK_OBJECT (window
), "delete_event",
1101 GTK_SIGNAL_FUNC (toolbox_delete
),
1104 gtk_signal_connect (GTK_OBJECT (window
), "destroy",
1105 GTK_SIGNAL_FUNC (toolbox_destroy
),
1108 main_vbox
= gtk_vbox_new (FALSE
, 1);
1109 gtk_container_set_border_width (GTK_CONTAINER (main_vbox
), 1);
1111 gnome_app_set_contents(GNOME_APP(window
), main_vbox
);
1113 gtk_container_add (GTK_CONTAINER (window
), main_vbox
);
1115 gtk_widget_show (main_vbox
);
1118 tool_tips
= gtk_tooltips_new ();
1120 /* gtk_tooltips_set_colors (tool_tips,
1122 &main_vbox->style->fg[GTK_STATE_NORMAL]);*/
1124 wrapbox
= gtk_hwrap_box_new(FALSE
);
1125 gtk_wrap_box_set_aspect_ratio(GTK_WRAP_BOX(wrapbox
), 144.0 / 318.0);
1126 gtk_wrap_box_set_justify(GTK_WRAP_BOX(wrapbox
), GTK_JUSTIFY_TOP
);
1127 gtk_wrap_box_set_line_justify(GTK_WRAP_BOX(wrapbox
), GTK_JUSTIFY_LEFT
);
1130 /* pack the rest of the stuff */
1131 gtk_box_pack_end (GTK_BOX (main_vbox
), wrapbox
, TRUE
, TRUE
, 0);
1132 gtk_container_set_border_width (GTK_CONTAINER (wrapbox
), 0);
1133 gtk_widget_show (wrapbox
);
1135 create_tools (wrapbox
);
1136 create_sheets (wrapbox
);
1137 create_color_area (wrapbox
);
1138 create_lineprops_area (wrapbox
);
1140 /* Setup toolbox area as file drop destination */
1141 gtk_drag_dest_set (wrapbox
,
1142 GTK_DEST_DEFAULT_ALL
,
1143 toolbox_target_table
, toolbox_n_targets
,
1145 gtk_signal_connect (GTK_OBJECT (wrapbox
), "drag_data_received",
1146 GTK_SIGNAL_FUNC (dia_dnd_file_drag_data_received
),
1149 /* menus -- initialised afterwards, because initing the display menus
1150 * uses the tool buttons*/
1151 menus_get_toolbox_menubar(&menubar
, &accel_group
);
1152 gtk_accel_group_attach (accel_group
, GTK_OBJECT (window
));
1154 gnome_app_set_menus(GNOME_APP(window
), GTK_MENU_BAR(menubar
));
1156 gtk_box_pack_start (GTK_BOX (main_vbox
), menubar
, FALSE
, TRUE
, 0);
1157 gtk_widget_show (menubar
);
1160 toolbox_shell
= window
;
1166 gtk_widget_show(toolbox_shell
);
1172 gtk_widget_hide(toolbox_shell
);
1176 create_tree_window(void)
1178 GtkCheckMenuItem
*item
= GTK_CHECK_MENU_ITEM
1179 (menus_get_item_from_path("<Toolbox>/File/Diagram tree", NULL
));
1180 create_diagram_tree_window(&prefs
.dia_tree
, GTK_WIDGET(item
));
1184 interface_get_toolbox_shell(void)
1186 return toolbox_shell
;