[gthumb] resize image: added buttons to set to the original image size or the screen size



commit 3f81d8a65f3e349c792f8635cc5ef4b88a81b8ad
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Jul 13 11:43:15 2011 +0200

    resize image: added buttons to set to the original image size or the screen size
    
    [bug #639012]

 extensions/file_tools/data/ui/resize-options.ui |  391 +++++++++++++++--------
 extensions/file_tools/gth-file-tool-resize.c    |   90 +++++-
 2 files changed, 346 insertions(+), 135 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/resize-options.ui b/extensions/file_tools/data/ui/resize-options.ui
index c9da317..a29d5ec 100644
--- a/extensions/file_tools/data/ui/resize-options.ui
+++ b/extensions/file_tools/data/ui/resize-options.ui
@@ -1,144 +1,40 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <requires lib="gtk+" version="2.16"/>
-  <!-- interface-naming-policy project-wide -->
+  <requires lib="gtk+" version="2.24"/>
   <object class="GtkAlignment" id="options">
     <property name="visible">True</property>
+    <property name="can_focus">False</property>
     <property name="top_padding">6</property>
     <child>
       <object class="GtkVBox" id="vbox2">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
+        <property name="can_focus">False</property>
         <child>
           <object class="GtkVBox" id="vbox1">
             <property name="visible">True</property>
-            <property name="orientation">vertical</property>
+            <property name="can_focus">False</property>
             <property name="spacing">12</property>
             <child>
-              <object class="GtkFrame" id="frame2">
-                <property name="visible">True</property>
-                <property name="label_xalign">0</property>
-                <property name="shadow_type">none</property>
-                <child>
-                  <object class="GtkAlignment" id="alignment2">
-                    <property name="visible">True</property>
-                    <property name="top_padding">6</property>
-                    <property name="left_padding">12</property>
-                    <child>
-                      <object class="GtkTable" id="table1">
-                        <property name="visible">True</property>
-                        <property name="n_rows">3</property>
-                        <property name="n_columns">2</property>
-                        <property name="column_spacing">6</property>
-                        <property name="row_spacing">6</property>
-                        <child>
-                          <object class="GtkLabel" id="label2">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes">Original dimensions:</property>
-                          </object>
-                          <packing>
-                            <property name="x_options">GTK_FILL</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="label4">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes">Scale factor:</property>
-                          </object>
-                          <packing>
-                            <property name="top_attach">2</property>
-                            <property name="bottom_attach">3</property>
-                            <property name="x_options">GTK_FILL</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="original_dimensions_label">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label">label</property>
-                          </object>
-                          <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="scale_factor_label">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label">label</property>
-                          </object>
-                          <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                            <property name="top_attach">2</property>
-                            <property name="bottom_attach">3</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="label5">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes">New dimensions:</property>
-                          </object>
-                          <packing>
-                            <property name="top_attach">1</property>
-                            <property name="bottom_attach">2</property>
-                            <property name="x_options">GTK_FILL</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="new_dimensions_label">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label">label</property>
-                          </object>
-                          <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                            <property name="top_attach">1</property>
-                            <property name="bottom_attach">2</property>
-                          </packing>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-                <child type="label">
-                  <object class="GtkLabel" id="label1">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Information</property>
-                    <property name="use_markup">True</property>
-                    <attributes>
-                      <attribute name="weight" value="bold"/>
-                    </attributes>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
               <object class="GtkFrame" id="frame4">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="label_xalign">0</property>
                 <property name="shadow_type">none</property>
                 <child>
                   <object class="GtkAlignment" id="alignment12">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="top_padding">6</property>
                     <property name="left_padding">12</property>
                     <child>
                       <object class="GtkVBox" id="vbox10">
                         <property name="visible">True</property>
-                        <property name="orientation">vertical</property>
-                        <property name="spacing">6</property>
+                        <property name="can_focus">False</property>
+                        <property name="spacing">12</property>
                         <child>
                           <object class="GtkTable" id="table2">
                             <property name="visible">True</property>
+                            <property name="can_focus">False</property>
                             <property name="n_rows">2</property>
                             <property name="n_columns">3</property>
                             <property name="column_spacing">6</property>
@@ -146,6 +42,7 @@
                             <child>
                               <object class="GtkLabel" id="resize_width_label">
                                 <property name="visible">True</property>
+                                <property name="can_focus">False</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">_Width:</property>
                                 <property name="use_underline">True</property>
@@ -159,6 +56,7 @@
                             <child>
                               <object class="GtkLabel" id="resize_height_label">
                                 <property name="visible">True</property>
+                                <property name="can_focus">False</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">Heigh_t:</property>
                                 <property name="use_underline">True</property>
@@ -174,11 +72,12 @@
                             <child>
                               <object class="GtkHBox" id="hbox7">
                                 <property name="visible">True</property>
+                                <property name="can_focus">False</property>
                                 <child>
                                   <object class="GtkSpinButton" id="resize_width_spinbutton">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
-                                    <property name="invisible_char">&#x25CF;</property>
+                                    <property name="invisible_char">â</property>
                                     <property name="width_chars">6</property>
                                     <property name="adjustment">resize_width_adjustment</property>
                                     <property name="climb_rate">1</property>
@@ -202,11 +101,12 @@
                             <child>
                               <object class="GtkHBox" id="hbox8">
                                 <property name="visible">True</property>
+                                <property name="can_focus">False</property>
                                 <child>
                                   <object class="GtkSpinButton" id="resize_height_spinbutton">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
-                                    <property name="invisible_char">&#x25CF;</property>
+                                    <property name="invisible_char">â</property>
                                     <property name="width_chars">6</property>
                                     <property name="adjustment">resize_height_adjustment</property>
                                     <property name="climb_rate">1</property>
@@ -232,6 +132,7 @@
                             <child>
                               <object class="GtkComboBox" id="unit_combobox">
                                 <property name="visible">True</property>
+                                <property name="can_focus">False</property>
                                 <property name="model">unit_liststore</property>
                                 <property name="active">0</property>
                                 <child>
@@ -252,9 +153,75 @@
                             </child>
                           </object>
                           <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
                             <property name="position">0</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkVButtonBox" id="hbuttonbox2">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="spacing">6</property>
+                            <property name="layout_style">spread</property>
+                            <child>
+                              <object class="GtkButton" id="image_size_button">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="tooltip_text" translatable="yes">Set the image size to this value</property>
+                                <property name="use_action_appearance">False</property>
+                                <property name="use_underline">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="image_size_label">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label">Image</property>
+                                    <attributes>
+                                      <attribute name="size" value="8000"/>
+                                    </attributes>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="screen_size_button">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="tooltip_text" translatable="yes">Set the image size to this value</property>
+                                <property name="use_action_appearance">False</property>
+                                <property name="use_underline">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="screen_size_label">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="xpad">1</property>
+                                    <property name="label">Screen</property>
+                                    <attributes>
+                                      <attribute name="size" value="8000"/>
+                                    </attributes>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
                       </object>
                     </child>
                   </object>
@@ -262,6 +229,7 @@
                 <child type="label">
                   <object class="GtkLabel" id="label15">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="label" translatable="yes">Dimensions</property>
                     <attributes>
                       <attribute name="weight" value="bold"/>
@@ -272,27 +240,30 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">1</property>
+                <property name="position">0</property>
               </packing>
             </child>
             <child>
               <object class="GtkFrame" id="frame5">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="label_xalign">0</property>
                 <property name="shadow_type">none</property>
                 <child>
                   <object class="GtkAlignment" id="alignment6">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="top_padding">6</property>
                     <property name="left_padding">12</property>
                     <child>
                       <object class="GtkVBox" id="vbox8">
                         <property name="visible">True</property>
-                        <property name="orientation">vertical</property>
+                        <property name="can_focus">False</property>
                         <property name="spacing">6</property>
                         <child>
                           <object class="GtkHBox" id="ratio_combobox_box">
                             <property name="visible">True</property>
+                            <property name="can_focus">False</property>
                             <child>
                               <placeholder/>
                             </child>
@@ -306,23 +277,26 @@
                         <child>
                           <object class="GtkHBox" id="custom_ratio_box">
                             <property name="visible">True</property>
+                            <property name="can_focus">False</property>
                             <property name="spacing">6</property>
                             <child>
                               <object class="GtkSpinButton" id="ratio_w_spinbutton">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
-                                <property name="invisible_char">&#x25CF;</property>
+                                <property name="invisible_char">â</property>
                                 <property name="adjustment">ratio_w_adjustment</property>
                                 <property name="climb_rate">1</property>
                               </object>
                               <packing>
                                 <property name="expand">False</property>
+                                <property name="fill">True</property>
                                 <property name="position">0</property>
                               </packing>
                             </child>
                             <child>
                               <object class="GtkLabel" id="label17">
                                 <property name="visible">True</property>
+                                <property name="can_focus">False</property>
                                 <property name="label">:</property>
                               </object>
                               <packing>
@@ -335,13 +309,14 @@
                               <object class="GtkSpinButton" id="ratio_h_spinbutton">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
-                                <property name="invisible_char">&#x25CF;</property>
+                                <property name="invisible_char">â</property>
                                 <property name="adjustment">ratio_h_adjustment</property>
                                 <property name="climb_rate">1</property>
                                 <property name="update_policy">if-valid</property>
                               </object>
                               <packing>
                                 <property name="expand">False</property>
+                                <property name="fill">True</property>
                                 <property name="position">2</property>
                               </packing>
                             </child>
@@ -358,6 +333,7 @@
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">False</property>
+                            <property name="use_action_appearance">False</property>
                             <property name="use_underline">True</property>
                             <property name="draw_indicator">True</property>
                           </object>
@@ -374,6 +350,7 @@
                 <child type="label">
                   <object class="GtkLabel" id="label16">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="label" translatable="yes">Aspect ratio</property>
                     <attributes>
                       <attribute name="weight" value="bold"/>
@@ -384,23 +361,25 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">2</property>
+                <property name="position">1</property>
               </packing>
             </child>
             <child>
               <object class="GtkFrame" id="frame1">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="label_xalign">0</property>
                 <property name="shadow_type">none</property>
                 <child>
                   <object class="GtkAlignment" id="alignment1">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="top_padding">6</property>
                     <property name="left_padding">12</property>
                     <child>
                       <object class="GtkVBox" id="vbox3">
                         <property name="visible">True</property>
-                        <property name="orientation">vertical</property>
+                        <property name="can_focus">False</property>
                         <property name="spacing">6</property>
                         <child>
                           <object class="GtkCheckButton" id="high_quality_checkbutton">
@@ -408,7 +387,9 @@
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">False</property>
+                            <property name="use_action_appearance">False</property>
                             <property name="use_underline">True</property>
+                            <property name="xalign">0</property>
                             <property name="active">True</property>
                             <property name="draw_indicator">True</property>
                           </object>
@@ -425,6 +406,7 @@
                 <child type="label">
                   <object class="GtkLabel" id="label3">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="label" translatable="yes">Options</property>
                     <attributes>
                       <attribute name="weight" value="bold"/>
@@ -435,21 +417,163 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkHSeparator" id="separator1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
                 <property name="position">3</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkAlignment" id="alignment2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="bottom_padding">6</property>
+                <child>
+                  <object class="GtkHBox" id="box1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkTable" id="table1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="n_rows">3</property>
+                        <property name="n_columns">2</property>
+                        <property name="column_spacing">6</property>
+                        <property name="row_spacing">6</property>
+                        <child>
+                          <object class="GtkLabel" id="label2">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">Original dimensions:</property>
+                            <attributes>
+                              <attribute name="scale" value="0.80000000000000004"/>
+                            </attributes>
+                          </object>
+                          <packing>
+                            <property name="x_options">GTK_FILL</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label4">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">Scale factor:</property>
+                            <attributes>
+                              <attribute name="scale" value="0.80000000000000004"/>
+                            </attributes>
+                          </object>
+                          <packing>
+                            <property name="top_attach">2</property>
+                            <property name="bottom_attach">3</property>
+                            <property name="x_options">GTK_FILL</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="original_dimensions_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="label">label</property>
+                            <attributes>
+                              <attribute name="scale" value="0.80000000000000004"/>
+                            </attributes>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="scale_factor_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="label">label</property>
+                            <attributes>
+                              <attribute name="scale" value="0.80000000000000004"/>
+                            </attributes>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">2</property>
+                            <property name="bottom_attach">3</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label5">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">New dimensions:</property>
+                            <attributes>
+                              <attribute name="scale" value="0.80000000000000004"/>
+                            </attributes>
+                          </object>
+                          <packing>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                            <property name="x_options">GTK_FILL</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="new_dimensions_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="label">label</property>
+                            <attributes>
+                              <attribute name="scale" value="0.80000000000000004"/>
+                            </attributes>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">4</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
+            <property name="fill">True</property>
             <property name="position">0</property>
           </packing>
         </child>
         <child>
           <object class="GtkHSeparator" id="hseparator1">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
           </object>
           <packing>
             <property name="expand">False</property>
+            <property name="fill">True</property>
             <property name="padding">6</property>
             <property name="position">1</property>
           </packing>
@@ -457,6 +581,7 @@
         <child>
           <object class="GtkHButtonBox" id="hbuttonbox1">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <property name="spacing">12</property>
             <property name="layout_style">center</property>
             <child>
@@ -465,6 +590,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
                 <property name="use_underline">True</property>
                 <property name="use_stock">True</property>
               </object>
@@ -480,6 +606,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
                 <property name="use_stock">True</property>
               </object>
               <packing>
@@ -499,8 +626,11 @@
       </object>
     </child>
   </object>
-  <object class="GtkAdjustment" id="resize_width_adjustment">
-    <property name="lower">1</property>
+  <object class="GtkAdjustment" id="ratio_h_adjustment">
+    <property name="upper">999999</property>
+    <property name="step_increment">1</property>
+  </object>
+  <object class="GtkAdjustment" id="ratio_w_adjustment">
     <property name="upper">999999</property>
     <property name="step_increment">1</property>
   </object>
@@ -509,6 +639,11 @@
     <property name="upper">999999</property>
     <property name="step_increment">1</property>
   </object>
+  <object class="GtkAdjustment" id="resize_width_adjustment">
+    <property name="lower">1</property>
+    <property name="upper">999999</property>
+    <property name="step_increment">1</property>
+  </object>
   <object class="GtkListStore" id="unit_liststore">
     <columns>
       <!-- column-name type -->
@@ -527,12 +662,4 @@
       </row>
     </data>
   </object>
-  <object class="GtkAdjustment" id="ratio_w_adjustment">
-    <property name="upper">999999</property>
-    <property name="step_increment">1</property>
-  </object>
-  <object class="GtkAdjustment" id="ratio_h_adjustment">
-    <property name="upper">999999</property>
-    <property name="step_increment">1</property>
-  </object>
 </interface>
diff --git a/extensions/file_tools/gth-file-tool-resize.c b/extensions/file_tools/gth-file-tool-resize.c
index f448d31..abbc62d 100644
--- a/extensions/file_tools/gth-file-tool-resize.c
+++ b/extensions/file_tools/gth-file-tool-resize.c
@@ -28,6 +28,9 @@
 
 
 #define GET_WIDGET(x) (_gtk_builder_get_widget (self->priv->builder, (x)))
+#define IMAGE_RATIO_POSITION 2
+#define SCREEN_RATIO_POSITION 3
+#define PIXELS_UNIT_POSITION 0
 
 
 static gpointer parent_class = NULL;
@@ -200,13 +203,11 @@ high_quality_checkbutton_toggled_cb (GtkToggleButton   *button,
 
 
 static void
-unit_combobox_changed_cb (GtkComboBox       *combobox,
-			  GthFileToolResize *self)
+update_size_spin_buttons_from_unit_value (GthFileToolResize *self)
 {
 	g_signal_handlers_block_by_data (GET_WIDGET ("resize_width_spinbutton"), self);
 	g_signal_handlers_block_by_data (GET_WIDGET ("resize_height_spinbutton"), self);
 
-	self->priv->unit = gtk_combo_box_get_active (combobox);
 	if (self->priv->unit == GTH_UNIT_PERCENTAGE) {
 		double p;
 
@@ -227,6 +228,15 @@ unit_combobox_changed_cb (GtkComboBox       *combobox,
 
 	g_signal_handlers_unblock_by_data (GET_WIDGET ("resize_width_spinbutton"), self);
 	g_signal_handlers_unblock_by_data (GET_WIDGET ("resize_height_spinbutton"), self);
+}
+
+
+static void
+unit_combobox_changed_cb (GtkComboBox       *combobox,
+			  GthFileToolResize *self)
+{
+	self->priv->unit = gtk_combo_box_get_active (combobox);
+	update_size_spin_buttons_from_unit_value (self);
 
 	selection_width_value_changed_cb (GTK_SPIN_BUTTON (GET_WIDGET ("resize_width_spinbutton")), self);
 }
@@ -359,6 +369,70 @@ invert_ratio_changed_cb (GtkSpinButton     *spin,
 }
 
 
+static void
+set_image_size (GthFileToolResize *self,
+		int                w,
+		int                h,
+		int                ratio)
+{
+	self->priv->fixed_aspect_ratio = TRUE;
+	self->priv->aspect_ratio = (double) w / h;;
+	self->priv->new_width = w;
+	self->priv->new_height = h;
+	self->priv->unit = GTH_UNIT_PIXELS;
+
+	update_size_spin_buttons_from_unit_value (self);
+
+	g_signal_handlers_block_by_data (GET_WIDGET ("resize_width_spinbutton"), self);
+	g_signal_handlers_block_by_data (GET_WIDGET ("resize_height_spinbutton"), self);
+	g_signal_handlers_block_by_data (GET_WIDGET ("unit_combobox"), self);
+	g_signal_handlers_block_by_data (self->priv->ratio_combobox, self);
+	g_signal_handlers_block_by_data (GET_WIDGET ("invert_ratio_checkbutton"), self);
+	g_signal_handlers_block_by_data (GET_WIDGET ("ratio_w_spinbutton"), self);
+	g_signal_handlers_block_by_data (GET_WIDGET ("ratio_h_spinbutton"), self);
+
+	gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("unit_combobox")), PIXELS_UNIT_POSITION);
+	gtk_combo_box_set_active (GTK_COMBO_BOX (self->priv->ratio_combobox), ratio);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("invert_ratio_checkbutton")), FALSE);
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("resize_width_spinbutton")), w);
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("resize_height_spinbutton")), h);
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("ratio_w_spinbutton")), w);
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("ratio_h_spinbutton")), h);
+
+	g_signal_handlers_unblock_by_data (GET_WIDGET ("resize_width_spinbutton"), self);
+	g_signal_handlers_unblock_by_data (GET_WIDGET ("resize_height_spinbutton"), self);
+	g_signal_handlers_unblock_by_data (GET_WIDGET ("unit_combobox"), self);
+	g_signal_handlers_unblock_by_data (self->priv->ratio_combobox, self);
+	g_signal_handlers_unblock_by_data (GET_WIDGET ("invert_ratio_checkbutton"), self);
+	g_signal_handlers_unblock_by_data (GET_WIDGET ("ratio_w_spinbutton"), self);
+	g_signal_handlers_unblock_by_data (GET_WIDGET ("ratio_h_spinbutton"), self);
+
+	update_pixbuf_size (self);
+}
+
+
+static void
+image_size_button_clicked_cb (GtkButton         *button,
+			      GthFileToolResize *self)
+{
+	set_image_size (self,
+			self->priv->original_width,
+			self->priv->original_height,
+			IMAGE_RATIO_POSITION);
+}
+
+
+static void
+screen_size_button_clicked_cb (GtkButton         *button,
+			       GthFileToolResize *self)
+{
+	set_image_size (self,
+			self->priv->screen_width,
+			self->priv->screen_height,
+			SCREEN_RATIO_POSITION);
+}
+
+
 static GtkWidget *
 gth_file_tool_resize_get_options (GthFileTool *base)
 {
@@ -418,9 +492,11 @@ gth_file_tool_resize_get_options (GthFileTool *base)
 
 	self->priv->ratio_combobox = _gtk_combo_box_new_with_texts (_("None"), _("Square"), NULL);
 	text = g_strdup_printf (_("%d x %d (Image)"), self->priv->original_width, self->priv->original_height);
+	gtk_label_set_text (GTK_LABEL (GET_WIDGET ("image_size_label")), text);
 	gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (self->priv->ratio_combobox), text);
 	g_free (text);
 	text = g_strdup_printf (_("%d x %d (Screen)"), self->priv->screen_width, self->priv->screen_height);
+	gtk_label_set_text (GTK_LABEL (GET_WIDGET ("screen_size_label")), text);
 	gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (self->priv->ratio_combobox), text);
 	g_free (text);
 	_gtk_combo_box_append_texts (GTK_COMBO_BOX_TEXT (self->priv->ratio_combobox),
@@ -483,6 +559,14 @@ gth_file_tool_resize_get_options (GthFileTool *base)
 			  "toggled",
 			  G_CALLBACK (invert_ratio_changed_cb),
 			  self);
+	g_signal_connect (GET_WIDGET ("image_size_button"),
+			  "clicked",
+			  G_CALLBACK (image_size_button_clicked_cb),
+			  self);
+	g_signal_connect (GET_WIDGET ("screen_size_button"),
+			  "clicked",
+			  G_CALLBACK (screen_size_button_clicked_cb),
+			  self);
 
 	gtk_combo_box_set_active (GTK_COMBO_BOX (self->priv->ratio_combobox), eel_gconf_get_enum (PREF_RESIZE_ASPECT_RATIO, GTH_TYPE_ASPECT_RATIO, GTH_ASPECT_RATIO_IMAGE));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]