scintilla editing component/widget (new iup widget)

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

scintilla editing component/widget (new iup widget)

Post by AGS »

A while ago there was a message on the iup site that scintilla would be added to iup
in the nearby future. This would give iup users access to a popular editing component
that comes with things like folding, syntax colouring, regular expression matching etc... etc....

The nearby future is... now :) This example is an almost exact replica of the C demo
written by the iup developer. It shows you how to create a scintilla control, select a lexer
(responsible for the all important folding and other syntax related things), change syntax colouring
and how to add some text to the control. Scintilla comes with a freebasic lexer but the visual
basic lexer included with scintilla seems to do a better job at folding/colourizing fb code.

I have chosen some wonderful colours for you to enjoy (liven up the demo a bit). I used
--> green (comments)
--> pink (operators)
--> turquoise(keywords1)
--> lime green (keywords2)
--> purple (strings)

A picture to illustrate
Image
Colours can be changed easily (colors are set using the standard rgb notation).

For more info on using iup scintilla: http://www.tecgraf.puc-rio.br/iup/
Info on scintilla can be found at the scintilla site http://www.scintilla.org/

To compile/run the example you need the iup binaries. You can get those from sourceforge.net
http://sourceforge.net/projects/iup/fil ... s/Dynamic/

Choose the file called iup-3.8_win32_dll8_lib.zip

You will also need the msvcr80.dll runtime library for the demo to work (it's an iup dependency).
That should be sitting on the hdd of your pc somewhere (if not in syswow64 then somewhere
else). If you cannot find msvcr80.dll then you can download a package that contains it from
http://www.sarmardar.nl/FreeBASIC/iup_dll.zip.

Be sure NOT to use any of the other files in the zip file (iup-3.8_win32_dll8_lib.zip contains
everything you need except for msvcr80.dll).

Linux users could try and download binaries for their distro from
http://sourceforge.net/projects/iup/fil ... Libraries/

I do not think the example will compile/run on linux but perhaps I am being
overly negative here (on linux iup acts as a 'wrapper' around gtk2.x. gtk2.x
works well on linux so there should be no reason for the demo not to work on linux).

You do not need import libraries on either windows or linux as I have used
DyLibLoad, DyLibSymbol and DyLibFree (the dynamic link libraries ((the ones
ending with .dll (win) or .so (lin)) are all you need).

Code: Select all

#include "crt/stdlib.bi"
#include "crt/stdio.bi"
#include "crt/string.bi"

#ifndef NIL
#define NIL cast(any ptr,0)
#endif

#define IUP_IGNORE    -1
#define IUP_DEFAULT   -2
#define IUP_CLOSE     -3
#define IUP_CONTINUE  -4


type Ihandle as any
type Icallback as function cdecl (byval as Ihandle ptr) as integer

  dim shared IupOpen as function cdecl (byval as integer ptr, byval as zstring ptr ptr ptr) as integer
  dim shared IupSetCallback as function cdecl (byval as ihandle ptr, byval as zstring ptr, byval as icallback) as icallback
  dim shared IupMainLoop as sub cdecl ()
  dim shared IupClose as sub cdecl ()
  dim shared IupGetAttributeId as function cdecl (byval as Ihandle ptr, byval as zstring ptr, byval as integer) as zstring ptr
  dim shared IupGetAttribute  as function cdecl (byval as Ihandle ptr, byval as zstring ptr) as zstring ptr
  dim shared IupSetAttribute  as sub cdecl (byval as Ihandle ptr, byval as zstring ptr, byval as zstring ptr)
  dim shared IupSetfAttribute as sub cdecl (byval as Ihandle ptr, byval as zstring ptr, byval as zstring ptr, ...)
  dim shared IupShow as function cdecl (byval as Ihandle ptr) as integer
  dim shared IupScintillaOpen as sub cdecl ()
  dim shared IupScintilla as function cdecl () as Ihandle ptr
  dim shared IupDialog  as function cdecl (byval as Ihandle ptr) as ihandle ptr
  dim shared IupVbox as function cdecl (byval as Ihandle ptr, ...) as ihandle ptr
  
dim shared sampleCode as string * 1708 = _
!"enum FB_TKCLASS\n" +_
!"  FB_TKCLASS_IDENTIFIER\n" +_
!"  FB_TKCLASS_KEYWORD\n" +_
!"  FB_TKCLASS_QUIRKWD\n" +_
!"  FB_TKCLASS_NUMLITERAL\n" +_
!"  FB_TKCLASS_STRLITERAL\n" +_
!"  FB_TKCLASS_OPERATOR\n" +_
!"  FB_TKCLASS_DELIMITER\n" +_
!"  FB_TKCLASS_UNKNOWN\n" +_
!"end enum\n" +_
!"\n" +_
!"\'\':::::\n" +_
!"sub symbSetDefType _\n" +_
!"  ( _\n" +_
!"  byval ichar as integer, _\n" +_
!"  byval echar as integer, _\n" +_
!"  byval dtype as integer _\n" +_
!"  )\n" +_
!"\n" +_
!"    dim as integer i = any\n" +_
!"\n" +_
!"  if( ichar < asc(\"A\") ) then\n" +_
!"    ichar = asc(\"A\")\n" +_
!"  elseif( ichar > asc(\"_\") ) then\n" +_
!"    ichar = asc(\"_\")\n" +_
!"  end if\n" +_
!"\n" +_
!"  if( echar < asc(\"A\") ) then\n" +_
!"    echar = asc(\"A\")\n" +_
!"  elseif( echar > asc(\"_\") ) then\n" +_
!"    echar = asc(\"_\")\n" +_
!"  end if\n" +_
!"\n" +_
!"  if( ichar > echar ) then\n" +_
!"    swap ichar, echar\n" +_
!"  end if\n" +_
!"\n" +_
!"  for i = ichar to echar\n" +_
!"    deftypeTB(i - asc(\"A\")) = dtype\n" +_
!"  next\n" +_
!"\n" +_
!"end sub\n" +_
!"\n" +_
!"\'\' Recalculate the length, to be used after the symbol's type was set/changed\n" +_
!"sub symbRecalcLen( byval sym as FBSYMBOL ptr )\n" +_
!"  if( sym->class = FB_SYMBCLASS_PARAM ) then\n" +_
!"    sym->lgt = symbCalcParamLen( sym->typ, sym->subtype, sym->param.mode )\n" +_
!"  else\n" +_
!"    sym->lgt = symbCalcLen( sym->typ, sym->subtype )\n" +_
!"  end if\n" +_
!"end sub\n" +_
!"\n" +_
!"dim shared s as string\n" +_
!"s = \"hello world\"\n" +_
!"type simple_type\n" +_
!"  dim field1 as integer\n" +_
!"  dim field2 as integer\n" +_
!"end type\n"


function marginclick_cb cdecl(byval self as Ihandle ptr, byval margin as integer, byval line_ as integer, byval status as zstring ptr) as integer

  printf(!"MARGINCLICK_CB(Margin: %d, Line: %d, Status:%s)\n", margin, line_, status)

  printf(!"Fold Level = %s\n", IupGetAttributeId(self, "FOLDLEVEL", line_))
  IupSetfAttribute(self, "FOLDTOGGLE", "%d", line_)

  return IUP_DEFAULT
end function

function hotspotclick_cb cdecl(byval self as Ihandle ptr, byval pos_ as integer, byval line_ as integer, byval col as integer, byval status as zstring ptr) as integer

  dim text as zstring ptr = IupGetAttributeId(self, "LINE", line_)

  printf(!"HOTSPOTCLICK_CB (Pos: %d, Line: %d, Col: %d, Status:%s)\n", pos_, line_, col, status)
  printf(!"    line text = %s\n", text)

  return IUP_DEFAULT
end function

function button_cb cdecl(byval self as Ihandle ptr, byval button as integer, byval pressed as integer, byval x as integer, byval y as integer, byval status as zstring ptr) as integer

  printf(!"BUTTON_CB = button: %d, pressed: %d, x: %d, y: %d, status: %s\n", button, pressed, x, y, status)
  return IUP_DEFAULT
end function

function motion_cb cdecl(byval self as Ihandle ptr, byval x as integer, byval y as integer, byval status as zstring ptr) as integer

  printf(!"MOTION_CB = x: %d, y: %d, status: %s\n", x, y, status)

  return IUP_DEFAULT
end function

function caret_cb cdecl (byval self as Ihandle ptr, byval lin as integer, byval col as integer, byval pos_ as integer) as integer

  printf(!"CARET_CB = lin: %d, col: %d, pos_: %d\n", lin, col, pos_)
  return IUP_DEFAULT
end function

function valuechanged_cb cdecl(byval self as Ihandle ptr) as integer

  printf(!"VALUECHANGED_CB\n")
  return IUP_DEFAULT
end function

function action_cb cdecl (byval self as Ihandle ptr, byval insert as integer, byval pos_ as integer, byval length as integer, byval text as zstring ptr) as integer

  printf(!"ACTION = insert: %d, pos_: %d, lenght:%d, text: %s\n", insert, pos_, length, text)
  return IUP_IGNORE

end function

sub set_attribs (byval sci as Ihandle ptr)

  IupSetAttribute(sci, "CLEARALL", "")
  IupSetAttribute(sci, "LEXERLANGUAGE", "vb")

  IupSetAttribute(sci, "KEYWORDS1", "sub function declare dim end type union as ptr enum "_
"if elseif then select case default break goto return for while do continue sizeof typeof new delete property namespace operator this cast using andalso orelse xor or and not cdecl byval byref ")
  IupSetAttribute(sci,"KEYWORDS2","integer long ulong ulongint longint string zstring wstring short ushort ubyte double single unsigned signed")
  IupSetAttribute(sci, "STYLEFONT32", "Consolas")
  IupSetAttribute(sci, "STYLEFONTSIZE32", "11")

  IupSetAttribute(sci, "STYLECLEARALL", "Yes")  /' sets all styles to have the same attributes as 32 '/

  IupSetAttribute(sci, "STYLEFGCOLOR1", "0 128 0")      '' 1-BASIC comment 
  IupSetAttribute(sci, "STYLEFGCOLOR2", "0 128 0")      '' 2-BASIC comment line 
  IupSetAttribute(sci, "STYLEFGCOLOR4", "139 0 139")    '' 4-String
  IupSetAttribute(sci, "STYLEFGCOLOR5", "0 128 128")     '' 
  IupSetAttribute(sci, "STYLEFGCOLOR6", "255 20 147")    ''6-Operators
  IupSetAttribute(sci, "STYLEFGCOLOR7", "0 0 0")          '' 7-Character 
  IupSetAttribute(sci, "STYLEFGCOLOR9", "205 149 12")     '' 9-Preprocessor block 
  IupSetAttribute(sci, "STYLEFGCOLOR10", "0 197 205")       '' 10-Keywords1
  IupSetAttribute(sci, "STYLEFGCOLOR11", "0 255 0")    '' 11-Keywords2

  IupSetAttribute(sci, "STYLEBOLD10", "YES")

  IupSetAttribute(sci, "STYLEHOTSPOT4", "YES")
  IupSetAttribute(sci, "STYLEHOTSPOT11", "YES")
  
  IupSetAttribute(sci, "INSERT0", sampleCode)

  IupSetAttribute(sci, "MARGINWIDTH0", "50")

  if (1) then  
    IupSetAttribute(sci, "PROPERTY", "fold=1")
    IupSetAttribute(sci, "PROPERTY", "fold.compact=0")
    IupSetAttribute(sci, "PROPERTY", "fold.comment=1")
    IupSetAttribute(sci, "PROPERTY", "fold.preprocessor=1")

    IupSetAttribute(sci, "MARGINWIDTH1", "20")
    IupSetAttribute(sci, "MARGINTYPE1",  "SYMBOL")
    IupSetAttribute(sci, "MARGINMASKFOLDERS1",  "Yes")

    IupSetAttribute(sci, "MARKERDEFINE", "FOLDER=PLUS")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDEROPEN=MINUS")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDEREND=EMPTY")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDERMIDTAIL=EMPTY")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDEROPENMID=EMPTY")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDERSUB=EMPTY")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDERTAIL=EMPTY")
    IupSetAttribute(sci, "FOLDFLAGS", "LINEAFTER_CONTRACTED")
    IupSetAttribute(sci, "MARGINSENSITIVE1", "YES")
  end if

  printf(!"Number of chars in this text: %s\n", IupGetAttribute(sci, "COUNT"))
  printf(!"Number of lines in this text: %s\n", IupGetAttribute(sci, "LINECOUNT"))
  printf(!"%s\n", IupGetAttribute(sci, "LINEVALUE"))
end sub

sub ScintillaTest()

  dim as Ihandle ptr dlg
  dim as Ihandle ptr sci

  IupScintillaOpen()     

  '' Creates an instance of the Scintilla control
  sci = IupScintilla()
''  IupSetAttribute(sci, "VISIBLECOLUMNS", "80")
''  IupSetAttribute(sci, "VISIBLELINES", "40")
  ''IupSetAttribute(sci, "SCROLLBAR", "NO")
''  IupSetAttribute(sci, "BORDER", "NO")
  IupSetAttribute(sci, "EXPAND", "Yes")

  IupSetCallback(sci, "MARGINCLICK_CB", cast(icallback,@marginclick_cb))
  IupSetCallback(sci, "HOTSPOTCLICK_CB", cast(icallback,@hotspotclick_cb))
''  IupSetCallback(sci, "BUTTON_CB", @button_cb)
''  IupSetCallback(sci, "MOTION_CB", @motion_cb)
  IupSetCallback(sci, "CARET_CB", cast(icallback,@caret_cb))
  IupSetCallback(sci, "VALUECHANGED_CB", cast(icallback,@valuechanged_cb))
  IupSetCallback(sci, "ACTION", cast(icallback,@action_cb))

  '' Creates a dialog containing the control
  dlg = IupDialog(IupVbox(sci, NIL))
  IupSetAttribute(dlg, "TITLE", "IupScintilla")
  IupSetAttribute(dlg, "RASTERSIZE", "700x500")
  IupSetAttribute(dlg, "MARGIN", "10x10")

  '' Shows dialog
  IupShow(dlg)
  IupSetAttribute(dlg, "RASTERSIZE", NIL)
  set_attribs(sci)
end sub

sub mymain()

  ''first set up the two dynamic link libraries
  var iup = DyLibLoad("iup.dll")
  if (iup = NIL) then
    print "error loading iup"
    return
  end if
  var scintilla = DyLibLoad("iup_scintilla.dll")
  if (scintilla = NIL) then
    print "error loading scintilla"
    dylibfree(iup)
    return
  end if
  
  IupOpen = DyLibSymbol(iup,"IupOpen")
  IupSetCallback = DyLibSymbol(iup,"IupSetCallback")
  IupMainLoop = DyLibSymbol(iup,"IupMainLoop")
  IupClose = DyLibSymbol(iup,"IupClose")
  IupSetAttribute = DyLibSymbol(iup,"IupSetAttribute")
  IupShow = DyLibSymbol(iup,"IupShow")
  IupScintilla = DyLibSymbol(scintilla,"IupScintilla")
  IupScintillaOpen = DyLibSymbol(scintilla,"IupScintillaOpen")
  IupSetCallback = DyLibSymbol(iup,"IupSetCallback")
  IupSetfAttribute = DyLibSymbol(iup,"IupSetfAttribute")
  IupDialog = DyLibSymbol(iup,"IupDialog")
  IupGetAttributeId = DyLibSymbol(iup,"IupGetAttributeId")
  IupGetAttribute = DyLibSymbol(iup,"IupGetAttribute")
  IupVbox = DyLibSymbol(iup,"IupVbox")
  IupOpen(NIL,NIL)

  ScintillaTest()

  IupMainLoop()

  IupClose()
  DyLibFree(iup)
  DyLibFree(scintilla)
  return

end sub

mymain()
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: scintilla editing component/widget (new iup widget)

Post by sancho2 »

Hello:
This is an old thread but hopefully someone will know the answer.

On the following line I am getting a procedure entry point error:

Code: Select all

var scintilla = DyLibLoad("iup_scintilla.dll")
procedure entry point __gxx_personality_V0 could not be located in the dynamic link library libstdc++6.dll

I also don't understand what you mean when you say do not use any of the other files.
Which files do I need?

Thanks
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: scintilla editing component/widget (new iup widget)

Post by nimdays »

Maybe this can help
Download iup-3.14-Lua51_Win32_bin.zip from : http://sourceforge.net/projects/iup/
And then copy these files (only 4) to your app folder :

Code: Select all

iup.dll
iup_scintilla.dll
msvcp100.dll
msvcr100.dll
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: scintilla editing component/widget (new iup widget)

Post by sancho2 »

Thanks very much Nimdays. That worked.
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: scintilla editing component/widget (new iup widget)

Post by sancho2 »

The code presented here by AGS is excellent for demonstrating this widget. It made it easy for step 2, creating a menu. I present that here.
(Explanation of additions first and complete code at end of post)
We need to add a few more Iup declarations:

Code: Select all

' these are the functions we add to create the menu
  Dim Shared IupItem As Function Cdecl (ByVal As ZString Ptr, ByVal As ZString Ptr) As Ihandle Ptr
  Dim Shared IupMenu As Function Cdecl (ByVal As Ihandle Ptr, ...) As Ihandle Ptr
  Dim Shared IupSubMenu As Function Cdecl (ByVal As ZString Ptr, ByVal As Ihandle Ptr) As Ihandle Ptr
  Dim Shared IupSeparator As Function Cdecl () As Ihandle Ptr
  Dim Shared IupSetHandle As function Cdecl (ByVal As ZString Ptr, ByVal As Ihandle Ptr) As Ihandle ptr
  
We get the function addresses from the dll using DyLibSymbol():

Code: Select all

  IupItem = DylibSymbol(iup, "IupItem")
  IupMenu = DylibSymbol(iup, "IupMenu")
  IupSubMenu = DylibSymbol(iup, "IupSubmenu")
  IupSeparator = DylibSymbol(iup, "IupSeparator")
  IupSetHandle = DylibSymbol(iup, "IupSetHandle")
And now we build the menu:

Code: Select all

' set up the menu title items
  itm_File = IupItem("File", "TITLE")
  IupSetAttribute(itm_File, "KEY", "f")
  
	' the & will display an underscore under the letter  
  itm_New = IupItem("&New", "TITLE")	
  IupSetAttribute(itm_New, "KEY", "n")

  itm_Open = IupItem("&Open", "TITLE")
  IupSetAttribute(itm_Open, "KEY", "o")
  
  itm_Save = IupItem("&Save", "TITLE")
  IupSetAttribute(itm_Save, "KEY", "s")
  IupSetAttribute(itm_Save, "ACTIVE", "NO")	' set the item as not active (disabled)
 
  itm_SaveAs = IupItem("Save&As", "TITLE")
  IupSetAttribute(itm_SaveAs, "KEY", "a")
  IupSetAttribute(itm_SaveAs, "ACTIVE", "NO")  
  
  itm_Close = IupItem("Close", "TITLE")
  IupSetAttribute(itm_Close, "KEY", "c")
  IupSetAttribute(itm_Close, "ACTIVE", "NO")
  
  ' Oddly, the exit command comes built in with an underscored 'x' and
  ' adding the & will display the &. If you select Exi&t, it will work
  ' as expected and show an underscored t.
  itm_Exit = IupItem("Exit", "TITLE")
  IupSetAttribute(itm_Exit, "KEY", "x")


  ' Here we create an entire menu ptr containing all the items we just created. 
  ' We use the function IupSeparator() to create our separator lines so that
  ' we don't have to create a ptr variable for each separator line. 
  file_Menu = IupMenu(itm_New, _
  							 itm_Open, _
  							 IupSeparator(), _
  							 itm_Save, _
  							 itm_SaveAs, _
  							 IupSeparator(), _
  							 itm_Close, _
  							 IupSeparator(), _
  							 itm_Exit, NIL)	' set up a menu consisting of the file menu contents 
  
  ' this creates a menu that when selected opens another menu 
  ' ie click on "File" to reveal submenu "Open" etc
  subMenu = IupSubMenu("File", file_Menu)	' File is the title, file_menu is the ptr to a menu
  
  mnu = IupMenu(subMenu, NIL)		'create a ptr to the complete menu
  
  ' Applying the menu (mnu) directly to the dialog (dlg) didn't seem to work.
  ' I found a confusing explanation as to why but its enought to know that you
  ' can assign a name to the interface element (mnu) and assign that to the dialog (dlg)
  IupSetHandle("mymenu", mnu)

  '' Creates a dialog containing the control
  dlg = IupDialog(IupVbox(sci, NIL))
  IupSetAttribute(dlg, "TITLE", "IupScintilla")
  IupSetAttribute(dlg, "RASTERSIZE", "700x500")
  IupSetAttribute(dlg, "MARGIN", "10x10")

  IupSetAttribute(dlg, "MENU", "mymenu")	' assign the menu name to the dialog

Here is the AGS code with the menu added:

Code: Select all

#include "crt/stdlib.bi"
#include "crt/stdio.bi"
#include "crt/string.bi"

#ifndef NIL
#define NIL cast(any ptr,0)
#endif

#define IUP_IGNORE    -1
#define IUP_DEFAULT   -2
#define IUP_CLOSE     -3
#define IUP_CONTINUE  -4


type Ihandle as any
type Icallback as function cdecl (byval as Ihandle ptr) as integer

  dim shared IupOpen as function cdecl (byval as integer ptr, byval as zstring ptr ptr ptr) as integer
  dim shared IupSetCallback as function cdecl (byval as ihandle ptr, byval as zstring ptr, byval as icallback) as icallback
  dim shared IupMainLoop as sub cdecl ()
  dim shared IupClose as sub cdecl ()
  dim shared IupGetAttributeId as function cdecl (byval as Ihandle ptr, byval as zstring ptr, byval as integer) as zstring ptr
  dim shared IupGetAttribute  as function cdecl (byval as Ihandle ptr, byval as zstring ptr) as zstring ptr
  dim shared IupSetAttribute  as sub cdecl (byval as Ihandle ptr, byval as zstring ptr, byval as zstring ptr)
  dim shared IupSetfAttribute as sub cdecl (byval as Ihandle ptr, byval as zstring ptr, byval as zstring ptr, ...)
  dim shared IupShow as function cdecl (byval as Ihandle ptr) as integer
  dim shared IupScintillaOpen as sub cdecl ()
  dim shared IupScintilla as function cdecl () as Ihandle ptr
  dim shared IupDialog  as function cdecl (byval as Ihandle ptr) as ihandle Ptr
  
	' these are the functions we add to create the menu
  Dim Shared IupItem As Function Cdecl (ByVal As ZString Ptr, ByVal As ZString Ptr) As Ihandle Ptr
  Dim Shared IupMenu As Function Cdecl (ByVal As Ihandle Ptr, ...) As Ihandle Ptr
  Dim Shared IupSubMenu As Function Cdecl (ByVal As ZString Ptr, ByVal As Ihandle Ptr) As Ihandle Ptr
  Dim Shared IupSeparator As Function Cdecl () As Ihandle Ptr
  Dim Shared IupSetHandle As function Cdecl (ByVal As ZString Ptr, ByVal As Ihandle Ptr) As Ihandle ptr
  
  ' We dont use this one yet. But later might need it.
  Dim Shared IupSetAttributeHandle As Sub Cdecl (ByVal As ihandle Ptr, ByVal As ZString Ptr, ByVal As Ihandle Ptr) 
  
  dim Shared IupVbox as function cdecl (byval as Ihandle ptr, ...) as ihandle ptr
 
dim shared sampleCode as string * 1708 = _
!"enum FB_TKCLASS\n" +_
!"  FB_TKCLASS_IDENTIFIER\n" +_
!"  FB_TKCLASS_KEYWORD\n" +_
!"  FB_TKCLASS_QUIRKWD\n" +_
!"  FB_TKCLASS_NUMLITERAL\n" +_
!"  FB_TKCLASS_STRLITERAL\n" +_
!"  FB_TKCLASS_OPERATOR\n" +_
!"  FB_TKCLASS_DELIMITER\n" +_
!"  FB_TKCLASS_UNKNOWN\n" +_
!"end enum\n" +_
!"\n" +_
!"\'\':::::\n" +_
!"sub symbSetDefType _\n" +_
!"  ( _\n" +_
!"  byval ichar as integer, _\n" +_
!"  byval echar as integer, _\n" +_
!"  byval dtype as integer _\n" +_
!"  )\n" +_
!"\n" +_
!"    dim as integer i = any\n" +_
!"\n" +_
!"  if( ichar < asc(\"A\") ) then\n" +_
!"    ichar = asc(\"A\")\n" +_
!"  elseif( ichar > asc(\"_\") ) then\n" +_
!"    ichar = asc(\"_\")\n" +_
!"  end if\n" +_
!"\n" +_
!"  if( echar < asc(\"A\") ) then\n" +_
!"    echar = asc(\"A\")\n" +_
!"  elseif( echar > asc(\"_\") ) then\n" +_
!"    echar = asc(\"_\")\n" +_
!"  end if\n" +_
!"\n" +_
!"  if( ichar > echar ) then\n" +_
!"    swap ichar, echar\n" +_
!"  end if\n" +_
!"\n" +_
!"  for i = ichar to echar\n" +_
!"    deftypeTB(i - asc(\"A\")) = dtype\n" +_
!"  next\n" +_
!"\n" +_
!"end sub\n" +_
!"\n" +_
!"\'\' Recalculate the length, to be used after the symbol's type was set/changed\n" +_
!"sub symbRecalcLen( byval sym as FBSYMBOL ptr )\n" +_
!"  if( sym->class = FB_SYMBCLASS_PARAM ) then\n" +_
!"    sym->lgt = symbCalcParamLen( sym->typ, sym->subtype, sym->param.mode )\n" +_
!"  else\n" +_
!"    sym->lgt = symbCalcLen( sym->typ, sym->subtype )\n" +_
!"  end if\n" +_
!"end sub\n" +_
!"\n" +_
!"dim shared s as string\n" +_
!"s = \"hello world\"\n" +_
!"type simple_type\n" +_
!"  dim field1 as integer\n" +_
!"  dim field2 as integer\n" +_
!"end type\n"


function marginclick_cb cdecl(byval self as Ihandle ptr, byval margin as integer, byval line_ as integer, byval status as zstring ptr) as integer

  Print "hello"
  printf(!"MARGINCLICK_CB(Margin: %d, Line: %d, Status:%s)\n", margin, line_, status)

  printf(!"Fold Level = %s\n", IupGetAttributeId(self, "FOLDLEVEL", line_))
  IupSetfAttribute(self, "FOLDTOGGLE", "%d", line_)

  return IUP_DEFAULT
end function

function hotspotclick_cb cdecl(byval self as Ihandle ptr, byval pos_ as integer, byval line_ as integer, byval col as integer, byval status as zstring ptr) as integer

  dim text as zstring ptr = IupGetAttributeId(self, "LINE", line_)

  printf(!"HOTSPOTCLICK_CB (Pos: %d, Line: %d, Col: %d, Status:%s)\n", pos_, line_, col, status)
  printf(!"    line text = %s\n", text)

  return IUP_DEFAULT
end function

function button_cb cdecl(byval self as Ihandle ptr, byval button as integer, byval pressed as integer, byval x as integer, byval y as integer, byval status as zstring ptr) as integer

  printf(!"BUTTON_CB = button: %d, pressed: %d, x: %d, y: %d, status: %s\n", button, pressed, x, y, status)
  return IUP_DEFAULT
end function

function motion_cb cdecl(byval self as Ihandle ptr, byval x as integer, byval y as integer, byval status as zstring ptr) as integer

  printf(!"MOTION_CB = x: %d, y: %d, status: %s\n", x, y, status)

  return IUP_DEFAULT
end function

function caret_cb cdecl (byval self as Ihandle ptr, byval lin as integer, byval col as integer, byval pos_ as integer) as integer

  printf(!"CARET_CB = lin: %d, col: %d, pos_: %d\n", lin, col, pos_)
  return IUP_DEFAULT
end function

function valuechanged_cb cdecl(byval self as Ihandle ptr) as integer

  printf(!"VALUECHANGED_CB\n")
  return IUP_DEFAULT
end function

function action_cb cdecl (byval self as Ihandle ptr, byval insert as integer, byval pos_ as integer, byval length as integer, byval text as zstring ptr) as integer

  printf(!"ACTION = insert: %d, pos_: %d, lenght:%d, text: %s\n", insert, pos_, length, text)
  return IUP_IGNORE

end function

sub set_attribs (byval sci as Ihandle ptr)

  IupSetAttribute(sci, "CLEARALL", "")
  IupSetAttribute(sci, "LEXERLANGUAGE", "vb")

  IupSetAttribute(sci, "KEYWORDS1", "sub function declare dim end type union as ptr enum "_
"if elseif then select case default break goto return for while do continue sizeof typeof new delete property namespace operator this cast using andalso orelse xor or and not cdecl byval byref ")
  IupSetAttribute(sci,"KEYWORDS2","integer long ulong ulongint longint string zstring wstring short ushort ubyte double single unsigned signed")
  IupSetAttribute(sci, "STYLEFONT32", "Consolas")
  IupSetAttribute(sci, "STYLEFONTSIZE32", "11")

  IupSetAttribute(sci, "STYLECLEARALL", "Yes")  /' sets all styles to have the same attributes as 32 '/

  IupSetAttribute(sci, "STYLEFGCOLOR1", "0 128 0")      '' 1-BASIC comment
  IupSetAttribute(sci, "STYLEFGCOLOR2", "0 128 0")      '' 2-BASIC comment line
  IupSetAttribute(sci, "STYLEFGCOLOR4", "139 0 139")    '' 4-String
  IupSetAttribute(sci, "STYLEFGCOLOR5", "0 128 128")     ''
  IupSetAttribute(sci, "STYLEFGCOLOR6", "255 20 147")    ''6-Operators
  IupSetAttribute(sci, "STYLEFGCOLOR7", "0 0 0")          '' 7-Character
  IupSetAttribute(sci, "STYLEFGCOLOR9", "205 149 12")     '' 9-Preprocessor block
  IupSetAttribute(sci, "STYLEFGCOLOR10", "0 197 205")       '' 10-Keywords1
  IupSetAttribute(sci, "STYLEFGCOLOR11", "0 255 0")    '' 11-Keywords2

  IupSetAttribute(sci, "STYLEBOLD10", "YES")

  IupSetAttribute(sci, "STYLEHOTSPOT4", "YES")
  IupSetAttribute(sci, "STYLEHOTSPOT11", "YES")
 
  IupSetAttribute(sci, "INSERT0", sampleCode)

  IupSetAttribute(sci, "MARGINWIDTH0", "50")

  if (1) then  
    IupSetAttribute(sci, "PROPERTY", "fold=1")
    IupSetAttribute(sci, "PROPERTY", "fold.compact=0")
    IupSetAttribute(sci, "PROPERTY", "fold.comment=1")
    IupSetAttribute(sci, "PROPERTY", "fold.preprocessor=1")

    IupSetAttribute(sci, "MARGINWIDTH1", "20")
    IupSetAttribute(sci, "MARGINTYPE1",  "SYMBOL")
    IupSetAttribute(sci, "MARGINMASKFOLDERS1",  "Yes")

    IupSetAttribute(sci, "MARKERDEFINE", "FOLDER=PLUS")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDEROPEN=MINUS")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDEREND=EMPTY")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDERMIDTAIL=EMPTY")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDEROPENMID=EMPTY")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDERSUB=EMPTY")
    IupSetAttribute(sci, "MARKERDEFINE", "FOLDERTAIL=EMPTY")
    IupSetAttribute(sci, "FOLDFLAGS", "LINEAFTER_CONTRACTED")
    IupSetAttribute(sci, "MARGINSENSITIVE1", "YES")
  end if

  printf(!"Number of chars in this text: %s\n", IupGetAttribute(sci, "COUNT"))
  printf(!"Number of lines in this text: %s\n", IupGetAttribute(sci, "LINECOUNT"))
  printf(!"%s\n", IupGetAttribute(sci, "LINEVALUE"))
end sub

sub ScintillaTest()

  dim as Ihandle ptr dlg
  dim as Ihandle ptr sci
  
  Dim As Ihandle Ptr file_Menu
  Dim As IHandle Ptr subMenu
  Dim As Ihandle Ptr itm_File
  Dim As Ihandle Ptr itm_New
  Dim As Ihandle Ptr itm_Open
  Dim As Ihandle Ptr itm_Save
  Dim As Ihandle Ptr itm_SaveAs
  Dim As Ihandle Ptr itm_Close
  Dim As Ihandle Ptr itm_Exit

  Dim As Ihandle Ptr mnu

  IupScintillaOpen()    

  '' Creates an instance of the Scintilla control
  sci = IupScintilla()
''  IupSetAttribute(sci, "VISIBLECOLUMNS", "80")
''  IupSetAttribute(sci, "VISIBLELINES", "40")
  ''IupSetAttribute(sci, "SCROLLBAR", "NO")
  IupSetAttribute(sci, "BORDER", "NO")
  IupSetAttribute(sci, "EXPAND", "Yes")

  IupSetCallback(sci, "MARGINCLICK_CB", cast(icallback,@marginclick_cb))
  IupSetCallback(sci, "HOTSPOTCLICK_CB", cast(icallback,@hotspotclick_cb))
''  IupSetCallback(sci, "BUTTON_CB", @button_cb)
''  IupSetCallback(sci, "MOTION_CB", @motion_cb)
  IupSetCallback(sci, "CARET_CB", cast(icallback,@caret_cb))
  IupSetCallback(sci, "VALUECHANGED_CB", cast(icallback,@valuechanged_cb))
  IupSetCallback(sci, "ACTION", cast(icallback,@action_cb))

  ' set up the menu title items
  itm_File = IupItem("File", "TITLE")
  IupSetAttribute(itm_File, "KEY", "f")
  
	' the & will display an underscore under the letter  
  itm_New = IupItem("&New", "TITLE")	
  IupSetAttribute(itm_New, "KEY", "n")

  itm_Open = IupItem("&Open", "TITLE")
  IupSetAttribute(itm_Open, "KEY", "o")
  
  itm_Save = IupItem("&Save", "TITLE")
  IupSetAttribute(itm_Save, "KEY", "s")
  IupSetAttribute(itm_Save, "ACTIVE", "NO")	' set the item as not active (disabled)
 
  itm_SaveAs = IupItem("Save&As", "TITLE")
  IupSetAttribute(itm_SaveAs, "KEY", "a")
  IupSetAttribute(itm_SaveAs, "ACTIVE", "NO")  
  
  itm_Close = IupItem("Close", "TITLE")
  IupSetAttribute(itm_Close, "KEY", "c")
  IupSetAttribute(itm_Close, "ACTIVE", "NO")
  
  ' Oddly, the exit command comes built in with an underscored 'x' and
  ' adding the & will display the &. If you select Exi&t, it will work
  ' as expected and show an underscored t.
  itm_Exit = IupItem("Exit", "TITLE")
  IupSetAttribute(itm_Exit, "KEY", "x")


  ' Here we create an entire menu ptr containing all the items we just created. 
  ' We use the function IupSeparator() to create our separator lines so that
  ' we don't have to create a ptr variable for each separator line. 
  file_Menu = IupMenu(itm_New, _
  							 itm_Open, _
  							 IupSeparator(), _
  							 itm_Save, _
  							 itm_SaveAs, _
  							 IupSeparator(), _
  							 itm_Close, _
  							 IupSeparator(), _
  							 itm_Exit, NIL)	' set up a menu consisting of the file menu contents 
  
  ' this creates a menu that when selected opens another menu 
  ' ie click on "File" to reveal submenu "Open" etc
  subMenu = IupSubMenu("File", file_Menu)	' File is the title, file_menu is the ptr to a menu
  
  mnu = IupMenu(subMenu, NIL)		'create a ptr to the complete menu
  
  ' Applying the menu (mnu) directly to the dialog (dlg) didn't seem to work.
  ' I found a confusing explanation as to why but its enought to know that you
  ' can assign a name to the interface element (mnu) and assign that to the dialog (dlg)
  IupSetHandle("mymenu", mnu)

  '' Creates a dialog containing the control
  dlg = IupDialog(IupVbox(sci, NIL))
  IupSetAttribute(dlg, "TITLE", "IupScintilla")
  IupSetAttribute(dlg, "RASTERSIZE", "700x500")
  IupSetAttribute(dlg, "MARGIN", "10x10")

  IupSetAttribute(dlg, "MENU", "mymenu")	' assign the menu name to the dialog

  '' Shows dialog
  IupShow(dlg)
  IupSetAttribute(dlg, "RASTERSIZE", NIL)
  set_attribs(sci)
end sub

sub mymain()

  ''first set up the two dynamic link libraries
  var iup = DyLibLoad("iup.dll")
  if (iup = NIL) then
    print "error loading iup"
    return
  end If
  var scintilla = DyLibLoad("iup_scintilla.dll")
  if (scintilla = NIL) then
    print "error loading scintilla"
    dylibfree(iup)
    Return
  end if
 
  IupOpen = DylibSymbol(iup,"IupOpen")
  IupSetCallback = DyLibSymbol(iup,"IupSetCallback")
  IupMainLoop = DyLibSymbol(iup,"IupMainLoop")
  IupClose = DyLibSymbol(iup,"IupClose")
  IupSetAttribute = DyLibSymbol(iup,"IupSetAttribute")
  IupShow = DyLibSymbol(iup,"IupShow")
  IupScintilla = DyLibSymbol(scintilla,"IupScintilla")
  IupScintillaOpen = DyLibSymbol(scintilla,"IupScintillaOpen")
  IupSetCallback = DyLibSymbol(iup,"IupSetCallback")
  IupSetfAttribute = DyLibSymbol(iup,"IupSetfAttribute")
  IupDialog = DyLibSymbol(iup,"IupDialog")
  IupGetAttributeId = DyLibSymbol(iup,"IupGetAttributeId")
  IupGetAttribute = DyLibSymbol(iup,"IupGetAttribute")

  IupVbox = DyLibSymbol(iup,"IupVbox")

  IupItem = DylibSymbol(iup, "IupItem")
  IupMenu = DylibSymbol(iup, "IupMenu")
  IupSubMenu = DylibSymbol(iup, "IupSubmenu")
  IupSeparator = DylibSymbol(iup, "IupSeparator")
  IupSetHandle = DylibSymbol(iup, "IupSetHandle")
 
  IupOpen(NIL,NIL) 

  ScintillaTest()

  IupMainLoop()

  IupClose()
  DyLibFree(iup)
  DyLibFree(scintilla)
  return

end Sub
mymain()
End 
aurelVZAB
Posts: 667
Joined: Jul 02, 2008 14:55
Contact:

Re: scintilla editing component/widget (new iup widget)

Post by aurelVZAB »

I compiled this example ,add files as suggested from sourceforge
and after compilation i get only blink of console and then nothing .
where is the trick ?
Kuan Hsu
Posts: 587
Joined: Sep 16, 2007 15:12
Location: Taiwan

Re: scintilla editing component/widget (new iup widget)

Post by Kuan Hsu »

aurelVZAB wrote: Jul 14, 2023 18:47 I compiled this example ,add files as suggested from sourceforge
and after compilation i get only blink of console and then nothing .
where is the trick ?
The iup / iup_scintilla are dynamic loading, no need link with the any *.a libraries.
In my test, just compile the single file, then put the exe with iup.dll and iup_scintilla.dll together, it runs....
aurelVZAB
Posts: 667
Joined: Jul 02, 2008 14:55
Contact:

Re: scintilla editing component/widget (new iup widget)

Post by aurelVZAB »

thanks Kuan
i will try
Post Reply