Copy and Paste Text

New to FreeBASIC? Post your questions here.
Post Reply
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Copy and Paste Text

Post by Sigord »

Is there any way to Paste Text into a Screen Window after using Copy from the Clipboard like another program such as a WP or Notepad?

Likewise can we create a Text Window to Copy from to Paste elsewhere?
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Copy and Paste Text

Post by TJF »

This creates a window with a multi line text editor in monospace font with scrollbars, filled by its own source code. Right-click to get a pop-up for copy /paste.

Image

Code: Select all

' TXTVW.BAS
' by TJF (2014)

#DEFINE __USE_GTK3__
#INCLUDE ONCE "gtk/gtk.bi"


gtk_init (NULL, NULL)

VAR win = gtk_window_new (GTK_WINDOW_TOPLEVEL)
gtk_widget_set_size_request (win, 500, 450)
g_signal_connect (G_OBJECT (win), "destroy", _
                  G_CALLBACK (@gtk_main_quit), NULL)
gtk_window_set_title (GTK_WINDOW (win), "Text Widget Example for Sigord")
gtk_container_set_border_width (GTK_CONTAINER (win), 5)

VAR scroll = gtk_scrolled_window_new (NULL, NULL)
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), _
                                GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC)
gtk_container_add (GTK_CONTAINER (win), scroll)
gtk_widget_show (scroll)

VAR text = gtk_text_view_new ()
gtk_text_view_set_editable (GTK_TEXT_VIEW (text), TRUE)
gtk_container_add (GTK_CONTAINER (scroll), text)
gtk_widget_show (text)

VAR panfo = pango_font_description_from_string("monospace 10")
gtk_widget_modify_font(GTK_WIDGET(text), panfo)
pango_font_description_free(panfo)

VAR buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW (text))
DIM AS GTKTextIter iter
gtk_text_buffer_get_iter_at_offset(buffer, @Iter, 0)

VAR inbuf = "", fnam = "TXTVW.BAS", fnr = FREEFILE
IF OPEN (fnam FOR INPUT AS #fnr) THEN
  inbuf = "Cannot open " & fnam & "!"
ELSE
  inbuf = STRING(LOF(fnr), 0)
  GET #fnr, , inbuf
  CLOSE #fnr
END IF
gtk_text_buffer_insert (buffer, @iter, inbuf, -1)

gtk_widget_show (win)

gtk_main ()
Last edited by TJF on Feb 01, 2014 15:53, edited 1 time in total.
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: Copy and Paste Text

Post by Sigord »

Thanks very much.

Will investigate.
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: Copy and Paste Text

Post by Sigord »

Sorry no luck

In realizing it must need numerous files in folder GTk-d I ran the code in there.

But it sill invoked numerous errors asking below

Command executed:
"C:\Tools\FreeBASIC-0.90.1-win32\fbc.exe" "C:\Tools\FreeBASIC-0.90.1-win32\Gtk-3\t.bas"

Compiler output:
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -lgtk-3
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -lgdk-3
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -lgthread-2.0
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -lglib-2.0
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -lgio-2.0
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -lgobject-2.0
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -lgmodule-2.0
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -lpango-1.0
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -lcairo
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -lgdk_pixbuf-2.0
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -lpangocairo-1.0
C:\Tools\FreeBASIC-0.90.1-win32\bin\win32\ld.exe: cannot find -latk-1.0

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 0.90.1 (07-17-2013) for win32
OS: Windows NT 6.1 (build 7601, Service Pack 1)
fxm
Moderator
Posts: 12158
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Copy and Paste Text

Post by fxm »

Post Reply