Plugin in poseidonFB using IUP

General FreeBASIC programming questions.
Post Reply
Kuan Hsu
Posts: 586
Joined: Sep 16, 2007 15:12
Location: Taiwan

Plugin in poseidonFB using IUP

Post by Kuan Hsu »

Dear all, at rev.387 I added plugin support, if anyone are interest in it, there is a example code in http://www.mediafire.com/file/mqkjz2l7d ... tPlugin.7z
Image

After downloading the source, use freeBASIC to build it with -dll option( need link with IUP library ), we will get *.dll or *.so dynamic library.

For using the new stuff, using poseidonFB rev.387, "Options" -> "Tools" -> "Set Custom Tools...", set the plugin name and path, then click "OK",
Image
select "Options" -> "Tools" -> "Set Custom Tools..." again, click the "plugin name" menuitem to run.

Every plugin need include a "poseidonFB_Dll_Go()" function as entry point( poseidonFB will can this function everytime execute the plugin ), using IUP we can use IupGetHandle / IupGetDialogChild function to get it's IUP Ihandle, and use them in our plugin code.
The *.dll / *.so can place at anywhere, poseidonFB will load it by it's steeing path, the older use *.exe custom tools are also supported.

For IupGetHandle:
IupGetHandle( "POSEIDONFB_MAIN_DIALOG" ), to get poseidonFB main dialog Ihandle

For IupGetDialogChild:
NAME = POSEIDONFB_MAIN_TABS, to get poseidonFB's main document IupFlatTabs Ihandle
NAME = POSEIDONFB_SUB_TABS, to get poseidonFB's sub(split) document IupFlatTabs Ihandle
NAME = POSEIDONFB_LEFT_TABS, to get poseidonFB's left( Project, Outline ) IupTabs Ihandle
NAME = POSEIDONFB_BOTTOM_TABS, , to get poseidonFB's bottom( Message, Search ) IupFlatTabs(Win) / IupTabs(Lin) Ihandle
Last edited by Kuan Hsu on Apr 15, 2018 2:41, edited 1 time in total.
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: Plugin in poseidonFB using IUP

Post by sancho3 »

Very nice Kuan. You are one dedicated individual.
I will look at this asap.
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: Plugin in poseidonFB using IUP

Post by sancho3 »

Hello Kuan:
I am getting errors:
home/les/Downloads/Poseiden/testPlugin/testDll.bas(135) error 41: Variable not declared, IupScintillaSendMessage in 'dim as integer _currentPos = cast(Integer, IupScintillaSendMessage( sci, 2008, 0, 0 ) ) ' SCI_GETCURRENTPOS = 2008'
/home/les/Downloads/Poseiden/testPlugin/testDll.bas(136) error 9: Expected expression, found 'IupScintillaSendMessage' in 'dim as integer _currentLin = cast(integer, IupScintillaSendMessage( sci, 2166, _currentPos, 0 ) ) ' SCI_LINEFROMPOSITION = 2166'
What is happening is in iup_scintilla.bi, SCINTILLA_H is not defined.

Code: Select all

#ifdef SCINTILLA_H
	declare function IupScintillaSendMessage(byval ih as Ihandle ptr, byval iMessage as ulong, byval wParam as uptr_t, byval lParam as sptr_t) as sptr_t
#endif
I put in some #print to test and the declare is never reached. I don't know what defines SCINTILLA_H or why its not for me.
Kuan Hsu
Posts: 586
Joined: Sep 16, 2007 15:12
Location: Taiwan

Re: Plugin in poseidonFB using IUP

Post by Kuan Hsu »

sancho3 wrote:Hello Kuan:
I am getting errors:
home/les/Downloads/Poseiden/testPlugin/testDll.bas(135) error 41: Variable not declared, IupScintillaSendMessage in 'dim as integer _currentPos = cast(Integer, IupScintillaSendMessage( sci, 2008, 0, 0 ) ) ' SCI_GETCURRENTPOS = 2008'
/home/les/Downloads/Poseiden/testPlugin/testDll.bas(136) error 9: Expected expression, found 'IupScintillaSendMessage' in 'dim as integer _currentLin = cast(integer, IupScintillaSendMessage( sci, 2166, _currentPos, 0 ) ) ' SCI_LINEFROMPOSITION = 2166'
What is happening is in iup_scintilla.bi, SCINTILLA_H is not defined.

Code: Select all

#ifdef SCINTILLA_H
	declare function IupScintillaSendMessage(byval ih as Ihandle ptr, byval iMessage as ulong, byval wParam as uptr_t, byval lParam as sptr_t) as sptr_t
#endif
I put in some #print to test and the declare is never reached. I don't know what defines SCINTILLA_H or why its not for me.
Please comment the Preprocessor:

Code: Select all

' #ifdef SCINTILLA_H
	declare function IupScintillaSendMessage(byval ih as Ihandle ptr, byval iMessage as ulong, byval wParam as uptr_t, byval lParam as sptr_t) as sptr_t
' #endif
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: Plugin in poseidonFB using IUP

Post by sancho3 »

I had tried that and got this error (note that the error is wparam as uptr_t in scintilla_bi):
home/les/Downloads/FreeBASIC-1.05.0-linux-x86_64/include/freebasic/IUP/iup_scintilla.bi(39) error 58: Illegal specification, at parameter 3 (wParam) of IupScintillaSendMessage() in 'declare function IupScintillaSendMessage(byval ih as Ihandle ptr, byval iMessage as ulong, byval wParam as uptr_t, byval lParam as sptr_t) as sptr_t'
I changed the uptr_t to ulongint and the sptr_t to longint and it compiled without errors.
I have testplugin.dll. I have Poseiden 385 so I will have to download 387 and I will let you know how it goes.
Kuan Hsu
Posts: 586
Joined: Sep 16, 2007 15:12
Location: Taiwan

Re: Plugin in poseidonFB using IUP

Post by Kuan Hsu »

sancho3 wrote:I had tried that and got this error (note that the error is wparam as uptr_t in scintilla_bi):
home/les/Downloads/FreeBASIC-1.05.0-linux-x86_64/include/freebasic/IUP/iup_scintilla.bi(39) error 58: Illegal specification, at parameter 3 (wParam) of IupScintillaSendMessage() in 'declare function IupScintillaSendMessage(byval ih as Ihandle ptr, byval iMessage as ulong, byval wParam as uptr_t, byval lParam as sptr_t) as sptr_t'
I changed the uptr_t to ulongint and the sptr_t to longint and it compiled without errors.
I have testplugin.dll. I have Poseiden 385 so I will have to download 387 and I will let you know how it goes.
Below is my iup_scintilla.bi ( Linux mint 18.3 64bit )

Code: Select all

#pragma once

#include "iup.bi"
#inclib "iup_scintilla"

extern "C"

#define __IUP_SCINTILLA_H
declare sub IupScintillaOpen()
declare function IupScintilla() as Ihandle ptr

'#ifdef SCINTILLA_H
	declare function IupScintillaSendMessage(byval ih as Ihandle ptr, byval iMessage as ulong, byval wParam as ulong, byval lParam as long) as long
'#endif

end extern
Please use the lastest reversion( now is 0.392 ) to test......^^
Kuan Hsu
Posts: 586
Joined: Sep 16, 2007 15:12
Location: Taiwan

Re: Plugin in poseidonFB using IUP

Post by Kuan Hsu »

New ToolbarExt sample: ( works >= rev.395 )

Code: Select all

#include once "IUP/iup.bi"
'#include once "IUP/iup_scintilla.bi"

'compile with -dll option
extern "C"

   declare sub poseidonFB_Dll_Go alias "poseidonFB_Dll_Go" ()

   dim shared as Ihandle ptr THIS_MAINDIALOG_HANDLE
   dim shared as Ihandle ptr POSEIDONFB_HANDLE
   dim shared as Ihandle ptr POSEIDONFB_COMMAND_HANDLE
   
   /'
   'Icon
   function load_image_uncomment() as Ihandle ptr
   
      dim imgdata(256) as ubyte = {_
                              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,_
                              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,_
                              0, 0, 0, 0, 0, 1, 2, 0, 0, 3, 4, 0, 0, 3, 4, 0,_
                              0, 0, 0, 0, 5, 2, 2, 0, 0, 0, 3, 4, 3, 4, 0, 0,_
                              0, 0, 0, 0, 1, 2, 6, 0, 0, 0, 0, 3, 4, 0, 0, 0,_
                              0, 0, 0, 0, 6, 2, 1, 0, 0, 0, 3, 4, 3, 4, 0, 0,_
                              0, 0, 0, 5, 2, 2, 5, 0, 0, 3, 4, 0, 0, 3, 4, 0,_
                              0, 0, 0, 1, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,_
                              0, 0, 0, 6, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,_
                              0, 0, 5, 2, 2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,_
                              0, 0, 1, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,_
                              0, 0, 6, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,_
                              0, 0, 2, 2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,_
                              0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,_
                              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,_
                              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
            
      dim as Ihandle ptr image = IupImage( 16, 16, @imgdata(0) )
      IupSetAttribute(image, "0", "BGCOLOR")
      IupSetAttribute(image, "1", "109 139 185")
      IupSetAttribute(image, "2", "53 88 131")
      IupSetAttribute(image, "3", "237 28 36")
      IupSetAttribute(image, "4", "243 103 111")
      IupSetAttribute(image, "5", "199 205 207")
      IupSetAttribute(image, "6", "92 124 169")
      IupSetAttribute(image, "7", "0 0 0")

      return image
	end function
	'/
   
   function comment_ACTION cdecl( ih as Ihandle ptr ) as integer
      
      if( POSEIDONFB_HANDLE <> 0 ) then
      
         dim as Ihandle ptr _MaintabsHandle = IupGetDialogChild( POSEIDONFB_HANDLE, "POSEIDONFB_MAIN_TABS" )
         if( _MaintabsHandle <> 0 ) then
            
            dim as Ihandle ptr sci = cast( Ihandle ptr, IupGetAttribute( _MaintabsHandle, "VALUE_HANDLE" ) )
            if( sci <> 0 ) then
            
				if( POSEIDONFB_COMMAND_HANDLE <> 0 ) then IupSetAttribute( POSEIDONFB_COMMAND_HANDLE, "VALUE", "Comment" )
            end if
         end if
      end if
      
      return IUP_DEFAULT
   end function   

   
   function uncomment_ACTION cdecl( ih as Ihandle ptr ) as integer
      
      if( POSEIDONFB_HANDLE <> 0 ) then
      
         dim as Ihandle ptr _MaintabsHandle = IupGetDialogChild( POSEIDONFB_HANDLE, "POSEIDONFB_MAIN_TABS" )
         if( _MaintabsHandle <> 0 ) then
            
            dim as Ihandle ptr sci = cast( Ihandle ptr, IupGetAttribute( _MaintabsHandle, "VALUE_HANDLE" ) )
            if( sci <> 0 ) then
            
               if( POSEIDONFB_COMMAND_HANDLE <> 0 ) then IupSetAttribute( POSEIDONFB_COMMAND_HANDLE, "VALUE", "UnComment" )
            end if
         end if
      end if
      
      return IUP_DEFAULT
   end function   



   ' Main
   sub poseidonFB_Dll_Go alias "poseidonFB_Dll_Go"() export
   
      ' The main IupOpen() is already ran by poseidonFB, no need anymore
      
      POSEIDONFB_HANDLE = IupGetHandle( "POSEIDONFB_MAIN_DIALOG" ) ' Get poseidonFB main dialog handle(IUP)
      if( POSEIDONFB_HANDLE <> 0 ) then
	  
         ' Check the THIS_MAINDIALOG_HANDLE is already created......
         if( THIS_MAINDIALOG_HANDLE = 0 ) then
		 
			' Setup the POSEIDONFB_COMMANDLINE
			POSEIDONFB_COMMAND_HANDLE = IupGetDialogChild( POSEIDONFB_HANDLE, "POSEIDONFB_COMMANDLINE" )
         
            dim as Ihandle ptr commentButton = IupButton( 0, 0 )
            IupSetAttributes( commentButton, "ALIGNMENT=ACENTER:ACENTER,NAME=COMMENT,FLAT=YES,IMAGE=icon_comment" ) ' Use poseidonFB's icon: icon_comment
            IupSetCallback( commentButton, "ACTION", cast( Icallback, @comment_ACTION ) )
            
            dim as Ihandle ptr uncommentButton = IupButton( 0, 0 )
            IupSetAttributes( uncommentButton, "ALIGNMENT=ACENTER:ACENTER,NAME=COMMENT,FLAT=YES,IMAGE=icon_uncomment" )
            IupSetCallback( uncommentButton, "ACTION", cast( Icallback, @uncomment_ACTION ) )
            
            dim as Ihandle ptr labelSEPARATOR = IupLabel( 0 )
            IupSetAttribute( labelSEPARATOR, "SEPARATOR", "VERTICAL")         
            
            
            ' Assign THIS_MAINDIALOG_HANDLE to one of buttons, to prevent multiple create...
            THIS_MAINDIALOG_HANDLE = commentButton
            
            dim as Ihandle ptr _toorbarHandle = IupGetDialogChild( POSEIDONFB_HANDLE, "POSEIDONFB_TOOLBAR" ) ' Get the poseidonFB's Toolbar Handle
            if( _toorbarHandle <> 0 ) then
               
               ' Insert to poseidonFB's Toolbar( before BackwardNav )
               IupInsert( _toorbarHandle, IupGetDialogChild( POSEIDONFB_HANDLE, "POSEIDONFB_TOOLBAR_BackwardNav"), commentButton )
               IupInsert( _toorbarHandle, IupGetDialogChild( POSEIDONFB_HANDLE, "POSEIDONFB_TOOLBAR_BackwardNav"), uncommentButton )
               IupInsert( _toorbarHandle, IupGetDialogChild( POSEIDONFB_HANDLE, "POSEIDONFB_TOOLBAR_BackwardNav"), labelSEPARATOR )
               IupMap( commentButton )
               IupMap( uncommentButton )
               IupMap( labelSEPARATOR )
			   IupRefresh( _toorbarHandle )
            else
               
               IupMessage( "Error!", "No poseidonFB's Toolbar Handle Found..." )
            end if
         end if
      end if
      
   end sub
   
end extern
Post Reply