ScintillaGadget EventTypes

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

ScintillaGadget EventTypes

Post by wombats »

Could we have the following EventTypes for the ScintillaGadget, please?

Code: Select all

#PB_EventType_Change
#PB_EventType_Focus
#PB_EventType_LostFocus
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ScintillaGadget EventTypes

Post 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
Last edited by mk-soft on Wed Aug 15, 2018 9:46 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: ScintillaGadget EventTypes

Post 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.
Taz
User
User
Posts: 52
Joined: Sat Jan 20, 2018 5:28 pm
Location: Germany

Re: ScintillaGadget EventTypes

Post 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?
User avatar
jacdelad
Addict
Addict
Posts: 1473
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: ScintillaGadget EventTypes

Post 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).
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Taz
User
User
Posts: 52
Joined: Sat Jan 20, 2018 5:28 pm
Location: Germany

Re: ScintillaGadget EventTypes

Post by Taz »

Thanks jacdelad for the "hack". :D
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
User avatar
jacdelad
Addict
Addict
Posts: 1473
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: ScintillaGadget EventTypes

Post 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. 8)
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Taz
User
User
Posts: 52
Joined: Sat Jan 20, 2018 5:28 pm
Location: Germany

Re: ScintillaGadget EventTypes

Post by Taz »

Awesome, thank you very much for the solution and the explanation jacdelad. Now everything works. :D
Post Reply