Page 1 of 1
ScintillaGadget EventTypes
Posted: Wed Aug 15, 2018 4:15 pm
by wombats
Could we have the following EventTypes for the ScintillaGadget, please?
Code: Select all
#PB_EventType_Change
#PB_EventType_Focus
#PB_EventType_LostFocus
Re: ScintillaGadget EventTypes
Posted: Wed Aug 15, 2018 8:54 pm
by mk-soft
You can use ScintillaCallback...
Code: Select all
;-TOP
Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification)
Select *scinotify\nmhdr\code
Case #SCN_MODIFIED
;Debug *scinotify\modificationType
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
; Always ready
CompilerCase #PB_OS_MacOS
If *scinotify\modificationType & #SC_MOD_BEFOREINSERT
PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_Change)
ElseIf *scinotify\modificationType & #SC_MOD_BEFOREDELETE
PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_Change)
EndIf
CompilerCase #PB_OS_Linux
If *scinotify\modificationType & #SC_MOD_BEFOREINSERT
PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_Change)
ElseIf *scinotify\modificationType & #SC_MOD_BEFOREDELETE
PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_Change)
EndIf
CompilerEndSelect
Case #SCN_FOCUSIN
PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_Focus)
Case #SCN_FOCUSOUT
PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_LostFocus)
EndSelect
EndProcedure
If OpenWindow(0, 0, 0, 330, 90, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If InitScintilla()
ScintillaGadget(0, 10, 10, 320, 70, @ScintillaCallBack())
; Ausgabe auf rote Farbe setzen
ScintillaSendMessage(0, #SCI_STYLESETFORE, 0, RGB(255, 0, 0))
; Anfänglichen Text des ScintillaGadgets festlegen
ScintillaSendMessage(0, #SCI_SETTEXT, 0, UTF8("This is a simple ScintillaGadget with text..."))
; Hinzufügen einer zweiten Zeile mit einem vorherigen Zeilenumbruch
Text$ = Chr(10) + "Second line"
ScintillaSendMessage(0, #SCI_APPENDTEXT, Len(Text$), UTF8(Text$))
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_Focus
Debug "Focus"
Case #PB_EventType_LostFocus
Debug "LostFocus"
Case #PB_EventType_Change
Debug "Change"
EndSelect
EndSelect
EndSelect
ForEver
EndIf
Re: ScintillaGadget EventTypes
Posted: Wed Aug 15, 2018 9:46 pm
by wombats
I forgot about the callback. Thanks. However, the ScintillaGadget in the Dialog library doesn't support assigning a callback.
I wonder if I could add a ScintillaGadget to a dialog after the dialog has been created. Hmm.
Re: ScintillaGadget EventTypes
Posted: Fri Apr 14, 2023 5:04 pm
by Taz
wombats wrote: ↑Wed Aug 15, 2018 9:46 pm
I forgot about the callback. Thanks. However, the ScintillaGadget in the Dialog library doesn't support assigning a callback.
Is there a way to set a callback when using the dialog library?
Re: ScintillaGadget EventTypes
Posted: Fri Apr 14, 2023 5:50 pm
by jacdelad
Taz wrote: ↑Fri Apr 14, 2023 5:04 pm
wombats wrote: ↑Wed Aug 15, 2018 9:46 pm
I forgot about the callback. Thanks. However, the ScintillaGadget in the Dialog library doesn't support assigning a callback.
Is there a way to set a callback when using the dialog library?
Hi Taz,
I started using the Dialog library some months ago and sadly have to tell you: no. Since there's no command to do this after creation, I can only imagine some kind of "hack" which I have done with ownerdraw listicongadgets: create your dialog, then exchange the scintillagadget with a new one (with callback). This way you need to define the id and use the same one for the new gadget.
Modified example from the help and very, very dirty!
Code: Select all
InitScintilla()
Runtime Enumeration
#Scintilla
EndEnumeration
Procedure MyCallback(Gadget, *scinotify.SCNotification)
Debug ElapsedMilliseconds()
EndProcedure
#Dialog = 0
#Xml = 0
XML$ = "<window id='#PB_Any' name='test' text='test' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
" <vbox expand='item:2'>" +
" <hbox>" +
" <button text='button 1'/>" +
" <checkbox text='checkbox 1'/>" +
" <button text='button 2'/>" +
" </hbox>" +
" <scintilla id='#Scintilla' text='content' height='150'/>" +
" </vbox>" +
"</window>"
If ParseXML(#Xml, XML$) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
ScintillaGadget(#Scintilla,GadgetX(#Scintilla),GadgetY(#Scintilla),GadgetWidth(#Scintilla),GadgetHeight(#Scintilla),@MyCallback())
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
...but this get's more and more complicated when using tabs, containergadgets etc. (though it's possible to do).
A native possibility to do this would be far better (and also a lot of other additions to the dialog library).
Re: ScintillaGadget EventTypes
Posted: Fri Apr 14, 2023 6:45 pm
by Taz
Thanks jacdelad for the "hack".
I already suspected that there is no clean solution.
And then the problems continue, in my app are containers and splitters, and it no longer works
I think the mistake is on the splitter or gridbox.
The big question is, can this still be fixed, hm...?
Code: Select all
InitScintilla()
Runtime Enumeration Gadgets
#ORG_FILE
#ORG_OPEN
#ORG_EDIT
#NEW_FILE
#NEW_OPEN
#NEW_SAVE
#NEW_EDIT
EndEnumeration
Procedure MyCallback(Gadget, *scinotify.SCNotification)
Debug ElapsedMilliseconds()
EndProcedure
#Dialog = 0
#Xml = 0
XML$ = ~" <window flags='#PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered' minwidth='400' minheight='300' text='Translate Json File' name='test' id='#PB_Any'>\n"
XML$ + ~" <vbox>\n"
XML$ + ~" <splitter colspan='2' flags='#PB_Splitter_Vertical' name='SPLIT1'>\n"
XML$ + ~" <frame text='Orginal'>\n"
XML$ + ~" <gridbox colexpand='item:1' rowexpand='item:2'>\n"
XML$ + ~" <string flags='#PB_String_ReadOnly' id='#ORG_FILE'/>\n"
XML$ + ~" <button text='. . .' id='#ORG_OPEN'/>\n"
XML$ + ~" <scintilla colspan='2' id='#ORG_EDIT'/> \n"
XML$ + ~" </gridbox> \n"
XML$ + ~" </frame>\n"
XML$ + ~" <frame text='New'>\n"
XML$ + ~" <gridbox colexpand='item:1' rowexpand='item:2' columns='3'>\n"
XML$ + ~" <string flags='#PB_String_ReadOnly' id='#NEW_FILE'/>\n"
XML$ + ~" <button text='. . .' id='#NEW_OPEN'/>\n"
XML$ + ~" <button text='Save' id='#NEW_SAVE'/>\n"
XML$ + ~" <scintilla colspan='3' id='#NEW_EDIT'/> \n"
XML$ + ~" </gridbox> \n"
XML$ + ~" </frame> \n"
XML$ + ~" </splitter> \n"
XML$ + ~" </vbox> \n"
XML$ + ~" </window> \n"
If ParseXML(#Xml, XML$) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
ScintillaGadget(#ORG_EDIT,GadgetX(#ORG_EDIT),GadgetY(#ORG_EDIT),GadgetWidth(#ORG_EDIT),GadgetHeight(#ORG_EDIT),@MyCallback())
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
Re: ScintillaGadget EventTypes
Posted: Fri Apr 14, 2023 7:43 pm
by jacdelad
Nah, it is possible:
Code: Select all
InitScintilla()
Runtime Enumeration Gadgets
#ORG_FILE
#ORG_OPEN
#ORG_EDIT
#NEW_FILE
#NEW_OPEN
#NEW_SAVE
#NEW_EDIT
EndEnumeration
Procedure MyCallback(Gadget, *scinotify.SCNotification)
Debug ElapsedMilliseconds()
EndProcedure
#Dialog = 0
#Xml = 0
XML$ = ~" <window flags='#PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered' minwidth='400' minheight='300' text='Translate Json File' name='test' id='#PB_Any'>\n"
XML$ + ~" <vbox>\n"
XML$ + ~" <splitter colspan='2' flags='#PB_Splitter_Vertical' name='SPLIT1'>\n"
XML$ + ~" <frame text='Orginal'>\n"
XML$ + ~" <gridbox colexpand='item:1' rowexpand='item:2'>\n"
XML$ + ~" <string flags='#PB_String_ReadOnly' id='#ORG_FILE'/>\n"
XML$ + ~" <button text='. . .' id='#ORG_OPEN'/>\n"
XML$ + ~" <scintilla colspan='2' id='#ORG_EDIT'/> \n"
XML$ + ~" </gridbox> \n"
XML$ + ~" </frame>\n"
XML$ + ~" <frame text='New'>\n"
XML$ + ~" <gridbox colexpand='item:1' rowexpand='item:2' columns='3'>\n"
XML$ + ~" <string flags='#PB_String_ReadOnly' id='#NEW_FILE'/>\n"
XML$ + ~" <button text='. . .' id='#NEW_OPEN'/>\n"
XML$ + ~" <button text='Save' id='#NEW_SAVE'/>\n"
XML$ + ~" <scintilla colspan='3' id='#NEW_EDIT'/> \n"
XML$ + ~" </gridbox> \n"
XML$ + ~" </frame> \n"
XML$ + ~" </splitter> \n"
XML$ + ~" </vbox> \n"
XML$ + ~" </window> \n"
If ParseXML(#Xml, XML$) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
OpenGadgetList(GetGadgetAttribute(DialogGadget(#Dialog,"SPLIT1"),#PB_Splitter_FirstGadget))
ScintillaGadget(#ORG_EDIT,GadgetX(#ORG_EDIT),GadgetY(#ORG_EDIT),GadgetWidth(#ORG_EDIT),GadgetHeight(#ORG_EDIT),@MyCallback())
CloseGadgetList()
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
The gridbox itself is a gadget, so you just have to get its handle (it's the handle of the splitters left gadget), open the gadgetlist, create your whacky, hacky scintillagadget and close the gadgetlist.
Re: ScintillaGadget EventTypes
Posted: Sat Apr 15, 2023 5:37 am
by Taz
Awesome, thank you very much for the solution and the explanation jacdelad. Now everything works.