454
gimp_scale_entry_unconstrained_adjustment_callback (GtkAdjustment *adjustment,
455
GtkAdjustment *other_adj)
457
g_signal_handlers_block_by_func (other_adj,
458
gimp_scale_entry_unconstrained_adjustment_callback,
461
gtk_adjustment_set_value (other_adj, adjustment->value);
463
g_signal_handlers_unblock_by_func (other_adj,
464
gimp_scale_entry_unconstrained_adjustment_callback,
469
gimp_scale_entry_exp_adjustment_callback (GtkAdjustment *, GtkAdjustment *);
472
gimp_scale_entry_log_adjustment_callback (GtkAdjustment *adjustment,
473
GtkAdjustment *other_adj)
477
g_signal_handlers_block_by_func (other_adj,
478
gimp_scale_entry_exp_adjustment_callback,
480
if (adjustment->lower <= 0.0)
481
value = log (adjustment->value - adjustment->lower + 0.1);
483
value = log (adjustment->value);
485
gtk_adjustment_set_value (other_adj, value);
487
g_signal_handlers_unblock_by_func (other_adj,
488
gimp_scale_entry_exp_adjustment_callback,
493
gimp_scale_entry_exp_adjustment_callback (GtkAdjustment *adjustment,
494
GtkAdjustment *other_adj)
498
g_signal_handlers_block_by_func (other_adj,
499
gimp_scale_entry_log_adjustment_callback,
502
value = exp (adjustment->value);
503
if (other_adj->lower <= 0.0)
504
value += other_adj->lower - 0.1;
506
gtk_adjustment_set_value (other_adj, value);
508
g_signal_handlers_unblock_by_func (other_adj,
509
gimp_scale_entry_log_adjustment_callback,
514
gimp_scale_entry_new_internal (gboolean color_scale,
520
gint spinbutton_width,
524
gdouble step_increment,
525
gdouble page_increment,
528
gdouble unconstrained_lower,
529
gdouble unconstrained_upper,
530
const gchar *tooltip,
531
const gchar *help_id)
536
GtkWidget *spinbutton;
537
GtkObject *adjustment;
538
GtkObject *return_adj;
540
label = gtk_label_new_with_mnemonic (text);
541
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
545
ebox = g_object_new (GTK_TYPE_EVENT_BOX,
546
"visible-window", FALSE,
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);
553
gtk_container_add (GTK_CONTAINER (ebox), label);
558
gtk_table_attach (GTK_TABLE (table), label,
559
column, column + 1, row, row + 1,
560
GTK_FILL, GTK_FILL, 0, 0);
563
gtk_widget_show (label);
566
unconstrained_lower <= lower &&
567
unconstrained_upper >= upper)
569
GtkObject *constrained_adj;
571
constrained_adj = gtk_adjustment_new (value, lower, upper,
572
step_increment, page_increment,
575
spinbutton = gimp_spin_button_new (&adjustment, value,
578
step_increment, page_increment, 0.0,
582
(G_OBJECT (constrained_adj), "value-changed",
583
G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
587
(G_OBJECT (adjustment), "value-changed",
588
G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
591
return_adj = adjustment;
593
adjustment = constrained_adj;
597
spinbutton = gimp_spin_button_new (&adjustment, value, lower, upper,
598
step_increment, page_increment, 0.0,
601
return_adj = adjustment;
604
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
606
if (spinbutton_width > 0)
608
if (spinbutton_width < 17)
609
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), spinbutton_width);
611
gtk_widget_set_size_request (spinbutton, spinbutton_width, -1);
616
scale = gimp_color_scale_new (GTK_ORIENTATION_HORIZONTAL,
617
GIMP_COLOR_SELECTOR_VALUE);
619
gtk_range_set_adjustment (GTK_RANGE (scale),
620
GTK_ADJUSTMENT (adjustment));
624
scale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
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);
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);
641
if (tooltip || help_id)
644
gimp_help_set_help_data (ebox, tooltip, help_id);
646
gimp_help_set_help_data (scale, tooltip, help_id);
647
gimp_help_set_help_data (spinbutton, tooltip, help_id);
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);
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()).
683
* This function creates a #GtkLabel, a #GtkHScale and a #GtkSpinButton and
684
* attaches them to a 3-column #GtkTable.
686
* Returns: The #GtkSpinButton's #GtkAdjustment.
689
gimp_scale_entry_new (GtkTable *table,
694
gint spinbutton_width,
698
gdouble step_increment,
699
gdouble page_increment,
702
gdouble unconstrained_lower,
703
gdouble unconstrained_upper,
704
const gchar *tooltip,
705
const gchar *help_id)
707
return gimp_scale_entry_new_internal (FALSE,
709
text, scale_width, spinbutton_width,
711
step_increment, page_increment,
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()).
737
* This function creates a #GtkLabel, a #GimpColorScale and a
738
* #GtkSpinButton and attaches them to a 3-column #GtkTable.
740
* Returns: The #GtkSpinButton's #GtkAdjustment.
743
gimp_color_scale_entry_new (GtkTable *table,
748
gint spinbutton_width,
752
gdouble step_increment,
753
gdouble page_increment,
755
const gchar *tooltip,
756
const gchar *help_id)
758
return gimp_scale_entry_new_internal (TRUE,
760
text, scale_width, spinbutton_width,
762
step_increment, page_increment,
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
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
782
gimp_scale_entry_set_logarithmic (GtkObject *adjustment,
783
gboolean logarithmic)
786
GtkAdjustment *scale_adj;
788
gdouble log_value, log_lower, log_upper;
789
gdouble log_step_increment, log_page_increment;
791
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
793
adj = GTK_ADJUSTMENT (adjustment);
794
scale_adj = GIMP_SCALE_ENTRY_SCALE_ADJ (adjustment);
798
if (gimp_scale_entry_get_logarithmic (adjustment))
801
correction = scale_adj->lower > 0 ? 0 : 0.1 + - scale_adj->lower;
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 -
808
scale_adj->step_increment);
809
log_page_increment = (log_upper - log_lower) / ((scale_adj->upper -
811
scale_adj->page_increment);
813
if (scale_adj == adj)
819
lower = scale_adj->lower;
820
upper = scale_adj->upper;
821
new_adj = gtk_adjustment_new (scale_adj->value,
824
scale_adj->step_increment,
825
scale_adj->page_increment,
827
gtk_range_set_adjustment (GTK_RANGE (GIMP_SCALE_ENTRY_SCALE (adj)),
828
GTK_ADJUSTMENT (new_adj));
830
scale_adj = (GtkAdjustment *) new_adj;
834
g_signal_handlers_disconnect_by_func (adj,
835
G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
837
g_signal_handlers_disconnect_by_func (scale_adj,
838
G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
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;
848
g_signal_connect (scale_adj, "value-changed",
849
G_CALLBACK (gimp_scale_entry_exp_adjustment_callback),
852
g_signal_connect (adj, "value-changed",
853
G_CALLBACK (gimp_scale_entry_log_adjustment_callback),
856
g_object_set_data (G_OBJECT (adjustment),
857
"logarithmic", GINT_TO_POINTER (TRUE));
861
gdouble lower, upper;
863
if (! gimp_scale_entry_get_logarithmic (adjustment))
866
g_signal_handlers_disconnect_by_func (adj,
867
G_CALLBACK (gimp_scale_entry_log_adjustment_callback),
869
g_signal_handlers_disconnect_by_func (scale_adj,
870
G_CALLBACK (gimp_scale_entry_exp_adjustment_callback),
873
lower = exp (scale_adj->lower);
874
upper = exp (scale_adj->upper);
876
if (adj->lower <= 0.0)
878
lower += - 0.1 + adj->lower;
879
upper += - 0.1 + adj->lower;
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;
888
g_signal_connect (scale_adj, "value-changed",
889
G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
892
g_signal_connect (adj, "value-changed",
893
G_CALLBACK (gimp_scale_entry_unconstrained_adjustment_callback),
896
g_object_set_data (G_OBJECT (adjustment),
897
"logarithmic", GINT_TO_POINTER (FALSE));
902
* gimp_scale_entry_get_logarithmic:
903
* @adjustment: a #GtkAdjustment as returned by gimp_scale_entry_new()
905
* Return value: %TRUE if the the entry's scale widget will behave in
906
* logharithmic fashion, %FALSE for linear behaviour.
911
gimp_scale_entry_get_logarithmic (GtkObject *adjustment)
913
return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (adjustment),
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()
923
* Sets the sensitivity of the scale_entry's #GtkLabel, #GtkHScale and
927
gimp_scale_entry_set_sensitive (GtkObject *adjustment,
932
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
934
widget = GIMP_SCALE_ENTRY_LABEL (adjustment);
936
gtk_widget_set_sensitive (widget, sensitive);
938
widget = GIMP_SCALE_ENTRY_SCALE (adjustment);
940
gtk_widget_set_sensitive (widget, sensitive);
942
widget = GIMP_SCALE_ENTRY_SPINBUTTON (adjustment);
944
gtk_widget_set_sensitive (widget, sensitive);
948
454
gimp_random_seed_update (GtkWidget *widget,