Use the gtkSourceView Widget with FreeBASIC (preview)

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

Use the gtkSourceView Widget with FreeBASIC (preview)

Postby D.J.Peters » Sep 13, 2010 1:13

gtkSourceView Widget homepage: http://projects.gnome.org/gtksourceview/

With the gtkSourceView widget you can create your own FreeBASIC IDE.

Create your own "FreeBASIC.lang" file or use one from net e.g. Gedit, Geany IDE, ...

Get the FreeBASIC gtk headers and a short sample: gtkSourceViewPreview.zip


Linux:
Image

Windows:
Image

Joshy

test01.bas only a short preview but it works so far.

Code: Select all

#include "gtk/gtk.bi"
#include "gtksourceview/gtksourceview.bi"
#include "gtksourceview/gtksourcelanguagemanager.bi"

#ifndef NULL
#define NULL cptr(any ptr,0)
#endif

gtk_init(0,NULL)

' create main window
dim as GtkWidget ptr mainwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL)
gtk_window_set_default_size (GTK_WINDOW (mainwindow), 800,600)
g_signal_connect (G_OBJECT (mainwindow),"destroy", G_CALLBACK(@gtk_main_quit),NULL)
' create a vbox
dim as GtkWidget ptr vbox = gtk_vbox_new (FALSE, 0)
gtk_container_add(GTK_CONTAINER(mainwindow), vbox)
' create a scroll window in the vbox
dim as GtkWidget ptr scrolledwindow = gtk_scrolled_window_new(NULL,NULL)
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC)
gtk_box_pack_start (GTK_BOX(vbox),scrolledwindow,TRUE,TRUE,0)
' create the stksourceview widget
dim as GtkWidget ptr editor = gtk_source_view_new()
gtk_container_add(GTK_CONTAINER(scrolledwindow), editor)
' set some params
gtk_source_view_set_auto_indent            (GTK_SOURCE_VIEW(editor),TRUE)
gtk_source_view_set_indent_width           (GTK_SOURCE_VIEW(editor),2)
gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW(editor),TRUE)
gtk_source_view_set_show_line_marks        (GTK_SOURCE_VIEW(editor),TRUE)
gtk_source_view_set_show_line_numbers      (GTK_SOURCE_VIEW(editor),TRUE)
gtk_source_view_set_right_margin_position  (GTK_SOURCE_VIEW(editor),80)
gtk_source_view_set_show_right_margin      (GTK_SOURCE_VIEW(editor),TRUE)
gtk_text_view_set_wrap_mode                (GTK_TEXT_VIEW(editor),GTK_WRAP_WORD_CHAR)

' use a mono space font
dim as PangoFontDescription ptr font_desc = pango_font_description_new()
pango_font_description_set_family (font_desc, "monospace")
gtk_widget_modify_font (editor, font_desc)

' create language manager
dim as GtkSourceLanguageManager ptr lm = gtk_source_language_manager_get_default()
' use default paths for *.lang files
gtk_source_language_manager_set_search_path(lm,NULL)
' create languages from "c.lang" file
dim as GtkSourceLanguage ptr lang = gtk_source_language_manager_get_language(lm,@"c")

' create source buffer from language
dim as GtkSourceBuffer ptr buffer = gtk_source_buffer_new_with_language(lang)
gtk_source_buffer_set_highlight_syntax(buffer,TRUE)

' add a litle bit c code
dim as string text= !"/* a litle bit c */\n\nprintf(\"hello world!\");\n\nfor (int i=0;i<10;i++) {\n\n\  printf(\"value is %d\",&i);\n\n}\n"
gtk_text_buffer_set_text (GTK_TEXT_BUFFER(buffer),strptr(text),len(text))
gtk_text_view_set_buffer (GTK_TEXT_VIEW(editor),GTK_TEXT_BUFFER(buffer))
g_object_unref(buffer)

gtk_widget_show_all(mainwindow)
gtk_main()
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Postby petan » Sep 13, 2010 22:10

Hi.
Your packed Test01.exe not working, missing library libgtksourceview200.dll

Pete
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

Postby D.J.Peters » Sep 14, 2010 0:27

petan wrote:Hi.
Your packed Test01.exe not working, missing library libgtksourceview200.dll

Pete
D.J.Peters wrote:gtkSourceView Widget homepage: http://projects.gnome.org/gtksourceview/

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest