It is currently Sat May 25, 2013 11:38 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Single-line Scintilla?
PostPosted: Tue Sep 25, 2012 1:07 am 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 932
Location: New York
Scintilla / the ScintillaGadget is a wonderful tool. Cross-platform, easy to customize and stylize, simple callback, etc. I just started using it this past year and I appreciate it very much...

I appreciate it so much I would like to use it in place of some StringGadgets (for formatting, mainly). Is it possible to force a ScintillaGadget to only allow a single line of text?

I have a feeling I will just need to watch the callback and manually filter out newline characters when typed or pasted.... unless anyone knows of a better way.


Top
 Profile  
 
 Post subject: Re: Single-line Scintilla?
PostPosted: Tue Sep 25, 2012 8:11 am 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1475
Maybe ?
Code:
  If OpenWindow(0, 0, 0, 320, 90, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
        InitScintilla()
        ScintillaGadget(0, 10, 10, 300, 40, #Null)       
        ScintillaSendMessage(0, #SCI_STYLESETFORE, 0, RGB(255, 0, 0))
       
 Repeat   
  Select WaitWindowEvent()
     
     Case #PB_Event_CloseWindow
          Quit = 1
         
     Case #PB_Event_Gadget
        Select EventGadget()
           Case 0
                  If ScintillaSendMessage(0, #SCI_GETLINECOUNT) > 1
                     Repeat                   
                        ScintillaSendMessage(0, #SCI_DELETEBACK)                   
                     Until ScintillaSendMessage(0, #SCI_GETLINECOUNT) = 1
                  EndIf
        EndSelect
  EndSelect
Until Quit = 1
  EndIf

_________________
Egypt my love


Top
 Profile  
 
 Post subject: Re: Single-line Scintilla?
PostPosted: Tue Sep 25, 2012 9:00 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 21, 2011 9:11 am
Posts: 125
Location: France (Paris)
To complete the code Rashad,
You can remove the horizontal scroll.
Code:
ScintillaSendMessage(0, #SCI_SETHSCROLLBAR, 0)


SetGadgetText not work. replaced by
Code:
ScintillaSendMessage(0, #SCI_SETTEXT, 0, @"Hello")


GettGadgetText not work. replaced by this procedure
Code:
Procedure.s ScintillaGetText(Gadget.l)
  Protected SciLength.i, *MemoryID.l, Buffer.s
 
  SciLength = ScintillaSendMessage(Gadget, #SCI_GETLENGTH)+1
      *MemoryID = AllocateMemory(SciLength)
      If *MemoryID
        ScintillaSendMessage(Gadget, #SCI_GETTEXT, SciLength, *MemoryID)
        Buffer=PeekS(*MemoryID)
        FreeMemory(*MemoryID) 
      EndIf
      ProcedureReturn(Buffer)
EndProcedure


Rashad code updated
Code:
Procedure.s ScintillaGetText(Gadget.l)
  Protected SciLength.i, *MemoryID.l, Buffer.s
 
  SciLength = ScintillaSendMessage(Gadget, #SCI_GETLENGTH)+1
      *MemoryID = AllocateMemory(SciLength)
      If *MemoryID
        ScintillaSendMessage(Gadget, #SCI_GETTEXT, SciLength, *MemoryID)
        Buffer=PeekS(*MemoryID)
        FreeMemory(*MemoryID) 
      EndIf
      ProcedureReturn(Buffer)
EndProcedure

Procedure ScintillaSetText(Gadget.l, Buffer.s)
  ScintillaSendMessage(Gadget, #SCI_SETTEXT, 0, @Buffer)
EndProcedure


If OpenWindow(0, 0, 0, 320, 90, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
        InitScintilla()
        ScintillaGadget(0, 10, 10, 300, 40, #Null)       
        ScintillaSendMessage(0, #SCI_STYLESETFORE, 0, RGB(255, 0, 0))
       
        ScintillaSendMessage(0, #SCI_SETHSCROLLBAR, 0)
       
        ScintillaSetText(0, "Hello")
        Debug ScintillaGetText(0)

       
 Repeat   
     Select WaitWindowEvent()
     
     Case #PB_Event_CloseWindow
          Quit = 1
         
     Case #PB_Event_Gadget
        Select EventGadget()
           Case 0
                 If ScintillaSendMessage(0, #SCI_GETLINECOUNT) > 1
                    ScintillaSendMessage(0, #SCI_DELETEBACK)
                 EndIf             
        EndSelect
  EndSelect
Until Quit = 1
  EndIf

_________________
Noob Inside - (Windows XP, 7 & 8: Full Version PB 4.51 -> 5.00)


Top
 Profile  
 
 Post subject: Re: Single-line Scintilla?
PostPosted: Tue Sep 25, 2012 9:43 am 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1475
kenmo did not ask about hiding the horizontal scroll :mrgreen:
Much more simple

Code:
  If OpenWindow(0, 0, 0, 300, 90, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
        InitScintilla()
        ContainerGadget(0,10,10,300,22)
          ScintillaGadget(1,-16, 0, 300, 40, #Null)
        CloseGadgetList()       
        ScintillaSendMessage(1, #SCI_STYLESETFORE, 0, RGB(255, 0, 0))
       
 Repeat   
  Select WaitWindowEvent()
     
     Case #PB_Event_CloseWindow
          Quit = 1
         
     Case #PB_Event_Gadget
        Select EventGadget()
           Case 1
                  If ScintillaSendMessage(1, #SCI_GETLINECOUNT) > 1
                     Repeat                   
                        ScintillaSendMessage(1, #SCI_DELETEBACK)                   
                     Until ScintillaSendMessage(1, #SCI_GETLINECOUNT) = 1
                  EndIf
        EndSelect
  EndSelect
Until Quit = 1
  EndIf


_________________
Egypt my love


Top
 Profile  
 
 Post subject: Re: Single-line Scintilla?
PostPosted: Tue Sep 25, 2012 9:51 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 21, 2011 9:11 am
Posts: 125
Location: France (Paris)
RASHAD wrote:
kenmo did not ask about hiding the horizontal scroll :mrgreen:
He did not ask .... but ask later when he has tested your previous code: p

Next time I'll wait before intervening. I would take rather a coffee :)

_________________
Noob Inside - (Windows XP, 7 & 8: Full Version PB 4.51 -> 5.00)


Top
 Profile  
 
 Post subject: Re: Single-line Scintilla?
PostPosted: Tue Sep 25, 2012 10:03 am 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1475
:P
You are a fan of ScintillaGadget() falsam
I can not beat you in that field

_________________
Egypt my love


Top
 Profile  
 
 Post subject: Re: Single-line Scintilla?
PostPosted: Wed Sep 26, 2012 1:51 am 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 932
Location: New York
Thanks to both of you, RASHAD and falsam!

This was easier than I expected.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye