gtk+pb+unicode problem

Linux specific forum
gerd
User
User
Posts: 94
Joined: Tue Feb 23, 2010 7:50 pm
Location: Germany

gtk+pb+unicode problem

Post 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
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: gtk+pb+unicode problem

Post 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
Windows 11, Manjaro, Raspberry Pi OS
Image
gerd
User
User
Posts: 94
Joined: Tue Feb 23, 2010 7:50 pm
Location: Germany

Re: gtk+pb+unicode problem

Post by gerd »

Hi idle,
thank you very much for your help. Everything works now as expected. All errors and warnings are gone.

gerd
gerd
User
User
Posts: 94
Joined: Tue Feb 23, 2010 7:50 pm
Location: Germany

Re: gtk+pb+unicode problem

Post 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
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: gtk+pb+unicode problem

Post by idle »

I see nothing wrong with the code, might be an issue with the purifyer
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: gtk+pb+unicode problem

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply