gtk +xml tutorial why not work?

New to FreeBASIC? Post your questions here.
covid19
Posts: 31
Joined: Apr 25, 2020 20:41

Re: gtk +xml tutorial why not work?

Postby covid19 » May 11, 2020 7:41

Xusinboy Bekchanov wrote:This code compiles without problems for me.

Code: Select all

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< main program generated by utility                 GTK+tobac2 V2.2.0 >
'< Hauptprogramm erzeugt von                                           >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' ---------------------------------------------------------------------
'< Program info:                                                       >
CONST PROG_NAME = "Scribble" '                                         >
CONST PROG_DESC = "Zeichenprogramm" '                                  >
CONST PROG_VERS = "0.0" '                                              >
CONST PROG_YEAR = "2010" '                                             >
CONST PROG_AUTH = "TJF" '                                              >
CONST PROG_MAIL = "Thomas.Freiherr@gmx.net" '                          >
CONST PROG_WEBS = "members.aon.at/tjf" '                               >
'<                                                                     >
'< Description / Beschreibung:                                         >
'< Beispiel DrawArea, einfaches Zeichenprogramm                        >
'<                                                                     >
'< License / Lizenz:                                                   >
'<                                                                     >
'< Redistribution and use in source and binary forms, with or          >
'< without modification, are permitted provided that the following     >
'< conditions are met:                                                 >
'<                                                                     >
'< * Redistributions of source code must retain the above              >
'< copyright notice, this list of conditions and the following         >
'< disclaimer.                                                         >
'<                                                                     >
'< * Redistributions in binary form must reproduce the above           >
'< copyright notice, this list of conditions and the following         >
'< disclaimer in the documentation and/or other materials provided     >
'< with the distribution.                                              >
'<                                                                     >
'< * Neither the name of the author nor the names of its               >
'< contributors may be used to endorse or promote products derived     >
'< from this software without specific prior written permission.       >
'<                                                                     >
'< THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS                  >
'< AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED                 >
'< WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES   >
'< OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE             >
'< ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER               >
'< OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     >
'< SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT    >
'< LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF    >
'< USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED     >
'< AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT         >
'< LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN   >
'< ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE     >
'< POSSIBILITY OF SUCH DAMAGE.                                         >
'<                                                                     >
' ---------------------------------------------------------------------
'< Please prefer GNU GENERAL PUBLIC LICENSE to support open software.  >
'< For more information please visit:               http://www.fsf.org >
'<                                                                     >
'< Bitte bevorzugen Sie die GNU GENERAL PUBLIC LICENSE und             >
'< unterstuetzen Sie mit Ihrem Programm die freie Software             >
'< Mehr Informationen finden Sie unter:             http://www.fsf.org >
' ---------------------------------------------------------------------
'<  GTK+tobac:             general init / Allgemeine Initialisierungen >
  '  #INCLUDE "gtk/GTK-2.18.6_TJF.bi" '   GTK+library / GTK+ Bibliothek >
  #include once "gtk/gtk.bi"
    gtk_init(@__FB_ARGC__, @__FB_ARGV__) '     start GKT / GTK starten >
'<  GTK+tobac:                                   end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

/' Backing pixmap for drawing area '/
DIM SHARED AS GdkPixmap PTR PIXMAP = NULL
DECLARE SUB draw_brush(BYVAL widget AS GtkWidget PTR, _
                       BYVAL x AS gdouble, _
                       BYVAL y AS gdouble)

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< _tobac.bas modul generated by utility             GTK+tobac2 V2.2.0 >
'< Modul _tobac.bas erzeugt von                                        >
'< Generated at / Generierung am                     2010-09-06, 02:45 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

'IF gtk_check_version(2, 16, 0) THEN
'  ?"Fehler/Error (GTK-Version): Version zu alt"
'  END -1
'END IF

DIM AS STRING GUISTR
DIM SHARED AS GtkBuilder PTR XML
DIM SHARED AS GObject PTR _
  WinScribble, Draw1, ButQuit

XML = gtk_builder_new()

SCOPE
  DIM AS GError PTR meld

  ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  '< _gui.bas modul generated by utility               GTK+tobac2 V2.2.0 >
  '< Modul _gui.bas erzeugt von                                          >
  '< Generated at / Generierung am                     2010-09-06, 02:45 >
  ' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

  GUIstr =_
  "<?xml version=""1.0""?>"+_
  "<interface>"+_
  "<requires lib=""gtk+"" version=""2.16""/>"+_
  "<!-- interface-naming-policy project-wide -->"+_
  "<object class=""GtkWindow"" id=""WinScribble"">"+_
  "<signal name=""destroy"" handler=""gtk_main_quit""/>"+_
  "<child>"+_
  "<object class=""GtkVBox"" id=""vbox1"">"+_
  "<property name=""visible"">True</property>"+_
  "<child>"+_
  "<object class=""GtkDrawingArea"" id=""Draw1"">"+_
  "<property name=""width_request"">200</property>"+_
  "<property name=""height_request"">200</property>"+_
  "<property name=""visible"">True</property>"+_
  "<property name=""events"">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK</property>"+_
  "<signal name=""button_press_event"" handler=""on_Draw1_button_press_event""/>"+_
  "<signal name=""motion_notify_event"" handler=""on_Draw1_motion_notify_event""/>"+_
  "<signal name=""expose_event"" handler=""on_Draw1_expose_event""/>"+_
  "<signal name=""configure_event"" handler=""on_Draw1_configure_event""/>"+_
  "</object>"+_
  "<packing>"+_
  "<property name=""position"">0</property>"+_
  "</packing>"+_
  "</child>"+_
  "<child>"+_
  "<object class=""GtkButton"" id=""ButQuit"">"+_
  "<property name=""label"" translatable=""yes"">Quit</property>"+_
  "<property name=""visible"">True</property>"+_
  "<property name=""can_focus"">True</property>"+_
  "<property name=""receives_default"">True</property>"+_
  "<signal name=""clicked"" handler=""gtk_main_quit""/>"+_
  "</object>"+_
  "<packing>"+_
  "<property name=""expand"">False</property>"+_
  "<property name=""fill"">False</property>"+_
  "<property name=""position"">1</property>"+_
  "</packing>"+_
  "</child>"+_
  "</object>"+_
  "</child>"+_
  "</object>"+_
  "</interface>"
  IF 0 = gtk_builder_add_from_string(XML, SADD(GUISTR), LEN(GUISTR), @meld) THEN
    WITH *meld
      ?"Fehler/Error (GTK-Builder):"
      ?*.message
    END WITH
    END -1
  END IF
END SCOPE

WinScribble = gtk_builder_get_object(XML, "WinScribble")
Draw1 = gtk_builder_get_object(XML, "Draw1")
ButQuit = gtk_builder_get_object(XML, "ButQuit")

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_button_press_event CDECL ALIAS "on_Draw1_button_press_event" _
         (BYVAL widget AS GtkWidget PTR, _
          BYVAL event AS GdkEventButton PTR) AS gboolean EXPORT
  IF event->button = 1 THEN IF PIXMAP THEN draw_brush(widget, event->x, event->y)
  RETURN TRUE
END FUNCTION

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_motion_notify_event CDECL ALIAS "on_Draw1_motion_notify_event" _
         (BYVAL widget AS GtkWidget PTR, _
          BYVAL event AS GdkEventMotion PTR) AS gboolean EXPORT
  DIM AS INTEGER x, y
  DIM AS GdkModifierType state

  IF event->is_hint THEN
    gdk_window_get_pointer(event->window, @x, @y, @state)
  ELSE
    x = event->x
    y = event->y
    state = event->state
  END IF

  IF state AND GDK_BUTTON1_MASK THEN IF PIXMAP THEN draw_brush(widget, x, y)
  RETURN TRUE
END FUNCTION

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_expose_event CDECL ALIAS "on_Draw1_expose_event" _
         (BYVAL widget AS GtkWidget PTR, _
          BYVAL event AS GdkEventExpose PTR) AS gboolean EXPORT
  gdk_draw_drawable(widget->window, _
                    widget->style->fg_gc(gtk_widget_get_state(widget)), _
                    PIXMAP, _
                    event->area.x, event->area.y, _
                    event->area.x, event->area.y, _
                    event->area.width, event->area.height)
  RETURN FALSE
END FUNCTION

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_configure_event CDECL ALIAS "on_Draw1_configure_event" _
        (BYVAL widget AS GtkWidget PTR, _
         BYVAL event AS GdkEventConfigure PTR) AS gboolean EXPORT
  IF PIXMAP THEN g_object_unref(pixmap)

  PIXMAP = gdk_pixmap_new(widget->window, _
                          widget->allocation.width, _
                          widget->allocation.height, _
                          -1)
  gdk_draw_rectangle(PIXMAP, _
                     widget->style->white_gc, _
                     TRUE, _
                     0, 0, _
                     widget->allocation.width, _
                     widget->allocation.height)
  RETURN TRUE
END FUNCTION


SUB draw_brush(BYVAL widget AS GtkWidget PTR, _
               BYVAL x AS gdouble, _
               BYVAL y AS gdouble)
  DIM AS GdkRectangle update_rect

  update_rect.x = x - 5
  update_rect.y = y - 5
  update_rect.width = 10
  update_rect.height = 10
  gdk_draw_rectangle(PIXMAP, _
                     widget->style->black_gc, _
                     TRUE, _
                     update_rect.x, update_rect.y, _
                     update_rect.width, update_rect.height)
  gtk_widget_queue_draw_area(widget, _
                             update_rect.x, update_rect.y, _
                             update_rect.width, update_rect.height)
END SUB

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'<  GTK+tobac:   run GTK main, then end / GTK Hauptschleife, dann Ende >
    gtk_builder_connect_signals(XML, 0) '           callbacks anbinden >
    gtk_widget_show_all(GTK_WIDGET(WinScribble)) 'ptfenster darstellen >
    gtk_main() '                             main loop / Hauptschleife >
    g_object_unref(XML) '               dereference / Referenz abbauen >
'<  GTK+tobac:                                   end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

' you may unref files here / ggf. Dateien hier schliessen

END 0 ' finish with return code 0 / Ende mit Returncode 0


Four things are needed for this:
1) Compiler version: 1.07.1-win32
2) gtk2 lib in the folder \FreeBASIC-1.07.1-win32\lib\win32
Here I inserted gtk2 lib, which I downloaded through mingw32:
https://drive.google.com/file/d/1JGmUSO ... sp=sharing
3) Installing the gtk2 runtime: If you use Geany Windows, he can install it himself.
4) comment line 687 in \FreeBASIC-1.07.1-win32\lib\win32\inc\glib.bi

Code: Select all

Private Sub g_mutex_locker_free(ByVal locker As GMutexLocker Ptr)
   'g_mutex_unlock(CPtr(GMutex Ptr, locker))
End Sub

Subject on this issue: https://www.freebasic.net/forum/viewtopic.php?t=26931


why you use gtk2 ? all topic try to show example with gtk 3 (thinking GTK is just a 4 version ) o_O
TJF
Posts: 3599
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: gtk +xml tutorial why not work?

Postby TJF » May 11, 2020 7:55

Xusinboy Bekchanov wrote:But here there are gtk 2 libraries like libgtk-win32-2.0.dll.a
Here's the downloads context from folder lib/:

Code: Select all

    7046 Jul  4  2013 atk-1.0.def
    8235 Jul  4  2013 cairo.def
    3565 Jul  4  2013 fontconfig.def
     404 Jul  4  2013 gailutil.def
    4096 Aug  5  2013 gdk-pixbuf-2.0
    3772 Jul  4  2013 gdk_pixbuf-2.0.def
   14532 Jul  4  2013 gdk-win32-3.0.def
    4096 Aug  5  2013 gio
    4096 Aug  5  2013 glib-2.0
      62 Jul  4  2013 gthread-2.0.def
    4096 Aug  5  2013 gtk-3.0
  116967 Jul  4  2013 gtk-win32-3.0.def
  170134 Jul  4  2013 libatk-1.0.dll.a
  219638 Jul  4  2013 libcairo.dll.a
   24890 Jul  4  2013 libcairo-gobject.dll.a
   61132 Jul  4  2013 libcairo-script-interpreter.dll.a
  282462 Jul  4  2013 libcroco-0.6.dll.a
    4096 Aug  5  2013 libffi-3.0.12
   25558 Jul  4  2013 libffi.dll.a
  129190 Jul  4  2013 libfontconfig.dll.a
  234982 Jul  4  2013 libfreetype.dll.a
   10082 Jul  4  2013 libgailutil-3.dll.a
  370690 Jul  4  2013 libgdk-3.dll.a
   85804 Jul  4  2013 libgdk_pixbuf-2.0.dll.a
 1157918 Jul  4  2013 libgio-2.0.dll.a
 1066826 Jul  4  2013 libglib-2.0.dll.a
    7364 Jul  4  2013 libgmodule-2.0.dll.a
  285058 Jul  4  2013 libgobject-2.0.dll.a
    2252 Jul  4  2013 libgthread-2.0.dll.a
 2718254 Jul  4  2013 libgtk-3.dll.a
  239486 Jul  4  2013 libjasper.dll.a
  108956 Jul  4  2013 libjpeg.dll.a
   62338 Jul  3  2013 liblzma.dll.a
  280822 Jul  4  2013 libpango-1.0.dll.a
   23318 Jul  4  2013 libpangocairo-1.0.dll.a
   21614 Jul  4  2013 libpangowin32-1.0.dll.a
  122522 Jul  4  2013 libpixman-1.dll.a
  153148 Jul  4  2013 libpng15.dll.a
  153148 Jul  4  2013 libpng.dll.a
  135356 Jul  4  2013 librsvg-2.dll.a
  160932 Jul  4  2013 libtiff.dll.a
    2878 Jul  4  2013 libtiffxx.dll.a
 1090716 Jul  4  2013 libxml2.dll.a
   46912 Jul  3  2013 libz.dll.a
    4096 Aug  5  2013 pango
    4096 Aug  5  2013 pkgconfig
     203 Jul  4  2013 xml2Conf.sh
Xusinboy Bekchanov
Posts: 243
Joined: Jul 26, 2018 18:28

Re: gtk +xml tutorial why not work?

Postby Xusinboy Bekchanov » May 11, 2020 8:01

TJF wrote:
Xusinboy Bekchanov wrote:But here there are gtk 2 libraries like libgtk-win32-2.0.dll.a
Here's the downloads context from folder lib/:

Code: Select all

    7046 Jul  4  2013 atk-1.0.def
    8235 Jul  4  2013 cairo.def
    3565 Jul  4  2013 fontconfig.def
     404 Jul  4  2013 gailutil.def
    4096 Aug  5  2013 gdk-pixbuf-2.0
    3772 Jul  4  2013 gdk_pixbuf-2.0.def
   14532 Jul  4  2013 gdk-win32-3.0.def
    4096 Aug  5  2013 gio
    4096 Aug  5  2013 glib-2.0
      62 Jul  4  2013 gthread-2.0.def
    4096 Aug  5  2013 gtk-3.0
  116967 Jul  4  2013 gtk-win32-3.0.def
  170134 Jul  4  2013 libatk-1.0.dll.a
  219638 Jul  4  2013 libcairo.dll.a
   24890 Jul  4  2013 libcairo-gobject.dll.a
   61132 Jul  4  2013 libcairo-script-interpreter.dll.a
  282462 Jul  4  2013 libcroco-0.6.dll.a
    4096 Aug  5  2013 libffi-3.0.12
   25558 Jul  4  2013 libffi.dll.a
  129190 Jul  4  2013 libfontconfig.dll.a
  234982 Jul  4  2013 libfreetype.dll.a
   10082 Jul  4  2013 libgailutil-3.dll.a
  370690 Jul  4  2013 libgdk-3.dll.a
   85804 Jul  4  2013 libgdk_pixbuf-2.0.dll.a
 1157918 Jul  4  2013 libgio-2.0.dll.a
 1066826 Jul  4  2013 libglib-2.0.dll.a
    7364 Jul  4  2013 libgmodule-2.0.dll.a
  285058 Jul  4  2013 libgobject-2.0.dll.a
    2252 Jul  4  2013 libgthread-2.0.dll.a
 2718254 Jul  4  2013 libgtk-3.dll.a
  239486 Jul  4  2013 libjasper.dll.a
  108956 Jul  4  2013 libjpeg.dll.a
   62338 Jul  3  2013 liblzma.dll.a
  280822 Jul  4  2013 libpango-1.0.dll.a
   23318 Jul  4  2013 libpangocairo-1.0.dll.a
   21614 Jul  4  2013 libpangowin32-1.0.dll.a
  122522 Jul  4  2013 libpixman-1.dll.a
  153148 Jul  4  2013 libpng15.dll.a
  153148 Jul  4  2013 libpng.dll.a
  135356 Jul  4  2013 librsvg-2.dll.a
  160932 Jul  4  2013 libtiff.dll.a
    2878 Jul  4  2013 libtiffxx.dll.a
 1090716 Jul  4  2013 libxml2.dll.a
   46912 Jul  3  2013 libz.dll.a
    4096 Aug  5  2013 pango
    4096 Aug  5  2013 pkgconfig
     203 Jul  4  2013 xml2Conf.sh

There is no lib folder for this link:
https://drive.google.com/file/d/1JGmUSO ... q_13s/view
TJF
Posts: 3599
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: gtk +xml tutorial why not work?

Postby TJF » May 11, 2020 8:11

Xusinboy Bekchanov wrote:There is no lib folder for this link:
https://drive.google.com/file/d/1JGmUSO ... q_13s/view
Sorry, I mixed up some downloads. Sure, you're right. (My list comes from file gtk+-bundle_3.8.2-20130704_win32-RC1.zip)

Hopefully @covid19 reads your tutorial.
Xusinboy Bekchanov
Posts: 243
Joined: Jul 26, 2018 18:28

Re: gtk +xml tutorial why not work?

Postby Xusinboy Bekchanov » May 11, 2020 8:29

covid19 wrote:
Xusinboy Bekchanov wrote:This code compiles without problems for me.

Code: Select all

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< main program generated by utility                 GTK+tobac2 V2.2.0 >
'< Hauptprogramm erzeugt von                                           >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' ---------------------------------------------------------------------
'< Program info:                                                       >
CONST PROG_NAME = "Scribble" '                                         >
CONST PROG_DESC = "Zeichenprogramm" '                                  >
CONST PROG_VERS = "0.0" '                                              >
CONST PROG_YEAR = "2010" '                                             >
CONST PROG_AUTH = "TJF" '                                              >
CONST PROG_MAIL = "Thomas.Freiherr@gmx.net" '                          >
CONST PROG_WEBS = "members.aon.at/tjf" '                               >
'<                                                                     >
'< Description / Beschreibung:                                         >
'< Beispiel DrawArea, einfaches Zeichenprogramm                        >
'<                                                                     >
'< License / Lizenz:                                                   >
'<                                                                     >
'< Redistribution and use in source and binary forms, with or          >
'< without modification, are permitted provided that the following     >
'< conditions are met:                                                 >
'<                                                                     >
'< * Redistributions of source code must retain the above              >
'< copyright notice, this list of conditions and the following         >
'< disclaimer.                                                         >
'<                                                                     >
'< * Redistributions in binary form must reproduce the above           >
'< copyright notice, this list of conditions and the following         >
'< disclaimer in the documentation and/or other materials provided     >
'< with the distribution.                                              >
'<                                                                     >
'< * Neither the name of the author nor the names of its               >
'< contributors may be used to endorse or promote products derived     >
'< from this software without specific prior written permission.       >
'<                                                                     >
'< THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS                  >
'< AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED                 >
'< WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES   >
'< OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE             >
'< ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER               >
'< OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     >
'< SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT    >
'< LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF    >
'< USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED     >
'< AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT         >
'< LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN   >
'< ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE     >
'< POSSIBILITY OF SUCH DAMAGE.                                         >
'<                                                                     >
' ---------------------------------------------------------------------
'< Please prefer GNU GENERAL PUBLIC LICENSE to support open software.  >
'< For more information please visit:               http://www.fsf.org >
'<                                                                     >
'< Bitte bevorzugen Sie die GNU GENERAL PUBLIC LICENSE und             >
'< unterstuetzen Sie mit Ihrem Programm die freie Software             >
'< Mehr Informationen finden Sie unter:             http://www.fsf.org >
' ---------------------------------------------------------------------
'<  GTK+tobac:             general init / Allgemeine Initialisierungen >
  '  #INCLUDE "gtk/GTK-2.18.6_TJF.bi" '   GTK+library / GTK+ Bibliothek >
  #include once "gtk/gtk.bi"
    gtk_init(@__FB_ARGC__, @__FB_ARGV__) '     start GKT / GTK starten >
'<  GTK+tobac:                                   end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

/' Backing pixmap for drawing area '/
DIM SHARED AS GdkPixmap PTR PIXMAP = NULL
DECLARE SUB draw_brush(BYVAL widget AS GtkWidget PTR, _
                       BYVAL x AS gdouble, _
                       BYVAL y AS gdouble)

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< _tobac.bas modul generated by utility             GTK+tobac2 V2.2.0 >
'< Modul _tobac.bas erzeugt von                                        >
'< Generated at / Generierung am                     2010-09-06, 02:45 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

'IF gtk_check_version(2, 16, 0) THEN
'  ?"Fehler/Error (GTK-Version): Version zu alt"
'  END -1
'END IF

DIM AS STRING GUISTR
DIM SHARED AS GtkBuilder PTR XML
DIM SHARED AS GObject PTR _
  WinScribble, Draw1, ButQuit

XML = gtk_builder_new()

SCOPE
  DIM AS GError PTR meld

  ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  '< _gui.bas modul generated by utility               GTK+tobac2 V2.2.0 >
  '< Modul _gui.bas erzeugt von                                          >
  '< Generated at / Generierung am                     2010-09-06, 02:45 >
  ' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

  GUIstr =_
  "<?xml version=""1.0""?>"+_
  "<interface>"+_
  "<requires lib=""gtk+"" version=""2.16""/>"+_
  "<!-- interface-naming-policy project-wide -->"+_
  "<object class=""GtkWindow"" id=""WinScribble"">"+_
  "<signal name=""destroy"" handler=""gtk_main_quit""/>"+_
  "<child>"+_
  "<object class=""GtkVBox"" id=""vbox1"">"+_
  "<property name=""visible"">True</property>"+_
  "<child>"+_
  "<object class=""GtkDrawingArea"" id=""Draw1"">"+_
  "<property name=""width_request"">200</property>"+_
  "<property name=""height_request"">200</property>"+_
  "<property name=""visible"">True</property>"+_
  "<property name=""events"">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK</property>"+_
  "<signal name=""button_press_event"" handler=""on_Draw1_button_press_event""/>"+_
  "<signal name=""motion_notify_event"" handler=""on_Draw1_motion_notify_event""/>"+_
  "<signal name=""expose_event"" handler=""on_Draw1_expose_event""/>"+_
  "<signal name=""configure_event"" handler=""on_Draw1_configure_event""/>"+_
  "</object>"+_
  "<packing>"+_
  "<property name=""position"">0</property>"+_
  "</packing>"+_
  "</child>"+_
  "<child>"+_
  "<object class=""GtkButton"" id=""ButQuit"">"+_
  "<property name=""label"" translatable=""yes"">Quit</property>"+_
  "<property name=""visible"">True</property>"+_
  "<property name=""can_focus"">True</property>"+_
  "<property name=""receives_default"">True</property>"+_
  "<signal name=""clicked"" handler=""gtk_main_quit""/>"+_
  "</object>"+_
  "<packing>"+_
  "<property name=""expand"">False</property>"+_
  "<property name=""fill"">False</property>"+_
  "<property name=""position"">1</property>"+_
  "</packing>"+_
  "</child>"+_
  "</object>"+_
  "</child>"+_
  "</object>"+_
  "</interface>"
  IF 0 = gtk_builder_add_from_string(XML, SADD(GUISTR), LEN(GUISTR), @meld) THEN
    WITH *meld
      ?"Fehler/Error (GTK-Builder):"
      ?*.message
    END WITH
    END -1
  END IF
END SCOPE

WinScribble = gtk_builder_get_object(XML, "WinScribble")
Draw1 = gtk_builder_get_object(XML, "Draw1")
ButQuit = gtk_builder_get_object(XML, "ButQuit")

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_button_press_event CDECL ALIAS "on_Draw1_button_press_event" _
         (BYVAL widget AS GtkWidget PTR, _
          BYVAL event AS GdkEventButton PTR) AS gboolean EXPORT
  IF event->button = 1 THEN IF PIXMAP THEN draw_brush(widget, event->x, event->y)
  RETURN TRUE
END FUNCTION

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_motion_notify_event CDECL ALIAS "on_Draw1_motion_notify_event" _
         (BYVAL widget AS GtkWidget PTR, _
          BYVAL event AS GdkEventMotion PTR) AS gboolean EXPORT
  DIM AS INTEGER x, y
  DIM AS GdkModifierType state

  IF event->is_hint THEN
    gdk_window_get_pointer(event->window, @x, @y, @state)
  ELSE
    x = event->x
    y = event->y
    state = event->state
  END IF

  IF state AND GDK_BUTTON1_MASK THEN IF PIXMAP THEN draw_brush(widget, x, y)
  RETURN TRUE
END FUNCTION

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_expose_event CDECL ALIAS "on_Draw1_expose_event" _
         (BYVAL widget AS GtkWidget PTR, _
          BYVAL event AS GdkEventExpose PTR) AS gboolean EXPORT
  gdk_draw_drawable(widget->window, _
                    widget->style->fg_gc(gtk_widget_get_state(widget)), _
                    PIXMAP, _
                    event->area.x, event->area.y, _
                    event->area.x, event->area.y, _
                    event->area.width, event->area.height)
  RETURN FALSE
END FUNCTION

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_configure_event CDECL ALIAS "on_Draw1_configure_event" _
        (BYVAL widget AS GtkWidget PTR, _
         BYVAL event AS GdkEventConfigure PTR) AS gboolean EXPORT
  IF PIXMAP THEN g_object_unref(pixmap)

  PIXMAP = gdk_pixmap_new(widget->window, _
                          widget->allocation.width, _
                          widget->allocation.height, _
                          -1)
  gdk_draw_rectangle(PIXMAP, _
                     widget->style->white_gc, _
                     TRUE, _
                     0, 0, _
                     widget->allocation.width, _
                     widget->allocation.height)
  RETURN TRUE
END FUNCTION


SUB draw_brush(BYVAL widget AS GtkWidget PTR, _
               BYVAL x AS gdouble, _
               BYVAL y AS gdouble)
  DIM AS GdkRectangle update_rect

  update_rect.x = x - 5
  update_rect.y = y - 5
  update_rect.width = 10
  update_rect.height = 10
  gdk_draw_rectangle(PIXMAP, _
                     widget->style->black_gc, _
                     TRUE, _
                     update_rect.x, update_rect.y, _
                     update_rect.width, update_rect.height)
  gtk_widget_queue_draw_area(widget, _
                             update_rect.x, update_rect.y, _
                             update_rect.width, update_rect.height)
END SUB

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'<  GTK+tobac:   run GTK main, then end / GTK Hauptschleife, dann Ende >
    gtk_builder_connect_signals(XML, 0) '           callbacks anbinden >
    gtk_widget_show_all(GTK_WIDGET(WinScribble)) 'ptfenster darstellen >
    gtk_main() '                             main loop / Hauptschleife >
    g_object_unref(XML) '               dereference / Referenz abbauen >
'<  GTK+tobac:                                   end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

' you may unref files here / ggf. Dateien hier schliessen

END 0 ' finish with return code 0 / Ende mit Returncode 0


Four things are needed for this:
1) Compiler version: 1.07.1-win32
2) gtk2 lib in the folder \FreeBASIC-1.07.1-win32\lib\win32
Here I inserted gtk2 lib, which I downloaded through mingw32:
https://drive.google.com/file/d/1JGmUSO ... sp=sharing
3) Installing the gtk2 runtime: If you use Geany Windows, he can install it himself.
4) comment line 687 in \FreeBASIC-1.07.1-win32\lib\win32\inc\glib.bi

Code: Select all

Private Sub g_mutex_locker_free(ByVal locker As GMutexLocker Ptr)
   'g_mutex_unlock(CPtr(GMutex Ptr, locker))
End Sub

Subject on this issue: https://www.freebasic.net/forum/viewtopic.php?t=26931


why you use gtk2 ? all topic try to show example with gtk 3 (thinking GTK is just a 4 version ) o_O

This code for gtk3 from Examples folder (GtkBuilder_Cairo.bas):

Code: Select all

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< main program generated by utility                           GladeToBac V3.0 >
'< Hauptprogramm erzeugt von                                                   >
'< Generated at / Generierung am                             2011-05-18, 08:56 >
' -----------------------------------------------------------------------------
'< Program info:                                                               >
CONST PROJ_NAME = "tom" '                                                      >
CONST PROJ_DESC = "GTK cairo test" '                                           >
CONST PROJ_VERS = "0.0" '                                                      >
CONST PROJ_YEAR = "2011" '                                                     >
CONST PROJ_AUTH = "" '                                                         >
CONST PROJ_MAIL = "Thomas[ dot ]Freiherr{ at }gmx{ dot }net" '                 >
CONST PROJ_WEBS = "www.freebasic-portal.de" '                                  >
CONST PROJ_LICE = "GNU General Public License v3" '                            >
'<                                                                             >
'< Description / Beschreibung:                                                 >
'<                                                                             >
'<                                                                             >
'< License / Lizenz:                                                           >
'<                                                                             >
'< This program is free software: you can redistribute it and/or modify        >
'< it under the terms of the GNU General Public License as published by        >
'< the Free Software Foundation, either version 3 of the License, or           >
'< (at your option) any later version.                                         >
'<                                                                             >
'< This program is distributed in the hope that it will be useful, but         >
'< WITHOUT ANY WARRANTY; without even the implied warranty of                  >
'< MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           >
'< General Public License for more details.                                    >
'<                                                                             >
'< You should have received a copy of the GNU General Public License along     >
'< with this program.  If not, see <http://www.gnu.org/licenses/>.             >
'<                                                                             >
' -----------------------------------------------------------------------------
'< Please prefer GNU GENERAL PUBLIC LICENSE to support open software.          >
'< For more information please visit:                       http://www.fsf.org >
'<                                                                             >
'< Bitte bevorzugen Sie die GNU GENERAL PUBLIC LICENSE und                     >
'< unterstuetzen Sie mit Ihrem Programm die freie Software                     >
'< Mehr Informationen finden Sie unter:                     http://www.fsf.org >
' -----------------------------------------------------------------------------
'<  GTK+tobac:                     general init / Allgemeine Initialisierungen >
    #DEFINE __USE_GTK3__ '         choose GTK version / GTK-version auswaehlen >
    #INCLUDE "gtk/gtk.bi" '                    GTK3+library / GTK3+ Bibliothek >
    gtk_init(@__FB_ARGC__, @__FB_ARGV__) '             start GKT / GTK starten >
'<  GTK+tobac:                                           end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv



' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'<  GTK+tobac:                                  load GTK stuff / GTK Anbindung >
DIM AS STRING GUISTR
DIM SHARED AS GtkBuilder PTR XML
DIM SHARED AS GObject PTR window1

XML = gtk_builder_new()

SCOPE
  DIM AS GError PTR meld
  GUIstr =_
  "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
  "<interface>" & _
  "<!-- interface-requires gtk+ 3.0 -->" & _
  "<object class=""GtkWindow"" id=""window1"">" & _
  "<property name=""can_focus"">False</property>" & _
  "<signal name=""destroy"" handler=""gtk_main_quit"" swapped=""no""/>" & _
  "<child>" & _
  "<object class=""GtkVBox"" id=""vbox1"">" & _
  "<property name=""visible"">True</property>" & _
  "<property name=""can_focus"">False</property>" & _
  "<property name=""border_width"">5</property>" & _
  "<property name=""spacing"">5</property>" & _
  "<child>" & _
  "<object class=""GtkButton"" id=""button1"">" & _
  "<property name=""label"" translatable=""yes"">Quit</property>" & _
  "<property name=""visible"">True</property>" & _
  "<property name=""can_focus"">True</property>" & _
  "<property name=""receives_default"">True</property>" & _
  "<property name=""use_action_appearance"">False</property>" & _
  "<signal name=""clicked"" handler=""gtk_main_quit"" swapped=""no""/>" & _
  "</object>" & _
  "<packing>" & _
  "<property name=""expand"">False</property>" & _
  "<property name=""fill"">False</property>" & _
  "<property name=""position"">0</property>" & _
  "</packing>" & _
  "</child>" & _
  "<child>" & _
  "<object class=""GtkDrawingArea"" id=""drawingarea1"">" & _
  "<property name=""width_request"">100</property>" & _
  "<property name=""height_request"">100</property>" & _
  "<property name=""visible"">True</property>" & _
  "<property name=""can_focus"">False</property>" & _
  "<signal name=""draw"" handler=""on_area_draw"" swapped=""no""/>" & _
  "</object>" & _
  "<packing>" & _
  "<property name=""expand"">True</property>" & _
  "<property name=""fill"">True</property>" & _
  "<property name=""position"">1</property>" & _
  "</packing>" & _
  "</child>" & _
  "</object>" & _
  "</child>" & _
  "</object>" & _
  "</interface>"
  IF 0 = gtk_builder_add_from_string(XML, SADD(GUISTR), LEN(GUISTR), @meld) THEN
    WITH *meld
      ?"Fehler/Error (GTK-Builder):"
      ?*.message
    END WITH
    END 2
  END IF
END SCOPE

window1 = gtk_builder_get_object(XML, @"window1")

FUNCTION on_area_draw CDECL ALIAS "on_area_draw" ( _
  BYVAL widget AS GtkWidget PTR, _
  BYVAL cr AS cairo_t PTR, _
  BYVAL user_data AS gpointer) AS gboolean EXPORT

  VAR w = gtk_widget_get_allocated_width(widget) \ 2
  VAR h = gtk_widget_get_allocated_height(widget) \ 2

  cairo_arc(cr, w, h, MIN(w, h), 0, 2 * G_PI)

  DIM AS GdkRGBA col
  gtk_style_context_get_color(gtk_widget_get_style_context (widget), _
                              0, _
                              @col)
  gdk_cairo_set_source_rgba(cr, @col)
  cairo_fill(cr)
  RETURN FALSE

END FUNCTION
'<  GTK+tobac:                                           end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv



' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'<  GTK+tobac:           run GTK main, then end / GTK Hauptschleife, dann Ende >
    gtk_builder_connect_signals(XML, 0) '                   callbacks anbinden >
    gtk_widget_show_all(GTK_WIDGET(window1)) '         Hauptfenster darstellen >
    gtk_main() '                                     main loop / Hauptschleife >
    g_object_unref(XML) '                       dereference / Referenz abbauen >
'<  GTK+tobac:                                           end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

END 0 ' finish with return code 0 / Ende mit Returncode 0

For compilation took the following steps:
1) added gtk3 lib to the folder \FreeBASIC-1.07.1-win32\lib\win32
Here I inserted gtk3 lib, which I downloaded through mingw32:
https://drive.google.com/file/d/1iqG5dD ... sp=sharing
3) Installed the gtk3 runtime from this site:
https://sourceforge.net/projects/gtk3win/files/
gtk2 runtime here (to old instruction):
https://sourceforge.net/projects/gtk-wi ... 2B%202.24/
4) Saved GtkBuilder_Cairo.bas to folder C:\Program Files (x86)\gtk-3.8.1\, so that the program finds the gtk3 library dll.

The program compiles and runs.
covid19
Posts: 31
Joined: Apr 25, 2020 20:41

Re: gtk +xml tutorial why not work?

Postby covid19 » May 11, 2020 8:34

Xusinboy Bekchanov wrote:
covid19 wrote:
Xusinboy Bekchanov wrote:This code compiles without problems for me.

Code: Select all

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< main program generated by utility                 GTK+tobac2 V2.2.0 >
'< Hauptprogramm erzeugt von                                           >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' ---------------------------------------------------------------------
'< Program info:                                                       >
CONST PROG_NAME = "Scribble" '                                         >
CONST PROG_DESC = "Zeichenprogramm" '                                  >
CONST PROG_VERS = "0.0" '                                              >
CONST PROG_YEAR = "2010" '                                             >
CONST PROG_AUTH = "TJF" '                                              >
CONST PROG_MAIL = "Thomas.Freiherr@gmx.net" '                          >
CONST PROG_WEBS = "members.aon.at/tjf" '                               >
'<                                                                     >
'< Description / Beschreibung:                                         >
'< Beispiel DrawArea, einfaches Zeichenprogramm                        >
'<                                                                     >
'< License / Lizenz:                                                   >
'<                                                                     >
'< Redistribution and use in source and binary forms, with or          >
'< without modification, are permitted provided that the following     >
'< conditions are met:                                                 >
'<                                                                     >
'< * Redistributions of source code must retain the above              >
'< copyright notice, this list of conditions and the following         >
'< disclaimer.                                                         >
'<                                                                     >
'< * Redistributions in binary form must reproduce the above           >
'< copyright notice, this list of conditions and the following         >
'< disclaimer in the documentation and/or other materials provided     >
'< with the distribution.                                              >
'<                                                                     >
'< * Neither the name of the author nor the names of its               >
'< contributors may be used to endorse or promote products derived     >
'< from this software without specific prior written permission.       >
'<                                                                     >
'< THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS                  >
'< AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED                 >
'< WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES   >
'< OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE             >
'< ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER               >
'< OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     >
'< SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT    >
'< LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF    >
'< USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED     >
'< AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT         >
'< LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN   >
'< ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE     >
'< POSSIBILITY OF SUCH DAMAGE.                                         >
'<                                                                     >
' ---------------------------------------------------------------------
'< Please prefer GNU GENERAL PUBLIC LICENSE to support open software.  >
'< For more information please visit:               http://www.fsf.org >
'<                                                                     >
'< Bitte bevorzugen Sie die GNU GENERAL PUBLIC LICENSE und             >
'< unterstuetzen Sie mit Ihrem Programm die freie Software             >
'< Mehr Informationen finden Sie unter:             http://www.fsf.org >
' ---------------------------------------------------------------------
'<  GTK+tobac:             general init / Allgemeine Initialisierungen >
  '  #INCLUDE "gtk/GTK-2.18.6_TJF.bi" '   GTK+library / GTK+ Bibliothek >
  #include once "gtk/gtk.bi"
    gtk_init(@__FB_ARGC__, @__FB_ARGV__) '     start GKT / GTK starten >
'<  GTK+tobac:                                   end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

/' Backing pixmap for drawing area '/
DIM SHARED AS GdkPixmap PTR PIXMAP = NULL
DECLARE SUB draw_brush(BYVAL widget AS GtkWidget PTR, _
                       BYVAL x AS gdouble, _
                       BYVAL y AS gdouble)

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< _tobac.bas modul generated by utility             GTK+tobac2 V2.2.0 >
'< Modul _tobac.bas erzeugt von                                        >
'< Generated at / Generierung am                     2010-09-06, 02:45 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

'IF gtk_check_version(2, 16, 0) THEN
'  ?"Fehler/Error (GTK-Version): Version zu alt"
'  END -1
'END IF

DIM AS STRING GUISTR
DIM SHARED AS GtkBuilder PTR XML
DIM SHARED AS GObject PTR _
  WinScribble, Draw1, ButQuit

XML = gtk_builder_new()

SCOPE
  DIM AS GError PTR meld

  ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  '< _gui.bas modul generated by utility               GTK+tobac2 V2.2.0 >
  '< Modul _gui.bas erzeugt von                                          >
  '< Generated at / Generierung am                     2010-09-06, 02:45 >
  ' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

  GUIstr =_
  "<?xml version=""1.0""?>"+_
  "<interface>"+_
  "<requires lib=""gtk+"" version=""2.16""/>"+_
  "<!-- interface-naming-policy project-wide -->"+_
  "<object class=""GtkWindow"" id=""WinScribble"">"+_
  "<signal name=""destroy"" handler=""gtk_main_quit""/>"+_
  "<child>"+_
  "<object class=""GtkVBox"" id=""vbox1"">"+_
  "<property name=""visible"">True</property>"+_
  "<child>"+_
  "<object class=""GtkDrawingArea"" id=""Draw1"">"+_
  "<property name=""width_request"">200</property>"+_
  "<property name=""height_request"">200</property>"+_
  "<property name=""visible"">True</property>"+_
  "<property name=""events"">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK</property>"+_
  "<signal name=""button_press_event"" handler=""on_Draw1_button_press_event""/>"+_
  "<signal name=""motion_notify_event"" handler=""on_Draw1_motion_notify_event""/>"+_
  "<signal name=""expose_event"" handler=""on_Draw1_expose_event""/>"+_
  "<signal name=""configure_event"" handler=""on_Draw1_configure_event""/>"+_
  "</object>"+_
  "<packing>"+_
  "<property name=""position"">0</property>"+_
  "</packing>"+_
  "</child>"+_
  "<child>"+_
  "<object class=""GtkButton"" id=""ButQuit"">"+_
  "<property name=""label"" translatable=""yes"">Quit</property>"+_
  "<property name=""visible"">True</property>"+_
  "<property name=""can_focus"">True</property>"+_
  "<property name=""receives_default"">True</property>"+_
  "<signal name=""clicked"" handler=""gtk_main_quit""/>"+_
  "</object>"+_
  "<packing>"+_
  "<property name=""expand"">False</property>"+_
  "<property name=""fill"">False</property>"+_
  "<property name=""position"">1</property>"+_
  "</packing>"+_
  "</child>"+_
  "</object>"+_
  "</child>"+_
  "</object>"+_
  "</interface>"
  IF 0 = gtk_builder_add_from_string(XML, SADD(GUISTR), LEN(GUISTR), @meld) THEN
    WITH *meld
      ?"Fehler/Error (GTK-Builder):"
      ?*.message
    END WITH
    END -1
  END IF
END SCOPE

WinScribble = gtk_builder_get_object(XML, "WinScribble")
Draw1 = gtk_builder_get_object(XML, "Draw1")
ButQuit = gtk_builder_get_object(XML, "ButQuit")

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_button_press_event CDECL ALIAS "on_Draw1_button_press_event" _
         (BYVAL widget AS GtkWidget PTR, _
          BYVAL event AS GdkEventButton PTR) AS gboolean EXPORT
  IF event->button = 1 THEN IF PIXMAP THEN draw_brush(widget, event->x, event->y)
  RETURN TRUE
END FUNCTION

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_motion_notify_event CDECL ALIAS "on_Draw1_motion_notify_event" _
         (BYVAL widget AS GtkWidget PTR, _
          BYVAL event AS GdkEventMotion PTR) AS gboolean EXPORT
  DIM AS INTEGER x, y
  DIM AS GdkModifierType state

  IF event->is_hint THEN
    gdk_window_get_pointer(event->window, @x, @y, @state)
  ELSE
    x = event->x
    y = event->y
    state = event->state
  END IF

  IF state AND GDK_BUTTON1_MASK THEN IF PIXMAP THEN draw_brush(widget, x, y)
  RETURN TRUE
END FUNCTION

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_expose_event CDECL ALIAS "on_Draw1_expose_event" _
         (BYVAL widget AS GtkWidget PTR, _
          BYVAL event AS GdkEventExpose PTR) AS gboolean EXPORT
  gdk_draw_drawable(widget->window, _
                    widget->style->fg_gc(gtk_widget_get_state(widget)), _
                    PIXMAP, _
                    event->area.x, event->area.y, _
                    event->area.x, event->area.y, _
                    event->area.width, event->area.height)
  RETURN FALSE
END FUNCTION

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< callback modul generated by utility               GTK+tobac2 V2.2.0 >
'< callback-Modul erzeugt von                                          >
'< Generated at / Generierung am                     2010-09-06, 01:24 >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

FUNCTION on_Draw1_configure_event CDECL ALIAS "on_Draw1_configure_event" _
        (BYVAL widget AS GtkWidget PTR, _
         BYVAL event AS GdkEventConfigure PTR) AS gboolean EXPORT
  IF PIXMAP THEN g_object_unref(pixmap)

  PIXMAP = gdk_pixmap_new(widget->window, _
                          widget->allocation.width, _
                          widget->allocation.height, _
                          -1)
  gdk_draw_rectangle(PIXMAP, _
                     widget->style->white_gc, _
                     TRUE, _
                     0, 0, _
                     widget->allocation.width, _
                     widget->allocation.height)
  RETURN TRUE
END FUNCTION


SUB draw_brush(BYVAL widget AS GtkWidget PTR, _
               BYVAL x AS gdouble, _
               BYVAL y AS gdouble)
  DIM AS GdkRectangle update_rect

  update_rect.x = x - 5
  update_rect.y = y - 5
  update_rect.width = 10
  update_rect.height = 10
  gdk_draw_rectangle(PIXMAP, _
                     widget->style->black_gc, _
                     TRUE, _
                     update_rect.x, update_rect.y, _
                     update_rect.width, update_rect.height)
  gtk_widget_queue_draw_area(widget, _
                             update_rect.x, update_rect.y, _
                             update_rect.width, update_rect.height)
END SUB

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'<  GTK+tobac:   run GTK main, then end / GTK Hauptschleife, dann Ende >
    gtk_builder_connect_signals(XML, 0) '           callbacks anbinden >
    gtk_widget_show_all(GTK_WIDGET(WinScribble)) 'ptfenster darstellen >
    gtk_main() '                             main loop / Hauptschleife >
    g_object_unref(XML) '               dereference / Referenz abbauen >
'<  GTK+tobac:                                   end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

' you may unref files here / ggf. Dateien hier schliessen

END 0 ' finish with return code 0 / Ende mit Returncode 0


Four things are needed for this:
1) Compiler version: 1.07.1-win32
2) gtk2 lib in the folder \FreeBASIC-1.07.1-win32\lib\win32
Here I inserted gtk2 lib, which I downloaded through mingw32:
https://drive.google.com/file/d/1JGmUSO ... sp=sharing
3) Installing the gtk2 runtime: If you use Geany Windows, he can install it himself.
4) comment line 687 in \FreeBASIC-1.07.1-win32\lib\win32\inc\glib.bi

Code: Select all

Private Sub g_mutex_locker_free(ByVal locker As GMutexLocker Ptr)
   'g_mutex_unlock(CPtr(GMutex Ptr, locker))
End Sub

Subject on this issue: https://www.freebasic.net/forum/viewtopic.php?t=26931


why you use gtk2 ? all topic try to show example with gtk 3 (thinking GTK is just a 4 version ) o_O

This code for gtk3 from Examples folder:

Code: Select all

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< main program generated by utility                           GladeToBac V3.0 >
'< Hauptprogramm erzeugt von                                                   >
'< Generated at / Generierung am                             2011-05-18, 08:56 >
' -----------------------------------------------------------------------------
'< Program info:                                                               >
CONST PROJ_NAME = "tom" '                                                      >
CONST PROJ_DESC = "GTK cairo test" '                                           >
CONST PROJ_VERS = "0.0" '                                                      >
CONST PROJ_YEAR = "2011" '                                                     >
CONST PROJ_AUTH = "" '                                                         >
CONST PROJ_MAIL = "Thomas[ dot ]Freiherr{ at }gmx{ dot }net" '                 >
CONST PROJ_WEBS = "www.freebasic-portal.de" '                                  >
CONST PROJ_LICE = "GNU General Public License v3" '                            >
'<                                                                             >
'< Description / Beschreibung:                                                 >
'<                                                                             >
'<                                                                             >
'< License / Lizenz:                                                           >
'<                                                                             >
'< This program is free software: you can redistribute it and/or modify        >
'< it under the terms of the GNU General Public License as published by        >
'< the Free Software Foundation, either version 3 of the License, or           >
'< (at your option) any later version.                                         >
'<                                                                             >
'< This program is distributed in the hope that it will be useful, but         >
'< WITHOUT ANY WARRANTY; without even the implied warranty of                  >
'< MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           >
'< General Public License for more details.                                    >
'<                                                                             >
'< You should have received a copy of the GNU General Public License along     >
'< with this program.  If not, see <http://www.gnu.org/licenses/>.             >
'<                                                                             >
' -----------------------------------------------------------------------------
'< Please prefer GNU GENERAL PUBLIC LICENSE to support open software.          >
'< For more information please visit:                       http://www.fsf.org >
'<                                                                             >
'< Bitte bevorzugen Sie die GNU GENERAL PUBLIC LICENSE und                     >
'< unterstuetzen Sie mit Ihrem Programm die freie Software                     >
'< Mehr Informationen finden Sie unter:                     http://www.fsf.org >
' -----------------------------------------------------------------------------
'<  GTK+tobac:                     general init / Allgemeine Initialisierungen >
    #DEFINE __USE_GTK3__ '         choose GTK version / GTK-version auswaehlen >
    #INCLUDE "gtk/gtk.bi" '                    GTK3+library / GTK3+ Bibliothek >
    gtk_init(@__FB_ARGC__, @__FB_ARGV__) '             start GKT / GTK starten >
'<  GTK+tobac:                                           end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv



' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'<  GTK+tobac:                                  load GTK stuff / GTK Anbindung >
DIM AS STRING GUISTR
DIM SHARED AS GtkBuilder PTR XML
DIM SHARED AS GObject PTR window1

XML = gtk_builder_new()

SCOPE
  DIM AS GError PTR meld
  GUIstr =_
  "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
  "<interface>" & _
  "<!-- interface-requires gtk+ 3.0 -->" & _
  "<object class=""GtkWindow"" id=""window1"">" & _
  "<property name=""can_focus"">False</property>" & _
  "<signal name=""destroy"" handler=""gtk_main_quit"" swapped=""no""/>" & _
  "<child>" & _
  "<object class=""GtkVBox"" id=""vbox1"">" & _
  "<property name=""visible"">True</property>" & _
  "<property name=""can_focus"">False</property>" & _
  "<property name=""border_width"">5</property>" & _
  "<property name=""spacing"">5</property>" & _
  "<child>" & _
  "<object class=""GtkButton"" id=""button1"">" & _
  "<property name=""label"" translatable=""yes"">Quit</property>" & _
  "<property name=""visible"">True</property>" & _
  "<property name=""can_focus"">True</property>" & _
  "<property name=""receives_default"">True</property>" & _
  "<property name=""use_action_appearance"">False</property>" & _
  "<signal name=""clicked"" handler=""gtk_main_quit"" swapped=""no""/>" & _
  "</object>" & _
  "<packing>" & _
  "<property name=""expand"">False</property>" & _
  "<property name=""fill"">False</property>" & _
  "<property name=""position"">0</property>" & _
  "</packing>" & _
  "</child>" & _
  "<child>" & _
  "<object class=""GtkDrawingArea"" id=""drawingarea1"">" & _
  "<property name=""width_request"">100</property>" & _
  "<property name=""height_request"">100</property>" & _
  "<property name=""visible"">True</property>" & _
  "<property name=""can_focus"">False</property>" & _
  "<signal name=""draw"" handler=""on_area_draw"" swapped=""no""/>" & _
  "</object>" & _
  "<packing>" & _
  "<property name=""expand"">True</property>" & _
  "<property name=""fill"">True</property>" & _
  "<property name=""position"">1</property>" & _
  "</packing>" & _
  "</child>" & _
  "</object>" & _
  "</child>" & _
  "</object>" & _
  "</interface>"
  IF 0 = gtk_builder_add_from_string(XML, SADD(GUISTR), LEN(GUISTR), @meld) THEN
    WITH *meld
      ?"Fehler/Error (GTK-Builder):"
      ?*.message
    END WITH
    END 2
  END IF
END SCOPE

window1 = gtk_builder_get_object(XML, @"window1")

FUNCTION on_area_draw CDECL ALIAS "on_area_draw" ( _
  BYVAL widget AS GtkWidget PTR, _
  BYVAL cr AS cairo_t PTR, _
  BYVAL user_data AS gpointer) AS gboolean EXPORT

  VAR w = gtk_widget_get_allocated_width(widget) \ 2
  VAR h = gtk_widget_get_allocated_height(widget) \ 2

  cairo_arc(cr, w, h, MIN(w, h), 0, 2 * G_PI)

  DIM AS GdkRGBA col
  gtk_style_context_get_color(gtk_widget_get_style_context (widget), _
                              0, _
                              @col)
  gdk_cairo_set_source_rgba(cr, @col)
  cairo_fill(cr)
  RETURN FALSE

END FUNCTION
'<  GTK+tobac:                                           end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv



' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'<  GTK+tobac:           run GTK main, then end / GTK Hauptschleife, dann Ende >
    gtk_builder_connect_signals(XML, 0) '                   callbacks anbinden >
    gtk_widget_show_all(GTK_WIDGET(window1)) '         Hauptfenster darstellen >
    gtk_main() '                                     main loop / Hauptschleife >
    g_object_unref(XML) '                       dereference / Referenz abbauen >
'<  GTK+tobac:                                           end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

END 0 ' finish with return code 0 / Ende mit Returncode 0

For compilation took the following steps:
1) added gtk3 lib to the folder \FreeBASIC-1.07.1-win32\lib\win32
Here I inserted gtk3 lib, which I downloaded through mingw32:
https://drive.google.com/file/d/1iqG5dD ... sp=sharing
3) Installed the gtk3 runtime from this site:
https://sourceforge.net/projects/gtk3win/files/
gtk2 runtime here (to old instruction):
https://sourceforge.net/projects/gtk-wi ... 2B%202.24/
4) Saved GtkBuilder_Cairo.bas to folder C:\Program Files (x86)\gtk-3.8.1\, so that the program finds the gtk3 library dll.

The program compiles and runs.


but for me not work rewturn

Code: Select all

Command executed:
"C:\FreeBasic\fbc.exe" "C:\Users\pc\Desktop\test_freebasic\FBIDETEMP.bas"

Compiler output:
C:\FreeBasic\inc\gtk\glib\gmacros.bi(14) error 4: Duplicated definition, G_STRLOC in '#define G_STRLOC ":" + str$(__LINE__)'
C:\FreeBasic\inc\gtk\glib\gmacros.bi(15) warning 39(0): Redefinition of intrinsic
C:\FreeBasic\inc\gtk\glib\gmacros.bi(16) warning 39(0): Redefinition of intrinsic
C:\FreeBasic\inc\gtk\glib\config.bi(23) error 4: Duplicated definition in 'type gint32 as integer'
C:\FreeBasic\inc\gtk\glib\config.bi(24) error 4: Duplicated definition in 'type guint32 as uinteger'
C:\FreeBasic\inc\gtk\glib\config.bi(29) error 4: Duplicated definition, G_HAVE_GINT64 in '#define G_HAVE_GINT64 1'
C:\FreeBasic\inc\gtk\glib\config.bi(37) error 4: Duplicated definition, GLIB_SIZEOF_VOID_P in '#define GLIB_SIZEOF_VOID_P 4'
C:\FreeBasic\inc\gtk\glib\config.bi(38) error 4: Duplicated definition, GLIB_SIZEOF_LONG in '#define GLIB_SIZEOF_LONG 4'
C:\FreeBasic\inc\gtk\glib\config.bi(41) error 4: Duplicated definition in 'type gssize as integer'
C:\FreeBasic\inc\gtk\glib\config.bi(42) error 4: Duplicated definition in 'type gsize as uinteger'
C:\FreeBasic\inc\gtk\glib\config.bi(47) error 4: Duplicated definition, GLIB_MAJOR_VERSION in '#define GLIB_MAJOR_VERSION 2'
C:\FreeBasic\inc\gtk\glib\config.bi(48) error 4: Duplicated definition, GLIB_MINOR_VERSION in '#define GLIB_MINOR_VERSION 6'
C:\FreeBasic\inc\gtk\glib\config.bi(48) error 133: Too many errors, exiting

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc:   FreeBASIC Compiler - Version 1.07.1 (2019-09-27), built for win32 (32bit)
OS:    Windows NT 6.2 (build 9200)
Xusinboy Bekchanov
Posts: 243
Joined: Jul 26, 2018 18:28

Re: gtk +xml tutorial why not work?

Postby Xusinboy Bekchanov » May 11, 2020 8:43

covid19 wrote:
Xusinboy Bekchanov wrote:
covid19 wrote:
why you use gtk2 ? all topic try to show example with gtk 3 (thinking GTK is just a 4 version ) o_O

This code for gtk3 from Examples folder:

Code: Select all

' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'< main program generated by utility                           GladeToBac V3.0 >
'< Hauptprogramm erzeugt von                                                   >
'< Generated at / Generierung am                             2011-05-18, 08:56 >
' -----------------------------------------------------------------------------
'< Program info:                                                               >
CONST PROJ_NAME = "tom" '                                                      >
CONST PROJ_DESC = "GTK cairo test" '                                           >
CONST PROJ_VERS = "0.0" '                                                      >
CONST PROJ_YEAR = "2011" '                                                     >
CONST PROJ_AUTH = "" '                                                         >
CONST PROJ_MAIL = "Thomas[ dot ]Freiherr{ at }gmx{ dot }net" '                 >
CONST PROJ_WEBS = "www.freebasic-portal.de" '                                  >
CONST PROJ_LICE = "GNU General Public License v3" '                            >
'<                                                                             >
'< Description / Beschreibung:                                                 >
'<                                                                             >
'<                                                                             >
'< License / Lizenz:                                                           >
'<                                                                             >
'< This program is free software: you can redistribute it and/or modify        >
'< it under the terms of the GNU General Public License as published by        >
'< the Free Software Foundation, either version 3 of the License, or           >
'< (at your option) any later version.                                         >
'<                                                                             >
'< This program is distributed in the hope that it will be useful, but         >
'< WITHOUT ANY WARRANTY; without even the implied warranty of                  >
'< MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           >
'< General Public License for more details.                                    >
'<                                                                             >
'< You should have received a copy of the GNU General Public License along     >
'< with this program.  If not, see <http://www.gnu.org/licenses/>.             >
'<                                                                             >
' -----------------------------------------------------------------------------
'< Please prefer GNU GENERAL PUBLIC LICENSE to support open software.          >
'< For more information please visit:                       http://www.fsf.org >
'<                                                                             >
'< Bitte bevorzugen Sie die GNU GENERAL PUBLIC LICENSE und                     >
'< unterstuetzen Sie mit Ihrem Programm die freie Software                     >
'< Mehr Informationen finden Sie unter:                     http://www.fsf.org >
' -----------------------------------------------------------------------------
'<  GTK+tobac:                     general init / Allgemeine Initialisierungen >
    #DEFINE __USE_GTK3__ '         choose GTK version / GTK-version auswaehlen >
    #INCLUDE "gtk/gtk.bi" '                    GTK3+library / GTK3+ Bibliothek >
    gtk_init(@__FB_ARGC__, @__FB_ARGV__) '             start GKT / GTK starten >
'<  GTK+tobac:                                           end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv



' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'<  GTK+tobac:                                  load GTK stuff / GTK Anbindung >
DIM AS STRING GUISTR
DIM SHARED AS GtkBuilder PTR XML
DIM SHARED AS GObject PTR window1

XML = gtk_builder_new()

SCOPE
  DIM AS GError PTR meld
  GUIstr =_
  "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
  "<interface>" & _
  "<!-- interface-requires gtk+ 3.0 -->" & _
  "<object class=""GtkWindow"" id=""window1"">" & _
  "<property name=""can_focus"">False</property>" & _
  "<signal name=""destroy"" handler=""gtk_main_quit"" swapped=""no""/>" & _
  "<child>" & _
  "<object class=""GtkVBox"" id=""vbox1"">" & _
  "<property name=""visible"">True</property>" & _
  "<property name=""can_focus"">False</property>" & _
  "<property name=""border_width"">5</property>" & _
  "<property name=""spacing"">5</property>" & _
  "<child>" & _
  "<object class=""GtkButton"" id=""button1"">" & _
  "<property name=""label"" translatable=""yes"">Quit</property>" & _
  "<property name=""visible"">True</property>" & _
  "<property name=""can_focus"">True</property>" & _
  "<property name=""receives_default"">True</property>" & _
  "<property name=""use_action_appearance"">False</property>" & _
  "<signal name=""clicked"" handler=""gtk_main_quit"" swapped=""no""/>" & _
  "</object>" & _
  "<packing>" & _
  "<property name=""expand"">False</property>" & _
  "<property name=""fill"">False</property>" & _
  "<property name=""position"">0</property>" & _
  "</packing>" & _
  "</child>" & _
  "<child>" & _
  "<object class=""GtkDrawingArea"" id=""drawingarea1"">" & _
  "<property name=""width_request"">100</property>" & _
  "<property name=""height_request"">100</property>" & _
  "<property name=""visible"">True</property>" & _
  "<property name=""can_focus"">False</property>" & _
  "<signal name=""draw"" handler=""on_area_draw"" swapped=""no""/>" & _
  "</object>" & _
  "<packing>" & _
  "<property name=""expand"">True</property>" & _
  "<property name=""fill"">True</property>" & _
  "<property name=""position"">1</property>" & _
  "</packing>" & _
  "</child>" & _
  "</object>" & _
  "</child>" & _
  "</object>" & _
  "</interface>"
  IF 0 = gtk_builder_add_from_string(XML, SADD(GUISTR), LEN(GUISTR), @meld) THEN
    WITH *meld
      ?"Fehler/Error (GTK-Builder):"
      ?*.message
    END WITH
    END 2
  END IF
END SCOPE

window1 = gtk_builder_get_object(XML, @"window1")

FUNCTION on_area_draw CDECL ALIAS "on_area_draw" ( _
  BYVAL widget AS GtkWidget PTR, _
  BYVAL cr AS cairo_t PTR, _
  BYVAL user_data AS gpointer) AS gboolean EXPORT

  VAR w = gtk_widget_get_allocated_width(widget) \ 2
  VAR h = gtk_widget_get_allocated_height(widget) \ 2

  cairo_arc(cr, w, h, MIN(w, h), 0, 2 * G_PI)

  DIM AS GdkRGBA col
  gtk_style_context_get_color(gtk_widget_get_style_context (widget), _
                              0, _
                              @col)
  gdk_cairo_set_source_rgba(cr, @col)
  cairo_fill(cr)
  RETURN FALSE

END FUNCTION
'<  GTK+tobac:                                           end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv



' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'<  GTK+tobac:           run GTK main, then end / GTK Hauptschleife, dann Ende >
    gtk_builder_connect_signals(XML, 0) '                   callbacks anbinden >
    gtk_widget_show_all(GTK_WIDGET(window1)) '         Hauptfenster darstellen >
    gtk_main() '                                     main loop / Hauptschleife >
    g_object_unref(XML) '                       dereference / Referenz abbauen >
'<  GTK+tobac:                                           end block / Blockende >
' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

END 0 ' finish with return code 0 / Ende mit Returncode 0

For compilation took the following steps:
1) added gtk3 lib to the folder \FreeBASIC-1.07.1-win32\lib\win32
Here I inserted gtk3 lib, which I downloaded through mingw32:
https://drive.google.com/file/d/1iqG5dD ... sp=sharing
3) Installed the gtk3 runtime from this site:
https://sourceforge.net/projects/gtk3win/files/
gtk2 runtime here (to old instruction):
https://sourceforge.net/projects/gtk-wi ... 2B%202.24/
4) Saved GtkBuilder_Cairo.bas to folder C:\Program Files (x86)\gtk-3.8.1\, so that the program finds the gtk3 library dll.

The program compiles and runs.


but for me not work rewturn

Code: Select all

Command executed:
"C:\FreeBasic\fbc.exe" "C:\Users\pc\Desktop\test_freebasic\FBIDETEMP.bas"

Compiler output:
C:\FreeBasic\inc\gtk\glib\gmacros.bi(14) error 4: Duplicated definition, G_STRLOC in '#define G_STRLOC ":" + str$(__LINE__)'
C:\FreeBasic\inc\gtk\glib\gmacros.bi(15) warning 39(0): Redefinition of intrinsic
C:\FreeBasic\inc\gtk\glib\gmacros.bi(16) warning 39(0): Redefinition of intrinsic
C:\FreeBasic\inc\gtk\glib\config.bi(23) error 4: Duplicated definition in 'type gint32 as integer'
C:\FreeBasic\inc\gtk\glib\config.bi(24) error 4: Duplicated definition in 'type guint32 as uinteger'
C:\FreeBasic\inc\gtk\glib\config.bi(29) error 4: Duplicated definition, G_HAVE_GINT64 in '#define G_HAVE_GINT64 1'
C:\FreeBasic\inc\gtk\glib\config.bi(37) error 4: Duplicated definition, GLIB_SIZEOF_VOID_P in '#define GLIB_SIZEOF_VOID_P 4'
C:\FreeBasic\inc\gtk\glib\config.bi(38) error 4: Duplicated definition, GLIB_SIZEOF_LONG in '#define GLIB_SIZEOF_LONG 4'
C:\FreeBasic\inc\gtk\glib\config.bi(41) error 4: Duplicated definition in 'type gssize as integer'
C:\FreeBasic\inc\gtk\glib\config.bi(42) error 4: Duplicated definition in 'type gsize as uinteger'
C:\FreeBasic\inc\gtk\glib\config.bi(47) error 4: Duplicated definition, GLIB_MAJOR_VERSION in '#define GLIB_MAJOR_VERSION 2'
C:\FreeBasic\inc\gtk\glib\config.bi(48) error 4: Duplicated definition, GLIB_MINOR_VERSION in '#define GLIB_MINOR_VERSION 6'
C:\FreeBasic\inc\gtk\glib\config.bi(48) error 133: Too many errors, exiting

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc:   FreeBASIC Compiler - Version 1.07.1 (2019-09-27), built for win32 (32bit)
OS:    Windows NT 6.2 (build 9200)

You, in my opinion, copied only fbc.exe to folder C:\FreeBasic\. Because there is no glib folder in the inc\gtk folder.
You delete the folder FreeBasic\ and put the folder FreeBASIC-1.07.1-win32 completely and check.
covid19
Posts: 31
Joined: Apr 25, 2020 20:41

Re: gtk +xml tutorial why not work?

Postby covid19 » May 11, 2020 9:08

inside a C:\GTK\include i have this glib-2.0
TJF
Posts: 3599
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: gtk +xml tutorial why not work?

Postby TJF » May 11, 2020 9:11

covid19 wrote:

Code: Select all

Command executed:
"C:\FreeBasic\fbc.exe" "C:\Users\pc\Desktop\test_freebasic\FBIDETEMP.bas"

Compiler output:
C:\FreeBasic\inc\gtk\glib\gmacros.bi(14) error 4: Duplicated definition, G_STRLOC in '#define G_STRLOC ":" + str$(__LINE__)'
C:\FreeBasic\inc\gtk\glib\gmacros.bi(15) warning 39(0): Redefinition of intrinsic
C:\FreeBasic\inc\gtk\glib\gmacros.bi(16) warning 39(0): Redefinition of intrinsic
C:\FreeBasic\inc\gtk\glib\config.bi(23) error 4: Duplicated definition in 'type gint32 as integer'
C:\FreeBasic\inc\gtk\glib\config.bi(24) error 4: Duplicated definition in 'type guint32 as uinteger'
C:\FreeBasic\inc\gtk\glib\config.bi(29) error 4: Duplicated definition, G_HAVE_GINT64 in '#define G_HAVE_GINT64 1'
C:\FreeBasic\inc\gtk\glib\config.bi(37) error 4: Duplicated definition, GLIB_SIZEOF_VOID_P in '#define GLIB_SIZEOF_VOID_P 4'
C:\FreeBasic\inc\gtk\glib\config.bi(38) error 4: Duplicated definition, GLIB_SIZEOF_LONG in '#define GLIB_SIZEOF_LONG 4'
C:\FreeBasic\inc\gtk\glib\config.bi(41) error 4: Duplicated definition in 'type gssize as integer'
C:\FreeBasic\inc\gtk\glib\config.bi(42) error 4: Duplicated definition in 'type gsize as uinteger'
C:\FreeBasic\inc\gtk\glib\config.bi(47) error 4: Duplicated definition, GLIB_MAJOR_VERSION in '#define GLIB_MAJOR_VERSION 2'
C:\FreeBasic\inc\gtk\glib\config.bi(48) error 4: Duplicated definition, GLIB_MINOR_VERSION in '#define GLIB_MINOR_VERSION 6'
C:\FreeBasic\inc\gtk\glib\config.bi(48) error 133: Too many errors, exiting

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc:   FreeBASIC Compiler - Version 1.07.1 (2019-09-27), built for win32 (32bit)
OS:    Windows NT 6.2 (build 9200)
I don't understand your header file locations. No file gmacros.bi nor file config.bi should get used in folder C:\FreeBasic\inc\gtk\glib\. Those are outdated since years. Instead the file C:\FreeBasic\inc\glib.bi should get used (check at https://github.com/freebasic/fbc/tree/master/inc). Obviously you mixed some fbc installations.
Xusinboy Bekchanov
Posts: 243
Joined: Jul 26, 2018 18:28

Re: gtk +xml tutorial why not work?

Postby Xusinboy Bekchanov » May 11, 2020 9:15

covid19 wrote:inside a C:\GTK\include i have this glib-2.0

Your problem is not in the library, only the gtk headers. There are only three files in the "\FreeBASIC-1.07.1-win32\inc\gtk" folder: gtk.bi, gtk2.bi and gtk3.bi. Because you are using the old compiler. Just copied fbс.exe to the folder of the old compiler.
covid19
Posts: 31
Joined: Apr 25, 2020 20:41

Re: gtk +xml tutorial why not work?

Postby covid19 » May 11, 2020 9:45

i ask why and repeat why , not exist a #%$@...... installer .exe that do it ??
is very difficult do a simple think
covid19
Posts: 31
Joined: Apr 25, 2020 20:41

Re: gtk +xml tutorial why not work?

Postby covid19 » May 11, 2020 9:49

so i hava a simple request i cancel all freebasic platform 64 bit ,i nwant run a free basic +gtk3 + glade 3 (for create xml gui) + editor for freebasic
some angel can give me a link of last repeat last version of things , and instruction for run all, and also example ?
clear list like you want turn on a airplan.
TJF
Posts: 3599
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: gtk +xml tutorial why not work?

Postby TJF » May 11, 2020 9:52

covid19 wrote:i ask why and repeat why , not exist a #%$@...... installer .exe that do it ??
is very difficult do a simple think
If you don't want to use the existing installer at

https://sourceforge.net/projects/fbc/fi ... 20Windows/

you #%$@...... will have to create your own.
covid19 wrote:so i hava a simple request i cancel all freebasic ,i nwant run a free basic +gtk3 + glade 3 (for create xml gui) + editor for freebasic
some angel can give me a link of last repeat last version of things , and instruction for run all, and also example ?
clear list like you want turn on a airplan.

Just switch to LINUX.
Xusinboy Bekchanov
Posts: 243
Joined: Jul 26, 2018 18:28

Re: gtk +xml tutorial why not work?

Postby Xusinboy Bekchanov » May 11, 2020 9:54

covid19 wrote:i ask why and repeat why , not exist a #%$@...... installer .exe that do it ??
is very difficult do a simple think

Here compiler installation is not required.
This link has the latest compiler 1.07.1.
viewtopic.php?f=1&t=27885
There, click .zip archive or .7z archive. Unzip it. Here is the compiler for you. In the IDE, specify the path to the compiler folder.

You need to install only gtk3 lib and gtk3 runtime.
Xusinboy Bekchanov
Posts: 243
Joined: Jul 26, 2018 18:28

Re: gtk +xml tutorial why not work?

Postby Xusinboy Bekchanov » May 11, 2020 9:56

covid19 wrote:so i hava a simple request i cancel all freebasic platform 64 bit ,i nwant run a free basic +gtk3 + glade 3 (for create xml gui) + editor for freebasic
some angel can give me a link of last repeat last version of things , and instruction for run all, and also example ?
clear list like you want turn on a airplan.

Use Geany for IDE: https://www.geany.org/download/releases/.
The rest is as I said above in previous posts.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 4 guests