Page 1 of 1

StringGadget Questions

Posted: Fri May 09, 2003 10:16 am
by Large
I'm sure these are easy ones to answer.

1. If I have some text in a multiple line string gadget and I use the command setgadgettext it overwrites the content already in the string gadget, is their a way to append text to a string gadget or insert text into a string gadget at the cursor position ?

2. Is their a way of reading highlighted text in a multiple line string gadget, I'm also testing another language which has feature that does this, its called 'get chunk', is their a way to read highlighted text in Pure basic.

Any help would be greatly appreciated. :D

Kind regards

Posted: Fri May 09, 2003 11:04 am
by dmoc
To answer part of your first question, read the gadget's text and append as you write to it. Something like...

SetGadgetText(#Gadget, GetGadgetText(#Gadget)+newtext)

Thanks but . . .

Posted: Fri May 09, 2003 11:46 am
by Large
dmoc that works great, all I need to know now is how to insert text at the cursor position.

I'm making an HTML editor which has a insert menu, you can select insert bold tags and it inserts <b></b> but at the moment it adds it to the end of the string gadget, I need it to insert it at the mouse position.

Kind regards

Posted: Fri May 09, 2003 12:58 pm
by freak
Guess this does the trick...

Code: Select all

; PureBasic Visual Designer v3.70a Beta


;- Window Constants
;
#Window_0 = 0

;- Gadget Constants
;
#Gadget_1 = 0
#original = 1
#start = 2


Procedure Open_Window_0()
  If OpenWindow(#Window_0, 402, 160, 293, 79,  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "New window ( 0 )")
    If CreateGadgetList(WindowID())
      TextGadget(#Gadget_1, 10, 10, 100, 30, "Enter String and select a piece:")
      StringGadget(#original, 110, 10, 170, 20, "")
      ButtonGadget(#start, 110, 40, 70, 20, "make bold")
      
    EndIf
  EndIf
EndProcedure


Open_Window_0()

Repeat
  Event = WaitWindowEvent()
  
  If event = #PB_EventGadget And EventGadgetID() = #start
  
    original.s = GetGadgetText(#original) ; get strings from Gadget
    new.s = ""
    
    ; get selected position from #original Gadget
    SendMessage_(GadgetID(#original), #EM_GETSEL, @startpos.l, @endpos.l)
    
    new = Left(original, startpos)  ; unselected part on the left
    new + "<B>"    ; bold mark
    new + Mid(original, startpos+1, endpos-startpos) ; marked text
    new + "</B>"   ; unbold mark
    new + Right(original, Len(original)-endpos) ; unselected part on the right
    
    SetGadgetText(#original, new) ; set new text


    ; set selection again (3 characters right of original position, because we
    ; added the <b>
    SendMessage_(GadgetID(#original), #EM_SETSEL, startpos+3, endpos+3) 
    ActivateGadget(#original)  ; activate Gadget again
  
  
  EndIf
  
Until Event = #PB_EventCloseWindow
End
Timo

Thanks for your reply but . . .

Posted: Fri May 09, 2003 2:02 pm
by Large
Thanks for your reply freak but . . .

I sat down and learnt how to use the richedit library, it doe's just what I want in two lines !!! :lol:

Kind regards

Re: Thanks for your reply but . . .

Posted: Sat Jan 20, 2018 7:01 am
by Dude
Freak's tip updated for the latest PureBasic (v5.61):

Code: Select all

#Window_0 = 0

;- Gadget Constants
;
#Gadget_1 = 0
#original = 1
#start = 2


Procedure Open_Window_0()
  If OpenWindow(#Window_0, 402, 160, 293, 79, "New window ( 0 )", #PB_Window_SystemMenu)
    TextGadget(#Gadget_1, 10, 10, 100, 30, "Enter String and select a piece:")
    StringGadget(#original, 110, 10, 170, 20, "this is a little test")
    ButtonGadget(#start, 110, 40, 70, 20, "make bold")
  EndIf
EndProcedure


Open_Window_0()

Repeat
  Event = WaitWindowEvent()
  
  If event = #PB_Event_Gadget And EventGadget() = #start
    
    original.s = GetGadgetText(#original) ; get strings from Gadget
    new.s = ""
    
    ; get selected position from #original Gadget
    SendMessage_(GadgetID(#original), #EM_GETSEL, @startpos.l, @endpos.l)
    
    new = Left(original, startpos)  ; unselected part on the left
    new + "<B>"                     ; bold mark
    new + Mid(original, startpos+1, endpos-startpos) ; marked text
    new + "</B>"                                     ; unbold mark
    new + Right(original, Len(original)-endpos)      ; unselected part on the right
    
    SetGadgetText(#original, new) ; set new text
    
    
    ; set selection again (3 characters right of original position, because we
    ; added the <b>
    SendMessage_(GadgetID(#original), #EM_SETSEL, startpos+3, endpos+3)
    SetActiveGadget(#original)  ; activate Gadget again
    
  EndIf
  
Until Event = #PB_Event_CloseWindow

Re:

Posted: Sat Jan 20, 2018 1:35 pm
by Dude
BTW, wasn't there a quicker way to append text to the end of a StringGadget without doing this:

Code: Select all

SetGadgetText(#Gadget, GetGadgetText(#Gadget)+newtext)
I'm sure I once did something with an API call to add text to the end, without reading the entire existing contents first, but I can't find anything in my sources now. I'm 99% sure it was something like SendMessage with #ES_SETTEXT or such. Anyone ever done it?

Re: Thanks for your reply but . . .

Posted: Tue Nov 20, 2018 6:06 am
by MarcosPC
Dude wrote:Freak's tip updated for the latest PureBasic (v5.61):
Error on line 30:

SendMessage_() is not a function, array, list, map or macro.


How can I arrange this?
My purebasic is version demo 5.51.
Windows 7 64

Right now, I appreciate any help.

Using google translate.

__________________________________________________
Quote tag repaired
20.11.2018
RSBasic

Re: Thanks for your reply but . . .

Posted: Tue Nov 20, 2018 7:02 am
by Bisonte
MarcosPC wrote:My purebasic is version demo 5.51
The use of the Windows-API is not available in the Purebasic demo.

Re: StringGadget Questions

Posted: Tue Nov 20, 2018 3:02 pm
by MarcosPC
Ok, thanks!