Page 1 of 1

[Closed] Calling OSX Api's - Possible? - How to?

Posted: Wed Jan 11, 2006 11:47 pm
by garretthylltun
Is it possible to call OSX api's in PB? If yes, any docs on how to do it?
Tuts on it? Example code? A lollipop for at least trying?

I'm trying to get cut, copy and paste function to the EditorGadget, but
I don't think the WM messages for Windows will work in OSX.

I have found the page at apple.com that gives the info on the api's for
this, but at this point do not have a clue if these can be used in PB, or
if it is possible, how.

http://developer.apple.com/documentatio ... H1g-F07831

Example:
TECopy
Copies the text selection range from the edit structure, leaving the selection range intact.

Not recommended

void TECopy (
TEHandle hTE
);
Parameters
hTE
A handle to the edit structure containing the text to be copied.

Discussion
The TECopy function copies the text to the private scrap. For text of a monostyled edit structure, the text is written to the private scrap only. For text of a multistyled edit structure, the text is written to the TextEdit private scrap, the character attribute information is written to the TextEdit style scrap, and both are written to the Scrap Manager’s desk scrap. Anything previously in the private scrap is deleted before the copied text is written to it.

For both multistyled and monostyled text, if the selection range is an insertion point, TECopy empties the TextEdit private scrap. When the selection range is an insertion point and the text is multistyled, TECopy has no effect on the null scrap, the style scrap, or the Scrap Manager’s desk scrap.

Availability
Available in CarbonLib 1.0 and later when running Mac OS 8.1 or later.
Available in Mac OS X 10.0 and later.
Declared In
TextEdit.h
Thanks,
-Garrett

Posted: Wed Jan 11, 2006 11:55 pm
by Fred
it's possible, and you will have to create a .pbl, and then compile it with the pbsoimporter tool. You have more infos here : viewtopic.php?t=18206

Posted: Thu Jan 12, 2006 1:59 am
by garretthylltun
Damn API Stuff! Even when I programmed on Windows, API's always
ticked me off!

Ok, let me see if I follow this correctly...

Put the api item in the control.pbl file;

Code: Select all

;
-framework Carbon
TEPaste 1
Then from the terminal, run;

Code: Select all

/Applications/Programming/PureBasic/compilers/pbsoimporter /Applications/Programming/PureBasic/compilers/control.pbl /TO /Applications/Programming/PureBasic/
Then copy the output file to ????

And do I need a library call in my source, or an include, or create a
function call?

Kind of lost at that point, except that the actual function would go like
this;

Code: Select all

TEPaste_(GadgetID(12))
Any tips or corrections are very appreciated :-)

Thanks,
-Garrett

PS Yes SEO! I'm writing something to the Application directory! :twisted: And it's not causing any crashes or problems ;-)

Posted: Thu Jan 12, 2006 2:18 am
by SEO
And that because you have permissions, but if you give away your application or sell it, then Congratulations!! Then it is time for me to smile!!!
Sorry if I my idea was to help!!
/SEO

Posted: Thu Jan 12, 2006 2:37 am
by Fred
try to take another name for the .pbl (for example edit.pbl) and look in the purebasic/purelibraries/macos if the 'edit' file has been created or not. If yes, it should be recognized by the compiler automatically (when calling TEPaste(GadgetID(x))).

Posted: Thu Jan 12, 2006 6:26 am
by garretthylltun
Hmmmm..... I neglected to mention last time that the output file ended
up in purbasic/purelibraries/linux and not in /macos. Same again after
changing the control.pbl to edit.pbl

Is there any problem with this event?

-Garrett

Posted: Thu Jan 12, 2006 1:03 pm
by Fred
can you move the file from linux/ to macos/ and try ?

Posted: Thu Jan 12, 2006 5:32 pm
by garretthylltun
Yes, moved, and no compile error from PB about the calls not being
found. Though they are not working as intended, at least there are
no errors being sent up and no crashing due to the calls.

-Garrett

Posted: Thu Jan 12, 2006 7:54 pm
by Fred
Ha yes, that's because the GadgetID() for an EditorGadget returns the userpane handle and not the TextEditor object. Note than PB use the TXNObject. You can use

Code: Select all

GetControlProperty_(GadgetID, 'PURE', 'TXOB', 4, 0, @TextObject.l)
to retrieve it.

Posted: Fri Jan 13, 2006 2:27 am
by garretthylltun
Thank you Fred. I also realized after some reading that I needed to use
the TXN references instead of the TE references.

-Garrett

Posted: Fri Jan 13, 2006 3:02 am
by garretthylltun
Is the following correct:

Code: Select all

  EditorGadget(12, -3, -3, 406, 290)
  vEditorID = GetControlProperty_(GadgetID(12), 'PURE', 'TXOB', 4, 0, @TextObject.l)
And do I add GetControlProperty to my edit.pbl file?

Code: Select all

;
-framework Carbon
GetControlProperty 6
TXNCut 1
TXNCopy 1
TXNPaste 1
Thanks,
-Garrett

Posted: Fri Jan 13, 2006 12:57 pm
by Fred
yes, it's correct execpt than the ID is returned in the 'TextObject' variable (note the @ for the address of this variable). It should look like this:

Code: Select all

If GetControlProperty_(GadgetID(12), 'PURE', 'TXOB', 4, 0, @TextObject.l) = 0 ; 0 on OS X is 'noErr', which means the call is successful
  MessageRequester("","Good !")
EndIf

Posted: Fri Jan 13, 2006 9:10 pm
by garretthylltun
Fred, I thank you much for trying to help me, but I still cannot get the
api calls working. I'm not getting any errors, they just don't work. I
really need to be able to use cut, copy and paste, but do not want to
take up your time since you have other things that you need to work
on.

Is there a way to get cut, copy and paste working native to PB instead of
using api calls?

Or, do you (or anyone else readying this) have a working example using
the api calls for cut, copy and paste?

Merci beaucoup,
-Garrett

Posted: Fri Jan 13, 2006 9:23 pm
by Polo
There's a clipboard lib on Windows, is it there on MacOsX ?