~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to libgimpwidgets/gimpwidgets.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: james.westby@ubuntu.com-20081006133041-3panbkcanaymfsmp
Tags: upstream-2.6.0
ImportĀ upstreamĀ versionĀ 2.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
451
451
}
452
452
 
453
453
static void
454
 
gimp_scale_entry_unconstrained_adjustment_callback (GtkAdjustment *adjustment,
455
 
                                                    GtkAdjustment *other_adj)
456
 
{
457
 
  g_signal_handlers_block_by_func (other_adj,
458
 
                                   gimp_scale_entry_unconstrained_adjustment_callback,
459
 
                                   adjustment);
460
 
 
461
 
  gtk_adjustment_set_value (other_adj, adjustment->value);
462
 
 
463
 
  g_signal_handlers_unblock_by_func (other_adj,
464
 
                                     gimp_scale_entry_unconstrained_adjustment_callback,
465
 
                                     adjustment);
466
 
}
467
 
 
468
 
static void
469
 
gimp_scale_entry_exp_adjustment_callback (GtkAdjustment *, GtkAdjustment *);
470
 
 
471
 
static void
472
 
gimp_scale_entry_log_adjustment_callback (GtkAdjustment *adjustment,
473
 
                                          GtkAdjustment *other_adj)
474
 
{
475
 
  gdouble value;
476
 
 
477
 
  g_signal_handlers_block_by_func (other_adj,
478
 
                                   gimp_scale_entry_exp_adjustment_callback,
479
 
                                   adjustment);
480
 
  if (adjustment->lower <= 0.0)
481
 
    value = log (adjustment->value - adjustment->lower + 0.1);
482
 
  else
483
 
    value = log (adjustment->value);
484
 
 
485
 
  gtk_adjustment_set_value (other_adj, value);
486
 
 
487
 
  g_signal_handlers_unblock_by_func (other_adj,
488
 
                                     gimp_scale_entry_exp_adjustment_callback,
489
 
                                     adjustment);
490
 
}
491
 
 
492
 
static void
493
 
gimp_scale_entry_exp_adjustment_callback (GtkAdjustment *adjustment,
494
 
                                          GtkAdjustment *other_adj)
495
 
{
496
 
  gdouble value;
497
 
 
498
 
  g_signal_handlers_block_by_func (other_adj,
499
 
                                   gimp_scale_entry_log_adjustment_callback,
500
 
                                   adjustment);
501
 
 
502
 
  value = exp (adjustment->value);
503
 
  if (other_adj->lower <= 0.0)
504
 
    value += other_adj->lower  - 0.1;
505
 
 
506
 
  gtk_adjustment_set_value (other_adj, value);
507
 
 
508
 
  g_signal_handlers_unblock_by_func (other_adj,
509
 
                                     gimp_scale_entry_log_adjustment_callback,
510
 
                                     adjustment);
511
 
}
512
 
 
513
 
static GtkObject *
514
 
gimp_scale_entry_new_internal (gboolean     color_scale,
515
 
                               GtkTable    *table,
516
 
                               gint         column,
517
 
                               gint         row,
518
 
                               const gchar *text,
519
 
                               gint         scale_width,
520
 
                               gint         spinbutton_width,
521
 
                               gdouble      value,
522
 
                               gdouble      lower,
523
 
                               gdouble      upper,
524
 
                               gdouble      step_increment,
525
 
                               gdouble      page_increment,
526
 
                               guint        digits,
527
 
                               gboolean     constrain,
528
 
                               gdouble      unconstrained_lower,
529
 
                               gdouble      unconstrained_upper,
530
 
                               const gchar *tooltip,
531
 
                               const gchar *help_id)
532
 
{
533
 
  GtkWidget *label;
534
 
  GtkWidget *ebox;
535
 
  GtkWidget *scale;
536
 
  GtkWidget *spinbutton;
537
 
  GtkObject *adjustment;
538
 
  GtkObject *return_adj;
539
 
 
540
 
  label = gtk_label_new_with_mnemonic (text);
541
 
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
542
 
 
543
 
  if (tooltip)
544
 
    {
545
 
      ebox = g_object_new (GTK_TYPE_EVENT_BOX,
546
 
                           "visible-window", FALSE,
547
 
                           NULL);
548
 
      gtk_table_attach (GTK_TABLE (table), ebox,
549
 
                        column, column + 1, row, row + 1,
550
 
                        GTK_FILL, GTK_FILL, 0, 0);
551
 
      gtk_widget_show (ebox);
552
 
 
553
 
      gtk_container_add (GTK_CONTAINER (ebox), label);
554
 
    }
555
 
  else
556
 
    {
557
 
      ebox = NULL;
558
 
      gtk_table_attach (GTK_TABLE (table), label,
559
 
                        column, column + 1, row, row + 1,
560
 
                        GTK_FILL, GTK_FILL, 0, 0);
561
 
    }
562
 
 
563
 
  gtk_widget_show (label);
564
 
 
565
 
  if (! constrain &&
566
 
           unconstrained_lower <= lower &&
567
 
           unconstrained_upper >= upper)
568
 
    {
569
 
      GtkObject *constrained_adj;
570
 
 
571
 
      constrained_adj = gtk_adjustment_new (value, lower, upper,
572
 
                                            step_increment, page_increment,
573
 
                                            0.0);
574
 
 
575
 
      spinbutton = gimp_spin_button_new (&adjustment, value,
576
 
                                         unconstrained_lower,
577
 
                                         unconstrained_upper,
578
 
                                         step_increment, page_increment, 0.0,
579
 
                                         1.0, digits);
580
 
 
581
 
      g_signal_connect
582
 
        (G_OBJECT (constrained_adj), "value-changed",
583
 
         G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
584
 
         adjustment);
585
 
 
586
 
      g_signal_connect
587
 
        (G_OBJECT (adjustment), "value-changed",
588
 
         G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
589
 
         constrained_adj);
590
 
 
591
 
      return_adj = adjustment;
592
 
 
593
 
      adjustment = constrained_adj;
594
 
    }
595
 
  else
596
 
    {
597
 
      spinbutton = gimp_spin_button_new (&adjustment, value, lower, upper,
598
 
                                         step_increment, page_increment, 0.0,
599
 
                                         1.0, digits);
600
 
 
601
 
      return_adj = adjustment;
602
 
    }
603
 
 
604
 
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
605
 
 
606
 
  if (spinbutton_width > 0)
607
 
    {
608
 
      if (spinbutton_width < 17)
609
 
        gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), spinbutton_width);
610
 
      else
611
 
        gtk_widget_set_size_request (spinbutton, spinbutton_width, -1);
612
 
    }
613
 
 
614
 
  if (color_scale)
615
 
    {
616
 
      scale = gimp_color_scale_new (GTK_ORIENTATION_HORIZONTAL,
617
 
                                    GIMP_COLOR_SELECTOR_VALUE);
618
 
 
619
 
      gtk_range_set_adjustment (GTK_RANGE (scale),
620
 
                                GTK_ADJUSTMENT (adjustment));
621
 
    }
622
 
  else
623
 
    {
624
 
      scale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
625
 
    }
626
 
 
627
 
  if (scale_width > 0)
628
 
    gtk_widget_set_size_request (scale, scale_width, -1);
629
 
  gtk_scale_set_digits (GTK_SCALE (scale), digits);
630
 
  gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
631
 
  gtk_table_attach (GTK_TABLE (table), scale,
632
 
                    column + 1, column + 2, row, row + 1,
633
 
                    GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
634
 
  gtk_widget_show (scale);
635
 
 
636
 
  gtk_table_attach (GTK_TABLE (table), spinbutton,
637
 
                    column + 2, column + 3, row, row + 1,
638
 
                    GTK_SHRINK, GTK_SHRINK, 0, 0);
639
 
  gtk_widget_show (spinbutton);
640
 
 
641
 
  if (tooltip || help_id)
642
 
    {
643
 
      if (ebox)
644
 
        gimp_help_set_help_data (ebox, tooltip, help_id);
645
 
 
646
 
      gimp_help_set_help_data (scale, tooltip, help_id);
647
 
      gimp_help_set_help_data (spinbutton, tooltip, help_id);
648
 
    }
649
 
 
650
 
  g_object_set_data (G_OBJECT (return_adj), "label",      label);
651
 
  g_object_set_data (G_OBJECT (return_adj), "scale",      scale);
652
 
  g_object_set_data (G_OBJECT (return_adj), "spinbutton", spinbutton);
653
 
 
654
 
 
655
 
 
656
 
  return return_adj;
657
 
}
658
 
 
659
 
/**
660
 
 * gimp_scale_entry_new:
661
 
 * @table:               The #GtkTable the widgets will be attached to.
662
 
 * @column:              The column to start with.
663
 
 * @row:                 The row to attach the widgets.
664
 
 * @text:                The text for the #GtkLabel which will appear
665
 
 *                       left of the #GtkHScale.
666
 
 * @scale_width:         The minimum horizontal size of the #GtkHScale.
667
 
 * @spinbutton_width:    The minimum horizontal size of the #GtkSpinButton.
668
 
 * @value:               The initial value.
669
 
 * @lower:               The lower boundary.
670
 
 * @upper:               The upper boundary.
671
 
 * @step_increment:      The step increment.
672
 
 * @page_increment:      The page increment.
673
 
 * @digits:              The number of decimal digits.
674
 
 * @constrain:           %TRUE if the range of possible values of the
675
 
 *                       #GtkSpinButton should be the same as of the #GtkHScale.
676
 
 * @unconstrained_lower: The spinbutton's lower boundary
677
 
 *                       if @constrain == %FALSE.
678
 
 * @unconstrained_upper: The spinbutton's upper boundary
679
 
 *                       if @constrain == %FALSE.
680
 
 * @tooltip:             A tooltip message for the scale and the spinbutton.
681
 
 * @help_id:             The widgets' help_id (see gimp_help_set_help_data()).
682
 
 *
683
 
 * This function creates a #GtkLabel, a #GtkHScale and a #GtkSpinButton and
684
 
 * attaches them to a 3-column #GtkTable.
685
 
 *
686
 
 * Returns: The #GtkSpinButton's #GtkAdjustment.
687
 
 **/
688
 
GtkObject *
689
 
gimp_scale_entry_new (GtkTable    *table,
690
 
                      gint         column,
691
 
                      gint         row,
692
 
                      const gchar *text,
693
 
                      gint         scale_width,
694
 
                      gint         spinbutton_width,
695
 
                      gdouble      value,
696
 
                      gdouble      lower,
697
 
                      gdouble      upper,
698
 
                      gdouble      step_increment,
699
 
                      gdouble      page_increment,
700
 
                      guint        digits,
701
 
                      gboolean     constrain,
702
 
                      gdouble      unconstrained_lower,
703
 
                      gdouble      unconstrained_upper,
704
 
                      const gchar *tooltip,
705
 
                      const gchar *help_id)
706
 
{
707
 
  return gimp_scale_entry_new_internal (FALSE,
708
 
                                        table, column, row,
709
 
                                        text, scale_width, spinbutton_width,
710
 
                                        value, lower, upper,
711
 
                                        step_increment, page_increment,
712
 
                                        digits,
713
 
                                        constrain,
714
 
                                        unconstrained_lower,
715
 
                                        unconstrained_upper,
716
 
                                        tooltip, help_id);
717
 
}
718
 
 
719
 
/**
720
 
 * gimp_color_scale_entry_new:
721
 
 * @table:               The #GtkTable the widgets will be attached to.
722
 
 * @column:              The column to start with.
723
 
 * @row:                 The row to attach the widgets.
724
 
 * @text:                The text for the #GtkLabel which will appear
725
 
 *                       left of the #GtkHScale.
726
 
 * @scale_width:         The minimum horizontal size of the #GtkHScale.
727
 
 * @spinbutton_width:    The minimum horizontal size of the #GtkSpinButton.
728
 
 * @value:               The initial value.
729
 
 * @lower:               The lower boundary.
730
 
 * @upper:               The upper boundary.
731
 
 * @step_increment:      The step increment.
732
 
 * @page_increment:      The page increment.
733
 
 * @digits:              The number of decimal digits.
734
 
 * @tooltip:             A tooltip message for the scale and the spinbutton.
735
 
 * @help_id:             The widgets' help_id (see gimp_help_set_help_data()).
736
 
 *
737
 
 * This function creates a #GtkLabel, a #GimpColorScale and a
738
 
 * #GtkSpinButton and attaches them to a 3-column #GtkTable.
739
 
 *
740
 
 * Returns: The #GtkSpinButton's #GtkAdjustment.
741
 
 **/
742
 
GtkObject *
743
 
gimp_color_scale_entry_new (GtkTable    *table,
744
 
                            gint         column,
745
 
                            gint         row,
746
 
                            const gchar *text,
747
 
                            gint         scale_width,
748
 
                            gint         spinbutton_width,
749
 
                            gdouble      value,
750
 
                            gdouble      lower,
751
 
                            gdouble      upper,
752
 
                            gdouble      step_increment,
753
 
                            gdouble      page_increment,
754
 
                            guint        digits,
755
 
                            const gchar *tooltip,
756
 
                            const gchar *help_id)
757
 
{
758
 
  return gimp_scale_entry_new_internal (TRUE,
759
 
                                        table, column, row,
760
 
                                        text, scale_width, spinbutton_width,
761
 
                                        value, lower, upper,
762
 
                                        step_increment, page_increment,
763
 
                                        digits,
764
 
                                        TRUE, 0.0, 0.0,
765
 
                                        tooltip, help_id);
766
 
}
767
 
 
768
 
/**
769
 
 * gimp_scale_entry_set_logarithmic:
770
 
 * @adjustment:  a  #GtkAdjustment as returned by gimp_scale_entry_new()
771
 
 * @logarithmic: a boolean value to set or reset logarithmic behaviour
772
 
 *               of the scale widget
773
 
 *
774
 
 * Sets whether the scale_entry's scale widget will behave in a linear
775
 
 * or logharithmic fashion. Useful when an entry has to attend large
776
 
 * ranges, but smaller selections on that range require a finer
777
 
 * adjustment.
778
 
 *
779
 
 * Since: GIMP 2.2
780
 
 **/
781
 
void
782
 
gimp_scale_entry_set_logarithmic (GtkObject *adjustment,
783
 
                                  gboolean   logarithmic)
784
 
{
785
 
  GtkAdjustment *adj;
786
 
  GtkAdjustment *scale_adj;
787
 
  gdouble        correction;
788
 
  gdouble        log_value, log_lower, log_upper;
789
 
  gdouble        log_step_increment, log_page_increment;
790
 
 
791
 
  g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
792
 
 
793
 
  adj       = GTK_ADJUSTMENT (adjustment);
794
 
  scale_adj = GIMP_SCALE_ENTRY_SCALE_ADJ (adjustment);
795
 
 
796
 
  if (logarithmic)
797
 
    {
798
 
      if (gimp_scale_entry_get_logarithmic (adjustment))
799
 
        return;
800
 
 
801
 
      correction = scale_adj->lower > 0 ? 0 : 0.1 + - scale_adj->lower;
802
 
 
803
 
      log_value = log (scale_adj->value + correction);
804
 
      log_lower = log (scale_adj->lower + correction);
805
 
      log_upper = log (scale_adj->upper + correction);
806
 
      log_step_increment = (log_upper - log_lower) / ((scale_adj->upper -
807
 
                                                       scale_adj->lower) /
808
 
                                                      scale_adj->step_increment);
809
 
      log_page_increment = (log_upper - log_lower) / ((scale_adj->upper -
810
 
                                                       scale_adj->lower) /
811
 
                                                      scale_adj->page_increment);
812
 
 
813
 
      if (scale_adj == adj)
814
 
        {
815
 
          GtkObject *new_adj;
816
 
          gdouble    lower;
817
 
          gdouble    upper;
818
 
 
819
 
          lower = scale_adj->lower;
820
 
          upper = scale_adj->upper;
821
 
          new_adj = gtk_adjustment_new (scale_adj->value,
822
 
                                        scale_adj->lower,
823
 
                                        scale_adj->upper,
824
 
                                        scale_adj->step_increment,
825
 
                                        scale_adj->page_increment,
826
 
                                        0.0);
827
 
          gtk_range_set_adjustment (GTK_RANGE (GIMP_SCALE_ENTRY_SCALE (adj)),
828
 
                                    GTK_ADJUSTMENT (new_adj));
829
 
 
830
 
          scale_adj = (GtkAdjustment *) new_adj;
831
 
         }
832
 
       else
833
 
         {
834
 
           g_signal_handlers_disconnect_by_func (adj,
835
 
                                                 G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
836
 
                                                 scale_adj);
837
 
           g_signal_handlers_disconnect_by_func (scale_adj,
838
 
                                                 G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
839
 
                                                 adj);
840
 
         }
841
 
 
842
 
       scale_adj->value          = log_value;
843
 
       scale_adj->lower          = log_lower;
844
 
       scale_adj->upper          = log_upper;
845
 
       scale_adj->step_increment = log_step_increment;
846
 
       scale_adj->page_increment = log_page_increment;
847
 
 
848
 
       g_signal_connect (scale_adj, "value-changed",
849
 
                         G_CALLBACK (gimp_scale_entry_exp_adjustment_callback),
850
 
                         adj);
851
 
 
852
 
       g_signal_connect (adj, "value-changed",
853
 
                         G_CALLBACK (gimp_scale_entry_log_adjustment_callback),
854
 
                         scale_adj);
855
 
 
856
 
       g_object_set_data (G_OBJECT (adjustment),
857
 
                          "logarithmic", GINT_TO_POINTER (TRUE));
858
 
    }
859
 
  else
860
 
    {
861
 
      gdouble lower, upper;
862
 
 
863
 
      if (! gimp_scale_entry_get_logarithmic (adjustment))
864
 
        return;
865
 
 
866
 
      g_signal_handlers_disconnect_by_func (adj,
867
 
                                            G_CALLBACK (gimp_scale_entry_log_adjustment_callback),
868
 
                                            scale_adj);
869
 
      g_signal_handlers_disconnect_by_func (scale_adj,
870
 
                                            G_CALLBACK (gimp_scale_entry_exp_adjustment_callback),
871
 
                                            adj);
872
 
 
873
 
      lower = exp (scale_adj->lower);
874
 
      upper = exp (scale_adj->upper);
875
 
 
876
 
      if (adj->lower <= 0.0)
877
 
        {
878
 
          lower += - 0.1  + adj->lower;
879
 
          upper += - 0.1  + adj->lower;
880
 
        }
881
 
 
882
 
      scale_adj->value          = adj->value;
883
 
      scale_adj->lower          = lower;
884
 
      scale_adj->upper          = upper;
885
 
      scale_adj->step_increment = adj->step_increment;
886
 
      scale_adj->page_increment = adj->page_increment;
887
 
 
888
 
      g_signal_connect (scale_adj, "value-changed",
889
 
                        G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
890
 
                        adj);
891
 
 
892
 
      g_signal_connect (adj, "value-changed",
893
 
                        G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
894
 
                        scale_adj);
895
 
 
896
 
      g_object_set_data (G_OBJECT (adjustment),
897
 
                         "logarithmic", GINT_TO_POINTER (FALSE));
898
 
    }
899
 
}
900
 
 
901
 
/**
902
 
 * gimp_scale_entry_get_logarithmic:
903
 
 * @adjustment: a  #GtkAdjustment as returned by gimp_scale_entry_new()
904
 
 *
905
 
 * Return value: %TRUE if the the entry's scale widget will behave in
906
 
 *               logharithmic fashion, %FALSE for linear behaviour.
907
 
 *
908
 
 * Since: GIMP 2.2
909
 
 **/
910
 
gboolean
911
 
gimp_scale_entry_get_logarithmic (GtkObject *adjustment)
912
 
{
913
 
  return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (adjustment),
914
 
                                             "logarithmic"));
915
 
}
916
 
 
917
 
/**
918
 
 * gimp_scale_entry_set_sensitive:
919
 
 * @adjustment: a #GtkAdjustment returned by gimp_scale_entry_new()
920
 
 * @sensitive:  a boolean value with the same semantics as the @sensitive
921
 
 *              parameter of gtk_widget_set_sensitive()
922
 
 *
923
 
 * Sets the sensitivity of the scale_entry's #GtkLabel, #GtkHScale and
924
 
 * #GtkSpinbutton.
925
 
 **/
926
 
void
927
 
gimp_scale_entry_set_sensitive (GtkObject *adjustment,
928
 
                                gboolean   sensitive)
929
 
{
930
 
  GtkWidget *widget;
931
 
 
932
 
  g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
933
 
 
934
 
  widget = GIMP_SCALE_ENTRY_LABEL (adjustment);
935
 
  if (widget)
936
 
    gtk_widget_set_sensitive (widget, sensitive);
937
 
 
938
 
  widget = GIMP_SCALE_ENTRY_SCALE (adjustment);
939
 
  if (widget)
940
 
    gtk_widget_set_sensitive (widget, sensitive);
941
 
 
942
 
  widget = GIMP_SCALE_ENTRY_SPINBUTTON (adjustment);
943
 
  if (widget)
944
 
    gtk_widget_set_sensitive (widget, sensitive);
945
 
}
946
 
 
947
 
static void
948
454
gimp_random_seed_update (GtkWidget *widget,
949
455
                         gpointer   data)
950
456
{
1007
513
                             "given \"random\" operation"), NULL);
1008
514
 
1009
515
  button = gtk_button_new_with_mnemonic (_("_New Seed"));
1010
 
  gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0);
 
516
  gtk_misc_set_padding (GTK_MISC (gtk_bin_get_child (GTK_BIN (button))), 2, 0);
1011
517
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
1012
518
  gtk_widget_show (button);
1013
519
 
1222
728
  GtkWidget           *sizeentry;
1223
729
  GtkWidget           *chainbutton;
1224
730
 
1225
 
  spinbutton = gimp_spin_button_new (&adjustment, 1, 0, 1, 1, 10, 1, 1, 2);
 
731
  spinbutton = gimp_spin_button_new (&adjustment, 1, 0, 1, 1, 10, 0, 1, 2);
1226
732
 
1227
733
  if (spinbutton_width > 0)
1228
734
    {
1469
975
{
1470
976
  gint *val = (gint *) data;
1471
977
 
1472
 
  *val = RINT (adjustment->value);
 
978
  *val = RINT (gtk_adjustment_get_value (adjustment));
1473
979
}
1474
980
 
1475
981
/**
1487
993
{
1488
994
  guint *val = (guint *) data;
1489
995
 
1490
 
  *val = (guint) (adjustment->value + 0.5);
 
996
  *val = (guint) (gtk_adjustment_get_value (adjustment) + 0.5);
1491
997
}
1492
998
 
1493
999
/**
1501
1007
                              gpointer       data)
1502
1008
{
1503
1009
  gfloat *val = (gfloat *) data;
1504
 
  *val = adjustment->value;
 
1010
 
 
1011
  *val = gtk_adjustment_get_value (adjustment);
1505
1012
 
1506
1013
}
1507
1014
 
1517
1024
{
1518
1025
  gdouble *val = (gdouble *) data;
1519
1026
 
1520
 
  *val = adjustment->value;
 
1027
  *val = gtk_adjustment_get_value (adjustment);
1521
1028
}
1522
1029
 
1523
1030
/**