Page 1 of 1

gtk+pb+unicode problem

Posted: Tue Feb 26, 2013 7:10 pm
by gerd
Hello everybody,
I am not sure if the following code is right, but it works well as long as it is compiled without unicode enabled. Even then I get this warning:
[18:48:58] [WARNING] GLib-GObject (WARNING): g_object_set_valist: object class `GtkTextTag' has no property named `0Ží'

Now same code still no unicode, but with internal purifier enabled, I get
[18:59:40] [ERROR] myTest.pb (Line: 56)
[18:59:40] [ERROR] Invalid memory access.

Finally with unicode enabled all colours are gone. The buttons turn black on activation.

Code: Select all

; GUI DESIGNER V 0.9 Beta


Enumeration       ; Windows
  #Form_100
EndEnumeration    ; Windows

Enumeration       ; Gadget
  #Button_0
  #Button_1
  #Editor_0
EndEnumeration    ; Gadget


; Your code here

Procedure Open_Form_100()
  OpenWindow(#Form_100, 380, 100, 600, 440, "Form_100", $2)
    ; Gadgetliste
      EditorGadget(#Editor_0, 10, 10, 360, 390)
      ButtonGadget(#Button_0, 385, 10, 200, 40, "Button blue")
      ButtonGadget(#Button_1, 385, 65, 200, 40, "Button black")
      
      SetGadgetAttribute(#Editor_0, #PB_Editor_WordWrap, 1)

EndProcedure

; Your code here

Procedure.l GetCursorPos(Id.l)
    Protected mypointertoiteration.GtkTextIter, *buffer, cursor.l
    *buffer = gtk_text_view_get_buffer_(GadgetID(#Editor_0))
    cursor = gtk_text_buffer_get_insert_(*buffer)
    gtk_text_buffer_get_iter_at_mark_(*buffer, @mypointertoiteration, cursor)
    ProcedureReturn gtk_text_iter_get_offset_(@mypointertoiteration)
  EndProcedure
 
Open_Form_100()

gtk_init_(0,0)
gdk_init_(0,0)

GtkTextBuffer *buffer
color.GdkColor
start.GtkTextIter 
ende.GtkTextIter

gdk_color_parse_("lightblue", @color)
gtk_widget_modify_bg_(GadgetID(#Button_0), #GTK_STATE_PRELIGHT, @color)
gtk_widget_modify_bg_(GadgetID(#Button_0), #GTK_STATE_ACTIVE, @color)
gdk_color_parse_("lightgreen", @color)
gtk_widget_modify_bg_(GadgetID(#Button_1), #GTK_STATE_PRELIGHT, @color)
gtk_widget_modify_bg_(GadgetID(#Button_1), #GTK_STATE_ACTIVE, @color)

buffer = gtk_text_view_get_buffer_(GadgetID(#Editor_0))
tag = gtk_text_buffer_create_tag_(buffer, "mytag", "foreground", "blue")

Define.l Event, EventWindow, EventGadget, EventType, EventMenu
; Event Schleife
Repeat
  Event = WaitWindowEvent()
  Select Event
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      ; Gadget
      If EventGadget = #Editor_0
      ElseIf EventGadget = #Button_0
        SetActiveGadget(#Editor_0)
        einfuegepos = GetCursorPos(GadgetID(#Editor_0))
        text$ = GetGadgetText(#Editor_0)
        SetGadgetText(#Editor_0, InsertString(text$, "<This should be blue>", einfuegepos + 1))
        gtk_text_buffer_get_iter_at_offset_(buffer, @start, einfuegepos)
        einfuegepos = GetCursorPos(GadgetID(#Editor_0))
        gtk_text_buffer_get_iter_at_offset_(buffer, @ende, einfuegepos)
        gtk_text_buffer_apply_tag_by_name_(buffer, "mytag", @start, @ende)
        If CountGadgetItems(#Editor_0) > 0
          GetGadgetText(#Editor_0)
          b = 1
          While b
            b = FindString(GetGadgetText(#Editor_0),"<",b)
            If b
              b + 1
              c = FindString(GetGadgetText(#Editor_0),">",b)
              If c
                gtk_text_buffer_get_iter_at_offset_(buffer, @start, b - 2)
                gtk_text_buffer_get_iter_at_offset_(buffer, @ende, c)
                gtk_text_buffer_apply_tag_by_name_(buffer, "mytag", @start, @ende)
              EndIf  
            EndIf
          Wend
        EndIf  
      ElseIf EventGadget = #Button_1
        SetActiveGadget(#Editor_0)
        einfuegepos = GetCursorPos(GadgetID(#Editor_0))
        text$ = GetGadgetText(#Editor_0)
        SetGadgetText(#Editor_0, InsertString(text$, "This should be black", einfuegepos + 1))
        If CountGadgetItems(#Editor_0) > 0
          GetGadgetText(#Editor_0)
          b = 1
          While b
            b = FindString(GetGadgetText(#Editor_0),"<",b)
            If b
              b + 1
              c = FindString(GetGadgetText(#Editor_0),">",b)
              If c
                gtk_text_buffer_get_iter_at_offset_(buffer, @start, b - 2)
                gtk_text_buffer_get_iter_at_offset_(buffer, @ende, c)
                gtk_text_buffer_apply_tag_by_name_(buffer, "mytag", @start, @ende)
              EndIf  
            EndIf
          Wend
        EndIf  
     EndIf
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      ; Window
      If EventWindow = #Form_100
        CloseWindow(#Form_100)
        Break
      EndIf
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  EndSelect
ForEver
End
I hope somebody can show me how this code has to be modified to work with unicode enabled and how to get rid of the annoying warning from the debugger.

openSuse 12.2, PureBasic 5.10 x64

Thanks in advance
gerd

Re: gtk+pb+unicode problem

Posted: Tue Feb 26, 2013 8:13 pm
by idle
redefine the imports

Code: Select all

ImportC ""
   gtk_text_buffer_create_tag(*buffer.GtkTextBuffer,tag_name.p-Ascii,first_property_name.p-ascii,tag_value.p-Ascii ,null=0) As " gtk_text_buffer_create_tag"
   gtk_text_buffer_apply_tag_by_name_(*buffer.GtkTextBuffer, name.p-Ascii,*start,*end) As "gtk_text_buffer_apply_tag_by_name"
EndImport   
some functions in gtk only take ascii

Re: gtk+pb+unicode problem

Posted: Wed Feb 27, 2013 6:46 pm
by gerd
Hi idle,
thank you very much for your help. Everything works now as expected. All errors and warnings are gone.

gerd

Re: gtk+pb+unicode problem

Posted: Thu Feb 28, 2013 5:45 pm
by gerd
Is this a bug with PB 5.11 beta1? Or am I doing something wrong?

The following code works without any problems with PB 5.10. But with PB 5.11 Beta, Purifier enabled and Unicode enabled I get an "Invalid Memory Access".

Code: Select all

; GUI DESIGNER V 0.9 Beta


Enumeration       ; Windows
  #Form_100
EndEnumeration    ; Windows

Enumeration       ; Gadget
  #Button_0
  #Button_1
  #Editor_0
EndEnumeration    ; Gadget


; Your code here

Procedure Open_Form_100()
  OpenWindow(#Form_100, 380, 100, 600, 440, "Form_100", $2)
    ; Gadgetliste
      EditorGadget(#Editor_0, 10, 10, 360, 390)
      ButtonGadget(#Button_0, 385, 10, 200, 40, "Button blue")
      ButtonGadget(#Button_1, 385, 65, 200, 40, "Button black")
      
      SetGadgetAttribute(#Editor_0, #PB_Editor_WordWrap, 1)

EndProcedure

; Your code here

Procedure.l GetCursorPos(Id.l)
    Protected mypointertoiteration.GtkTextIter, *buffer, cursor.l
    *buffer = gtk_text_view_get_buffer_(GadgetID(#Editor_0))
    cursor = gtk_text_buffer_get_insert_(*buffer)
    gtk_text_buffer_get_iter_at_mark_(*buffer, @mypointertoiteration, cursor)
    ProcedureReturn gtk_text_iter_get_offset_(@mypointertoiteration)
  EndProcedure
 
Open_Form_100()

gtk_init_(0,0)
gdk_init_(0,0)

GtkTextBuffer *buffer
color.GdkColor
start.GtkTextIter 
ende.GtkTextIter

ImportC ""
   gdk_color_parse_(spec.p-Ascii, *color.GdkColor) As "gdk_color_parse"
   gtk_widget_modify_bg_(*buffer.GtkTextBuffer, state, *color.p-Ascii) As "gtk_widget_modify_bg"
   gtk_text_buffer_create_tag_(*buffer.GtkTextBuffer,tag_name.p-Ascii,first_property_name.p-ascii,tag_value.p-Ascii ,null=0) As "gtk_text_buffer_create_tag"
   gtk_text_buffer_apply_tag_by_name_(*buffer.GtkTextBuffer, name.p-Ascii,*start,*end) As "gtk_text_buffer_apply_tag_by_name"
EndImport   

gdk_color_parse_("dodgerblue", @color)  ; Here I get INVALID MEMORY ACCESS!!!
gtk_widget_modify_bg_(GadgetID(#Button_0), #GTK_STATE_PRELIGHT, @color)
gtk_widget_modify_bg_(GadgetID(#Button_0), #GTK_STATE_ACTIVE, @color)
gdk_color_parse_("mediumseagreen", @color)
gtk_widget_modify_bg_(GadgetID(#Button_1), #GTK_STATE_PRELIGHT, @color)
gtk_widget_modify_bg_(GadgetID(#Button_1), #GTK_STATE_ACTIVE, @color)

buffer = gtk_text_view_get_buffer_(GadgetID(#Editor_0))
tag = gtk_text_buffer_create_tag_(buffer, "mytag", "foreground", "blue")

Define.l Event, EventWindow, EventGadget, EventType, EventMenu
; Event Schleife
Repeat
  Event = WaitWindowEvent()
  Select Event
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      ; Gadget
      If EventGadget = #Editor_0
      ElseIf EventGadget = #Button_0
        SetActiveGadget(#Editor_0)
        einfuegepos = GetCursorPos(GadgetID(#Editor_0))
        text$ = GetGadgetText(#Editor_0)
        SetGadgetText(#Editor_0, InsertString(text$, "<This should be blue>", einfuegepos + 1))
        gtk_text_buffer_get_iter_at_offset_(buffer, @start, einfuegepos)
        einfuegepos = GetCursorPos(GadgetID(#Editor_0))
        gtk_text_buffer_get_iter_at_offset_(buffer, @ende, einfuegepos)
        gtk_text_buffer_apply_tag_by_name_(buffer, "mytag", @start, @ende)
        If CountGadgetItems(#Editor_0) > 0
          GetGadgetText(#Editor_0)
          b = 1
          While b
            b = FindString(GetGadgetText(#Editor_0),"<",b)
            If b
              b + 1
              c = FindString(GetGadgetText(#Editor_0),">",b)
              If c
                gtk_text_buffer_get_iter_at_offset_(buffer, @start, b - 2)
                gtk_text_buffer_get_iter_at_offset_(buffer, @ende, c)
                gtk_text_buffer_apply_tag_by_name_(buffer, "mytag", @start, @ende)
              EndIf  
            EndIf
          Wend
        EndIf  
      ElseIf EventGadget = #Button_1
        SetActiveGadget(#Editor_0)
        einfuegepos = GetCursorPos(GadgetID(#Editor_0))
        text$ = GetGadgetText(#Editor_0)
        SetGadgetText(#Editor_0, InsertString(text$, "This should be black", einfuegepos + 1))
        If CountGadgetItems(#Editor_0) > 0
          GetGadgetText(#Editor_0)
          b = 1
          While b
            b = FindString(GetGadgetText(#Editor_0),"<",b)
            If b
              b + 1
              c = FindString(GetGadgetText(#Editor_0),">",b)
              If c
                gtk_text_buffer_get_iter_at_offset_(buffer, @start, b - 2)
                gtk_text_buffer_get_iter_at_offset_(buffer, @ende, c)
                gtk_text_buffer_apply_tag_by_name_(buffer, "mytag", @start, @ende)
              EndIf  
            EndIf
          Wend
        EndIf  
     EndIf
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      ; Window
      If EventWindow = #Form_100
        CloseWindow(#Form_100)
        Break
      EndIf
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  EndSelect
ForEver
End
Any idea what is wrong?
openSuse 12.2

gerd

Re: gtk+pb+unicode problem

Posted: Thu Feb 28, 2013 10:58 pm
by idle
I see nothing wrong with the code, might be an issue with the purifyer

Re: gtk+pb+unicode problem

Posted: Thu Feb 28, 2013 11:13 pm
by ts-soft
I think, there is a bug in purefier with pseudotype p-ascii.
The error comes with all your imported function, that uses this pseudotype.

Greetings - Thomas

//edit
Bugmessage is out: http://www.purebasic.fr/english/viewtop ... 45#p406445