Page 1 of 1

Re: Cursor in StringGadget

Posted: Thu Dec 09, 2010 7:55 pm
by Shardik
WilliamL wrote:Hey, Shardik! What about the Mac?
Dear William,
unfortunately the only machine I don't have at work is a Mac... :lol:

But Windows (NT, XP, 7), AIX, z/OS (Mainframe), Linux (SLES, OpenSuse, Debian, Ubuntu,
Kubuntu, Xubuntu) and a VMWare 4.1 ESX cluster I would have available for testing purposes... :wink:

At home I have expanded my above example for MacOS X support:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  ImportC ""
    SetControlData(Control, ControlPartCode, TagName, BufferSize, *Buffer)
  EndImport

  #kControlEditTextPart = 5
  #kControlEditTextSelectionTag = 'sele'

  Structure ControlEditTextSelectionRec
    selStart.W
    selEnd.W
  EndStructure
CompilerEndIf

OpenWindow(0, 100, 200, 400, 200, "", #PB_Window_MinimizeGadget)
StringGadget(0, 50, 50, 200, 20, "example")
Text$ = GetGadgetText(0)
SetActiveGadget(0)

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_MacOS
    TextSelection.ControlEditTextSelectionRec
    TextSelection\selStart = Len(Text$)
    TextSelection\selEnd = Len(Text$)
    SetControlData(GadgetID(0), #kControlEditTextPart, #kControlEditTextSelectionTag, SizeOf(ControlEditTextSelectionRec), @TextSelection)
  CompilerCase #PB_OS_Linux
    gtk_editable_set_position_(GadgetID(0), -1)
  CompilerCase #PB_OS_Windows
    SendMessage_(GadgetID(0), #EM_SETSEL, Len(Text$), Len(Text$))
CompilerEndSelect

Repeat
  EventID = WaitWindowEvent()   
Until EventID = #PB_Event_CloseWindow

Re: Cursor in StringGadget

Posted: Thu Dec 09, 2010 8:27 pm
by Shardik
WilliamL wrote:

Code: Select all

gtk_editable_set_position_(GadgetID(0), -1)
..and does the -1 indicate the position? If so then do other values put the cursor somewhere else within the string?
Yes, but you can use gtk_editable_set_position() only in Linux because it is a Linux API function:
(http://library.gnome.org/devel/gtk/stab ... t-position)
GTK+ Reference Manual wrote:Sets the cursor position in the editable to the given value.

The cursor is displayed before the character with the given (base 0) index in the contents of the editable. The value must be less than or equal to the number of characters in the editable. A value of -1 indicates that the position should be set after the last character of the editable. Note that position is in characters, not in bytes.

Re: Cursor in StringGadget

Posted: Thu Dec 09, 2010 8:51 pm
by WilliamL
Thanks Shardik,

It works perfectly! And like the Linux example the same command can be used to select part or all of the text. This is a work-around for SetSelect for the Mac and I will add it to my list.