15
15
* You should have received a copy of the GNU General Public License
16
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
177
177
EggEditableToolbar *etoolbar)
179
179
int pos, toolbar_pos;
181
182
widget = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
182
183
g_return_if_fail (widget != NULL);
183
184
g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
185
pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (widget->parent),
186
parent = gtk_widget_get_parent (widget);
187
pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (parent),
186
188
GTK_TOOL_ITEM (widget));
187
toolbar_pos = get_toolbar_position (etoolbar, widget->parent);
189
toolbar_pos = get_toolbar_position (etoolbar, parent);
189
191
egg_toolbars_model_remove_item (etoolbar->priv->model,
190
192
toolbar_pos, pos);
198
200
GtkAction *action;
201
203
gtk_widget_hide (widget);
203
205
#if GTK_CHECK_VERSION (2, 16, 0)
204
206
action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
206
action = gtk_widget_get_action (widget);
208
action = gtk_widget_get_action (widget);
209
211
if (action == NULL) return;
211
213
flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
212
214
gtk_action_get_name (action));
213
215
if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
262
264
EggToolbarsModel *model;
263
265
const char *name;
266
269
g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
267
270
model = egg_editable_toolbar_get_model (etoolbar);
269
272
name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
270
273
if (name == NULL)
272
275
name = g_object_get_data (G_OBJECT (gtk_widget_get_parent (widget)), EGG_ITEM_NAME);
273
276
g_return_if_fail (name != NULL);
276
data = egg_toolbars_model_get_data (model, selection_data->target, name);
279
target = gtk_selection_data_get_target (selection_data);
280
data = egg_toolbars_model_get_data (model, target, name);
277
281
if (data != NULL)
279
gtk_selection_data_set (selection_data, selection_data->target, 8, (unsigned char *)data, strlen (data));
283
gtk_selection_data_set (selection_data, target, 8, (unsigned char *)data, strlen (data));
298
302
gdk_event_get_state (realevent, &event.state);
299
303
gdk_event_get_coords (realevent, &event.x, &event.y);
300
304
gdk_event_get_root_coords (realevent, &event.x_root, &event.y_root);
302
306
gtk_drag_begin (toolitem, list, GDK_ACTION_MOVE, 1, (GdkEvent *)&event);
303
307
gtk_target_list_unref (list);
308
312
EggEditableToolbar *etoolbar)
310
314
GtkWidget *toolitem = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM);
315
GtkWidget *parent = gtk_widget_get_parent (toolitem);
311
316
int pos, toolbar_pos;
313
toolbar_pos = get_toolbar_position (etoolbar, toolitem->parent);
314
pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolitem->parent),
318
toolbar_pos = get_toolbar_position (etoolbar, parent);
319
pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (parent),
315
320
GTK_TOOL_ITEM (toolitem));
317
322
egg_toolbars_model_remove_item (etoolbar->priv->model,
353
358
if (etoolbar->priv->popup_path != NULL)
357
362
egg_editable_toolbar_set_selected (etoolbar, toolbar);
358
363
g_object_notify (G_OBJECT (etoolbar), "selected");
360
menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
365
menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
361
366
etoolbar->priv->popup_path));
362
367
g_return_if_fail (menu != NULL);
363
368
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button_number, gtk_get_current_event_time ());
375
380
if (event->button == 3 && etoolbar->priv->popup_path != NULL)
379
384
egg_editable_toolbar_set_selected (etoolbar, widget);
380
385
g_object_notify (G_OBJECT (etoolbar), "selected");
382
menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
387
menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
383
388
etoolbar->priv->popup_path));
384
389
g_return_val_if_fail (menu != NULL, FALSE);
385
390
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, event->time);
386
391
g_signal_connect_object (menu, "selection-done",
387
392
G_CALLBACK (popup_context_deactivate),
399
404
GtkAction *action;
402
407
name = g_object_get_data (G_OBJECT (item), EGG_ITEM_NAME);
403
408
action = name ? find_action (etoolbar, name) : NULL;
407
412
g_object_notify (G_OBJECT (action), "sensitive");
410
415
gtk_tool_item_set_use_drag_window (item,
411
(etoolbar->priv->edit_mode > 0) ||
416
(etoolbar->priv->edit_mode > 0) ||
412
417
GTK_IS_SEPARATOR_TOOL_ITEM (item));
429
435
GdkPixbuf *pixbuf = NULL;
431
437
screen = gtk_widget_get_screen (GTK_WIDGET (etoolbar));
433
439
cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen),
435
gdk_window_set_cursor (widget->window, cursor);
436
gdk_cursor_unref (cursor);
441
gdk_window_set_cursor (window, cursor);
442
g_object_unref (cursor);
438
444
gtk_drag_source_set (widget, GDK_BUTTON1_MASK, dest_drag_types,
439
445
G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE);
480
486
MIN (width, height), 0, NULL);
482
488
else if (stock_id)
484
pixbuf = gtk_widget_render_icon (widget, stock_id,
485
GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
490
pixbuf = gtk_widget_render_icon_pixbuf (widget, stock_id,
491
GTK_ICON_SIZE_LARGE_TOOLBAR);
487
493
g_free (icon_name);
488
494
g_free (stock_id);
535
541
if (GTK_IS_TOOL_ITEM (proxy))
537
543
g_signal_connect_object (proxy, "drag_begin",
538
G_CALLBACK (drag_begin_cb),
544
G_CALLBACK (drag_begin_cb),
540
546
g_signal_connect_object (proxy, "drag_end",
541
547
G_CALLBACK (drag_end_cb),
543
549
g_signal_connect_object (proxy, "drag_data_get",
544
G_CALLBACK (drag_data_get_cb),
550
G_CALLBACK (drag_data_get_cb),
546
552
g_signal_connect_object (proxy, "drag_data_delete",
547
553
G_CALLBACK (drag_data_delete_cb),
551
557
if (GTK_IS_BUTTON (proxy) || GTK_IS_TOOL_ITEM (proxy))
553
559
g_signal_connect_object (proxy, "button-press-event",
642
648
* actually add a new item to the toolbar.
645
GdkAtom type = selection_data->type;
646
const char *data = (char *)selection_data->data;
651
GdkAtom type = gtk_selection_data_get_data_type (selection_data);
652
const char *data = (char *)gtk_selection_data_get_data (selection_data);
649
655
char *name = NULL;
650
656
gboolean used = FALSE;
652
658
/* Find out where the drop is occuring, and the name of what is being dropped. */
653
if (selection_data->length >= 0)
659
if (gtk_selection_data_get_length (selection_data) >= 0)
655
661
ipos = gtk_toolbar_get_drop_index (toolbar, x, y);
656
662
name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, FALSE);
677
683
gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
678
684
etoolbar->priv->dnd_toolbar = NULL;
679
685
etoolbar->priv->dnd_toolitem = NULL;
681
687
/* If we don't have a name to use yet, try to create one. */
682
if (name == NULL && selection_data->length >= 0)
688
if (name == NULL && gtk_selection_data_get_length (selection_data) >= 0)
684
690
name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, TRUE);
687
693
if (name != NULL && !used)
689
695
gint tpos = get_toolbar_position (etoolbar, GTK_WIDGET (toolbar));
690
696
egg_toolbars_model_add_item (etoolbar->priv->model, tpos, ipos, name);
691
gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
697
gtk_drag_finish (context, TRUE,
698
gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
695
gtk_drag_finish (context, FALSE, context->action == GDK_ACTION_MOVE, time);
702
gtk_drag_finish (context, FALSE,
703
gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
784
792
gtk_drag_dest_set (GTK_WIDGET (toolbar), 0,
785
793
dest_drag_types, G_N_ELEMENTS (dest_drag_types),
786
794
GDK_ACTION_MOVE | GDK_ACTION_COPY);
788
796
/* Add any specialist drag-drop abilities. */
789
797
targets = gtk_drag_dest_get_target_list (GTK_WIDGET (toolbar));
790
798
list = egg_toolbars_model_get_types (etoolbar->priv->model);
865
873
priv->visibility_actions = g_ptr_array_new ();
868
876
if (priv->visibility_id != 0)
870
878
gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
873
881
priv->visibility_id = gtk_ui_manager_new_merge_id (priv->manager);
883
#if GTK_CHECK_VERSION(2,20,0)
884
showing = gtk_widget_get_visible (GTK_WIDGET (etoolbar));
875
886
showing = GTK_WIDGET_VISIBLE (etoolbar);
877
889
n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
878
890
for (i = 0; i < n_toolbars; i++)
951
963
g_object_set (action, "label", action_label, NULL);
954
gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
966
gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
955
967
& EGG_TB_MODEL_NOT_REMOVABLE) == 0);
956
968
gtk_action_set_sensitive (GTK_ACTION (action), showing);
969
#if GTK_CHECK_VERSION(2,20,0)
970
gtk_toggle_action_set_active (action, gtk_widget_get_visible
971
(get_dock_nth (etoolbar, i)));
957
973
gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
958
974
(get_dock_nth (etoolbar, i)));
960
977
for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
962
979
gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
963
980
(const char *)list->data, action_name, action_name,
964
981
GTK_UI_MANAGER_MENUITEM, FALSE);
967
984
g_free (action_label);
970
987
gtk_ui_manager_ensure_update (priv->manager);
972
989
while (i < priv->visibility_actions->len)
974
991
action = g_ptr_array_index (priv->visibility_actions, i);
991
1008
gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
993
1010
g_signal_connect (toolbar, "drag_drop",
994
G_CALLBACK (toolbar_drag_drop_cb), etoolbar);
1011
G_CALLBACK (toolbar_drag_drop_cb), etoolbar);
995
1012
g_signal_connect (toolbar, "drag_motion",
996
1013
G_CALLBACK (toolbar_drag_motion_cb), etoolbar);
997
1014
g_signal_connect (toolbar, "drag_leave",
1093
1110
toolbar = etoolbar->priv->fixed_toolbar;
1094
1111
dock = get_dock_nth (etoolbar, 0);
1096
if (dock && toolbar && toolbar->parent == NULL)
1113
if (dock && toolbar && gtk_widget_get_parent (toolbar) == NULL)
1098
1115
gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
1100
1117
gtk_widget_show (toolbar);
1102
1119
gtk_widget_set_size_request (dock, -1, -1);
1103
1120
gtk_widget_queue_resize_no_redraw (dock);
1161
1178
toolbar = get_toolbar_nth (etoolbar, tpos);
1162
1179
item = create_item_from_position (etoolbar, tpos, ipos);
1163
1180
if (item == NULL) return;
1165
1182
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, ipos);
1167
1184
connect_widget_signals (GTK_WIDGET (item), etoolbar);
1168
1185
configure_item_tooltip (item);
1169
1186
configure_item_cursor (item, etoolbar);
1170
1187
configure_item_sensitivity (item, etoolbar);
1172
1189
dock = get_dock_nth (etoolbar, tpos);
1173
1190
gtk_widget_set_size_request (dock, -1, -1);
1174
1191
gtk_widget_queue_resize_no_redraw (dock);
1727
1744
#define DEFAULT_ICON_HEIGHT 20
1728
#define DEFAULT_ICON_WIDTH 0
1731
fake_expose_widget (GtkWidget *widget,
1734
GdkWindow *tmp_window;
1735
GdkEventExpose event;
1737
event.type = GDK_EXPOSE;
1738
event.window = pixmap;
1739
event.send_event = FALSE;
1740
event.area = widget->allocation;
1741
event.region = NULL;
1744
tmp_window = widget->window;
1745
widget->window = pixmap;
1746
gtk_widget_send_expose (widget, (GdkEvent *) &event);
1747
widget->window = tmp_window;
1750
1746
/* We should probably experiment some more with this.
1751
1747
* Right now the rendered icon is pretty good for most
1758
1754
GtkWidget *window;
1759
1755
GdkPixbuf *pixbuf;
1760
GtkRequisition requisition;
1761
GtkAllocation allocation;
1765
1756
gint icon_height;
1766
1757
GdkScreen *screen;
1768
icon_width = DEFAULT_ICON_WIDTH;
1770
1759
screen = gtk_widget_get_screen (widget);
1772
1761
if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
1773
1762
GTK_ICON_SIZE_LARGE_TOOLBAR,
1777
1766
icon_height = DEFAULT_ICON_HEIGHT;
1780
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1769
window = gtk_offscreen_window_new ();
1770
/* Set the width to -1 as we want the separator to be as thin as possible. */
1771
gtk_widget_set_size_request (widget, -1, icon_height);
1782
1773
gtk_container_add (GTK_CONTAINER (window), widget);
1783
gtk_widget_realize (window);
1784
gtk_widget_show (widget);
1785
gtk_widget_realize (widget);
1786
gtk_widget_map (widget);
1788
/* Gtk will never set the width or height of a window to 0. So setting the width to
1789
* 0 and than getting it will provide us with the minimum width needed to render
1790
* the icon correctly, without any additional window background noise.
1791
* This is needed mostly for pixmap based themes.
1793
gtk_window_set_default_size (GTK_WINDOW (window), icon_width, icon_height);
1794
gtk_window_get_size (GTK_WINDOW (window),&icon_width, &icon_height);
1796
gtk_widget_size_request (window, &requisition);
1799
allocation.width = icon_width;
1800
allocation.height = icon_height;
1801
gtk_widget_size_allocate (window, &allocation);
1802
gtk_widget_size_request (window, &requisition);
1804
/* Create a pixmap */
1805
visual = gtk_widget_get_visual (window);
1806
pixmap = gdk_pixmap_new (NULL, icon_width, icon_height, visual->depth);
1807
gdk_drawable_set_colormap (GDK_DRAWABLE (pixmap), gtk_widget_get_colormap (window));
1809
/* Draw the window */
1810
gtk_widget_ensure_style (window);
1811
g_assert (window->style);
1812
g_assert (window->style->font_desc);
1814
fake_expose_widget (window, pixmap);
1815
fake_expose_widget (widget, pixmap);
1817
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, icon_width, icon_height);
1818
gdk_pixbuf_get_from_drawable (pixbuf, pixmap, NULL, 0, 0, 0, 0, icon_width, icon_height);
1774
gtk_widget_show_all (window);
1776
/* Process the waiting events to have the widget actually drawn */
1777
gdk_window_process_updates (gtk_widget_get_window (window), TRUE);
1778
pixbuf = gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (window));
1820
1779
gtk_widget_destroy (window);