There were several errors in my code. Now it's working.
One point I don't understand, in the code below :
- the value of x for the first menu button is 0 and no problem the menu is displayed when right clicking.
- For the second menu button, defined in the sub, the x value must be set at 310 otherwise nothing happens.
That's strange.
Code: Select all
#include once "fltk-c.bi"
' test of: Fl_TabsEnd, Fl_TabNew and Fl_TabEnd
' this are macros defined in fltk-c.bi
Sub TreeCB cdecl (byval wgt as Fl_Widget ptr,byval tree as any ptr)
dim as Fl_Tree_Item ptr item = Fl_TreeGetCallbackItem(tree)
if (item=0) then exit sub
print *Fl_Tree_ItemGetLabel(item);
select case Fl_TreeGetCallbackReason(tree)
case FL_TREE_REASON_SELECTED
print " selected"
case FL_TREE_REASON_DESELECTED
print " deselected"
case FL_TREE_REASON_OPENED
print " opened"
case FL_TREE_REASON_CLOSED
print " closed"
case else
print "?"
end select
end sub
sub TestCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr)
dim as Fl_Menu_ ptr mnu = cptr(Fl_Menu_ ptr,self)
dim as Fl_Menu_Item ptr mi = cptr(any ptr,Fl_Menu_MValue(mnu))
if (mi=0) then
print ("NULL")
elseif Fl_Menu_ItemGetShortcut(mi) then
print *Fl_Menu_ItemGetLabel(mi), *Fl_GetShortcutLabel(Fl_Menu_ItemGetShortcut(mi))
else
print *Fl_Menu_ItemGetLabel(mi)
end if
end sub
'
' main
'
Dim Shared As Fl_Menu_Item menuitems(...) => _
{(@"Red" ,FL_ALT+asc("r")), _
(@"Green" ,FL_ALT+asc("g")), _
(@"Blue" ,FL_ALT+asc("b")), _
(@"Strange",FL_ALT+asc("s"),0,0,FL_MENU_INACTIVE), _
(@"&Charm" ,FL_ALT+asc("c")), _
(@"Truth" ,FL_ALT+asc("t")), _
(@"Beauty" ,FL_ALT+asc("b")), _
(0)}
dim As Fl_Menu_Item menuitems2(...) => _
{(@"ONE" ,FL_ALT+asc("r")), _
(@"TWO" ,FL_ALT+asc("g")), _
(@"THREE" ,FL_ALT+asc("b")), _
(@"FOUR",FL_ALT+asc("s"),0,0,FL_MENU_INACTIVE), _
(0)}
sub TabCB cdecl (byval tabs as FL_WIDGET ptr,byval parent as any ptr)
print "TabCB: " & *Fl_WidgetGetLabel(Fl_TabsGetValue(parent))
end sub
sub ButtonCB cdecl (byval btn as FL_WIDGET ptr)
print "ButtonCB: " & *Fl_WidgetGetLabel(btn)
end sub
Sub create_menu(ByRef mb As fl_menu_button Ptr,tb As fl_group Ptr,w As Long,h As Long)
Fl_GroupBegin(tb)
mb= Fl_Menu_ButtonNew(310,0,w,900,"&popup")'310
Fl_WidgetSetType mb,POPUP3
Fl_WidgetSetBox mb,FL_NO_BOX
Fl_Menu_SetMenu mb,@menuitems(0)
Fl_WidgetSetCallback mb,@TestCB
'fl_groupadd(tb,mb)
fl_groupend(tb)
End Sub
dim as Fl_Window ptr win = Fl_WindowNew(600,200, "Fl_Tree01.bas")
dim as fl_tabs ptr tabs=fl_tabsnew(310,10,300,170)
Fl_WidgetSetCallbackArg tabs,@TabCB,tabs
var tab1 = Fl_TabNew(310,35,500-20,200-45,"Tab 1")
Fl_WidgetSetCallback0 Fl_ButtonNew(350,60,90,25,"Button A"),@ButtonCB
Fl_WidgetSetCallback0 Fl_ButtonNew(350,90,90,25,"Button B"),@ButtonCB
dim as FL_MENU_BUTTON ptr mb2 = Fl_Menu_ButtonNew(0,0,Fl_WidgetGetW(tab1),Fl_WidgetGetH(tab1),"&popup")
Fl_WidgetSetType mb2,POPUP3
Fl_WidgetSetBox mb2,FL_NO_BOX
Fl_Menu_SetMenu mb2,@menuitems2(0)
Fl_WidgetSetCallback mb2,@TestCB
Fl_TabEnd tab1
Fl_WindowEnd(win)
'Fl_Windowbegin(win)
Var tab2 = Fl_TabNew(310,35,500-20,200-45,"Tab 2")
dim as Fl_Tree ptr tree = Fl_TreeNew(310,50,300,170,"Fl_Tree")
Fl_TreeBegin tree
Fl_TreeSetShowRoot(tree,0) ' don't show root of tree
Fl_TreeAdd(tree,"Flintstones/Fred") ' add some items
Fl_TreeAdd(tree,"Flintstones/Wilma")
Fl_TreeAdd(tree,"Flintstones/Pebbles")
Fl_TreeAdd(tree,"Simpsons/Homer")
Fl_TreeAdd(tree,"Simpsons/Marge")
Fl_TreeAdd(tree,"Simpsons/Bart")
Fl_TreeAdd(tree,"Simpsons/Lisa")
Fl_TreeClose(tree,"Simpsons") ' Start with one item closed
Fl_WidgetSetCallbackArg(tree,@TreeCB,tree) ' setup a callback for the treeview
Fl_TreeEnd tree
Fl_TabEnd tab2
dim as FL_MENU_BUTTON ptr mb '= Fl_Menu_ButtonNew(0,0,Fl_WidgetGetW(tree),Fl_WidgetGetH(tree),"&popup")
create_menu(mb,tab2,Fl_WidgetGetW(tree),Fl_WidgetGetH(tree))
fl_groupadd(tabs,tab2)
'Fl_WindowEnd(win)
Fl_GroupSetResizable(win,win)
Fl_WindowShow win
Fl_Run
Also I don't know why but it seems that this sub reacts very slowly even when not changing the tab. The aim is just to highlight a given line.
Code: Select all
Sub dsp_line(newtab As Long =curtab,newline As Long=curline)
Dim As Fl_Text_Buffer Ptr curbuftxt=Fl_Text_DisplayGetBuffer(curdsptxt)
Dim As integer ps,ps2
Dim txt As zstring Ptr
Fl_Text_BufferUnhighlight(curbuftxt)
If shwtab<>newtab Then
shwtab=newtab:Fl_Text_DisplaySetBuffer(curdsptxt,TextBuffer(shwtab)):curbuftxt=Fl_Text_DisplayGetBuffer(curdsptxt)
Fl_TabsSetValue(Cast(fl_tabs Ptr,Fl_WidgetGetParent(tabx(shwtab))),tabx(shwtab))
Fl_Widgetredraw(Fl_WidgetGetParent(tabx(0)))
fl_widgetredraw(Fl_WidgetGetParent(Fl_WidgetGetParent(tabx(0))))
fl_widgetredraw(Fl_WidgetGetParent(Fl_WidgetGetParent(Fl_WidgetGetParent(tabx(0)))))
EndIf
ps=Fl_Text_BufferSkipLines(curbuftxt,0,newline-1)
ps2=Fl_Text_BufferLineEnd(curbuftxt,ps)1
Fl_Text_BufferSetHighlight(curbuftxt,ps,ps2)
fl_widgetsetlabel(hcurline,Fl_Text_BufferHighlightText(curbuftxt))
Fl_Text_DisplayScroll(curdsptxt,newline-3,0)
End Sub