(SOLVED) IUPScintilla how to insert text when clicked "ENTER" ?

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
VANYA
Posts: 1255
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

(SOLVED) IUPScintilla how to insert text when clicked "ENTER" ?

Postby VANYA » Oct 07, 2017 9:01

Hi All!

I want that when you press a key "ENTER" , inserted a certain text, but it does not work. What am I doing wrong?


Code: Select all

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

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
 
  If Asc(*text) = 10 OrElse Asc(*text) = 13 Then
     
     print Asc(*text)
     
     IupSetAttributeId(self, "INSERT", pos_, "bla bla") ' does not insert text !!!!!!!!!!!!!!!!!!
     
     return IUP_IGNORE ' not ignored ??????????
     
  EndIf
 
  Return IUP_DEFAULT
 
end Function


IupOpen(0,0)

IupScintillaOpen()

var ih = IupScintilla()

IupSetCallback(ih, "ACTION", cast(icallback,@action_cb))

var dlg = IupDialog(ih)

IupSetAttributes( dlg, "TITLE = IupDialog, RASTERSIZE = 640x480" )

IupShow(dlg)

IupMainLoop()

IupClose()
Last edited by VANYA on Oct 07, 2017 12:40, edited 1 time in total.
Kuan Hsu
Posts: 287
Joined: Sep 16, 2007 15:12
Location: Taiwan

Re: IUPScintilla how to insert text when clicked "ENTER" ?

Postby Kuan Hsu » Oct 07, 2017 11:30

VANYA wrote:Hi All!

I want that when you press a key "ENTER" , inserted a certain text, but it does not work. What am I doing wrong?


Code: Select all

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

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
 
  If Asc(*text) = 10 OrElse Asc(*text) = 13 Then
     
     print Asc(*text)
     
     IupSetAttributeId(self, "INSERT", pos_, "bla bla") ' does not insert text !!!!!!!!!!!!!!!!!!
     
     return IUP_IGNORE ' not ignored ??????????
     
  EndIf
 
  Return IUP_DEFAULT
 
end Function


IupOpen(0,0)

IupScintillaOpen()

var ih = IupScintilla()

IupSetCallback(ih, "ACTION", cast(icallback,@action_cb))

var dlg = IupDialog(ih)

IupSetAttributes( dlg, "TITLE = IupDialog, RASTERSIZE = 640x480" )

IupShow(dlg)

IupMainLoop()

IupClose()

We can't insert text in ACTION callback function, this callback function trigger when the text is edited, but before its value is actually changed.(from IUP document)
In poseidonFB, I declare a global variable( just boolean ) and catch the "ENTER" in K_ANY( or ACTION ) callback to change the value, if the variable is true, insert the "bla bla" in CARET_CB callback( if ENTER, the CARET_CB must trigger ).
VANYA
Posts: 1255
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: IUPScintilla how to insert text when clicked "ENTER" ?

Postby VANYA » Oct 07, 2017 12:39

Kuan Hsu wrote:We can't insert text in ACTION callback function, this callback function trigger when the text is edited, but before its value is actually changed.(from IUP document)
In poseidonFB, I declare a global variable( just boolean ) and catch the "ENTER" in K_ANY( or ACTION ) callback to change the value, if the variable is true, insert the "bla bla" in CARET_CB callback( if ENTER, the CARET_CB must trigger ).


Many thanks to my friend, I already began to think this way, but until recently I hoped that there was still some way to make changes in the event "ACTION". In Windows, using the technique of subclassing, you can change the value for Control "EDIT" before the changes in the editor (ниже пример). But, since in the IUP library, this can not be done in the Scintilla, I will do it according to your method.

--------------------------

Perhaps you know all this, but I decided to show the really correct approach applied in the Windows API. It's unclear why the IUP author did not do this for the ACTION event. The example works with freebasic compilier 32-bit, I did not test it with 64-bit compilier. After starting the example and pressing "Enter" , Instead, it will "SPACE":

Code: Select all

#INCLUDE "windows.bi"
LoadLibrary "RICHED20.DLL"

Dim msg As MSG
Dim As WNDCLASSEX wc
Dim As String NameClass="MyClass"
Dim As HINSTANCE Hinst=GetModuleHandle(0)

Dim Shared As Integer OldWndproc

' EDIT proc CALLBACK
Function editproc_cb(hwnd As HWND, msg As Uinteger,_
    wparam As WPARAM, lparam As LPARAM) As Integer
   
    Select Case msg
       
       Case WM_CHAR
         
         Dim As Byte bChar = Cast(Byte ,LoByte(wparam))
         
         If  bChar = 13 Then
           
            *Cast(Byte Ptr ,@wparam) = 32 ' change to space
           
         EndIf
         
         
       Case WM_KEYDOWN
         
          If LoByte(wparam) = VK_RETURN Then
             
             Return 0
             
          EndIf
         
    End Select
   
   Return CallWindowProc(Cast(Any Ptr,OldWndproc),hwnd, msg, wparam ,lparam)
   
End Function

Function wndproc(hwnd As HWND, msg As Uinteger,_
    wparam As WPARAM, lparam As LPARAM) As Integer
   
    Select Case msg
        Case WM_DESTROY
            PostQuitMessage(0)
        Case WM_CREATE
            Var edit = CreateWindowEx(WS_EX_CLIENTEDGE, "RICHEDIT20A", "RichEdit Control",_
            WS_VISIBLE Or WS_CHILD Or WS_HSCROLL Or WS_VSCROLL  Or ES_MULTILINE Or ES_AUTOHSCROLL Or ES_AUTOVSCROLL,_
            10,10,200,200, hwnd, Cast(HMENU,1), 0, 0)
           
            OldWndproc = SetWindowLongPtr(edit ,GWL_WNDPROC , Cast(Integer , @editproc_cb))
           
    End Select
   
    Return DefWindowProc(hwnd,msg,wparam,lparam)
   
End Function

With wc
    .cbSize=SizeOf(WNDCLASSEX)
    .style=CS_HREDRAW Or CS_VREDRAW
    .lpfnWndProc=@wndproc
    .hInstance=Hinst
    .hIcon=LoadIcon(0,IDI_WINLOGO)
    .hCursor=LoadCursor(0,IDC_ARROW)
    .hbrBackground=Cast(HBRUSH,COLOR_WINDOWFRAME)
    .lpszClassName=StrPtr(NameClass)
    .hIconSm=.hIcon
End With

If RegisterClassEx(@wc)=0 Then
    Print "Register error, press any key"
    Sleep
    End
Endif

CreateWindowEx(0,NameClass,"RichEdit",_
WS_VISIBLE Or WS_OVERLAPPEDWINDOW,100,100,240,260,0,0,Hinst,0)

While GetMessage(@msg,0,0,0)
    TranslateMessage(@msg)
    DispatchMessage(@msg)
Wend
dodicat
Posts: 4475
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: (SOLVED) IUPScintilla how to insert text when clicked "ENTER" ?

Postby dodicat » Oct 07, 2017 13:35

It works on 64 bit if you insert -4 for GWL_WNDPROC

GWL_WNDPROC seems not defined in 64 bit.
PaulSquires
Posts: 593
Joined: Jul 14, 2005 23:41
Contact:

Re: (SOLVED) IUPScintilla how to insert text when clicked "ENTER" ?

Postby PaulSquires » Oct 07, 2017 16:53

dodicat wrote:It works on 64 bit if you insert -4 for GWL_WNDPROC

GWL_WNDPROC seems not defined in 64 bit.


Use:
GWLP_WNDPROC

Per:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms644898(v=vs.85).aspx

Return to “Libraries”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest