Initial import of ephy (rev# 7126) from svn
[ephy-soc.git] / embed / mozilla / .svn / text-base / mozilla-embed-find.cpp.svn-base
blob576d8ec11675ef5f935224f8220ea4101c2766c3
1 /*
2  *  Copyright © 2000-2004 Marco Pesenti Gritti
3  *  Copyright © 2003, 2004 Christian Persch
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  *  $Id$
20  */
22 #include "mozilla-config.h"
23 #include "config.h"
25 #include "ephy-debug.h"
26 #include "ephy-embed-find.h"
27 #include "ephy-embed-shell.h"
29 #include "EphyFind.h"
31 #include "mozilla-embed-find.h"
33 #define MOZILLA_EMBED_FIND_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), MOZILLA_TYPE_EMBED_FIND, MozillaEmbedFindPrivate))
35 struct _MozillaEmbedFindPrivate
37         EphyFind *find;
40 static GObjectClass *parent_class = NULL;
42 static void
43 impl_set_embed (EphyEmbedFind *efind,
44                 EphyEmbed *embed)
46         MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind);
47         MozillaEmbedFindPrivate *priv = find->priv;
49         priv->find->SetEmbed (embed);
52 static void
53 impl_set_properties (EphyEmbedFind *efind,
54                      const char *find_string,
55                      gboolean case_sensitive)
57         MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind);
58         MozillaEmbedFindPrivate *priv = find->priv;
60         priv->find->SetFindProperties (find_string, case_sensitive);
63 static EphyEmbedFindResult
64 impl_find (EphyEmbedFind *efind,
65              const char *find_string,
66              gboolean links_only)
68         MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind);
69         MozillaEmbedFindPrivate *priv = find->priv;
71         return priv->find->Find (find_string, links_only);
74 static EphyEmbedFindResult
75 impl_find_again (EphyEmbedFind *efind,
76                  gboolean forward,
77                  gboolean links_only)
79         MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind);
80         MozillaEmbedFindPrivate *priv = find->priv;
82         return priv->find->FindAgain (forward, links_only);
85 static void
86 impl_set_selection (EphyEmbedFind *efind,
87                     gboolean attention)
89         MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind);
90         MozillaEmbedFindPrivate *priv = find->priv;
92         priv->find->SetSelectionAttention (attention);
95 static gboolean
96 impl_activate_link (EphyEmbedFind *efind,
97                     GdkModifierType mask)
99         MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind);
100         MozillaEmbedFindPrivate *priv = find->priv;
102         return priv->find->ActivateLink (mask);
105 static void
106 ephy_find_iface_init (EphyEmbedFindIface *iface)
108         iface->set_embed = impl_set_embed;
109         iface->set_properties = impl_set_properties;
110         iface->find = impl_find;
111         iface->find_again = impl_find_again;
112         iface->set_selection = impl_set_selection;
113         iface->activate_link = impl_activate_link;
116 static void
117 mozilla_embed_find_init (MozillaEmbedFind *find)
119         find->priv = MOZILLA_EMBED_FIND_GET_PRIVATE (find);
120         find->priv->find = new EphyFind ();
123 static GObject *
124 mozilla_embed_find_constructor (GType type, guint n_construct_properties,
125                                 GObjectConstructParam *construct_params)
127         g_object_ref (embed_shell);
129         /* we depend on single because of mozilla initialization */
130         ephy_embed_shell_get_embed_single (embed_shell);
132         return parent_class->constructor (type, n_construct_properties,
133                                           construct_params);
136 static void
137 mozilla_embed_find_finalize (GObject *object)
139         MozillaEmbedFind *find = MOZILLA_EMBED_FIND (object);
141         delete find->priv->find;
143         parent_class->finalize (object);
145         g_object_unref (embed_shell);
148 static void
149 mozilla_embed_find_class_init (MozillaEmbedFindClass *klass)
151         GObjectClass *object_class = G_OBJECT_CLASS (klass);
153         parent_class = (GObjectClass *) g_type_class_peek_parent (klass);
155         object_class->constructor = mozilla_embed_find_constructor;
156         object_class->finalize = mozilla_embed_find_finalize;
158         g_type_class_add_private (object_class, sizeof (MozillaEmbedFindPrivate));
161 GType 
162 mozilla_embed_find_get_type (void)
164         static GType type = 0;
166         if (G_UNLIKELY (type == 0))
167         {
168                 const GTypeInfo our_info =
169                 {
170                         sizeof (MozillaEmbedFindClass),
171                         NULL, /* base_init */
172                         NULL, /* base_finalize */
173                         (GClassInitFunc) mozilla_embed_find_class_init,
174                         NULL,
175                         NULL, /* class_data */
176                         sizeof (MozillaEmbedFind),
177                         0, /* n_preallocs */
178                         (GInstanceInitFunc) mozilla_embed_find_init
179                 };
181                 const GInterfaceInfo find_info =
182                 {
183                         (GInterfaceInitFunc) ephy_find_iface_init,
184                         NULL,
185                         NULL
186                 };
187         
188                 type = g_type_register_static (G_TYPE_OBJECT,
189                                                "MozillaEmbedFind",
190                                                &our_info, 
191                                                (GTypeFlags)0);
192                 g_type_add_interface_static (type,
193                                              EPHY_TYPE_EMBED_FIND,
194                                              &find_info);
195         }
197         return type;