f



How to get selected text from a text edit control?

I created a text edit control using CreateEditTextControl.
I can get the current text by calling

char buf[256];
Size textSize = 0;
GetControlData(controlRef, kControlEditTextPart,
kControlEditTextTextTag, 255, buf, &textSize);

but how do I get only the text that is currently selected
(highlighted)?

thanks,

Shai

0
shai
3/17/2005 7:03:44 PM
comp.mac.codewarrior 2568 articles. 0 followers. ja7789 (3) is leader. Post Follow

3 Replies
1369 Views

Similar Articles

[PageSpeed] 26

In article <1111086224.345185.78280@g14g2000cwa.googlegroups.com>,
 shai@waves.com wrote:

> I created a text edit control using CreateEditTextControl.
> I can get the current text by calling
> 
> char buf[256];
> Size textSize = 0;
> GetControlData(controlRef, kControlEditTextPart,
> kControlEditTextTextTag, 255, buf, &textSize);
> 
> but how do I get only the text that is currently selected
> (highlighted)?
> 
> thanks,
> 
> Shai

char buf[256];
char * sel;
Size theSize = 0;
ControlEditTextSelectionRec selection;

GetControlData(controlRef, kControlEditTextPart, 
kControlEditTextTextTag, 255, buf, &theSize);
GetControlData(controlRef, kControlEditTextPart, 
kControlEditTextSelectionTag, sizeof(selection), &selection, &theSize);

sel = buf+selection.selStart;
sel[selection.selEnd] = '\0';

HTH,
-Will
0
Will
3/17/2005 7:27:29 PM
Thanks, Will, this is what I needed.


Will wrote:
> In article <1111086224.345185.78280@g14g2000cwa.googlegroups.com>,
>  shai@waves.com wrote:
>
> > I created a text edit control using CreateEditTextControl.
> > I can get the current text by calling
> >
> > char buf[256];
> > Size textSize = 0;
> > GetControlData(controlRef, kControlEditTextPart,
> > kControlEditTextTextTag, 255, buf, &textSize);
> >
> > but how do I get only the text that is currently selected
> > (highlighted)?
> >
> > thanks,
> >
> > Shai
>
> char buf[256];
> char * sel;
> Size theSize = 0;
> ControlEditTextSelectionRec selection;
>
> GetControlData(controlRef, kControlEditTextPart,
> kControlEditTextTextTag, 255, buf, &theSize);
> GetControlData(controlRef, kControlEditTextPart,
> kControlEditTextSelectionTag, sizeof(selection), &selection,
&theSize);
>
> sel = buf+selection.selStart;
> sel[selection.selEnd] = '\0';
> 
> HTH,
> -Will

0
shai
3/20/2005 8:10:51 AM
shai@waves.com wrote:
> I created a text edit control using CreateEditTextControl.
> I can get the current text by calling
>
> char buf[256];
> Size textSize = 0;
> GetControlData(controlRef, kControlEditTextPart,
> kControlEditTextTextTag, 255, buf, &textSize);

On Mac OS X this is considered old and undesirable. Is there a reason
you're using an Edit Text control instead of an Edit Unicode Text
control? And you should strongly consider getting the text as a
CFStringRef instead of a buffer of chars.

Larry

0
larry
3/21/2005 8:41:37 AM
Reply: