[Geany-Devel] [PATCH geany] gtkcompat: Add gtk_widget_{set_can_default, get_allocation}
Quentin Glidic
sardemff7+geany at xxxxx
Fri Apr 5 08:49:31 UTC 2013
On 05/04/2013 10:39, Thomas Martitz wrote:
> Am 05.04.2013 08:58, schrieb Quentin Glidic:
>> From: Quentin Glidic <sardemff7+git at sardemff7.net>
>>
>> Signed-off-by: Quentin Glidic <sardemff7+git at sardemff7.net>
>> ---
>> src/gtkcompat.h | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/src/gtkcompat.h b/src/gtkcompat.h
>> index ca1c187..7e0276c 100644
>> --- a/src/gtkcompat.h
>> +++ b/src/gtkcompat.h
>> @@ -92,6 +92,12 @@ G_BEGIN_DECLS
>> compat_widget_set_flag((widget), GTK_NO_WINDOW, !(has_window))
>> # define gtk_widget_set_can_focus(widget, can_focus) \
>> compat_widget_set_flag((widget), GTK_CAN_FOCUS, (can_focus))
>> +# define gtk_widget_set_can_default(widget, can_default) \
>> + compat_widget_set_flag((widget), GTK_CAN_DEFAULT, (can_default))
>> +# define gtk_widget_get_allocation(widget, alloc) \
>> + do { \
>> + (alloc) = (((GtkWidget *) (widget))->allocation
>> + } while (0)
>> #endif
>> #if ! GTK_CHECK_VERSION(2, 20, 0)
>> # define gtk_widget_get_mapped(widget) GTK_WIDGET_MAPPED(widget)
>
> This isn't right. alloc is a pointer to caller-provided GtkAllocation.
> If this were a function (inline or not) the pointer would point to
> something else, but that doesn't affect the caller-provided
> GtkAllocation which is supposed to be initialized.
> Since this is a macro I expect it to not even compile (havent tried
> though). You're calling it in a later patch ("addons: Fix GTK+3
> support") like this:
>
> gtk_widget_get_allocation(widget, &allocation);
>
> The macro would expand to:
>
> ..
> (&allocation) = (((GtkWidget *) (widget))->allocation
> ..
>
> That isn't valid C.
Sure, my mistake. I even thought of that exact error when writing the
code, and still I did it…
> This should be correct, as it copies the contents over to the
> caller-provided GtkAllocation:
> *(alloc) = *((GtkAllocation *) ((((GtkWidget *) (widget))->allocation));
That was the code I thought I wrote actually…
> or:
> mempcy(alloc, ((GtkWidget *) (widget))->allocation, sizeof(GtkAllocation));
Not sure which one is better, I would let the choice to Geany devs!
--
Quentin “Sardem FF7” Glidic
More information about the Devel
mailing list