Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / dialogs / find.cpp
index c76390ccba5a7c164a43fdd3a6df4f0490cdb2f3..fe264892abdcdf7175bac6f0400bfae0aff92c79 100644 (file)
@@ -1,23 +1,17 @@
-#define __SP_TRANSFORMATION_C__
-
-/**
- * \brief  Find dialog
- *
- * Authors:
+/** @file
+ * @brief  Find dialog
+ */
+/* Authors:
  *   bulia byak <bulia@users.sf.net>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2004 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-
 #include "widgets/icon.h"
-
 #include "message-stack.h"
 
 //TODO  : delete this
@@ -44,13 +38,14 @@ sp_find_dialog(){
 #include "desktop-handles.h"
 
 #include "dialog-events.h"
-#include "../prefs-utils.h"
+#include "../preferences.h"
 #include "../verbs.h"
 #include "../interface.h"
 #include "../sp-text.h"
 #include "../sp-flowtext.h"
 #include "../text-editing.h"
 #include "../sp-tspan.h"
+#include "../sp-tref.h"
 #include "../selection-chemistry.h"
 #include "../sp-defs.h"
 #include "../sp-rect.h"
@@ -66,15 +61,14 @@ sp_find_dialog(){
 #include "../sp-offset.h"
 #include <xml/repr.h>
 
-using NR::X;
-using NR::Y;
+#define MIN_ONSCREEN_DISTANCE 50
 
 static GtkWidget *dlg = NULL;
 static win_data wd;
 
 // impossible original values to make sure they are read from prefs
 static gint x = -1000, y = -1000, w = 0, h = 0;
-static gchar *prefs_path = "dialogs.find";
+static Glib::ustring const prefs_path = "/dialogs/find/";
 
 
 
@@ -88,7 +82,7 @@ static void sp_find_dialog_destroy(GtkObject *object, gpointer)
 
 
 
-static gboolean sp_find_dialog_delete(GtkObject *, GdkEvent *, gpointer data)
+static gboolean sp_find_dialog_delete(GtkObject *, GdkEvent *, gpointer /*data*/)
 {
     gtk_window_get_position (GTK_WINDOW (dlg), &x, &y);
     gtk_window_get_size (GTK_WINDOW (dlg), &w, &h);
@@ -96,10 +90,11 @@ static gboolean sp_find_dialog_delete(GtkObject *, GdkEvent *, gpointer data)
     if (x<0) x=0;
     if (y<0) y=0;
 
-    prefs_set_int_attribute (prefs_path, "x", x);
-    prefs_set_int_attribute (prefs_path, "y", y);
-    prefs_set_int_attribute (prefs_path, "w", w);
-    prefs_set_int_attribute (prefs_path, "h", h);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    prefs->setInt(prefs_path + "x", x);
+    prefs->setInt(prefs_path + "y", y);
+    prefs->setInt(prefs_path + "w", w);
+    prefs->setInt(prefs_path + "h", h);
 
     return FALSE; // which means, go ahead and destroy it
 }
@@ -236,7 +231,7 @@ item_type_match (SPItem *item, GtkWidget *widget)
     } else if (SP_IS_PATH(item) || SP_IS_LINE(item) || SP_IS_POLYLINE(item)) {
         return (type_checkbox (widget, "paths"));
 
-    } else if (SP_IS_TEXT(item) || SP_IS_TSPAN(item) || SP_IS_STRING(item)) {
+    } else if (SP_IS_TEXT(item) || SP_IS_TSPAN(item) || SP_IS_TREF(item) || SP_IS_STRING(item)) {
         return (type_checkbox (widget, "texts"));
 
     } else if (SP_IS_GROUP(item) && !desktop->isLayer(item) ) { // never select layers!
@@ -299,7 +294,7 @@ all_items (SPObject *r, GSList *l, bool hidden, bool locked)
     if (!strcmp (SP_OBJECT_REPR (r)->name(), "svg:metadata"))
         return l; // we're not interested in metadata
 
-    for (SPObject *child = sp_object_first_child(r); child; child = SP_OBJECT_NEXT (child)) {
+    for (SPObject *child = r->firstChild(); child; child = child->next) {
         if (SP_IS_ITEM (child) && !SP_OBJECT_IS_CLONED (child) && !desktop->isLayer(SP_ITEM(child))) {
                 if ((hidden || !desktop->itemIsHidden(SP_ITEM(child))) && (locked || !SP_ITEM(child)->isLocked())) {
                     l = g_slist_prepend (l, child);
@@ -349,7 +344,7 @@ void sp_find_dialog_find(GObject *, GObject *dlg)
         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_object_get_data (GTK_OBJECT (dlg), "inlayer")))) {
             l = all_items (desktop->currentLayer(), l, hidden, locked);
         } else {
-            l = all_items (SP_DOCUMENT_ROOT (SP_DT_DOCUMENT (desktop)), l, hidden, locked);
+            l = all_items(sp_desktop_document(desktop)->getRoot(), l, hidden, locked);
         }
     }
     guint all = g_slist_length (l);
@@ -371,7 +366,7 @@ void sp_find_dialog_find(GObject *, GObject *dlg)
                                                  count),
                                         count, all, exact? _("exact") : _("partial"));
 
-        Inkscape::Selection *selection = SP_DT_SELECTION (desktop);
+        Inkscape::Selection *selection = sp_desktop_selection (desktop);
         selection->clear();
         selection->setList(n);
         scroll_to_show_item (desktop, SP_ITEM(n->data));
@@ -612,7 +607,9 @@ sp_find_types ()
         }
 
         {
-            GtkWidget *c = sp_find_types_checkbox_indented (vb, "clones", TRUE, tt, _("Search clones"), _("Clones"), NULL, 10);
+            GtkWidget *c = sp_find_types_checkbox_indented (vb, "clones", TRUE, tt, _("Search clones"),
+                                                            //TRANSLATORS: "Clones" is a noun indicating type of object to find
+                                                            C_("Find dialog","Clones"), NULL, 10);
             gtk_box_pack_start (GTK_BOX (vb_all), c, FALSE, FALSE, 0);
         }
 
@@ -642,27 +639,28 @@ sp_find_dialog_old (void)
     {
         gchar title[500];
         sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_FIND), title);
+        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
         dlg = sp_window_new (title, TRUE);
         if (x == -1000 || y == -1000) {
-            x = prefs_get_int_attribute (prefs_path, "x", 0);
-            y = prefs_get_int_attribute (prefs_path, "y", 0);
+            x = prefs->getInt(prefs_path + "x", -1000);
+            y = prefs->getInt(prefs_path + "y", -1000);
         }
         if (w ==0 || h == 0) {
-            w = prefs_get_int_attribute (prefs_path, "w", 0);
-            h = prefs_get_int_attribute (prefs_path, "h", 0);
+            w = prefs->getInt(prefs_path + "w", 0);
+            h = prefs->getInt(prefs_path + "h", 0);
         }
         
-        if (x<0) x=0;
-        if (y<0) y=0;
+//        if (x<0) x=0;
+//        if (y<0) y=0;
 
-        if (x != 0 || y != 0) {
+        if (w && h)
+            gtk_window_resize ((GtkWindow *) dlg, w, h);
+        if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) {
             gtk_window_move ((GtkWindow *) dlg, x, y);
         } else {
             gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
         }
-        if (w && h)
-            gtk_window_resize ((GtkWindow *) dlg, w, h);
 
         sp_transientize (dlg);
         wd.win = dlg;
@@ -686,10 +684,10 @@ sp_find_dialog_old (void)
         GtkWidget *vb = gtk_vbox_new (FALSE, 0);
         gtk_container_add (GTK_CONTAINER (dlg), vb);
 
-        sp_find_new_searchfield (dlg, vb, _("_Text: "), "text", tt, _("Find objects by their text content (exact or partial match)"));
-        sp_find_new_searchfield (dlg, vb, _("_ID: "), "id", tt, _("Find objects by the value of the id attribute (exact or partial match)"));
-        sp_find_new_searchfield (dlg, vb, _("_Style: "), "style", tt, _("Find objects by the value of the style attribute (exact or partial match)"));
-        sp_find_new_searchfield (dlg, vb, _("_Attribute: "), "attr", tt ,_("Find objects by the name of an attribute (exact or partial match)"));
+        sp_find_new_searchfield (dlg, vb, _("_Text:"), "text", tt, _("Find objects by their text content (exact or partial match)"));
+        sp_find_new_searchfield (dlg, vb, _("_ID:"), "id", tt, _("Find objects by the value of the id attribute (exact or partial match)"));
+        sp_find_new_searchfield (dlg, vb, _("_Style:"), "style", tt, _("Find objects by the value of the style attribute (exact or partial match)"));
+        sp_find_new_searchfield (dlg, vb, _("_Attribute:"), "attr", tt ,_("Find objects by the name of an attribute (exact or partial match)"));
 
         gtk_widget_show_all (vb);
 
@@ -767,4 +765,4 @@ sp_find_dialog_old (void)
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :