~ubuntu-branches/ubuntu/oneiric/evince/oneiric-updates

« back to all changes in this revision

Viewing changes to cut-n-paste/toolbar-editor/egg-editable-toolbar.c

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2011-04-14 16:20:57 UTC
  • mfrom: (1.6.4 upstream)
  • mto: (1.3.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 138.
  • Revision ID: james.westby@ubuntu.com-20110414162057-0ofhbd139zs6ev6y
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *
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.
18
18
 *
19
19
 *  $Id$
20
20
 */
66
66
  guint edit_mode;
67
67
  gboolean save_hidden;
68
68
  GtkWidget *fixed_toolbar;
69
 
  
 
69
 
70
70
  GtkWidget *selected;
71
71
  GtkActionGroup *actions;
72
 
  
 
72
 
73
73
  guint visibility_id;
74
74
  GList *visibility_paths;
75
75
  GPtrArray *visibility_actions;
100
100
static int
101
101
get_toolbar_position (EggEditableToolbar *etoolbar, GtkWidget *toolbar)
102
102
{
103
 
  return get_dock_position (etoolbar, toolbar->parent);
 
103
  return get_dock_position (etoolbar, gtk_widget_get_parent (toolbar));
104
104
}
105
105
 
106
106
static int
177
177
                     EggEditableToolbar *etoolbar)
178
178
{
179
179
  int pos, toolbar_pos;
 
180
  GtkWidget *parent;
180
181
 
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));
184
185
 
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);
188
190
 
189
191
  egg_toolbars_model_remove_item (etoolbar->priv->model,
190
192
                                  toolbar_pos, pos);
197
199
{
198
200
  GtkAction *action;
199
201
  gint flags;
200
 
  
 
202
 
201
203
  gtk_widget_hide (widget);
202
204
 
203
205
#if GTK_CHECK_VERSION (2, 16, 0)
204
206
  action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
205
207
#else
206
 
action = gtk_widget_get_action (widget);
 
208
  action = gtk_widget_get_action (widget);
207
209
#endif
208
210
 
209
211
  if (action == NULL) return;
210
 
  
 
212
 
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))
226
228
{
227
229
  GtkAction *action;
228
230
  gint flags;
229
 
 
 
231
 
230
232
  if (gtk_widget_get_parent (widget) != NULL)
231
233
    {
232
234
      gtk_widget_show (widget);
238
240
#endif
239
241
 
240
242
      if (action == NULL) return;
241
 
      
 
243
 
242
244
      flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
243
245
                                                 gtk_action_get_name (action));
244
246
      if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
262
264
  EggToolbarsModel *model;
263
265
  const char *name;
264
266
  char *data;
 
267
  GdkAtom target;
265
268
 
266
269
  g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
267
270
  model = egg_editable_toolbar_get_model (etoolbar);
268
 
  
 
271
 
269
272
  name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
270
273
  if (name == NULL)
271
274
    {
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);
274
277
    }
275
 
  
276
 
  data = egg_toolbars_model_get_data (model, selection_data->target, name);
 
278
 
 
279
  target = gtk_selection_data_get_target (selection_data);
 
280
  data = egg_toolbars_model_get_data (model, target, name);
277
281
  if (data != NULL)
278
282
    {
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));
280
284
      g_free (data);
281
285
    }
282
286
}
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);
301
 
    
 
305
 
302
306
  gtk_drag_begin (toolitem, list, GDK_ACTION_MOVE, 1, (GdkEvent *)&event);
303
307
  gtk_target_list_unref (list);
304
308
}
308
312
                EggEditableToolbar *etoolbar)
309
313
{
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;
312
 
      
313
 
  toolbar_pos = get_toolbar_position (etoolbar, toolitem->parent);
314
 
  pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolitem->parent), 
 
317
 
 
318
  toolbar_pos = get_toolbar_position (etoolbar, parent);
 
319
  pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (parent),
315
320
                                    GTK_TOOL_ITEM (toolitem));
316
321
 
317
322
  egg_toolbars_model_remove_item (etoolbar->priv->model,
353
358
  if (etoolbar->priv->popup_path != NULL)
354
359
    {
355
360
      GtkMenu *menu;
356
 
      
 
361
 
357
362
      egg_editable_toolbar_set_selected (etoolbar, toolbar);
358
363
      g_object_notify (G_OBJECT (etoolbar), "selected");
359
 
      
360
 
      menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager, 
 
364
 
 
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)
376
381
    {
377
382
      GtkMenu *menu;
378
 
      
 
383
 
379
384
      egg_editable_toolbar_set_selected (etoolbar, widget);
380
385
      g_object_notify (G_OBJECT (etoolbar), "selected");
381
 
        
382
 
      menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager, 
 
386
 
 
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),
388
393
                               etoolbar, 0);
389
 
      
 
394
 
390
395
      return TRUE;
391
396
    }
392
 
    
 
397
 
393
398
  return FALSE;
394
399
}
395
400
 
398
403
{
399
404
  GtkAction *action;
400
405
  char *name;
401
 
  
 
406
 
402
407
  name = g_object_get_data (G_OBJECT (item), EGG_ITEM_NAME);
403
408
  action = name ? find_action (etoolbar, name) : NULL;
404
 
  
 
409
 
405
410
  if (action)
406
411
    {
407
412
      g_object_notify (G_OBJECT (action), "sensitive");
408
413
    }
409
414
 
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));
413
 
  
 
418
 
414
419
}
415
420
 
416
421
static void
419
424
{
420
425
  EggEditableToolbarPrivate *priv = etoolbar->priv;
421
426
  GtkWidget *widget = GTK_WIDGET (item);
 
427
  GdkWindow *window = gtk_widget_get_window (widget);
422
428
 
423
 
  if (widget->window != NULL)
 
429
  if (window != NULL)
424
430
    {
425
431
      if (priv->edit_mode > 0)
426
432
        {
429
435
          GdkPixbuf *pixbuf = NULL;
430
436
 
431
437
          screen = gtk_widget_get_screen (GTK_WIDGET (etoolbar));
432
 
          
 
438
 
433
439
          cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen),
434
440
                                               GDK_HAND2);
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);
437
443
 
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);
481
487
                }
482
488
              else if (stock_id)
483
 
                {                
484
 
                  pixbuf = gtk_widget_render_icon (widget, stock_id,
485
 
                                                   GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
 
489
                {
 
490
                  pixbuf = gtk_widget_render_icon_pixbuf (widget, stock_id,
 
491
                                                          GTK_ICON_SIZE_LARGE_TOOLBAR);
486
492
                }
487
493
              g_free (icon_name);
488
494
              g_free (stock_id);
498
504
        }
499
505
      else
500
506
        {
501
 
          gdk_window_set_cursor (GTK_WIDGET(item)->window, NULL);
 
507
          gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET(item)), NULL);
502
508
        }
503
509
    }
504
510
}
535
541
  if (GTK_IS_TOOL_ITEM (proxy))
536
542
    {
537
543
      g_signal_connect_object (proxy, "drag_begin",
538
 
                               G_CALLBACK (drag_begin_cb), 
 
544
                               G_CALLBACK (drag_begin_cb),
539
545
                               etoolbar, 0);
540
546
      g_signal_connect_object (proxy, "drag_end",
541
547
                               G_CALLBACK (drag_end_cb),
542
548
                               etoolbar, 0);
543
549
      g_signal_connect_object (proxy, "drag_data_get",
544
 
                               G_CALLBACK (drag_data_get_cb), 
 
550
                               G_CALLBACK (drag_data_get_cb),
545
551
                               etoolbar, 0);
546
552
      g_signal_connect_object (proxy, "drag_data_delete",
547
553
                               G_CALLBACK (drag_data_delete_cb),
548
554
                               etoolbar, 0);
549
555
    }
550
 
    
 
556
 
551
557
  if (GTK_IS_BUTTON (proxy) || GTK_IS_TOOL_ITEM (proxy))
552
558
    {
553
559
      g_signal_connect_object (proxy, "button-press-event",
557
563
}
558
564
 
559
565
static void
560
 
action_sensitive_cb (GtkAction   *action, 
 
566
action_sensitive_cb (GtkAction   *action,
561
567
                     GParamSpec  *pspec,
562
568
                     GtkToolItem *item)
563
569
{
577
583
  GtkToolItem *item;
578
584
 
579
585
  g_return_val_if_fail (name != NULL, NULL);
580
 
  
 
586
 
581
587
  if (strcmp (name, "_separator") == 0)
582
588
    {
583
589
      item = gtk_separator_tool_item_new ();
586
592
    {
587
593
      GtkAction *action = find_action (etoolbar, name);
588
594
      if (action == NULL) return NULL;
589
 
        
 
595
 
590
596
      item = GTK_TOOL_ITEM (gtk_action_create_tool_item (action));
591
597
 
592
598
      /* Normally done on-demand by the GtkUIManager, but no
594
600
       */
595
601
      gtk_action_set_accel_group
596
602
        (action, gtk_ui_manager_get_accel_group(etoolbar->priv->manager));
597
 
     
 
603
 
598
604
      g_signal_connect_object (action, "notify::sensitive",
599
605
                               G_CALLBACK (action_sensitive_cb), item, 0);
600
606
    }
602
608
  gtk_widget_show (GTK_WIDGET (item));
603
609
 
604
610
  g_object_set_data_full (G_OBJECT (item), EGG_ITEM_NAME,
605
 
                          g_strdup (name), g_free);  
606
 
  
 
611
                          g_strdup (name), g_free);
 
612
 
607
613
  return item;
608
614
}
609
615
 
642
648
   *      actually add a new item to the toolbar.
643
649
   */
644
650
 
645
 
  GdkAtom type = selection_data->type;
646
 
  const char *data = (char *)selection_data->data;
647
 
  
 
651
  GdkAtom type = gtk_selection_data_get_data_type (selection_data);
 
652
  const char *data = (char *)gtk_selection_data_get_data (selection_data);
 
653
 
648
654
  int ipos = -1;
649
655
  char *name = NULL;
650
656
  gboolean used = FALSE;
651
 
  
 
657
 
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)
654
660
    {
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);
664
670
  if (etoolbar->priv->dnd_pending > 0)
665
671
    {
666
672
      etoolbar->priv->dnd_pending--;
667
 
      
 
673
 
668
674
      if (name != NULL && etoolbar->priv->dnd_toolbar == toolbar && !used)
669
675
        {
670
676
          etoolbar->priv->dnd_toolitem = create_item_from_action (etoolbar, name);
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;
680
 
  
 
686
 
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)
683
689
        {
684
690
          name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, TRUE);
685
691
        }
686
 
  
 
692
 
687
693
      if (name != NULL && !used)
688
694
        {
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);
692
699
        }
693
700
      else
694
 
        {  
695
 
          gtk_drag_finish (context, FALSE, context->action == GDK_ACTION_MOVE, time);
 
701
        {
 
702
          gtk_drag_finish (context, FALSE,
 
703
                           gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
696
704
        }
697
705
    }
698
 
        
 
706
 
699
707
  g_free (name);
700
708
}
701
709
 
715
723
      gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
716
724
      return TRUE;
717
725
    }
718
 
  
 
726
 
719
727
  return FALSE;
720
728
}
721
729
 
742
750
      etoolbar->priv->dnd_pending++;
743
751
      gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
744
752
    }
745
 
  
 
753
 
746
754
  /* If a highlight item is available, use it. */
747
755
  else if (etoolbar->priv->dnd_toolitem)
748
756
    {
751
759
                                           etoolbar->priv->dnd_toolitem, ipos);
752
760
    }
753
761
 
754
 
  gdk_drag_status (context, context->suggested_action, time);
 
762
  gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time);
755
763
 
756
764
  return TRUE;
757
765
}
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);
787
 
 
 
795
 
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);
806
814
  EggTbModelFlags flags;
807
815
  gboolean visible;
808
816
  gint i;
809
 
  
 
817
 
810
818
  visible = gtk_toggle_action_get_active (action);
811
819
  for (i = 0; i < priv->visibility_actions->len; i++)
812
820
    if (g_ptr_array_index (priv->visibility_actions, i) == action)
813
821
      break;
814
 
  
 
822
 
815
823
  g_return_if_fail (i < priv->visibility_actions->len);
816
 
  
817
 
  dock = get_dock_nth (etoolbar, i);  
 
824
 
 
825
  dock = get_dock_nth (etoolbar, i);
818
826
  if (visible)
819
827
    {
820
828
      gtk_widget_show (dock);
823
831
    {
824
832
      gtk_widget_hide (dock);
825
833
    }
826
 
  
 
834
 
827
835
  if (priv->save_hidden)
828
 
    {      
 
836
    {
829
837
      flags = egg_toolbars_model_get_flags (priv->model, i);
830
 
      
 
838
 
831
839
      if (visible)
832
840
        {
833
841
          flags &= ~(EGG_TB_MODEL_HIDDEN);
836
844
        {
837
845
          flags |=  (EGG_TB_MODEL_HIDDEN);
838
846
        }
839
 
      
 
847
 
840
848
      egg_toolbars_model_set_flags (priv->model, i, flags);
841
849
    }
842
850
}
852
860
  gboolean showing;
853
861
  char action_name[40];
854
862
  char *action_label;
855
 
  char *tmp;            
856
 
  
 
863
  char *tmp;
 
864
 
857
865
  if (priv == NULL || priv->model == NULL || priv->manager == NULL ||
858
866
      priv->visibility_paths == NULL || priv->actions == NULL)
859
867
    {
864
872
    {
865
873
      priv->visibility_actions = g_ptr_array_new ();
866
874
    }
867
 
  
 
875
 
868
876
  if (priv->visibility_id != 0)
869
877
    {
870
878
      gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
871
 
    }  
872
 
  
 
879
    }
 
880
 
873
881
  priv->visibility_id = gtk_ui_manager_new_merge_id (priv->manager);
874
 
  
 
882
 
 
883
#if GTK_CHECK_VERSION(2,20,0)
 
884
  showing = gtk_widget_get_visible (GTK_WIDGET (etoolbar));
 
885
#else
875
886
  showing = GTK_WIDGET_VISIBLE (etoolbar);
876
 
  
 
887
#endif
 
888
 
877
889
  n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
878
890
  for (i = 0; i < n_toolbars; i++)
879
891
    {
915
927
        {
916
928
          g_string_append (string, " ...");
917
929
        }
918
 
      
 
930
 
919
931
      tmp = g_string_free (string, FALSE);
920
932
      for (j = 0, k = 0; tmp[j]; j++)
921
933
      {
933
945
       * please remove. */
934
946
      action_label = g_strdup_printf (_("Show ā€œ_%sā€"), tmp);
935
947
      g_free (tmp);
936
 
      
 
948
 
937
949
      sprintf(action_name, "ToolbarToggle%d", i);
938
 
      
 
950
 
939
951
      if (i >= priv->visibility_actions->len)
940
952
        {
941
953
          action = gtk_toggle_action_new (action_name, action_label, NULL, NULL);
951
963
          g_object_set (action, "label", action_label, NULL);
952
964
        }
953
965
 
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)));
 
972
#else
957
973
      gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
958
974
                                    (get_dock_nth (etoolbar, i)));
959
 
      
 
975
#endif
 
976
 
960
977
      for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
961
978
        {
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);
965
982
        }
966
 
            
 
983
 
967
984
      g_free (action_label);
968
985
    }
969
 
  
 
986
 
970
987
  gtk_ui_manager_ensure_update (priv->manager);
971
 
  
 
988
 
972
989
  while (i < priv->visibility_actions->len)
973
990
    {
974
991
      action = g_ptr_array_index (priv->visibility_actions, i);
991
1008
  gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
992
1009
 
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",
1003
1020
                    G_CALLBACK (popup_context_menu_cb), etoolbar);
1004
1021
 
1005
1022
  configure_drag_dest (etoolbar, GTK_TOOLBAR (toolbar));
1006
 
  
 
1023
 
1007
1024
  return hbox;
1008
1025
}
1009
1026
 
1078
1095
  toolbar = etoolbar->priv->fixed_toolbar;
1079
1096
  dock = get_dock_nth (etoolbar, 0);
1080
1097
 
1081
 
  if (dock && toolbar->parent != NULL)
 
1098
  if (dock && gtk_widget_get_parent (toolbar) != NULL)
1082
1099
    {
1083
1100
      gtk_container_remove (GTK_CONTAINER (dock), toolbar);
1084
1101
    }
1093
1110
  toolbar = etoolbar->priv->fixed_toolbar;
1094
1111
  dock = get_dock_nth (etoolbar, 0);
1095
1112
 
1096
 
  if (dock && toolbar && toolbar->parent == NULL)
 
1113
  if (dock && toolbar && gtk_widget_get_parent (toolbar) == NULL)
1097
1114
    {
1098
1115
      gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
1099
1116
 
1100
1117
      gtk_widget_show (toolbar);
1101
 
  
 
1118
 
1102
1119
      gtk_widget_set_size_request (dock, -1, -1);
1103
1120
      gtk_widget_queue_resize_no_redraw (dock);
1104
1121
    }
1122
1139
  gtk_box_reorder_child (GTK_BOX (etoolbar), dock, position);
1123
1140
 
1124
1141
  gtk_widget_show_all (dock);
1125
 
  
 
1142
 
1126
1143
  update_fixed (etoolbar);
1127
1144
 
1128
1145
  toolbar_visibility_refresh (etoolbar);
1144
1161
  gtk_widget_destroy (dock);
1145
1162
 
1146
1163
  update_fixed (etoolbar);
1147
 
  
 
1164
 
1148
1165
  toolbar_visibility_refresh (etoolbar);
1149
1166
}
1150
1167
 
1161
1178
  toolbar = get_toolbar_nth (etoolbar, tpos);
1162
1179
  item = create_item_from_position (etoolbar, tpos, ipos);
1163
1180
  if (item == NULL) return;
1164
 
    
 
1181
 
1165
1182
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, ipos);
1166
 
  
 
1183
 
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);
1171
 
  
 
1188
 
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);
1183
1200
                 EggEditableToolbar *etoolbar)
1184
1201
{
1185
1202
  EggEditableToolbarPrivate *priv = etoolbar->priv;
1186
 
  
 
1203
 
1187
1204
  GtkWidget *toolbar;
1188
1205
  GtkWidget *item;
1189
1206
 
1232
1249
          if (item)
1233
1250
            {
1234
1251
              gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, l);
1235
 
              
 
1252
 
1236
1253
              connect_widget_signals (GTK_WIDGET (item), etoolbar);
1237
1254
              configure_item_tooltip (item);
1238
1255
              configure_item_sensitivity (item, etoolbar);
1338
1355
  priv = etoolbar->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (etoolbar);
1339
1356
 
1340
1357
  priv->save_hidden = TRUE;
1341
 
  
 
1358
 
1342
1359
  g_signal_connect (etoolbar, "notify::visible",
1343
1360
                    G_CALLBACK (toolbar_visibility_refresh), NULL);
1344
1361
}
1401
1418
    { "RemoveToolbar", GTK_STOCK_DELETE, N_("_Delete Toolbar"), NULL,
1402
1419
      N_("Remove the selected toolbar"), G_CALLBACK (remove_toolbar_cb) },
1403
1420
  };
1404
 
  
 
1421
 
1405
1422
  etoolbar->priv->manager = g_object_ref (manager);
1406
1423
 
1407
1424
  etoolbar->priv->actions = gtk_action_group_new ("ToolbarActions");
1427
1444
  gboolean editable;
1428
1445
 
1429
1446
  etoolbar->priv->selected = widget;
1430
 
  
 
1447
 
1431
1448
  toolbar = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) : NULL;
1432
1449
  toolitem = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) : NULL;
1433
 
  
 
1450
 
1434
1451
  if(toolbar != NULL)
1435
1452
    {
1436
1453
      gint tpos = get_toolbar_position (etoolbar, toolbar);
1440
1457
    {
1441
1458
      editable = FALSE;
1442
1459
    }
1443
 
  
 
1460
 
1444
1461
  gtk_action_set_visible (find_action (etoolbar, "RemoveToolbar"), (toolbar != NULL) && (etoolbar->priv->edit_mode > 0));
1445
1462
  gtk_action_set_visible (find_action (etoolbar, "RemoveToolItem"), (toolitem != NULL) && editable);
1446
1463
  gtk_action_set_visible (find_action (etoolbar, "MoveToolItem"), (toolitem != NULL) && editable);
1464
1481
      priv->edit_mode--;
1465
1482
    }
1466
1483
  i *= priv->edit_mode;
1467
 
  
 
1484
 
1468
1485
  if (i == 0)
1469
1486
    {
1470
1487
      for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--)
1471
1488
        {
1472
1489
          GtkWidget *toolbar;
1473
 
          
 
1490
 
1474
1491
          toolbar = get_toolbar_nth (etoolbar, i);
1475
1492
          n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
1476
1493
 
1479
1496
              egg_toolbars_model_remove_toolbar (priv->model, i);
1480
1497
            }
1481
1498
          else
1482
 
            {          
 
1499
            {
1483
1500
              for (l = 0; l < n_items; l++)
1484
1501
                {
1485
1502
                  GtkToolItem *item;
1486
 
              
 
1503
 
1487
1504
                  item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
1488
 
                  
 
1505
 
1489
1506
                  configure_item_cursor (item, etoolbar);
1490
1507
                  configure_item_sensitivity (item, etoolbar);
1491
1508
                }
1725
1742
}
1726
1743
 
1727
1744
#define DEFAULT_ICON_HEIGHT 20
1728
 
#define DEFAULT_ICON_WIDTH 0
1729
 
 
1730
 
static void
1731
 
fake_expose_widget (GtkWidget *widget,
1732
 
                    GdkPixmap *pixmap)
1733
 
{
1734
 
  GdkWindow *tmp_window;
1735
 
  GdkEventExpose event;
1736
 
 
1737
 
  event.type = GDK_EXPOSE;
1738
 
  event.window = pixmap;
1739
 
  event.send_event = FALSE;
1740
 
  event.area = widget->allocation;
1741
 
  event.region = NULL;
1742
 
  event.count = 0;
1743
 
 
1744
 
  tmp_window = widget->window;
1745
 
  widget->window = pixmap;
1746
 
  gtk_widget_send_expose (widget, (GdkEvent *) &event);
1747
 
  widget->window = tmp_window;
1748
 
}
1749
1745
 
1750
1746
/* We should probably experiment some more with this.
1751
1747
 * Right now the rendered icon is pretty good for most
1757
1753
{
1758
1754
  GtkWidget *window;
1759
1755
  GdkPixbuf *pixbuf;
1760
 
  GtkRequisition requisition;
1761
 
  GtkAllocation allocation;
1762
 
  GdkPixmap *pixmap;
1763
 
  GdkVisual *visual;
1764
 
  gint icon_width;
1765
1756
  gint icon_height;
1766
1757
  GdkScreen *screen;
1767
1758
 
1768
 
  icon_width = DEFAULT_ICON_WIDTH;
1769
 
 
1770
1759
  screen = gtk_widget_get_screen (widget);
1771
1760
 
1772
1761
  if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
1773
1762
                                          GTK_ICON_SIZE_LARGE_TOOLBAR,
1774
 
                                          NULL, 
 
1763
                                          NULL,
1775
1764
                                          &icon_height))
1776
1765
    {
1777
1766
      icon_height = DEFAULT_ICON_HEIGHT;
1778
1767
    }
1779
1768
 
1780
 
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1781
 
  
 
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);
 
1772
 
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);
1787
 
 
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.
1792
 
   */
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);
1795
 
 
1796
 
  gtk_widget_size_request (window, &requisition);
1797
 
  allocation.x = 0;
1798
 
  allocation.y = 0;
1799
 
  allocation.width = icon_width;
1800
 
  allocation.height = icon_height;
1801
 
  gtk_widget_size_allocate (window, &allocation);
1802
 
  gtk_widget_size_request (window, &requisition);
1803
 
  
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));
1808
 
 
1809
 
  /* Draw the window */
1810
 
  gtk_widget_ensure_style (window);
1811
 
  g_assert (window->style);
1812
 
  g_assert (window->style->font_desc);
1813
 
  
1814
 
  fake_expose_widget (window, pixmap);
1815
 
  fake_expose_widget (widget, pixmap);
1816
 
  
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);
1819
 
 
 
1774
  gtk_widget_show_all (window);
 
1775
 
 
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);
1821
1780
 
1822
1781
  return pixbuf;