--- widgets/src/HubWindow.c | 36 +++++++++++++++++++++++++++++++----- widgets/src/StandaloneWindow.c | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 66 insertions(+), 10 deletions(-)
diff --git a/widgets/src/HubWindow.c b/widgets/src/HubWindow.c index 6756a31..b776016 100644 --- a/widgets/src/HubWindow.c +++ b/widgets/src/HubWindow.c @@ -100,18 +100,36 @@ static int get_sidebar_height(GtkWidget *window) {
/* function to override default drawing to insert sidebar image */ static gboolean anaconda_hub_window_on_draw(GtkWidget *win, cairo_t *cr) { + GtkStyleContext *context; + gdouble sidebar_x; + gdouble sidebar_width; + /* calls parent class' draw handler */ GTK_WIDGET_CLASS(anaconda_hub_window_parent_class)->draw(win,cr);
- GtkStyleContext * context = gtk_widget_get_style_context(win); + sidebar_width = get_sidebar_width(win); + + /* For RTL languages, move the sidebar to the right edge */ + if (gtk_get_locale_direction() == GTK_TEXT_DIR_LTR) + { + sidebar_x = 0; + } + else + { + GtkAllocation allocation; + gtk_widget_get_allocation(win, &allocation); + sidebar_x = allocation.width - sidebar_width; + } + + context = gtk_widget_get_style_context(win); gtk_style_context_save (context);
gtk_style_context_add_class(context, "logo-sidebar"); - gtk_render_background(context, cr, 0, 0, get_sidebar_width(win), get_sidebar_height(win)); + gtk_render_background(context, cr, sidebar_x, 0, sidebar_width, get_sidebar_height(win)); gtk_style_context_remove_class(context, "logo-sidebar");
gtk_style_context_add_class(context, "logo"); - gtk_render_background(context, cr, 0, 0, get_sidebar_width(win), get_sidebar_height(win)); + gtk_render_background(context, cr, sidebar_x, 0, sidebar_width, get_sidebar_height(win)); gtk_style_context_remove_class(context, "logo");
gtk_style_context_restore (context); @@ -119,7 +137,7 @@ static gboolean anaconda_hub_window_on_draw(GtkWidget *win, cairo_t *cr) { return TRUE; /* TRUE to avoid default draw handler */ }
-/* Move base window content appropriate amount of space to the right to make room for sidebar */ +/* Move base window content appropriate amount of space to make room for sidebar */ static void anaconda_hub_window_size_allocate (GtkWidget *window, GtkAllocation *allocation) { GtkAllocation child_allocation; GtkWidget *child; @@ -127,11 +145,19 @@ static void anaconda_hub_window_size_allocate (GtkWidget *window, GtkAllocation
gtk_widget_set_allocation(window, allocation); sidebar_width = get_sidebar_width(window); - child_allocation.x = allocation->x+sidebar_width; child_allocation.y = allocation->y; child_allocation.width = allocation->width-sidebar_width; child_allocation.height = allocation->height;
+ if (gtk_get_locale_direction() == GTK_TEXT_DIR_LTR) + { + child_allocation.x = allocation->x+sidebar_width; + } + else + { + child_allocation.x = allocation->x; + } + child = gtk_bin_get_child (GTK_BIN (window)); if (child && gtk_widget_get_visible (child)) gtk_widget_size_allocate (child, &child_allocation); diff --git a/widgets/src/StandaloneWindow.c b/widgets/src/StandaloneWindow.c index 0ccf56e..53a4b49 100644 --- a/widgets/src/StandaloneWindow.c +++ b/widgets/src/StandaloneWindow.c @@ -88,18 +88,36 @@ static int get_sidebar_height(GtkWidget *window) {
/* function to override default drawing to insert sidebar image */ static gboolean anaconda_standalone_window_on_draw(GtkWidget *win, cairo_t *cr) { + GtkStyleContext *context; + gdouble sidebar_x; + gdouble sidebar_width; + /* calls parent class' draw handler */ GTK_WIDGET_CLASS(anaconda_standalone_window_parent_class)->draw(win,cr);
- GtkStyleContext * context = gtk_widget_get_style_context(win); + sidebar_width = get_sidebar_width(win); + + /* For RTL languages, move the sidebar to the right edge */ + if (gtk_get_locale_direction() == GTK_TEXT_DIR_LTR) + { + sidebar_x = 0; + } + else + { + GtkAllocation allocation; + gtk_widget_get_allocation(win, &allocation); + sidebar_x = allocation.width - sidebar_width; + } + + context = gtk_widget_get_style_context(win); gtk_style_context_save (context);
gtk_style_context_add_class(context, "logo-sidebar"); - gtk_render_background(context, cr, 0, 0, get_sidebar_width(win), get_sidebar_height(win)); + gtk_render_background(context, cr, sidebar_x, 0, sidebar_width, get_sidebar_height(win)); gtk_style_context_remove_class(context, "logo-sidebar");
gtk_style_context_add_class(context, "logo"); - gtk_render_background(context, cr, 0, 0, get_sidebar_width(win), get_sidebar_height(win)); + gtk_render_background(context, cr, sidebar_x, 0, sidebar_width, get_sidebar_height(win)); gtk_style_context_remove_class(context, "logo");
gtk_style_context_restore (context); @@ -107,19 +125,31 @@ static gboolean anaconda_standalone_window_on_draw(GtkWidget *win, cairo_t *cr) return TRUE; /* TRUE to avoid default draw handler */ }
-/* Move base window content appropriate amount of space to the right to make room for sidebar */ +/* Move base window content appropriate amount of space to make room for sidebar */ static void anaconda_standalone_window_size_allocate (GtkWidget *window, GtkAllocation *allocation) { GtkAllocation child_allocation; GtkWidget *child; int sidebar_width;
+ /* + * For RTL languages, the width is reduced by the same amount, but the + * start of the window does not need to move. + */ gtk_widget_set_allocation(window, allocation); sidebar_width = get_sidebar_width(window); - child_allocation.x = allocation->x+sidebar_width; child_allocation.y = allocation->y; child_allocation.width = allocation->width-sidebar_width; child_allocation.height = allocation->height;
+ if (gtk_get_locale_direction() == GTK_TEXT_DIR_LTR) + { + child_allocation.x = allocation->x+sidebar_width; + } + else + { + child_allocation.x = allocation->x; + } + child = gtk_bin_get_child (GTK_BIN (window)); if (child && gtk_widget_get_visible (child)) gtk_widget_size_allocate (child, &child_allocation);
On Fri, 2014-02-21 at 20:05 -0500, David Shea wrote:
widgets/src/HubWindow.c | 36 +++++++++++++++++++++++++++++++----- widgets/src/StandaloneWindow.c | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 66 insertions(+), 10 deletions(-)
diff --git a/widgets/src/HubWindow.c b/widgets/src/HubWindow.c index 6756a31..b776016 100644 --- a/widgets/src/HubWindow.c +++ b/widgets/src/HubWindow.c @@ -100,18 +100,36 @@ static int get_sidebar_height(GtkWidget *window) {
/* function to override default drawing to insert sidebar image */ static gboolean anaconda_hub_window_on_draw(GtkWidget *win, cairo_t *cr) {
- GtkStyleContext *context;
- gdouble sidebar_x;
- gdouble sidebar_width;
- /* calls parent class' draw handler */ GTK_WIDGET_CLASS(anaconda_hub_window_parent_class)->draw(win,cr);
- GtkStyleContext * context = gtk_widget_get_style_context(win);
sidebar_width = get_sidebar_width(win);
/* For RTL languages, move the sidebar to the right edge */
if (gtk_get_locale_direction() == GTK_TEXT_DIR_LTR)
{
sidebar_x = 0;}
else
{
GtkAllocation allocation;gtk_widget_get_allocation(win, &allocation);sidebar_x = allocation.width - sidebar_width;}
context = gtk_widget_get_style_context(win); gtk_style_context_save (context);
gtk_style_context_add_class(context, "logo-sidebar");
- gtk_render_background(context, cr, 0, 0, get_sidebar_width(win), get_sidebar_height(win));
gtk_render_background(context, cr, sidebar_x, 0, sidebar_width, get_sidebar_height(win)); gtk_style_context_remove_class(context, "logo-sidebar");
gtk_style_context_add_class(context, "logo");
- gtk_render_background(context, cr, 0, 0, get_sidebar_width(win), get_sidebar_height(win));
gtk_render_background(context, cr, sidebar_x, 0, sidebar_width, get_sidebar_height(win)); gtk_style_context_remove_class(context, "logo");
gtk_style_context_restore (context);
@@ -119,7 +137,7 @@ static gboolean anaconda_hub_window_on_draw(GtkWidget *win, cairo_t *cr) { return TRUE; /* TRUE to avoid default draw handler */ }
-/* Move base window content appropriate amount of space to the right to make room for sidebar */ +/* Move base window content appropriate amount of space to make room for sidebar */ static void anaconda_hub_window_size_allocate (GtkWidget *window, GtkAllocation *allocation) { GtkAllocation child_allocation; GtkWidget *child; @@ -127,11 +145,19 @@ static void anaconda_hub_window_size_allocate (GtkWidget *window, GtkAllocation
gtk_widget_set_allocation(window, allocation); sidebar_width = get_sidebar_width(window);
- child_allocation.x = allocation->x+sidebar_width; child_allocation.y = allocation->y; child_allocation.width = allocation->width-sidebar_width; child_allocation.height = allocation->height;
- if (gtk_get_locale_direction() == GTK_TEXT_DIR_LTR)
- {
child_allocation.x = allocation->x+sidebar_width;- }
- else
- {
child_allocation.x = allocation->x;- }
I remember guys pointing out to me that we don't use curly brackets around one-line blocks in our C code. It wasn't true consistently by that time and I'm not sure if it has changed in the meantime, but I think you can drop them in cases like this one.
Otherwise this looks good to me.
On 02/24/2014 03:48 AM, Vratislav Podzimek wrote:
I remember guys pointing out to me that we don't use curly brackets around one-line blocks in our C code. It wasn't true consistently by that time and I'm not sure if it has changed in the meantime, but I think you can drop them in cases like this one.
Ok. I tend to err on the side of more punctuation when I do C, but whatever. For the block that's
+ if (gtk_get_locale_direction() == GTK_TEXT_DIR_LTR) + { + child_allocation.x = allocation->x+sidebar_width; + } + else + { + child_allocation.x = allocation->x; + }
I'll change that to dump the brackets, but for the block that's
+ if (gtk_get_locale_direction() == GTK_TEXT_DIR_LTR) + { + sidebar_x = 0; + } + else + { + GtkAllocation allocation; + gtk_widget_get_allocation(win, &allocation); + sidebar_x = allocation.width - sidebar_width; + }
I'm going to keep all the brackets, because elsewhere lies madness. I can move the opening brackets to the same line as the if/elses instead of giving them their own line, though. I don't know our habits on that.
On Mon, 2014-02-24 at 09:48 +0100, Vratislav Podzimek wrote:
On Fri, 2014-02-21 at 20:05 -0500, David Shea wrote:
- if (gtk_get_locale_direction() == GTK_TEXT_DIR_LTR)
- {
child_allocation.x = allocation->x+sidebar_width;- }
- else
- {
child_allocation.x = allocation->x;- }
I remember guys pointing out to me that we don't use curly brackets around one-line blocks in our C code. It wasn't true consistently by that time and I'm not sure if it has changed in the meantime, but I think you can drop them in cases like this one.
I'm pretty sure there's some folks at Apple¹ who would recommend against using this coding style right now :P
-w
anaconda-patches@lists.fedorahosted.org