EditorGadget: Jump to line number (Windows)

Just starting out? Need help? Post your questions and find answers here.
firace
Addict
Addict
Posts: 903
Joined: Wed Nov 09, 2011 8:58 am

EditorGadget: Jump to line number (Windows)

Post by firace »

This jumps to line 100 but does not set the caret there :(

Code: Select all

Enumeration 
  #EditArea
EndEnumeration

Window_1 = OpenWindow(#PB_Any, x, y, 554, 443, "Test", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)


EditorGadget(#EditArea,0,0,WindowWidth(Window_1),WindowHeight(Window_1)-24)
For g = 1 To 300
initialtext$ + g + " LOVE PUREBASIC!" + #CRLF$ 
Next
SetGadgetText(#EditArea, initialtext$)


SetActiveGadget(#EditArea)

SendMessage_(GadgetID(#EditArea),#EM_LINESCROLL,0,100)          ; this scrolls to Line 100 but does not place the caret there


Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_CloseWindow :   End    
  EndSelect
ForEver
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget: Jump to line number (Windows)

Post by RASHAD »

Hi

Code: Select all

Enumeration
  #EditArea
EndEnumeration

Window_1 = OpenWindow(#PB_Any, x, y, 554, 443, "Test", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)


EditorGadget(#EditArea,0,0,WindowWidth(Window_1), WindowHeight(Window_1)-24)
For g = 1 To 300
initialtext$ + g + " LOVE PUREBASIC!" + #CRLF$
Next
SetGadgetText(#EditArea, initialtext$)

SetActiveGadget(#EditArea)

SendMessage_(GadgetID(#EditArea),#EM_LINESCROLL,0,100)          ; this scrolls to Line 100 but does not place the caret there
index = SendMessage_(GadgetID(#EditArea),#EM_LINEINDEX,100-1,0)
SendMessage_(GadgetID(#EditArea),#EM_SETSEL,index,index)
Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_CloseWindow :   End   
  EndSelect
ForEver
Egypt my love
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: EditorGadget: Jump to line number (Windows)

Post by RSBasic »

RASHAD is too fast. I was just about to post a solution, too. :(
Image
Image
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget: Jump to line number (Windows)

Post by RASHAD »

Hi RSBasic
If your solution differ than mine Please post it
For the benefit of all forum members
Egypt my love
firace
Addict
Addict
Posts: 903
Joined: Wed Nov 09, 2011 8:58 am

Re: EditorGadget: Jump to line number (Windows)

Post by firace »

Thanks RASHAD, awesome :)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget: Jump to line number (Windows)

Post by RASHAD »

Hi firace
You are welcome
#EM_LINESCROLL has some drawbacks
Next is a better implementations

#1 :

Code: Select all

Enumeration
  #EditArea
EndEnumeration

LoadFont(0,"Tahoma",12)

Window_1 = OpenWindow(#PB_Any, x, y, 554, 443, "Test", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)

EditorGadget(#EditArea,0,0,WindowWidth(Window_1), WindowHeight(Window_1)-24)
SetGadgetFont(#EditArea,FontID(0))

For g = 1 To 300
  initialtext$ + g + " LOVE PUREBASIC!" + #CRLF$
Next
SetGadgetText(#EditArea, initialtext$)

SetActiveGadget(#EditArea)
Row = 250

;SendMessage_(GadgetID(#EditArea),#EM_LINESCROLL,0,Row)          ; this scrolls to Line 100 but does not place the caret there
index = SendMessage_(GadgetID(#EditArea),#EM_LINEINDEX,Row-1,0)
SendMessage_(GadgetID(#EditArea),#EM_SETSEL,index,index)
Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_CloseWindow :   End   
  EndSelect
ForEver
#2 :

Code: Select all

Enumeration
  #EditArea
EndEnumeration

Structure POINTL
  x.l
  y.l
EndStructure

LoadFont(0,"Tahoma",12)

Window_1 = OpenWindow(#PB_Any, x, y, 554, 443, "Test", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)


EditorGadget(#EditArea,0,0,WindowWidth(Window_1), WindowHeight(Window_1)-24)
SetGadgetFont(#EditArea,FontID(0))

For g = 1 To 300
initialtext$ + g + " LOVE PUREBASIC!" + #CRLF$
Next
SetGadgetText(#EditArea, initialtext$)

SetActiveGadget(#EditArea)

index = SendMessage_(GadgetID(#EditArea),#EM_LINEINDEX,1,0)
SendMessage_(GadgetID(#EditArea),#EM_POSFROMCHAR,p.POINTL,index)

Row = 120
Rowh = p\y

CreateImage(0, 2, Rowh ,24)
StartDrawing(ImageOutput(0))
    Box(0,0,2,Rowh,$F6F103)
StopDrawing()

;SendMessage_(GadgetID(#EditArea),#EM_LINESCROLL,0,Row)          ; this scrolls to Line 100 but does not place the caret there
index = SendMessage_(GadgetID(#EditArea),#EM_LINEINDEX,Row,0)
SendMessage_(GadgetID(#EditArea),#EM_SETSEL,index,index)
SendMessage_(GadgetID(#EditArea),#EM_POSFROMCHAR,p.POINTL,index-1)
CreateCaret_(GadgetID(#EditArea),ImageID(0),0,0)
SetCaretPos_(0,p\y)
ShowCaret_(GadgetID(#EditArea))
Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_CloseWindow :   End   
  EndSelect
ForEver
Egypt my love
Post Reply