Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 383303 - Use gtk_widget_has_default function for newer gtk versions.
Summary: Use gtk_widget_has_default function for newer gtk versions.
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.8   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.3 M2   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 384749 (view as bug list)
Depends on:
Blocks: 340067
  Show dependency tree
 
Reported: 2012-06-22 08:48 EDT by Alexander Kurtakov CLA
Modified: 2013-05-24 09:34 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Kurtakov CLA 2012-06-22 08:48:28 EDT
The macro used upto now is deprecated and removed in GTK 3.

Commit/patch:
http://fedorapeople.org/gitweb?p=akurtakov/public_git/eclipse.platform.swt.git;a=commit;h=dedb20194a68795bd0f8c3b0e415ba018125408d
Comment 1 Arun Thondapu CLA 2012-06-22 09:16:48 EDT
if (OS.VERSION(2, 20, 0) >= OS.GTK_VERSION) {
        hasDefault = OS.gtk_widget_has_default(handle);

It looks to me like the version check needs to be reversed here.

Also, the check can be modified to invoke gtk_widget_has_default() from GTK version 2.18 and above instead of version 2.20 as this function to replace the macro is available from GTK version 2.18 itself.

Thanks!
Comment 2 Alexander Kurtakov CLA 2012-06-22 09:24:21 EDT
(In reply to comment #1)
> if (OS.VERSION(2, 20, 0) >= OS.GTK_VERSION) {
>         hasDefault = OS.gtk_widget_has_default(handle);
> 
> It looks to me like the version check needs to be reversed here.
> 
> Also, the check can be modified to invoke gtk_widget_has_default() from GTK
> version 2.18 and above instead of version 2.20 as this function to replace the
> macro is available from GTK version 2.18 itself.
> 
> Thanks!

Why should it be reversed ? I used the deprecation version of GTK_WIDGET_HAS_DEFAULT as the check version but I can change it to 2.18 if you prefer. But please explain the reversed I don't understand it.
Comment 3 Arun Thondapu CLA 2012-06-22 09:51:23 EDT
(In reply to comment #2)
> 
> Why should it be reversed ?

The current if condition implies that gtk_widget_has_default() will be invoked when OS.GTK_VERSION <= OS.VERSION(2, 20, 0) and GTK_WIDGET_HAS_DEFAULT() macro will be invoked otherwise. Isn't that the exact opposite of what we intend to do here?

Also, I do prefer changing the version to 2.18.
Comment 4 Alexander Kurtakov CLA 2012-06-22 09:54:38 EDT
(In reply to comment #3)
> (In reply to comment #2)
> > 
> > Why should it be reversed ?
> 
> The current if condition implies that gtk_widget_has_default() will be invoked
> when OS.GTK_VERSION <= OS.VERSION(2, 20, 0) and GTK_WIDGET_HAS_DEFAULT() macro
> will be invoked otherwise. Isn't that the exact opposite of what we intend to
> do here?
> 
> Also, I do prefer changing the version to 2.18.

Well, the current code implies that gtk_widget_has_default will be called when GTK is newer than version 2.20 and this is exactly what it's intended to be.
Comment 5 Arun Thondapu CLA 2012-06-22 10:10:22 EDT
(In reply to comment #4)
> Well, the current code implies that gtk_widget_has_default will be called when
> GTK is newer than version 2.20 and this is exactly what it's intended to be.

I just took a look at the patch again and I still think the if check is wrong. If I assume my GTK version lets say is 2.24, the condition

if (OS.VERSION(2, 20, 0) >= OS.GTK_VERSION)

will fail because it effectively means 2.20 >= 2.24, implying that the else case of GTK_WIDGET_HAS_DEFAULT() macro gets invoked then. Am I making sense?
Comment 6 Alexander Kurtakov CLA 2012-06-22 10:18:10 EDT
Ah sorry, I'm stupid today :). Will redo it on monday.
Comment 8 Arun Thondapu CLA 2012-06-22 13:42:37 EDT
(In reply to comment #7)
> Ok, modified patch.
> 
> http://fedorapeople.org/gitweb?p=akurtakov/public_git/eclipse.platform.swt.git;a=commit;h=c8a188e89cb18f89d56079c805fd32a9da717664

Looks good to me, thanks for the modified patch!
Silenio will probably push the changes soon.
Comment 9 Silenio Quarti CLA 2012-06-26 09:51:39 EDT
The native GTK_WIDGET_HAS_DEFAULT cannot be dynamic for the same reason of https://bugs.eclipse.org/bugs/show_bug.cgi?id=374994#c1.
Comment 10 Alexander Kurtakov CLA 2012-06-26 10:28:50 EDT
(In reply to comment #9)
> The native GTK_WIDGET_HAS_DEFAULT cannot be dynamic for the same reason of
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=374994#c1.

But GTK_WIDGET_HAS_DEFAULT is provided by libgtk so it's not exactly the same case. I have explicitly tested it and the dynamic case works for me too, when in the case you refer to I was getting crashes.
The macro in question comes from gtkwidget.h so even if we can not make it dynamic we can not use the same approach as in the other bug.

cat /usr/include/gtk-2.0/gtk/gtkwidget.h|grep GTK_WIDGET_HAS_DEFAULT
 * GTK_WIDGET_HAS_DEFAULT:
#define GTK_WIDGET_HAS_DEFAULT(wid)       ((GTK_WIDGET_FLAGS (wid) & GTK_HAS_DEFAULT) != 0)
Comment 11 Silenio Quarti CLA 2012-06-26 11:21:04 EDT
GTK_WIDGET_HAS_DEFAULT is a macro, it cannot be look up dynamically. The function pointer is never found and the native always return false silently. Would putting something like this in os_custom.h work when compiling against GTK 3?

#ifndef GTK_WIDGET_HAS_DEFAULT
#define GTK_WIDGET_HAS_DEFAULT(arg0) 0
#endif
Comment 12 Anatoly Spektor CLA 2012-07-12 14:52:12 EDT
*** Bug 384749 has been marked as a duplicate of this bug. ***
Comment 13 Anatoly Spektor CLA 2012-07-12 14:56:26 EDT
My patch has #define GTK_WIDGET_HAS_DEFAULT as pointed by Silenio, feel free to use it, if you like:

http://fedorapeople.org/gitweb?p=aspektor/public_git/eclipse.platform.swt.git;a=commit;h=ce3fc00e298b9fc1bb0b1a142f5a8d8f283e2572
Comment 15 Anatoly Spektor CLA 2012-08-01 10:28:54 EDT
Thank you for fixing formatting Silenio,

   I will pay more attention to spaces and tabs in my future patches.

Regards,

Anatoly