GNOME Bugzilla – Bug 553765
Add orientation API to GtkRange
Last modified: 2010-07-10 03:50:54 UTC
See bug #541009. Here are the patches for GtkRange and all its subclasses.
Created attachment 119362 [details] [review] Patch implementing the above This one is a bit more complex: - GtkRange: add orientation API, add some evil code that makes sure we keep using the right drawing details instead of always the ones from GtkRangeClass. - GtkScale: swallow all code from GtkHScale and GtkVScale, set the drawing detail in GtkRangeClass in a way that triggers above magic in GtkRange. Make sure the range is set to flippable when the orientation is horizontal, but not when it's vertical. - GtkScrollbar: set the drawing detail so range's magic is triggered.
One think I don't like about the evil details business is that this makes the detail string per instance, rather than per class. How about using static strings instead of duping the string for each instance ?
(In reply to comment #2) > One think I don't like about the evil details business is that this makes the > detail string per instance, rather than per class. How about using static > strings instead of duping the string for each instance ? The problem with using static strings is that the detail string is partly determined by sub classes ("scale", "scrollbar") and partly from orientation state ("h"/"v"). However since only a limited set of strings make sense here and are very likely to be reused over the program lifetime, i agree with Matthias that wasting strdup-ed space for these strings per instance should be fixed. I suggest changing _get_*_detail() so that it does: gchar *s = g_strdup_printf ("createdynamicstring..."); GQuark q = g_quark_from_string (s); g_free (s); return g_quark_to_string (q);
Created attachment 122428 [details] [review] Updated patch - caches the detail strings in quarks - implements the GtkOrientable interface
+ * gtk_scale_new: + * @orientation: the scale's orientation. + * @adjustment: the #GtkAdjustment which sets the range of the scale. Should add ", or %NULL to create a new adjustement" for the adjustment, since that is what the code does. + if (!layout) I prefer to reserve ! for actual booleans nowadays, and use != NULL for pointers, but no big deal... Other than that, looks good to me.
Committed including above mentioned doc fix. Leaving the bug open since deprecation needs to be discussed. Also, GtkScrollbar and GtkScale are not abstract any longer so we can change their defaults. Needs discussion too. 2008-11-11 Michael Natterer <mitch@imendio.com> Bug 553765 – Add orientation API to GtkRange * gtk/gtkrange.[ch]: implement the GtkOrientable interface. Add evil code that makes sure that the stepper_detail and slider_detail set in GtkRangeClass continue to work with the hacked subclasses below. * gtk/gtkscale.[ch]: swallow all code from GtkHScale and GtkVScale and add gtk_scale_new() and gtk_scale_new_with_range() which take a GtkOrientation argument. Set slider_detail to "Xscale" so above evil code works. * gtk/gtkscrollbar.[ch]: add gtk_scrollbar_new() which takes a GtkOrientation argument. Set stepper_detail to "Xscrollbar" so above evil code works. * gtk/gtkhscale.c * gtk/gtkvscale.c * gtk/gtkhscrollbar.c * gtk/gtkvscrollbar.c: remove all code except the constructor and call gtk_orientable_set_orientation() in init(). * gtk/gtk.symbols: changed accordingly.