Page 1 of 1

StringGadget CursorPos question

Posted: Wed Aug 12, 2009 10:11 am
by sverson
How can I set/get the StringGadget's CursorPos on Mac OSX :?:

Code: Select all

Procedure SetCursorPos(GadgetNo.l, CursorPos)
  Protected GadgetID = GadgetID(GadgetNo)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      SendMessage_(GadgetID, #EM_SETSEL, CursorPos, CursorPos)  
    CompilerCase #PB_OS_Linux
      gtk_editable_set_position_(GadgetID, CursorPos)
    CompilerCase #PB_OS_MacOS
      ; ??? please help ...
  CompilerEndSelect
EndProcedure

Procedure.l GetCursorPos(GadgetNo.l)
  Protected GadgetID = GadgetID(GadgetNo)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ProcedureReturn SendMessage_(GadgetID, #EM_GETSEL, 0, 0)/65536 
    CompilerCase #PB_OS_Linux
      ProcedureReturn gtk_editable_get_position_(GadgetID)
    CompilerCase #PB_OS_MacOS
      ; ??? please help ...
    CompilerDefault
      ProcedureReturn 0
  CompilerEndSelect
EndProcedure

Posted: Wed Aug 12, 2009 6:14 pm
by WilliamL
...been asking myself the same question.

maybe you are looking for something like my 'feature request' of

http://www.purebasic.fr/english/viewtop ... =setselect

I haven't heard back about that request... :D

Re: StringGadget CursorPos question

Posted: Fri Feb 25, 2011 7:56 pm
by Shardik
sverson wrote:How can I set/get the StringGadget's CursorPos on Mac OSX :?:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  ImportC ""
    GetControlData(ControlRef.L, ControlPartCode.L, TagName.L, BufferSize.L, *Buffer, *ActualSize)
    SetControlData(ControlRef.L, ControlPartCode.L, TagName.L, BufferSize.L, *Buffer)
  EndImport

  #kControlEditTextPart = 5
  #kControlEditTextSelectionTag = 'sele'

  Structure ControlEditTextSelectionRec
    SelStart.W
    SelEnd.W
  EndStructure
CompilerEndIf

Procedure SetCursorPos(GadgetNo.l, CursorPos)
  Protected GadgetID = GadgetID(GadgetNo)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      SendMessage_(GadgetID, #EM_SETSEL, CursorPos, CursorPos) 
    CompilerCase #PB_OS_Linux
      gtk_editable_set_position_(GadgetID, CursorPos)
    CompilerCase #PB_OS_MacOS
      TextSelection.ControlEditTextSelectionRec
      TextSelection\selStart = CursorPos
      TextSelection\selEnd = CursorPos
      SetControlData(GadgetID, #kControlEditTextPart, #kControlEditTextSelectionTag, SizeOf(ControlEditTextSelectionRec), @TextSelection)
      SetActiveGadget(GadgetNo)
  CompilerEndSelect
EndProcedure

Procedure.l GetCursorPos(GadgetNo.l)
  Protected GadgetID = GadgetID(GadgetNo)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ProcedureReturn SendMessage_(GadgetID, #EM_GETSEL, 0, 0)/65536
    CompilerCase #PB_OS_Linux
      ProcedureReturn gtk_editable_get_position_(GadgetID)
    CompilerCase #PB_OS_MacOS
      GetControlData(GadgetID, #kControlEditTextPart, #kControlEditTextSelectionTag, SizeOf(ControlEditTextSelectionRec), @TextSelection.ControlEditTextSelectionRec, 0)
      ProcedureReturn TextSelection\SelStart
  CompilerEndSelect
EndProcedure

Re: StringGadget CursorPos question

Posted: Fri Feb 25, 2011 9:28 pm
by sverson
@Shardik
Can't test it right now - thanks anyway.

:wink: sverson