Code

The dialog to panel refactoring:
[inkscape.git] / src / ui / widget / page-sizer.cpp
index 642f64c43342b361ac724ffd80dd588b53b32b65..7b0fea5f558fd8b91d0397b444762ec8c24a8841 100644 (file)
@@ -210,7 +210,7 @@ PageSizer::PageSizer() : Gtk::VBox(false,4)
            {
         Glib::ustring name = p->name;
         char formatBuf[80];
-        snprintf(formatBuf, 79, "%0.2f x %0.2f", p->smaller, p->larger);
+        snprintf(formatBuf, 79, "%0.1f x %0.1f", p->smaller, p->larger);
         Glib::ustring desc = formatBuf;
         if (p->unit == SP_UNIT_IN)
             desc.append(" in");
@@ -224,9 +224,9 @@ PageSizer::PageSizer() : Gtk::VBox(false,4)
         row[_paperSizeListColumns.nameColumn] = name;
         row[_paperSizeListColumns.descColumn] = desc;
         }
-    //Gtk::TreeModel::Row row = _paperSizeListStore->children()[0];
-    //if (row)
-    //    _paperSizeListSelection->select(row);
+    //Gtk::TreeModel::iterator iter = _paperSizeListStore->children().begin();
+    //if (iter)
+    //    _paperSizeListSelection->select(iter);
 
 
     pack_start (_paperSizeListBox, false, false, 0);
@@ -240,10 +240,12 @@ PageSizer::PageSizer() : Gtk::VBox(false,4)
     pack_start (_orientationBox, false, false, 0);
     _orientationLabel.set_label(_("Page orientation:")); 
     _orientationBox.pack_start(_orientationLabel, false, false, 0);
+    _landscapeButton.set_use_underline();
     _landscapeButton.set_label(_("_Landscape"));
        _landscapeButton.set_active(true);
     Gtk::RadioButton::Group group = _landscapeButton.get_group();
     _orientationBox.pack_end (_landscapeButton, false, false, 5);
+    _portraitButton.set_use_underline();
     _portraitButton.set_label(_("_Portrait"));
        _portraitButton.set_active(true);
     _orientationBox.pack_end (_portraitButton, false, false, 5);
@@ -259,6 +261,7 @@ PageSizer::PageSizer() : Gtk::VBox(false,4)
     _customTable.set_col_spacings (4);
     _customFrame.add(_customTable);
     
+    _fitPageButton.set_use_underline();
     _fitPageButton.set_label(_("_Fit page to selection"));
     _tips.set_tip(_fitPageButton, 
        _("Resize the page to fit the current selection, or the entire drawing if there is no selection"));
@@ -349,8 +352,7 @@ PageSizer::setDim (double w, double h, bool changeList)
         SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP);
         sp_document_set_width (doc, w, &_px_unit);
         sp_document_set_height (doc, h, &_px_unit);
-        sp_document_done (doc, SP_VERB_NONE, 
-        /* TODO: annotate */ "page-sizer.cpp:301");
+        sp_document_done (doc, SP_VERB_NONE, _("Set page size"));
     } 
     
     _landscape = ( w > h );
@@ -359,8 +361,7 @@ PageSizer::setDim (double w, double h, bool changeList)
     
     if (changeList)
         {
-        int index = find_paper_size(w, h);
-        Gtk::TreeModel::Row row = _paperSizeListStore->children()[index];
+        Gtk::TreeModel::Row row = (*find_paper_size(w, h));
         if (row)
             _paperSizeListSelection->select(row);
         }
@@ -380,10 +381,11 @@ PageSizer::setDim (double w, double h, bool changeList)
 
 
 /** 
- * Returns an index into paperSizeTable of a paper of the specified 
- * size (specified in px), or -1 if there's no such paper.
+ * Returns an iterator pointing to a row in paperSizeListStore which
+ * contains a paper of the specified size (specified in px), or 
+ * paperSizeListStore->children().end() if no such paper exists.
  */
-int
+Gtk::ListStore::iterator
 PageSizer::find_paper_size (double w, double h) const
 {
     double smaller = w;
@@ -392,9 +394,8 @@ PageSizer::find_paper_size (double w, double h) const
         smaller = h; larger = w;
     }
 
-    g_return_val_if_fail(smaller <= larger, -1);
+    g_return_val_if_fail(smaller <= larger, _paperSizeListStore->children().end());
     
-    int index = 0;
     std::map<Glib::ustring, PaperSize>::const_iterator iter;
     for (iter = _paperSizeTable.begin() ;
             iter != _paperSizeTable.end() ; iter++) {
@@ -403,15 +404,22 @@ PageSizer::find_paper_size (double w, double h) const
         double smallX = sp_units_get_pixels(paper.smaller, i_unit);
         double largeX = sp_units_get_pixels(paper.larger,  i_unit);
         
-        g_return_val_if_fail(smallX <= largeX, -1);
+        g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end());
         
         if ((std::abs(smaller - smallX) <= 0.1) &&
-            (std::abs(larger  - largeX) <= 0.1)   )
-            return index;
-            
-        index++;
+            (std::abs(larger  - largeX) <= 0.1)   ) {
+            Gtk::ListStore::iterator p;
+            // We need to search paperSizeListStore explicitly for the
+            // specified paper size because it is sorted in a different
+            // way than paperSizeTable (which is sorted alphabetically)
+            for (p = _paperSizeListStore->children().begin(); p != _paperSizeListStore->children().end(); p++) {
+                if ((*p)[_paperSizeListColumns.nameColumn] == paper.name) {
+                    return p;
+                }
+            }
+        }
     }
-    return -1;
+    return _paperSizeListStore->children().end();
 }