GTK3 porting problem (clipboard)
I resolved the majority of the the issues when porting my program from GTK 2.x to GTK 3.x. Unfortunately I still have one issue left: when compiling the program on Feodra 15 alpha (gcc 4.6, GTK3 v3.0.2) I get these errors: ./src/clipboard.cpp:442:38: error: invalid use of incomplete type 'GtkTargetList' /usr/include/gtk-3.0/gtk/gtkselection.h:48:16: error: forward declaration of 'GtkTargetList' ./src/clipboard.cpp:445:20: error: invalid use of incomplete type 'GtkTargetList' /usr/include/gtk-3.0/gtk/gtkselection.h:48:16: error: forward declaration of 'GtkTargetList' ./src/clipboard.cpp:447:3: error: 'GtkTargetPair' was not declared in this scope ./src/clipboard.cpp:447:18: error: 'pair' was not declared in this scope The relevant code is this: #include GtkTargetList *list = gtk_target_list_new (NULL, 0); .. add text and other targets in the list // LINE 442: error: invalid use of incomplete type 'GtkTargetList' int nTargetCnt = g_list_length (list->list); //LINE 445: error: invalid use of incomplete type 'GtkTargetList' for (GList *l=list->list; l; l=l->next, i++) //LINE 447: error: 'GtkTargetPair' was not declared in this scope GtkTargetPair *pair = (GtkTargetPair *)l->data; This all works fine with GTK2.x. What is the correct way to work with this on GTK 3.x ? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
于 2011年03月10日 20:44, Miroslav Rajcic 写道: I resolved the majority of the the issues when porting my program from GTK 2.x to GTK 3.x. Unfortunately I still have one issue left: when compiling the program on Feodra 15 alpha (gcc 4.6, GTK3 v3.0.2) I get these errors: ./src/clipboard.cpp:442:38: error: invalid use of incomplete type 'GtkTargetList' /usr/include/gtk-3.0/gtk/gtkselection.h:48:16: error: forward declaration of 'GtkTargetList' ./src/clipboard.cpp:445:20: error: invalid use of incomplete type 'GtkTargetList' /usr/include/gtk-3.0/gtk/gtkselection.h:48:16: error: forward declaration of 'GtkTargetList' ./src/clipboard.cpp:447:3: error: 'GtkTargetPair' was not declared in this scope ./src/clipboard.cpp:447:18: error: 'pair' was not declared in this scope The relevant code is this: #include GtkTargetList *list = gtk_target_list_new (NULL, 0); .. add text and other targets in the list // LINE 442: error: invalid use of incomplete type 'GtkTargetList' int nTargetCnt = g_list_length (list->list); //LINE 445: error: invalid use of incomplete type 'GtkTargetList' for (GList *l=list->list; l; l=l->next, i++) //LINE 447: error: 'GtkTargetPair' was not declared in this scope GtkTargetPair *pair = (GtkTargetPair *)l->data; This all works fine with GTK2.x. What is the correct way to work with this on GTK 3.x ? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list gtk3-devel package in Fedora 14 is too old (2.90.5). Maybe you want to get latest version (I'm not sure). -- Mike. Blog: http://ekd123.org/ Fedora Project Contributor - Translator. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
gtk3-devel package in Fedora 14 is too old (2.90.5). Maybe you want to get latest version (I'm not sure). Actually, I use GTK3 v3.0.2 on Fedora 15 alpha. This is the last version I could find in their repository. Is there any other distro on the net with newer packages ? I'd prefer if I don't have to compile GTK by myself. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
I don't know the answer, but this is "wrong": int nTargetCnt = g_list_length (list->list); g_list_length returns guint, not int. Although this is valid code (implicit typecast), it can cause bad things. On 03/10/2011 01:44 PM, Miroslav Rajcic wrote: I resolved the majority of the the issues when porting my program from GTK 2.x to GTK 3.x. Unfortunately I still have one issue left: when compiling the program on Feodra 15 alpha (gcc 4.6, GTK3 v3.0.2) I get these errors: ./src/clipboard.cpp:442:38: error: invalid use of incomplete type 'GtkTargetList' /usr/include/gtk-3.0/gtk/gtkselection.h:48:16: error: forward declaration of 'GtkTargetList' ./src/clipboard.cpp:445:20: error: invalid use of incomplete type 'GtkTargetList' /usr/include/gtk-3.0/gtk/gtkselection.h:48:16: error: forward declaration of 'GtkTargetList' ./src/clipboard.cpp:447:3: error: 'GtkTargetPair' was not declared in this scope ./src/clipboard.cpp:447:18: error: 'pair' was not declared in this scope The relevant code is this: #include GtkTargetList *list = gtk_target_list_new (NULL, 0); .. add text and other targets in the list // LINE 442: error: invalid use of incomplete type 'GtkTargetList' int nTargetCnt = g_list_length (list->list); //LINE 445: error: invalid use of incomplete type 'GtkTargetList' for (GList *l=list->list; l; l=l->next, i++) //LINE 447: error: 'GtkTargetPair' was not declared in this scope GtkTargetPair *pair = (GtkTargetPair *)l->data; This all works fine with GTK2.x. What is the correct way to work with this on GTK 3.x ? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
I don't know the answer, but this is "wrong": int nTargetCnt = g_list_length (list->list); But as you say, it doesn't help me :( ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
From GTK documentation: --- A GtkTargetList structure is a reference counted list of GtkTargetPair. It is used to represent the same information as a table of GtkTargetEntry, but in an efficient form. This structure should be treated as opaque. --- Important to read is "This structure should be treated as opaque". You shouldn't access members of this structure directly. In GTK2, structure definition was available in GTK headers, in GTK3, it is not. Info: http://library.gnome.org/devel/gtk3/stable/gtk3-Selections.html#GtkTargetList-struct Hope this helps J. On 03/10/2011 08:11 PM, Miroslav Rajcic wrote: I don't know the answer, but this is "wrong": int nTargetCnt = g_list_length (list->list); But as you say, it doesn't help me :( ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
On Fri, 11 Mar 2011, [windows-1252] Jaroslav ^Jm�d wrote: > From GTK documentation: > > --- > A GtkTargetList structure is a reference counted list of GtkTargetPair. > It is used to represent the same information as a table of > GtkTargetEntry, but in an efficient form. This structure should be > treated as opaque. > --- > > Important to read is "This structure should be treated as opaque". > You shouldn't access members of this structure directly. In GTK2, > structure definition was available in GTK headers, in GTK3, it is not. > > Info: > http://library.gnome.org/devel/gtk3/stable/gtk3-Selections.html#GtkTargetList-struct You're right, but this seems odd. In the GTK3 version of the documentation the basic structures GtkTargetEntry and GtkTargetPair are still exposed in the API, and although GtkTargetList is said to be opaque (a) it's unclear why this should be so (it seems to be a trivial composite) and (b) the functionality that was previously available via the struct itself is not replicated via accessor functions. For example, there's no gtk_target_list_get_n_targets() to replace the original poster's GTK2 idiom: int nTargetCnt = g_list_length (list->list); Allin Cottrell ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
You're right, but this seems odd. In the GTK3 version of the documentation the basic structures GtkTargetEntry and GtkTargetPair are still exposed in the API, and although GtkTargetList is said to be opaque (a) it's unclear why this should be so (it seems to be a trivial composite) and (b) the functionality that was previously available via the struct itself is not replicated via accessor functions. For example, there's no gtk_target_list_get_n_targets() to replace the original poster's GTK2 idiom: int nTargetCnt = g_list_length (list->list); Perhaps someone knows any workaround for what I am trying to do in my code or a way to implement this differently? The code does the following: //create a target list with text and HTML formats GtkTargetList *list = gtk_target_list_new (NULL, 0); gtk_target_list_add(list, atomTextHtml, 0, 0); gtk_target_list_add_text_targets(list, 0); //now I need to convert the target list to an array of the GtkTargetEntry structures as needed by gtk_clipboard_set_with_data int nTargetCnt = g_list_length (list->list); GtkTargetEntry *targets = g_new0 (GtkTargetEntry, nTargetCnt); int i=0; for (GList *l=list->list; l; l=l->next, i++) { GtkTargetPair *pair = (GtkTargetPair *)l->data; targets[i].target = gdk_atom_name (pair->target); } //set the clipboard with target formats gboolean bOK = gtk_clipboard_set_with_data(clipboard, targets, nTargetCnt, MyGtkClipboardGetFunc, NULL, 0); Basically the big problem is that gtk_clipboard_set_with_data API does not use GtktargetList directly. Regards, Miroslav ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
GtkTargetEntry targets[] = { {"text/html", 0, 0}, {"text/plain", 0, 0} }; size_t num_targets = sizeof(targets) / sizeof(targets[]); // This IS required no matter what, or your program WILL BE broken if (sizeof(size_t) > sizeof(guint) && num_targets > (size_t)G_MAX_GUINT) { // fail here because of stupid decision to use guint instead of size_t // this might get optimised away by compiler (condition is know to be false/true during compile-time } gtk_clipboard_set_with_data(clipboard, targets, (guint)num_targets, get_func, clear_func, data); NOTE: you will get warning about conversion from const char* to char*. This is that even though this was reported as BUG years ago, once it was fixed and that fix was removed because it broke existing apps. Still, the could've fixed this for GTK3, but they didn't. Right way to do this would be either allocate string using strdup and than free it, or use something like this: char target1[] = "text/html"; char target2[] = "text/plain"; // char *target = "blabla"; // this is NOT right GtkTargetEntry targets[] = { { target1, 0, 0}, { target2, 0, 0}, }; On 03/11/2011 08:55 AM, Miroslav Rajcic wrote: You're right, but this seems odd. In the GTK3 version of the documentation the basic structures GtkTargetEntry and GtkTargetPair are still exposed in the API, and although GtkTargetList is said to be opaque (a) it's unclear why this should be so (it seems to be a trivial composite) and (b) the functionality that was previously available via the struct itself is not replicated via accessor functions. For example, there's no gtk_target_list_get_n_targets() to replace the original poster's GTK2 idiom: int nTargetCnt = g_list_length (list->list); Perhaps someone knows any workaround for what I am trying to do in my code or a way to implement this differently? The code does the following: //create a target list with text and HTML formats GtkTargetList *list = gtk_target_list_new (NULL, 0); gtk_target_list_add(list, atomTextHtml, 0, 0); gtk_target_list_add_text_targets(list, 0); //now I need to convert the target list to an array of the GtkTargetEntry structures as needed by gtk_clipboard_set_with_data int nTargetCnt = g_list_length (list->list); GtkTargetEntry *targets = g_new0 (GtkTargetEntry, nTargetCnt); int i=0; for (GList *l=list->list; l; l=l->next, i++) { GtkTargetPair *pair = (GtkTargetPair *)l->data; targets[i].target = gdk_atom_name (pair->target); } //set the clipboard with target formats gboolean bOK = gtk_clipboard_set_with_data(clipboard, targets, nTargetCnt, MyGtkClipboardGetFunc, NULL, 0); Basically the big problem is that gtk_clipboard_set_with_data API does not use GtktargetList directly. Regards, Miroslav ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
And perhaps missing accessors for GtkTargetList should be reported as BUG. On 03/11/2011 08:55 AM, Miroslav Rajcic wrote: You're right, but this seems odd. In the GTK3 version of the documentation the basic structures GtkTargetEntry and GtkTargetPair are still exposed in the API, and although GtkTargetList is said to be opaque (a) it's unclear why this should be so (it seems to be a trivial composite) and (b) the functionality that was previously available via the struct itself is not replicated via accessor functions. For example, there's no gtk_target_list_get_n_targets() to replace the original poster's GTK2 idiom: int nTargetCnt = g_list_length (list->list); Perhaps someone knows any workaround for what I am trying to do in my code or a way to implement this differently? The code does the following: //create a target list with text and HTML formats GtkTargetList *list = gtk_target_list_new (NULL, 0); gtk_target_list_add(list, atomTextHtml, 0, 0); gtk_target_list_add_text_targets(list, 0); //now I need to convert the target list to an array of the GtkTargetEntry structures as needed by gtk_clipboard_set_with_data int nTargetCnt = g_list_length (list->list); GtkTargetEntry *targets = g_new0 (GtkTargetEntry, nTargetCnt); int i=0; for (GList *l=list->list; l; l=l->next, i++) { GtkTargetPair *pair = (GtkTargetPair *)l->data; targets[i].target = gdk_atom_name (pair->target); } //set the clipboard with target formats gboolean bOK = gtk_clipboard_set_with_data(clipboard, targets, nTargetCnt, MyGtkClipboardGetFunc, NULL, 0); Basically the big problem is that gtk_clipboard_set_with_data API does not use GtktargetList directly. Regards, Miroslav ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
GtkTargetEntry targets[] = { {"text/html", 0, 0}, {"text/plain", 0, 0} }; size_t num_targets = sizeof(targets) / sizeof(targets[]); This would work if I would know the count of the targets in advance. I want to support all possible text formats, so I use "gtk_target_list_add_text_targets" as shown in my previous mail. The problem is that "gtk_target_list_add_text_targets" adds several text related formats. At compile time I don't know how many formats will it add, it can probably vary from platform to platform or according to some other state. This makes your static array of entries unusable to me :( Regards, Miroslav ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
Maybe you should report the bug about missing accessors so it gets fixed. On 03/11/2011 12:06 PM, Miroslav Rajcic wrote: GtkTargetEntry targets[] = { {"text/html", 0, 0}, {"text/plain", 0, 0} }; size_t num_targets = sizeof(targets) / sizeof(targets[]); This would work if I would know the count of the targets in advance. I want to support all possible text formats, so I use "gtk_target_list_add_text_targets" as shown in my previous mail. The problem is that "gtk_target_list_add_text_targets" adds several text related formats. At compile time I don't know how many formats will it add, it can probably vary from platform to platform or according to some other state. This makes your static array of entries unusable to me :( Regards, Miroslav ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
On Fri, Mar 11, 2011 at 11:42:12AM +0100, Jaroslav Šmíd wrote: > GtkTargetEntry targets[] = { > {"text/html", 0, 0}, > {"text/plain", 0, 0} > }; > > size_t num_targets = sizeof(targets) / sizeof(targets[]); > > // This IS required no matter what, or your program WILL BE broken > if (sizeof(size_t) > sizeof(guint) && num_targets > (size_t)G_MAX_GUINT) { > // fail here because of stupid decision to use guint instead of size_t > // this might get optimised away by compiler (condition is know to be > false/true during compile-time > } You are no fun any more. Yeti ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
Maybe you should report the bug about missing accessors so it gets fixed. I've added the bug report here: https://bugzilla.gnome.org/show_bug.cgi?id=644490 Feel free to comment or add suggestions there. Thanks to everyone for the help. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
Seems I was blind not to see gtk_target_table_from_list. And maybe I was not alone :-) J. On 03/10/2011 01:44 PM, Miroslav Rajcic wrote: I resolved the majority of the the issues when porting my program from GTK 2.x to GTK 3.x. Unfortunately I still have one issue left: when compiling the program on Feodra 15 alpha (gcc 4.6, GTK3 v3.0.2) I get these errors: ./src/clipboard.cpp:442:38: error: invalid use of incomplete type 'GtkTargetList' /usr/include/gtk-3.0/gtk/gtkselection.h:48:16: error: forward declaration of 'GtkTargetList' ./src/clipboard.cpp:445:20: error: invalid use of incomplete type 'GtkTargetList' /usr/include/gtk-3.0/gtk/gtkselection.h:48:16: error: forward declaration of 'GtkTargetList' ./src/clipboard.cpp:447:3: error: 'GtkTargetPair' was not declared in this scope ./src/clipboard.cpp:447:18: error: 'pair' was not declared in this scope The relevant code is this: #include GtkTargetList *list = gtk_target_list_new (NULL, 0); .. add text and other targets in the list // LINE 442: error: invalid use of incomplete type 'GtkTargetList' int nTargetCnt = g_list_length (list->list); //LINE 445: error: invalid use of incomplete type 'GtkTargetList' for (GList *l=list->list; l; l=l->next, i++) //LINE 447: error: 'GtkTargetPair' was not declared in this scope GtkTargetPair *pair = (GtkTargetPair *)l->data; This all works fine with GTK2.x. What is the correct way to work with this on GTK 3.x ? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GTK3 porting problem (clipboard)
Seems I was blind not to see gtk_target_table_from_list. And maybe I was not alone :-) J. So true :) ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list