Code: Select all
private function Fl_Tree.prefs() byref as const Fl_Tree_Prefs
return prefs
end function
Code: Select all
private function Fl_Tree.prefs() byref as const Fl_Tree_Prefs
return _prefs
end function
Code: Select all
private function Fl_Tree.prefs() byref as const Fl_Tree_Prefs
return prefs
end function
Code: Select all
private function Fl_Tree.prefs() byref as const Fl_Tree_Prefs
return _prefs
end function
there is no private function Fl_Tree.prefs() in Fl_Tree_Prefs.biangros47 wrote: ↑Aug 21, 2023 21:17 In Fl_Tree_Prefs.bi, change:ToCode: Select all
private function Fl_Tree.prefs() byref as const Fl_Tree_Prefs return prefs end function
Code: Select all
private function Fl_Tree.prefs() byref as const Fl_Tree_Prefs return _prefs end function
Code: Select all
#include once "FLTK/Fl_Double_Window.bi"
#include once "FLTK/Fl_Menu_Bar.bi"
#include once "FLTK/Fl_Tree.bi"
'Tree's callback
'Invoked whenever an item's state changes.
'This callback is invoked whenever the user clicks an item in the menu bar
Sub TreeCallback(w as Fl_Widget ptr, p as any ptr)
var tree = cptr(Fl_Tree ptr, w)
dim item as const Fl_Tree_Item ptr = cptr(Fl_Tree_Item ptr, tree->callback_item())
if (item <> 1) then
exit sub
end if
select case (tree->callback_reason())
case FL_TREE_REASON_SELECTED
dim pathname as string*256
tree->item_pathname(pathname, sizeof(pathname), item)
print "TreeCallback: Item selected=" & item->label() & " Full pathname= " & pathname
case FL_TREE_REASON_DESELECTED
print "TreeCallback: Item " & item->label() & " deselected"
case FL_TREE_REASON_OPENED
print "TreeCallback: Item " & item->label() & " opened"
case FL_TREE_REASON_CLOSED
print "TreeCallback: Item " & item->label() & " closed"
end select
end sub
'main program
Fl.scheme("gtk+")
dim win as Fl_Double_Window = Fl_Double_Window(250, 400, "Simple Tree")
win.begin()
'Create the tree
dim tree as Fl_Tree= Fl_Tree(10, 10, win.w()-20, win.h()-20)
tree.showroot(0) 'don't show root of tree
dim cb as Fl_Callback = @TreeCallback
tree.callback(cb) 'setup a callback for the tree
'Add some items
tree.add("Flintstones/Fred")
tree.add("Flintstones/Wilma")
tree.add("Flintstones/Pebbles")
tree.add("Simpsons/Homer")
tree.add("Simpsons/Marge")
tree.add("Simpsons/Bart")
tree.add("Simpsons/Lisa")
tree.add(!"Pathnames/\\/bin") 'front slashes
tree.add(!"Pathnames/\\/usr\\/sbin")
tree.add(!"Pathnames/C:\\\\Program Files") 'backslashes
tree.add(!"Pathnames/C:\\\\Documents and Settings")
tree.close_("Simpsons")
tree.close_("Pathnames")
win.end_()
win.resizable(win)
win.show()
Fl.run_()
Code: Select all
#include once "FLTK/Fl_Window.bi"
#include once "FLTK/Fl_Menu_Bar.bi"
#include once "FLTK/filename.bi"
' This callback is invoked whenever the user clicks an item in the menu bar
Sub MyMenuCallback(w as Fl_Widget ptr, p as any ptr)
dim bar as Fl_Menu_Bar ptr = cptr(Fl_Menu_Bar ptr, w)
dim item as const Fl_Menu_Item ptr = cptr(Fl_Menu_Item ptr, bar->mvalue())
dim ipath as string*256
bar->item_pathname(ipath, sizeof(ipath)) ' Get full pathname of picked item
print "callback: You picked " & *item->label() 'Print item picked
print "item_pathname() is: " & ipath 'and full pathname
if ( item->flags and (FL_MENU_RADIO or FL_MENU_TOGGLE) ) then 'Toggle or radio item?
print "value is " & iif(item->value(), "on", "off") 'Print item's value
end if
if (*item->label() = "Google" ) then
'fl_open_uri("http://google.com/")
end if
if (*item->label()="&Quit") then
end
end if
end sub
'main program
Fl.scheme("gtk+")
dim win as Fl_Window = Fl_Window(400,200, "menubar-simple") ' Create window
dim menu as Fl_Menu_Bar = Fl_Menu_Bar(0,0,400,25) ' Create menubar, items..
Dim cb as Fl_Callback = @MyMenuCallback
menu.add("&File/&Open", "^o", cb)
menu.add("&File/&Save", "^s", cb, 0, FL_MENU_DIVIDER)
menu.add("&File/&Quit", "^q", cb)
menu.add("&Edit/&Copy", "^c", cb)
menu.add("&Edit/&Paste", "^v", cb, 0, FL_MENU_DIVIDER)
menu.add("&Edit/Radio 1", 0, cb, 0, FL_MENU_RADIO)
menu.add("&Edit/Radio 2", 0, cb, 0, FL_MENU_RADIO or FL_MENU_DIVIDER)
menu.add("&Edit/Toggle 1", 0, cb, 0, FL_MENU_TOGGLE) ' Default: off
menu.add("&Edit/Toggle 2", 0, cb, 0, FL_MENU_TOGGLE) ' Default: off
menu.add("&Edit/Toggle 3", 0, cb, 0, FL_MENU_TOGGLE or FL_MENU_VALUE) ' Default: on
menu.add("&Help/Google", 0, cb)
win.end_()
win.show()
Fl.run_()
The book has been released !demosthenesk wrote: ↑Aug 15, 2023 17:20 I was started to writing a book about FLTK and FreeBASIC.
It is based on fltk-1.3.5.pdf documentation and example code by Angelo Rosina (angros47) and me Demosthenes Koptsis (demosthenesk).
Soon available...
https://github.com/demosthenesk/Getting ... BASIC-Book
Code: Select all
declare function fl_open_uri(uri as const zstring ptr, msg as zstring ptr= 0, msglen as long = 0) as long
Code: Select all
shell "xdg-open http://google.com"
it is in an example of FLTK and it is provided by the lib...so why not to be included ?angros47 wrote: ↑Aug 22, 2023 16:07 I guess it can be declared as
test it to see if it has to be inside an 'extern "c" ' or extern "c++" ' blockCode: Select all
declare function fl_open_uri(uri as const zstring ptr, msg as zstring ptr= 0, msglen as long = 0) as long
But, why do you need that command? Can't you just do something like
or similar?Code: Select all
shell "xdg-open http://google.com"
The main reason I didn't bother to translate the headers of filenames is that FreeBasic already provided equivalent functions
Code: Select all
'
' "$Id$"
'
' Simple example of using Fl_Table - Greg Ercolano 11/29/2010
'
' Demonstrates the simplest use of Fl_Table possible.
' Display a 10x10 array of integers with row/col headers.
' No interaction; simple display of data only.
' See other examples for more complex interactions with the table.
'
' Copyright 2010 Greg Ercolano.
' Copyright 1998-2010 by Bill Spitzak and others.
'
' This library is free software. Distribution and use rights are outlined in
' the file "COPYING" which should have been included with this file. If this
' file is missing or damaged, see the license at:
'
' http:'www.fltk.org/COPYING.php
'
' Please report all bugs and problems on the following page:
'
' http:'www.fltk.org/str.php
'
#include once "FLTK/Fl.bi"
#include once "FLTK/Fl_Double_Window.bi"
#include once "FLTK/Fl_Table.bi"
#include once "FLTK/fl_draw.bi"
#include once "FLTK/Fl_Menu_Bar.bi"
extern "c++"
#define MAX_ROWS 30
#define MAX_COLS 26 ' A-Z
' Derive a class from Fl_Table
type MyTable extends Fl_Table
private:
declare constructor (byref w as const MyTable)
declare operator let (byref w as const MyTable)
data_(MAX_ROWS,MAX_COLS) as long ' data array for cells
' Draw the row/col headings
' Make this a dark thin upbox with the text inside.
'
declare sub DrawHeader(s as const zstring ptr, X as long, Y as long, W as long, H as long)
' Draw the cell data
' Dark gray text on white background with subtle border
'
declare sub DrawData(s as const zstring ptr, X as long, Y as long, W as long, H as long)
' Handle drawing table's cells
' Fl_Table calls this function to draw each visible cell in the table.
' It's up to us to use FLTK's drawing functions to draw the cells the way we want.
'
declare sub draw_cell(context as TableContext, ROW as long=0, COL as long=0, X as long=0, Y as long=0, W as long=0, H as long=0)
public:
' Constructor
' Make our data array, and initialize the table options.
'
declare constructor(X as long, Y as long, W as long, H as long, L as const zstring ptr=0)
declare destructor()
end type
private sub MyTable.DrawHeader(s as const zstring ptr, X as long, Y as long, W as long, H as long)
fl_push_clip(X,Y,W,H)
fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, row_header_color())
fl_color(FL_BLACK)
fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER)
fl_pop_clip()
end sub
private sub MyTable.DrawData(s as const zstring ptr, X as long, Y as long, W as long, H as long)
fl_push_clip(X,Y,W,H)
' Draw cell bg
fl_color(FL_WHITE): fl_rectf(X,Y,W,H)
' Draw cell data
fl_color(FL_GRAY0): fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER)
' Draw box border
fl_color(color()): fl_rect(X,Y,W,H)
fl_pop_clip()
end sub
private sub MyTable.draw_cell(context as TableContext, ROW as long=0, COL as long=0, X as long=0, Y as long=0, W as long=0, H as long=0)
static s as zstring * 40
select case context
case CONTEXT_STARTPAGE: ' before page is drawn..
fl_font(FL_HELVETICA, 16) ' set the font for our drawing operations
return
case CONTEXT_COL_HEADER: ' Draw column headers
' sprintf(s,"%c",'A'+COL) ' "A", "B", "C", etc.
s=chr(65+COL)
DrawHeader(s,X,Y,W,H)
return
case CONTEXT_ROW_HEADER ' Draw row headers
' sprintf(s,"%03d:",ROW) ' "001:", "002:", etc
s=str(ROW)
DrawHeader(s,X,Y,W,H)
return
case CONTEXT_CELL: ' Draw data in cells
' sprintf(s,"%d",data(ROW,COL))
s=str(data_(ROW,COL))
DrawData(s,X,Y,W,H)
return
case else:
return
end select
end sub
private constructor MyTable(X as long, Y as long, W as long, H as long, L as const zstring ptr=0)
base(X,Y,W,H,L)
' Fill data array
for r as integer=0 to MAX_ROWS
for c as integer=0 to MAX_COLS
data_(r,c) = 1000+(r*1000)+c
next
next
' Rows
rows(MAX_ROWS) ' how many rows
row_header(1) ' enable row headers (along left)
row_height_all(20) ' default height of rows
row_resize(0) ' disable row resizing
' Cols
cols(MAX_COLS) ' how many columns
col_header(1) ' enable column headers (along top)
col_width_all(80) ' default width of columns
col_resize(1) ' enable column resizing
end_() ' end the Fl_Table group
end constructor
private destructor MyTable()
end destructor
end extern
dim win as Fl_Double_Window=Fl_Double_Window (900, 400, "Simple Table")
dim table as MyTable=MyTable(10,10,880,380)
win.end_()
win.resizable(table)
win.show(__FB_ARGC__, __FB_ARGV__)
Fl.run_()
'
' End of "$Id$".
'
Code: Select all
'
' "$Id$"
'
' Fl_Tree as a container of FLTK widgets. - erco 04/15/2012
'
' Copyright 2010,2012 Greg Ercolano.
' Copyright 1998-2010 by Bill Spitzak and others.
'
' This library is free software. Distribution and use rights are outlined in
' the file "COPYING" which should have been included with this file. If this
' file is missing or damaged, see the license at:
'
' http:'www.fltk.org/COPYING.php
'
' Please report all bugs and problems on the following page:
'
' http:'www.fltk.org/str.php
'
#include once "FLTK/Fl.bi"
#include once "FLTK/Fl_Double_Window.bi"
#include once "FLTK/Fl_Tree.bi"
#include once "FLTK/Fl_Group.bi"
#include once "FLTK/Fl_Input.bi"
#include once "FLTK/Fl_Menu_Item.bi"
#define MAX_ROWS 20000
#define MAX_FIELDS 5
#define FIELD_WIDTH 70
#define FIELD_HEIGHT 30
type MyData extends Fl_Group
private:
declare constructor (byref w as const MyData)
declare operator let (byref w as const MyData)
fields(MAX_FIELDS-1) as Fl_Input ptr
public:
declare constructor(X as long, Y as long, W as long, H as long)
declare sub SetData(col as long, val_ as const zstring ptr)
end type
private constructor MyData(X as long, Y as long, W as long, H as long)
base(X,Y,W,H)
static colors(MAX_FIELDS-1) as unsigned long = {&Hffffdd00, &Hffdddd00, &Hddffff00, &Hddffdd00, &Hddddff00}
for t as integer=0 to MAX_FIELDS-1
fields(t) = new Fl_Input(X+t*FIELD_WIDTH,Y,FIELD_WIDTH,H)
fields(t)->color(cast(Fl_Color,colors(t)))
next
end_()
end constructor
private sub MyData.SetData(col as long, val_ as const zstring ptr)
if col >= 0 andalso col < MAX_FIELDS then
fields(col)->value(val_)
end if
end sub
dim win as Fl_Double_Window ptr = new Fl_Double_Window(450, 400, "Tree As FLTK Widget Container")
win->begin()
' Create the tree
dim tree as Fl_Tree ptr = new Fl_Tree(10, 10, win->w()-20, win->h()-20)
tree->showroot(0) ' don't show root of tree
' Add some regular text nodes
tree->add("Foo/Bar/001")
tree->add("Foo/Bar/002")
tree->add("Foo/Bla/Aaa")
tree->add("Foo/Bla/Bbb")
' Add items to the 'Data' node
for t as integer=0 to MAX_ROWS
' Add item to tree
static s as zstring*79
'sprintf(s, "FLTK Widgets/%d", t)
s="FLTK Widgets/"+str(t)
dim item as Fl_Tree_Item ptr = tree->add(s)
' Reconfigure item to be an FLTK widget (MyData)
tree->begin()
dim data_ as MyData ptr = new MyData(0,0,FIELD_WIDTH*MAX_FIELDS, FIELD_HEIGHT)
item->widget(data_)
' Initialize widget data
for c as integer=0 to MAX_FIELDS
'sprintf(s, "%d-%d", t,c);
s=str(t)+"-"+str(c)
data_->SetData(c,s)
next
tree->end_()
next
win->end_()
win->resizable(win)
win->show(__FB_ARGC__, __FB_ARGV__)
Fl.run_()
'
' End of "$Id$".
'
Code: Select all
'
' "$Id$"
'
' How to use Fl_Text_Display with colors. -erco 11/09/2010
' Originally from erco's cheat sheet, permission by author.
'
' Shows how to use the two Fl_Text_Buffer's needed to manage
' the text and style info separately.
'
' For an example of a color text *editor*, see the 'editor'
' example in the test directory.
'
' Copyright 2010 Greg Ercolano.
' Copyright 1998-2010 by Bill Spitzak and others.
'
' This library is free software. Distribution and use rights are outlined in
' the file "COPYING" which should have been included with this file. If this
' file is missing or damaged, see the license at:
'
' http:'www.fltk.org/COPYING.php
'
' Please report all bugs and problems on the following page:
'
' http:'www.fltk.org/str.php
'
#include once "FLTK/Fl.bi"
#include once "FLTK/Fl_Window.bi"
#include once "FLTK/Fl_Text_Display.bi"
' Style table
dim stable(...) as Fl_Text_Display.Style_Table_Entry = {_
_ ' FONT COLOR FONT FACE FONT SIZE
_ ' --------------- ----------- --------------
( FL_RED, FL_COURIER, 18 ),_ ' A - Red
( FL_DARK_YELLOW, FL_COURIER, 18 ),_ ' B - Yellow
( FL_DARK_GREEN, FL_COURIER, 18 ),_ ' C - Green
( FL_BLUE, FL_COURIER, 18 )_ ' D - Blue
}
dim win as Fl_Window ptr = new Fl_Window(640, 480, "Simple Text Display With Colors")
dim disp as Fl_Text_Display ptr = new Fl_Text_Display(20, 20, 640-40, 480-40)
dim tbuff as Fl_Text_Buffer ptr = new Fl_Text_Buffer() ' text buffer
dim sbuff as Fl_Text_Buffer ptr = new Fl_Text_Buffer() ' style buffer
disp->buffer(tbuff)
dim stable_size as long= ubound(stable)+1'len(stable)/len(stable(0)) ' # entries in style table (4)
disp->highlight_data(sbuff, @stable(0), stable_size, asc("A"), 0, 0)
' Text
tbuff->text(!"Red Line 1\nYel Line 2\nGrn Line 3\nBlu Line 4\nRed Line 5\nYel Line 6\nGrn Line 7\nBlu Line 8\n")
' Style for text
sbuff->text(!"AAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\nAAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\n")
win->resizable(*disp)
win->show()
Fl.run_()
'
' End of "$Id$".
'