How to get the handle of SWT control in Mac 64 bit cocoa enviornment?

我怕爱的太早我们不能终老 提交于 2020-01-05 05:01:13

问题


I have one Eclipse based RCP application in which I need to pass the SWT Control handles to native code to paint something on it. I have the following code to get the handle of any SWT control:

public static int getControlHandle(Control c){
            int handle = 0;
            try {
                if(_isMACOS){
                    if(_viewField== null)
                        _viewField = Control.class.getDeclaredField("view");
                    Object view = _viewField.get(c);
                    if(_idField== null) {
                        Class<?>idClass = Class.forName("org.eclipse.swt.internal.cocoa.id");
                        _idField = idClass.getDeclaredField("id");
                    }
                    handle = _idField.getInt(view);

                }
                else {
                    if(_idField== null)
                        _idField = Control.class.getDeclaredField("handle");
                    handle = _idField.getInt(c);
                }
            }
            catch(Exception e){

            }
            return handle;
    }

_viewField and _idField are java.lang.reflect.Field.

While this works well for Windows and Mac 32 bit but its not working with Mac 64 bit cocoa libs and env. Is there any change in the way to get the handle for 64 bit Mac?


回答1:


On Cocoa 64 bit the id value is a long not an int



来源:https://stackoverflow.com/questions/29889540/how-to-get-the-handle-of-swt-control-in-mac-64-bit-cocoa-enviornment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!