weInsert

External developers... This forum's for you!

weInsert

Postby HairyHighlandCow » Mon Aug 15, 2016 9:52 am

I've had success using the internals toolbox to change properties of fields such as the text color of different chunks of text in the field. I'd like to change the text content in a field but I'm a bit confused by the options. One of the example projects uses this:

Code: Select all
weInsertFormattedText(par, hWE2, *textData, textLength, stylHandle, souphand, parahand, rulehand)


I don't want to change any text styles, just change the contents of the field and keep the existing text style. There is also 'weInsert()' which takes fewer options. However, I'm not sure what to pass it for the soup handle parameter.

Or can you just set the 'hText' part of a WEHandle directly? But then I assume a lot of other properties won't match the new text, like textLength and styling. I was wondering if calling the 'weInsert' method correctly would change the field's text and update the other properties automatically.
Externals, projects and software made with SC:
www.hairyhighlandcow.net/software/SC-projects.html
User avatar
HairyHighlandCow
 
Posts: 256
Joined: Sun Jul 06, 2008 1:45 pm
Location: London, UK

Re: weInsert

Postby codegreen » Mon Aug 15, 2016 2:00 pm

These variants all put text into the selection/insert point (defined by selSart/selEnd which you can either set manually to bypass redraw, or via weSetSelection).

weInsert implements WASTE 1.x style options (basically the original TextEdit suite), nowadays just a wrapper around weInsertFormattedText, which is itself a wrapper around WEPut

weInsertFormattedText adds support for WASTE 2.x level attributes like strikethrough and paragraph formatting

weUseText is a 'shortcut' that lets you just replace all the text in a field, applying the first style run's attributes to it

Only the text Handle is required for these (any style params are optional).

You certainly CAN modify the hText field (or any other part) of a WERec directly if you know what you're doing but otherwise it's generally not a good idea because it's a pretty complicated piece of kit so you risk orphaning various WERec sub-structures, or worse corrupting the project.

Does that help?

-Mark
codegreen
 
Posts: 1556
Joined: Mon Jul 14, 2008 11:03 pm

Re: weInsert

Postby HairyHighlandCow » Mon Aug 15, 2016 4:23 pm

Thanks Mark, I think 'weUseText' sounds like the nice shortcut I was looking for.

If in future I want to try something more advanced and use 'weInsert', could you tell me what the last parameter does? Looking at the definition of the WERec struct, there doesn't appear to be a member called 'hSoup'. I found a reference to it somewhere else but I couldn't work out what it was.

Code: Select all
weInsert (XCmdPtr par, WEHandle we, Ptr textPtr, long textLength, StScrpHandle hStyles, Handle hSoup);


codegreen wrote:You certainly CAN modify the hText field (or any other part) of a WERec directly if you know what you're doing but otherwise it's generally not a good idea because it's a pretty complicated piece of kit so you risk orphaning various WERec sub-structures, or worse corrupting the project.


Heh, yes I thought it might not be a good idea; even though I've got a few things to work, I'm not sure I feel very confident that I understand much of the complexities of a WERec yet.
Externals, projects and software made with SC:
www.hairyhighlandcow.net/software/SC-projects.html
User avatar
HairyHighlandCow
 
Posts: 256
Joined: Sun Jul 06, 2008 1:45 pm
Location: London, UK

Re: weInsert

Postby codegreen » Mon Aug 15, 2016 8:01 pm

Looking at the definition of the WERec struct, there doesn't appear to be a member called 'hSoup'. I found a reference to it somewhere else but I couldn't work out what it was.

It's a scrap format for WASTE embedded objects. The definitions for all these structures are in SuperWASTE_480.h, and you can find links to more documentation at http://www.merzwaren.com/waste/

-Mark
codegreen
 
Posts: 1556
Joined: Mon Jul 14, 2008 11:03 pm

Re: weInsert

Postby HairyHighlandCow » Fri Aug 19, 2016 8:33 am

Thanks Mark! I'm still using the 4.7 Internals Toolbox, I don't think you've released a beta of the 4.8 toolbox yet. I write externals on a Mac running OS 10.9 so I can still use the older version of XCode: I have decided to avoid trying to configure XCode 7 to play nicely with externals for the time being.
Externals, projects and software made with SC:
www.hairyhighlandcow.net/software/SC-projects.html
User avatar
HairyHighlandCow
 
Posts: 256
Joined: Sun Jul 06, 2008 1:45 pm
Location: London, UK


Return to Xcode and the Internals Toolbox

Who is online

Users browsing this forum: No registered users and 0 guests