Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Embedding custom cocoa widgets in SWT
icon5.gif  Embedding custom cocoa widgets in SWT [message #520143] Thu, 11 March 2010 10:06 Go to next message
Artem Redkin is currently offline Artem RedkinFriend
Messages: 26
Registered: July 2009
Junior Member
I have written 2 classes in Cocoa, one which extends NSTextFieldCell, another - extends NSTextField to use first one. What is the right way to add them to my SWT project? Basically, i need to replace cell in SWT Text Widget's NSTextField to my custom one.
Re: Embedding custom cocoa widgets in SWT [message #520523 is a reply to message #520143] Fri, 12 March 2010 17:47 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
SWT currently sets the cell in Display.initClasses() (search for string
"SWTTextField") by calling NSTextField.setCellClass(...). So you need to do
this too, but this will remove the accessibility callbacks that swt's custom
cell was hooking. Perhaps the best approach is for you to create a Text
control, get its cell (this will be the SWT-provided cell), and make your
cell class a subclass of the SWT cell's class. Then you should be able to
call NSTextField.setCellClass(...) with your class and still preserve the
SWT cell's accessibility hooks.

If this doesn't work then feel free to follow up here.

Grant


"Artem Redkin" <artem@redkin.su> wrote in message
news:hnafb1$a9q$1@build.eclipse.org...
> I have written 2 classes in Cocoa, one which extends NSTextFieldCell,
another - extends NSTextField to use first one. What is the right way to add
them to my SWT project? Basically, i need to replace cell in SWT Text
Widget's NSTextField to my custom one.
Re: Embedding custom cocoa widgets in SWT [message #521407 is a reply to message #520523] Wed, 17 March 2010 14:18 Go to previous messageGo to next message
Artem Redkin is currently offline Artem RedkinFriend
Messages: 26
Registered: July 2009
Junior Member
Grant Gayed wrote on Fri, 12 March 2010 12:47
SWT currently sets the cell in Display.initClasses() (search for string
"SWTTextField") by calling NSTextField.setCellClass(...). So you need to do this too, but this will remove the accessibility callbacks that swt's custom cell was hooking. Perhaps the best approach is for you to create a Text control, get its cell (this will be the SWT-provided cell), and make your cell class a subclass of the SWT cell's class. Then you should be able to call NSTextField.setCellClass(...) with your class and still preserve the SWT cell's accessibility hooks.


Thank for your answer, Grant! I was able to substitute NSTextField's cell with my own, but other questions emerged.
If i call setCellClass, all my instances of Text will use my cell, right? I need both types of cell simultaneously, more precise i want new control, that is subclass of Text, that uses my cell. Maybe i should sublcass NSTextField and call setCellClass on it?

I also can't understand, how to call obj-c method through jni. I have function:
JNIEXPORT jint JNICALL Java_org_cargosoft_internal_LibDFCell_setButtonWidth(JNIEnv *env, jobject arg0, jfloat arg1) {
DefaultReferenceCell *cell = (DefaultReferenceCell*)arg0;
[cell setButtonsWidth:(float)arg1];
return 0;
}

from java i call it like that:
LibDFCell.setButtonWidth(widget.cell, 10);
With that i get:
Invalid memory access of location 0x3800000010 rip=0x7fff884ea13e
How can i pass pointer to cell to jni/obj-c (sorry, i'm not very experienced with jni)?
Re: Embedding custom cocoa widgets in SWT [message #522301 is a reply to message #521407] Mon, 22 March 2010 08:27 Go to previous message
Artem Redkin is currently offline Artem RedkinFriend
Messages: 26
Registered: July 2009
Junior Member
Artem Redkin wrote on Wed, 17 March 2010 10:18
I also can't understand, how to call obj-c method through jni. I have function:
JNIEXPORT jint JNICALL Java_org_cargosoft_internal_LibDFCell_setButtonWidth(JNIEnv *env, jobject arg0, jfloat arg1) {
DefaultReferenceCell *cell = (DefaultReferenceCell*)arg0;
[cell setButtonsWidth:(float)arg1];
return 0;
}
That was a bit stupid bit of code Smile. I was able to do it in java:

long selector = OS.sel_registerName("setButtonsWidth:");
OS.objc_msgSend(widget.cell().id, selector, 10);

But I want to know how to make objc/jni work. I rewrote jni code:
JNIEXPORT jlong JNICALL Java_org_cargosoft_internal_LibDFCell_setButtonWidth(JNIEnv *env, jlong arg0, jfloat arg1) {
jlong rc = 0;
SEL selector = sel_registerName("setButtonsWidth:");
rc = (jlong)objc_msgSend((id)arg0, selector, (float)arg1);
return rc;
}
This gives me Invalid memory access of location 0x3800000010 rip=0x7fff884ea13e.

[Updated on: Mon, 22 March 2010 10:54]

Report message to a moderator

Previous Topic:Ton futur PC
Next Topic:Calculate with pixels of text widget
Goto Forum:
  


Current Time: Sun Dec 15 15:52:59 GMT 2019

Powered by FUDForum. Page generated in 0.01974 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top