gtkfilechooserembed.c 6.39 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
2 3 4 5 6 7 8 9 10 11 12 13 14 15
 * gtkfilechooserembed.h: Abstract sizing interface for file selector implementations
 * Copyright (C) 2004, Red Hat, Inc.
 *
 * This library 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 of the License, or (at your option) any later version.
 *
 * This library 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
Javier Jardón's avatar
Javier Jardón committed
16
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 18
 */

19
#include "config.h"
20 21
#include "gtkfilechooserembed.h"
#include "gtkmarshalers.h"
22
#include "gtkintl.h"
23 24 25 26 27

static void gtk_file_chooser_embed_class_init (gpointer g_iface);
static void delegate_get_default_size         (GtkFileChooserEmbed *chooser_embed,
					       gint                *default_width,
					       gint                *default_height);
28
static gboolean delegate_should_respond       (GtkFileChooserEmbed *chooser_embed);
Federico Mena Quintero's avatar
Federico Mena Quintero committed
29
static void delegate_initial_focus            (GtkFileChooserEmbed *chooser_embed);
30 31
static void delegate_default_size_changed     (GtkFileChooserEmbed *chooser_embed,
					       gpointer             data);
32 33
static void delegate_response_requested       (GtkFileChooserEmbed *chooser_embed,
					       gpointer             data);
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

static GtkFileChooserEmbed *
get_delegate (GtkFileChooserEmbed *receiver)
{
  return g_object_get_data (G_OBJECT (receiver), "gtk-file-chooser-embed-delegate");
}

/**
 * _gtk_file_chooser_embed_delegate_iface_init:
 * @iface: a #GtkFileChoserEmbedIface structure
 * 
 * An interface-initialization function for use in cases where an object is
 * simply delegating the methods, signals of the #GtkFileChooserEmbed interface
 * to another object.  _gtk_file_chooser_embed_set_delegate() must be called on
 * each instance of the object so that the delegate object can be found.
 **/
void
_gtk_file_chooser_embed_delegate_iface_init (GtkFileChooserEmbedIface *iface)
{
  iface->get_default_size = delegate_get_default_size;
54
  iface->should_respond = delegate_should_respond;
Federico Mena Quintero's avatar
Federico Mena Quintero committed
55
  iface->initial_focus = delegate_initial_focus;
56 57 58 59 60 61 62 63 64
}

/**
 * _gtk_file_chooser_embed_set_delegate:
 * @receiver: a GOobject implementing #GtkFileChooserEmbed
 * @delegate: another GObject implementing #GtkFileChooserEmbed
 *
 * Establishes that calls on @receiver for #GtkFileChooser methods should be
 * delegated to @delegate, and that #GtkFileChooser signals emitted on @delegate
65 66
 * should be forwarded to @receiver. Must be used in conjunction with
 * _gtk_file_chooser_embed_delegate_iface_init().
67 68 69 70 71 72 73 74
 **/
void
_gtk_file_chooser_embed_set_delegate (GtkFileChooserEmbed *receiver,
				      GtkFileChooserEmbed *delegate)
{
  g_return_if_fail (GTK_IS_FILE_CHOOSER_EMBED (receiver));
  g_return_if_fail (GTK_IS_FILE_CHOOSER_EMBED (delegate));
  
75
  g_object_set_data (G_OBJECT (receiver), I_("gtk-file-chooser-embed-delegate"), delegate);
76

77
  g_signal_connect (delegate, "default-size-changed",
78
		    G_CALLBACK (delegate_default_size_changed), receiver);
79
  g_signal_connect (delegate, "response-requested",
80
		    G_CALLBACK (delegate_response_requested), receiver);
81 82 83 84 85 86 87 88 89 90 91
}



static void
delegate_get_default_size (GtkFileChooserEmbed *chooser_embed,
			   gint                *default_width,
			   gint                *default_height)
{
  _gtk_file_chooser_embed_get_default_size (get_delegate (chooser_embed), default_width, default_height);
}
92

93 94 95 96 97 98
static gboolean
delegate_should_respond (GtkFileChooserEmbed *chooser_embed)
{
  return _gtk_file_chooser_embed_should_respond (get_delegate (chooser_embed));
}

Federico Mena Quintero's avatar
Federico Mena Quintero committed
99 100 101
static void
delegate_initial_focus (GtkFileChooserEmbed *chooser_embed)
{
102
  _gtk_file_chooser_embed_initial_focus (get_delegate (chooser_embed));
Federico Mena Quintero's avatar
Federico Mena Quintero committed
103 104
}

105 106 107 108 109 110 111
static void
delegate_default_size_changed (GtkFileChooserEmbed *chooser_embed,
			       gpointer             data)
{
  g_signal_emit_by_name (data, "default-size-changed");
}

112 113 114 115 116 117 118
static void
delegate_response_requested (GtkFileChooserEmbed *chooser_embed,
			     gpointer             data)
{
  g_signal_emit_by_name (data, "response-requested");
}

119 120 121 122 123 124 125 126 127 128

/* publicly callable functions */

GType
_gtk_file_chooser_embed_get_type (void)
{
  static GType file_chooser_embed_type = 0;

  if (!file_chooser_embed_type)
    {
129
      const GTypeInfo file_chooser_embed_info =
130 131 132 133 134 135 136 137
      {
	sizeof (GtkFileChooserEmbedIface),  /* class_size */
	NULL,                          /* base_init */
	NULL,			       /* base_finalize */
	(GClassInitFunc)gtk_file_chooser_embed_class_init, /* class_init */
      };

      file_chooser_embed_type = g_type_register_static (G_TYPE_INTERFACE,
138
							I_("GtkFileChooserEmbed"),
139 140 141 142 143 144 145 146 147 148 149 150 151
							&file_chooser_embed_info, 0);

      g_type_interface_add_prerequisite (file_chooser_embed_type, GTK_TYPE_WIDGET);
    }

  return file_chooser_embed_type;
}

static void
gtk_file_chooser_embed_class_init (gpointer g_iface)
{
  GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);

152
  g_signal_new (I_("default-size-changed"),
153 154 155 156 157 158
		iface_type,
		G_SIGNAL_RUN_LAST,
		G_STRUCT_OFFSET (GtkFileChooserEmbedIface, default_size_changed),
		NULL, NULL,
		_gtk_marshal_VOID__VOID,
		G_TYPE_NONE, 0);
159
  g_signal_new (I_("response-requested"),
160 161 162 163 164 165
		iface_type,
		G_SIGNAL_RUN_LAST,
		G_STRUCT_OFFSET (GtkFileChooserEmbedIface, response_requested),
		NULL, NULL,
		_gtk_marshal_VOID__VOID,
		G_TYPE_NONE, 0);
166 167 168 169 170 171 172 173
}

void
_gtk_file_chooser_embed_get_default_size (GtkFileChooserEmbed *chooser_embed,
					 gint                *default_width,
					 gint                *default_height)
{
  g_return_if_fail (GTK_IS_FILE_CHOOSER_EMBED (chooser_embed));
174 175
  g_return_if_fail (default_width != NULL);
  g_return_if_fail (default_height != NULL);
176 177 178 179

  GTK_FILE_CHOOSER_EMBED_GET_IFACE (chooser_embed)->get_default_size (chooser_embed, default_width, default_height);
}

180 181 182 183 184 185 186 187
gboolean
_gtk_file_chooser_embed_should_respond (GtkFileChooserEmbed *chooser_embed)
{
  g_return_val_if_fail (GTK_IS_FILE_CHOOSER_EMBED (chooser_embed), FALSE);

  return GTK_FILE_CHOOSER_EMBED_GET_IFACE (chooser_embed)->should_respond (chooser_embed);
}

Federico Mena Quintero's avatar
Federico Mena Quintero committed
188 189 190 191 192 193 194
void
_gtk_file_chooser_embed_initial_focus (GtkFileChooserEmbed *chooser_embed)
{
  g_return_if_fail (GTK_IS_FILE_CHOOSER_EMBED (chooser_embed));

  GTK_FILE_CHOOSER_EMBED_GET_IFACE (chooser_embed)->initial_focus (chooser_embed);
}