]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfontchooser.c
Fix DND with frame sync
[~andy/gtk] / gtk / gtkfontchooser.c
index cdc8d5acbc0be315f1bd7024c90f41ba7899f8ba..6f16b13a5f6594b2c1902cc7f687bb54be4a066d 100644 (file)
@@ -15,9 +15,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
@@ -50,23 +48,43 @@ enum
 
 static guint chooser_signals[LAST_SIGNAL];
 
-#define DEFAULT_FONT_NAME "Sans 10"
-#define MAX_FONT_SIZE 999
-
 typedef GtkFontChooserIface GtkFontChooserInterface;
 G_DEFINE_INTERFACE (GtkFontChooser, gtk_font_chooser, G_TYPE_OBJECT);
 
 static void
 gtk_font_chooser_default_init (GtkFontChooserInterface *iface)
 {
+  /**
+   * GtkFontChooser:font:
+   *
+   * The font description as a string, e.g. "Sans Italic 12".
+   */
   g_object_interface_install_property
      (iface,
       g_param_spec_string ("font",
                           P_("Font"),
-                          P_("The string that represents this font"),
-                          DEFAULT_FONT_NAME,
+                           P_("Font description as a string, e.g. \"Sans Italic 12\""),
+                           GTK_FONT_CHOOSER_DEFAULT_FONT_NAME,
+                           GTK_PARAM_READWRITE));
+
+  /**
+   * GtkFontChooser:font-desc:
+   *
+   * The font description as a #PangoFontDescription.
+   */
+  g_object_interface_install_property
+     (iface,
+      g_param_spec_boxed ("font-desc",
+                          P_("Font description"),
+                          P_("Font description as a PangoFontDescription struct"),
+                          PANGO_TYPE_FONT_DESCRIPTION,
                           GTK_PARAM_READWRITE));
 
+  /**
+   * GtkFontChooser:preview-text:
+   *
+   * The string with which to preview the font.
+   */
   g_object_interface_install_property
      (iface,
       g_param_spec_string ("preview-text",
@@ -75,6 +93,11 @@ gtk_font_chooser_default_init (GtkFontChooserInterface *iface)
                           pango_language_get_sample_string (NULL),
                           GTK_PARAM_READWRITE));
 
+  /**
+   * GtkFontChooser:show-preview-entry:
+   *
+   * Whether to show an entry to change the preview text.
+   */
   g_object_interface_install_property
      (iface,
       g_param_spec_boolean ("show-preview-entry",
@@ -105,20 +128,22 @@ gtk_font_chooser_default_init (GtkFontChooserInterface *iface)
 }
 
 /**
- * gtk_font_chooser_get_family:
+ * gtk_font_chooser_get_font_family:
  * @fontchooser: a #GtkFontChooser
  *
  * Gets the #PangoFontFamily representing the selected font family.
  * Font families are a collection of font faces.
  *
+ * If the selected font is not installed, returns %NULL.
+ *
  * Return value: (transfer none): A #PangoFontFamily representing the
- *     selected font family. The returned object is owned by @fontchooser
+ *     selected font family, or %NULL. The returned object is owned by @fontchooser
  *     and must not be modified or freed.
  *
  * Since: 3.2
  */
 PangoFontFamily *
-gtk_font_chooser_get_family (GtkFontChooser *fontchooser)
+gtk_font_chooser_get_font_family (GtkFontChooser *fontchooser)
 {
   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
 
@@ -126,20 +151,22 @@ gtk_font_chooser_get_family (GtkFontChooser *fontchooser)
 }
 
 /**
- * gtk_font_chooser_get_face:
+ * gtk_font_chooser_get_font_face:
  * @fontchooser: a #GtkFontChooser
  *
  * Gets the #PangoFontFace representing the selected font group
  * details (i.e. family, slant, weight, width, etc).
  *
+ * If the selected font is not installed, returns %NULL.
+ *
  * Return value: (transfer none): A #PangoFontFace representing the
- *     selected font group details. The returned object is owned by
+ *     selected font group details, or %NULL. The returned object is owned by
  *     @fontchooser and must not be modified or freed.
  *
  * Since: 3.2
  */
 PangoFontFace *
-gtk_font_chooser_get_face (GtkFontChooser *fontchooser)
+gtk_font_chooser_get_font_face (GtkFontChooser *fontchooser)
 {
   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
 
@@ -147,7 +174,7 @@ gtk_font_chooser_get_face (GtkFontChooser *fontchooser)
 }
 
 /**
- * gtk_font_chooser_get_size:
+ * gtk_font_chooser_get_font_size:
  * @fontchooser: a #GtkFontChooser
  *
  * The selected font size.
@@ -158,7 +185,7 @@ gtk_font_chooser_get_face (GtkFontChooser *fontchooser)
  * Since: 3.2
  */
 gint
-gtk_font_chooser_get_size (GtkFontChooser *fontchooser)
+gtk_font_chooser_get_font_size (GtkFontChooser *fontchooser)
 {
   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), -1);
 
@@ -189,9 +216,14 @@ gtk_font_chooser_get_size (GtkFontChooser *fontchooser)
 gchar *
 gtk_font_chooser_get_font (GtkFontChooser *fontchooser)
 {
+  gchar *fontname;
+
   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
 
-  return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font (fontchooser);
+  g_object_get (fontchooser, "font", &fontname, NULL);
+
+
+  return fontname;
 }
 
 /**
@@ -201,21 +233,67 @@ gtk_font_chooser_get_font (GtkFontChooser *fontchooser)
  *
  * Sets the currently-selected font.
  *
- * Return value: %TRUE if the font could be set successfully; %FALSE
- *     if no such font exists or if the @fontchooser doesn't belong
- *     to a particular screen yet.
- *
  * Since: 3.2
  */
-gboolean
+void
 gtk_font_chooser_set_font (GtkFontChooser *fontchooser,
                            const gchar    *fontname)
 {
-  g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE);
-  g_return_val_if_fail (fontname != NULL, FALSE);
+  g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
+  g_return_if_fail (fontname != NULL);
+
+  g_object_set (fontchooser, "font", fontname, NULL);
+}
+
+/**
+ * gtk_font_chooser_get_font_desc:
+ * @fontchooser: a #GtkFontChooser
+ *
+ * Gets the currently-selected font.
+ *
+ * Note that this can be a different string than what you set with
+ * gtk_font_chooser_set_font(), as the font chooser widget may
+ * normalize font names and thus return a string with a different
+ * structure. For example, "Helvetica Italic Bold 12" could be
+ * normalized to "Helvetica Bold Italic 12".
+ *
+ * Use pango_font_description_equal() if you want to compare two
+ * font descriptions.
+ *
+ * Return value: (transfer full) (allow-none): A #PangoFontDescription for the
+ *     current font, or %NULL if  no font is selected.
+ *
+ * Since: 3.2
+ */
+PangoFontDescription *
+gtk_font_chooser_get_font_desc (GtkFontChooser *fontchooser)
+{
+  PangoFontDescription *font_desc;
+
+  g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
+
+  g_object_get (fontchooser, "font-desc", &font_desc, NULL);
+
+  return font_desc;
+}
+
+/**
+ * gtk_font_chooser_set_font_desc:
+ * @fontchooser: a #GtkFontChooser
+ * @font_desc: a #PangoFontDescription
+ *
+ * Sets the currently-selected font from @font_desc.
+ *
+ * Since: 3.2
+ */
+void
+gtk_font_chooser_set_font_desc (GtkFontChooser             *fontchooser,
+                                const PangoFontDescription *font_desc)
+{
+  g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
+  g_return_if_fail (font_desc != NULL);
 
-  return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_font (fontchooser,
-                                                             fontname);
+  g_object_set (fontchooser, "font-desc", font_desc, NULL);
 }
 
 /**