Hi Charles,
may I ask for your help?
The basic principle of the Iup toolkit is rather simple: create a dialog with some controls, add some attributes to the controls and create some callbacks in cdecl for the events. Although I have managed to run many of the Iup test cases with OxygenBasic I am not sure if I could do some things better.
For setting the attributes I use IupSetStrAttribute (old IupStoreAttribute) because IupSetAttribute does not always work correctly. The declarations is:
iup.h:
void IupSetAttribute (Ihandle* ih, const char* name, const char* value);
void IupSetStrAttribute(Ihandle* ih, const char* name, const char* value);
void IupStoreAttribute(Ihandle* ih, const char* name, const char* value); ' old form
in iup.inc I used:
! IupSetAttribute (sys ih, string name, string value)
! IupSetStrAttribute (sys ih, string name, string value)
! IupStoreAttribute (sys ih, string name, string value) ' old form
Although the arguments for IupSetAttribute and IupSetStrAttribute seem to be of the same type there must be a difference. The help file indicates:
IupSetAttribute can store only constant strings (like "Title", "30", etc) or application pointers.
IupSetStrAttribute (old IupStoreAttribute) can only store strings. The given string value will be duplicated internally.
I managed to do a lot with IupSetStrAttribute (old IupStoreAttribute) but it would be nice if I could get IupSetAttribute to work too. I suppose that some other functions should be adapted also because they internally call IupSetAttribute. Should I use a different type for IupSetAttribute? Maybe I can create a helper function like this?
! IupSetAttribute_ alias "IupSetAttribute" (sys ih, string name, string(?) value)
sub IupSetAttribute(...
what to do?
end sub
This is a small example (intended to run in the folder OxygenBasic\ProjectB\Iup) which shows the difference:
include "$/inc/console.inc"
typedef sys Icallback
includepath "iup\"
extern lib "IUP/iup.dll" cdecl
#define IUP_DEFAULT -2
#define IUP_CENTER 0xFFFF /* 65535 */
! IupOpen (sys argc,argv) as int
! IupClose ()
! IupMainLoop () as int
! IupShowXY (sys ih, int x, int y) as int
! IupSetAttribute (sys ih, string name, string value)
! IupStoreAttribute(sys ih, string name, string value)
! IupSetFunction(string name, Icallback func) as Icallback
! IupSetCallback (sys ih, string name, Icallback func) as Icallback
! IupCanvas (string action) as sys
! IupDialog (sys child) as sys
end extern
extern cdecl
static int idle_count = 0
function idle()
print "IDLE_ACTION( count = " idle_count ")" & cr
idle_count++
// if (idle_count == 10000)
// return IUP_IGNORE
return IUP_DEFAULT
end function
function motion_cb(sys ih) as int callback
print "MOTION_CB()" & cr
if (idle_count > 15000) then
IupSetFunction ("IDLE_ACTION", NULL)
end if
return IUP_DEFAULT
end function
sub IdleTest()
sys dlg, canvas
canvas = IupCanvas(NULL)
IupSetCallback(canvas, "MOTION_CB", @motion_cb)
dlg = IupDialog(canvas)
IupSetAttribute(dlg, "TITLE", "Idle Test")
IupSetAttribute(dlg, "RASTERSIZE", "500x500")
' IupStoreAttribute(dlg, "TITLE", "Idle Test")
' IupStoreAttribute(dlg, "RASTERSIZE", "500x500")
IupShowXY(dlg, IUP_CENTER, IUP_CENTER)
IupSetFunction ("IDLE_ACTION", @idle)
end sub
sub main()
IupOpen(0,0)
IdleTest()
IupMainLoop()
IupClose()
end sub
main()
With IupSetAttribute the title of the dialog shows "RASTERSIZE" wich should be "Idle Test". But how should I construct and use IupSetAttribute with a pointer to "value"?
Roland