Any way to insert graphic into TextArea??

I’m using Xojo to create a document editor to teach myself a little programming. Using TextArea with the extensions provided by the macoslib, a lot of things happen for free. Back a “few” years ago when I was doing some very light programming, the motto was “steal the best, invent the rest” so this has worked out really well for me so far. Anyway, I am having no problem opening RTFD files with graphics and having them show up in my TextArea. Beyond that, I can’t resize or move the graphic other than by inserting/removing text.

What I’d like to be able to do is insert graphics from either a file or the clipboard and then subsequently manipulate (move and resize) the graphic as you can in most software. What I’m hoping is that it’s possible to use built-in cocoa functionality (this is going to be Mac-only) which has been great for me so far. If that’s not possible, it seems like it would be possible to directly manipulate the RTF control codes ({{\eXTGraphic attachment \widthN \heightN} string} that I got from Apple’s docs seems like a good place to start).

Can anybody point me in the right direction?

OK, I’m still trying. It seems as if there is a cocoa way of doing this, it would involve “createFromAttachment” and “insertAttributedString:atIndex”, but I’m fairly lost. Any ideas?

The TextArea is not a graphics-capable control from what I’ve seen. You will need to use a canvas and draw both the text and the graphic via code. The fact that you’re seeing the images is odd from my experience. My earlier tests with loading RTFD files resulted in very strange results.

However, if it IS working, you will need to manipulate the image and then reload / reflow the page.

Tim, I’m not using the standard TextArea. I’m using macoslib - there’s a link on Xojo’s support page. The five guys who put this together really know their stuff. It extends the standard Xojo TextArea by leveraging OS X’s built-in services. Essentially it really spoils you because you get a whole lot of functionality for almost no effort.

If I can indeed use cocoa functions, I might be able to get all the tidying-up you mentioned done for me. I’m not currently worried about cross-platform, so using macoslib isn’t limiting me in that respect. If I come up with an answer, I’ll post it here. My problem is that I stare at the ObjC stuff and it’s like hieroglyphics to me.

Ah - that makes my reading of your question dramatically different :).

For cross-platform results (I know you said you’re not worried about it) I’ve taken to using the WebKit HTMLViewer for pretty much everything in my program…

Shao,

I looked at HTMLViewer first thing when I started getting serious about learning Xojo last November. The demo to build a browser took about 10 minutes - pretty cool.

I’m actually looking to make a fairly full-featured editor, and I don’t think HTMLViewer does any kind of editing. However, TextArea with the macoslib will handle HTML as well as OS X’s .webarchive format. I can also load and edit Word .doc files, but any embedded graphics don’t show up (yet) and .docx files with no graphics and the paragraph formatting not right.

I’m pretty sure the relatively minor issues I’m having are from my own ignorance on how to use macoslib. Unfortunately, to understand how it works, I’m also having to get into Xcode to read the documentation and try to figure out what’s what. Very lucky for me is that the source for “TextEdit”, the basic editor that comes with OS X, is provided with Xcode for tutorial purposes. This relates almost directly to the extensions to TextArea provided by macoslib. The biggest problem of course is that I know less about cocoa/ObjC than I do about Xojo, so I don’t think this will be a fast process.

Anyway, it looks like I’m going to have to start reading up on NSAttributedString to figure this out. I thought asking on this forum might help, but not much luck yet. On the other hand, I’ve actually learned quite a bit and got some answers here just by searching for previous questions and answers. And I really have to say that macoslib is truly powerful - I just wish it was better documented. Thanks again to the people who contributed to it.

[quote=58228:@Danny Coyle]I’m using Xojo to create a document editor to teach myself a little programming. Using TextArea with the extensions provided by the macoslib, a lot of things happen for free. Back a “few” years ago when I was doing some very light programming, the motto was “steal the best, invent the rest” so this has worked out really well for me so far. Anyway, I am having no problem opening RTFD files with graphics and having them show up in my TextArea. Beyond that, I can’t resize or move the graphic other than by inserting/removing text.

What I’d like to be able to do is insert graphics from either a file or the clipboard and then subsequently manipulate (move and resize) the graphic as you can in most software. What I’m hoping is that it’s possible to use built-in cocoa functionality (this is going to be Mac-only) which has been great for me so far. If that’s not possible, it seems like it would be possible to directly manipulate the RTF control codes ({{\eXTGraphic attachment \widthN \heightN} string} that I got from Apple’s docs seems like a good place to start).

Can anybody point me in the right direction?[/quote]

If you are using cocoa to make a text editor, you will need the free formattedtextinput Plugin (see bkeeney software) since cocoa and carbon are wildly different in handling styledtext… but you could change the widthN and heightN in the styledtext based on mouse coordinates within the textarea surface to change placement.

A questionable method (I’ve used it) is to use an htmlviewer and let’s say TinyMCE, and put javascripts that are fired which make requests to an embedded tcpsocket when certain properties are invoked. Basically embedding a pseudo server that only recognizes certain commands and when data is received, sets Xojo properties equal to that value (like htmlviewer.Text would get the contents of the editor) then do whatever you want with them application side.

Matthew,

Thanks for your response. To the extent I understood your second suggestion, it sounds like it would be at least a good learning experience. I’ll try the plugin you mentioned. Judging by what I’ve seen on the forum, B. Keeney is held in pretty high regard (plus I like “free”).

The widthN and heightN properties I’ve played with and knew those would work. What’s interesting is that if I copy a graphic from within the macoslib-extended TextArea, it does get copied to the Mac clipboard. So, the ONLY thing I can’t seem to do is paste a graphic in that environment (text alone, including styles, works fine).

I know that you know what you’re talking about, so I will stop beating my head on the floor. Been learning a lot, though. Thanks again.

in TextArea Open Event

  #if targetCocoa
    declare function documentView lib "Cocoa" selector "documentView" _
    (obj_id as Integer) as Ptr
    declare sub setImportsGraphics lib "Cocoa" selector "setImportsGraphics:" _
    (obj_id as Ptr, value as Boolean)
    setImportsGraphics (ptr(documentView(TextArea1.Handle)), true)
  #endif

Drag a picture th the TextArea

Well, the TextInputCanvas plugin is free but the Formatted Text Control is not. To deal with Cocoa text handling, Xojo had to release the TIC plugin.

The Formatted Text Control creates a word processor in a Canvas subclass. It allow RTF import/export, inline images, URL’s and a few other goodies that that TextArea control cannot do cross platform.

Links:
Formatted Text Control: http://www.bkeeney.com/formatted-text-control/
Text Input Canvas: GitHub - xojo/TextInputCanvas: TextInputCanvas is a plugin for the Xojo programming environment that allows developers to implement custom text input controls with international input support.

[quote=128256:@Axel Schneider]in TextArea Open Event

  #if targetCocoa
    declare function documentView lib "Cocoa" selector "documentView" _
    (obj_id as Integer) as Ptr
    declare sub setImportsGraphics lib "Cocoa" selector "setImportsGraphics:" _
    (obj_id as Ptr, value as Boolean)
    setImportsGraphics (ptr(documentView(TextArea1.Handle)), true)
  #endif

Drag a picture th the TextArea[/quote]

This is great ! Thank you .

Any way to make it work from code, instead of dropping the picture over ? Being able to paste from the clipboard comes to mind.

Also, it seems not possible to save the content of the TextArea as RTF :frowning:

If there is an image in the clipboard, you can paste it.
And there are 2 new contextmenu entries (Screenshot and Import from Camera or Scanner)

With an Image choose RTFD in the Save Dialog. (it has RTF, Plain Text, RTFD)

see more in this Example

Two graphics seem to be missing (Open16 and New16? if I remember correctly)

[quote=128550:@Axel Schneider]With an Image choose RTFD in the Save Dialog. (it has RTF, Plain Text, RTFD)

see more in this Example [/quote]

Great. Thank you.

Indeed. I have replaced them by a couple icons from the FatCow collection and was able to run the project.

Tipp: In Mavericks you can hit CTRL + CMD + SPACE on Push Button - Caption Field ,there are some icons

I have corrected it. (same link)

[quote=128559:@Axel Schneider]Tipp: In Mavericks you can hit CTRL + CMD + SPACE on Push Button - Caption Field ,there are some icons

[/quote]

Neat :slight_smile:

Added Font Inspector

DL