Page 1 of 1

[Linux 4.10b3] gtk_ and unicode

Posted: Thu Oct 25, 2007 11:26 am
by walker
why does the following code work with unicode disabled but not with unicode enabled?
I'm a bit clueless..... :roll:

Code: Select all

;to access them everywhere
Global *toolbar1.gtkwidget
Global *toolbutton1.gtkwidget
Global *toolbutton6.gtkwidget
Global *tooltips.GtkTooltips
;constants
Enumeration 
    #toolbar_0
EndEnumeration

ProcedureCDLL on_new_toolbutton_clicked (toolbutton,user_data)

EndProcedure

ProcedureCDLL on_exit_toolbutton_clicked (toolbutton,user_data)
    End
EndProcedure

Procedure Open_Window_0()
    If OpenWindow(0,0,0,500,350,"GTK2-Toolbar",#PB_Window_ScreenCentered)
        If CreateGadgetList(WindowID(0))
        *tooltips = gtk_tooltips_new_();
        *toolbar1= CreateToolBar(#toolbar_0,WindowID(0))
         gtk_widget_show_(*toolbar1);
         gtk_toolbar_set_style_(*toolbar1, #GTK_TOOLBAR_BOTH)
         tmp_toolbar_icon_size = gtk_toolbar_get_icon_size_(*toolbar1);
          
        *toolbutton1 = gtk_tool_button_new_from_stock_("gtk-new")
        gtk_widget_show_(*toolbutton1);
        gtk_container_add_(*toolbar1, *toolbutton1);
        gtk_tool_item_set_tooltip_(*toolbutton1, *tooltips,"New", #Null);
                 
        *toolbutton6 = gtk_tool_button_new_from_stock_("gtk-quit");
        gtk_widget_show_(*toolbutton6);
        gtk_container_add_(*toolbar1, *toolbutton6);
        gtk_tool_item_set_tooltip_(*toolbutton6, *tooltips,"Quit", #Null);
        
        CloseGadgetList()
        
        g_signal_connect_object_( *toolbutton1, "clicked",@on_new_toolbutton_clicked(),*pointer,0)
        g_signal_connect_object_( *toolbutton6, "clicked",@on_exit_toolbutton_clicked(),*pointer,0)
      EndIf
  EndIf
  EndProcedure

Open_Window_0()
Repeat
event=WaitWindowEvent()
Until event = #PB_Event_CloseWindow
End  
  

Output of console-Debugger when compiled with unicode enabled:

Code: Select all

(purebasic_compilation0.out:8524): GLib-GObject-WARNING **: /build/buildd/glib2.0-2.14.1/gobject/gsignal.c:1669: signal `c' is invalid for instance `0x80f2070'

(purebasic_compilation0.out:8524): GLib-GObject-WARNING **: /build/buildd/glib2.0-2.14.1/gobject/gsignal.c:1669: signal `c' is invalid for instance `0x80f20f8'



Posted: Thu Oct 25, 2007 11:36 am
by freak
Because gtk (version 2 anyway) uses UTF-8 everywhere. You have to convert your signal name
to UTF-8 before passing it to the gtk function.

Posted: Thu Oct 25, 2007 1:32 pm
by walker
..even if i comment out the 2 lines for the signal connect... an empty toolbar is created... (though with two buttons.. but no text and no image)

If i determine the locale encoding with g_get_charset_(cs.s) it returns 1 what means, utf8 encoding is used by the system (and therefor no conversion is needed.....?)

even if I try to convert the signal name with g_convert_() nothing changes...

Posted: Thu Oct 25, 2007 1:56 pm
by freak
When you turn on unicode, all PB strings are in UCS2 format. (same as UTF16 without 4byte sequences)
This is independant from the locale used on your system.

So there are null-bytes inside the strings.
Gtk expects the strings in utf8, so it stops at the first null byte found.

You use gtk_tool_button_new_from_stock_() which expects a string
as well. It will only see a single character though and fail to load an image.

Posted: Thu Oct 25, 2007 2:46 pm
by Fred
That's true than it makes gtk hardly usable with unicode, as there is a lot of functions which uses a string as parameter. To workaround it (until we change the way the .pbl are handled), you can create an Import section with your functions using a p-utf8 type where needed.

Code: Select all

Import ""
  gtk_tool_button_new_from_stock_unicode(a.p-utf8)
EndImport
Another way is to do a procedure "ToUTF8()" which returns the converted string (use PokeS(..., #PB_UTF8)) in unicode mode, and does nothing in none unicode mode.

Posted: Thu Oct 25, 2007 4:08 pm
by walker
Thanks a lot.... NOW it's clear to me how it works...:D
I always thougt that, as GTK+ always uses UTF8, no conversion has to be made... :oops: :oops:

added

Code: Select all

ImportC "/usr/lib/libgtk-x11-2.0.so"
  gtk_tool_button_new_from_stock(a.p-utf8)
  g_signal_connect_object(*gadgetid,h.p-utf8,*cbproc,*pointer,*e)
EndImport
to the code above and (after removing the trailing _ at both commands) all works as expected 8)