diff options
author | Stefano Karapetsas <[email protected]> | 2014-01-20 16:17:02 +0100 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2014-01-20 16:17:02 +0100 |
commit | 64c176af81eb133ecdd13ca54e5c3dba657806ad (patch) | |
tree | b2816472eb9034f469ae59096f3118525ce4aedf /gst-mixer | |
parent | 89df05d618d097c98d0586c67e9d8fb9ae402cb6 (diff) | |
download | mate-media-64c176af81eb133ecdd13ca54e5c3dba657806ad.tar.bz2 mate-media-64c176af81eb133ecdd13ca54e5c3dba657806ad.tar.xz |
gst-mixer: Add GTK3 support
Bump minimum GTK2 version to use GtkComboBoxText for both GTK versions
Diffstat (limited to 'gst-mixer')
-rw-r--r-- | gst-mixer/src/preferences.c | 2 | ||||
-rw-r--r-- | gst-mixer/src/track.c | 6 | ||||
-rw-r--r-- | gst-mixer/src/volume.c | 99 | ||||
-rw-r--r-- | gst-mixer/src/window.c | 9 |
4 files changed, 110 insertions, 6 deletions
diff --git a/gst-mixer/src/preferences.c b/gst-mixer/src/preferences.c index b84b264..76fbcf9 100644 --- a/gst-mixer/src/preferences.c +++ b/gst-mixer/src/preferences.c @@ -103,7 +103,9 @@ mate_volume_control_preferences_init (MateVolumeControlPreferences *prefs) /* make window look cute */ gtk_window_set_title (GTK_WINDOW (prefs), _("Volume Control Preferences")); +#if !GTK_CHECK_VERSION (3, 0, 0) gtk_dialog_set_has_separator (GTK_DIALOG (prefs), FALSE); +#endif gtk_container_set_border_width (GTK_CONTAINER (prefs), 5); gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (prefs))), 2); gtk_dialog_add_buttons (GTK_DIALOG (prefs), diff --git a/gst-mixer/src/track.c b/gst-mixer/src/track.c index 2eb13cc..1861cfd 100644 --- a/gst-mixer/src/track.c +++ b/gst-mixer/src/track.c @@ -116,7 +116,7 @@ cb_option_changed (GtkComboBox *box, MateVolumeControlTrack *ctrl = data; gchar *opt; - opt = gtk_combo_box_get_active_text (box); + opt = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (box)); if (opt) gst_mixer_set_option (ctrl->mixer, GST_MIXER_OPTIONS (ctrl->track), opt); g_free (opt); @@ -542,13 +542,13 @@ mate_volume_control_track_add_option (GtkTable *table, /* optionmenu */ active_opt = gst_mixer_get_option (mixer, options); if (active_opt != NULL) { - ctrl->options = gtk_combo_box_new_text (); + ctrl->options = gtk_combo_box_text_new (); opts = gst_mixer_options_get_values (options); for (opt = opts; opt != NULL; opt = opt->next, i++) { if (opt->data == NULL) continue; - gtk_combo_box_append_text (GTK_COMBO_BOX (ctrl->options), opt->data); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (ctrl->options), opt->data); if (g_str_equal (active_opt, opt->data)) { gtk_combo_box_set_active (GTK_COMBO_BOX (ctrl->options), i); diff --git a/gst-mixer/src/volume.c b/gst-mixer/src/volume.c index 3df721f..9a1aaac 100644 --- a/gst-mixer/src/volume.c +++ b/gst-mixer/src/volume.c @@ -40,12 +40,26 @@ static void mate_volume_control_volume_class_init (MateVolumeControlVolumeClass static void mate_volume_control_volume_init (MateVolumeControlVolume *el); static void mate_volume_control_volume_dispose (GObject *object); +#if GTK_CHECK_VERSION (3, 0, 0) +static void mate_volume_control_volume_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width); +static void mate_volume_control_volume_get_preferred_height (GtkWidget *widget, + gint *minimum_height, + gint *natural_height); +#else static void mate_volume_control_volume_size_req (GtkWidget *widget, GtkRequisition *req); +#endif static void mate_volume_control_volume_size_alloc (GtkWidget *widget, GtkAllocation *alloc); +#if GTK_CHECK_VERSION (3, 0, 0) +static gboolean mate_volume_control_volume_draw (GtkWidget *widget, + cairo_t *cr); +#else static gboolean mate_volume_control_volume_expose (GtkWidget *widget, GdkEventExpose *expose); +#endif static void cb_volume_changed (GtkAdjustment *adj, gpointer data); @@ -63,8 +77,14 @@ mate_volume_control_volume_class_init (MateVolumeControlVolumeClass *klass) gobject_class->dispose = mate_volume_control_volume_dispose; gtkwidget_class->size_allocate = mate_volume_control_volume_size_alloc; +#if GTK_CHECK_VERSION (3, 0, 0) + gtkwidget_class->get_preferred_width = mate_volume_control_volume_get_preferred_width; + gtkwidget_class->get_preferred_height = mate_volume_control_volume_get_preferred_height; + gtkwidget_class->draw = mate_volume_control_volume_draw; +#else gtkwidget_class->size_request = mate_volume_control_volume_size_req; gtkwidget_class->expose_event = mate_volume_control_volume_expose; +#endif } static void @@ -91,7 +111,11 @@ get_scale (MateVolumeControlVolume *vol, gint volume) { GtkWidget *slider; +#if GTK_CHECK_VERSION (3, 0, 0) + GtkAdjustment *adj; +#else GtkObject *adj; +#endif AtkObject *accessible; gchar *accessible_name; @@ -101,7 +125,11 @@ get_scale (MateVolumeControlVolume *vol, (vol->track->max_volume - vol->track->min_volume) / 10.0, 0.0); g_signal_connect (adj, "value_changed", G_CALLBACK (cb_volume_changed), vol); +#if GTK_CHECK_VERSION (3, 0, 0) + slider = gtk_vscale_new (adj); +#else slider = gtk_vscale_new (GTK_ADJUSTMENT (adj)); +#endif gtk_scale_set_draw_value (GTK_SCALE (slider), FALSE); gtk_range_set_inverted (GTK_RANGE (slider), TRUE); @@ -283,9 +311,14 @@ mate_volume_control_volume_size_req (GtkWidget *widget, GtkRequisition but_req, scale_req; /* request size of kids */ +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_get_preferred_size (vol->button, &but_req, NULL); + gtk_widget_get_preferred_size (vol->scales->data, &scale_req, NULL); +#else GTK_WIDGET_GET_CLASS (vol->button)->size_request (vol->button, &but_req); GTK_WIDGET_GET_CLASS (vol->scales->data)->size_request (vol->scales->data, &scale_req); +#endif if (scale_req.height < 100) scale_req.height = 100; @@ -295,6 +328,28 @@ mate_volume_control_volume_size_req (GtkWidget *widget, req->height = scale_req.height + but_req.height /*+ vol->padding*/; } +#if GTK_CHECK_VERSION (3, 0, 0) +static void +mate_volume_control_volume_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width) +{ + GtkRequisition req; + mate_volume_control_volume_size_req (widget, &req); + *minimum_width = *natural_width = req.width; +} + +static void +mate_volume_control_volume_get_preferred_height (GtkWidget *widget, + gint *minimum_height, + gint *natural_height) +{ + GtkRequisition req; + mate_volume_control_volume_size_req (widget, &req); + *minimum_height = *natural_height = req.height; +} +#endif + static void mate_volume_control_volume_size_alloc (GtkWidget *widget, GtkAllocation *alloc) @@ -315,9 +370,14 @@ mate_volume_control_volume_size_alloc (GtkWidget *widget, return; /* request size of kids */ +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_get_preferred_size (vol->button, &but_req, NULL); + gtk_widget_get_preferred_size (vol->scales->data, &scale_req, NULL); +#else GTK_WIDGET_GET_CLASS (vol->button)->size_request (vol->button, &but_req); GTK_WIDGET_GET_CLASS (vol->scales->data)->size_request (vol->scales->data, &scale_req); +#endif /* calculate */ x_offset = (alloc->width - ((vol->track->num_channels * scale_req.width) + @@ -349,17 +409,24 @@ mate_volume_control_volume_size_alloc (GtkWidget *widget, } static gboolean +#if GTK_CHECK_VERSION (3, 0, 0) +mate_volume_control_volume_draw (GtkWidget *widget, + cairo_t *cr) +#else mate_volume_control_volume_expose (GtkWidget *widget, GdkEventExpose *expose) +#endif { GtkAllocation allocation; MateVolumeControlVolume *vol = MATE_VOLUME_CONTROL_VOLUME (widget); +#if !GTK_CHECK_VERSION (3, 0, 0) /* clear background */ gtk_widget_get_allocation (widget, &allocation); gdk_window_clear_area (gtk_widget_get_window (widget), 0, 0, allocation.width, allocation.height); +#endif if (vol->track->num_channels > 1) { gint x_offset, y_offset, height, width; @@ -369,9 +436,14 @@ mate_volume_control_volume_expose (GtkWidget *widget, GtkStateType state; /* request size of kids */ +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_get_preferred_size (vol->button, &but_req, NULL); + gtk_widget_get_preferred_size (vol->scales->data, &scale_req, NULL); +#else GTK_WIDGET_GET_CLASS (vol->button)->size_request (vol->button, &but_req); GTK_WIDGET_GET_CLASS (vol->scales->data)->size_request (vol->scales->data, &scale_req); +#endif /* calculate */ gtk_widget_get_allocation (widget, &allocation); @@ -390,23 +462,50 @@ mate_volume_control_volume_expose (GtkWidget *widget, points[0].x = points[1].x = x_offset + 3; points[2].x = points[0].x + width - 6; +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_move_to (cr, points[0].x, points[0].x); + cairo_line_to (cr, points[1].x, points[1].x); + cairo_move_to (cr, points[1].x, points[1].x); + cairo_line_to (cr, points[2].x, points[2].x); + cairo_move_to (cr, points[0].x, points[0].x); +#else gtk_paint_polygon (style, gtk_widget_get_window (widget), state, GTK_SHADOW_ETCHED_IN, &expose->area, widget, "hseparator", points, 3, FALSE); +#endif points[0].x = points[1].x = allocation.width - x_offset - 3; points[2].x = points[0].x - width + 6; +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_move_to (cr, points[0].x, points[0].x); + cairo_line_to (cr, points[1].x, points[1].x); + cairo_move_to (cr, points[1].x, points[1].x); + cairo_line_to (cr, points[2].x, points[2].x); + cairo_move_to (cr, points[0].x, points[0].x); +#else gtk_paint_polygon (style, gtk_widget_get_window (widget), state, GTK_SHADOW_ETCHED_IN, &expose->area, widget, "hseparator", points, 3, FALSE); +#endif + +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); + cairo_set_line_width (cr, 1.0); + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_stroke (cr); +#endif } /* take care of redrawing the kids */ +#if GTK_CHECK_VERSION (3, 0, 0) + return GTK_WIDGET_CLASS (mate_volume_control_volume_parent_class)->draw (widget, cr); +#else return GTK_WIDGET_CLASS (mate_volume_control_volume_parent_class)->expose_event (widget, expose); +#endif } /* diff --git a/gst-mixer/src/window.c b/gst-mixer/src/window.c index c266ee0..58188c6 100644 --- a/gst-mixer/src/window.c +++ b/gst-mixer/src/window.c @@ -27,6 +27,9 @@ #include <gtk/gtk.h> #include <gio/gio.h> #include <gdk/gdkkeysyms.h> +#if GTK_CHECK_VERSION (3, 0, 0) +#include <gdk/gdkkeysyms-compat.h> +#endif #include "schemas.h" #include "preferences.h" @@ -61,7 +64,7 @@ cb_change (GtkComboBox *widget, { gchar *device_name; - device_name = gtk_combo_box_get_active_text (widget); + device_name = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (widget)); g_return_if_fail (device_name != NULL); g_settings_set_string (win->settings, MATE_VOLUME_CONTROL_KEY_ACTIVE_ELEMENT, device_name); @@ -340,7 +343,7 @@ mate_volume_control_window_new (GList *elements) } active_element_num = count; - combo_box = gtk_combo_box_new_text (); + combo_box = gtk_combo_box_text_new (); renderer = gtk_cell_renderer_text_new (); g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box)); @@ -350,7 +353,7 @@ mate_volume_control_window_new (GList *elements) const gchar *name; name = g_object_get_data (item->data, "mate-volume-control-name"); - gtk_combo_box_append_text(GTK_COMBO_BOX (combo_box), name); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT (combo_box), name); } gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), active_element_num); g_signal_connect (combo_box, "changed", G_CALLBACK (cb_change), win); |