aboutsummaryrefslogtreecommitdiffstats
path: root/embed/xulrunner/src/gecko-embed-single.cpp
blob: dd147e5125c0b24442479aa9c6625aaa4c604ea4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 *  Copyright © Christopher Blizzard
 *  Copyright © Ramiro Estrugo
 *  Copyright © 2006 Christian Persch
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2.1, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  ---------------------------------------------------------------------------
 *  Derived from Mozilla.org code, which had the following attributions:
 *
 *  The Original Code is mozilla.org code.
 *
 *  The Initial Developer of the Original Code is
 *  Christopher Blizzard. Portions created by Christopher Blizzard are Copyright © Christopher Blizzard.  All Rights Reserved.
 *  Portions created by the Initial Developer are Copyright © 2001
 *  the Initial Developer. All Rights Reserved.
 *
 *  Contributor(s):
 *    Christopher Blizzard <blizzard@mozilla.org>
 *    Ramiro Estrugo <ramiro@eazel.com>
 *  ---------------------------------------------------------------------------
 *
 *  $Id$
 */

#include <mozilla-config.h>
#include "config.h"

#include "gecko-embed-single.h"
#include "gecko-embed-private.h"
#include "gecko-embed-signals.h"
#include "gecko-embed-marshal.h"

#include "GeckoSingle.h"

#define GECKO_EMBED_SINGLE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GECKO_TYPE_EMBED_SINGLE, GeckoEmbedSinglePrivate))

struct _GeckoEmbedSinglePrivate
{
  GeckoSingle *single;
};

enum
{
  NEW_WINDOW_ORPHAN,
  LAST_SINGLE_SIGNAL
};

static guint gecko_embed_single_signals[LAST_SINGLE_SIGNAL] = { 0 };

static void gecko_embed_single_class_init (GeckoEmbedSingleClass *klass);
static void gecko_embed_single_init       (GeckoEmbedSingle *embed);

static GObjectClass *parent_class = NULL;

GType
gecko_embed_single_get_type(void)
{
  static GType type = 0;

  if (!type)
  {
    const GTypeInfo info =
    {
      sizeof (GeckoEmbedSingleClass),
      NULL, /* base_init */
      NULL, /* base_finalize */
      (GClassInitFunc) gecko_embed_single_class_init,
      NULL,
      NULL, /* class_data */
      sizeof (GeckoEmbedSingle),
      0, /* n_preallocs */
      (GInstanceInitFunc) gecko_embed_single_init
    };

    type = g_type_register_static (G_TYPE_OBJECT, "GeckoEmbedSingle",
                                   &info, (GTypeFlags) 0);
  }

  return type;
}

GeckoEmbedSingle *
gecko_embed_single_get (void)
{
  static GeckoEmbedSingle *single = NULL;

  if (!single)
  {
    single = GECKO_EMBED_SINGLE (g_object_new (GECKO_TYPE_EMBED_SINGLE, NULL));

    g_object_add_weak_pointer (G_OBJECT (single), (gpointer *) &single);
  }

  return single;
}

extern "C" void
gecko_embed_single_create_window (GeckoEmbed **aNewEmbed,
                                  guint aChromeFlags)
{
  GeckoEmbedSingle *single = gecko_embed_single_get ();

  *aNewEmbed = nsnull;

  if (!single)
    return;

  g_signal_emit (single, gecko_embed_single_signals[NEW_WINDOW_ORPHAN], 0,
                 (void **) aNewEmbed, aChromeFlags);
}

void
gecko_embed_single_push_startup(void)
{
  GeckoEmbedSingle *single = gecko_embed_single_get ();

  single->priv->single->PushStartup();
}

void
gecko_embed_single_pop_startup(void)
{
  GeckoEmbedSingle *single = gecko_embed_single_get ();

  single->priv->single->PopStartup();
}

static void
gecko_embed_single_init(GeckoEmbedSingle *embed)
{
  embed->priv = GECKO_EMBED_SINGLE_GET_PRIVATE (embed);

  embed->priv->single = new GeckoSingle ();
}

static void
gecko_embed_single_finalize (GObject *object)
{
  GeckoEmbedSingle *single = GECKO_EMBED_SINGLE (object);

  delete single->priv->single;
  single->priv->single = nsnull;

  G_OBJECT_CLASS (parent_class)->finalize (object);
}

static void
gecko_embed_single_class_init (GeckoEmbedSingleClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  parent_class = (GObjectClass *) g_type_class_peek_parent (klass);

  object_class->finalize = gecko_embed_single_finalize;

  gecko_embed_single_signals[NEW_WINDOW] =
    g_signal_new ("new_window_orphan",
                  GECKO_TYPE_EMBED_SINGLE,
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GeckoEmbedSingleClass, new_window_orphan),
                  NULL, NULL,
                  gecko_embed_marshal_VOID__OBJECT_UINT,
                  G_TYPE_NONE,
                  2,
                  G_TYPE_OBJECT,
                  G_TYPE_UINT);

  g_type_class_add_private (object_class, sizeof (GeckoEmbedSinglePrivate));
}